Module: Mesa Branch: 9.1 Commit: 307a703c759263bb37285b0919721ff2c413fc56 URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=307a703c759263bb37285b0919721ff2c413fc56
Author: Ian Romanick <[email protected]> Date: Mon Jun 10 10:39:28 2013 -0700 glsl: Generate smaller values for uniform locations Previously we would generate uniform locations as (slot << 16) + array_index. We do this to handle applications that assume the location of a[2] will be +1 from the location of a[1]. This resulted in every uniform location being at least 0x10000. The OpenGL 4.3 spec was amended to require this behavior, but previous versions did not require locations of array (or structure) members be sequential. We've now encountered two applications that assume uniform values will be "small." As far as we can tell, these applications store the GLint returned by glGetUniformLocation in a int16_t or possibly an int8_t. THIS BEHAVIOR IS NOT GUARANTEED OR IMPLIED BY ANY VERSION OF OpenGL. Other implementations happen to have both these behaviors (sequential array elements and small values) since OpenGL 2.0, so let's just match their behavior. Fixes "3D Bowling" on Android. NOTE: This is a candidate for stable release branches. Signed-off-by: Ian Romanick <[email protected]> Reviewed-by: Brian Paul <[email protected]> Reviewed-and-tested-by: Chad Versace <[email protected]> (cherry picked from commit cfa3c5ad828f56559a6cc2de299f993b8e748ea4) --- src/glsl/link_uniforms.cpp | 15 ++++++++++++++- 1 files changed, 14 insertions(+), 1 deletions(-) diff --git a/src/glsl/link_uniforms.cpp b/src/glsl/link_uniforms.cpp index ac726f4..8e01d2e 100644 --- a/src/glsl/link_uniforms.cpp +++ b/src/glsl/link_uniforms.cpp @@ -730,7 +730,20 @@ link_assign_uniform_locations(struct gl_shader_program *prog) assert(sizeof(prog->SamplerTargets) == sizeof(parcel.targets)); memcpy(prog->SamplerTargets, parcel.targets, sizeof(prog->SamplerTargets)); - prog->UniformLocationBaseScale = (1U<<16); + + /* Determine the size of the largest uniform array queryable via + * glGetUniformLocation. Using this as the location scale guarantees that + * there is enough "room" for the array index to be stored in the low order + * part of the uniform location. It also makes the locations be more + * tightly packed. + */ + unsigned max_array_size = 1; + for (unsigned i = 0; i < num_user_uniforms; i++) { + if (uniforms[i].array_elements > max_array_size) + max_array_size = uniforms[i].array_elements; + } + + prog->UniformLocationBaseScale = max_array_size; #ifndef NDEBUG for (unsigned i = 0; i < num_user_uniforms; i++) { _______________________________________________ mesa-commit mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/mesa-commit
