Add tests for conditionals that return a struct value

There are 3 separate tests added to cover the 3 cases in
visitSelection(). With SPIR-V versions prior to 1.4, control flow is
generated, with GLSL generating code to execute only the appropriate
branch of the conditional while HLSL executes both branches and uses the
control flow to select the appropriate one. Finally, with SPIR-V
versions newer than 1.4, OpSelect can be used on structs.

Note that the hlsl.structcopy.comp and hlsl.structcopylogical.comp tests
have identical shader code, but are compiled with different versions of
SPIR-V and result in different codepaths being used and different SPIR-V
generated.
This commit is contained in:
Arcady Goldmints-Orlov 2023-03-31 14:29:50 -06:00 committed by arcady-lunarg
parent cdb350b356
commit adcc7e8163
8 changed files with 1026 additions and 1 deletions

View File

@ -0,0 +1,402 @@
hlsl.structcopy.comp
Shader version: 500
local_size = (128, 1, 1)
0:? Sequence
0:20 Function Definition: @main(u1; ( temp void)
0:20 Function Parameters:
0:20 'id' ( in uint)
0:? Sequence
0:21 move second child to first child ( temp structure{ temp uint a, temp uint b, temp uint c})
0:21 direct index ( temp structure{ temp uint a, temp uint b, temp uint c})
0:21 's' ( shared 128-element array of structure{ temp uint a, temp uint b, temp uint c})
0:21 Constant:
0:21 0 (const int)
0:21 Constant:
0:21 1 (const uint)
0:21 2 (const uint)
0:21 3 (const uint)
0:22 Sequence
0:22 move second child to first child ( temp uint)
0:22 'count' ( temp uint)
0:22 count: direct index for structure ( temp uint)
0:22 direct index (layout( row_major std430) buffer structure{ temp uint count, temp unsized 1-element array of structure{ temp uint a, temp uint b, temp uint c} data})
0:22 @data: direct index for structure (layout( row_major std430) buffer unsized 1-element array of structure{ temp uint count, temp unsized 1-element array of structure{ temp uint a, temp uint b, temp uint c} data})
0:22 'sb' (layout( row_major std430) readonly buffer block{layout( row_major std430) buffer unsized 1-element array of structure{ temp uint count, temp unsized 1-element array of structure{ temp uint a, temp uint b, temp uint c} data} @data})
0:22 Constant:
0:22 0 (const uint)
0:22 Constant:
0:22 0 (const int)
0:22 Constant:
0:22 0 (const int)
0:23 Sequence
0:23 move second child to first child ( temp structure{ temp uint a, temp uint b, temp uint c})
0:23 'ms' ( temp structure{ temp uint a, temp uint b, temp uint c})
0:23 Test condition and select ( temp structure{ temp uint a, temp uint b, temp uint c}): no shortcircuit
0:23 Condition
0:23 Compare Greater Than ( temp bool)
0:23 'id' ( in uint)
0:23 'count' ( temp uint)
0:23 true case
0:23 indirect index ( temp structure{ temp uint a, temp uint b, temp uint c})
0:23 's' ( shared 128-element array of structure{ temp uint a, temp uint b, temp uint c})
0:23 subtract ( temp uint)
0:23 'id' ( in uint)
0:23 'count' ( temp uint)
0:23 false case
0:23 indirect index ( temp structure{ temp uint a, temp uint b, temp uint c})
0:23 data: direct index for structure ( temp unsized 1-element array of structure{ temp uint a, temp uint b, temp uint c})
0:23 direct index (layout( row_major std430) buffer structure{ temp uint count, temp unsized 1-element array of structure{ temp uint a, temp uint b, temp uint c} data})
0:23 @data: direct index for structure (layout( row_major std430) buffer unsized 1-element array of structure{ temp uint count, temp unsized 1-element array of structure{ temp uint a, temp uint b, temp uint c} data})
0:23 'sb' (layout( row_major std430) readonly buffer block{layout( row_major std430) buffer unsized 1-element array of structure{ temp uint count, temp unsized 1-element array of structure{ temp uint a, temp uint b, temp uint c} data} @data})
0:23 Constant:
0:23 0 (const uint)
0:23 Constant:
0:23 0 (const int)
0:23 Constant:
0:23 1 (const int)
0:23 'id' ( in uint)
0:25 AtomicAdd ( temp uint)
0:25 a: direct index for structure ( temp uint)
0:25 direct index (layout( row_major std430) buffer structure{ temp uint a, temp uint b, temp uint c})
0:25 @data: direct index for structure (layout( row_major std430) buffer unsized 1-element array of structure{ temp uint a, temp uint b, temp uint c})
0:25 'o' (layout( row_major std430) readonly buffer block{layout( row_major std430) buffer unsized 1-element array of structure{ temp uint a, temp uint b, temp uint c} @data})
0:25 Constant:
0:25 0 (const uint)
0:25 Constant:
0:25 0 (const int)
0:25 Constant:
0:25 0 (const int)
0:25 a: direct index for structure ( temp uint)
0:25 'ms' ( temp structure{ temp uint a, temp uint b, temp uint c})
0:25 Constant:
0:25 0 (const int)
0:26 AtomicAdd ( temp uint)
0:26 b: direct index for structure ( temp uint)
0:26 direct index (layout( row_major std430) buffer structure{ temp uint a, temp uint b, temp uint c})
0:26 @data: direct index for structure (layout( row_major std430) buffer unsized 1-element array of structure{ temp uint a, temp uint b, temp uint c})
0:26 'o' (layout( row_major std430) readonly buffer block{layout( row_major std430) buffer unsized 1-element array of structure{ temp uint a, temp uint b, temp uint c} @data})
0:26 Constant:
0:26 0 (const uint)
0:26 Constant:
0:26 0 (const int)
0:26 Constant:
0:26 1 (const int)
0:26 b: direct index for structure ( temp uint)
0:26 'ms' ( temp structure{ temp uint a, temp uint b, temp uint c})
0:26 Constant:
0:26 1 (const int)
0:27 AtomicAdd ( temp uint)
0:27 c: direct index for structure ( temp uint)
0:27 direct index (layout( row_major std430) buffer structure{ temp uint a, temp uint b, temp uint c})
0:27 @data: direct index for structure (layout( row_major std430) buffer unsized 1-element array of structure{ temp uint a, temp uint b, temp uint c})
0:27 'o' (layout( row_major std430) readonly buffer block{layout( row_major std430) buffer unsized 1-element array of structure{ temp uint a, temp uint b, temp uint c} @data})
0:27 Constant:
0:27 0 (const uint)
0:27 Constant:
0:27 0 (const int)
0:27 Constant:
0:27 2 (const int)
0:27 c: direct index for structure ( temp uint)
0:27 'ms' ( temp structure{ temp uint a, temp uint b, temp uint c})
0:27 Constant:
0:27 2 (const int)
0:20 Function Definition: main( ( temp void)
0:20 Function Parameters:
0:? Sequence
0:20 move second child to first child ( temp uint)
0:? 'id' ( temp uint)
0:? 'id' ( in uint LocalInvocationIndex)
0:20 Function Call: @main(u1; ( temp void)
0:? 'id' ( temp uint)
0:? Linker Objects
0:? 'sb' (layout( row_major std430) readonly buffer block{layout( row_major std430) buffer unsized 1-element array of structure{ temp uint count, temp unsized 1-element array of structure{ temp uint a, temp uint b, temp uint c} data} @data})
0:? 'o' (layout( row_major std430) readonly buffer block{layout( row_major std430) buffer unsized 1-element array of structure{ temp uint a, temp uint b, temp uint c} @data})
0:? 's' ( shared 128-element array of structure{ temp uint a, temp uint b, temp uint c})
0:? 'deflt' ( const structure{ temp uint a, temp uint b, temp uint c})
0:? 1 (const uint)
0:? 2 (const uint)
0:? 3 (const uint)
0:? 'id' ( in uint LocalInvocationIndex)
Linked compute stage:
Shader version: 500
local_size = (128, 1, 1)
0:? Sequence
0:20 Function Definition: @main(u1; ( temp void)
0:20 Function Parameters:
0:20 'id' ( in uint)
0:? Sequence
0:21 move second child to first child ( temp structure{ temp uint a, temp uint b, temp uint c})
0:21 direct index ( temp structure{ temp uint a, temp uint b, temp uint c})
0:21 's' ( shared 128-element array of structure{ temp uint a, temp uint b, temp uint c})
0:21 Constant:
0:21 0 (const int)
0:21 Constant:
0:21 1 (const uint)
0:21 2 (const uint)
0:21 3 (const uint)
0:22 Sequence
0:22 move second child to first child ( temp uint)
0:22 'count' ( temp uint)
0:22 count: direct index for structure ( temp uint)
0:22 direct index (layout( row_major std430) buffer structure{ temp uint count, temp unsized 1-element array of structure{ temp uint a, temp uint b, temp uint c} data})
0:22 @data: direct index for structure (layout( row_major std430) buffer unsized 1-element array of structure{ temp uint count, temp unsized 1-element array of structure{ temp uint a, temp uint b, temp uint c} data})
0:22 'sb' (layout( row_major std430) readonly buffer block{layout( row_major std430) buffer unsized 1-element array of structure{ temp uint count, temp unsized 1-element array of structure{ temp uint a, temp uint b, temp uint c} data} @data})
0:22 Constant:
0:22 0 (const uint)
0:22 Constant:
0:22 0 (const int)
0:22 Constant:
0:22 0 (const int)
0:23 Sequence
0:23 move second child to first child ( temp structure{ temp uint a, temp uint b, temp uint c})
0:23 'ms' ( temp structure{ temp uint a, temp uint b, temp uint c})
0:23 Test condition and select ( temp structure{ temp uint a, temp uint b, temp uint c}): no shortcircuit
0:23 Condition
0:23 Compare Greater Than ( temp bool)
0:23 'id' ( in uint)
0:23 'count' ( temp uint)
0:23 true case
0:23 indirect index ( temp structure{ temp uint a, temp uint b, temp uint c})
0:23 's' ( shared 128-element array of structure{ temp uint a, temp uint b, temp uint c})
0:23 subtract ( temp uint)
0:23 'id' ( in uint)
0:23 'count' ( temp uint)
0:23 false case
0:23 indirect index ( temp structure{ temp uint a, temp uint b, temp uint c})
0:23 data: direct index for structure ( temp unsized 1-element array of structure{ temp uint a, temp uint b, temp uint c})
0:23 direct index (layout( row_major std430) buffer structure{ temp uint count, temp unsized 1-element array of structure{ temp uint a, temp uint b, temp uint c} data})
0:23 @data: direct index for structure (layout( row_major std430) buffer unsized 1-element array of structure{ temp uint count, temp unsized 1-element array of structure{ temp uint a, temp uint b, temp uint c} data})
0:23 'sb' (layout( row_major std430) readonly buffer block{layout( row_major std430) buffer unsized 1-element array of structure{ temp uint count, temp unsized 1-element array of structure{ temp uint a, temp uint b, temp uint c} data} @data})
0:23 Constant:
0:23 0 (const uint)
0:23 Constant:
0:23 0 (const int)
0:23 Constant:
0:23 1 (const int)
0:23 'id' ( in uint)
0:25 AtomicAdd ( temp uint)
0:25 a: direct index for structure ( temp uint)
0:25 direct index (layout( row_major std430) buffer structure{ temp uint a, temp uint b, temp uint c})
0:25 @data: direct index for structure (layout( row_major std430) buffer unsized 1-element array of structure{ temp uint a, temp uint b, temp uint c})
0:25 'o' (layout( row_major std430) readonly buffer block{layout( row_major std430) buffer unsized 1-element array of structure{ temp uint a, temp uint b, temp uint c} @data})
0:25 Constant:
0:25 0 (const uint)
0:25 Constant:
0:25 0 (const int)
0:25 Constant:
0:25 0 (const int)
0:25 a: direct index for structure ( temp uint)
0:25 'ms' ( temp structure{ temp uint a, temp uint b, temp uint c})
0:25 Constant:
0:25 0 (const int)
0:26 AtomicAdd ( temp uint)
0:26 b: direct index for structure ( temp uint)
0:26 direct index (layout( row_major std430) buffer structure{ temp uint a, temp uint b, temp uint c})
0:26 @data: direct index for structure (layout( row_major std430) buffer unsized 1-element array of structure{ temp uint a, temp uint b, temp uint c})
0:26 'o' (layout( row_major std430) readonly buffer block{layout( row_major std430) buffer unsized 1-element array of structure{ temp uint a, temp uint b, temp uint c} @data})
0:26 Constant:
0:26 0 (const uint)
0:26 Constant:
0:26 0 (const int)
0:26 Constant:
0:26 1 (const int)
0:26 b: direct index for structure ( temp uint)
0:26 'ms' ( temp structure{ temp uint a, temp uint b, temp uint c})
0:26 Constant:
0:26 1 (const int)
0:27 AtomicAdd ( temp uint)
0:27 c: direct index for structure ( temp uint)
0:27 direct index (layout( row_major std430) buffer structure{ temp uint a, temp uint b, temp uint c})
0:27 @data: direct index for structure (layout( row_major std430) buffer unsized 1-element array of structure{ temp uint a, temp uint b, temp uint c})
0:27 'o' (layout( row_major std430) readonly buffer block{layout( row_major std430) buffer unsized 1-element array of structure{ temp uint a, temp uint b, temp uint c} @data})
0:27 Constant:
0:27 0 (const uint)
0:27 Constant:
0:27 0 (const int)
0:27 Constant:
0:27 2 (const int)
0:27 c: direct index for structure ( temp uint)
0:27 'ms' ( temp structure{ temp uint a, temp uint b, temp uint c})
0:27 Constant:
0:27 2 (const int)
0:20 Function Definition: main( ( temp void)
0:20 Function Parameters:
0:? Sequence
0:20 move second child to first child ( temp uint)
0:? 'id' ( temp uint)
0:? 'id' ( in uint LocalInvocationIndex)
0:20 Function Call: @main(u1; ( temp void)
0:? 'id' ( temp uint)
0:? Linker Objects
0:? 'sb' (layout( row_major std430) readonly buffer block{layout( row_major std430) buffer unsized 1-element array of structure{ temp uint count, temp unsized 1-element array of structure{ temp uint a, temp uint b, temp uint c} data} @data})
0:? 'o' (layout( row_major std430) readonly buffer block{layout( row_major std430) buffer unsized 1-element array of structure{ temp uint a, temp uint b, temp uint c} @data})
0:? 's' ( shared 128-element array of structure{ temp uint a, temp uint b, temp uint c})
0:? 'deflt' ( const structure{ temp uint a, temp uint b, temp uint c})
0:? 1 (const uint)
0:? 2 (const uint)
0:? 3 (const uint)
0:? 'id' ( in uint LocalInvocationIndex)
// Module Version 10000
// Generated by (magic number): 8000b
// Id's are bound by 88
Capability Shader
1: ExtInstImport "GLSL.std.450"
MemoryModel Logical GLSL450
EntryPoint GLCompute 4 "main" 83
ExecutionMode 4 LocalSize 128 1 1
Source HLSL 500
Name 4 "main"
Name 10 "@main(u1;"
Name 9 "id"
Name 12 "MyStruct"
MemberName 12(MyStruct) 0 "a"
MemberName 12(MyStruct) 1 "b"
MemberName 12(MyStruct) 2 "c"
Name 16 "s"
Name 25 "count"
Name 26 "MyStruct"
MemberName 26(MyStruct) 0 "a"
MemberName 26(MyStruct) 1 "b"
MemberName 26(MyStruct) 2 "c"
Name 28 "MyStructs"
MemberName 28(MyStructs) 0 "count"
MemberName 28(MyStructs) 1 "data"
Name 30 "sb"
MemberName 30(sb) 0 "@data"
Name 32 "sb"
Name 37 "ms"
Name 65 "o"
MemberName 65(o) 0 "@data"
Name 67 "o"
Name 81 "id"
Name 83 "id"
Name 85 "param"
MemberDecorate 26(MyStruct) 0 Offset 0
MemberDecorate 26(MyStruct) 1 Offset 4
MemberDecorate 26(MyStruct) 2 Offset 8
Decorate 27 ArrayStride 12
MemberDecorate 28(MyStructs) 0 Offset 0
MemberDecorate 28(MyStructs) 1 Offset 4
Decorate 28(MyStructs) BufferBlock
Decorate 29 ArrayStride 16
MemberDecorate 30(sb) 0 NonWritable
MemberDecorate 30(sb) 0 Offset 0
Decorate 30(sb) BufferBlock
Decorate 32(sb) DescriptorSet 0
Decorate 32(sb) Binding 0
Decorate 64 ArrayStride 12
MemberDecorate 65(o) 0 NonWritable
MemberDecorate 65(o) 0 Offset 0
Decorate 65(o) BufferBlock
Decorate 67(o) DescriptorSet 0
Decorate 67(o) Binding 1
Decorate 83(id) BuiltIn LocalInvocationIndex
2: TypeVoid
3: TypeFunction 2
6: TypeInt 32 0
7: TypePointer Function 6(int)
8: TypeFunction 2 7(ptr)
12(MyStruct): TypeStruct 6(int) 6(int) 6(int)
13: 6(int) Constant 128
14: TypeArray 12(MyStruct) 13
15: TypePointer Workgroup 14
16(s): 15(ptr) Variable Workgroup
17: TypeInt 32 1
18: 17(int) Constant 0
19: 6(int) Constant 1
20: 6(int) Constant 2
21: 6(int) Constant 3
22:12(MyStruct) ConstantComposite 19 20 21
23: TypePointer Workgroup 12(MyStruct)
26(MyStruct): TypeStruct 6(int) 6(int) 6(int)
27: TypeRuntimeArray 26(MyStruct)
28(MyStructs): TypeStruct 6(int) 27
29: TypeRuntimeArray 28(MyStructs)
30(sb): TypeStruct 29
31: TypePointer Uniform 30(sb)
32(sb): 31(ptr) Variable Uniform
33: TypePointer Uniform 6(int)
36: TypePointer Function 12(MyStruct)
40: TypeBool
47: 17(int) Constant 1
49: TypePointer Uniform 26(MyStruct)
61: 17(int) Constant 2
64: TypeRuntimeArray 26(MyStruct)
65(o): TypeStruct 64
66: TypePointer Uniform 65(o)
67(o): 66(ptr) Variable Uniform
71: 6(int) Constant 0
82: TypePointer Input 6(int)
83(id): 82(ptr) Variable Input
4(main): 2 Function None 3
5: Label
81(id): 7(ptr) Variable Function
85(param): 7(ptr) Variable Function
84: 6(int) Load 83(id)
Store 81(id) 84
86: 6(int) Load 81(id)
Store 85(param) 86
87: 2 FunctionCall 10(@main(u1;) 85(param)
Return
FunctionEnd
10(@main(u1;): 2 Function None 8
9(id): 7(ptr) FunctionParameter
11: Label
25(count): 7(ptr) Variable Function
37(ms): 36(ptr) Variable Function
52: 36(ptr) Variable Function
24: 23(ptr) AccessChain 16(s) 18
Store 24 22
34: 33(ptr) AccessChain 32(sb) 18 18 18
35: 6(int) Load 34
Store 25(count) 35
38: 6(int) Load 9(id)
39: 6(int) Load 25(count)
41: 40(bool) UGreaterThan 38 39
42: 6(int) Load 9(id)
43: 6(int) Load 25(count)
44: 6(int) ISub 42 43
45: 23(ptr) AccessChain 16(s) 44
46:12(MyStruct) Load 45
48: 6(int) Load 9(id)
50: 49(ptr) AccessChain 32(sb) 18 18 47 48
51:26(MyStruct) Load 50
SelectionMerge 54 None
BranchConditional 41 53 55
53: Label
Store 52 46
Branch 54
55: Label
56: 6(int) CompositeExtract 51 0
57: 7(ptr) AccessChain 52 18
Store 57 56
58: 6(int) CompositeExtract 51 1
59: 7(ptr) AccessChain 52 47
Store 59 58
60: 6(int) CompositeExtract 51 2
62: 7(ptr) AccessChain 52 61
Store 62 60
Branch 54
54: Label
63:12(MyStruct) Load 52
Store 37(ms) 63
68: 33(ptr) AccessChain 67(o) 18 18 18
69: 7(ptr) AccessChain 37(ms) 18
70: 6(int) Load 69
72: 6(int) AtomicIAdd 68 19 71 70
73: 33(ptr) AccessChain 67(o) 18 18 47
74: 7(ptr) AccessChain 37(ms) 47
75: 6(int) Load 74
76: 6(int) AtomicIAdd 73 19 71 75
77: 33(ptr) AccessChain 67(o) 18 18 61
78: 7(ptr) AccessChain 37(ms) 61
79: 6(int) Load 78
80: 6(int) AtomicIAdd 77 19 71 79
Return
FunctionEnd

View File

@ -0,0 +1,385 @@
hlsl.structcopylogical.comp
Shader version: 500
local_size = (128, 1, 1)
0:? Sequence
0:20 Function Definition: @main(u1; ( temp void)
0:20 Function Parameters:
0:20 'id' ( in uint)
0:? Sequence
0:21 move second child to first child ( temp structure{ temp uint a, temp uint b, temp uint c})
0:21 direct index ( temp structure{ temp uint a, temp uint b, temp uint c})
0:21 's' ( shared 128-element array of structure{ temp uint a, temp uint b, temp uint c})
0:21 Constant:
0:21 0 (const int)
0:21 Constant:
0:21 1 (const uint)
0:21 2 (const uint)
0:21 3 (const uint)
0:22 Sequence
0:22 move second child to first child ( temp uint)
0:22 'count' ( temp uint)
0:22 count: direct index for structure ( temp uint)
0:22 direct index (layout( row_major std430) buffer structure{ temp uint count, temp unsized 1-element array of structure{ temp uint a, temp uint b, temp uint c} data})
0:22 @data: direct index for structure (layout( row_major std430) buffer unsized 1-element array of structure{ temp uint count, temp unsized 1-element array of structure{ temp uint a, temp uint b, temp uint c} data})
0:22 'sb' (layout( row_major std430) readonly buffer block{layout( row_major std430) buffer unsized 1-element array of structure{ temp uint count, temp unsized 1-element array of structure{ temp uint a, temp uint b, temp uint c} data} @data})
0:22 Constant:
0:22 0 (const uint)
0:22 Constant:
0:22 0 (const int)
0:22 Constant:
0:22 0 (const int)
0:23 Sequence
0:23 move second child to first child ( temp structure{ temp uint a, temp uint b, temp uint c})
0:23 'ms' ( temp structure{ temp uint a, temp uint b, temp uint c})
0:23 Test condition and select ( temp structure{ temp uint a, temp uint b, temp uint c}): no shortcircuit
0:23 Condition
0:23 Compare Greater Than ( temp bool)
0:23 'id' ( in uint)
0:23 'count' ( temp uint)
0:23 true case
0:23 indirect index ( temp structure{ temp uint a, temp uint b, temp uint c})
0:23 's' ( shared 128-element array of structure{ temp uint a, temp uint b, temp uint c})
0:23 subtract ( temp uint)
0:23 'id' ( in uint)
0:23 'count' ( temp uint)
0:23 false case
0:23 indirect index ( temp structure{ temp uint a, temp uint b, temp uint c})
0:23 data: direct index for structure ( temp unsized 1-element array of structure{ temp uint a, temp uint b, temp uint c})
0:23 direct index (layout( row_major std430) buffer structure{ temp uint count, temp unsized 1-element array of structure{ temp uint a, temp uint b, temp uint c} data})
0:23 @data: direct index for structure (layout( row_major std430) buffer unsized 1-element array of structure{ temp uint count, temp unsized 1-element array of structure{ temp uint a, temp uint b, temp uint c} data})
0:23 'sb' (layout( row_major std430) readonly buffer block{layout( row_major std430) buffer unsized 1-element array of structure{ temp uint count, temp unsized 1-element array of structure{ temp uint a, temp uint b, temp uint c} data} @data})
0:23 Constant:
0:23 0 (const uint)
0:23 Constant:
0:23 0 (const int)
0:23 Constant:
0:23 1 (const int)
0:23 'id' ( in uint)
0:25 AtomicAdd ( temp uint)
0:25 a: direct index for structure ( temp uint)
0:25 direct index (layout( row_major std430) buffer structure{ temp uint a, temp uint b, temp uint c})
0:25 @data: direct index for structure (layout( row_major std430) buffer unsized 1-element array of structure{ temp uint a, temp uint b, temp uint c})
0:25 'o' (layout( row_major std430) readonly buffer block{layout( row_major std430) buffer unsized 1-element array of structure{ temp uint a, temp uint b, temp uint c} @data})
0:25 Constant:
0:25 0 (const uint)
0:25 Constant:
0:25 0 (const int)
0:25 Constant:
0:25 0 (const int)
0:25 a: direct index for structure ( temp uint)
0:25 'ms' ( temp structure{ temp uint a, temp uint b, temp uint c})
0:25 Constant:
0:25 0 (const int)
0:26 AtomicAdd ( temp uint)
0:26 b: direct index for structure ( temp uint)
0:26 direct index (layout( row_major std430) buffer structure{ temp uint a, temp uint b, temp uint c})
0:26 @data: direct index for structure (layout( row_major std430) buffer unsized 1-element array of structure{ temp uint a, temp uint b, temp uint c})
0:26 'o' (layout( row_major std430) readonly buffer block{layout( row_major std430) buffer unsized 1-element array of structure{ temp uint a, temp uint b, temp uint c} @data})
0:26 Constant:
0:26 0 (const uint)
0:26 Constant:
0:26 0 (const int)
0:26 Constant:
0:26 1 (const int)
0:26 b: direct index for structure ( temp uint)
0:26 'ms' ( temp structure{ temp uint a, temp uint b, temp uint c})
0:26 Constant:
0:26 1 (const int)
0:27 AtomicAdd ( temp uint)
0:27 c: direct index for structure ( temp uint)
0:27 direct index (layout( row_major std430) buffer structure{ temp uint a, temp uint b, temp uint c})
0:27 @data: direct index for structure (layout( row_major std430) buffer unsized 1-element array of structure{ temp uint a, temp uint b, temp uint c})
0:27 'o' (layout( row_major std430) readonly buffer block{layout( row_major std430) buffer unsized 1-element array of structure{ temp uint a, temp uint b, temp uint c} @data})
0:27 Constant:
0:27 0 (const uint)
0:27 Constant:
0:27 0 (const int)
0:27 Constant:
0:27 2 (const int)
0:27 c: direct index for structure ( temp uint)
0:27 'ms' ( temp structure{ temp uint a, temp uint b, temp uint c})
0:27 Constant:
0:27 2 (const int)
0:20 Function Definition: main( ( temp void)
0:20 Function Parameters:
0:? Sequence
0:20 move second child to first child ( temp uint)
0:? 'id' ( temp uint)
0:? 'id' ( in uint LocalInvocationIndex)
0:20 Function Call: @main(u1; ( temp void)
0:? 'id' ( temp uint)
0:? Linker Objects
0:? 'sb' (layout( row_major std430) readonly buffer block{layout( row_major std430) buffer unsized 1-element array of structure{ temp uint count, temp unsized 1-element array of structure{ temp uint a, temp uint b, temp uint c} data} @data})
0:? 'o' (layout( row_major std430) readonly buffer block{layout( row_major std430) buffer unsized 1-element array of structure{ temp uint a, temp uint b, temp uint c} @data})
0:? 's' ( shared 128-element array of structure{ temp uint a, temp uint b, temp uint c})
0:? 'deflt' ( const structure{ temp uint a, temp uint b, temp uint c})
0:? 1 (const uint)
0:? 2 (const uint)
0:? 3 (const uint)
0:? 'id' ( in uint LocalInvocationIndex)
Linked compute stage:
Shader version: 500
local_size = (128, 1, 1)
0:? Sequence
0:20 Function Definition: @main(u1; ( temp void)
0:20 Function Parameters:
0:20 'id' ( in uint)
0:? Sequence
0:21 move second child to first child ( temp structure{ temp uint a, temp uint b, temp uint c})
0:21 direct index ( temp structure{ temp uint a, temp uint b, temp uint c})
0:21 's' ( shared 128-element array of structure{ temp uint a, temp uint b, temp uint c})
0:21 Constant:
0:21 0 (const int)
0:21 Constant:
0:21 1 (const uint)
0:21 2 (const uint)
0:21 3 (const uint)
0:22 Sequence
0:22 move second child to first child ( temp uint)
0:22 'count' ( temp uint)
0:22 count: direct index for structure ( temp uint)
0:22 direct index (layout( row_major std430) buffer structure{ temp uint count, temp unsized 1-element array of structure{ temp uint a, temp uint b, temp uint c} data})
0:22 @data: direct index for structure (layout( row_major std430) buffer unsized 1-element array of structure{ temp uint count, temp unsized 1-element array of structure{ temp uint a, temp uint b, temp uint c} data})
0:22 'sb' (layout( row_major std430) readonly buffer block{layout( row_major std430) buffer unsized 1-element array of structure{ temp uint count, temp unsized 1-element array of structure{ temp uint a, temp uint b, temp uint c} data} @data})
0:22 Constant:
0:22 0 (const uint)
0:22 Constant:
0:22 0 (const int)
0:22 Constant:
0:22 0 (const int)
0:23 Sequence
0:23 move second child to first child ( temp structure{ temp uint a, temp uint b, temp uint c})
0:23 'ms' ( temp structure{ temp uint a, temp uint b, temp uint c})
0:23 Test condition and select ( temp structure{ temp uint a, temp uint b, temp uint c}): no shortcircuit
0:23 Condition
0:23 Compare Greater Than ( temp bool)
0:23 'id' ( in uint)
0:23 'count' ( temp uint)
0:23 true case
0:23 indirect index ( temp structure{ temp uint a, temp uint b, temp uint c})
0:23 's' ( shared 128-element array of structure{ temp uint a, temp uint b, temp uint c})
0:23 subtract ( temp uint)
0:23 'id' ( in uint)
0:23 'count' ( temp uint)
0:23 false case
0:23 indirect index ( temp structure{ temp uint a, temp uint b, temp uint c})
0:23 data: direct index for structure ( temp unsized 1-element array of structure{ temp uint a, temp uint b, temp uint c})
0:23 direct index (layout( row_major std430) buffer structure{ temp uint count, temp unsized 1-element array of structure{ temp uint a, temp uint b, temp uint c} data})
0:23 @data: direct index for structure (layout( row_major std430) buffer unsized 1-element array of structure{ temp uint count, temp unsized 1-element array of structure{ temp uint a, temp uint b, temp uint c} data})
0:23 'sb' (layout( row_major std430) readonly buffer block{layout( row_major std430) buffer unsized 1-element array of structure{ temp uint count, temp unsized 1-element array of structure{ temp uint a, temp uint b, temp uint c} data} @data})
0:23 Constant:
0:23 0 (const uint)
0:23 Constant:
0:23 0 (const int)
0:23 Constant:
0:23 1 (const int)
0:23 'id' ( in uint)
0:25 AtomicAdd ( temp uint)
0:25 a: direct index for structure ( temp uint)
0:25 direct index (layout( row_major std430) buffer structure{ temp uint a, temp uint b, temp uint c})
0:25 @data: direct index for structure (layout( row_major std430) buffer unsized 1-element array of structure{ temp uint a, temp uint b, temp uint c})
0:25 'o' (layout( row_major std430) readonly buffer block{layout( row_major std430) buffer unsized 1-element array of structure{ temp uint a, temp uint b, temp uint c} @data})
0:25 Constant:
0:25 0 (const uint)
0:25 Constant:
0:25 0 (const int)
0:25 Constant:
0:25 0 (const int)
0:25 a: direct index for structure ( temp uint)
0:25 'ms' ( temp structure{ temp uint a, temp uint b, temp uint c})
0:25 Constant:
0:25 0 (const int)
0:26 AtomicAdd ( temp uint)
0:26 b: direct index for structure ( temp uint)
0:26 direct index (layout( row_major std430) buffer structure{ temp uint a, temp uint b, temp uint c})
0:26 @data: direct index for structure (layout( row_major std430) buffer unsized 1-element array of structure{ temp uint a, temp uint b, temp uint c})
0:26 'o' (layout( row_major std430) readonly buffer block{layout( row_major std430) buffer unsized 1-element array of structure{ temp uint a, temp uint b, temp uint c} @data})
0:26 Constant:
0:26 0 (const uint)
0:26 Constant:
0:26 0 (const int)
0:26 Constant:
0:26 1 (const int)
0:26 b: direct index for structure ( temp uint)
0:26 'ms' ( temp structure{ temp uint a, temp uint b, temp uint c})
0:26 Constant:
0:26 1 (const int)
0:27 AtomicAdd ( temp uint)
0:27 c: direct index for structure ( temp uint)
0:27 direct index (layout( row_major std430) buffer structure{ temp uint a, temp uint b, temp uint c})
0:27 @data: direct index for structure (layout( row_major std430) buffer unsized 1-element array of structure{ temp uint a, temp uint b, temp uint c})
0:27 'o' (layout( row_major std430) readonly buffer block{layout( row_major std430) buffer unsized 1-element array of structure{ temp uint a, temp uint b, temp uint c} @data})
0:27 Constant:
0:27 0 (const uint)
0:27 Constant:
0:27 0 (const int)
0:27 Constant:
0:27 2 (const int)
0:27 c: direct index for structure ( temp uint)
0:27 'ms' ( temp structure{ temp uint a, temp uint b, temp uint c})
0:27 Constant:
0:27 2 (const int)
0:20 Function Definition: main( ( temp void)
0:20 Function Parameters:
0:? Sequence
0:20 move second child to first child ( temp uint)
0:? 'id' ( temp uint)
0:? 'id' ( in uint LocalInvocationIndex)
0:20 Function Call: @main(u1; ( temp void)
0:? 'id' ( temp uint)
0:? Linker Objects
0:? 'sb' (layout( row_major std430) readonly buffer block{layout( row_major std430) buffer unsized 1-element array of structure{ temp uint count, temp unsized 1-element array of structure{ temp uint a, temp uint b, temp uint c} data} @data})
0:? 'o' (layout( row_major std430) readonly buffer block{layout( row_major std430) buffer unsized 1-element array of structure{ temp uint a, temp uint b, temp uint c} @data})
0:? 's' ( shared 128-element array of structure{ temp uint a, temp uint b, temp uint c})
0:? 'deflt' ( const structure{ temp uint a, temp uint b, temp uint c})
0:? 1 (const uint)
0:? 2 (const uint)
0:? 3 (const uint)
0:? 'id' ( in uint LocalInvocationIndex)
// Module Version 10600
// Generated by (magic number): 8000b
// Id's are bound by 79
Capability Shader
1: ExtInstImport "GLSL.std.450"
MemoryModel Logical GLSL450
EntryPoint GLCompute 4 "main" 17 32 57 74
ExecutionModeId 4 LocalSizeId 7 8 8
Source HLSL 500
Name 4 "main"
Name 12 "@main(u1;"
Name 11 "id"
Name 14 "MyStruct"
MemberName 14(MyStruct) 0 "a"
MemberName 14(MyStruct) 1 "b"
MemberName 14(MyStruct) 2 "c"
Name 17 "s"
Name 25 "count"
Name 26 "MyStruct"
MemberName 26(MyStruct) 0 "a"
MemberName 26(MyStruct) 1 "b"
MemberName 26(MyStruct) 2 "c"
Name 28 "MyStructs"
MemberName 28(MyStructs) 0 "count"
MemberName 28(MyStructs) 1 "data"
Name 30 "sb"
MemberName 30(sb) 0 "@data"
Name 32 "sb"
Name 37 "ms"
Name 55 "o"
MemberName 55(o) 0 "@data"
Name 57 "o"
Name 72 "id"
Name 74 "id"
Name 76 "param"
MemberDecorate 26(MyStruct) 0 Offset 0
MemberDecorate 26(MyStruct) 1 Offset 4
MemberDecorate 26(MyStruct) 2 Offset 8
Decorate 27 ArrayStride 12
MemberDecorate 28(MyStructs) 0 Offset 0
MemberDecorate 28(MyStructs) 1 Offset 4
Decorate 28(MyStructs) Block
Decorate 29 ArrayStride 16
MemberDecorate 30(sb) 0 NonWritable
MemberDecorate 30(sb) 0 Offset 0
Decorate 30(sb) Block
Decorate 32(sb) DescriptorSet 0
Decorate 32(sb) Binding 0
Decorate 54 ArrayStride 12
MemberDecorate 55(o) 0 NonWritable
MemberDecorate 55(o) 0 Offset 0
Decorate 55(o) Block
Decorate 57(o) DescriptorSet 0
Decorate 57(o) Binding 1
Decorate 74(id) BuiltIn LocalInvocationIndex
2: TypeVoid
3: TypeFunction 2
6: TypeInt 32 0
7: 6(int) Constant 128
8: 6(int) Constant 1
9: TypePointer Function 6(int)
10: TypeFunction 2 9(ptr)
14(MyStruct): TypeStruct 6(int) 6(int) 6(int)
15: TypeArray 14(MyStruct) 7
16: TypePointer Workgroup 15
17(s): 16(ptr) Variable Workgroup
18: TypeInt 32 1
19: 18(int) Constant 0
20: 6(int) Constant 2
21: 6(int) Constant 3
22:14(MyStruct) ConstantComposite 8 20 21
23: TypePointer Workgroup 14(MyStruct)
26(MyStruct): TypeStruct 6(int) 6(int) 6(int)
27: TypeRuntimeArray 26(MyStruct)
28(MyStructs): TypeStruct 6(int) 27
29: TypeRuntimeArray 28(MyStructs)
30(sb): TypeStruct 29
31: TypePointer StorageBuffer 30(sb)
32(sb): 31(ptr) Variable StorageBuffer
33: TypePointer StorageBuffer 6(int)
36: TypePointer Function 14(MyStruct)
40: TypeBool
47: 18(int) Constant 1
49: TypePointer StorageBuffer 26(MyStruct)
54: TypeRuntimeArray 26(MyStruct)
55(o): TypeStruct 54
56: TypePointer StorageBuffer 55(o)
57(o): 56(ptr) Variable StorageBuffer
61: 6(int) Constant 0
67: 18(int) Constant 2
73: TypePointer Input 6(int)
74(id): 73(ptr) Variable Input
4(main): 2 Function None 3
5: Label
72(id): 9(ptr) Variable Function
76(param): 9(ptr) Variable Function
75: 6(int) Load 74(id)
Store 72(id) 75
77: 6(int) Load 72(id)
Store 76(param) 77
78: 2 FunctionCall 12(@main(u1;) 76(param)
Return
FunctionEnd
12(@main(u1;): 2 Function None 10
11(id): 9(ptr) FunctionParameter
13: Label
25(count): 9(ptr) Variable Function
37(ms): 36(ptr) Variable Function
24: 23(ptr) AccessChain 17(s) 19
Store 24 22
34: 33(ptr) AccessChain 32(sb) 19 19 19
35: 6(int) Load 34
Store 25(count) 35
38: 6(int) Load 11(id)
39: 6(int) Load 25(count)
41: 40(bool) UGreaterThan 38 39
42: 6(int) Load 11(id)
43: 6(int) Load 25(count)
44: 6(int) ISub 42 43
45: 23(ptr) AccessChain 17(s) 44
46:14(MyStruct) Load 45
48: 6(int) Load 11(id)
50: 49(ptr) AccessChain 32(sb) 19 19 47 48
51:26(MyStruct) Load 50
52:14(MyStruct) CopyLogical 51
53:14(MyStruct) Select 41 46 52
Store 37(ms) 53
58: 33(ptr) AccessChain 57(o) 19 19 19
59: 9(ptr) AccessChain 37(ms) 19
60: 6(int) Load 59
62: 6(int) AtomicIAdd 58 8 61 60
63: 33(ptr) AccessChain 57(o) 19 19 47
64: 9(ptr) AccessChain 37(ms) 47
65: 6(int) Load 64
66: 6(int) AtomicIAdd 63 8 61 65
68: 33(ptr) AccessChain 57(o) 19 19 67
69: 9(ptr) AccessChain 37(ms) 67
70: 6(int) Load 69
71: 6(int) AtomicIAdd 68 8 61 70
Return
FunctionEnd

View File

@ -0,0 +1,142 @@
spv.structCopy.comp
// Module Version 10000
// Generated by (magic number): 8000b
// Id's are bound by 81
Capability Shader
1: ExtInstImport "GLSL.std.450"
MemoryModel Logical GLSL450
EntryPoint GLCompute 4 "main" 24
ExecutionMode 4 LocalSize 512 1 1
Source GLSL 460
Name 4 "main"
Name 7 "MyStruct"
MemberName 7(MyStruct) 0 "a"
MemberName 7(MyStruct) 1 "b"
MemberName 7(MyStruct) 2 "c"
Name 11 "s"
Name 21 "id"
Name 24 "gl_GlobalInvocationID"
Name 30 "ms"
Name 32 "MyStruct"
MemberName 32(MyStruct) 0 "a"
MemberName 32(MyStruct) 1 "b"
MemberName 32(MyStruct) 2 "c"
Name 34 "MyStructs"
MemberName 34(MyStructs) 0 "count"
MemberName 34(MyStructs) 1 "data"
Name 36 "my_structs"
Name 65 "Output"
MemberName 65(Output) 0 "a"
MemberName 65(Output) 1 "b"
MemberName 65(Output) 2 "c"
Name 67 "o"
Decorate 24(gl_GlobalInvocationID) BuiltIn GlobalInvocationId
MemberDecorate 32(MyStruct) 0 Offset 0
MemberDecorate 32(MyStruct) 1 Offset 4
MemberDecorate 32(MyStruct) 2 Offset 8
Decorate 33 ArrayStride 12
MemberDecorate 34(MyStructs) 0 Offset 0
MemberDecorate 34(MyStructs) 1 Offset 4
Decorate 34(MyStructs) BufferBlock
Decorate 36(my_structs) DescriptorSet 0
Decorate 36(my_structs) Binding 0
MemberDecorate 65(Output) 0 Offset 0
MemberDecorate 65(Output) 1 Offset 4
MemberDecorate 65(Output) 2 Offset 8
Decorate 65(Output) BufferBlock
Decorate 67(o) DescriptorSet 0
Decorate 67(o) Binding 1
Decorate 80 BuiltIn WorkgroupSize
2: TypeVoid
3: TypeFunction 2
6: TypeInt 32 0
7(MyStruct): TypeStruct 6(int) 6(int) 6(int)
8: 6(int) Constant 512
9: TypeArray 7(MyStruct) 8
10: TypePointer Workgroup 9
11(s): 10(ptr) Variable Workgroup
12: TypeInt 32 1
13: 12(int) Constant 0
14: 6(int) Constant 1
15: 6(int) Constant 2
16: 6(int) Constant 3
17: 7(MyStruct) ConstantComposite 14 15 16
18: TypePointer Workgroup 7(MyStruct)
20: TypePointer Function 6(int)
22: TypeVector 6(int) 3
23: TypePointer Input 22(ivec3)
24(gl_GlobalInvocationID): 23(ptr) Variable Input
25: 6(int) Constant 0
26: TypePointer Input 6(int)
29: TypePointer Function 7(MyStruct)
32(MyStruct): TypeStruct 6(int) 6(int) 6(int)
33: TypeRuntimeArray 32(MyStruct)
34(MyStructs): TypeStruct 6(int) 33
35: TypePointer Uniform 34(MyStructs)
36(my_structs): 35(ptr) Variable Uniform
37: TypePointer Uniform 6(int)
40: TypeBool
52: 12(int) Constant 1
54: TypePointer Uniform 32(MyStruct)
62: 12(int) Constant 2
65(Output): TypeStruct 6(int) 6(int) 6(int)
66: TypePointer Uniform 65(Output)
67(o): 66(ptr) Variable Uniform
80: 22(ivec3) ConstantComposite 8 14 14
4(main): 2 Function None 3
5: Label
21(id): 20(ptr) Variable Function
30(ms): 29(ptr) Variable Function
42: 29(ptr) Variable Function
19: 18(ptr) AccessChain 11(s) 13
Store 19 17
27: 26(ptr) AccessChain 24(gl_GlobalInvocationID) 25
28: 6(int) Load 27
Store 21(id) 28
31: 6(int) Load 21(id)
38: 37(ptr) AccessChain 36(my_structs) 13
39: 6(int) Load 38
41: 40(bool) UGreaterThan 31 39
SelectionMerge 44 None
BranchConditional 41 43 51
43: Label
45: 6(int) Load 21(id)
46: 37(ptr) AccessChain 36(my_structs) 13
47: 6(int) Load 46
48: 6(int) ISub 45 47
49: 18(ptr) AccessChain 11(s) 48
50: 7(MyStruct) Load 49
Store 42 50
Branch 44
51: Label
53: 6(int) Load 21(id)
55: 54(ptr) AccessChain 36(my_structs) 52 53
56:32(MyStruct) Load 55
57: 6(int) CompositeExtract 56 0
58: 20(ptr) AccessChain 42 13
Store 58 57
59: 6(int) CompositeExtract 56 1
60: 20(ptr) AccessChain 42 52
Store 60 59
61: 6(int) CompositeExtract 56 2
63: 20(ptr) AccessChain 42 62
Store 63 61
Branch 44
44: Label
64: 7(MyStruct) Load 42
Store 30(ms) 64
68: 37(ptr) AccessChain 67(o) 13
69: 20(ptr) AccessChain 30(ms) 13
70: 6(int) Load 69
71: 6(int) AtomicIAdd 68 14 25 70
72: 37(ptr) AccessChain 67(o) 52
73: 20(ptr) AccessChain 30(ms) 52
74: 6(int) Load 73
75: 6(int) AtomicIAdd 72 14 25 74
76: 37(ptr) AccessChain 67(o) 62
77: 20(ptr) AccessChain 30(ms) 62
78: 6(int) Load 77
79: 6(int) AtomicIAdd 76 14 25 78
Return
FunctionEnd

28
Test/hlsl.structcopy.comp Normal file
View File

@ -0,0 +1,28 @@
struct MyStruct {
uint a;
uint b;
uint c;
};
struct MyStructs {
uint count;
MyStruct data[];
};
StructuredBuffer<MyStructs> sb;
StructuredBuffer<MyStruct> o;
groupshared MyStruct s[128];
static const MyStruct deflt = { 1u, 2u, 3u };
[numthreads(128, 1, 1)]
void main(uint id : SV_GroupIndex)
{
s[0] = deflt;
uint count = sb.Load(0).count;
MyStruct ms = id > count ? s[id - count] : sb.Load(0).data[id];
InterlockedAdd(o[0].a, ms.a);
InterlockedAdd(o[0].b, ms.b);
InterlockedAdd(o[0].c, ms.c);
}

View File

@ -0,0 +1,28 @@
struct MyStruct {
uint a;
uint b;
uint c;
};
struct MyStructs {
uint count;
MyStruct data[];
};
StructuredBuffer<MyStructs> sb;
StructuredBuffer<MyStruct> o;
groupshared MyStruct s[128];
static const MyStruct deflt = { 1u, 2u, 3u };
[numthreads(128, 1, 1)]
void main(uint id : SV_GroupIndex)
{
s[0] = deflt;
uint count = sb.Load(0).count;
MyStruct ms = id > count ? s[id - count] : sb.Load(0).data[id];
InterlockedAdd(o[0].a, ms.a);
InterlockedAdd(o[0].b, ms.b);
InterlockedAdd(o[0].c, ms.c);
}

37
Test/spv.structCopy.comp Normal file
View File

@ -0,0 +1,37 @@
#version 460
layout(local_size_x = 512, local_size_y = 1) in;
layout(std430) buffer;
struct MyStruct {
uint a;
uint b;
uint c;
};
layout(binding = 0) buffer MyStructs {
uint count;
MyStruct data[];
}
my_structs;
layout(binding = 1) buffer Output {
uint a;
uint b;
uint c;
}
o;
shared MyStruct s[512];
void main() {
s[0] = MyStruct(1, 2, 3);
uint id = gl_GlobalInvocationID.x;
MyStruct ms =
id > my_structs.count ? s[id - my_structs.count] : my_structs.data[id];
atomicAdd(o.a, ms.a);
atomicAdd(o.b, ms.b);
atomicAdd(o.c, ms.c);
}

View File

@ -402,6 +402,7 @@ INSTANTIATE_TEST_SUITE_P(
{"hlsl.structbuffer.rw.frag", "main"},
{"hlsl.structbuffer.rwbyte.frag", "main"},
{"hlsl.structbuffer.rwbyte2.comp", "main"},
{"hlsl.structcopy.comp", "main"},
{"hlsl.structin.vert", "main"},
{"hlsl.structIoFourWay.frag", "main"},
{"hlsl.structStructName.frag", "main"},
@ -472,7 +473,8 @@ INSTANTIATE_TEST_SUITE_P(
INSTANTIATE_TEST_SUITE_P(
ToSpirv, HlslSpv1_6CompileTest,
::testing::ValuesIn(std::vector<FileNameEntryPointPair>{
{"hlsl.spv.1.6.discard.frag", "PixelShaderFunction"}
{"hlsl.spv.1.6.discard.frag", "PixelShaderFunction"},
{"hlsl.structcopylogical.comp","main"},
}),
FileNameAsCustomTestSuffix
);

View File

@ -441,6 +441,7 @@ INSTANTIATE_TEST_SUITE_P(
"spv.sparseTexture.frag",
"spv.sparseTextureClamp.frag",
"spv.structAssignment.frag",
"spv.structCopy.comp",
"spv.structDeref.frag",
"spv.structure.frag",
"spv.switch.frag",