Skip to content

Commit

Permalink
Do true SPV type check for function array arg linkage
Browse files Browse the repository at this point in the history
Previous check was missing type difference between uniform array
actual arg with stride decoration and the formal arg without. Now
does logical or component-wise copy where needed.

Fixes KhronosGroup#2637
  • Loading branch information
greg-lunarg committed May 20, 2021
1 parent e71278c commit 11c24e9
Show file tree
Hide file tree
Showing 8 changed files with 308 additions and 100 deletions.
2 changes: 1 addition & 1 deletion SPIRV/GlslangToSpv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5562,7 +5562,7 @@ spv::Id TGlslangToSpvTraverser::handleUserFunctionCall(const glslang::TIntermAgg
++lValueCount;
} else {
// process r-value, which involves a copy for a type mismatch
if (function->getParamType(a) != convertGlslangToSpvType(*argTypes[a]) ||
if (function->getParamType(a) != builder.getTypeId(rValues[rValueCount]) ||
TranslatePrecisionDecoration(*argTypes[a]) != function->getParamPrecision(a))
{
spv::Id argCopy = builder.createVariable(function->getParamPrecision(a), spv::StorageClassFunction, function->getParamType(a), "arg");
Expand Down
90 changes: 43 additions & 47 deletions Test/baseResults/spv.1.4.OpCopyLogical.funcall.frag.out
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
spv.1.4.OpCopyLogical.funcall.frag
// Module Version 10400
// Generated by (magic number): 8000a
// Id's are bound by 60
// Id's are bound by 59

Capability Shader
1: ExtInstImport "GLSL.std.450"
MemoryModel Logical GLSL450
EntryPoint Fragment 4 "main" 25 37
EntryPoint Fragment 4 "main" 25 36
ExecutionMode 4 OriginUpperLeft
Source GLSL 450
Name 4 "main"
Expand All @@ -23,22 +23,19 @@ spv.1.4.OpCopyLogical.funcall.frag
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"
Name 31 "arg"
Name 36 "s2"
Name 39 "param"
Name 44 "param"
Name 47 "param"
Name 55 "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
Expand All @@ -55,46 +52,45 @@ spv.1.4.OpCopyLogical.funcall.frag
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
35: TypePointer Private 9(S)
36(s2): 35(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
31(arg): 14(ptr) Variable Function
39(param): 14(ptr) Variable Function
44(param): 14(ptr) Variable Function
47(param): 14(ptr) Variable Function
55(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
32: 9(S) CopyLogical 30
Store 31(arg) 32
33: 9(S) Load 31(arg)
34: 2 FunctionCall 12(fooConst(struct-S-mf441;) 33
37: 9(S) Load 36(s2)
38: 2 FunctionCall 12(fooConst(struct-S-mf441;) 37
40: 28(ptr) AccessChain 25 27
41: 22(S) Load 40
42: 9(S) CopyLogical 41
Store 39(param) 42
43: 2 FunctionCall 17(foo(struct-S-mf441;) 39(param)
45: 9(S) Load 36(s2)
Store 44(param) 45
46: 2 FunctionCall 17(foo(struct-S-mf441;) 44(param)
48: 28(ptr) AccessChain 25 27
49: 22(S) Load 48
50: 9(S) CopyLogical 49
Store 47(param) 50
51: 2 FunctionCall 20(fooOut(struct-S-mf441;) 47(param)
52: 9(S) Load 47(param)
53: 28(ptr) AccessChain 25 27
54: 22(S) CopyLogical 52
Store 53 54
56: 9(S) Load 36(s2)
Store 55(param) 56
57: 2 FunctionCall 20(fooOut(struct-S-mf441;) 55(param)
58: 9(S) Load 55(param)
Store 36(s2) 58
Return
FunctionEnd
12(fooConst(struct-S-mf441;): 2 Function None 10
Expand Down
74 changes: 74 additions & 0 deletions Test/baseResults/spv.1.4.funcall.array.frag.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
spv.1.4.funcall.array.frag
// Module Version 10400
// Generated by (magic number): 8000a
// Id's are bound by 42

Capability Shader
1: ExtInstImport "GLSL.std.450"
MemoryModel Logical GLSL450
EntryPoint Fragment 4 "main" 27 31
ExecutionMode 4 OriginUpperLeft
Source GLSL 450
Name 4 "main"
Name 16 "f(vf4[9];i1;"
Name 14 "a"
Name 15 "ix"
Name 20 "indexable"
Name 27 "color"
Name 29 "ub"
MemberName 29(ub) 0 "u"
Name 31 ""
Name 37 "arg"
Name 40 "param"
Decorate 27(color) Location 0
Decorate 28 ArrayStride 16
MemberDecorate 29(ub) 0 Offset 0
Decorate 29(ub) Block
Decorate 31 DescriptorSet 0
Decorate 31 Binding 0
2: TypeVoid
3: TypeFunction 2
6: TypeFloat 32
7: TypeVector 6(float) 4
8: TypeInt 32 0
9: 8(int) Constant 9
10: TypeArray 7(fvec4) 9
11: TypeInt 32 1
12: TypePointer Function 11(int)
13: TypeFunction 7(fvec4) 10 12(ptr)
19: TypePointer Function 10
21: TypePointer Function 7(fvec4)
26: TypePointer Output 7(fvec4)
27(color): 26(ptr) Variable Output
28: TypeArray 7(fvec4) 9
29(ub): TypeStruct 28
30: TypePointer Uniform 29(ub)
31: 30(ptr) Variable Uniform
32: 11(int) Constant 0
33: TypePointer Uniform 28
36: 11(int) Constant 2
4(main): 2 Function None 3
5: Label
37(arg): 19(ptr) Variable Function
40(param): 12(ptr) Variable Function
34: 33(ptr) AccessChain 31 32
35: 28 Load 34
38: 10 CopyLogical 35
Store 37(arg) 38
39: 10 Load 37(arg)
Store 40(param) 36
41: 7(fvec4) FunctionCall 16(f(vf4[9];i1;) 39 40(param)
Store 27(color) 41
Return
FunctionEnd
16(f(vf4[9];i1;): 7(fvec4) Function None 13
14(a): 10 FunctionParameter
15(ix): 12(ptr) FunctionParameter
17: Label
20(indexable): 19(ptr) Variable Function
18: 11(int) Load 15(ix)
Store 20(indexable) 14(a)
22: 21(ptr) AccessChain 20(indexable) 18
23: 7(fvec4) Load 22
ReturnValue 23
FunctionEnd
106 changes: 106 additions & 0 deletions Test/baseResults/spv.funcall.array.frag.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
spv.funcall.array.frag
// Module Version 10000
// Generated by (magic number): 8000a
// Id's are bound by 66

Capability Shader
1: ExtInstImport "GLSL.std.450"
MemoryModel Logical GLSL450
EntryPoint Fragment 4 "main" 27
ExecutionMode 4 OriginUpperLeft
Source GLSL 450
Name 4 "main"
Name 16 "f(vf4[9];i1;"
Name 14 "a"
Name 15 "ix"
Name 20 "indexable"
Name 27 "color"
Name 29 "ub"
MemberName 29(ub) 0 "u"
Name 31 ""
Name 37 "arg"
Name 64 "param"
Decorate 27(color) Location 0
Decorate 28 ArrayStride 16
MemberDecorate 29(ub) 0 Offset 0
Decorate 29(ub) Block
Decorate 31 DescriptorSet 0
Decorate 31 Binding 0
2: TypeVoid
3: TypeFunction 2
6: TypeFloat 32
7: TypeVector 6(float) 4
8: TypeInt 32 0
9: 8(int) Constant 9
10: TypeArray 7(fvec4) 9
11: TypeInt 32 1
12: TypePointer Function 11(int)
13: TypeFunction 7(fvec4) 10 12(ptr)
19: TypePointer Function 10
21: TypePointer Function 7(fvec4)
26: TypePointer Output 7(fvec4)
27(color): 26(ptr) Variable Output
28: TypeArray 7(fvec4) 9
29(ub): TypeStruct 28
30: TypePointer Uniform 29(ub)
31: 30(ptr) Variable Uniform
32: 11(int) Constant 0
33: TypePointer Uniform 28
36: 11(int) Constant 2
41: 11(int) Constant 1
46: 11(int) Constant 3
49: 11(int) Constant 4
52: 11(int) Constant 5
55: 11(int) Constant 6
58: 11(int) Constant 7
61: 11(int) Constant 8
4(main): 2 Function None 3
5: Label
37(arg): 19(ptr) Variable Function
64(param): 12(ptr) Variable Function
34: 33(ptr) AccessChain 31 32
35: 28 Load 34
38: 7(fvec4) CompositeExtract 35 0
39: 21(ptr) AccessChain 37(arg) 32
Store 39 38
40: 7(fvec4) CompositeExtract 35 1
42: 21(ptr) AccessChain 37(arg) 41
Store 42 40
43: 7(fvec4) CompositeExtract 35 2
44: 21(ptr) AccessChain 37(arg) 36
Store 44 43
45: 7(fvec4) CompositeExtract 35 3
47: 21(ptr) AccessChain 37(arg) 46
Store 47 45
48: 7(fvec4) CompositeExtract 35 4
50: 21(ptr) AccessChain 37(arg) 49
Store 50 48
51: 7(fvec4) CompositeExtract 35 5
53: 21(ptr) AccessChain 37(arg) 52
Store 53 51
54: 7(fvec4) CompositeExtract 35 6
56: 21(ptr) AccessChain 37(arg) 55
Store 56 54
57: 7(fvec4) CompositeExtract 35 7
59: 21(ptr) AccessChain 37(arg) 58
Store 59 57
60: 7(fvec4) CompositeExtract 35 8
62: 21(ptr) AccessChain 37(arg) 61
Store 62 60
63: 10 Load 37(arg)
Store 64(param) 36
65: 7(fvec4) FunctionCall 16(f(vf4[9];i1;) 63 64(param)
Store 27(color) 65
Return
FunctionEnd
16(f(vf4[9];i1;): 7(fvec4) Function None 13
14(a): 10 FunctionParameter
15(ix): 12(ptr) FunctionParameter
17: Label
20(indexable): 19(ptr) Variable Function
18: 11(int) Load 15(ix)
Store 20(indexable) 14(a)
22: 21(ptr) AccessChain 20(indexable) 18
23: 7(fvec4) Load 22
ReturnValue 23
FunctionEnd
Loading

0 comments on commit 11c24e9

Please sign in to comment.