Add memory qualifiers (coherent volatile restrict) to imageSize(), imageLoad(), image...
authorJohn Kessenich <cepheus@frii.com>
Mon, 17 Nov 2014 16:45:10 +0000 (16:45 +0000)
committerJohn Kessenich <cepheus@frii.com>
Mon, 17 Nov 2014 16:45:10 +0000 (16:45 +0000)
Several bugs are related to this, and this is a slightly speculative fix, bit it is certainly wrong to either do it the way it was or to reflect the current specifications.

git-svn-id: https://cvs.khronos.org/svn/repos/ogl/trunk/ecosystem/public/sdk/tools/glslang@28968 e7fa87d3-cd2b-0410-9028-fcbf551c1848

Test/310.frag
Test/baseResults/310.frag.out
glslang/MachineIndependent/Initialize.cpp

index 87f6efc..c1ccaaa 100644 (file)
@@ -62,7 +62,11 @@ void foo23()
 \r
 layout(binding=3) uniform sampler2D s1;\r
 layout(binding=3) uniform sampler2D s2; // ERROR: overlapping bindings?  Don't see that in the 310 spec.\r
-layout(binding=2) uniform writeonly image2D i2D;\r
+layout(binding=2) uniform writeonly image2D      i2D;\r
+layout(binding=4) uniform readonly  image3D      i3D;\r
+layout(binding=5) uniform           imageCube    iCube;\r
+layout(binding=6) uniform           image2DArray i2DA;\r
+layout(binding=6) uniform coherent volatile restrict image2D i2Dqualified;\r
 \r
 layout(binding = 1) uniform bb {\r
     int foo;\r
@@ -97,6 +101,10 @@ void foots()
     highp ivec3 v3 = textureSize(isamp2DA, 3);\r
     v2 = textureSize(s2dms);\r
     v2 = imageSize(i2D);\r
+    v3 = imageSize(i3D);\r
+    v2 = imageSize(iCube);\r
+    v3 = imageSize(i2DA);\r
+    v2 = imageSize(i2Dqualified);\r
 }\r
 \r
 out bool bout;          // ERROR\r
