HLSL: for split output structs, propagate indirection to builtin.

Some stage (e.g, hull shaders) have arrayed builtin outputs (e.g, position).
When copying from the internal structure to the split form, it is necessary
to propagate that indirection to the actual arrayed outputs.  This was not
happening.

Addresses #1181
This commit is contained in:
LoopDawg 2017-12-12 16:21:22 -07:00
parent e078059d06
commit 0cff51004d
3 changed files with 91 additions and 84 deletions

View File

@ -159,10 +159,9 @@ triangle order = cw
0:? 'cpid' ( in uint InvocationID) 0:? 'cpid' ( in uint InvocationID)
0:39 Sequence 0:39 Sequence
0:39 move second child to first child ( temp 4-component vector of float) 0:39 move second child to first child ( temp 4-component vector of float)
0:39 direct index ( out 4-component vector of float Position) 0:39 indirect index ( out 4-component vector of float Position)
0:? '@entryPointOutput.m_Position' ( out 3-element array of 4-component vector of float Position) 0:? '@entryPointOutput.m_Position' ( out 3-element array of 4-component vector of float Position)
0:39 Constant: 0:? 'cpid' ( in uint InvocationID)
0:39 0 (const int)
0:39 m_Position: direct index for structure ( temp 4-component vector of float) 0:39 m_Position: direct index for structure ( temp 4-component vector of float)
0:39 Function Call: @main(struct-HS_Input-vf4-vf41[3];u1; ( temp structure{ temp 4-component vector of float m_Position}) 0:39 Function Call: @main(struct-HS_Input-vf4-vf41[3];u1; ( temp structure{ temp 4-component vector of float m_Position})
0:? 'I' ( temp 3-element array of structure{ temp 4-component vector of float m_Position, temp 4-component vector of float m_Normal}) 0:? 'I' ( temp 3-element array of structure{ temp 4-component vector of float m_Position, temp 4-component vector of float m_Normal})
@ -400,10 +399,9 @@ triangle order = cw
0:? 'cpid' ( in uint InvocationID) 0:? 'cpid' ( in uint InvocationID)
0:39 Sequence 0:39 Sequence
0:39 move second child to first child ( temp 4-component vector of float) 0:39 move second child to first child ( temp 4-component vector of float)
0:39 direct index ( out 4-component vector of float Position) 0:39 indirect index ( out 4-component vector of float Position)
0:? '@entryPointOutput.m_Position' ( out 3-element array of 4-component vector of float Position) 0:? '@entryPointOutput.m_Position' ( out 3-element array of 4-component vector of float Position)
0:39 Constant: 0:? 'cpid' ( in uint InvocationID)
0:39 0 (const int)
0:39 m_Position: direct index for structure ( temp 4-component vector of float) 0:39 m_Position: direct index for structure ( temp 4-component vector of float)
0:39 Function Call: @main(struct-HS_Input-vf4-vf41[3];u1; ( temp structure{ temp 4-component vector of float m_Position}) 0:39 Function Call: @main(struct-HS_Input-vf4-vf41[3];u1; ( temp structure{ temp 4-component vector of float m_Position})
0:? 'I' ( temp 3-element array of structure{ temp 4-component vector of float m_Position, temp 4-component vector of float m_Normal}) 0:? 'I' ( temp 3-element array of structure{ temp 4-component vector of float m_Position, temp 4-component vector of float m_Normal})
@ -479,12 +477,12 @@ triangle order = cw
// Module Version 10000 // Module Version 10000
// Generated by (magic number): 80002 // Generated by (magic number): 80002
// Id's are bound by 127 // Id's are bound by 128
Capability Tessellation Capability Tessellation
1: ExtInstImport "GLSL.std.450" 1: ExtInstImport "GLSL.std.450"
MemoryModel Logical GLSL450 MemoryModel Logical GLSL450
EntryPoint TessellationControl 4 "main" 56 64 83 86 110 123 EntryPoint TessellationControl 4 "main" 56 64 83 86 111 124
ExecutionMode 4 OutputVertices 3 ExecutionMode 4 OutputVertices 3
ExecutionMode 4 Triangles ExecutionMode 4 Triangles
ExecutionMode 4 SpacingFractionalOdd ExecutionMode 4 SpacingFractionalOdd
@ -514,20 +512,20 @@ triangle order = cw
Name 81 "cpid" Name 81 "cpid"
Name 83 "cpid" Name 83 "cpid"
Name 86 "@entryPointOutput.m_Position" Name 86 "@entryPointOutput.m_Position"
Name 87 "param" Name 88 "param"
Name 89 "param" Name 90 "param"
Name 103 "@patchConstantResult" Name 104 "@patchConstantResult"
Name 104 "param" Name 105 "param"
Name 110 "@patchConstantOutput.fTessFactor" Name 111 "@patchConstantOutput.fTessFactor"
Name 123 "@patchConstantOutput.fInsideTessFactor" Name 124 "@patchConstantOutput.fInsideTessFactor"
Decorate 56(I.m_Position) BuiltIn Position Decorate 56(I.m_Position) BuiltIn Position
Decorate 64(I) Location 0 Decorate 64(I) Location 0
Decorate 83(cpid) BuiltIn InvocationId Decorate 83(cpid) BuiltIn InvocationId
Decorate 86(@entryPointOutput.m_Position) BuiltIn Position Decorate 86(@entryPointOutput.m_Position) BuiltIn Position
Decorate 110(@patchConstantOutput.fTessFactor) Patch Decorate 111(@patchConstantOutput.fTessFactor) Patch
Decorate 110(@patchConstantOutput.fTessFactor) BuiltIn TessLevelOuter Decorate 111(@patchConstantOutput.fTessFactor) BuiltIn TessLevelOuter
Decorate 123(@patchConstantOutput.fInsideTessFactor) Patch Decorate 124(@patchConstantOutput.fInsideTessFactor) Patch
Decorate 123(@patchConstantOutput.fInsideTessFactor) BuiltIn TessLevelInner Decorate 124(@patchConstantOutput.fInsideTessFactor) BuiltIn TessLevelInner
2: TypeVoid 2: TypeVoid
3: TypeFunction 2 3: TypeFunction 2
6: TypeFloat 32 6: TypeFloat 32
@ -568,27 +566,27 @@ triangle order = cw
83(cpid): 82(ptr) Variable Input 83(cpid): 82(ptr) Variable Input
85: TypePointer Output 54 85: TypePointer Output 54
86(@entryPointOutput.m_Position): 85(ptr) Variable Output 86(@entryPointOutput.m_Position): 85(ptr) Variable Output
93: TypePointer Output 7(fvec4) 94: TypePointer Output 7(fvec4)
95: 9(int) Constant 2 96: 9(int) Constant 2
96: 9(int) Constant 1 97: 9(int) Constant 1
97: 9(int) Constant 0 98: 9(int) Constant 0
99: TypeBool 100: TypeBool
107: 9(int) Constant 4 108: 9(int) Constant 4
108: TypeArray 6(float) 107 109: TypeArray 6(float) 108
109: TypePointer Output 108 110: TypePointer Output 109
110(@patchConstantOutput.fTessFactor): 109(ptr) Variable Output 111(@patchConstantOutput.fTessFactor): 110(ptr) Variable Output
113: TypePointer Output 6(float) 114: TypePointer Output 6(float)
121: TypeArray 6(float) 95 122: TypeArray 6(float) 96
122: TypePointer Output 121 123: TypePointer Output 122
123(@patchConstantOutput.fInsideTessFactor): 122(ptr) Variable Output 124(@patchConstantOutput.fInsideTessFactor): 123(ptr) Variable Output
4(main): 2 Function None 3 4(main): 2 Function None 3
5: Label 5: Label
53(I): 12(ptr) Variable Function 53(I): 12(ptr) Variable Function
81(cpid): 19(ptr) Variable Function 81(cpid): 19(ptr) Variable Function
87(param): 12(ptr) Variable Function 88(param): 12(ptr) Variable Function
89(param): 19(ptr) Variable Function 90(param): 19(ptr) Variable Function
103(@patchConstantResult): 26(ptr) Variable Function 104(@patchConstantResult): 26(ptr) Variable Function
104(param): 12(ptr) Variable Function 105(param): 12(ptr) Variable Function
58: 57(ptr) AccessChain 56(I.m_Position) 33 58: 57(ptr) AccessChain 56(I.m_Position) 33
59: 7(fvec4) Load 58 59: 7(fvec4) Load 58
60: 48(ptr) AccessChain 53(I) 33 33 60: 48(ptr) AccessChain 53(I) 33 33
@ -615,42 +613,43 @@ triangle order = cw
Store 80 79 Store 80 79
84: 9(int) Load 83(cpid) 84: 9(int) Load 83(cpid)
Store 81(cpid) 84 Store 81(cpid) 84
88: 11 Load 53(I) 87: 9(int) Load 83(cpid)
Store 87(param) 88 89: 11 Load 53(I)
90: 9(int) Load 81(cpid) Store 88(param) 89
Store 89(param) 90 91: 9(int) Load 81(cpid)
91:20(HS_Main_Output) FunctionCall 24(@main(struct-HS_Input-vf4-vf41[3];u1;) 87(param) 89(param) Store 90(param) 91
92: 7(fvec4) CompositeExtract 91 0 92:20(HS_Main_Output) FunctionCall 24(@main(struct-HS_Input-vf4-vf41[3];u1;) 88(param) 90(param)
94: 93(ptr) AccessChain 86(@entryPointOutput.m_Position) 33 93: 7(fvec4) CompositeExtract 92 0
Store 94 92 95: 94(ptr) AccessChain 86(@entryPointOutput.m_Position) 87
ControlBarrier 95 96 97 Store 95 93
98: 9(int) Load 83(cpid) ControlBarrier 96 97 98
100: 99(bool) IEqual 98 33 99: 9(int) Load 83(cpid)
SelectionMerge 102 None 101: 100(bool) IEqual 99 33
BranchConditional 100 101 102 SelectionMerge 103 None
101: Label BranchConditional 101 102 103
105: 11 Load 53(I) 102: Label
Store 104(param) 105 106: 11 Load 53(I)
106:14(HS_Output) FunctionCall 17(HS_ConstFunc(struct-HS_Input-vf4-vf41[3];) 104(param) Store 105(param) 106
Store 103(@patchConstantResult) 106 107:14(HS_Output) FunctionCall 17(HS_ConstFunc(struct-HS_Input-vf4-vf41[3];) 105(param)
111: 34(ptr) AccessChain 103(@patchConstantResult) 33 33 Store 104(@patchConstantResult) 107
112: 6(float) Load 111 112: 34(ptr) AccessChain 104(@patchConstantResult) 33 33
114: 113(ptr) AccessChain 110(@patchConstantOutput.fTessFactor) 33 113: 6(float) Load 112
Store 114 112 115: 114(ptr) AccessChain 111(@patchConstantOutput.fTessFactor) 33
115: 34(ptr) AccessChain 103(@patchConstantResult) 33 32 Store 115 113
116: 6(float) Load 115 116: 34(ptr) AccessChain 104(@patchConstantResult) 33 32
117: 113(ptr) AccessChain 110(@patchConstantOutput.fTessFactor) 32 117: 6(float) Load 116
Store 117 116 118: 114(ptr) AccessChain 111(@patchConstantOutput.fTessFactor) 32
118: 34(ptr) AccessChain 103(@patchConstantResult) 33 74 Store 118 117
119: 6(float) Load 118 119: 34(ptr) AccessChain 104(@patchConstantResult) 33 74
120: 113(ptr) AccessChain 110(@patchConstantOutput.fTessFactor) 74 120: 6(float) Load 119
Store 120 119 121: 114(ptr) AccessChain 111(@patchConstantOutput.fTessFactor) 74
124: 34(ptr) AccessChain 103(@patchConstantResult) 32 Store 121 120
125: 6(float) Load 124 125: 34(ptr) AccessChain 104(@patchConstantResult) 32
126: 113(ptr) AccessChain 123(@patchConstantOutput.fInsideTessFactor) 33 126: 6(float) Load 125
Store 126 125 127: 114(ptr) AccessChain 124(@patchConstantOutput.fInsideTessFactor) 33
Branch 102 Store 127 126
102: Label Branch 103
103: Label
Return Return
FunctionEnd FunctionEnd
17(HS_ConstFunc(struct-HS_Input-vf4-vf41[3];):14(HS_Output) Function None 15 17(HS_ConstFunc(struct-HS_Input-vf4-vf41[3];):14(HS_Output) Function None 15

View File

@ -80,10 +80,9 @@ ERROR: node is still EOpNull!
0:? 'cpid' ( in uint InvocationID) 0:? 'cpid' ( in uint InvocationID)
0:39 Sequence 0:39 Sequence
0:39 move second child to first child ( temp 4-component vector of float) 0:39 move second child to first child ( temp 4-component vector of float)
0:39 direct index ( out 4-component vector of float Position) 0:39 indirect index ( out 4-component vector of float Position)
0:? '@entryPointOutput.m_Position' ( out 3-element array of 4-component vector of float Position) 0:? '@entryPointOutput.m_Position' ( out 3-element array of 4-component vector of float Position)
0:39 Constant: 0:? 'cpid' ( in uint InvocationID)
0:39 0 (const int)
0:39 m_Position: direct index for structure ( temp 4-component vector of float) 0:39 m_Position: direct index for structure ( temp 4-component vector of float)
0:39 Function Call: @main(u1; ( temp structure{ temp 4-component vector of float m_Position}) 0:39 Function Call: @main(u1; ( temp structure{ temp 4-component vector of float m_Position})
0:? 'cpid' ( temp uint) 0:? 'cpid' ( temp uint)
@ -174,10 +173,9 @@ ERROR: node is still EOpNull!
0:? 'cpid' ( in uint InvocationID) 0:? 'cpid' ( in uint InvocationID)
0:39 Sequence 0:39 Sequence
0:39 move second child to first child ( temp 4-component vector of float) 0:39 move second child to first child ( temp 4-component vector of float)
0:39 direct index ( out 4-component vector of float Position) 0:39 indirect index ( out 4-component vector of float Position)
0:? '@entryPointOutput.m_Position' ( out 3-element array of 4-component vector of float Position) 0:? '@entryPointOutput.m_Position' ( out 3-element array of 4-component vector of float Position)
0:39 Constant: 0:? 'cpid' ( in uint InvocationID)
0:39 0 (const int)
0:39 m_Position: direct index for structure ( temp 4-component vector of float) 0:39 m_Position: direct index for structure ( temp 4-component vector of float)
0:39 Function Call: @main(u1; ( temp structure{ temp 4-component vector of float m_Position}) 0:39 Function Call: @main(u1; ( temp structure{ temp 4-component vector of float m_Position})
0:? 'cpid' ( temp uint) 0:? 'cpid' ( temp uint)

View File

@ -2731,13 +2731,23 @@ TIntermTyped* HlslParseContext::handleAssign(const TSourceLoc& loc, TOperator op
// copy from interstage IO built-in if needed // copy from interstage IO built-in if needed
subTree = intermediate.addSymbol(*builtInVar); subTree = intermediate.addSymbol(*builtInVar);
// Arrayness of builtIn symbols isn't handled by the normal recursion: if (subTree->getType().isArray()) {
// it's been extracted and moved to the built-in. // Arrayness of builtIn symbols isn't handled by the normal recursion:
if (subTree->getType().isArray() && !arrayElement.empty()) { // it's been extracted and moved to the built-in.
const TType splitDerefType(subTree->getType(), arrayElement.back()); if (!arrayElement.empty()) {
subTree = intermediate.addIndex(EOpIndexDirect, subTree, const TType splitDerefType(subTree->getType(), arrayElement.back());
intermediate.addConstantUnion(arrayElement.back(), loc), loc); subTree = intermediate.addIndex(EOpIndexDirect, subTree,
subTree->setType(splitDerefType); intermediate.addConstantUnion(arrayElement.back(), loc), loc);
subTree->setType(splitDerefType);
} else if (splitNode->getAsOperator() != nullptr && (splitNode->getAsOperator()->getOp() == EOpIndexIndirect)) {
// This might also be a stage with arrayed outputs, in which case there's an index
// operation we should transfer to the output builtin.
const TType splitDerefType(subTree->getType(), 0);
subTree = intermediate.addIndex(splitNode->getAsOperator()->getOp(), subTree,
splitNode->getAsBinaryNode()->getRight(), loc);
subTree->setType(splitDerefType);
}
} }
} else if (flattened && !shouldFlatten(derefType, isLeft ? leftStorage : rightStorage, false)) { } else if (flattened && !shouldFlatten(derefType, isLeft ? leftStorage : rightStorage, false)) {
if (isLeft) if (isLeft)