From e1ff231235ff7cb8bd559969f951e3f37e9fa96d Mon Sep 17 00:00:00 2001
From: John Kessenich <cepheus@frii.com>
Date: Sat, 16 Dec 2017 10:07:22 -0700
Subject: [PATCH] GLSL: Fix #1193: no 'location' on uniform/buffer block.

---
 Test/310implicitSizeArrayError.vert                 | 2 +-
 Test/450.vert                                       | 8 ++++++++
 Test/baseResults/310implicitSizeArrayError.vert.out | 8 ++++----
 Test/baseResults/330.frag.out                       | 4 +++-
 Test/baseResults/450.vert.out                       | 8 +++++++-
 glslang/MachineIndependent/ParseHelper.cpp          | 2 ++
 6 files changed, 25 insertions(+), 7 deletions(-)

diff --git a/Test/310implicitSizeArrayError.vert b/Test/310implicitSizeArrayError.vert
index 72c403e83..7aa0ee1b7 100644
--- a/Test/310implicitSizeArrayError.vert
+++ b/Test/310implicitSizeArrayError.vert
@@ -1,5 +1,5 @@
 #version 310 es
-layout (location=0) uniform Block {
+layout (binding=0) uniform Block {
   highp int a[];
 } uni;
 layout (location=0) out highp int o;
diff --git a/Test/450.vert b/Test/450.vert
index 51e9b1004..e99a133c1 100644
--- a/Test/450.vert
+++ b/Test/450.vert
@@ -46,3 +46,11 @@ void foo()
     allInvocationsEqual(b1);  // ERROR, need 4.6
 }
 ; // ERROR: no extraneous semicolons
+
+layout(location = 0) uniform locBlock {        // ERROR, no location uniform block
+    int a;
+};
+
+layout(location = 0) buffer locBuffBlock {     // ERROR, no location on buffer block
+    int b;
+};
diff --git a/Test/baseResults/310implicitSizeArrayError.vert.out b/Test/baseResults/310implicitSizeArrayError.vert.out
index 1eed457db..982634871 100644
--- a/Test/baseResults/310implicitSizeArrayError.vert.out
+++ b/Test/baseResults/310implicitSizeArrayError.vert.out
@@ -12,13 +12,13 @@ ERROR: node is still EOpNull!
 0:7        'o' (layout( location=0) smooth out highp int)
 0:7        direct index (layout( column_major shared) temp highp int)
 0:7          a: direct index for structure (layout( column_major shared) uniform implicitly-sized array of highp int)
-0:7            'uni' (layout( location=0 column_major shared) uniform block{layout( column_major shared) uniform implicitly-sized array of highp int a})
+0:7            'uni' (layout( binding=0 column_major shared) uniform block{layout( column_major shared) uniform implicitly-sized array of highp int a})
 0:7            Constant:
 0:7              0 (const int)
 0:7          Constant:
 0:7            2 (const int)
 0:?   Linker Objects
-0:?     'uni' (layout( location=0 column_major shared) uniform block{layout( column_major shared) uniform implicitly-sized array of highp int a})
+0:?     'uni' (layout( binding=0 column_major shared) uniform block{layout( column_major shared) uniform implicitly-sized array of highp int a})
 0:?     'o' (layout( location=0) smooth out highp int)
 0:?     'gl_VertexID' ( gl_VertexId highp int VertexId)
 0:?     'gl_InstanceID' ( gl_InstanceId highp int InstanceId)
@@ -36,13 +36,13 @@ ERROR: node is still EOpNull!
 0:7        'o' (layout( location=0) smooth out highp int)
 0:7        direct index (layout( column_major shared) temp highp int)
 0:7          a: direct index for structure (layout( column_major shared) uniform 1-element array of highp int)
-0:7            'uni' (layout( location=0 column_major shared) uniform block{layout( column_major shared) uniform 1-element array of highp int a})
+0:7            'uni' (layout( binding=0 column_major shared) uniform block{layout( column_major shared) uniform 1-element array of highp int a})
 0:7            Constant:
 0:7              0 (const int)
 0:7          Constant:
 0:7            2 (const int)
 0:?   Linker Objects
-0:?     'uni' (layout( location=0 column_major shared) uniform block{layout( column_major shared) uniform 1-element array of highp int a})
+0:?     'uni' (layout( binding=0 column_major shared) uniform block{layout( column_major shared) uniform 1-element array of highp int a})
 0:?     'o' (layout( location=0) smooth out highp int)
 0:?     'gl_VertexID' ( gl_VertexId highp int VertexId)
 0:?     'gl_InstanceID' ( gl_InstanceId highp int InstanceId)
diff --git a/Test/baseResults/330.frag.out b/Test/baseResults/330.frag.out
index 5919c76af..774563125 100644
--- a/Test/baseResults/330.frag.out
+++ b/Test/baseResults/330.frag.out
@@ -16,6 +16,7 @@ ERROR: 0:57: 'location on block member' : not supported for this version or the
 ERROR: 0:62: 'location on block member' : can only use in an in/out block 
 ERROR: 0:62: 'location qualifier on uniform or buffer' : not supported for this version or the enabled extensions 
 ERROR: 0:60: 'location qualifier on uniform or buffer' : not supported for this version or the enabled extensions 
