Implement 'index' layout qualifier for fragment outputs. Based partly on a submission.
authorJohn Kessenich <cepheus@frii.com>
Tue, 19 Aug 2014 02:12:44 +0000 (02:12 +0000)
committerJohn Kessenich <cepheus@frii.com>
Tue, 19 Aug 2014 02:12:44 +0000 (02:12 +0000)
git-svn-id: https://cvs.khronos.org/svn/repos/ogl/trunk/ecosystem/public/sdk/tools/glslang@27759 e7fa87d3-cd2b-0410-9028-fcbf551c1848

18 files changed:
Test/330.frag
Test/400.geom
Test/430.vert
Test/baseResults/140.frag.out
Test/baseResults/140.vert.out
Test/baseResults/330.frag.out
Test/baseResults/400.geom.out
Test/baseResults/420.vert.out
Test/baseResults/430.vert.out
Test/baseResults/440.frag.out
Test/baseResults/440.vert.out
Test/baseResults/specExamples.frag.out
Todo.txt
glslang/Include/Types.h
glslang/MachineIndependent/ParseHelper.cpp
glslang/MachineIndependent/Versions.cpp
glslang/MachineIndependent/linkValidate.cpp
glslang/MachineIndependent/localintermediate.h

index d6083c0..a23ab66 100644 (file)
@@ -1,7 +1,7 @@
 #version 330 compatibility
 
 in vec4 inVar;
-out vec4 outVar;
+layout(location=0, index=0) out vec4 outVar;
 
 varying vec4 varyingVar;
 
@@ -118,3 +118,11 @@ layout(location = 44) in block {
     vec4 j; // gets location 43
     vec4 k; // ERROR, location 44 already used
 };
+
+layout(index=0) out vec4 outVar2; // ERROR: missing explicit location
+layout(location=0, index=1) out vec4 outVar3; // no error even though location is overlapping
+layout(location=0, index=1) out vec4 outVar4; // ERROR overlapping
+layout(location=27, index=0) in vec4 indexIn; // ERROR, not on in
+layout(location=0, index=0) in; // ERROR, not just on in
+layout(location=0, index=0) out; // ERROR, need a variable
+layout(location=26, index=0) out indexBlock { int a; } indexBlockI; // ERROR, not on a block
\ No newline at end of file
index 34a3fb9..7fe9fc1 100644 (file)
@@ -99,3 +99,5 @@ void bits()
     i1 = findMSB(i1);\r
     i2 = findMSB(u2);\r
 }\r
+\r
+layout(location = 7, index = 1) out vec4 indexedOut;\r
index 0722823..64dd42f 100644 (file)
@@ -114,13 +114,13 @@ int bconst[gl_MaxTransformFeedbackInterleavedComponents];
 const int start2 = 5;\r
 layout(location = start2 * start2 - 2 - 4) in vec4 v6;\r
 \r
