Skip to content

Commit

Permalink
[GLES] Fixed ClothPhysics example for GLES.
Browse files Browse the repository at this point in the history
- SSBO binding slots can only be set in shaders for GLES :-(
- Enable LLGL_GLEXT_SHADER_STORAGE_BUFFER_OBJECT for GL_ES_VERSION_3_1, but exclude glShaderStorageBlockBinding() for GLES.
- Add LLGL_GLEXT_PROGRAM_INTERFACE_QUERY macro to fix conditional use of GLQueryBufferProperties().
  • Loading branch information
LukasBanana committed Aug 5, 2024
1 parent 956b4fd commit 11caca2
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 27 deletions.
10 changes: 5 additions & 5 deletions examples/Cpp/ClothPhysics/Example.CSForces.comp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

#version 430

#ifdef GL_ES
precision mediump float;
#if GL_ES
precision highp float;
#endif

layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
Expand All @@ -25,17 +25,17 @@ layout(std140, row_major) uniform SceneState
};

// Particle buffers
layout(std430) readonly buffer parBase
layout(std430, binding = 1) readonly buffer parBase
{
vec4 g_parBase[];
};

layout(std430) buffer parCurrPos
layout(std430, binding = 2) buffer parCurrPos
{
vec4 g_parCurrPos[];
};

layout(std430) buffer parVelocity
layout(std430, binding = 5) buffer parVelocity
{
vec4 g_parVelocity[];
};
Expand Down
12 changes: 6 additions & 6 deletions examples/Cpp/ClothPhysics/Example.CSRelaxation.comp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

#version 430

#ifdef GL_ES
precision mediump float;
#if GL_ES
precision highp float;
#endif

layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
Expand All @@ -25,22 +25,22 @@ layout(std140, row_major) uniform SceneState
};

// Particle buffers
layout(std430) buffer parCurrPos
layout(std430, binding = 2) buffer parCurrPos
{
vec4 g_parCurrPos[];
};

layout(std430) buffer parNextPos
layout(std430, binding = 3) buffer parNextPos
{
vec4 g_parNextPos[];
};

layout(std430) buffer parPrevPos
layout(std430, binding = 4) buffer parPrevPos
{
vec4 g_parPrevPos[];
};

layout(std430) writeonly buffer parVelocity
layout(std430, binding = 5) writeonly buffer parVelocity
{
vec4 g_parVelocity[];
};
Expand Down
12 changes: 8 additions & 4 deletions examples/Cpp/ClothPhysics/Example.CSStretchConstraints.comp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

#version 430

#if GL_ES
precision highp float;
#endif

layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;

layout(std140, row_major) uniform SceneState
Expand Down Expand Up @@ -31,22 +35,22 @@ struct ParticleView
};

// Particle buffers
layout(std430) readonly buffer parBase
layout(std430, binding = 1) buffer parBase
{
vec4 g_parBase[];
};

layout(std430) buffer parCurrPos
layout(std430, binding = 2) buffer parCurrPos
{
vec4 g_parCurrPos[];
};

layout(std430) writeonly buffer parNextPos
layout(std430, binding = 3) writeonly buffer parNextPos
{
vec4 g_parNextPos[];
};

layout(std430) buffer parNormal
layout(std430, binding = 6) buffer parNormal
{
vec4 g_parNormal[];
};
Expand Down
2 changes: 1 addition & 1 deletion examples/Cpp/ClothPhysics/Example.PS.frag
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#version 140

#ifdef GL_ES
#if GL_ES
precision mediump float;
precision mediump sampler2D;
#endif
Expand Down
2 changes: 1 addition & 1 deletion examples/Cpp/ClothPhysics/Example.VS.vert
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#version 140

#ifdef GL_ES
#if GL_ES
precision mediump float;
#endif