+ERROR: 0:60: 'location' : cannot apply to uniform or buffer block 
 ERROR: 0:68: 'layout-id value' : cannot be negative 
 ERROR: 0:69: 'layout-id value' : cannot be negative 
 ERROR: 0:76: 'f2' : cannot use layout qualifiers on structure members 
@@ -23,6 +24,7 @@ ERROR: 0:91: 'location on block member' : can only use in an in/out block
 ERROR: 0:91: 'location qualifier on uniform or buffer' : not supported for this version or the enabled extensions 
 ERROR: 0:91: 'location' : overlapping use of location 3
 ERROR: 0:89: 'location qualifier on uniform or buffer' : not supported for this version or the enabled extensions 
+ERROR: 0:89: 'location' : cannot apply to uniform or buffer block 
 ERROR: 0:94: 'location' : either the block needs a location, or all members need a location, or no members have a location 
 ERROR: 0:108: 'A' : cannot use layout qualifiers on structure members 
 ERROR: 0:119: 'location' : overlapping use of location 44
@@ -38,7 +40,7 @@ ERROR: 0:140: 'assign' :  cannot convert from ' const float' to ' temp 2-compone
 ERROR: 0:141: 'textureQueryLod' : no matching overloaded function found 
 ERROR: 0:141: 'assign' :  cannot convert from ' const float' to ' temp 2-component vector of float'
 ERROR: 0:152: 'index' : value must be 0 or 1 
-ERROR: 39 compilation errors.  No code generated.
+ERROR: 41 compilation errors.  No code generated.
 
 
 Shader version: 330
diff --git a/Test/baseResults/450.vert.out b/Test/baseResults/450.vert.out
index 64143de56..0f5f23136 100644
--- a/Test/baseResults/450.vert.out
+++ b/Test/baseResults/450.vert.out
@@ -19,7 +19,9 @@ ERROR: 0:44: 'anyInvocation' : no matching overloaded function found
 ERROR: 0:45: 'allInvocations' : no matching overloaded function found 
 ERROR: 0:46: 'allInvocationsEqual' : no matching overloaded function found 
 ERROR: 0:48: 'extraneous semicolon' : not supported for this version or the enabled extensions 
-ERROR: 20 compilation errors.  No code generated.
+ERROR: 0:50: 'location' : cannot apply to uniform or buffer block 
+ERROR: 0:54: 'location' : cannot apply to uniform or buffer block 
+ERROR: 22 compilation errors.  No code generated.
 
 
 Shader version: 450
@@ -77,6 +79,8 @@ ERROR: node is still EOpNull!
 0:?     'outSS' ( smooth out structure{ global float f,  global structure{ global float f} s})
 0:?     'aui' (layout( binding=0 offset=0) uniform atomic_uint)
 0:?     'ui' ( global uint)
+0:?     'anon@1' (layout( location=0 column_major shared) uniform block{layout( column_major shared) uniform int a})
+0:?     'anon@2' (layout( location=0 column_major shared) buffer block{layout( column_major shared) buffer int b})
 0:?     'gl_VertexID' ( gl_VertexId int VertexId)
 0:?     'gl_InstanceID' ( gl_InstanceId int InstanceId)
 
@@ -112,6 +116,8 @@ ERROR: node is still EOpNull!
 0:?     'outSS' ( smooth out structure{ global float f,  global structure{ global float f} s})
 0:?     'aui' (layout( binding=0 offset=0) uniform atomic_uint)
 0:?     'ui' ( global uint)
+0:?     'anon@1' (layout( location=0 column_major shared) uniform block{layout( column_major shared) uniform int a})
+0:?     'anon@2' (layout( location=0 column_major shared) buffer block{layout( column_major shared) buffer int b})
 0:?     'gl_VertexID' ( gl_VertexId int VertexId)
 0:?     'gl_InstanceID' ( gl_InstanceId int InstanceId)
 
diff --git a/glslang/MachineIndependent/ParseHelper.cpp b/glslang/MachineIndependent/ParseHelper.cpp
index 228909c0e..d662be155 100644
--- a/glslang/MachineIndependent/ParseHelper.cpp
+++ b/glslang/MachineIndependent/ParseHelper.cpp
@@ -4569,6 +4569,8 @@ void TParseContext::layoutTypeCheck(const TSourceLoc& loc, const TType& type)
             break;
         case EvqUniform:
         case EvqBuffer:
+            if (type.getBasicType() == EbtBlock)
+                error(loc, "cannot apply to uniform or buffer block", "location", "");
             break;
         default:
             error(loc, "can only apply to uniform, buffer, in, or out storage qualifiers", "location", "");
-- 
GitLab