Commit ead86224 by John Kessenich

Non-functional. Rationalizations enabling future generalizations:

- Use much simpler method to update implicit array sizes. The previous overly complicated method was error prone. - Rationalize all use of unsized arrays. - Combine decorations when generating SPIR-V, to simplify adding extensions.
parent 2316924b
......@@ -854,9 +854,9 @@ Id Builder::makeFpConstant(Id type, double d, bool specConstant)
switch (getScalarTypeWidth(type)) {
case 16:
return makeFloat16Constant(d, specConstant);
return makeFloat16Constant((float)d, specConstant);
case 32:
return makeFloatConstant(d, specConstant);
return makeFloatConstant((float)d, specConstant);
case 64:
return makeDoubleConstant(d, specConstant);
default:
......
......@@ -104,3 +104,9 @@ void foo3()
int[] i = int[](); // ERROR, need constructor arguments
float emptyA[];
float b = vec4(emptyA); // ERROR, array can't be a constructor argument
uniform sampler2D s2d[];
void foo4()
{
s2d[a]; // ERROR, can't variably index unsized array
}
......@@ -453,7 +453,7 @@ ERROR: 0:47: 'patch' : cannot use interpolation qualifiers with patch
ERROR: 0:48: 'patch' : cannot use interpolation qualifiers with patch
ERROR: 0:49: 'patch' : cannot use interpolation qualifiers with patch
ERROR: 0:50: '' : can only have one auxiliary qualifier (centroid, patch, and sample)
ERROR: 0:54: 'gl_PerVertex' : block already declared with size, can't redeclare as implicitly-sized
ERROR: 0:54: 'gl_PerVertex' : block already declared with size, can't redeclare as unsized
ERROR: 0:59: 'gl_PerVertex' : can only redeclare a built-in block once, and before any use
ERROR: 0:64: 'quads' : cannot apply to 'out'
ERROR: 0:64: 'cw' : can only apply to 'in'
......
......@@ -25,7 +25,7 @@ ERROR: 0:53: 'noperspective' : not supported for this version or the enabled ext
ERROR: 0:53: 'patch' : cannot use interpolation qualifiers with patch
ERROR: 0:54: 'sample' : Reserved word.
ERROR: 0:54: '' : can only have one auxiliary qualifier (centroid, patch, and sample)
ERROR: 0:58: 'gl_PerVertex' : block already declared with size, can't redeclare as implicitly-sized
ERROR: 0:58: 'gl_PerVertex' : block already declared with size, can't redeclare as unsized
ERROR: 0:63: 'gl_PerVertex' : can only redeclare a built-in block once, and before any use
ERROR: 0:68: 'quads' : cannot apply to 'out'
ERROR: 0:68: 'cw' : can only apply to 'in'
......
......@@ -11,14 +11,14 @@ ERROR: node is still EOpNull!
0:7 move second child to first child ( temp highp int)
0:7 'o' (layout( location=0) smooth out highp int)
0:7 direct index (layout( column_major shared) temp highp int)
0:7 a: direct index for structure (layout( column_major shared) uniform unsized 1-element array of highp int)
0:7 'uni' (layout( binding=0 column_major shared) uniform block{layout( column_major shared) uniform unsized 1-element array of highp int a})
0:7 a: direct index for structure (layout( column_major shared) uniform unsized 3-element array of highp int)
0:7 'uni' (layout( binding=0 column_major shared) uniform block{layout( column_major shared) uniform unsized 3-element array of highp int a})
0:7 Constant:
0:7 0 (const int)
0:7 Constant:
0:7 2 (const int)
0:? Linker Objects
0:? 'uni' (layout( binding=0 column_major shared) uniform block{layout( column_major shared) uniform unsized 1-element array of highp int a})
0:? 'uni' (layout( binding=0 column_major shared) uniform block{layout( column_major shared) uniform unsized 3-element array of highp int a})
0:? 'o' (layout( location=0) smooth out highp int)
0:? 'gl_VertexID' ( gl_VertexId highp int VertexId)
0:? 'gl_InstanceID' ( gl_InstanceId highp int InstanceId)
......@@ -35,14 +35,14 @@ ERROR: node is still EOpNull!
0:7 move second child to first child ( temp highp int)
0:7 'o' (layout( location=0) smooth out highp int)
0:7 direct index (layout( column_major shared) temp highp int)
0:7 a: direct index for structure (layout( column_major shared) uniform 1-element array of highp int)
0:7 'uni' (layout( binding=0 column_major shared) uniform block{layout( column_major shared) uniform 1-element array of highp int a})
0:7 a: direct index for structure (layout( column_major shared) uniform 3-element array of highp int)
0:7 'uni' (layout( binding=0 column_major shared) uniform block{layout( column_major shared) uniform 3-element array of highp int a})
0:7 Constant:
0:7 0 (const int)
0:7 Constant:
0:7 2 (const int)
0:? Linker Objects
0:? 'uni' (layout( binding=0 column_major shared) uniform block{layout( column_major shared) uniform 1-element array of highp int a})
0:? 'uni' (layout( binding=0 column_major shared) uniform block{layout( column_major shared) uniform 3-element array of highp int a})
0:? 'o' (layout( location=0) smooth out highp int)
0:? 'gl_VertexID' ( gl_VertexId highp int VertexId)
0:? 'gl_InstanceID' ( gl_InstanceId highp int InstanceId)
......
......@@ -24,7 +24,7 @@ ERROR: 0:49: 'noperspective' : Reserved word.
ERROR: 0:49: 'noperspective' : not supported for this version or the enabled extensions
ERROR: 0:49: 'patch' : cannot use interpolation qualifiers with patch
ERROR: 0:50: '' : can only have one auxiliary qualifier (centroid, patch, and sample)
ERROR: 0:54: 'gl_PerVertex' : block already declared with size, can't redeclare as implicitly-sized
ERROR: 0:54: 'gl_PerVertex' : block already declared with size, can't redeclare as unsized
ERROR: 0:59: 'gl_PerVertex' : can only redeclare a built-in block once, and before any use
ERROR: 0:64: 'quads' : cannot apply to 'out'
ERROR: 0:64: 'cw' : can only apply to 'in'
......
......@@ -11,7 +11,7 @@ ERROR: 0:47: 'patch' : cannot use interpolation qualifiers with patch
ERROR: 0:48: 'patch' : cannot use interpolation qualifiers with patch
ERROR: 0:49: 'patch' : cannot use interpolation qualifiers with patch
ERROR: 0:50: '' : can only have one auxiliary qualifier (centroid, patch, and sample)
ERROR: 0:54: 'gl_PerVertex' : block already declared with size, can't redeclare as implicitly-sized
ERROR: 0:54: 'gl_PerVertex' : block already declared with size, can't redeclare as unsized
ERROR: 0:59: 'gl_PerVertex' : can only redeclare a built-in block once, and before any use
ERROR: 0:64: 'quads' : cannot apply to 'out'
ERROR: 0:64: 'cw' : can only apply to 'in'
......
......@@ -51,7 +51,7 @@ ERROR: 0:157: 'textureQueryLevels' : no matching overloaded function found
ERROR: 0:157: 'assign' : cannot convert from ' const float' to ' temp int'
ERROR: 0:158: 'textureQueryLevels' : no matching overloaded function found
ERROR: 0:158: 'assign' : cannot convert from ' const float' to ' temp int'
WARNING: 0:161: '[]' : assuming array size of one for compile-time checking of binding numbers for implicitly-sized array
WARNING: 0:161: '[]' : assuming array size of one for compile-time checking of binding numbers for unsized array
ERROR: 51 compilation errors. No code generated.
......
......@@ -33,13 +33,13 @@ ERROR: node is still EOpNull!
0:35 GroupMemoryBarrier ( global void)
0:36 move second child to first child ( temp int)
0:36 value: direct index for structure (layout( column_major shared) buffer int)
0:36 'anon@0' (layout( column_major shared) buffer block{layout( column_major shared) buffer int value, layout( column_major shared) buffer unsized 1-element array of float values})
0:36 'anon@0' (layout( column_major shared) buffer block{layout( column_major shared) buffer int value, layout( column_major shared) buffer runtime-sized array of float values})
0:36 Constant:
0:36 0 (const uint)
0:36 Convert float to int ( temp int)
0:36 indirect index (layout( column_major shared) temp float)
0:36 values: direct index for structure (layout( column_major shared) buffer unsized 1-element array of float)
0:36 'anon@0' (layout( column_major shared) buffer block{layout( column_major shared) buffer int value, layout( column_major shared) buffer unsized 1-element array of float values})
0:36 values: direct index for structure (layout( column_major shared) buffer runtime-sized array of float)
0:36 'anon@0' (layout( column_major shared) buffer block{layout( column_major shared) buffer int value, layout( column_major shared) buffer runtime-sized array of float values})
0:36 Constant:
0:36 1 (const uint)
0:36 'gl_LocalInvocationIndex' ( in uint LocalInvocationIndex)
......@@ -56,8 +56,8 @@ ERROR: node is still EOpNull!
0:65 Sequence
0:65 move second child to first child ( temp float)
0:65 direct index (layout( column_major shared) temp float)
0:65 values: direct index for structure (layout( column_major shared) buffer unsized 1-element array of float)
0:65 'ro' (layout( column_major shared) readonly buffer block{layout( column_major shared) buffer int value, layout( column_major shared) buffer unsized 1-element array of float values})
0:65 values: direct index for structure (layout( column_major shared) buffer unsized 3-element array of float)
0:65 'ro' (layout( column_major shared) readonly buffer block{layout( column_major shared) buffer int value, layout( column_major shared) buffer unsized 3-element array of float values})
0:65 Constant:
0:65 1 (const int)
0:65 Constant:
......@@ -65,8 +65,8 @@ ERROR: node is still EOpNull!
0:65 Constant:
0:65 4.700000
0:66 array length ( temp int)
0:66 values: direct index for structure (layout( column_major shared) buffer unsized 1-element array of float)
0:66 'ro' (layout( column_major shared) readonly buffer block{layout( column_major shared) buffer int value, layout( column_major shared) buffer unsized 1-element array of float values})
0:66 values: direct index for structure (layout( column_major shared) buffer unsized 3-element array of float)
0:66 'ro' (layout( column_major shared) readonly buffer block{layout( column_major shared) buffer int value, layout( column_major shared) buffer unsized 3-element array of float values})
0:66 Constant:
0:66 1 (const int)
0:67 Barrier ( global void)
......@@ -129,7 +129,7 @@ ERROR: node is still EOpNull!
0:? 4096 (const uint)
0:? 'total' ( const int)
0:? 66592 (const int)
0:? 'anon@0' (layout( column_major shared) buffer block{layout( column_major shared) buffer int value, layout( column_major shared) buffer unsized 1-element array of float values})
0:? 'anon@0' (layout( column_major shared) buffer block{layout( column_major shared) buffer int value, layout( column_major shared) buffer runtime-sized array of float values})
0:? 'invalid' (layout( column_major shared) buffer block{layout( column_major shared) buffer unsized 1-element array of float values, layout( column_major shared) buffer int value})
0:? 'v3' (layout( location=2) in 3-component vector of float)
0:? 'f' ( in float)
......@@ -140,7 +140,7 @@ ERROR: node is still EOpNull!
0:? 'arrX' ( global 2-element array of int)
0:? 'arrY' ( global 1-element array of int)
0:? 'arrZ' ( global 4096-element array of int)
0:? 'ro' (layout( column_major shared) readonly buffer block{layout( column_major shared) buffer int value, layout( column_major shared) buffer unsized 1-element array of float values})
0:? 'ro' (layout( column_major shared) readonly buffer block{layout( column_major shared) buffer int value, layout( column_major shared) buffer unsized 3-element array of float values})
0:? 'roll' ( uniform double)
0:? 'destTex' ( writeonly uniform image2D)
0:? 'inbi' ( in block{ in int a})
......@@ -165,13 +165,13 @@ ERROR: node is still EOpNull!
0:35 GroupMemoryBarrier ( global void)
0:36 move second child to first child ( temp int)
0:36 value: direct index for structure (layout( column_major shared) buffer int)
0:36 'anon@0' (layout( column_major shared) buffer block{layout( column_major shared) buffer int value, layout( column_major shared) buffer unsized 1-element array of float values})
0:36 'anon@0' (layout( column_major shared) buffer block{layout( column_major shared) buffer int value, layout( column_major shared) buffer runtime-sized array of float values})
0:36 Constant:
0:36 0 (const uint)
0:36 Convert float to int ( temp int)
0:36 indirect index (layout( column_major shared) temp float)
0:36 values: direct index for structure (layout( column_major shared) buffer unsized 1-element array of float)
0:36 'anon@0' (layout( column_major shared) buffer block{layout( column_major shared) buffer int value, layout( column_major shared) buffer unsized 1-element array of float values})
0:36 values: direct index for structure (layout( column_major shared) buffer runtime-sized array of float)
0:36 'anon@0' (layout( column_major shared) buffer block{layout( column_major shared) buffer int value, layout( column_major shared) buffer runtime-sized array of float values})
0:36 Constant:
0:36 1 (const uint)
0:36 'gl_LocalInvocationIndex' ( in uint LocalInvocationIndex)
......@@ -190,8 +190,8 @@ ERROR: node is still EOpNull!
0:? 4096 (const uint)
0:? 'total' ( const int)
0:? 66592 (const int)
0:? 'anon@0' (layout( column_major shared) buffer block{layout( column_major shared) buffer int value, layout( column_major shared) buffer unsized 1-element array of float values})
0:? 'invalid' (layout( column_major shared) buffer block{layout( column_major shared) buffer unsized 1-element array of float values, layout( column_major shared) buffer int value})
0:? 'anon@0' (layout( column_major shared) buffer block{layout( column_major shared) buffer int value, layout( column_major shared) buffer runtime-sized array of float values})
0:? 'invalid' (layout( column_major shared) buffer block{layout( column_major shared) buffer 1-element array of float values, layout( column_major shared) buffer int value})
0:? 'v3' (layout( location=2) in 3-component vector of float)
0:? 'f' ( in float)
0:? 'fo' ( out float)
......@@ -201,7 +201,7 @@ ERROR: node is still EOpNull!
0:? 'arrX' ( global 2-element array of int)
0:? 'arrY' ( global 1-element array of int)
0:? 'arrZ' ( global 4096-element array of int)
0:? 'ro' (layout( column_major shared) readonly buffer block{layout( column_major shared) buffer int value, layout( column_major shared) buffer unsized 1-element array of float values})
0:? 'ro' (layout( column_major shared) readonly buffer block{layout( column_major shared) buffer int value, layout( column_major shared) buffer unsized 3-element array of float values})
0:? 'roll' ( uniform double)
0:? 'destTex' ( writeonly uniform image2D)
0:? 'inbi' ( in block{ in int a})
......
......@@ -2,7 +2,7 @@ array.frag
ERROR: 0:21: '[' : array index out of range '2'
ERROR: 0:27: '[' : array must be redeclared with a size before being indexed with a variable
ERROR: 0:30: 'assign' : cannot convert from ' global 4-element array of float' to ' global 5-element array of float'
ERROR: 0:31: 'assign' : cannot convert from ' global 4-element array of float' to ' global unsized 4-element array of float'
ERROR: 0:31: 'assign' : cannot convert from ' global 4-element array of float' to ' global runtime-sized array of float'
ERROR: 0:33: 'foo' : no matching overloaded function found
ERROR: 0:42: '[' : array index out of range '5'
ERROR: 0:45: '[' : array index out of range '1000'
......@@ -25,7 +25,9 @@ ERROR: 0:101: '[' : array index out of range '5'
ERROR: 0:104: 'constructor' : array constructor must have at least one argument
ERROR: 0:104: '=' : cannot convert from ' const float' to ' global unsized 1-element array of int'
ERROR: 0:106: 'constructor' : array argument must be sized
ERROR: 26 compilation errors. No code generated.
ERROR: 0:111: '[' : array must be redeclared with a size before being indexed with a variable
ERROR: 0:111: 'variable indexing sampler array' : not supported with this profile: none
ERROR: 28 compilation errors. No code generated.
Shader version: 130
......@@ -68,21 +70,21 @@ ERROR: node is still EOpNull!
0:21 4.000000
0:24 move second child to first child ( temp float)
0:24 direct index ( temp float)
0:24 'gu' ( global unsized 4-element array of float)
0:24 'gu' ( global runtime-sized array of float)
0:24 Constant:
0:24 2 (const int)
0:24 Constant:
0:24 4.000000
0:26 move second child to first child ( temp float)
0:26 direct index ( temp float)
0:26 'gu' ( global unsized 4-element array of float)
0:26 'gu' ( global runtime-sized array of float)
0:26 Constant:
0:26 3 (const int)
0:26 Constant:
0:26 3.000000
0:27 move second child to first child ( temp float)
0:27 indirect index ( temp float)
0:27 'gu' ( global unsized 4-element array of float)
0:27 'gu' ( global runtime-sized array of float)
0:27 'a' ( uniform int)
0:27 Constant:
0:27 5.000000
......@@ -91,7 +93,7 @@ ERROR: node is still EOpNull!
0:29 Function Call: foo(f1[5]; ( global 4-element array of float)
0:29 'g5' ( global 5-element array of float)
0:30 'g5' ( global 5-element array of float)
0:31 'gu' ( global unsized 4-element array of float)
0:31 'gu' ( global runtime-sized array of float)
0:33 Constant:
0:33 0.000000
0:34 Function Call: bar(f1[5]; ( global void)
......@@ -108,7 +110,7 @@ ERROR: node is still EOpNull!
0:36 true case
0:37 move second child to first child ( temp float)
0:37 direct index ( temp float)
0:37 'gu' ( global unsized 4-element array of float)
0:37 'gu' ( global runtime-sized array of float)
0:37 Constant:
0:37 0 (const int)
0:37 Constant:
......@@ -264,8 +266,14 @@ ERROR: node is still EOpNull!
0:106 'b' ( global float)
0:106 Constant:
0:106 0.000000
0:109 Function Definition: foo4( ( global void)
0:109 Function Parameters:
0:111 Sequence
0:111 indirect index ( temp sampler2D)
0:111 's2d' ( uniform runtime-sized array of sampler2D)
0:111 'a' ( uniform int)
0:? Linker Objects
0:? 'gu' ( global unsized 4-element array of float)
0:? 'gu' ( global runtime-sized array of float)
0:? 'g4' ( global 4-element array of float)
0:? 'g5' ( global 5-element array of float)
0:? 'a' ( uniform int)
......@@ -275,6 +283,7 @@ ERROR: node is still EOpNull!
0:? 'i' ( global unsized 1-element array of int)
0:? 'emptyA' ( global unsized 1-element array of float)
0:? 'b' ( global float)
0:? 's2d' ( uniform runtime-sized array of sampler2D)
Linked fragment stage:
......@@ -320,21 +329,21 @@ ERROR: node is still EOpNull!
0:21 4.000000
0:24 move second child to first child ( temp float)
0:24 direct index ( temp float)
0:24 'gu' ( global 4-element array of float)
0:24 'gu' ( global runtime-sized array of float)
0:24 Constant:
0:24 2 (const int)
0:24 Constant:
0:24 4.000000
0:26 move second child to first child ( temp float)
0:26 direct index ( temp float)
0:26 'gu' ( global 4-element array of float)
0:26 'gu' ( global runtime-sized array of float)
0:26 Constant:
0:26 3 (const int)
0:26 Constant:
0:26 3.000000
0:27 move second child to first child ( temp float)
0:27 indirect index ( temp float)
0:27 'gu' ( global 4-element array of float)
0:27 'gu' ( global runtime-sized array of float)
0:27 'a' ( uniform int)
0:27 Constant:
0:27 5.000000
......@@ -343,7 +352,7 @@ ERROR: node is still EOpNull!
0:29 Function Call: foo(f1[5]; ( global 4-element array of float)
0:29 'g5' ( global 5-element array of float)
0:30 'g5' ( global 5-element array of float)
0:31 'gu' ( global 4-element array of float)
0:31 'gu' ( global runtime-sized array of float)
0:33 Constant:
0:33 0.000000
0:34 Function Call: bar(f1[5]; ( global void)
......@@ -360,7 +369,7 @@ ERROR: node is still EOpNull!
0:36 true case
0:37 move second child to first child ( temp float)
0:37 direct index ( temp float)
0:37 'gu' ( global 4-element array of float)
0:37 'gu' ( global runtime-sized array of float)
0:37 Constant:
0:37 0 (const int)
0:37 Constant:
......@@ -452,7 +461,7 @@ ERROR: node is still EOpNull!
0:106 Constant:
0:106 0.000000
0:? Linker Objects
0:? 'gu' ( global 4-element array of float)
0:? 'gu' ( global runtime-sized array of float)
0:? 'g4' ( global 4-element array of float)
0:? 'g5' ( global 5-element array of float)
0:? 'a' ( uniform int)
......@@ -462,4 +471,5 @@ ERROR: node is still EOpNull!
0:? 'i' ( global 1-element array of int)
0:? 'emptyA' ( global 1-element array of float)
0:? 'b' ( global float)
0:? 's2d' ( uniform runtime-sized array of sampler2D)
......@@ -470,7 +470,7 @@ public:
// Drop just the storage qualification, which perhaps should
// never be done, as it is fundamentally inconsistent, but need to
// explore what downstream consumers need.
// E.g., in a deference, it is an inconsistency between:
// E.g., in a dereference, it is an inconsistency between:
// A) partially dereferenced resource is still in the storage class it started in
// B) partially dereferenced resource is a new temporary object
// If A, then nothing should change, if B, then everything should change, but this is half way.
......@@ -1354,9 +1354,11 @@ public:
virtual bool isVector() const { return vectorSize > 1 || vector1; }
virtual bool isMatrix() const { return matrixCols ? true : false; }
virtual bool isArray() const { return arraySizes != nullptr; }
virtual bool isExplicitlySizedArray() const { return isArray() && getOuterArraySize() != UnsizedArraySize; }
virtual bool isImplicitlySizedArray() const { return isArray() && getOuterArraySize() == UnsizedArraySize && qualifier.storage != EvqBuffer; }
virtual bool isRuntimeSizedArray() const { return isArray() && getOuterArraySize() == UnsizedArraySize && qualifier.storage == EvqBuffer; }
virtual bool isSizedArray() const { return isArray() && arraySizes->isSized(); }
virtual bool isUnsizedArray() const { return isArray() && !arraySizes->isSized(); }
virtual bool isArrayVariablyIndexed() const { assert(isArray()); return arraySizes->isVariablyIndexed(); }
virtual void setArrayVariablyIndexed() { assert(isArray()); arraySizes->setVariablyIndexed(); }
virtual void updateImplicitArraySize(int size) { assert(isArray()); arraySizes->updateImplicitSize(size); }
virtual bool isStruct() const { return structure != nullptr; }
virtual bool isFloatingDomain() const { return basicType == EbtFloat || basicType == EbtDouble || basicType == EbtFloat16; }
virtual bool isIntegerDomain() const
......@@ -1414,10 +1416,10 @@ public:
return contains([this](const TType* t) { return t != this && t->isStruct(); } );
}
// Recursively check the structure for any implicitly-sized arrays, needed for triggering a copyUp().
virtual bool containsImplicitlySizedArray() const
// Recursively check the structure for any unsized arrays, needed for triggering a copyUp().
virtual bool containsUnsizedArray() const
{
return contains([](const TType* t) { return t->isImplicitlySizedArray(); } );
return contains([](const TType* t) { return t->isUnsizedArray(); } );
}
virtual bool containsOpaque() const
......@@ -1510,16 +1512,22 @@ public:
}
}
void changeOuterArraySize(int s) { arraySizes->changeOuterSize(s); }
void setImplicitArraySize(int s) { arraySizes->setImplicitSize(s); }
// Recursively make the implicit array size the explicit array size, through the type tree.
void adoptImplicitArraySizes()
// Recursively make the implicit array size the explicit array size.
// Expicit arrays are compile-time or link-time sized, never run-time sized.
// Sometimes, policy calls for an array to be run-time sized even if it was
// never variably indexed: Don't turn a 'skipNonvariablyIndexed' array into
// an explicit array.
void adoptImplicitArraySizes(bool skipNonvariablyIndexed)
{
if (isImplicitlySizedArray())
if (isUnsizedArray() && !(skipNonvariablyIndexed || isArrayVariablyIndexed()))
changeOuterArraySize(getImplicitArraySize());
if (isStruct()) {
for (int i = 0; i < (int)structure->size(); ++i)
(*structure)[i].type->adoptImplicitArraySizes();
if (isStruct() && structure->size() > 0) {
int lastMember = (int)structure->size() - 1;
for (int i = 0; i < lastMember; ++i)
(*structure)[i].type->adoptImplicitArraySizes(false);
// implement the "last member of an SSBO" policy
(*structure)[lastMember].type->adoptImplicitArraySizes(getQualifier().storage == EvqBuffer);
}
}
......@@ -1686,17 +1694,21 @@ public:
if (isArray()) {
for(int i = 0; i < (int)arraySizes->getNumDims(); ++i) {
int size = arraySizes->getDimSize(i);
if (size == UnsizedArraySize) {
appendStr(" unsized");
if (i == 0) {
if (size == UnsizedArraySize && i == 0 && arraySizes->isVariablyIndexed())
appendStr(" runtime-sized array of");
else {
if (size == UnsizedArraySize) {
appendStr(" unsized");
if (i == 0) {
appendStr(" ");
appendInt(arraySizes->getImplicitSize());
}
} else {
appendStr(" ");
appendInt(arraySizes->getImplicitSize());
appendInt(arraySizes->getDimSize(i));
}
} else {
appendStr(" ");
appendInt(arraySizes->getDimSize(i));
appendStr("-element array of");
}
appendStr("-element array of");
}
}
if (qualifier.precision != EpqNone) {
......
......@@ -41,6 +41,8 @@
#ifndef _ARRAYS_INCLUDED
#define _ARRAYS_INCLUDED
#include <algorithm>
namespace glslang {
// This is used to mean there is no size yet (unsized), it is waiting to get a size from somewhere else.
......@@ -220,12 +222,13 @@ protected:
struct TArraySizes {
POOL_ALLOCATOR_NEW_DELETE(GetThreadPoolAllocator())
TArraySizes() : implicitArraySize(1) { }
TArraySizes() : implicitArraySize(1), variablyIndexed(false) { }
// For breaking into two non-shared copies, independently modifiable.
TArraySizes& operator=(const TArraySizes& from)
{
implicitArraySize = from.implicitArraySize;
variablyIndexed = from.variablyIndexed;
sizes = from.sizes;
return *this;
......@@ -254,9 +257,9 @@ struct TArraySizes {
void addInnerSize(TArraySize pair) { sizes.push_back(pair.size, pair.node); }
void addInnerSizes(const TArraySizes& s) { sizes.push_back(s.sizes); }
void changeOuterSize(int s) { sizes.changeFront((unsigned)s); }
int getImplicitSize() const { return (int)implicitArraySize; }
void setImplicitSize(int s) { implicitArraySize = s; }
bool isInnerImplicit() const
int getImplicitSize() const { return implicitArraySize; }
void updateImplicitSize(int s) { implicitArraySize = std::max(implicitArraySize, s); }
bool isInnerUnsized() const
{
for (int d = 1; d < sizes.size(); ++d) {
if (sizes.getDimSize(d) == (unsigned)UnsizedArraySize)
......@@ -265,7 +268,7 @@ struct TArraySizes {
return false;
}
bool clearInnerImplicit()
bool clearInnerUnsized()
{
for (int d = 1; d < sizes.size(); ++d) {
if (sizes.getDimSize(d) == (unsigned)UnsizedArraySize)
......@@ -288,7 +291,8 @@ struct TArraySizes {
return sizes.getDimNode(0) != nullptr;
}
bool isImplicit() const { return getOuterSize() == UnsizedArraySize || isInnerImplicit(); }
bool hasUnsized() const { return getOuterSize() == UnsizedArraySize || isInnerUnsized(); }
bool isSized() const { return getOuterSize() != UnsizedArraySize; }
void dereference() { sizes.pop_front(); }
void copyDereferenced(const TArraySizes& rhs)
{
......@@ -311,6 +315,9 @@ struct TArraySizes {
return true;
}
void setVariablyIndexed() { variablyIndexed = true; }
bool isVariablyIndexed() const { return variablyIndexed; }
bool operator==(const TArraySizes& rhs) { return sizes == rhs.sizes; }
bool operator!=(const TArraySizes& rhs) { return sizes != rhs.sizes; }
......@@ -319,9 +326,12 @@ protected:
TArraySizes(const TArraySizes&);
// for tracking maximum referenced index, before an explicit size is given
// applies only to the outer-most dimension
// For tracking maximum referenced compile-time constant index.
// Applies only to the outer-most dimension. Potentially becomes
// the implicit size of the array, if not variably indexed and
// otherwise legal.
int implicitArraySize;
bool variablyIndexed; // true if array is indexed with a non compile-time constant
};
} // end namespace glslang
......
......@@ -729,7 +729,11 @@ enum TOperator {
// Array operators
//
EOpArrayLength, // "Array" distinguishes from length(v) built-in function, but it applies to vectors and matrices as well.
// Can apply to arrays, vectors, or matrices.
// Can be decomposed to a constant at compile time, but this does not always happen,
// due to link-time effects. So, consumer can expect either a link-time sized or
// run-time sized array.
EOpArrayLength,
//
// Image operations
......
......@@ -243,7 +243,7 @@ void TParseContextBase::checkIndex(const TSourceLoc& loc, const TType& type, int
error(loc, "", "[", "index out of range '%d'", index);
index = 0;
} else if (type.isArray()) {
if (type.isExplicitlySizedArray() && index >= type.getOuterArraySize()) {
if (type.isSizedArray() && index >= type.getOuterArraySize()) {
error(loc, "", "[", "array index out of range '%d'", index);
index = type.getOuterArraySize() - 1;
}
......
......@@ -348,6 +348,7 @@ public:
void samplerCheck(const TSourceLoc&, const TType&, const TString& identifier, TIntermTyped* initializer);
void atomicUintCheck(const TSourceLoc&, const TType&, const TString& identifier);
void transparentOpaqueCheck(const TSourceLoc&, const TType&, const TString& identifier);
void memberQualifierCheck(glslang::TPublicType&);
void globalQualifierFixCheck(const TSourceLoc&, TQualifier&);
void globalQualifierTypeCheck(const TSourceLoc&, const TQualifier&, const TPublicType&);
bool structQualifierErrorCheck(const TSourceLoc&, const TPublicType& pType);
......@@ -360,7 +361,7 @@ public:
bool containsFieldWithBasicType(const TType& type ,TBasicType basicType);
TSymbol* redeclareBuiltinVariable(const TSourceLoc&, const TString&, const TQualifier&, const TShaderQualifiers&);
void redeclareBuiltinBlock(const TSourceLoc&, TTypeList& typeList, const TString& blockName, const TString* instanceName, TArraySizes* arraySizes);
void paramCheckFix(const TSourceLoc&, const TStorageQualifier&, TType& type);
void paramCheckFixStorage(const TSourceLoc&, const TStorageQualifier&, TType& type);
void paramCheckFix(const TSourceLoc&, const TQualifier&, TType& type);
void nestedBlockCheck(const TSourceLoc&);
void nestedStructCheck(const TSourceLoc&);
......@@ -408,7 +409,6 @@ public:
void wrapupSwitchSubsequence(TIntermAggregate* statements, TIntermNode* branchNode);
TIntermNode* addSwitch(const TSourceLoc&, TIntermTyped* expression, TIntermAggregate* body);
void updateImplicitArraySize(const TSourceLoc&, TIntermNode*, int index);
TAttributeType attributeFromName(const TString& name) const;
TAttributes* makeAttributes(const TString& identifier) const;
TAttributes* makeAttributes(const TString& identifier, TIntermNode* node) const;
......
......@@ -968,7 +968,7 @@ parameter_declaration
$$ = $1;
parseContext.parameterTypeCheck($1.loc, EvqIn, *$1.param.type);
parseContext.paramCheckFix($1.loc, EvqTemporary, *$$.param.type);
parseContext.paramCheckFixStorage($1.loc, EvqTemporary, *$$.param.type);
parseContext.precisionQualifierCheck($$.loc, $$.param.type->getBasicType(), $$.param.type->getQualifier());
}
//
......@@ -988,7 +988,7 @@ parameter_declaration
$$ = $1;
parseContext.parameterTypeCheck($1.loc, EvqIn, *$1.param.type);
parseContext.paramCheckFix($1.loc, EvqTemporary, *$$.param.type);
parseContext.paramCheckFixStorage($1.loc, EvqTemporary, *$$.param.type);
parseContext.precisionQualifierCheck($$.loc, $$.param.type->getBasicType(), $$.param.type->getQualifier());
}
;
......@@ -3121,7 +3121,6 @@ struct_declaration
}
}
| type_qualifier type_specifier struct_declarator_list SEMICOLON {
parseContext.globalQualifierFixCheck($1.loc, $1.qualifier);
if ($2.arraySizes) {
parseContext.profileRequires($2.loc, ENoProfile, 120, E_GL_3DL_array_objects, "arrayed type");
parseContext.profileRequires($2.loc, EEsProfile, 300, 0, "arrayed type");
......@@ -3131,7 +3130,7 @@ struct_declaration
$$ = $3;
parseContext.checkNoShaderLayouts($1.loc, $1.shaderQualifiers);
parseContext.memberQualifierCheck($1);
parseContext.voidErrorCheck($2.loc, (*$3)[0].type->getFieldName(), $2.basicType);
parseContext.mergeQualifiers($2.loc, $2.qualifier, $1.qualifier, true);
parseContext.precisionQualifierCheck($2.loc, $2.basicType, $2.qualifier);
......
......@@ -268,10 +268,12 @@ void TIntermediate::mergeLinkerObjects(TInfoSink& infoSink, TIntermSequence& lin
// Recursively merge the implicit array sizes through the objects' respective type trees.
void TIntermediate::mergeImplicitArraySizes(TType& type, const TType& unitType)
{
if (type.isImplicitlySizedArray() && unitType.isArray()) {
int newImplicitArraySize = unitType.isImplicitlySizedArray() ? unitType.getImplicitArraySize() : unitType.getOuterArraySize();
if (newImplicitArraySize > type.getImplicitArraySize ())
type.setImplicitArraySize(newImplicitArraySize);
if (type.isUnsizedArray() && unitType.isArray()) {
int newImplicitArraySize = unitType.isSizedArray() ? unitType.getOuterArraySize() :
unitType.getImplicitArraySize();
type.updateImplicitArraySize(type.getImplicitArraySize());
if (unitType.isArrayVariablyIndexed())
type.setArrayVariablyIndexed();
}
// Type mismatches are caught and reported after this, just be careful for now.
......@@ -511,7 +513,9 @@ void TIntermediate::finalCheck(TInfoSink& infoSink, bool keepUncalled)
virtual void visitSymbol(TIntermSymbol* symbol)
{
// Implicitly size arrays.
symbol->getWritableType().adoptImplicitArraySizes();
// If an unsized array is left as unsized, it effectively
// becomes run-time sized.
symbol->getWritableType().adoptImplicitArraySizes(false);
}
} finalLinkTraverser;
......@@ -766,7 +770,7 @@ int TIntermediate::addUsedLocation(const TQualifier& qualifier, const TType& typ
int size;
if (qualifier.isUniformOrBuffer()) {
if (type.isExplicitlySizedArray())
if (type.isSizedArray())
size = type.getCumulativeArraySize();
else
size = 1;
......@@ -914,12 +918,12 @@ int TIntermediate::computeTypeLocationSize(const TType& type, EShLanguage stage)
// consecutive locations..."
if (type.isArray()) {
// TODO: perf: this can be flattened by using getCumulativeArraySize(), and a deref that discards all arrayness
// TODO: are there valid cases of having an unsized array with a location? If so, running this code too early.
TType elementType(type, 0);
if (type.isImplicitlySizedArray()) {
// TODO: are there valid cases of having an implicitly-sized array with a location? If so, running this code too early.
return computeTypeLocationSize(elementType, stage);
} else
if (type.isSizedArray())
return type.getOuterArraySize() * computeTypeLocationSize(elementType, stage);
else
return computeTypeLocationSize(elementType, stage);
}
// "The locations consumed by block and structure members are determined by applying the rules above
......@@ -971,11 +975,12 @@ int TIntermediate::computeTypeUniformLocationSize(const TType& type)
if (type.isArray()) {
// TODO: perf: this can be flattened by using getCumulativeArraySize(), and a deref that discards all arrayness
TType elementType(type, 0);
if (type.isImplicitlySizedArray()) {
if (type.isSizedArray()) {
return type.getOuterArraySize() * computeTypeUniformLocationSize(elementType);
} else {
// TODO: are there valid cases of having an implicitly-sized array with a location? If so, running this code too early.
return computeTypeUniformLocationSize(elementType);
} else
return type.getOuterArraySize() * computeTypeUniformLocationSize(elementType);
}
}
// "Each subsequent inner-most member or element gets incremental
......@@ -1036,7 +1041,7 @@ unsigned int TIntermediate::computeTypeXfbSize(const TType& type, bool& contains
if (type.isArray()) {
// TODO: perf: this can be flattened by using getCumulativeArraySize(), and a deref that discards all arrayness
assert(type.isExplicitlySizedArray());
assert(type.isSizedArray());
TType elementType(type, 0);
return type.getOuterArraySize() * computeTypeXfbSize(elementType, containsDouble);
}
......
......@@ -2569,8 +2569,8 @@ bool HlslGrammar::acceptParameterDeclaration(TFunction& function)
TArraySizes* arraySizes = nullptr;
acceptArraySpecifier(arraySizes);
if (arraySizes) {
if (arraySizes->isImplicit()) {
parseContext.error(token.loc, "function parameter array cannot be implicitly sized", "", "");
if (arraySizes->hasUnsized()) {
parseContext.error(token.loc, "function parameter requires array size", "[]", "");
return false;
}
......
......@@ -164,8 +164,6 @@ public:
void wrapupSwitchSubsequence(TIntermAggregate* statements, TIntermNode* branchNode);
TIntermNode* addSwitch(const TSourceLoc&, TIntermTyped* expression, TIntermAggregate* body, const TAttributes&);
void updateImplicitArraySize(const TSourceLoc&, TIntermNode*, int index);
void nestLooping() { ++loopNestingLevel; }
void unnestLooping() { --loopNestingLevel; }
void nestAnnotations() { ++annotationNestingLevel; }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment