Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 1 | // Copyright 2016 The SwiftShader Authors. All Rights Reserved. |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2 | // |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6 | // |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 8 | // |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 14 | |
| 15 | #include "Config.hpp" |
| 16 | |
| 17 | #include "Thread.hpp" |
| 18 | #include "Timer.hpp" |
| 19 | |
Nicolas Capens | b663f71 | 2016-04-18 12:02:39 -0400 | [diff] [blame] | 20 | namespace sw |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 21 | { |
Nicolas Capens | b663f71 | 2016-04-18 12:02:39 -0400 | [diff] [blame] | 22 | Profiler profiler; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 23 | |
Nicolas Capens | b663f71 | 2016-04-18 12:02:39 -0400 | [diff] [blame] | 24 | Profiler::Profiler() |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 25 | { |
Nicolas Capens | b663f71 | 2016-04-18 12:02:39 -0400 | [diff] [blame] | 26 | reset(); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 27 | } |
Nicolas Capens | b663f71 | 2016-04-18 12:02:39 -0400 | [diff] [blame] | 28 | |
| 29 | void Profiler::reset() |
| 30 | { |
| 31 | framesSec = 0; |
| 32 | framesTotal = 0; |
| 33 | FPS = 0; |
| 34 | |
| 35 | #if PERF_PROFILE |
| 36 | for(int i = 0; i < PERF_TIMERS; i++) |
| 37 | { |
| 38 | cycles[i] = 0; |
| 39 | } |
| 40 | |
| 41 | ropOperations = 0; |
| 42 | ropOperationsTotal = 0; |
| 43 | ropOperationsFrame = 0; |
| 44 | |
| 45 | texOperations = 0; |
| 46 | texOperationsTotal = 0; |
| 47 | texOperationsFrame = 0; |
| 48 | |
| 49 | compressedTex = 0; |
| 50 | compressedTexTotal = 0; |
| 51 | compressedTexFrame = 0; |
| 52 | #endif |
| 53 | }; |
| 54 | |
| 55 | void Profiler::nextFrame() |
| 56 | { |
| 57 | #if PERF_PROFILE |
| 58 | ropOperationsFrame = sw::atomicExchange(&ropOperations, 0); |
| 59 | texOperationsFrame = sw::atomicExchange(&texOperations, 0); |
| 60 | compressedTexFrame = sw::atomicExchange(&compressedTex, 0); |
| 61 | |
| 62 | ropOperationsTotal += ropOperationsFrame; |
| 63 | texOperationsTotal += texOperationsFrame; |
| 64 | compressedTexTotal += compressedTexFrame; |
| 65 | #endif |
| 66 | |
| 67 | static double fpsTime = sw::Timer::seconds(); |
| 68 | |
| 69 | double time = sw::Timer::seconds(); |
| 70 | double delta = time - fpsTime; |
| 71 | framesSec++; |
| 72 | |
| 73 | if(delta > 1.0) |
| 74 | { |
| 75 | FPS = framesSec / delta; |
| 76 | |
| 77 | fpsTime = time; |
| 78 | framesTotal += framesSec; |
| 79 | framesSec = 0; |
| 80 | } |
| 81 | } |
| 82 | } |