Commit 47777271 by John Kessenich

Implicit Arrays: Use much simpler method to update implicit array sizes.

The previous overly complicated method was error prone, and used by new paths, causing a crash.
parent 21c53ecf
#version 310 es
precision highp float;
layout(location=0) out float o;
struct S { float f; };
buffer b1 { S s[]; };
buffer b2 { S s[]; } b2name;
buffer b3 { S s[]; } b3name[];
buffer b4 { S s[]; } b4name[4];
void main()
{
o = s[5].f;
o += b2name.s[6].f;
o += b3name[3].s[7].f;
o += b4name[2].s[8].f;
}
...@@ -35,14 +35,14 @@ ERROR: node is still EOpNull! ...@@ -35,14 +35,14 @@ ERROR: node is still EOpNull!
0:7 move second child to first child ( temp highp int) 0:7 move second child to first child ( temp highp int)
0:7 'o' (layout( location=0) smooth out 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 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 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 1-element array of highp int a}) 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 Constant:
0:7 0 (const int) 0:7 0 (const int)
0:7 Constant: 0:7 Constant:
0:7 2 (const int) 0:7 2 (const int)
0:? Linker Objects 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:? 'o' (layout( location=0) smooth out highp int)
0:? 'gl_VertexID' ( gl_VertexId highp int VertexId) 0:? 'gl_VertexID' ( gl_VertexId highp int VertexId)
0:? 'gl_InstanceID' ( gl_InstanceId highp int InstanceId) 0:? 'gl_InstanceID' ( gl_InstanceId highp int InstanceId)
......
310runtimeArray.vert
ERROR: 0:9: '' : array size required
ERROR: 1 compilation errors. No code generated.
Shader version: 310
ERROR: node is still EOpNull!
0:12 Function Definition: main( ( global void)
0:12 Function Parameters:
0:14 Sequence
0:14 move second child to first child ( temp highp float)
0:14 'o' (layout( location=0) smooth out highp float)
0:14 f: direct index for structure ( global highp float)
0:14 direct index (layout( column_major shared) temp structure{ global highp float f})
0:14 s: direct index for structure (layout( column_major shared) buffer implicitly-sized array of structure{ global highp float f})
0:14 'anon@0' (layout( column_major shared) buffer block{layout( column_major shared) buffer implicitly-sized array of structure{ global highp float f} s})
0:14 Constant:
0:14 0 (const uint)
0:14 Constant:
0:14 5 (const int)
0:14 Constant:
0:14 0 (const int)
0:15 add second child into first child ( temp highp float)
0:15 'o' (layout( location=0) smooth out highp float)
0:15 f: direct index for structure ( global highp float)
0:15 direct index (layout( column_major shared) temp structure{ global highp float f})
0:15 s: direct index for structure (layout( column_major shared) buffer implicitly-sized array of structure{ global highp float f})
0:15 'b2name' (layout( column_major shared) buffer block{layout( column_major shared) buffer implicitly-sized array of structure{ global highp float f} s})
0:15 Constant:
0:15 0 (const int)
0:15 Constant:
0:15 6 (const int)
0:15 Constant:
0:15 0 (const int)
0:16 add second child into first child ( temp highp float)
0:16 'o' (layout( location=0) smooth out highp float)
0:16 f: direct index for structure ( global highp float)
0:16 direct index (layout( column_major shared) temp structure{ global highp float f})
0:16 s: direct index for structure (layout( column_major shared) buffer implicitly-sized array of structure{ global highp float f})
0:16 direct index (layout( column_major shared) temp block{layout( column_major shared) buffer implicitly-sized array of structure{ global highp float f} s})
0:16 'b3name' (layout( column_major shared) buffer implicitly-sized array of block{layout( column_major shared) buffer implicitly-sized array of structure{ global highp float f} s})
0:16 Constant:
0:16 3 (const int)
0:16 Constant:
0:16 0 (const int)
0:16 Constant:
0:16 7 (const int)
0:16 Constant:
0:16 0 (const int)
0:17 add second child into first child ( temp highp float)
0:17 'o' (layout( location=0) smooth out highp float)
0:17 f: direct index for structure ( global highp float)
0:17 direct index (layout( column_major shared) temp structure{ global highp float f})
0:17 s: direct index for structure (layout( column_major shared) buffer implicitly-sized array of structure{ global highp float f})
0:17 direct index (layout( column_major shared) temp block{layout( column_major shared) buffer implicitly-sized array of structure{ global highp float f} s})
0:17 'b4name' (layout( column_major shared) buffer 4-element array of block{layout( column_major shared) buffer implicitly-sized array of structure{ global highp float f} s})
0:17 Constant:
0:17 2 (const int)
0:17 Constant:
0:17 0 (const int)
0:17 Constant:
0:17 8 (const int)
0:17 Constant:
0:17 0 (const int)
0:? Linker Objects
0:? 'o' (layout( location=0) smooth out highp float)
0:? 'anon@0' (layout( column_major shared) buffer block{layout( column_major shared) buffer implicitly-sized array of structure{ global highp float f} s})
0:? 'b2name' (layout( column_major shared) buffer block{layout( column_major shared) buffer implicitly-sized array of structure{ global highp float f} s})
0:? 'b3name' (layout( column_major shared) buffer implicitly-sized array of block{layout( column_major shared) buffer implicitly-sized array of structure{ global highp float f} s})
0:? 'b4name' (layout( column_major shared) buffer 4-element array of block{layout( column_major shared) buffer implicitly-sized array of structure{ global highp float f} s})
0:? 'gl_VertexID' ( gl_VertexId highp int VertexId)
0:? 'gl_InstanceID' ( gl_InstanceId highp int InstanceId)
Linked vertex stage:
Shader version: 310
ERROR: node is still EOpNull!
0:12 Function Definition: main( ( global void)
0:12 Function Parameters:
0:14 Sequence
0:14 move second child to first child ( temp highp float)
0:14 'o' (layout( location=0) smooth out highp float)
0:14 f: direct index for structure ( global highp float)
0:14 direct index (layout( column_major shared) temp structure{ global highp float f})
0:14 s: direct index for structure (layout( column_major shared) buffer implicitly-sized array of structure{ global highp float f})
0:14 'anon@0' (layout( column_major shared) buffer block{layout( column_major shared) buffer implicitly-sized array of structure{ global highp float f} s})
0:14 Constant:
0:14 0 (const uint)
0:14 Constant:
0:14 5 (const int)
0:14 Constant:
0:14 0 (const int)
0:15 add second child into first child ( temp highp float)
0:15 'o' (layout( location=0) smooth out highp float)
0:15 f: direct index for structure ( global highp float)
0:15 direct index (layout( column_major shared) temp structure{ global highp float f})
0:15 s: direct index for structure (layout( column_major shared) buffer implicitly-sized array of structure{ global highp float f})
0:15 'b2name' (layout( column_major shared) buffer block{layout( column_major shared) buffer implicitly-sized array of structure{ global highp float f} s})
0:15 Constant:
0:15 0 (const int)
0:15 Constant:
0:15 6 (const int)
0:15 Constant:
0:15 0 (const int)
0:16 add second child into first child ( temp highp float)
0:16 'o' (layout( location=0) smooth out highp float)
0:16 f: direct index for structure ( global highp float)
0:16 direct index (layout( column_major shared) temp structure{ global highp float f})
0:16 s: direct index for structure (layout( column_major shared) buffer implicitly-sized array of structure{ global highp float f})
0:16 direct index (layout( column_major shared) temp block{layout( column_major shared) buffer implicitly-sized array of structure{ global highp float f} s})
0:16 'b3name' (layout( column_major shared) buffer 4-element array of block{layout( column_major shared) buffer implicitly-sized array of structure{ global highp float f} s})
0:16 Constant:
0:16 3 (const int)
0:16 Constant:
0:16 0 (const int)
0:16 Constant:
0:16 7 (const int)
0:16 Constant:
0:16 0 (const int)
0:17 add second child into first child ( temp highp float)
0:17 'o' (layout( location=0) smooth out highp float)
0:17 f: direct index for structure ( global highp float)
0:17 direct index (layout( column_major shared) temp structure{ global highp float f})
0:17 s: direct index for structure (layout( column_major shared) buffer implicitly-sized array of structure{ global highp float f})
0:17 direct index (layout( column_major shared) temp block{layout( column_major shared) buffer implicitly-sized array of structure{ global highp float f} s})
0:17 'b4name' (layout( column_major shared) buffer 4-element array of block{layout( column_major shared) buffer implicitly-sized array of structure{ global highp float f} s})
0:17 Constant:
0:17 2 (const int)
0:17 Constant:
0:17 0 (const int)
0:17 Constant:
0:17 8 (const int)
0:17 Constant:
0:17 0 (const int)
0:? Linker Objects
0:? 'o' (layout( location=0) smooth out highp float)
0:? 'anon@0' (layout( column_major shared) buffer block{layout( column_major shared) buffer implicitly-sized array of structure{ global highp float f} s})
0:? 'b2name' (layout( column_major shared) buffer block{layout( column_major shared) buffer implicitly-sized array of structure{ global highp float f} s})
0:? 'b3name' (layout( column_major shared) buffer 4-element array of block{layout( column_major shared) buffer implicitly-sized array of structure{ global highp float f} s})
0:? 'b4name' (layout( column_major shared) buffer 4-element array of block{layout( column_major shared) buffer implicitly-sized array of structure{ global highp float f} s})
0:? 'gl_VertexID' ( gl_VertexId highp int VertexId)
0:? 'gl_InstanceID' ( gl_InstanceId highp int InstanceId)
...@@ -1387,6 +1387,7 @@ public: ...@@ -1387,6 +1387,7 @@ public:
virtual bool isUnsizedArray() const { return isArray() && !arraySizes->isSized(); } virtual bool isUnsizedArray() const { return isArray() && !arraySizes->isSized(); }
virtual bool isArrayVariablyIndexed() const { assert(isArray()); return arraySizes->isVariablyIndexed(); } virtual bool isArrayVariablyIndexed() const { assert(isArray()); return arraySizes->isVariablyIndexed(); }
virtual void setArrayVariablyIndexed() { assert(isArray()); arraySizes->setVariablyIndexed(); } 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 isStruct() const { return structure != nullptr; }
virtual bool isFloatingDomain() const { return basicType == EbtFloat || basicType == EbtDouble || basicType == EbtFloat16; } virtual bool isFloatingDomain() const { return basicType == EbtFloat || basicType == EbtDouble || basicType == EbtFloat16; }
virtual bool isIntegerDomain() const virtual bool isIntegerDomain() const
...@@ -1529,7 +1530,6 @@ public: ...@@ -1529,7 +1530,6 @@ public:
arraySizes->addOuterSizes(s); arraySizes->addOuterSizes(s);
} }
void changeOuterArraySize(int s) { arraySizes->changeOuterSize(s); } void changeOuterArraySize(int s) { arraySizes->changeOuterSize(s); }
void setImplicitArraySize(int s) { arraySizes->setImplicitSize(s); }
// Recursively make the implicit array size the explicit array size. // Recursively make the implicit array size the explicit array size.
// Expicit arrays are compile-time or link-time sized, never run-time sized. // Expicit arrays are compile-time or link-time sized, never run-time sized.
......
...@@ -41,6 +41,8 @@ ...@@ -41,6 +41,8 @@
#ifndef _ARRAYS_INCLUDED #ifndef _ARRAYS_INCLUDED
#define _ARRAYS_INCLUDED #define _ARRAYS_INCLUDED
#include <algorithm>
namespace glslang { namespace glslang {
// This is used to mean there is no size yet (unsized), it is waiting to get a size from somewhere else. // This is used to mean there is no size yet (unsized), it is waiting to get a size from somewhere else.
...@@ -254,8 +256,8 @@ struct TArraySizes { ...@@ -254,8 +256,8 @@ struct TArraySizes {
void addInnerSize(int s, TIntermTyped* n) { sizes.push_back((unsigned)s, n); } void addInnerSize(int s, TIntermTyped* n) { sizes.push_back((unsigned)s, n); }
void addInnerSize(TArraySize pair) { sizes.push_back(pair.size, pair.node); } void addInnerSize(TArraySize pair) { sizes.push_back(pair.size, pair.node); }
void changeOuterSize(int s) { sizes.changeFront((unsigned)s); } void changeOuterSize(int s) { sizes.changeFront((unsigned)s); }
int getImplicitSize() const { return (int)implicitArraySize; } int getImplicitSize() const { return implicitArraySize; }
void setImplicitSize(int s) { implicitArraySize = s; } void updateImplicitSize(int s) { implicitArraySize = std::max(implicitArraySize, s); }
bool isInnerUnsized() const bool isInnerUnsized() const
{ {
for (int d = 1; d < sizes.size(); ++d) { for (int d = 1; d < sizes.size(); ++d) {
......
...@@ -377,7 +377,7 @@ TIntermTyped* TParseContext::handleBracketDereference(const TSourceLoc& loc, TIn ...@@ -377,7 +377,7 @@ TIntermTyped* TParseContext::handleBracketDereference(const TSourceLoc& loc, TIn
if (index->getQualifier().isFrontEndConstant()) { if (index->getQualifier().isFrontEndConstant()) {
if (base->getType().isUnsizedArray()) if (base->getType().isUnsizedArray())
updateImplicitArraySize(loc, base, indexValue); base->getWritableType().updateImplicitArraySize(indexValue + 1);
else else
checkIndex(loc, base->getType(), indexValue); checkIndex(loc, base->getType(), indexValue);
result = intermediate.addIndex(EOpIndexDirect, base, index, loc); result = intermediate.addIndex(EOpIndexDirect, base, index, loc);
...@@ -3283,66 +3283,6 @@ void TParseContext::declareArray(const TSourceLoc& loc, const TString& identifie ...@@ -3283,66 +3283,6 @@ void TParseContext::declareArray(const TSourceLoc& loc, const TString& identifie
checkIoArraysConsistency(loc); checkIoArraysConsistency(loc);
} }
void TParseContext::updateImplicitArraySize(const TSourceLoc& loc, TIntermNode *node, int index)
{
// maybe there is nothing to do...
TIntermTyped* typedNode = node->getAsTyped();
if (typedNode->getType().getImplicitArraySize() > index)
return;
// something to do...
// Figure out what symbol to lookup, as we will use its type to edit for the size change,
// as that type will be shared through shallow copies for future references.
TSymbol* symbol = nullptr;
int blockIndex = -1;
const TString* lookupName = nullptr;
if (node->getAsSymbolNode())
lookupName = &node->getAsSymbolNode()->getName();
else if (node->getAsBinaryNode()) {
const TIntermBinary* deref = node->getAsBinaryNode();
// This has to be the result of a block dereference, unless it's bad shader code
// If it's a uniform block, then an error will be issued elsewhere, but
// return early now to avoid crashing later in this function.
if (deref->getLeft()->getBasicType() != EbtBlock ||
deref->getLeft()->getType().getQualifier().storage == EvqUniform ||
deref->getRight()->getAsConstantUnion() == nullptr)
return;
const TIntermTyped* left = deref->getLeft();
const TIntermTyped* right = deref->getRight();
if (left->getAsBinaryNode()) {
left = left->getAsBinaryNode()->getLeft(); // Block array access
assert(left->isArray());
}
if (! left->getAsSymbolNode())
return;
blockIndex = right->getAsConstantUnion()->getConstArray()[0].getIConst();
lookupName = &left->getAsSymbolNode()->getName();
if (IsAnonymous(*lookupName))
lookupName = &(*left->getType().getStruct())[blockIndex].type->getFieldName();
}
// Lookup the symbol, should only fail if shader code is incorrect
symbol = symbolTable.find(*lookupName);
if (symbol == nullptr)
return;
if (symbol->getAsFunction()) {
error(loc, "array variable name expected", symbol->getName().c_str(), "");
return;
}
if (symbol->getType().isStruct() && blockIndex != -1)
(*symbol->getWritableType().getStruct())[blockIndex].type->setImplicitArraySize(index + 1);
else
symbol->getWritableType().setImplicitArraySize(index + 1);
}
// Returns true if the first argument to the #line directive is the line number for the next line. // 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 // Desktop, pre-version 3.30: "After processing this directive
......
...@@ -412,7 +412,6 @@ public: ...@@ -412,7 +412,6 @@ public:
void wrapupSwitchSubsequence(TIntermAggregate* statements, TIntermNode* branchNode); void wrapupSwitchSubsequence(TIntermAggregate* statements, TIntermNode* branchNode);
TIntermNode* addSwitch(const TSourceLoc&, TIntermTyped* expression, TIntermAggregate* body); TIntermNode* addSwitch(const TSourceLoc&, TIntermTyped* expression, TIntermAggregate* body);
void updateImplicitArraySize(const TSourceLoc&, TIntermNode*, int index);
TAttributeType attributeFromName(const TString& name) const; TAttributeType attributeFromName(const TString& name) const;
TAttributes* makeAttributes(const TString& identifier) const; TAttributes* makeAttributes(const TString& identifier) const;
TAttributes* makeAttributes(const TString& identifier, TIntermNode* node) const; TAttributes* makeAttributes(const TString& identifier, TIntermNode* node) const;
......
...@@ -271,8 +271,7 @@ void TIntermediate::mergeImplicitArraySizes(TType& type, const TType& unitType) ...@@ -271,8 +271,7 @@ void TIntermediate::mergeImplicitArraySizes(TType& type, const TType& unitType)
if (type.isUnsizedArray() && unitType.isArray()) { if (type.isUnsizedArray() && unitType.isArray()) {
int newImplicitArraySize = unitType.isSizedArray() ? unitType.getOuterArraySize() : int newImplicitArraySize = unitType.isSizedArray() ? unitType.getOuterArraySize() :
unitType.getImplicitArraySize(); unitType.getImplicitArraySize();
if (newImplicitArraySize > type.getImplicitArraySize ()) type.updateImplicitArraySize(type.getImplicitArraySize());
type.setImplicitArraySize(newImplicitArraySize);
if (unitType.isArrayVariablyIndexed()) if (unitType.isArrayVariablyIndexed())
type.setArrayVariablyIndexed(); type.setArrayVariablyIndexed();
} }
......
...@@ -106,6 +106,7 @@ INSTANTIATE_TEST_CASE_P( ...@@ -106,6 +106,7 @@ INSTANTIATE_TEST_CASE_P(
"310.tese", "310.tese",
"310implicitSizeArrayError.vert", "310implicitSizeArrayError.vert",
"310AofA.vert", "310AofA.vert",
"310runtimeArray.vert",
"320.comp", "320.comp",
"320.vert", "320.vert",
"320.geom", "320.geom",
......
...@@ -840,7 +840,7 @@ TIntermTyped* HlslParseContext::handleBracketDereference(const TSourceLoc& loc, ...@@ -840,7 +840,7 @@ TIntermTyped* HlslParseContext::handleBracketDereference(const TSourceLoc& loc,
} else { } else {
if (index->getQualifier().isFrontEndConstant()) { if (index->getQualifier().isFrontEndConstant()) {
if (base->getType().isUnsizedArray()) if (base->getType().isUnsizedArray())
updateImplicitArraySize(loc, base, indexValue); base->getWritableType().updateImplicitArraySize(indexValue + 1);
else else
checkIndex(loc, base->getType(), indexValue); checkIndex(loc, base->getType(), indexValue);
result = intermediate.addIndex(EOpIndexDirect, base, index, loc); result = intermediate.addIndex(EOpIndexDirect, base, index, loc);
...@@ -6698,52 +6698,6 @@ void HlslParseContext::declareArray(const TSourceLoc& loc, const TString& identi ...@@ -6698,52 +6698,6 @@ void HlslParseContext::declareArray(const TSourceLoc& loc, const TString& identi
existingType.updateArraySizes(type); existingType.updateArraySizes(type);
} }
void HlslParseContext::updateImplicitArraySize(const TSourceLoc& loc, TIntermNode *node, int index)
{
// maybe there is nothing to do...
TIntermTyped* typedNode = node->getAsTyped();
if (typedNode->getType().getImplicitArraySize() > index)
return;
// something to do...
// Figure out what symbol to lookup, as we will use its type to edit for the size change,
// as that type will be shared through shallow copies for future references.
TSymbol* symbol = nullptr;
int blockIndex = -1;
const TString* lookupName = nullptr;
if (node->getAsSymbolNode())
lookupName = &node->getAsSymbolNode()->getName();
else if (node->getAsBinaryNode()) {
const TIntermBinary* deref = node->getAsBinaryNode();
// This has to be the result of a block dereference, unless it's bad shader code
// If it's a uniform block, then an error will be issued elsewhere, but
// return early now to avoid crashing later in this function.
if (! deref->getLeft()->getAsSymbolNode() || deref->getLeft()->getBasicType() != EbtBlock ||
deref->getLeft()->getType().getQualifier().storage == EvqUniform ||
deref->getRight()->getAsConstantUnion() == nullptr)
return;
blockIndex = deref->getRight()->getAsConstantUnion()->getConstArray()[0].getIConst();
lookupName = &deref->getLeft()->getAsSymbolNode()->getName();
if (IsAnonymous(*lookupName))
lookupName = &(*deref->getLeft()->getType().getStruct())[blockIndex].type->getFieldName();
}
// Lookup the symbol, should only fail if shader code is incorrect
symbol = symbolTable.find(*lookupName);
if (symbol == nullptr)
return;
if (symbol->getAsFunction()) {
error(loc, "array variable name expected", symbol->getName().c_str(), "");
return;
}
symbol->getWritableType().setImplicitArraySize(index + 1);
}
// //
// Enforce non-initializer type/qualifier rules. // Enforce non-initializer type/qualifier rules.
// //
......
...@@ -165,8 +165,6 @@ public: ...@@ -165,8 +165,6 @@ public:
void wrapupSwitchSubsequence(TIntermAggregate* statements, TIntermNode* branchNode); void wrapupSwitchSubsequence(TIntermAggregate* statements, TIntermNode* branchNode);
TIntermNode* addSwitch(const TSourceLoc&, TIntermTyped* expression, TIntermAggregate* body, const TAttributes&); TIntermNode* addSwitch(const TSourceLoc&, TIntermTyped* expression, TIntermAggregate* body, const TAttributes&);
void updateImplicitArraySize(const TSourceLoc&, TIntermNode*, int index);
void nestLooping() { ++loopNestingLevel; } void nestLooping() { ++loopNestingLevel; }
void unnestLooping() { --loopNestingLevel; } void unnestLooping() { --loopNestingLevel; }
void nestAnnotations() { ++annotationNestingLevel; } 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