Skip to content

Commit

Permalink
GL: Limit uniform block size to 64KB
Browse files Browse the repository at this point in the history
This change works around an inefficiency in ANGLE when the uniform block
has a large size.  That will be fixed in a follow up, but in the
meantime this clamping makes ANGLE more uniform on different vendors
(most of which expose this limit as 64KB already).  This also aligns
with the strategy adopted by the Vulkan backend.

Bug: angleproject:346561003
Change-Id: Id23a1f1bbbc1c7224c432d5bee1c4989ff2c92b7
Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/5645627
Reviewed-by: Geoff Lang <[email protected]>
Commit-Queue: Shahbaz Youssefi <[email protected]>
  • Loading branch information
ShabbyX authored and Angle LUCI CQ committed Jun 21, 2024
1 parent 1202822 commit 3be15cb
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
4 changes: 4 additions & 0 deletions src/libANGLE/renderer/gl/renderergl_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1065,6 +1065,10 @@ void GenerateCaps(const FunctionsGL *functions,
QuerySingleGLInt64(functions, GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS);
caps->maxCombinedShaderUniformComponents[gl::ShaderType::Fragment] =
QuerySingleGLInt64(functions, GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS);

// Clamp the maxUniformBlockSize to 64KB (majority of devices support up to this size
// currently), some drivers expose an excessively large value.
caps->maxUniformBlockSize = std::min<GLint64>(0x10000, caps->maxUniformBlockSize);
}
else
{
Expand Down
9 changes: 3 additions & 6 deletions src/tests/gl_tests/UniformBufferTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3835,7 +3835,7 @@ TEST_P(WebGL2UniformBufferTest, LargeArrayOfStructs)
constexpr char kVertexShader[] = R"(
struct InstancingData
{
mat4 transformation;
vec4 transformation;
};
layout(std140) uniform InstanceBlock
Expand All @@ -3845,7 +3845,7 @@ TEST_P(WebGL2UniformBufferTest, LargeArrayOfStructs)
void main()
{
gl_Position = vec4(1.0) * instances[gl_InstanceID].transformation;
gl_Position = vec4(1.0) * instances[gl_InstanceID].transformation[0];
})";

constexpr char kFragmentShader[] = R"(#version 300 es
Expand All @@ -3860,12 +3860,9 @@ TEST_P(WebGL2UniformBufferTest, LargeArrayOfStructs)
glGetIntegerv(GL_MAX_UNIFORM_BLOCK_SIZE, &maxUniformBlockSize);

std::string vs = "#version 300 es\n#define MAX_INSTANCE_COUNT " +
std::to_string(std::min(800, maxUniformBlockSize / 64)) + kVertexShader;
std::to_string(maxUniformBlockSize / 16) + kVertexShader;

ANGLE_GL_PROGRAM(program, vs.c_str(), kFragmentShader);
// Add a draw call for the sake of the Vulkan backend that currently really builds shaders at
// draw time.
drawQuad(program, essl3_shaders::PositionAttrib(), 0.5f);
}

GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(UniformBufferTest);
Expand Down

0 comments on commit 3be15cb

Please sign in to comment.