[Mesa-dev] glsl: Properly handle blocks that define the same field name.

Submitted by Iago Toral Quiroga on April 4, 2014, 1:11 p.m.

Details

Message ID 1396617075-5760-1-git-send-email-itoral@igalia.com
State Accepted
Commit 6d0e30c6a332de9ea7ab00e1fd303df2fb337c64
Headers show

Not browsing as part of any series.

Commit Message

Iago Toral Quiroga April 4, 2014, 1:11 p.m.
Currently we can have name space collisions between blocks that define the same
fields. For example:

in block
{
    vec4 Color;
} In[];

out block
{
    vec4 Color;
} Out;

These two blocks will assign the same interface name (block.Color) to the Color
field in flatten_named_interface_blocks_declarations.cpp, leading to havoc.
This was breaking badly the gl-320-primitive-shading test from ogl-samples.

The patch uses the block instance name to avoid collisions, producing names
like block.In.Color and block.Out.Color to avoid the name clash.

Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=76394
---
 src/glsl/lower_named_interface_blocks.cpp | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

Patch hide | download patch | download mbox

diff --git a/src/glsl/lower_named_interface_blocks.cpp b/src/glsl/lower_named_interface_blocks.cpp
index 09d867e..04e0d36 100644
--- a/src/glsl/lower_named_interface_blocks.cpp
+++ b/src/glsl/lower_named_interface_blocks.cpp
@@ -125,8 +125,8 @@  flatten_named_interface_blocks_declarations::run(exec_list *instructions)
       for (unsigned i = 0; i < iface_t->length; i++) {
          const char * field_name = iface_t->fields.structure[i].name;
          char *iface_field_name =
-            ralloc_asprintf(mem_ctx, "%s.%s",
-                            iface_t->name, field_name);
+            ralloc_asprintf(mem_ctx, "%s.%s.%s",
+                            iface_t->name, var->name, field_name);
 
          ir_variable *found_var =
             (ir_variable *) hash_table_find(interface_namespace,
@@ -217,8 +217,8 @@  flatten_named_interface_blocks_declarations::handle_rvalue(ir_rvalue **rvalue)
 
    if (var->get_interface_type() != NULL) {
       char *iface_field_name =
-         ralloc_asprintf(mem_ctx, "%s.%s", var->get_interface_type()->name,
-                         ir->field);
+         ralloc_asprintf(mem_ctx, "%s.%s.%s", var->get_interface_type()->name,
+                         var->name, ir->field);
       /* Find the variable in the set of flattened interface blocks */
       ir_variable *found_var =
          (ir_variable *) hash_table_find(interface_namespace,