Refactor implementation constants. Bug 19353282 Change-Id: If2eb9f2d78c3a44b720bb1f223711411b576d710 Reviewed-on: https://swiftshader-review.googlesource.com/5140 Reviewed-by: Alexis Hétu <sugoi@google.com> Tested-by: Nicolas Capens <capn@google.com> Reviewed-by: Nicolas Capens <capn@google.com>
diff --git a/src/Main/Config.cpp b/src/Main/Config.cpp index 10928ba..becea9c 100644 --- a/src/Main/Config.cpp +++ b/src/Main/Config.cpp
@@ -14,63 +14,66 @@ #include "Thread.hpp" #include "Timer.hpp" -Profiler profiler; - -Profiler::Profiler() +namespace sw { - reset(); -} + Profiler profiler; -void Profiler::reset() -{ - framesSec = 0; - framesTotal = 0; - FPS = 0; - - #if PERF_PROFILE - for(int i = 0; i < PERF_TIMERS; i++) - { - cycles[i] = 0; - } - - ropOperations = 0; - ropOperationsTotal = 0; - ropOperationsFrame = 0; - - texOperations = 0; - texOperationsTotal = 0; - texOperationsFrame = 0; - - compressedTex = 0; - compressedTexTotal = 0; - compressedTexFrame = 0; - #endif -}; - -void Profiler::nextFrame() -{ - #if PERF_PROFILE - ropOperationsFrame = sw::atomicExchange(&ropOperations, 0); - texOperationsFrame = sw::atomicExchange(&texOperations, 0); - compressedTexFrame = sw::atomicExchange(&compressedTex, 0); - - ropOperationsTotal += ropOperationsFrame; - texOperationsTotal += texOperationsFrame; - compressedTexTotal += compressedTexFrame; - #endif - - static double fpsTime = sw::Timer::seconds(); - - double time = sw::Timer::seconds(); - double delta = time - fpsTime; - framesSec++; - - if(delta > 1.0) + Profiler::Profiler() { - FPS = framesSec / delta; - - fpsTime = time; - framesTotal += framesSec; - framesSec = 0; + reset(); } -} + + void Profiler::reset() + { + framesSec = 0; + framesTotal = 0; + FPS = 0; + + #if PERF_PROFILE + for(int i = 0; i < PERF_TIMERS; i++) + { + cycles[i] = 0; + } + + ropOperations = 0; + ropOperationsTotal = 0; + ropOperationsFrame = 0; + + texOperations = 0; + texOperationsTotal = 0; + texOperationsFrame = 0; + + compressedTex = 0; + compressedTexTotal = 0; + compressedTexFrame = 0; + #endif + }; + + void Profiler::nextFrame() + { + #if PERF_PROFILE + ropOperationsFrame = sw::atomicExchange(&ropOperations, 0); + texOperationsFrame = sw::atomicExchange(&texOperations, 0); + compressedTexFrame = sw::atomicExchange(&compressedTex, 0); + + ropOperationsTotal += ropOperationsFrame; + texOperationsTotal += texOperationsFrame; + compressedTexTotal += compressedTexFrame; + #endif + + static double fpsTime = sw::Timer::seconds(); + + double time = sw::Timer::seconds(); + double delta = time - fpsTime; + framesSec++; + + if(delta > 1.0) + { + FPS = framesSec / delta; + + fpsTime = time; + framesTotal += framesSec; + framesSec = 0; + } + } +} \ No newline at end of file
diff --git a/src/Main/Config.hpp b/src/Main/Config.hpp index 7237d28..7d0952c 100644 --- a/src/Main/Config.hpp +++ b/src/Main/Config.hpp
@@ -30,74 +30,69 @@ #define DEFAULT_THREAD_COUNT 0 #endif -enum +namespace sw { - PERF_PIXEL, - PERF_PIPE, - PERF_INTERP, - PERF_SHADER, - PERF_TEX, - PERF_ROP, + enum + { + PERF_PIXEL, + PERF_PIPE, + PERF_INTERP, + PERF_SHADER, + PERF_TEX, + PERF_ROP, - PERF_TIMERS -}; + PERF_TIMERS + }; -struct Profiler -{ - Profiler(); + struct Profiler + { + Profiler(); - void reset(); - void nextFrame(); + void reset(); + void nextFrame(); - int framesSec; - int framesTotal; - double FPS; + int framesSec; + int framesTotal; + double FPS; - #if PERF_PROFILE - double cycles[PERF_TIMERS]; + #if PERF_PROFILE + double cycles[PERF_TIMERS]; - int64_t ropOperations; - int64_t ropOperationsTotal; - int64_t ropOperationsFrame; + int64_t ropOperations; + int64_t ropOperationsTotal; + int64_t ropOperationsFrame; - int64_t texOperations; - int64_t texOperationsTotal; - int64_t texOperationsFrame; + int64_t texOperations; + int64_t texOperationsTotal; + int64_t texOperationsFrame; - int64_t compressedTex; - int64_t compressedTexTotal; - int64_t compressedTexFrame; - #endif -}; + int64_t compressedTex; + int64_t compressedTexTotal; + int64_t compressedTexFrame; + #endif + }; -extern Profiler profiler; + extern Profiler profiler; -enum -{ - OUTLINE_RESOLUTION = 4096, // Maximum vertical resolution of the render target - MIPMAP_LEVELS = 14, - MAX_COLOR_ATTACHMENTS = 8, - VERTEX_ATTRIBUTES = 16, - TEXTURE_IMAGE_UNITS = 16, - VERTEX_TEXTURE_IMAGE_UNITS = 16, - TOTAL_IMAGE_UNITS = TEXTURE_IMAGE_UNITS + VERTEX_TEXTURE_IMAGE_UNITS, - FRAGMENT_UNIFORM_VECTORS = 224, - VERTEX_UNIFORM_VECTORS = 256, - MAX_FRAGMENT_UNIFORM_COMPONENTS = FRAGMENT_UNIFORM_VECTORS * 4, - MAX_VERTEX_UNIFORM_COMPONENTS = VERTEX_UNIFORM_VECTORS * 4, - MAX_FRAGMENT_UNIFORM_BLOCKS = 12, - MAX_VERTEX_UNIFORM_BLOCKS = 12, - MAX_UNIFORM_BLOCK_SIZE = 16384, - MAX_FRAGMENT_UNIFORM_BLOCKS_COMPONENTS = MAX_FRAGMENT_UNIFORM_BLOCKS * MAX_UNIFORM_BLOCK_SIZE / 4, - MAX_VERTEX_UNIFORM_BLOCKS_COMPONENTS = MAX_VERTEX_UNIFORM_BLOCKS * MAX_UNIFORM_BLOCK_SIZE / 4, - MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS = MAX_FRAGMENT_UNIFORM_BLOCKS_COMPONENTS + MAX_FRAGMENT_UNIFORM_COMPONENTS, - MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS = MAX_VERTEX_UNIFORM_BLOCKS_COMPONENTS + MAX_VERTEX_UNIFORM_COMPONENTS, - MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS = 4, - MAX_UNIFORM_BUFFER_BINDINGS = MAX_FRAGMENT_UNIFORM_BLOCKS + MAX_VERTEX_UNIFORM_BLOCKS, // Limited to 127 by SourceParameter.bufferIndex in Shader.hpp - MAX_CLIP_PLANES = 6, - MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS = 64, - MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS = 64, - RENDERTARGETS = 4, -}; + enum + { + OUTLINE_RESOLUTION = 4096, // Maximum vertical resolution of the render target + MIPMAP_LEVELS = 14, + VERTEX_ATTRIBUTES = 16, + TEXTURE_IMAGE_UNITS = 16, + VERTEX_TEXTURE_IMAGE_UNITS = 16, + TOTAL_IMAGE_UNITS = TEXTURE_IMAGE_UNITS + VERTEX_TEXTURE_IMAGE_UNITS, + FRAGMENT_UNIFORM_VECTORS = 224, + VERTEX_UNIFORM_VECTORS = 256, + MAX_FRAGMENT_UNIFORM_BLOCKS = 12, + MAX_VERTEX_UNIFORM_BLOCKS = 12, + MAX_UNIFORM_BUFFER_BINDINGS = MAX_FRAGMENT_UNIFORM_BLOCKS + MAX_VERTEX_UNIFORM_BLOCKS, // Limited to 127 by SourceParameter.bufferIndex in Shader.hpp + MAX_UNIFORM_BLOCK_SIZE = 16384, + MAX_CLIP_PLANES = 6, + MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS = 64, + MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS = 64, + RENDERTARGETS = 4, + }; +} #endif // sw_Config_hpp
diff --git a/src/Main/SwiftConfig.cpp b/src/Main/SwiftConfig.cpp index d80e344..9dce441 100644 --- a/src/Main/SwiftConfig.cpp +++ b/src/Main/SwiftConfig.cpp
@@ -22,10 +22,10 @@ #include <sys/stat.h> #include <string.h> -extern Profiler profiler; - namespace sw { + extern Profiler profiler; + std::string itoa(int number) { std::stringstream ss;