Commit fbb6bdf0 by John Kessenich

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

parent 1f4d0468
......@@ -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);
......
......@@ -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'");
......
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
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
#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;
}
#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);
}
\ No newline at end of file
#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;
}
......@@ -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
);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment