HLSL: Recognize types declared as identifiers as identifiers.
E.g., in float float; (float) * float; The "(float)" is not a type cast, it is an expression.
This commit is contained in:
parent
91c46c6567
commit
0320d090e2
@ -99,17 +99,28 @@ gl_FragCoord origin is upper left
|
|||||||
0:25 'float' ( temp mediump float)
|
0:25 'float' ( temp mediump float)
|
||||||
0:25 Function Call: fn(f1; ( temp mediump float)
|
0:25 Function Call: fn(f1; ( temp mediump float)
|
||||||
0:25 'float' ( temp mediump float)
|
0:25 'float' ( temp mediump float)
|
||||||
0:29 Branch: Return with expression
|
0:28 move second child to first child ( temp float)
|
||||||
0:29 Construct vec4 ( temp 4-component vector of float)
|
0:28 direct index ( temp float)
|
||||||
0:29 add ( temp float)
|
0:28 direct index ( temp 3-component vector of float)
|
||||||
0:29 'float' ( temp float)
|
0:28 'half2x3' ( temp 2X3 matrix of float)
|
||||||
0:29 direct index ( temp float)
|
0:28 Constant:
|
||||||
0:29 direct index ( temp 3-component vector of float)
|
0:28 0 (const int)
|
||||||
0:29 'half2x3' ( temp 2X3 matrix of float)
|
0:28 Constant:
|
||||||
0:29 Constant:
|
0:28 0 (const int)
|
||||||
0:29 0 (const int)
|
0:28 component-wise multiply ( temp float)
|
||||||
0:29 Constant:
|
0:28 'float' ( temp float)
|
||||||
0:29 0 (const int)
|
0:28 'float' ( temp float)
|
||||||
|
0:30 Branch: Return with expression
|
||||||
|
0:30 Construct vec4 ( temp 4-component vector of float)
|
||||||
|
0:30 add ( temp float)
|
||||||
|
0:30 'float' ( temp float)
|
||||||
|
0:30 direct index ( temp float)
|
||||||
|
0:30 direct index ( temp 3-component vector of float)
|
||||||
|
0:30 'half2x3' ( temp 2X3 matrix of float)
|
||||||
|
0:30 Constant:
|
||||||
|
0:30 0 (const int)
|
||||||
|
0:30 Constant:
|
||||||
|
0:30 0 (const int)
|
||||||
0:9 Function Definition: main( ( temp void)
|
0:9 Function Definition: main( ( temp void)
|
||||||
0:9 Function Parameters:
|
0:9 Function Parameters:
|
||||||
0:? Sequence
|
0:? Sequence
|
||||||
@ -223,17 +234,28 @@ gl_FragCoord origin is upper left
|
|||||||
0:25 'float' ( temp mediump float)
|
0:25 'float' ( temp mediump float)
|
||||||
0:25 Function Call: fn(f1; ( temp mediump float)
|
0:25 Function Call: fn(f1; ( temp mediump float)
|
||||||
0:25 'float' ( temp mediump float)
|
0:25 'float' ( temp mediump float)
|
||||||
0:29 Branch: Return with expression
|
0:28 move second child to first child ( temp float)
|
||||||
0:29 Construct vec4 ( temp 4-component vector of float)
|
0:28 direct index ( temp float)
|
||||||
0:29 add ( temp float)
|
0:28 direct index ( temp 3-component vector of float)
|
||||||
0:29 'float' ( temp float)
|
0:28 'half2x3' ( temp 2X3 matrix of float)
|
||||||
0:29 direct index ( temp float)
|
0:28 Constant:
|
||||||
0:29 direct index ( temp 3-component vector of float)
|
0:28 0 (const int)
|
||||||
0:29 'half2x3' ( temp 2X3 matrix of float)
|
0:28 Constant:
|
||||||
0:29 Constant:
|
0:28 0 (const int)
|
||||||
0:29 0 (const int)
|
0:28 component-wise multiply ( temp float)
|
||||||
0:29 Constant:
|
0:28 'float' ( temp float)
|
||||||
0:29 0 (const int)
|
0:28 'float' ( temp float)
|
||||||
|
0:30 Branch: Return with expression
|
||||||
|
0:30 Construct vec4 ( temp 4-component vector of float)
|
||||||
|
0:30 add ( temp float)
|
||||||
|
0:30 'float' ( temp float)
|
||||||
|
0:30 direct index ( temp float)
|
||||||
|
0:30 direct index ( temp 3-component vector of float)
|
||||||
|
0:30 'half2x3' ( temp 2X3 matrix of float)
|
||||||
|
0:30 Constant:
|
||||||
|
0:30 0 (const int)
|
||||||
|
0:30 Constant:
|
||||||
|
0:30 0 (const int)
|
||||||
0:9 Function Definition: main( ( temp void)
|
0:9 Function Definition: main( ( temp void)
|
||||||
0:9 Function Parameters:
|
0:9 Function Parameters:
|
||||||
0:? Sequence
|
0:? Sequence
|
||||||
@ -245,12 +267,12 @@ gl_FragCoord origin is upper left
|
|||||||
|
|
||||||
// Module Version 10000
|
// Module Version 10000
|
||||||
// Generated by (magic number): 80001
|
// Generated by (magic number): 80001
|
||||||
// Id's are bound by 105
|
// Id's are bound by 109
|
||||||
|
|
||||||
Capability Shader
|
Capability Shader
|
||||||
1: ExtInstImport "GLSL.std.450"
|
1: ExtInstImport "GLSL.std.450"
|
||||||
MemoryModel Logical GLSL450
|
MemoryModel Logical GLSL450
|
||||||
EntryPoint Fragment 4 "main" 103
|
EntryPoint Fragment 4 "main" 107
|
||||||
ExecutionMode 4 OriginUpperLeft
|
ExecutionMode 4 OriginUpperLeft
|
||||||
Source HLSL 500
|
Source HLSL 500
|
||||||
Name 4 "main"
|
Name 4 "main"
|
||||||
@ -268,8 +290,8 @@ gl_FragCoord origin is upper left
|
|||||||
MemberName 56(foo_t) 0 "float"
|
MemberName 56(foo_t) 0 "float"
|
||||||
Name 58 "float"
|
Name 58 "float"
|
||||||
Name 86 "param"
|
Name 86 "param"
|
||||||
Name 94 "half2x3"
|
Name 93 "half2x3"
|
||||||
Name 103 "@entryPointOutput"
|
Name 107 "@entryPointOutput"
|
||||||
Decorate 49(min16float) RelaxedPrecision
|
Decorate 49(min16float) RelaxedPrecision
|
||||||
Decorate 50 RelaxedPrecision
|
Decorate 50 RelaxedPrecision
|
||||||
Decorate 51 RelaxedPrecision
|
Decorate 51 RelaxedPrecision
|
||||||
@ -294,7 +316,7 @@ gl_FragCoord origin is upper left
|
|||||||
Decorate 87 RelaxedPrecision
|
Decorate 87 RelaxedPrecision
|
||||||
Decorate 88 RelaxedPrecision
|
Decorate 88 RelaxedPrecision
|
||||||
Decorate 89 RelaxedPrecision
|
Decorate 89 RelaxedPrecision
|
||||||
Decorate 103(@entryPointOutput) Location 0
|
Decorate 107(@entryPointOutput) Location 0
|
||||||
2: TypeVoid
|
2: TypeVoid
|
||||||
3: TypeFunction 2
|
3: TypeFunction 2
|
||||||
6: TypeFloat 32
|
6: TypeFloat 32
|
||||||
@ -319,16 +341,16 @@ gl_FragCoord origin is upper left
|
|||||||
56(foo_t): TypeStruct 6(float)
|
56(foo_t): TypeStruct 6(float)
|
||||||
57: TypePointer Function 56(foo_t)
|
57: TypePointer Function 56(foo_t)
|
||||||
59: 6(float) Constant 1109917696
|
59: 6(float) Constant 1109917696
|
||||||
91: TypeVector 6(float) 3
|
90: TypeVector 6(float) 3
|
||||||
92: TypeMatrix 91(fvec3) 2
|
91: TypeMatrix 90(fvec3) 2
|
||||||
93: TypePointer Function 92
|
92: TypePointer Function 91
|
||||||
95: 22(int) Constant 0
|
97: 22(int) Constant 0
|
||||||
102: TypePointer Output 12(fvec4)
|
106: TypePointer Output 12(fvec4)
|
||||||
103(@entryPointOutput): 102(ptr) Variable Output
|
107(@entryPointOutput): 106(ptr) Variable Output
|
||||||
4(main): 2 Function None 3
|
4(main): 2 Function None 3
|
||||||
5: Label
|
5: Label
|
||||||
104: 12(fvec4) FunctionCall 14(@main()
|
108: 12(fvec4) FunctionCall 14(@main()
|
||||||
Store 103(@entryPointOutput) 104
|
Store 107(@entryPointOutput) 108
|
||||||
Return
|
Return
|
||||||
FunctionEnd
|
FunctionEnd
|
||||||
10(fn(f1;): 6(float) Function None 8
|
10(fn(f1;): 6(float) Function None 8
|
||||||
@ -349,7 +371,7 @@ gl_FragCoord origin is upper left
|
|||||||
58(float): 57(ptr) Variable Function
|
58(float): 57(ptr) Variable Function
|
||||||
75: 7(ptr) Variable Function
|
75: 7(ptr) Variable Function
|
||||||
86(param): 7(ptr) Variable Function
|
86(param): 7(ptr) Variable Function
|
||||||
94(half2x3): 93(ptr) Variable Function
|
93(half2x3): 92(ptr) Variable Function
|
||||||
Store 19(float) 20
|
Store 19(float) 20
|
||||||
27: 6(float) Load 19(float)
|
27: 6(float) Load 19(float)
|
||||||
29: 21(bool) FOrdNotEqual 27 28
|
29: 21(bool) FOrdNotEqual 27 28
|
||||||
@ -411,10 +433,15 @@ gl_FragCoord origin is upper left
|
|||||||
88: 6(float) FunctionCall 10(fn(f1;) 86(param)
|
88: 6(float) FunctionCall 10(fn(f1;) 86(param)
|
||||||
89: 6(float) FAdd 85 88
|
89: 6(float) FAdd 85 88
|
||||||
Store 19(float) 89
|
Store 19(float) 89
|
||||||
90: 6(float) Load 19(float)
|
94: 6(float) Load 19(float)
|
||||||
96: 7(ptr) AccessChain 94(half2x3) 40 95
|
95: 6(float) Load 19(float)
|
||||||
97: 6(float) Load 96
|
96: 6(float) FMul 94 95
|
||||||
98: 6(float) FAdd 90 97
|
98: 7(ptr) AccessChain 93(half2x3) 40 97
|
||||||
99: 12(fvec4) CompositeConstruct 98 98 98 98
|
Store 98 96
|
||||||
ReturnValue 99
|
99: 6(float) Load 19(float)
|
||||||
|
100: 7(ptr) AccessChain 93(half2x3) 40 97
|
||||||
|
101: 6(float) Load 100
|
||||||
|
102: 6(float) FAdd 99 101
|
||||||
|
103: 12(fvec4) CompositeConstruct 102 102 102 102
|
||||||
|
ReturnValue 103
|
||||||
FunctionEnd
|
FunctionEnd
|
||||||
|
@ -25,6 +25,7 @@ float4 main() : SV_Target0
|
|||||||
float = float + int + uint + min16float + min10float + (bool[0] ? int : float) + fn(float);
|
float = float + int + uint + min16float + min10float + (bool[0] ? int : float) + fn(float);
|
||||||
|
|
||||||
half2x3 half2x3;
|
half2x3 half2x3;
|
||||||
|
half2x3._11 = (float) * float;
|
||||||
|
|
||||||
return float + half2x3._11;
|
return float + half2x3._11;
|
||||||
}
|
}
|
||||||
|
@ -107,42 +107,14 @@ bool HlslGrammar::acceptIdentifier(HlslToken& idToken)
|
|||||||
// valid identifier, nor is "linear". This code special cases the known instances of this, so
|
// valid identifier, nor is "linear". This code special cases the known instances of this, so
|
||||||
// e.g, "int sample;" or "float float;" is accepted. Other cases can be added here if needed.
|
// e.g, "int sample;" or "float float;" is accepted. Other cases can be added here if needed.
|
||||||
|
|
||||||
TString* idString = nullptr;
|
const char* idString = getTypeString(peek());
|
||||||
switch (peek()) {
|
if (idString == nullptr)
|
||||||
case EHTokSample: idString = NewPoolTString("sample"); break;
|
|
||||||
case EHTokHalf: idString = NewPoolTString("half"); break;
|
|
||||||
case EHTokHalf1x1: idString = NewPoolTString("half1x1"); break;
|
|
||||||
case EHTokHalf1x2: idString = NewPoolTString("half1x2"); break;
|
|
||||||
case EHTokHalf1x3: idString = NewPoolTString("half1x3"); break;
|
|
||||||
case EHTokHalf1x4: idString = NewPoolTString("half1x4"); break;
|
|
||||||
case EHTokHalf2x1: idString = NewPoolTString("half2x1"); break;
|
|
||||||
case EHTokHalf2x2: idString = NewPoolTString("half2x2"); break;
|
|
||||||
case EHTokHalf2x3: idString = NewPoolTString("half2x3"); break;
|
|
||||||
case EHTokHalf2x4: idString = NewPoolTString("half2x4"); break;
|
|
||||||
case EHTokHalf3x1: idString = NewPoolTString("half3x1"); break;
|
|
||||||
case EHTokHalf3x2: idString = NewPoolTString("half3x2"); break;
|
|
||||||
case EHTokHalf3x3: idString = NewPoolTString("half3x3"); break;
|
|
||||||
case EHTokHalf3x4: idString = NewPoolTString("half3x4"); break;
|
|
||||||
case EHTokHalf4x1: idString = NewPoolTString("half4x1"); break;
|
|
||||||
case EHTokHalf4x2: idString = NewPoolTString("half4x2"); break;
|
|
||||||
case EHTokHalf4x3: idString = NewPoolTString("half4x3"); break;
|
|
||||||
case EHTokHalf4x4: idString = NewPoolTString("half4x4"); break;
|
|
||||||
case EHTokBool: idString = NewPoolTString("bool"); break;
|
|
||||||
case EHTokFloat: idString = NewPoolTString("float"); break;
|
|
||||||
case EHTokDouble: idString = NewPoolTString("double"); break;
|
|
||||||
case EHTokInt: idString = NewPoolTString("int"); break;
|
|
||||||
case EHTokUint: idString = NewPoolTString("uint"); break;
|
|
||||||
case EHTokMin16float: idString = NewPoolTString("min16float"); break;
|
|
||||||
case EHTokMin10float: idString = NewPoolTString("min10float"); break;
|
|
||||||
case EHTokMin16int: idString = NewPoolTString("min16int"); break;
|
|
||||||
case EHTokMin12int: idString = NewPoolTString("min12int"); break;
|
|
||||||
default:
|
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
|
|
||||||
token.string = idString;
|
token.string = NewPoolTString(idString);
|
||||||
token.tokenClass = EHTokIdentifier;
|
token.tokenClass = EHTokIdentifier;
|
||||||
idToken = token;
|
idToken = token;
|
||||||
|
typeIdentifiers = true;
|
||||||
|
|
||||||
advanceToken();
|
advanceToken();
|
||||||
|
|
||||||
@ -1311,6 +1283,18 @@ bool HlslGrammar::acceptType(TType& type, TIntermNode*& nodeList)
|
|||||||
static const TBasicType min12int_bt = EbtInt;
|
static const TBasicType min12int_bt = EbtInt;
|
||||||
static const TBasicType min16uint_bt = EbtUint;
|
static const TBasicType min16uint_bt = EbtUint;
|
||||||
|
|
||||||
|
// Some types might have turned into identifiers. Take the hit for checking
|
||||||
|
// when this has happened.
|
||||||
|
if (typeIdentifiers) {
|
||||||
|
const char* identifierString = getTypeString(peek());
|
||||||
|
if (identifierString != nullptr) {
|
||||||
|
TString name = identifierString;
|
||||||
|
// if it's an identifier, it's not a type
|
||||||
|
if (parseContext.symbolTable.find(name) != nullptr)
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
switch (peek()) {
|
switch (peek()) {
|
||||||
case EHTokVector:
|
case EHTokVector:
|
||||||
return acceptVectorTemplateType(type);
|
return acceptVectorTemplateType(type);
|
||||||
@ -3840,4 +3824,40 @@ bool HlslGrammar::captureBlockTokens(TVector<HlslToken>& tokens)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Return a string for just the types that can also be declared as an identifier.
|
||||||
|
const char* HlslGrammar::getTypeString(EHlslTokenClass tokenClass) const
|
||||||
|
{
|
||||||
|
switch (tokenClass) {
|
||||||
|
case EHTokSample: return "sample";
|
||||||
|
case EHTokHalf: return "half";
|
||||||
|
case EHTokHalf1x1: return "half1x1";
|
||||||
|
case EHTokHalf1x2: return "half1x2";
|
||||||
|
case EHTokHalf1x3: return "half1x3";
|
||||||
|
case EHTokHalf1x4: return "half1x4";
|
||||||
|
case EHTokHalf2x1: return "half2x1";
|
||||||
|
case EHTokHalf2x2: return "half2x2";
|
||||||
|
case EHTokHalf2x3: return "half2x3";
|
||||||
|
case EHTokHalf2x4: return "half2x4";
|
||||||
|
case EHTokHalf3x1: return "half3x1";
|
||||||
|
case EHTokHalf3x2: return "half3x2";
|
||||||
|
case EHTokHalf3x3: return "half3x3";
|
||||||
|
case EHTokHalf3x4: return "half3x4";
|
||||||
|
case EHTokHalf4x1: return "half4x1";
|
||||||
|
case EHTokHalf4x2: return "half4x2";
|
||||||
|
case EHTokHalf4x3: return "half4x3";
|
||||||
|
case EHTokHalf4x4: return "half4x4";
|
||||||
|
case EHTokBool: return "bool";
|
||||||
|
case EHTokFloat: return "float";
|
||||||
|
case EHTokDouble: return "double";
|
||||||
|
case EHTokInt: return "int";
|
||||||
|
case EHTokUint: return "uint";
|
||||||
|
case EHTokMin16float: return "min16float";
|
||||||
|
case EHTokMin10float: return "min10float";
|
||||||
|
case EHTokMin16int: return "min16int";
|
||||||
|
case EHTokMin12int: return "min12int";
|
||||||
|
default:
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
} // end namespace glslang
|
} // end namespace glslang
|
||||||
|
@ -52,7 +52,8 @@ namespace glslang {
|
|||||||
class HlslGrammar : public HlslTokenStream {
|
class HlslGrammar : public HlslTokenStream {
|
||||||
public:
|
public:
|
||||||
HlslGrammar(HlslScanContext& scanner, HlslParseContext& parseContext)
|
HlslGrammar(HlslScanContext& scanner, HlslParseContext& parseContext)
|
||||||
: HlslTokenStream(scanner), parseContext(parseContext), intermediate(parseContext.intermediate) { }
|
: HlslTokenStream(scanner), parseContext(parseContext), intermediate(parseContext.intermediate),
|
||||||
|
typeIdentifiers(false) { }
|
||||||
virtual ~HlslGrammar() { }
|
virtual ~HlslGrammar() { }
|
||||||
|
|
||||||
bool parse();
|
bool parse();
|
||||||
@ -126,9 +127,11 @@ namespace glslang {
|
|||||||
bool acceptDefaultParameterDeclaration(const TType&, TIntermTyped*&);
|
bool acceptDefaultParameterDeclaration(const TType&, TIntermTyped*&);
|
||||||
|
|
||||||
bool captureBlockTokens(TVector<HlslToken>& tokens);
|
bool captureBlockTokens(TVector<HlslToken>& tokens);
|
||||||
|
const char* getTypeString(EHlslTokenClass tokenClass) const;
|
||||||
|
|
||||||
HlslParseContext& parseContext; // state of parsing and helper functions for building the intermediate
|
HlslParseContext& parseContext; // state of parsing and helper functions for building the intermediate
|
||||||
TIntermediate& intermediate; // the final product, the intermediate representation, includes the AST
|
TIntermediate& intermediate; // the final product, the intermediate representation, includes the AST
|
||||||
|
bool typeIdentifiers; // shader uses some types as identifiers
|
||||||
};
|
};
|
||||||
|
|
||||||
} // end namespace glslang
|
} // end namespace glslang
|
||||||
|
Loading…
x
Reference in New Issue
Block a user