Debian Codegraph @

test/val/val_extension_spv_ext_descriptor_heap.cpp

raw
1 // Copyright 2025 The Khronos Group Inc.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 // Tests for SPV_EXT_descriptor_heap
16
17 #include <string>
18
19 #include "gmock/gmock.h"
20 #include "test/val/val_fixtures.h"
21
22 namespace spvtools {
23 namespace val {
24 namespace {
25
26 using ::testing::HasSubstr;
27
28 using ValidateSpvEXTDescriptorHeap = spvtest::ValidateBase<bool>;
29
30 TEST_F(ValidateSpvEXTDescriptorHeap, Valid) {
31 const std::string str = R"(
32 OpCapability Shader
33 OpCapability UntypedPointersKHR
34 OpCapability DescriptorHeapEXT
35 OpCapability ShaderNonUniform
36 OpCapability UniformBufferArrayNonUniformIndexing
37 OpCapability StorageBufferArrayNonUniformIndexing
38 OpExtension "SPV_EXT_descriptor_heap"
39 OpExtension "SPV_KHR_untyped_pointers"
40 %1 = OpExtInstImport "GLSL.std.450"
41 OpMemoryModel Logical GLSL450
42 OpEntryPoint Fragment %main "main" %resource_heap %sampler_heap %fragColor %uvs %index
43 OpExecutionMode %main OriginUpperLeft
44 OpSource GLSL 460
45 OpSourceExtension "GL_EXT_descriptor_heap"
46 OpSourceExtension "GL_EXT_nonuniform_qualifier"
47 OpName %main "main"
48 OpName %fragColor "fragColor"
49 OpName %resource_heap "resource_heap"
50 OpName %sampler_heap "sampler_heap"
51 OpName %uvs "uvs"
52 OpName %index "index"
53 OpName %UniformBuffer "UniformBuffer"
54 OpMemberName %UniformBuffer 0 "colorOffset"
55 OpName %StorageBufferA "StorageBufferA"
56 OpMemberName %StorageBufferA 0 "a"
57 OpName %StorageBufferB "StorageBufferB"
58 OpMemberName %StorageBufferB 0 "b"
59 OpDecorate %fragColor Location 0
60 OpDecorate %resource_heap BuiltIn ResourceHeapEXT
61 OpDecorateId %_runtimearr_14 ArrayStrideIdEXT %17
62 OpDecorate %sampler_heap BuiltIn SamplerHeapEXT
63 OpDecorateId %_runtimearr_22 ArrayStrideIdEXT %uint_2
64 OpDecorate %uvs Location 0
65 OpDecorate %index Flat
66 OpDecorate %index Location 1
67 OpDecorate %38 NonUniform
68 OpDecorate %UniformBuffer Block
69 OpMemberDecorate %UniformBuffer 0 Offset 0
70 OpDecorateId %_runtimearr_41 ArrayStrideIdEXT %42
71 OpDecorate %44 NonUniform
72 OpDecorate %46 NonUniform
73 OpDecorate %48 NonUniform
74 OpDecorate %StorageBufferA Block
75 OpMemberDecorate %StorageBufferA 0 Offset 0
76 OpDecorateId %_runtimearr_58 ArrayStrideIdEXT %59
77 OpDecorate %64 NonUniform
78 OpDecorate %StorageBufferB Block
79 OpMemberDecorate %StorageBufferB 0 Offset 0
80 OpDecorateId %_runtimearr_58_0 ArrayStrideIdEXT %69
81 OpDecorate %71 NonUniform
82 OpDecorate %73 NonUniform
83 OpDecorate %77 NonUniform
84 OpDecorate %44 NonReadable
85 %void = OpTypeVoid
86 %3 = OpTypeFunction %void
87 %float = OpTypeFloat 32
88 %v4float = OpTypeVector %float 4
89 %_ptr_Output_v4float = OpTypePointer Output %v4float
90 %fragColor = OpVariable %_ptr_Output_v4float Output
91 %_ptr_UniformConstant = OpTypeUntypedPointerKHR UniformConstant
92 %resource_heap = OpUntypedVariableKHR %_ptr_UniformConstant UniformConstant
93 %int = OpTypeInt 32 1
94 %int_27 = OpConstant %int 27
95 %14 = OpTypeImage %float 2D 0 0 0 1 Unknown
96 %_ptr_Uniform = OpTypeUntypedPointerKHR Uniform
97 %17 = OpConstantSizeOfEXT %int %14
98 %_runtimearr_14 = OpTypeRuntimeArray %14
99 %sampler_heap = OpUntypedVariableKHR %_ptr_UniformConstant UniformConstant
100 %int_0 = OpConstant %int 0
101 %22 = OpTypeSampler
102 %uint = OpTypeInt 32 0
103 %uint_2 = OpConstant %uint 2
104 %_runtimearr_22 = OpTypeRuntimeArray %22
105 %28 = OpTypeSampledImage %14
106 %v2float = OpTypeVector %float 2
107 %_ptr_Input_v2float = OpTypePointer Input %v2float
108 %uvs = OpVariable %_ptr_Input_v2float Input
109 %_ptr_Input_uint = OpTypePointer Input %uint
110 %index = OpVariable %_ptr_Input_uint Input
111 %UniformBuffer = OpTypeStruct %v4float
112 %41 = OpTypeBufferEXT Uniform
113 %42 = OpConstantSizeOfEXT %int %41
114 %_runtimearr_41 = OpTypeRuntimeArray %41
115 %int_1 = OpConstant %int 1
116 %StorageBufferA = OpTypeStruct %v4float
117 %float_1 = OpConstant %float 1
118 %float_2 = OpConstant %float 2
119 %float_3 = OpConstant %float 3
120 %float_4 = OpConstant %float 4
121 %55 = OpConstantComposite %v4float %float_1 %float_2 %float_3 %float_4
122 %_ptr_StorageBuffer = OpTypeUntypedPointerKHR StorageBuffer
123 %58 = OpTypeBufferEXT StorageBuffer
124 %59 = OpConstantSizeOfEXT %int %58
125 %_runtimearr_58 = OpTypeRuntimeArray %58
126 %v3float = OpTypeVector %float 3
127 %StorageBufferB = OpTypeStruct %v3float
128 %uint_0 = OpConstant %uint 0
129 %69 = OpConstantSizeOfEXT %int %58
130 %_runtimearr_58_0 = OpTypeRuntimeArray %58
131 %_ptr_Output_float = OpTypePointer Output %float
132 %main = OpFunction %void None %3
133 %5 = OpLabel
134 %16 = OpUntypedAccessChainKHR %_ptr_UniformConstant %_runtimearr_14 %resource_heap %int_27
135 %19 = OpLoad %14 %16
136 %23 = OpUntypedAccessChainKHR %_ptr_UniformConstant %_runtimearr_22 %sampler_heap %int_0
137 %27 = OpLoad %22 %23
138 %29 = OpSampledImage %28 %19 %27
139 %33 = OpLoad %v2float %uvs
140 %34 = OpImageSampleImplicitLod %v4float %29 %33
141 OpStore %fragColor %34
142 %37 = OpLoad %uint %index
143 %38 = OpCopyObject %uint %37
144 %40 = OpUntypedAccessChainKHR %_ptr_UniformConstant %_runtimearr_41 %resource_heap %38
145 %44 = OpBufferPointerEXT %_ptr_Uniform %40
146 %45 = OpUntypedAccessChainKHR %_ptr_Uniform %UniformBuffer %44 %int_0
147 %46 = OpLoad %v4float %45
148 %47 = OpLoad %v4float %fragColor
149 %48 = OpFAdd %v4float %47 %46
150 OpStore %fragColor %48
151 %57 = OpUntypedAccessChainKHR %_ptr_UniformConstant %_runtimearr_58 %resource_heap %int_1
152 %61 = OpBufferPointerEXT %_ptr_StorageBuffer %57
153 %62 = OpUntypedAccessChainKHR %_ptr_StorageBuffer %StorageBufferA %61 %int_0
154 OpStore %62 %55
155 %63 = OpLoad %uint %index
156 %64 = OpCopyObject %uint %63
157 %68 = OpUntypedAccessChainKHR %_ptr_UniformConstant %_runtimearr_58_0 %resource_heap %64
158 %71 = OpBufferPointerEXT %_ptr_StorageBuffer %68
159 %72 = OpUntypedAccessChainKHR %_ptr_StorageBuffer %StorageBufferB %71 %int_0 %uint_0
160 %73 = OpLoad %float %72
161 %75 = OpAccessChain %_ptr_Output_float %fragColor %uint_0
162 %76 = OpLoad %float %75
163 %77 = OpFAdd %float %76 %73
164 %78 = OpAccessChain %_ptr_Output_float %fragColor %uint_0
165 OpStore %78 %77
166 OpReturn
167 OpFunctionEnd
168 )";
169 CompileSuccessfully(str.c_str(), SPV_ENV_VULKAN_1_3);
170 EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_3));
171 }
172
173 TEST_F(ValidateSpvEXTDescriptorHeap, OffsetId64BitIndexingGood) {
174 const std::string str = R"(
175 OpCapability Shader
176 OpCapability Shader64BitIndexingEXT
177 OpCapability DescriptorHeapEXT
178 OpCapability Int64
179 OpExtension "SPV_EXT_descriptor_heap"
180 OpExtension "SPV_EXT_shader_64bit_indexing"
181 %1 = OpExtInstImport "GLSL.std.450"
182 OpMemoryModel Logical GLSL450
183 OpEntryPoint GLCompute %2 "main" %3
184 OpExecutionMode %2 LocalSize 1 1 1
185 OpSource GLSL 450
186 OpMemberDecorate %4 0 Offset 0
187 OpMemberDecorate %4 1 Offset 4
188 OpMemberDecorate %4 2 Offset 8
189 OpMemberDecorate %4 3 Offset 12
190 OpDecorate %4 Block
191 OpDecorate %3 Binding 0
192 OpDecorate %3 DescriptorSet 0
193 %5 = OpTypeVoid
194 %6 = OpTypeFunction %5
195 %7 = OpTypeInt 32 0
196 %8 = OpTypeInt 64 0
197 %4 = OpTypeStruct %7 %7 %7 %7
198 %9 = OpTypePointer StorageBuffer %4
199 %3 = OpVariable %9 StorageBuffer
200 %10 = OpTypeInt 32 1
201 %11 = OpConstant %10 0
202 %12 = OpConstant %10 1
203 %13 = OpConstant %10 2
204 %14 = OpConstant %10 3
205 %15 = OpTypePointer StorageBuffer %7
206 %16 = OpTypeBufferEXT StorageBuffer
207 %17 = OpTypeBufferEXT Uniform
208 %18 = OpTypeImage %7 2D 0 0 0 1 Unknown
209 %19 = OpTypeSampler
210 %20 = OpConstantSizeOfEXT %8 %16
211 %21 = OpConstantSizeOfEXT %8 %17
212 %22 = OpConstantSizeOfEXT %8 %18
213 %23 = OpConstantSizeOfEXT %8 %19
214 %2 = OpFunction %5 None %6
215 %24 = OpLabel
216 %25 = OpAccessChain %15 %3 %11
217 %26 = OpAccessChain %15 %3 %12
218 %27 = OpAccessChain %15 %3 %13
219 %28 = OpAccessChain %15 %3 %14
220 %29 = OpUConvert %7 %20
221 %30 = OpUConvert %7 %21
222 %31 = OpUConvert %7 %22
223 %32 = OpUConvert %7 %23
224 OpStore %25 %29
225 OpStore %26 %30
226 OpStore %27 %31
227 OpStore %28 %32
228 OpReturn
229 OpFunctionEnd
230 )";
231 CompileSuccessfully(str.c_str(), SPV_ENV_VULKAN_1_4);
232 EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_4));
233 }
234
235 TEST_F(ValidateSpvEXTDescriptorHeap, AtomicImageFuncs) {
236 const std::string str = R"(
237 OpCapability Shader
238 OpCapability Image1D
239 OpCapability UntypedPointersKHR
240 OpCapability DescriptorHeapEXT
241 OpExtension "SPV_EXT_descriptor_heap"
242 OpExtension "SPV_KHR_untyped_pointers"
243 %1 = OpExtInstImport "GLSL.std.450"
244 OpMemoryModel Logical GLSL450
245 OpEntryPoint GLCompute %main "main" %resource_heap
246 OpExecutionMode %main LocalSize 1 1 1
247 OpSource GLSL 460
248 OpSourceExtension "GL_EXT_descriptor_heap"
249 OpName %main "main"
250 OpName %resource_heap "resource_heap"
251 OpDecorate %resource_heap BuiltIn ResourceHeapEXT
252 OpDecorateId %_runtimearr_10 ArrayStrideIdEXT %13
253 %void = OpTypeVoid
254 %3 = OpTypeFunction %void
255 %_ptr_UniformConstant = OpTypeUntypedPointerKHR UniformConstant
256 %resource_heap = OpUntypedVariableKHR %_ptr_UniformConstant UniformConstant
257 %int = OpTypeInt 32 1
258 %int_1 = OpConstant %int 1
259 %10 = OpTypeImage %int 1D 0 0 0 2 R32i
260 %13 = OpConstantSizeOfEXT %int %10
261 %_runtimearr_10 = OpTypeRuntimeArray %10
262 %uint = OpTypeInt 32 0
263 %uint_0 = OpConstant %uint 0
264 %_ptr_Image_int = OpTypePointer Image %int
265 %_ptr_Image = OpTypeUntypedPointerKHR Image
266 %uint_1 = OpConstant %uint 1
267 %main = OpFunction %void None %3
268 %5 = OpLabel
269 %12 = OpUntypedAccessChainKHR %_ptr_UniformConstant %_runtimearr_10 %resource_heap %int_1
270 %19 = OpUntypedImageTexelPointerEXT %_ptr_Image %10 %12 %int_1 %uint_0
271 %21 = OpAtomicIAdd %int %19 %uint_1 %uint_0 %int_1
272 OpReturn
273 OpFunctionEnd
274 )";
275 CompileSuccessfully(str.c_str(), SPV_ENV_VULKAN_1_3);
276 EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_3));
277 }
278
279 TEST_F(ValidateSpvEXTDescriptorHeap, ValidMemberDecorateIdExt) {
280 const std::string str = R"(
281 OpCapability Shader
282 OpCapability UntypedPointersKHR
283 OpCapability DescriptorHeapEXT
284 OpCapability BindlessTextureNV
285 OpExtension "SPV_EXT_descriptor_heap"
286 OpExtension "SPV_KHR_untyped_pointers"
287 OpExtension "SPV_NV_bindless_texture"
288 %1 = OpExtInstImport "GLSL.std.450"
289 OpMemoryModel Logical GLSL450
290 OpSamplerImageAddressingModeNV 64
291 OpEntryPoint Fragment %main "main" %resource_heap %fragColor
292 OpExecutionMode %main OriginUpperLeft
293 OpSource GLSL 460
294 OpSourceExtension "GL_EXT_descriptor_heap"
295 OpSourceExtension "GL_EXT_nonuniform_qualifier"
296 OpName %main "main"
297 OpName %fragColor "fragColor"
298 OpName %resource_heap "resource_heap"
299 OpName %U "U"
300 OpMemberName %U 0 "uv"
301 OpMemberName %U 1 "k"
302 OpMemberName %U 2 "g"
303 OpDecorate %fragColor Location 0
304 OpDecorate %resource_heap BuiltIn ResourceHeapEXT
305 OpDecorate %U Block
306 OpMemberDecorateIdEXT %U 0 OffsetIdEXT %specA
307 OpMemberDecorateIdEXT %U 1 OffsetIdEXT %specB
308 OpMemberDecorateIdEXT %U 2 OffsetIdEXT %specC
309 OpDecorateId %_runtimearr_20 ArrayStrideIdEXT %uint_2
310 %void = OpTypeVoid
311 %3 = OpTypeFunction %void
312 %float = OpTypeFloat 32
313 %v2float = OpTypeVector %float 2
314 %_ptr_Output_v2float = OpTypePointer Output %v2float
315 %fragColor = OpVariable %_ptr_Output_v2float Output
316 %_ptr_UniformConstant = OpTypeUntypedPointerKHR UniformConstant
317 %resource_heap = OpUntypedVariableKHR %_ptr_UniformConstant UniformConstant
318 %int = OpTypeInt 32 1
319 %int_3 = OpConstant %int 3
320 %uint = OpTypeInt 32 0
321 %v3uint = OpTypeVector %uint 3
322 %samplerTy = OpTypeSampler
323 %_runtimearr_sampler = OpTypeRuntimeArray %samplerTy
324 %specA = OpSpecConstant %int 0
325 %specB = OpSpecConstant %int 4
326 %specC = OpSpecConstant %int 8
327 %U = OpTypeStruct %samplerTy %samplerTy %_runtimearr_sampler
328 %int_0 = OpConstant %int 0
329 %_ptr_Uniform = OpTypeUntypedPointerKHR Uniform
330 %20 = OpTypeBufferEXT Uniform
331 %uint_2 = OpConstant %uint 2
332 %_runtimearr_20 = OpTypeRuntimeArray %20
333 %main = OpFunction %void None %3
334 %5 = OpLabel
335 %19 = OpUntypedAccessChainKHR %_ptr_UniformConstant %_runtimearr_20 %resource_heap %int_3
336 %23 = OpBufferPointerEXT %_ptr_Uniform %19
337 %24 = OpUntypedAccessChainKHR %_ptr_Uniform %U %23 %int_0
338 OpReturn
339 OpFunctionEnd
340 )";
341 CompileSuccessfully(str.c_str(), SPV_ENV_VULKAN_1_4);
342 EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_4));
343 }
344
345 TEST_F(ValidateSpvEXTDescriptorHeap, ValidMemberDecorateIdExt2) {
346 const std::string str = R"(
347 OpCapability Shader
348 OpCapability UntypedPointersKHR
349 OpCapability DescriptorHeapEXT
350 OpCapability BindlessTextureNV
351 OpExtension "SPV_EXT_descriptor_heap"
352 OpExtension "SPV_KHR_untyped_pointers"
353 OpExtension "SPV_NV_bindless_texture"
354 %1 = OpExtInstImport "GLSL.std.450"
355 OpMemoryModel Logical GLSL450
356 OpSamplerImageAddressingModeNV 64
357 OpEntryPoint Fragment %main "main" %resource_heap %fragColor
358 OpExecutionMode %main OriginUpperLeft
359 OpSource GLSL 460
360 OpSourceExtension "GL_EXT_descriptor_heap"
361 OpSourceExtension "GL_EXT_nonuniform_qualifier"
362 OpName %main "main"
363 OpName %fragColor "fragColor"
364 OpName %resource_heap "resource_heap"
365 OpName %U "U"
366 OpMemberName %U 0 "uv"
367 OpMemberName %U 1 "k"
368 OpMemberName %U 2 "g"
369 OpDecorate %fragColor Location 0
370 OpDecorate %resource_heap BuiltIn ResourceHeapEXT
371 OpDecorate %U Block
372 OpMemberDecorateIdEXT %U 0 OffsetIdEXT %specA
373 OpMemberDecorateIdEXT %U 1 OffsetIdEXT %specB
374 OpMemberDecorateIdEXT %U 2 OffsetIdEXT %specC
375 OpDecorateId %_runtimearr_20 ArrayStrideIdEXT %uint_2
376 %void = OpTypeVoid
377 %3 = OpTypeFunction %void
378 %float = OpTypeFloat 32
379 %v2float = OpTypeVector %float 2
380 %_ptr_Output_v2float = OpTypePointer Output %v2float
381 %fragColor = OpVariable %_ptr_Output_v2float Output
382 %_ptr_UniformConstant = OpTypeUntypedPointerKHR UniformConstant
383 %resource_heap = OpUntypedVariableKHR %_ptr_UniformConstant UniformConstant
384 %int = OpTypeInt 32 1
385 %int_3 = OpConstant %int 3
386 %uint = OpTypeInt 32 0
387 %v3uint = OpTypeVector %uint 3
388 %samplerTy = OpTypeSampler
389 %_runtimearr_sampler = OpTypeRuntimeArray %samplerTy
390 %specA = OpSpecConstant %int 0
391 %specB = OpSpecConstant %int 4
392 %specC = OpSpecConstant %int 8
393 %U = OpTypeStruct %v2float %int %_runtimearr_sampler
394 %int_0 = OpConstant %int 0
395 %_ptr_Uniform = OpTypeUntypedPointerKHR Uniform
396 %20 = OpTypeBufferEXT Uniform
397 %uint_2 = OpConstant %uint 2
398 %_runtimearr_20 = OpTypeRuntimeArray %20
399 %main = OpFunction %void None %3
400 %5 = OpLabel
401 %19 = OpUntypedAccessChainKHR %_ptr_UniformConstant %_runtimearr_20 %resource_heap %int_3
402 %23 = OpBufferPointerEXT %_ptr_Uniform %19
403 %24 = OpUntypedAccessChainKHR %_ptr_Uniform %U %23 %int_0
404 %25 = OpLoad %v2float %24
405 OpStore %fragColor %25
406 OpReturn
407 OpFunctionEnd
408 )";
409 CompileSuccessfully(str.c_str(), SPV_ENV_VULKAN_1_4);
410 EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_4));
411 }
412
413 // From VVL CTS
414 TEST_F(ValidateSpvEXTDescriptorHeap, Alignment) {
415 const std::string str = R"(
416 OpCapability Shader
417 OpCapability SampledBuffer
418 OpCapability UntypedPointersKHR
419 OpCapability DescriptorHeapEXT
420 OpExtension "SPV_EXT_descriptor_heap"
421 OpExtension "SPV_KHR_untyped_pointers"
422 OpMemoryModel Logical GLSL450
423 OpEntryPoint GLCompute %2 "main" %3 %4 %5
424 OpExecutionMode %2 LocalSize 1 1 1
425 OpSource GLSL 450
426 OpSourceExtension "GL_EXT_descriptor_heap"
427 OpDecorate %3 BuiltIn ResourceHeapEXT
428 OpDecorateId %_runtimearr_12 ArrayStrideIdEXT %7
429 OpDecorate %4 Binding 0
430 OpDecorate %4 DescriptorSet 0
431 OpDecorate %_struct_8 Block
432 OpMemberDecorate %_struct_8 0 Offset 0
433 OpDecorate %5 Binding 1
434 OpDecorate %5 DescriptorSet 0
435 %void = OpTypeVoid
436 %10 = OpTypeFunction %void
437 %uint = OpTypeInt 32 0
438 %12 = OpTypeImage %uint Buffer 0 0 0 1 Unknown
439 %_ptr_UniformConstant_12 = OpTypePointer UniformConstant %12
440 %_ptr_UniformConstant = OpTypeUntypedPointerKHR UniformConstant
441 %15 = OpTypeFunction %uint %_ptr_UniformConstant
442 %uint_0 = OpConstant %uint 0
443 %v4uint = OpTypeVector %uint 4
444 %v2uint = OpTypeVector %uint 2
445 %3 = OpUntypedVariableKHR %_ptr_UniformConstant UniformConstant
446 %7 = OpConstantSizeOfEXT %uint %12
447 %_runtimearr_12 = OpTypeRuntimeArray %12
448 %_ptr_Function_uint = OpTypePointer Function %uint
449 %4 = OpVariable %_ptr_UniformConstant_12 UniformConstant
450 %uint_1 = OpConstant %uint 1
451 %_struct_8 = OpTypeStruct %v2uint
452 %_ptr_StorageBuffer__struct_8 = OpTypePointer StorageBuffer %_struct_8
453 %5 = OpVariable %_ptr_StorageBuffer__struct_8 StorageBuffer
454 %_ptr_StorageBuffer_v2uint = OpTypePointer StorageBuffer %v2uint
455 %v3uint = OpTypeVector %uint 3
456 %24 = OpConstantComposite %v3uint %uint_1 %uint_1 %uint_1
457 %25 = OpFunction %uint None %15
458 %26 = OpFunctionParameter %_ptr_UniformConstant
459 %27 = OpLabel
460 %28 = OpLoad %12 %26
461 %29 = OpImageFetch %v4uint %28 %uint_0 ZeroExtend
462 %30 = OpCompositeExtract %uint %29 0
463 OpReturnValue %30
464 OpFunctionEnd
465 %2 = OpFunction %void None %10
466 %31 = OpLabel
467 %32 = OpUntypedAccessChainKHR %_ptr_UniformConstant %_runtimearr_12 %3 %uint_0
468 %33 = OpUntypedAccessChainKHR %_ptr_UniformConstant %12 %4
469 %34 = OpFunctionCall %uint %25 %32
470 %35 = OpFunctionCall %uint %25 %33
471 %36 = OpCompositeConstruct %v2uint %34 %35
472 %37 = OpAccessChain %_ptr_StorageBuffer_v2uint %5 %uint_0
473 OpStore %37 %36
474 OpReturn
475 OpFunctionEnd
476 )";
477 CompileSuccessfully(str.c_str(), SPV_ENV_VULKAN_1_4);
478 EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_4));
479 }
480
481 TEST_F(ValidateSpvEXTDescriptorHeap, HeapBaseVarStorageClassResource) {
482 const std::string str = R"(
483 OpCapability Shader
484 OpCapability UntypedPointersKHR
485 OpCapability DescriptorHeapEXT
486 OpExtension "SPV_EXT_descriptor_heap"
487 OpExtension "SPV_KHR_untyped_pointers"
488 %1 = OpExtInstImport "GLSL.std.450"
489 OpMemoryModel Logical GLSL450
490 OpEntryPoint Fragment %main "main" %resource_heap %o
491 OpExecutionMode %main OriginUpperLeft
492 OpSource GLSL 450
493 OpSourceExtension "GL_EXT_descriptor_heap"
494 OpName %main "main"
495 OpName %o "o"
496 OpName %resource_heap "resource_heap"
497 OpName %U "U"
498 OpMemberName %U 0 "inputData"
499 OpDecorate %o Location 0
500 OpDecorate %resource_heap BuiltIn ResourceHeapEXT
501 OpDecorate %U Block
502 OpMemberDecorate %U 0 Offset 0
503 OpDecorateId %_runtimearr_17 ArrayStrideIdEXT %18
504 %void = OpTypeVoid
505 %3 = OpTypeFunction %void
506 %uint = OpTypeInt 32 0
507 %_ptr_Output_uint = OpTypePointer Output %uint
508 %o = OpVariable %_ptr_Output_uint Output
509 %_ptr_Uniform = OpTypeUntypedPointerKHR Uniform
510 %resource_heap = OpUntypedVariableKHR %_ptr_Uniform Uniform
511 %int = OpTypeInt 32 1
512 %int_9 = OpConstant %int 9
513 %U = OpTypeStruct %uint
514 %int_0 = OpConstant %int 0
515 %17 = OpTypeBufferEXT Uniform
516 %18 = OpConstantSizeOfEXT %int %17
517 %_runtimearr_17 = OpTypeRuntimeArray %17
518 %main = OpFunction %void None %3
519 %5 = OpLabel
520 %16 = OpUntypedAccessChainKHR %_ptr_Uniform %_runtimearr_17 %resource_heap %int_9
521 %20 = OpBufferPointerEXT %_ptr_Uniform %16
522 %21 = OpUntypedAccessChainKHR %_ptr_Uniform %U %20 %int_0
523 %22 = OpLoad %uint %21
524 OpStore %o %22
525 OpReturn
526 OpFunctionEnd
527 )";
528 CompileSuccessfully(str.c_str(), SPV_ENV_VULKAN_1_3);
529 EXPECT_NE(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_3));
530 const std::string diag = getDiagnosticString();
531 EXPECT_THAT(diag, AnyVUID("VUID-StandaloneSpirv-OpUntypedVariableKHR-11167"));
532 EXPECT_THAT(
533 diag,
534 HasSubstr("Storage class is Uniform, but Vulkan requires that Data Type "
535 "be specified when not using UniformConstant storage class"));
536 }
537
538 TEST_F(ValidateSpvEXTDescriptorHeap, HeapBaseVarStorageClassSampler) {
539 const std::string str = R"(
540 OpCapability Shader
541 OpCapability UntypedPointersKHR
542 OpCapability DescriptorHeapEXT
543 OpExtension "SPV_EXT_descriptor_heap"
544 OpExtension "SPV_KHR_untyped_pointers"
545 %1 = OpExtInstImport "GLSL.std.450"
546 OpMemoryModel Logical GLSL450
547 OpEntryPoint Fragment %main "main" %resource_heap %sampler_heap %fragColor %uvs
548 OpExecutionMode %main OriginUpperLeft
549 OpSource GLSL 460
550 OpSourceExtension "GL_EXT_descriptor_heap"
551 OpSourceExtension "GL_EXT_nonuniform_qualifier"
552 OpName %main "main"
553 OpName %fragColor "fragColor"
554 OpName %resource_heap "resource_heap"
555 OpName %sampler_heap "sampler_heap"
556 OpName %uvs "uvs"
557 OpDecorate %fragColor Location 0
558 OpDecorate %resource_heap BuiltIn ResourceHeapEXT
559 OpDecorateId %_runtimearr_14 ArrayStrideIdEXT %17
560 OpDecorate %sampler_heap BuiltIn SamplerHeapEXT
561 OpDecorateId %_runtimearr_22 ArrayStrideIdEXT %uint_2
562 OpDecorate %uvs Location 0
563 %void = OpTypeVoid
564 %3 = OpTypeFunction %void
565 %float = OpTypeFloat 32
566 %v4float = OpTypeVector %float 4
567 %_ptr_Output_v4float = OpTypePointer Output %v4float
568 %fragColor = OpVariable %_ptr_Output_v4float Output
569 %_ptr_StorageBuffer = OpTypeUntypedPointerKHR StorageBuffer
570 %int = OpTypeInt 32 1
571 %int_27 = OpConstant %int 27
572 %14 = OpTypeImage %float 2D 0 0 0 1 Unknown
573 %_ptr_UniformConstant = OpTypeUntypedPointerKHR UniformConstant
574 %17 = OpConstantSizeOfEXT %int %14
575 %_runtimearr_14 = OpTypeRuntimeArray %14
576 %sampler_heap = OpUntypedVariableKHR %_ptr_StorageBuffer StorageBuffer
577 %resource_heap = OpUntypedVariableKHR %_ptr_StorageBuffer StorageBuffer
578 %int_0 = OpConstant %int 0
579 %22 = OpTypeSampler
580 %uint = OpTypeInt 32 0
581 %uint_2 = OpConstant %uint 2
582 %_runtimearr_22 = OpTypeRuntimeArray %22
583 %28 = OpTypeSampledImage %14
584 %v2float = OpTypeVector %float 2
585 %_ptr_Input_v2float = OpTypePointer Input %v2float
586 %uvs = OpVariable %_ptr_Input_v2float Input
587 %main = OpFunction %void None %3
588 %5 = OpLabel
589 %16 = OpUntypedAccessChainKHR %_ptr_StorageBuffer %_runtimearr_14 %resource_heap %int_27
590 %19 = OpLoad %14 %16
591 %23 = OpUntypedAccessChainKHR %_ptr_StorageBuffer %_runtimearr_22 %sampler_heap %int_0
592 %27 = OpLoad %22 %23
593 %29 = OpSampledImage %28 %19 %27
594 %33 = OpLoad %v2float %uvs
595 %34 = OpImageSampleImplicitLod %v4float %29 %33
596 OpStore %fragColor %34
597 OpReturn
598 OpFunctionEnd
599 )";
600 CompileSuccessfully(str.c_str(), SPV_ENV_VULKAN_1_3);
601 EXPECT_NE(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_3));
602 const std::string diag = getDiagnosticString();
603 EXPECT_THAT(diag, AnyVUID("VUID-StandaloneSpirv-OpUntypedVariableKHR-11167"));
604 EXPECT_THAT(
605 diag,
606 HasSubstr(
607 "Storage class is StorageBuffer, but Vulkan requires that Data Type "
608 "be specified when not using UniformConstant storage class"));
609 }
610
611 TEST_F(ValidateSpvEXTDescriptorHeap, ResourceHeapWorkgroup) {
612 const std::string str = R"(
613 OpCapability Shader
614 OpCapability UntypedPointersKHR
615 OpCapability DescriptorHeapEXT
616 OpCapability WorkgroupMemoryExplicitLayoutKHR
617 OpExtension "SPV_KHR_workgroup_memory_explicit_layout"
618 OpExtension "SPV_EXT_descriptor_heap"
619 OpExtension "SPV_KHR_untyped_pointers"
620 OpMemoryModel Logical GLSL450
621 OpEntryPoint GLCompute %main "main"
622 OpExecutionMode %main LocalSize 1 1 1
623 OpDecorate %resource_heap BuiltIn ResourceHeapEXT
624 %void = OpTypeVoid
625 %3 = OpTypeFunction %void
626 %15 = OpTypeBufferEXT StorageBuffer
627 %_ptr_workgroup = OpTypeUntypedPointerKHR Workgroup
628 %resource_heap = OpUntypedVariableKHR %_ptr_workgroup Workgroup %15
629 %main = OpFunction %void None %3
630 %5 = OpLabel
631 OpReturn
632 OpFunctionEnd
633 )";
634 CompileSuccessfully(str.c_str(), SPV_ENV_VULKAN_1_3);
635 EXPECT_NE(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_3));
636 const std::string diag = getDiagnosticString();
637 EXPECT_THAT(diag, AnyVUID("VUID-ResourceHeapEXT-ResourceHeapEXT-11241"));
638 EXPECT_THAT(diag,
639 HasSubstr("The variable decorated with ResourceHeapEXT must be "
640 "declared using the UniformConstant storage class"));
641 }
642
643 TEST_F(ValidateSpvEXTDescriptorHeap, SamplerHeapWorkgroup) {
644 const std::string str = R"(
645 OpCapability Shader
646 OpCapability UntypedPointersKHR
647 OpCapability DescriptorHeapEXT
648 OpCapability WorkgroupMemoryExplicitLayoutKHR
649 OpExtension "SPV_KHR_workgroup_memory_explicit_layout"
650 OpExtension "SPV_EXT_descriptor_heap"
651 OpExtension "SPV_KHR_untyped_pointers"
652 OpMemoryModel Logical GLSL450
653 OpEntryPoint GLCompute %main "main"
654 OpExecutionMode %main LocalSize 1 1 1
655 OpDecorate %resource_heap BuiltIn SamplerHeapEXT
656 %void = OpTypeVoid
657 %3 = OpTypeFunction %void
658 %15 = OpTypeBufferEXT StorageBuffer
659 %_ptr_workgroup = OpTypeUntypedPointerKHR Workgroup
660 %resource_heap = OpUntypedVariableKHR %_ptr_workgroup Workgroup %15
661 %main = OpFunction %void None %3
662 %5 = OpLabel
663 OpReturn
664 OpFunctionEnd
665 )";
666 CompileSuccessfully(str.c_str(), SPV_ENV_VULKAN_1_3);
667 EXPECT_NE(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_3));
668 const std::string diag = getDiagnosticString();
669 EXPECT_THAT(diag, AnyVUID("VUID-SamplerHeapEXT-SamplerHeapEXT-11239"));
670 EXPECT_THAT(diag,
671 HasSubstr("The variable decorated with SamplerHeapEXT must be "
672 "declared using the UniformConstant storage class"));
673 }
674
675 TEST_F(ValidateSpvEXTDescriptorHeap, LoadDescHeapDerivedSampler) {
676 const std::string str = R"(
677 OpCapability Shader
678 OpCapability UntypedPointersKHR
679 OpCapability DescriptorHeapEXT
680 OpExtension "SPV_EXT_descriptor_heap"
681 OpExtension "SPV_KHR_untyped_pointers"
682 %1 = OpExtInstImport "GLSL.std.450"
683 OpMemoryModel Logical GLSL450
684 OpEntryPoint Fragment %main "main" %resource_heap %sampler_heap %fragColor %uvs
685 OpExecutionMode %main OriginUpperLeft
686 OpSource GLSL 460
687 OpSourceExtension "GL_EXT_descriptor_heap"
688 OpSourceExtension "GL_EXT_nonuniform_qualifier"
689 OpName %main "main"
690 OpName %fragColor "fragColor"
691 OpName %resource_heap "resource_heap"
692 OpName %sampler_heap "sampler_heap"
693 OpName %uvs "uvs"
694 OpDecorate %fragColor Location 0
695 OpDecorate %resource_heap BuiltIn ResourceHeapEXT
696 OpDecorateId %_runtimearr_14 ArrayStrideIdEXT %17
697 OpDecorate %sampler_heap BuiltIn ResourceHeapEXT
698 OpDecorateId %_runtimearr_22 ArrayStrideIdEXT %uint_2
699 OpDecorate %uvs Location 0
700 %void = OpTypeVoid
701 %3 = OpTypeFunction %void
702 %float = OpTypeFloat 32
703 %v4float = OpTypeVector %float 4
704 %_ptr_Output_v4float = OpTypePointer Output %v4float
705 %fragColor = OpVariable %_ptr_Output_v4float Output
706 %_ptr_UniformConstant = OpTypeUntypedPointerKHR UniformConstant
707 %resource_heap = OpUntypedVariableKHR %_ptr_UniformConstant UniformConstant
708 %int = OpTypeInt 32 1
709 %int_27 = OpConstant %int 27
710 %14 = OpTypeImage %float 2D 0 0 0 1 Unknown
711 %17 = OpConstantSizeOfEXT %int %14
712 %_runtimearr_14 = OpTypeRuntimeArray %14
713 %sampler_heap = OpUntypedVariableKHR %_ptr_UniformConstant UniformConstant
714 %int_0 = OpConstant %int 0
715 %22 = OpTypeSampler
716 %uint = OpTypeInt 32 0
717 %uint_2 = OpConstant %uint 2
718 %_runtimearr_22 = OpTypeRuntimeArray %22
719 %28 = OpTypeSampledImage %14
720 %v2float = OpTypeVector %float 2
721 %_ptr_Input_v2float = OpTypePointer Input %v2float
722 %uvs = OpVariable %_ptr_Input_v2float Input
723 %main = OpFunction %void None %3
724 %5 = OpLabel
725 %16 = OpUntypedAccessChainKHR %_ptr_UniformConstant %_runtimearr_14 %resource_heap %int_27
726 %19 = OpLoad %14 %16
727 %23 = OpUntypedAccessChainKHR %_ptr_UniformConstant %_runtimearr_22 %sampler_heap %int_0
728 %27 = OpLoad %22 %23
729 %29 = OpSampledImage %28 %19 %27
730 %33 = OpLoad %v2float %uvs
731 %34 = OpImageSampleImplicitLod %v4float %29 %33
732 OpStore %fragColor %34
733 OpReturn
734 OpFunctionEnd
735 )";
736 CompileSuccessfully(str.c_str(), SPV_ENV_VULKAN_1_3);
737 EXPECT_NE(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_3));
738 const std::string diag = getDiagnosticString();
739 EXPECT_THAT(diag, AnyVUID("VUID-StandaloneSpirv-Result-11336"));
740 EXPECT_THAT(
741 diag,
742 HasSubstr(
743 "pointer instruction has no descriptor set or binding "
744 "and is not derived from a variable decorated with SamplerHeapEXT"));
745 }
746
747 TEST_F(ValidateSpvEXTDescriptorHeap, LoadDescHeapDerivedImage) {
748 const std::string str = R"(
749 OpCapability Shader
750 OpCapability UntypedPointersKHR
751 OpCapability DescriptorHeapEXT
752 OpExtension "SPV_EXT_descriptor_heap"
753 OpExtension "SPV_KHR_untyped_pointers"
754 %1 = OpExtInstImport "GLSL.std.450"
755 OpMemoryModel Logical GLSL450
756 OpEntryPoint Fragment %main "main" %resource_heap %sampler_heap %fragColor %uvs
757 OpExecutionMode %main OriginUpperLeft
758 OpSource GLSL 460
759 OpSourceExtension "GL_EXT_descriptor_heap"
760 OpSourceExtension "GL_EXT_nonuniform_qualifier"
761 OpName %main "main"
762 OpName %fragColor "fragColor"
763 OpName %resource_heap "resource_heap"
764 OpName %sampler_heap "sampler_heap"
765 OpName %uvs "uvs"
766 OpDecorate %fragColor Location 0
767 OpDecorate %resource_heap BuiltIn SamplerHeapEXT
768 OpDecorateId %_runtimearr_14 ArrayStrideIdEXT %17
769 OpDecorate %sampler_heap BuiltIn SamplerHeapEXT
770 OpDecorateId %_runtimearr_22 ArrayStrideIdEXT %uint_2
771 OpDecorate %uvs Location 0
772 %void = OpTypeVoid
773 %3 = OpTypeFunction %void
774 %float = OpTypeFloat 32
775 %v4float = OpTypeVector %float 4
776 %_ptr_Output_v4float = OpTypePointer Output %v4float
777 %fragColor = OpVariable %_ptr_Output_v4float Output
778 %_ptr_UniformConstant = OpTypeUntypedPointerKHR UniformConstant
779 %resource_heap = OpUntypedVariableKHR %_ptr_UniformConstant UniformConstant
780 %int = OpTypeInt 32 1
781 %int_27 = OpConstant %int 27
782 %14 = OpTypeImage %float 2D 0 0 0 1 Unknown
783 %17 = OpConstantSizeOfEXT %int %14
784 %_runtimearr_14 = OpTypeRuntimeArray %14
785 %sampler_heap = OpUntypedVariableKHR %_ptr_UniformConstant UniformConstant
786 %int_0 = OpConstant %int 0
787 %22 = OpTypeSampler
788 %uint = OpTypeInt 32 0
789 %uint_2 = OpConstant %uint 2
790 %_runtimearr_22 = OpTypeRuntimeArray %22
791 %28 = OpTypeSampledImage %14
792 %v2float = OpTypeVector %float 2
793 %_ptr_Input_v2float = OpTypePointer Input %v2float
794 %uvs = OpVariable %_ptr_Input_v2float Input
795 %main = OpFunction %void None %3
796 %5 = OpLabel
797 %16 = OpUntypedAccessChainKHR %_ptr_UniformConstant %_runtimearr_14 %resource_heap %int_27
798 %19 = OpLoad %14 %16
799 %23 = OpUntypedAccessChainKHR %_ptr_UniformConstant %_runtimearr_22 %sampler_heap %int_0
800 %27 = OpLoad %22 %23
801 %29 = OpSampledImage %28 %19 %27
802 %33 = OpLoad %v2float %uvs
803 %34 = OpImageSampleImplicitLod %v4float %29 %33
804 OpStore %fragColor %34
805 OpReturn
806 OpFunctionEnd
807 )";
808 CompileSuccessfully(str.c_str(), SPV_ENV_VULKAN_1_3);
809 EXPECT_NE(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_3));
810 const std::string diag = getDiagnosticString();
811 EXPECT_THAT(diag, AnyVUID("VUID-StandaloneSpirv-Result-11337"));
812 EXPECT_THAT(
813 diag,
814 HasSubstr(
815 "pointer instruction has no descriptor set or binding "
816 "and is not derived from a variable decorated with ResourceHeapEXT"));
817 }
818
819 TEST_F(ValidateSpvEXTDescriptorHeap, LoadDescHeapDerivedAccStruct) {
820 const std::string str = R"(
821 OpCapability Shader
822 OpCapability RayQueryKHR
823 OpCapability UntypedPointersKHR
824 OpCapability DescriptorHeapEXT
825 OpExtension "SPV_EXT_descriptor_heap"
826 OpExtension "SPV_KHR_untyped_pointers"
827 OpExtension "SPV_KHR_ray_query"
828 OpMemoryModel Logical GLSL450
829 OpEntryPoint GLCompute %main "main" %resource_heap
830 OpExecutionMode %main LocalSize 1 1 1
831 OpName %resource_heap "resource_heap"
832 OpDecorate %resource_heap BuiltIn SamplerHeapEXT
833 OpDecorateId %_runtimearr_14 ArrayStrideIdEXT %17
834 %_ptr_UniformConstant = OpTypeUntypedPointerKHR UniformConstant
835 %resource_heap = OpUntypedVariableKHR %_ptr_UniformConstant UniformConstant
836 %int = OpTypeInt 32 1
837 %int_27 = OpConstant %int 27
838 %void = OpTypeVoid
839 %as = OpTypeAccelerationStructureKHR
840 %ptr_as = OpTypePointer Function %as
841 %void_fn = OpTypeFunction %void
842 %17 = OpConstantSizeOfEXT %int %as
843 %_runtimearr_14 = OpTypeRuntimeArray %as
844 %main = OpFunction %void None %void_fn
845 %entry = OpLabel
846 %var = OpUntypedAccessChainKHR %_ptr_UniformConstant %_runtimearr_14 %resource_heap %int_27
847 %value = OpLoad %as %var
848 OpReturn
849 OpFunctionEnd
850 )";
851 CompileSuccessfully(str.c_str(), SPV_ENV_VULKAN_1_3);
852 EXPECT_NE(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_3));
853 const std::string diag = getDiagnosticString();
854 EXPECT_THAT(diag, AnyVUID("VUID-StandaloneSpirv-Result-11339"));
855 EXPECT_THAT(
856 diag,
857 HasSubstr(
858 "pointer instruction has no descriptor set or binding "
859 "and is not derived from a variable decorated with ResourceHeapEXT"));
860 }
861
862 TEST_F(ValidateSpvEXTDescriptorHeap, ConstantSizeOfScalarIntType) {
863 const std::string str = R"(
864 OpCapability Shader
865 OpCapability UntypedPointersKHR
866 OpCapability DescriptorHeapEXT
867 OpExtension "SPV_EXT_descriptor_heap"
868 OpExtension "SPV_KHR_untyped_pointers"
869 %1 = OpExtInstImport "GLSL.std.450"
870 OpMemoryModel Logical GLSL450
871 OpEntryPoint Fragment %main "main" %resource_heap %o
872 OpExecutionMode %main OriginUpperLeft
873 OpSource GLSL 450
874 OpSourceExtension "GL_EXT_descriptor_heap"
875 OpName %main "main"
876 OpName %o "o"
877 OpName %resource_heap "resource_heap"
878 OpName %U "U"
879 OpMemberName %U 0 "inputData"
880 OpDecorate %o Location 0
881 OpDecorate %resource_heap BuiltIn ResourceHeapEXT
882 OpDecorate %U Block
883 OpMemberDecorate %U 0 Offset 0
884 OpDecorateId %_runtimearr_17 ArrayStrideIdEXT %18
885 %void = OpTypeVoid
886 %3 = OpTypeFunction %void
887 %uint = OpTypeInt 32 0
888 %_ptr_Output_uint = OpTypePointer Output %uint
889 %o = OpVariable %_ptr_Output_uint Output
890 %_ptr_Uniform = OpTypeUntypedPointerKHR UniformConstant
891 %resource_heap = OpUntypedVariableKHR %_ptr_Uniform UniformConstant
892 %int = OpTypeInt 32 1
893 %v2int = OpTypeVector %int 2
894 %int_9 = OpConstant %int 9
895 %U = OpTypeStruct %uint
896 %int_0 = OpConstant %int 0
897 %17 = OpTypeBufferEXT Uniform
898 %18 = OpConstantSizeOfEXT %v2int %17
899 %_runtimearr_17 = OpTypeRuntimeArray %17
900 %main = OpFunction %void None %3
901 %5 = OpLabel
902 %16 = OpUntypedAccessChainKHR %_ptr_Uniform %_runtimearr_17 %resource_heap %int_9
903 %20 = OpBufferPointerEXT %_ptr_Uniform %16
904 %21 = OpUntypedAccessChainKHR %_ptr_Uniform %U %20 %int_0
905 %22 = OpLoad %uint %21
906 OpStore %o %22
907 OpReturn
908 OpFunctionEnd
909 )";
910 CompileSuccessfully(str.c_str(), SPV_ENV_VULKAN_1_3);
911 EXPECT_NE(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_3));
912 const std::string diag = getDiagnosticString();
913 EXPECT_THAT(
914 diag,
915 HasSubstr(
916 "ArrayStrideIdEXT extra operand must be a 32-bit int scalar type"));
917 }
918
919 TEST_F(ValidateSpvEXTDescriptorHeap, ConstantSizeOfDescriptorTypeTarget) {
920 const std::string str = R"(
921 OpCapability Shader
922 OpCapability UntypedPointersKHR
923 OpCapability DescriptorHeapEXT
924 OpExtension "SPV_EXT_descriptor_heap"
925 OpExtension "SPV_KHR_untyped_pointers"
926 %1 = OpExtInstImport "GLSL.std.450"
927 OpMemoryModel Logical GLSL450
928 OpEntryPoint Fragment %main "main" %resource_heap %o
929 OpExecutionMode %main OriginUpperLeft
930 OpSource GLSL 450
931 OpSourceExtension "GL_EXT_descriptor_heap"
932 OpName %main "main"
933 OpName %o "o"
934 OpName %resource_heap "resource_heap"
935 OpName %U "U"
936 OpMemberName %U 0 "inputData"
937 OpDecorate %o Location 0
938 OpDecorate %resource_heap BuiltIn ResourceHeapEXT
939 OpDecorate %U Block
940 OpMemberDecorate %U 0 Offset 0
941 OpDecorateId %_runtimearr_17 ArrayStrideIdEXT %18
942 %void = OpTypeVoid
943 %3 = OpTypeFunction %void
944 %uint = OpTypeInt 32 0
945 %_ptr_Output_uint = OpTypePointer Output %uint
946 %o = OpVariable %_ptr_Output_uint Output
947 %_ptr_Uniform = OpTypeUntypedPointerKHR UniformConstant
948 %resource_heap = OpUntypedVariableKHR %_ptr_Uniform UniformConstant
949 %int = OpTypeInt 32 1
950 %int_9 = OpConstant %int 9
951 %U = OpTypeStruct %uint
952 %int_0 = OpConstant %int 0
953 %17 = OpTypeBufferEXT Uniform
954 %18 = OpConstantSizeOfEXT %int %U
955 %_runtimearr_17 = OpTypeRuntimeArray %17
956 %main = OpFunction %void None %3
957 %5 = OpLabel
958 %16 = OpUntypedAccessChainKHR %_ptr_Uniform %_runtimearr_17 %resource_heap %int_9
959 %20 = OpBufferPointerEXT %_ptr_Uniform %16
960 %21 = OpUntypedAccessChainKHR %_ptr_Uniform %U %20 %int_0
961 %22 = OpLoad %uint %21
962 OpStore %o %22
963 OpReturn
964 OpFunctionEnd
965 )";
966 CompileSuccessfully(str.c_str(), SPV_ENV_VULKAN_1_3);
967 EXPECT_NE(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_3));
968 const std::string diag = getDiagnosticString();
969 EXPECT_THAT(diag,
970 HasSubstr("For OpConstantSizeOfEXT instruction, its Type operand "
971 "<Id> '5[%U]' must be a Descriptor type"));
972 }
973
974 TEST_F(ValidateSpvEXTDescriptorHeap, OffsetId64BitIndexingBad) {
975 const std::string str = R"(
976 OpCapability Shader
977 OpCapability DescriptorHeapEXT
978 OpExtension "SPV_EXT_descriptor_heap"
979 %1 = OpExtInstImport "GLSL.std.450"
980 OpMemoryModel Logical GLSL450
981 OpEntryPoint GLCompute %2 "main" %3
982 OpExecutionMode %2 LocalSize 1 1 1
983 OpSource GLSL 450
984 OpMemberDecorate %4 0 Offset 0
985 OpMemberDecorate %4 1 Offset 4
986 OpMemberDecorate %4 2 Offset 8
987 OpMemberDecorate %4 3 Offset 12
988 OpDecorate %4 Block
989 OpDecorate %3 Binding 0
990 OpDecorate %3 DescriptorSet 0
991 %5 = OpTypeVoid
992 %6 = OpTypeFunction %5
993 %7 = OpTypeInt 32 0
994 %8 = OpTypeInt 64 0
995 %4 = OpTypeStruct %7 %7 %7 %7
996 %9 = OpTypePointer StorageBuffer %4
997 %3 = OpVariable %9 StorageBuffer
998 %10 = OpTypeInt 32 1
999 %11 = OpConstant %10 0
1000 %12 = OpConstant %10 1
1001 %13 = OpConstant %10 2
1002 %14 = OpConstant %10 3
1003 %15 = OpTypePointer StorageBuffer %7
1004 %16 = OpTypeBufferEXT StorageBuffer
1005 %17 = OpTypeBufferEXT Uniform
1006 %18 = OpTypeImage %7 2D 0 0 0 1 Unknown
1007 %19 = OpTypeSampler
1008 %20 = OpConstantSizeOfEXT %8 %16
1009 %21 = OpConstantSizeOfEXT %8 %17
1010 %22 = OpConstantSizeOfEXT %8 %18
1011 %23 = OpConstantSizeOfEXT %8 %19
1012 %2 = OpFunction %5 None %6
1013 %24 = OpLabel
1014 %25 = OpAccessChain %15 %3 %11
1015 %26 = OpAccessChain %15 %3 %12
1016 %27 = OpAccessChain %15 %3 %13
1017 %28 = OpAccessChain %15 %3 %14
1018 %29 = OpUConvert %7 %20
1019 %30 = OpUConvert %7 %21
1020 %31 = OpUConvert %7 %22
1021 %32 = OpUConvert %7 %23
1022 OpStore %25 %29
1023 OpStore %26 %30
1024 OpStore %27 %31
1025 OpStore %28 %32
1026 OpReturn
1027 OpFunctionEnd
1028 )";
1029 CompileSuccessfully(str.c_str(), SPV_ENV_VULKAN_1_3);
1030 EXPECT_NE(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_3));
1031 const std::string diag = getDiagnosticString();
1032 EXPECT_THAT(
1033 diag,
1034 HasSubstr("Using a 64-bit integer type requires the Int64 capability."));
1035 }
1036
1037 TEST_F(ValidateSpvEXTDescriptorHeap, TypeBufferEXTStorageClass) {
1038 const std::string str = R"(
1039 OpCapability Shader
1040 OpCapability UntypedPointersKHR
1041 OpCapability DescriptorHeapEXT
1042 OpExtension "SPV_EXT_descriptor_heap"
1043 OpExtension "SPV_KHR_untyped_pointers"
1044 %1 = OpExtInstImport "GLSL.std.450"
1045 OpMemoryModel Logical GLSL450
1046 OpEntryPoint Fragment %main "main" %resource_heap %o
1047 OpExecutionMode %main OriginUpperLeft
1048 OpSource GLSL 450
1049 OpSourceExtension "GL_EXT_descriptor_heap"
1050 OpName %main "main"
1051 OpName %o "o"
1052 OpName %resource_heap "resource_heap"
1053 OpName %U "U"
1054 OpMemberName %U 0 "inputData"
1055 OpDecorate %o Location 0
1056 OpDecorate %resource_heap BuiltIn ResourceHeapEXT
1057 OpDecorate %U Block
1058 OpMemberDecorate %U 0 Offset 0
1059 OpDecorateId %_runtimearr_17 ArrayStrideIdEXT %18
1060 %void = OpTypeVoid
1061 %3 = OpTypeFunction %void
1062 %uint = OpTypeInt 32 0
1063 %_ptr_Output_uint = OpTypePointer Output %uint
1064 %o = OpVariable %_ptr_Output_uint Output
1065 %_ptr_Uniform = OpTypeUntypedPointerKHR UniformConstant
1066 %resource_heap = OpUntypedVariableKHR %_ptr_Uniform UniformConstant
1067 %int = OpTypeInt 32 1
1068 %int_9 = OpConstant %int 9
1069 %U = OpTypeStruct %uint
1070 %int_0 = OpConstant %int 0
1071 %17 = OpTypeBufferEXT UniformConstant
1072 %18 = OpConstantSizeOfEXT %int %17
1073 %_runtimearr_17 = OpTypeRuntimeArray %17
1074 %main = OpFunction %void None %3
1075 %5 = OpLabel
1076 %16 = OpUntypedAccessChainKHR %_ptr_Uniform %_runtimearr_17 %resource_heap %int_9
1077 %20 = OpBufferPointerEXT %_ptr_Uniform %16
1078 %21 = OpUntypedAccessChainKHR %_ptr_Uniform %U %20 %int_0
1079 %22 = OpLoad %uint %21
1080 OpStore %o %22
1081 OpReturn
1082 OpFunctionEnd
1083 )";
1084 CompileSuccessfully(str.c_str(), SPV_ENV_VULKAN_1_3);
1085 EXPECT_NE(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_3));
1086 const std::string diag = getDiagnosticString();
1087 EXPECT_THAT(diag, HasSubstr("TypeBufferEXT StorageClass could only be "
1088 "StorageBuffer or Uniform."));
1089 }
1090
1091 TEST_F(ValidateSpvEXTDescriptorHeap, BufferPointerEXTStorageClass) {
1092 const std::string str = R"(
1093 OpCapability Shader
1094 OpCapability UntypedPointersKHR
1095 OpCapability DescriptorHeapEXT
1096 OpExtension "SPV_EXT_descriptor_heap"
1097 OpExtension "SPV_KHR_untyped_pointers"
1098 %1 = OpExtInstImport "GLSL.std.450"
1099 OpMemoryModel Logical GLSL450
1100 OpEntryPoint Fragment %main "main" %resource_heap %o
1101 OpExecutionMode %main OriginUpperLeft
1102 OpSource GLSL 450
1103 OpSourceExtension "GL_EXT_descriptor_heap"
1104 OpName %main "main"
1105 OpName %o "o"
1106 OpName %resource_heap "resource_heap"
1107 OpName %U "U"
1108 OpMemberName %U 0 "inputData"
1109 OpDecorate %o Location 0
1110 OpDecorate %resource_heap BuiltIn ResourceHeapEXT
1111 OpDecorate %U Block
1112 OpMemberDecorate %U 0 Offset 0
1113 OpDecorateId %_runtimearr_17 ArrayStrideIdEXT %18
1114 %void = OpTypeVoid
1115 %3 = OpTypeFunction %void
1116 %uint = OpTypeInt 32 0
1117 %_ptr_Output_uint = OpTypePointer Output %uint
1118 %o = OpVariable %_ptr_Output_uint Output
1119 %_ptr_UniformConstant = OpTypeUntypedPointerKHR UniformConstant
1120 %resource_heap = OpUntypedVariableKHR %_ptr_UniformConstant UniformConstant
1121 %int = OpTypeInt 32 1
1122 %int_9 = OpConstant %int 9
1123 %U = OpTypeStruct %uint
1124 %int_0 = OpConstant %int 0
1125 %17 = OpTypeBufferEXT Uniform
1126 %18 = OpConstantSizeOfEXT %int %17
1127 %_runtimearr_17 = OpTypeRuntimeArray %17
1128 %main = OpFunction %void None %3
1129 %5 = OpLabel
1130 %16 = OpUntypedAccessChainKHR %_ptr_UniformConstant %_runtimearr_17 %resource_heap %int_9
1131 %20 = OpBufferPointerEXT %_ptr_UniformConstant %16
1132 %21 = OpUntypedAccessChainKHR %_ptr_UniformConstant %U %20 %int_0
1133 %22 = OpLoad %uint %21
1134 OpStore %o %22
1135 OpReturn
1136 OpFunctionEnd
1137 )";
1138 CompileSuccessfully(str.c_str(), SPV_ENV_VULKAN_1_3);
1139 EXPECT_NE(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_3));
1140 const std::string diag = getDiagnosticString();
1141 EXPECT_THAT(
1142 diag,
1143 HasSubstr("OpBufferPointerEXT's Result Type must be a pointer "
1144 "type with a Storage Class of Uniform or StorageBuffer."));
1145 }
1146
1147 TEST_F(ValidateSpvEXTDescriptorHeap, BufferPointerEXTLayout) {
1148 const std::string str = R"(
1149 OpCapability Shader
1150 OpCapability UntypedPointersKHR
1151 OpCapability DescriptorHeapEXT
1152 OpExtension "SPV_EXT_descriptor_heap"
1153 OpExtension "SPV_KHR_untyped_pointers"
1154 %1 = OpExtInstImport "GLSL.std.450"
1155 OpMemoryModel Logical GLSL450
1156 OpEntryPoint Fragment %main "main" %resource_heap %o
1157 OpExecutionMode %main OriginUpperLeft
1158 OpSource GLSL 450
1159 OpSourceExtension "GL_EXT_descriptor_heap"
1160 OpName %main "main"
1161 OpName %o "o"
1162 OpName %resource_heap "resource_heap"
1163 OpName %U "U"
1164 OpMemberName %U 0 "inputData"
1165 OpDecorate %o Location 0
1166 OpDecorate %resource_heap BuiltIn ResourceHeapEXT
1167 OpDecorate %U Block
1168 OpMemberDecorate %U 0 Offset 0
1169 OpDecorateId %_runtimearr_17 ArrayStrideIdEXT %18
1170 OpDecorate %_ptr_UniformConstant Offset 0
1171 %void = OpTypeVoid
1172 %3 = OpTypeFunction %void
1173 %uint = OpTypeInt 32 0
1174 %_ptr_Output_uint = OpTypePointer Output %uint
1175 %o = OpVariable %_ptr_Output_uint Output
1176 %_ptr_UniformConstant = OpTypeUntypedPointerKHR UniformConstant
1177 %resource_heap = OpUntypedVariableKHR %_ptr_UniformConstant UniformConstant
1178 %int = OpTypeInt 32 1
1179 %int_9 = OpConstant %int 9
1180 %U = OpTypeStruct %uint
1181 %int_0 = OpConstant %int 0
1182 %17 = OpTypeBufferEXT Uniform
1183 %18 = OpConstantSizeOfEXT %int %17
1184 %_runtimearr_17 = OpTypeRuntimeArray %17
1185 %main = OpFunction %void None %3
1186 %5 = OpLabel
1187 %16 = OpUntypedAccessChainKHR %_ptr_UniformConstant %_runtimearr_17 %resource_heap %int_9
1188 %20 = OpBufferPointerEXT %_ptr_UniformConstant %16
1189 %21 = OpUntypedAccessChainKHR %_ptr_UniformConstant %U %20 %int_0
1190 %22 = OpLoad %uint %21
1191 OpStore %o %22
1192 OpReturn
1193 OpFunctionEnd
1194 )";
1195 CompileSuccessfully(str.c_str(), SPV_ENV_VULKAN_1_3);
1196 EXPECT_NE(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_3));
1197 const std::string diag = getDiagnosticString();
1198 EXPECT_THAT(diag, AnyVUID("VUID-StandaloneSpirv-Result-11346"));
1199 EXPECT_THAT(
1200 diag, HasSubstr("The result type operand of OpBufferPointerEXT "
1201 "must have a Type operand that is explicitly laid out"));
1202 }
1203
1204 TEST_F(ValidateSpvEXTDescriptorHeap, BufferPointerEXTDecorate) {
1205 const std::string str = R"(
1206 OpCapability Shader
1207 OpCapability UntypedPointersKHR
1208 OpCapability DescriptorHeapEXT
1209 OpExtension "SPV_EXT_descriptor_heap"
1210 OpExtension "SPV_KHR_untyped_pointers"
1211 %1 = OpExtInstImport "GLSL.std.450"
1212 OpMemoryModel Logical GLSL450
1213 OpEntryPoint Fragment %main "main" %resource_heap %o
1214 OpExecutionMode %main OriginUpperLeft
1215 OpSource GLSL 450
1216 OpSourceExtension "GL_EXT_descriptor_heap"
1217 OpName %main "main"
1218 OpName %o "o"
1219 OpName %resource_heap "resource_heap"
1220 OpName %U "U"
1221 OpMemberName %U 0 "inputData"
1222 OpDecorate %o Location 0
1223 OpDecorate %resource_heap BuiltIn SamplerHeapEXT
1224 OpDecorate %U Block
1225 OpMemberDecorate %U 0 Offset 0
1226 OpDecorateId %_runtimearr_17 ArrayStrideIdEXT %18
1227 %void = OpTypeVoid
1228 %3 = OpTypeFunction %void
1229 %uint = OpTypeInt 32 0
1230 %_ptr_Output_uint = OpTypePointer Output %uint
1231 %o = OpVariable %_ptr_Output_uint Output
1232 %_ptr_Uniform = OpTypeUntypedPointerKHR UniformConstant
1233 %resource_heap = OpUntypedVariableKHR %_ptr_Uniform UniformConstant
1234 %int = OpTypeInt 32 1
1235 %int_9 = OpConstant %int 9
1236 %U = OpTypeStruct %uint
1237 %int_0 = OpConstant %int 0
1238 %17 = OpTypeBufferEXT Uniform
1239 %18 = OpConstantSizeOfEXT %int %17
1240 %_runtimearr_17 = OpTypeRuntimeArray %17
1241 %main = OpFunction %void None %3
1242 %5 = OpLabel
1243 %16 = OpUntypedAccessChainKHR %_ptr_Uniform %_runtimearr_17 %resource_heap %int_9
1244 %20 = OpBufferPointerEXT %_ptr_Uniform %16
1245 %21 = OpUntypedAccessChainKHR %_ptr_Uniform %U %20 %int_0
1246 %22 = OpLoad %uint %21
1247 OpStore %o %22
1248 OpReturn
1249 OpFunctionEnd
1250 )";
1251 CompileSuccessfully(str.c_str(), SPV_ENV_VULKAN_1_3);
1252 EXPECT_NE(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_3));
1253 const std::string diag = getDiagnosticString();
1254 EXPECT_THAT(diag, HasSubstr("OpBufferPointerEXT's buffer must be an untyped "
1255 "pointer into a variable declared with the "
1256 "ResourceHeapEXT built-in"));
1257 }
1258
1259 TEST_F(ValidateSpvEXTDescriptorHeap, BufferPointerEXTNonWritable) {
1260 const std::string str = R"(
1261 OpCapability Shader
1262 OpCapability UntypedPointersKHR
1263 OpCapability DescriptorHeapEXT
1264 OpExtension "SPV_EXT_descriptor_heap"
1265 OpExtension "SPV_KHR_untyped_pointers"
1266 %1 = OpExtInstImport "GLSL.std.450"
1267 OpMemoryModel Logical GLSL450
1268 OpEntryPoint Fragment %main "main" %resource_heap %fragColor
1269 OpExecutionMode %main OriginUpperLeft
1270 OpSource GLSL 460
1271 OpSourceExtension "GL_EXT_descriptor_heap"
1272 OpSourceExtension "GL_EXT_nonuniform_qualifier"
1273 OpName %main "main"
1274 OpName %fragColor "fragColor"
1275 OpName %resource_heap "resource_heap"
1276 OpName %U "U"
1277 OpMemberName %U 0 "uv"
1278 OpDecorate %fragColor Location 0
1279 OpDecorate %resource_heap BuiltIn ResourceHeapEXT
1280 OpDecorate %U Block
1281 OpMemberDecorate %U 0 Offset 0
1282 OpDecorateId %_runtimearr_18 ArrayStrideIdEXT %uint_2
1283 OpDecorate %22 NonWritable
1284 %void = OpTypeVoid
1285 %3 = OpTypeFunction %void
1286 %float = OpTypeFloat 32
1287 %v2float = OpTypeVector %float 2
1288 %_ptr_Output_v2float = OpTypePointer Output %v2float
1289 %fragColor = OpVariable %_ptr_Output_v2float Output
1290 %_ptr_UniformConstant = OpTypeUntypedPointerKHR UniformConstant
1291 %resource_heap = OpUntypedVariableKHR %_ptr_UniformConstant UniformConstant
1292 %int = OpTypeInt 32 1
1293 %int_3 = OpConstant %int 3
1294 %U = OpTypeStruct %v2float
1295 %int_0 = OpConstant %int 0
1296 %_ptr_Uniform = OpTypeUntypedPointerKHR Uniform
1297 %18 = OpTypeBufferEXT Uniform
1298 %uint = OpTypeInt 32 0
1299 %uint_2 = OpConstant %uint 2
1300 %_runtimearr_18 = OpTypeRuntimeArray %18
1301 %main = OpFunction %void None %3
1302 %5 = OpLabel
1303 %17 = OpUntypedAccessChainKHR %_ptr_UniformConstant %_runtimearr_18 %resource_heap %int_3
1304 %22 = OpBufferPointerEXT %_ptr_Uniform %17
1305 %23 = OpUntypedAccessChainKHR %_ptr_Uniform %U %22 %int_0
1306 %24 = OpLoad %v2float %23
1307 OpStore %fragColor %24
1308 OpReturn
1309 OpFunctionEnd
1310 )";
1311 CompileSuccessfully(str.c_str(), SPV_ENV_VULKAN_1_3);
1312 EXPECT_NE(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_3));
1313 const std::string diag = getDiagnosticString();
1314 EXPECT_THAT(diag, HasSubstr("Target of NonWritable decoration is invalid"));
1315 EXPECT_THAT(
1316 diag,
1317 HasSubstr(
1318 "cannot be used to OpBufferPointerEXT with Uniform storage class"));
1319 }
1320
1321 TEST_F(ValidateSpvEXTDescriptorHeap, BufferPointerEXTNonWritableWithSSBO) {
1322 const std::string str = R"(
1323 OpCapability Shader
1324 OpCapability UntypedPointersKHR
1325 OpCapability DescriptorHeapEXT
1326 OpExtension "SPV_EXT_descriptor_heap"
1327 OpExtension "SPV_KHR_untyped_pointers"
1328 %1 = OpExtInstImport "GLSL.std.450"
1329 OpMemoryModel Logical GLSL450
1330 OpEntryPoint Fragment %main "main" %resource_heap %fragColor
1331 OpExecutionMode %main OriginUpperLeft
1332 OpSource GLSL 460
1333 OpSourceExtension "GL_EXT_descriptor_heap"
1334 OpSourceExtension "GL_EXT_nonuniform_qualifier"
1335 OpName %main "main"
1336 OpName %fragColor "fragColor"
1337 OpName %resource_heap "resource_heap"
1338 OpName %U "U"
1339 OpMemberName %U 0 "uv"
1340 OpDecorate %fragColor Location 0
1341 OpDecorate %resource_heap BuiltIn ResourceHeapEXT
1342 OpDecorate %U Block
1343 OpMemberDecorate %U 0 Offset 0
1344 OpDecorateId %_runtimearr_18 ArrayStrideIdEXT %uint_2
1345 OpDecorate %22 NonWritable
1346 %void = OpTypeVoid
1347 %3 = OpTypeFunction %void
1348 %float = OpTypeFloat 32
1349 %v2float = OpTypeVector %float 2
1350 %_ptr_Output_v2float = OpTypePointer Output %v2float
1351 %fragColor = OpVariable %_ptr_Output_v2float Output
1352 %_ptr_UniformConstant = OpTypeUntypedPointerKHR UniformConstant
1353 %resource_heap = OpUntypedVariableKHR %_ptr_UniformConstant UniformConstant
1354 %int = OpTypeInt 32 1
1355 %int_3 = OpConstant %int 3
1356 %U = OpTypeStruct %v2float
1357 %int_0 = OpConstant %int 0
1358 %_ptr_Uniform = OpTypeUntypedPointerKHR Uniform
1359 %_ptr_Buffer = OpTypeUntypedPointerKHR StorageBuffer
1360 %18 = OpTypeBufferEXT Uniform
1361 %uint = OpTypeInt 32 0
1362 %uint_2 = OpConstant %uint 2
1363 %_runtimearr_18 = OpTypeRuntimeArray %18
1364 %main = OpFunction %void None %3
1365 %5 = OpLabel
1366 %17 = OpUntypedAccessChainKHR %_ptr_UniformConstant %_runtimearr_18 %resource_heap %int_3
1367 %22 = OpBufferPointerEXT %_ptr_Buffer %17
1368 %23 = OpUntypedAccessChainKHR %_ptr_Buffer %U %22 %int_0
1369 %24 = OpLoad %v2float %23
1370 OpStore %fragColor %24
1371 OpReturn
1372 OpFunctionEnd
1373 )";
1374 CompileSuccessfully(str.c_str(), SPV_ENV_VULKAN_1_3);
1375 EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_3));
1376 }
1377
1378 TEST_F(ValidateSpvEXTDescriptorHeap, MemberDecorateIdExtStruct) {
1379 const std::string str = R"(
1380 OpCapability Shader
1381 OpCapability DescriptorHeapEXT
1382 OpExtension "SPV_EXT_descriptor_heap"
1383 %1 = OpExtInstImport "GLSL.std.450"
1384 OpMemoryModel Logical GLSL450
1385 OpEntryPoint GLCompute %2 "main" %3 %4
1386 OpExecutionMode %2 LocalSize 1 1 1
1387 OpSource GLSL 450
1388 OpMemberDecorate %5 0 Offset 0
1389 OpDecorate %3 DescriptorSet 0
1390 OpDecorate %3 Binding 0
1391 OpDecorate %4 DescriptorSet 0
1392 OpDecorate %4 Binding 0
1393 OpDecorate %5 Block
1394 OpDecorate %6 Block
1395 OpDecorate %7 SpecId 0
1396 OpMemberDecorateIdEXT %11 0 OffsetIdEXT %7
1397 OpMemberDecorate %6 1 Offset 4
1398 OpMemberDecorateIdEXT %6 2 OffsetIdEXT %8
1399 %9 = OpTypeVoid
1400 %10 = OpTypeFunction %9
1401 %11 = OpTypeInt 32 0
1402 %5 = OpTypeStruct %11
1403 %12 = OpTypePointer StorageBuffer %5
1404 %13 = OpTypeImage %11 2D 0 0 0 1 Unknown
1405 %14 = OpTypeBufferEXT Uniform
1406 %15 = OpConstantSizeOfEXT %11 %13
1407 %16 = OpConstantSizeOfEXT %11 %14
1408 %17 = OpConstant %11 1
1409 %18 = OpConstant %11 8
1410 %19 = OpSpecConstantOp %11 IAdd %18 %15
1411 %20 = OpSpecConstantOp %11 ISub %19 %17
1412 %21 = OpSpecConstantOp %11 UDiv %20 %15
1413 %22 = OpSpecConstantOp %11 IMul %21 %15
1414 %23 = OpSpecConstantOp %11 IAdd %22 %15
1415 %24 = OpSpecConstantOp %11 IAdd %23 %16
1416 %25 = OpSpecConstantOp %11 ISub %24 %17
1417 %26 = OpSpecConstantOp %11 UDiv %25 %16
1418 %27 = OpSpecConstantOp %11 IMul %26 %16
1419 %8 = OpSpecConstantOp %11 IAdd %27 %16
1420 %7 = OpSpecConstant %11 4
1421 %3 = OpVariable %12 StorageBuffer
1422 %28 = OpConstant %11 0
1423 %6 = OpTypeStruct %11 %11 %11
1424 %29 = OpTypePointer Uniform %6
1425 %4 = OpVariable %29 Uniform
1426 %30 = OpTypePointer StorageBuffer %11
1427 %31 = OpConstant %11 2
1428 %2 = OpFunction %9 None %10
1429 %32 = OpLabel
1430 %33 = OpAccessChain %30 %4 %28
1431 %34 = OpLoad %11 %33
1432 %35 = OpAccessChain %30 %4 %31
1433 %36 = OpLoad %11 %35
1434 %37 = OpIAdd %11 %34 %36
1435 %38 = OpAccessChain %30 %3 %28
1436 OpStore %38 %37
1437 OpReturn
1438 OpFunctionEnd
1439 )";
1440 CompileSuccessfully(str.c_str(), SPV_ENV_VULKAN_1_3);
1441 EXPECT_NE(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_3));
1442 const std::string diag = getDiagnosticString();
1443 EXPECT_THAT(diag, HasSubstr("MemberDecorateIdEXT Structure type"));
1444 EXPECT_THAT(diag, HasSubstr("is not a struct type."));
1445 }
1446
1447 TEST_F(ValidateSpvEXTDescriptorHeap, DecorateIdArrayStrideIdEXT) {
1448 const std::string str = R"(
1449 OpCapability Shader
1450 OpCapability DescriptorHeapEXT
1451 OpExtension "SPV_EXT_descriptor_heap"
1452 %1 = OpExtInstImport "GLSL.std.450"
1453 OpMemoryModel Logical GLSL450
1454 OpEntryPoint GLCompute %2 "main" %3 %4
1455 OpExecutionMode %2 LocalSize 1 1 1
1456 OpSource GLSL 450
1457 OpMemberDecorate %5 0 Offset 0
1458 OpDecorate %3 DescriptorSet 0
1459 OpDecorate %3 Binding 0
1460 OpDecorate %4 DescriptorSet 0
1461 OpDecorate %4 Binding 0
1462 OpDecorate %5 Block
1463 OpDecorate %6 Block
1464 OpDecorate %7 SpecId 0
1465 OpDecorateId %5 ArrayStrideIdEXT %7
1466 OpMemberDecorate %6 1 Offset 4
1467 OpMemberDecorateIdEXT %6 2 OffsetIdEXT %8
1468 %9 = OpTypeVoid
1469 %10 = OpTypeFunction %9
1470 %11 = OpTypeInt 32 0
1471 %5 = OpTypeStruct %11
1472 %12 = OpTypePointer StorageBuffer %5
1473 %13 = OpTypeImage %11 2D 0 0 0 1 Unknown
1474 %14 = OpTypeBufferEXT Uniform
1475 %15 = OpConstantSizeOfEXT %11 %13
1476 %16 = OpConstantSizeOfEXT %11 %14
1477 %17 = OpConstant %11 1
1478 %18 = OpConstant %11 8
1479 %19 = OpSpecConstantOp %11 IAdd %18 %15
1480 %20 = OpSpecConstantOp %11 ISub %19 %17
1481 %21 = OpSpecConstantOp %11 UDiv %20 %15
1482 %22 = OpSpecConstantOp %11 IMul %21 %15
1483 %23 = OpSpecConstantOp %11 IAdd %22 %15
1484 %24 = OpSpecConstantOp %11 IAdd %23 %16
1485 %25 = OpSpecConstantOp %11 ISub %24 %17
1486 %26 = OpSpecConstantOp %11 UDiv %25 %16
1487 %27 = OpSpecConstantOp %11 IMul %26 %16
1488 %8 = OpSpecConstantOp %11 IAdd %27 %16
1489 %7 = OpSpecConstant %11 4
1490 %3 = OpVariable %12 StorageBuffer
1491 %28 = OpConstant %11 0
1492 %6 = OpTypeStruct %11 %11 %11
1493 %29 = OpTypePointer Uniform %6
1494 %4 = OpVariable %29 Uniform
1495 %30 = OpTypePointer StorageBuffer %11
1496 %31 = OpConstant %11 2
1497 %2 = OpFunction %9 None %10
1498 %32 = OpLabel
1499 %33 = OpAccessChain %30 %4 %28
1500 %34 = OpLoad %11 %33
1501 %35 = OpAccessChain %30 %4 %31
1502 %36 = OpLoad %11 %35
1503 %37 = OpIAdd %11 %34 %36
1504 %38 = OpAccessChain %30 %3 %28
1505 OpStore %38 %37
1506 OpReturn
1507 OpFunctionEnd
1508 )";
1509 CompileSuccessfully(str.c_str(), SPV_ENV_VULKAN_1_3);
1510 EXPECT_NE(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_3));
1511 const std::string diag = getDiagnosticString();
1512 EXPECT_THAT(
1513 diag,
1514 HasSubstr(
1515 "ArrayStrideIdEXT decoration must only be applied to array types."));
1516 }
1517
1518 TEST_F(ValidateSpvEXTDescriptorHeap, ArrayStrideNonDescriptor) {
1519 const std::string str = R"(
1520 OpCapability Shader
1521 OpCapability UntypedPointersKHR
1522 OpCapability DescriptorHeapEXT
1523 OpExtension "SPV_EXT_descriptor_heap"
1524 OpExtension "SPV_KHR_untyped_pointers"
1525 OpMemoryModel Logical GLSL450
1526 OpEntryPoint GLCompute %main "main" %resource_heap
1527 OpExecutionMode %main LocalSize 1 1 1
1528 OpDecorate %resource_heap BuiltIn ResourceHeapEXT
1529 OpDecorate %ssbo Block
1530 OpMemberDecorate %ssbo 0 BuiltIn ResourceHeapEXT
1531 OpMemberDecorate %ssbo 0 Offset 0
1532 OpDecorateId %_runtimearr_13 ArrayStrideIdEXT %16
1533 OpDecorateId %_runtimearr_24 ArrayStrideIdEXT %25
1534 %void = OpTypeVoid
1535 %3 = OpTypeFunction %void
1536 %_ptr_UniformConstant = OpTypeUntypedPointerKHR UniformConstant
1537 %resource_heap = OpUntypedVariableKHR %_ptr_UniformConstant UniformConstant
1538 %int = OpTypeInt 32 1
1539 %int_16 = OpConstant %int 16
1540 %v4int = OpTypeVector %int 4
1541 %ssbo = OpTypeStruct %v4int
1542 %int_0 = OpConstant %int 0
1543 %13 = OpTypeImage %int 2D 0 0 0 2 Rgba8i
1544 %_ptr_Uniform = OpTypeUntypedPointerKHR Uniform
1545 %16 = OpConstantSizeOfEXT %int %13
1546 %_runtimearr_13 = OpTypeRuntimeArray %13
1547 %24 = OpTypeBufferEXT StorageBuffer
1548 %25 = OpConstantSizeOfEXT %int %24
1549 %_runtimearr_24 = OpTypeRuntimeArray %int
1550 %main = OpFunction %void None %3
1551 %5 = OpLabel
1552 OpReturn
1553 OpFunctionEnd
1554 )";
1555 CompileSuccessfully(str.c_str(), SPV_ENV_VULKAN_1_3);
1556 EXPECT_NE(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_3));
1557 const std::string diag = getDiagnosticString();
1558 EXPECT_THAT(diag,
1559 HasSubstr("ArrayStrideIdEXT decoration must only be applied to "
1560 "array type containing a Descriptor type."));
1561 }
1562
1563 TEST_F(ValidateSpvEXTDescriptorHeap, MemberDecorateIdArrayStrideIdEXT) {
1564 const std::string str = R"(
1565 OpCapability Shader
1566 OpCapability DescriptorHeapEXT
1567 OpExtension "SPV_EXT_descriptor_heap"
1568 %1 = OpExtInstImport "GLSL.std.450"
1569 OpMemoryModel Logical GLSL450
1570 OpEntryPoint GLCompute %2 "main" %3 %4
1571 OpExecutionMode %2 LocalSize 1 1 1
1572 OpSource GLSL 450
1573 OpMemberDecorate %5 0 Offset 0
1574 OpDecorate %3 DescriptorSet 0
1575 OpDecorate %3 Binding 0
1576 OpDecorate %4 DescriptorSet 0
1577 OpDecorate %4 Binding 0
1578 OpDecorate %5 Block
1579 OpDecorate %6 Block
1580 OpDecorate %7 SpecId 0
1581 OpMemberDecorateIdEXT %6 0 ArrayStrideIdEXT %7
1582 OpMemberDecorate %6 1 Offset 4
1583 OpMemberDecorateIdEXT %6 2 OffsetIdEXT %8
1584 %9 = OpTypeVoid
1585 %10 = OpTypeFunction %9
1586 %11 = OpTypeInt 32 0
1587 %5 = OpTypeStruct %11
1588 %12 = OpTypePointer StorageBuffer %5
1589 %13 = OpTypeImage %11 2D 0 0 0 1 Unknown
1590 %14 = OpTypeBufferEXT Uniform
1591 %15 = OpConstantSizeOfEXT %11 %13
1592 %16 = OpConstantSizeOfEXT %11 %14
1593 %17 = OpConstant %11 1
1594 %18 = OpConstant %11 8
1595 %19 = OpSpecConstantOp %11 IAdd %18 %15
1596 %20 = OpSpecConstantOp %11 ISub %19 %17
1597 %21 = OpSpecConstantOp %11 UDiv %20 %15
1598 %22 = OpSpecConstantOp %11 IMul %21 %15
1599 %23 = OpSpecConstantOp %11 IAdd %22 %15
1600 %24 = OpSpecConstantOp %11 IAdd %23 %16
1601 %25 = OpSpecConstantOp %11 ISub %24 %17
1602 %26 = OpSpecConstantOp %11 UDiv %25 %16
1603 %27 = OpSpecConstantOp %11 IMul %26 %16
1604 %8 = OpSpecConstantOp %11 IAdd %27 %16
1605 %7 = OpSpecConstant %11 4
1606 %3 = OpVariable %12 StorageBuffer
1607 %28 = OpConstant %11 0
1608 %6 = OpTypeStruct %11 %11 %11
1609 %29 = OpTypePointer Uniform %6
1610 %4 = OpVariable %29 Uniform
1611 %30 = OpTypePointer StorageBuffer %11
1612 %31 = OpConstant %11 2
1613 %2 = OpFunction %9 None %10
1614 %32 = OpLabel
1615 %33 = OpAccessChain %30 %4 %28
1616 %34 = OpLoad %11 %33
1617 %35 = OpAccessChain %30 %4 %31
1618 %36 = OpLoad %11 %35
1619 %37 = OpIAdd %11 %34 %36
1620 %38 = OpAccessChain %30 %3 %28
1621 OpStore %38 %37
1622 OpReturn
1623 OpFunctionEnd
1624 )";
1625 CompileSuccessfully(str.c_str(), SPV_ENV_VULKAN_1_3);
1626 EXPECT_NE(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_3));
1627 const std::string diag = getDiagnosticString();
1628 EXPECT_THAT(diag, HasSubstr("ArrayStrideIdEXT could only be directly applied "
1629 "to array type using OpDecorateId."));
1630 }
1631
1632 TEST_F(ValidateSpvEXTDescriptorHeap, MemberDecorateIdOffsetIdEXT) {
1633 const std::string str = R"(
1634 OpCapability Shader
1635 OpCapability DescriptorHeapEXT
1636 OpExtension "SPV_EXT_descriptor_heap"
1637 %1 = OpExtInstImport "GLSL.std.450"
1638 OpMemoryModel Logical GLSL450
1639 OpEntryPoint GLCompute %2 "main" %3 %4
1640 OpExecutionMode %2 LocalSize 1 1 1
1641 OpSource GLSL 450
1642 OpMemberDecorate %5 0 Offset 0
1643 OpDecorate %3 DescriptorSet 0
1644 OpDecorate %3 Binding 0
1645 OpDecorate %4 DescriptorSet 0
1646 OpDecorate %4 Binding 0
1647 OpDecorate %5 Block
1648 OpDecorate %6 Block
1649 OpDecorate %7 SpecId 0
1650 OpMemberDecorateIdEXT %6 0 OffsetIdEXT %7
1651 OpMemberDecorate %6 1 Offset 4
1652 OpMemberDecorateIdEXT %6 2 ArrayStrideIdEXT %8
1653 %9 = OpTypeVoid
1654 %10 = OpTypeFunction %9
1655 %11 = OpTypeInt 32 0
1656 %5 = OpTypeStruct %11
1657 %12 = OpTypePointer StorageBuffer %5
1658 %13 = OpTypeImage %11 2D 0 0 0 1 Unknown
1659 %14 = OpTypeBufferEXT Uniform
1660 %15 = OpConstantSizeOfEXT %11 %13
1661 %16 = OpConstantSizeOfEXT %11 %14
1662 %17 = OpConstant %11 1
1663 %18 = OpConstant %11 8
1664 %19 = OpSpecConstantOp %11 IAdd %18 %15
1665 %20 = OpSpecConstantOp %11 ISub %19 %17
1666 %21 = OpSpecConstantOp %11 UDiv %20 %15
1667 %22 = OpSpecConstantOp %11 IMul %21 %15
1668 %23 = OpSpecConstantOp %11 IAdd %22 %15
1669 %24 = OpSpecConstantOp %11 IAdd %23 %16
1670 %25 = OpSpecConstantOp %11 ISub %24 %17
1671 %26 = OpSpecConstantOp %11 UDiv %25 %16
1672 %27 = OpSpecConstantOp %11 IMul %26 %16
1673 %8 = OpSpecConstantOp %11 IAdd %27 %16
1674 %7 = OpSpecConstant %11 4
1675 %3 = OpVariable %12 StorageBuffer
1676 %28 = OpConstant %11 0
1677 %6 = OpTypeStruct %11 %11 %11
1678 %29 = OpTypePointer Uniform %6
1679 %4 = OpVariable %29 Uniform
1680 %30 = OpTypePointer StorageBuffer %11
1681 %31 = OpConstant %11 2
1682 %2 = OpFunction %9 None %10
1683 %32 = OpLabel
1684 %33 = OpAccessChain %30 %4 %28
1685 %34 = OpLoad %11 %33
1686 %35 = OpAccessChain %30 %4 %31
1687 %36 = OpLoad %11 %35
1688 %37 = OpIAdd %11 %34 %36
1689 %38 = OpAccessChain %30 %3 %28
1690 OpStore %38 %37
1691 OpReturn
1692 OpFunctionEnd
1693 )";
1694 CompileSuccessfully(str.c_str(), SPV_ENV_VULKAN_1_3);
1695 EXPECT_NE(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_3));
1696 const std::string diag = getDiagnosticString();
1697 EXPECT_THAT(
1698 diag,
1699 HasSubstr(
1700 "OffsetIdEXT decoration in MemberDecorateIdEXT must only be applied "
1701 "to members of structs where the struct contains descriptor types."));
1702 }
1703
1704 TEST_F(ValidateSpvEXTDescriptorHeap, OffsetIdAllSingleImages) {
1705 const std::string str = R"(
1706 OpCapability Shader
1707 OpCapability UntypedPointersKHR
1708 OpCapability DescriptorHeapEXT
1709 OpCapability ImageBuffer
1710 OpExtension "SPV_KHR_untyped_pointers"
1711 OpExtension "SPV_EXT_descriptor_heap"
1712 OpMemoryModel Logical GLSL450
1713 OpEntryPoint GLCompute %1 "main" %2
1714 OpExecutionMode %1 LocalSize 1 1 1
1715 OpDecorate %2 BuiltIn ResourceHeapEXT
1716 OpMemberDecorate %_struct_3 0 Offset 0
1717 OpMemberDecorateIdEXT %_struct_3 1 OffsetIdEXT %uint_0
1718 OpMemberDecorate %_struct_3 2 Offset 16
1719 %void = OpTypeVoid
1720 %7 = OpTypeFunction %void
1721 %uint = OpTypeInt 32 0
1722 %uint_0 = OpConstant %uint 0
1723 %uint_2 = OpConstant %uint 2
1724 %uint_51966 = OpConstant %uint 51966
1725 %uint_0_0 = OpConstant %uint 0
1726 %_ptr_UniformConstant = OpTypeUntypedPointerKHR UniformConstant
1727 %2 = OpUntypedVariableKHR %_ptr_UniformConstant UniformConstant
1728 %14 = OpTypeImage %uint Buffer 0 0 0 2 R32ui
1729 %_struct_3 = OpTypeStruct %14 %14 %14
1730 %1 = OpFunction %void None %7
1731 %15 = OpLabel
1732 %16 = OpUntypedAccessChainKHR %_ptr_UniformConstant %_struct_3 %2 %uint_2
1733 %17 = OpLoad %14 %16
1734 OpImageWrite %17 %uint_0 %uint_51966
1735 OpReturn
1736 OpFunctionEnd
1737 )";
1738 CompileSuccessfully(str.c_str(), SPV_ENV_VULKAN_1_4);
1739 EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_4));
1740 }
1741
1742 TEST_F(ValidateSpvEXTDescriptorHeap, OffsetIdAllImages) {
1743 const std::string str = R"(
1744 OpCapability Shader
1745 OpCapability UntypedPointersKHR
1746 OpCapability DescriptorHeapEXT
1747 OpCapability ImageBuffer
1748 OpExtension "SPV_KHR_untyped_pointers"
1749 OpExtension "SPV_EXT_descriptor_heap"
1750 OpMemoryModel Logical GLSL450
1751 OpEntryPoint GLCompute %1 "main" %2
1752 OpExecutionMode %1 LocalSize 1 1 1
1753 OpDecorate %2 BuiltIn ResourceHeapEXT
1754 OpDecorate %4 SpecId 0
1755 OpMemberDecorate %_struct_3 0 Offset 0
1756 OpMemberDecorateIdEXT %_struct_3 1 OffsetIdEXT %4
1757 OpMemberDecorateIdEXT %_struct_3 2 OffsetIdEXT %5
1758 %void = OpTypeVoid
1759 %7 = OpTypeFunction %void
1760 %uint = OpTypeInt 32 0
1761 %uint_0 = OpConstant %uint 0
1762 %uint_2 = OpConstant %uint 2
1763 %uint_51966 = OpConstant %uint 51966
1764 %uint_0_0 = OpConstant %uint 0
1765 %4 = OpSpecConstant %uint 0
1766 %5 = OpSpecConstantOp %uint IMul %4 %uint_2
1767 %_ptr_UniformConstant = OpTypeUntypedPointerKHR UniformConstant
1768 %2 = OpUntypedVariableKHR %_ptr_UniformConstant UniformConstant
1769 %14 = OpTypeImage %uint Buffer 0 0 0 2 R32ui
1770 %_struct_3 = OpTypeStruct %14 %14 %14
1771 %1 = OpFunction %void None %7
1772 %15 = OpLabel
1773 %16 = OpUntypedAccessChainKHR %_ptr_UniformConstant %_struct_3 %2 %uint_2
1774 %17 = OpLoad %14 %16
1775 OpImageWrite %17 %uint_0 %uint_51966
1776 OpReturn
1777 OpFunctionEnd
1778 )";
1779 CompileSuccessfully(str.c_str(), SPV_ENV_VULKAN_1_4);
1780 EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_4));
1781 }
1782
1783 TEST_F(ValidateSpvEXTDescriptorHeap, OffsetIdStructOfStructOfImage) {
1784 const std::string str = R"(
1785 OpCapability Shader
1786 OpCapability UntypedPointersKHR
1787 OpCapability DescriptorHeapEXT
1788 OpCapability ImageBuffer
1789 OpExtension "SPV_KHR_untyped_pointers"
1790 OpExtension "SPV_EXT_descriptor_heap"
1791 OpMemoryModel Logical GLSL450
1792 OpEntryPoint GLCompute %1 "main" %2
1793 OpExecutionMode %1 LocalSize 1 1 1
1794 OpDecorate %2 BuiltIn ResourceHeapEXT
1795 OpMemberDecorate %struct 0 Offset 0
1796 OpMemberDecorateIdEXT %struct 1 OffsetIdEXT %uint_0
1797 OpMemberDecorate %image_struct 0 Offset 0
1798 %void = OpTypeVoid
1799 %7 = OpTypeFunction %void
1800 %uint = OpTypeInt 32 0
1801 %uint_0 = OpConstant %uint 0
1802 %uint_1 = OpConstant %uint 1
1803 %uint_51966 = OpConstant %uint 51966
1804 %uint_0_0 = OpConstant %uint 0
1805 %_ptr_UniformConstant = OpTypeUntypedPointerKHR UniformConstant
1806 %2 = OpUntypedVariableKHR %_ptr_UniformConstant UniformConstant
1807 %14 = OpTypeImage %uint Buffer 0 0 0 2 R32ui
1808 %image_struct = OpTypeStruct %14
1809 %struct = OpTypeStruct %uint %image_struct
1810 %1 = OpFunction %void None %7
1811 %15 = OpLabel
1812 %16 = OpUntypedAccessChainKHR %_ptr_UniformConstant %struct %2 %uint_1 %uint_0
1813 %17 = OpLoad %14 %16
1814 OpImageWrite %17 %uint_0 %uint_51966
1815 OpReturn
1816 OpFunctionEnd
1817 )";
1818 CompileSuccessfully(str.c_str(), SPV_ENV_VULKAN_1_4);
1819 EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_4));
1820 }
1821
1822 TEST_F(ValidateSpvEXTDescriptorHeap, MemberDecorateIdDecorator) {
1823 const std::string str = R"(
1824 OpCapability Shader
1825 OpCapability UntypedPointersKHR
1826 OpCapability DescriptorHeapEXT
1827 OpCapability BindlessTextureNV
1828 OpExtension "SPV_EXT_descriptor_heap"
1829 OpExtension "SPV_KHR_untyped_pointers"
1830 OpExtension "SPV_NV_bindless_texture"
1831 %1 = OpExtInstImport "GLSL.std.450"
1832 OpMemoryModel Logical GLSL450
1833 OpSamplerImageAddressingModeNV 64
1834 OpEntryPoint Fragment %main "main" %resource_heap %fragColor
1835 OpExecutionMode %main OriginUpperLeft
1836 OpSource GLSL 460
1837 OpSourceExtension "GL_EXT_descriptor_heap"
1838 OpSourceExtension "GL_EXT_nonuniform_qualifier"
1839 OpName %main "main"
1840 OpName %fragColor "fragColor"
1841 OpName %resource_heap "resource_heap"
1842 OpName %U "U"
1843 OpMemberName %U 0 "uv"
1844 OpMemberName %U 1 "k"
1845 OpMemberName %U 2 "g"
1846 OpDecorate %fragColor Location 0
1847 OpDecorate %resource_heap BuiltIn ResourceHeapEXT
1848 OpDecorate %U Block
1849 OpMemberDecorate %U 0 Offset 0
1850 OpMemberDecorate %U 1 Offset 8
1851 OpMemberDecorateIdEXT %U 2 Offset 0
1852 OpDecorateId %_runtimearr_20 ArrayStrideIdEXT %uint_2
1853 %void = OpTypeVoid
1854 %3 = OpTypeFunction %void
1855 %float = OpTypeFloat 32
1856 %v2float = OpTypeVector %float 2
1857 %_ptr_Output_v2float = OpTypePointer Output %v2float
1858 %fragColor = OpVariable %_ptr_Output_v2float Output
1859 %_ptr_UniformConstant = OpTypeUntypedPointerKHR UniformConstant
1860 %resource_heap = OpUntypedVariableKHR %_ptr_UniformConstant UniformConstant
1861 %int = OpTypeInt 32 1
1862 %int_3 = OpConstant %int 3
1863 %uint = OpTypeInt 32 0
1864 %v3uint = OpTypeVector %uint 3
1865 %specC = OpSpecConstant %int 4
1866 %samplerTy = OpTypeSampler
1867 %_runtimearr_sampler = OpTypeRuntimeArray %samplerTy
1868 %U = OpTypeStruct %v2float %int %_runtimearr_sampler
1869 %int_0 = OpConstant %int 0
1870 %_ptr_Uniform = OpTypeUntypedPointerKHR Uniform
1871 %20 = OpTypeBufferEXT Uniform
1872 %uint_2 = OpConstant %uint 2
1873 %_runtimearr_20 = OpTypeRuntimeArray %20
1874 %main = OpFunction %void None %3
1875 %5 = OpLabel
1876 %19 = OpUntypedAccessChainKHR %_ptr_Uniform %_runtimearr_20 %resource_heap %int_3
1877 %23 = OpBufferPointerEXT %_ptr_Uniform %19
1878 %24 = OpUntypedAccessChainKHR %_ptr_Uniform %U %23 %int_0
1879 %25 = OpLoad %v2float %24
1880 OpStore %fragColor %25
1881 OpReturn
1882 OpFunctionEnd
1883 )";
1884 CompileSuccessfully(str.c_str(), SPV_ENV_VULKAN_1_4);
1885 EXPECT_NE(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_4));
1886 const std::string diag = getDiagnosticString();
1887 EXPECT_THAT(diag, HasSubstr("Decoration operand could only be OffsetIdEXT."));
1888 }
1889
1890 TEST_F(ValidateSpvEXTDescriptorHeap, MemberDecorateIdExtraIdOrder) {
1891 const std::string str = R"(
1892 OpCapability Shader
1893 OpCapability UntypedPointersKHR
1894 OpCapability DescriptorHeapEXT
1895 OpCapability BindlessTextureNV
1896 OpExtension "SPV_EXT_descriptor_heap"
1897 OpExtension "SPV_KHR_untyped_pointers"
1898 OpExtension "SPV_NV_bindless_texture"
1899 %1 = OpExtInstImport "GLSL.std.450"
1900 OpMemoryModel Logical GLSL450
1901 OpSamplerImageAddressingModeNV 64
1902 OpEntryPoint Fragment %main "main" %resource_heap %fragColor
1903 OpExecutionMode %main OriginUpperLeft
1904 OpSource GLSL 460
1905 OpSourceExtension "GL_EXT_descriptor_heap"
1906 OpSourceExtension "GL_EXT_nonuniform_qualifier"
1907 OpName %main "main"
1908 OpName %fragColor "fragColor"
1909 OpName %resource_heap "resource_heap"
1910 OpName %U "U"
1911 OpMemberName %U 0 "uv"
1912 OpMemberName %U 1 "k"
1913 OpMemberName %U 2 "g"
1914 OpDecorate %fragColor Location 0
1915 OpDecorate %resource_heap BuiltIn ResourceHeapEXT
1916 OpDecorate %U Block
1917 OpMemberDecorate %U 0 Offset 0
1918 OpMemberDecorate %U 1 Offset 8
1919 OpMemberDecorateIdEXT %U 2 OffsetIdEXT %specC
1920 OpDecorateId %_runtimearr_20 ArrayStrideIdEXT %uint_2
1921 %void = OpTypeVoid
1922 %3 = OpTypeFunction %void
1923 %float = OpTypeFloat 32
1924 %v2float = OpTypeVector %float 2
1925 %_ptr_Output_v2float = OpTypePointer Output %v2float
1926 %fragColor = OpVariable %_ptr_Output_v2float Output
1927 %_ptr_UniformConstant = OpTypeUntypedPointerKHR UniformConstant
1928 %resource_heap = OpUntypedVariableKHR %_ptr_UniformConstant UniformConstant
1929 %int = OpTypeInt 32 1
1930 %int_3 = OpConstant %int 3
1931 %uint = OpTypeInt 32 0
1932 %v3uint = OpTypeVector %uint 3
1933 %samplerTy = OpTypeSampler
1934 %_runtimearr_sampler = OpTypeRuntimeArray %samplerTy
1935 %U = OpTypeStruct %v2float %int %_runtimearr_sampler
1936 %specC = OpSpecConstant %int 4
1937 %int_0 = OpConstant %int 0
1938 %_ptr_Uniform = OpTypeUntypedPointerKHR Uniform
1939 %20 = OpTypeBufferEXT Uniform
1940 %uint_2 = OpConstant %uint 2
1941 %_runtimearr_20 = OpTypeRuntimeArray %20
1942 %main = OpFunction %void None %3
1943 %5 = OpLabel
1944 %19 = OpUntypedAccessChainKHR %_ptr_Uniform %_runtimearr_20 %resource_heap %int_3
1945 %23 = OpBufferPointerEXT %_ptr_Uniform %19
1946 %24 = OpUntypedAccessChainKHR %_ptr_Uniform %U %23 %int_0
1947 %25 = OpLoad %v2float %24
1948 OpStore %fragColor %25
1949 OpReturn
1950 OpFunctionEnd
1951 )";
1952 CompileSuccessfully(str.c_str(), SPV_ENV_VULKAN_1_4);
1953 EXPECT_NE(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_4));
1954 const std::string diag = getDiagnosticString();
1955 EXPECT_THAT(
1956 diag,
1957 HasSubstr("All <id> Extra Operands must appear before Structure Type."));
1958 }
1959
1960 TEST_F(ValidateSpvEXTDescriptorHeap, OpMemberDecorateIdDuplicateOffset) {
1961 const std::string str = R"(
1962 OpCapability Shader
1963 OpCapability SampledBuffer
1964 OpCapability DescriptorHeapEXT
1965 OpExtension "SPV_EXT_descriptor_heap"
1966 OpMemoryModel Logical GLSL450
1967 OpEntryPoint GLCompute %main "main"
1968 OpExecutionMode %main LocalSize 1 1 1
1969 OpMemberDecorateIdEXT %struct 0 OffsetIdEXT %uint_0
1970 OpMemberDecorateIdEXT %struct 1 OffsetIdEXT %uint_0
1971 OpMemberDecorateIdEXT %struct 1 OffsetIdEXT %uint_0
1972 OpMemberDecorateIdEXT %struct 2 OffsetIdEXT %uint_0
1973 %uint = OpTypeInt 32 0
1974 %uint_0 = OpConstant %uint 0
1975 %14 = OpTypeImage %uint Buffer 0 0 0 2 R32ui
1976 %struct = OpTypeStruct %14 %uint %uint
1977 %void = OpTypeVoid
1978 %3 = OpTypeFunction %void
1979 %main = OpFunction %void None %3
1980 %5 = OpLabel
1981 OpReturn
1982 OpFunctionEnd
1983
1984 )";
1985 CompileSuccessfully(str.c_str(), SPV_ENV_VULKAN_1_4);
1986 EXPECT_NE(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_4));
1987 EXPECT_THAT(getDiagnosticString(),
1988 HasSubstr("member '1' decorated with OffsetIdEXT multiple times "
1989 "is not allowed"));
1990 }
1991
1992 TEST_F(ValidateSpvEXTDescriptorHeap, OffsetAndOffsetId) {
1993 const std::string str = R"(
1994 OpCapability Shader
1995 OpCapability SampledBuffer
1996 OpCapability DescriptorHeapEXT
1997 OpExtension "SPV_EXT_descriptor_heap"
1998 OpMemoryModel Logical GLSL450
1999 OpEntryPoint GLCompute %main "main"
2000 OpExecutionMode %main LocalSize 1 1 1
2001 OpMemberDecorate %struct 0 Offset 0
2002 OpMemberDecorateIdEXT %struct 0 OffsetIdEXT %uint_0
2003 OpMemberDecorateIdEXT %struct 1 OffsetIdEXT %uint_0
2004 OpMemberDecorateIdEXT %struct 2 OffsetIdEXT %uint_0
2005 %uint = OpTypeInt 32 0
2006 %uint_0 = OpConstant %uint 0
2007 %14 = OpTypeImage %uint Buffer 0 0 0 2 R32ui
2008 %struct = OpTypeStruct %14 %uint %uint
2009 %void = OpTypeVoid
2010 %3 = OpTypeFunction %void
2011 %main = OpFunction %void None %3
2012 %5 = OpLabel
2013 OpReturn
2014 OpFunctionEnd
2015
2016 )";
2017 CompileSuccessfully(str.c_str(), SPV_ENV_VULKAN_1_4);
2018 EXPECT_NE(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_4));
2019 EXPECT_THAT(getDiagnosticString(),
2020 HasSubstr("member '0' decorated with both OffsetIdEXT and Offset "
2021 "is not allowed"));
2022 }
2023
2024 TEST_F(ValidateSpvEXTDescriptorHeap, AtomicImageType) {
2025 const std::string str = R"(
2026 OpCapability Shader
2027 OpCapability Image1D
2028 OpCapability UntypedPointersKHR
2029 OpCapability DescriptorHeapEXT
2030 OpExtension "SPV_EXT_descriptor_heap"
2031 OpExtension "SPV_KHR_untyped_pointers"
2032 %1 = OpExtInstImport "GLSL.std.450"
2033 OpMemoryModel Logical GLSL450
2034 OpEntryPoint GLCompute %main "main" %resource_heap
2035 OpExecutionMode %main LocalSize 1 1 1
2036 OpSource GLSL 460
2037 OpSourceExtension "GL_EXT_descriptor_heap"
2038 OpName %main "main"
2039 OpName %resource_heap "resource_heap"
2040 OpDecorate %resource_heap BuiltIn ResourceHeapEXT
2041 OpDecorateId %_runtimearr_10 ArrayStrideIdEXT %13
2042 %void = OpTypeVoid
2043 %3 = OpTypeFunction %void
2044 %_ptr_UniformConstant = OpTypeUntypedPointerKHR UniformConstant
2045 %resource_heap = OpUntypedVariableKHR %_ptr_UniformConstant UniformConstant
2046 %int = OpTypeInt 32 1
2047 %int_1 = OpConstant %int 1
2048 %10 = OpTypeImage %int 1D 0 0 0 2 Rgba16i
2049 %13 = OpConstantSizeOfEXT %int %10
2050 %_runtimearr_10 = OpTypeRuntimeArray %10
2051 %uint = OpTypeInt 32 0
2052 %uint_0 = OpConstant %uint 0
2053 %_ptr_Image_int = OpTypePointer Image %int
2054 %_ptr_Image = OpTypeUntypedPointerKHR Image
2055 %uint_1 = OpConstant %uint 1
2056 %main = OpFunction %void None %3
2057 %5 = OpLabel
2058 %12 = OpUntypedAccessChainKHR %_ptr_UniformConstant %_runtimearr_10 %resource_heap %int_1
2059 %19 = OpUntypedImageTexelPointerEXT %_ptr_Image %10 %12 %int_1 %uint_0
2060 %21 = OpAtomicIAdd %int %19 %uint_1 %uint_0 %int_1
2061 OpReturn
2062 OpFunctionEnd
2063 )";
2064 CompileSuccessfully(str.c_str(), SPV_ENV_VULKAN_1_4);
2065 EXPECT_NE(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_4));
2066 const std::string diag = getDiagnosticString();
2067 EXPECT_THAT(
2068 diag,
2069 AnyVUID("VUID-StandaloneSpirv-OpUntypedImageTexelPointerEXT-11416"));
2070 EXPECT_THAT(diag,
2071 HasSubstr("Expected the Image Format in Image to be R64i, R64ui, "
2072 "R32f, R32i, or R32ui for Vulkan environment using "
2073 "OpUntypedImageTexelPointerEXT"));
2074 }
2075
2076 TEST_F(ValidateSpvEXTDescriptorHeap, UntypedPointerStorageClass) {
2077 const std::string str = R"(
2078 OpCapability Shader
2079 OpCapability Image1D
2080 OpCapability UntypedPointersKHR
2081 OpCapability DescriptorHeapEXT
2082 OpExtension "SPV_EXT_descriptor_heap"
2083 OpExtension "SPV_KHR_untyped_pointers"
2084 %1 = OpExtInstImport "GLSL.std.450"
2085 OpMemoryModel Logical GLSL450
2086 OpEntryPoint GLCompute %main "main" %resource_heap
2087 OpExecutionMode %main LocalSize 1 1 1
2088 OpSource GLSL 460
2089 OpSourceExtension "GL_EXT_descriptor_heap"
2090 OpName %main "main"
2091 OpName %resource_heap "resource_heap"
2092 OpDecorate %resource_heap BuiltIn ResourceHeapEXT
2093 OpDecorateId %_runtimearr_10 ArrayStrideIdEXT %13
2094 %void = OpTypeVoid
2095 %3 = OpTypeFunction %void
2096 %_ptr_UniformConstant = OpTypeUntypedPointerKHR UniformConstant
2097 %resource_heap = OpUntypedVariableKHR %_ptr_UniformConstant UniformConstant
2098 %int = OpTypeInt 32 1
2099 %int_1 = OpConstant %int 1
2100 %10 = OpTypeImage %int 1D 0 0 0 2 R32i
2101 %_ptr_Uniform = OpTypeUntypedPointerKHR Private
2102 %13 = OpConstantSizeOfEXT %int %10
2103 %_runtimearr_10 = OpTypeRuntimeArray %10
2104 %uint = OpTypeInt 32 0
2105 %uint_0 = OpConstant %uint 0
2106 %_ptr_Image_int = OpTypePointer Image %int
2107 %_ptr_Image = OpTypeUntypedPointerKHR Image
2108 %uint_1 = OpConstant %uint 1
2109 %main = OpFunction %void None %3
2110 %5 = OpLabel
2111 %12 = OpUntypedAccessChainKHR %_ptr_Uniform %_runtimearr_10 %resource_heap %int_1
2112 %19 = OpUntypedImageTexelPointerEXT %_ptr_Image %10 %12 %int_1 %uint_0
2113 %21 = OpAtomicIAdd %int %19 %uint_1 %uint_0 %int_1
2114 OpReturn
2115 OpFunctionEnd
2116 )";
2117 CompileSuccessfully(str.c_str(), SPV_ENV_VULKAN_1_4);
2118 EXPECT_NE(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_4));
2119 const std::string diag = getDiagnosticString();
2120 EXPECT_THAT(diag,
2121 AnyVUID("VUID-StandaloneSpirv-OpTypeUntypedPointerKHR-11417"));
2122 EXPECT_THAT(diag, HasSubstr("In Vulkan, untyped pointers can only be used "
2123 "in an explicitly laid out storage class"));
2124 }
2125
2126 TEST_F(ValidateSpvEXTDescriptorHeap, InvalidStoreToHeap) {
2127 const std::string str = R"(
2128 OpCapability Shader
2129 OpCapability UntypedPointersKHR
2130 OpCapability DescriptorHeapEXT
2131 OpExtension "SPV_EXT_descriptor_heap"
2132 OpExtension "SPV_KHR_untyped_pointers"
2133 %1 = OpExtInstImport "GLSL.std.450"
2134 OpMemoryModel Logical GLSL450
2135 OpEntryPoint GLCompute %main "main" %resource_heap %_
2136 OpExecutionMode %main LocalSize 1 1 1
2137 OpSource GLSL 450
2138 OpSourceExtension "GL_EXT_descriptor_heap"
2139 OpName %main "main"
2140 OpName %resource_heap "resource_heap"
2141 OpName %A "A"
2142 OpMemberName %A 0 "a"
2143 OpName %PushConstant "PushConstant"
2144 OpMemberName %PushConstant 0 "b"
2145 OpName %_ ""
2146 OpDecorate %resource_heap BuiltIn ResourceHeapEXT
2147 OpDecorate %A Block
2148 OpMemberDecorate %A 0 BuiltIn ResourceHeapEXT
2149 OpMemberDecorate %A 0 Offset 0
2150 OpDecorate %PushConstant Block
2151 OpMemberDecorate %PushConstant 0 Offset 0
2152 OpDecorateId %_runtimearr_20 ArrayStrideIdEXT %21
2153 %void = OpTypeVoid
2154 %3 = OpTypeFunction %void
2155 %_ptr_UniformConstant = OpTypeUntypedPointerKHR UniformConstant
2156 %resource_heap = OpUntypedVariableKHR %_ptr_UniformConstant UniformConstant
2157 %int = OpTypeInt 32 1
2158 %int_0 = OpConstant %int 0
2159 %uint = OpTypeInt 32 0
2160 %A = OpTypeStruct %uint
2161 %PushConstant = OpTypeStruct %uint
2162 %_ptr_PushConstant_PushConstant = OpTypePointer PushConstant %PushConstant
2163 %_ = OpVariable %_ptr_PushConstant_PushConstant PushConstant
2164 %_ptr_PushConstant_uint = OpTypePointer PushConstant %uint
2165 %_ptr_StorageBuffer = OpTypeUntypedPointerKHR StorageBuffer
2166 %20 = OpTypeBufferEXT StorageBuffer
2167 %21 = OpConstantSizeOfEXT %int %20
2168 %_runtimearr_20 = OpTypeRuntimeArray %20
2169 %v3uint = OpTypeVector %uint 3
2170 %uint_1 = OpConstant %uint 1
2171 %27 = OpConstantComposite %v3uint %uint_1 %uint_1 %uint_1
2172 %main = OpFunction %void None %3
2173 %5 = OpLabel
2174 %16 = OpAccessChain %_ptr_PushConstant_uint %_ %int_0
2175 %17 = OpLoad %uint %16
2176 OpStore %resource_heap %17
2177 OpReturn
2178 OpFunctionEnd
2179 )";
2180 CompileSuccessfully(str.c_str(), SPV_ENV_VULKAN_1_4);
2181 EXPECT_NE(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_4));
2182 const std::string diag = getDiagnosticString();
2183 EXPECT_THAT(diag, HasSubstr("OpStore Pointer <id>"));
2184 EXPECT_THAT(diag, HasSubstr("storage class is read-only"));
2185 }
2186
2187 TEST_F(ValidateSpvEXTDescriptorHeap, NonDescriptorOpaqueType) {
2188 std::string spirv = R"(
2189 OpCapability Shader
2190 OpCapability DescriptorHeapEXT
2191 OpExtension "SPV_EXT_descriptor_heap"
2192 OpMemoryModel Logical GLSL450
2193 OpEntryPoint Vertex %main "main"
2194 %float = OpTypeFloat 32
2195 %image = OpTypeImage %float 2D 0 0 0 1 Unknown
2196 %sampled = OpTypeSampledImage %image
2197 %struct = OpTypeStruct %sampled
2198 %void = OpTypeVoid
2199 %func = OpTypeFunction %void
2200 %main = OpFunction %void None %func
2201 %l = OpLabel
2202 OpReturn
2203 OpFunctionEnd
2204 )";
2205 CompileSuccessfully(spirv.c_str(), SPV_ENV_VULKAN_1_4);
2206 EXPECT_NE(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_4));
2207 const std::string diag = getDiagnosticString();
2208 EXPECT_THAT(diag, AnyVUID("VUID-StandaloneSpirv-DescriptorHeapEXT-11482"));
2209 EXPECT_THAT(
2210 diag,
2211 HasSubstr(
2212 "In Vulkan, OpTypeStruct must not contain an invalid opaque type."));
2213 }
2214
2215 TEST_F(ValidateSpvEXTDescriptorHeap, ResourceHeapBuiltinOnMemeber) {
2216 std::string spirv = R"(
2217 OpCapability Shader
2218 OpCapability UntypedPointersKHR
2219 OpCapability DescriptorHeapEXT
2220 OpExtension "SPV_EXT_descriptor_heap"
2221 OpExtension "SPV_KHR_untyped_pointers"
2222 OpMemoryModel Logical GLSL450
2223 OpEntryPoint GLCompute %main "main" %resource_heap %_
2224 OpExecutionMode %main LocalSize 1 1 1
2225 OpDecorate %resource_heap BuiltIn ResourceHeapEXT
2226 OpDecorate %A Block
2227 OpMemberDecorate %A 0 BuiltIn ResourceHeapEXT
2228 OpMemberDecorate %A 0 Offset 0
2229 OpDecorate %PushConstant Block
2230 OpMemberDecorate %PushConstant 0 Offset 0
2231 OpDecorateId %_runtimearr_21 ArrayStrideIdEXT %22
2232 %void = OpTypeVoid
2233 %3 = OpTypeFunction %void
2234 %_ptr_UniformConstant = OpTypeUntypedPointerKHR UniformConstant
2235 %resource_heap = OpUntypedVariableKHR %_ptr_UniformConstant UniformConstant
2236 %int = OpTypeInt 32 1
2237 %int_2 = OpConstant %int 2
2238 %uint = OpTypeInt 32 0
2239 %A = OpTypeStruct %uint
2240 %int_0 = OpConstant %int 0
2241 %PushConstant = OpTypeStruct %uint
2242 %_ptr_PushConstant_PushConstant = OpTypePointer PushConstant %PushConstant
2243 %_ = OpVariable %_ptr_PushConstant_PushConstant PushConstant
2244 %_ptr_PushConstant_uint = OpTypePointer PushConstant %uint
2245 %_ptr_StorageBuffer = OpTypeUntypedPointerKHR StorageBuffer
2246 %21 = OpTypeBufferEXT StorageBuffer
2247 %22 = OpConstantSizeOfEXT %int %21
2248 %_runtimearr_21 = OpTypeRuntimeArray %21
2249 %main = OpFunction %void None %3
2250 %5 = OpLabel
2251 %17 = OpAccessChain %_ptr_PushConstant_uint %_ %int_0
2252 %18 = OpLoad %uint %17
2253 %20 = OpUntypedAccessChainKHR %_ptr_UniformConstant %_runtimearr_21 %resource_heap %int_2
2254 %24 = OpBufferPointerEXT %_ptr_StorageBuffer %20
2255 %25 = OpUntypedAccessChainKHR %_ptr_StorageBuffer %A %24 %int_0
2256 OpStore %25 %18
2257 OpReturn
2258 OpFunctionEnd
2259 )";
2260 CompileSuccessfully(spirv.c_str(), SPV_ENV_VULKAN_1_4);
2261 EXPECT_NE(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_4));
2262 EXPECT_THAT(
2263 getDiagnosticString(),
2264 HasSubstr(
2265 "BuiltIn ResourceHeapEXT cannot be used as a member decoration"));
2266 }
2267
2268 TEST_F(ValidateSpvEXTDescriptorHeap, OffsetIdFloat) {
2269 const std::string str = R"(
2270 OpCapability Shader
2271 OpCapability SampledBuffer
2272 OpCapability DescriptorHeapEXT
2273 OpExtension "SPV_EXT_descriptor_heap"
2274 OpMemoryModel Logical GLSL450
2275 OpEntryPoint GLCompute %main "main"
2276 OpExecutionMode %main LocalSize 1 1 1
2277 OpMemberDecorateIdEXT %struct 0 OffsetIdEXT %float_0
2278 OpMemberDecorateIdEXT %struct 1 OffsetIdEXT %uint_0
2279 OpMemberDecorateIdEXT %struct 2 OffsetIdEXT %uint_0
2280 %uint = OpTypeInt 32 0
2281 %uint_0 = OpConstant %uint 0
2282 %float = OpTypeFloat 32
2283 %float_0 = OpConstant %float 0
2284 %14 = OpTypeImage %uint Buffer 0 0 0 2 R32ui
2285 %struct = OpTypeStruct %14 %uint %uint
2286 %void = OpTypeVoid
2287 %3 = OpTypeFunction %void
2288 %main = OpFunction %void None %3
2289 %5 = OpLabel
2290 OpReturn
2291 OpFunctionEnd
2292
2293 )";
2294 CompileSuccessfully(str.c_str(), SPV_ENV_VULKAN_1_4);
2295 EXPECT_NE(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_4));
2296 EXPECT_THAT(
2297 getDiagnosticString(),
2298 HasSubstr("OffsetIdEXT extra operand must be a 32-bit int scalar type"));
2299 }
2300
2301 TEST_F(ValidateSpvEXTDescriptorHeap, OffsetIdNonConstant) {
2302 const std::string str = R"(
2303 OpCapability Shader
2304 OpCapability SampledBuffer
2305 OpCapability DescriptorHeapEXT
2306 OpExtension "SPV_EXT_descriptor_heap"
2307 OpMemoryModel Logical GLSL450
2308 OpEntryPoint GLCompute %main "main"
2309 OpExecutionMode %main LocalSize 1 1 1
2310 OpMemberDecorateIdEXT %struct 0 OffsetIdEXT %void
2311 OpMemberDecorateIdEXT %struct 1 OffsetIdEXT %uint_0
2312 OpMemberDecorateIdEXT %struct 2 OffsetIdEXT %uint_0
2313 %uint = OpTypeInt 32 0
2314 %uint_0 = OpConstant %uint 0
2315 %float = OpTypeFloat 32
2316 %float_0 = OpConstant %float 0
2317 %14 = OpTypeImage %uint Buffer 0 0 0 2 R32ui
2318 %struct = OpTypeStruct %14 %uint %uint
2319 %void = OpTypeVoid
2320 %3 = OpTypeFunction %void
2321 %main = OpFunction %void None %3
2322 %5 = OpLabel
2323 OpReturn
2324 OpFunctionEnd
2325
2326 )";
2327 CompileSuccessfully(str.c_str(), SPV_ENV_VULKAN_1_4);
2328 EXPECT_NE(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_4));
2329 EXPECT_THAT(
2330 getDiagnosticString(),
2331 HasSubstr("OffsetIdEXT extra operand must be a 32-bit int scalar type"));
2332 }
2333
2334 TEST_F(ValidateSpvEXTDescriptorHeap, ArrayStrideFloat) {
2335 const std::string str = R"(
2336 OpCapability Shader
2337 OpCapability DescriptorHeapEXT
2338 OpExtension "SPV_EXT_descriptor_heap"
2339 OpMemoryModel Logical GLSL450
2340 OpEntryPoint GLCompute %main "main"
2341 OpExecutionMode %main LocalSize 1 1 1
2342 OpDecorateId %array ArrayStrideIdEXT %float_4
2343 %float = OpTypeFloat 32
2344 %float_4 = OpConstant %float 4
2345 %int = OpTypeInt 32 0
2346 %int_2 = OpConstant %int 2
2347 %sampler = OpTypeSampler
2348 %array = OpTypeArray %sampler %int_2
2349 %void = OpTypeVoid
2350 %3 = OpTypeFunction %void
2351 %main = OpFunction %void None %3
2352 %5 = OpLabel
2353 OpReturn
2354 OpFunctionEnd
2355
2356 )";
2357 CompileSuccessfully(str.c_str(), SPV_ENV_VULKAN_1_4);
2358 EXPECT_NE(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_4));
2359 EXPECT_THAT(
2360 getDiagnosticString(),
2361 HasSubstr(
2362 "ArrayStrideIdEXT extra operand must be a 32-bit int scalar type"));
2363 }
2364
2365 } // namespace
2366 } // namespace val
2367 } // namespace spvtools