SPV: Flatten structs for copy when they are GLSL type aliases.
Addresses issue #304 and issue #307 by replacing unmatched type OpStores with per-member copies. Covers assignment statements and most argument passing, but does not yet cover r-value-based argument passing.
This commit is contained in:
parent
31207bc20a
commit
4bf7155051
7 changed files with 455 additions and 26 deletions
192
Test/baseResults/spv.multiStruct.comp.out
Executable file
192
Test/baseResults/spv.multiStruct.comp.out
Executable file
|
|
@ -0,0 +1,192 @@
|
|||
spv.multiStruct.comp
|
||||
Warning, version 450 is not yet complete; most version-specific features are present, but some are missing.
|
||||
|
||||
|
||||
Linked compute stage:
|
||||
|
||||
|
||||
// Module Version 10000
|
||||
// Generated by (magic number): 80001
|
||||
// Id's are bound by 97
|
||||
|
||||
Capability Shader
|
||||
1: ExtInstImport "GLSL.std.450"
|
||||
MemoryModel Logical GLSL450
|
||||
EntryPoint GLCompute 4 "main"
|
||||
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
|
||||
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)
|
||||
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
|
||||
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
|
||||
Store 77 76
|
||||
78: 12(int) CompositeExtract 74 1
|
||||
79: 27(ptr) AccessChain 75 26
|
||||
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
|
||||
Return
|
||||
FunctionEnd
|
||||
120
Test/baseResults/spv.multiStructFuncall.frag.out
Executable file
120
Test/baseResults/spv.multiStructFuncall.frag.out
Executable file
|
|
@ -0,0 +1,120 @@
|
|||
spv.multiStructFuncall.frag
|
||||
Warning, version 450 is not yet complete; most version-specific features are present, but some are missing.
|
||||
|
||||
|
||||
Linked fragment stage:
|
||||
|
||||
|
||||
// Module Version 10000
|
||||
// Generated by (magic number): 80001
|
||||
// Id's are bound by 63
|
||||
|
||||
Capability Shader
|
||||
1: ExtInstImport "GLSL.std.450"
|
||||
MemoryModel Logical GLSL450
|
||||
EntryPoint Fragment 4 "main"
|
||||
ExecutionMode 4 OriginUpperLeft
|
||||
Source GLSL 450
|
||||
Name 4 "main"
|
||||
Name 9 "S"
|
||||
MemberName 9(S) 0 "m"
|
||||
Name 12 "fooConst(struct-S-mf441;"
|
||||
Name 11 "s"
|
||||
Name 17 "foo(struct-S-mf441;"
|
||||
Name 16 "s"
|
||||
Name 20 "fooOut(struct-S-mf441;"
|
||||
Name 19 "s"
|
||||
Name 22 "S"
|
||||
MemberName 22(S) 0 "m"
|
||||
Name 23 "blockName"
|
||||
MemberName 23(blockName) 0 "s1"
|
||||
Name 25 ""
|
||||
Name 33 "s2"
|
||||
Name 36 "S"
|
||||
MemberName 36(S) 0 "m"
|
||||
Name 38 "param"
|
||||
Name 45 "param"
|
||||
Name 48 "param"
|
||||
Name 59 "param"
|
||||
MemberDecorate 22(S) 0 ColMajor
|
||||
MemberDecorate 22(S) 0 Offset 0
|
||||
MemberDecorate 22(S) 0 MatrixStride 16
|
||||
MemberDecorate 23(blockName) 0 Offset 0
|
||||
Decorate 23(blockName) BufferBlock
|
||||
Decorate 25 DescriptorSet 0
|
||||
MemberDecorate 36(S) 0 ColMajor
|
||||
2: TypeVoid
|
||||
3: TypeFunction 2
|
||||
6: TypeFloat 32
|
||||
7: TypeVector 6(float) 4
|
||||
8: TypeMatrix 7(fvec4) 4
|
||||
9(S): TypeStruct 8
|
||||
10: TypeFunction 2 9(S)
|
||||
14: TypePointer Function 9(S)
|
||||
15: TypeFunction 2 14(ptr)
|
||||
22(S): TypeStruct 8
|
||||
23(blockName): TypeStruct 22(S)
|
||||
24: TypePointer Uniform 23(blockName)
|
||||
25: 24(ptr) Variable Uniform
|
||||
26: TypeInt 32 1
|
||||
27: 26(int) Constant 0
|
||||
28: TypePointer Uniform 22(S)
|
||||
32: TypePointer Private 9(S)
|
||||
33(s2): 32(ptr) Variable Private
|
||||
36(S): TypeStruct 8
|
||||
37: TypePointer Function 36(S)
|
||||
42: TypePointer Function 8
|
||||
57: TypePointer Uniform 8
|
||||
4(main): 2 Function None 3
|
||||
5: Label
|
||||
38(param): 37(ptr) Variable Function
|
||||
45(param): 14(ptr) Variable Function
|
||||
48(param): 37(ptr) Variable Function
|
||||
59(param): 14(ptr) Variable Function
|
||||
29: 28(ptr) AccessChain 25 27
|
||||
30: 22(S) Load 29
|
||||
31: 2 FunctionCall 12(fooConst(struct-S-mf441;) 30
|
||||
34: 9(S) Load 33(s2)
|
||||
35: 2 FunctionCall 12(fooConst(struct-S-mf441;) 34
|
||||
39: 28(ptr) AccessChain 25 27
|
||||
40: 22(S) Load 39
|
||||
41: 8 CompositeExtract 40 0
|
||||
43: 42(ptr) AccessChain 38(param) 27
|
||||
Store 43 41
|
||||
44: 2 FunctionCall 17(foo(struct-S-mf441;) 38(param)
|
||||
46: 9(S) Load 33(s2)
|
||||
Store 45(param) 46
|
||||
47: 2 FunctionCall 17(foo(struct-S-mf441;) 45(param)
|
||||
49: 28(ptr) AccessChain 25 27
|
||||
50: 22(S) Load 49
|
||||
51: 8 CompositeExtract 50 0
|
||||
52: 42(ptr) AccessChain 48(param) 27
|
||||
Store 52 51
|
||||
53: 2 FunctionCall 20(fooOut(struct-S-mf441;) 48(param)
|
||||
54: 36(S) Load 48(param)
|
||||
55: 28(ptr) AccessChain 25 27
|
||||
56: 8 CompositeExtract 54 0
|
||||
58: 57(ptr) AccessChain 55 27
|
||||
Store 58 56
|
||||
60: 9(S) Load 33(s2)
|
||||
Store 59(param) 60
|
||||
61: 2 FunctionCall 20(fooOut(struct-S-mf441;) 59(param)
|
||||
62: 9(S) Load 59(param)
|
||||
Store 33(s2) 62
|
||||
Return
|
||||
FunctionEnd
|
||||
12(fooConst(struct-S-mf441;): 2 Function None 10
|
||||
11(s): 9(S) FunctionParameter
|
||||
13: Label
|
||||
Return
|
||||
FunctionEnd
|
||||
17(foo(struct-S-mf441;): 2 Function None 15
|
||||
16(s): 14(ptr) FunctionParameter
|
||||
18: Label
|
||||
Return
|
||||
FunctionEnd
|
||||
20(fooOut(struct-S-mf441;): 2 Function None 15
|
||||
19(s): 14(ptr) FunctionParameter
|
||||
21: Label
|
||||
Return
|
||||
FunctionEnd
|
||||
48
Test/spv.multiStruct.comp
Normal file
48
Test/spv.multiStruct.comp
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
#version 450 core
|
||||
|
||||
struct MyStruct
|
||||
{
|
||||
vec4 foo;
|
||||
bool sb;
|
||||
};
|
||||
|
||||
layout(binding = 0, std430) buffer SSBO0
|
||||
{
|
||||
MyStruct a;
|
||||
} inBuf;
|
||||
|
||||
layout(binding = 1, std430) buffer SSBO1
|
||||
{
|
||||
MyStruct b;
|
||||
} outBuf;
|
||||
|
||||
layout(binding = 2, std140) uniform UBO
|
||||
{
|
||||
MyStruct c;
|
||||
} uBuf;
|
||||
|
||||
struct Nested {
|
||||
float f;
|
||||
MyStruct S;
|
||||
};
|
||||
|
||||
layout(binding = 2, std140) uniform UBON
|
||||
{
|
||||
Nested N1;
|
||||
} uBufN;
|
||||
|
||||
layout(binding = 1, std430) buffer SSBO1N
|
||||
{
|
||||
Nested N2;
|
||||
} outBufN;
|
||||
|
||||
void main()
|
||||
{
|
||||
MyStruct t = inBuf.a;
|
||||
outBuf.b = t;
|
||||
t = uBuf.c;
|
||||
outBuf.b = t;
|
||||
|
||||
Nested n = uBufN.N1;
|
||||
outBufN.N2 = n;
|
||||
}
|
||||
21
Test/spv.multiStructFuncall.frag
Executable file
21
Test/spv.multiStructFuncall.frag
Executable file
|
|
@ -0,0 +1,21 @@
|
|||
#version 450
|
||||
|
||||
struct S { mat4 m; };
|
||||
buffer blockName { S s1; }; // need an S with decoration
|
||||
S s2; // no decorations on S
|
||||
|
||||
void fooConst(const in S s) { }
|
||||
void foo(in S s) { }
|
||||
void fooOut(inout S s) { }
|
||||
|
||||
void main()
|
||||
{
|
||||
fooConst(s1);
|
||||
fooConst(s2);
|
||||
|
||||
foo(s1);
|
||||
foo(s2);
|
||||
|
||||
fooOut(s1);
|
||||
fooOut(s2);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue