From b804de605cd27eefcb35b324b63eb68242d06e38 Mon Sep 17 00:00:00 2001
From: John Kessenich <cepheus@frii.com>
Date: Mon, 5 Sep 2016 12:19:18 -0600
Subject: [PATCH] HLSL: Track binding numbers to struct instances; fixes issue
 #496.

---
 Test/baseResults/hlsl.buffer.frag.out | 18 ++++++++++--------
 glslang/Include/revision.h            |  4 ++--
 hlsl/hlslGrammar.cpp                  | 18 ++++++++++--------
 3 files changed, 22 insertions(+), 18 deletions(-)

diff --git a/Test/baseResults/hlsl.buffer.frag.out b/Test/baseResults/hlsl.buffer.frag.out
index 23f8627dc..d1b36fb8a 100755
--- a/Test/baseResults/hlsl.buffer.frag.out
+++ b/Test/baseResults/hlsl.buffer.frag.out
@@ -23,19 +23,19 @@ gl_FragCoord origin is upper left
 0:27                  Constant:
 0:27                    0 (const uint)
 0:27              v3: direct index for structure (layout(column_major std140 ) uniform 4-component vector of float)
-0:27                'anon@2' (layout(column_major std140 ) uniform block{layout(column_major std140 ) uniform 4-component vector of float v3, layout(column_major std140 offset=20 ) uniform int i3})
+0:27                'anon@2' (layout(binding=2 column_major std140 ) uniform block{layout(column_major std140 ) uniform 4-component vector of float v3, layout(column_major std140 offset=20 ) uniform int i3})
 0:27                Constant:
 0:27                  0 (const uint)
 0:27            v4: direct index for structure (layout(column_major std430 offset=16 ) buffer 4-component vector of float)
-0:27              'anon@3' (layout(column_major std430 ) buffer block{layout(column_major std430 offset=16 ) buffer 4-component vector of float v4, layout(column_major std430 offset=48 ) buffer int i4, layout(column_major std430 offset=60 ) buffer float f1, layout(column_major std430 offset=64 ) buffer float f3, layout(column_major std430 offset=68 ) buffer float f4, layout(column_major std430 offset=72 ) buffer float f5, layout(column_major std430 ) buffer float f6, layout(column_major std430 ) buffer float f7})
+0:27              'anon@3' (layout(binding=8 column_major std430 ) buffer block{layout(column_major std430 offset=16 ) buffer 4-component vector of float v4, layout(column_major std430 offset=48 ) buffer int i4, layout(column_major std430 offset=60 ) buffer float f1, layout(column_major std430 offset=64 ) buffer float f3, layout(column_major std430 offset=68 ) buffer float f4, layout(column_major std430 offset=72 ) buffer float f5, layout(column_major std430 ) buffer float f6, layout(column_major std430 ) buffer float f7})
 0:27              Constant:
 0:27                0 (const uint)
 0:27        Branch: Return
 0:?   Linker Objects
 0:?     'anon@0' (layout(column_major std140 ) uniform block{layout(column_major std140 ) uniform 4-component vector of float v1})
 0:?     'anon@1' (layout(column_major std430 ) buffer block{layout(column_major std430 ) buffer 4-component vector of float v2})
