HLSL: Rationalize combination of type arrayness and name arrayness.

This commit is contained in:
John Kessenich 2016-09-27 14:38:57 -06:00
parent b1672fa0de
commit e82061de08
4 changed files with 43 additions and 45 deletions

View File

@ -2,5 +2,5 @@
// For the version, it uses the latest git tag followed by the number of commits. // For the version, it uses the latest git tag followed by the number of commits.
// For the date, it uses the current date (when then script is run). // For the date, it uses the current date (when then script is run).
#define GLSLANG_REVISION "Overload400-PrecQual.1507" #define GLSLANG_REVISION "Overload400-PrecQual.1523"
#define GLSLANG_DATE "25-Sep-2016" #define GLSLANG_DATE "27-Sep-2016"

View File

@ -271,7 +271,7 @@ bool HlslGrammar::acceptDeclaration(TIntermNode*& node)
// typedef // typedef
bool typedefDecl = acceptTokenClass(EHTokTypedef); bool typedefDecl = acceptTokenClass(EHTokTypedef);
TType type; TType declaredType;
// DX9 sampler declaration use a different syntax // DX9 sampler declaration use a different syntax
// DX9 shaders need to run through HLSL compiler (fxc) via a back compat mode, it isn't going to // DX9 shaders need to run through HLSL compiler (fxc) via a back compat mode, it isn't going to
@ -280,21 +280,21 @@ bool HlslGrammar::acceptDeclaration(TIntermNode*& node)
// As such, the sampler keyword in D3D10+ turns into an automatic sampler type, and is commonly used // As such, the sampler keyword in D3D10+ turns into an automatic sampler type, and is commonly used
// For that reason, this line is commented out // For that reason, this line is commented out
// if (acceptSamplerDeclarationDX9(type)) // if (acceptSamplerDeclarationDX9(declaredType))
// return true; // return true;
// fully_specified_type // fully_specified_type
if (! acceptFullySpecifiedType(type)) if (! acceptFullySpecifiedType(declaredType))
return false; return false;
if (type.getQualifier().storage == EvqTemporary && parseContext.symbolTable.atGlobalLevel()) { if (declaredType.getQualifier().storage == EvqTemporary && parseContext.symbolTable.atGlobalLevel()) {
if (type.getBasicType() == EbtSampler) { if (declaredType.getBasicType() == EbtSampler) {
// Sampler/textures are uniform by default (if no explicit qualifier is present) in // Sampler/textures are uniform by default (if no explicit qualifier is present) in
// HLSL. This line silently converts samplers *explicitly* declared static to uniform, // HLSL. This line silently converts samplers *explicitly* declared static to uniform,
// which is incorrect but harmless. // which is incorrect but harmless.
type.getQualifier().storage = EvqUniform; declaredType.getQualifier().storage = EvqUniform;
} else { } else {
type.getQualifier().storage = EvqGlobal; declaredType.getQualifier().storage = EvqGlobal;
} }
} }
@ -302,7 +302,7 @@ bool HlslGrammar::acceptDeclaration(TIntermNode*& node)
HlslToken idToken; HlslToken idToken;
while (acceptIdentifier(idToken)) { while (acceptIdentifier(idToken)) {
// function_parameters // function_parameters
TFunction& function = *new TFunction(idToken.string, type); TFunction& function = *new TFunction(idToken.string, declaredType);
if (acceptFunctionParameters(function)) { if (acceptFunctionParameters(function)) {
// post_decls // post_decls
acceptPostDecls(function.getWritableType().getQualifier()); acceptPostDecls(function.getWritableType().getQualifier());
@ -320,20 +320,38 @@ bool HlslGrammar::acceptDeclaration(TIntermNode*& node)
parseContext.handleFunctionDeclarator(idToken.loc, function, true); parseContext.handleFunctionDeclarator(idToken.loc, function, true);
} }
} else { } else {
// a variable declaration // A variable declaration.
// We can handle multiple variables per type declaration, so
// the number of types can expand when arrayness is different.
TType variableType;
variableType.shallowCopy(declaredType);
// array_specifier // recognize array_specifier
TArraySizes* arraySizes = nullptr; TArraySizes* arraySizes = nullptr;
acceptArraySpecifier(arraySizes); acceptArraySpecifier(arraySizes);
// Fix arrayness in the variableType
if (declaredType.isImplicitlySizedArray()) {
// Because "int[] a = int[2](...), b = int[3](...)" makes two arrays a and b
// of different sizes, for this case sharing the shallow copy of arrayness
// with the parseType oversubscribes it, so get a deep copy of the arrayness.
variableType.newArraySizes(declaredType.getArraySizes());
}
if (arraySizes || variableType.isArray()) {
// In the most general case, arrayness is potentially coming both from the
// declared type and from the variable: "int[] a[];" or just one or the other.
// Merge it all to the variableType, so all arrayness is part of the variableType.
parseContext.arrayDimMerge(variableType, arraySizes);
}
// samplers accept immediate sampler state // samplers accept immediate sampler state
if (type.getBasicType() == EbtSampler) { if (variableType.getBasicType() == EbtSampler) {
if (! acceptSamplerState()) if (! acceptSamplerState())
return false; return false;
} }
// post_decls // post_decls
acceptPostDecls(type.getQualifier()); acceptPostDecls(variableType.getQualifier());
// EQUAL assignment_expression // EQUAL assignment_expression
TIntermTyped* expressionNode = nullptr; TIntermTyped* expressionNode = nullptr;
@ -347,16 +365,16 @@ bool HlslGrammar::acceptDeclaration(TIntermNode*& node)
} }
if (typedefDecl) if (typedefDecl)
parseContext.declareTypedef(idToken.loc, *idToken.string, type, arraySizes); parseContext.declareTypedef(idToken.loc, *idToken.string, variableType, arraySizes);
else if (type.getBasicType() == EbtBlock) else if (variableType.getBasicType() == EbtBlock)
parseContext.declareBlock(idToken.loc, type, idToken.string); parseContext.declareBlock(idToken.loc, variableType, idToken.string);
else { else {
// Declare the variable and add any initializer code to the AST. // Declare the variable and add any initializer code to the AST.
// The top-level node is always made into an aggregate, as that's // The top-level node is always made into an aggregate, as that's
// historically how the AST has been. // historically how the AST has been.
node = intermediate.growAggregate(node, node = intermediate.growAggregate(node,
parseContext.declareVariable(idToken.loc, *idToken.string, type, parseContext.declareVariable(idToken.loc, *idToken.string, variableType,
arraySizes, expressionNode), expressionNode),
idToken.loc); idToken.loc);
} }
} }
@ -412,7 +430,7 @@ bool HlslGrammar::acceptControlDeclaration(TIntermNode*& node)
return false; return false;
} }
node = parseContext.declareVariable(idToken.loc, *idToken.string, type, 0, expressionNode); node = parseContext.declareVariable(idToken.loc, *idToken.string, type, expressionNode);
return true; return true;
} }

