SPV 1.4: Add support for OpCopyLogical, careful of Boolean differences.

This commit is contained in:
John Kessenich 2019-01-15 21:48:27 +07:00
parent 1f4d04687b
commit fbb6bdf046
9 changed files with 636 additions and 0 deletions

View File

@ -3656,6 +3656,20 @@ void TGlslangToSpvTraverser::multiTypeStore(const glslang::TType& type, spv::Id
// where the two types were the same type in GLSL. This requires member
// by member copy, recursively.
// SPIR-V 1.4 added an instruction to do help do this.
if (glslangIntermediate->getSpv().spv >= glslang::EShTargetSpv_1_4) {
// However, bool in uniform space is changed to int, so
// OpCopyLogical does not work for that.
// TODO: It would be more robust to do a full recursive verification of the types satisfying SPIR-V rules.
bool rBool = builder.containsType(builder.getTypeId(rValue), spv::OpTypeBool, 0);
bool lBool = builder.containsType(lType, spv::OpTypeBool, 0);
if (lBool == rBool) {
spv::Id logicalCopy = builder.createUnaryOp(spv::OpCopyLogical, lType, rValue);
accessChainStore(type, logicalCopy);
return;
}
}
// If an array, copy element by element.
if (type.isArray()) {
glslang::TType glslangElementType(type, 0);

View File

@ -1031,6 +1031,7 @@ const char* OpcodeString(int op)
case 82: return "OpCompositeInsert";
case 83: return "OpCopyObject";
case 84: return "OpTranspose";
case OpCopyLogical: return "OpCopyLogical";
case 85: return "Bad";
case 86: return "OpSampledImage";
case 87: return "OpImageSampleImplicitLod";
@ -1938,6 +1939,8 @@ void Parameterize()
InstructionDesc[OpTranspose].operands.push(OperandId, "'Matrix'");
InstructionDesc[OpCopyLogical].operands.push(OperandId, "'Operand'");
InstructionDesc[OpIsNan].operands.push(OperandId, "'x'");
InstructionDesc[OpIsInf].operands.push(OperandId, "'x'");

View File

@ -0,0 +1,151 @@
spv.1.4.OpCopyLogical.comp
Validation failed
// Module Version 10400
// Generated by (magic number): 80007
// Id's are bound by 65
Capability Shader
1: ExtInstImport "GLSL.std.450"
MemoryModel Logical GLSL450
EntryPoint GLCompute 4 "main" 19 27 35 51 60
ExecutionMode 4 LocalSize 1 1 1
Source GLSL 450
Name 4 "main"
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 25 "SSBO1"
MemberName 25(SSBO1) 0 "b"
Name 27 "outBuf"
Name 32 "MyStruct"
MemberName 32(MyStruct) 0 "foo"
MemberName 32(MyStruct) 1 "sb"
Name 33 "UBO"
MemberName 33(UBO) 0 "c"
Name 35 "uBuf"
Name 44 "Nested"
MemberName 44(Nested) 0 "f"
MemberName 44(Nested) 1 "S"
Name 46 "n"
Name 48 "Nested"
MemberName 48(Nested) 0 "f"
MemberName 48(Nested) 1 "S"
Name 49 "UBON"
MemberName 49(UBON) 0 "N1"
Name 51 "uBufN"
Name 57 "Nested"
MemberName 57(Nested) 0 "f"
MemberName 57(Nested) 1 "S"
Name 58 "SSBO1N"
MemberName 58(SSBO1N) 0 "N2"
Name 60 "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) Block
Decorate 19(inBuf) DescriptorSet 0
Decorate 19(inBuf) Binding 0
MemberDecorate 25(SSBO1) 0 Offset 0
Decorate 25(SSBO1) Block
Decorate 27(outBuf) DescriptorSet 0
Decorate 27(outBuf) Binding 1
Decorate 31 ArrayStride 16
MemberDecorate 32(MyStruct) 0 Offset 0
MemberDecorate 32(MyStruct) 1 Offset 32
MemberDecorate 33(UBO) 0 Offset 0
Decorate 33(UBO) Block
Decorate 35(uBuf) DescriptorSet 0
Decorate 35(uBuf) Binding 2
Decorate 47 ArrayStride 48
MemberDecorate 48(Nested) 0 Offset 0
MemberDecorate 48(Nested) 1 Offset 16
MemberDecorate 49(UBON) 0 Offset 0
Decorate 49(UBON) Block
Decorate 51(uBufN) DescriptorSet 0
Decorate 51(uBufN) Binding 2
Decorate 56 ArrayStride 24
MemberDecorate 57(Nested) 0 Offset 0
MemberDecorate 57(Nested) 1 Offset 8
MemberDecorate 58(SSBO1N) 0 Offset 0
Decorate 58(SSBO1N) Block
Decorate 60(outBufN) DescriptorSet 0
Decorate 60(outBufN) Binding 1
2: TypeVoid
3: TypeFunction 2
6: TypeFloat 32
7: TypeVector 6(float) 2
8: TypeInt 32 0
9: 8(int) Constant 2
10: TypeArray 7(fvec2) 9
11: TypeInt 32 1
12(MyStruct): TypeStruct 10 11(int)
13: TypePointer Function 12(MyStruct)
15: TypeArray 7(fvec2) 9
16(MyStruct): TypeStruct 15 11(int)
17(SSBO0): TypeStruct 16(MyStruct)
18: TypePointer StorageBuffer 17(SSBO0)
19(inBuf): 18(ptr) Variable StorageBuffer
20: 11(int) Constant 0
21: TypePointer StorageBuffer 16(MyStruct)
25(SSBO1): TypeStruct 16(MyStruct)
26: TypePointer StorageBuffer 25(SSBO1)
27(outBuf): 26(ptr) Variable StorageBuffer
31: TypeArray 7(fvec2) 9
32(MyStruct): TypeStruct 31 11(int)
33(UBO): TypeStruct 32(MyStruct)
34: TypePointer Uniform 33(UBO)
35(uBuf): 34(ptr) Variable Uniform
36: TypePointer Uniform 32(MyStruct)
43: TypeArray 12(MyStruct) 9
44(Nested): TypeStruct 6(float) 43
45: TypePointer Function 44(Nested)
47: TypeArray 32(MyStruct) 9
48(Nested): TypeStruct 6(float) 47
49(UBON): TypeStruct 48(Nested)
50: TypePointer Uniform 49(UBON)
51(uBufN): 50(ptr) Variable Uniform
52: TypePointer Uniform 48(Nested)
56: TypeArray 16(MyStruct) 9
57(Nested): TypeStruct 6(float) 56
58(SSBO1N): TypeStruct 57(Nested)
59: TypePointer StorageBuffer 58(SSBO1N)
60(outBufN): 59(ptr) Variable StorageBuffer
62: TypePointer StorageBuffer 57(Nested)
4(main): 2 Function None 3
5: Label
14(t): 13(ptr) Variable Function
46(n): 45(ptr) Variable Function
22: 21(ptr) AccessChain 19(inBuf) 20
23:16(MyStruct) Load 22
24:12(MyStruct) CopyLogical 23
Store 14(t) 24
28:12(MyStruct) Load 14(t)
29: 21(ptr) AccessChain 27(outBuf) 20
30:16(MyStruct) CopyLogical 28
Store 29 30
37: 36(ptr) AccessChain 35(uBuf) 20
38:32(MyStruct) Load 37
39:12(MyStruct) CopyLogical 38
Store 14(t) 39
40:12(MyStruct) Load 14(t)
41: 21(ptr) AccessChain 27(outBuf) 20
42:16(MyStruct) CopyLogical 40
Store 41 42
53: 52(ptr) AccessChain 51(uBufN) 20
54: 48(Nested) Load 53
55: 44(Nested) CopyLogical 54
Store 46(n) 55
61: 44(Nested) Load 46(n)
63: 62(ptr) AccessChain 60(outBufN) 20
64: 57(Nested) CopyLogical 61
Store 63 64
Return
FunctionEnd

View File

@ -0,0 +1,115 @@
spv.1.4.OpCopyLogical.funcall.frag
Validation failed
// Module Version 10400
// Generated by (magic number): 80007
// Id's are bound by 60
Capability Shader
1: ExtInstImport "GLSL.std.450"
MemoryModel Logical GLSL450
EntryPoint Fragment 4 "main" 25 37
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 31 "S"
MemberName 31(S) 0 "m"
Name 32 "arg"
Name 37 "s2"
Name 40 "param"
Name 45 "param"
Name 48 "param"
Name 56 "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) Block
Decorate 25 DescriptorSet 0
Decorate 25 Binding 0
MemberDecorate 31(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 StorageBuffer 23(blockName)
25: 24(ptr) Variable StorageBuffer
26: TypeInt 32 1
27: 26(int) Constant 0
28: TypePointer StorageBuffer 22(S)
31(S): TypeStruct 8
36: TypePointer Private 9(S)
37(s2): 36(ptr) Variable Private
4(main): 2 Function None 3
5: Label
32(arg): 14(ptr) Variable Function
40(param): 14(ptr) Variable Function
45(param): 14(ptr) Variable Function
48(param): 14(ptr) Variable Function
56(param): 14(ptr) Variable Function
29: 28(ptr) AccessChain 25 27
30: 22(S) Load 29
33: 9(S) CopyLogical 30
Store 32(arg) 33
34: 9(S) Load 32(arg)
35: 2 FunctionCall 12(fooConst(struct-S-mf441;) 34
38: 9(S) Load 37(s2)
39: 2 FunctionCall 12(fooConst(struct-S-mf441;) 38
41: 28(ptr) AccessChain 25 27
42: 22(S) Load 41
43: 9(S) CopyLogical 42
Store 40(param) 43
44: 2 FunctionCall 17(foo(struct-S-mf441;) 40(param)
46: 9(S) Load 37(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: 9(S) CopyLogical 50
Store 48(param) 51
52: 2 FunctionCall 20(fooOut(struct-S-mf441;) 48(param)
53: 9(S) Load 48(param)
54: 28(ptr) AccessChain 25 27
55: 22(S) CopyLogical 53
Store 54 55
57: 9(S) Load 37(s2)
Store 56(param) 57
58: 2 FunctionCall 20(fooOut(struct-S-mf441;) 56(param)
59: 9(S) Load 56(param)
Store 37(s2) 59
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

View File

@ -0,0 +1,233 @@
spv.1.4.OpCopyLogicalBool.comp
Validation failed
// Module Version 10400
// Generated by (magic number): 80007
// Id's are bound by 135
Capability Shader
1: ExtInstImport "GLSL.std.450"
MemoryModel Logical GLSL450
EntryPoint GLCompute 4 "main" 19 37 53 79 109
ExecutionMode 4 LocalSize 1 1 1
Source GLSL 450
Name 4 "main"
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 35 "SSBO1"
MemberName 35(SSBO1) 0 "b"
Name 37 "outBuf"
Name 50 "MyStruct"
MemberName 50(MyStruct) 0 "foo"
MemberName 50(MyStruct) 1 "sb"
Name 51 "UBO"
MemberName 51(UBO) 0 "c"
Name 53 "uBuf"
Name 72 "Nested"
MemberName 72(Nested) 0 "b"
MemberName 72(Nested) 1 "S"
Name 74 "n"
Name 76 "Nested"
MemberName 76(Nested) 0 "b"
MemberName 76(Nested) 1 "S"
Name 77 "UBON"
MemberName 77(UBON) 0 "N1"
Name 79 "uBufN"
Name 106 "Nested"
MemberName 106(Nested) 0 "b"
MemberName 106(Nested) 1 "S"
Name 107 "SSBO1N"
MemberName 107(SSBO1N) 0 "N2"
Name 109 "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) Block
Decorate 19(inBuf) DescriptorSet 0
Decorate 19(inBuf) Binding 0
MemberDecorate 35(SSBO1) 0 Offset 0
Decorate 35(SSBO1) Block
Decorate 37(outBuf) DescriptorSet 0
Decorate 37(outBuf) Binding 1
Decorate 49 ArrayStride 16
MemberDecorate 50(MyStruct) 0 Offset 0
MemberDecorate 50(MyStruct) 1 Offset 32
MemberDecorate 51(UBO) 0 Offset 0
Decorate 51(UBO) Block
Decorate 53(uBuf) DescriptorSet 0
Decorate 53(uBuf) Binding 2
Decorate 75 ArrayStride 48
MemberDecorate 76(Nested) 0 Offset 0
MemberDecorate 76(Nested) 1 Offset 16
MemberDecorate 77(UBON) 0 Offset 0
Decorate 77(UBON) Block
Decorate 79(uBufN) DescriptorSet 0
Decorate 79(uBufN) Binding 2
Decorate 105 ArrayStride 24
MemberDecorate 106(Nested) 0 Offset 0
MemberDecorate 106(Nested) 1 Offset 8
MemberDecorate 107(SSBO1N) 0 Offset 0
Decorate 107(SSBO1N) Block
Decorate 109(outBufN) DescriptorSet 0
Decorate 109(outBufN) Binding 1
2: TypeVoid
3: TypeFunction 2
6: TypeFloat 32
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 StorageBuffer 17(SSBO0)
19(inBuf): 18(ptr) Variable StorageBuffer
20: TypeInt 32 1
21: 20(int) Constant 0
22: TypePointer StorageBuffer 16(MyStruct)
26: TypePointer Function 10
30: 20(int) Constant 1
31: 8(int) Constant 0
33: TypePointer Function 11(bool)
35(SSBO1): TypeStruct 16(MyStruct)
36: TypePointer StorageBuffer 35(SSBO1)
37(outBuf): 36(ptr) Variable StorageBuffer
41: TypePointer StorageBuffer 15
45: 8(int) Constant 1
47: TypePointer StorageBuffer 8(int)
49: TypeArray 7(fvec2) 9
50(MyStruct): TypeStruct 49 8(int)
51(UBO): TypeStruct 50(MyStruct)
52: TypePointer Uniform 51(UBO)
53(uBuf): 52(ptr) Variable Uniform
54: TypePointer Uniform 50(MyStruct)
71: TypeArray 12(MyStruct) 9
72(Nested): TypeStruct 11(bool) 71
73: TypePointer Function 72(Nested)
75: TypeArray 50(MyStruct) 9
76(Nested): TypeStruct 8(int) 75
77(UBON): TypeStruct 76(Nested)
78: TypePointer Uniform 77(UBON)
79(uBufN): 78(ptr) Variable Uniform
80: TypePointer Uniform 76(Nested)
87: TypePointer Function 71
105: TypeArray 16(MyStruct) 9
106(Nested): TypeStruct 8(int) 105
107(SSBO1N): TypeStruct 106(Nested)
108: TypePointer StorageBuffer 107(SSBO1N)
109(outBufN): 108(ptr) Variable StorageBuffer
111: TypePointer StorageBuffer 106(Nested)
117: TypePointer StorageBuffer 105
4(main): 2 Function None 3
5: Label
14(t): 13(ptr) Variable Function
74(n): 73(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: 10 CopyLogical 25
Store 27 28
29: 8(int) CompositeExtract 24 1
32: 11(bool) INotEqual 29 31
34: 33(ptr) AccessChain 14(t) 30
Store 34 32
38:12(MyStruct) Load 14(t)
39: 22(ptr) AccessChain 37(outBuf) 21
40: 10 CompositeExtract 38 0
42: 41(ptr) AccessChain 39 21
43: 15 CopyLogical 40
Store 42 43
44: 11(bool) CompositeExtract 38 1
46: 8(int) Select 44 45 31
48: 47(ptr) AccessChain 39 30
Store 48 46
55: 54(ptr) AccessChain 53(uBuf) 21
56:50(MyStruct) Load 55
57: 49 CompositeExtract 56 0
58: 26(ptr) AccessChain 14(t) 21
59: 10 CopyLogical 57
Store 58 59
60: 8(int) CompositeExtract 56 1
61: 11(bool) INotEqual 60 31
62: 33(ptr) AccessChain 14(t) 30
Store 62 61
63:12(MyStruct) Load 14(t)
64: 22(ptr) AccessChain 37(outBuf) 21
65: 10 CompositeExtract 63 0
66: 41(ptr) AccessChain 64 21
67: 15 CopyLogical 65
Store 66 67
68: 11(bool) CompositeExtract 63 1
69: 8(int) Select 68 45 31
70: 47(ptr) AccessChain 64 30
Store 70 69
81: 80(ptr) AccessChain 79(uBufN) 21
82: 76(Nested) Load 81
83: 8(int) CompositeExtract 82 0
84: 11(bool) INotEqual 83 31
85: 33(ptr) AccessChain 74(n) 21
Store 85 84
86: 75 CompositeExtract 82 1
88: 87(ptr) AccessChain 74(n) 30
89:50(MyStruct) CompositeExtract 86 0
90: 13(ptr) AccessChain 88 21
91: 49 CompositeExtract 89 0
92: 26(ptr) AccessChain 90 21
93: 10 CopyLogical 91
Store 92 93
94: 8(int) CompositeExtract 89 1
95: 11(bool) INotEqual 94 31
96: 33(ptr) AccessChain 90 30
Store 96 95
97:50(MyStruct) CompositeExtract 86 1
98: 13(ptr) AccessChain 88 30
99: 49 CompositeExtract 97 0
100: 26(ptr) AccessChain 98 21
101: 10 CopyLogical 99
Store 100 101
102: 8(int) CompositeExtract 97 1
103: 11(bool) INotEqual 102 31
104: 33(ptr) AccessChain 98 30
Store 104 103
110: 72(Nested) Load 74(n)
112: 111(ptr) AccessChain 109(outBufN) 21
113: 11(bool) CompositeExtract 110 0
114: 8(int) Select 113 45 31
115: 47(ptr) AccessChain 112 21
Store 115 114
116: 71 CompositeExtract 110 1
118: 117(ptr) AccessChain 112 30
119:12(MyStruct) CompositeExtract 116 0
120: 22(ptr) AccessChain 118 21
121: 10 CompositeExtract 119 0
122: 41(ptr) AccessChain 120 21
123: 15 CopyLogical 121
Store 122 123
124: 11(bool) CompositeExtract 119 1
125: 8(int) Select 124 45 31
126: 47(ptr) AccessChain 120 30
Store 126 125
127:12(MyStruct) CompositeExtract 116 1
128: 22(ptr) AccessChain 118 30
129: 10 CompositeExtract 127 0
130: 41(ptr) AccessChain 128 21
131: 15 CopyLogical 129
Store 130 131
132: 11(bool) CompositeExtract 127 1
133: 8(int) Select 132 45 31
134: 47(ptr) AccessChain 128 30
Store 134 133
Return
FunctionEnd

View File

@ -0,0 +1,48 @@
#version 450 core
struct MyStruct
{
vec2 foo[2];
int 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[2];
};
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;
}

View 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);
}

View File

@ -0,0 +1,48 @@
#version 450 core
struct MyStruct
{
vec2 foo[2];
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 {
bool b;
MyStruct S[2];
};
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;
}

View File

@ -468,6 +468,9 @@ INSTANTIATE_TEST_CASE_P(
"spv.1.4.OpEntryPoint.frag",
"spv.1.4.OpSelect.frag",
"spv.1.4.LoopControl.frag",
"spv.1.4.OpCopyLogical.comp",
"spv.1.4.OpCopyLogicalBool.comp",
"spv.1.4.OpCopyLogical.funcall.frag",
})),
FileNameAsCustomTestSuffix
);