glsl: Add gl_shader_program::UniformLocationBaseScale
authorIan Romanick <ian.d.romanick@intel.com>
Mon, 10 Jun 2013 17:35:05 +0000 (10:35 -0700)
committerIan Romanick <ian.d.romanick@intel.com>
Wed, 12 Jun 2013 23:30:18 +0000 (16:30 -0700)
This is used by _mesa_uniform_merge_location_offset and
_mesa_uniform_split_location_offset to determine how the base and offset
are packed.  Previously, this value was hard coded as (1U<<16) in those
functions via the shift and mask contained therein.  The value is still
(1U<<16), but it can be changed in the future.

The next patch dynamically generates this value.

NOTE: This is a candidate for stable release branches.

Signed-off-by: Ian Romanick <ian.d.romanick@intel.com>
Reviewed-by: Brian Paul <brianp@vmware.com>
Reviewed-and-tested-by: Chad Versace <chad.versace@linux.intel.com>
src/glsl/link_uniforms.cpp
src/mesa/main/mtypes.h
src/mesa/main/shaderobj.c
src/mesa/main/uniforms.h

index 010296b6b69bdd772cc05d608bd96ee238baa1a4..84680bebd9a387de5c73ee181946a1c7889b6863 100644 (file)
@@ -739,6 +739,8 @@ link_assign_uniform_locations(struct gl_shader_program *prog)
              sizeof(prog->_LinkedShaders[i]->SamplerTargets));
    }
 
+   prog->UniformLocationBaseScale = (1U<<16);
+
 #ifndef NDEBUG
    for (unsigned i = 0; i < num_user_uniforms; i++) {
       assert(uniforms[i].storage != NULL);
index 92a70f416d31de185cb72d104f8ac2d9c88cfcd8..cd8650cbc2b5693e7e297efb533592f96f13915a 100644 (file)
@@ -2332,6 +2332,21 @@ struct gl_shader_program
    struct gl_uniform_block *UniformBlocks;
    unsigned NumUniformBlocks;
 
+   /**
+    * Scale factor for the uniform base location
+    *
+    * This is used to generate locations (returned by \c glGetUniformLocation)
+    * of uniforms.  The base location of the uniform is multiplied by this
+    * value, and the array index is added.
+    *
+    * \note
+    * Must be >= 1.
+    *
+    * \sa
+    * _mesa_uniform_merge_location_offset, _mesa_uniform_split_location_offset
+    */
+   unsigned UniformLocationBaseScale;
+
    /**
     * Indices into the _LinkedShaders's UniformBlocks[] array for each stage
     * they're used in, or -1.
index a60d8f38a9a93cf595368c8e815774c59430bad0..a62ad0413cfea48cea537a2d1a73d6686de6bfbc 100644 (file)
@@ -283,6 +283,7 @@ _mesa_clear_shader_program_data(struct gl_context *ctx,
       ralloc_free(shProg->UniformStorage);
       shProg->NumUserUniformStorage = 0;
       shProg->UniformStorage = NULL;
+      shProg->UniformLocationBaseScale = 0;
    }
 
    if (shProg->UniformHash) {
index d718b0f12e39231c4720c36b955a6784dc9e9933..14fe26d5fdea90910b6275b24225426c40351cfc 100644 (file)
@@ -272,7 +272,9 @@ static inline GLint
 _mesa_uniform_merge_location_offset(const struct gl_shader_program *prog,
                                     unsigned base_location, unsigned offset)
 {
-   return (base_location << 16) | offset;
+   assert(prog->UniformLocationBaseScale >= 0);
+   assert(offset < prog->UniformLocationBaseScale);
+   return (base_location * prog->UniformLocationBaseScale) + offset;
 }
 
 /**
@@ -283,8 +285,8 @@ _mesa_uniform_split_location_offset(const struct gl_shader_program *prog,
                                     GLint location, unsigned *base_location,
                                    unsigned *offset)
 {
-   *offset = location & 0xffff;
-   *base_location = location >> 16;
+   *offset = location % prog->UniformLocationBaseScale;
+   *base_location = location / prog->UniformLocationBaseScale;
 }
 /*@}*/