HLSL: Fix #1974: ignore input primitives on non-entry-point functions.

This commit is contained in:
John Kessenich 2020-01-17 00:11:12 -07:00
parent 3ed344dd78
commit b0ada80356
6 changed files with 244 additions and 80 deletions

View File

@ -1,7 +1,6 @@
hlsl.gs-hs-mix.tesc hlsl.gs-hs-mix.tesc
Shader version: 500 Shader version: 500
vertices = 3 vertices = 3
input primitive = triangles
vertex spacing = fractional_odd_spacing vertex spacing = fractional_odd_spacing
triangle order = ccw triangle order = ccw
0:? Sequence 0:? Sequence
@ -402,7 +401,6 @@ Linked tessellation control stage:
Shader version: 500 Shader version: 500
vertices = 3 vertices = 3
input primitive = triangles
vertex spacing = fractional_odd_spacing vertex spacing = fractional_odd_spacing
triangle order = ccw triangle order = ccw
0:? Sequence 0:? Sequence

View File

@ -66,6 +66,58 @@ output primitive = line_strip
0:13 Function Call: @main(u1[3];struct-S-f1-f1-f1-u1-u1-i11; ( temp void) 0:13 Function Call: @main(u1[3];struct-S-f1-f1-f1-u1-u1-i11; ( temp void)
0:? 'VertexID' ( temp 3-element array of uint) 0:? 'VertexID' ( temp 3-element array of uint)
0:? 'OutputStream' ( temp structure{ temp float clip0, temp float clip0, temp float cull0, temp uint vpai, temp uint rtai, temp int ii}) 0:? 'OutputStream' ( temp structure{ temp float clip0, temp float clip0, temp float cull0, temp uint vpai, temp uint rtai, temp int ii})
0:21 Function Definition: notmain(u1[2];struct-S-f1-f1-f1-u1-u1-i11; ( temp void)
0:21 Function Parameters:
0:21 'VertexID' ( in 2-element array of uint)
0:21 'OutputStream' ( out structure{ temp float clip0, temp float clip0, temp float cull0, temp uint vpai, temp uint rtai, temp int ii})
0:? Sequence
0:23 Sequence
0:23 Sequence
0:23 move second child to first child ( temp float)
0:? 'OutputStream.clip0' ( out float Position)
0:23 clip0: direct index for structure ( temp float)
0:23 's' ( temp structure{ temp float clip0, temp float clip0, temp float cull0, temp uint vpai, temp uint rtai, temp int ii})
0:23 Constant:
0:23 0 (const int)
0:? Sequence
0:23 move second child to first child ( temp float)
0:23 direct index ( out float ClipDistance)
0:? 'OutputStream.clip0' ( out 1-element array of float ClipDistance)
0:23 Constant:
0:23 0 (const int)
0:23 clip0: direct index for structure ( temp float)
0:23 's' ( temp structure{ temp float clip0, temp float clip0, temp float cull0, temp uint vpai, temp uint rtai, temp int ii})
0:23 Constant:
0:23 1 (const int)
0:? Sequence
0:23 move second child to first child ( temp float)
0:23 direct index ( out float CullDistance)
0:? 'OutputStream.cull0' ( out 1-element array of float CullDistance)
0:23 Constant:
0:23 0 (const int)
0:23 cull0: direct index for structure ( temp float)
0:23 's' ( temp structure{ temp float clip0, temp float clip0, temp float cull0, temp uint vpai, temp uint rtai, temp int ii})
0:23 Constant:
0:23 2 (const int)
0:23 move second child to first child ( temp uint)
0:? 'OutputStream.vpai' ( out uint ViewportIndex)
0:23 vpai: direct index for structure ( temp uint)
0:23 's' ( temp structure{ temp float clip0, temp float clip0, temp float cull0, temp uint vpai, temp uint rtai, temp int ii})
0:23 Constant:
0:23 3 (const int)
0:23 move second child to first child ( temp uint)
0:? 'OutputStream.rtai' ( out uint Layer)
0:23 rtai: direct index for structure ( temp uint)
0:23 's' ( temp structure{ temp float clip0, temp float clip0, temp float cull0, temp uint vpai, temp uint rtai, temp int ii})
0:23 Constant:
0:23 4 (const int)
0:23 move second child to first child ( temp int)
0:? 'OutputStream.ii' (layout( location=0) out int)
0:23 ii: direct index for structure ( temp int)
0:23 's' ( temp structure{ temp float clip0, temp float clip0, temp float cull0, temp uint vpai, temp uint rtai, temp int ii})
0:23 Constant:
0:23 5 (const int)
0:23 EmitVertex ( temp void)
0:? Linker Objects 0:? Linker Objects
0:? 'VertexID' (layout( location=0) in 3-element array of uint) 0:? 'VertexID' (layout( location=0) in 3-element array of uint)
0:? 'OutputStream.clip0' ( out float Position) 0:? 'OutputStream.clip0' ( out float Position)
@ -146,6 +198,58 @@ output primitive = line_strip
0:13 Function Call: @main(u1[3];struct-S-f1-f1-f1-u1-u1-i11; ( temp void) 0:13 Function Call: @main(u1[3];struct-S-f1-f1-f1-u1-u1-i11; ( temp void)
0:? 'VertexID' ( temp 3-element array of uint) 0:? 'VertexID' ( temp 3-element array of uint)
0:? 'OutputStream' ( temp structure{ temp float clip0, temp float clip0, temp float cull0, temp uint vpai, temp uint rtai, temp int ii}) 0:? 'OutputStream' ( temp structure{ temp float clip0, temp float clip0, temp float cull0, temp uint vpai, temp uint rtai, temp int ii})
0:21 Function Definition: notmain(u1[2];struct-S-f1-f1-f1-u1-u1-i11; ( temp void)
0:21 Function Parameters:
0:21 'VertexID' ( in 2-element array of uint)
0:21 'OutputStream' ( out structure{ temp float clip0, temp float clip0, temp float cull0, temp uint vpai, temp uint rtai, temp int ii})
0:? Sequence
0:23 Sequence
0:23 Sequence
0:23 move second child to first child ( temp float)
0:? 'OutputStream.clip0' ( out float Position)
0:23 clip0: direct index for structure ( temp float)
0:23 's' ( temp structure{ temp float clip0, temp float clip0, temp float cull0, temp uint vpai, temp uint rtai, temp int ii})
0:23 Constant:
0:23 0 (const int)
0:? Sequence
0:23 move second child to first child ( temp float)
0:23 direct index ( out float ClipDistance)
0:? 'OutputStream.clip0' ( out 1-element array of float ClipDistance)
0:23 Constant:
0:23 0 (const int)
0:23 clip0: direct index for structure ( temp float)
0:23 's' ( temp structure{ temp float clip0, temp float clip0, temp float cull0, temp uint vpai, temp uint rtai, temp int ii})
0:23 Constant:
0:23 1 (const int)
0:? Sequence
0:23 move second child to first child ( temp float)
0:23 direct index ( out float CullDistance)
0:? 'OutputStream.cull0' ( out 1-element array of float CullDistance)
0:23 Constant:
0:23 0 (const int)
0:23 cull0: direct index for structure ( temp float)
0:23 's' ( temp structure{ temp float clip0, temp float clip0, temp float cull0, temp uint vpai, temp uint rtai, temp int ii})
0:23 Constant:
0:23 2 (const int)
0:23 move second child to first child ( temp uint)
0:? 'OutputStream.vpai' ( out uint ViewportIndex)
0:23 vpai: direct index for structure ( temp uint)
0:23 's' ( temp structure{ temp float clip0, temp float clip0, temp float cull0, temp uint vpai, temp uint rtai, temp int ii})
0:23 Constant:
0:23 3 (const int)
0:23 move second child to first child ( temp uint)
0:? 'OutputStream.rtai' ( out uint Layer)
0:23 rtai: direct index for structure ( temp uint)
0:23 's' ( temp structure{ temp float clip0, temp float clip0, temp float cull0, temp uint vpai, temp uint rtai, temp int ii})
0:23 Constant:
0:23 4 (const int)
0:23 move second child to first child ( temp int)
0:? 'OutputStream.ii' (layout( location=0) out int)
0:23 ii: direct index for structure ( temp int)
0:23 's' ( temp structure{ temp float clip0, temp float clip0, temp float cull0, temp uint vpai, temp uint rtai, temp int ii})
0:23 Constant:
0:23 5 (const int)
0:23 EmitVertex ( temp void)
0:? Linker Objects 0:? Linker Objects
0:? 'VertexID' (layout( location=0) in 3-element array of uint) 0:? 'VertexID' (layout( location=0) in 3-element array of uint)
0:? 'OutputStream.clip0' ( out float Position) 0:? 'OutputStream.clip0' ( out float Position)
@ -158,7 +262,7 @@ output primitive = line_strip
Validation failed Validation failed
// Module Version 10000 // Module Version 10000
// Generated by (magic number): 80008 // Generated by (magic number): 80008
// Id's are bound by 65 // Id's are bound by 88
Capability Geometry Capability Geometry
Capability ClipDistance Capability ClipDistance
@ -166,7 +270,7 @@ Validation failed
Capability MultiViewport Capability MultiViewport
1: ExtInstImport "GLSL.std.450" 1: ExtInstImport "GLSL.std.450"
MemoryModel Logical GLSL450 MemoryModel Logical GLSL450
EntryPoint Geometry 4 "main" 20 29 34 40 45 50 57 EntryPoint Geometry 4 "main" 28 37 42 48 53 58 65
ExecutionMode 4 Triangles ExecutionMode 4 Triangles
ExecutionMode 4 Invocations 1 ExecutionMode 4 Invocations 1
ExecutionMode 4 OutputLineStrip ExecutionMode 4 OutputLineStrip
@ -183,25 +287,29 @@ Validation failed
Name 17 "@main(u1[3];struct-S-f1-f1-f1-u1-u1-i11;" Name 17 "@main(u1[3];struct-S-f1-f1-f1-u1-u1-i11;"
Name 15 "VertexID" Name 15 "VertexID"
Name 16 "OutputStream" Name 16 "OutputStream"
Name 20 "OutputStream.clip0" Name 25 "notmain(u1[2];struct-S-f1-f1-f1-u1-u1-i11;"
Name 21 "s" Name 23 "VertexID"
Name 29 "OutputStream.clip0" Name 24 "OutputStream"
Name 34 "OutputStream.cull0" Name 28 "OutputStream.clip0"
Name 40 "OutputStream.vpai" Name 29 "s"
Name 45 "OutputStream.rtai" Name 37 "OutputStream.clip0"
Name 50 "OutputStream.ii" Name 42 "OutputStream.cull0"
Name 55 "VertexID" Name 48 "OutputStream.vpai"
Name 57 "VertexID" Name 53 "OutputStream.rtai"
Name 59 "OutputStream" Name 58 "OutputStream.ii"
Name 60 "param" Name 63 "VertexID"
Name 62 "param" Name 65 "VertexID"
Decorate 20(OutputStream.clip0) BuiltIn Position Name 67 "OutputStream"
Decorate 29(OutputStream.clip0) BuiltIn ClipDistance Name 68 "param"
Decorate 34(OutputStream.cull0) BuiltIn CullDistance Name 70 "param"
Decorate 40(OutputStream.vpai) BuiltIn ViewportIndex Name 73 "s"
Decorate 45(OutputStream.rtai) BuiltIn Layer Decorate 28(OutputStream.clip0) BuiltIn Position
Decorate 50(OutputStream.ii) Location 0 Decorate 37(OutputStream.clip0) BuiltIn ClipDistance
Decorate 57(VertexID) Location 0 Decorate 42(OutputStream.cull0) BuiltIn CullDistance
Decorate 48(OutputStream.vpai) BuiltIn ViewportIndex
Decorate 53(OutputStream.rtai) BuiltIn Layer
Decorate 58(OutputStream.ii) Location 0
Decorate 65(VertexID) Location 0
2: TypeVoid 2: TypeVoid
3: TypeFunction 2 3: TypeFunction 2
6: TypeInt 32 0 6: TypeInt 32 0
@ -213,69 +321,101 @@ Validation failed
12(S): TypeStruct 10(float) 10(float) 10(float) 6(int) 6(int) 11(int) 12(S): TypeStruct 10(float) 10(float) 10(float) 6(int) 6(int) 11(int)
13: TypePointer Function 12(S) 13: TypePointer Function 12(S)
14: TypeFunction 2 9(ptr) 13(ptr) 14: TypeFunction 2 9(ptr) 13(ptr)
19: TypePointer Output 10(float) 19: 6(int) Constant 2
20(OutputStream.clip0): 19(ptr) Variable Output 20: TypeArray 6(int) 19
22: 11(int) Constant 0 21: TypePointer Function 20
23: TypePointer Function 10(float) 22: TypeFunction 2 21(ptr) 13(ptr)
26: 6(int) Constant 1 27: TypePointer Output 10(float)
27: TypeArray 10(float) 26 28(OutputStream.clip0): 27(ptr) Variable Output
28: TypePointer Output 27 30: 11(int) Constant 0
29(OutputStream.clip0): 28(ptr) Variable Output 31: TypePointer Function 10(float)
30: 11(int) Constant 1 34: 6(int) Constant 1
34(OutputStream.cull0): 28(ptr) Variable Output 35: TypeArray 10(float) 34
35: 11(int) Constant 2 36: TypePointer Output 35
39: TypePointer Output 6(int) 37(OutputStream.clip0): 36(ptr) Variable Output
40(OutputStream.vpai): 39(ptr) Variable Output 38: 11(int) Constant 1
41: 11(int) Constant 3 42(OutputStream.cull0): 36(ptr) Variable Output
42: TypePointer Function 6(int) 43: 11(int) Constant 2
45(OutputStream.rtai): 39(ptr) Variable Output 47: TypePointer Output 6(int)
46: 11(int) Constant 4 48(OutputStream.vpai): 47(ptr) Variable Output
49: TypePointer Output 11(int) 49: 11(int) Constant 3
50(OutputStream.ii): 49(ptr) Variable Output 50: TypePointer Function 6(int)
51: 11(int) Constant 5 53(OutputStream.rtai): 47(ptr) Variable Output
52: TypePointer Function 11(int) 54: 11(int) Constant 4
56: TypePointer Input 8 57: TypePointer Output 11(int)
57(VertexID): 56(ptr) Variable Input 58(OutputStream.ii): 57(ptr) Variable Output
59: 11(int) Constant 5
60: TypePointer Function 11(int)
64: TypePointer Input 8
65(VertexID): 64(ptr) Variable Input
4(main): 2 Function None 3 4(main): 2 Function None 3
5: Label 5: Label
55(VertexID): 9(ptr) Variable Function 63(VertexID): 9(ptr) Variable Function
59(OutputStream): 13(ptr) Variable Function 67(OutputStream): 13(ptr) Variable Function
60(param): 9(ptr) Variable Function 68(param): 9(ptr) Variable Function
62(param): 13(ptr) Variable Function 70(param): 13(ptr) Variable Function
58: 8 Load 57(VertexID) 66: 8 Load 65(VertexID)
Store 55(VertexID) 58 Store 63(VertexID) 66
61: 8 Load 55(VertexID) 69: 8 Load 63(VertexID)
Store 60(param) 61 Store 68(param) 69
63: 2 FunctionCall 17(@main(u1[3];struct-S-f1-f1-f1-u1-u1-i11;) 60(param) 62(param) 71: 2 FunctionCall 17(@main(u1[3];struct-S-f1-f1-f1-u1-u1-i11;) 68(param) 70(param)
64: 12(S) Load 62(param) 72: 12(S) Load 70(param)
Store 59(OutputStream) 64 Store 67(OutputStream) 72
Return Return
FunctionEnd FunctionEnd
17(@main(u1[3];struct-S-f1-f1-f1-u1-u1-i11;): 2 Function None 14 17(@main(u1[3];struct-S-f1-f1-f1-u1-u1-i11;): 2 Function None 14
15(VertexID): 9(ptr) FunctionParameter 15(VertexID): 9(ptr) FunctionParameter
16(OutputStream): 13(ptr) FunctionParameter 16(OutputStream): 13(ptr) FunctionParameter
18: Label 18: Label
21(s): 13(ptr) Variable Function 29(s): 13(ptr) Variable Function
24: 23(ptr) AccessChain 21(s) 22 32: 31(ptr) AccessChain 29(s) 30
25: 10(float) Load 24 33: 10(float) Load 32
Store 20(OutputStream.clip0) 25 Store 28(OutputStream.clip0) 33
31: 23(ptr) AccessChain 21(s) 30 39: 31(ptr) AccessChain 29(s) 38
32: 10(float) Load 31 40: 10(float) Load 39
33: 19(ptr) AccessChain 29(OutputStream.clip0) 22 41: 27(ptr) AccessChain 37(OutputStream.clip0) 30
Store 33 32 Store 41 40
36: 23(ptr) AccessChain 21(s) 35 44: 31(ptr) AccessChain 29(s) 43
37: 10(float) Load 36 45: 10(float) Load 44
38: 19(ptr) AccessChain 34(OutputStream.cull0) 22 46: 27(ptr) AccessChain 42(OutputStream.cull0) 30
Store 38 37 Store 46 45
43: 42(ptr) AccessChain 21(s) 41 51: 50(ptr) AccessChain 29(s) 49
44: 6(int) Load 43 52: 6(int) Load 51
Store 40(OutputStream.vpai) 44 Store 48(OutputStream.vpai) 52
47: 42(ptr) AccessChain 21(s) 46 55: 50(ptr) AccessChain 29(s) 54
48: 6(int) Load 47 56: 6(int) Load 55
Store 45(OutputStream.rtai) 48 Store 53(OutputStream.rtai) 56
53: 52(ptr) AccessChain 21(s) 51 61: 60(ptr) AccessChain 29(s) 59
54: 11(int) Load 53 62: 11(int) Load 61
Store 50(OutputStream.ii) 54 Store 58(OutputStream.ii) 62
EmitVertex
Return
FunctionEnd
25(notmain(u1[2];struct-S-f1-f1-f1-u1-u1-i11;): 2 Function None 22
23(VertexID): 21(ptr) FunctionParameter
24(OutputStream): 13(ptr) FunctionParameter
26: Label
73(s): 13(ptr) Variable Function
74: 31(ptr) AccessChain 73(s) 30
75: 10(float) Load 74
Store 28(OutputStream.clip0) 75
76: 31(ptr) AccessChain 73(s) 38
77: 10(float) Load 76
78: 27(ptr) AccessChain 37(OutputStream.clip0) 30
Store 78 77
79: 31(ptr) AccessChain 73(s) 43
80: 10(float) Load 79
81: 27(ptr) AccessChain 42(OutputStream.cull0) 30
Store 81 80
82: 50(ptr) AccessChain 73(s) 49
83: 6(int) Load 82
Store 48(OutputStream.vpai) 83
84: 50(ptr) AccessChain 73(s) 54
85: 6(int) Load 84
Store 53(OutputStream.rtai) 85
86: 60(ptr) AccessChain 73(s) 59
87: 11(int) Load 86
Store 58(OutputStream.ii) 87
EmitVertex EmitVertex
Return Return
FunctionEnd FunctionEnd

View File

@ -14,3 +14,11 @@ void main(triangle in uint VertexID[3] : VertexID,
S s; S s;
OutputStream.Append(s); OutputStream.Append(s);
} }
[maxvertexcount(4)]
void notmain(line in uint VertexID[2] : VertexID,
inout LineStream<S> OutputStream)
{
S s;
OutputStream.Append(s);
}

View File

@ -2516,6 +2516,8 @@ bool HlslGrammar::acceptMemberFunctionDefinition(TIntermNode*& nodeList, const T
// //
bool HlslGrammar::acceptFunctionParameters(TFunction& function) bool HlslGrammar::acceptFunctionParameters(TFunction& function)
{ {
parseContext.beginParameterParsing(function);
// LEFT_PAREN // LEFT_PAREN
if (! acceptTokenClass(EHTokLeftParen)) if (! acceptTokenClass(EHTokLeftParen))
return false; return false;

View File

@ -69,7 +69,8 @@ HlslParseContext::HlslParseContext(TSymbolTable& symbolTable, TIntermediate& int
clipDistanceOutput(nullptr), clipDistanceOutput(nullptr),
cullDistanceOutput(nullptr), cullDistanceOutput(nullptr),
clipDistanceInput(nullptr), clipDistanceInput(nullptr),
cullDistanceInput(nullptr) cullDistanceInput(nullptr),
parsingEntrypointParameters(false)
{ {
globalUniformDefaults.clear(); globalUniformDefaults.clear();
globalUniformDefaults.layoutMatrix = ElmRowMajor; globalUniformDefaults.layoutMatrix = ElmRowMajor;
@ -2049,7 +2050,7 @@ TIntermNode* HlslParseContext::transformEntryPoint(const TSourceLoc& loc, TFunct
}; };
// if we aren't in the entry point, fix the IO as such and exit // if we aren't in the entry point, fix the IO as such and exit
if (userFunction.getName().compare(intermediate.getEntryPointName().c_str()) != 0) { if (! isEntrypointName(userFunction.getName())) {
remapNonEntryPointIO(userFunction); remapNonEntryPointIO(userFunction);
return nullptr; return nullptr;
} }
@ -8884,6 +8885,10 @@ void HlslParseContext::addQualifierToExisting(const TSourceLoc& loc, TQualifier
// //
bool HlslParseContext::handleInputGeometry(const TSourceLoc& loc, const TLayoutGeometry& geometry) bool HlslParseContext::handleInputGeometry(const TSourceLoc& loc, const TLayoutGeometry& geometry)
{ {
// these can be declared on non-entry-points, in which case they lose their meaning
if (! parsingEntrypointParameters)
return true;
switch (geometry) { switch (geometry) {
case ElgPoints: // fall through case ElgPoints: // fall through
case ElgLines: // ... case ElgLines: // ...
@ -8914,6 +8919,10 @@ bool HlslParseContext::handleOutputGeometry(const TSourceLoc& loc, const TLayout
if (language != EShLangGeometry) if (language != EShLangGeometry)
return true; return true;
// these can be declared on non-entry-points, in which case they lose their meaning
if (! parsingEntrypointParameters)
return true;
switch (geometry) { switch (geometry) {
case ElgPoints: case ElgPoints:
case ElgLineStrip: case ElgLineStrip:

View File

@ -183,6 +183,11 @@ public:
void getFullNamespaceName(TString*&) const; void getFullNamespaceName(TString*&) const;
void addScopeMangler(TString&); void addScopeMangler(TString&);
void beginParameterParsing(TFunction& function)
{
parsingEntrypointParameters = isEntrypointName(function.getName());
}
void pushSwitchSequence(TIntermSequence* sequence) { switchSequenceStack.push_back(sequence); } void pushSwitchSequence(TIntermSequence* sequence) { switchSequenceStack.push_back(sequence); }
void popSwitchSequence() { switchSequenceStack.pop_back(); } void popSwitchSequence() { switchSequenceStack.pop_back(); }
@ -241,6 +246,7 @@ protected:
TIntermTyped* convertInitializerList(const TSourceLoc&, const TType&, TIntermTyped* initializer, TIntermTyped* scalarInit); TIntermTyped* convertInitializerList(const TSourceLoc&, const TType&, TIntermTyped* initializer, TIntermTyped* scalarInit);
bool isScalarConstructor(const TIntermNode*); bool isScalarConstructor(const TIntermNode*);
TOperator mapAtomicOp(const TSourceLoc& loc, TOperator op, bool isImage); TOperator mapAtomicOp(const TSourceLoc& loc, TOperator op, bool isImage);
bool isEntrypointName(const TString& name) { return name.compare(intermediate.getEntryPointName().c_str()) == 0; }
// Return true if this node requires L-value conversion (e.g, to an imageStore). // Return true if this node requires L-value conversion (e.g, to an imageStore).
bool shouldConvertLValue(const TIntermNode*) const; bool shouldConvertLValue(const TIntermNode*) const;
@ -494,6 +500,7 @@ protected:
}; };
TMap<int, tShadowTextureSymbols*> textureShadowVariant; TMap<int, tShadowTextureSymbols*> textureShadowVariant;
bool parsingEntrypointParameters;
}; };
// This is the prefix we use for built-in methods to avoid namespace collisions with // This is the prefix we use for built-in methods to avoid namespace collisions with