Skip to content

Commit

Permalink
GL3Plus: use global instead of per shader UBOs
Browse files Browse the repository at this point in the history
as we overwrite all data on binding anyway
  • Loading branch information
paroj committed Sep 8, 2024
1 parent 2d26c0e commit cf0f1e9
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 16 deletions.
2 changes: 2 additions & 0 deletions RenderSystems/GL3Plus/include/OgreGL3PlusRenderSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ namespace Ogre {

std::array<GLSLShader*, GPT_COUNT> mCurrentShader;

HardwareBufferPtr mUniformBuffer[GPT_COUNT];

GLenum getBlendMode(SceneBlendFactor ogreBlend) const;

void bindVertexElementToGpu(const VertexElement& elem,
Expand Down
5 changes: 1 addition & 4 deletions RenderSystems/GL3Plus/src/GLSL/include/OgreGLSLShader.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<GLSLShader*>(mShaders[fromProgType])->getDefaultBuffer())
{
// we ignore ma
ubo->writeData(0, ubo->getSizeInBytes(), params->getConstantList().data(), true);
static_cast<GL3PlusHardwareBuffer*>(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)
Expand Down
7 changes: 3 additions & 4 deletions RenderSystems/GL3Plus/src/GLSL/src/OgreGLSLShader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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<GL3PlusHardwareBuffer*>(mDefaultBuffer.get())->setGLBufferBinding(binding);
OGRE_CHECK_GL_ERROR(glUniformBlockBinding(mGLProgramHandle, blockIdx, binding));
mLogicalToPhysical.reset();
continue;
}

Expand Down
16 changes: 16 additions & 0 deletions RenderSystems/GL3Plus/src/OgreGL3PlusRenderSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<GL3PlusHardwareBuffer*>(ubo.get())->setGLBufferBinding(binding);
}

// Pass on parameters from params to program object uniforms.
program->updateUniforms(params, mask, gptype);
}
Expand Down

0 comments on commit cf0f1e9

Please sign in to comment.