View File

@ -4160,11 +4160,6 @@ void HlslParseContext::declareTypedef(const TSourceLoc& loc, TString& identifier
TType type; TType type;
type.deepCopy(parseType); type.deepCopy(parseType);
// Arrayness is potentially coming both from the type and from the
// variable: "int[] a[];" or just one or the other.
// Merge it all to the type, so all arrayness is part of the type.
arrayDimMerge(type, arraySizes);
TVariable* typeSymbol = new TVariable(&identifier, type, true); TVariable* typeSymbol = new TVariable(&identifier, type, true);
if (! symbolTable.insert(*typeSymbol)) if (! symbolTable.insert(*typeSymbol))
error(loc, "name already defined", "typedef", identifier.c_str()); error(loc, "name already defined", "typedef", identifier.c_str());
@ -4181,7 +4176,7 @@ void HlslParseContext::declareTypedef(const TSourceLoc& loc, TString& identifier
// 'parseType' is the type part of the declaration (to the left) // 'parseType' is the type part of the declaration (to the left)
// 'arraySizes' is the arrayness tagged on the identifier (to the right) // 'arraySizes' is the arrayness tagged on the identifier (to the right)
// //
TIntermNode* HlslParseContext::declareVariable(const TSourceLoc& loc, TString& identifier, const TType& parseType, TArraySizes* arraySizes, TIntermTyped* initializer) TIntermNode* HlslParseContext::declareVariable(const TSourceLoc& loc, TString& identifier, TType& type, TIntermTyped* initializer)
{ {
// TODO: things scoped within an annotation need their own name space; // TODO: things scoped within an annotation need their own name space;
// haven't done that yet // haven't done that yet
@ -4189,18 +4184,9 @@ TIntermNode* HlslParseContext::declareVariable(const TSourceLoc& loc, TString& i
return nullptr; return nullptr;
// TODO: strings are not yet handled // TODO: strings are not yet handled
if (parseType.getBasicType() == EbtString) if (type.getBasicType() == EbtString)
return nullptr; return nullptr;
TType type;
type.shallowCopy(parseType);
if (type.isImplicitlySizedArray()) {
// Because "int[] a = int[2](...), b = int[3](...)" makes two arrays a and b
// of different sizes, for this case sharing the shallow copy of arrayness
// with the parseType oversubscribes it, so get a deep copy of the arrayness.
type.newArraySizes(*parseType.getArraySizes());
}
if (voidErrorCheck(loc, identifier, type.getBasicType())) if (voidErrorCheck(loc, identifier, type.getBasicType()))
return nullptr; return nullptr;
@ -4213,16 +4199,10 @@ TIntermNode* HlslParseContext::declareVariable(const TSourceLoc& loc, TString& i
bool flattenVar = false; bool flattenVar = false;
// Declare the variable // Declare the variable
if (arraySizes || type.isArray()) { if (type.isArray()) {
// Arrayness is potentially coming both from the type and from the // array case
// variable: "int[] a[];" or just one or the other.
// Merge it all to the type, so all arrayness is part of the type.
arrayDimMerge(type, arraySizes); // Safe if there are no arraySizes
declareArray(loc, identifier, type, symbol, newDeclaration); declareArray(loc, identifier, type, symbol, newDeclaration);
flattenVar = shouldFlatten(type); flattenVar = shouldFlatten(type);
if (flattenVar) if (flattenVar)
flatten(loc, *symbol->getAsVariable()); flatten(loc, *symbol->getAsVariable());
} else { } else {

View File

@ -140,7 +140,7 @@ public:
const TFunction* findFunction(const TSourceLoc& loc, const TFunction& call, bool& builtIn); const TFunction* findFunction(const TSourceLoc& loc, const TFunction& call, bool& builtIn);
void declareTypedef(const TSourceLoc&, TString& identifier, const TType&, TArraySizes* typeArray = 0); void declareTypedef(const TSourceLoc&, TString& identifier, const TType&, TArraySizes* typeArray = 0);
TIntermNode* declareVariable(const TSourceLoc&, TString& identifier, const TType&, TArraySizes* typeArray = 0, TIntermTyped* initializer = 0); TIntermNode* declareVariable(const TSourceLoc&, TString& identifier, TType&, TIntermTyped* initializer = 0);
TIntermTyped* addConstructor(const TSourceLoc&, TIntermNode*, const TType&); TIntermTyped* addConstructor(const TSourceLoc&, TIntermNode*, const TType&);
TIntermTyped* constructAggregate(TIntermNode*, const TType&, int, const TSourceLoc&); TIntermTyped* constructAggregate(TIntermNode*, const TType&, int, const TSourceLoc&);
TIntermTyped* constructBuiltIn(const TType&, TOperator, TIntermTyped*, const TSourceLoc&, bool subset); TIntermTyped* constructBuiltIn(const TType&, TOperator, TIntermTyped*, const TSourceLoc&, bool subset);