-0:?     'anon@2' (layout(column_major std140 ) uniform block{layout(column_major std140 ) uniform 4-component vector of float v3, layout(column_major std140 offset=20 ) uniform int i3})
-0:?     'anon@3' (layout(column_major std430 ) buffer block{layout(column_major std430 offset=16 ) buffer 4-component vector of float v4, layout(column_major std430 offset=48 ) buffer int i4, layout(column_major std430 offset=60 ) buffer float f1, layout(column_major std430 offset=64 ) buffer float f3, layout(column_major std430 offset=68 ) buffer float f4, layout(column_major std430 offset=72 ) buffer float f5, layout(column_major std430 ) buffer float f6, layout(column_major std430 ) buffer float f7})
+0:?     'anon@2' (layout(binding=2 column_major std140 ) uniform block{layout(column_major std140 ) uniform 4-component vector of float v3, layout(column_major std140 offset=20 ) uniform int i3})
+0:?     'anon@3' (layout(binding=8 column_major std430 ) buffer block{layout(column_major std430 offset=16 ) buffer 4-component vector of float v4, layout(column_major std430 offset=48 ) buffer int i4, layout(column_major std430 offset=60 ) buffer float f1, layout(column_major std430 offset=64 ) buffer float f3, layout(column_major std430 offset=68 ) buffer float f4, layout(column_major std430 offset=72 ) buffer float f5, layout(column_major std430 ) buffer float f6, layout(column_major std430 ) buffer float f7})
 
 
 Linked fragment stage:
@@ -65,19 +65,19 @@ gl_FragCoord origin is upper left
 0:27                  Constant:
 0:27                    0 (const uint)
 0:27              v3: direct index for structure (layout(column_major std140 ) uniform 4-component vector of float)
-0:27                'anon@2' (layout(column_major std140 ) uniform block{layout(column_major std140 ) uniform 4-component vector of float v3, layout(column_major std140 offset=20 ) uniform int i3})
+0:27                'anon@2' (layout(binding=2 column_major std140 ) uniform block{layout(column_major std140 ) uniform 4-component vector of float v3, layout(column_major std140 offset=20 ) uniform int i3})
 0:27                Constant:
 0:27                  0 (const uint)
 0:27            v4: direct index for structure (layout(column_major std430 offset=16 ) buffer 4-component vector of float)
-0:27              'anon@3' (layout(column_major std430 ) buffer block{layout(column_major std430 offset=16 ) buffer 4-component vector of float v4, layout(column_major std430 offset=48 ) buffer int i4, layout(column_major std430 offset=60 ) buffer float f1, layout(column_major std430 offset=64 ) buffer float f3, layout(column_major std430 offset=68 ) buffer float f4, layout(column_major std430 offset=72 ) buffer float f5, layout(column_major std430 ) buffer float f6, layout(column_major std430 ) buffer float f7})
+0:27              'anon@3' (layout(binding=8 column_major std430 ) buffer block{layout(column_major std430 offset=16 ) buffer 4-component vector of float v4, layout(column_major std430 offset=48 ) buffer int i4, layout(column_major std430 offset=60 ) buffer float f1, layout(column_major std430 offset=64 ) buffer float f3, layout(column_major std430 offset=68 ) buffer float f4, layout(column_major std430 offset=72 ) buffer float f5, layout(column_major std430 ) buffer float f6, layout(column_major std430 ) buffer float f7})
 0:27              Constant:
 0:27                0 (const uint)
 0:27        Branch: Return
 0:?   Linker Objects
 0:?     'anon@0' (layout(column_major std140 ) uniform block{layout(column_major std140 ) uniform 4-component vector of float v1})
 0:?     'anon@1' (layout(column_major std430 ) buffer block{layout(column_major std430 ) buffer 4-component vector of float v2})
-0:?     'anon@2' (layout(column_major std140 ) uniform block{layout(column_major std140 ) uniform 4-component vector of float v3, layout(column_major std140 offset=20 ) uniform int i3})
-0:?     'anon@3' (layout(column_major std430 ) buffer block{layout(column_major std430 offset=16 ) buffer 4-component vector of float v4, layout(column_major std430 offset=48 ) buffer int i4, layout(column_major std430 offset=60 ) buffer float f1, layout(column_major std430 offset=64 ) buffer float f3, layout(column_major std430 offset=68 ) buffer float f4, layout(column_major std430 offset=72 ) buffer float f5, layout(column_major std430 ) buffer float f6, layout(column_major std430 ) buffer float f7})
+0:?     'anon@2' (layout(binding=2 column_major std140 ) uniform block{layout(column_major std140 ) uniform 4-component vector of float v3, layout(column_major std140 offset=20 ) uniform int i3})
+0:?     'anon@3' (layout(binding=8 column_major std430 ) buffer block{layout(column_major std430 offset=16 ) buffer 4-component vector of float v4, layout(column_major std430 offset=48 ) buffer int i4, layout(column_major std430 offset=60 ) buffer float f1, layout(column_major std430 offset=64 ) buffer float f3, layout(column_major std430 offset=68 ) buffer float f4, layout(column_major std430 offset=72 ) buffer float f5, layout(column_major std430 ) buffer float f6, layout(column_major std430 ) buffer float f7})
 
 // Module Version 10000
 // Generated by (magic number): 80001
