1[require]
2VK_KHR_spirv_1_4
3VK_KHR_variable_pointers
4VariablePointerFeatures.variablePointersStorageBuffer
5VariablePointerFeatures.variablePointers
6VK_KHR_storage_buffer_storage_class
7VK_KHR_get_physical_device_properties2
8
9[compute shader spirv]
10; Test operates on a Workgroup array (%wg_var) containing an array of 16 arrays of four ints.
11
12; Each invocation writes out the result of OpPtrEqual for elements of the
13; outer array to index 16 of the corresponding output variable. Pointers are
14; based the gid'th element vs the zero'th element.
15
16; Each invocation loops 4 times and writes out 4 results each for OpPtrEqual.
17; The pointers are the lid'th element of gid'th element of the outer array vs
18; the iteration count mod 4'th element of the gid'th element of the outer
19; array. Results are ordered so each thread writes continguous results.
20
21OpCapability Shader
22OpCapability VariablePointers
23OpMemoryModel Logical GLSL450
24OpEntryPoint GLCompute %main "main" %wg_var %equal_var %lid_var %gid_var
25OpExecutionMode %main LocalSize 16 4 1
26
27OpDecorate %struct_17 Block
28OpMemberDecorate %struct_17 0 Offset 0
29OpDecorate %runtime_17 ArrayStride 68
30OpDecorate %array_17 ArrayStride 4
31
32OpDecorate %equal_var DescriptorSet 0
33OpDecorate %equal_var Binding 0
34
35OpDecorate %lid_var BuiltIn LocalInvocationId
36OpDecorate %gid_var BuiltIn GlobalInvocationId
37
38%void = OpTypeVoid
39%bool = OpTypeBool
40%int = OpTypeInt 32 1
41%int_0 = OpConstant %int 0
42%int_1 = OpConstant %int 1
43%int_4 = OpConstant %int 4
44%int_16 = OpConstant %int 16
45%int_17 = OpConstant %int 17
46%int_64 = OpConstant %int 64
47%int3 = OpTypeVector %int 3
48
49%ptr_input_int3 = OpTypePointer Input %int3
50
51%array_4 = OpTypeArray %int %int_4
52%array_array_4 = OpTypeArray %array_4 %int_16
53%ptr_array_array_4 = OpTypePointer Workgroup %array_array_4
54%ptr_array_4 = OpTypePointer Workgroup %array_4
55%ptr_wg_int = OpTypePointer Workgroup %int
56
57%array_17 = OpTypeArray %int %int_17
58%runtime_17 = OpTypeRuntimeArray %array_17
59%struct_17 = OpTypeStruct %runtime_17
60%ptr_struct_17 = OpTypePointer StorageBuffer %struct_17
61%ptr_array_17 = OpTypePointer StorageBuffer %array_17
62%ptr_int = OpTypePointer StorageBuffer %int
63
64%wg_var = OpVariable %ptr_array_array_4 Workgroup
65%equal_var = OpVariable %ptr_struct_17 StorageBuffer
66%lid_var = OpVariable %ptr_input_int3 Input
67%gid_var = OpVariable %ptr_input_int3 Input
68
69%void_fn = OpTypeFunction %void
70%main = OpFunction %void None %void_fn
71%entry = OpLabel
72%gid = OpLoad %int3 %gid_var
73%gid_x = OpCompositeExtract %int %gid 0
74%gid_y = OpCompositeExtract %int %gid 1
75%lid = OpLoad %int3 %lid_var
76%lid_x = OpCompositeExtract %int %lid 0
77%lid_y = OpCompositeExtract %int %lid 1
78%array_gep_0 = OpAccessChain %ptr_array_4 %wg_var %int_0
79%array_gep = OpAccessChain %ptr_array_4 %wg_var %lid_x
80%lid_y_is_1 = OpIEqual %bool %lid_y %int_1
81OpSelectionMerge %loop None
82OpBranchConditional %lid_y_is_1 %then %loop
83
84%then = OpLabel
85; Compute results for outer array
86%large_equal = OpPtrEqual %bool %array_gep %array_gep_0
87%large_equal_gep = OpAccessChain %ptr_int %equal_var %int_0 %gid_x %int_16
88%large_equal_int = OpSelect %int %large_equal %int_1 %int_0
89OpStore %large_equal_gep %large_equal_int
90;
91OpBranch %loop
92
93%loop = OpLabel
94%i = OpPhi %int %int_0 %entry %int_0 %then %inc_i %loop
95%inc_i = OpIAdd %int %i %int_1
96%i_cmp = OpIEqual %bool %inc_i %int_4
97%lid_offset = OpIMul %int %lid_y %int_4
98%out_gep_index = OpIAdd %int %i %lid_offset
99; Compute results for inner array
100%ref_gep = OpAccessChain %ptr_wg_int %array_gep %lid_y
101%cmp_gep = OpAccessChain %ptr_wg_int %array_gep %i
102%equal = OpPtrEqual %bool %ref_gep %cmp_gep
103%equal_int = OpSelect %int %equal %int_1 %int_0
104%equal_gep = OpAccessChain %ptr_int %equal_var %int_0 %gid_x %out_gep_index
105OpStore %equal_gep %equal_int
106;
107OpLoopMerge %exit %loop None
108OpBranchConditional %i_cmp %exit %loop
109
110%exit = OpLabel
111OpReturn
112OpFunctionEnd
113
114
115[test]
116# 16 x 4 x 2 = 128 work items
117# 4 x 4 = 16 bytes per invocation
118# 2048 bytes from looping
119# 16 x 2 = 32 coarse results (1 per lid)
120# 128 bytes
121# 2176 total bytes
122ssbo 0:0 2176
123
124compute entrypoint main
125compute 2 1 1
126
127#equal var
128probe ssbo int 0:0 0    == 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 1
129probe ssbo int 0:0 68   == 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0
130probe ssbo int 0:0 136  == 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0
131probe ssbo int 0:0 204  == 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0
132probe ssbo int 0:0 272  == 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0
133probe ssbo int 0:0 340  == 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0
134probe ssbo int 0:0 408  == 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0
135probe ssbo int 0:0 476  == 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0
136probe ssbo int 0:0 544  == 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0
137probe ssbo int 0:0 612  == 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0
138probe ssbo int 0:0 680  == 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0
139probe ssbo int 0:0 748  == 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0
140probe ssbo int 0:0 816  == 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0
141probe ssbo int 0:0 884  == 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0
142probe ssbo int 0:0 952  == 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0
143probe ssbo int 0:0 1020 == 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0
144probe ssbo int 0:0 1088 == 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 1
145probe ssbo int 0:0 1156 == 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0
146probe ssbo int 0:0 1224 == 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0
147probe ssbo int 0:0 1292 == 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0
148probe ssbo int 0:0 1360 == 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0
149probe ssbo int 0:0 1428 == 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0
150probe ssbo int 0:0 1496 == 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0
151probe ssbo int 0:0 1564 == 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0
152probe ssbo int 0:0 1632 == 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0
153probe ssbo int 0:0 1700 == 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0
154probe ssbo int 0:0 1768 == 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0
155probe ssbo int 0:0 1836 == 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0
156probe ssbo int 0:0 1904 == 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0
157probe ssbo int 0:0 1972 == 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0
158probe ssbo int 0:0 2040 == 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0
159probe ssbo int 0:0 2108 == 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0
160
161