Mesa (master): glsl: give all unnamed structs the same name

Nicolai Hähnle nh at kemper.freedesktop.org
Tue Jun 13 07:36:29 UTC 2017


Module: Mesa
Branch: master
Commit: 77ea2ada5ae4b72c43598f3faa518526cb36b822
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=77ea2ada5ae4b72c43598f3faa518526cb36b822

Author: Nicolai Hähnle <nicolai.haehnle at amd.com>
Date:   Fri May 12 12:22:45 2017 +0200

glsl: give all unnamed structs the same name

As a result, unnamed structs defined in different places of the program
are considered the same types if they have the same fields in the same
order.

This will simplify matching of global variables whose type is an unnamed
struct.

It also fixes a memory leak when the same shader containing unnamed
structs is compiled over and over again: instead of creating a new type
each time, the existing type is re-used.

Finally, this does have the effect that some previously rejected programs
are now accepted, such as:

   struct {
      float a;
   } s1;

   struct {
      float a;
   } s2;

   s2 = s1;

C/C++ do not allow that, but GLSL does seem to want to treat unnamed
structs with the same fields as the same type at least during linking
(and apparently, some applications require it), so it seems odd to treat
them as different types elsewhere.

Reviewed-by: Timothy Arceri <tarceri at itsqueeze.com>

---

 src/compiler/glsl/glsl_parser_extras.cpp | 16 +++++++---------
 1 file changed, 7 insertions(+), 9 deletions(-)

diff --git a/src/compiler/glsl/glsl_parser_extras.cpp b/src/compiler/glsl/glsl_parser_extras.cpp
index 398bab55dd..68af6baafa 100644
--- a/src/compiler/glsl/glsl_parser_extras.cpp
+++ b/src/compiler/glsl/glsl_parser_extras.cpp
@@ -1676,15 +1676,13 @@ ast_struct_specifier::ast_struct_specifier(void *lin_ctx, const char *identifier
 					   ast_declarator_list *declarator_list)
 {
    if (identifier == NULL) {
-      static mtx_t mutex = _MTX_INITIALIZER_NP;
-      static unsigned anon_count = 1;
-      unsigned count;
-
-      mtx_lock(&mutex);
-      count = anon_count++;
-      mtx_unlock(&mutex);
-
-      identifier = linear_asprintf(lin_ctx, "#anon_struct_%04x", count);
+      /* All anonymous structs have the same name. This simplifies matching of
+       * globals whose type is an unnamed struct.
+       *
+       * It also avoids a memory leak when the same shader is compiled over and
+       * over again.
+       */
+      identifier = "#anon_struct";
    }
    name = identifier;
    this->declarations.push_degenerate_list_at_head(&declarator_list->link);




More information about the mesa-commit mailing list