glsl: Add gl_uniform_buffer_variable::IndexName field
authorIan Romanick <ian.d.romanick@intel.com>
Tue, 22 Jan 2013 05:23:24 +0000 (00:23 -0500)
committerIan Romanick <ian.d.romanick@intel.com>
Fri, 25 Jan 2013 14:07:35 +0000 (09:07 -0500)
glGetUniformIndices requires that the block instance index not be
present in the name of queried uniforms.  However,
gl_uniform_buffer_variable::Name will include the instance index.  The
IndexName field is added to handle this difference.

Note that currently IndexName will always point to the same string as
Name.  This will change soon.

Signed-off-by: Ian Romanick <ian.d.romanick@intel.com>
Reviewed-by: Carl Worth <cworth@cworth.org>
src/glsl/ast_to_hir.cpp
src/glsl/link_uniforms.cpp
src/mesa/main/mtypes.h
src/mesa/main/uniforms.c

index 80dd86e78035a54e6a5124df4caf288b137ca990..bf4130fa8c6e0d5059edb83cc194aa536be4d818 100644 (file)
@@ -4322,6 +4322,7 @@ ast_uniform_block::hir(exec_list *instructions,
          &ubo->Uniforms[ubo->NumUniforms++];
 
       ubo_var->Name = ralloc_strdup(state->uniform_blocks, fields[i].name);
+      ubo_var->IndexName = ubo_var->Name;
       ubo_var->Type = fields[i].type;
       ubo_var->Offset = 0; /* Assigned at link time. */
       ubo_var->RowMajor = fields[i].row_major;
index 531efa4a39fe5b52086e8aaeca5c40d8540b57a9..68cafbf3946f184526090dcbe0b7aa33319623db 100644 (file)
@@ -510,7 +510,13 @@ link_cross_validate_uniform_block(void *mem_ctx,
       struct gl_uniform_buffer_variable *ubo_var =
         &linked_block->Uniforms[i];
 
-      ubo_var->Name = ralloc_strdup(*linked_blocks, ubo_var->Name);
+      if (ubo_var->Name == ubo_var->IndexName) {
+         ubo_var->Name = ralloc_strdup(*linked_blocks, ubo_var->Name);
+         ubo_var->IndexName = ubo_var->Name;
+      } else {
+         ubo_var->Name = ralloc_strdup(*linked_blocks, ubo_var->Name);
+         ubo_var->IndexName = ralloc_strdup(*linked_blocks, ubo_var->IndexName);
+      }
    }
 
    return linked_block_index;
index 4c7cc6099cab6aa60c1473940a5852b5bf212c99..9078475c62320966be59f3913e5e1633b4068158 100644 (file)
@@ -2273,6 +2273,19 @@ typedef enum
 struct gl_uniform_buffer_variable
 {
    char *Name;
+
+   /**
+    * Name of the uniform as seen by glGetUniformIndices.
+    *
+    * glGetUniformIndices requires that the block instance index \b not be
+    * present in the name of queried uniforms.
+    *
+    * \note
+    * \c gl_uniform_buffer_variable::IndexName and
+    * \c gl_uniform_buffer_variable::Name may point to identical storage.
+    */
+   char *IndexName;
+
    const struct glsl_type *Type;
    unsigned int Offset;
    GLboolean RowMajor;
index 62c85b3c0f5d3c8ade3224068c3ea415f63091be..d902407a077eda6e28e9795b5b17fdabaf428d24 100644 (file)
@@ -695,7 +695,7 @@ _mesa_GetActiveUniformBlockiv(GLuint program,
       for (i = 0; i < block->NumUniforms; i++) {
         unsigned offset;
         params[i] = _mesa_get_uniform_location(ctx, shProg,
-                                               block->Uniforms[i].Name,
+                                               block->Uniforms[i].IndexName,
                                                &offset);
       }
       return;