Expand Down
10 changes: 8 additions & 2 deletions examples/Cpp/ClothPhysics/Example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -361,12 +361,18 @@ class Example_ClothPhysics : public ExampleBase
computeShaders[1] = LoadShader({ LLGL::ShaderType::Compute, "Example.hlsl", "CSStretchConstraints", "cs_5_0" }, {}, {}, g_shaderMacros);
computeShaders[2] = LoadShader({ LLGL::ShaderType::Compute, "Example.hlsl", "CSRelaxation", "cs_5_0" }, {}, {}, g_shaderMacros);
}
else if (Supported(LLGL::ShadingLanguage::GLSL) || Supported(LLGL::ShadingLanguage::ESSL))
else if (Supported(LLGL::ShadingLanguage::GLSL))
{
computeShaders[0] = LoadShader({ LLGL::ShaderType::Compute, "Example.CSForces.comp" });
computeShaders[1] = LoadShader({ LLGL::ShaderType::Compute, "Example.CSStretchConstraints.comp" });
computeShaders[2] = LoadShader({ LLGL::ShaderType::Compute, "Example.CSRelaxation.comp" });
}
else if (Supported(LLGL::ShadingLanguage::ESSL))
{
computeShaders[0] = LoadShader({ LLGL::ShaderType::Compute, "Example.CSForces.comp", "", "310 es" });
computeShaders[1] = LoadShader({ LLGL::ShaderType::Compute, "Example.CSStretchConstraints.comp", "", "310 es" });
computeShaders[2] = LoadShader({ LLGL::ShaderType::Compute, "Example.CSRelaxation.comp", "", "310 es" });
}
else if (Supported(LLGL::ShadingLanguage::SPIRV))
{
computeShaders[0] = LoadShader({ LLGL::ShaderType::Compute, "Example.CSForces.450core.comp.spv" });
Expand Down Expand Up @@ -450,7 +456,7 @@ class Example_ClothPhysics : public ExampleBase
graphicsShaderPipeline.vs = LoadShader({ LLGL::ShaderType::Vertex, "Example.hlsl", "VS", "vs_5_0" }, usedVertexFormats, {}, g_shaderMacros);
graphicsShaderPipeline.ps = LoadShader({ LLGL::ShaderType::Fragment, "Example.hlsl", "PS", "ps_5_0" }, {}, g_shaderMacros);
}
else if (Supported(LLGL::ShadingLanguage::GLSL))
else if (Supported(LLGL::ShadingLanguage::GLSL) || Supported(LLGL::ShadingLanguage::ESSL))
{
graphicsShaderPipeline.vs = LoadShader({ LLGL::ShaderType::Vertex, "Example.VS.vert" }, usedVertexFormats, {}, g_shaderMacros);
graphicsShaderPipeline.ps = LoadShader({ LLGL::ShaderType::Fragment, "Example.PS.frag" }, {}, g_shaderMacros);
Expand Down
6 changes: 5 additions & 1 deletion sources/Renderer/OpenGL/OpenGL.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,14 @@
# define LLGL_GLEXT_TESSELLATION_SHADER
#endif

#if GL_ARB_shader_storage_buffer_object
#if GL_ARB_shader_storage_buffer_object || GL_ES_VERSION_3_1
# define LLGL_GLEXT_SHADER_STORAGE_BUFFER_OBJECT
#endif

#if GL_ARB_program_interface_query || GL_ES_VERSION_3_1
# define LLGL_GLEXT_PROGRAM_INTERFACE_QUERY
#endif

#if defined LLGL_OPENGL || GL_ES_VERSION_3_1
# define LLGL_GLEXT_GET_TEX_LEVEL_PARAMETER
#endif
Expand Down
4 changes: 2 additions & 2 deletions sources/Renderer/OpenGL/Shader/GLShaderBindingLayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ void GLShaderBindingLayout::UniformAndBlockBinding(GLuint program, GLStateManage
glUniformBlockBinding(program, blockIndex, resource.slot);
}

/* Set shader-storage bindings */
#ifdef LLGL_GLEXT_SHADER_STORAGE_BUFFER_OBJECT
/* Set shader-storage bindings (not supported in GLES) */
#if defined LLGL_GLEXT_SHADER_STORAGE_BUFFER_OBJECT && defined LLGL_OPENGL
for_range(i, numShaderStorageBindings_)
{
const NamedResourceBinding& resource = bindings_[resourceIndex++];
Expand Down
16 changes: 11 additions & 5 deletions sources/Renderer/OpenGL/Shader/GLShaderProgram.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@ static void GLQueryStreamOutputAttributes(GLuint program, ShaderReflection& refl
#endif
}

#ifdef GL_ARB_program_interface_query
#ifdef LLGL_GLEXT_PROGRAM_INTERFACE_QUERY

static bool GLGetProgramResourceProperties(
GLuint program,
Expand Down Expand Up @@ -620,7 +620,7 @@ static void GLQueryBufferProperties(GLuint program, ShaderResourceReflection& re
}
}

#endif // /GL_ARB_program_interface_query
#endif // /LLGL_GLEXT_PROGRAM_INTERFACE_QUERY

static void GLQueryConstantBuffers(GLuint program, ShaderReflection& reflection)
{
Expand Down Expand Up @@ -653,7 +653,7 @@ static void GLQueryConstantBuffers(GLuint program, ShaderReflection& reflection)
glGetActiveUniformBlockiv(program, i, GL_UNIFORM_BLOCK_DATA_SIZE, &blockSize);
resource.constantBufferSize = static_cast<std::uint32_t>(blockSize);

#ifdef GL_ARB_program_interface_query
#ifdef LLGL_GLEXT_PROGRAM_INTERFACE_QUERY
/* Query resource view properties */
GLQueryBufferProperties(program, resource, GL_UNIFORM_BLOCK, i);
#else
Expand Down Expand Up @@ -701,8 +701,14 @@ static void GLQueryStorageBuffers(GLuint program, ShaderReflection& reflection)
glGetProgramResourceName(program, GL_SHADER_STORAGE_BLOCK, i, maxNameLength, &nameLength, blockName.data());
resource.binding.name = std::string(blockName.data());

#ifdef LLGL_GLEXT_PROGRAM_INTERFACE_QUERY
/* Query resource view properties */
GLQueryBufferProperties(program, resource, GL_SHADER_STORAGE_BLOCK, i);
#else
/* Set binding slot to invalid index */
resource.binding.stageFlags = StageFlags::AllStages;
resource.binding.slot = LLGL_INVALID_SLOT;
#endif
}
reflection.resources.push_back(resource);
}
Expand Down Expand Up @@ -753,7 +759,7 @@ static void GLQueryUniforms(GLuint program, ShaderReflection& reflection)

resource.binding.slot = static_cast<std::uint32_t>(uniformValue);

#ifdef GL_ARB_program_interface_query
#ifdef LLGL_GLEXT_PROGRAM_INTERFACE_QUERY
/* Query resource properties */
const GLenum props[] =
{
Expand All @@ -774,7 +780,7 @@ static void GLQueryUniforms(GLuint program, ShaderReflection& reflection)
resource.binding.arraySize = static_cast<std::uint32_t>(params[6]);
}
else
#endif // /GL_ARB_program_interface_query
#endif // /LLGL_GLEXT_PROGRAM_INTERFACE_QUERY
{
/* Set binding slot to invalid index */
resource.binding.stageFlags = StageFlags::AllStages;
Expand Down

0 comments on commit 11caca2

Please sign in to comment.