From cf0f1e9db1d8e0053856c83890511ffd1deec1fd Mon Sep 17 00:00:00 2001 From: Pavel Rojtberg Date: Sun, 8 Sep 2024 13:34:08 +0200 Subject: [PATCH] GL3Plus: use global instead of per shader UBOs as we overwrite all data on binding anyway --- .../GL3Plus/include/OgreGL3PlusRenderSystem.h | 2 ++ .../GL3Plus/src/GLSL/include/OgreGLSLShader.h | 5 +---- .../src/GLSL/src/OgreGLSLSeparableProgram.cpp | 9 +-------- .../GL3Plus/src/GLSL/src/OgreGLSLShader.cpp | 7 +++---- .../GL3Plus/src/OgreGL3PlusRenderSystem.cpp | 16 ++++++++++++++++ 5 files changed, 23 insertions(+), 16 deletions(-) diff --git a/RenderSystems/GL3Plus/include/OgreGL3PlusRenderSystem.h b/RenderSystems/GL3Plus/include/OgreGL3PlusRenderSystem.h index d2957747acf..7e146bcc67c 100644 --- a/RenderSystems/GL3Plus/include/OgreGL3PlusRenderSystem.h +++ b/RenderSystems/GL3Plus/include/OgreGL3PlusRenderSystem.h @@ -102,6 +102,8 @@ namespace Ogre { std::array mCurrentShader; + HardwareBufferPtr mUniformBuffer[GPT_COUNT]; + GLenum getBlendMode(SceneBlendFactor ogreBlend) const; void bindVertexElementToGpu(const VertexElement& elem, diff --git a/RenderSystems/GL3Plus/src/GLSL/include/OgreGLSLShader.h b/RenderSystems/GL3Plus/src/GLSL/include/OgreGLSLShader.h index 993b7ee7a75..dcb8bb7acc5 100644 --- a/RenderSystems/GL3Plus/src/GLSL/include/OgreGLSLShader.h +++ b/RenderSystems/GL3Plus/src/GLSL/include/OgreGLSLShader.h @@ -52,8 +52,6 @@ namespace Ogre { void setSamplerBinding(bool enable) { mHasSamplerBinding = enable; } bool getSamplerBinding() const { return mHasSamplerBinding; } - const HardwareBufferPtr& getDefaultBuffer() const { return mDefaultBuffer; } - /// Overridden from GpuProgram const String& getLanguage(void) const override; protected: @@ -68,9 +66,8 @@ namespace Ogre { /// @param block uniform block to consider. -1 for non-UBO uniforms void extractUniforms(int block = -1) const; - void extractBufferBlocks(GLenum type) const; + void extractBufferBlocks(GLenum type); - mutable HardwareBufferPtr mDefaultBuffer; bool mHasSamplerBinding; }; diff --git a/RenderSystems/GL3Plus/src/GLSL/src/OgreGLSLSeparableProgram.cpp b/RenderSystems/GL3Plus/src/GLSL/src/OgreGLSLSeparableProgram.cpp index 1d712c2f6fe..fe2578eb334 100644 --- a/RenderSystems/GL3Plus/src/GLSL/src/OgreGLSLSeparableProgram.cpp +++ b/RenderSystems/GL3Plus/src/GLSL/src/OgreGLSLSeparableProgram.cpp @@ -120,14 +120,7 @@ namespace Ogre GLuint progID = mShaders[fromProgType]->getGLProgramHandle(); GLUniformCache* uniformCache = mShaders[fromProgType]->getUniformCache(); - bool usesUBO = false; - if(const auto& ubo = static_cast(mShaders[fromProgType])->getDefaultBuffer()) - { - // we ignore ma - ubo->writeData(0, ubo->getSizeInBytes(), params->getConstantList().data(), true); - static_cast(ubo.get())->bind(); - usesUBO = true; - } + bool usesUBO = !params->hasLogicalIndexedParameters(); // Iterate through uniform reference list and update uniform values for (const auto& it : params->getConstantDefinitions().map) diff --git a/RenderSystems/GL3Plus/src/GLSL/src/OgreGLSLShader.cpp b/RenderSystems/GL3Plus/src/GLSL/src/OgreGLSLShader.cpp index 88ea9e2a2c5..2046c11377b 100644 --- a/RenderSystems/GL3Plus/src/GLSL/src/OgreGLSLShader.cpp +++ b/RenderSystems/GL3Plus/src/GLSL/src/OgreGLSLShader.cpp @@ -566,7 +566,7 @@ namespace Ogre { } } - void GLSLShader::extractBufferBlocks(GLenum type) const + void GLSLShader::extractBufferBlocks(GLenum type) { GLint numBlocks = 0; OGRE_CHECK_GL_ERROR(glGetProgramInterfaceiv(mGLProgramHandle, type, GL_ACTIVE_RESOURCES, &numBlocks)); @@ -589,15 +589,14 @@ namespace Ogre { if (name == "OgreUniforms") // default buffer { extractUniforms(blockIdx); - int binding = mType == GPT_COMPUTE_PROGRAM ? 0 : int(mType); + int binding = mType == GPT_COMPUTE_PROGRAM ? 0 : (int(mType) % GPT_PIPELINE_COUNT); if (binding > 1) LogManager::getSingleton().logWarning( getResourceLogName() + " - using 'OgreUniforms' in this shader type does alias with shared_params"); - mDefaultBuffer = hbm.createUniformBuffer(values[2]); - static_cast(mDefaultBuffer.get())->setGLBufferBinding(binding); OGRE_CHECK_GL_ERROR(glUniformBlockBinding(mGLProgramHandle, blockIdx, binding)); + mLogicalToPhysical.reset(); continue; } diff --git a/RenderSystems/GL3Plus/src/OgreGL3PlusRenderSystem.cpp b/RenderSystems/GL3Plus/src/OgreGL3PlusRenderSystem.cpp index 83e25029fae..393280d6821 100644 --- a/RenderSystems/GL3Plus/src/OgreGL3PlusRenderSystem.cpp +++ b/RenderSystems/GL3Plus/src/OgreGL3PlusRenderSystem.cpp @@ -1648,6 +1648,22 @@ namespace Ogre { params->_updateSharedParams(); } + auto paramsSize = params->getConstantList().size(); + if (paramsSize && getCapabilities()->hasCapability(RSC_SEPARATE_SHADER_OBJECTS) && + !params->hasLogicalIndexedParameters()) + { + auto& ubo = mUniformBuffer[gptype]; + if(!ubo || ubo->getSizeInBytes() < paramsSize) + { + ubo = mHardwareBufferManager->createUniformBuffer(paramsSize); + } + + ubo->writeData(0, ubo->getSizeInBytes(), params->getConstantList().data(), true); + + int binding = gptype == GPT_COMPUTE_PROGRAM ? 0 : (int(gptype) % GPT_PIPELINE_COUNT); + static_cast(ubo.get())->setGLBufferBinding(binding); + } + // Pass on parameters from params to program object uniforms. program->updateUniforms(params, mask, gptype); }