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.
void TGlslangToSpvTraverser::multiTypeStore(const glslang::TType& type, spv::Id rValue)
{
// we only do the complex path here if it's a structure
if (! type.isStruct()) {
// we only do the complex path here if it's an aggregate
if (! type.isStruct() && ! type.isArray()) {
accessChainStore(type, rValue);
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 lValue = builder.accessChainGetLValue();
spv::Id lType = builder.getContainedTypeId(builder.getTypeId(lValue));
@ -2298,26 +2298,46 @@ void TGlslangToSpvTraverser::multiTypeStore(const glslang::TType& type, spv::Id
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
// by member copy, recursively.
// loop over members
const glslang::TTypeList& members = *type.getStruct();
for (int m = 0; m < (int)members.size(); ++m) {
const glslang::TType& glslangMemberType = *members[m].type;
// 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);
// get the source member
spv::Id memberRType = builder.getContainedTypeId(rType, m);
spv::Id memberRValue = builder.createCompositeExtract(rValue, memberRType, m);
// set up the target storage
builder.clearAccessChain();
builder.setAccessChainLValue(lValue);
builder.accessChainPush(builder.makeIntConstant(index));
// set up the target storage
builder.clearAccessChain();
builder.setAccessChainLValue(lValue);
builder.accessChainPush(builder.makeIntConstant(m));
// store the member
multiTypeStore(glslangElementType, elementRValue);
}
} else {
assert(type.isStruct());
// store the member
multiTypeStore(glslangMemberType, memberRValue);
// loop over structure members
const glslang::TTypeList& members = *type.getStruct();
for (int m = 0; m < (int)members.size(); ++m) {
const glslang::TType& glslangMemberType = *members[m].type;
// get the source member
spv::Id memberRType = builder.getContainedTypeId(rType, m);
spv::Id memberRValue = builder.createCompositeExtract(rValue, memberRType, m);
// set up the target storage
builder.clearAccessChain();
builder.setAccessChainLValue(lValue);
builder.accessChainPush(builder.makeIntConstant(m));
// store the member
multiTypeStore(glslangMemberType, memberRValue);
}
}
}

View File

@ -7,7 +7,7 @@ Linked compute stage:
// Module Version 10000
// Generated by (magic number): 80001
// Id's are bound by 97
// Id's are bound by 157
Capability Shader
1: ExtInstImport "GLSL.std.450"
@ -16,177 +16,253 @@ Linked compute stage:
ExecutionMode 4 LocalSize 1 1 1
Source GLSL 450
Name 4 "main"
Name 9 "MyStruct"
MemberName 9(MyStruct) 0 "foo"
MemberName 9(MyStruct) 1 "sb"
Name 11 "t"
Name 13 "MyStruct"
MemberName 13(MyStruct) 0 "foo"
MemberName 13(MyStruct) 1 "sb"
Name 14 "SSBO0"
MemberName 14(SSBO0) 0 "a"
Name 16 "inBuf"
Name 29 "SSBO1"
MemberName 29(SSBO1) 0 "b"
Name 31 "outBuf"
Name 43 "MyStruct"
MemberName 43(MyStruct) 0 "foo"
MemberName 43(MyStruct) 1 "sb"
Name 44 "UBO"
MemberName 44(UBO) 0 "c"
Name 46 "uBuf"
Name 61 "Nested"
MemberName 61(Nested) 0 "f"
MemberName 61(Nested) 1 "S"
Name 63 "n"
Name 64 "Nested"
MemberName 64(Nested) 0 "f"
MemberName 64(Nested) 1 "S"
Name 65 "UBON"
MemberName 65(UBON) 0 "N1"
Name 67 "uBufN"
Name 80 "Nested"
MemberName 80(Nested) 0 "f"
MemberName 80(Nested) 1 "S"
Name 81 "SSBO1N"
MemberName 81(SSBO1N) 0 "N2"
Name 83 "outBufN"
MemberDecorate 13(MyStruct) 0 Offset 0
MemberDecorate 13(MyStruct) 1 Offset 16
MemberDecorate 14(SSBO0) 0 Offset 0
Decorate 14(SSBO0) BufferBlock
Decorate 16(inBuf) DescriptorSet 0
Decorate 16(inBuf) Binding 0
MemberDecorate 29(SSBO1) 0 Offset 0
Decorate 29(SSBO1) BufferBlock
Decorate 31(outBuf) DescriptorSet 0
Decorate 31(outBuf) Binding 1
MemberDecorate 43(MyStruct) 0 Offset 0
MemberDecorate 43(MyStruct) 1 Offset 16
MemberDecorate 44(UBO) 0 Offset 0
Decorate 44(UBO) Block
Decorate 46(uBuf) DescriptorSet 0
Decorate 46(uBuf) Binding 2
MemberDecorate 64(Nested) 0 Offset 0
MemberDecorate 64(Nested) 1 Offset 16
MemberDecorate 65(UBON) 0 Offset 0
Decorate 65(UBON) Block
Decorate 67(uBufN) DescriptorSet 0
Decorate 67(uBufN) Binding 2
MemberDecorate 80(Nested) 0 Offset 0
MemberDecorate 80(Nested) 1 Offset 16
MemberDecorate 81(SSBO1N) 0 Offset 0
Decorate 81(SSBO1N) BufferBlock
Decorate 83(outBufN) DescriptorSet 0
Decorate 83(outBufN) Binding 1
Name 12 "MyStruct"
MemberName 12(MyStruct) 0 "foo"
MemberName 12(MyStruct) 1 "sb"
Name 14 "t"
Name 16 "MyStruct"
MemberName 16(MyStruct) 0 "foo"
MemberName 16(MyStruct) 1 "sb"
Name 17 "SSBO0"
MemberName 17(SSBO0) 0 "a"
Name 19 "inBuf"
Name 37 "SSBO1"
MemberName 37(SSBO1) 0 "b"
Name 39 "outBuf"
Name 57 "MyStruct"
MemberName 57(MyStruct) 0 "foo"
MemberName 57(MyStruct) 1 "sb"
Name 58 "UBO"
MemberName 58(UBO) 0 "c"
Name 60 "uBuf"
Name 84 "Nested"
MemberName 84(Nested) 0 "f"
MemberName 84(Nested) 1 "S"
Name 86 "n"
Name 88 "Nested"
MemberName 88(Nested) 0 "f"
MemberName 88(Nested) 1 "S"
Name 89 "UBON"
MemberName 89(UBON) 0 "N1"
Name 91 "uBufN"
Name 122 "Nested"
MemberName 122(Nested) 0 "f"
MemberName 122(Nested) 1 "S"
Name 123 "SSBO1N"
MemberName 123(SSBO1N) 0 "N2"
Name 125 "outBufN"
Decorate 15 ArrayStride 8
MemberDecorate 16(MyStruct) 0 Offset 0
MemberDecorate 16(MyStruct) 1 Offset 16
MemberDecorate 17(SSBO0) 0 Offset 0
Decorate 17(SSBO0) BufferBlock
Decorate 19(inBuf) DescriptorSet 0
Decorate 19(inBuf) Binding 0
MemberDecorate 37(SSBO1) 0 Offset 0
Decorate 37(SSBO1) BufferBlock
Decorate 39(outBuf) DescriptorSet 0
Decorate 39(outBuf) Binding 1
Decorate 56 ArrayStride 16
MemberDecorate 57(MyStruct) 0 Offset 0
MemberDecorate 57(MyStruct) 1 Offset 32
MemberDecorate 58(UBO) 0 Offset 0
Decorate 58(UBO) Block
Decorate 60(uBuf) DescriptorSet 0
Decorate 60(uBuf) Binding 2
Decorate 87 ArrayStride 48
MemberDecorate 88(Nested) 0 Offset 0
MemberDecorate 88(Nested) 1 Offset 16
MemberDecorate 89(UBON) 0 Offset 0
Decorate 89(UBON) Block
Decorate 91(uBufN) DescriptorSet 0
Decorate 91(uBufN) Binding 2
Decorate 121 ArrayStride 24
MemberDecorate 122(Nested) 0 Offset 0
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
3: TypeFunction 2
6: TypeFloat 32
7: TypeVector 6(float) 4
8: TypeBool
9(MyStruct): TypeStruct 7(fvec4) 8(bool)
10: TypePointer Function 9(MyStruct)
12: TypeInt 32 0
13(MyStruct): TypeStruct 7(fvec4) 12(int)
14(SSBO0): TypeStruct 13(MyStruct)
15: TypePointer Uniform 14(SSBO0)
16(inBuf): 15(ptr) Variable Uniform
17: TypeInt 32 1
18: 17(int) Constant 0
19: TypePointer Uniform 13(MyStruct)
23: TypePointer Function 7(fvec4)
26: 17(int) Constant 1
27: TypePointer Function 8(bool)
29(SSBO1): TypeStruct 13(MyStruct)
30: TypePointer Uniform 29(SSBO1)
31(outBuf): 30(ptr) Variable Uniform
35: TypePointer Uniform 7(fvec4)
38: 12(int) Constant 0
39: 12(int) Constant 1
41: TypePointer Uniform 12(int)
43(MyStruct): TypeStruct 7(fvec4) 12(int)
44(UBO): TypeStruct 43(MyStruct)
45: TypePointer Uniform 44(UBO)
46(uBuf): 45(ptr) Variable Uniform
47: TypePointer Uniform 43(MyStruct)
61(Nested): TypeStruct 6(float) 9(MyStruct)
62: TypePointer Function 61(Nested)
64(Nested): TypeStruct 6(float) 43(MyStruct)
65(UBON): TypeStruct 64(Nested)
66: TypePointer Uniform 65(UBON)
67(uBufN): 66(ptr) Variable Uniform
68: TypePointer Uniform 64(Nested)
72: TypePointer Function 6(float)
80(Nested): TypeStruct 6(float) 13(MyStruct)
81(SSBO1N): TypeStruct 80(Nested)
82: TypePointer Uniform 81(SSBO1N)
83(outBufN): 82(ptr) Variable Uniform
85: TypePointer Uniform 80(Nested)
88: TypePointer Uniform 6(float)
7: TypeVector 6(float) 2
8: TypeInt 32 0
9: 8(int) Constant 2
10: TypeArray 7(fvec2) 9
11: TypeBool
12(MyStruct): TypeStruct 10 11(bool)
13: TypePointer Function 12(MyStruct)
15: TypeArray 7(fvec2) 9
16(MyStruct): TypeStruct 15 8(int)
17(SSBO0): TypeStruct 16(MyStruct)
18: TypePointer Uniform 17(SSBO0)
19(inBuf): 18(ptr) Variable Uniform
20: TypeInt 32 1
21: 20(int) Constant 0
22: TypePointer Uniform 16(MyStruct)
26: TypePointer Function 10
29: TypePointer Function 7(fvec2)
32: 20(int) Constant 1
35: TypePointer Function 11(bool)
37(SSBO1): TypeStruct 16(MyStruct)
38: TypePointer Uniform 37(SSBO1)
39(outBuf): 38(ptr) Variable Uniform
43: TypePointer Uniform 15
46: TypePointer Uniform 7(fvec2)
51: 8(int) Constant 0
52: 8(int) Constant 1
54: TypePointer Uniform 8(int)
56: TypeArray 7(fvec2) 9
57(MyStruct): TypeStruct 56 8(int)
58(UBO): TypeStruct 57(MyStruct)
59: TypePointer Uniform 58(UBO)
60(uBuf): 59(ptr) Variable Uniform
61: TypePointer Uniform 57(MyStruct)
83: TypeArray 12(MyStruct) 9
84(Nested): TypeStruct 6(float) 83
85: TypePointer Function 84(Nested)
87: TypeArray 57(MyStruct) 9
88(Nested): TypeStruct 6(float) 87
89(UBON): TypeStruct 88(Nested)
90: TypePointer Uniform 89(UBON)
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
5: Label
11(t): 10(ptr) Variable Function
63(n): 62(ptr) Variable Function
20: 19(ptr) AccessChain 16(inBuf) 18
21:13(MyStruct) Load 20
22: 7(fvec4) CompositeExtract 21 0
24: 23(ptr) AccessChain 11(t) 18
Store 24 22
25: 12(int) CompositeExtract 21 1
28: 27(ptr) AccessChain 11(t) 26
Store 28 25
32: 9(MyStruct) Load 11(t)
33: 19(ptr) AccessChain 31(outBuf) 18
34: 7(fvec4) CompositeExtract 32 0
36: 35(ptr) AccessChain 33 18
14(t): 13(ptr) Variable Function
86(n): 85(ptr) Variable Function
23: 22(ptr) AccessChain 19(inBuf) 21
24:16(MyStruct) Load 23
25: 15 CompositeExtract 24 0
27: 26(ptr) AccessChain 14(t) 21
28: 7(fvec2) CompositeExtract 25 0
30: 29(ptr) AccessChain 27 21
Store 30 28
31: 7(fvec2) CompositeExtract 25 1
33: 29(ptr) AccessChain 27 32
Store 33 31
34: 8(int) CompositeExtract 24 1
36: 35(ptr) AccessChain 14(t) 32
Store 36 34
37: 8(bool) CompositeExtract 32 1
40: 12(int) Select 37 39 38
42: 41(ptr) AccessChain 33 26
Store 42 40
48: 47(ptr) AccessChain 46(uBuf) 18
49:43(MyStruct) Load 48
50: 7(fvec4) CompositeExtract 49 0
51: 23(ptr) AccessChain 11(t) 18
Store 51 50
52: 12(int) CompositeExtract 49 1
53: 27(ptr) AccessChain 11(t) 26
Store 53 52
54: 9(MyStruct) Load 11(t)
55: 19(ptr) AccessChain 31(outBuf) 18
56: 7(fvec4) CompositeExtract 54 0
57: 35(ptr) AccessChain 55 18
Store 57 56
58: 8(bool) CompositeExtract 54 1
59: 12(int) Select 58 39 38
60: 41(ptr) AccessChain 55 26
Store 60 59
69: 68(ptr) AccessChain 67(uBufN) 18
70: 64(Nested) Load 69
71: 6(float) CompositeExtract 70 0
73: 72(ptr) AccessChain 63(n) 18
Store 73 71
74:43(MyStruct) CompositeExtract 70 1
75: 10(ptr) AccessChain 63(n) 26
76: 7(fvec4) CompositeExtract 74 0
77: 23(ptr) AccessChain 75 18
40:12(MyStruct) Load 14(t)
41: 22(ptr) AccessChain 39(outBuf) 21
42: 10 CompositeExtract 40 0
44: 43(ptr) AccessChain 41 21
45: 7(fvec2) CompositeExtract 42 0
47: 46(ptr) AccessChain 44 21
Store 47 45
48: 7(fvec2) CompositeExtract 42 1
49: 46(ptr) AccessChain 44 32
Store 49 48
50: 11(bool) CompositeExtract 40 1
53: 8(int) Select 50 52 51
55: 54(ptr) AccessChain 41 32
Store 55 53
62: 61(ptr) AccessChain 60(uBuf) 21
63:57(MyStruct) Load 62
64: 56 CompositeExtract 63 0
65: 26(ptr) AccessChain 14(t) 21
66: 7(fvec2) CompositeExtract 64 0
67: 29(ptr) AccessChain 65 21
Store 67 66
68: 7(fvec2) CompositeExtract 64 1
69: 29(ptr) AccessChain 65 32
Store 69 68
70: 8(int) CompositeExtract 63 1
71: 35(ptr) AccessChain 14(t) 32
Store 71 70
72:12(MyStruct) Load 14(t)
73: 22(ptr) AccessChain 39(outBuf) 21
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
78: 12(int) CompositeExtract 74 1
79: 27(ptr) AccessChain 75 26
78: 7(fvec2) CompositeExtract 74 1
79: 46(ptr) AccessChain 75 32
Store 79 78
84: 61(Nested) Load 63(n)
86: 85(ptr) AccessChain 83(outBufN) 18
87: 6(float) CompositeExtract 84 0
89: 88(ptr) AccessChain 86 18
Store 89 87
90: 9(MyStruct) CompositeExtract 84 1
91: 19(ptr) AccessChain 86 26
92: 7(fvec4) CompositeExtract 90 0
93: 35(ptr) AccessChain 91 18
Store 93 92
94: 8(bool) CompositeExtract 90 1
95: 12(int) Select 94 39 38
96: 41(ptr) AccessChain 91 26
Store 96 95
80: 11(bool) CompositeExtract 72 1
81: 8(int) Select 80 52 51
82: 54(ptr) AccessChain 73 32
Store 82 81
93: 92(ptr) AccessChain 91(uBufN) 21
94: 88(Nested) Load 93
95: 6(float) CompositeExtract 94 0
97: 96(ptr) AccessChain 86(n) 21
Store 97 95
98: 87 CompositeExtract 94 1
100: 99(ptr) AccessChain 86(n) 32
101:57(MyStruct) CompositeExtract 98 0
102: 13(ptr) AccessChain 100 21
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
FunctionEnd

View File

@ -2,7 +2,7 @@
struct MyStruct
{
vec4 foo;
vec2 foo[2];
bool sb;
};
@ -23,7 +23,7 @@ layout(binding = 2, std140) uniform UBO
struct Nested {
float f;
MyStruct S;
MyStruct S[2];
};
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).
#define GLSLANG_REVISION "Overload400-PrecQual.1481"
#define GLSLANG_DATE "10-Sep-2016"
#define GLSLANG_DATE "11-Sep-2016"