Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Devel #3218

Merged
merged 2 commits into from
Sep 8, 2024
Merged

Devel #3218

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions Docs/src/high-level-programs.md
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,18 @@ param_named skewMatrix float4 0.5 0 -0.5 1.0
This means that `mat[0]` is the first column in GLSL, but the first row in HLSL and %Ogre. %Ogre takes care of transposing square matrices before uploading them with GLSL, so matrix-vector multiplication `M*v` just works and `mat[0]` will return the same data.
However, with non-square matrices transposing would change their GLSL type from e.g. `mat2x4` (two columns, four rows) to `mat4x2` (two rows, four columns) and consequently what `mat[0]` would return. Therefore %Ogre just passes such matrices unchanged and you have to handle this case (notably in skinning) yourself by either transposing the matrix in the shader or column-wise access.

## Uniform Buffers {#Uniform-Buffers}

If supported by the RenderSystem, you can opt-in to use uniform buffers for parameter storage.
This is done by declaring the parameters in a uniform block named @c OgreUniforms

```cpp
layout(std140, row_major) uniform OgreUniforms
{
mat4 worldTransform;
}
```

## Transform Feedback Varyings {#Transform-Feedback-Varyings}

Similarly to vertex attributes, the transform feedback varyings are bound by name.
Expand Down
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