@@ -123,6 +123,7 @@ gl_FragCoord origin is upper left
                               MemberDecorate 28 1 Offset 20
                               Decorate 28 Block
                               Decorate 30 DescriptorSet 0
+                              Decorate 30 Binding 2
                               MemberDecorate 34 0 Offset 16
                               MemberDecorate 34 1 Offset 48
                               MemberDecorate 34 2 Offset 60
@@ -133,6 +134,7 @@ gl_FragCoord origin is upper left
                               MemberDecorate 34 7 Offset 80
                               Decorate 34 BufferBlock
                               Decorate 36 DescriptorSet 0
+                              Decorate 36 Binding 8
                2:             TypeVoid
                3:             TypeFunction 2
                6:             TypeFloat 32
diff --git a/glslang/Include/revision.h b/glslang/Include/revision.h
index bd0738d54..1b212891e 100644
--- a/glslang/Include/revision.h
+++ b/glslang/Include/revision.h
@@ -2,5 +2,5 @@
 // For the version, it uses the latest git tag followed by the number of commits.
 // For the date, it uses the current date (when then script is run).
 
-#define GLSLANG_REVISION "Overload400-PrecQual.1465"
-#define GLSLANG_DATE "02-Sep-2016"
+#define GLSLANG_REVISION "Overload400-PrecQual.1468"
+#define GLSLANG_DATE "05-Sep-2016"
diff --git a/hlsl/hlslGrammar.cpp b/hlsl/hlslGrammar.cpp
index a4fe38ecd..c45cd8be8 100755
--- a/hlsl/hlslGrammar.cpp
+++ b/hlsl/hlslGrammar.cpp
@@ -1292,17 +1292,16 @@ bool HlslGrammar::acceptType(TType& type)
 //
 bool HlslGrammar::acceptStruct(TType& type)
 {
-    // This qualifier.storage will tell us whether it's an AST block or
-    // just a struct.
-    TQualifier qualifier;
-    qualifier.clear();
+    // This storage qualifier will tell us whether it's an AST
+    // block type or just a generic structure type.
+    TStorageQualifier storageQualifier = EvqTemporary;
 
     // CBUFFER
     if (acceptTokenClass(EHTokCBuffer))
-        qualifier.storage = EvqUniform;
+        storageQualifier = EvqUniform;
     // TBUFFER
     else if (acceptTokenClass(EHTokTBuffer))
-        qualifier.storage = EvqBuffer;
+        storageQualifier = EvqBuffer;
     // STRUCT
     else if (! acceptTokenClass(EHTokStruct))
         return false;
@@ -1337,10 +1336,13 @@ bool HlslGrammar::acceptStruct(TType& type)
     }
 
     // create the user-defined type
-    if (qualifier.storage == EvqTemporary)
+    if (storageQualifier == EvqTemporary)
         new(&type) TType(typeList, structName);
-    else
+    else {
+        TQualifier qualifier = type.getQualifier();
+        qualifier.storage = storageQualifier;
         new(&type) TType(typeList, structName, qualifier); // sets EbtBlock
+    }
 
     // If it was named, which means the type can be reused later, add
     // it to the symbol table.  (Unless it's a block, in which
-- 
GitLab