GLSL: Implement correct semantic checking for run-time sized arrays.
authorJohn Kessenich <cepheus@frii.com>
Mon, 2 Apr 2018 20:52:15 +0000 (14:52 -0600)
committerJohn Kessenich <cepheus@frii.com>
Mon, 2 Apr 2018 20:52:15 +0000 (14:52 -0600)
Test/baseResults/runtimeArray.vert.out [new file with mode: 0755]
Test/runtimeArray.vert [new file with mode: 0644]
glslang/MachineIndependent/ParseHelper.cpp
glslang/MachineIndependent/ParseHelper.h
gtests/AST.FromFile.cpp

diff --git a/Test/baseResults/runtimeArray.vert.out b/Test/baseResults/runtimeArray.vert.out
new file mode 100755 (executable)
index 0000000..65c14f6
--- /dev/null
@@ -0,0 +1,490 @@
+runtimeArray.vert
+ERROR: 0:52: '[' :  array must be redeclared with a size before being indexed with a variable
+ERROR: 0:53: '[' :  array must be redeclared with a size before being indexed with a variable
+ERROR: 0:54: '[' :  array must be redeclared with a size before being indexed with a variable
+ERROR: 0:57: 'length' :  array must be declared with a size before using this method
+ERROR: 0:58: 'length' :  array must be declared with a size before using this method
+ERROR: 0:59: 'length' :  array must be declared with a size before using this method
+ERROR: 0:62: '[' :  array must be redeclared with a size before being indexed with a variable
+ERROR: 0:63: '[' :  array must be redeclared with a size before being indexed with a variable
+ERROR: 0:64: '[' :  array must be redeclared with a size before being indexed with a variable
+ERROR: 0:67: 'length' :  array must be declared with a size before using this method
+ERROR: 0:68: 'length' :  array must be declared with a size before using this method
+ERROR: 0:69: 'length' :  array must be declared with a size before using this method
+ERROR: 0:72: '[' :  array must be redeclared with a size before being indexed with a variable
+ERROR: 0:73: '[' :  array must be redeclared with a size before being indexed with a variable
+ERROR: 0:74: '[' :  array must be redeclared with a size before being indexed with a variable
+ERROR: 0:77: 'length' :  array must be declared with a size before using this method
+ERROR: 0:78: 'length' :  array must be declared with a size before using this method
+ERROR: 0:79: 'length' :  array must be declared with a size before using this method
+ERROR: 18 compilation errors.  No code generated.
+
+
+Shader version: 450
+ERROR: node is still EOpNull!
+0:35  Function Definition: main( ( global void)
+0:35    Function Parameters: 
+0:37    Sequence
+0:37      direct index (layout( column_major shared) temp int)
+0:37        a: direct index for structure (layout( column_major shared) uniform runtime-sized array of int)
+0:37          'ubuf' (layout( column_major shared) uniform block{layout( column_major shared) uniform runtime-sized array of int a, layout( column_major shared) uniform runtime-sized array of float b})
+0:37          Constant:
+0:37            0 (const int)
+0:37        Constant:
+0:37          3 (const int)
+0:38      direct index (layout( column_major shared) temp float)
+0:38        b: direct index for structure (layout( column_major shared) uniform runtime-sized array of float)
+0:38          'ubuf' (layout( column_major shared) uniform block{layout( column_major shared) uniform runtime-sized array of int a, layout( column_major shared) uniform runtime-sized array of float b})
+0:38          Constant:
+0:38            1 (const int)
+0:38        Constant:
+0:38          3 (const int)
+0:39      direct index (layout( column_major shared) temp int)
+0:39        a: direct index for structure (layout( column_major shared) buffer runtime-sized array of int)
+0:39          'buf' (layout( column_major shared) buffer block{layout( column_major shared) buffer runtime-sized array of int a, layout( column_major shared) buffer runtime-sized array of float b})
+0:39          Constant:
+0:39            0 (const int)
+0:39        Constant:
+0:39          3 (const int)
+0:40      direct index (layout( column_major shared) temp float)
+0:40        b: direct index for structure (layout( column_major shared) buffer runtime-sized array of float)
+0:40          'buf' (layout( column_major shared) buffer block{layout( column_major shared) buffer runtime-sized array of int a, layout( column_major shared) buffer runtime-sized array of float b})
+0:40          Constant:
+0:40            1 (const int)
+0:40        Constant:
+0:40          3 (const int)
+0:42      direct index (layout( column_major shared) temp int)
+0:42        a: direct index for structure (layout( column_major shared) uniform runtime-sized array of int)
+0:42          direct index (layout( column_major shared) temp block{layout( column_major shared) uniform runtime-sized array of int a, layout( column_major shared) uniform runtime-sized array of float b})
+0:42            'ubufa' (layout( column_major shared) uniform 4-element array of block{layout( column_major shared) uniform runtime-sized array of int a, layout( column_major shared) uniform runtime-sized array of float b})
+0:42            Constant:
+0:42              3 (const int)
+0:42          Constant:
+0:42            0 (const int)
+0:42        Constant:
+0:42          3 (const int)
+0:43      direct index (layout( column_major shared) temp float)
+0:43        b: direct index for structure (layout( column_major shared) uniform runtime-sized array of float)
+0:43          direct index (layout( column_major shared) temp block{layout( column_major shared) uniform runtime-sized array of int a, layout( column_major shared) uniform runtime-sized array of float b})
+0:43            'ubufa' (layout( column_major shared) uniform 4-element array of block{layout( column_major shared) uniform runtime-sized array of int a, layout( column_major shared) uniform runtime-sized array of float b})
+0:43            Constant:
+0:43              3 (const int)
+0:43          Constant:
+0:43            1 (const int)
+0:43        Constant:
+0:43          3 (const int)
+0:44      direct index (layout( column_major shared) temp int)
+0:44        a: direct index for structure (layout( column_major shared) buffer runtime-sized array of int)
+0:44          direct index (layout( column_major shared) temp block{layout( column_major shared) buffer runtime-sized array of int a, layout( column_major shared) buffer runtime-sized array of float b})
+0:44            'bufa' (layout( column_major shared) buffer 4-element array of block{layout( column_major shared) buffer runtime-sized array of int a, layout( column_major shared) buffer runtime-sized array of float b})
+0:44            Constant:
+0:44              3 (const int)
+0:44          Constant:
+0:44            0 (const int)
+0:44        Constant:
+0:44          3 (const int)
+0:45      direct index (layout( column_major shared) temp float)
+0:45        b: direct index for structure (layout( column_major shared) buffer runtime-sized array of float)
+0:45          direct index (layout( column_major shared) temp block{layout( column_major shared) buffer runtime-sized array of int a, layout( column_major shared) buffer runtime-sized array of float b})
+0:45            'bufa' (layout( column_major shared) buffer 4-element array of block{layout( column_major shared) buffer runtime-sized array of int a, layout( column_major shared) buffer runtime-sized array of float b})
+0:45            Constant:
+0:45              3 (const int)
+0:45          Constant:
+0:45            1 (const int)
+0:45        Constant:
+0:45          3 (const int)
+0:47      direct index (layout( column_major shared) temp int)
+0:47        aua: direct index for structure (layout( column_major shared) uniform runtime-sized array of int)
+0:47          'anon@1' (layout( column_major shared) uniform block{layout( column_major shared) uniform runtime-sized array of int aua, layout( column_major shared) uniform runtime-sized array of float aub})
+0:47          Constant:
+0:47            0 (const uint)
+0:47        Constant:
+0:47          3 (const int)
+0:48      direct index (layout( column_major shared) temp float)
+0:48        aub: direct index for structure (layout( column_major shared) uniform runtime-sized array of float)
+0:48          'anon@1' (layout( column_major shared) uniform block{layout( column_major shared) uniform runtime-sized array of int aua, layout( column_major shared) uniform runtime-sized array of float aub})
+0:48          Constant:
+0:48            1 (const uint)
+0:48        Constant:
+0:48          3 (const int)
+0:49      direct index (layout( column_major shared) temp int)
+0:49        aba: direct index for structure (layout( column_major shared) buffer runtime-sized array of int)
+0:49          'anon@0' (layout( column_major shared) buffer block{layout( column_major shared) buffer runtime-sized array of int aba, layout( column_major shared) buffer runtime-sized array of float abb})
+0:49          Constant:
+0:49            0 (const uint)
+0:49        Constant:
+0:49          3 (const int)
+0:50      direct index (layout( column_major shared) temp float)
+0:50        abb: direct index for structure (layout( column_major shared) buffer runtime-sized array of float)
+0:50          'anon@0' (layout( column_major shared) buffer block{layout( column_major shared) buffer runtime-sized array of int aba, layout( column_major shared) buffer runtime-sized array of float abb})
+0:50          Constant:
+0:50            1 (const uint)
+0:50        Constant:
+0:50          3 (const int)
+0:52      indirect index (layout( column_major shared) temp int)
+0:52        a: direct index for structure (layout( column_major shared) uniform runtime-sized array of int)
+0:52          'ubuf' (layout( column_major shared) uniform block{layout( column_major shared) uniform runtime-sized array of int a, layout( column_major shared) uniform runtime-sized array of float b})
+0:52          Constant:
+0:52            0 (const int)
+0:52        'i' ( global int)
+0:53      indirect index (layout( column_major shared) temp float)
+0:53        b: direct index for structure (layout( column_major shared) uniform runtime-sized array of float)
+0:53          'ubuf' (layout( column_major shared) uniform block{layout( column_major shared) uniform runtime-sized array of int a, layout( column_major shared) uniform runtime-sized array of float b})
+0:53          Constant:
+0:53            1 (const int)
+0:53        'i' ( global int)
+0:54      indirect index (layout( column_major shared) temp int)
+0:54        a: direct index for structure (layout( column_major shared) buffer runtime-sized array of int)
+0:54          'buf' (layout( column_major shared) buffer block{layout( column_major shared) buffer runtime-sized array of int a, layout( column_major shared) buffer runtime-sized array of float b})
+0:54          Constant:
+0:54            0 (const int)
+0:54        'i' ( global int)
+0:55      indirect index (layout( column_major shared) temp float)
+0:55        b: direct index for structure (layout( column_major shared) buffer runtime-sized array of float)
+0:55          'buf' (layout( column_major shared) buffer block{layout( column_major shared) buffer runtime-sized array of int a, layout( column_major shared) buffer runtime-sized array of float b})
+0:55          Constant:
+0:55            1 (const int)
+0:55        'i' ( global int)
+0:57      Constant:
+0:57        1 (const int)
+0:58      Constant:
+0:58        1 (const int)
+0:59      Constant:
+0:59        1 (const int)
+0:60      array length ( temp int)
+0:60        b: direct index for structure (layout( column_major shared) buffer runtime-sized array of float)
+0:60          'buf' (layout( column_major shared) buffer block{layout( column_major shared) buffer runtime-sized array of int a, layout( column_major shared) buffer runtime-sized array of float b})
+0:60          Constant:
+0:60            1 (const int)
+0:62      indirect index (layout( column_major shared) temp int)
+0:62        a: direct index for structure (layout( column_major shared) uniform runtime-sized array of int)
+0:62          direct index (layout( column_major shared) temp block{layout( column_major shared) uniform runtime-sized array of int a, layout( column_major shared) uniform runtime-sized array of float b})
+0:62            'ubufa' (layout( column_major shared) uniform 4-element array of block{layout( column_major shared) uniform runtime-sized array of int a, layout( column_major shared) uniform runtime-sized array of float b})
+0:62            Constant:
+0:62              1 (const int)
+0:62          Constant:
+0:62            0 (const int)
+0:62        'i' ( global int)
+0:63      indirect index (layout( column_major shared) temp float)
+0:63        b: direct index for structure (layout( column_major shared) uniform runtime-sized array of float)
+0:63          direct index (layout( column_major shared) temp block{layout( column_major shared) uniform runtime-sized array of int a, layout( column_major shared) uniform runtime-sized array of float b})
+0:63            'ubufa' (layout( column_major shared) uniform 4-element array of block{layout( column_major shared) uniform runtime-sized array of int a, layout( column_major shared) uniform runtime-sized array of float b})
+0:63            Constant:
+0:63              1 (const int)
+0:63          Constant:
+0:63            1 (const int)
+0:63        'i' ( global int)
+0:64      indirect index (layout( column_major shared) temp int)
+0:64        a: direct index for structure (layout( column_major shared) buffer runtime-sized array of int)
+0:64          direct index (layout( column_major shared) temp block{layout( column_major shared) buffer runtime-sized array of int a, layout( column_major shared) buffer runtime-sized array of float b})
+0:64            'bufa' (layout( column_major shared) buffer 4-element array of block{layout( column_major shared) buffer runtime-sized array of int a, layout( column_major shared) buffer runtime-sized array of float b})
+0:64            Constant:
+0:64              1 (const int)
+0:64          Constant:
+0:64            0 (const int)
+0:64        'i' ( global int)
+0:65      indirect index (layout( column_major shared) temp float)
+0:65        b: direct index for structure (layout( column_major shared) buffer runtime-sized array of float)
+0:65          direct index (layout( column_major shared) temp block{layout( column_major shared) buffer runtime-sized array of int a, layout( column_major shared) buffer runtime-sized array of float b})
+0:65            'bufa' (layout( column_major shared) buffer 4-element array of block{layout( column_major shared) buffer runtime-sized array of int a, layout( column_major shared) buffer runtime-sized array of float b})
+0:65            Constant:
+0:65              1 (const int)
+0:65          Constant:
+0:65            1 (const int)
+0:65        'i' ( global int)
+0:67      Constant:
+0:67        1 (const int)
+0:68      Constant:
+0:68        1 (const int)
+0:69      Constant:
+0:69        1 (const int)
+0:70      array length ( temp int)
+0:70        b: direct index for structure (layout( column_major shared) buffer runtime-sized array of float)
+0:70          direct index (layout( column_major shared) temp block{layout( column_major shared) buffer runtime-sized array of int a, layout( column_major shared) buffer runtime-sized array of float b})
+0:70            'bufa' (layout( column_major shared) buffer 4-element array of block{layout( column_major shared) buffer runtime-sized array of int a, layout( column_major shared) buffer runtime-sized array of float b})
+0:70            Constant:
+0:70              1 (const int)
+0:70          Constant:
+0:70            1 (const int)
+0:72      indirect index (layout( column_major shared) temp int)
+0:72        aua: direct index for structure (layout( column_major shared) uniform runtime-sized array of int)
+0:72          'anon@1' (layout( column_major shared) uniform block{layout( column_major shared) uniform runtime-sized array of int aua, layout( column_major shared) uniform runtime-sized array of float aub})
+0:72          Constant:
+0:72            0 (const uint)
+0:72        'i' ( global int)
+0:73      indirect index (layout( column_major shared) temp float)
+0:73        aub: direct index for structure (layout( column_major shared) uniform runtime-sized array of float)
+0:73          'anon@1' (layout( column_major shared) uniform block{layout( column_major shared) uniform runtime-sized array of int aua, layout( column_major shared) uniform runtime-sized array of float aub})
+0:73          Constant:
+0:73            1 (const uint)
+0:73        'i' ( global int)
+0:74      indirect index (layout( column_major shared) temp int)
+0:74        aba: direct index for structure (layout( column_major shared) buffer runtime-sized array of int)
+0:74          'anon@0' (layout( column_major shared) buffer block{layout( column_major shared) buffer runtime-sized array of int aba, layout( column_major shared) buffer runtime-sized array of float abb})
+0:74          Constant:
+0:74            0 (const uint)
+0:74        'i' ( global int)
+0:75      indirect index (layout( column_major shared) temp float)
+0:75        abb: direct index for structure (layout( column_major shared) buffer runtime-sized array of float)
+0:75          'anon@0' (layout( column_major shared) buffer block{layout( column_major shared) buffer runtime-sized array of int aba, layout( column_major shared) buffer runtime-sized array of float abb})
+0:75          Constant:
+0:75            1 (const uint)
+0:75        'i' ( global int)
+0:77      Constant:
+0:77        1 (const int)
+0:78      Constant:
+0:78        1 (const int)
+0:79      Constant:
+0:79        1 (const int)
+0:80      array length ( temp int)
+0:80        abb: direct index for structure (layout( column_major shared) buffer runtime-sized array of float)
+0:80          'anon@0' (layout( column_major shared) buffer block{layout( column_major shared) buffer runtime-sized array of int aba, layout( column_major shared) buffer runtime-sized array of float abb})
+0:80          Constant:
+0:80            1 (const uint)
+0:?   Linker Objects
+0:?     'buf' (layout( column_major shared) buffer block{layout( column_major shared) buffer runtime-sized array of int a, layout( column_major shared) buffer runtime-sized array of float b})
+0:?     'ubuf' (layout( column_major shared) uniform block{layout( column_major shared) uniform runtime-sized array of int a, layout( column_major shared) uniform runtime-sized array of float b})
+0:?     'bufa' (layout( column_major shared) buffer 4-element array of block{layout( column_major shared) buffer runtime-sized array of int a, layout( column_major shared) buffer runtime-sized array of float b})
+0:?     'ubufa' (layout( column_major shared) uniform 4-element array of block{layout( column_major shared) uniform runtime-sized array of int a, layout( column_major shared) uniform runtime-sized array of float b})
+0:?     'anon@0' (layout( column_major shared) buffer block{layout( column_major shared) buffer runtime-sized array of int aba, layout( column_major shared) buffer runtime-sized array of float abb})
+0:?     'anon@1' (layout( column_major shared) uniform block{layout( column_major shared) uniform runtime-sized array of int aua, layout( column_major shared) uniform runtime-sized array of float aub})
+0:?     'i' ( global int)
+0:?     'gl_VertexID' ( gl_VertexId int VertexId)
+0:?     'gl_InstanceID' ( gl_InstanceId int InstanceId)
+
+
+Linked vertex stage:
+
+
+Shader version: 450
+ERROR: node is still EOpNull!
+0:35  Function Definition: main( ( global void)
+0:35    Function Parameters: 
+0:37    Sequence
+0:37      direct index (layout( column_major shared) temp int)
+0:37        a: direct index for structure (layout( column_major shared) uniform runtime-sized array of int)
+0:37          'ubuf' (layout( column_major shared) uniform block{layout( column_major shared) uniform runtime-sized array of int a, layout( column_major shared) uniform runtime-sized array of float b})
+0:37          Constant:
+0:37            0 (const int)
+0:37        Constant:
+0:37          3 (const int)
+0:38      direct index (layout( column_major shared) temp float)
+0:38        b: direct index for structure (layout( column_major shared) uniform runtime-sized array of float)
+0:38          'ubuf' (layout( column_major shared) uniform block{layout( column_major shared) uniform runtime-sized array of int a, layout( column_major shared) uniform runtime-sized array of float b})
+0:38          Constant:
+0:38            1 (const int)
+0:38        Constant:
+0:38          3 (const int)
+0:39      direct index (layout( column_major shared) temp int)
+0:39        a: direct index for structure (layout( column_major shared) buffer runtime-sized array of int)
+0:39          'buf' (layout( column_major shared) buffer block{layout( column_major shared) buffer runtime-sized array of int a, layout( column_major shared) buffer runtime-sized array of float b})
+0:39          Constant:
+0:39            0 (const int)
+0:39        Constant:
+0:39          3 (const int)
+0:40      direct index (layout( column_major shared) temp float)
+0:40        b: direct index for structure (layout( column_major shared) buffer runtime-sized array of float)
+0:40          'buf' (layout( column_major shared) buffer block{layout( column_major shared) buffer runtime-sized array of int a, layout( column_major shared) buffer runtime-sized array of float b})
+0:40          Constant:
+0:40            1 (const int)
+0:40        Constant:
+0:40          3 (const int)
+0:42      direct index (layout( column_major shared) temp int)
+0:42        a: direct index for structure (layout( column_major shared) uniform runtime-sized array of int)
+0:42          direct index (layout( column_major shared) temp block{layout( column_major shared) uniform runtime-sized array of int a, layout( column_major shared) uniform runtime-sized array of float b})
+0:42            'ubufa' (layout( column_major shared) uniform 4-element array of block{layout( column_major shared) uniform runtime-sized array of int a, layout( column_major shared) uniform runtime-sized array of float b})
+0:42            Constant:
+0:42              3 (const int)
+0:42          Constant:
+0:42            0 (const int)
+0:42        Constant:
+0:42          3 (const int)
+0:43      direct index (layout( column_major shared) temp float)
+0:43        b: direct index for structure (layout( column_major shared) uniform runtime-sized array of float)
+0:43          direct index (layout( column_major shared) temp block{layout( column_major shared) uniform runtime-sized array of int a, layout( column_major shared) uniform runtime-sized array of float b})
+0:43            'ubufa' (layout( column_major shared) uniform 4-element array of block{layout( column_major shared) uniform runtime-sized array of int a, layout( column_major shared) uniform runtime-sized array of float b})
+0:43            Constant:
+0:43              3 (const int)
+0:43          Constant:
+0:43            1 (const int)
+0:43        Constant:
+0:43          3 (const int)
+0:44      direct index (layout( column_major shared) temp int)
+0:44        a: direct index for structure (layout( column_major shared) buffer runtime-sized array of int)
+0:44          direct index (layout( column_major shared) temp block{layout( column_major shared) buffer runtime-sized array of int a, layout( column_major shared) buffer runtime-sized array of float b})
+0:44            'bufa' (layout( column_major shared) buffer 4-element array of block{layout( column_major shared) buffer runtime-sized array of int a, layout( column_major shared) buffer runtime-sized array of float b})
+0:44            Constant:
+0:44              3 (const int)
+0:44          Constant:
+0:44            0 (const int)
+0:44        Constant:
+0:44          3 (const int)
+0:45      direct index (layout( column_major shared) temp float)
+0:45        b: direct index for structure (layout( column_major shared) buffer runtime-sized array of float)
+0:45          direct index (layout( column_major shared) temp block{layout( column_major shared) buffer runtime-sized array of int a, layout( column_major shared) buffer runtime-sized array of float b})
+0:45            'bufa' (layout( column_major shared) buffer 4-element array of block{layout( column_major shared) buffer runtime-sized array of int a, layout( column_major shared) buffer runtime-sized array of float b})
+0:45            Constant:
+0:45              3 (const int)
+0:45          Constant:
+0:45            1 (const int)
+0:45        Constant:
+0:45          3 (const int)
+0:47      direct index (layout( column_major shared) temp int)
+0:47        aua: direct index for structure (layout( column_major shared) uniform runtime-sized array of int)
+0:47          'anon@1' (layout( column_major shared) uniform block{layout( column_major shared) uniform runtime-sized array of int aua, layout( column_major shared) uniform runtime-sized array of float aub})
+0:47          Constant:
+0:47            0 (const uint)
+0:47        Constant:
+0:47          3 (const int)
+0:48      direct index (layout( column_major shared) temp float)
+0:48        aub: direct index for structure (layout( column_major shared) uniform runtime-sized array of float)
+0:48          'anon@1' (layout( column_major shared) uniform block{layout( column_major shared) uniform runtime-sized array of int aua, layout( column_major shared) uniform runtime-sized array of float aub})
+0:48          Constant:
+0:48            1 (const uint)
+0:48        Constant:
+0:48          3 (const int)
+0:49      direct index (layout( column_major shared) temp int)
+0:49        aba: direct index for structure (layout( column_major shared) buffer runtime-sized array of int)
+0:49          'anon@0' (layout( column_major shared) buffer block{layout( column_major shared) buffer runtime-sized array of int aba, layout( column_major shared) buffer runtime-sized array of float abb})
+0:49          Constant:
+0:49            0 (const uint)
+0:49        Constant:
+0:49          3 (const int)
+0:50      direct index (layout( column_major shared) temp float)
+0:50        abb: direct index for structure (layout( column_major shared) buffer runtime-sized array of float)
+0:50          'anon@0' (layout( column_major shared) buffer block{layout( column_major shared) buffer runtime-sized array of int aba, layout( column_major shared) buffer runtime-sized array of float abb})
+0:50          Constant:
+0:50            1 (const uint)
+0:50        Constant:
+0:50          3 (const int)
+0:52      indirect index (layout( column_major shared) temp int)
+0:52        a: direct index for structure (layout( column_major shared) uniform runtime-sized array of int)
+0:52          'ubuf' (layout( column_major shared) uniform block{layout( column_major shared) uniform runtime-sized array of int a, layout( column_major shared) uniform runtime-sized array of float b})
+0:52          Constant:
+0:52            0 (const int)
+0:52        'i' ( global int)
+0:53      indirect index (layout( column_major shared) temp float)
+0:53        b: direct index for structure (layout( column_major shared) uniform runtime-sized array of float)
+0:53          'ubuf' (layout( column_major shared) uniform block{layout( column_major shared) uniform runtime-sized array of int a, layout( column_major shared) uniform runtime-sized array of float b})
+0:53          Constant:
+0:53            1 (const int)
+0:53        'i' ( global int)
+0:54      indirect index (layout( column_major shared) temp int)
+0:54        a: direct index for structure (layout( column_major shared) buffer runtime-sized array of int)
+0:54          'buf' (layout( column_major shared) buffer block{layout( column_major shared) buffer runtime-sized array of int a, layout( column_major shared) buffer runtime-sized array of float b})
+0:54          Constant:
+0:54            0 (const int)
+0:54        'i' ( global int)
+0:55      indirect index (layout( column_major shared) temp float)
+0:55        b: direct index for structure (layout( column_major shared) buffer runtime-sized array of float)
+0:55          'buf' (layout( column_major shared) buffer block{layout( column_major shared) buffer runtime-sized array of int a, layout( column_major shared) buffer runtime-sized array of float b})
+0:55          Constant:
+0:55            1 (const int)
+0:55        'i' ( global int)
+0:57      Constant:
+0:57        1 (const int)
+0:58      Constant:
+0:58        1 (const int)
+0:59      Constant:
+0:59        1 (const int)
+0:60      array length ( temp int)
+0:60        b: direct index for structure (layout( column_major shared) buffer runtime-sized array of float)
+0:60          'buf' (layout( column_major shared) buffer block{layout( column_major shared) buffer runtime-sized array of int a, layout( column_major shared) buffer runtime-sized array of float b})
+0:60          Constant:
+0:60            1 (const int)
+0:62      indirect index (layout( column_major shared) temp int)
+0:62        a: direct index for structure (layout( column_major shared) uniform runtime-sized array of int)
+0:62          direct index (layout( column_major shared) temp block{layout( column_major shared) uniform runtime-sized array of int a, layout( column_major shared) uniform runtime-sized array of float b})
+0:62            'ubufa' (layout( column_major shared) uniform 4-element array of block{layout( column_major shared) uniform runtime-sized array of int a, layout( column_major shared) uniform runtime-sized array of float b})
+0:62            Constant:
+0:62              1 (const int)
+0:62          Constant:
+0:62            0 (const int)
+0:62        'i' ( global int)
+0:63      indirect index (layout( column_major shared) temp float)
+0:63        b: direct index for structure (layout( column_major shared) uniform runtime-sized array of float)
+0:63          direct index (layout( column_major shared) temp block{layout( column_major shared) uniform runtime-sized array of int a, layout( column_major shared) uniform runtime-sized array of float b})
+0:63            'ubufa' (layout( column_major shared) uniform 4-element array of block{layout( column_major shared) uniform runtime-sized array of int a, layout( column_major shared) uniform runtime-sized array of float b})
+0:63            Constant:
+0:63              1 (const int)
+0:63          Constant:
+0:63            1 (const int)
+0:63        'i' ( global int)
+0:64      indirect index (layout( column_major shared) temp int)
+0:64        a: direct index for structure (layout( column_major shared) buffer runtime-sized array of int)
+0:64          direct index (layout( column_major shared) temp block{layout( column_major shared) buffer runtime-sized array of int a, layout( column_major shared) buffer runtime-sized array of float b})
+0:64            'bufa' (layout( column_major shared) buffer 4-element array of block{layout( column_major shared) buffer runtime-sized array of int a, layout( column_major shared) buffer runtime-sized array of float b})
+0:64            Constant:
+0:64              1 (const int)
+0:64          Constant:
+0:64            0 (const int)
+0:64        'i' ( global int)
+0:65      indirect index (layout( column_major shared) temp float)
+0:65        b: direct index for structure (layout( column_major shared) buffer runtime-sized array of float)
+0:65          direct index (layout( column_major shared) temp block{layout( column_major shared) buffer runtime-sized array of int a, layout( column_major shared) buffer runtime-sized array of float b})
+0:65            'bufa' (layout( column_major shared) buffer 4-element array of block{layout( column_major shared) buffer runtime-sized array of int a, layout( column_major shared) buffer runtime-sized array of float b})
+0:65            Constant:
+0:65              1 (const int)
+0:65          Constant:
+0:65            1 (const int)
+0:65        'i' ( global int)
+0:67      Constant:
+0:67        1 (const int)
+0:68      Constant:
+0:68        1 (const int)
+0:69      Constant:
+0:69        1 (const int)
+0:70      array length ( temp int)
+0:70        b: direct index for structure (layout( column_major shared) buffer runtime-sized array of float)
+0:70          direct index (layout( column_major shared) temp block{layout( column_major shared) buffer runtime-sized array of int a, layout( column_major shared) buffer runtime-sized array of float b})
+0:70            'bufa' (layout( column_major shared) buffer 4-element array of block{layout( column_major shared) buffer runtime-sized array of int a, layout( column_major shared) buffer runtime-sized array of float b})
+0:70            Constant:
+0:70              1 (const int)
+0:70          Constant:
+0:70            1 (const int)
+0:72      indirect index (layout( column_major shared) temp int)
+0:72        aua: direct index for structure (layout( column_major shared) uniform runtime-sized array of int)
+0:72          'anon@1' (layout( column_major shared) uniform block{layout( column_major shared) uniform runtime-sized array of int aua, layout( column_major shared) uniform runtime-sized array of float aub})
+0:72          Constant:
+0:72            0 (const uint)
+0:72        'i' ( global int)
+0:73      indirect index (layout( column_major shared) temp float)
+0:73        aub: direct index for structure (layout( column_major shared) uniform runtime-sized array of float)
+0:73          'anon@1' (layout( column_major shared) uniform block{layout( column_major shared) uniform runtime-sized array of int aua, layout( column_major shared) uniform runtime-sized array of float aub})
+0:73          Constant:
+0:73            1 (const uint)
+0:73        'i' ( global int)
+0:74      indirect index (layout( column_major shared) temp int)
+0:74        aba: direct index for structure (layout( column_major shared) buffer runtime-sized array of int)
+0:74          'anon@0' (layout( column_major shared) buffer block{layout( column_major shared) buffer runtime-sized array of int aba, layout( column_major shared) buffer runtime-sized array of float abb})
+0:74          Constant:
+0:74            0 (const uint)
+0:74        'i' ( global int)
+0:75      indirect index (layout( column_major shared) temp float)
+0:75        abb: direct index for structure (layout( column_major shared) buffer runtime-sized array of float)
+0:75          'anon@0' (layout( column_major shared) buffer block{layout( column_major shared) buffer runtime-sized array of int aba, layout( column_major shared) buffer runtime-sized array of float abb})
+0:75          Constant:
+0:75            1 (const uint)
+0:75        'i' ( global int)
+0:77      Constant:
+0:77        1 (const int)
+0:78      Constant:
+0:78        1 (const int)
+0:79      Constant:
+0:79        1 (const int)
+0:80      array length ( temp int)
+0:80        abb: direct index for structure (layout( column_major shared) buffer runtime-sized array of float)
+0:80          'anon@0' (layout( column_major shared) buffer block{layout( column_major shared) buffer runtime-sized array of int aba, layout( column_major shared) buffer runtime-sized array of float abb})
+0:80          Constant:
+0:80            1 (const uint)
+0:?   Linker Objects
+0:?     'buf' (layout( column_major shared) buffer block{layout( column_major shared) buffer runtime-sized array of int a, layout( column_major shared) buffer runtime-sized array of float b})
+0:?     'ubuf' (layout( column_major shared) uniform block{layout( column_major shared) uniform runtime-sized array of int a, layout( column_major shared) uniform runtime-sized array of float b})
+0:?     'bufa' (layout( column_major shared) buffer 4-element array of block{layout( column_major shared) buffer runtime-sized array of int a, layout( column_major shared) buffer runtime-sized array of float b})
+0:?     'ubufa' (layout( column_major shared) uniform 4-element array of block{layout( column_major shared) uniform runtime-sized array of int a, layout( column_major shared) uniform runtime-sized array of float b})
+0:?     'anon@0' (layout( column_major shared) buffer block{layout( column_major shared) buffer runtime-sized array of int aba, layout( column_major shared) buffer runtime-sized array of float abb})
+0:?     'anon@1' (layout( column_major shared) uniform block{layout( column_major shared) uniform runtime-sized array of int aua, layout( column_major shared) uniform runtime-sized array of float aub})
+0:?     'i' ( global int)
+0:?     'gl_VertexID' ( gl_VertexId int VertexId)
+0:?     'gl_InstanceID' ( gl_InstanceId int InstanceId)
+
diff --git a/Test/runtimeArray.vert b/Test/runtimeArray.vert
new file mode 100644 (file)
index 0000000..4ddb2dc
--- /dev/null
@@ -0,0 +1,81 @@
+#version 450 core\r
+\r
+buffer bn {\r
+    int a[];\r
+    float b[];\r
+} buf;\r
+\r
+uniform un {\r
+    int a[];\r
+    float b[];\r
+} ubuf;\r
+\r
+buffer bna {\r
+    int a[];\r
+    float b[];\r
+} bufa[4];\r
+\r
+uniform una {\r
+    int a[];\r
+    float b[];\r
+} ubufa[4];\r
+\r
+buffer abn {\r
+    int aba[];\r
+    float abb[];\r
+};\r
+\r
+uniform aun {\r
+    int aua[];\r
+    float aub[];\r
+};\r
+\r
+int i;\r
+\r
+void main()\r
+{\r
+    ubuf.a[3];\r
+    ubuf.b[3];\r
+    buf.a[3];\r
+    buf.b[3];\r
+\r
+    ubufa[3].a[3];\r
+    ubufa[3].b[3];\r
+    bufa[3].a[3];\r
+    bufa[3].b[3];\r
+\r
+    aua[3];\r
+    aub[3];\r
+    aba[3];\r
+    abb[3];\r
+\r
+    ubuf.a[i];             // ERROR\r
+    ubuf.b[i];             // ERROR\r
+    buf.a[i];              // ERROR\r
+    buf.b[i];\r
+\r
+    ubuf.a.length();       // ERROR\r
+    ubuf.b.length();       // ERROR\r
+    buf.a.length();        // ERROR\r
+    buf.b.length();\r
+\r
+    ubufa[1].a[i];         // ERROR\r
+    ubufa[1].b[i];         // ERROR\r
+    bufa[1].a[i];          // ERROR\r
+    bufa[1].b[i];\r
+\r
+    ubufa[1].a.length();   // ERROR\r
+    ubufa[1].b.length();   // ERROR\r
+    bufa[1].a.length();    // ERROR\r
+    bufa[1].b.length();\r
+\r
+    aua[i];                // ERROR\r
+    aub[i];                // ERROR\r
+    aba[i];                // ERROR\r
+    abb[i];\r
+\r
+    aua.length();          // ERROR\r
+    aub.length();          // ERROR\r
+    aba.length();          // ERROR\r
+    abb.length();\r
+}\r
index 06ca4891b097221c7802d7eb03fbf13cf106668b..5111bb72fdb3f355b3069d2a7fccd1aba8593064 100644 (file)
@@ -390,7 +390,7 @@ TIntermTyped* TParseContext::handleBracketDereference(const TSourceLoc& loc, TIn
                     error(loc, "", "[", "array must be sized by a redeclaration or layout qualifier before being indexed with a variable");
                 else {
                     // it is okay for a run-time sized array
-                    if (base->getType().getQualifier().storage != EvqBuffer)
+                    if (!isRuntimeSizable(*base))
                         error(loc, "", "[", "array must be redeclared with a size before being indexed with a variable");
                 }
                 base->getWritableType().setArrayVariablyIndexed();
@@ -1235,7 +1235,7 @@ TIntermTyped* TParseContext::handleLengthMethod(const TSourceLoc& loc, TFunction
                 if (length == 0) {
                     if (intermNode->getAsSymbolNode() && isIoResizeArray(type))
                         error(loc, "", function->getName().c_str(), "array must first be sized by a redeclaration or layout qualifier");
-                    else if (type.getQualifier().isUniformOrBuffer()) {
+                    else if (isRuntimeLength(*intermNode->getAsTyped())) {
                         // Create a unary op and let the back end handle it
                         return intermediate.addBuiltInFunctionCall(loc, EOpArrayLength, true, intermNode, TType(EbtInt));
                     } else
@@ -3268,6 +3268,31 @@ void TParseContext::declareArray(const TSourceLoc& loc, const TString& identifie
         checkIoArraysConsistency(loc);
 }
 
+// Policy decision for whether a node could potentially be sized at runtime.
+bool TParseContext::isRuntimeSizable(const TIntermTyped& base) const
+{
+    const TType& type = base.getType();
+    if (type.getQualifier().storage == EvqBuffer) {
+        // in a buffer block
+        const TIntermBinary* binary = base.getAsBinaryNode();
+        if (binary != nullptr && binary->getOp() == EOpIndexDirectStruct) {
+            // is it the last member?
+            const int index = binary->getRight()->getAsConstantUnion()->getConstArray()[0].getIConst();
+            const int memberCount = (int)binary->getLeft()->getType().getStruct()->size();
+            if (index == memberCount - 1)
+                return true;
+        }
+    }
+
+    return false;
+}
+
+// Policy decision for whether a run-time .length() is allowed.
+bool TParseContext::isRuntimeLength(const TIntermTyped& base) const
+{
+    return isRuntimeSizable(base);
+}
+
 // Returns true if the first argument to the #line directive is the line number for the next line.
 //
 // Desktop, pre-version 3.30:  "After processing this directive
index af1a927b73676b84ec4c3d300e7cd9b2a45da45b..7dabb01bccac15ae33cb3227e977cb5e30bd6327 100644 (file)
@@ -427,6 +427,8 @@ protected:
     TVariable* makeInternalVariable(const char* name, const TType&) const;
     TVariable* declareNonArray(const TSourceLoc&, const TString& identifier, const TType&);
     void declareArray(const TSourceLoc&, const TString& identifier, const TType&, TSymbol*&);
+    bool isRuntimeSizable(const TIntermTyped&) const;
+    bool isRuntimeLength(const TIntermTyped&) const;
     TIntermNode* executeInitializer(const TSourceLoc&, TIntermTyped* initializer, TVariable* variable);
     TIntermTyped* convertInitializerList(const TSourceLoc&, const TType&, TIntermTyped* initializer);
     void finish() override;
index 320991047e7d3229271483254450ff230129e0a6..e2b2bf840aba182539b2401a25e1c5abd99e7fce 100644 (file)
@@ -204,6 +204,7 @@ INSTANTIATE_TEST_CASE_P(
         "Operations.frag",
         "overlongLiteral.frag",
         "prepost.frag",
+        "runtimeArray.vert",
         "simpleFunctionCall.frag",
         "structAssignment.frag",
         "structDeref.frag",