1 /*
2 * Copyright © 2020 Valve Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
22 */
23 #include "helpers.h"
24
25 class AvailabilityVisibility : public spirv_test {};
26
TEST_F(AvailabilityVisibility,opload_vis)27 TEST_F(AvailabilityVisibility, opload_vis)
28 {
29 /*
30 OpCapability Shader
31 OpCapability VulkanMemoryModel
32 OpCapability VulkanMemoryModelDeviceScope
33 %1 = OpExtInstImport "GLSL.std.450"
34 OpMemoryModel Logical Vulkan
35 OpEntryPoint GLCompute %4 "main" %9
36 OpExecutionMode %4 LocalSize 1 1 1
37 OpMemberDecorate %_struct_7 0 Offset 0
38 OpDecorate %_struct_7 Block
39 OpDecorate %9 DescriptorSet 0
40 OpDecorate %9 Binding 0
41 %void = OpTypeVoid
42 %3 = OpTypeFunction %void
43 %uint = OpTypeInt 32 0
44 %_struct_7 = OpTypeStruct %uint
45 %_ptr_StorageBuffer__struct_7 = OpTypePointer StorageBuffer %_struct_7
46 %9 = OpVariable %_ptr_StorageBuffer__struct_7 StorageBuffer
47 %int = OpTypeInt 32 1
48 %int_0 = OpConstant %int 0
49 %_ptr_StorageBuffer_uint = OpTypePointer StorageBuffer %uint
50 %device = OpConstant %int 1
51 %4 = OpFunction %void None %3
52 %5 = OpLabel
53 %13 = OpAccessChain %_ptr_StorageBuffer_uint %9 %int_0
54 %14 = OpLoad %uint %13 NonPrivatePointer|MakePointerVisible %device
55 OpStore %13 %14
56 OpReturn
57 OpFunctionEnd
58 */
59 static const uint32_t words[] = {
60 0x07230203, 0x00010500, 0x00070000, 0x00000010, 0x00000000, 0x00020011,
61 0x00000001, 0x00020011, 0x000014e1, 0x00020011, 0x000014e2, 0x0006000b,
62 0x00000001, 0x4c534c47, 0x6474732e, 0x3035342e, 0x00000000, 0x0003000e,
63 0x00000000, 0x00000003, 0x0006000f, 0x00000005, 0x00000002, 0x6e69616d,
64 0x00000000, 0x00000003, 0x00060010, 0x00000002, 0x00000011, 0x00000001,
65 0x00000001, 0x00000001, 0x00050048, 0x00000004, 0x00000000, 0x00000023,
66 0x00000000, 0x00030047, 0x00000004, 0x00000002, 0x00040047, 0x00000003,
67 0x00000022, 0x00000000, 0x00040047, 0x00000003, 0x00000021, 0x00000000,
68 0x00020013, 0x00000005, 0x00030021, 0x00000006, 0x00000005, 0x00040015,
69 0x00000007, 0x00000020, 0x00000000, 0x0003001e, 0x00000004, 0x00000007,
70 0x00040020, 0x00000008, 0x0000000c, 0x00000004, 0x0004003b, 0x00000008,
71 0x00000003, 0x0000000c, 0x00040015, 0x00000009, 0x00000020, 0x00000001,
72 0x0004002b, 0x00000009, 0x0000000a, 0x00000000, 0x00040020, 0x0000000b,
73 0x0000000c, 0x00000007, 0x0004002b, 0x00000009, 0x0000000c, 0x00000001,
74 0x00050036, 0x00000005, 0x00000002, 0x00000000, 0x00000006, 0x000200f8,
75 0x0000000d, 0x00050041, 0x0000000b, 0x0000000e, 0x00000003, 0x0000000a,
76 0x0006003d, 0x00000007, 0x0000000f, 0x0000000e, 0x00000030, 0x0000000c,
77 0x0003003e, 0x0000000e, 0x0000000f, 0x000100fd, 0x00010038,
78 };
79
80 get_nir(sizeof(words) / sizeof(words[0]), words);
81
82 nir_intrinsic_instr *intrinsic = find_intrinsic(nir_intrinsic_barrier, 0);
83 ASSERT_NE(intrinsic, nullptr);
84
85 EXPECT_EQ(nir_intrinsic_memory_semantics(intrinsic), NIR_MEMORY_MAKE_VISIBLE | NIR_MEMORY_ACQUIRE);
86 EXPECT_NE(nir_intrinsic_memory_modes(intrinsic) & nir_var_mem_ssbo, 0);
87 EXPECT_EQ(nir_intrinsic_memory_scope(intrinsic), SCOPE_DEVICE);
88 EXPECT_EQ(nir_intrinsic_execution_scope(intrinsic), SCOPE_NONE);
89 }
90
TEST_F(AvailabilityVisibility,opstore_avail)91 TEST_F(AvailabilityVisibility, opstore_avail)
92 {
93 /*
94 OpCapability Shader
95 OpCapability VulkanMemoryModel
96 OpCapability VulkanMemoryModelDeviceScope
97 %1 = OpExtInstImport "GLSL.std.450"
98 OpMemoryModel Logical Vulkan
99 OpEntryPoint GLCompute %4 "main" %9
100 OpExecutionMode %4 LocalSize 1 1 1
101 OpMemberDecorate %_struct_7 0 Offset 0
102 OpDecorate %_struct_7 Block
103 OpDecorate %9 DescriptorSet 0
104 OpDecorate %9 Binding 0
105 %void = OpTypeVoid
106 %3 = OpTypeFunction %void
107 %uint = OpTypeInt 32 0
108 %_struct_7 = OpTypeStruct %uint
109 %_ptr_StorageBuffer__struct_7 = OpTypePointer StorageBuffer %_struct_7
110 %9 = OpVariable %_ptr_StorageBuffer__struct_7 StorageBuffer
111 %int = OpTypeInt 32 1
112 %int_0 = OpConstant %int 0
113 %_ptr_StorageBuffer_uint = OpTypePointer StorageBuffer %uint
114 %device = OpConstant %int 1
115 %4 = OpFunction %void None %3
116 %5 = OpLabel
117 %13 = OpAccessChain %_ptr_StorageBuffer_uint %9 %int_0
118 %14 = OpLoad %uint %13
119 OpStore %13 %14 NonPrivatePointer|MakePointerAvailable %device
120 OpReturn
121 OpFunctionEnd
122 */
123 static const uint32_t words[] = {
124 0x07230203, 0x00010500, 0x00070000, 0x00000010, 0x00000000, 0x00020011,
125 0x00000001, 0x00020011, 0x000014e1, 0x00020011, 0x000014e2, 0x0006000b,
126 0x00000001, 0x4c534c47, 0x6474732e, 0x3035342e, 0x00000000, 0x0003000e,
127 0x00000000, 0x00000003, 0x0006000f, 0x00000005, 0x00000002, 0x6e69616d,
128 0x00000000, 0x00000003, 0x00060010, 0x00000002, 0x00000011, 0x00000001,
129 0x00000001, 0x00000001, 0x00050048, 0x00000004, 0x00000000, 0x00000023,
130 0x00000000, 0x00030047, 0x00000004, 0x00000002, 0x00040047, 0x00000003,
131 0x00000022, 0x00000000, 0x00040047, 0x00000003, 0x00000021, 0x00000000,
132 0x00020013, 0x00000005, 0x00030021, 0x00000006, 0x00000005, 0x00040015,
133 0x00000007, 0x00000020, 0x00000000, 0x0003001e, 0x00000004, 0x00000007,
134 0x00040020, 0x00000008, 0x0000000c, 0x00000004, 0x0004003b, 0x00000008,
135 0x00000003, 0x0000000c, 0x00040015, 0x00000009, 0x00000020, 0x00000001,
136 0x0004002b, 0x00000009, 0x0000000a, 0x00000000, 0x00040020, 0x0000000b,
137 0x0000000c, 0x00000007, 0x0004002b, 0x00000009, 0x0000000c, 0x00000001,
138 0x00050036, 0x00000005, 0x00000002, 0x00000000, 0x00000006, 0x000200f8,
139 0x0000000d, 0x00050041, 0x0000000b, 0x0000000e, 0x00000003, 0x0000000a,
140 0x0004003d, 0x00000007, 0x0000000f, 0x0000000e, 0x0005003e, 0x0000000e,
141 0x0000000f, 0x00000028, 0x0000000c, 0x000100fd, 0x00010038,
142 };
143
144 get_nir(sizeof(words) / sizeof(words[0]), words);
145
146 nir_intrinsic_instr *intrinsic = find_intrinsic(nir_intrinsic_barrier, 0);
147 ASSERT_NE(intrinsic, nullptr);
148
149 EXPECT_EQ(nir_intrinsic_memory_semantics(intrinsic), NIR_MEMORY_MAKE_AVAILABLE | NIR_MEMORY_RELEASE);
150 EXPECT_NE(nir_intrinsic_memory_modes(intrinsic) & nir_var_mem_ssbo, 0);
151 EXPECT_EQ(nir_intrinsic_memory_scope(intrinsic), SCOPE_DEVICE);
152 EXPECT_EQ(nir_intrinsic_execution_scope(intrinsic), SCOPE_NONE);
153 }
154
TEST_F(AvailabilityVisibility,opcopymemory_visavail_both_combined)155 TEST_F(AvailabilityVisibility, opcopymemory_visavail_both_combined)
156 {
157 /*
158 OpCapability Shader
159 OpCapability VulkanMemoryModel
160 OpCapability VulkanMemoryModelDeviceScope
161 %1 = OpExtInstImport "GLSL.std.450"
162 OpMemoryModel Logical Vulkan
163 OpEntryPoint GLCompute %4 "main" %9
164 OpExecutionMode %4 LocalSize 1 1 1
165 OpMemberDecorate %_struct_7 0 Offset 0
166 OpDecorate %_struct_7 Block
167 OpDecorate %9 DescriptorSet 0
168 OpDecorate %9 Binding 0
169 %void = OpTypeVoid
170 %3 = OpTypeFunction %void
171 %uint = OpTypeInt 32 0
172 %_struct_7 = OpTypeStruct %uint
173 %_ptr_StorageBuffer__struct_7 = OpTypePointer StorageBuffer %_struct_7
174 %9 = OpVariable %_ptr_StorageBuffer__struct_7 StorageBuffer
175 %int = OpTypeInt 32 1
176 %int_0 = OpConstant %int 0
177 %_ptr_StorageBuffer_uint = OpTypePointer StorageBuffer %uint
178 %device = OpConstant %int 1
179 %workgroup = OpConstant %int 2
180 %4 = OpFunction %void None %3
181 %5 = OpLabel
182 %13 = OpAccessChain %_ptr_StorageBuffer_uint %9 %int_0
183 OpCopyMemory %13 %13 NonPrivatePointer|MakePointerAvailable|MakePointerVisible %device %workgroup
184 OpReturn
185 OpFunctionEnd
186 */
187 static const uint32_t words[] = {
188 0x07230203, 0x00010500, 0x00070000, 0x00000010, 0x00000000, 0x00020011,
189 0x00000001, 0x00020011, 0x000014e1, 0x00020011, 0x000014e2, 0x0006000b,
190 0x00000001, 0x4c534c47, 0x6474732e, 0x3035342e, 0x00000000, 0x0003000e,
191 0x00000000, 0x00000003, 0x0006000f, 0x00000005, 0x00000002, 0x6e69616d,
192 0x00000000, 0x00000003, 0x00060010, 0x00000002, 0x00000011, 0x00000001,
193 0x00000001, 0x00000001, 0x00050048, 0x00000004, 0x00000000, 0x00000023,
194 0x00000000, 0x00030047, 0x00000004, 0x00000002, 0x00040047, 0x00000003,
195 0x00000022, 0x00000000, 0x00040047, 0x00000003, 0x00000021, 0x00000000,
196 0x00020013, 0x00000005, 0x00030021, 0x00000006, 0x00000005, 0x00040015,
197 0x00000007, 0x00000020, 0x00000000, 0x0003001e, 0x00000004, 0x00000007,
198 0x00040020, 0x00000008, 0x0000000c, 0x00000004, 0x0004003b, 0x00000008,
199 0x00000003, 0x0000000c, 0x00040015, 0x00000009, 0x00000020, 0x00000001,
200 0x0004002b, 0x00000009, 0x0000000a, 0x00000000, 0x00040020, 0x0000000b,
201 0x0000000c, 0x00000007, 0x0004002b, 0x00000009, 0x0000000c, 0x00000001,
202 0x0004002b, 0x00000009, 0x0000000d, 0x00000002, 0x00050036, 0x00000005,
203 0x00000002, 0x00000000, 0x00000006, 0x000200f8, 0x0000000e, 0x00050041,
204 0x0000000b, 0x0000000f, 0x00000003, 0x0000000a, 0x0006003f, 0x0000000f,
205 0x0000000f, 0x00000038, 0x0000000c, 0x0000000d, 0x000100fd, 0x00010038,
206 };
207
208 get_nir(sizeof(words) / sizeof(words[0]), words);
209
210 nir_intrinsic_instr *first = find_intrinsic(nir_intrinsic_barrier, 0);
211 nir_intrinsic_instr *second = find_intrinsic(nir_intrinsic_barrier, 1);
212 ASSERT_NE(first, nullptr);
213 ASSERT_NE(second, nullptr);
214
215 EXPECT_EQ(nir_intrinsic_memory_semantics(first), NIR_MEMORY_MAKE_VISIBLE | NIR_MEMORY_ACQUIRE);
216 EXPECT_NE(nir_intrinsic_memory_modes(first) & nir_var_mem_ssbo, 0);
217 EXPECT_EQ(nir_intrinsic_memory_scope(first), SCOPE_WORKGROUP);
218 EXPECT_EQ(nir_intrinsic_execution_scope(first), SCOPE_NONE);
219
220 EXPECT_EQ(nir_intrinsic_memory_semantics(second), NIR_MEMORY_MAKE_AVAILABLE | NIR_MEMORY_RELEASE);
221 EXPECT_NE(nir_intrinsic_memory_modes(second) & nir_var_mem_ssbo, 0);
222 EXPECT_EQ(nir_intrinsic_memory_scope(second), SCOPE_DEVICE);
223 EXPECT_EQ(nir_intrinsic_execution_scope(first), SCOPE_NONE);
224 }
225
TEST_F(AvailabilityVisibility,opcopymemory_visavail_both_separate)226 TEST_F(AvailabilityVisibility, opcopymemory_visavail_both_separate)
227 {
228 /*
229 OpCapability Shader
230 OpCapability VulkanMemoryModel
231 OpCapability VulkanMemoryModelDeviceScope
232 %1 = OpExtInstImport "GLSL.std.450"
233 OpMemoryModel Logical Vulkan
234 OpEntryPoint GLCompute %4 "main" %9
235 OpExecutionMode %4 LocalSize 1 1 1
236 OpMemberDecorate %_struct_7 0 Offset 0
237 OpDecorate %_struct_7 Block
238 OpDecorate %9 DescriptorSet 0
239 OpDecorate %9 Binding 0
240 %void = OpTypeVoid
241 %3 = OpTypeFunction %void
242 %uint = OpTypeInt 32 0
243 %_struct_7 = OpTypeStruct %uint
244 %_ptr_StorageBuffer__struct_7 = OpTypePointer StorageBuffer %_struct_7
245 %9 = OpVariable %_ptr_StorageBuffer__struct_7 StorageBuffer
246 %int = OpTypeInt 32 1
247 %int_0 = OpConstant %int 0
248 %_ptr_StorageBuffer_uint = OpTypePointer StorageBuffer %uint
249 %device = OpConstant %int 1
250 %workgroup = OpConstant %int 2
251 %4 = OpFunction %void None %3
252 %5 = OpLabel
253 %13 = OpAccessChain %_ptr_StorageBuffer_uint %9 %int_0
254 OpCopyMemory %13 %13 NonPrivatePointer|MakePointerAvailable %device NonPrivatePointer|MakePointerVisible %workgroup
255 OpReturn
256 OpFunctionEnd
257 */
258 static const uint32_t words[] = {
259 0x07230203, 0x00010500, 0x00070000, 0x00000010, 0x00000000, 0x00020011,
260 0x00000001, 0x00020011, 0x000014e1, 0x00020011, 0x000014e2, 0x0006000b,
261 0x00000001, 0x4c534c47, 0x6474732e, 0x3035342e, 0x00000000, 0x0003000e,
262 0x00000000, 0x00000003, 0x0006000f, 0x00000005, 0x00000002, 0x6e69616d,
263 0x00000000, 0x00000003, 0x00060010, 0x00000002, 0x00000011, 0x00000001,
264 0x00000001, 0x00000001, 0x00050048, 0x00000004, 0x00000000, 0x00000023,
265 0x00000000, 0x00030047, 0x00000004, 0x00000002, 0x00040047, 0x00000003,
266 0x00000022, 0x00000000, 0x00040047, 0x00000003, 0x00000021, 0x00000000,
267 0x00020013, 0x00000005, 0x00030021, 0x00000006, 0x00000005, 0x00040015,
268 0x00000007, 0x00000020, 0x00000000, 0x0003001e, 0x00000004, 0x00000007,
269 0x00040020, 0x00000008, 0x0000000c, 0x00000004, 0x0004003b, 0x00000008,
270 0x00000003, 0x0000000c, 0x00040015, 0x00000009, 0x00000020, 0x00000001,
271 0x0004002b, 0x00000009, 0x0000000a, 0x00000000, 0x00040020, 0x0000000b,
272 0x0000000c, 0x00000007, 0x0004002b, 0x00000009, 0x0000000c, 0x00000001,
273 0x0004002b, 0x00000009, 0x0000000d, 0x00000002, 0x00050036, 0x00000005,
274 0x00000002, 0x00000000, 0x00000006, 0x000200f8, 0x0000000e, 0x00050041,
275 0x0000000b, 0x0000000f, 0x00000003, 0x0000000a, 0x0007003f, 0x0000000f,
276 0x0000000f, 0x00000028, 0x0000000c, 0x00000030, 0x0000000d, 0x000100fd,
277 0x00010038,
278 };
279
280 get_nir(sizeof(words) / sizeof(words[0]), words);
281
282 nir_intrinsic_instr *first = find_intrinsic(nir_intrinsic_barrier, 0);
283 nir_intrinsic_instr *second = find_intrinsic(nir_intrinsic_barrier, 1);
284 ASSERT_NE(first, nullptr);
285 ASSERT_NE(second, nullptr);
286
287 EXPECT_EQ(nir_intrinsic_memory_semantics(first), NIR_MEMORY_MAKE_VISIBLE | NIR_MEMORY_ACQUIRE);
288 EXPECT_NE(nir_intrinsic_memory_modes(first) & nir_var_mem_ssbo, 0);
289 EXPECT_EQ(nir_intrinsic_memory_scope(first), SCOPE_WORKGROUP);
290 EXPECT_EQ(nir_intrinsic_execution_scope(first), SCOPE_NONE);
291
292 EXPECT_EQ(nir_intrinsic_memory_semantics(second), NIR_MEMORY_MAKE_AVAILABLE | NIR_MEMORY_RELEASE);
293 EXPECT_NE(nir_intrinsic_memory_modes(second) & nir_var_mem_ssbo, 0);
294 EXPECT_EQ(nir_intrinsic_memory_scope(second), SCOPE_DEVICE);
295 EXPECT_EQ(nir_intrinsic_execution_scope(second), SCOPE_NONE);
296 }
297
TEST_F(AvailabilityVisibility,opcopymemory_avail)298 TEST_F(AvailabilityVisibility, opcopymemory_avail)
299 {
300 /*
301 OpCapability Shader
302 OpCapability VulkanMemoryModel
303 OpCapability VulkanMemoryModelDeviceScope
304 %1 = OpExtInstImport "GLSL.std.450"
305 OpMemoryModel Logical Vulkan
306 OpEntryPoint GLCompute %4 "main" %9
307 OpExecutionMode %4 LocalSize 1 1 1
308 OpMemberDecorate %_struct_7 0 Offset 0
309 OpDecorate %_struct_7 Block
310 OpDecorate %9 DescriptorSet 0
311 OpDecorate %9 Binding 0
312 %void = OpTypeVoid
313 %3 = OpTypeFunction %void
314 %uint = OpTypeInt 32 0
315 %_struct_7 = OpTypeStruct %uint
316 %_ptr_StorageBuffer__struct_7 = OpTypePointer StorageBuffer %_struct_7
317 %9 = OpVariable %_ptr_StorageBuffer__struct_7 StorageBuffer
318 %int = OpTypeInt 32 1
319 %int_0 = OpConstant %int 0
320 %_ptr_StorageBuffer_uint = OpTypePointer StorageBuffer %uint
321 %device = OpConstant %int 1
322 %4 = OpFunction %void None %3
323 %5 = OpLabel
324 %13 = OpAccessChain %_ptr_StorageBuffer_uint %9 %int_0
325 OpCopyMemory %13 %13 NonPrivatePointer|MakePointerAvailable %device
326 OpReturn
327 OpFunctionEnd
328 */
329 static const uint32_t words[] = {
330 0x07230203, 0x00010500, 0x00070000, 0x0000000f, 0x00000000, 0x00020011,
331 0x00000001, 0x00020011, 0x000014e1, 0x00020011, 0x000014e2, 0x0006000b,
332 0x00000001, 0x4c534c47, 0x6474732e, 0x3035342e, 0x00000000, 0x0003000e,
333 0x00000000, 0x00000003, 0x0006000f, 0x00000005, 0x00000002, 0x6e69616d,
334 0x00000000, 0x00000003, 0x00060010, 0x00000002, 0x00000011, 0x00000001,
335 0x00000001, 0x00000001, 0x00050048, 0x00000004, 0x00000000, 0x00000023,
336 0x00000000, 0x00030047, 0x00000004, 0x00000002, 0x00040047, 0x00000003,
337 0x00000022, 0x00000000, 0x00040047, 0x00000003, 0x00000021, 0x00000000,
338 0x00020013, 0x00000005, 0x00030021, 0x00000006, 0x00000005, 0x00040015,
339 0x00000007, 0x00000020, 0x00000000, 0x0003001e, 0x00000004, 0x00000007,
340 0x00040020, 0x00000008, 0x0000000c, 0x00000004, 0x0004003b, 0x00000008,
341 0x00000003, 0x0000000c, 0x00040015, 0x00000009, 0x00000020, 0x00000001,
342 0x0004002b, 0x00000009, 0x0000000a, 0x00000000, 0x00040020, 0x0000000b,
343 0x0000000c, 0x00000007, 0x0004002b, 0x00000009, 0x0000000c, 0x00000001,
344 0x00050036, 0x00000005, 0x00000002, 0x00000000, 0x00000006, 0x000200f8,
345 0x0000000d, 0x00050041, 0x0000000b, 0x0000000e, 0x00000003, 0x0000000a,
346 0x0005003f, 0x0000000e, 0x0000000e, 0x00000028, 0x0000000c, 0x000100fd,
347 0x00010038,
348 };
349
350 get_nir(sizeof(words) / sizeof(words[0]), words);
351
352 nir_intrinsic_instr *intrinsic = find_intrinsic(nir_intrinsic_barrier, 0);
353 ASSERT_NE(intrinsic, nullptr);
354
355 EXPECT_EQ(nir_intrinsic_memory_semantics(intrinsic), NIR_MEMORY_MAKE_AVAILABLE | NIR_MEMORY_RELEASE);
356 EXPECT_NE(nir_intrinsic_memory_modes(intrinsic) & nir_var_mem_ssbo, 0);
357 EXPECT_EQ(nir_intrinsic_memory_scope(intrinsic), SCOPE_DEVICE);
358 EXPECT_EQ(nir_intrinsic_execution_scope(intrinsic), SCOPE_NONE);
359 }
360
TEST_F(AvailabilityVisibility,opcopymemory_vis)361 TEST_F(AvailabilityVisibility, opcopymemory_vis)
362 {
363 /*
364 OpCapability Shader
365 OpCapability VulkanMemoryModel
366 OpCapability VulkanMemoryModelDeviceScope
367 %1 = OpExtInstImport "GLSL.std.450"
368 OpMemoryModel Logical Vulkan
369 OpEntryPoint GLCompute %4 "main" %9
370 OpExecutionMode %4 LocalSize 1 1 1
371 OpMemberDecorate %_struct_7 0 Offset 0
372 OpDecorate %_struct_7 Block
373 OpDecorate %9 DescriptorSet 0
374 OpDecorate %9 Binding 0
375 %void = OpTypeVoid
376 %3 = OpTypeFunction %void
377 %uint = OpTypeInt 32 0
378 %_struct_7 = OpTypeStruct %uint
379 %_ptr_StorageBuffer__struct_7 = OpTypePointer StorageBuffer %_struct_7
380 %9 = OpVariable %_ptr_StorageBuffer__struct_7 StorageBuffer
381 %int = OpTypeInt 32 1
382 %int_0 = OpConstant %int 0
383 %_ptr_StorageBuffer_uint = OpTypePointer StorageBuffer %uint
384 %workgroup = OpConstant %int 2
385 %4 = OpFunction %void None %3
386 %5 = OpLabel
387 %13 = OpAccessChain %_ptr_StorageBuffer_uint %9 %int_0
388 OpCopyMemory %13 %13 NonPrivatePointer|MakePointerVisible %workgroup
389 OpReturn
390 OpFunctionEnd
391 */
392 static const uint32_t words[] = {
393 0x07230203, 0x00010500, 0x00070000, 0x0000000f, 0x00000000, 0x00020011,
394 0x00000001, 0x00020011, 0x000014e1, 0x00020011, 0x000014e2, 0x0006000b,
395 0x00000001, 0x4c534c47, 0x6474732e, 0x3035342e, 0x00000000, 0x0003000e,
396 0x00000000, 0x00000003, 0x0006000f, 0x00000005, 0x00000002, 0x6e69616d,
397 0x00000000, 0x00000003, 0x00060010, 0x00000002, 0x00000011, 0x00000001,
398 0x00000001, 0x00000001, 0x00050048, 0x00000004, 0x00000000, 0x00000023,
399 0x00000000, 0x00030047, 0x00000004, 0x00000002, 0x00040047, 0x00000003,
400 0x00000022, 0x00000000, 0x00040047, 0x00000003, 0x00000021, 0x00000000,
401 0x00020013, 0x00000005, 0x00030021, 0x00000006, 0x00000005, 0x00040015,
402 0x00000007, 0x00000020, 0x00000000, 0x0003001e, 0x00000004, 0x00000007,
403 0x00040020, 0x00000008, 0x0000000c, 0x00000004, 0x0004003b, 0x00000008,
404 0x00000003, 0x0000000c, 0x00040015, 0x00000009, 0x00000020, 0x00000001,
405 0x0004002b, 0x00000009, 0x0000000a, 0x00000000, 0x00040020, 0x0000000b,
406 0x0000000c, 0x00000007, 0x0004002b, 0x00000009, 0x0000000c, 0x00000002,
407 0x00050036, 0x00000005, 0x00000002, 0x00000000, 0x00000006, 0x000200f8,
408 0x0000000d, 0x00050041, 0x0000000b, 0x0000000e, 0x00000003, 0x0000000a,
409 0x0005003f, 0x0000000e, 0x0000000e, 0x00000030, 0x0000000c, 0x000100fd,
410 0x00010038,
411 };
412
413 get_nir(sizeof(words) / sizeof(words[0]), words);
414
415 nir_intrinsic_instr *intrinsic = find_intrinsic(nir_intrinsic_barrier, 0);
416 ASSERT_NE(intrinsic, nullptr);
417
418 EXPECT_EQ(nir_intrinsic_memory_semantics(intrinsic), NIR_MEMORY_MAKE_VISIBLE | NIR_MEMORY_ACQUIRE);
419 EXPECT_NE(nir_intrinsic_memory_modes(intrinsic) & nir_var_mem_ssbo, 0);
420 EXPECT_EQ(nir_intrinsic_memory_scope(intrinsic), SCOPE_WORKGROUP);
421 EXPECT_EQ(nir_intrinsic_execution_scope(intrinsic), SCOPE_NONE);
422 }
423