SPV: Fix issue #506: generalize struct deep copy to include arrays.

This commit is contained in:
John Kessenich 2016-09-11 12:33:43 -06:00
parent cd0a78a0d9
commit b3e24e4359
4 changed files with 281 additions and 185 deletions

View File

@ -2283,13 +2283,13 @@ void TGlslangToSpvTraverser::accessChainStore(const glslang::TType& type, spv::I
// Implicitly uses the existing builder.accessChain as the storage target. // Implicitly uses the existing builder.accessChain as the storage target.
void TGlslangToSpvTraverser::multiTypeStore(const glslang::TType& type, spv::Id rValue) void TGlslangToSpvTraverser::multiTypeStore(const glslang::TType& type, spv::Id rValue)
{ {
// we only do the complex path here if it's a structure // we only do the complex path here if it's an aggregate
if (! type.isStruct()) { if (! type.isStruct() && ! type.isArray()) {
accessChainStore(type, rValue); accessChainStore(type, rValue);
return; return;
} }
// and, it has to be a case of structure type aliasing // and, it has to be a case of type aliasing
spv::Id rType = builder.getTypeId(rValue); spv::Id rType = builder.getTypeId(rValue);
spv::Id lValue = builder.accessChainGetLValue(); spv::Id lValue = builder.accessChainGetLValue();
spv::Id lType = builder.getContainedTypeId(builder.getTypeId(lValue)); spv::Id lType = builder.getContainedTypeId(builder.getTypeId(lValue));
@ -2298,11 +2298,30 @@ void TGlslangToSpvTraverser::multiTypeStore(const glslang::TType& type, spv::Id
return; return;
} }
// Recursively (as needed) copy a struct type to a different struct type, // Recursively (as needed) copy an aggregate type to a different aggregate type,
// where the two types were the same type in GLSL. This requires member // where the two types were the same type in GLSL. This requires member
// by member copy, recursively. // by member copy, recursively.
// loop over members // If an array, copy element by element.
if (type.isArray()) {
glslang::TType glslangElementType(type, 0);
spv::Id elementRType = builder.getContainedTypeId(rType);
for (int index = 0; index < type.getOuterArraySize(); ++index) {
// get the source member
spv::Id elementRValue = builder.createCompositeExtract(rValue, elementRType, index);
// set up the target storage
builder.clearAccessChain();
builder.setAccessChainLValue(lValue);
builder.accessChainPush(builder.makeIntConstant(index));
// store the member
multiTypeStore(glslangElementType, elementRValue);
}
} else {
assert(type.isStruct());
// loop over structure members
const glslang::TTypeList& members = *type.getStruct(); const glslang::TTypeList& members = *type.getStruct();
for (int m = 0; m < (int)members.size(); ++m) { for (int m = 0; m < (int)members.size(); ++m) {
const glslang::TType& glslangMemberType = *members[m].type; const glslang::TType& glslangMemberType = *members[m].type;
@ -2319,6 +2338,7 @@ void TGlslangToSpvTraverser::multiTypeStore(const glslang::TType& type, spv::Id
// store the member // store the member
multiTypeStore(glslangMemberType, memberRValue); multiTypeStore(glslangMemberType, memberRValue);
} }
}
} }
// Decide whether or not this type should be // Decide whether or not this type should be

View File

@ -7,7 +7,7 @@ Linked compute stage:
// Module Version 10000 // Module Version 10000
// Generated by (magic number): 80001 // Generated by (magic number): 80001
// Id's are bound by 97 // Id's are bound by 157
Capability Shader Capability Shader
1: ExtInstImport "GLSL.std.450" 1: ExtInstImport "GLSL.std.450"
@ -16,177 +16,253 @@ Linked compute stage:
ExecutionMode 4 LocalSize 1 1 1 ExecutionMode 4 LocalSize 1 1 1
Source GLSL 450 Source GLSL 450
Name 4 "main" Name 4 "main"
Name 9 "MyStruct" Name 12 "MyStruct"
MemberName 9(MyStruct) 0 "foo" MemberName 12(MyStruct) 0 "foo"
MemberName 9(MyStruct) 1 "sb" MemberName 12(MyStruct) 1 "sb"
Name 11 "t" Name 14 "t"
Name 13 "MyStruct" Name 16 "MyStruct"
MemberName 13(MyStruct) 0 "foo" MemberName 16(MyStruct) 0 "foo"
MemberName 13(MyStruct) 1 "sb" MemberName 16(MyStruct) 1 "sb"
Name 14 "SSBO0" Name 17 "SSBO0"
MemberName 14(SSBO0) 0 "a" MemberName 17(SSBO0) 0 "a"
Name 16 "inBuf" Name 19 "inBuf"
Name 29 "SSBO1" Name 37 "SSBO1"
MemberName 29(SSBO1) 0 "b" MemberName 37(SSBO1) 0 "b"
Name 31 "outBuf" Name 39 "outBuf"
Name 43 "MyStruct" Name 57 "MyStruct"
MemberName 43(MyStruct) 0 "foo" MemberName 57(MyStruct) 0 "foo"
MemberName 43(MyStruct) 1 "sb" MemberName 57(MyStruct) 1 "sb"
Name 44 "UBO" Name 58 "UBO"
MemberName 44(UBO) 0 "c" MemberName 58(UBO) 0 "c"
Name 46 "uBuf" Name 60 "uBuf"
Name 61 "Nested" Name 84 "Nested"
MemberName 61(Nested) 0 "f" MemberName 84(Nested) 0 "f"
MemberName 61(Nested) 1 "S" MemberName 84(Nested) 1 "S"
Name 63 "n" Name 86 "n"
Name 64 "Nested" Name 88 "Nested"
MemberName 64(Nested) 0 "f" MemberName 88(Nested) 0 "f"
MemberName 64(Nested) 1 "S" MemberName 88(Nested) 1 "S"
Name 65 "UBON" Name 89 "UBON"
MemberName 65(UBON) 0 "N1" MemberName 89(UBON) 0 "N1"
Name 67 "uBufN" Name 91 "uBufN"
Name 80 "Nested" Name 122 "Nested"
MemberName 80(Nested) 0 "f" MemberName 122(Nested) 0 "f"
MemberName 80(Nested) 1 "S" MemberName 122(Nested) 1 "S"
Name 81 "SSBO1N" Name 123 "SSBO1N"
MemberName 81(SSBO1N) 0 "N2" MemberName 123(SSBO1N) 0 "N2"
Name 83 "outBufN" Name 125 "outBufN"
MemberDecorate 13(MyStruct) 0 Offset 0 Decorate 15 ArrayStride 8
MemberDecorate 13(MyStruct) 1 Offset 16 MemberDecorate 16(MyStruct) 0 Offset 0
MemberDecorate 14(SSBO0) 0 Offset 0 MemberDecorate 16(MyStruct) 1 Offset 16
Decorate 14(SSBO0) BufferBlock MemberDecorate 17(SSBO0) 0 Offset 0
Decorate 16(inBuf) DescriptorSet 0 Decorate 17(SSBO0) BufferBlock
Decorate 16(inBuf) Binding 0 Decorate 19(inBuf) DescriptorSet 0
MemberDecorate 29(SSBO1) 0 Offset 0 Decorate 19(inBuf) Binding 0
Decorate 29(SSBO1) BufferBlock MemberDecorate 37(SSBO1) 0 Offset 0
Decorate 31(outBuf) DescriptorSet 0 Decorate 37(SSBO1) BufferBlock
Decorate 31(outBuf) Binding 1 Decorate 39(outBuf) DescriptorSet 0
MemberDecorate 43(MyStruct) 0 Offset 0 Decorate 39(outBuf) Binding 1
MemberDecorate 43(MyStruct) 1 Offset 16 Decorate 56 ArrayStride 16
MemberDecorate 44(UBO) 0 Offset 0 MemberDecorate 57(MyStruct) 0 Offset 0
Decorate 44(UBO) Block MemberDecorate 57(MyStruct) 1 Offset 32
Decorate 46(uBuf) DescriptorSet 0 MemberDecorate 58(UBO) 0 Offset 0
Decorate 46(uBuf) Binding 2 Decorate 58(UBO) Block
MemberDecorate 64(Nested) 0 Offset 0 Decorate 60(uBuf) DescriptorSet 0
MemberDecorate 64(Nested) 1 Offset 16 Decorate 60(uBuf) Binding 2
MemberDecorate 65(UBON) 0 Offset 0 Decorate 87 ArrayStride 48
Decorate 65(UBON) Block MemberDecorate 88(Nested) 0 Offset 0
Decorate 67(uBufN) DescriptorSet 0 MemberDecorate 88(Nested) 1 Offset 16
Decorate 67(uBufN) Binding 2 MemberDecorate 89(UBON) 0 Offset 0
MemberDecorate 80(Nested) 0 Offset 0 Decorate 89(UBON) Block
MemberDecorate 80(Nested) 1 Offset 16 Decorate 91(uBufN) DescriptorSet 0
MemberDecorate 81(SSBO1N) 0 Offset 0 Decorate 91(uBufN) Binding 2
Decorate 81(SSBO1N) BufferBlock Decorate 121 ArrayStride 24
Decorate 83(outBufN) DescriptorSet 0 MemberDecorate 122(Nested) 0 Offset 0
Decorate 83(outBufN) Binding 1 MemberDecorate 122(Nested) 1 Offset 8
MemberDecorate 123(SSBO1N) 0 Offset 0
Decorate 123(SSBO1N) BufferBlock
Decorate 125(outBufN) DescriptorSet 0
Decorate 125(outBufN) Binding 1
2: TypeVoid 2: TypeVoid
3: TypeFunction 2 3: TypeFunction 2
6: TypeFloat 32 6: TypeFloat 32
7: TypeVector 6(float) 4 7: TypeVector 6(float) 2
8: TypeBool 8: TypeInt 32 0
9(MyStruct): TypeStruct 7(fvec4) 8(bool) 9: 8(int) Constant 2
10: TypePointer Function 9(MyStruct) 10: TypeArray 7(fvec2) 9
12: TypeInt 32 0 11: TypeBool
13(MyStruct): TypeStruct 7(fvec4) 12(int) 12(MyStruct): TypeStruct 10 11(bool)
14(SSBO0): TypeStruct 13(MyStruct) 13: TypePointer Function 12(MyStruct)
15: TypePointer Uniform 14(SSBO0) 15: TypeArray 7(fvec2) 9
16(inBuf): 15(ptr) Variable Uniform 16(MyStruct): TypeStruct 15 8(int)
17: TypeInt 32 1 17(SSBO0): TypeStruct 16(MyStruct)
18: 17(int) Constant 0 18: TypePointer Uniform 17(SSBO0)
19: TypePointer Uniform 13(MyStruct) 19(inBuf): 18(ptr) Variable Uniform
23: TypePointer Function 7(fvec4) 20: TypeInt 32 1
26: 17(int) Constant 1 21: 20(int) Constant 0
27: TypePointer Function 8(bool) 22: TypePointer Uniform 16(MyStruct)
29(SSBO1): TypeStruct 13(MyStruct) 26: TypePointer Function 10
30: TypePointer Uniform 29(SSBO1) 29: TypePointer Function 7(fvec2)
31(outBuf): 30(ptr) Variable Uniform 32: 20(int) Constant 1
35: TypePointer Uniform 7(fvec4) 35: TypePointer Function 11(bool)
38: 12(int) Constant 0 37(SSBO1): TypeStruct 16(MyStruct)
39: 12(int) Constant 1 38: TypePointer Uniform 37(SSBO1)
41: TypePointer Uniform 12(int) 39(outBuf): 38(ptr) Variable Uniform
43(MyStruct): TypeStruct 7(fvec4) 12(int) 43: TypePointer Uniform 15
44(UBO): TypeStruct 43(MyStruct) 46: TypePointer Uniform 7(fvec2)
45: TypePointer Uniform 44(UBO) 51: 8(int) Constant 0
46(uBuf): 45(ptr) Variable Uniform 52: 8(int) Constant 1
47: TypePointer Uniform 43(MyStruct) 54: TypePointer Uniform 8(int)
61(Nested): TypeStruct 6(float) 9(MyStruct) 56: TypeArray 7(fvec2) 9
62: TypePointer Function 61(Nested) 57(MyStruct): TypeStruct 56 8(int)
64(Nested): TypeStruct 6(float) 43(MyStruct) 58(UBO): TypeStruct 57(MyStruct)
65(UBON): TypeStruct 64(Nested) 59: TypePointer Uniform 58(UBO)
66: TypePointer Uniform 65(UBON) 60(uBuf): 59(ptr) Variable Uniform
67(uBufN): 66(ptr) Variable Uniform 61: TypePointer Uniform 57(MyStruct)
68: TypePointer Uniform 64(Nested) 83: TypeArray 12(MyStruct) 9
72: TypePointer Function 6(float) 84(Nested): TypeStruct 6(float) 83
80(Nested): TypeStruct 6(float) 13(MyStruct) 85: TypePointer Function 84(Nested)
81(SSBO1N): TypeStruct 80(Nested) 87: TypeArray 57(MyStruct) 9
82: TypePointer Uniform 81(SSBO1N) 88(Nested): TypeStruct 6(float) 87
83(outBufN): 82(ptr) Variable Uniform 89(UBON): TypeStruct 88(Nested)
85: TypePointer Uniform 80(Nested) 90: TypePointer Uniform 89(UBON)
88: TypePointer Uniform 6(float) 91(uBufN): 90(ptr) Variable Uniform
92: TypePointer Uniform 88(Nested)
96: TypePointer Function 6(float)
99: TypePointer Function 83
121: TypeArray 16(MyStruct) 9
122(Nested): TypeStruct 6(float) 121
123(SSBO1N): TypeStruct 122(Nested)
124: TypePointer Uniform 123(SSBO1N)
125(outBufN): 124(ptr) Variable Uniform
127: TypePointer Uniform 122(Nested)
130: TypePointer Uniform 6(float)
133: TypePointer Uniform 121
4(main): 2 Function None 3 4(main): 2 Function None 3
5: Label 5: Label
11(t): 10(ptr) Variable Function 14(t): 13(ptr) Variable Function
63(n): 62(ptr) Variable Function 86(n): 85(ptr) Variable Function
20: 19(ptr) AccessChain 16(inBuf) 18 23: 22(ptr) AccessChain 19(inBuf) 21
21:13(MyStruct) Load 20 24:16(MyStruct) Load 23
22: 7(fvec4) CompositeExtract 21 0 25: 15 CompositeExtract 24 0
24: 23(ptr) AccessChain 11(t) 18 27: 26(ptr) AccessChain 14(t) 21
Store 24 22 28: 7(fvec2) CompositeExtract 25 0
25: 12(int) CompositeExtract 21 1 30: 29(ptr) AccessChain 27 21
28: 27(ptr) AccessChain 11(t) 26 Store 30 28
Store 28 25 31: 7(fvec2) CompositeExtract 25 1
32: 9(MyStruct) Load 11(t) 33: 29(ptr) AccessChain 27 32
33: 19(ptr) AccessChain 31(outBuf) 18 Store 33 31
34: 7(fvec4) CompositeExtract 32 0 34: 8(int) CompositeExtract 24 1
36: 35(ptr) AccessChain 33 18 36: 35(ptr) AccessChain 14(t) 32
Store 36 34 Store 36 34
37: 8(bool) CompositeExtract 32 1 40:12(MyStruct) Load 14(t)
40: 12(int) Select 37 39 38 41: 22(ptr) AccessChain 39(outBuf) 21
42: 41(ptr) AccessChain 33 26 42: 10 CompositeExtract 40 0
Store 42 40 44: 43(ptr) AccessChain 41 21
48: 47(ptr) AccessChain 46(uBuf) 18 45: 7(fvec2) CompositeExtract 42 0
49:43(MyStruct) Load 48 47: 46(ptr) AccessChain 44 21
50: 7(fvec4) CompositeExtract 49 0 Store 47 45
51: 23(ptr) AccessChain 11(t) 18 48: 7(fvec2) CompositeExtract 42 1
Store 51 50 49: 46(ptr) AccessChain 44 32
52: 12(int) CompositeExtract 49 1 Store 49 48
53: 27(ptr) AccessChain 11(t) 26 50: 11(bool) CompositeExtract 40 1
Store 53 52 53: 8(int) Select 50 52 51
54: 9(MyStruct) Load 11(t) 55: 54(ptr) AccessChain 41 32
55: 19(ptr) AccessChain 31(outBuf) 18 Store 55 53
56: 7(fvec4) CompositeExtract 54 0 62: 61(ptr) AccessChain 60(uBuf) 21
57: 35(ptr) AccessChain 55 18 63:57(MyStruct) Load 62
Store 57 56 64: 56 CompositeExtract 63 0
58: 8(bool) CompositeExtract 54 1 65: 26(ptr) AccessChain 14(t) 21
59: 12(int) Select 58 39 38 66: 7(fvec2) CompositeExtract 64 0
60: 41(ptr) AccessChain 55 26 67: 29(ptr) AccessChain 65 21
Store 60 59 Store 67 66
69: 68(ptr) AccessChain 67(uBufN) 18 68: 7(fvec2) CompositeExtract 64 1
70: 64(Nested) Load 69 69: 29(ptr) AccessChain 65 32
71: 6(float) CompositeExtract 70 0 Store 69 68
73: 72(ptr) AccessChain 63(n) 18 70: 8(int) CompositeExtract 63 1
Store 73 71 71: 35(ptr) AccessChain 14(t) 32
74:43(MyStruct) CompositeExtract 70 1 Store 71 70
75: 10(ptr) AccessChain 63(n) 26 72:12(MyStruct) Load 14(t)
76: 7(fvec4) CompositeExtract 74 0 73: 22(ptr) AccessChain 39(outBuf) 21
77: 23(ptr) AccessChain 75 18 74: 10 CompositeExtract 72 0
75: 43(ptr) AccessChain 73 21
76: 7(fvec2) CompositeExtract 74 0
77: 46(ptr) AccessChain 75 21
Store 77 76 Store 77 76
78: 12(int) CompositeExtract 74 1 78: 7(fvec2) CompositeExtract 74 1
79: 27(ptr) AccessChain 75 26 79: 46(ptr) AccessChain 75 32
Store 79 78 Store 79 78
84: 61(Nested) Load 63(n) 80: 11(bool) CompositeExtract 72 1
86: 85(ptr) AccessChain 83(outBufN) 18 81: 8(int) Select 80 52 51
87: 6(float) CompositeExtract 84 0 82: 54(ptr) AccessChain 73 32
89: 88(ptr) AccessChain 86 18 Store 82 81
Store 89 87 93: 92(ptr) AccessChain 91(uBufN) 21
90: 9(MyStruct) CompositeExtract 84 1 94: 88(Nested) Load 93
91: 19(ptr) AccessChain 86 26 95: 6(float) CompositeExtract 94 0
92: 7(fvec4) CompositeExtract 90 0 97: 96(ptr) AccessChain 86(n) 21
93: 35(ptr) AccessChain 91 18 Store 97 95
Store 93 92 98: 87 CompositeExtract 94 1
94: 8(bool) CompositeExtract 90 1 100: 99(ptr) AccessChain 86(n) 32
95: 12(int) Select 94 39 38 101:57(MyStruct) CompositeExtract 98 0
96: 41(ptr) AccessChain 91 26 102: 13(ptr) AccessChain 100 21
Store 96 95 103: 56 CompositeExtract 101 0
104: 26(ptr) AccessChain 102 21
105: 7(fvec2) CompositeExtract 103 0
106: 29(ptr) AccessChain 104 21
Store 106 105
107: 7(fvec2) CompositeExtract 103 1
108: 29(ptr) AccessChain 104 32
Store 108 107
109: 8(int) CompositeExtract 101 1
110: 35(ptr) AccessChain 102 32
Store 110 109
111:57(MyStruct) CompositeExtract 98 1
112: 13(ptr) AccessChain 100 32
113: 56 CompositeExtract 111 0
114: 26(ptr) AccessChain 112 21
115: 7(fvec2) CompositeExtract 113 0
116: 29(ptr) AccessChain 114 21
Store 116 115
117: 7(fvec2) CompositeExtract 113 1
118: 29(ptr) AccessChain 114 32
Store 118 117
119: 8(int) CompositeExtract 111 1
120: 35(ptr) AccessChain 112 32
Store 120 119
126: 84(Nested) Load 86(n)
128: 127(ptr) AccessChain 125(outBufN) 21
129: 6(float) CompositeExtract 126 0
131: 130(ptr) AccessChain 128 21
Store 131 129
132: 83 CompositeExtract 126 1
134: 133(ptr) AccessChain 128 32
135:12(MyStruct) CompositeExtract 132 0
136: 22(ptr) AccessChain 134 21
137: 10 CompositeExtract 135 0
138: 43(ptr) AccessChain 136 21
139: 7(fvec2) CompositeExtract 137 0
140: 46(ptr) AccessChain 138 21
Store 140 139
141: 7(fvec2) CompositeExtract 137 1
142: 46(ptr) AccessChain 138 32
Store 142 141
143: 11(bool) CompositeExtract 135 1
144: 8(int) Select 143 52 51
145: 54(ptr) AccessChain 136 32
Store 145 144
146:12(MyStruct) CompositeExtract 132 1
147: 22(ptr) AccessChain 134 32
148: 10 CompositeExtract 146 0
149: 43(ptr) AccessChain 147 21
150: 7(fvec2) CompositeExtract 148 0
151: 46(ptr) AccessChain 149 21
Store 151 150
152: 7(fvec2) CompositeExtract 148 1
153: 46(ptr) AccessChain 149 32
Store 153 152
154: 11(bool) CompositeExtract 146 1
155: 8(int) Select 154 52 51
156: 54(ptr) AccessChain 147 32
Store 156 155
Return Return
FunctionEnd FunctionEnd

View File

@ -2,7 +2,7 @@
struct MyStruct struct MyStruct
{ {
vec4 foo; vec2 foo[2];
bool sb; bool sb;
}; };
@ -23,7 +23,7 @@ layout(binding = 2, std140) uniform UBO
struct Nested { struct Nested {
float f; float f;
MyStruct S; MyStruct S[2];
}; };
layout(binding = 2, std140) uniform UBON layout(binding = 2, std140) uniform UBON

View File

@ -3,4 +3,4 @@
// 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.1481" #define GLSLANG_REVISION "Overload400-PrecQual.1481"
#define GLSLANG_DATE "10-Sep-2016" #define GLSLANG_DATE "11-Sep-2016"