how to fix "Vertex shader active uniforms exceed GL_MAX_VERTEX_UNIFORM_VECTORS (256)"

279 views
Skip to first unread message

Łukasz Indyk

unread,
Apr 10, 2023, 10:48:12 AM4/10/23
to angleproject
i'm running some complex rendering code for integration testing on android emulator running on x86 linux, this code works nicely on android devices but on emulator i get "Vertex shader active uniforms exceed GL_MAX_VERTEX_UNIFORM_VECTORS (256)".

my emulator uses swiftshader, in the past when swiftshader wasn't vulkan only and had open gl specific code i was able to fix it this way:

--- a/swiftshader/src/OpenGL/libGLESv2/Context.h

+++ b/swiftshader/src/OpenGL/libGLESv2/Context.h

@@ -75,7 +75,7 @@

 enum

 {

        MAX_VERTEX_ATTRIBS = sw::MAX_VERTEX_INPUTS,

-       MAX_UNIFORM_VECTORS = 2051,   // Device limit

+       MAX_UNIFORM_VECTORS = 256,   // Device limit

        MAX_VERTEX_UNIFORM_VECTORS = sw::VERTEX_UNIFORM_VECTORS - 3,   // Reserve space for gl_DepthRange

        MAX_VARYING_VECTORS = 10,

        MAX_TEXTURE_IMAGE_UNITS = sw::TEXTURE_IMAGE_UNITS,

but now swift shader is stripped to vulkan only open gl is provided by angle on top of vulkan swiftshader, so swiftshader/src/OpenGL/libGLESv2/Context.h no longer exists. i wonder what would be my best bet for the fix for my integration testing need?

for example looking into angle and swift shader code i see that in src/libANGLE/Caps.cpp and also in other places in code we have maxVertexUniformVectors variable set to 256, i wonder if doing this fix there and rebuilding angle for emulator would be a good idea?

Shahbaz Youssefi

unread,
Apr 11, 2023, 9:52:35 PM4/11/23
to angleproject
Hi,

The code you've found in src/libANGLE/Caps.cpp is not actually used anywhere (other than the no-op "null" backend). The real values for maxVertexUniformVectors are derived from the Vulkan device in the Vulkan backend. See how src/libANGLE/renderer/vulkan/vk_caps_utils.cpp sets it:

    GLuint maxUniformBlockSize = limitsVk.maxUniformBufferRange;
    ...

    const GLuint maxUniformVectors = maxUniformBlockSize / (sizeof(GLfloat) * kComponentsPerVector);
    ...

    // Uniforms are implemented using a uniform buffer, so the max number of uniforms we can
    // support is the max buffer range divided by the size of a single uniform (4X float).
    mNativeCaps.maxVertexUniformVectors   = maxUniformVectors;

So the ANGLE limit is derived from maxUniformBufferRange. In SwiftShader, I see in src/Vulkan/VkPhysicalDevice.cpp that it is set to 65536. This should give you a value of 4096, so you need to do a bit of debugging to understand why you are getting 256 here :-?

---

As a side note, if you have that many uniforms, you may want to instead consider using a uniform buffer.

Reply all
Reply to author
Forward
0 new messages