-layout(location = 28) in inblock2 {\r
+layout(location = 28) in inblock2 {  // ERROR, input block in vertex shader, other errors are valid checks still...\r
     bool b1;\r
     float f1;\r
     layout(location = 25) float f2;\r
 } ininst2;\r
 \r
-in ublock4 {\r
+in ublock4 {                         // ERROR, input block in vertex shader, other errors are valid checks still...\r
     layout(location = 50) float f1;\r
     layout(location = 51) float f2;\r
 } in4;\r
index 8600e92..ebb4e56 100644 (file)
@@ -6,7 +6,6 @@ ERROR: 0:24: 'location' : not supported for this version or the enabled extensio
 ERROR: 0:24: 'location qualifier on input' : not supported for this version or the enabled extensions \r
 ERROR: 0:26: 'location' : not supported for this version or the enabled extensions \r
 ERROR: 0:26: 'location qualifier on output' : not supported for this version or the enabled extensions \r
-WARNING: 0:28: '#extension' : extension is only partially supported: GL_ARB_explicit_attrib_location\r
 ERROR: 0:38: 'assign' :  l-value required "v" (can't modify shader input)\r
 ERROR: 0:38: 'out' : Non-L-value cannot be passed for 'out' or 'inout' parameters. \r
 ERROR: 8 compilation errors.  No code generated.\r
index 2fa9191..0b0799f 100644 (file)
@@ -2,7 +2,6 @@
 ERROR: 0:23: 'gl_Position' : identifiers starting with "gl_" are reserved \r
 ERROR: 0:25: 'location' : not supported for this version or the enabled extensions \r
 ERROR: 0:25: 'location qualifier on input' : not supported for this version or the enabled extensions \r
-WARNING: 0:27: '#extension' : extension is only partially supported: GL_ARB_explicit_attrib_location\r
 ERROR: 0:34: 'redeclaration' : cannot change storage, memory, or auxiliary qualification of gl_Position\r
 ERROR: 0:34: 'redeclaration' : cannot change interpolation qualification of gl_Position\r
 ERROR: 0:35: 'redeclaration' : cannot change the type of gl_Position\r
index e56026b..e2c4540 100644 (file)
@@ -26,7 +26,14 @@ ERROR: 0:89: 'location qualifier on uniform or buffer' : not supported for this
 ERROR: 0:94: 'location' : either the block needs a location, or all members need a location, or no members have a location \r
 ERROR: 0:108: 'A' : cannot use layout qualifiers on structure members \r
 ERROR: 0:119: 'location' : overlapping use of location 44\r
-ERROR: 27 compilation errors.  No code generated.\r
+ERROR: 0:122: 'index' : can only be used with an explicit location \r
+ERROR: 0:124: 'location' : overlapping use of location 0\r
+ERROR: 0:125: 'index' : can only be used on an output \r
+ERROR: 0:126: 'index' : can only be used on an output \r
+ERROR: 0:126: 'location/component/index' : cannot declare a default, use a full declaration \r
+ERROR: 0:127: 'location/component/index' : cannot declare a default, use a full declaration \r
+ERROR: 0:128: 'out' : cannot declare an output block in a fragment shader \r
+ERROR: 34 compilation errors.  No code generated.\r
 \r
 \r
 Shader version: 330\r
@@ -61,11 +68,11 @@ ERROR: node is still EOpNull!
 0:23            Constant:\r
 0:23              2 (const uint)\r
 0:24      move second child to first child (4-component vector of float)\r
-0:24        'outVar' (out 4-component vector of float)\r
+0:24        'outVar' (layout(location=0 index=0 ) out 4-component vector of float)\r
 0:24        'inVar' (smooth in 4-component vector of float)\r
 0:?   Linker Objects\r
 0:?     'inVar' (smooth in 4-component vector of float)\r
-0:?     'outVar' (out 4-component vector of float)\r
+0:?     'outVar' (layout(location=0 index=0 ) out 4-component vector of float)\r
 0:?     'varyingVar' (smooth in 4-component vector of float)\r
 0:?     'anon@0' (in block{in 4-component vector of float gl_Color, })\r
 0:?     'gl_name' (in block{in int gl_i})\r
@@ -90,6 +97,11 @@ ERROR: node is still EOpNull!
 0:?     'in4' (in block{layout(location=50 ) in float f1, layout(location=51 ) in float f2})\r
 0:?     's' (layout(location=33 ) smooth in structure{3-component vector of float a, 2X2 matrix of float b, 2-element array of 4-component vector of float c, 2-component vector of float A})\r
 0:?     'anon@2' (in block{layout(location=44 component=0 ) in 4-component vector of float d, layout(location=45 component=0 ) in 4-component vector of float e, layout(location=47 ) in 4-component vector of float f, layout(location=48 component=0 ) in 4-component vector of float g, layout(location=41 ) in 4-component vector of float h, layout(location=42 component=0 ) in 4-component vector of float i, layout(location=43 component=0 ) in 4-component vector of float j, layout(location=44 component=0 ) in 4-component vector of float k})\r
+0:?     'outVar2' (layout(location=63 index=0 ) out 4-component vector of float)\r
+0:?     'outVar3' (layout(location=0 index=1 ) out 4-component vector of float)\r
+0:?     'outVar4' (layout(location=0 index=1 ) out 4-component vector of float)\r
+0:?     'indexIn' (layout(location=27 index=0 ) smooth in 4-component vector of float)\r
+0:?     'indexBlockI' (layout(location=26 index=0 ) out block{out int a})\r
 \r
 \r
 Linked fragment stage:\r
@@ -129,11 +141,11 @@ ERROR: node is still EOpNull!
 0:23            Constant:\r
 0:23              2 (const uint)\r
 0:24      move second child to first child (4-component vector of float)\r
-0:24        'outVar' (out 4-component vector of float)\r
+0:24        'outVar' (layout(location=0 index=0 ) out 4-component vector of float)\r
 0:24        'inVar' (smooth in 4-component vector of float)\r
 0:?   Linker Objects\r
 0:?     'inVar' (smooth in 4-component vector of float)\r
-0:?     'outVar' (out 4-component vector of float)\r
+0:?     'outVar' (layout(location=0 index=0 ) out 4-component vector of float)\r
 0:?     'varyingVar' (smooth in 4-component vector of float)\r
 0:?     'anon@0' (in block{in 4-component vector of float gl_Color, })\r
 0:?     'gl_name' (in block{in int gl_i})\r
@@ -158,4 +170,9 @@ ERROR: node is still EOpNull!
 0:?     'in4' (in block{layout(location=50 ) in float f1, layout(location=51 ) in float f2})\r
 0:?     's' (layout(location=33 ) smooth in structure{3-component vector of float a, 2X2 matrix of float b, 2-element array of 4-component vector of float c, 2-component vector of float A})\r
 0:?     'anon@2' (in block{layout(location=44 component=0 ) in 4-component vector of float d, layout(location=45 component=0 ) in 4-component vector of float e, layout(location=47 ) in 4-component vector of float f, layout(location=48 component=0 ) in 4-component vector of float g, layout(location=41 ) in 4-component vector of float h, layout(location=42 component=0 ) in 4-component vector of float i, layout(location=43 component=0 ) in 4-component vector of float j, layout(location=44 component=0 ) in 4-component vector of float k})\r
+0:?     'outVar2' (layout(location=63 index=0 ) out 4-component vector of float)\r
+0:?     'outVar3' (layout(location=0 index=1 ) out 4-component vector of float)\r
+0:?     'outVar4' (layout(location=0 index=1 ) out 4-component vector of float)\r
+0:?     'indexIn' (layout(location=27 index=0 ) smooth in 4-component vector of float)\r
+0:?     'indexBlockI' (layout(location=26 index=0 ) out block{out int a})\r
 \r
index b05fd2f..65895a6 100644 (file)
@@ -18,7 +18,8 @@ ERROR: 0:65: 'max_vertices' : can only apply to 'out'
 ERROR: 0:65: 'invocations' : can only apply to 'in' \r
 ERROR: 0:67: 'in' : type must be an array: inbls\r
 ERROR: 0:71: 'triangles' : inconsistent input primitive for array size of inbla\r
-ERROR: 18 compilation errors.  No code generated.\r
+ERROR: 0:103: 'index' : there is no such layout identifier for this stage taking an assigned value \r
+ERROR: 19 compilation errors.  No code generated.\r
 \r
 \r
 Shader version: 400\r
@@ -180,6 +181,7 @@ ERROR: node is still EOpNull!
 0:?     'scalar' (in float)\r
 0:?     'inbls' (in block{in int a})\r
 0:?     'inbla' (in 17-element array of block{in int a})\r
+0:?     'indexedOut' (layout(location=7 stream=0 ) out 4-component vector of float)\r
 \r
 \r
 Linked geometry stage:\r
@@ -345,4 +347,5 @@ ERROR: node is still EOpNull!
 0:?     'scalar' (in float)\r
 0:?     'inbls' (in block{in int a})\r
 0:?     'inbla' (in 17-element array of block{in int a})\r
+0:?     'indexedOut' (layout(location=7 stream=0 ) out 4-component vector of float)\r
 \r
index ca3c81e..fd58f68 100644 (file)
@@ -23,7 +23,8 @@ ERROR: 0:54: 'y' : vector field selection out of range
 ERROR: 0:62: 'xxxxx' : illegal vector field selection \r
 ERROR: 0:63: 'xxy' : vector field selection out of range \r
 ERROR: 0:66: 'binding' : cannot declare a default, include a type or full declaration \r
-ERROR: 0:69: 'location' : cannot declare a default, use a full declaration \r
+ERROR: 0:69: 'location/component/index' : cannot declare a default, use a full declaration \r
+ERROR: 0:70: 'in' : cannot declare an input block in a vertex shader \r
 ERROR: 0:70: 'binding' : requires uniform or buffer storage qualifier \r
 ERROR: 0:71: 'binding' : binding is too large \r
 ERROR: 0:74: 'binding' : sampler binding not less than gl_MaxCombinedTextureImageUnits \r
@@ -48,7 +49,7 @@ ERROR: 0:142: 'r8_snorm' : does not apply to signed integer images
 ERROR: 0:143: 'rgba32ui' : does not apply to signed integer images \r
 ERROR: 0:144: 'r8ui' : does not apply to signed integer images \r
 ERROR: 0:147: 'offset on block member' : not supported for this version or the enabled extensions \r
-ERROR: 47 compilation errors.  No code generated.\r
+ERROR: 48 compilation errors.  No code generated.\r
 \r
 \r
 Shader version: 420\r
index 3f6515b..b3cb9b2 100644 (file)
@@ -1,6 +1,7 @@
 430.vert\r
 Warning, version 430 is not yet complete; most version-specific features are present, but some are missing.\r
 ERROR: 0:3: 'location' : can only appy to uniform, buffer, in, or out storage qualifiers \r
+ERROR: 0:7: 'in' : cannot declare an input block in a vertex shader \r
 ERROR: 0:7: 'location qualifier on in/out block' : not supported for this version or the enabled extensions \r
 ERROR: 0:8: 'location qualifier on in/out block' : not supported for this version or the enabled extensions \r
 ERROR: 0:21: 'g' : cannot use storage or interpolation qualifiers on structure members \r
@@ -16,7 +17,9 @@ ERROR: 0:47: 'gl_ClipDistance array size' : must be less than gl_MaxClipDistance
 ERROR: 0:51: 'start' : undeclared identifier \r
 ERROR: 0:51: '' : constant expression required \r
 ERROR: 0:51: 'layout-id value' : scalar integer expression required \r
+ERROR: 0:53: 'in' : cannot declare an input block in a vertex shader \r
 ERROR: 0:54: 'location on block member' : not supported for this version or the enabled extensions \r
+ERROR: 0:57: 'in' : cannot declare an input block in a vertex shader \r
 ERROR: 0:58: 'location on block member' : not supported for this version or the enabled extensions \r
 ERROR: 0:59: 'location on block member' : not supported for this version or the enabled extensions \r
 ERROR: 0:62: 'uniform buffer-member align' : not supported for this version or the enabled extensions \r
@@ -44,6 +47,8 @@ ERROR: 0:92: 'transform feedback qualifier' : not supported for this version or
 ERROR: 0:93: 'transform feedback qualifier' : not supported for this version or the enabled extensions \r
 ERROR: 0:93: 'transform feedback qualifier' : not supported for this version or the enabled extensions \r
 ERROR: 0:93: 'transform feedback qualifier' : not supported for this version or the enabled extensions \r
+ERROR: 0:117: 'in' : cannot declare an input block in a vertex shader \r
+ERROR: 0:123: 'in' : cannot declare an input block in a vertex shader \r
 ERROR: 0:146: 'shared' : not supported in this stage: vertex\r
 ERROR: 0:150: 'barrier' : no matching overloaded function found \r
 ERROR: 0:154: 'memoryBarrierShared' : no matching overloaded function found \r
@@ -53,7 +58,7 @@ ERROR: 0:168: 'textureSamples and imageSamples' : not supported for this version
 ERROR: 0:169: 'textureSamples and imageSamples' : not supported for this version or the enabled extensions \r
 ERROR: 0:170: 'textureSamples and imageSamples' : not supported for this version or the enabled extensions \r
 ERROR: 0:171: 'textureSamples and imageSamples' : not supported for this version or the enabled extensions \r
-ERROR: 53 compilation errors.  No code generated.\r
+ERROR: 58 compilation errors.  No code generated.\r
 \r
 \r
 Shader version: 430\r
index eb5632a..d872949 100644 (file)
@@ -19,11 +19,13 @@ ERROR: 0:35: 'layout' : offset/align can only be used on a uniform or buffer
 ERROR: 0:37: 'offset' : only applies to block members, not blocks \r
 ERROR: 0:38: 'layout' : offset/align can only be used on a uniform or buffer \r
 ERROR: 0:38: 'offset' : only applies to block members, not blocks \r
+ERROR: 0:39: 'out' : cannot declare an output block in a fragment shader \r
 ERROR: 0:39: 'layout' : offset/align can only be used on a uniform or buffer \r
 ERROR: 0:39: 'offset' : only applies to block members, not blocks \r
 ERROR: 0:42: 'offset/align' : can only be used with std140 or std430 layout packing \r
 ERROR: 0:43: 'offset/align' : can only be used with std140 or std430 layout packing \r
 ERROR: 0:43: 'layout' : offset/align can only be used on a uniform or buffer \r
+ERROR: 0:44: 'out' : cannot declare an output block in a fragment shader \r
 ERROR: 0:44: 'offset/align' : can only be used with std140 or std430 layout packing \r
 ERROR: 0:44: 'layout' : offset/align can only be used on a uniform or buffer \r
 ERROR: 0:46: 'offset' : cannot specify on a variable declaration \r
@@ -45,7 +47,7 @@ ERROR: 0:85: 'offset' : must be a multiple of the member's alignment
 ERROR: 0:103: 'align' : must be a power of 2 \r
 ERROR: 0:102: 'offset' : cannot lie in previous members \r
 ERROR: 0:104: 'offset' : must be a multiple of the member's alignment \r
-ERROR: 45 compilation errors.  No code generated.\r
+ERROR: 47 compilation errors.  No code generated.\r
 \r
 \r
 Shader version: 440\r
index 5bf7670..12814f2 100644 (file)
@@ -18,7 +18,7 @@ ERROR: 0:54: 'component' : type overflows the available 4 components
 ERROR: 0:55: 'component' : type overflows the available 4 components \r
 ERROR: 0:57: 'component' : cannot apply to a matrix, structure, or block \r
 ERROR: 0:58: 'component' : cannot apply to a matrix, structure, or block \r
-ERROR: 0:61: 'location' : cannot declare a default, use a full declaration \r
+ERROR: 0:61: 'location/component/index' : cannot declare a default, use a full declaration \r
 ERROR: 0:81: 'xfb layout qualifier' : can only be used on an output \r
 ERROR: 0:87: 'xfb_offset' : cannot declare a default, use a full declaration \r
 ERROR: 0:97: 'xfb_buffer' : member cannot contradict block (or what block inherited from global) \r
index 7e0b41d..6dfa4b8 100644 (file)
@@ -14,8 +14,6 @@ ERROR: 0:99: 'local_size_x' : there is no such layout identifier for this stage
 ERROR: 0:99: 'local_size_y' : there is no such layout identifier for this stage taking an assigned value \r
 ERROR: 0:100: 'local_size_x' : there is no such layout identifier for this stage taking an assigned value \r
 ERROR: 0:102: 'color' : redefinition \r
-ERROR: 0:103: 'index' : there is no such layout identifier for this stage taking an assigned value \r
-ERROR: 0:104: 'location' : overlapping use of location 3\r
 ERROR: 0:112: 'redeclaration' : all redeclarations must use the same depth layout on gl_FragDepth\r
 ERROR: 0:118: 'redeclaration' : all redeclarations must use the same depth layout on gl_FragDepth\r
 ERROR: 0:121: 'redeclaration' : all redeclarations must use the same depth layout on gl_FragDepth\r
@@ -43,7 +41,7 @@ ERROR: 0:226: 'in' : not allowed in nested scope
 ERROR: 0:227: 'in' : not allowed in nested scope \r
 ERROR: 0:228: 'in' : not allowed in nested scope \r
 ERROR: 0:232: 'out' : not allowed in nested scope \r
-ERROR: 43 compilation errors.  No code generated.\r
+ERROR: 41 compilation errors.  No code generated.\r
 \r
 \r
 Shader version: 430\r
@@ -289,7 +287,7 @@ ERROR: node is still EOpNull!
 0:?     'Materiala' (in block{in 4-component vector of float Color, in 2-component vector of float TexCoord})\r
 0:?     'gl_FragCoord' (gl_FragCoord 4-component vector of float)\r
 0:?     'gl_FragCoord' (gl_FragCoord 4-component vector of float)\r
-0:?     'factor' (layout(location=3 ) out 4-component vector of float)\r
+0:?     'factor' (layout(location=3 index=1 ) out 4-component vector of float)\r
 0:?     'colors' (layout(location=2 ) out 3-element array of 4-component vector of float)\r
 0:?     'gl_FragDepth' (gl_FragDepth float)\r
 0:?     'gl_FragDepth' (gl_FragDepth float)\r
@@ -543,7 +541,7 @@ ERROR: node is still EOpNull!
 0:?     'Materiala' (in block{in 4-component vector of float Color, in 2-component vector of float TexCoord})\r
 0:?     'gl_FragCoord' (gl_FragCoord 4-component vector of float)\r
 0:?     'gl_FragCoord' (gl_FragCoord 4-component vector of float)\r
-0:?     'factor' (layout(location=3 ) out 4-component vector of float)\r
+0:?     'factor' (layout(location=3 index=1 ) out 4-component vector of float)\r
 0:?     'colors' (layout(location=2 ) out 3-element array of 4-component vector of float)\r
 0:?     'gl_FragDepth' (gl_FragDepth float)\r
 0:?     'gl_FragDepth' (gl_FragDepth float)\r
index 6d03f46..9be6445 100644 (file)
--- a/Todo.txt
+++ b/Todo.txt
@@ -206,7 +206,7 @@ Shader Functionality to Implement/Finish
       + Add built-in functions to pack/unpack 16 bit floating-point numbers (ARB_shading_language_pack2f).
         + packHalf2x16 and unpackHalf2x16
         + packSnorm2x16and unpackSnorm2x16
-      - Add gl_FragDepth layout qualifiers to communicate what kind of changes will be made to gl_FragDepth (GL_AMD_conservative depth).
+      + Add gl_FragDepth layout qualifiers to communicate what kind of changes will be made to gl_FragDepth (GL_AMD_conservative depth).
       + Add C-style curly brace initializer lists syntax for initializers. Full initialization of aggregates is required when these are used.
       + Allow .length() to be applied to vectors and matrices, returning the number of components or columns.
       + Clarify that .length() returns an int type and can be used as a constant integer expression.
index 6efc3f1..4ac3a02 100644 (file)
@@ -483,6 +483,8 @@ public:
         layoutLocation = layoutLocationEnd;
         layoutComponent = layoutComponentEnd;
         layoutBinding = layoutBindingEnd;
+        layoutIndex = layoutIndexEnd;
+
         layoutStream = layoutStreamEnd;
 
         layoutXfbBuffer = layoutXfbBufferEnd;
@@ -494,7 +496,7 @@ public:
     bool hasLayout() const
     {
         return hasUniformLayout() || 
-               hasLocation() ||
+               hasAnyLocation() ||
                hasBinding() ||
                hasStream() ||
                hasXfb() ||
@@ -514,6 +516,9 @@ public:
                  unsigned int layoutBinding          : 8;
     static const unsigned int layoutBindingEnd =    0xFF;
 
+                 unsigned int layoutIndex           :  8;
+    static const unsigned int layoutIndexEnd =      0xFF;
+
                  unsigned int layoutStream           : 8;
     static const unsigned int layoutStreamEnd =     0xFF;
 
@@ -552,15 +557,24 @@ public:
     {
         return layoutAlign != -1;
     }
+    bool hasAnyLocation() const
+    {
+        return hasLocation() ||
+               hasComponent() ||
+               hasIndex();
+    }
     bool hasLocation() const
     {
-        return layoutLocation  != layoutLocationEnd ||
-               layoutComponent != layoutComponentEnd;
+        return layoutLocation  != layoutLocationEnd;
     }
     bool hasComponent() const
     {
         return layoutComponent != layoutComponentEnd;
     }
+    bool hasIndex() const
+    {
+        return layoutIndex != layoutIndexEnd;
+    }
     bool hasBinding() const
     {
         return layoutBinding != layoutBindingEnd;
@@ -1167,10 +1181,12 @@ public:
             noXfbBuffer.layoutXfbBuffer = TQualifier::layoutXfbBufferEnd;
             if (noXfbBuffer.hasLayout()) {
                 p += snprintf(p, end - p, "layout(");
-                if (qualifier.hasLocation()) {
+                if (qualifier.hasAnyLocation()) {
                     p += snprintf(p, end - p, "location=%d ", qualifier.layoutLocation);
-                    if (qualifier.layoutComponent != qualifier.layoutComponentEnd)
+                    if (qualifier.hasComponent())
                         p += snprintf(p, end - p, "component=%d ", qualifier.layoutComponent);
+                    if (qualifier.hasIndex())
+                        p += snprintf(p, end - p, "index=%d ", qualifier.layoutIndex);
                 }
                 if (qualifier.hasBinding())
                     p += snprintf(p, end - p, "binding=%d ", qualifier.layoutBinding);
index b4393de..9abd958 100644 (file)
@@ -3266,6 +3266,13 @@ void TParseContext::setLayoutQualifier(TSourceLoc loc, TPublicType& publicType,
         break;
 
     case EShLangFragment:
+        if (id == "index") {
+            requireProfile(loc, ECompatibilityProfile | ECoreProfile, "index layout qualifier on fragment output");
+            const char* exts[2] = { GL_ARB_separate_shader_objects, GL_ARB_explicit_attrib_location };
+            profileRequires(loc, ECompatibilityProfile | ECoreProfile, 330, 2, exts, "index layout qualifier on fragment output");
+            publicType.qualifier.layoutIndex = value;
+            return;
+        }
         break;
 
     case EShLangCompute:
@@ -3325,11 +3332,13 @@ void TParseContext::mergeObjectLayoutQualifiers(TSourceLoc loc, TQualifier& dst,
         dst.layoutAlign = src.layoutAlign;
 
     if (! inheritOnly) {
-        if (src.layoutLocation != TQualifier::layoutLocationEnd)
+        if (src.hasLocation())
             dst.layoutLocation = src.layoutLocation;
-        if (src.layoutComponent != TQualifier::layoutComponentEnd)
+        if (src.hasComponent())
             dst.layoutComponent = src.layoutComponent;
-        
+        if (src.hasIndex())
+            dst.layoutIndex = src.layoutIndex;
+
         if (src.hasOffset())
             dst.layoutOffset = src.layoutOffset;
 
@@ -3354,7 +3363,7 @@ void TParseContext::layoutObjectCheck(TSourceLoc loc, const TSymbol& symbol)
 
     // now, any remaining error checking based on the object itself
 
-    if (qualifier.hasLocation()) {
+    if (qualifier.hasAnyLocation()) {
         switch (qualifier.storage) {
         case EvqUniform:
         case EvqBuffer:
@@ -3405,8 +3414,14 @@ void TParseContext::layoutTypeCheck(TSourceLoc loc, const TType& type)
 
     // now, error checking combining type and qualifier
 
-    if (qualifier.hasLocation()) {
-        if (qualifier.layoutComponent != TQualifier::layoutComponentEnd) {
+    if (qualifier.hasAnyLocation()) {
+        if (qualifier.hasLocation()) {
+            if (qualifier.storage == EvqVaryingOut && language == EShLangFragment) {
+                if (qualifier.layoutLocation >= (unsigned int)resources.maxDrawBuffers)
+                    error(loc, "too large for fragment output", "location", "");
+            }
+        }
+        if (qualifier.hasComponent()) {
             // "It is a compile-time error if this sequence of components gets larger than 3."
             if (qualifier.layoutComponent + type.getVectorSize() > 4)
                 error(loc, "type overflows the available 4 components", "component", "");
@@ -3416,11 +3431,6 @@ void TParseContext::layoutTypeCheck(TSourceLoc loc, const TType& type)
                 error(loc, "cannot apply to a matrix, structure, or block", "component", "");
         }
 
-        if (qualifier.storage == EvqVaryingOut && language == EShLangFragment) {
-            if (qualifier.layoutLocation >= (unsigned int)resources.maxDrawBuffers)
-                error(loc, "too large for fragment output", "location", "");
-        }
-
         switch (qualifier.storage) {
         case EvqVaryingIn:
         case EvqVaryingOut:
@@ -3514,10 +3524,10 @@ void TParseContext::layoutQualifierCheck(TSourceLoc loc, const TQualifier& quali
         error(loc, "cannot apply layout qualifiers to a shared variable", "shared", "");
 
     // "It is a compile-time error to use *component* without also specifying the location qualifier (order does not matter)."
-    if (qualifier.layoutComponent != TQualifier::layoutComponentEnd && qualifier.layoutLocation == TQualifier::layoutLocationEnd)
+    if (qualifier.hasComponent() && ! qualifier.hasLocation())
         error(loc, "must specify 'location' to use 'component'", "component", "");
 
-    if (qualifier.hasLocation()) {
+    if (qualifier.hasAnyLocation()) {
 
         // "As with input layout qualifiers, all shaders except compute shaders 
         // allow *location* layout qualifiers on output variable declarations, 
@@ -3570,6 +3580,12 @@ void TParseContext::layoutQualifierCheck(TSourceLoc loc, const TQualifier& quali
         default:
             break;
         }
+        if (qualifier.hasIndex()) {
+            if (qualifier.storage != EvqVaryingOut)
+                error(loc, "can only be used on an output", "index", "");
+            if (! qualifier.hasLocation())
+                error(loc, "can only be used with an explicit location", "index", "");
+        }
     }
 
     if (qualifier.hasBinding()) {
@@ -4240,10 +4256,14 @@ void TParseContext::declareBlock(TSourceLoc loc, TTypeList& typeList, const TStr
     case EvqVaryingIn:
         requireProfile(loc, ~EEsProfile, "input block");
         profileRequires(loc, ~EEsProfile, 150, GL_ARB_separate_shader_objects, "input block");
+        if (language == EShLangVertex)
+            error(loc, "cannot declare an input block in a vertex shader", "in", "");
         break;
     case EvqVaryingOut:
         requireProfile(loc, ~EEsProfile, "output block");
         profileRequires(loc, ~EEsProfile, 150, GL_ARB_separate_shader_objects, "output block");
+        if (language == EShLangFragment)
+            error(loc, "cannot declare an output block in a fragment shader", "out", "");
         break;
     default:
         error(loc, "only uniform, buffer, in, or out blocks are supported", blockName->c_str(), "");
@@ -4455,13 +4475,16 @@ void TParseContext::fixBlockLocations(TSourceLoc loc, TQualifier& qualifier, TTy
         if (memberWithLocation) {
             // remove any block-level location and make it per *every* member
             int nextLocation;  // by the rule above, initial value is not relevant
-            if (qualifier.hasLocation()) {
+            if (qualifier.hasAnyLocation()) {
                 nextLocation = qualifier.layoutLocation;
                 qualifier.layoutLocation = TQualifier::layoutLocationEnd;
-                if (qualifier.layoutComponent != TQualifier::layoutComponentEnd) {
+                if (qualifier.hasComponent()) {
                     // "It is a compile-time error to apply the *component* qualifier to a ... block"
                     error(loc, "cannot apply to a block", "component", "");
                 }
+                if (qualifier.hasIndex()) {
+                    error(loc, "cannot apply to a block", "index", "");
+                }
             }
             for (unsigned int member = 0; member < typeList.size(); ++member) {
                 TQualifier& memberQualifier = typeList[member].type->getQualifier();
@@ -4781,8 +4804,8 @@ void TParseContext::updateStandaloneQualifierDefaults(TSourceLoc loc, const TPub
 
     if (qualifier.hasBinding())
         error(loc, "cannot declare a default, include a type or full declaration", "binding", "");
-    if (qualifier.hasLocation())
-        error(loc, "cannot declare a default, use a full declaration", "location", "");
+    if (qualifier.hasAnyLocation())
+        error(loc, "cannot declare a default, use a full declaration", "location/component/index", "");
     if (qualifier.hasXfbOffset())
         error(loc, "cannot declare a default, use a full declaration", "xfb_offset", "");
 }
index 5add18c..cf4e750 100644 (file)
@@ -165,7 +165,7 @@ void TParseContext::initializeExtensionBehavior()
     extensionBehavior[GL_ARB_enhanced_layouts]             = EBhDisable;
     extensionBehavior[GL_ARB_texture_cube_map_array]       = EBhDisable;
     extensionBehavior[GL_ARB_shader_texture_lod]           = EBhDisable;
-    extensionBehavior[GL_ARB_explicit_attrib_location]     = EBhDisablePartial; // "index" for fragment outputs is missing
+    extensionBehavior[GL_ARB_explicit_attrib_location]     = EBhDisable;
     extensionBehavior[GL_ARB_shader_image_load_store]      = EBhDisable;
     extensionBehavior[GL_ARB_shader_atomic_counters]       = EBhDisable;
     extensionBehavior[GL_ARB_derivative_control]           = EBhDisable;
index 8efe224..d183a65 100644 (file)
@@ -313,13 +313,15 @@ void TIntermediate::mergeErrorCheck(TInfoSink& infoSink, const TIntermSymbol& sy
     }\r
 \r
     // Layouts... \r
-    // TODO: 4.4 enhanced layouts: Generalize to include offset/align: currrent spec \r
+    // TODO: 4.4 enhanced layouts: Generalize to include offset/align: current spec \r
     //       requires separate user-supplied offset from actual computed offset, but \r
     //       current implementation only has one offset.\r
-    if (symbol.getQualifier().layoutMatrix   != unitSymbol.getQualifier().layoutMatrix ||\r
-        symbol.getQualifier().layoutPacking  != unitSymbol.getQualifier().layoutPacking ||\r
-        symbol.getQualifier().layoutLocation != unitSymbol.getQualifier().layoutLocation ||\r
-        symbol.getQualifier().layoutBinding  != unitSymbol.getQualifier().layoutBinding) {\r
+    if (symbol.getQualifier().layoutMatrix    != unitSymbol.getQualifier().layoutMatrix ||\r
+        symbol.getQualifier().layoutPacking   != unitSymbol.getQualifier().layoutPacking ||\r
+        symbol.getQualifier().layoutLocation  != unitSymbol.getQualifier().layoutLocation ||\r
+        symbol.getQualifier().layoutComponent != unitSymbol.getQualifier().layoutComponent ||\r
+        symbol.getQualifier().layoutIndex     != unitSymbol.getQualifier().layoutIndex ||\r
+        symbol.getQualifier().layoutBinding   != unitSymbol.getQualifier().layoutBinding) {\r
         error(infoSink, "Layout qualification must match:");\r
         writeTypeComparison = true;\r
     }\r
@@ -547,7 +549,7 @@ void TIntermediate::inOutLocationCheck(TInfoSink& infoSink)
         if (language == EShLangFragment) {\r
             if (qualifier.storage == EvqVaryingOut) {\r
                 ++numFragOut;\r
-                if (qualifier.hasLocation())\r
+                if (qualifier.hasAnyLocation())\r
                     fragOutHasLocation = true;\r
                 else\r
                     fragOutWithNoLocation = true;\r
@@ -634,11 +636,11 @@ int TIntermediate::addUsedLocation(const TQualifier& qualifier, const TType& typ
 \r
     TRange locationRange(qualifier.layoutLocation, qualifier.layoutLocation + size - 1);\r
     TRange componentRange(0, 3);\r
-    if (qualifier.layoutComponent != TQualifier::layoutComponentEnd) {\r
+    if (qualifier.hasComponent()) {\r
         componentRange.start = qualifier.layoutComponent;\r
         componentRange.last = componentRange.start + type.getVectorSize() - 1;\r
     }\r
-    TIoRange range(locationRange, componentRange, type.getBasicType());\r
+    TIoRange range(locationRange, componentRange, type.getBasicType(), qualifier.hasIndex() ? qualifier.layoutIndex : 0);\r
 \r
     // check for collisions, except for vertex inputs on desktop\r
     if (! (profile != EEsProfile && language == EShLangVertex && qualifier.isPipeInput())) {\r
index 8fdc0e8..d762efe 100644 (file)
@@ -77,18 +77,20 @@ struct TRange {
     int last;
 };
 
-// A *location* range is a 2-D rectangle; the set of (location, component) pairs all lying
-// both within the location range and the component range.  Locations don't alias unless
-// both dimensions of their range overlap.
+// An IO range is a 3-D rectangle; the set of (location, component, index) triples all lying
+// within the same location range, component range, and index value.  Locations don't alias unless
+// all other dimensions of their range overlap.
 struct TIoRange {
-    TIoRange(TRange location, TRange component, TBasicType basicType) : location(location), component(component), basicType(basicType) { }
+    TIoRange(TRange location, TRange component, TBasicType basicType, int index)
+        : location(location), component(component), basicType(basicType), index(index) { }
     bool overlap(const TIoRange& rhs) const
     {
-        return location.overlap(rhs.location) && component.overlap(rhs.component);
+        return location.overlap(rhs.location) && component.overlap(rhs.component) && index == rhs.index;
     }
     TRange location;
     TRange component;
     TBasicType basicType;
+    int index;
 };
 
 // Things that need to be tracked per xfb buffer.