From f044cf76d6a35b65733fc20c54810042d6f6c8a5 Mon Sep 17 00:00:00 2001 From: samcake Date: Tue, 30 Jan 2018 18:31:30 -0800 Subject: [PATCH] add the count of compilations of shaders to avoid recompiling them if ot needed --- .../src/display-plugins/hmd/HmdDisplayPlugin.cpp | 1 - libraries/gpu-gl/src/gpu/gl/GLBackendShader.cpp | 2 ++ libraries/gpu/src/gpu/Shader.cpp | 4 ++++ libraries/gpu/src/gpu/Shader.h | 4 ++++ libraries/render/src/render/ShapePipeline.cpp | 2 +- 5 files changed, 11 insertions(+), 2 deletions(-) diff --git a/libraries/display-plugins/src/display-plugins/hmd/HmdDisplayPlugin.cpp b/libraries/display-plugins/src/display-plugins/hmd/HmdDisplayPlugin.cpp index b64836627c..d35d5c5317 100644 --- a/libraries/display-plugins/src/display-plugins/hmd/HmdDisplayPlugin.cpp +++ b/libraries/display-plugins/src/display-plugins/hmd/HmdDisplayPlugin.cpp @@ -398,7 +398,6 @@ void HmdDisplayPlugin::HUDRenderer::updatePipeline() { auto vs = gpu::Shader::createVertex(std::string(hmd_ui_vert)); auto ps = gpu::Shader::createPixel(std::string(hmd_ui_frag)); auto program = gpu::Shader::createProgram(vs, ps); - // gpu::gl::GLBackend::makeProgram(*program, gpu::Shader::BindingSet()); gpu::Shader::makeProgram(*program, gpu::Shader::BindingSet()); uniformsLocation = program->getUniformBuffers().findLocation("hudBuffer"); diff --git a/libraries/gpu-gl/src/gpu/gl/GLBackendShader.cpp b/libraries/gpu-gl/src/gpu/gl/GLBackendShader.cpp index 40b9c94610..e9d23b543f 100644 --- a/libraries/gpu-gl/src/gpu/gl/GLBackendShader.cpp +++ b/libraries/gpu-gl/src/gpu/gl/GLBackendShader.cpp @@ -62,6 +62,7 @@ GLShader* GLBackend::compileBackendShader(const Shader& shader, Shader::Compilat GLenum shaderDomain = SHADER_DOMAINS[shader.getType()]; GLShader::ShaderObjects shaderObjects; Shader::CompilationLogs compilationLogs(GLShader::NumVersions); + shader.incrementCompilationAttempt(); for (int version = 0; version < GLShader::NumVersions; version++) { auto& shaderObject = shaderObjects[version]; @@ -108,6 +109,7 @@ GLShader* GLBackend::compileBackendProgram(const Shader& program, Shader::Compil GLShader::ShaderObjects programObjects; + program.incrementCompilationAttempt(); Shader::CompilationLogs compilationLogs(GLShader::NumVersions); for (int version = 0; version < GLShader::NumVersions; version++) { diff --git a/libraries/gpu/src/gpu/Shader.cpp b/libraries/gpu/src/gpu/Shader.cpp index 35c9ad8ae2..b6b90e98fa 100755 --- a/libraries/gpu/src/gpu/Shader.cpp +++ b/libraries/gpu/src/gpu/Shader.cpp @@ -95,3 +95,7 @@ void Shader::setCompilationLogs(const CompilationLogs& logs) const { _compilationLogs.emplace_back(CompilationLog(log)); } } + +void Shader::incrementCompilationAttempt() const { + _numCompilationAttempts++; +} \ No newline at end of file diff --git a/libraries/gpu/src/gpu/Shader.h b/libraries/gpu/src/gpu/Shader.h index d78077a396..a489146e36 100755 --- a/libraries/gpu/src/gpu/Shader.h +++ b/libraries/gpu/src/gpu/Shader.h @@ -185,10 +185,12 @@ public: // Check the compilation state bool compilationHasFailed() const { return _compilationHasFailed; } const CompilationLogs& getCompilationLogs() const { return _compilationLogs; } + uint32_t getNumCompilationAttempts() const { return _numCompilationAttempts; } // Set COmpilation logs can only be called by the Backend layers void setCompilationHasFailed(bool compilationHasFailed) { _compilationHasFailed = compilationHasFailed; } void setCompilationLogs(const CompilationLogs& logs) const; + void incrementCompilationAttempt() const; const GPUObjectPointer gpuObject {}; @@ -219,6 +221,8 @@ protected: // The type of the shader, the master key Type _type; + // Number of attempts to compile the shader + mutable uint32_t _numCompilationAttempts{ 0 }; // Compilation logs (one for each versions generated) mutable CompilationLogs _compilationLogs; diff --git a/libraries/render/src/render/ShapePipeline.cpp b/libraries/render/src/render/ShapePipeline.cpp index 597a6a0fab..a6d73897ae 100644 --- a/libraries/render/src/render/ShapePipeline.cpp +++ b/libraries/render/src/render/ShapePipeline.cpp @@ -72,7 +72,7 @@ void ShapePlumber::addPipeline(const Filter& filter, const gpu::ShaderPointer& p BatchSetter batchSetter, ItemSetter itemSetter) { ShapeKey key{ filter._flags }; - if (program->getInputs().empty()) { + if (program->getNumCompilationAttempts() < 1) { gpu::Shader::BindingSet slotBindings; slotBindings.insert(gpu::Shader::Binding(std::string("lightingModelBuffer"), Slot::BUFFER::LIGHTING_MODEL)); slotBindings.insert(gpu::Shader::Binding(std::string("skinClusterBuffer"), Slot::BUFFER::SKINNING));