index 0d4e70e..8bc8db6 100644 (file)
@@ -17,26 +17,36 @@ ERROR: 0:44: 'texel offset' : value is out of range: [gl_MinProgramTexelOffset,
 ERROR: 0:44: 'texel offset' : value is out of range: [gl_MinProgramTexelOffset, gl_MaxProgramTexelOffset]\r
 ERROR: 0:45: 'texel offset' : value is out of range: [gl_MinProgramTexelOffset, gl_MaxProgramTexelOffset]\r
 ERROR: 0:45: 'texel offset' : value is out of range: [gl_MinProgramTexelOffset, gl_MaxProgramTexelOffset]\r
-ERROR: 0:69: 'binding' : requires block, or sampler/image, or atomic-counter type \r
-ERROR: 0:73: 'location' : location is too large \r
-ERROR: 0:77: 'location' : too large for fragment output \r
-ERROR: 0:78: 'location' : too large for fragment output \r
-ERROR: 0:78: 'location' : overlapping use of location 40\r
-ERROR: 0:79: 'non-literal layout-id value' : not supported with this profile: es\r
-ERROR: 0:79: 'layout-id value' : cannot be negative \r
-ERROR: 0:99: 'writeonly' : argument cannot drop memory qualifier when passed to formal parameter \r
-ERROR: 0:102: 'out' : cannot be bool \r
-ERROR: 0:103: 'image2D' : sampler/image types can only be used in uniform variables or function parameters: imageOut\r
-ERROR: 0:103: '' : image variables not declared 'writeonly' must have a format layout qualifier \r
-ERROR: 0:104: 'out' : cannot be a matrix \r
-ERROR: 0:106: 'in' : cannot be bool \r
-ERROR: 0:107: 'sampler2D' : sampler/image types can only be used in uniform variables or function parameters: ino\r
-ERROR: 0:109: 'fragment-shader array-of-array input' : not supported with this profile: es\r
-ERROR: 0:112: 'fragment-shader array-of-struct input' : not supported with this profile: es\r
-ERROR: 0:113: 'fragment-shader array-of-struct input' : not supported with this profile: es\r
-ERROR: 0:115: 'fragment-shader struct input containing an array' : not supported with this profile: es\r
-ERROR: 0:117: 'fragment-shader struct input containing structure' : not supported with this profile: es\r
-ERROR: 36 compilation errors.  No code generated.\r
+ERROR: 0:66: 'sampler/image' : type requires declaration of default precision qualifier \r
+ERROR: 0:66: '' : image variables not declared 'writeonly' must have a format layout qualifier \r
+ERROR: 0:67: '' : image variables not declared 'writeonly' must have a format layout qualifier \r
+ERROR: 0:68: 'sampler/image' : type requires declaration of default precision qualifier \r
+ERROR: 0:68: '' : image variables not declared 'writeonly' must have a format layout qualifier \r
+ERROR: 0:69: '' : image variables not declared 'writeonly' must have a format layout qualifier \r
+ERROR: 0:73: 'binding' : requires block, or sampler/image, or atomic-counter type \r
+ERROR: 0:77: 'location' : location is too large \r
+ERROR: 0:81: 'location' : too large for fragment output \r
+ERROR: 0:82: 'location' : too large for fragment output \r
+ERROR: 0:82: 'location' : overlapping use of location 40\r
+ERROR: 0:83: 'non-literal layout-id value' : not supported with this profile: es\r
+ERROR: 0:83: 'layout-id value' : cannot be negative \r
+ERROR: 0:103: 'writeonly' : argument cannot drop memory qualifier when passed to formal parameter \r
+ERROR: 0:104: 'readonly' : argument cannot drop memory qualifier when passed to formal parameter \r
+ERROR: 0:107: 'volatile' : argument cannot drop memory qualifier when passed to formal parameter \r
+ERROR: 0:107: 'coherent' : argument cannot drop memory qualifier when passed to formal parameter \r
+ERROR: 0:107: 'restrict' : argument cannot drop memory qualifier when passed to formal parameter \r
+ERROR: 0:110: 'out' : cannot be bool \r
+ERROR: 0:111: 'image2D' : sampler/image types can only be used in uniform variables or function parameters: imageOut\r
+ERROR: 0:111: '' : image variables not declared 'writeonly' must have a format layout qualifier \r
+ERROR: 0:112: 'out' : cannot be a matrix \r
+ERROR: 0:114: 'in' : cannot be bool \r
+ERROR: 0:115: 'sampler2D' : sampler/image types can only be used in uniform variables or function parameters: ino\r
+ERROR: 0:117: 'fragment-shader array-of-array input' : not supported with this profile: es\r
+ERROR: 0:120: 'fragment-shader array-of-struct input' : not supported with this profile: es\r
+ERROR: 0:121: 'fragment-shader array-of-struct input' : not supported with this profile: es\r
+ERROR: 0:123: 'fragment-shader struct input containing an array' : not supported with this profile: es\r
+ERROR: 0:125: 'fragment-shader struct input containing structure' : not supported with this profile: es\r
+ERROR: 46 compilation errors.  No code generated.\r
 \r
 \r
 Shader version: 310\r
@@ -213,31 +223,47 @@ ERROR: node is still EOpNull!
 0:60              'i' (uniform mediump int)\r
 0:60            Construct bvec4 (4-component vector of bool)\r
 0:60              'b' (bool)\r
-0:94  Function Definition: foots( (void)\r
-0:94    Function Parameters: \r
-0:96    Sequence\r
-0:96      Sequence\r
-0:96        move second child to first child (highp 2-component vector of int)\r
-0:96          'v2' (highp 2-component vector of int)\r
-0:96          Function Call: textureSize(s21;i1; (highp 2-component vector of int)\r
-0:96            's1' (layout(binding=3 ) uniform highp sampler2D)\r
-0:96            Constant:\r
-0:96              2 (const int)\r
-0:97      Sequence\r
-0:97        move second child to first child (highp 3-component vector of int)\r
-0:97          'v3' (highp 3-component vector of int)\r
-0:97          Function Call: textureSize(isA21;i1; (highp 3-component vector of int)\r
-0:97            'isamp2DA' (uniform highp isampler2DArray)\r
-0:97            Constant:\r
-0:97              3 (const int)\r
-0:98      move second child to first child (highp 2-component vector of int)\r
-0:98        'v2' (highp 2-component vector of int)\r
-0:98        Function Call: textureSize(s21; (highp 2-component vector of int)\r
-0:98          's2dms' (uniform highp sampler2DMS)\r
-0:99      move second child to first child (highp 2-component vector of int)\r
-0:99        'v2' (highp 2-component vector of int)\r
-0:99        Function Call: imageSize(I21; (highp 2-component vector of int)\r
-0:99          'i2D' (layout(binding=2 ) writeonly uniform highp image2D)\r
+0:98  Function Definition: foots( (void)\r
+0:98    Function Parameters: \r
+0:100    Sequence\r
+0:100      Sequence\r
+0:100        move second child to first child (highp 2-component vector of int)\r
+0:100          'v2' (highp 2-component vector of int)\r
+0:100          Function Call: textureSize(s21;i1; (highp 2-component vector of int)\r
+0:100            's1' (layout(binding=3 ) uniform highp sampler2D)\r
+0:100            Constant:\r
+0:100              2 (const int)\r
+0:101      Sequence\r
+0:101        move second child to first child (highp 3-component vector of int)\r
+0:101          'v3' (highp 3-component vector of int)\r
+0:101          Function Call: textureSize(isA21;i1; (highp 3-component vector of int)\r
+0:101            'isamp2DA' (uniform highp isampler2DArray)\r
+0:101            Constant:\r
+0:101              3 (const int)\r
+0:102      move second child to first child (highp 2-component vector of int)\r
+0:102        'v2' (highp 2-component vector of int)\r
+0:102        Function Call: textureSize(s21; (highp 2-component vector of int)\r
+0:102          's2dms' (uniform highp sampler2DMS)\r
+0:103      move second child to first child (highp 2-component vector of int)\r
+0:103        'v2' (highp 2-component vector of int)\r
+0:103        Function Call: imageSize(I21; (highp 2-component vector of int)\r
+0:103          'i2D' (layout(binding=2 ) writeonly uniform highp image2D)\r
+0:104      move second child to first child (highp 3-component vector of int)\r
+0:104        'v3' (highp 3-component vector of int)\r
+0:104        Function Call: imageSize(I31; (highp 3-component vector of int)\r
+0:104          'i3D' (layout(binding=4 ) readonly uniform mediump image3D)\r
+0:105      move second child to first child (highp 2-component vector of int)\r
+0:105        'v2' (highp 2-component vector of int)\r
+0:105        Function Call: imageSize(IC1; (highp 2-component vector of int)\r
+0:105          'iCube' (layout(binding=5 ) uniform lowp imageCube)\r
+0:106      move second child to first child (highp 3-component vector of int)\r
+0:106        'v3' (highp 3-component vector of int)\r
+0:106        Function Call: imageSize(IA21; (highp 3-component vector of int)\r
+0:106          'i2DA' (layout(binding=6 ) uniform mediump image2DArray)\r
+0:107      move second child to first child (highp 2-component vector of int)\r
+0:107        'v2' (highp 2-component vector of int)\r
+0:107        Function Call: imageSize(I21; (highp 2-component vector of int)\r
+0:107          'i2Dqualified' (layout(binding=6 ) coherent volatile restrict uniform highp image2D)\r
 0:?   Linker Objects\r
 0:?     'gl_FragCoord' (smooth in mediump 4-component vector of float)\r
 0:?     'v3' (layout(location=2 ) smooth in mediump 3-component vector of float)\r
@@ -252,6 +278,10 @@ ERROR: node is still EOpNull!
 0:?     's1' (layout(binding=3 ) uniform highp sampler2D)\r
 0:?     's2' (layout(binding=3 ) uniform highp sampler2D)\r
 0:?     'i2D' (layout(binding=2 ) writeonly uniform highp image2D)\r
+0:?     'i3D' (layout(binding=4 ) readonly uniform mediump image3D)\r
+0:?     'iCube' (layout(binding=5 ) uniform lowp imageCube)\r
+0:?     'i2DA' (layout(binding=6 ) uniform mediump image2DArray)\r
+0:?     'i2Dqualified' (layout(binding=6 ) coherent volatile restrict uniform highp image2D)\r
 0:?     'bbi' (layout(binding=1 column_major shared ) uniform block{layout(column_major shared ) uniform mediump int foo, layout(binding=2 column_major shared ) uniform mediump float f})\r
 0:?     'centroidIn' (centroid smooth in mediump 4-component vector of float)\r
 0:?     'bigl' (uniform mediump 4-component vector of float)\r
@@ -455,31 +485,47 @@ ERROR: node is still EOpNull!
 0:60              'i' (uniform mediump int)\r
 0:60            Construct bvec4 (4-component vector of bool)\r
 0:60              'b' (bool)\r
-0:94  Function Definition: foots( (void)\r
-0:94    Function Parameters: \r
-0:96    Sequence\r
-0:96      Sequence\r
-0:96        move second child to first child (highp 2-component vector of int)\r
-0:96          'v2' (highp 2-component vector of int)\r
-0:96          Function Call: textureSize(s21;i1; (highp 2-component vector of int)\r
-0:96            's1' (layout(binding=3 ) uniform highp sampler2D)\r
-0:96            Constant:\r
-0:96              2 (const int)\r
-0:97      Sequence\r
-0:97        move second child to first child (highp 3-component vector of int)\r
-0:97          'v3' (highp 3-component vector of int)\r
-0:97          Function Call: textureSize(isA21;i1; (highp 3-component vector of int)\r
-0:97            'isamp2DA' (uniform highp isampler2DArray)\r
-0:97            Constant:\r
-0:97              3 (const int)\r
-0:98      move second child to first child (highp 2-component vector of int)\r
-0:98        'v2' (highp 2-component vector of int)\r
-0:98        Function Call: textureSize(s21; (highp 2-component vector of int)\r
-0:98          's2dms' (uniform highp sampler2DMS)\r
-0:99      move second child to first child (highp 2-component vector of int)\r
-0:99        'v2' (highp 2-component vector of int)\r
-0:99        Function Call: imageSize(I21; (highp 2-component vector of int)\r
-0:99          'i2D' (layout(binding=2 ) writeonly uniform highp image2D)\r
+0:98  Function Definition: foots( (void)\r
+0:98    Function Parameters: \r
+0:100    Sequence\r
+0:100      Sequence\r
+0:100        move second child to first child (highp 2-component vector of int)\r
+0:100          'v2' (highp 2-component vector of int)\r
+0:100          Function Call: textureSize(s21;i1; (highp 2-component vector of int)\r
+0:100            's1' (layout(binding=3 ) uniform highp sampler2D)\r
+0:100            Constant:\r
+0:100              2 (const int)\r
+0:101      Sequence\r
+0:101        move second child to first child (highp 3-component vector of int)\r
+0:101          'v3' (highp 3-component vector of int)\r
+0:101          Function Call: textureSize(isA21;i1; (highp 3-component vector of int)\r
+0:101            'isamp2DA' (uniform highp isampler2DArray)\r
+0:101            Constant:\r
+0:101              3 (const int)\r
+0:102      move second child to first child (highp 2-component vector of int)\r
+0:102        'v2' (highp 2-component vector of int)\r
+0:102        Function Call: textureSize(s21; (highp 2-component vector of int)\r
+0:102          's2dms' (uniform highp sampler2DMS)\r
+0:103      move second child to first child (highp 2-component vector of int)\r
+0:103        'v2' (highp 2-component vector of int)\r
+0:103        Function Call: imageSize(I21; (highp 2-component vector of int)\r
+0:103          'i2D' (layout(binding=2 ) writeonly uniform highp image2D)\r
+0:104      move second child to first child (highp 3-component vector of int)\r
+0:104        'v3' (highp 3-component vector of int)\r
+0:104        Function Call: imageSize(I31; (highp 3-component vector of int)\r
+0:104          'i3D' (layout(binding=4 ) readonly uniform mediump image3D)\r
+0:105      move second child to first child (highp 2-component vector of int)\r
+0:105        'v2' (highp 2-component vector of int)\r
+0:105        Function Call: imageSize(IC1; (highp 2-component vector of int)\r
+0:105          'iCube' (layout(binding=5 ) uniform lowp imageCube)\r
+0:106      move second child to first child (highp 3-component vector of int)\r
+0:106        'v3' (highp 3-component vector of int)\r
+0:106        Function Call: imageSize(IA21; (highp 3-component vector of int)\r
+0:106          'i2DA' (layout(binding=6 ) uniform mediump image2DArray)\r
+0:107      move second child to first child (highp 2-component vector of int)\r
+0:107        'v2' (highp 2-component vector of int)\r
+0:107        Function Call: imageSize(I21; (highp 2-component vector of int)\r
+0:107          'i2Dqualified' (layout(binding=6 ) coherent volatile restrict uniform highp image2D)\r
 0:?   Linker Objects\r
 0:?     'gl_FragCoord' (smooth in mediump 4-component vector of float)\r
 0:?     'v3' (layout(location=2 ) smooth in mediump 3-component vector of float)\r
@@ -494,6 +540,10 @@ ERROR: node is still EOpNull!
 0:?     's1' (layout(binding=3 ) uniform highp sampler2D)\r
 0:?     's2' (layout(binding=3 ) uniform highp sampler2D)\r
 0:?     'i2D' (layout(binding=2 ) writeonly uniform highp image2D)\r
+0:?     'i3D' (layout(binding=4 ) readonly uniform mediump image3D)\r
+0:?     'iCube' (layout(binding=5 ) uniform lowp imageCube)\r
+0:?     'i2DA' (layout(binding=6 ) uniform mediump image2DArray)\r
+0:?     'i2Dqualified' (layout(binding=6 ) coherent volatile restrict uniform highp image2D)\r
 0:?     'bbi' (layout(binding=1 column_major shared ) uniform block{layout(column_major shared ) uniform mediump int foo, layout(binding=2 column_major shared ) uniform mediump float f})\r
 0:?     'centroidIn' (centroid smooth in mediump 4-component vector of float)\r
 0:?     'bigl' (uniform mediump 4-component vector of float)\r
index 07e38b4..eb7de1b 100644 (file)
@@ -418,29 +418,29 @@ void TBuiltIns::initialize(int version, EProfile profile)
     if (profile == EEsProfile && version >= 310 ||
         profile != EEsProfile && version >= 430) {
         commonBuiltins.append(
-            "uint atomicAdd(coherent inout uint, uint);"
-            " int atomicAdd(coherent inout  int,  int);"
+            "uint atomicAdd(coherent volatile restrict inout uint, uint);"
+            " int atomicAdd(coherent volatile restrict inout  int,  int);"
 
-            "uint atomicMin(coherent inout uint, uint);"
-            " int atomicMin(coherent inout  int,  int);"
+            "uint atomicMin(coherent volatile restrict inout uint, uint);"
+            " int atomicMin(coherent volatile restrict inout  int,  int);"
             
-            "uint atomicMax(coherent inout uint, uint);"
-            " int atomicMax(coherent inout  int,  int);"
+            "uint atomicMax(coherent volatile restrict inout uint, uint);"
+            " int atomicMax(coherent volatile restrict inout  int,  int);"
             
-            "uint atomicAnd(coherent inout uint, uint);"
-            " int atomicAnd(coherent inout  int,  int);"
+            "uint atomicAnd(coherent volatile restrict inout uint, uint);"
+            " int atomicAnd(coherent volatile restrict inout  int,  int);"
             
-            "uint atomicOr (coherent inout uint, uint);"
-            " int atomicOr (coherent inout  int,  int);"
+            "uint atomicOr (coherent volatile restrict inout uint, uint);"
+            " int atomicOr (coherent volatile restrict inout  int,  int);"
             
-            "uint atomicXor(coherent inout uint, uint);"
-            " int atomicXor(coherent inout  int,  int);"
+            "uint atomicXor(coherent volatile restrict inout uint, uint);"
+            " int atomicXor(coherent volatile restrict inout  int,  int);"
 
-            "uint atomicExchange(coherent inout uint, uint);"
-            " int atomicExchange(coherent inout  int,  int);"
+            "uint atomicExchange(coherent volatile restrict inout uint, uint);"
+            " int atomicExchange(coherent volatile restrict inout  int,  int);"
 
-            "uint atomicCompSwap(coherent inout uint, uint, uint);"
-            " int atomicCompSwap(coherent inout  int,  int,  int);"
+            "uint atomicCompSwap(coherent volatile restrict inout uint, uint, uint);"
+            " int atomicCompSwap(coherent volatile restrict inout  int,  int,  int);"
 
             "\n");
     }
@@ -1847,7 +1847,7 @@ void TBuiltIns::addQueryFunctions(TSampler sampler, TString& typeName, int versi
         commonBuiltins.append(postfixes[dims]);
     }
     if (sampler.image)
-        commonBuiltins.append(" imageSize(");
+        commonBuiltins.append(" imageSize(readonly writeonly volatile coherent restrict ");
     else
         commonBuiltins.append(" textureSize(");
     commonBuiltins.append(typeName);
@@ -1889,11 +1889,11 @@ void TBuiltIns::addImageFunctions(TSampler sampler, TString& typeName, int versi
         imageParams.append(", int");
 
     commonBuiltins.append(prefixes[sampler.type]);
-    commonBuiltins.append("vec4 imageLoad(readonly ");
+    commonBuiltins.append("vec4 imageLoad(readonly volatile coherent restrict ");
     commonBuiltins.append(imageParams);
     commonBuiltins.append(");\n");
 
-    commonBuiltins.append("void imageStore(writeonly ");
+    commonBuiltins.append("void imageStore(writeonly volatile coherent restrict ");
     commonBuiltins.append(imageParams);
     commonBuiltins.append(", ");
     commonBuiltins.append(prefixes[sampler.type]);
@@ -1906,20 +1906,18 @@ void TBuiltIns::addImageFunctions(TSampler sampler, TString& typeName, int versi
             const int numBuiltins = 7;
 
             static const char* atomicFunc[numBuiltins] = {
-                " imageAtomicAdd(",
-                " imageAtomicMin(",
-                " imageAtomicMax(",
-                " imageAtomicAnd(",
-                " imageAtomicOr(",
-                " imageAtomicXor(",
-                " imageAtomicExchange("
+                " imageAtomicAdd(volatile coherent restrict ",
+                " imageAtomicMin(volatile coherent restrict ",
+                " imageAtomicMax(volatile coherent restrict ",
+                " imageAtomicAnd(volatile coherent restrict ",
+                " imageAtomicOr(volatile coherent restrict ",
+                " imageAtomicXor(volatile coherent restrict ",
+                " imageAtomicExchange(volatile coherent restrict "
             }; 
 
             for (size_t i = 0; i < numBuiltins; ++i) {
                 commonBuiltins.append(dataType);
                 commonBuiltins.append(atomicFunc[i]);
-                if (version >= 450)
-                    commonBuiltins.append("coherent ");
                 commonBuiltins.append(imageParams);
                 commonBuiltins.append(", ");
                 commonBuiltins.append(dataType);
@@ -1927,7 +1925,7 @@ void TBuiltIns::addImageFunctions(TSampler sampler, TString& typeName, int versi
             }
 
             commonBuiltins.append(dataType);
-            commonBuiltins.append(" imageAtomicCompSwap(");
+            commonBuiltins.append(" imageAtomicCompSwap(volatile coherent restrict ");
             commonBuiltins.append(imageParams);
             commonBuiltins.append(", ");
             commonBuiltins.append(dataType);
@@ -1939,7 +1937,7 @@ void TBuiltIns::addImageFunctions(TSampler sampler, TString& typeName, int versi
             // GL_ARB_ES3_1_compatibility
             // TODO: spec issue: are there restrictions on the kind of layout() that can be used?  what about dropping memory qualifiers?
             if (version >= 450) {
-                commonBuiltins.append("float imageAtomicExchange(coherent ");
+                commonBuiltins.append("float imageAtomicExchange(volatile coherent restrict ");
                 commonBuiltins.append(imageParams);
                 commonBuiltins.append(", float);\n");
             }