nir/spirv: Rework decoration iteration
authorJason Ekstrand <jason.ekstrand@intel.com>
Fri, 20 Nov 2015 23:15:38 +0000 (15:15 -0800)
committerJason Ekstrand <jason.ekstrand@intel.com>
Fri, 20 Nov 2015 23:15:40 +0000 (15:15 -0800)
The old code didn't work correctly if you had member decorations after
non-member decorations.  Since glslang never gave us any of those, it
wasn't properly tested.

src/glsl/nir/spirv_to_nir.c

index ba49b04a54e7ffbd23ac2f328476245c0a4082bd..70610ca0f66b4442c013cabf82b91b2bd31bea78 100644 (file)
@@ -186,24 +186,25 @@ vtn_handle_extension(struct vtn_builder *b, SpvOp opcode,
 static void
 _foreach_decoration_helper(struct vtn_builder *b,
                            struct vtn_value *base_value,
-                           int member,
+                           int parent_member,
                            struct vtn_value *value,
                            vtn_decoration_foreach_cb cb, void *data)
 {
-   int new_member = member;
-
    for (struct vtn_decoration *dec = value->decoration; dec; dec = dec->next) {
-      if (dec->member >= 0) {
-         assert(member == -1);
-         new_member = dec->member;
+      int member;
+      if (dec->member < 0) {
+         member = parent_member;
+      } else {
+         assert(parent_member == -1);
+         member = dec->member;
       }
 
       if (dec->group) {
          assert(dec->group->value_type == vtn_value_type_decoration_group);
-         _foreach_decoration_helper(b, base_value, new_member, dec->group,
+         _foreach_decoration_helper(b, base_value, member, dec->group,
                                     cb, data);
       } else {
-         cb(b, base_value, new_member, dec, data);
+         cb(b, base_value, member, dec, data);
       }
    }
 }