Debian Codegraph @

test/val/val_image_test.cpp

raw
1 // Copyright (c) 2017 Google Inc.
2 // Modifications Copyright (C) 2020 Advanced Micro Devices, Inc. All rights
3 // reserved.
4 //
5 // Licensed under the Apache License, Version 2.0 (the "License");
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16
17 // Tests for unique type declaration rules validator.
18
19 #include <sstream>
20 #include <string>
21
22 #include "gmock/gmock.h"
23 #include "spirv-tools/libspirv.h"
24 #include "test/unit_spirv.h"
25 #include "test/val/val_fixtures.h"
26
27 namespace spvtools {
28 namespace val {
29 namespace {
30
31 using ::testing::Eq;
32 using ::testing::HasSubstr;
33 using ::testing::Not;
34
35 using ValidateImage = spvtest::ValidateBase<bool>;
36
37 std::string GenerateShaderCode(
38 const std::string& body,
39 const std::string& capabilities_and_extensions = "",
40 const std::string& execution_model = "Fragment",
41 const std::string& execution_mode = "",
42 const spv_target_env env = SPV_ENV_UNIVERSAL_1_0,
43 const std::string& memory_model = "GLSL450",
44 const std::string& declarations = "") {
45 std::ostringstream ss;
46 ss << R"(
47 OpCapability Shader
48 OpCapability InputAttachment
49 OpCapability ImageGatherExtended
50 OpCapability MinLod
51 OpCapability Sampled1D
52 OpCapability ImageQuery
53 OpCapability Int16
54 OpCapability Int64
55 OpCapability Float16
56 OpCapability Float64
57 OpCapability SparseResidency
58 OpCapability ImageBuffer
59 )";
60
61 if (env == SPV_ENV_UNIVERSAL_1_0) {
62 ss << "OpCapability SampledRect\n";
63 }
64
65 // In 1.4, the entry point must list all module-scope variables used. Just
66 // list all of them.
67 //
68 // For Vulkan, anything Location decoration needs to be an interface variable
69 std::string interface_vars =
70 (env != SPV_ENV_UNIVERSAL_1_4) ? "%input_flat_u32" :
71 R"(
72 %uniform_image_f32_1d_0001
73 %uniform_image_f32_1d_0002_rgba32f
74 %uniform_image_f32_2d_0001
75 %uniform_image_f32_2d_0011 ; multisampled sampled
76 %uniform_image_u32_2d_0001
77 %uniform_image_u32_2d_0002
78 %uniform_image_s32_3d_0001
79 %uniform_image_f32_2d_0002
80 %uniform_image_s32_2d_0002
81 %uniform_image_f32_spd_0002
82 %uniform_image_f32_3d_0111
83 %uniform_image_f32_cube_0101
84 %uniform_image_f32_cube_0102_rgba32f
85 %uniform_sampler
86 %private_image_u32_buffer_0002_r32ui
87 %private_image_u32_spd_0002
88 %private_image_f32_buffer_0002_r32ui
89 %input_flat_u32
90 )";
91
92 ss << capabilities_and_extensions;
93 ss << "OpMemoryModel Logical " << memory_model << "\n";
94 ss << "OpEntryPoint " << execution_model
95 << " %main \"main\" " + interface_vars + "\n";
96 if (execution_model == "Fragment") {
97 ss << "OpExecutionMode %main OriginUpperLeft\n";
98 }
99 ss << execution_mode;
100
101 if (env == SPV_ENV_VULKAN_1_0) {
102 ss << R"(
103 OpDecorate %uniform_image_f32_1d_0001 DescriptorSet 0
104 OpDecorate %uniform_image_f32_1d_0001 Binding 0
105 OpDecorate %uniform_image_f32_1d_0002_rgba32f DescriptorSet 0
106 OpDecorate %uniform_image_f32_1d_0002_rgba32f Binding 1
107 OpDecorate %uniform_image_f32_2d_0001 DescriptorSet 0
108 OpDecorate %uniform_image_f32_2d_0001 Binding 2
109 OpDecorate %uniform_image_f32_2d_0011 DescriptorSet 0
110 OpDecorate %uniform_image_f32_2d_0011 Binding 3
111 OpDecorate %uniform_image_u32_2d_0001 DescriptorSet 1
112 OpDecorate %uniform_image_u32_2d_0001 Binding 0
113 OpDecorate %uniform_image_u32_2d_0002 DescriptorSet 1
114 OpDecorate %uniform_image_u32_2d_0002 Binding 1
115 OpDecorate %uniform_image_s32_3d_0001 DescriptorSet 1
116 OpDecorate %uniform_image_s32_3d_0001 Binding 2
117 OpDecorate %uniform_image_f32_2d_0002 DescriptorSet 1
118 OpDecorate %uniform_image_f32_2d_0002 Binding 3
119 OpDecorate %uniform_image_s32_2d_0002 DescriptorSet 1
120 OpDecorate %uniform_image_s32_2d_0002 Binding 4
121 OpDecorate %uniform_image_u32_3d_0001 DescriptorSet 1
122 OpDecorate %uniform_image_u32_3d_0001 Binding 5
123 OpDecorate %uniform_image_f32_spd_0002 DescriptorSet 2
124 OpDecorate %uniform_image_f32_spd_0002 Binding 0
125 OpDecorate %uniform_image_f32_3d_0111 DescriptorSet 2
126 OpDecorate %uniform_image_f32_3d_0111 Binding 1
127 OpDecorate %uniform_image_f32_cube_0101 DescriptorSet 2
128 OpDecorate %uniform_image_f32_cube_0101 Binding 2
129 OpDecorate %uniform_image_f32_cube_0102_rgba32f DescriptorSet 2
130 OpDecorate %uniform_image_f32_cube_0102_rgba32f Binding 3
131 OpDecorate %uniform_image_f32_3d_0001 DescriptorSet 2
132 OpDecorate %uniform_image_f32_3d_0001 Binding 4
133 OpDecorate %uniform_sampler DescriptorSet 3
134 OpDecorate %uniform_sampler Binding 0
135 OpDecorate %input_flat_u32 Flat
136 OpDecorate %input_flat_u32 Location 0
137 )";
138 }
139
140 ss << R"(
141 %void = OpTypeVoid
142 %func = OpTypeFunction %void
143 %bool = OpTypeBool
144 %f16 = OpTypeFloat 16
145 %f32 = OpTypeFloat 32
146 %f64 = OpTypeFloat 64
147 %u16 = OpTypeInt 16 0
148 %u32 = OpTypeInt 32 0
149 %s32 = OpTypeInt 32 1
150 %u64 = OpTypeInt 64 0
151 %s64 = OpTypeInt 64 1
152 %f16vec2 = OpTypeVector %f16 2
153 %s32vec2 = OpTypeVector %s32 2
154 %u32vec2 = OpTypeVector %u32 2
155 %f32vec2 = OpTypeVector %f32 2
156 %u32vec3 = OpTypeVector %u32 3
157 %s32vec3 = OpTypeVector %s32 3
158 %f32vec3 = OpTypeVector %f32 3
159 %u32vec4 = OpTypeVector %u32 4
160 %s32vec4 = OpTypeVector %s32 4
161 %f32vec4 = OpTypeVector %f32 4
162 %boolvec4 = OpTypeVector %bool 4
163
164 %f16_0 = OpConstant %f16 0
165
166 %f32_0 = OpConstant %f32 0
167 %f32_1 = OpConstant %f32 1
168 %f32_0_5 = OpConstant %f32 0.5
169 %f32_0_25 = OpConstant %f32 0.25
170 %f32_0_75 = OpConstant %f32 0.75
171
172 %f64_0 = OpConstant %f64 0
173 %f64_1 = OpConstant %f64 1
174
175 %s32_0 = OpConstant %s32 0
176 %s32_1 = OpConstant %s32 1
177 %s32_2 = OpConstant %s32 2
178 %s32_3 = OpConstant %s32 3
179 %s32_4 = OpConstant %s32 4
180 %s32_m1 = OpConstant %s32 -1
181
182 %u16_0 = OpConstant %u16 0
183
184 %u32_0 = OpConstant %u32 0
185 %u32_1 = OpConstant %u32 1
186 %u32_2 = OpConstant %u32 2
187 %u32_3 = OpConstant %u32 3
188 %u32_4 = OpConstant %u32 4
189
190 %u64_0 = OpConstant %u64 0
191 %u64_1 = OpConstant %u64 1
192
193 %bool_t = OpConstantTrue %bool
194
195 %u32vec2arr4 = OpTypeArray %u32vec2 %u32_4
196 %u32vec2arr3 = OpTypeArray %u32vec2 %u32_3
197 %u32arr4 = OpTypeArray %u32 %u32_4
198 %u32vec3arr4 = OpTypeArray %u32vec3 %u32_4
199 %f16vec2arr4 = OpTypeArray %f16vec2 %u32_4
200
201 %struct_u32_f32vec4 = OpTypeStruct %u32 %f32vec4
202 %struct_u64_f32vec4 = OpTypeStruct %u64 %f32vec4
203 %struct_u32_u32vec4 = OpTypeStruct %u32 %u32vec4
204 %struct_u32_f32vec3 = OpTypeStruct %u32 %f32vec3
205 %struct_f32_f32vec4 = OpTypeStruct %f32 %f32vec4
206 %struct_u32_u32 = OpTypeStruct %u32 %u32
207 %struct_f32_f32 = OpTypeStruct %f32 %f32
208 %struct_u32 = OpTypeStruct %u32
209 %struct_u32_f32_u32 = OpTypeStruct %u32 %f32 %u32
210 %struct_u32_f32vec4_u32 = OpTypeStruct %u32 %f32vec4 %u32
211 %struct_u32_u32arr4 = OpTypeStruct %u32 %u32arr4
212
213 %u32vec2_01 = OpConstantComposite %u32vec2 %u32_0 %u32_1
214 %u32vec2_12 = OpConstantComposite %u32vec2 %u32_1 %u32_2
215 %u32vec3_012 = OpConstantComposite %u32vec3 %u32_0 %u32_1 %u32_2
216 %u32vec3_123 = OpConstantComposite %u32vec3 %u32_1 %u32_2 %u32_3
217 %u32vec4_0123 = OpConstantComposite %u32vec4 %u32_0 %u32_1 %u32_2 %u32_3
218 %u32vec4_1234 = OpConstantComposite %u32vec4 %u32_1 %u32_2 %u32_3 %u32_4
219
220 %s32vec2_01 = OpConstantComposite %s32vec2 %s32_0 %s32_1
221 %s32vec2_12 = OpConstantComposite %s32vec2 %s32_1 %s32_2
222 %s32vec3_012 = OpConstantComposite %s32vec3 %s32_0 %s32_1 %s32_2
223 %s32vec3_123 = OpConstantComposite %s32vec3 %s32_1 %s32_2 %s32_3
224 %s32vec4_0123 = OpConstantComposite %s32vec4 %s32_0 %s32_1 %s32_2 %s32_3
225 %s32vec4_1234 = OpConstantComposite %s32vec4 %s32_1 %s32_2 %s32_3 %s32_4
226
227 %f16vec2_00 = OpConstantComposite %f16vec2 %f16_0 %f16_0
228
229 %f32vec2_00 = OpConstantComposite %f32vec2 %f32_0 %f32_0
230 %f32vec2_01 = OpConstantComposite %f32vec2 %f32_0 %f32_1
231 %f32vec2_10 = OpConstantComposite %f32vec2 %f32_1 %f32_0
232 %f32vec2_11 = OpConstantComposite %f32vec2 %f32_1 %f32_1
233 %f32vec2_hh = OpConstantComposite %f32vec2 %f32_0_5 %f32_0_5
234
235 %f32vec3_000 = OpConstantComposite %f32vec3 %f32_0 %f32_0 %f32_0
236 %f32vec3_hhh = OpConstantComposite %f32vec3 %f32_0_5 %f32_0_5 %f32_0_5
237
238 %f32vec4_0000 = OpConstantComposite %f32vec4 %f32_0 %f32_0 %f32_0 %f32_0
239
240 %boolvec4_tttt = OpConstantComposite %boolvec4 %bool_t %bool_t %bool_t %bool_t
241
242 %const_offsets = OpConstantComposite %u32vec2arr4 %u32vec2_01 %u32vec2_12 %u32vec2_01 %u32vec2_12
243 %const_offsets3x2 = OpConstantComposite %u32vec2arr3 %u32vec2_01 %u32vec2_12 %u32vec2_01
244 %const_offsets4xu = OpConstantComposite %u32arr4 %u32_0 %u32_0 %u32_0 %u32_0
245 %const_offsets4x3 = OpConstantComposite %u32vec3arr4 %u32vec3_012 %u32vec3_012 %u32vec3_012 %u32vec3_012
246 %const_offsets4f16 = OpConstantComposite %f16vec2arr4 %f16vec2_00 %f16vec2_00 %f16vec2_00 %f16vec2_00
247
248 %type_image_f32_1d_0001 = OpTypeImage %f32 1D 0 0 0 1 Unknown
249 %ptr_image_f32_1d_0001 = OpTypePointer UniformConstant %type_image_f32_1d_0001
250 %uniform_image_f32_1d_0001 = OpVariable %ptr_image_f32_1d_0001 UniformConstant
251 %type_sampled_image_f32_1d_0001 = OpTypeSampledImage %type_image_f32_1d_0001
252
253 %type_image_f32_1d_0002_rgba32f = OpTypeImage %f32 1D 0 0 0 2 Rgba32f
254 %ptr_image_f32_1d_0002_rgba32f = OpTypePointer UniformConstant %type_image_f32_1d_0002_rgba32f
255 %uniform_image_f32_1d_0002_rgba32f = OpVariable %ptr_image_f32_1d_0002_rgba32f UniformConstant
256
257 %type_image_f32_2d_0001 = OpTypeImage %f32 2D 0 0 0 1 Unknown
258 %ptr_image_f32_2d_0001 = OpTypePointer UniformConstant %type_image_f32_2d_0001
259 %uniform_image_f32_2d_0001 = OpVariable %ptr_image_f32_2d_0001 UniformConstant
260 %type_sampled_image_f32_2d_0001 = OpTypeSampledImage %type_image_f32_2d_0001
261
262 %type_image_f32_2d_0011 = OpTypeImage %f32 2D 0 0 1 1 Unknown
263 %ptr_image_f32_2d_0011 = OpTypePointer UniformConstant %type_image_f32_2d_0011
264 %uniform_image_f32_2d_0011 = OpVariable %ptr_image_f32_2d_0011 UniformConstant
265 %type_sampled_image_f32_2d_0011 = OpTypeSampledImage %type_image_f32_2d_0011
266
267 %type_image_u32_2d_0001 = OpTypeImage %u32 2D 0 0 0 1 Unknown
268 %ptr_image_u32_2d_0001 = OpTypePointer UniformConstant %type_image_u32_2d_0001
269 %uniform_image_u32_2d_0001 = OpVariable %ptr_image_u32_2d_0001 UniformConstant
270 %type_sampled_image_u32_2d_0001 = OpTypeSampledImage %type_image_u32_2d_0001
271
272 %type_image_u32_3d_0001 = OpTypeImage %u32 3D 0 0 0 1 Unknown
273 %ptr_image_u32_3d_0001 = OpTypePointer UniformConstant %type_image_u32_3d_0001
274 %uniform_image_u32_3d_0001 = OpVariable %ptr_image_u32_3d_0001 UniformConstant
275 %type_sampled_image_u32_3d_0001 = OpTypeSampledImage %type_image_u32_3d_0001
276
277 %type_image_u32_2d_0002 = OpTypeImage %u32 2D 0 0 0 2 Unknown
278 %ptr_image_u32_2d_0002 = OpTypePointer UniformConstant %type_image_u32_2d_0002
279 %uniform_image_u32_2d_0002 = OpVariable %ptr_image_u32_2d_0002 UniformConstant
280
281 %type_image_s32_3d_0001 = OpTypeImage %s32 3D 0 0 0 1 Unknown
282 %ptr_image_s32_3d_0001 = OpTypePointer UniformConstant %type_image_s32_3d_0001
283 %uniform_image_s32_3d_0001 = OpVariable %ptr_image_s32_3d_0001 UniformConstant
284 %type_sampled_image_s32_3d_0001 = OpTypeSampledImage %type_image_s32_3d_0001
285
286 %type_image_f32_2d_0002 = OpTypeImage %f32 2D 0 0 0 2 Unknown
287 %ptr_image_f32_2d_0002 = OpTypePointer UniformConstant %type_image_f32_2d_0002
288 %uniform_image_f32_2d_0002 = OpVariable %ptr_image_f32_2d_0002 UniformConstant
289
290 %type_image_s32_2d_0002 = OpTypeImage %s32 2D 0 0 0 2 Unknown
291 %ptr_image_s32_2d_0002 = OpTypePointer UniformConstant %type_image_s32_2d_0002
292 %uniform_image_s32_2d_0002 = OpVariable %ptr_image_s32_2d_0002 UniformConstant
293
294 %type_image_f32_spd_0002 = OpTypeImage %f32 SubpassData 0 0 0 2 Unknown
295 %ptr_image_f32_spd_0002 = OpTypePointer UniformConstant %type_image_f32_spd_0002
296 %uniform_image_f32_spd_0002 = OpVariable %ptr_image_f32_spd_0002 UniformConstant
297
298 %type_image_f32_3d_0111 = OpTypeImage %f32 3D 0 1 1 1 Unknown
299 %ptr_image_f32_3d_0111 = OpTypePointer UniformConstant %type_image_f32_3d_0111
300 %uniform_image_f32_3d_0111 = OpVariable %ptr_image_f32_3d_0111 UniformConstant
301 %type_sampled_image_f32_3d_0111 = OpTypeSampledImage %type_image_f32_3d_0111
302
303 %type_image_f32_3d_0001 = OpTypeImage %f32 3D 0 0 0 1 Unknown
304 %ptr_image_f32_3d_0001 = OpTypePointer UniformConstant %type_image_f32_3d_0001
305 %uniform_image_f32_3d_0001 = OpVariable %ptr_image_f32_3d_0001 UniformConstant
306 %type_sampled_image_f32_3d_0001 = OpTypeSampledImage %type_image_f32_3d_0001
307
308 %type_image_f32_cube_0101 = OpTypeImage %f32 Cube 0 1 0 1 Unknown
309 %ptr_image_f32_cube_0101 = OpTypePointer UniformConstant %type_image_f32_cube_0101
310 %uniform_image_f32_cube_0101 = OpVariable %ptr_image_f32_cube_0101 UniformConstant
311 %type_sampled_image_f32_cube_0101 = OpTypeSampledImage %type_image_f32_cube_0101
312
313 %type_image_f32_cube_0102_rgba32f = OpTypeImage %f32 Cube 0 1 0 2 Rgba32f
314 %ptr_image_f32_cube_0102_rgba32f = OpTypePointer UniformConstant %type_image_f32_cube_0102_rgba32f
315 %uniform_image_f32_cube_0102_rgba32f = OpVariable %ptr_image_f32_cube_0102_rgba32f UniformConstant
316
317 %type_sampler = OpTypeSampler
318 %ptr_sampler = OpTypePointer UniformConstant %type_sampler
319 %uniform_sampler = OpVariable %ptr_sampler UniformConstant
320
321 %type_image_u32_buffer_0002_r32ui = OpTypeImage %u32 Buffer 0 0 0 2 R32ui
322 %ptr_Image_u32 = OpTypePointer Image %u32
323 %ptr_image_u32_buffer_0002_r32ui = OpTypePointer Private %type_image_u32_buffer_0002_r32ui
324 %private_image_u32_buffer_0002_r32ui = OpVariable %ptr_image_u32_buffer_0002_r32ui Private
325
326 %ptr_Image_u32arr4 = OpTypePointer Image %u32arr4
327
328 %type_image_u32_spd_0002 = OpTypeImage %u32 SubpassData 0 0 0 2 Unknown
329 %ptr_image_u32_spd_0002 = OpTypePointer Private %type_image_u32_spd_0002
330 %private_image_u32_spd_0002 = OpVariable %ptr_image_u32_spd_0002 Private
331
332 %type_image_f32_buffer_0002_r32ui = OpTypeImage %f32 Buffer 0 0 0 2 R32ui
333 %ptr_Image_f32 = OpTypePointer Image %f32
334 %ptr_image_f32_buffer_0002_r32ui = OpTypePointer Private %type_image_f32_buffer_0002_r32ui
335 %private_image_f32_buffer_0002_r32ui = OpVariable %ptr_image_f32_buffer_0002_r32ui Private
336
337 %ptr_input_flat_u32 = OpTypePointer Input %u32
338 %input_flat_u32 = OpVariable %ptr_input_flat_u32 Input
339 )";
340
341 if (env == SPV_ENV_UNIVERSAL_1_0) {
342 ss << R"(
343 %type_image_void_2d_0001 = OpTypeImage %void 2D 0 0 0 1 Unknown
344 %ptr_image_void_2d_0001 = OpTypePointer UniformConstant %type_image_void_2d_0001
345 %uniform_image_void_2d_0001 = OpVariable %ptr_image_void_2d_0001 UniformConstant
346 %type_sampled_image_void_2d_0001 = OpTypeSampledImage %type_image_void_2d_0001
347
348 %type_image_void_2d_0002 = OpTypeImage %void 2D 0 0 0 2 Unknown
349 %ptr_image_void_2d_0002 = OpTypePointer UniformConstant %type_image_void_2d_0002
350 %uniform_image_void_2d_0002 = OpVariable %ptr_image_void_2d_0002 UniformConstant
351
352 %type_image_f32_rect_0001 = OpTypeImage %f32 Rect 0 0 0 1 Unknown
353 %ptr_image_f32_rect_0001 = OpTypePointer UniformConstant %type_image_f32_rect_0001
354 %uniform_image_f32_rect_0001 = OpVariable %ptr_image_f32_rect_0001 UniformConstant
355 %type_sampled_image_f32_rect_0001 = OpTypeSampledImage %type_image_f32_rect_0001
356 )";
357 }
358
359 ss << declarations;
360
361 ss << R"(
362 %main = OpFunction %void None %func
363 %main_entry = OpLabel
364 )";
365
366 ss << body;
367
368 ss << R"(
369 OpReturn
370 OpFunctionEnd)";
371
372 return ss.str();
373 }
374
375 std::string GenerateKernelCode(
376 const std::string& body,
377 const std::string& capabilities_and_extensions = "",
378 const std::string& declarations = "") {
379 std::ostringstream ss;
380 ss << R"(
381 OpCapability Addresses
382 OpCapability Kernel
383 OpCapability Linkage
384 OpCapability ImageQuery
385 OpCapability ImageGatherExtended
386 OpCapability InputAttachment
387 OpCapability SampledRect
388 OpCapability Int16
389 )";
390
391 ss << capabilities_and_extensions;
392 ss << R"(
393 OpMemoryModel Physical32 OpenCL
394 %void = OpTypeVoid
395 %func = OpTypeFunction %void
396 %bool = OpTypeBool
397 %f32 = OpTypeFloat 32
398 %u16 = OpTypeInt 16 0
399 %u32 = OpTypeInt 32 0
400 %u32vec2 = OpTypeVector %u32 2
401 %f32vec2 = OpTypeVector %f32 2
402 %u32vec3 = OpTypeVector %u32 3
403 %f32vec3 = OpTypeVector %f32 3
404 %u32vec4 = OpTypeVector %u32 4
405 %f32vec4 = OpTypeVector %f32 4
406
407 %f32_0 = OpConstant %f32 0
408 %f32_1 = OpConstant %f32 1
409 %f32_0_5 = OpConstant %f32 0.5
410 %f32_0_25 = OpConstant %f32 0.25
411 %f32_0_75 = OpConstant %f32 0.75
412
413 %u16_0 = OpConstant %u16 0
414
415 %u32_0 = OpConstant %u32 0
416 %u32_1 = OpConstant %u32 1
417 %u32_2 = OpConstant %u32 2
418 %u32_3 = OpConstant %u32 3
419 %u32_4 = OpConstant %u32 4
420
421 %u32vec2_01 = OpConstantComposite %u32vec2 %u32_0 %u32_1
422 %u32vec2_12 = OpConstantComposite %u32vec2 %u32_1 %u32_2
423 %u32vec3_012 = OpConstantComposite %u32vec3 %u32_0 %u32_1 %u32_2
424 %u32vec3_123 = OpConstantComposite %u32vec3 %u32_1 %u32_2 %u32_3
425 %u32vec4_0123 = OpConstantComposite %u32vec4 %u32_0 %u32_1 %u32_2 %u32_3
426 %u32vec4_1234 = OpConstantComposite %u32vec4 %u32_1 %u32_2 %u32_3 %u32_4
427
428 %f32vec2_00 = OpConstantComposite %f32vec2 %f32_0 %f32_0
429 %f32vec2_01 = OpConstantComposite %f32vec2 %f32_0 %f32_1
430 %f32vec2_10 = OpConstantComposite %f32vec2 %f32_1 %f32_0
431 %f32vec2_11 = OpConstantComposite %f32vec2 %f32_1 %f32_1
432 %f32vec2_hh = OpConstantComposite %f32vec2 %f32_0_5 %f32_0_5
433
434 %f32vec3_000 = OpConstantComposite %f32vec3 %f32_0 %f32_0 %f32_0
435 %f32vec3_hhh = OpConstantComposite %f32vec3 %f32_0_5 %f32_0_5 %f32_0_5
436
437 %f32vec4_0000 = OpConstantComposite %f32vec4 %f32_0 %f32_0 %f32_0 %f32_0
438
439 %type_image_f32_2d_0001 = OpTypeImage %f32 2D 0 0 0 1 Unknown
440 %ptr_image_f32_2d_0001 = OpTypePointer UniformConstant %type_image_f32_2d_0001
441 %uniform_image_f32_2d_0001 = OpVariable %ptr_image_f32_2d_0001 UniformConstant
442 %type_sampled_image_f32_2d_0001 = OpTypeSampledImage %type_image_f32_2d_0001
443
444 %type_image_f32_2d_0011 = OpTypeImage %f32 2D 0 0 1 1 Unknown
445 %ptr_image_f32_2d_0011 = OpTypePointer UniformConstant %type_image_f32_2d_0011
446 %uniform_image_f32_2d_0011 = OpVariable %ptr_image_f32_2d_0011 UniformConstant
447 %type_sampled_image_f32_2d_0011 = OpTypeSampledImage %type_image_f32_2d_0011
448
449 %type_image_f32_3d_0011 = OpTypeImage %f32 3D 0 0 1 1 Unknown
450 %ptr_image_f32_3d_0011 = OpTypePointer UniformConstant %type_image_f32_3d_0011
451 %uniform_image_f32_3d_0011 = OpVariable %ptr_image_f32_3d_0011 UniformConstant
452 %type_sampled_image_f32_3d_0011 = OpTypeSampledImage %type_image_f32_3d_0011
453
454 %type_image_f32_rect_0001 = OpTypeImage %f32 Rect 0 0 0 1 Unknown
455 %ptr_image_f32_rect_0001 = OpTypePointer UniformConstant %type_image_f32_rect_0001
456 %uniform_image_f32_rect_0001 = OpVariable %ptr_image_f32_rect_0001 UniformConstant
457 %type_sampled_image_f32_rect_0001 = OpTypeSampledImage %type_image_f32_rect_0001
458
459 %type_sampler = OpTypeSampler
460 %ptr_sampler = OpTypePointer UniformConstant %type_sampler
461 %uniform_sampler = OpVariable %ptr_sampler UniformConstant
462 )";
463
464 ss << declarations;
465
466 ss << R"(
467 %main = OpFunction %void None %func
468 %main_entry = OpLabel
469 )";
470
471 ss << body;
472 ss << R"(
473 OpReturn
474 OpFunctionEnd)";
475
476 return ss.str();
477 }
478
479 std::string GetKernelHeader() {
480 return R"(
481 OpCapability Kernel
482 OpCapability Addresses
483 OpCapability Linkage
484 OpMemoryModel Physical32 OpenCL
485 %void = OpTypeVoid
486 %func = OpTypeFunction %void
487 %f32 = OpTypeFloat 32
488 %u32 = OpTypeInt 32 0
489 )";
490 }
491
492 std::string TrivialMain() {
493 return R"(
494 %main = OpFunction %void None %func
495 %entry = OpLabel
496 OpReturn
497 OpFunctionEnd
498 )";
499 }
500
501 std::string GetShaderHeader(const std::string& capabilities_and_extensions = "",
502 bool include_entry_point = true) {
503 std::ostringstream ss;
504 ss << R"(
505 OpCapability Shader
506 OpCapability Int64
507 OpCapability Float64
508 )";
509
510 if (!include_entry_point) {
511 ss << "OpCapability Linkage\n";
512 }
513 ss << capabilities_and_extensions;
514
515 ss << R"(
516 OpMemoryModel Logical GLSL450
517 )";
518
519 if (include_entry_point) {
520 ss << "OpEntryPoint Fragment %main \"main\"\n";
521 ss << "OpExecutionMode %main OriginUpperLeft";
522 }
523 ss << R"(
524 %void = OpTypeVoid
525 %func = OpTypeFunction %void
526 %bool = OpTypeBool
527 %f32 = OpTypeFloat 32
528 %f64 = OpTypeFloat 64
529 %u32 = OpTypeInt 32 0
530 %u64 = OpTypeInt 64 0
531 %s32 = OpTypeInt 32 1
532 %s64 = OpTypeInt 64 1
533 )";
534
535 return ss.str();
536 }
537
538 TEST_F(ValidateImage, TypeImageWrongSampledType) {
539 const std::string code = GetShaderHeader("", false) + R"(
540 %img_type = OpTypeImage %bool 2D 0 0 0 1 Unknown
541 )";
542
543 CompileSuccessfully(code.c_str());
544 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
545 EXPECT_THAT(getDiagnosticString(),
546 HasSubstr("Expected Sampled Type to be either void or "
547 "numerical scalar "
548 "type"));
549 }
550
551 TEST_F(ValidateImage, TypeImageVoidSampledTypeVulkan) {
552 const std::string code = GetShaderHeader() + R"(
553 %img_type = OpTypeImage %void 2D 0 0 0 1 Unknown
554 %main = OpFunction %void None %func
555 %main_lab = OpLabel
556 OpReturn
557 OpFunctionEnd
558 )";
559
560 const spv_target_env env = SPV_ENV_VULKAN_1_0;
561 CompileSuccessfully(code, env);
562 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions(env));
563 EXPECT_THAT(getDiagnosticString(),
564 AnyVUID("VUID-StandaloneSpirv-OpTypeImage-04656"));
565 EXPECT_THAT(getDiagnosticString(),
566 HasSubstr("Expected Sampled Type to be a 32-bit int, 64-bit int "
567 "or 32-bit float scalar type for Vulkan environment"));
568 }
569
570 TEST_F(ValidateImage, TypeImageU32SampledTypeVulkan) {
571 const std::string code = GetShaderHeader() + R"(
572 %img_type = OpTypeImage %u32 2D 0 0 0 1 Unknown
573 %main = OpFunction %void None %func
574 %main_lab = OpLabel
575 OpReturn
576 OpFunctionEnd
577 )";
578
579 const spv_target_env env = SPV_ENV_VULKAN_1_0;
580 CompileSuccessfully(code, env);
581 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions(env));
582 EXPECT_THAT(getDiagnosticString(), Eq(""));
583 }
584
585 TEST_F(ValidateImage, TypeImageI32SampledTypeVulkan) {
586 const std::string code = GetShaderHeader() + R"(
587 %img_type = OpTypeImage %s32 2D 0 0 0 1 Unknown
588 %main = OpFunction %void None %func
589 %main_lab = OpLabel
590 OpReturn
591 OpFunctionEnd
592 )";
593
594 const spv_target_env env = SPV_ENV_VULKAN_1_0;
595 CompileSuccessfully(code, env);
596 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions(env));
597 EXPECT_THAT(getDiagnosticString(), Eq(""));
598 }
599
600 TEST_F(ValidateImage, TypeImageI64SampledTypeNoCapabilityVulkan) {
601 const std::string code = GetShaderHeader() + R"(
602 %img_type = OpTypeImage %s64 2D 0 0 0 1 Unknown
603 %main = OpFunction %void None %func
604 %main_lab = OpLabel
605 OpReturn
606 OpFunctionEnd
607 )";
608
609 const spv_target_env env = SPV_ENV_VULKAN_1_0;
610 CompileSuccessfully(code, env);
611 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions(env));
612 EXPECT_THAT(getDiagnosticString(),
613 HasSubstr("Capability Int64ImageEXT is required when using "
614 "Sampled Type of 64-bit int"));
615 }
616
617 TEST_F(ValidateImage, TypeImageI64SampledTypeVulkan) {
618 const std::string code = GetShaderHeader(
619 "OpCapability Int64ImageEXT\nOpExtension "
620 "\"SPV_EXT_shader_image_int64\"\n") +
621 R"(
622 %img_type = OpTypeImage %s64 2D 0 0 0 1 Unknown
623 %main = OpFunction %void None %func
624 %main_lab = OpLabel
625 OpReturn
626 OpFunctionEnd
627 )";
628
629 const spv_target_env env = SPV_ENV_VULKAN_1_0;
630 CompileSuccessfully(code, env);
631 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions(env));
632 EXPECT_THAT(getDiagnosticString(), Eq(""));
633 }
634
635 TEST_F(ValidateImage, TypeImageU64SampledTypeNoCapabilityVulkan) {
636 const std::string code = GetShaderHeader() + R"(
637 %img_type = OpTypeImage %u64 2D 0 0 0 1 Unknown
638 %main = OpFunction %void None %func
639 %main_lab = OpLabel
640 OpReturn
641 OpFunctionEnd
642 )";
643
644 const spv_target_env env = SPV_ENV_VULKAN_1_0;
645 CompileSuccessfully(code, env);
646 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions(env));
647 EXPECT_THAT(getDiagnosticString(),
648 HasSubstr("Capability Int64ImageEXT is required when using "
649 "Sampled Type of 64-bit int"));
650 }
651
652 TEST_F(ValidateImage, TypeImageU64SampledTypeVulkan) {
653 const std::string code = GetShaderHeader(
654 "OpCapability Int64ImageEXT\nOpExtension "
655 "\"SPV_EXT_shader_image_int64\"\n") +
656 R"(
657 %img_type = OpTypeImage %u64 2D 0 0 0 1 Unknown
658 %main = OpFunction %void None %func
659 %main_lab = OpLabel
660 OpReturn
661 OpFunctionEnd
662 )";
663
664 const spv_target_env env = SPV_ENV_VULKAN_1_0;
665 CompileSuccessfully(code, env);
666 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions(env));
667 EXPECT_THAT(getDiagnosticString(), Eq(""));
668 }
669
670 TEST_F(ValidateImage, TypeImageF32SampledTypeVulkan) {
671 const std::string code = GetShaderHeader() + R"(
672 %img_type = OpTypeImage %f32 2D 0 0 0 1 Unknown
673 %main = OpFunction %void None %func
674 %main_lab = OpLabel
675 OpReturn
676 OpFunctionEnd
677 )";
678
679 const spv_target_env env = SPV_ENV_VULKAN_1_0;
680 CompileSuccessfully(code, env);
681 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions(env));
682 EXPECT_THAT(getDiagnosticString(), Eq(""));
683 }
684
685 TEST_F(ValidateImage, TypeImageF64SampledTypeVulkan) {
686 const std::string code = GetShaderHeader() + R"(
687 %img_type = OpTypeImage %f64 2D 0 0 0 1 Unknown
688 %main = OpFunction %void None %func
689 %main_lab = OpLabel
690 OpReturn
691 OpFunctionEnd
692 )";
693
694 const spv_target_env env = SPV_ENV_VULKAN_1_0;
695 CompileSuccessfully(code, env);
696 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions(env));
697 EXPECT_THAT(getDiagnosticString(),
698 AnyVUID("VUID-StandaloneSpirv-OpTypeImage-04656"));
699 EXPECT_THAT(getDiagnosticString(),
700 HasSubstr("Expected Sampled Type to be a 32-bit int, 64-bit int "
701 "or 32-bit float scalar type for Vulkan environment"));
702 }
703
704 TEST_F(ValidateImage, TypeImageF64SampledTypeWithInt64Vulkan) {
705 const std::string code = GetShaderHeader(
706 "OpCapability Int64ImageEXT\nOpExtension "
707 "\"SPV_EXT_shader_image_int64\"\n") +
708 R"(
709 %img_type = OpTypeImage %f64 2D 0 0 0 1 Unknown
710 %main = OpFunction %void None %func
711 %main_lab = OpLabel
712 OpReturn
713 OpFunctionEnd
714 )";
715
716 const spv_target_env env = SPV_ENV_VULKAN_1_0;
717 CompileSuccessfully(code, env);
718 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions(env));
719 EXPECT_THAT(getDiagnosticString(),
720 AnyVUID("VUID-StandaloneSpirv-OpTypeImage-04656"));
721 EXPECT_THAT(getDiagnosticString(),
722 HasSubstr("Expected Sampled Type to be a 32-bit int, 64-bit int "
723 "or 32-bit float scalar type for Vulkan environment"));
724 }
725
726 TEST_F(ValidateImage, TypeImageWrongDepth) {
727 const std::string code = GetShaderHeader("", false) + R"(
728 %img_type = OpTypeImage %f32 2D 3 0 0 1 Unknown
729 )";
730
731 CompileSuccessfully(code.c_str());
732 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
733 EXPECT_THAT(getDiagnosticString(),
734 HasSubstr("Invalid Depth 3 (must be 0, 1 or 2)"));
735 }
736
737 TEST_F(ValidateImage, TypeImageWrongArrayed) {
738 const std::string code = GetShaderHeader("", false) + R"(
739 %img_type = OpTypeImage %f32 2D 0 2 0 1 Unknown
740 )";
741
742 CompileSuccessfully(code.c_str());
743 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
744 EXPECT_THAT(getDiagnosticString(),
745 HasSubstr("Invalid Arrayed 2 (must be 0 or 1)"));
746 }
747
748 TEST_F(ValidateImage, TypeImageWrongMS) {
749 const std::string code = GetShaderHeader("", false) + R"(
750 %img_type = OpTypeImage %f32 2D 0 0 2 1 Unknown
751 )";
752
753 CompileSuccessfully(code.c_str());
754 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
755 EXPECT_THAT(getDiagnosticString(),
756 HasSubstr("Invalid MS 2 (must be 0 or 1)"));
757 }
758
759 TEST_F(ValidateImage, TypeImageWrongSampled) {
760 const std::string code = GetShaderHeader("", false) + R"(
761 %img_type = OpTypeImage %f32 2D 0 0 0 3 Unknown
762 )";
763
764 CompileSuccessfully(code.c_str());
765 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
766 EXPECT_THAT(getDiagnosticString(),
767 HasSubstr("Invalid Sampled 3 (must be 0, 1 or 2)"));
768 }
769
770 TEST_F(ValidateImage, TypeImageWrongSampledForSubpassData) {
771 const std::string code =
772 GetShaderHeader("OpCapability InputAttachment\n", false) +
773 R"(
774 %img_type = OpTypeImage %f32 SubpassData 0 0 0 1 Unknown
775 )";
776
777 CompileSuccessfully(code.c_str());
778 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
779 EXPECT_THAT(getDiagnosticString(),
780 HasSubstr("Dim SubpassData requires Sampled to be 2"));
781 }
782
783 TEST_F(ValidateImage, TypeImageWrongSampledForSubpassDataVulkan) {
784 const std::string code = GetShaderHeader("OpCapability InputAttachment\n") +
785 R"(
786 %img_type = OpTypeImage %f32 SubpassData 0 0 0 1 Unknown
787 )" + TrivialMain();
788
789 CompileSuccessfully(code.c_str());
790 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions(SPV_ENV_VULKAN_1_0));
791 EXPECT_THAT(getDiagnosticString(),
792 AnyVUID("VUID-StandaloneSpirv-OpTypeImage-06214"));
793 EXPECT_THAT(getDiagnosticString(),
794 HasSubstr("Dim SubpassData requires Sampled to be 2"));
795 }
796
797 TEST_F(ValidateImage, TypeImageWrongArrayForSubpassDataVulkan) {
798 const std::string code = GetShaderHeader("OpCapability InputAttachment\n") +
799 R"(
800 %img_type = OpTypeImage %f32 SubpassData 0 1 0 2 Unknown
801 )" + TrivialMain();
802
803 CompileSuccessfully(code.c_str());
804 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions(SPV_ENV_VULKAN_1_0));
805 EXPECT_THAT(getDiagnosticString(),
806 AnyVUID("VUID-StandaloneSpirv-OpTypeImage-06214"));
807 EXPECT_THAT(getDiagnosticString(),
808 HasSubstr("Dim SubpassData requires Arrayed to be 0"));
809 }
810
811 TEST_F(ValidateImage, TypeImageDimRectVulkan) {
812 const std::string code = GetShaderHeader("OpCapability InputAttachment\n") +
813 R"(
814 %img_type = OpTypeImage %f32 Rect 0 1 0 2 Unknown
815 )" + TrivialMain();
816
817 CompileSuccessfully(code.c_str());
818 ASSERT_EQ(SPV_ERROR_INVALID_CAPABILITY,
819 ValidateInstructions(SPV_ENV_VULKAN_1_0));
820 // Can't actually hit VUID-StandaloneSpirv-OpTypeImage-09638
821 EXPECT_THAT(
822 getDiagnosticString(),
823 AnyVUID("TypeImage requires one of these capabilities: SampledRect"));
824 }
825
826 TEST_F(ValidateImage, TypeImageWrongSampledTypeForTileImageDataEXT) {
827 const std::string code = GetShaderHeader(
828 "OpCapability TileImageColorReadAccessEXT\n"
829 "OpExtension \"SPV_EXT_shader_tile_image\"\n",
830 false) +
831 R"(
832 %img_type = OpTypeImage %void TileImageDataEXT 0 0 0 2 Unknown
833 )";
834
835 CompileSuccessfully(code.c_str());
836 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
837 EXPECT_THAT(
838 getDiagnosticString(),
839 HasSubstr(
840 "Dim TileImageDataEXT requires Sampled Type to be not OpTypeVoid"));
841 }
842
843 TEST_F(ValidateImage, TypeImageWrongSampledForTileImageDataEXT) {
844 const std::string code = GetShaderHeader(
845 "OpCapability TileImageColorReadAccessEXT\n"
846 "OpExtension \"SPV_EXT_shader_tile_image\"\n",
847 false) +
848 R"(
849 %img_type = OpTypeImage %f32 TileImageDataEXT 0 0 0 1 Unknown
850 )";
851
852 CompileSuccessfully(code.c_str());
853 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
854 EXPECT_THAT(getDiagnosticString(),
855 HasSubstr("Dim TileImageDataEXT requires Sampled to be 2"));
856 }
857
858 TEST_F(ValidateImage, TypeImageWrongFormatForTileImageDataEXT) {
859 const std::string code = GetShaderHeader(
860 "OpCapability TileImageColorReadAccessEXT\n"
861 "OpExtension \"SPV_EXT_shader_tile_image\"\n",
862 false) +
863 R"(
864 %img_type = OpTypeImage %f32 TileImageDataEXT 0 0 0 2 Rgba32f
865 )";
866
867 CompileSuccessfully(code.c_str());
868 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
869 EXPECT_THAT(getDiagnosticString(),
870 HasSubstr("Dim TileImageDataEXT requires format Unknown"));
871 }
872
873 TEST_F(ValidateImage, TypeImageWrongDepthForTileImageDataEXT) {
874 const std::string code = GetShaderHeader(
875 "OpCapability TileImageColorReadAccessEXT\n"
876 "OpExtension \"SPV_EXT_shader_tile_image\"\n",
877 false) +
878 R"(
879 %img_type = OpTypeImage %f32 TileImageDataEXT 1 0 0 2 Unknown
880 )";
881
882 CompileSuccessfully(code.c_str());
883 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
884 EXPECT_THAT(getDiagnosticString(),
885 HasSubstr("Dim TileImageDataEXT requires Depth to be 0"));
886 }
887
888 TEST_F(ValidateImage, TypeImageWrongArrayedForTileImageDataEXT) {
889 const std::string code = GetShaderHeader(
890 "OpCapability TileImageColorReadAccessEXT\n"
891 "OpExtension \"SPV_EXT_shader_tile_image\"\n",
892 false) +
893 R"(
894 %img_type = OpTypeImage %f32 TileImageDataEXT 0 1 0 2 Unknown
895 )";
896
897 CompileSuccessfully(code.c_str());
898 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
899 EXPECT_THAT(getDiagnosticString(),
900 HasSubstr("Dim TileImageDataEXT requires Arrayed to be 0"));
901 }
902
903 TEST_F(ValidateImage, TypeSampledImage_TileImageDataEXT_Error) {
904 const std::string code = GetShaderHeader(
905 "OpCapability TileImageColorReadAccessEXT\n"
906 "OpExtension \"SPV_EXT_shader_tile_image\"\n",
907 false) +
908 R"(
909 %img_type = OpTypeImage %f32 TileImageDataEXT 0 0 0 2 Unknown
910 %simg_type = OpTypeSampledImage %img_type
911 )";
912
913 CompileSuccessfully(code.c_str());
914 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
915 EXPECT_THAT(getDiagnosticString(),
916 HasSubstr("Sampled image type requires an image type with "
917 "\"Sampled\" operand set to 0 or 1"));
918 }
919
920 TEST_F(ValidateImage, ImageTexelPointerImageDimTileImageDataEXTBad) {
921 const std::string body = R"(
922 %texel_ptr = OpImageTexelPointer %ptr_Image_u32 %tile_image_u32_tid_0002 %u32_0 %u32_0
923 %sum = OpAtomicIAdd %u32 %texel_ptr %u32_1 %u32_0 %u32_1
924 )";
925 const std::string decl = R"(
926 %type_image_u32_tid_0002 = OpTypeImage %u32 TileImageDataEXT 0 0 0 2 Unknown
927 %ptr_image_u32_tid_0002 = OpTypePointer TileImageEXT %type_image_u32_tid_0002
928 %tile_image_u32_tid_0002 = OpVariable %ptr_image_u32_tid_0002 TileImageEXT
929 )";
930
931 const std::string extra = R"(
932 OpCapability TileImageColorReadAccessEXT
933 OpExtension "SPV_EXT_shader_tile_image"
934 )";
935
936 CompileSuccessfully(GenerateShaderCode(body, extra, "Fragment", "",
937 SPV_ENV_UNIVERSAL_1_5, "GLSL450", decl)
938 .c_str());
939 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
940 EXPECT_THAT(getDiagnosticString(),
941 HasSubstr("Image Dim TileImageDataEXT cannot be used with "
942 "OpImageTexelPointer"));
943 }
944
945 TEST_F(ValidateImage, ReadTileImageDataEXT) {
946 const std::string body = R"(
947 %img = OpLoad %type_image_f32_tid_0002 %uniform_image_f32_tid_0002
948 %res1 = OpImageRead %f32vec4 %img %u32vec2_01
949 )";
950
951 const std::string decl = R"(
952 %type_image_f32_tid_0002 = OpTypeImage %f32 TileImageDataEXT 0 0 0 2 Unknown
953 %ptr_image_f32_tid_0002 = OpTypePointer UniformConstant %type_image_f32_tid_0002
954 %uniform_image_f32_tid_0002 = OpVariable %ptr_image_f32_tid_0002 UniformConstant
955 )";
956
957 const std::string extra = R"(
958 OpCapability StorageImageReadWithoutFormat
959 OpCapability TileImageColorReadAccessEXT
960 OpExtension "SPV_EXT_shader_tile_image"
961 )";
962
963 CompileSuccessfully(GenerateShaderCode(body, extra, "Fragment", "",
964 SPV_ENV_UNIVERSAL_1_5, "GLSL450", decl)
965 .c_str());
966 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
967 EXPECT_THAT(
968 getDiagnosticString(),
969 HasSubstr("Image Dim TileImageDataEXT cannot be used with ImageRead"));
970 }
971
972 TEST_F(ValidateImage, WriteTileImageDataEXT) {
973 const std::string body = R"(
974 %img = OpLoad %type_image_f32_tid_0002 %uniform_image_f32_tid_0002
975 OpImageWrite %img %u32vec2_01 %f32vec4_0000
976 )";
977
978 const std::string decl = R"(
979 %type_image_f32_tid_0002 = OpTypeImage %f32 TileImageDataEXT 0 0 0 2 Unknown
980 %ptr_image_f32_tid_0002 = OpTypePointer UniformConstant %type_image_f32_tid_0002
981 %uniform_image_f32_tid_0002 = OpVariable %ptr_image_f32_tid_0002 UniformConstant
982 )";
983
984 const std::string extra = R"(
985 OpCapability TileImageColorReadAccessEXT
986 OpExtension "SPV_EXT_shader_tile_image"
987 )";
988
989 CompileSuccessfully(GenerateShaderCode(body, extra, "Fragment", "",
990 SPV_ENV_UNIVERSAL_1_5, "GLSL450", decl)
991 .c_str());
992 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
993 EXPECT_THAT(getDiagnosticString(),
994 HasSubstr("Image 'Dim' cannot be TileImageDataEXT"));
995 }
996
997 TEST_F(ValidateImage, QueryFormatTileImageDataEXT) {
998 const std::string body = R"(
999 %img = OpLoad %type_image_f32_tid_0002 %uniform_image_f32_tid_0002
1000 %res1 = OpImageQueryFormat %u32 %img
1001 )";
1002
1003 const std::string decl = R"(
1004 %type_image_f32_tid_0002 = OpTypeImage %f32 TileImageDataEXT 0 0 0 2 Unknown
1005 %ptr_image_f32_tid_0002 = OpTypePointer UniformConstant %type_image_f32_tid_0002
1006 %uniform_image_f32_tid_0002 = OpVariable %ptr_image_f32_tid_0002 UniformConstant
1007 )";
1008
1009 const std::string extra = R"(
1010 OpCapability TileImageColorReadAccessEXT
1011 OpExtension "SPV_EXT_shader_tile_image"
1012 )";
1013
1014 CompileSuccessfully(GenerateKernelCode(body, extra, decl).c_str());
1015
1016 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1017 EXPECT_THAT(getDiagnosticString(),
1018 HasSubstr("Image 'Dim' cannot be TileImageDataEXT"));
1019 }
1020
1021 TEST_F(ValidateImage, QueryOrderTileImageDataEXT) {
1022 const std::string body = R"(
1023 %img = OpLoad %type_image_f32_tid_0002 %uniform_image_f32_tid_0002
1024 %res1 = OpImageQueryOrder %u32 %img
1025 )";
1026
1027 const std::string decl = R"(
1028 %type_image_f32_tid_0002 = OpTypeImage %f32 TileImageDataEXT 0 0 0 2 Unknown
1029 %ptr_image_f32_tid_0002 = OpTypePointer UniformConstant %type_image_f32_tid_0002
1030 %uniform_image_f32_tid_0002 = OpVariable %ptr_image_f32_tid_0002 UniformConstant
1031 )";
1032
1033 const std::string extra = R"(
1034 OpCapability TileImageColorReadAccessEXT
1035 OpExtension "SPV_EXT_shader_tile_image"
1036 )";
1037
1038 CompileSuccessfully(GenerateKernelCode(body, extra, decl).c_str());
1039
1040 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1041 EXPECT_THAT(getDiagnosticString(),
1042 HasSubstr("Image 'Dim' cannot be TileImageDataEXT"));
1043 }
1044
1045 TEST_F(ValidateImage, SparseFetchTileImageDataEXT) {
1046 const std::string body = R"(
1047 %img = OpLoad %type_image_f32_tid_0002 %uniform_image_f32_tid_0002
1048 %res1 = OpImageSparseFetch %struct_u32_f32vec4 %img %u32vec2_01
1049 )";
1050
1051 const std::string decl = R"(
1052 %type_image_f32_tid_0002 = OpTypeImage %f32 TileImageDataEXT 0 0 0 2 Unknown
1053 %ptr_image_f32_tid_0002 = OpTypePointer UniformConstant %type_image_f32_tid_0002
1054 %uniform_image_f32_tid_0002 = OpVariable %ptr_image_f32_tid_0002 UniformConstant
1055 )";
1056
1057 const std::string extra = R"(
1058 OpCapability StorageImageReadWithoutFormat
1059 OpCapability TileImageColorReadAccessEXT
1060 OpExtension "SPV_EXT_shader_tile_image"
1061 )";
1062
1063 CompileSuccessfully(GenerateShaderCode(body, extra, "Fragment", "",
1064 SPV_ENV_UNIVERSAL_1_5, "GLSL450", decl)
1065 .c_str());
1066 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1067 EXPECT_THAT(getDiagnosticString(),
1068 HasSubstr("Expected Image 'Sampled' parameter to be 1"));
1069 }
1070
1071 TEST_F(ValidateImage, SparseReadTileImageDataEXT) {
1072 const std::string body = R"(
1073 %img = OpLoad %type_image_f32_tid_0002 %uniform_image_f32_tid_0002
1074 %res1 = OpImageSparseRead %struct_u32_f32vec4 %img %u32vec2_01
1075 )";
1076
1077 const std::string decl = R"(
1078 %type_image_f32_tid_0002 = OpTypeImage %f32 TileImageDataEXT 0 0 0 2 Unknown
1079 %ptr_image_f32_tid_0002 = OpTypePointer UniformConstant %type_image_f32_tid_0002
1080 %uniform_image_f32_tid_0002 = OpVariable %ptr_image_f32_tid_0002 UniformConstant
1081 )";
1082
1083 const std::string extra = R"(
1084 OpCapability StorageImageReadWithoutFormat
1085 OpCapability TileImageColorReadAccessEXT
1086 OpExtension "SPV_EXT_shader_tile_image"
1087 )";
1088
1089 CompileSuccessfully(GenerateShaderCode(body, extra, "Fragment", "",
1090 SPV_ENV_UNIVERSAL_1_5, "GLSL450", decl)
1091 .c_str());
1092 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1093 EXPECT_THAT(
1094 getDiagnosticString(),
1095 HasSubstr(
1096 "Image Dim TileImageDataEXT cannot be used with ImageSparseRead"));
1097 }
1098
1099 TEST_F(ValidateImage, TypeImage_OpenCL_Sampled0_OK) {
1100 const std::string code = GetKernelHeader() + R"(
1101 %img_type = OpTypeImage %void 2D 0 0 0 0 Unknown ReadOnly
1102 )";
1103
1104 CompileSuccessfully(code.c_str());
1105 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_OPENCL_2_1));
1106 EXPECT_THAT(getDiagnosticString(), Eq(""));
1107 }
1108
1109 TEST_F(ValidateImage, TypeImage_OpenCL_Sampled1_Invalid) {
1110 const std::string code = GetKernelHeader() + R"(
1111 %img_type = OpTypeImage %void 2D 0 0 0 1 Unknown ReadOnly
1112 )";
1113
1114 CompileSuccessfully(code.c_str());
1115 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions(SPV_ENV_OPENCL_2_1));
1116 EXPECT_THAT(getDiagnosticString(),
1117 HasSubstr("Sampled must be 0 in the OpenCL environment."));
1118 }
1119
1120 TEST_F(ValidateImage, TypeImage_OpenCL_Sampled2_Invalid) {
1121 const std::string code = GetKernelHeader() + R"(
1122 %img_type = OpTypeImage %void 2D 0 0 0 2 Unknown ReadOnly
1123 )";
1124
1125 CompileSuccessfully(code.c_str());
1126 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions(SPV_ENV_OPENCL_2_1));
1127 EXPECT_THAT(getDiagnosticString(),
1128 HasSubstr("Sampled must be 0 in the OpenCL environment."));
1129 }
1130
1131 TEST_F(ValidateImage, TypeImage_OpenCL_AccessQualifierMissing) {
1132 const std::string code = GetKernelHeader() + R"(
1133 %img_type = OpTypeImage %void 2D 0 0 0 0 Unknown
1134 )";
1135
1136 CompileSuccessfully(code.c_str());
1137 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions(SPV_ENV_OPENCL_2_1));
1138 EXPECT_THAT(getDiagnosticString(),
1139 HasSubstr("In the OpenCL environment, the optional Access "
1140 "Qualifier must be present"));
1141 }
1142
1143 TEST_F(ValidateImage, TypeImage_Vulkan_Sampled1_OK) {
1144 const std::string code = GetShaderHeader() + R"(
1145 %img_type = OpTypeImage %f32 2D 0 0 0 1 Unknown
1146 )" + TrivialMain();
1147
1148 CompileSuccessfully(code.c_str());
1149 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_0));
1150 EXPECT_THAT(getDiagnosticString(), Eq(""));
1151 }
1152
1153 TEST_F(ValidateImage, TypeImage_Vulkan_Sampled2_OK) {
1154 const std::string code = GetShaderHeader() + R"(
1155 %img_type = OpTypeImage %f32 2D 0 0 0 2 Rgba32f
1156 )" + TrivialMain();
1157
1158 CompileSuccessfully(code.c_str());
1159 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_0));
1160 EXPECT_THAT(getDiagnosticString(), Eq(""));
1161 }
1162
1163 TEST_F(ValidateImage, TypeImage_Vulkan_Sampled0_Invalid) {
1164 const std::string code = GetShaderHeader() + R"(
1165 %img_type = OpTypeImage %f32 2D 0 0 0 0 Unknown
1166 )" + TrivialMain();
1167
1168 CompileSuccessfully(code.c_str());
1169 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions(SPV_ENV_VULKAN_1_0));
1170 EXPECT_THAT(getDiagnosticString(),
1171 AnyVUID("VUID-StandaloneSpirv-OpTypeImage-04657"));
1172 EXPECT_THAT(getDiagnosticString(),
1173 HasSubstr("Sampled must be 1 or 2 in the Vulkan environment."));
1174 }
1175
1176 TEST_F(ValidateImage, TypeImageWrongFormatForSubpassData) {
1177 const std::string code =
1178 GetShaderHeader("OpCapability InputAttachment\n", false) +
1179 R"(
1180 %img_type = OpTypeImage %f32 SubpassData 0 0 0 2 Rgba32f
1181 )";
1182
1183 CompileSuccessfully(code.c_str());
1184 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1185 EXPECT_THAT(getDiagnosticString(),
1186 HasSubstr("Dim SubpassData requires format Unknown"));
1187 }
1188
1189 TEST_F(ValidateImage, TypeImageMultisampleStorageImage_MissingCapability) {
1190 const std::string code = GetShaderHeader("", false) +
1191 R"(
1192 %img_type = OpTypeImage %f32 2D 0 0 1 2 Rgba32f
1193 )";
1194
1195 CompileSuccessfully(code.c_str());
1196 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions()) << code;
1197 EXPECT_THAT(getDiagnosticString(),
1198 HasSubstr("Capability StorageImageMultisample is required when "
1199 "using multisampled storage image"));
1200 }
1201
1202 TEST_F(ValidateImage, TypeImageMultisampleStorageImage_UsesCapability) {
1203 const std::string code =
1204 GetShaderHeader("OpCapability StorageImageMultisample\n", false) +
1205 R"(
1206 %img_type = OpTypeImage %f32 2D 0 0 1 2 Rgba32f
1207 )";
1208
1209 CompileSuccessfully(code.c_str());
1210 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions()) << code;
1211 EXPECT_THAT(getDiagnosticString(), Eq(""));
1212 }
1213
1214 TEST_F(ValidateImage, TypeImageMultisampleSubpassData_OK) {
1215 const std::string code =
1216 GetShaderHeader("OpCapability InputAttachment\n", false) +
1217 R"(
1218 %img_type = OpTypeImage %f32 SubpassData 0 0 1 2 Unknown
1219 )";
1220
1221 CompileSuccessfully(code.c_str());
1222 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions()) << code;
1223 EXPECT_THAT(getDiagnosticString(), Eq(""));
1224 }
1225
1226 TEST_F(ValidateImage, TypeSampledImage_NotImage_Error) {
1227 const std::string code = GetShaderHeader("", false) + R"(
1228 %simg_type = OpTypeSampledImage %f32
1229 )";
1230
1231 CompileSuccessfully(code.c_str());
1232 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1233 EXPECT_THAT(getDiagnosticString(),
1234 HasSubstr("Expected Image to be of type OpTypeImage"));
1235 }
1236
1237 TEST_F(ValidateImage, TypeSampledImage_Sampled0_Success) {
1238 // This is ok in the OpenCL and universal environments.
1239 // Vulkan will reject an OpTypeImage with Sampled=0, checked elsewhere.
1240 const std::string code = GetShaderHeader() + R"(
1241 %imty = OpTypeImage %f32 2D 0 0 0 0 Unknown
1242 %simg_type = OpTypeSampledImage %imty
1243 )" + TrivialMain();
1244
1245 CompileSuccessfully(code.c_str());
1246 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
1247 EXPECT_EQ(getDiagnosticString(), "");
1248 }
1249
1250 TEST_F(ValidateImage, TypeSampledImage_Sampled2_Error) {
1251 const std::string code = GetShaderHeader() + R"(
1252 %storage_image = OpTypeImage %f32 2D 0 0 0 2 Rgba32f
1253 %simg_type = OpTypeSampledImage %storage_image
1254 )" + TrivialMain();
1255
1256 CompileSuccessfully(code.c_str());
1257 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1258 EXPECT_THAT(getDiagnosticString(),
1259 HasSubstr("Sampled image type requires an image type with "
1260 "\"Sampled\" operand set to 0 or 1"));
1261 }
1262
1263 TEST_F(ValidateImage, TypeSampledImage_Sampled1_Success) {
1264 const std::string code = GetShaderHeader() + R"(
1265 %im = OpTypeImage %f32 2D 0 0 0 1 Unknown
1266 %simg_type = OpTypeSampledImage %im
1267 )" + TrivialMain();
1268
1269 CompileSuccessfully(code.c_str());
1270 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
1271 EXPECT_EQ(getDiagnosticString(), "");
1272 }
1273
1274 TEST_F(ValidateImage, SampledImageSuccess) {
1275 const std::string body = R"(
1276 %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
1277 %sampler = OpLoad %type_sampler %uniform_sampler
1278 %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
1279 )";
1280
1281 CompileSuccessfully(GenerateShaderCode(body).c_str());
1282 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
1283 }
1284
1285 TEST_F(ValidateImage, SampledImageVulkanSuccess) {
1286 const std::string body = R"(
1287 %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
1288 %sampler = OpLoad %type_sampler %uniform_sampler
1289 %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
1290 )";
1291
1292 const spv_target_env env = SPV_ENV_VULKAN_1_0;
1293 CompileSuccessfully(GenerateShaderCode(body, "", "Fragment", "", env), env);
1294 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions(env));
1295 }
1296
1297 TEST_F(ValidateImage, SampledImageWrongResultType) {
1298 const std::string body = R"(
1299 %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
1300 %sampler = OpLoad %type_sampler %uniform_sampler
1301 %simg = OpSampledImage %type_image_f32_2d_0001 %img %sampler
1302 )";
1303
1304 CompileSuccessfully(GenerateShaderCode(body).c_str());
1305 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1306 EXPECT_THAT(getDiagnosticString(),
1307 HasSubstr("Expected Result Type to be OpTypeSampledImage"));
1308 }
1309
1310 TEST_F(ValidateImage, SampledImageNotImage) {
1311 const std::string body = R"(
1312 %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
1313 %sampler = OpLoad %type_sampler %uniform_sampler
1314 %simg1 = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
1315 %simg2 = OpSampledImage %type_sampled_image_f32_2d_0001 %simg1 %sampler
1316 )";
1317
1318 CompileSuccessfully(GenerateShaderCode(body).c_str());
1319 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1320 EXPECT_THAT(getDiagnosticString(),
1321 HasSubstr("Expected Image to be of type OpTypeImage"));
1322 }
1323
1324 TEST_F(ValidateImage, SampledImageImageNotForSampling) {
1325 const std::string code = GetShaderHeader() + R"(
1326 %im_ty = OpTypeImage %f32 2D 0 0 0 2 Unknown
1327 %sampler_ty = OpTypeSampler
1328 %sampled_image_ty = OpTypeSampledImage %im_ty ; will fail here first!
1329
1330 %ptr_im_ty = OpTypePointer UniformConstant %im_ty
1331 %var_im = OpVariable %ptr_im_ty UniformConstant
1332
1333 %ptr_sampler_ty = OpTypePointer UniformConstant %sampler_ty
1334 %var_sampler = OpVariable %ptr_sampler_ty UniformConstant
1335
1336 %main = OpFunction %void None %func
1337 %entry = OpLabel
1338 %im = OpLoad %im_ty %var_im
1339 %sampler = OpLoad %sampler_ty %var_sampler
1340 %sampled_image = OpSampledImage %sampled_image_ty %im %sampler
1341 OpReturn
1342 OpFunctionEnd
1343 )";
1344
1345 CompileSuccessfully(code.c_str());
1346 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1347 EXPECT_THAT(getDiagnosticString(),
1348 HasSubstr("Sampled image type requires an image type with "
1349 "\"Sampled\" operand set to 0 or 1"))
1350 << code;
1351 }
1352
1353 TEST_F(ValidateImage, SampledImageNotSampler) {
1354 const std::string body = R"(
1355 %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
1356 %sampler = OpLoad %type_sampler %uniform_sampler
1357 %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %img
1358 )";
1359
1360 CompileSuccessfully(GenerateShaderCode(body).c_str());
1361 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1362 EXPECT_THAT(getDiagnosticString(),
1363 HasSubstr("Expected Sampler to be of type OpTypeSampler"));
1364 }
1365
1366 TEST_F(ValidateImage, SampledImageIsStorage) {
1367 const std::string declarations = R"(
1368 %type_sampled_image_f32_2d_0002 = OpTypeSampledImage %type_image_f32_2d_0002
1369 )";
1370 const std::string body = R"(
1371 %img = OpLoad %type_image_f32_2d_0002 %uniform_image_f32_2d_0002
1372 %sampler = OpLoad %type_sampler %uniform_sampler
1373 %simg = OpSampledImage %type_sampled_image_f32_2d_0002 %img %sampler
1374 )";
1375
1376 CompileSuccessfully(GenerateShaderCode(body, "", "Fragment", "",
1377 SPV_ENV_UNIVERSAL_1_0, "GLSL450",
1378 declarations)
1379 .c_str());
1380 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1381 EXPECT_THAT(getDiagnosticString(),
1382 HasSubstr("Sampled image type requires an image type with "
1383 "\"Sampled\" operand set to 0 or 1"));
1384 }
1385
1386 TEST_F(ValidateImage, ImageTexelPointerSuccess) {
1387 const std::string body = R"(
1388 %texel_ptr = OpImageTexelPointer %ptr_Image_u32 %private_image_u32_buffer_0002_r32ui %u32_0 %u32_0
1389 %sum = OpAtomicIAdd %u32 %texel_ptr %u32_1 %u32_0 %u32_1
1390 )";
1391
1392 CompileSuccessfully(GenerateShaderCode(body).c_str());
1393 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
1394 }
1395
1396 TEST_F(ValidateImage, ImageTexelPointerResultTypeNotPointer) {
1397 const std::string body = R"(
1398 %texel_ptr = OpImageTexelPointer %type_image_u32_buffer_0002_r32ui %private_image_u32_buffer_0002_r32ui %u32_0 %u32_0
1399 %sum = OpAtomicIAdd %u32 %texel_ptr %u32_1 %u32_0 %u32_1
1400 )";
1401
1402 CompileSuccessfully(GenerateShaderCode(body).c_str());
1403 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1404 EXPECT_THAT(getDiagnosticString(),
1405 HasSubstr("Expected Result Type to be a pointer"));
1406 }
1407
1408 TEST_F(ValidateImage, ImageTexelPointerResultTypeNotImageClass) {
1409 const std::string body = R"(
1410 %texel_ptr = OpImageTexelPointer %ptr_image_f32_cube_0101 %private_image_u32_buffer_0002_r32ui %u32_0 %u32_0
1411 %sum = OpAtomicIAdd %u32 %texel_ptr %u32_1 %u32_0 %u32_1
1412 )";
1413
1414 CompileSuccessfully(GenerateShaderCode(body).c_str());
1415 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1416 EXPECT_THAT(getDiagnosticString(),
1417 HasSubstr("Expected Result Type to be a pointer whose "
1418 "Storage Class operand is Image"));
1419 }
1420
1421 TEST_F(ValidateImage, ImageTexelPointerResultTypeNotNumericNorVoid) {
1422 const std::string body = R"(
1423 %texel_ptr = OpImageTexelPointer %ptr_Image_u32arr4 %private_image_u32_buffer_0002_r32ui %u32_0 %u32_0
1424 %sum = OpAtomicIAdd %u32 %texel_ptr %u32_1 %u32_0 %u32_1
1425 )";
1426
1427 CompileSuccessfully(GenerateShaderCode(body).c_str());
1428 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1429 EXPECT_THAT(
1430 getDiagnosticString(),
1431 HasSubstr("Expected Result Type to be a pointer whose Type operand "
1432 "must be a scalar numerical type or OpTypeVoid"));
1433 }
1434
1435 TEST_F(ValidateImage, ImageTexelPointerImageNotResultTypePointer) {
1436 const std::string body = R"(
1437 %texel_ptr = OpImageTexelPointer %ptr_Image_u32 %type_image_f32_buffer_0002_r32ui %u32_0 %u32_0
1438 %sum = OpAtomicIAdd %u32 %texel_ptr %u32_1 %u32_0 %u32_1
1439 )";
1440
1441 CompileSuccessfully(GenerateShaderCode(body).c_str());
1442 ASSERT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions());
1443 EXPECT_THAT(getDiagnosticString(),
1444 HasSubstr("Operand '156[%156]' cannot be a "
1445 "type"));
1446 }
1447
1448 TEST_F(ValidateImage, ImageTexelPointerImageNotImage) {
1449 const std::string body = R"(
1450 %texel_ptr = OpImageTexelPointer %ptr_Image_u32 %uniform_sampler %u32_0 %u32_0
1451 %sum = OpAtomicIAdd %u32 %texel_ptr %u32_1 %u32_0 %u32_1
1452 )";
1453
1454 CompileSuccessfully(GenerateShaderCode(body).c_str());
1455 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1456 EXPECT_THAT(
1457 getDiagnosticString(),
1458 HasSubstr("Expected Image to be OpTypePointer with Type OpTypeImage"));
1459 }
1460
1461 TEST_F(ValidateImage, ImageTexelPointerImageSampledNotResultType) {
1462 const std::string body = R"(
1463 %texel_ptr = OpImageTexelPointer %ptr_Image_u32 %uniform_image_f32_cube_0101 %u32_0 %u32_0
1464 %sum = OpAtomicIAdd %u32 %texel_ptr %u32_1 %u32_0 %u32_1
1465 )";
1466
1467 CompileSuccessfully(GenerateShaderCode(body).c_str());
1468 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1469 EXPECT_THAT(getDiagnosticString(),
1470 HasSubstr("Expected Image 'Sampled Type' to be the same as the "
1471 "Type pointed to by Result Type"));
1472 }
1473
1474 TEST_F(ValidateImage, ImageTexelPointerImageDimSubpassDataBad) {
1475 const std::string body = R"(
1476 %texel_ptr = OpImageTexelPointer %ptr_Image_u32 %private_image_u32_spd_0002 %u32_0 %u32_0
1477 %sum = OpAtomicIAdd %u32 %texel_ptr %u32_1 %u32_0 %u32_1
1478 )";
1479
1480 CompileSuccessfully(GenerateShaderCode(body).c_str());
1481 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1482 EXPECT_THAT(
1483 getDiagnosticString(),
1484 HasSubstr(
1485 "Image Dim SubpassData cannot be used with OpImageTexelPointer"));
1486 }
1487
1488 TEST_F(ValidateImage, ImageTexelPointerImageCoordTypeBad) {
1489 const std::string body = R"(
1490 %texel_ptr = OpImageTexelPointer %ptr_Image_f32 %private_image_f32_buffer_0002_r32ui %f32_0 %f32_0
1491 %sum = OpAtomicIAdd %f32 %texel_ptr %f32_1 %f32_0 %f32_1
1492 )";
1493
1494 CompileSuccessfully(GenerateShaderCode(body).c_str());
1495 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1496 EXPECT_THAT(
1497 getDiagnosticString(),
1498 HasSubstr("Expected Coordinate to be a 32-bit integer scalar or vector"));
1499 }
1500
1501 TEST_F(ValidateImage, ImageTexelPointerImageCoordSizeBad) {
1502 const std::string body = R"(
1503 %texel_ptr = OpImageTexelPointer %ptr_Image_u32 %uniform_image_u32_2d_0002 %u32vec3_012 %u32_0
1504 %sum = OpAtomicIAdd %u32 %texel_ptr %u32_1 %u32_0 %u32_1
1505 )";
1506
1507 CompileSuccessfully(GenerateShaderCode(body).c_str());
1508 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1509 EXPECT_THAT(
1510 getDiagnosticString(),
1511 HasSubstr("Expected Coordinate to have 2 components, but given 3"));
1512 }
1513
1514 TEST_F(ValidateImage, ImageTexelPointerSampleNotIntScalar) {
1515 const std::string body = R"(
1516 %texel_ptr = OpImageTexelPointer %ptr_Image_u32 %private_image_u32_buffer_0002_r32ui %u32_0 %f32_0
1517 %sum = OpAtomicIAdd %u32 %texel_ptr %u32_1 %u32_0 %u32_1
1518 )";
1519
1520 CompileSuccessfully(GenerateShaderCode(body).c_str());
1521 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1522 EXPECT_THAT(getDiagnosticString(),
1523 HasSubstr("Expected Sample to be integer scalar"));
1524 }
1525
1526 TEST_F(ValidateImage, ImageTexelPointerSampleNotZeroForImageWithMSZero) {
1527 const std::string body = R"(
1528 %texel_ptr = OpImageTexelPointer %ptr_Image_u32 %private_image_u32_buffer_0002_r32ui %u32_0 %u32_1
1529 %sum = OpAtomicIAdd %u32 %texel_ptr %u32_1 %u32_0 %u32_1
1530 )";
1531
1532 CompileSuccessfully(GenerateShaderCode(body).c_str());
1533 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1534 EXPECT_THAT(getDiagnosticString(),
1535 HasSubstr("Expected Sample for Image with MS 0 to be a valid "
1536 "<id> for the value 0"));
1537 }
1538
1539 TEST_F(ValidateImage, SampleImplicitLodSuccess) {
1540 const std::string body = R"(
1541 %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
1542 %sampler = OpLoad %type_sampler %uniform_sampler
1543 %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
1544 %res1 = OpImageSampleImplicitLod %f32vec4 %simg %f32vec2_hh
1545 %res2 = OpImageSampleImplicitLod %f32vec4 %simg %f32vec2_hh Bias %f32_0_25
1546 %res4 = OpImageSampleImplicitLod %f32vec4 %simg %f32vec2_hh ConstOffset %s32vec2_01
1547 %res5 = OpImageSampleImplicitLod %f32vec4 %simg %f32vec2_hh Offset %s32vec2_01
1548 %res6 = OpImageSampleImplicitLod %f32vec4 %simg %f32vec2_hh MinLod %f32_0_5
1549 %res7 = OpImageSampleImplicitLod %f32vec4 %simg %f32vec2_hh Bias|Offset|MinLod %f32_0_25 %s32vec2_01 %f32_0_5
1550 %res8 = OpImageSampleImplicitLod %f32vec4 %simg %f32vec2_hh NonPrivateTexelKHR
1551 )";
1552
1553 const std::string extra = R"(
1554 OpCapability VulkanMemoryModelKHR
1555 OpExtension "SPV_KHR_vulkan_memory_model"
1556 )";
1557 CompileSuccessfully(GenerateShaderCode(body, extra, "Fragment", "",
1558 SPV_ENV_UNIVERSAL_1_3, "VulkanKHR")
1559 .c_str(),
1560 SPV_ENV_UNIVERSAL_1_3);
1561 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_UNIVERSAL_1_3));
1562 }
1563
1564 TEST_F(ValidateImage, SampleImplicitLodWrongResultType) {
1565 const std::string body = R"(
1566 %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
1567 %sampler = OpLoad %type_sampler %uniform_sampler
1568 %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
1569 %res1 = OpImageSampleImplicitLod %f32 %simg %f32vec2_hh
1570 )";
1571
1572 CompileSuccessfully(GenerateShaderCode(body).c_str());
1573 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1574 EXPECT_THAT(getDiagnosticString(),
1575 HasSubstr("Expected Result Type to be int or float vector type"));
1576 }
1577
1578 TEST_F(ValidateImage, SampleImplicitLodWrongNumComponentsResultType) {
1579 const std::string body = R"(
1580 %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
1581 %sampler = OpLoad %type_sampler %uniform_sampler
1582 %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
1583 %res1 = OpImageSampleImplicitLod %f32vec3 %simg %f32vec2_hh
1584 )";
1585
1586 CompileSuccessfully(GenerateShaderCode(body).c_str());
1587 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1588 EXPECT_THAT(getDiagnosticString(),
1589 HasSubstr("Expected Result Type to have 4 components"));
1590 }
1591
1592 TEST_F(ValidateImage, SampleImplicitLodNotSampledImage) {
1593 const std::string body = R"(
1594 %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
1595 %res1 = OpImageSampleImplicitLod %f32vec4 %img %f32vec2_hh
1596 )";
1597
1598 CompileSuccessfully(GenerateShaderCode(body).c_str());
1599 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1600 EXPECT_THAT(
1601 getDiagnosticString(),
1602 HasSubstr("Expected Sampled Image to be of type OpTypeSampledImage"));
1603 }
1604
1605 TEST_F(ValidateImage, SampleImplicitLodMultisampleError) {
1606 const std::string body = R"(
1607 %img = OpLoad %type_image_f32_2d_0011 %uniform_image_f32_2d_0011
1608 %sampler = OpLoad %type_sampler %uniform_sampler
1609 %simg = OpSampledImage %type_sampled_image_f32_2d_0011 %img %sampler
1610 %res1 = OpImageSampleExplicitLod %f32vec4 %simg %f32vec2_hh Sample %u32_1
1611 )";
1612
1613 CompileSuccessfully(GenerateShaderCode(body).c_str());
1614 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1615 EXPECT_THAT(getDiagnosticString(),
1616 HasSubstr("Sampling operation is invalid for multisample image"));
1617 }
1618
1619 TEST_F(ValidateImage, SampleImplicitLodWrongSampledType) {
1620 const std::string body = R"(
1621 %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
1622 %sampler = OpLoad %type_sampler %uniform_sampler
1623 %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
1624 %res1 = OpImageSampleImplicitLod %u32vec4 %simg %f32vec2_00
1625 )";
1626
1627 CompileSuccessfully(GenerateShaderCode(body).c_str());
1628 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1629 EXPECT_THAT(getDiagnosticString(),
1630 HasSubstr("Expected Image 'Sampled Type' to be the same as "
1631 "Result Type components"));
1632 }
1633
1634 TEST_F(ValidateImage, SampleImplicitLodVoidSampledType) {
1635 const std::string body = R"(
1636 %img = OpLoad %type_image_void_2d_0001 %uniform_image_void_2d_0001
1637 %sampler = OpLoad %type_sampler %uniform_sampler
1638 %simg = OpSampledImage %type_sampled_image_void_2d_0001 %img %sampler
1639 %res1 = OpImageSampleImplicitLod %u32vec4 %simg %f32vec2_00
1640 )";
1641
1642 CompileSuccessfully(GenerateShaderCode(body).c_str());
1643 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
1644 }
1645
1646 TEST_F(ValidateImage, SampleImplicitLodWrongCoordinateType) {
1647 const std::string body = R"(
1648 %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
1649 %sampler = OpLoad %type_sampler %uniform_sampler
1650 %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
1651 %res1 = OpImageSampleImplicitLod %f32vec4 %simg %img
1652 )";
1653
1654 CompileSuccessfully(GenerateShaderCode(body).c_str());
1655 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1656 EXPECT_THAT(
1657 getDiagnosticString(),
1658 HasSubstr("Expected Coordinate to be a 32-bit float scalar or vector"));
1659 }
1660
1661 TEST_F(ValidateImage, SampleImplicitLodCoordinateSizeTooSmall) {
1662 const std::string body = R"(
1663 %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
1664 %sampler = OpLoad %type_sampler %uniform_sampler
1665 %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
1666 %res1 = OpImageSampleImplicitLod %f32vec4 %simg %f32_0_5
1667 )";
1668
1669 CompileSuccessfully(GenerateShaderCode(body).c_str());
1670 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1671 EXPECT_THAT(getDiagnosticString(),
1672 HasSubstr("Expected Coordinate to have at least 2 components, "
1673 "but given only 1"));
1674 }
1675
1676 TEST_F(ValidateImage, SampleExplicitLodSuccessShader) {
1677 const std::string body = R"(
1678 %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
1679 %sampler = OpLoad %type_sampler %uniform_sampler
1680 %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
1681 %res1 = OpImageSampleExplicitLod %f32vec4 %simg %f32vec4_0000 Lod %f32_1
1682 %res2 = OpImageSampleExplicitLod %f32vec4 %simg %f32vec2_hh Grad %f32vec2_10 %f32vec2_01
1683 %res3 = OpImageSampleExplicitLod %f32vec4 %simg %f32vec2_hh ConstOffset %s32vec2_01
1684 %res4 = OpImageSampleExplicitLod %f32vec4 %simg %f32vec3_hhh Offset %s32vec2_01
1685 %res5 = OpImageSampleExplicitLod %f32vec4 %simg %f32vec2_hh Grad|Offset|MinLod %f32vec2_10 %f32vec2_01 %s32vec2_01 %f32_0_5
1686 %res6 = OpImageSampleExplicitLod %f32vec4 %simg %f32vec4_0000 Lod|NonPrivateTexelKHR %f32_1
1687 )";
1688
1689 const std::string extra = R"(
1690 OpCapability VulkanMemoryModelKHR
1691 OpExtension "SPV_KHR_vulkan_memory_model"
1692 )";
1693 CompileSuccessfully(GenerateShaderCode(body, extra, "Fragment", "",
1694 SPV_ENV_UNIVERSAL_1_3, "VulkanKHR")
1695 .c_str(),
1696 SPV_ENV_UNIVERSAL_1_3);
1697 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_UNIVERSAL_1_3));
1698 }
1699
1700 TEST_F(ValidateImage, SampleExplicitLodSuccessKernel) {
1701 const std::string body = R"(
1702 %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
1703 %sampler = OpLoad %type_sampler %uniform_sampler
1704 %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
1705 %res1 = OpImageSampleExplicitLod %f32vec4 %simg %u32vec4_0123 Lod %f32_1
1706 %res2 = OpImageSampleExplicitLod %f32vec4 %simg %u32vec2_01 Grad %f32vec2_10 %f32vec2_01
1707 %res3 = OpImageSampleExplicitLod %f32vec4 %simg %f32vec2_hh ConstOffset %u32vec2_01
1708 %res4 = OpImageSampleExplicitLod %f32vec4 %simg %u32vec2_01 Offset %u32vec2_01
1709 %res5 = OpImageSampleExplicitLod %f32vec4 %simg %f32vec2_hh Grad|Offset %f32vec2_10 %f32vec2_01 %u32vec2_01
1710 )";
1711
1712 CompileSuccessfully(GenerateKernelCode(body).c_str());
1713 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
1714 }
1715
1716 TEST_F(ValidateImage, SampleExplicitLodSuccessCubeArrayed) {
1717 const std::string body = R"(
1718 %img = OpLoad %type_image_f32_cube_0101 %uniform_image_f32_cube_0101
1719 %sampler = OpLoad %type_sampler %uniform_sampler
1720 %simg = OpSampledImage %type_sampled_image_f32_cube_0101 %img %sampler
1721 %res1 = OpImageSampleExplicitLod %f32vec4 %simg %f32vec4_0000 Grad %f32vec3_hhh %f32vec3_hhh
1722 )";
1723
1724 CompileSuccessfully(GenerateShaderCode(body).c_str());
1725 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
1726 }
1727
1728 TEST_F(ValidateImage, SampleExplicitLodWrongResultType) {
1729 const std::string body = R"(
1730 %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
1731 %sampler = OpLoad %type_sampler %uniform_sampler
1732 %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
1733 %res1 = OpImageSampleExplicitLod %f32 %simg %f32vec2_hh Lod %f32_1
1734 )";
1735
1736 CompileSuccessfully(GenerateShaderCode(body).c_str());
1737 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1738 EXPECT_THAT(getDiagnosticString(),
1739 HasSubstr("Expected Result Type to be int or float vector type"));
1740 }
1741
1742 TEST_F(ValidateImage, SampleExplicitLodWrongNumComponentsResultType) {
1743 const std::string body = R"(
1744 %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
1745 %sampler = OpLoad %type_sampler %uniform_sampler
1746 %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
1747 %res1 = OpImageSampleExplicitLod %f32vec3 %simg %f32vec2_hh Lod %f32_1
1748 )";
1749
1750 CompileSuccessfully(GenerateShaderCode(body).c_str());
1751 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1752 EXPECT_THAT(getDiagnosticString(),
1753 HasSubstr("Expected Result Type to have 4 components"));
1754 }
1755
1756 TEST_F(ValidateImage, SampleExplicitLodNotSampledImage) {
1757 const std::string body = R"(
1758 %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
1759 %res1 = OpImageSampleExplicitLod %f32vec4 %img %f32vec2_hh Lod %f32_1
1760 )";
1761
1762 CompileSuccessfully(GenerateShaderCode(body).c_str());
1763 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1764 EXPECT_THAT(
1765 getDiagnosticString(),
1766 HasSubstr("Expected Sampled Image to be of type OpTypeSampledImage"));
1767 }
1768
1769 TEST_F(ValidateImage, SampleExplicitLodMultisampleError) {
1770 const std::string body = R"(
1771 %img = OpLoad %type_image_f32_2d_0011 %uniform_image_f32_2d_0011
1772 %sampler = OpLoad %type_sampler %uniform_sampler
1773 %simg = OpSampledImage %type_sampled_image_f32_2d_0011 %img %sampler
1774 %res1 = OpImageSampleImplicitLod %f32vec4 %simg %f32vec2_hh Lod|Sample %f32_0 %u32_1
1775 )";
1776
1777 CompileSuccessfully(GenerateShaderCode(body).c_str());
1778 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1779 EXPECT_THAT(getDiagnosticString(),
1780 HasSubstr("Sampling operation is invalid for multisample image"));
1781 }
1782
1783 TEST_F(ValidateImage, SampleExplicitLodWrongSampledType) {
1784 const std::string body = R"(
1785 %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
1786 %sampler = OpLoad %type_sampler %uniform_sampler
1787 %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
1788 %res1 = OpImageSampleExplicitLod %u32vec4 %simg %f32vec2_00 Lod %f32_1
1789 )";
1790
1791 CompileSuccessfully(GenerateShaderCode(body).c_str());
1792 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1793 EXPECT_THAT(getDiagnosticString(),
1794 HasSubstr("Expected Image 'Sampled Type' to be the same as "
1795 "Result Type components"));
1796 }
1797
1798 TEST_F(ValidateImage, SampleExplicitLodVoidSampledType) {
1799 const std::string body = R"(
1800 %img = OpLoad %type_image_void_2d_0001 %uniform_image_void_2d_0001
1801 %sampler = OpLoad %type_sampler %uniform_sampler
1802 %simg = OpSampledImage %type_sampled_image_void_2d_0001 %img %sampler
1803 %res1 = OpImageSampleExplicitLod %u32vec4 %simg %f32vec2_00 Lod %f32_1
1804 )";
1805
1806 CompileSuccessfully(GenerateShaderCode(body).c_str());
1807 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
1808 }
1809
1810 TEST_F(ValidateImage, SampleExplicitLodWrongCoordinateType) {
1811 const std::string body = R"(
1812 %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
1813 %sampler = OpLoad %type_sampler %uniform_sampler
1814 %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
1815 %res1 = OpImageSampleExplicitLod %f32vec4 %simg %img Lod %f32_1
1816 )";
1817
1818 CompileSuccessfully(GenerateShaderCode(body).c_str());
1819 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1820 EXPECT_THAT(getDiagnosticString(),
1821 HasSubstr("Expected Coordinate to be a 32-bit integer or float "
1822 "scalar or vector"));
1823 }
1824
1825 TEST_F(ValidateImage, SampleExplicitLodWrongCoordinateType16Bit) {
1826 const std::string body = R"(
1827 %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
1828 %sampler = OpLoad %type_sampler %uniform_sampler
1829 %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
1830 %res1 = OpImageSampleExplicitLod %f32vec4 %simg %f16vec2_00 Lod %f32_1
1831 )";
1832
1833 CompileSuccessfully(GenerateShaderCode(body).c_str());
1834 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1835 EXPECT_THAT(getDiagnosticString(),
1836 HasSubstr("Expected Coordinate to be a 32-bit scalar or vector"));
1837 }
1838
1839 TEST_F(ValidateImage, SampleExplicitLodCoordinateSizeTooSmall) {
1840 const std::string body = R"(
1841 %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
1842 %sampler = OpLoad %type_sampler %uniform_sampler
1843 %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
1844 %res1 = OpImageSampleExplicitLod %f32vec4 %simg %f32_0_5 Lod %f32_1
1845 )";
1846
1847 CompileSuccessfully(GenerateShaderCode(body).c_str());
1848 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1849 EXPECT_THAT(getDiagnosticString(),
1850 HasSubstr("Expected Coordinate to have at least 2 components, "
1851 "but given only 1"));
1852 }
1853
1854 TEST_F(ValidateImage, SampleExplicitLodBias) {
1855 const std::string body = R"(
1856 %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
1857 %sampler = OpLoad %type_sampler %uniform_sampler
1858 %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
1859 %res1 = OpImageSampleExplicitLod %f32vec4 %simg %f32vec2_00 Bias|Lod %f32_1 %f32_1
1860 )";
1861
1862 CompileSuccessfully(GenerateShaderCode(body).c_str());
1863 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1864 EXPECT_THAT(
1865 getDiagnosticString(),
1866 HasSubstr(
1867 "Image Operand Bias can only be used with ImplicitLod opcodes"));
1868 }
1869
1870 TEST_F(ValidateImage, LodAndGrad) {
1871 const std::string body = R"(
1872 %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
1873 %sampler = OpLoad %type_sampler %uniform_sampler
1874 %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
1875 %res1 = OpImageSampleExplicitLod %f32vec4 %simg %f32vec2_00 Lod|Grad %f32_1 %f32vec2_hh %f32vec2_hh
1876 )";
1877
1878 CompileSuccessfully(GenerateShaderCode(body).c_str());
1879 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1880 EXPECT_THAT(
1881 getDiagnosticString(),
1882 HasSubstr(
1883 "Image Operand bits Lod and Grad cannot be set at the same time"));
1884 }
1885
1886 TEST_F(ValidateImage, ImplicitLodWithLod) {
1887 const std::string body = R"(
1888 %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
1889 %sampler = OpLoad %type_sampler %uniform_sampler
1890 %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
1891 %res2 = OpImageSampleImplicitLod %f32vec4 %simg %f32vec2_hh Lod %f32_0_5
1892 )";
1893
1894 CompileSuccessfully(GenerateShaderCode(body).c_str());
1895 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1896 EXPECT_THAT(
1897 getDiagnosticString(),
1898 HasSubstr("Image Operand Lod can only be used with ExplicitLod opcodes "
1899 "and OpImageFetch"));
1900 }
1901
1902 TEST_F(ValidateImage, LodWrongType) {
1903 const std::string body = R"(
1904 %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
1905 %sampler = OpLoad %type_sampler %uniform_sampler
1906 %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
1907 %res1 = OpImageSampleExplicitLod %f32vec4 %simg %f32vec2_00 Lod %f32vec2_hh)";
1908
1909 CompileSuccessfully(GenerateShaderCode(body).c_str());
1910 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1911 EXPECT_THAT(
1912 getDiagnosticString(),
1913 HasSubstr("Expected Image Operand Lod to be a 32-bit float scalar when "
1914 "used with ExplicitLod"));
1915 }
1916
1917 TEST_F(ValidateImage, LodWithHalf) {
1918 const std::string body = R"(
1919 %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
1920 %sampler = OpLoad %type_sampler %uniform_sampler
1921 %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
1922 %res1 = OpImageSampleExplicitLod %f32vec4 %simg %f32vec2_00 Lod %f16_0
1923 )";
1924
1925 CompileSuccessfully(GenerateShaderCode(body).c_str());
1926 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1927 EXPECT_THAT(getDiagnosticString(),
1928 HasSubstr("Expected Image Operand Lod to be a 32-bit float "
1929 "scalar when used with ExplicitLod"));
1930 }
1931
1932 TEST_F(ValidateImage, LodWrongDim) {
1933 const std::string body = R"(
1934 %img = OpLoad %type_image_f32_rect_0001 %uniform_image_f32_rect_0001
1935 %sampler = OpLoad %type_sampler %uniform_sampler
1936 %simg = OpSampledImage %type_sampled_image_f32_rect_0001 %img %sampler
1937 %res1 = OpImageSampleExplicitLod %f32vec4 %simg %f32vec2_00 Lod %f32_0)";
1938
1939 CompileSuccessfully(GenerateShaderCode(body).c_str());
1940 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1941 EXPECT_THAT(getDiagnosticString(),
1942 HasSubstr("Image Operand Lod requires 'Dim' parameter to be 1D, "
1943 "2D, 3D or Cube"));
1944 }
1945
1946 TEST_F(ValidateImage, LodWrongMultisample) {
1947 const std::string body = R"(
1948 %img = OpLoad %type_image_f32_2d_0011 %uniform_image_f32_2d_0011
1949 %res1 = OpImageFetch %f32vec4 %img %u32vec2_01 Lod|Sample %u32_1 %u32_1
1950 )";
1951
1952 CompileSuccessfully(GenerateShaderCode(body).c_str());
1953 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1954 EXPECT_THAT(getDiagnosticString(),
1955 HasSubstr("Image Operand Lod requires 'MS' parameter to be 0"));
1956 }
1957
1958 TEST_F(ValidateImage, MinLodIncompatible) {
1959 const std::string body = R"(
1960 %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
1961 %sampler = OpLoad %type_sampler %uniform_sampler
1962 %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
1963 %res1 = OpImageSampleExplicitLod %f32vec4 %simg %f32vec2_00 Lod|MinLod %f32_0 %f32_0)";
1964
1965 CompileSuccessfully(GenerateShaderCode(body).c_str());
1966 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1967 EXPECT_THAT(
1968 getDiagnosticString(),
1969 HasSubstr(
1970 "Image Operand MinLod can only be used with ImplicitLod opcodes or "
1971 "together with Image Operand Grad"));
1972 }
1973
1974 TEST_F(ValidateImage, ImplicitLodWithGrad) {
1975 const std::string body = R"(
1976 %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
1977 %sampler = OpLoad %type_sampler %uniform_sampler
1978 %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
1979 %res2 = OpImageSampleImplicitLod %f32vec4 %simg %f32vec2_hh Grad %f32vec2_hh %f32vec2_hh
1980 )";
1981
1982 CompileSuccessfully(GenerateShaderCode(body).c_str());
1983 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1984 EXPECT_THAT(
1985 getDiagnosticString(),
1986 HasSubstr(
1987 "Image Operand Grad can only be used with ExplicitLod opcodes"));
1988 }
1989
1990 TEST_F(ValidateImage, SampleImplicitLodCubeArrayedSuccess) {
1991 const std::string body = R"(
1992 %img = OpLoad %type_image_f32_cube_0101 %uniform_image_f32_cube_0101
1993 %sampler = OpLoad %type_sampler %uniform_sampler
1994 %simg = OpSampledImage %type_sampled_image_f32_cube_0101 %img %sampler
1995 %res1 = OpImageSampleImplicitLod %f32vec4 %simg %f32vec4_0000
1996 %res2 = OpImageSampleImplicitLod %f32vec4 %simg %f32vec4_0000 Bias %f32_0_25
1997 %res4 = OpImageSampleImplicitLod %f32vec4 %simg %f32vec4_0000 MinLod %f32_0_5
1998 %res5 = OpImageSampleImplicitLod %f32vec4 %simg %f32vec4_0000 Bias|MinLod %f32_0_25 %f32_0_5
1999 )";
2000
2001 CompileSuccessfully(GenerateShaderCode(body).c_str());
2002 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
2003 }
2004
2005 TEST_F(ValidateImage, SampleImplicitLodBiasWrongType) {
2006 const std::string body = R"(
2007 %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
2008 %sampler = OpLoad %type_sampler %uniform_sampler
2009 %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
2010 %res2 = OpImageSampleImplicitLod %f32vec4 %simg %f32vec2_hh Bias %u32_0
2011 )";
2012
2013 CompileSuccessfully(GenerateShaderCode(body).c_str());
2014 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
2015 EXPECT_THAT(
2016 getDiagnosticString(),
2017 HasSubstr("Expected Image Operand Bias to be a 32-bit float scalar"));
2018 }
2019
2020 TEST_F(ValidateImage, SampleImplicitLodBias16Bit) {
2021 const std::string body = R"(
2022 %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
2023 %sampler = OpLoad %type_sampler %uniform_sampler
2024 %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
2025 %res2 = OpImageSampleImplicitLod %f32vec4 %simg %f32vec2_hh Bias %f16_0
2026 )";
2027
2028 CompileSuccessfully(GenerateShaderCode(body).c_str());
2029 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
2030 EXPECT_THAT(
2031 getDiagnosticString(),
2032 HasSubstr("Expected Image Operand Bias to be a 32-bit float scalar"));
2033 }
2034
2035 TEST_F(ValidateImage, SampleImplicitLodBiasWrongDim) {
2036 const std::string body = R"(
2037 %img = OpLoad %type_image_f32_rect_0001 %uniform_image_f32_rect_0001
2038 %sampler = OpLoad %type_sampler %uniform_sampler
2039 %simg = OpSampledImage %type_sampled_image_f32_rect_0001 %img %sampler
2040 %res2 = OpImageSampleImplicitLod %f32vec4 %simg %f32vec2_hh Bias %f32_0
2041 )";
2042
2043 CompileSuccessfully(GenerateShaderCode(body).c_str());
2044 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
2045 EXPECT_THAT(getDiagnosticString(),
2046 HasSubstr("Image Operand Bias requires 'Dim' parameter to be 1D, "
2047 "2D, 3D or Cube"));
2048 }
2049
2050 TEST_F(ValidateImage, SampleExplicitLodGradDxWrongType) {
2051 const std::string body = R"(
2052 %img = OpLoad %type_image_f32_cube_0101 %uniform_image_f32_cube_0101
2053 %sampler = OpLoad %type_sampler %uniform_sampler
2054 %simg = OpSampledImage %type_sampled_image_f32_cube_0101 %img %sampler
2055 %res1 = OpImageSampleExplicitLod %f32vec4 %simg %f32vec4_0000 Grad %s32vec3_012 %f32vec3_hhh
2056 )";
2057
2058 CompileSuccessfully(GenerateShaderCode(body).c_str());
2059 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
2060 EXPECT_THAT(
2061 getDiagnosticString(),
2062 HasSubstr("Expected both Image Operand Grad ids to be 32-bit float "
2063 "scalars or vectors"));
2064 }
2065
2066 TEST_F(ValidateImage, SampleExplicitLodGradDyWrongType) {
2067 const std::string body = R"(
2068 %img = OpLoad %type_image_f32_cube_0101 %uniform_image_f32_cube_0101
2069 %sampler = OpLoad %type_sampler %uniform_sampler
2070 %simg = OpSampledImage %type_sampled_image_f32_cube_0101 %img %sampler
2071 %res1 = OpImageSampleExplicitLod %f32vec4 %simg %f32vec4_0000 Grad %f32vec3_hhh %s32vec3_012
2072 )";
2073
2074 CompileSuccessfully(GenerateShaderCode(body).c_str());
2075 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
2076 EXPECT_THAT(
2077 getDiagnosticString(),
2078 HasSubstr("Expected both Image Operand Grad ids to be 32-bit float "
2079 "scalars or vectors"));
2080 }
2081
2082 TEST_F(ValidateImage, SampleExplicitLodGrad16Bit) {
2083 const std::string body = R"(
2084 %img = OpLoad %type_image_f32_cube_0101 %uniform_image_f32_cube_0101
2085 %sampler = OpLoad %type_sampler %uniform_sampler
2086 %simg = OpSampledImage %type_sampled_image_f32_cube_0101 %img %sampler
2087 %res1 = OpImageSampleExplicitLod %f32vec4 %simg %f32vec4_0000 Grad %f16vec2_00 %f32vec2_00
2088 )";
2089
2090 CompileSuccessfully(GenerateShaderCode(body).c_str());
2091 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
2092 EXPECT_THAT(getDiagnosticString(),
2093 HasSubstr("Expected both Image Operand Grad ids to be 32-bit "
2094 "float scalars or vectors"));
2095 }
2096
2097 TEST_F(ValidateImage, SampleExplicitLodGradDxWrongSize) {
2098 const std::string body = R"(
2099 %img = OpLoad %type_image_f32_cube_0101 %uniform_image_f32_cube_0101
2100 %sampler = OpLoad %type_sampler %uniform_sampler
2101 %simg = OpSampledImage %type_sampled_image_f32_cube_0101 %img %sampler
2102 %res1 = OpImageSampleExplicitLod %f32vec4 %simg %f32vec4_0000 Grad %f32vec2_00 %f32vec3_hhh
2103 )";
2104
2105 CompileSuccessfully(GenerateShaderCode(body).c_str());
2106 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
2107 EXPECT_THAT(
2108 getDiagnosticString(),
2109 HasSubstr(
2110 "Expected Image Operand Grad dx to have 3 components, but given 2"));
2111 }
2112
2113 TEST_F(ValidateImage, SampleExplicitLodGradDyWrongSize) {
2114 const std::string body = R"(
2115 %img = OpLoad %type_image_f32_cube_0101 %uniform_image_f32_cube_0101
2116 %sampler = OpLoad %type_sampler %uniform_sampler
2117 %simg = OpSampledImage %type_sampled_image_f32_cube_0101 %img %sampler
2118 %res1 = OpImageSampleExplicitLod %f32vec4 %simg %f32vec4_0000 Grad %f32vec3_hhh %f32vec2_00
2119 )";
2120
2121 CompileSuccessfully(GenerateShaderCode(body).c_str());
2122 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
2123 EXPECT_THAT(
2124 getDiagnosticString(),
2125 HasSubstr(
2126 "Expected Image Operand Grad dy to have 3 components, but given 2"));
2127 }
2128
2129 TEST_F(ValidateImage, SampleImplicitLodConstOffsetCubeDim) {
2130 const std::string body = R"(
2131 %img = OpLoad %type_image_f32_cube_0101 %uniform_image_f32_cube_0101
2132 %sampler = OpLoad %type_sampler %uniform_sampler
2133 %simg = OpSampledImage %type_sampled_image_f32_cube_0101 %img %sampler
2134 %res4 = OpImageSampleImplicitLod %f32vec4 %simg %f32vec4_0000 ConstOffset %s32vec3_012
2135 )";
2136
2137 CompileSuccessfully(GenerateShaderCode(body).c_str());
2138 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
2139 EXPECT_THAT(
2140 getDiagnosticString(),
2141 HasSubstr(
2142 "Image Operand ConstOffset cannot be used with Cube Image 'Dim'"));
2143 }
2144
2145 TEST_F(ValidateImage, SampleImplicitLodConstOffsetWrongType) {
2146 const std::string body = R"(
2147 %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
2148 %sampler = OpLoad %type_sampler %uniform_sampler
2149 %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
2150 %res4 = OpImageSampleImplicitLod %f32vec4 %simg %f32vec2_00 ConstOffset %f32vec2_00
2151 )";
2152
2153 CompileSuccessfully(GenerateShaderCode(body).c_str());
2154 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
2155 EXPECT_THAT(getDiagnosticString(),
2156 HasSubstr("Expected Image Operand ConstOffset to be a 32-bit int "
2157 "scalar or vector"));
2158 }
2159
2160 TEST_F(ValidateImage, SampleImplicitLodConstOffset16Bit) {
2161 const std::string body = R"(
2162 %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
2163 %sampler = OpLoad %type_sampler %uniform_sampler
2164 %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
2165 %res4 = OpImageSampleImplicitLod %f32vec4 %simg %f32vec2_00 ConstOffset %u16_0
2166 )";
2167
2168 CompileSuccessfully(GenerateShaderCode(body).c_str());
2169 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
2170 EXPECT_THAT(getDiagnosticString(),
2171 HasSubstr("Expected Image Operand ConstOffset to be a 32-bit int "
2172 "scalar or vector"));
2173 }
2174
2175 TEST_F(ValidateImage, SampleImplicitLodConstOffsetWrongSize) {
2176 const std::string body = R"(
2177 %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
2178 %sampler = OpLoad %type_sampler %uniform_sampler
2179 %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
2180 %res4 = OpImageSampleImplicitLod %f32vec4 %simg %f32vec2_00 ConstOffset %s32vec3_012
2181 )";
2182
2183 CompileSuccessfully(GenerateShaderCode(body).c_str());
2184 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
2185 EXPECT_THAT(getDiagnosticString(),
2186 HasSubstr("Expected Image Operand ConstOffset to have 2 "
2187 "components, but given 3"));
2188 }
2189
2190 TEST_F(ValidateImage, SampleImplicitLodConstOffsetNotConst) {
2191 const std::string body = R"(
2192 %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
2193 %sampler = OpLoad %type_sampler %uniform_sampler
2194 %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
2195 %offset = OpSNegate %s32vec3 %s32vec3_012
2196 %res4 = OpImageSampleImplicitLod %f32vec4 %simg %f32vec2_00 ConstOffset %offset
2197 )";
2198
2199 CompileSuccessfully(GenerateShaderCode(body).c_str());
2200 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
2201 EXPECT_THAT(
2202 getDiagnosticString(),
2203 HasSubstr("Expected Image Operand ConstOffset to be a const object"));
2204 }
2205
2206 TEST_F(ValidateImage, SampleImplicitLodOffsetCubeDim) {
2207 const std::string body = R"(
2208 %img = OpLoad %type_image_f32_cube_0101 %uniform_image_f32_cube_0101
2209 %sampler = OpLoad %type_sampler %uniform_sampler
2210 %simg = OpSampledImage %type_sampled_image_f32_cube_0101 %img %sampler
2211 %res4 = OpImageSampleImplicitLod %f32vec4 %simg %f32vec4_0000 Offset %s32vec3_012
2212 )";
2213
2214 CompileSuccessfully(GenerateShaderCode(body).c_str());
2215 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
2216 EXPECT_THAT(
2217 getDiagnosticString(),
2218 HasSubstr("Image Operand Offset cannot be used with Cube Image 'Dim'"));
2219 }
2220
2221 TEST_F(ValidateImage, SampleImplicitLodOffsetWrongType) {
2222 const std::string body = R"(
2223 %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
2224 %sampler = OpLoad %type_sampler %uniform_sampler
2225 %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
2226 %res4 = OpImageSampleImplicitLod %f32vec4 %simg %f32vec4_0000 Offset %f32vec2_00
2227 )";
2228
2229 CompileSuccessfully(GenerateShaderCode(body).c_str());
2230 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
2231 EXPECT_THAT(
2232 getDiagnosticString(),
2233 HasSubstr(
2234 "Expected Image Operand Offset to be a 32-bit int scalar or vector"));
2235 }
2236
2237 TEST_F(ValidateImage, SampleImplicitLodOffset16Bit) {
2238 const std::string body = R"(
2239 %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
2240 %sampler = OpLoad %type_sampler %uniform_sampler
2241 %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
2242 %res4 = OpImageSampleImplicitLod %f32vec4 %simg %f32vec4_0000 Offset %u16_0
2243 )";
2244
2245 CompileSuccessfully(GenerateShaderCode(body).c_str());
2246 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
2247 EXPECT_THAT(
2248 getDiagnosticString(),
2249 HasSubstr(
2250 "Expected Image Operand Offset to be a 32-bit int scalar or vector"));
2251 }
2252
2253 TEST_F(ValidateImage, SampleImplicitLodOffsetWrongSize) {
2254 const std::string body = R"(
2255 %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
2256 %sampler = OpLoad %type_sampler %uniform_sampler
2257 %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
2258 %res4 = OpImageSampleImplicitLod %f32vec4 %simg %f32vec4_0000 Offset %s32vec3_012
2259 )";
2260
2261 CompileSuccessfully(GenerateShaderCode(body).c_str());
2262 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
2263 EXPECT_THAT(
2264 getDiagnosticString(),
2265 HasSubstr(
2266 "Expected Image Operand Offset to have 2 components, but given 3"));
2267 }
2268
2269 TEST_F(ValidateImage, SampleImplicitLodVulkanOffsetWrongSize) {
2270 const std::string body = R"(
2271 %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
2272 %sampler = OpLoad %type_sampler %uniform_sampler
2273 %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
2274 %res4 = OpImageSampleImplicitLod %f32vec4 %simg %f32vec4_0000 Offset %s32vec2_01
2275 )";
2276
2277 CompileSuccessfully(
2278 GenerateShaderCode(body, "", "Fragment", "", SPV_ENV_VULKAN_1_0).c_str());
2279 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions(SPV_ENV_VULKAN_1_0));
2280 EXPECT_THAT(getDiagnosticString(), AnyVUID("VUID-RuntimeSpirv-Offset-10213"));
2281 EXPECT_THAT(getDiagnosticString(),
2282 HasSubstr("Image Operand Offset can only be used with "
2283 "OpImage*Gather operations"));
2284 }
2285
2286 TEST_F(ValidateImage, SampleImplicitLodVulkanOffsetMaintenance8) {
2287 const std::string body = R"(
2288 %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
2289 %sampler = OpLoad %type_sampler %uniform_sampler
2290 %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
2291 %res4 = OpImageSampleImplicitLod %f32vec4 %simg %f32vec4_0000 Offset %s32vec2_01
2292 )";
2293
2294 CompileSuccessfully(
2295 GenerateShaderCode(body, "", "Fragment", "", SPV_ENV_VULKAN_1_0).c_str());
2296 spvValidatorOptionsSetAllowOffsetTextureOperand(getValidatorOptions(), true);
2297 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_0));
2298 }
2299
2300 TEST_F(ValidateImage, SampleImplicitLodVulkanOffsetWrongBeforeLegalization) {
2301 const std::string body = R"(
2302 %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
2303 %sampler = OpLoad %type_sampler %uniform_sampler
2304 %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
2305 %res4 = OpImageSampleImplicitLod %f32vec4 %simg %f32vec4_0000 Offset %s32vec2_01
2306 )";
2307
2308 CompileSuccessfully(
2309 GenerateShaderCode(body, "", "Fragment", "", SPV_ENV_VULKAN_1_0).c_str());
2310 getValidatorOptions()->before_hlsl_legalization = true;
2311 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_0));
2312 }
2313
2314 TEST_F(ValidateImage, SampleImplicitLodMoreThanOneOffset) {
2315 const std::string body = R"(
2316 %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
2317 %sampler = OpLoad %type_sampler %uniform_sampler
2318 %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
2319 %res4 = OpImageSampleImplicitLod %f32vec4 %simg %f32vec4_0000 ConstOffset|Offset %s32vec2_01 %s32vec2_01
2320 )";
2321
2322 CompileSuccessfully(GenerateShaderCode(body).c_str());
2323 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
2324 EXPECT_THAT(
2325 getDiagnosticString(),
2326 HasSubstr("Image Operands Offset, ConstOffset, ConstOffsets, Offsets "
2327 "cannot be used together"));
2328 }
2329
2330 TEST_F(ValidateImage, SampleImplicitLodVulkanMoreThanOneOffset) {
2331 const std::string body = R"(
2332 %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
2333 %sampler = OpLoad %type_sampler %uniform_sampler
2334 %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
2335 %res4 = OpImageSampleImplicitLod %f32vec4 %simg %f32vec4_0000 ConstOffset|Offset %s32vec2_01 %s32vec2_01
2336 )";
2337
2338 CompileSuccessfully(
2339 GenerateShaderCode(body, "", "Fragment", "", SPV_ENV_VULKAN_1_0).c_str());
2340 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions(SPV_ENV_VULKAN_1_0));
2341 EXPECT_THAT(
2342 getDiagnosticString(),
2343 HasSubstr("Image Operands Offset, ConstOffset, ConstOffsets, Offsets "
2344 "cannot be used together"));
2345 }
2346
2347 TEST_F(ValidateImage, SampleImplicitLodMinLodWrongType) {
2348 const std::string body = R"(
2349 %img = OpLoad %type_image_f32_cube_0101 %uniform_image_f32_cube_0101
2350 %sampler = OpLoad %type_sampler %uniform_sampler
2351 %simg = OpSampledImage %type_sampled_image_f32_cube_0101 %img %sampler
2352 %res1 = OpImageSampleImplicitLod %f32vec4 %simg %f32vec4_0000 MinLod %s32_0
2353 )";
2354
2355 CompileSuccessfully(GenerateShaderCode(body).c_str());
2356 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
2357 EXPECT_THAT(
2358 getDiagnosticString(),
2359 HasSubstr("Expected Image Operand MinLod to be a 32-bit float scalar"));
2360 }
2361
2362 TEST_F(ValidateImage, SampleImplicitLodMinLod16Bit) {
2363 const std::string body = R"(
2364 %img = OpLoad %type_image_f32_cube_0101 %uniform_image_f32_cube_0101
2365 %sampler = OpLoad %type_sampler %uniform_sampler
2366 %simg = OpSampledImage %type_sampled_image_f32_cube_0101 %img %sampler
2367 %res1 = OpImageSampleImplicitLod %f32vec4 %simg %f32vec4_0000 MinLod %f16_0
2368 )";
2369
2370 CompileSuccessfully(GenerateShaderCode(body).c_str());
2371 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
2372 EXPECT_THAT(
2373 getDiagnosticString(),
2374 HasSubstr("Expected Image Operand MinLod to be a 32-bit float scalar"));
2375 }
2376
2377 TEST_F(ValidateImage, SampleImplicitLodMinLodWrongDim) {
2378 const std::string body = R"(
2379 %img = OpLoad %type_image_f32_rect_0001 %uniform_image_f32_rect_0001
2380 %sampler = OpLoad %type_sampler %uniform_sampler
2381 %simg = OpSampledImage %type_sampled_image_f32_rect_0001 %img %sampler
2382 %res2 = OpImageSampleImplicitLod %f32vec4 %simg %f32vec2_hh MinLod %f32_0_25
2383 )";
2384
2385 CompileSuccessfully(GenerateShaderCode(body).c_str());
2386 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
2387 EXPECT_THAT(getDiagnosticString(),
2388 HasSubstr("Image Operand MinLod requires 'Dim' parameter to be "
2389 "1D, 2D, 3D or Cube"));
2390 }
2391
2392 TEST_F(ValidateImage, SampleProjExplicitLodSuccess2D) {
2393 const std::string body = R"(
2394 %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
2395 %sampler = OpLoad %type_sampler %uniform_sampler
2396 %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
2397 %res1 = OpImageSampleProjExplicitLod %f32vec4 %simg %f32vec3_hhh Lod %f32_1
2398 %res3 = OpImageSampleProjExplicitLod %f32vec4 %simg %f32vec3_hhh Grad %f32vec2_10 %f32vec2_01
2399 %res4 = OpImageSampleProjExplicitLod %f32vec4 %simg %f32vec3_hhh ConstOffset %s32vec2_01
2400 %res5 = OpImageSampleProjExplicitLod %f32vec4 %simg %f32vec3_hhh Offset %s32vec2_01
2401 %res7 = OpImageSampleProjExplicitLod %f32vec4 %simg %f32vec3_hhh Grad|Offset %f32vec2_10 %f32vec2_01 %s32vec2_01
2402 %res8 = OpImageSampleProjExplicitLod %f32vec4 %simg %f32vec3_hhh Lod|NonPrivateTexelKHR %f32_1
2403 )";
2404
2405 const std::string extra = R"(
2406 OpCapability VulkanMemoryModelKHR
2407 OpExtension "SPV_KHR_vulkan_memory_model"
2408 )";
2409 CompileSuccessfully(GenerateShaderCode(body, extra, "Fragment", "",
2410 SPV_ENV_UNIVERSAL_1_3, "VulkanKHR")
2411 .c_str(),
2412 SPV_ENV_UNIVERSAL_1_3);
2413 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_UNIVERSAL_1_3));
2414 }
2415
2416 TEST_F(ValidateImage, SampleProjExplicitLodSuccessRect) {
2417 const std::string body = R"(
2418 %img = OpLoad %type_image_f32_rect_0001 %uniform_image_f32_rect_0001
2419 %sampler = OpLoad %type_sampler %uniform_sampler
2420 %simg = OpSampledImage %type_sampled_image_f32_rect_0001 %img %sampler
2421 %res1 = OpImageSampleProjExplicitLod %f32vec4 %simg %f32vec3_hhh Grad %f32vec2_10 %f32vec2_01
2422 %res2 = OpImageSampleProjExplicitLod %f32vec4 %simg %f32vec3_hhh Grad|Offset %f32vec2_10 %f32vec2_01 %s32vec2_01
2423 )";
2424
2425 CompileSuccessfully(GenerateShaderCode(body).c_str());
2426 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
2427 }
2428
2429 TEST_F(ValidateImage, GradWrongMultisample) {
2430 const std::string body = R"(
2431 %img = OpLoad %type_image_f32_2d_0011 %uniform_image_f32_2d_0011
2432 %sampler = OpLoad %type_sampler %uniform_sampler
2433 %simg = OpSampledImage %type_sampled_image_f32_2d_0011 %img %sampler
2434 %res1 = OpImageSampleExplicitLod %f32vec4 %simg %f32vec2_00 Grad %f32vec2_01 %f32vec2_01
2435 )";
2436
2437 CompileSuccessfully(GenerateShaderCode(body).c_str());
2438 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
2439 EXPECT_THAT(getDiagnosticString(),
2440 HasSubstr("Sampling operation is invalid for multisample image"));
2441 }
2442
2443 TEST_F(ValidateImage, SampleProjExplicitLodWrongResultType) {
2444 const std::string body = R"(
2445 %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
2446 %sampler = OpLoad %type_sampler %uniform_sampler
2447 %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
2448 %res1 = OpImageSampleProjExplicitLod %f32 %simg %f32vec3_hhh Lod %f32_1
2449 )";
2450
2451 CompileSuccessfully(GenerateShaderCode(body).c_str());
2452 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
2453 EXPECT_THAT(getDiagnosticString(),
2454 HasSubstr("Expected Result Type to be int or float vector type"));
2455 }
2456
2457 TEST_F(ValidateImage, SampleProjExplicitLodWrongNumComponentsResultType) {
2458 const std::string body = R"(
2459 %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
2460 %sampler = OpLoad %type_sampler %uniform_sampler
2461 %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
2462 %res1 = OpImageSampleProjExplicitLod %f32vec3 %simg %f32vec3_hhh Lod %f32_1
2463 )";
2464
2465 CompileSuccessfully(GenerateShaderCode(body).c_str());
2466 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
2467 EXPECT_THAT(getDiagnosticString(),
2468 HasSubstr("Expected Result Type to have 4 components"));
2469 }
2470
2471 TEST_F(ValidateImage, SampleProjExplicitLodNotSampledImage) {
2472 const std::string body = R"(
2473 %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
2474 %res1 = OpImageSampleProjExplicitLod %f32vec4 %img %f32vec3_hhh Lod %f32_1
2475 )";
2476
2477 CompileSuccessfully(GenerateShaderCode(body).c_str());
2478 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
2479 EXPECT_THAT(
2480 getDiagnosticString(),
2481 HasSubstr("Expected Sampled Image to be of type OpTypeSampledImage"));
2482 }
2483
2484 TEST_F(ValidateImage, SampleProjExplicitLodMultisampleError) {
2485 const std::string body = R"(
2486 %img = OpLoad %type_image_f32_2d_0011 %uniform_image_f32_2d_0011
2487 %sampler = OpLoad %type_sampler %uniform_sampler
2488 %simg = OpSampledImage %type_sampled_image_f32_2d_0011 %img %sampler
2489 %res1 = OpImageSampleProjExplicitLod %f32vec4 %simg %f32vec2_hh Lod|Sample %f32_1 %u32_1
2490 )";
2491
2492 CompileSuccessfully(GenerateShaderCode(body).c_str());
2493 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
2494 EXPECT_THAT(getDiagnosticString(),
2495 HasSubstr("Expected Image 'MS' parameter to be 0"));
2496 }
2497
2498 TEST_F(ValidateImage, SampleProjExplicitLodWrongSampledType) {
2499 const std::string body = R"(
2500 %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
2501 %sampler = OpLoad %type_sampler %uniform_sampler
2502 %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
2503 %res1 = OpImageSampleProjExplicitLod %u32vec4 %simg %f32vec3_hhh Lod %f32_1
2504 )";
2505
2506 CompileSuccessfully(GenerateShaderCode(body).c_str());
2507 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
2508 EXPECT_THAT(getDiagnosticString(),
2509 HasSubstr("Expected Image 'Sampled Type' to be the same as "
2510 "Result Type components"));
2511 }
2512
2513 TEST_F(ValidateImage, SampleProjExplicitLodVoidSampledType) {
2514 const std::string body = R"(
2515 %img = OpLoad %type_image_void_2d_0001 %uniform_image_void_2d_0001
2516 %sampler = OpLoad %type_sampler %uniform_sampler
2517 %simg = OpSampledImage %type_sampled_image_void_2d_0001 %img %sampler
2518 %res1 = OpImageSampleProjExplicitLod %u32vec4 %simg %f32vec3_hhh Lod %f32_1
2519 )";
2520
2521 CompileSuccessfully(GenerateShaderCode(body).c_str());
2522 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
2523 }
2524
2525 TEST_F(ValidateImage, SampleProjExplicitLodWrongCoordinateType) {
2526 const std::string body = R"(
2527 %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
2528 %sampler = OpLoad %type_sampler %uniform_sampler
2529 %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
2530 %res1 = OpImageSampleProjExplicitLod %f32vec4 %simg %img Lod %f32_1
2531 )";
2532
2533 CompileSuccessfully(GenerateShaderCode(body).c_str());
2534 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
2535 EXPECT_THAT(
2536 getDiagnosticString(),
2537 HasSubstr("Expected Coordinate to be a 32-bit float scalar or vector"));
2538 }
2539
2540 TEST_F(ValidateImage, SampleProjExplicitLodCoordinateSizeTooSmall) {
2541 const std::string body = R"(
2542 %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
2543 %sampler = OpLoad %type_sampler %uniform_sampler
2544 %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
2545 %res1 = OpImageSampleProjExplicitLod %f32vec4 %simg %f32vec2_hh Lod %f32_1
2546 )";
2547
2548 CompileSuccessfully(GenerateShaderCode(body).c_str());
2549 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
2550 EXPECT_THAT(getDiagnosticString(),
2551 HasSubstr("Expected Coordinate to have at least 3 components, "
2552 "but given only 2"));
2553 }
2554
2555 TEST_F(ValidateImage, SampleProjImplicitLodSuccess) {
2556 const std::string body = R"(
2557 %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
2558 %sampler = OpLoad %type_sampler %uniform_sampler
2559 %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
2560 %res1 = OpImageSampleProjImplicitLod %f32vec4 %simg %f32vec3_hhh
2561 %res2 = OpImageSampleProjImplicitLod %f32vec4 %simg %f32vec3_hhh Bias %f32_0_25
2562 %res4 = OpImageSampleProjImplicitLod %f32vec4 %simg %f32vec3_hhh ConstOffset %s32vec2_01
2563 %res5 = OpImageSampleProjImplicitLod %f32vec4 %simg %f32vec3_hhh Offset %s32vec2_01
2564 %res6 = OpImageSampleProjImplicitLod %f32vec4 %simg %f32vec3_hhh MinLod %f32_0_5
2565 %res7 = OpImageSampleProjImplicitLod %f32vec4 %simg %f32vec3_hhh Bias|Offset|MinLod %f32_0_25 %s32vec2_01 %f32_0_5
2566 %res8 = OpImageSampleProjImplicitLod %f32vec4 %simg %f32vec3_hhh NonPrivateTexelKHR
2567 )";
2568
2569 const std::string extra = R"(
2570 OpCapability VulkanMemoryModelKHR
2571 OpExtension "SPV_KHR_vulkan_memory_model"
2572 )";
2573 CompileSuccessfully(GenerateShaderCode(body, extra, "Fragment", "",
2574 SPV_ENV_UNIVERSAL_1_3, "VulkanKHR")
2575 .c_str(),
2576 SPV_ENV_UNIVERSAL_1_3);
2577 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_UNIVERSAL_1_3));
2578 }
2579
2580 TEST_F(ValidateImage, SampleProjImplicitLodWrongResultType) {
2581 const std::string body = R"(
2582 %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
2583 %sampler = OpLoad %type_sampler %uniform_sampler
2584 %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
2585 %res1 = OpImageSampleProjImplicitLod %f32 %simg %f32vec3_hhh
2586 )";
2587
2588 CompileSuccessfully(GenerateShaderCode(body).c_str());
2589 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
2590 EXPECT_THAT(getDiagnosticString(),
2591 HasSubstr("Expected Result Type to be int or float vector type"));
2592 }
2593
2594 TEST_F(ValidateImage, SampleProjImplicitLodWrongNumComponentsResultType) {
2595 const std::string body = R"(
2596 %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
2597 %sampler = OpLoad %type_sampler %uniform_sampler
2598 %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
2599 %res1 = OpImageSampleProjImplicitLod %f32vec3 %simg %f32vec3_hhh
2600 )";
2601
2602 CompileSuccessfully(GenerateShaderCode(body).c_str());
2603 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
2604 EXPECT_THAT(getDiagnosticString(),
2605 HasSubstr("Expected Result Type to have 4 components"));
2606 }
2607
2608 TEST_F(ValidateImage, SampleProjImplicitLodNotSampledImage) {
2609 const std::string body = R"(
2610 %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
2611 %res1 = OpImageSampleProjImplicitLod %f32vec4 %img %f32vec3_hhh
2612 )";
2613
2614 CompileSuccessfully(GenerateShaderCode(body).c_str());
2615 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
2616 EXPECT_THAT(
2617 getDiagnosticString(),
2618 HasSubstr("Expected Sampled Image to be of type OpTypeSampledImage"));
2619 }
2620
2621 TEST_F(ValidateImage, SampleProjImplicitLodMultisampleError) {
2622 const std::string body = R"(
2623 %img = OpLoad %type_image_f32_2d_0011 %uniform_image_f32_2d_0011
2624 %sampler = OpLoad %type_sampler %uniform_sampler
2625 %simg = OpSampledImage %type_sampled_image_f32_2d_0011 %img %sampler
2626 %res1 = OpImageSampleProjImplicitLod %f32vec4 %simg %f32vec2_hh Sample %u32_1
2627 )";
2628
2629 CompileSuccessfully(GenerateShaderCode(body).c_str());
2630 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
2631 EXPECT_THAT(getDiagnosticString(),
2632 HasSubstr("Expected Image 'MS' parameter to be 0"));
2633 }
2634
2635 TEST_F(ValidateImage, SampleProjImplicitLodWrongSampledType) {
2636 const std::string body = R"(
2637 %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
2638 %sampler = OpLoad %type_sampler %uniform_sampler
2639 %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
2640 %res1 = OpImageSampleProjImplicitLod %u32vec4 %simg %f32vec3_hhh
2641 )";
2642
2643 CompileSuccessfully(GenerateShaderCode(body).c_str());
2644 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
2645 EXPECT_THAT(getDiagnosticString(),
2646 HasSubstr("Expected Image 'Sampled Type' to be the same as "
2647 "Result Type components"));
2648 }
2649
2650 TEST_F(ValidateImage, SampleProjImplicitLodVoidSampledType) {
2651 const std::string body = R"(
2652 %img = OpLoad %type_image_void_2d_0001 %uniform_image_void_2d_0001
2653 %sampler = OpLoad %type_sampler %uniform_sampler
2654 %simg = OpSampledImage %type_sampled_image_void_2d_0001 %img %sampler
2655 %res1 = OpImageSampleProjImplicitLod %u32vec4 %simg %f32vec3_hhh
2656 )";
2657
2658 CompileSuccessfully(GenerateShaderCode(body).c_str());
2659 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
2660 }
2661
2662 TEST_F(ValidateImage, SampleProjImplicitLodWrongCoordinateType) {
2663 const std::string body = R"(
2664 %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
2665 %sampler = OpLoad %type_sampler %uniform_sampler
2666 %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
2667 %res1 = OpImageSampleProjImplicitLod %f32vec4 %simg %img
2668 )";
2669
2670 CompileSuccessfully(GenerateShaderCode(body).c_str());
2671 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
2672 EXPECT_THAT(
2673 getDiagnosticString(),
2674 HasSubstr("Expected Coordinate to be a 32-bit float scalar or vector"));
2675 }
2676
2677 TEST_F(ValidateImage, SampleProjImplicitLodCoordinateSizeTooSmall) {
2678 const std::string body = R"(
2679 %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
2680 %sampler = OpLoad %type_sampler %uniform_sampler
2681 %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
2682 %res1 = OpImageSampleProjImplicitLod %f32vec4 %simg %f32vec2_hh
2683 )";
2684
2685 CompileSuccessfully(GenerateShaderCode(body).c_str());
2686 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
2687 EXPECT_THAT(getDiagnosticString(),
2688 HasSubstr("Expected Coordinate to have at least 3 components, "
2689 "but given only 2"));
2690 }
2691
2692 TEST_F(ValidateImage, SampleDrefImplicitLodSuccess) {
2693 const std::string body = R"(
2694 %img = OpLoad %type_image_u32_2d_0001 %uniform_image_u32_2d_0001
2695 %sampler = OpLoad %type_sampler %uniform_sampler
2696 %simg = OpSampledImage %type_sampled_image_u32_2d_0001 %img %sampler
2697 %res1 = OpImageSampleDrefImplicitLod %u32 %simg %f32vec2_hh %f32_1
2698 %res2 = OpImageSampleDrefImplicitLod %u32 %simg %f32vec2_hh %f32_1 Bias %f32_0_25
2699 %res4 = OpImageSampleDrefImplicitLod %u32 %simg %f32vec2_hh %f32_1 ConstOffset %s32vec2_01
2700 %res5 = OpImageSampleDrefImplicitLod %u32 %simg %f32vec2_hh %f32_1 Offset %s32vec2_01
2701 %res6 = OpImageSampleDrefImplicitLod %u32 %simg %f32vec2_hh %f32_1 MinLod %f32_0_5
2702 %res7 = OpImageSampleDrefImplicitLod %u32 %simg %f32vec2_hh %f32_1 Bias|Offset|MinLod %f32_0_25 %s32vec2_01 %f32_0_5
2703 %res8 = OpImageSampleDrefImplicitLod %u32 %simg %f32vec2_hh %f32_1 NonPrivateTexelKHR
2704 )";
2705
2706 const std::string extra = R"(
2707 OpCapability VulkanMemoryModelKHR
2708 OpExtension "SPV_KHR_vulkan_memory_model"
2709 )";
2710 CompileSuccessfully(GenerateShaderCode(body, extra, "Fragment", "",
2711 SPV_ENV_UNIVERSAL_1_3, "VulkanKHR")
2712 .c_str(),
2713 SPV_ENV_UNIVERSAL_1_3);
2714 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_UNIVERSAL_1_3));
2715 }
2716
2717 TEST_F(ValidateImage, SampleDrefImplicitLodWrongResultType) {
2718 const std::string body = R"(
2719 %img = OpLoad %type_image_void_2d_0001 %uniform_image_void_2d_0001
2720 %sampler = OpLoad %type_sampler %uniform_sampler
2721 %simg = OpSampledImage %type_sampled_image_void_2d_0001 %img %sampler
2722 %res1 = OpImageSampleDrefImplicitLod %void %simg %f32vec2_hh %u32_1
2723 )";
2724
2725 CompileSuccessfully(GenerateShaderCode(body).c_str());
2726 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
2727 EXPECT_THAT(getDiagnosticString(),
2728 HasSubstr("Expected Result Type to be int or float scalar type"));
2729 }
2730
2731 TEST_F(ValidateImage, SampleDrefImplicitLodNotSampledImage) {
2732 const std::string body = R"(
2733 %img = OpLoad %type_image_u32_2d_0001 %uniform_image_u32_2d_0001
2734 %res1 = OpImageSampleDrefImplicitLod %u32 %img %f32vec2_hh %u32_1
2735 )";
2736
2737 CompileSuccessfully(GenerateShaderCode(body).c_str());
2738 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
2739 EXPECT_THAT(
2740 getDiagnosticString(),
2741 HasSubstr("Expected Sampled Image to be of type OpTypeSampledImage"));
2742 }
2743
2744 TEST_F(ValidateImage, SampleDrefImplicitLodMultisampleError) {
2745 const std::string body = R"(
2746 %img = OpLoad %type_image_f32_2d_0011 %uniform_image_f32_2d_0011
2747 %sampler = OpLoad %type_sampler %uniform_sampler
2748 %simg = OpSampledImage %type_sampled_image_f32_2d_0011 %img %sampler
2749 %res1 = OpImageSampleDrefImplicitLod %f32 %simg %f32vec2_hh %f32_1 Sample %u32_1
2750 )";
2751
2752 CompileSuccessfully(GenerateShaderCode(body).c_str());
2753 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
2754 EXPECT_THAT(
2755 getDiagnosticString(),
2756 HasSubstr("Dref sampling operation is invalid for multisample image"));
2757 }
2758
2759 TEST_F(ValidateImage, SampleDrefImplicitLodWrongSampledType) {
2760 const std::string body = R"(
2761 %img = OpLoad %type_image_u32_2d_0001 %uniform_image_u32_2d_0001
2762 %sampler = OpLoad %type_sampler %uniform_sampler
2763 %simg = OpSampledImage %type_sampled_image_u32_2d_0001 %img %sampler
2764 %res1 = OpImageSampleDrefImplicitLod %f32 %simg %f32vec2_00 %u32_1
2765 )";
2766
2767 CompileSuccessfully(GenerateShaderCode(body).c_str());
2768 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
2769 EXPECT_THAT(
2770 getDiagnosticString(),
2771 HasSubstr("Expected Image 'Sampled Type' to be the same as Result Type"));
2772 }
2773
2774 TEST_F(ValidateImage, SampleDrefImplicitLodVoidSampledType) {
2775 const std::string body = R"(
2776 %img = OpLoad %type_image_void_2d_0001 %uniform_image_void_2d_0001
2777 %sampler = OpLoad %type_sampler %uniform_sampler
2778 %simg = OpSampledImage %type_sampled_image_void_2d_0001 %img %sampler
2779 %res1 = OpImageSampleDrefImplicitLod %u32 %simg %f32vec2_00 %u32_1
2780 )";
2781
2782 CompileSuccessfully(GenerateShaderCode(body).c_str());
2783 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
2784 EXPECT_THAT(
2785 getDiagnosticString(),
2786 HasSubstr("Expected Image 'Sampled Type' to be the same as Result Type"));
2787 }
2788
2789 TEST_F(ValidateImage, SampleDrefImplicitLodWrongCoordinateType) {
2790 const std::string body = R"(
2791 %img = OpLoad %type_image_u32_2d_0001 %uniform_image_u32_2d_0001
2792 %sampler = OpLoad %type_sampler %uniform_sampler
2793 %simg = OpSampledImage %type_sampled_image_u32_2d_0001 %img %sampler
2794 %res1 = OpImageSampleDrefImplicitLod %u32 %simg %img %u32_1
2795 )";
2796
2797 CompileSuccessfully(GenerateShaderCode(body).c_str());
2798 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
2799 EXPECT_THAT(
2800 getDiagnosticString(),
2801 HasSubstr("Expected Coordinate to be a 32-bit float scalar or vector"));
2802 }
2803
2804 TEST_F(ValidateImage, SampleDrefImplicitLodCoordinateSizeTooSmall) {
2805 const std::string body = R"(
2806 %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
2807 %sampler = OpLoad %type_sampler %uniform_sampler
2808 %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
2809 %res1 = OpImageSampleDrefImplicitLod %f32 %simg %f32_0_5 %f32_0_5
2810 )";
2811
2812 CompileSuccessfully(GenerateShaderCode(body).c_str());
2813 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
2814 EXPECT_THAT(getDiagnosticString(),
2815 HasSubstr("Expected Coordinate to have at least 2 components, "
2816 "but given only 1"));
2817 }
2818
2819 TEST_F(ValidateImage, SampleDrefImplicitLodWrongDrefType) {
2820 const std::string body = R"(
2821 %img = OpLoad %type_image_u32_2d_0001 %uniform_image_u32_2d_0001
2822 %sampler = OpLoad %type_sampler %uniform_sampler
2823 %simg = OpSampledImage %type_sampled_image_u32_2d_0001 %img %sampler
2824 %res1 = OpImageSampleDrefImplicitLod %u32 %simg %f32vec2_00 %f64_1
2825 )";
2826
2827 CompileSuccessfully(GenerateShaderCode(body).c_str());
2828 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
2829 EXPECT_THAT(getDiagnosticString(),
2830 HasSubstr("Expected Dref to be of 32-bit float type"));
2831 }
2832
2833 TEST_F(ValidateImage, SampleDrefImplicitLodWrongDimVulkan) {
2834 const std::string body = R"(
2835 %img = OpLoad %type_image_u32_3d_0001 %uniform_image_u32_3d_0001
2836 %sampler = OpLoad %type_sampler %uniform_sampler
2837 %simg = OpSampledImage %type_sampled_image_u32_3d_0001 %img %sampler
2838 %res1 = OpImageSampleDrefImplicitLod %u32 %simg %f32vec3_hhh %f32_1
2839 )";
2840
2841 CompileSuccessfully(
2842 GenerateShaderCode(body, "", "Fragment", "", SPV_ENV_VULKAN_1_0).c_str());
2843 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions(SPV_ENV_VULKAN_1_0));
2844 EXPECT_THAT(getDiagnosticString(),
2845 AnyVUID("VUID-StandaloneSpirv-OpImage-04777"));
2846 EXPECT_THAT(getDiagnosticString(),
2847 HasSubstr("In Vulkan, OpImage*Dref* instructions must not use "
2848 "images with a 3D Dim"));
2849 }
2850
2851 TEST_F(ValidateImage, SampleDrefExplicitLodSuccess) {
2852 const std::string body = R"(
2853 %img = OpLoad %type_image_s32_3d_0001 %uniform_image_s32_3d_0001
2854 %sampler = OpLoad %type_sampler %uniform_sampler
2855 %simg = OpSampledImage %type_sampled_image_s32_3d_0001 %img %sampler
2856 %res1 = OpImageSampleDrefExplicitLod %s32 %simg %f32vec4_0000 %f32_1 Lod %f32_1
2857 %res3 = OpImageSampleDrefExplicitLod %s32 %simg %f32vec3_hhh %f32_1 Grad %f32vec3_hhh %f32vec3_hhh
2858 %res4 = OpImageSampleDrefExplicitLod %s32 %simg %f32vec3_hhh %f32_1 ConstOffset %s32vec3_012
2859 %res5 = OpImageSampleDrefExplicitLod %s32 %simg %f32vec4_0000 %f32_1 Offset %s32vec3_012
2860 %res7 = OpImageSampleDrefExplicitLod %s32 %simg %f32vec3_hhh %f32_1 Grad|Offset %f32vec3_hhh %f32vec3_hhh %s32vec3_012
2861 %res8 = OpImageSampleDrefExplicitLod %s32 %simg %f32vec4_0000 %f32_1 Lod|NonPrivateTexelKHR %f32_1
2862 )";
2863
2864 const std::string extra = R"(
2865 OpCapability VulkanMemoryModelKHR
2866 OpExtension "SPV_KHR_vulkan_memory_model"
2867 )";
2868 CompileSuccessfully(GenerateShaderCode(body, extra, "Fragment", "",
2869 SPV_ENV_UNIVERSAL_1_3, "VulkanKHR")
2870 .c_str(),
2871 SPV_ENV_UNIVERSAL_1_3);
2872 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_UNIVERSAL_1_3));
2873 }
2874
2875 TEST_F(ValidateImage, SampleDrefExplicitLodWrongResultType) {
2876 const std::string body = R"(
2877 %img = OpLoad %type_image_s32_3d_0001 %uniform_image_s32_3d_0001
2878 %sampler = OpLoad %type_sampler %uniform_sampler
2879 %simg = OpSampledImage %type_sampled_image_s32_3d_0001 %img %sampler
2880 %res1 = OpImageSampleDrefExplicitLod %bool %simg %f32vec3_hhh %s32_1 Lod %f32_1
2881 )";
2882
2883 CompileSuccessfully(GenerateShaderCode(body).c_str());
2884 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
2885 EXPECT_THAT(getDiagnosticString(),
2886 HasSubstr("Expected Result Type to be int or float scalar type"));
2887 }
2888
2889 TEST_F(ValidateImage, SampleDrefExplicitLodNotSampledImage) {
2890 const std::string body = R"(
2891 %img = OpLoad %type_image_s32_3d_0001 %uniform_image_s32_3d_0001
2892 %res1 = OpImageSampleDrefExplicitLod %s32 %img %f32vec3_hhh %s32_1 Lod %f32_1
2893 )";
2894
2895 CompileSuccessfully(GenerateShaderCode(body).c_str());
2896 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
2897 EXPECT_THAT(
2898 getDiagnosticString(),
2899 HasSubstr("Expected Sampled Image to be of type OpTypeSampledImage"));
2900 }
2901
2902 TEST_F(ValidateImage, SampleDrefExplicitLodMultisampleError) {
2903 const std::string body = R"(
2904 %img = OpLoad %type_image_f32_2d_0011 %uniform_image_f32_2d_0011
2905 %sampler = OpLoad %type_sampler %uniform_sampler
2906 %simg = OpSampledImage %type_sampled_image_f32_2d_0011 %img %sampler
2907 %res1 = OpImageSampleDrefExplicitLod %f32 %simg %f32vec2_hh %f32_1 Lod|Sample %f32_1 %u32_1
2908 )";
2909
2910 CompileSuccessfully(GenerateShaderCode(body).c_str());
2911 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
2912 EXPECT_THAT(
2913 getDiagnosticString(),
2914 HasSubstr("Dref sampling operation is invalid for multisample image"));
2915 }
2916
2917 TEST_F(ValidateImage, SampleDrefExplicitLodWrongSampledType) {
2918 const std::string body = R"(
2919 %img = OpLoad %type_image_s32_3d_0001 %uniform_image_s32_3d_0001
2920 %sampler = OpLoad %type_sampler %uniform_sampler
2921 %simg = OpSampledImage %type_sampled_image_s32_3d_0001 %img %sampler
2922 %res1 = OpImageSampleDrefExplicitLod %f32 %simg %f32vec3_hhh %s32_1 Lod %f32_1
2923 )";
2924
2925 CompileSuccessfully(GenerateShaderCode(body).c_str());
2926 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
2927 EXPECT_THAT(
2928 getDiagnosticString(),
2929 HasSubstr("Expected Image 'Sampled Type' to be the same as Result Type"));
2930 }
2931
2932 TEST_F(ValidateImage, SampleDrefExplicitLodVoidSampledType) {
2933 const std::string body = R"(
2934 %img = OpLoad %type_image_void_2d_0001 %uniform_image_void_2d_0001
2935 %sampler = OpLoad %type_sampler %uniform_sampler
2936 %simg = OpSampledImage %type_sampled_image_void_2d_0001 %img %sampler
2937 %res1 = OpImageSampleDrefExplicitLod %u32 %simg %f32vec2_00 %s32_1 Lod %f32_1
2938 )";
2939
2940 CompileSuccessfully(GenerateShaderCode(body).c_str());
2941 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
2942 EXPECT_THAT(
2943 getDiagnosticString(),
2944 HasSubstr("Expected Image 'Sampled Type' to be the same as Result Type"));
2945 }
2946
2947 TEST_F(ValidateImage, SampleDrefExplicitLodWrongCoordinateType) {
2948 const std::string body = R"(
2949 %img = OpLoad %type_image_s32_3d_0001 %uniform_image_s32_3d_0001
2950 %sampler = OpLoad %type_sampler %uniform_sampler
2951 %simg = OpSampledImage %type_sampled_image_s32_3d_0001 %img %sampler
2952 %res1 = OpImageSampleDrefExplicitLod %s32 %simg %img %s32_1 Lod %f32_1
2953 )";
2954
2955 CompileSuccessfully(GenerateShaderCode(body).c_str());
2956 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
2957 EXPECT_THAT(
2958 getDiagnosticString(),
2959 HasSubstr("Expected Coordinate to be a 32-bit float scalar or vector"));
2960 }
2961
2962 TEST_F(ValidateImage, SampleDrefExplicitLodCoordinateSizeTooSmall) {
2963 const std::string body = R"(
2964 %img = OpLoad %type_image_s32_3d_0001 %uniform_image_s32_3d_0001
2965 %sampler = OpLoad %type_sampler %uniform_sampler
2966 %simg = OpSampledImage %type_sampled_image_s32_3d_0001 %img %sampler
2967 %res1 = OpImageSampleDrefExplicitLod %s32 %simg %f32vec2_hh %s32_1 Lod %f32_1
2968 )";
2969
2970 CompileSuccessfully(GenerateShaderCode(body).c_str());
2971 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
2972 EXPECT_THAT(getDiagnosticString(),
2973 HasSubstr("Expected Coordinate to have at least 3 components, "
2974 "but given only 2"));
2975 }
2976
2977 TEST_F(ValidateImage, SampleDrefExplicitLodWrongDrefType) {
2978 const std::string body = R"(
2979 %img = OpLoad %type_image_s32_3d_0001 %uniform_image_s32_3d_0001
2980 %sampler = OpLoad %type_sampler %uniform_sampler
2981 %simg = OpSampledImage %type_sampled_image_s32_3d_0001 %img %sampler
2982 %res1 = OpImageSampleDrefExplicitLod %s32 %simg %f32vec3_hhh %u32_1 Lod %f32_1
2983 )";
2984
2985 CompileSuccessfully(GenerateShaderCode(body).c_str());
2986 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
2987 EXPECT_THAT(getDiagnosticString(),
2988 HasSubstr("Expected Dref to be of 32-bit float type"));
2989 }
2990
2991 TEST_F(ValidateImage, SampleProjDrefImplicitLodSuccess) {
2992 const std::string body = R"(
2993 %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
2994 %sampler = OpLoad %type_sampler %uniform_sampler
2995 %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
2996 %res1 = OpImageSampleProjDrefImplicitLod %f32 %simg %f32vec3_hhh %f32_0_5
2997 %res2 = OpImageSampleProjDrefImplicitLod %f32 %simg %f32vec3_hhh %f32_0_5 Bias %f32_0_25
2998 %res4 = OpImageSampleProjDrefImplicitLod %f32 %simg %f32vec3_hhh %f32_0_5 ConstOffset %s32vec2_01
2999 %res5 = OpImageSampleProjDrefImplicitLod %f32 %simg %f32vec3_hhh %f32_0_5 Offset %s32vec2_01
3000 %res6 = OpImageSampleProjDrefImplicitLod %f32 %simg %f32vec3_hhh %f32_0_5 MinLod %f32_0_5
3001 %res7 = OpImageSampleProjDrefImplicitLod %f32 %simg %f32vec3_hhh %f32_0_5 Bias|Offset|MinLod %f32_0_25 %s32vec2_01 %f32_0_5
3002 %res8 = OpImageSampleProjDrefImplicitLod %f32 %simg %f32vec3_hhh %f32_0_5 NonPrivateTexelKHR
3003 )";
3004
3005 const std::string extra = R"(
3006 OpCapability VulkanMemoryModelKHR
3007 OpExtension "SPV_KHR_vulkan_memory_model"
3008 )";
3009 CompileSuccessfully(GenerateShaderCode(body, extra, "Fragment", "",
3010 SPV_ENV_UNIVERSAL_1_3, "VulkanKHR")
3011 .c_str(),
3012 SPV_ENV_UNIVERSAL_1_3);
3013 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_UNIVERSAL_1_3));
3014 }
3015
3016 TEST_F(ValidateImage, SampleProjDrefImplicitLodWrongResultType) {
3017 const std::string body = R"(
3018 %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
3019 %sampler = OpLoad %type_sampler %uniform_sampler
3020 %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
3021 %res1 = OpImageSampleProjDrefImplicitLod %void %simg %f32vec3_hhh %f32_0_5
3022 )";
3023
3024 CompileSuccessfully(GenerateShaderCode(body).c_str());
3025 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
3026 EXPECT_THAT(getDiagnosticString(),
3027 HasSubstr("Expected Result Type to be int or float scalar type"));
3028 }
3029
3030 TEST_F(ValidateImage, SampleProjDrefImplicitLodNotSampledImage) {
3031 const std::string body = R"(
3032 %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
3033 %res1 = OpImageSampleProjDrefImplicitLod %f32 %img %f32vec3_hhh %f32_0_5
3034 )";
3035
3036 CompileSuccessfully(GenerateShaderCode(body).c_str());
3037 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
3038 EXPECT_THAT(
3039 getDiagnosticString(),
3040 HasSubstr("Expected Sampled Image to be of type OpTypeSampledImage"));
3041 }
3042
3043 TEST_F(ValidateImage, SampleProjDrefImplicitLodMultisampleError) {
3044 const std::string body = R"(
3045 %img = OpLoad %type_image_f32_2d_0011 %uniform_image_f32_2d_0011
3046 %sampler = OpLoad %type_sampler %uniform_sampler
3047 %simg = OpSampledImage %type_sampled_image_f32_2d_0011 %img %sampler
3048 %res1 = OpImageSampleDrefExplicitLod %f32 %simg %f32vec2_hh %f32_1 Sample %u32_1
3049 )";
3050
3051 CompileSuccessfully(GenerateShaderCode(body).c_str());
3052 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
3053 EXPECT_THAT(
3054 getDiagnosticString(),
3055 HasSubstr("Dref sampling operation is invalid for multisample image"));
3056 }
3057
3058 TEST_F(ValidateImage, SampleProjDrefImplicitLodWrongSampledType) {
3059 const std::string body = R"(
3060 %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
3061 %sampler = OpLoad %type_sampler %uniform_sampler
3062 %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
3063 %res1 = OpImageSampleProjDrefImplicitLod %u32 %simg %f32vec3_hhh %f32_0_5
3064 )";
3065
3066 CompileSuccessfully(GenerateShaderCode(body).c_str());
3067 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
3068 EXPECT_THAT(
3069 getDiagnosticString(),
3070 HasSubstr("Expected Image 'Sampled Type' to be the same as Result Type"));
3071 }
3072
3073 TEST_F(ValidateImage, SampleProjDrefImplicitLodVoidSampledType) {
3074 const std::string body = R"(
3075 %img = OpLoad %type_image_void_2d_0001 %uniform_image_void_2d_0001
3076 %sampler = OpLoad %type_sampler %uniform_sampler
3077 %simg = OpSampledImage %type_sampled_image_void_2d_0001 %img %sampler
3078 %res1 = OpImageSampleProjDrefImplicitLod %u32 %simg %f32vec3_hhh %f32_0_5
3079 )";
3080
3081 CompileSuccessfully(GenerateShaderCode(body).c_str());
3082 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
3083 EXPECT_THAT(
3084 getDiagnosticString(),
3085 HasSubstr("Expected Image 'Sampled Type' to be the same as Result Type"));
3086 }
3087
3088 TEST_F(ValidateImage, SampleProjDrefImplicitLodWrongCoordinateType) {
3089 const std::string body = R"(
3090 %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
3091 %sampler = OpLoad %type_sampler %uniform_sampler
3092 %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
3093 %res1 = OpImageSampleProjDrefImplicitLod %f32 %simg %img %f32_0_5
3094 )";
3095
3096 CompileSuccessfully(GenerateShaderCode(body).c_str());
3097 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
3098 EXPECT_THAT(
3099 getDiagnosticString(),
3100 HasSubstr("Expected Coordinate to be a 32-bit float scalar or vector"));
3101 }
3102
3103 TEST_F(ValidateImage, SampleProjDrefImplicitLodCoordinateSizeTooSmall) {
3104 const std::string body = R"(
3105 %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
3106 %sampler = OpLoad %type_sampler %uniform_sampler
3107 %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
3108 %res1 = OpImageSampleProjDrefImplicitLod %f32 %simg %f32vec2_hh %f32_0_5
3109 )";
3110
3111 CompileSuccessfully(GenerateShaderCode(body).c_str());
3112 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
3113 EXPECT_THAT(getDiagnosticString(),
3114 HasSubstr("Expected Coordinate to have at least 3 components, "
3115 "but given only 2"));
3116 }
3117
3118 TEST_F(ValidateImage, SampleProjDrefImplicitLodWrongDrefType) {
3119 const std::string body = R"(
3120 %img = OpLoad %type_image_u32_2d_0001 %uniform_image_u32_2d_0001
3121 %sampler = OpLoad %type_sampler %uniform_sampler
3122 %simg = OpSampledImage %type_sampled_image_u32_2d_0001 %img %sampler
3123 %res1 = OpImageSampleProjDrefImplicitLod %u32 %simg %f32vec3_hhh %f32vec4_0000
3124 )";
3125
3126 CompileSuccessfully(GenerateShaderCode(body).c_str());
3127 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
3128 EXPECT_THAT(getDiagnosticString(),
3129 HasSubstr("Expected Dref to be of 32-bit float type"));
3130 }
3131
3132 TEST_F(ValidateImage, SampleProjDrefExplicitLodSuccess) {
3133 const std::string body = R"(
3134 %img = OpLoad %type_image_f32_1d_0001 %uniform_image_f32_1d_0001
3135 %sampler = OpLoad %type_sampler %uniform_sampler
3136 %simg = OpSampledImage %type_sampled_image_f32_1d_0001 %img %sampler
3137 %res1 = OpImageSampleProjDrefExplicitLod %f32 %simg %f32vec2_hh %f32_0_5 Lod %f32_1
3138 %res2 = OpImageSampleProjDrefExplicitLod %f32 %simg %f32vec3_hhh %f32_0_5 Grad %f32_0_5 %f32_0_5
3139 %res3 = OpImageSampleProjDrefExplicitLod %f32 %simg %f32vec2_hh %f32_0_5 ConstOffset %s32_1
3140 %res4 = OpImageSampleProjDrefExplicitLod %f32 %simg %f32vec2_hh %f32_0_5 Offset %s32_1
3141 %res5 = OpImageSampleProjDrefExplicitLod %f32 %simg %f32vec2_hh %f32_0_5 Grad|Offset %f32_0_5 %f32_0_5 %s32_1
3142 %res6 = OpImageSampleProjDrefExplicitLod %f32 %simg %f32vec2_hh %f32_0_5 Lod|NonPrivateTexelKHR %f32_1
3143 )";
3144
3145 const std::string extra = R"(
3146 OpCapability VulkanMemoryModelKHR
3147 OpExtension "SPV_KHR_vulkan_memory_model"
3148 )";
3149 CompileSuccessfully(GenerateShaderCode(body, extra, "Fragment", "",
3150 SPV_ENV_UNIVERSAL_1_3, "VulkanKHR")
3151 .c_str(),
3152 SPV_ENV_UNIVERSAL_1_3);
3153 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_UNIVERSAL_1_3));
3154 }
3155
3156 TEST_F(ValidateImage, SampleProjDrefExplicitLodWrongResultType) {
3157 const std::string body = R"(
3158 %img = OpLoad %type_image_f32_1d_0001 %uniform_image_f32_1d_0001
3159 %sampler = OpLoad %type_sampler %uniform_sampler
3160 %simg = OpSampledImage %type_sampled_image_f32_1d_0001 %img %sampler
3161 %res1 = OpImageSampleProjDrefExplicitLod %bool %simg %f32vec2_hh %f32_0_5 Lod %f32_1
3162 )";
3163
3164 CompileSuccessfully(GenerateShaderCode(body).c_str());
3165 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
3166 EXPECT_THAT(getDiagnosticString(),
3167 HasSubstr("Expected Result Type to be int or float scalar type"));
3168 }
3169
3170 TEST_F(ValidateImage, SampleProjDrefExplicitLodNotSampledImage) {
3171 const std::string body = R"(
3172 %img = OpLoad %type_image_f32_1d_0001 %uniform_image_f32_1d_0001
3173 %res1 = OpImageSampleProjDrefExplicitLod %f32 %img %f32vec2_hh %f32_0_5 Lod %f32_1
3174 )";
3175
3176 CompileSuccessfully(GenerateShaderCode(body).c_str());
3177 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
3178 EXPECT_THAT(
3179 getDiagnosticString(),
3180 HasSubstr("Expected Sampled Image to be of type OpTypeSampledImage"));
3181 }
3182
3183 TEST_F(ValidateImage, SampleProjDrefExplicitLodMultisampleError) {
3184 const std::string body = R"(
3185 %img = OpLoad %type_image_f32_2d_0011 %uniform_image_f32_2d_0011
3186 %sampler = OpLoad %type_sampler %uniform_sampler
3187 %simg = OpSampledImage %type_sampled_image_f32_2d_0011 %img %sampler
3188 %res1 = OpImageSampleDrefExplicitLod %f32 %simg %f32vec2_hh %f32_1 Lod|Sample %f32_1 %u32_1
3189 )";
3190
3191 CompileSuccessfully(GenerateShaderCode(body).c_str());
3192 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
3193 EXPECT_THAT(
3194 getDiagnosticString(),
3195 HasSubstr("Dref sampling operation is invalid for multisample image"));
3196 }
3197
3198 TEST_F(ValidateImage, SampleProjDrefExplicitLodWrongSampledType) {
3199 const std::string body = R"(
3200 %img = OpLoad %type_image_f32_1d_0001 %uniform_image_f32_1d_0001
3201 %sampler = OpLoad %type_sampler %uniform_sampler
3202 %simg = OpSampledImage %type_sampled_image_f32_1d_0001 %img %sampler
3203 %res1 = OpImageSampleProjDrefExplicitLod %u32 %simg %f32vec2_hh %f32_0_5 Lod %f32_1
3204 )";
3205
3206 CompileSuccessfully(GenerateShaderCode(body).c_str());
3207 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
3208 EXPECT_THAT(
3209 getDiagnosticString(),
3210 HasSubstr("Expected Image 'Sampled Type' to be the same as Result Type"));
3211 }
3212
3213 TEST_F(ValidateImage, SampleProjDrefExplicitLodVoidSampledType) {
3214 const std::string body = R"(
3215 %img = OpLoad %type_image_void_2d_0001 %uniform_image_void_2d_0001
3216 %sampler = OpLoad %type_sampler %uniform_sampler
3217 %simg = OpSampledImage %type_sampled_image_void_2d_0001 %img %sampler
3218 %res1 = OpImageSampleProjDrefExplicitLod %u32 %simg %f32vec3_hhh %f32_0_5 Lod %f32_1
3219 )";
3220
3221 CompileSuccessfully(GenerateShaderCode(body).c_str());
3222 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
3223 EXPECT_THAT(
3224 getDiagnosticString(),
3225 HasSubstr("Expected Image 'Sampled Type' to be the same as Result Type"));
3226 }
3227
3228 TEST_F(ValidateImage, SampleProjDrefExplicitLodWrongCoordinateType) {
3229 const std::string body = R"(
3230 %img = OpLoad %type_image_f32_1d_0001 %uniform_image_f32_1d_0001
3231 %sampler = OpLoad %type_sampler %uniform_sampler
3232 %simg = OpSampledImage %type_sampled_image_f32_1d_0001 %img %sampler
3233 %res1 = OpImageSampleProjDrefExplicitLod %f32 %simg %img %f32_0_5 Lod %f32_1
3234 )";
3235
3236 CompileSuccessfully(GenerateShaderCode(body).c_str());
3237 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
3238 EXPECT_THAT(
3239 getDiagnosticString(),
3240 HasSubstr("Expected Coordinate to be a 32-bit float scalar or vector"));
3241 }
3242
3243 TEST_F(ValidateImage, SampleProjDrefExplicitLodCoordinateSizeTooSmall) {
3244 const std::string body = R"(
3245 %img = OpLoad %type_image_f32_1d_0001 %uniform_image_f32_1d_0001
3246 %sampler = OpLoad %type_sampler %uniform_sampler
3247 %simg = OpSampledImage %type_sampled_image_f32_1d_0001 %img %sampler
3248 %res1 = OpImageSampleProjDrefExplicitLod %f32 %simg %f32_0_5 %f32_0_5 Lod %f32_1
3249 )";
3250
3251 CompileSuccessfully(GenerateShaderCode(body).c_str());
3252 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
3253 EXPECT_THAT(getDiagnosticString(),
3254 HasSubstr("Expected Coordinate to have at least 2 components, "
3255 "but given only 1"));
3256 }
3257
3258 TEST_F(ValidateImage, FetchSuccess) {
3259 const std::string body = R"(
3260 %img = OpLoad %type_image_f32_1d_0001 %uniform_image_f32_1d_0001
3261 %res1 = OpImageFetch %f32vec4 %img %u32vec2_01
3262 %res2 = OpImageFetch %f32vec4 %img %u32vec2_01 NonPrivateTexelKHR
3263 )";
3264
3265 const std::string extra = R"(
3266 OpCapability VulkanMemoryModelKHR
3267 OpExtension "SPV_KHR_vulkan_memory_model"
3268 )";
3269 CompileSuccessfully(GenerateShaderCode(body, extra, "Fragment", "",
3270 SPV_ENV_UNIVERSAL_1_3, "VulkanKHR")
3271 .c_str(),
3272 SPV_ENV_UNIVERSAL_1_3);
3273 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_UNIVERSAL_1_3));
3274 }
3275
3276 TEST_F(ValidateImage, FetchMultisampledSuccess) {
3277 const std::string body = R"(
3278 %img = OpLoad %type_image_f32_2d_0011 %uniform_image_f32_2d_0011
3279 %res1 = OpImageFetch %f32vec4 %img %u32vec2_01 Sample %u32_1
3280 %res2 = OpImageFetch %f32vec4 %img %u32vec2_01 Sample|NonPrivateTexelKHR %u32_1
3281 )";
3282
3283 const std::string extra = R"(
3284 OpCapability VulkanMemoryModelKHR
3285 OpExtension "SPV_KHR_vulkan_memory_model"
3286 )";
3287 CompileSuccessfully(GenerateShaderCode(body, extra, "Fragment", "",
3288 SPV_ENV_UNIVERSAL_1_3, "VulkanKHR")
3289 .c_str(),
3290 SPV_ENV_UNIVERSAL_1_3);
3291 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_UNIVERSAL_1_3));
3292 }
3293
3294 TEST_F(ValidateImage, FetchWrongResultType) {
3295 const std::string body = R"(
3296 %img = OpLoad %type_image_f32_rect_0001 %uniform_image_f32_rect_0001
3297 %res1 = OpImageFetch %f32 %img %u32vec2_01
3298 )";
3299
3300 CompileSuccessfully(GenerateShaderCode(body).c_str());
3301 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
3302 EXPECT_THAT(getDiagnosticString(),
3303 HasSubstr("Expected Result Type to be int or float vector type"));
3304 }
3305
3306 TEST_F(ValidateImage, FetchWrongNumComponentsResultType) {
3307 const std::string body = R"(
3308 %img = OpLoad %type_image_f32_rect_0001 %uniform_image_f32_rect_0001
3309 %res1 = OpImageFetch %f32vec3 %img %u32vec2_01
3310 )";
3311
3312 CompileSuccessfully(GenerateShaderCode(body).c_str());
3313 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
3314 EXPECT_THAT(getDiagnosticString(),
3315 HasSubstr("Expected Result Type to have 4 components"));
3316 }
3317
3318 TEST_F(ValidateImage, FetchNotImage) {
3319 const std::string body = R"(
3320 %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
3321 %sampler = OpLoad %type_sampler %uniform_sampler
3322 %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
3323 %res1 = OpImageFetch %f32vec4 %sampler %u32vec2_01
3324 )";
3325
3326 CompileSuccessfully(GenerateShaderCode(body).c_str());
3327 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
3328 EXPECT_THAT(getDiagnosticString(),
3329 HasSubstr("Expected Image to be of type OpTypeImage"));
3330 }
3331
3332 TEST_F(ValidateImage, FetchSampledImageDirectly) {
3333 const std::string body = R"(
3334 %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
3335 %sampler = OpLoad %type_sampler %uniform_sampler
3336 %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
3337 %res1 = OpImageFetch %f32vec4 %simg %u32vec2_01
3338 )";
3339
3340 CompileSuccessfully(GenerateShaderCode(body).c_str());
3341 ASSERT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions());
3342 EXPECT_THAT(getDiagnosticString(),
3343 HasSubstr("OpSampledImage instruction must not appear as operand "
3344 "for OpImageFetch"));
3345 }
3346
3347 TEST_F(ValidateImage, FetchNotSampled) {
3348 const std::string body = R"(
3349 %img = OpLoad %type_image_u32_2d_0002 %uniform_image_u32_2d_0002
3350 %res1 = OpImageFetch %u32vec4 %img %u32vec2_01
3351 )";
3352
3353 CompileSuccessfully(GenerateShaderCode(body).c_str());
3354 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
3355 EXPECT_THAT(getDiagnosticString(),
3356 HasSubstr("Expected Image 'Sampled' parameter to be 1"));
3357 }
3358
3359 TEST_F(ValidateImage, FetchCube) {
3360 const std::string body = R"(
3361 %img = OpLoad %type_image_f32_cube_0101 %uniform_image_f32_cube_0101
3362 %res1 = OpImageFetch %f32vec4 %img %u32vec3_012
3363 )";
3364
3365 CompileSuccessfully(GenerateShaderCode(body).c_str());
3366 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
3367 EXPECT_THAT(getDiagnosticString(), HasSubstr("Image 'Dim' cannot be Cube"));
3368 }
3369
3370 TEST_F(ValidateImage, FetchWrongSampledType) {
3371 const std::string body = R"(
3372 %img = OpLoad %type_image_f32_rect_0001 %uniform_image_f32_rect_0001
3373 %res1 = OpImageFetch %u32vec4 %img %u32vec2_01
3374 )";
3375
3376 CompileSuccessfully(GenerateShaderCode(body).c_str());
3377 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
3378 EXPECT_THAT(getDiagnosticString(),
3379 HasSubstr("Expected Image 'Sampled Type' to be the same as "
3380 "Result Type components"));
3381 }
3382
3383 TEST_F(ValidateImage, FetchVoidSampledType) {
3384 const std::string body = R"(
3385 %img = OpLoad %type_image_void_2d_0001 %uniform_image_void_2d_0001
3386 %res1 = OpImageFetch %f32vec4 %img %u32vec2_01
3387 %res2 = OpImageFetch %u32vec4 %img %u32vec2_01
3388 %res3 = OpImageFetch %s32vec4 %img %u32vec2_01
3389 )";
3390
3391 CompileSuccessfully(GenerateShaderCode(body).c_str());
3392 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
3393 }
3394
3395 TEST_F(ValidateImage, FetchWrongCoordinateType) {
3396 const std::string body = R"(
3397 %img = OpLoad %type_image_f32_rect_0001 %uniform_image_f32_rect_0001
3398 %res1 = OpImageFetch %f32vec4 %img %f32vec2_00
3399 )";
3400
3401 CompileSuccessfully(GenerateShaderCode(body).c_str());
3402 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
3403 EXPECT_THAT(
3404 getDiagnosticString(),
3405 HasSubstr("Expected Coordinate to be a 32-bit integer scalar or vector"));
3406 }
3407
3408 TEST_F(ValidateImage, FetchCoordinateSizeTooSmall) {
3409 const std::string body = R"(
3410 %img = OpLoad %type_image_f32_rect_0001 %uniform_image_f32_rect_0001
3411 %res1 = OpImageFetch %f32vec4 %img %u32_1
3412 )";
3413
3414 CompileSuccessfully(GenerateShaderCode(body).c_str());
3415 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
3416 EXPECT_THAT(getDiagnosticString(),
3417 HasSubstr("Expected Coordinate to have at least 2 components, "
3418 "but given only 1"));
3419 }
3420
3421 TEST_F(ValidateImage, FetchLodNotInt) {
3422 const std::string body = R"(
3423 %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
3424 %res1 = OpImageFetch %f32vec4 %img %u32vec2_01 Lod %f32_1
3425 )";
3426
3427 CompileSuccessfully(GenerateShaderCode(body).c_str());
3428 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
3429 EXPECT_THAT(
3430 getDiagnosticString(),
3431 HasSubstr(
3432 "Expected Image Operand Lod to be a 32-bit int scalar when used "
3433 "with OpImageFetch"));
3434 }
3435
3436 TEST_F(ValidateImage, FetchLod16Int) {
3437 const std::string body = R"(
3438 %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
3439 %res1 = OpImageFetch %f32vec4 %img %u32vec2_01 Lod %u16_0
3440 )";
3441
3442 CompileSuccessfully(GenerateShaderCode(body).c_str());
3443 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
3444 EXPECT_THAT(
3445 getDiagnosticString(),
3446 HasSubstr(
3447 "Expected Image Operand Lod to be a 32-bit int scalar when used "
3448 "with OpImageFetch"));
3449 }
3450
3451 TEST_F(ValidateImage, FetchMultisampledMissingSample) {
3452 const std::string body = R"(
3453 %img = OpLoad %type_image_f32_2d_0011 %uniform_image_f32_2d_0011
3454 %res1 = OpImageFetch %f32vec4 %img %u32vec2_01
3455 )";
3456
3457 CompileSuccessfully(GenerateShaderCode(body).c_str());
3458 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions())
3459 << GenerateShaderCode(body);
3460 EXPECT_THAT(getDiagnosticString(),
3461 HasSubstr("Image Operand Sample is required for operation on "
3462 "multi-sampled image"))
3463 << getDiagnosticString();
3464 }
3465
3466 TEST_F(ValidateImage, GatherSuccess) {
3467 const std::string body = R"(
3468 %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
3469 %sampler = OpLoad %type_sampler %uniform_sampler
3470 %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
3471 %res1 = OpImageGather %f32vec4 %simg %f32vec4_0000 %u32_1
3472 %res2 = OpImageGather %f32vec4 %simg %f32vec4_0000 %u32_1 ConstOffsets %const_offsets
3473 %res3 = OpImageGather %f32vec4 %simg %f32vec4_0000 %u32_1 NonPrivateTexelKHR
3474 )";
3475
3476 const std::string extra = R"(
3477 OpCapability VulkanMemoryModelKHR
3478 OpExtension "SPV_KHR_vulkan_memory_model"
3479 )";
3480 CompileSuccessfully(GenerateShaderCode(body, extra, "Fragment", "",
3481 SPV_ENV_UNIVERSAL_1_3, "VulkanKHR")
3482 .c_str(),
3483 SPV_ENV_UNIVERSAL_1_3);
3484 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_UNIVERSAL_1_3));
3485 }
3486
3487 TEST_F(ValidateImage, GatherWrongResultType) {
3488 const std::string body = R"(
3489 %img = OpLoad %type_image_f32_cube_0101 %uniform_image_f32_cube_0101
3490 %sampler = OpLoad %type_sampler %uniform_sampler
3491 %simg = OpSampledImage %type_sampled_image_f32_cube_0101 %img %sampler
3492 %res1 = OpImageGather %f32 %simg %f32vec4_0000 %u32_1
3493 )";
3494
3495 CompileSuccessfully(GenerateShaderCode(body).c_str());
3496 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
3497 EXPECT_THAT(getDiagnosticString(),
3498 HasSubstr("Expected Result Type to be int or float vector type"));
3499 }
3500
3501 TEST_F(ValidateImage, GatherWrongNumComponentsResultType) {
3502 const std::string body = R"(
3503 %img = OpLoad %type_image_f32_cube_0101 %uniform_image_f32_cube_0101
3504 %sampler = OpLoad %type_sampler %uniform_sampler
3505 %simg = OpSampledImage %type_sampled_image_f32_cube_0101 %img %sampler
3506 %res1 = OpImageGather %f32vec3 %simg %f32vec4_0000 %u32_1
3507 )";
3508
3509 CompileSuccessfully(GenerateShaderCode(body).c_str());
3510 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
3511 EXPECT_THAT(getDiagnosticString(),
3512 HasSubstr("Expected Result Type to have 4 components"));
3513 }
3514
3515 TEST_F(ValidateImage, GatherNotSampledImage) {
3516 const std::string body = R"(
3517 %img = OpLoad %type_image_f32_cube_0101 %uniform_image_f32_cube_0101
3518 %res1 = OpImageGather %f32vec4 %img %f32vec4_0000 %u32_1
3519 )";
3520
3521 CompileSuccessfully(GenerateShaderCode(body).c_str());
3522 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
3523 EXPECT_THAT(
3524 getDiagnosticString(),
3525 HasSubstr("Expected Sampled Image to be of type OpTypeSampledImage"));
3526 }
3527
3528 TEST_F(ValidateImage, GatherMultisampleError) {
3529 const std::string body = R"(
3530 %img = OpLoad %type_image_f32_2d_0011 %uniform_image_f32_2d_0011
3531 %sampler = OpLoad %type_sampler %uniform_sampler
3532 %simg = OpSampledImage %type_sampled_image_f32_2d_0011 %img %sampler
3533 %res1 = OpImageGather %f32vec4 %simg %f32vec4_0000 %u32_1 Sample %u32_1
3534 )";
3535
3536 CompileSuccessfully(GenerateShaderCode(body).c_str());
3537 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
3538 EXPECT_THAT(getDiagnosticString(),
3539 HasSubstr("Gather operation is invalid for multisample image"));
3540 }
3541
3542 TEST_F(ValidateImage, GatherWrongSampledType) {
3543 const std::string body = R"(
3544 %img = OpLoad %type_image_f32_cube_0101 %uniform_image_f32_cube_0101
3545 %sampler = OpLoad %type_sampler %uniform_sampler
3546 %simg = OpSampledImage %type_sampled_image_f32_cube_0101 %img %sampler
3547 %res1 = OpImageGather %u32vec4 %simg %f32vec4_0000 %u32_1
3548 )";
3549
3550 CompileSuccessfully(GenerateShaderCode(body).c_str());
3551 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
3552 EXPECT_THAT(getDiagnosticString(),
3553 HasSubstr("Expected Image 'Sampled Type' to be the same as "
3554 "Result Type components"));
3555 }
3556
3557 TEST_F(ValidateImage, GatherVoidSampledType) {
3558 const std::string body = R"(
3559 %img = OpLoad %type_image_void_2d_0001 %uniform_image_void_2d_0001
3560 %sampler = OpLoad %type_sampler %uniform_sampler
3561 %simg = OpSampledImage %type_sampled_image_void_2d_0001 %img %sampler
3562 %res1 = OpImageGather %u32vec4 %simg %f32vec2_00 %u32_1
3563 )";
3564
3565 CompileSuccessfully(GenerateShaderCode(body).c_str());
3566 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
3567 }
3568
3569 TEST_F(ValidateImage, GatherWrongCoordinateType) {
3570 const std::string body = R"(
3571 %img = OpLoad %type_image_f32_cube_0101 %uniform_image_f32_cube_0101
3572 %sampler = OpLoad %type_sampler %uniform_sampler
3573 %simg = OpSampledImage %type_sampled_image_f32_cube_0101 %img %sampler
3574 %res1 = OpImageGather %f32vec4 %simg %u32vec4_0123 %u32_1
3575 )";
3576
3577 CompileSuccessfully(GenerateShaderCode(body).c_str());
3578 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
3579 EXPECT_THAT(
3580 getDiagnosticString(),
3581 HasSubstr("Expected Coordinate to be a 32-bit float scalar or vector"));
3582 }
3583
3584 TEST_F(ValidateImage, GatherCoordinateSizeTooSmall) {
3585 const std::string body = R"(
3586 %img = OpLoad %type_image_f32_cube_0101 %uniform_image_f32_cube_0101
3587 %sampler = OpLoad %type_sampler %uniform_sampler
3588 %simg = OpSampledImage %type_sampled_image_f32_cube_0101 %img %sampler
3589 %res1 = OpImageGather %f32vec4 %simg %f32_0_5 %u32_1
3590 )";
3591
3592 CompileSuccessfully(GenerateShaderCode(body).c_str());
3593 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
3594 EXPECT_THAT(getDiagnosticString(),
3595 HasSubstr("Expected Coordinate to have at least 4 components, "
3596 "but given only 1"));
3597 }
3598
3599 TEST_F(ValidateImage, GatherWrongComponentType) {
3600 const std::string body = R"(
3601 %img = OpLoad %type_image_f32_cube_0101 %uniform_image_f32_cube_0101
3602 %sampler = OpLoad %type_sampler %uniform_sampler
3603 %simg = OpSampledImage %type_sampled_image_f32_cube_0101 %img %sampler
3604 %res1 = OpImageGather %f32vec4 %simg %f32vec4_0000 %f32_1
3605 )";
3606
3607 CompileSuccessfully(GenerateShaderCode(body).c_str());
3608 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
3609 EXPECT_THAT(getDiagnosticString(),
3610 HasSubstr("Expected Component to be 32-bit int scalar"));
3611 }
3612
3613 TEST_F(ValidateImage, GatherComponentNot32Bit) {
3614 const std::string body = R"(
3615 %img = OpLoad %type_image_f32_cube_0101 %uniform_image_f32_cube_0101
3616 %sampler = OpLoad %type_sampler %uniform_sampler
3617 %simg = OpSampledImage %type_sampled_image_f32_cube_0101 %img %sampler
3618 %res1 = OpImageGather %f32vec4 %simg %f32vec4_0000 %u64_0
3619 )";
3620
3621 CompileSuccessfully(GenerateShaderCode(body).c_str());
3622 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
3623 EXPECT_THAT(getDiagnosticString(),
3624 HasSubstr("Expected Component to be 32-bit int scalar"));
3625 }
3626
3627 TEST_F(ValidateImage, GatherComponentSuccessVulkan) {
3628 const std::string body = R"(
3629 %img = OpLoad %type_image_f32_cube_0101 %uniform_image_f32_cube_0101
3630 %sampler = OpLoad %type_sampler %uniform_sampler
3631 %simg = OpSampledImage %type_sampled_image_f32_cube_0101 %img %sampler
3632 %res1 = OpImageGather %f32vec4 %simg %f32vec4_0000 %u32_0
3633 )";
3634
3635 spv_target_env env = SPV_ENV_VULKAN_1_0;
3636 CompileSuccessfully(GenerateShaderCode(body, "", "Fragment", "", env).c_str(),
3637 env);
3638 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions(env));
3639 }
3640
3641 TEST_F(ValidateImage, GatherComponentNotConstantVulkan) {
3642 const std::string body = R"(
3643 %input_u32 = OpLoad %u32 %input_flat_u32
3644 %img = OpLoad %type_image_f32_cube_0101 %uniform_image_f32_cube_0101
3645 %sampler = OpLoad %type_sampler %uniform_sampler
3646 %simg = OpSampledImage %type_sampled_image_f32_cube_0101 %img %sampler
3647 %res1 = OpImageGather %f32vec4 %simg %f32vec4_0000 %input_u32
3648 )";
3649
3650 spv_target_env env = SPV_ENV_VULKAN_1_0;
3651 CompileSuccessfully(GenerateShaderCode(body, "", "Fragment", "", env).c_str(),
3652 env);
3653 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions(env));
3654 EXPECT_THAT(getDiagnosticString(),
3655 AnyVUID("VUID-StandaloneSpirv-OpImageGather-04664"));
3656 EXPECT_THAT(getDiagnosticString(),
3657 HasSubstr("Expected Component Operand to be a const object for "
3658 "Vulkan environment"));
3659 }
3660
3661 TEST_F(ValidateImage, GatherDimCube) {
3662 const std::string body = R"(
3663 %img = OpLoad %type_image_f32_cube_0101 %uniform_image_f32_cube_0101
3664 %sampler = OpLoad %type_sampler %uniform_sampler
3665 %simg = OpSampledImage %type_sampled_image_f32_cube_0101 %img %sampler
3666 %res1 = OpImageGather %f32vec4 %simg %f32vec4_0000 %u32_1 ConstOffsets %const_offsets
3667 )";
3668
3669 CompileSuccessfully(GenerateShaderCode(body).c_str());
3670 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
3671 EXPECT_THAT(
3672 getDiagnosticString(),
3673 HasSubstr(
3674 "Image Operand ConstOffsets cannot be used with Cube Image 'Dim'"));
3675 }
3676
3677 TEST_F(ValidateImage, GatherConstOffsetsNotArray) {
3678 const std::string body = R"(
3679 %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
3680 %sampler = OpLoad %type_sampler %uniform_sampler
3681 %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
3682 %res1 = OpImageGather %f32vec4 %simg %f32vec4_0000 %u32_1 ConstOffsets %u32vec4_0123
3683 )";
3684
3685 CompileSuccessfully(GenerateShaderCode(body).c_str());
3686 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
3687 EXPECT_THAT(
3688 getDiagnosticString(),
3689 HasSubstr(
3690 "Expected Image Operand ConstOffsets to be an array of size 4"));
3691 }
3692
3693 TEST_F(ValidateImage, GatherConstOffsetsArrayWrongSize) {
3694 const std::string body = R"(
3695 %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
3696 %sampler = OpLoad %type_sampler %uniform_sampler
3697 %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
3698 %res1 = OpImageGather %f32vec4 %simg %f32vec4_0000 %u32_1 ConstOffsets %const_offsets3x2
3699 )";
3700
3701 CompileSuccessfully(GenerateShaderCode(body).c_str());
3702 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
3703 EXPECT_THAT(
3704 getDiagnosticString(),
3705 HasSubstr(
3706 "Expected Image Operand ConstOffsets to be an array of size 4"));
3707 }
3708
3709 TEST_F(ValidateImage, GatherConstOffsetsArrayNotVector) {
3710 const std::string body = R"(
3711 %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
3712 %sampler = OpLoad %type_sampler %uniform_sampler
3713 %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
3714 %res1 = OpImageGather %f32vec4 %simg %f32vec4_0000 %u32_1 ConstOffsets %const_offsets4xu
3715 )";
3716
3717 CompileSuccessfully(GenerateShaderCode(body).c_str());
3718 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
3719 EXPECT_THAT(getDiagnosticString(),
3720 HasSubstr("Expected Image Operand ConstOffsets array components "
3721 "to be a 32-bit int vectors of size 2"));
3722 }
3723
3724 TEST_F(ValidateImage, GatherConstOffsetsArrayVectorWrongSize) {
3725 const std::string body = R"(
3726 %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
3727 %sampler = OpLoad %type_sampler %uniform_sampler
3728 %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
3729 %res1 = OpImageGather %f32vec4 %simg %f32vec4_0000 %u32_1 ConstOffsets %const_offsets4x3
3730 )";
3731
3732 CompileSuccessfully(GenerateShaderCode(body).c_str());
3733 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
3734 EXPECT_THAT(getDiagnosticString(),
3735 HasSubstr("Expected Image Operand ConstOffsets array components "
3736 "to be a 32-bit int vectors of size 2"));
3737 }
3738
3739 TEST_F(ValidateImage, GatherConstOffsetsArrayVector16Bit) {
3740 const std::string body = R"(
3741 %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
3742 %sampler = OpLoad %type_sampler %uniform_sampler
3743 %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
3744 %res1 = OpImageGather %f32vec4 %simg %f32vec4_0000 %u32_1 ConstOffsets %const_offsets4f16
3745 )";
3746
3747 CompileSuccessfully(GenerateShaderCode(body).c_str());
3748 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
3749 EXPECT_THAT(getDiagnosticString(),
3750 HasSubstr("Expected Image Operand ConstOffsets array components "
3751 "to be a 32-bit int vectors of size 2"));
3752 }
3753
3754 TEST_F(ValidateImage, GatherConstOffsetsArrayNotConst) {
3755 const std::string body = R"(
3756 %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
3757 %sampler = OpLoad %type_sampler %uniform_sampler
3758 %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
3759 %offsets = OpUndef %u32vec2arr4
3760 %res1 = OpImageGather %f32vec4 %simg %f32vec4_0000 %u32_1 ConstOffsets %offsets
3761 )";
3762
3763 CompileSuccessfully(GenerateShaderCode(body).c_str());
3764 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
3765 EXPECT_THAT(
3766 getDiagnosticString(),
3767 HasSubstr("Expected Image Operand ConstOffsets to be a const object"));
3768 }
3769
3770 TEST_F(ValidateImage, NotGatherWithConstOffsets) {
3771 const std::string body = R"(
3772 %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
3773 %sampler = OpLoad %type_sampler %uniform_sampler
3774 %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
3775 %res2 = OpImageSampleImplicitLod %f32vec4 %simg %f32vec2_hh ConstOffsets %const_offsets
3776 )";
3777
3778 CompileSuccessfully(GenerateShaderCode(body).c_str());
3779 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
3780 EXPECT_THAT(
3781 getDiagnosticString(),
3782 HasSubstr(
3783 "Image Operand ConstOffsets can only be used with OpImageGather "
3784 "and OpImageDrefGather"));
3785 }
3786
3787 TEST_F(ValidateImage, DrefGatherSuccess) {
3788 const std::string body = R"(
3789 %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
3790 %sampler = OpLoad %type_sampler %uniform_sampler
3791 %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
3792 %res1 = OpImageDrefGather %f32vec4 %simg %f32vec4_0000 %f32_0_5
3793 %res2 = OpImageDrefGather %f32vec4 %simg %f32vec4_0000 %f32_0_5 ConstOffsets %const_offsets
3794 %res3 = OpImageDrefGather %f32vec4 %simg %f32vec4_0000 %f32_0_5 NonPrivateTexelKHR
3795 )";
3796
3797 const std::string extra = R"(
3798 OpCapability VulkanMemoryModelKHR
3799 OpExtension "SPV_KHR_vulkan_memory_model"
3800 )";
3801 CompileSuccessfully(GenerateShaderCode(body, extra, "Fragment", "",
3802 SPV_ENV_UNIVERSAL_1_3, "VulkanKHR")
3803 .c_str(),
3804 SPV_ENV_UNIVERSAL_1_3);
3805 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_UNIVERSAL_1_3));
3806 }
3807
3808 TEST_F(ValidateImage, DrefGatherMultisampleError) {
3809 const std::string body = R"(
3810 %img = OpLoad %type_image_f32_2d_0011 %uniform_image_f32_2d_0011
3811 %sampler = OpLoad %type_sampler %uniform_sampler
3812 %simg = OpSampledImage %type_sampled_image_f32_2d_0011 %img %sampler
3813 %res1 = OpImageDrefGather %f32vec4 %simg %f32vec4_0000 %f32_1 Sample %u32_1
3814 )";
3815
3816 CompileSuccessfully(GenerateShaderCode(body).c_str());
3817 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
3818 EXPECT_THAT(getDiagnosticString(),
3819 HasSubstr("Gather operation is invalid for multisample image"));
3820 }
3821
3822 TEST_F(ValidateImage, DrefGatherVoidSampledType) {
3823 const std::string body = R"(
3824 %img = OpLoad %type_image_void_2d_0001 %uniform_image_void_2d_0001
3825 %sampler = OpLoad %type_sampler %uniform_sampler
3826 %simg = OpSampledImage %type_sampled_image_void_2d_0001 %img %sampler
3827 %res1 = OpImageDrefGather %u32vec4 %simg %f32vec2_00 %f32_0_5
3828 )";
3829
3830 CompileSuccessfully(GenerateShaderCode(body).c_str());
3831 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
3832 EXPECT_THAT(getDiagnosticString(),
3833 HasSubstr("Expected Image 'Sampled Type' to be the same as "
3834 "Result Type components"));
3835 }
3836
3837 TEST_F(ValidateImage, DrefGatherWrongDrefType) {
3838 const std::string body = R"(
3839 %img = OpLoad %type_image_f32_cube_0101 %uniform_image_f32_cube_0101
3840 %sampler = OpLoad %type_sampler %uniform_sampler
3841 %simg = OpSampledImage %type_sampled_image_f32_cube_0101 %img %sampler
3842 %res1 = OpImageDrefGather %f32vec4 %simg %f32vec4_0000 %u32_1
3843 )";
3844
3845 CompileSuccessfully(GenerateShaderCode(body).c_str());
3846 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
3847 EXPECT_THAT(getDiagnosticString(),
3848 HasSubstr("Expected Dref to be of 32-bit float type"));
3849 }
3850
3851 TEST_F(ValidateImage, DrefGatherWrongDimVulkan) {
3852 const std::string body = R"(
3853 %img = OpLoad %type_image_f32_3d_0001 %uniform_image_f32_3d_0001
3854 %sampler = OpLoad %type_sampler %uniform_sampler
3855 %simg = OpSampledImage %type_sampled_image_f32_3d_0001 %img %sampler
3856 %res1 = OpImageDrefGather %f32vec4 %simg %f32vec4_0000 %f32_0_5
3857 )";
3858
3859 CompileSuccessfully(
3860 GenerateShaderCode(body, "", "Fragment", "", SPV_ENV_VULKAN_1_0).c_str());
3861 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions(SPV_ENV_VULKAN_1_0));
3862 EXPECT_THAT(getDiagnosticString(),
3863 AnyVUID("VUID-StandaloneSpirv-OpImage-04777"));
3864 EXPECT_THAT(getDiagnosticString(),
3865 HasSubstr("Expected Image 'Dim' to be 2D, Cube, or Rect"));
3866 }
3867
3868 TEST_F(ValidateImage, ReadSuccess1) {
3869 const std::string body = R"(
3870 %img = OpLoad %type_image_u32_2d_0002 %uniform_image_u32_2d_0002
3871 %res1 = OpImageRead %u32vec4 %img %u32vec2_01
3872 )";
3873
3874 const std::string extra = "\nOpCapability StorageImageReadWithoutFormat\n";
3875 CompileSuccessfully(GenerateShaderCode(body, extra).c_str());
3876 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
3877 }
3878
3879 TEST_F(ValidateImage, ReadSuccess2) {
3880 const std::string body = R"(
3881 %img = OpLoad %type_image_f32_1d_0002_rgba32f %uniform_image_f32_1d_0002_rgba32f
3882 %res1 = OpImageRead %f32vec4 %img %u32vec2_01
3883 )";
3884
3885 const std::string extra = "\nOpCapability Image1D\n";
3886 CompileSuccessfully(GenerateShaderCode(body, extra).c_str());
3887 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
3888 }
3889
3890 TEST_F(ValidateImage, ReadSuccess3) {
3891 const std::string body = R"(
3892 %img = OpLoad %type_image_f32_cube_0102_rgba32f %uniform_image_f32_cube_0102_rgba32f
3893 %res1 = OpImageRead %f32vec4 %img %u32vec3_012
3894 )";
3895
3896 const std::string extra = "\nOpCapability ImageCubeArray\n";
3897 CompileSuccessfully(GenerateShaderCode(body, extra).c_str());
3898 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
3899 }
3900
3901 TEST_F(ValidateImage, ReadSuccess4) {
3902 const std::string body = R"(
3903 %img = OpLoad %type_image_f32_spd_0002 %uniform_image_f32_spd_0002
3904 %res1 = OpImageRead %f32vec4 %img %u32vec2_01
3905 )";
3906
3907 CompileSuccessfully(GenerateShaderCode(body).c_str());
3908 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
3909 }
3910
3911 TEST_F(ValidateImage, ReadNeedCapabilityStorageImageReadWithoutFormat) {
3912 const std::string body = R"(
3913 %img = OpLoad %type_image_u32_2d_0002 %uniform_image_u32_2d_0002
3914 %res1 = OpImageRead %u32vec4 %img %u32vec2_01
3915 )";
3916
3917 CompileSuccessfully(GenerateShaderCode(body).c_str());
3918 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
3919 }
3920
3921 TEST_F(ValidateImage, ReadNeedCapabilityStorageImageReadWithoutFormatVulkan) {
3922 const std::string body = R"(
3923 %img = OpLoad %type_image_u32_2d_0002 %uniform_image_u32_2d_0002
3924 %res1 = OpImageRead %u32vec4 %img %u32vec2_01
3925 )";
3926
3927 spv_target_env env = SPV_ENV_VULKAN_1_0;
3928 CompileSuccessfully(GenerateShaderCode(body, "", "Fragment", "", env).c_str(),
3929 env);
3930 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions(env));
3931 EXPECT_THAT(getDiagnosticString(),
3932 HasSubstr("Capability StorageImageReadWithoutFormat is required "
3933 "to read storage image"));
3934 }
3935
3936 TEST_F(ValidateImage, ReadNeedCapabilityImage1D) {
3937 const std::string body = R"(
3938 %img = OpLoad %type_image_f32_1d_0002_rgba32f %uniform_image_f32_1d_0002_rgba32f
3939 %res1 = OpImageRead %f32vec4 %img %u32vec2_01
3940 )";
3941
3942 CompileSuccessfully(GenerateShaderCode(body).c_str());
3943 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
3944 EXPECT_THAT(
3945 getDiagnosticString(),
3946 HasSubstr("Capability Image1D is required to access storage image"));
3947 }
3948
3949 TEST_F(ValidateImage, ReadNeedCapabilityImageCubeArray) {
3950 const std::string body = R"(
3951 %img = OpLoad %type_image_f32_cube_0102_rgba32f %uniform_image_f32_cube_0102_rgba32f
3952 %res1 = OpImageRead %f32vec4 %img %u32vec3_012
3953 )";
3954
3955 CompileSuccessfully(GenerateShaderCode(body).c_str());
3956 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
3957 EXPECT_THAT(
3958 getDiagnosticString(),
3959 HasSubstr(
3960 "Capability ImageCubeArray is required to access storage image"));
3961 }
3962
3963 // TODO([email protected]) Disabled until the spec is clarified.
3964 TEST_F(ValidateImage, DISABLED_ReadWrongResultType) {
3965 const std::string body = R"(
3966 %img = OpLoad %type_image_u32_2d_0002 %uniform_image_u32_2d_0002
3967 %res1 = OpImageRead %f32 %img %u32vec2_01
3968 )";
3969
3970 const std::string extra = "\nOpCapability StorageImageReadWithoutFormat\n";
3971 CompileSuccessfully(GenerateShaderCode(body, extra).c_str());
3972 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
3973 EXPECT_THAT(getDiagnosticString(),
3974 HasSubstr("Expected Result Type to be int or float vector type"));
3975 }
3976
3977 TEST_F(ValidateImage, ReadScalarResultType_Universal) {
3978 const std::string body = R"(
3979 %img = OpLoad %type_image_u32_2d_0002 %uniform_image_u32_2d_0002
3980 %res1 = OpImageRead %u32 %img %u32vec2_01
3981 )";
3982
3983 const std::string extra = "\nOpCapability StorageImageReadWithoutFormat\n";
3984 CompileSuccessfully(GenerateShaderCode(body, extra).c_str());
3985 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_UNIVERSAL_1_0));
3986 EXPECT_THAT(getDiagnosticString(), Eq(""));
3987 }
3988
3989 TEST_F(ValidateImage, ReadUnusualNumComponentsResultType_Universal) {
3990 const std::string body = R"(
3991 %img = OpLoad %type_image_u32_2d_0002 %uniform_image_u32_2d_0002
3992 %res1 = OpImageRead %u32vec3 %img %u32vec2_01
3993 )";
3994
3995 const std::string extra = "\nOpCapability StorageImageReadWithoutFormat\n";
3996 CompileSuccessfully(GenerateShaderCode(body, extra).c_str());
3997 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_UNIVERSAL_1_0));
3998 EXPECT_THAT(getDiagnosticString(), Eq(""));
3999 }
4000
4001 TEST_F(ValidateImage, ReadWrongNumComponentsResultType_Vulkan) {
4002 const std::string body = R"(
4003 %img = OpLoad %type_image_u32_2d_0002 %uniform_image_u32_2d_0002
4004 %res1 = OpImageRead %u32vec3 %img %u32vec2_01
4005 )";
4006
4007 const std::string extra = "\nOpCapability StorageImageReadWithoutFormat\n";
4008 CompileSuccessfully(
4009 GenerateShaderCode(body, extra, "Fragment", "", SPV_ENV_VULKAN_1_0)
4010 .c_str());
4011 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions(SPV_ENV_VULKAN_1_0));
4012 EXPECT_THAT(getDiagnosticString(),
4013 AnyVUID("VUID-StandaloneSpirv-Result-04780"));
4014 EXPECT_THAT(getDiagnosticString(),
4015 HasSubstr("Expected Result Type to have 4 components"));
4016 }
4017
4018 TEST_F(ValidateImage, ReadNotImage) {
4019 const std::string body = R"(
4020 %sampler = OpLoad %type_sampler %uniform_sampler
4021 %res1 = OpImageRead %f32vec4 %sampler %u32vec2_01
4022 )";
4023
4024 const std::string extra = "\nOpCapability StorageImageReadWithoutFormat\n";
4025 CompileSuccessfully(GenerateShaderCode(body, extra).c_str());
4026 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
4027 EXPECT_THAT(getDiagnosticString(),
4028 HasSubstr("Expected Image to be of type OpTypeImage"));
4029 }
4030
4031 TEST_F(ValidateImage, ReadImageSampled) {
4032 const std::string body = R"(
4033 %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
4034 %res1 = OpImageRead %f32vec4 %img %u32vec2_01
4035 )";
4036
4037 const std::string extra = "\nOpCapability StorageImageReadWithoutFormat\n";
4038 CompileSuccessfully(GenerateShaderCode(body, extra).c_str());
4039 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
4040 EXPECT_THAT(getDiagnosticString(),
4041 HasSubstr("Expected Image 'Sampled' parameter to be 0 or 2"));
4042 }
4043
4044 TEST_F(ValidateImage, ReadWrongSampledType) {
4045 const std::string body = R"(
4046 %img = OpLoad %type_image_u32_2d_0002 %uniform_image_u32_2d_0002
4047 %res1 = OpImageRead %f32vec4 %img %u32vec2_01
4048 )";
4049
4050 const std::string extra = "\nOpCapability StorageImageReadWithoutFormat\n";
4051 CompileSuccessfully(GenerateShaderCode(body, extra).c_str());
4052 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
4053 EXPECT_THAT(getDiagnosticString(),
4054 HasSubstr("Expected Image 'Sampled Type' to be the same as "
4055 "Result Type components"));
4056 }
4057
4058 TEST_F(ValidateImage, ReadVoidSampledType) {
4059 const std::string body = R"(
4060 %img = OpLoad %type_image_void_2d_0002 %uniform_image_void_2d_0002
4061 %res1 = OpImageRead %f32vec4 %img %u32vec2_01
4062 %res2 = OpImageRead %u32vec4 %img %u32vec2_01
4063 %res3 = OpImageRead %s32vec4 %img %u32vec2_01
4064 )";
4065
4066 const std::string extra = "\nOpCapability StorageImageReadWithoutFormat\n";
4067 CompileSuccessfully(GenerateShaderCode(body, extra).c_str());
4068 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
4069 }
4070
4071 TEST_F(ValidateImage, ReadFloatCoordinateType) {
4072 const std::string body = R"(
4073 %img = OpLoad %type_image_u32_2d_0002 %uniform_image_u32_2d_0002
4074 %res1 = OpImageRead %u32vec4 %img %f32vec2_00
4075 )";
4076
4077 const std::string extra = "\nOpCapability StorageImageReadWithoutFormat\n";
4078 CompileSuccessfully(GenerateShaderCode(body, extra).c_str());
4079 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
4080 }
4081
4082 TEST_F(ValidateImage, ReadWrongCoordinateType) {
4083 const std::string body = R"(
4084 %img = OpLoad %type_image_u32_2d_0002 %uniform_image_u32_2d_0002
4085 %res1 = OpImageRead %u32vec4 %img %f16vec2_00
4086 )";
4087
4088 const std::string extra = "\nOpCapability StorageImageReadWithoutFormat\n";
4089 CompileSuccessfully(GenerateShaderCode(body, extra).c_str());
4090 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
4091 EXPECT_THAT(getDiagnosticString(),
4092 HasSubstr("Expected Coordinate to be a 32-bit scalar or vector"));
4093 }
4094
4095 TEST_F(ValidateImage, ReadCoordinateSizeTooSmall) {
4096 const std::string body = R"(
4097 %img = OpLoad %type_image_u32_2d_0002 %uniform_image_u32_2d_0002
4098 %res1 = OpImageRead %u32vec4 %img %u32_1
4099 )";
4100
4101 const std::string extra = "\nOpCapability StorageImageReadWithoutFormat\n";
4102 CompileSuccessfully(GenerateShaderCode(body, extra).c_str());
4103 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
4104 EXPECT_THAT(getDiagnosticString(),
4105 HasSubstr("Expected Coordinate to have at least 2 components, "
4106 "but given only 1"));
4107 }
4108
4109 TEST_F(ValidateImage, WriteSuccess1) {
4110 const std::string body = R"(
4111 %img = OpLoad %type_image_u32_2d_0002 %uniform_image_u32_2d_0002
4112 OpImageWrite %img %u32vec2_01 %u32vec4_0123
4113 )";
4114
4115 const std::string extra = "\nOpCapability StorageImageWriteWithoutFormat\n";
4116 CompileSuccessfully(GenerateShaderCode(body, extra).c_str());
4117 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
4118 }
4119
4120 TEST_F(ValidateImage, WriteSuccess2) {
4121 const std::string body = R"(
4122 %img = OpLoad %type_image_f32_1d_0002_rgba32f %uniform_image_f32_1d_0002_rgba32f
4123 OpImageWrite %img %u32_1 %f32vec4_0000
4124 )";
4125
4126 const std::string extra = "\nOpCapability Image1D\n";
4127 CompileSuccessfully(GenerateShaderCode(body, extra).c_str());
4128 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
4129 }
4130
4131 TEST_F(ValidateImage, WriteSuccess3) {
4132 const std::string body = R"(
4133 %img = OpLoad %type_image_f32_cube_0102_rgba32f %uniform_image_f32_cube_0102_rgba32f
4134 OpImageWrite %img %u32vec3_012 %f32vec4_0000
4135 )";
4136
4137 const std::string extra = "\nOpCapability ImageCubeArray\n";
4138 CompileSuccessfully(GenerateShaderCode(body, extra).c_str());
4139 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
4140 }
4141
4142 TEST_F(ValidateImage, WriteSuccess4) {
4143 const std::string body = R"(
4144 %img = OpLoad %type_image_f32_2d_0012 %uniform_image_f32_2d_0012
4145 OpImageWrite %img %u32vec2_01 %f32vec4_0000 Sample %u32_1
4146 )";
4147
4148 const std::string extra = R"(
4149 OpCapability StorageImageWriteWithoutFormat
4150 OpCapability StorageImageMultisample
4151 )";
4152
4153 const std::string declarations = R"(
4154 %type_image_f32_2d_0012 = OpTypeImage %f32 2D 0 0 1 2 Unknown
4155 %ptr_image_f32_2d_0012 = OpTypePointer UniformConstant %type_image_f32_2d_0012
4156 %uniform_image_f32_2d_0012 = OpVariable %ptr_image_f32_2d_0012 UniformConstant
4157 )";
4158 CompileSuccessfully(GenerateShaderCode(body, extra, "Fragment", "",
4159 SPV_ENV_UNIVERSAL_1_0, "GLSL450",
4160 declarations)
4161 .c_str());
4162 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
4163 }
4164
4165 TEST_F(ValidateImage, WriteSubpassData) {
4166 const std::string body = R"(
4167 %img = OpLoad %type_image_f32_spd_0002 %uniform_image_f32_spd_0002
4168 OpImageWrite %img %u32vec2_01 %f32vec4_0000
4169 )";
4170
4171 CompileSuccessfully(GenerateShaderCode(body).c_str());
4172 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
4173 EXPECT_THAT(getDiagnosticString(),
4174 HasSubstr("Image 'Dim' cannot be SubpassData"));
4175 }
4176
4177 TEST_F(ValidateImage, WriteNeedCapabilityStorageImageWriteWithoutFormat) {
4178 const std::string body = R"(
4179 %img = OpLoad %type_image_u32_2d_0002 %uniform_image_u32_2d_0002
4180 OpImageWrite %img %u32vec2_01 %u32vec4_0123
4181 )";
4182
4183 CompileSuccessfully(GenerateShaderCode(body).c_str());
4184 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
4185 }
4186
4187 TEST_F(ValidateImage, WriteNeedCapabilityStorageImageWriteWithoutFormatVulkan) {
4188 const std::string body = R"(
4189 %img = OpLoad %type_image_u32_2d_0002 %uniform_image_u32_2d_0002
4190 OpImageWrite %img %u32vec2_01 %u32vec4_0123
4191 )";
4192
4193 spv_target_env env = SPV_ENV_VULKAN_1_0;
4194 CompileSuccessfully(GenerateShaderCode(body, "", "Fragment", "", env).c_str(),
4195 env);
4196 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions(env));
4197 EXPECT_THAT(
4198 getDiagnosticString(),
4199 HasSubstr(
4200 "Capability StorageImageWriteWithoutFormat is required to write to "
4201 "storage image"));
4202 }
4203
4204 TEST_F(ValidateImage, WriteNeedCapabilityImage1D) {
4205 const std::string body = R"(
4206 %img = OpLoad %type_image_f32_1d_0002_rgba32f %uniform_image_f32_1d_0002_rgba32f
4207 OpImageWrite %img %u32vec2_01 %f32vec4_0000
4208 )";
4209
4210 CompileSuccessfully(GenerateShaderCode(body).c_str());
4211 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
4212 EXPECT_THAT(getDiagnosticString(),
4213 HasSubstr("Capability Image1D is required to access storage "
4214 "image"));
4215 }
4216
4217 TEST_F(ValidateImage, WriteNeedCapabilityImageCubeArray) {
4218 const std::string body = R"(
4219 %img = OpLoad %type_image_f32_cube_0102_rgba32f %uniform_image_f32_cube_0102_rgba32f
4220 OpImageWrite %img %u32vec3_012 %f32vec4_0000
4221 )";
4222
4223 CompileSuccessfully(GenerateShaderCode(body).c_str());
4224 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
4225 EXPECT_THAT(
4226 getDiagnosticString(),
4227 HasSubstr(
4228 "Capability ImageCubeArray is required to access storage image"));
4229 }
4230
4231 TEST_F(ValidateImage, WriteNotImage) {
4232 const std::string body = R"(
4233 %sampler = OpLoad %type_sampler %uniform_sampler
4234 OpImageWrite %sampler %u32vec2_01 %f32vec4_0000
4235 )";
4236
4237 CompileSuccessfully(GenerateShaderCode(body).c_str());
4238 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
4239 EXPECT_THAT(getDiagnosticString(),
4240 HasSubstr("Expected Image to be of type OpTypeImage"));
4241 }
4242
4243 TEST_F(ValidateImage, WriteImageSampled) {
4244 const std::string body = R"(
4245 %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
4246 OpImageWrite %img %u32vec2_01 %f32vec4_0000
4247 )";
4248
4249 const std::string extra = "\nOpCapability StorageImageWriteWithoutFormat\n";
4250 CompileSuccessfully(GenerateShaderCode(body, extra).c_str());
4251 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
4252 EXPECT_THAT(getDiagnosticString(),
4253 HasSubstr("Expected Image 'Sampled' parameter to be 0 or 2"));
4254 }
4255
4256 TEST_F(ValidateImage, WriteFloatCoordinateType) {
4257 const std::string body = R"(
4258 %img = OpLoad %type_image_u32_2d_0002 %uniform_image_u32_2d_0002
4259 OpImageWrite %img %f32vec2_00 %u32vec4_0123
4260 )";
4261
4262 const std::string extra = "\nOpCapability StorageImageWriteWithoutFormat\n";
4263 CompileSuccessfully(GenerateShaderCode(body, extra).c_str());
4264 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
4265 }
4266
4267 TEST_F(ValidateImage, WriteWrongCoordinateType) {
4268 const std::string body = R"(
4269 %img = OpLoad %type_image_u32_2d_0002 %uniform_image_u32_2d_0002
4270 OpImageWrite %img %f16vec2_00 %u32vec4_0123
4271 )";
4272
4273 const std::string extra = "\nOpCapability StorageImageWriteWithoutFormat\n";
4274 CompileSuccessfully(GenerateShaderCode(body, extra).c_str());
4275 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
4276 EXPECT_THAT(getDiagnosticString(),
4277 HasSubstr("Expected Coordinate to be a 32-bit scalar or vector"));
4278 }
4279
4280 TEST_F(ValidateImage, WriteCoordinateSizeTooSmall) {
4281 const std::string body = R"(
4282 %img = OpLoad %type_image_u32_2d_0002 %uniform_image_u32_2d_0002
4283 OpImageWrite %img %u32_1 %u32vec4_0123
4284 )";
4285
4286 const std::string extra = "\nOpCapability StorageImageWriteWithoutFormat\n";
4287 CompileSuccessfully(GenerateShaderCode(body, extra).c_str());
4288 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
4289 EXPECT_THAT(getDiagnosticString(),
4290 HasSubstr("Expected Coordinate to have at least 2 components, "
4291 "but given only 1"));
4292 }
4293
4294 TEST_F(ValidateImage, WriteTexelScalarSuccess) {
4295 const std::string body = R"(
4296 %img = OpLoad %type_image_u32_2d_0002 %uniform_image_u32_2d_0002
4297 OpImageWrite %img %u32vec2_01 %u32_2
4298 )";
4299
4300 const std::string extra = "\nOpCapability StorageImageWriteWithoutFormat\n";
4301 CompileSuccessfully(GenerateShaderCode(body, extra).c_str());
4302 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
4303 }
4304
4305 TEST_F(ValidateImage, WriteTexelWrongType) {
4306 const std::string body = R"(
4307 %img = OpLoad %type_image_u32_2d_0002 %uniform_image_u32_2d_0002
4308 OpImageWrite %img %u32vec2_01 %img
4309 )";
4310
4311 const std::string extra = "\nOpCapability StorageImageWriteWithoutFormat\n";
4312 CompileSuccessfully(GenerateShaderCode(body, extra).c_str());
4313 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
4314 EXPECT_THAT(getDiagnosticString(),
4315 HasSubstr("Expected Texel to be int or float vector or scalar"));
4316 }
4317
4318 TEST_F(ValidateImage, WriteTexelNonNumericalType) {
4319 const std::string body = R"(
4320 %img = OpLoad %type_image_u32_2d_0002 %uniform_image_u32_2d_0002
4321 OpImageWrite %img %u32vec2_01 %boolvec4_tttt
4322 )";
4323
4324 const std::string extra = "\nOpCapability StorageImageWriteWithoutFormat\n";
4325 CompileSuccessfully(GenerateShaderCode(body, extra).c_str());
4326 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
4327 EXPECT_THAT(getDiagnosticString(),
4328 HasSubstr("Expected Texel to be int or float vector or scalar"));
4329 }
4330
4331 TEST_F(ValidateImage, WriteTexelWrongComponentType) {
4332 const std::string body = R"(
4333 %img = OpLoad %type_image_u32_2d_0002 %uniform_image_u32_2d_0002
4334 OpImageWrite %img %u32vec2_01 %f32vec4_0000
4335 )";
4336
4337 const std::string extra = "\nOpCapability StorageImageWriteWithoutFormat\n";
4338 CompileSuccessfully(GenerateShaderCode(body, extra).c_str());
4339 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
4340 EXPECT_THAT(
4341 getDiagnosticString(),
4342 HasSubstr(
4343 "Expected Image 'Sampled Type' to be the same as Texel components"));
4344 }
4345
4346 TEST_F(ValidateImage, WriteSampleNotInteger) {
4347 const std::string body = R"(
4348 %img = OpLoad %type_image_f32_2d_0012 %uniform_image_f32_2d_0012
4349 OpImageWrite %img %u32vec2_01 %f32vec4_0000 Sample %f32_1
4350 )";
4351
4352 const std::string extra = R"(
4353 OpCapability StorageImageWriteWithoutFormat
4354 OpCapability StorageImageMultisample
4355 )";
4356 const std::string declarations = R"(
4357 %type_image_f32_2d_0012 = OpTypeImage %f32 2D 0 0 1 2 Unknown
4358 %ptr_image_f32_2d_0012 = OpTypePointer UniformConstant %type_image_f32_2d_0012
4359 %uniform_image_f32_2d_0012 = OpVariable %ptr_image_f32_2d_0012 UniformConstant
4360 )";
4361 CompileSuccessfully(GenerateShaderCode(body, extra, "Fragment", "",
4362 SPV_ENV_UNIVERSAL_1_0, "GLSL450",
4363 declarations)
4364 .c_str());
4365 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
4366 EXPECT_THAT(
4367 getDiagnosticString(),
4368 HasSubstr("Expected Image Operand Sample to be a 32-bit int scalar"));
4369 }
4370
4371 TEST_F(ValidateImage, WriteSample16Bit) {
4372 const std::string body = R"(
4373 %img = OpLoad %type_image_f32_2d_0012 %uniform_image_f32_2d_0012
4374 OpImageWrite %img %u32vec2_01 %f32vec4_0000 Sample %u16_0
4375 )";
4376
4377 const std::string extra = R"(
4378 OpCapability StorageImageWriteWithoutFormat
4379 OpCapability StorageImageMultisample
4380 )";
4381 const std::string declarations = R"(
4382 %type_image_f32_2d_0012 = OpTypeImage %f32 2D 0 0 1 2 Unknown
4383 %ptr_image_f32_2d_0012 = OpTypePointer UniformConstant %type_image_f32_2d_0012
4384 %uniform_image_f32_2d_0012 = OpVariable %ptr_image_f32_2d_0012 UniformConstant
4385 )";
4386 CompileSuccessfully(GenerateShaderCode(body, extra, "Fragment", "",
4387 SPV_ENV_UNIVERSAL_1_0, "GLSL450",
4388 declarations)
4389 .c_str());
4390 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
4391 EXPECT_THAT(
4392 getDiagnosticString(),
4393 HasSubstr("Expected Image Operand Sample to be a 32-bit int scalar"));
4394 }
4395
4396 TEST_F(ValidateImage, WriteSampleNotMultisampled) {
4397 const std::string body = R"(
4398 %img = OpLoad %type_image_f32_2d_0002 %uniform_image_f32_2d_0002
4399 OpImageWrite %img %u32vec2_01 %f32vec4_0000 Sample %u32_1
4400 )";
4401
4402 const std::string extra = "\nOpCapability StorageImageWriteWithoutFormat\n";
4403 CompileSuccessfully(GenerateShaderCode(body, extra).c_str());
4404 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
4405 EXPECT_THAT(
4406 getDiagnosticString(),
4407 HasSubstr("Image Operand Sample requires non-zero 'MS' parameter"));
4408 }
4409
4410 TEST_F(ValidateImage, SampleWrongOpcode) {
4411 const std::string body = R"(
4412 %img = OpLoad %type_image_f32_2d_0011 %uniform_image_f32_2d_0011
4413 %sampler = OpLoad %type_sampler %uniform_sampler
4414 %simg = OpSampledImage %type_sampled_image_f32_2d_0011 %img %sampler
4415 %res1 = OpImageSampleExplicitLod %f32vec4 %simg %f32vec2_00 Sample %u32_1
4416 )";
4417
4418 CompileSuccessfully(GenerateShaderCode(body).c_str());
4419 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
4420 EXPECT_THAT(getDiagnosticString(),
4421 HasSubstr("Sampling operation is invalid for multisample image"));
4422 }
4423
4424 TEST_F(ValidateImage, SampleImageToImageSuccess) {
4425 const std::string body = R"(
4426 %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
4427 %sampler = OpLoad %type_sampler %uniform_sampler
4428 %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
4429 %img2 = OpImage %type_image_f32_2d_0001 %simg
4430 )";
4431
4432 CompileSuccessfully(GenerateShaderCode(body).c_str());
4433 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
4434 }
4435
4436 TEST_F(ValidateImage, SampleImageToImageWrongResultType) {
4437 const std::string body = R"(
4438 %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
4439 %sampler = OpLoad %type_sampler %uniform_sampler
4440 %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
4441 %img2 = OpImage %type_sampled_image_f32_2d_0001 %simg
4442 )";
4443
4444 CompileSuccessfully(GenerateShaderCode(body).c_str());
4445 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
4446 EXPECT_THAT(getDiagnosticString(),
4447 HasSubstr("Expected Result Type to be OpTypeImage"));
4448 }
4449
4450 TEST_F(ValidateImage, SampleImageToImageNotSampledImage) {
4451 const std::string body = R"(
4452 %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
4453 %img2 = OpImage %type_image_f32_2d_0001 %img
4454 )";
4455
4456 CompileSuccessfully(GenerateShaderCode(body).c_str());
4457 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
4458 EXPECT_THAT(
4459 getDiagnosticString(),
4460 HasSubstr("Expected Sample Image to be of type OpTypeSampleImage"));
4461 }
4462
4463 TEST_F(ValidateImage, SampleImageToImageNotTheSameImageType) {
4464 const std::string body = R"(
4465 %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
4466 %sampler = OpLoad %type_sampler %uniform_sampler
4467 %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
4468 %img2 = OpImage %type_image_f32_2d_0002 %simg
4469 )";
4470
4471 CompileSuccessfully(GenerateShaderCode(body).c_str());
4472 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
4473 EXPECT_THAT(getDiagnosticString(),
4474 HasSubstr("Expected Sample Image image type to be equal to "
4475 "Result Type"));
4476 }
4477
4478 TEST_F(ValidateImage, QueryFormatSuccess) {
4479 const std::string body = R"(
4480 %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
4481 %res1 = OpImageQueryFormat %u32 %img
4482 )";
4483
4484 CompileSuccessfully(GenerateKernelCode(body).c_str());
4485 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
4486 }
4487
4488 TEST_F(ValidateImage, QueryFormatWrongResultType) {
4489 const std::string body = R"(
4490 %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
4491 %res1 = OpImageQueryFormat %bool %img
4492 )";
4493
4494 CompileSuccessfully(GenerateKernelCode(body).c_str());
4495 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
4496 EXPECT_THAT(getDiagnosticString(),
4497 HasSubstr("Expected Result Type to be int scalar type"));
4498 }
4499
4500 TEST_F(ValidateImage, QueryFormatNotImage) {
4501 const std::string body = R"(
4502 %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
4503 %sampler = OpLoad %type_sampler %uniform_sampler
4504 %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
4505 %res1 = OpImageQueryFormat %u32 %sampler
4506 )";
4507
4508 CompileSuccessfully(GenerateKernelCode(body).c_str());
4509 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
4510 EXPECT_THAT(getDiagnosticString(),
4511 HasSubstr("Expected operand to be of type OpTypeImage"));
4512 }
4513
4514 TEST_F(ValidateImage, QueryOrderSuccess) {
4515 const std::string body = R"(
4516 %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
4517 %res1 = OpImageQueryOrder %u32 %img
4518 )";
4519
4520 CompileSuccessfully(GenerateKernelCode(body).c_str());
4521 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
4522 }
4523
4524 TEST_F(ValidateImage, QueryOrderWrongResultType) {
4525 const std::string body = R"(
4526 %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
4527 %res1 = OpImageQueryOrder %bool %img
4528 )";
4529
4530 CompileSuccessfully(GenerateKernelCode(body).c_str());
4531 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
4532 EXPECT_THAT(getDiagnosticString(),
4533 HasSubstr("Expected Result Type to be int scalar type"));
4534 }
4535
4536 TEST_F(ValidateImage, QueryOrderNotImage) {
4537 const std::string body = R"(
4538 %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
4539 %sampler = OpLoad %type_sampler %uniform_sampler
4540 %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
4541 %res1 = OpImageQueryOrder %u32 %sampler
4542 )";
4543
4544 CompileSuccessfully(GenerateKernelCode(body).c_str());
4545 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
4546 EXPECT_THAT(getDiagnosticString(),
4547 HasSubstr("Expected operand to be of type OpTypeImage"));
4548 }
4549
4550 TEST_F(ValidateImage, QuerySizeLodSuccess) {
4551 const std::string body = R"(
4552 %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
4553 %res1 = OpImageQuerySizeLod %u32vec2 %img %u32_1
4554 )";
4555
4556 CompileSuccessfully(GenerateKernelCode(body).c_str());
4557 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
4558 }
4559
4560 TEST_F(ValidateImage, QuerySizeLodWrongResultType) {
4561 const std::string body = R"(
4562 %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
4563 %res1 = OpImageQuerySizeLod %f32vec2 %img %u32_1
4564 )";
4565
4566 CompileSuccessfully(GenerateKernelCode(body).c_str());
4567 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
4568 EXPECT_THAT(
4569 getDiagnosticString(),
4570 HasSubstr("Expected Result Type to be int scalar or vector type"));
4571 }
4572
4573 TEST_F(ValidateImage, QuerySizeLodResultTypeWrongSize) {
4574 const std::string body = R"(
4575 %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
4576 %res1 = OpImageQuerySizeLod %u32 %img %u32_1
4577 )";
4578
4579 CompileSuccessfully(GenerateKernelCode(body).c_str());
4580 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
4581 EXPECT_THAT(getDiagnosticString(),
4582 HasSubstr("Result Type has 1 components, but 2 expected"));
4583 }
4584
4585 TEST_F(ValidateImage, QuerySizeLodNotImage) {
4586 const std::string body = R"(
4587 %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
4588 %sampler = OpLoad %type_sampler %uniform_sampler
4589 %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
4590 %res1 = OpImageQuerySizeLod %u32vec2 %sampler %u32_1
4591 )";
4592
4593 CompileSuccessfully(GenerateKernelCode(body).c_str());
4594 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
4595 EXPECT_THAT(getDiagnosticString(),
4596 HasSubstr("Expected Image to be of type OpTypeImage"));
4597 }
4598
4599 TEST_F(ValidateImage, QuerySizeLodSampledImageDirectly) {
4600 const std::string body = R"(
4601 %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
4602 %sampler = OpLoad %type_sampler %uniform_sampler
4603 %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
4604 %res1 = OpImageQuerySizeLod %u32vec2 %simg %u32_1
4605 )";
4606
4607 CompileSuccessfully(GenerateShaderCode(body).c_str());
4608 ASSERT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions());
4609 EXPECT_THAT(getDiagnosticString(),
4610 HasSubstr("OpSampledImage instruction must not appear as operand "
4611 "for OpImageQuerySizeLod"));
4612 }
4613
4614 TEST_F(ValidateImage, QuerySizeLodMultisampledError) {
4615 const std::string body = R"(
4616 %img = OpLoad %type_image_f32_2d_0011 %uniform_image_f32_2d_0011
4617 %res1 = OpImageQuerySizeLod %u32vec2 %img %u32_1
4618 )";
4619
4620 CompileSuccessfully(GenerateKernelCode(body).c_str());
4621 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
4622 EXPECT_THAT(getDiagnosticString(), HasSubstr("Image 'MS' must be 0"));
4623 }
4624
4625 TEST_F(ValidateImage, QuerySizeLodNonSampledUniversalSuccess) {
4626 const std::string body = R"(
4627 %img = OpLoad %type_image_f32_2d_0002 %uniform_image_f32_2d_0002
4628 %res1 = OpImageQuerySizeLod %u32vec2 %img %u32_1
4629 )";
4630
4631 CompileSuccessfully(GenerateShaderCode(body).c_str());
4632 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
4633 EXPECT_EQ(getDiagnosticString(), "");
4634 }
4635
4636 TEST_F(ValidateImage, QuerySizeLodVulkanNonSampledError) {
4637 // Create a whole shader module. Avoid Vulkan incompatibility with
4638 // SampledRrect images inserted by helper function GenerateShaderCode.
4639 const std::string body = R"(
4640 OpCapability Shader
4641 OpCapability ImageQuery
4642 OpMemoryModel Logical Simple
4643 OpEntryPoint Fragment %main "main"
4644 OpExecutionMode %main OriginUpperLeft
4645
4646 %f32 = OpTypeFloat 32
4647 %u32 = OpTypeInt 32 0
4648 %u32_0 = OpConstant %u32 0
4649 %u32vec2 = OpTypeVector %u32 2
4650 %void = OpTypeVoid
4651 %voidfn = OpTypeFunction %void
4652
4653 ; Test with a storage image.
4654 %type_image_f32_2d_0002 = OpTypeImage %f32 2D 0 0 0 2 Rgba32f
4655 %ptr_image_f32_2d_0002 = OpTypePointer UniformConstant %type_image_f32_2d_0002
4656 %uniform_image_f32_2d_0002 = OpVariable %ptr_image_f32_2d_0002 UniformConstant
4657
4658 %main = OpFunction %void None %voidfn
4659 %entry = OpLabel
4660 %img = OpLoad %type_image_f32_2d_0002 %uniform_image_f32_2d_0002
4661 %res1 = OpImageQuerySizeLod %u32vec2 %img %u32_0
4662 OpReturn
4663 OpFunctionEnd
4664 )";
4665
4666 CompileSuccessfully(body.c_str());
4667 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions(SPV_ENV_VULKAN_1_0));
4668 EXPECT_THAT(getDiagnosticString(),
4669 AnyVUID("VUID-StandaloneSpirv-OpImageQuerySizeLod-04659"));
4670 EXPECT_THAT(
4671 getDiagnosticString(),
4672 HasSubstr(
4673 "OpImageQuerySizeLod must only consume an \"Image\" operand whose "
4674 "type has its \"Sampled\" operand set to 1"));
4675 }
4676
4677 TEST_F(ValidateImage, QuerySizeLodWrongImageDim) {
4678 const std::string body = R"(
4679 %img = OpLoad %type_image_f32_rect_0001 %uniform_image_f32_rect_0001
4680 %res1 = OpImageQuerySizeLod %u32vec2 %img %u32_1
4681 )";
4682
4683 CompileSuccessfully(GenerateKernelCode(body).c_str());
4684 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
4685 EXPECT_THAT(getDiagnosticString(),
4686 HasSubstr("Image 'Dim' must be 1D, 2D, 3D or Cube"));
4687 }
4688
4689 TEST_F(ValidateImage, QuerySizeLodWrongLodType) {
4690 const std::string body = R"(
4691 %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
4692 %res1 = OpImageQuerySizeLod %u32vec2 %img %f32_0
4693 )";
4694
4695 CompileSuccessfully(GenerateKernelCode(body).c_str());
4696 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
4697 EXPECT_THAT(getDiagnosticString(),
4698 HasSubstr("Expected Level of Detail to be a 32-bit int scalar"));
4699 }
4700
4701 TEST_F(ValidateImage, QuerySizeLodWrong16Bit) {
4702 const std::string body = R"(
4703 %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
4704 %res1 = OpImageQuerySizeLod %u32vec2 %img %u16_0
4705 )";
4706
4707 CompileSuccessfully(GenerateKernelCode(body).c_str());
4708 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
4709 EXPECT_THAT(getDiagnosticString(),
4710 HasSubstr("Expected Level of Detail to be a 32-bit int scalar"));
4711 }
4712
4713 TEST_F(ValidateImage, QuerySizeSuccess) {
4714 const std::string body = R"(
4715 %img = OpLoad %type_image_f32_2d_0011 %uniform_image_f32_2d_0011
4716 %res1 = OpImageQuerySize %u32vec2 %img
4717 )";
4718
4719 CompileSuccessfully(GenerateKernelCode(body).c_str());
4720 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
4721 }
4722
4723 TEST_F(ValidateImage, QuerySizeWrongResultType) {
4724 const std::string body = R"(
4725 %img = OpLoad %type_image_f32_2d_0011 %uniform_image_f32_2d_0011
4726 %res1 = OpImageQuerySize %f32vec2 %img
4727 )";
4728
4729 CompileSuccessfully(GenerateKernelCode(body).c_str());
4730 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
4731 EXPECT_THAT(
4732 getDiagnosticString(),
4733 HasSubstr("Expected Result Type to be int scalar or vector type"));
4734 }
4735
4736 TEST_F(ValidateImage, QuerySizeNotImage) {
4737 const std::string body = R"(
4738 %img = OpLoad %type_image_f32_2d_0011 %uniform_image_f32_2d_0011
4739 %sampler = OpLoad %type_sampler %uniform_sampler
4740 %simg = OpSampledImage %type_sampled_image_f32_2d_0011 %img %sampler
4741 %res1 = OpImageQuerySize %u32vec2 %sampler
4742 )";
4743
4744 CompileSuccessfully(GenerateKernelCode(body).c_str());
4745 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
4746 EXPECT_THAT(getDiagnosticString(),
4747 HasSubstr("Expected Image to be of type OpTypeImage"));
4748 }
4749
4750 TEST_F(ValidateImage, QuerySizeSampledImageDirectly) {
4751 const std::string body = R"(
4752 %img = OpLoad %type_image_f32_2d_0011 %uniform_image_f32_2d_0011
4753 %sampler = OpLoad %type_sampler %uniform_sampler
4754 %simg = OpSampledImage %type_sampled_image_f32_2d_0011 %img %sampler
4755 %res1 = OpImageQuerySize %u32vec2 %simg
4756 )";
4757
4758 CompileSuccessfully(GenerateShaderCode(body).c_str());
4759 ASSERT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions());
4760 EXPECT_THAT(getDiagnosticString(),
4761 HasSubstr("OpSampledImage instruction must not appear as operand "
4762 "for OpImageQuerySize"));
4763 }
4764
4765 TEST_F(ValidateImage, QuerySizeDimSubpassDataBad) {
4766 const std::string body = R"(
4767 %img = OpLoad %type_image_f32_spd_0002 %uniform_image_f32_spd_0002
4768 %res1 = OpImageQuerySize %u32vec2 %img
4769 )";
4770
4771 CompileSuccessfully(GenerateShaderCode(body).c_str());
4772 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
4773 EXPECT_THAT(
4774 getDiagnosticString(),
4775 HasSubstr("Image 'Dim' must be 1D, Buffer, 2D, Cube, 3D or Rect"));
4776 }
4777
4778 TEST_F(ValidateImage, QuerySizeWrongSampling) {
4779 const std::string body = R"(
4780 %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
4781 %res1 = OpImageQuerySize %u32vec2 %img
4782 )";
4783
4784 CompileSuccessfully(GenerateKernelCode(body).c_str());
4785 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
4786 EXPECT_THAT(
4787 getDiagnosticString(),
4788 HasSubstr("Image must have either 'MS'=1 or 'Sampled'=0 or 'Sampled'=2"));
4789 }
4790
4791 TEST_F(ValidateImage, QuerySizeWrongNumberOfComponents) {
4792 const std::string body = R"(
4793 %img = OpLoad %type_image_f32_3d_0111 %uniform_image_f32_3d_0111
4794 %res1 = OpImageQuerySize %u32vec2 %img
4795 )";
4796
4797 CompileSuccessfully(GenerateShaderCode(body).c_str());
4798 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
4799 EXPECT_THAT(getDiagnosticString(),
4800 HasSubstr("Result Type has 2 components, but 4 expected"));
4801 }
4802
4803 TEST_F(ValidateImage, QueryLodSuccessKernel) {
4804 const std::string body = R"(
4805 %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
4806 %sampler = OpLoad %type_sampler %uniform_sampler
4807 %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
4808 %res1 = OpImageQueryLod %f32vec2 %simg %f32vec2_hh
4809 %res2 = OpImageQueryLod %f32vec2 %simg %u32vec2_01
4810 )";
4811
4812 CompileSuccessfully(GenerateKernelCode(body).c_str());
4813 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
4814 }
4815
4816 TEST_F(ValidateImage, QueryLodSuccessShader) {
4817 const std::string body = R"(
4818 %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
4819 %sampler = OpLoad %type_sampler %uniform_sampler
4820 %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
4821 %res1 = OpImageQueryLod %f32vec2 %simg %f32vec2_hh
4822 )";
4823
4824 CompileSuccessfully(GenerateShaderCode(body).c_str());
4825 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
4826 }
4827
4828 TEST_F(ValidateImage, QueryLodWrongResultType) {
4829 const std::string body = R"(
4830 %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
4831 %sampler = OpLoad %type_sampler %uniform_sampler
4832 %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
4833 %res1 = OpImageQueryLod %u32vec2 %simg %f32vec2_hh
4834 )";
4835
4836 CompileSuccessfully(GenerateKernelCode(body).c_str());
4837 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
4838 EXPECT_THAT(getDiagnosticString(),
4839 HasSubstr("Expected Result Type to be float vector type"));
4840 }
4841
4842 TEST_F(ValidateImage, QueryLodResultTypeWrongSize) {
4843 const std::string body = R"(
4844 %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
4845 %sampler = OpLoad %type_sampler %uniform_sampler
4846 %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
4847 %res1 = OpImageQueryLod %f32vec3 %simg %f32vec2_hh
4848 )";
4849
4850 CompileSuccessfully(GenerateKernelCode(body).c_str());
4851 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
4852 EXPECT_THAT(getDiagnosticString(),
4853 HasSubstr("Expected Result Type to have 2 components"));
4854 }
4855
4856 TEST_F(ValidateImage, QueryLodNotSampledImage) {
4857 const std::string body = R"(
4858 %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
4859 %res1 = OpImageQueryLod %f32vec2 %img %f32vec2_hh
4860 )";
4861
4862 CompileSuccessfully(GenerateKernelCode(body).c_str());
4863 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
4864 EXPECT_THAT(
4865 getDiagnosticString(),
4866 HasSubstr("Expected Image operand to be of type OpTypeSampledImage"));
4867 }
4868
4869 TEST_F(ValidateImage, QueryLodWrongDim) {
4870 const std::string body = R"(
4871 %img = OpLoad %type_image_f32_rect_0001 %uniform_image_f32_rect_0001
4872 %sampler = OpLoad %type_sampler %uniform_sampler
4873 %simg = OpSampledImage %type_sampled_image_f32_rect_0001 %img %sampler
4874 %res1 = OpImageQueryLod %f32vec2 %simg %f32vec2_hh
4875 )";
4876
4877 CompileSuccessfully(GenerateKernelCode(body).c_str());
4878 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
4879 EXPECT_THAT(getDiagnosticString(),
4880 HasSubstr("Image 'Dim' must be 1D, 2D, 3D or Cube"));
4881 }
4882
4883 TEST_F(ValidateImage, QueryLodWrongCoordinateType) {
4884 const std::string body = R"(
4885 %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
4886 %sampler = OpLoad %type_sampler %uniform_sampler
4887 %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
4888 %res1 = OpImageQueryLod %f32vec2 %simg %u32vec2_01
4889 )";
4890
4891 CompileSuccessfully(GenerateShaderCode(body).c_str());
4892 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
4893 EXPECT_THAT(
4894 getDiagnosticString(),
4895 HasSubstr("Expected Coordinate to be a 32-bit float scalar or vector"));
4896 }
4897
4898 TEST_F(ValidateImage, QueryLodCoordinateSizeTooSmall) {
4899 const std::string body = R"(
4900 %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
4901 %sampler = OpLoad %type_sampler %uniform_sampler
4902 %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
4903 %res1 = OpImageQueryLod %f32vec2 %simg %f32_0
4904 )";
4905
4906 CompileSuccessfully(GenerateShaderCode(body).c_str());
4907 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
4908 EXPECT_THAT(getDiagnosticString(),
4909 HasSubstr("Expected Coordinate to have at least 2 components, "
4910 "but given only 1"));
4911 }
4912
4913 TEST_F(ValidateImage, QueryLevelsSuccess) {
4914 const std::string body = R"(
4915 %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
4916 %res1 = OpImageQueryLevels %u32 %img
4917 )";
4918
4919 CompileSuccessfully(GenerateKernelCode(body).c_str());
4920 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
4921 }
4922
4923 TEST_F(ValidateImage, QueryLevelsWrongResultType) {
4924 const std::string body = R"(
4925 %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
4926 %res1 = OpImageQueryLevels %f32 %img
4927 )";
4928
4929 CompileSuccessfully(GenerateKernelCode(body).c_str());
4930 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
4931 EXPECT_THAT(getDiagnosticString(),
4932 HasSubstr("Expected Result Type to be int scalar type"));
4933 }
4934
4935 TEST_F(ValidateImage, QueryLevelsNotImage) {
4936 const std::string body = R"(
4937 %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
4938 %sampler = OpLoad %type_sampler %uniform_sampler
4939 %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
4940 %res1 = OpImageQueryLevels %u32 %sampler
4941 )";
4942
4943 CompileSuccessfully(GenerateKernelCode(body).c_str());
4944 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
4945 EXPECT_THAT(getDiagnosticString(),
4946 HasSubstr("Expected Image to be of type OpTypeImage"));
4947 }
4948
4949 TEST_F(ValidateImage, QueryLevelsSampledImageDirectly) {
4950 const std::string body = R"(
4951 %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
4952 %sampler = OpLoad %type_sampler %uniform_sampler
4953 %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
4954 %res1 = OpImageQueryLevels %u32 %simg
4955 )";
4956
4957 CompileSuccessfully(GenerateShaderCode(body).c_str());
4958 ASSERT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions());
4959 EXPECT_THAT(getDiagnosticString(),
4960 HasSubstr("OpSampledImage instruction must not appear as operand "
4961 "for OpImageQueryLevels"));
4962 }
4963
4964 TEST_F(ValidateImage, QueryLevelsWrongDim) {
4965 const std::string body = R"(
4966 %img = OpLoad %type_image_f32_rect_0001 %uniform_image_f32_rect_0001
4967 %res1 = OpImageQueryLevels %u32 %img
4968 )";
4969
4970 CompileSuccessfully(GenerateKernelCode(body).c_str());
4971 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
4972 EXPECT_THAT(getDiagnosticString(),
4973 HasSubstr("Image 'Dim' must be 1D, 2D, 3D or Cube"));
4974 }
4975
4976 TEST_F(ValidateImage, QuerySizeLevelsNonSampledUniversalSuccess) {
4977 const std::string body = R"(
4978 %img = OpLoad %type_image_f32_2d_0002 %uniform_image_f32_2d_0002
4979 %res1 = OpImageQueryLevels %u32 %img
4980 )";
4981
4982 CompileSuccessfully(GenerateShaderCode(body).c_str());
4983 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
4984 EXPECT_EQ(getDiagnosticString(), "");
4985 }
4986
4987 TEST_F(ValidateImage, QuerySizeLevelsVulkanNonSampledError) {
4988 // Create a whole shader module. Avoid Vulkan incompatibility with
4989 // SampledRrect images inserted by helper function GenerateShaderCode.
4990 const std::string body = R"(
4991 OpCapability Shader
4992 OpCapability ImageQuery
4993 OpMemoryModel Logical Simple
4994 OpEntryPoint Fragment %main "main"
4995 OpExecutionMode %main OriginUpperLeft
4996
4997 %f32 = OpTypeFloat 32
4998 %u32 = OpTypeInt 32 0
4999 %void = OpTypeVoid
5000 %voidfn = OpTypeFunction %void
5001
5002 ; Test with a storage image.
5003 %type_image_f32_2d_0002 = OpTypeImage %f32 2D 0 0 0 2 Rgba32f
5004 %ptr_image_f32_2d_0002 = OpTypePointer UniformConstant %type_image_f32_2d_0002
5005 %uniform_image_f32_2d_0002 = OpVariable %ptr_image_f32_2d_0002 UniformConstant
5006
5007 %main = OpFunction %void None %voidfn
5008 %entry = OpLabel
5009 %img = OpLoad %type_image_f32_2d_0002 %uniform_image_f32_2d_0002
5010 %res1 = OpImageQueryLevels %u32 %img
5011 OpReturn
5012 OpFunctionEnd
5013 )";
5014
5015 CompileSuccessfully(body.c_str());
5016 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions(SPV_ENV_VULKAN_1_0));
5017 EXPECT_THAT(getDiagnosticString(),
5018 AnyVUID("VUID-StandaloneSpirv-OpImageQuerySizeLod-04659"));
5019 EXPECT_THAT(
5020 getDiagnosticString(),
5021 HasSubstr("OpImageQueryLevels must only consume an \"Image\" operand "
5022 "whose type has its \"Sampled\" operand set to 1"));
5023 }
5024
5025 TEST_F(ValidateImage, QuerySamplesSuccess) {
5026 const std::string body = R"(
5027 %img = OpLoad %type_image_f32_2d_0011 %uniform_image_f32_2d_0011
5028 %res1 = OpImageQuerySamples %u32 %img
5029 )";
5030
5031 CompileSuccessfully(GenerateKernelCode(body).c_str());
5032 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
5033 }
5034
5035 TEST_F(ValidateImage, QuerySamplesNot2D) {
5036 const std::string body = R"(
5037 %img = OpLoad %type_image_f32_3d_0011 %uniform_image_f32_3d_0011
5038 %res1 = OpImageQuerySamples %u32 %img
5039 )";
5040
5041 CompileSuccessfully(GenerateKernelCode(body).c_str());
5042 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
5043 EXPECT_THAT(getDiagnosticString(), HasSubstr("Image 'Dim' must be 2D"));
5044 }
5045
5046 TEST_F(ValidateImage, QuerySamplesNotMultisampled) {
5047 const std::string body = R"(
5048 %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
5049 %res1 = OpImageQuerySamples %u32 %img
5050 )";
5051
5052 CompileSuccessfully(GenerateKernelCode(body).c_str());
5053 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
5054 EXPECT_THAT(getDiagnosticString(), HasSubstr("Image 'MS' must be 1"));
5055 }
5056
5057 TEST_F(ValidateImage, QueryLodWrongExecutionModel) {
5058 const std::string body = R"(
5059 %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
5060 %sampler = OpLoad %type_sampler %uniform_sampler
5061 %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
5062 %res1 = OpImageQueryLod %f32vec2 %simg %f32vec2_hh
5063 )";
5064
5065 CompileSuccessfully(GenerateShaderCode(body, "", "Vertex").c_str());
5066 ASSERT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions());
5067 EXPECT_THAT(
5068 getDiagnosticString(),
5069 HasSubstr(
5070 "OpImageQueryLod requires Fragment, GLCompute, MeshEXT or TaskEXT "
5071 "execution model"));
5072 }
5073
5074 TEST_F(ValidateImage, QueryLodWrongExecutionModelWithFunc) {
5075 const std::string body = R"(
5076 %call_ret = OpFunctionCall %void %my_func
5077 OpReturn
5078 OpFunctionEnd
5079 %my_func = OpFunction %void None %func
5080 %my_func_entry = OpLabel
5081 %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
5082 %sampler = OpLoad %type_sampler %uniform_sampler
5083 %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
5084 %res1 = OpImageQueryLod %f32vec2 %simg %f32vec2_hh
5085 )";
5086
5087 CompileSuccessfully(GenerateShaderCode(body, "", "Vertex").c_str());
5088 ASSERT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions());
5089 EXPECT_THAT(
5090 getDiagnosticString(),
5091 HasSubstr(
5092 "OpImageQueryLod requires Fragment, GLCompute, MeshEXT or TaskEXT "
5093 "execution model"));
5094 }
5095
5096 TEST_F(ValidateImage, QueryLodComputeShaderDerivatives) {
5097 const std::string body = R"(
5098 %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
5099 %sampler = OpLoad %type_sampler %uniform_sampler
5100 %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
5101 %res1 = OpImageQueryLod %f32vec2 %simg %f32vec2_hh
5102 )";
5103
5104 const std::string extra = R"(
5105 OpCapability ComputeDerivativeGroupLinearKHR
5106 OpExtension "SPV_KHR_compute_shader_derivatives"
5107 )";
5108 const std::string mode = R"(
5109 OpExecutionMode %main LocalSize 8 8 1
5110 OpExecutionMode %main DerivativeGroupLinearKHR
5111 )";
5112 CompileSuccessfully(
5113 GenerateShaderCode(body, extra, "GLCompute", mode).c_str());
5114 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
5115 }
5116
5117 TEST_F(ValidateImage, QueryLodUniversalSuccess) {
5118 // Create a whole shader module. Avoid Vulkan incompatibility with
5119 // SampledRrect images inserted by helper function GenerateShaderCode.
5120 const std::string body = R"(
5121 OpCapability Shader
5122 OpCapability ImageQuery
5123 OpMemoryModel Logical Simple
5124 OpEntryPoint Fragment %main "main"
5125 OpExecutionMode %main OriginUpperLeft
5126
5127 OpDecorate %uniform_image_f32_2d_0000 DescriptorSet 0
5128 OpDecorate %uniform_image_f32_2d_0000 Binding 0
5129 OpDecorate %sampler DescriptorSet 0
5130 OpDecorate %sampler Binding 1
5131
5132 %f32 = OpTypeFloat 32
5133 %f32vec2 = OpTypeVector %f32 2
5134 %f32vec2_null = OpConstantNull %f32vec2
5135 %u32 = OpTypeInt 32 0
5136 %u32vec2 = OpTypeVector %u32 2
5137 %void = OpTypeVoid
5138 %voidfn = OpTypeFunction %void
5139
5140 ; Test with an image with sampled = 0
5141 %type_image_f32_2d_0000 = OpTypeImage %f32 2D 0 0 0 0 Rgba32f
5142 %ptr_image_f32_2d_0000 = OpTypePointer UniformConstant %type_image_f32_2d_0000
5143 %uniform_image_f32_2d_0000 = OpVariable %ptr_image_f32_2d_0000 UniformConstant
5144 %sampled_image_ty = OpTypeSampledImage %type_image_f32_2d_0000
5145
5146 %sampler_ty = OpTypeSampler
5147 %ptr_sampler_ty = OpTypePointer UniformConstant %sampler_ty
5148 %sampler = OpVariable %ptr_sampler_ty UniformConstant
5149
5150
5151 %main = OpFunction %void None %voidfn
5152 %entry = OpLabel
5153 %img = OpLoad %type_image_f32_2d_0000 %uniform_image_f32_2d_0000
5154 %s = OpLoad %sampler_ty %sampler
5155 %simg = OpSampledImage %sampled_image_ty %img %s
5156 %res1 = OpImageQueryLod %f32vec2 %simg %f32vec2_null
5157 OpReturn
5158 OpFunctionEnd
5159 )";
5160
5161 CompileSuccessfully(body.c_str());
5162 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
5163 }
5164
5165 TEST_F(ValidateImage, QueryLodVulkanNonSampledError) {
5166 // Create a whole shader module. Avoid Vulkan incompatibility with
5167 // SampledRrect images inserted by helper function GenerateShaderCode.
5168 const std::string body = R"(
5169 OpCapability Shader
5170 OpCapability ImageQuery
5171 OpMemoryModel Logical Simple
5172 OpEntryPoint Fragment %main "main"
5173 OpExecutionMode %main OriginUpperLeft
5174
5175 OpDecorate %sampled_image DescriptorSet 0
5176 OpDecorate %sampled_image Binding 0
5177
5178 %f32 = OpTypeFloat 32
5179 %f32vec2 = OpTypeVector %f32 2
5180 %f32vec2_null = OpConstantNull %f32vec2
5181 %u32 = OpTypeInt 32 0
5182 %u32vec2 = OpTypeVector %u32 2
5183 %void = OpTypeVoid
5184 %voidfn = OpTypeFunction %void
5185
5186 ; Test with an image with Sampled = 2
5187 ; In Vulkan it Sampled must be 1 or 2, checked in another part of the
5188 ; validation flow.
5189 %type_image_f32_2d_0002 = OpTypeImage %f32 2D 0 0 0 2 Rgba32f
5190
5191 ; Expect to fail here.
5192 %sampled_image_ty = OpTypeSampledImage %type_image_f32_2d_0002
5193 %ptr_sampled_image_ty = OpTypePointer UniformConstant %sampled_image_ty
5194 %sampled_image = OpVariable %ptr_sampled_image_ty UniformConstant
5195
5196 %main = OpFunction %void None %voidfn
5197 %entry = OpLabel
5198 %simg = OpLoad %sampled_image_ty %sampled_image
5199 %res1 = OpImageQueryLod %f32vec2 %simg %f32vec2_null
5200 OpReturn
5201 OpFunctionEnd
5202 )";
5203
5204 CompileSuccessfully(body.c_str());
5205 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions(SPV_ENV_VULKAN_1_0));
5206 EXPECT_THAT(getDiagnosticString(),
5207 AnyVUID("VUID-StandaloneSpirv-OpTypeImage-04657"));
5208 EXPECT_THAT(getDiagnosticString(),
5209 HasSubstr("Sampled image type requires an image type with "
5210 "\"Sampled\" operand set to 0 or 1"));
5211 }
5212
5213 TEST_F(ValidateImage, QueryLodComputeShaderDerivativesMissingMode) {
5214 const std::string body = R"(
5215 %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
5216 %sampler = OpLoad %type_sampler %uniform_sampler
5217 %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
5218 %res1 = OpImageQueryLod %f32vec2 %simg %f32vec2_hh
5219 )";
5220
5221 const std::string extra = R"(
5222 OpCapability ComputeDerivativeGroupLinearKHR
5223 OpExtension "SPV_KHR_compute_shader_derivatives"
5224 )";
5225 const std::string mode = R"(
5226 OpExecutionMode %main LocalSize 8 8 1
5227 )";
5228 CompileSuccessfully(
5229 GenerateShaderCode(body, extra, "GLCompute", mode).c_str());
5230 ASSERT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions());
5231 EXPECT_THAT(getDiagnosticString(),
5232 HasSubstr("OpImageQueryLod requires DerivativeGroupQuadsKHR or "
5233 "DerivativeGroupLinearKHR execution mode for "
5234 "GLCompute, MeshEXT or TaskEXT execution model"));
5235 }
5236
5237 TEST_F(ValidateImage, ImplicitLodWrongExecutionModel) {
5238 const std::string body = R"(
5239 %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
5240 %sampler = OpLoad %type_sampler %uniform_sampler
5241 %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
5242 %res1 = OpImageSampleImplicitLod %f32vec4 %simg %f32vec2_hh
5243 )";
5244
5245 CompileSuccessfully(GenerateShaderCode(body, "", "Vertex").c_str());
5246 ASSERT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions());
5247 EXPECT_THAT(getDiagnosticString(),
5248 HasSubstr("ImplicitLod instructions require Fragment, "
5249 "GLCompute, MeshEXT or TaskEXT execution model"));
5250 }
5251
5252 TEST_F(ValidateImage, ImplicitLodComputeShaderDerivatives) {
5253 const std::string body = R"(
5254 %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
5255 %sampler = OpLoad %type_sampler %uniform_sampler
5256 %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
5257 %res1 = OpImageSampleImplicitLod %f32vec4 %simg %f32vec2_hh
5258 )";
5259
5260 const std::string extra = R"(
5261 OpCapability ComputeDerivativeGroupLinearKHR
5262 OpExtension "SPV_KHR_compute_shader_derivatives"
5263 )";
5264 const std::string mode = R"(
5265 OpExecutionMode %main LocalSize 8 8 1
5266 OpExecutionMode %main DerivativeGroupLinearKHR
5267 )";
5268 CompileSuccessfully(
5269 GenerateShaderCode(body, extra, "GLCompute", mode).c_str());
5270 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
5271 }
5272
5273 TEST_F(ValidateImage, ImplicitLodComputeShaderDerivativesMissingMode) {
5274 const std::string body = R"(
5275 %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
5276 %sampler = OpLoad %type_sampler %uniform_sampler
5277 %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
5278 %res1 = OpImageSampleImplicitLod %f32vec4 %simg %f32vec2_hh
5279 )";
5280
5281 const std::string extra = R"(
5282 OpCapability ComputeDerivativeGroupLinearKHR
5283 OpExtension "SPV_KHR_compute_shader_derivatives"
5284 )";
5285 const std::string mode = R"(
5286 OpExecutionMode %main LocalSize 8 8 1
5287 )";
5288 CompileSuccessfully(
5289 GenerateShaderCode(body, extra, "GLCompute", mode).c_str());
5290 ASSERT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions());
5291 EXPECT_THAT(
5292 getDiagnosticString(),
5293 HasSubstr("ImplicitLod instructions require DerivativeGroupQuadsKHR or "
5294 "DerivativeGroupLinearKHR execution mode for GLCompute, "
5295 "MeshEXT or TaskEXT execution model"));
5296 }
5297
5298 TEST_F(ValidateImage, ReadSubpassDataWrongExecutionModel) {
5299 const std::string body = R"(
5300 %img = OpLoad %type_image_f32_spd_0002 %uniform_image_f32_spd_0002
5301 %res1 = OpImageRead %f32vec4 %img %u32vec2_01
5302 )";
5303
5304 const std::string extra = "\nOpCapability StorageImageReadWithoutFormat\n";
5305 CompileSuccessfully(GenerateShaderCode(body, extra, "Vertex").c_str());
5306 ASSERT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions());
5307 EXPECT_THAT(getDiagnosticString(),
5308 HasSubstr("Dim SubpassData requires Fragment execution model"));
5309 }
5310
5311 TEST_F(ValidateImage, SparseSampleImplicitLodSuccess) {
5312 const std::string body = R"(
5313 %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
5314 %sampler = OpLoad %type_sampler %uniform_sampler
5315 %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
5316 %res1 = OpImageSparseSampleImplicitLod %struct_u32_f32vec4 %simg %f32vec2_hh
5317 %res2 = OpImageSparseSampleImplicitLod %struct_u32_f32vec4 %simg %f32vec2_hh Bias %f32_0_25
5318 %res4 = OpImageSparseSampleImplicitLod %struct_u32_f32vec4 %simg %f32vec2_hh ConstOffset %s32vec2_01
5319 %res5 = OpImageSparseSampleImplicitLod %struct_u32_f32vec4 %simg %f32vec2_hh Offset %s32vec2_01
5320 %res6 = OpImageSparseSampleImplicitLod %struct_u32_f32vec4 %simg %f32vec2_hh MinLod %f32_0_5
5321 %res7 = OpImageSparseSampleImplicitLod %struct_u64_f32vec4 %simg %f32vec2_hh Bias|Offset|MinLod %f32_0_25 %s32vec2_01 %f32_0_5
5322 %res8 = OpImageSparseSampleImplicitLod %struct_u32_f32vec4 %simg %f32vec2_hh NonPrivateTexelKHR
5323 )";
5324
5325 const std::string extra = R"(
5326 OpCapability VulkanMemoryModelKHR
5327 OpExtension "SPV_KHR_vulkan_memory_model"
5328 )";
5329 CompileSuccessfully(GenerateShaderCode(body, extra, "Fragment", "",
5330 SPV_ENV_UNIVERSAL_1_3, "VulkanKHR")
5331 .c_str(),
5332 SPV_ENV_UNIVERSAL_1_3);
5333 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_UNIVERSAL_1_3));
5334 }
5335
5336 TEST_F(ValidateImage, SparseSampleImplicitLodResultTypeNotStruct) {
5337 const std::string body = R"(
5338 %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
5339 %sampler = OpLoad %type_sampler %uniform_sampler
5340 %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
5341 %res1 = OpImageSparseSampleImplicitLod %f32 %simg %f32vec2_hh
5342 )";
5343
5344 CompileSuccessfully(GenerateShaderCode(body).c_str());
5345 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
5346 EXPECT_THAT(getDiagnosticString(),
5347 HasSubstr("Expected Result Type to be OpTypeStruct"));
5348 }
5349
5350 TEST_F(ValidateImage, SparseSampleImplicitLodResultTypeNotTwoMembers1) {
5351 const std::string body = R"(
5352 %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
5353 %sampler = OpLoad %type_sampler %uniform_sampler
5354 %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
5355 %res1 = OpImageSparseSampleImplicitLod %struct_u32 %simg %f32vec2_hh
5356 )";
5357
5358 CompileSuccessfully(GenerateShaderCode(body).c_str());
5359 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
5360 EXPECT_THAT(getDiagnosticString(),
5361 HasSubstr("Expected Result Type to be a struct containing an int "
5362 "scalar and a texel"));
5363 }
5364
5365 TEST_F(ValidateImage, SparseSampleImplicitLodResultTypeNotTwoMembers2) {
5366 const std::string body = R"(
5367 %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
5368 %sampler = OpLoad %type_sampler %uniform_sampler
5369 %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
5370 %res1 = OpImageSparseSampleImplicitLod %struct_u32_f32vec4_u32 %simg %f32vec2_hh
5371 )";
5372
5373 CompileSuccessfully(GenerateShaderCode(body).c_str());
5374 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
5375 EXPECT_THAT(getDiagnosticString(),
5376 HasSubstr("Expected Result Type to be a struct containing an "
5377 "int scalar and a texel"));
5378 }
5379
5380 TEST_F(ValidateImage, SparseSampleImplicitLodResultTypeFirstMemberNotInt) {
5381 const std::string body = R"(
5382 %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
5383 %sampler = OpLoad %type_sampler %uniform_sampler
5384 %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
5385 %res1 = OpImageSparseSampleImplicitLod %struct_f32_f32vec4 %simg %f32vec2_hh
5386 )";
5387
5388 CompileSuccessfully(GenerateShaderCode(body).c_str());
5389 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
5390 EXPECT_THAT(getDiagnosticString(),
5391 HasSubstr("Expected Result Type to be a struct containing an "
5392 "int scalar and a texel"));
5393 }
5394
5395 TEST_F(ValidateImage, SparseSampleImplicitLodResultTypeTexelNotVector) {
5396 const std::string body = R"(
5397 %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
5398 %sampler = OpLoad %type_sampler %uniform_sampler
5399 %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
5400 %res1 = OpImageSparseSampleImplicitLod %struct_u32_u32 %simg %f32vec2_hh
5401 )";
5402
5403 CompileSuccessfully(GenerateShaderCode(body).c_str());
5404 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
5405 EXPECT_THAT(getDiagnosticString(),
5406 HasSubstr("Expected Result Type's second member to be int or "
5407 "float vector type"));
5408 }
5409
5410 TEST_F(ValidateImage, SparseSampleImplicitLodWrongNumComponentsTexel) {
5411 const std::string body = R"(
5412 %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
5413 %sampler = OpLoad %type_sampler %uniform_sampler
5414 %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
5415 %res1 = OpImageSparseSampleImplicitLod %struct_u32_f32vec3 %simg %f32vec2_hh
5416 )";
5417
5418 CompileSuccessfully(GenerateShaderCode(body).c_str());
5419 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
5420 EXPECT_THAT(getDiagnosticString(),
5421 HasSubstr("Expected Result Type's second member to have 4 "
5422 "components"));
5423 }
5424
5425 TEST_F(ValidateImage, SparseSampleImplicitLodWrongComponentTypeTexel) {
5426 const std::string body = R"(
5427 %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
5428 %sampler = OpLoad %type_sampler %uniform_sampler
5429 %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
5430 %res1 = OpImageSparseSampleImplicitLod %struct_u32_u32vec4 %simg %f32vec2_hh
5431 )";
5432
5433 CompileSuccessfully(GenerateShaderCode(body).c_str());
5434 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
5435 EXPECT_THAT(getDiagnosticString(),
5436 HasSubstr("Expected Image 'Sampled Type' to be the same as "
5437 "Result Type's second member components"));
5438 }
5439
5440 TEST_F(ValidateImage, SparseSampleDrefImplicitLodSuccess) {
5441 const std::string body = R"(
5442 %img = OpLoad %type_image_u32_2d_0001 %uniform_image_u32_2d_0001
5443 %sampler = OpLoad %type_sampler %uniform_sampler
5444 %simg = OpSampledImage %type_sampled_image_u32_2d_0001 %img %sampler
5445 %res1 = OpImageSparseSampleDrefImplicitLod %struct_u32_u32 %simg %f32vec2_hh %f32_1
5446 %res2 = OpImageSparseSampleDrefImplicitLod %struct_u32_u32 %simg %f32vec2_hh %f32_1 Bias %f32_0_25
5447 %res4 = OpImageSparseSampleDrefImplicitLod %struct_u32_u32 %simg %f32vec2_hh %f32_1 ConstOffset %s32vec2_01
5448 %res5 = OpImageSparseSampleDrefImplicitLod %struct_u32_u32 %simg %f32vec2_hh %f32_1 Offset %s32vec2_01
5449 %res6 = OpImageSparseSampleDrefImplicitLod %struct_u32_u32 %simg %f32vec2_hh %f32_1 MinLod %f32_0_5
5450 %res7 = OpImageSparseSampleDrefImplicitLod %struct_u32_u32 %simg %f32vec2_hh %f32_1 Bias|Offset|MinLod %f32_0_25 %s32vec2_01 %f32_0_5
5451 %res8 = OpImageSparseSampleDrefImplicitLod %struct_u32_u32 %simg %f32vec2_hh %f32_1 NonPrivateTexelKHR
5452 )";
5453
5454 const std::string extra = R"(
5455 OpCapability VulkanMemoryModelKHR
5456 OpExtension "SPV_KHR_vulkan_memory_model"
5457 )";
5458 CompileSuccessfully(GenerateShaderCode(body, extra, "Fragment", "",
5459 SPV_ENV_UNIVERSAL_1_3, "VulkanKHR")
5460 .c_str(),
5461 SPV_ENV_UNIVERSAL_1_3);
5462 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_UNIVERSAL_1_3));
5463 }
5464
5465 TEST_F(ValidateImage, SparseSampleDrefImplicitLodResultTypeNotStruct) {
5466 const std::string body = R"(
5467 %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
5468 %sampler = OpLoad %type_sampler %uniform_sampler
5469 %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
5470 %res1 = OpImageSparseSampleDrefImplicitLod %f32 %simg %f32vec2_hh %f32_1
5471 )";
5472
5473 CompileSuccessfully(GenerateShaderCode(body).c_str());
5474 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
5475 EXPECT_THAT(getDiagnosticString(),
5476 HasSubstr("Expected Result Type to be OpTypeStruct"));
5477 }
5478
5479 TEST_F(ValidateImage, SparseSampleDrefImplicitLodResultTypeNotTwoMembers1) {
5480 const std::string body = R"(
5481 %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
5482 %sampler = OpLoad %type_sampler %uniform_sampler
5483 %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
5484 %res1 = OpImageSparseSampleDrefImplicitLod %struct_u32 %simg %f32vec2_hh %f32_1
5485 )";
5486
5487 CompileSuccessfully(GenerateShaderCode(body).c_str());
5488 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
5489 EXPECT_THAT(
5490 getDiagnosticString(),
5491 HasSubstr("Expected Result Type to be a struct containing an int scalar "
5492 "and a texel"));
5493 }
5494
5495 TEST_F(ValidateImage, SparseSampleDrefImplicitLodResultTypeNotTwoMembers2) {
5496 const std::string body = R"(
5497 %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
5498 %sampler = OpLoad %type_sampler %uniform_sampler
5499 %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
5500 %res1 = OpImageSparseSampleDrefImplicitLod %struct_u32_f32_u32 %simg %f32vec2_hh %f32_1
5501 )";
5502
5503 CompileSuccessfully(GenerateShaderCode(body).c_str());
5504 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
5505 EXPECT_THAT(
5506 getDiagnosticString(),
5507 HasSubstr("Expected Result Type to be a struct containing an int scalar "
5508 "and a texel"));
5509 }
5510
5511 TEST_F(ValidateImage, SparseSampleDrefImplicitLodResultTypeFirstMemberNotInt) {
5512 const std::string body = R"(
5513 %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
5514 %sampler = OpLoad %type_sampler %uniform_sampler
5515 %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
5516 %res1 = OpImageSparseSampleDrefImplicitLod %struct_f32_f32 %simg %f32vec2_hh %f32_1
5517 )";
5518
5519 CompileSuccessfully(GenerateShaderCode(body).c_str());
5520 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
5521 EXPECT_THAT(
5522 getDiagnosticString(),
5523 HasSubstr("Expected Result Type to be a struct containing an int scalar "
5524 "and a texel"));
5525 }
5526
5527 TEST_F(ValidateImage, SparseSampleDrefImplicitLodDifferentSampledType) {
5528 const std::string body = R"(
5529 %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
5530 %sampler = OpLoad %type_sampler %uniform_sampler
5531 %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
5532 %res1 = OpImageSparseSampleDrefImplicitLod %struct_u32_u32 %simg %f32vec2_hh %f32_1
5533 )";
5534
5535 CompileSuccessfully(GenerateShaderCode(body).c_str());
5536 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
5537 EXPECT_THAT(getDiagnosticString(),
5538 HasSubstr("Expected Image 'Sampled Type' to be the same as "
5539 "Result Type's second member"));
5540 }
5541
5542 TEST_F(ValidateImage, SparseFetchSuccess) {
5543 const std::string body = R"(
5544 %img = OpLoad %type_image_f32_1d_0001 %uniform_image_f32_1d_0001
5545 %res1 = OpImageSparseFetch %struct_u32_f32vec4 %img %u32vec2_01
5546 %res2 = OpImageSparseFetch %struct_u32_f32vec4 %img %u32vec2_01 NonPrivateTexelKHR
5547 )";
5548
5549 const std::string extra = R"(
5550 OpCapability VulkanMemoryModelKHR
5551 OpExtension "SPV_KHR_vulkan_memory_model"
5552 )";
5553 CompileSuccessfully(GenerateShaderCode(body, extra, "Fragment", "",
5554 SPV_ENV_UNIVERSAL_1_3, "VulkanKHR")
5555 .c_str(),
5556 SPV_ENV_UNIVERSAL_1_3);
5557 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_UNIVERSAL_1_3));
5558 }
5559
5560 TEST_F(ValidateImage, SparseFetchResultTypeNotStruct) {
5561 const std::string body = R"(
5562 %img = OpLoad %type_image_f32_rect_0001 %uniform_image_f32_rect_0001
5563 %res1 = OpImageSparseFetch %f32 %img %u32vec2_01
5564 )";
5565
5566 CompileSuccessfully(GenerateShaderCode(body).c_str());
5567 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
5568 EXPECT_THAT(getDiagnosticString(),
5569 HasSubstr("Expected Result Type to be OpTypeStruct"));
5570 }
5571
5572 TEST_F(ValidateImage, SparseFetchResultTypeNotTwoMembers1) {
5573 const std::string body = R"(
5574 %img = OpLoad %type_image_f32_rect_0001 %uniform_image_f32_rect_0001
5575 %res1 = OpImageSparseFetch %struct_u32 %img %u32vec2_01
5576 )";
5577
5578 CompileSuccessfully(GenerateShaderCode(body).c_str());
5579 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
5580 EXPECT_THAT(getDiagnosticString(),
5581 HasSubstr("Expected Result Type to be a struct containing an "
5582 "int scalar and a texel"));
5583 }
5584
5585 TEST_F(ValidateImage, SparseFetchResultTypeNotTwoMembers2) {
5586 const std::string body = R"(
5587 %img = OpLoad %type_image_f32_rect_0001 %uniform_image_f32_rect_0001
5588 %res1 = OpImageSparseFetch %struct_u32_f32vec4_u32 %img %u32vec2_01
5589 )";
5590
5591 CompileSuccessfully(GenerateShaderCode(body).c_str());
5592 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
5593 EXPECT_THAT(getDiagnosticString(),
5594 HasSubstr("Expected Result Type to be a struct containing an "
5595 "int scalar and a texel"));
5596 }
5597
5598 TEST_F(ValidateImage, SparseFetchResultTypeFirstMemberNotInt) {
5599 const std::string body = R"(
5600 %img = OpLoad %type_image_f32_rect_0001 %uniform_image_f32_rect_0001
5601 %res1 = OpImageSparseFetch %struct_f32_f32vec4 %img %u32vec2_01
5602 )";
5603
5604 CompileSuccessfully(GenerateShaderCode(body).c_str());
5605 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
5606 EXPECT_THAT(getDiagnosticString(),
5607 HasSubstr("Expected Result Type to be a struct containing an "
5608 "int scalar and a texel"));
5609 }
5610
5611 TEST_F(ValidateImage, SparseFetchResultTypeTexelNotVector) {
5612 const std::string body = R"(
5613 %img = OpLoad %type_image_f32_rect_0001 %uniform_image_f32_rect_0001
5614 %res1 = OpImageSparseFetch %struct_u32_u32 %img %u32vec2_01
5615 )";
5616
5617 CompileSuccessfully(GenerateShaderCode(body).c_str());
5618 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
5619 EXPECT_THAT(getDiagnosticString(),
5620 HasSubstr("Expected Result Type's second member to be int or "
5621 "float vector type"));
5622 }
5623
5624 TEST_F(ValidateImage, SparseFetchWrongNumComponentsTexel) {
5625 const std::string body = R"(
5626 %img = OpLoad %type_image_f32_rect_0001 %uniform_image_f32_rect_0001
5627 %res1 = OpImageSparseFetch %struct_u32_f32vec3 %img %u32vec2_01
5628 )";
5629
5630 CompileSuccessfully(GenerateShaderCode(body).c_str());
5631 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
5632 EXPECT_THAT(getDiagnosticString(),
5633 HasSubstr("Expected Result Type's second member to have 4 "
5634 "components"));
5635 }
5636
5637 TEST_F(ValidateImage, SparseFetchWrongComponentTypeTexel) {
5638 const std::string body = R"(
5639 %img = OpLoad %type_image_f32_rect_0001 %uniform_image_f32_rect_0001
5640 %res1 = OpImageSparseFetch %struct_u32_u32vec4 %img %u32vec2_01
5641 )";
5642
5643 CompileSuccessfully(GenerateShaderCode(body).c_str());
5644 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
5645 EXPECT_THAT(getDiagnosticString(),
5646 HasSubstr("Expected Image 'Sampled Type' to be the same as "
5647 "Result Type's second member components"));
5648 }
5649
5650 TEST_F(ValidateImage, SparseReadSuccess) {
5651 const std::string body = R"(
5652 %img = OpLoad %type_image_f32_2d_0002 %uniform_image_f32_2d_0002
5653 %res1 = OpImageSparseRead %struct_u32_f32vec4 %img %u32vec2_01
5654 )";
5655
5656 const std::string extra = "\nOpCapability StorageImageReadWithoutFormat\n";
5657 CompileSuccessfully(GenerateShaderCode(body, extra).c_str());
5658 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
5659 }
5660
5661 TEST_F(ValidateImage, SparseReadResultTypeNotStruct) {
5662 const std::string body = R"(
5663 %img = OpLoad %type_image_f32_2d_0002 %uniform_image_f32_2d_0002
5664 %res1 = OpImageSparseRead %f32 %img %u32vec2_01
5665 )";
5666
5667 const std::string extra = "\nOpCapability StorageImageReadWithoutFormat\n";
5668 CompileSuccessfully(GenerateShaderCode(body, extra).c_str());
5669 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
5670 EXPECT_THAT(getDiagnosticString(),
5671 HasSubstr("Expected Result Type to be OpTypeStruct"));
5672 }
5673
5674 TEST_F(ValidateImage, SparseReadResultTypeNotTwoMembers1) {
5675 const std::string body = R"(
5676 %img = OpLoad %type_image_f32_2d_0002 %uniform_image_f32_2d_0002
5677 %res1 = OpImageSparseRead %struct_u32 %img %u32vec2_01
5678 )";
5679
5680 const std::string extra = "\nOpCapability StorageImageReadWithoutFormat\n";
5681 CompileSuccessfully(GenerateShaderCode(body, extra).c_str());
5682 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
5683 EXPECT_THAT(getDiagnosticString(),
5684 HasSubstr("Expected Result Type to be a struct containing an "
5685 "int scalar and a texel"));
5686 }
5687
5688 TEST_F(ValidateImage, SparseReadResultTypeNotTwoMembers2) {
5689 const std::string body = R"(
5690 %img = OpLoad %type_image_f32_2d_0002 %uniform_image_f32_2d_0002
5691 %res1 = OpImageSparseRead %struct_u32_f32vec4_u32 %img %u32vec2_01
5692 )";
5693
5694 const std::string extra = "\nOpCapability StorageImageReadWithoutFormat\n";
5695 CompileSuccessfully(GenerateShaderCode(body, extra).c_str());
5696 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
5697 EXPECT_THAT(getDiagnosticString(),
5698 HasSubstr("Expected Result Type to be a struct containing an "
5699 "int scalar and a texel"));
5700 }
5701
5702 TEST_F(ValidateImage, SparseReadResultTypeFirstMemberNotInt) {
5703 const std::string body = R"(
5704 %img = OpLoad %type_image_f32_2d_0002 %uniform_image_f32_2d_0002
5705 %res1 = OpImageSparseRead %struct_f32_f32vec4 %img %u32vec2_01
5706 )";
5707
5708 const std::string extra = "\nOpCapability StorageImageReadWithoutFormat\n";
5709 CompileSuccessfully(GenerateShaderCode(body, extra).c_str());
5710 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
5711 EXPECT_THAT(getDiagnosticString(),
5712 HasSubstr("Expected Result Type to be a struct containing an "
5713 "int scalar and a texel"));
5714 }
5715
5716 TEST_F(ValidateImage, SparseReadResultTypeTexelWrongType) {
5717 const std::string body = R"(
5718 %img = OpLoad %type_image_f32_2d_0002 %uniform_image_f32_2d_0002
5719 %res1 = OpImageSparseRead %struct_u32_u32arr4 %img %u32vec2_01
5720 )";
5721
5722 const std::string extra = "\nOpCapability StorageImageReadWithoutFormat\n";
5723 CompileSuccessfully(GenerateShaderCode(body, extra).c_str());
5724 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
5725 EXPECT_THAT(getDiagnosticString(),
5726 HasSubstr("Expected Result Type's second member to be int or "
5727 "float scalar or vector type"));
5728 }
5729
5730 TEST_F(ValidateImage, SparseReadWrongComponentTypeTexel) {
5731 const std::string body = R"(
5732 %img = OpLoad %type_image_f32_2d_0002 %uniform_image_f32_2d_0002
5733 %res1 = OpImageSparseRead %struct_u32_u32vec4 %img %u32vec2_01
5734 )";
5735
5736 const std::string extra = "\nOpCapability StorageImageReadWithoutFormat\n";
5737 CompileSuccessfully(GenerateShaderCode(body, extra).c_str());
5738 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
5739 EXPECT_THAT(getDiagnosticString(),
5740 HasSubstr("Expected Image 'Sampled Type' to be the same as "
5741 "Result Type's second member components"));
5742 }
5743
5744 TEST_F(ValidateImage, SparseReadSubpassDataNotAllowed) {
5745 const std::string body = R"(
5746 %img = OpLoad %type_image_f32_spd_0002 %uniform_image_f32_spd_0002
5747 %res1 = OpImageSparseRead %struct_u32_f32vec4 %img %u32vec2_01
5748 )";
5749
5750 const std::string extra = "\nOpCapability StorageImageReadWithoutFormat\n";
5751 CompileSuccessfully(GenerateShaderCode(body, extra, "Fragment").c_str());
5752 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
5753 EXPECT_THAT(
5754 getDiagnosticString(),
5755 HasSubstr("Image Dim SubpassData cannot be used with ImageSparseRead"));
5756 }
5757
5758 TEST_F(ValidateImage, SparseGatherSuccess) {
5759 const std::string body = R"(
5760 %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
5761 %sampler = OpLoad %type_sampler %uniform_sampler
5762 %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
5763 %res1 = OpImageSparseGather %struct_u32_f32vec4 %simg %f32vec4_0000 %u32_1
5764 %res2 = OpImageSparseGather %struct_u32_f32vec4 %simg %f32vec4_0000 %u32_1 NonPrivateTexelKHR
5765 )";
5766
5767 const std::string extra = R"(
5768 OpCapability VulkanMemoryModelKHR
5769 OpExtension "SPV_KHR_vulkan_memory_model"
5770 )";
5771 CompileSuccessfully(GenerateShaderCode(body, extra, "Fragment", "",
5772 SPV_ENV_UNIVERSAL_1_3, "VulkanKHR")
5773 .c_str(),
5774 SPV_ENV_UNIVERSAL_1_3);
5775 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_UNIVERSAL_1_3));
5776 }
5777
5778 TEST_F(ValidateImage, SparseGatherResultTypeNotStruct) {
5779 const std::string body = R"(
5780 %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
5781 %sampler = OpLoad %type_sampler %uniform_sampler
5782 %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
5783 %res1 = OpImageSparseGather %f32 %simg %f32vec2_hh %u32_1
5784 )";
5785
5786 CompileSuccessfully(GenerateShaderCode(body).c_str());
5787 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
5788 EXPECT_THAT(getDiagnosticString(),
5789 HasSubstr("Expected Result Type to be OpTypeStruct"));
5790 }
5791
5792 TEST_F(ValidateImage, SparseGatherResultTypeNotTwoMembers1) {
5793 const std::string body = R"(
5794 %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
5795 %sampler = OpLoad %type_sampler %uniform_sampler
5796 %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
5797 %res1 = OpImageSparseGather %struct_u32 %simg %f32vec2_hh %u32_1
5798 )";
5799
5800 CompileSuccessfully(GenerateShaderCode(body).c_str());
5801 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
5802 EXPECT_THAT(getDiagnosticString(),
5803 HasSubstr("Expected Result Type to be a struct containing an int "
5804 "scalar and a texel"));
5805 }
5806
5807 TEST_F(ValidateImage, SparseGatherResultTypeNotTwoMembers2) {
5808 const std::string body = R"(
5809 %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
5810 %sampler = OpLoad %type_sampler %uniform_sampler
5811 %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
5812 %res1 = OpImageSparseGather %struct_u32_f32vec4_u32 %simg %f32vec2_hh %u32_1
5813 )";
5814
5815 CompileSuccessfully(GenerateShaderCode(body).c_str());
5816 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
5817 EXPECT_THAT(getDiagnosticString(),
5818 HasSubstr("Expected Result Type to be a struct containing an int "
5819 "scalar and a texel"));
5820 }
5821
5822 TEST_F(ValidateImage, SparseGatherResultTypeFirstMemberNotInt) {
5823 const std::string body = R"(
5824 %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
5825 %sampler = OpLoad %type_sampler %uniform_sampler
5826 %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
5827 %res1 = OpImageSparseGather %struct_f32_f32vec4 %simg %f32vec2_hh %u32_1
5828 )";
5829
5830 CompileSuccessfully(GenerateShaderCode(body).c_str());
5831 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
5832 EXPECT_THAT(getDiagnosticString(),
5833 HasSubstr("Expected Result Type to be a struct containing an "
5834 "int scalar and a texel"));
5835 }
5836
5837 TEST_F(ValidateImage, SparseGatherResultTypeTexelNotVector) {
5838 const std::string body = R"(
5839 %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
5840 %sampler = OpLoad %type_sampler %uniform_sampler
5841 %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
5842 %res1 = OpImageSparseGather %struct_u32_u32 %simg %f32vec2_hh %u32_1
5843 )";
5844
5845 CompileSuccessfully(GenerateShaderCode(body).c_str());
5846 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
5847 EXPECT_THAT(getDiagnosticString(),
5848 HasSubstr("Expected Result Type's second member to be int or "
5849 "float vector type"));
5850 }
5851
5852 TEST_F(ValidateImage, SparseGatherWrongNumComponentsTexel) {
5853 const std::string body = R"(
5854 %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
5855 %sampler = OpLoad %type_sampler %uniform_sampler
5856 %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
5857 %res1 = OpImageSparseGather %struct_u32_f32vec3 %simg %f32vec2_hh %u32_1
5858 )";
5859
5860 CompileSuccessfully(GenerateShaderCode(body).c_str());
5861 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
5862 EXPECT_THAT(getDiagnosticString(),
5863 HasSubstr("Expected Result Type's second member to have 4 "
5864 "components"));
5865 }
5866
5867 TEST_F(ValidateImage, SparseGatherWrongComponentTypeTexel) {
5868 const std::string body = R"(
5869 %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
5870 %sampler = OpLoad %type_sampler %uniform_sampler
5871 %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
5872 %res1 = OpImageSparseGather %struct_u32_u32vec4 %simg %f32vec2_hh %u32_1
5873 )";
5874
5875 CompileSuccessfully(GenerateShaderCode(body).c_str());
5876 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
5877 EXPECT_THAT(getDiagnosticString(),
5878 HasSubstr("Expected Image 'Sampled Type' to be the same as "
5879 "Result Type's second member components"));
5880 }
5881
5882 TEST_F(ValidateImage, SparseTexelsResidentSuccess) {
5883 const std::string body = R"(
5884 %res1 = OpImageSparseTexelsResident %bool %u32_1
5885 )";
5886
5887 CompileSuccessfully(GenerateShaderCode(body).c_str());
5888 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
5889 }
5890
5891 TEST_F(ValidateImage, SparseTexelsResidentResultTypeNotBool) {
5892 const std::string body = R"(
5893 %res1 = OpImageSparseTexelsResident %u32 %u32_1
5894 )";
5895
5896 CompileSuccessfully(GenerateShaderCode(body).c_str());
5897 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
5898 EXPECT_THAT(getDiagnosticString(),
5899 HasSubstr("Expected Result Type to be bool scalar type"));
5900 }
5901
5902 TEST_F(ValidateImage, MakeTexelVisibleKHRSuccessImageRead) {
5903 const std::string body = R"(
5904 %img = OpLoad %type_image_u32_2d_0002 %uniform_image_u32_2d_0002
5905 %res1 = OpImageRead %u32vec4 %img %u32vec2_01 MakeTexelVisibleKHR|NonPrivateTexelKHR %u32_2
5906 )";
5907
5908 const std::string extra = R"(
5909 OpCapability StorageImageReadWithoutFormat
5910 OpCapability VulkanMemoryModelKHR
5911 OpExtension "SPV_KHR_vulkan_memory_model"
5912 )";
5913 CompileSuccessfully(GenerateShaderCode(body, extra, "Fragment", "",
5914 SPV_ENV_UNIVERSAL_1_3, "VulkanKHR")
5915 .c_str(),
5916 SPV_ENV_UNIVERSAL_1_3);
5917 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_UNIVERSAL_1_3));
5918 }
5919
5920 TEST_F(ValidateImage, MakeTexelVisibleKHRSuccessImageSparseRead) {
5921 const std::string body = R"(
5922 %img = OpLoad %type_image_f32_2d_0002 %uniform_image_f32_2d_0002
5923 %res1 = OpImageSparseRead %struct_u32_f32vec4 %img %u32vec2_01 MakeTexelVisibleKHR|NonPrivateTexelKHR %u32_2
5924 )";
5925
5926 const std::string extra = R"(
5927 OpCapability StorageImageReadWithoutFormat
5928 OpCapability VulkanMemoryModelKHR
5929 OpExtension "SPV_KHR_vulkan_memory_model"
5930 )";
5931 CompileSuccessfully(GenerateShaderCode(body, extra, "Fragment", "",
5932 SPV_ENV_UNIVERSAL_1_3, "VulkanKHR")
5933 .c_str(),
5934 SPV_ENV_UNIVERSAL_1_3);
5935 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_UNIVERSAL_1_3));
5936 }
5937
5938 TEST_F(ValidateImage, MakeTexelVisibleKHRFailureOpcode) {
5939 const std::string body = R"(
5940 %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
5941 %sampler = OpLoad %type_sampler %uniform_sampler
5942 %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
5943 %res1 = OpImageSampleImplicitLod %f32vec4 %simg %f32vec2_hh MakeTexelVisibleKHR|NonPrivateTexelKHR %u32_1
5944 )";
5945
5946 const std::string extra = R"(
5947 OpCapability StorageImageReadWithoutFormat
5948 OpCapability VulkanMemoryModelKHR
5949 OpExtension "SPV_KHR_vulkan_memory_model"
5950 )";
5951 CompileSuccessfully(GenerateShaderCode(body, extra, "Fragment", "",
5952 SPV_ENV_UNIVERSAL_1_3, "VulkanKHR")
5953 .c_str(),
5954 SPV_ENV_UNIVERSAL_1_3);
5955 ASSERT_EQ(SPV_ERROR_INVALID_DATA,
5956 ValidateInstructions(SPV_ENV_UNIVERSAL_1_3));
5957 EXPECT_THAT(
5958 getDiagnosticString(),
5959 HasSubstr("Image Operand MakeTexelVisibleKHR can only be used with "
5960 "OpImageRead or OpImageSparseRead: OpImageSampleImplicitLod"));
5961 }
5962
5963 TEST_F(ValidateImage, MakeTexelVisibleKHRFailureMissingNonPrivate) {
5964 const std::string body = R"(
5965 %img = OpLoad %type_image_u32_2d_0002 %uniform_image_u32_2d_0002
5966 %res1 = OpImageRead %u32vec4 %img %u32vec2_01 MakeTexelVisibleKHR %u32_1
5967 )";
5968
5969 const std::string extra = R"(
5970 OpCapability StorageImageReadWithoutFormat
5971 OpCapability VulkanMemoryModelKHR
5972 OpExtension "SPV_KHR_vulkan_memory_model"
5973 )";
5974 CompileSuccessfully(GenerateShaderCode(body, extra, "Fragment", "",
5975 SPV_ENV_UNIVERSAL_1_3, "VulkanKHR")
5976 .c_str(),
5977 SPV_ENV_UNIVERSAL_1_3);
5978 ASSERT_EQ(SPV_ERROR_INVALID_DATA,
5979 ValidateInstructions(SPV_ENV_UNIVERSAL_1_3));
5980 EXPECT_THAT(getDiagnosticString(),
5981 HasSubstr("Image Operand MakeTexelVisibleKHR requires "
5982 "NonPrivateTexelKHR is also specified: OpImageRead"));
5983 }
5984
5985 TEST_F(ValidateImage, MakeTexelAvailableKHRSuccessImageWrite) {
5986 const std::string body = R"(
5987 %img = OpLoad %type_image_u32_2d_0002 %uniform_image_u32_2d_0002
5988 OpImageWrite %img %u32vec2_01 %u32vec4_0123 MakeTexelAvailableKHR|NonPrivateTexelKHR %u32_2
5989 )";
5990
5991 const std::string extra = R"(
5992 OpCapability StorageImageWriteWithoutFormat
5993 OpCapability VulkanMemoryModelKHR
5994 OpExtension "SPV_KHR_vulkan_memory_model"
5995 )";
5996 CompileSuccessfully(GenerateShaderCode(body, extra, "Fragment", "",
5997 SPV_ENV_UNIVERSAL_1_3, "VulkanKHR")
5998 .c_str(),
5999 SPV_ENV_UNIVERSAL_1_3);
6000 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_UNIVERSAL_1_3));
6001 }
6002
6003 TEST_F(ValidateImage, MakeTexelAvailableKHRFailureOpcode) {
6004 const std::string body = R"(
6005 %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
6006 %sampler = OpLoad %type_sampler %uniform_sampler
6007 %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
6008 %res1 = OpImageSampleImplicitLod %f32vec4 %simg %f32vec2_hh MakeTexelAvailableKHR|NonPrivateTexelKHR %u32_1
6009 )";
6010
6011 const std::string extra = R"(
6012 OpCapability StorageImageReadWithoutFormat
6013 OpCapability VulkanMemoryModelKHR
6014 OpExtension "SPV_KHR_vulkan_memory_model"
6015 )";
6016 CompileSuccessfully(GenerateShaderCode(body, extra, "Fragment", "",
6017 SPV_ENV_UNIVERSAL_1_3, "VulkanKHR")
6018 .c_str(),
6019 SPV_ENV_UNIVERSAL_1_3);
6020 ASSERT_EQ(SPV_ERROR_INVALID_DATA,
6021 ValidateInstructions(SPV_ENV_UNIVERSAL_1_3));
6022 EXPECT_THAT(getDiagnosticString(),
6023 HasSubstr("Image Operand MakeTexelAvailableKHR can only be used "
6024 "with OpImageWrite: OpImageSampleImplicitLod"));
6025 }
6026
6027 TEST_F(ValidateImage, MakeTexelAvailableKHRFailureMissingNonPrivate) {
6028 const std::string body = R"(
6029 %img = OpLoad %type_image_u32_2d_0002 %uniform_image_u32_2d_0002
6030 OpImageWrite %img %u32vec2_01 %u32vec4_0123 MakeTexelAvailableKHR %u32_1
6031 )";
6032
6033 const std::string extra = R"(
6034 OpCapability StorageImageWriteWithoutFormat
6035 OpCapability VulkanMemoryModelKHR
6036 OpExtension "SPV_KHR_vulkan_memory_model"
6037 )";
6038 CompileSuccessfully(GenerateShaderCode(body, extra, "Fragment", "",
6039 SPV_ENV_UNIVERSAL_1_3, "VulkanKHR")
6040 .c_str(),
6041 SPV_ENV_UNIVERSAL_1_3);
6042 ASSERT_EQ(SPV_ERROR_INVALID_DATA,
6043 ValidateInstructions(SPV_ENV_UNIVERSAL_1_3));
6044 EXPECT_THAT(getDiagnosticString(),
6045 HasSubstr("Image Operand MakeTexelAvailableKHR requires "
6046 "NonPrivateTexelKHR is also specified: OpImageWrite"));
6047 }
6048
6049 TEST_F(ValidateImage, VulkanMemoryModelDeviceScopeImageWriteBad) {
6050 const std::string body = R"(
6051 %img = OpLoad %type_image_u32_2d_0002 %uniform_image_u32_2d_0002
6052 OpImageWrite %img %u32vec2_01 %u32vec4_0123 MakeTexelAvailableKHR|NonPrivateTexelKHR %u32_1
6053 )";
6054
6055 const std::string extra = R"(
6056 OpCapability StorageImageWriteWithoutFormat
6057 OpCapability VulkanMemoryModelKHR
6058 OpExtension "SPV_KHR_vulkan_memory_model"
6059 )";
6060 CompileSuccessfully(GenerateShaderCode(body, extra, "Fragment", "",
6061 SPV_ENV_UNIVERSAL_1_3, "VulkanKHR")
6062 .c_str(),
6063 SPV_ENV_UNIVERSAL_1_3);
6064 ASSERT_EQ(SPV_ERROR_INVALID_DATA,
6065 ValidateInstructions(SPV_ENV_UNIVERSAL_1_3));
6066 EXPECT_THAT(
6067 getDiagnosticString(),
6068 HasSubstr("Use of device scope with VulkanKHR memory model requires the "
6069 "VulkanMemoryModelDeviceScopeKHR capability"));
6070 }
6071
6072 TEST_F(ValidateImage, VulkanMemoryModelDeviceScopeImageWriteGood) {
6073 const std::string body = R"(
6074 %img = OpLoad %type_image_u32_2d_0002 %uniform_image_u32_2d_0002
6075 OpImageWrite %img %u32vec2_01 %u32vec4_0123 MakeTexelAvailableKHR|NonPrivateTexelKHR %u32_1
6076 )";
6077
6078 const std::string extra = R"(
6079 OpCapability StorageImageWriteWithoutFormat
6080 OpCapability VulkanMemoryModelKHR
6081 OpCapability VulkanMemoryModelDeviceScopeKHR
6082 OpExtension "SPV_KHR_vulkan_memory_model"
6083 )";
6084 CompileSuccessfully(GenerateShaderCode(body, extra, "Fragment", "",
6085 SPV_ENV_UNIVERSAL_1_3, "VulkanKHR")
6086 .c_str(),
6087 SPV_ENV_UNIVERSAL_1_3);
6088 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_UNIVERSAL_1_3));
6089 }
6090
6091 TEST_F(ValidateImage, VulkanMemoryModelDeviceScopeImageReadBad) {
6092 const std::string body = R"(
6093 %img = OpLoad %type_image_u32_2d_0002 %uniform_image_u32_2d_0002
6094 %res1 = OpImageRead %u32vec4 %img %u32vec2_01 MakeTexelVisibleKHR|NonPrivateTexelKHR %u32_1
6095 )";
6096
6097 const std::string extra = R"(
6098 OpCapability StorageImageReadWithoutFormat
6099 OpCapability VulkanMemoryModelKHR
6100 OpExtension "SPV_KHR_vulkan_memory_model"
6101 )";
6102 CompileSuccessfully(GenerateShaderCode(body, extra, "Fragment", "",
6103 SPV_ENV_UNIVERSAL_1_3, "VulkanKHR")
6104 .c_str(),
6105 SPV_ENV_UNIVERSAL_1_3);
6106 ASSERT_EQ(SPV_ERROR_INVALID_DATA,
6107 ValidateInstructions(SPV_ENV_UNIVERSAL_1_3));
6108 EXPECT_THAT(
6109 getDiagnosticString(),
6110 HasSubstr("Use of device scope with VulkanKHR memory model requires the "
6111 "VulkanMemoryModelDeviceScopeKHR capability"));
6112 }
6113
6114 TEST_F(ValidateImage, VulkanMemoryModelDeviceScopeImageReadGood) {
6115 const std::string body = R"(
6116 %img = OpLoad %type_image_u32_2d_0002 %uniform_image_u32_2d_0002
6117 %res1 = OpImageRead %u32vec4 %img %u32vec2_01 MakeTexelVisibleKHR|NonPrivateTexelKHR %u32_1
6118 )";
6119
6120 const std::string extra = R"(
6121 OpCapability StorageImageReadWithoutFormat
6122 OpCapability VulkanMemoryModelKHR
6123 OpCapability VulkanMemoryModelDeviceScopeKHR
6124 OpExtension "SPV_KHR_vulkan_memory_model"
6125 )";
6126 CompileSuccessfully(GenerateShaderCode(body, extra, "Fragment", "",
6127 SPV_ENV_UNIVERSAL_1_3, "VulkanKHR")
6128 .c_str(),
6129 SPV_ENV_UNIVERSAL_1_3);
6130 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_UNIVERSAL_1_3));
6131 }
6132
6133 // This example used to cause a seg fault on OpReturnValue, verifying it doesn't
6134 // anymore.
6135 TEST_F(ValidateImage, Issue2463NoSegFault) {
6136 const std::string spirv = R"(
6137 OpCapability Linkage
6138 OpCapability Shader
6139 %1 = OpExtInstImport "GLSL.std.450"
6140 OpMemoryModel Logical GLSL450
6141 %void = OpTypeVoid
6142 %6 = OpTypeFunction %void
6143 %float = OpTypeFloat 32
6144 %8 = OpTypeImage %float 3D 0 0 0 1 Unknown
6145 %_ptr_UniformConstant_8 = OpTypePointer UniformConstant %8
6146 %10 = OpTypeSampler
6147 %_ptr_UniformConstant_10 = OpTypePointer UniformConstant %10
6148 %12 = OpTypeSampledImage %8
6149 %13 = OpTypeFunction %12 %_ptr_UniformConstant_8 %_ptr_UniformConstant_10
6150 %23 = OpFunction %12 None %13
6151 %24 = OpFunctionParameter %_ptr_UniformConstant_8
6152 %25 = OpFunctionParameter %_ptr_UniformConstant_10
6153 %26 = OpLabel
6154 %27 = OpLoad %8 %24
6155 %28 = OpLoad %10 %25
6156 %29 = OpSampledImage %12 %27 %28
6157 OpReturnValue %29
6158 OpFunctionEnd
6159 )";
6160
6161 CompileSuccessfully(spirv);
6162 ASSERT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions());
6163 EXPECT_THAT(getDiagnosticString(),
6164 HasSubstr("OpSampledImage instruction must not appear as operand "
6165 "for OpReturnValue"));
6166 }
6167
6168 TEST_F(ValidateImage, SignExtendV13Bad) {
6169 const std::string body = R"(
6170 %img = OpLoad %type_image_u32_2d_0002 %uniform_image_u32_2d_0002
6171 %res1 = OpImageRead %u32vec4 %img %u32vec2_01 SignExtend
6172 )";
6173
6174 CompileSuccessfully(
6175 GenerateShaderCode(body, "", "Fragment", "", SPV_ENV_UNIVERSAL_1_3));
6176 ASSERT_EQ(SPV_ERROR_WRONG_VERSION, ValidateInstructions());
6177 EXPECT_THAT(
6178 getDiagnosticString(),
6179 HasSubstr("SignExtend(4096) requires SPIR-V version 1.4 or later"));
6180 }
6181
6182 TEST_F(ValidateImage, ZeroExtendV13Bad) {
6183 const std::string body = R"(
6184 %img = OpLoad %type_image_u32_2d_0002 %uniform_image_u32_2d_0002
6185 %res1 = OpImageRead %u32vec4 %img %u32vec2_01 ZeroExtend
6186 )";
6187
6188 CompileSuccessfully(
6189 GenerateShaderCode(body, "", "Fragment", "", SPV_ENV_UNIVERSAL_1_3));
6190 ASSERT_EQ(SPV_ERROR_WRONG_VERSION, ValidateInstructions());
6191 EXPECT_THAT(
6192 getDiagnosticString(),
6193 HasSubstr("ZeroExtend(8192) requires SPIR-V version 1.4 or later"));
6194 }
6195
6196 TEST_F(ValidateImage, SignExtendScalarUIntTexelV14Good) {
6197 // Unsigned int sampled type
6198 const std::string body = R"(
6199 %img = OpLoad %type_image_u32_2d_0002 %uniform_image_u32_2d_0002
6200 %res1 = OpImageRead %u32 %img %u32vec2_01 SignExtend
6201 )";
6202 const std::string extra = "\nOpCapability StorageImageReadWithoutFormat\n";
6203
6204 CompileSuccessfully(
6205 GenerateShaderCode(body, extra, "Fragment", "", SPV_ENV_UNIVERSAL_1_4),
6206 SPV_ENV_UNIVERSAL_1_4);
6207 EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_UNIVERSAL_1_4));
6208 EXPECT_THAT(getDiagnosticString(), Eq(""));
6209 }
6210
6211 TEST_F(ValidateImage, SignExtendScalarSIntTexelV14Good) {
6212 // Signed int sampled type
6213 const std::string body = R"(
6214 %img = OpLoad %type_image_s32_2d_0002 %uniform_image_s32_2d_0002
6215 %res1 = OpImageRead %s32 %img %u32vec2_01 SignExtend
6216 )";
6217 const std::string extra = "\nOpCapability StorageImageReadWithoutFormat\n";
6218
6219 CompileSuccessfully(
6220 GenerateShaderCode(body, extra, "Fragment", "", SPV_ENV_UNIVERSAL_1_4),
6221 SPV_ENV_UNIVERSAL_1_4);
6222 EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_UNIVERSAL_1_4));
6223 EXPECT_THAT(getDiagnosticString(), Eq(""));
6224 }
6225
6226 TEST_F(ValidateImage, SignExtendScalarVectorUIntTexelV14Good) {
6227 const std::string body = R"(
6228 %img = OpLoad %type_image_u32_2d_0002 %uniform_image_u32_2d_0002
6229 %res1 = OpImageRead %u32vec4 %img %u32vec2_01 SignExtend
6230 )";
6231 const std::string extra = "\nOpCapability StorageImageReadWithoutFormat\n";
6232
6233 CompileSuccessfully(
6234 GenerateShaderCode(body, extra, "Fragment", "", SPV_ENV_UNIVERSAL_1_4),
6235 SPV_ENV_UNIVERSAL_1_4);
6236 EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_UNIVERSAL_1_4));
6237 EXPECT_THAT(getDiagnosticString(), Eq(""));
6238 }
6239
6240 TEST_F(ValidateImage, SignExtendVectorSIntTexelV14Good) {
6241 const std::string body = R"(
6242 %img = OpLoad %type_image_s32_2d_0002 %uniform_image_s32_2d_0002
6243 %res1 = OpImageRead %s32vec4 %img %u32vec2_01 SignExtend
6244 )";
6245 const std::string extra = "\nOpCapability StorageImageReadWithoutFormat\n";
6246
6247 CompileSuccessfully(
6248 GenerateShaderCode(body, extra, "Fragment", "", SPV_ENV_UNIVERSAL_1_4),
6249 SPV_ENV_UNIVERSAL_1_4);
6250 EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_UNIVERSAL_1_4));
6251 EXPECT_THAT(getDiagnosticString(), Eq(""));
6252 }
6253
6254 // No negative tests for SignExtend since we don't truly know the
6255 // texel format.
6256
6257 TEST_F(ValidateImage, ZeroExtendScalarUIntTexelV14Good) {
6258 // Unsigned int sampled type
6259 const std::string body = R"(
6260 %img = OpLoad %type_image_u32_2d_0002 %uniform_image_u32_2d_0002
6261 %res1 = OpImageRead %u32 %img %u32vec2_01 ZeroExtend
6262 )";
6263 const std::string extra = "\nOpCapability StorageImageReadWithoutFormat\n";
6264
6265 CompileSuccessfully(
6266 GenerateShaderCode(body, extra, "Fragment", "", SPV_ENV_UNIVERSAL_1_4),
6267 SPV_ENV_UNIVERSAL_1_4);
6268 EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_UNIVERSAL_1_4));
6269 EXPECT_THAT(getDiagnosticString(), Eq(""));
6270 }
6271
6272 TEST_F(ValidateImage, ZeroExtendScalarSIntTexelV14Good) {
6273 // Zeroed int sampled type
6274 const std::string body = R"(
6275 %img = OpLoad %type_image_s32_2d_0002 %uniform_image_s32_2d_0002
6276 %res1 = OpImageRead %s32 %img %u32vec2_01 ZeroExtend
6277 )";
6278 const std::string extra = "\nOpCapability StorageImageReadWithoutFormat\n";
6279
6280 CompileSuccessfully(
6281 GenerateShaderCode(body, extra, "Fragment", "", SPV_ENV_UNIVERSAL_1_4),
6282 SPV_ENV_UNIVERSAL_1_4);
6283 EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_UNIVERSAL_1_4));
6284 EXPECT_THAT(getDiagnosticString(), Eq(""));
6285 }
6286
6287 TEST_F(ValidateImage, ZeroExtendScalarVectorUIntTexelV14Good) {
6288 const std::string body = R"(
6289 %img = OpLoad %type_image_u32_2d_0002 %uniform_image_u32_2d_0002
6290 %res1 = OpImageRead %u32vec4 %img %u32vec2_01 ZeroExtend
6291 )";
6292 const std::string extra = "\nOpCapability StorageImageReadWithoutFormat\n";
6293
6294 CompileSuccessfully(
6295 GenerateShaderCode(body, extra, "Fragment", "", SPV_ENV_UNIVERSAL_1_4),
6296 SPV_ENV_UNIVERSAL_1_4);
6297 EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_UNIVERSAL_1_4));
6298 EXPECT_THAT(getDiagnosticString(), Eq(""));
6299 }
6300
6301 TEST_F(ValidateImage, ZeroExtendVectorSIntTexelV14Good) {
6302 const std::string body = R"(
6303 %img = OpLoad %type_image_s32_2d_0002 %uniform_image_s32_2d_0002
6304 %res1 = OpImageRead %s32vec4 %img %u32vec2_01 ZeroExtend
6305 )";
6306 const std::string extra = "\nOpCapability StorageImageReadWithoutFormat\n";
6307
6308 CompileSuccessfully(
6309 GenerateShaderCode(body, extra, "Fragment", "", SPV_ENV_UNIVERSAL_1_4),
6310 SPV_ENV_UNIVERSAL_1_4);
6311 EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_UNIVERSAL_1_4));
6312 EXPECT_THAT(getDiagnosticString(), Eq(""));
6313 }
6314
6315 TEST_F(ValidateImage, ReadLodAMDSuccess1) {
6316 const std::string body = R"(
6317 %img = OpLoad %type_image_u32_2d_0002 %uniform_image_u32_2d_0002
6318 %res1 = OpImageRead %u32vec4 %img %u32vec2_01 Lod %u32_0
6319 )";
6320
6321 const std::string extra =
6322 "\nOpCapability StorageImageReadWithoutFormat\n"
6323 "OpCapability ImageReadWriteLodAMD\n"
6324 "OpExtension \"SPV_AMD_shader_image_load_store_lod\"\n";
6325 CompileSuccessfully(
6326 GenerateShaderCode(body, extra, "Fragment", "", SPV_ENV_UNIVERSAL_1_1),
6327 SPV_ENV_UNIVERSAL_1_1);
6328 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_UNIVERSAL_1_1));
6329 }
6330
6331 TEST_F(ValidateImage, ReadLodAMDSuccess2) {
6332 const std::string body = R"(
6333 %img = OpLoad %type_image_f32_1d_0002_rgba32f %uniform_image_f32_1d_0002_rgba32f
6334 %res1 = OpImageRead %f32vec4 %img %u32vec2_01 Lod %u32_0
6335 )";
6336
6337 const std::string extra =
6338 "\nOpCapability Image1D\n"
6339 "OpCapability ImageReadWriteLodAMD\n"
6340 "OpExtension \"SPV_AMD_shader_image_load_store_lod\"\n";
6341 CompileSuccessfully(
6342 GenerateShaderCode(body, extra, "Fragment", "", SPV_ENV_UNIVERSAL_1_1),
6343 SPV_ENV_UNIVERSAL_1_1);
6344 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_UNIVERSAL_1_1));
6345 }
6346
6347 TEST_F(ValidateImage, ReadLodAMDSuccess3) {
6348 const std::string body = R"(
6349 %img = OpLoad %type_image_f32_cube_0102_rgba32f %uniform_image_f32_cube_0102_rgba32f
6350 %res1 = OpImageRead %f32vec4 %img %u32vec3_012 Lod %u32_0
6351 )";
6352
6353 const std::string extra =
6354 "\nOpCapability ImageCubeArray\n"
6355 "OpCapability ImageReadWriteLodAMD\n"
6356 "OpExtension \"SPV_AMD_shader_image_load_store_lod\"\n";
6357 CompileSuccessfully(
6358 GenerateShaderCode(body, extra, "Fragment", "", SPV_ENV_UNIVERSAL_1_1),
6359 SPV_ENV_UNIVERSAL_1_1);
6360 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_UNIVERSAL_1_1));
6361 }
6362
6363 TEST_F(ValidateImage, ReadLodAMDNeedCapability) {
6364 const std::string body = R"(
6365 %img = OpLoad %type_image_f32_cube_0102_rgba32f %uniform_image_f32_cube_0102_rgba32f
6366 %res1 = OpImageRead %f32vec4 %img %u32vec3_012 Lod %u32_0
6367 )";
6368
6369 const std::string extra = "\nOpCapability ImageCubeArray\n";
6370 CompileSuccessfully(
6371 GenerateShaderCode(body, extra, "Fragment", "", SPV_ENV_UNIVERSAL_1_1),
6372 SPV_ENV_UNIVERSAL_1_1);
6373 ASSERT_EQ(SPV_ERROR_INVALID_DATA,
6374 ValidateInstructions(SPV_ENV_UNIVERSAL_1_1));
6375 EXPECT_THAT(getDiagnosticString(),
6376 HasSubstr("Image Operand Lod can only be used with ExplicitLod "
6377 "opcodes and OpImageFetch"));
6378 }
6379
6380 TEST_F(ValidateImage, WriteLodAMDSuccess1) {
6381 const std::string body = R"(
6382 %img = OpLoad %type_image_u32_2d_0002 %uniform_image_u32_2d_0002
6383 OpImageWrite %img %u32vec2_01 %u32vec4_0123 Lod %u32_0
6384 )";
6385
6386 const std::string extra =
6387 "\nOpCapability StorageImageWriteWithoutFormat\n"
6388 "OpCapability ImageReadWriteLodAMD\n"
6389 "OpExtension \"SPV_AMD_shader_image_load_store_lod\"\n";
6390 CompileSuccessfully(
6391 GenerateShaderCode(body, extra, "Fragment", "", SPV_ENV_UNIVERSAL_1_1),
6392 SPV_ENV_UNIVERSAL_1_1);
6393 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_UNIVERSAL_1_1));
6394 }
6395
6396 TEST_F(ValidateImage, WriteLodAMDSuccess2) {
6397 const std::string body = R"(
6398 %img = OpLoad %type_image_f32_1d_0002_rgba32f %uniform_image_f32_1d_0002_rgba32f
6399 OpImageWrite %img %u32_1 %f32vec4_0000 Lod %u32_0
6400 )";
6401
6402 const std::string extra =
6403 "\nOpCapability Image1D\n"
6404 "OpCapability ImageReadWriteLodAMD\n"
6405 "OpExtension \"SPV_AMD_shader_image_load_store_lod\"\n";
6406 CompileSuccessfully(
6407 GenerateShaderCode(body, extra, "Fragment", "", SPV_ENV_UNIVERSAL_1_1),
6408 SPV_ENV_UNIVERSAL_1_1);
6409 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_UNIVERSAL_1_1));
6410 }
6411
6412 TEST_F(ValidateImage, WriteLodAMDSuccess3) {
6413 const std::string body = R"(
6414 %img = OpLoad %type_image_f32_cube_0102_rgba32f %uniform_image_f32_cube_0102_rgba32f
6415 OpImageWrite %img %u32vec3_012 %f32vec4_0000 Lod %u32_0
6416 )";
6417
6418 const std::string extra =
6419 "\nOpCapability ImageCubeArray\n"
6420 "OpCapability ImageReadWriteLodAMD\n"
6421 "OpExtension \"SPV_AMD_shader_image_load_store_lod\"\n";
6422 CompileSuccessfully(
6423 GenerateShaderCode(body, extra, "Fragment", "", SPV_ENV_UNIVERSAL_1_1),
6424 SPV_ENV_UNIVERSAL_1_1);
6425 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_UNIVERSAL_1_1));
6426 }
6427
6428 TEST_F(ValidateImage, WriteLodAMDNeedCapability) {
6429 const std::string body = R"(
6430 %img = OpLoad %type_image_f32_cube_0102_rgba32f %uniform_image_f32_cube_0102_rgba32f
6431 OpImageWrite %img %u32vec3_012 %f32vec4_0000 Lod %u32_0
6432 )";
6433
6434 const std::string extra = "\nOpCapability ImageCubeArray\n";
6435 CompileSuccessfully(
6436 GenerateShaderCode(body, extra, "Fragment", "", SPV_ENV_UNIVERSAL_1_1),
6437 SPV_ENV_UNIVERSAL_1_1);
6438 ASSERT_EQ(SPV_ERROR_INVALID_DATA,
6439 ValidateInstructions(SPV_ENV_UNIVERSAL_1_1));
6440 EXPECT_THAT(getDiagnosticString(),
6441 HasSubstr("Image Operand Lod can only be used with ExplicitLod "
6442 "opcodes and OpImageFetch"));
6443 }
6444
6445 TEST_F(ValidateImage, SparseReadLodAMDSuccess) {
6446 const std::string body = R"(
6447 %img = OpLoad %type_image_f32_2d_0002 %uniform_image_f32_2d_0002
6448 %res1 = OpImageSparseRead %struct_u32_f32vec4 %img %u32vec2_01 Lod %u32_0
6449 )";
6450
6451 const std::string extra =
6452 "\nOpCapability StorageImageReadWithoutFormat\n"
6453 "OpCapability ImageReadWriteLodAMD\n"
6454 "OpExtension \"SPV_AMD_shader_image_load_store_lod\"\n";
6455 CompileSuccessfully(
6456 GenerateShaderCode(body, extra, "Fragment", "", SPV_ENV_UNIVERSAL_1_1),
6457 SPV_ENV_UNIVERSAL_1_1);
6458 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_UNIVERSAL_1_1));
6459 }
6460
6461 TEST_F(ValidateImage, SparseReadLodAMDNeedCapability) {
6462 const std::string body = R"(
6463 %img = OpLoad %type_image_f32_2d_0002 %uniform_image_f32_2d_0002
6464 %res1 = OpImageSparseRead %struct_u32_f32vec4 %img %u32vec2_01 Lod %u32_0
6465 )";
6466
6467 const std::string extra = "\nOpCapability StorageImageReadWithoutFormat\n";
6468 CompileSuccessfully(
6469 GenerateShaderCode(body, extra, "Fragment", "", SPV_ENV_UNIVERSAL_1_1),
6470 SPV_ENV_UNIVERSAL_1_1);
6471 ASSERT_EQ(SPV_ERROR_INVALID_DATA,
6472 ValidateInstructions(SPV_ENV_UNIVERSAL_1_1));
6473 EXPECT_THAT(getDiagnosticString(),
6474 HasSubstr("Image Operand Lod can only be used with ExplicitLod "
6475 "opcodes and OpImageFetch"));
6476 }
6477
6478 TEST_F(ValidateImage, GatherBiasAMDSuccess) {
6479 const std::string body = R"(
6480 %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
6481 %sampler = OpLoad %type_sampler %uniform_sampler
6482 %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
6483 %res1 = OpImageGather %f32vec4 %simg %f32vec4_0000 %u32_1 Bias %f32_1
6484 )";
6485
6486 const std::string extra = R"(
6487 OpCapability ImageGatherBiasLodAMD
6488 OpExtension "SPV_AMD_texture_gather_bias_lod"
6489 )";
6490 CompileSuccessfully(GenerateShaderCode(body, extra).c_str());
6491 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
6492 }
6493
6494 TEST_F(ValidateImage, GatherLodAMDSuccess) {
6495 const std::string body = R"(
6496 %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
6497 %sampler = OpLoad %type_sampler %uniform_sampler
6498 %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
6499 %res1 = OpImageGather %f32vec4 %simg %f32vec4_0000 %u32_1 Lod %f32_1
6500 )";
6501
6502 const std::string extra = R"(
6503 OpCapability ImageGatherBiasLodAMD
6504 OpExtension "SPV_AMD_texture_gather_bias_lod"
6505 )";
6506 CompileSuccessfully(GenerateShaderCode(body, extra).c_str());
6507 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
6508 }
6509
6510 TEST_F(ValidateImage, SparseGatherBiasAMDSuccess) {
6511 const std::string body = R"(
6512 %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
6513 %sampler = OpLoad %type_sampler %uniform_sampler
6514 %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
6515 %res1 = OpImageSparseGather %struct_u32_f32vec4 %simg %f32vec4_0000 %u32_1 Bias %f32_1
6516 )";
6517
6518 const std::string extra = R"(
6519 OpCapability ImageGatherBiasLodAMD
6520 OpExtension "SPV_AMD_texture_gather_bias_lod"
6521 )";
6522 CompileSuccessfully(GenerateShaderCode(body, extra).c_str());
6523 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
6524 }
6525
6526 TEST_F(ValidateImage, SparseGatherLodAMDSuccess) {
6527 const std::string body = R"(
6528 %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
6529 %sampler = OpLoad %type_sampler %uniform_sampler
6530 %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
6531 %res1 = OpImageSparseGather %struct_u32_f32vec4 %simg %f32vec4_0000 %u32_1 Lod %f32_1
6532 )";
6533
6534 const std::string extra = R"(
6535 OpCapability ImageGatherBiasLodAMD
6536 OpExtension "SPV_AMD_texture_gather_bias_lod"
6537 )";
6538 CompileSuccessfully(GenerateShaderCode(body, extra).c_str());
6539 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
6540 }
6541
6542 // No negative tests for ZeroExtend since we don't truly know the
6543 // texel format.
6544
6545 // Tests for 64-bit images
6546 static const std::string capabilities_and_extensions_image64 = R"(
6547 OpCapability Int64ImageEXT
6548 OpExtension "SPV_EXT_shader_image_int64"
6549 )";
6550 static const std::string capabilities_and_extensions_image64_atomic = R"(
6551 OpCapability Int64Atomics
6552 OpCapability Int64ImageEXT
6553 OpExtension "SPV_EXT_shader_image_int64"
6554 )";
6555 static const std::string declarations_image64 = R"(
6556 %type_image_u64_buffer_0002_r64ui = OpTypeImage %u64 Buffer 0 0 0 2 R64ui
6557 %ptr_Image_u64 = OpTypePointer Image %u64
6558 %ptr_image_u64_buffer_0002_r64ui = OpTypePointer Private %type_image_u64_buffer_0002_r64ui
6559 %private_image_u64_buffer_0002_r64ui = OpVariable %ptr_image_u64_buffer_0002_r64ui Private
6560 )";
6561 static const std::string declarations_image64i = R"(
6562 %type_image_s64_buffer_0002_r64i = OpTypeImage %s64 Buffer 0 0 0 2 R64i
6563 %ptr_Image_s64 = OpTypePointer Image %s64
6564 %ptr_image_s64_buffer_0002_r64i = OpTypePointer Private %type_image_s64_buffer_0002_r64i
6565 %private_image_s64_buffer_0002_r64i = OpVariable %ptr_image_s64_buffer_0002_r64i Private
6566 )";
6567
6568 TEST_F(ValidateImage, Image64MissingCapability) {
6569 CompileSuccessfully(GenerateShaderCode("", "", "Fragment", "",
6570 SPV_ENV_UNIVERSAL_1_3, "GLSL450",
6571 declarations_image64)
6572 .c_str());
6573 ASSERT_EQ(SPV_ERROR_INVALID_CAPABILITY, ValidateInstructions());
6574 }
6575
6576 TEST_F(ValidateImage, Image64MissingExtension) {
6577 const std::string extra = R"(
6578 OpCapability Int64ImageEXT
6579 )";
6580
6581 CompileSuccessfully(GenerateShaderCode("", extra, "Fragment", "",
6582 SPV_ENV_UNIVERSAL_1_3, "GLSL450",
6583 declarations_image64)
6584 .c_str());
6585 ASSERT_EQ(SPV_ERROR_MISSING_EXTENSION, ValidateInstructions());
6586 }
6587
6588 TEST_F(ValidateImage, ImageTexelPointer64Success) {
6589 const std::string body = R"(
6590 %texel_ptr = OpImageTexelPointer %ptr_Image_u64 %private_image_u64_buffer_0002_r64ui %u32_0 %u32_0
6591 %sum = OpAtomicIAdd %u64 %texel_ptr %u32_1 %u32_0 %u64_1
6592 )";
6593
6594 CompileSuccessfully(
6595 GenerateShaderCode(body, capabilities_and_extensions_image64_atomic,
6596 "Fragment", "", SPV_ENV_UNIVERSAL_1_3, "GLSL450",
6597 declarations_image64)
6598 .c_str());
6599 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
6600 }
6601
6602 TEST_F(ValidateImage, ImageTexelPointer64ResultTypeNotPointer) {
6603 const std::string body = R"(
6604 %texel_ptr = OpImageTexelPointer %type_image_u64_buffer_0002_r64ui %private_image_u64_buffer_0002_r64ui %u32_0 %u32_0
6605 %sum = OpAtomicIAdd %u64 %texel_ptr %u32_1 %u32_0 %u64_1
6606 )";
6607
6608 CompileSuccessfully(
6609 GenerateShaderCode(body, capabilities_and_extensions_image64_atomic,
6610 "Fragment", "", SPV_ENV_UNIVERSAL_1_3, "GLSL450",
6611 declarations_image64)
6612 .c_str());
6613 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
6614 EXPECT_THAT(getDiagnosticString(),
6615 HasSubstr("Expected Result Type to be a pointer"));
6616 }
6617
6618 TEST_F(ValidateImage, ImageTexelPointer64ResultTypeNotImageClass) {
6619 const std::string body = R"(
6620 %texel_ptr = OpImageTexelPointer %ptr_image_f32_cube_0101 %private_image_u64_buffer_0002_r64ui %u32_0 %u32_0
6621 %sum = OpAtomicIAdd %u64 %texel_ptr %u32_1 %u32_0 %u64_1
6622 )";
6623
6624 CompileSuccessfully(
6625 GenerateShaderCode(body, capabilities_and_extensions_image64_atomic,
6626 "Fragment", "", SPV_ENV_UNIVERSAL_1_3, "GLSL450",
6627 declarations_image64)
6628 .c_str());
6629 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
6630 EXPECT_THAT(getDiagnosticString(),
6631 HasSubstr("Expected Result Type to be a pointer whose "
6632 "Storage Class operand is Image"));
6633 }
6634
6635 TEST_F(ValidateImage, ImageTexelPointer64SampleNotZeroForImageWithMSZero) {
6636 const std::string body = R"(
6637 %texel_ptr = OpImageTexelPointer %ptr_Image_u64 %private_image_u64_buffer_0002_r64ui %u32_0 %u32_1
6638 %sum = OpAtomicIAdd %u64 %texel_ptr %u32_1 %u32_0 %u64_1
6639 )";
6640
6641 CompileSuccessfully(
6642 GenerateShaderCode(body, capabilities_and_extensions_image64_atomic,
6643 "Fragment", "", SPV_ENV_UNIVERSAL_1_3, "GLSL450",
6644 declarations_image64)
6645 .c_str());
6646 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
6647 EXPECT_THAT(getDiagnosticString(),
6648 HasSubstr("Expected Sample for Image with MS 0 to be a valid "
6649 "<id> for the value 0"));
6650 }
6651
6652 TEST_F(ValidateImage, ImageTexelPointerR32uiSuccessVulkan) {
6653 const std::string body = R"(
6654 %texel_ptr = OpImageTexelPointer %ptr_Image_u32 %private_image_u32_buffer_0002_r32ui %u32_0 %u32_0
6655 )";
6656
6657 spv_target_env env = SPV_ENV_VULKAN_1_0;
6658 CompileSuccessfully(GenerateShaderCode(body, "", "Fragment", "", env).c_str(),
6659 env);
6660 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions(env));
6661 }
6662
6663 TEST_F(ValidateImage, ImageTexelPointerR32iSuccessVulkan) {
6664 const std::string& declarations = R"(
6665 %type_image_s32_buffer_0002_r32i = OpTypeImage %s32 Buffer 0 0 0 2 R32i
6666 %ptr_Image_s32 = OpTypePointer Image %s32
6667 %ptr_image_s32_buffer_0002_r32i = OpTypePointer Private %type_image_s32_buffer_0002_r32i
6668 %private_image_s32_buffer_0002_r32i = OpVariable %ptr_image_s32_buffer_0002_r32i Private
6669 )";
6670
6671 const std::string body = R"(
6672 %texel_ptr = OpImageTexelPointer %ptr_Image_s32 %private_image_s32_buffer_0002_r32i %u32_0 %u32_0
6673 )";
6674
6675 spv_target_env env = SPV_ENV_VULKAN_1_0;
6676 CompileSuccessfully(
6677 GenerateShaderCode(body, "", "Fragment", "", env, "GLSL450", declarations)
6678 .c_str(),
6679 env);
6680 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions(env));
6681 }
6682
6683 TEST_F(ValidateImage, ImageTexelPointerR64uiSuccessVulkan) {
6684 const std::string body = R"(
6685 %texel_ptr = OpImageTexelPointer %ptr_Image_u64 %private_image_u64_buffer_0002_r64ui %u32_0 %u32_0
6686 )";
6687
6688 spv_target_env env = SPV_ENV_VULKAN_1_0;
6689 CompileSuccessfully(
6690 GenerateShaderCode(body, capabilities_and_extensions_image64, "Fragment",
6691 "", env, "GLSL450", declarations_image64)
6692 .c_str(),
6693 env);
6694 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions(env));
6695 }
6696
6697 TEST_F(ValidateImage, ImageTexelPointerR64iSuccessVulkan) {
6698 const std::string body = R"(
6699 %texel_ptr = OpImageTexelPointer %ptr_Image_s64 %private_image_s64_buffer_0002_r64i %u32_0 %u32_0
6700 )";
6701
6702 spv_target_env env = SPV_ENV_VULKAN_1_0;
6703 CompileSuccessfully(
6704 GenerateShaderCode(body, capabilities_and_extensions_image64, "Fragment",
6705 "", env, "GLSL450", declarations_image64i)
6706 .c_str(),
6707 env);
6708 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions(env));
6709 }
6710
6711 TEST_F(ValidateImage, ImageTexelPointerR32fSuccessVulkan) {
6712 const std::string& declarations = R"(
6713 %type_image_f32_buffer_0002_r32f = OpTypeImage %f32 Buffer 0 0 0 2 R32f
6714 %ptr_image_f32_buffer_0002_r32f = OpTypePointer Private %type_image_f32_buffer_0002_r32f
6715 %private_image_f32_buffer_0002_r32f = OpVariable %ptr_image_f32_buffer_0002_r32f Private
6716 )";
6717
6718 const std::string body = R"(
6719 %texel_ptr = OpImageTexelPointer %ptr_Image_f32 %private_image_f32_buffer_0002_r32f %u32_0 %u32_0
6720 )";
6721
6722 spv_target_env env = SPV_ENV_VULKAN_1_0;
6723 CompileSuccessfully(
6724 GenerateShaderCode(body, "", "Fragment", "", env, "GLSL450", declarations)
6725 .c_str(),
6726 env);
6727 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions(env));
6728 }
6729
6730 TEST_F(ValidateImage, ImageTexelPointerRgba32iVulkan) {
6731 const std::string& declarations = R"(
6732 %type_image_s32_buffer_0002_rgba32i = OpTypeImage %s32 Buffer 0 0 0 2 Rgba32i
6733 %ptr_Image_s32 = OpTypePointer Image %s32
6734 %ptr_image_s32_buffer_0002_rgba32i = OpTypePointer Private %type_image_s32_buffer_0002_rgba32i
6735 %private_image_s32_buffer_0002_rgba32i = OpVariable %ptr_image_s32_buffer_0002_rgba32i Private
6736 )";
6737
6738 const std::string body = R"(
6739 %texel_ptr = OpImageTexelPointer %ptr_Image_s32 %private_image_s32_buffer_0002_rgba32i %u32_0 %u32_0
6740 )";
6741
6742 spv_target_env env = SPV_ENV_VULKAN_1_0;
6743 CompileSuccessfully(
6744 GenerateShaderCode(body, "", "Fragment", "", env, "GLSL450", declarations)
6745 .c_str(),
6746 env);
6747 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions(env));
6748 EXPECT_THAT(getDiagnosticString(),
6749 AnyVUID("VUID-StandaloneSpirv-OpImageTexelPointer-04658"));
6750 EXPECT_THAT(getDiagnosticString(),
6751 HasSubstr("Expected the Image Format in Image to be R64i, R64ui, "
6752 "R32f, R32i, or R32ui for Vulkan environment using "
6753 "OpImageTexelPointer"));
6754 }
6755
6756 TEST_F(ValidateImage, ImageTexelPointerRgba16fVulkan) {
6757 const std::string& declarations = R"(
6758 %type_image_s32_buffer_0002_rgba16f = OpTypeImage %s32 Buffer 0 0 0 2 Rgba16f
6759 %ptr_Image_s32 = OpTypePointer Image %s32
6760 %ptr_image_s32_buffer_0002_rgba16f = OpTypePointer Private %type_image_s32_buffer_0002_rgba16f
6761 %private_image_s32_buffer_0002_rgba16f = OpVariable %ptr_image_s32_buffer_0002_rgba16f Private
6762 )";
6763
6764 const std::string body = R"(
6765 %texel_ptr = OpImageTexelPointer %ptr_Image_s32 %private_image_s32_buffer_0002_rgba16f %u32_0 %u32_0
6766 )";
6767
6768 spv_target_env env = SPV_ENV_VULKAN_1_0;
6769 CompileSuccessfully(
6770 GenerateShaderCode(body, "", "Fragment", "", env, "GLSL450", declarations)
6771 .c_str(),
6772 env);
6773 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions(env));
6774 EXPECT_THAT(getDiagnosticString(),
6775 AnyVUID("VUID-StandaloneSpirv-OpImageTexelPointer-04658"));
6776 EXPECT_THAT(getDiagnosticString(),
6777 HasSubstr("Expected the Image Format in Image to be R64i, R64ui, "
6778 "R32f, R32i, or R32ui for Vulkan environment using "
6779 "OpImageTexelPointer"));
6780 }
6781
6782 TEST_F(ValidateImage, ImageExecutionModeLimitationNoMode) {
6783 const std::string text = R"(
6784 OpCapability Shader
6785 OpMemoryModel Logical GLSL450
6786 OpEntryPoint GLCompute %2 " " %4
6787 %void = OpTypeVoid
6788 %8 = OpTypeFunction %void
6789 %float = OpTypeFloat 32
6790 %v4float = OpTypeVector %float 4
6791 %12 = OpTypeImage %float 2D 0 0 0 1 Rgba8ui
6792 %13 = OpTypeSampledImage %12
6793 %_ptr_UniformConstant_13 = OpTypePointer UniformConstant %13
6794 %5 = OpVariable %_ptr_UniformConstant_13 UniformConstant
6795 %_ptr_Input_v4float = OpTypePointer Input %v4float
6796 %4 = OpVariable %_ptr_Input_v4float Input
6797 %v2float = OpTypeVector %float 2
6798 %float_1_35631564en19 = OpConstant %float 1.35631564e-19
6799 %2 = OpFunction %void None %8
6800 %8224 = OpLabel
6801 %6 = OpLoad %13 %5
6802 %19 = OpLoad %v4float %4
6803 %20 = OpVectorShuffle %v2float %19 %19 0 1
6804 %21 = OpVectorTimesScalar %v2float %20 %float_1_35631564en19
6805 %65312 = OpImageSampleImplicitLod %v4float %6 %21
6806 OpUnreachable
6807 OpFunctionEnd
6808 )";
6809
6810 CompileSuccessfully(text);
6811 EXPECT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions());
6812 EXPECT_THAT(getDiagnosticString(),
6813 HasSubstr("ImplicitLod instructions require "
6814 "DerivativeGroupQuadsKHR or DerivativeGroupLinearKHR "
6815 "execution mode for GLCompute, MeshEXT or TaskEXT "
6816 "execution model"));
6817 }
6818
6819 TEST_F(ValidateImage, TypeSampledImageNotBufferPost1p6) {
6820 const std::string text = R"(
6821 OpCapability Shader
6822 OpCapability Linkage
6823 OpCapability SampledBuffer
6824 OpMemoryModel Logical GLSL450
6825 %float = OpTypeFloat 32
6826 %image = OpTypeImage %float Buffer 0 0 0 1 Unknown
6827 %sampled = OpTypeSampledImage %image
6828 )";
6829
6830 CompileSuccessfully(text, SPV_ENV_UNIVERSAL_1_6);
6831 EXPECT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions(SPV_ENV_UNIVERSAL_1_6));
6832 EXPECT_THAT(getDiagnosticString(),
6833 HasSubstr("In SPIR-V 1.6 or later, sampled image dimension must "
6834 "not be Buffer"));
6835 }
6836
6837 TEST_F(ValidateImage, NonTemporalImage) {
6838 const std::string text = R"(
6839 OpCapability Shader
6840 OpMemoryModel Logical GLSL450
6841 OpEntryPoint Fragment %2 " " %4 %5
6842 OpExecutionMode %2 OriginUpperLeft
6843 %void = OpTypeVoid
6844 %8 = OpTypeFunction %void
6845 %float = OpTypeFloat 32
6846 %v4float = OpTypeVector %float 4
6847 %12 = OpTypeImage %float 2D 0 0 0 1 Rgba8ui
6848 %13 = OpTypeSampledImage %12
6849 %_ptr_UniformConstant_13 = OpTypePointer UniformConstant %13
6850 %5 = OpVariable %_ptr_UniformConstant_13 UniformConstant
6851 %_ptr_Input_v4float = OpTypePointer Input %v4float
6852 %4 = OpVariable %_ptr_Input_v4float Input
6853 %v2float = OpTypeVector %float 2
6854 %float_1_35631564en19 = OpConstant %float 1.35631564e-19
6855 %2 = OpFunction %void None %8
6856 %8224 = OpLabel
6857 %6 = OpLoad %13 %5
6858 %19 = OpLoad %v4float %4
6859 %20 = OpVectorShuffle %v2float %19 %19 0 1
6860 %21 = OpVectorTimesScalar %v2float %20 %float_1_35631564en19
6861 %65312 = OpImageSampleImplicitLod %v4float %6 %21 Nontemporal
6862 OpReturn
6863 OpFunctionEnd
6864 )";
6865
6866 CompileSuccessfully(text, SPV_ENV_UNIVERSAL_1_6);
6867 EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_UNIVERSAL_1_6));
6868 }
6869
6870 TEST_F(ValidateImage, NVBindlessSamplerBuiltins) {
6871 const std::string text = R"(
6872 OpCapability Shader
6873 OpCapability Int64
6874 OpCapability Image1D
6875 OpCapability BindlessTextureNV
6876 OpExtension "SPV_NV_bindless_texture"
6877 %1 = OpExtInstImport "GLSL.std.450"
6878 OpMemoryModel Logical GLSL450
6879 OpSamplerImageAddressingModeNV 64
6880 OpEntryPoint Fragment %main "main"
6881 OpExecutionMode %main OriginUpperLeft
6882 OpSource GLSL 450
6883 OpName %main "main"
6884 OpName %s2D "s2D"
6885 OpName %textureHandle "textureHandle"
6886 OpName %i1D "i1D"
6887 OpName %s "s"
6888 OpName %temp "temp"
6889 %void = OpTypeVoid
6890 %3 = OpTypeFunction %void
6891 %float = OpTypeFloat 32
6892 %7 = OpTypeImage %float 2D 0 0 0 1 Unknown
6893 %8 = OpTypeSampledImage %7
6894 %_ptr_Function_8 = OpTypePointer Function %8
6895 %ulong = OpTypeInt 64 0
6896 %_ptr_Private_ulong = OpTypePointer Private %ulong
6897 %textureHandle = OpVariable %_ptr_Private_ulong Private
6898 %16 = OpTypeImage %float 1D 0 0 0 2 Rgba32f
6899 %_ptr_Function_16 = OpTypePointer Function %16
6900 %21 = OpTypeSampler
6901 %_ptr_Function_21 = OpTypePointer Function %21
6902 %_ptr_Function_ulong = OpTypePointer Function %ulong
6903 %main = OpFunction %void None %3
6904 %5 = OpLabel
6905 %s2D = OpVariable %_ptr_Function_8 Function
6906 %i1D = OpVariable %_ptr_Function_16 Function
6907 %s = OpVariable %_ptr_Function_21 Function
6908 %temp = OpVariable %_ptr_Function_ulong Function
6909 %14 = OpLoad %ulong %textureHandle
6910 %15 = OpConvertUToSampledImageNV %8 %14
6911 OpStore %s2D %15
6912 %19 = OpLoad %ulong %textureHandle
6913 %20 = OpConvertUToImageNV %16 %19
6914 OpStore %i1D %20
6915 %24 = OpLoad %ulong %textureHandle
6916 %25 = OpConvertUToSamplerNV %21 %24
6917 OpStore %s %25
6918 %28 = OpLoad %8 %s2D
6919 %29 = OpConvertSampledImageToUNV %ulong %28
6920 OpStore %temp %29
6921 %30 = OpLoad %16 %i1D
6922 %31 = OpConvertImageToUNV %ulong %30
6923 OpStore %temp %31
6924 %32 = OpLoad %21 %s
6925 %33 = OpConvertSamplerToUNV %ulong %32
6926 OpStore %temp %33
6927 OpReturn
6928 OpFunctionEnd
6929 )";
6930
6931 CompileSuccessfully(text, SPV_ENV_UNIVERSAL_1_3);
6932 EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_UNIVERSAL_1_3));
6933 }
6934
6935 TEST_F(ValidateImage, NVBindlessAddressingMode64) {
6936 std::string text = R"(
6937 OpCapability Shader
6938 OpCapability BindlessTextureNV
6939 OpExtension "SPV_NV_bindless_texture"
6940 OpMemoryModel Logical GLSL450
6941 OpSamplerImageAddressingModeNV 64
6942 OpEntryPoint GLCompute %func "main"
6943 %voidt = OpTypeVoid
6944 %uintt = OpTypeInt 32 0
6945 %funct = OpTypeFunction %voidt
6946 %func = OpFunction %voidt None %funct
6947 %entry = OpLabel
6948 %udef = OpUndef %uintt
6949 OpReturn
6950 OpFunctionEnd
6951 )";
6952 CompileSuccessfully(text, SPV_ENV_UNIVERSAL_1_3);
6953 EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_UNIVERSAL_1_3));
6954 }
6955
6956 TEST_F(ValidateImage, NVBindlessAddressingMode32) {
6957 std::string text = R"(
6958 OpCapability Shader
6959 OpCapability BindlessTextureNV
6960 OpExtension "SPV_NV_bindless_texture"
6961 OpMemoryModel Logical GLSL450
6962 OpSamplerImageAddressingModeNV 32
6963 OpEntryPoint GLCompute %func "main"
6964 %voidt = OpTypeVoid
6965 %uintt = OpTypeInt 32 0
6966 %funct = OpTypeFunction %voidt
6967 %func = OpFunction %voidt None %funct
6968 %entry = OpLabel
6969 %udef = OpUndef %uintt
6970 OpReturn
6971 OpFunctionEnd
6972 )";
6973 CompileSuccessfully(text, SPV_ENV_UNIVERSAL_1_3);
6974 EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_UNIVERSAL_1_3));
6975 }
6976
6977 TEST_F(ValidateImage, NVBindlessInvalidAddressingMode) {
6978 std::string text = R"(
6979 OpCapability Shader
6980 OpCapability BindlessTextureNV
6981 OpExtension "SPV_NV_bindless_texture"
6982 OpMemoryModel Logical GLSL450
6983 OpSamplerImageAddressingModeNV 0
6984 OpEntryPoint GLCompute %func "main"
6985 %voidt = OpTypeVoid
6986 %uintt = OpTypeInt 32 0
6987 %funct = OpTypeFunction %voidt
6988 %func = OpFunction %voidt None %funct
6989 %entry = OpLabel
6990 %udef = OpUndef %uintt
6991 OpReturn
6992 OpFunctionEnd
6993 )";
6994 CompileSuccessfully(text, SPV_ENV_UNIVERSAL_1_3);
6995 EXPECT_EQ(SPV_ERROR_INVALID_DATA,
6996 ValidateInstructions(SPV_ENV_UNIVERSAL_1_3));
6997 EXPECT_THAT(
6998 getDiagnosticString(),
6999 HasSubstr("OpSamplerImageAddressingModeNV bitwidth should be 64 or 32"));
7000 }
7001
7002 TEST_F(ValidateImage, QCOMImageProcessingBlockMatchSADNoDecorationA) {
7003 std::string text = R"(
7004 OpCapability Shader
7005 OpCapability TextureBlockMatchQCOM
7006 OpExtension "SPV_QCOM_image_processing"
7007 %1 = OpExtInstImport "GLSL.std.450"
7008 OpMemoryModel Logical GLSL450
7009 OpEntryPoint Fragment %2 "main" %3 %4 %5 %6
7010 OpExecutionMode %2 OriginUpperLeft
7011 OpDecorate %3 Location 0
7012 OpDecorate %4 DescriptorSet 0
7013 OpDecorate %4 Binding 1
7014 OpDecorate %5 DescriptorSet 0
7015 OpDecorate %5 Binding 3
7016 OpDecorate %6 DescriptorSet 0
7017 OpDecorate %6 Binding 2
7018 OpDecorate %6 BlockMatchTextureQCOM
7019 %void = OpTypeVoid
7020 %8 = OpTypeFunction %void
7021 %uint = OpTypeInt 32 0
7022 %v2uint = OpTypeVector %uint 2
7023 %_ptr_Function_v2uint = OpTypePointer Function %v2uint
7024 %float = OpTypeFloat 32
7025 %v4float = OpTypeVector %float 4
7026 %_ptr_Input_float = OpTypePointer Input %float
7027 %_ptr_Function_uint = OpTypePointer Function %uint
7028 %uint_4 = OpConstant %uint 4
7029 %17 = OpConstantComposite %v2uint %uint_4 %uint_4
7030 %_ptr_Output_v4float = OpTypePointer Output %v4float
7031 %3 = OpVariable %_ptr_Output_v4float Output
7032 %19 = OpTypeImage %float 2D 0 0 0 1 Unknown
7033 %_ptr_UniformConstant_19 = OpTypePointer UniformConstant %19
7034 %4 = OpVariable %_ptr_UniformConstant_19 UniformConstant
7035 %21 = OpTypeSampler
7036 %_ptr_UniformConstant_21 = OpTypePointer UniformConstant %21
7037 %5 = OpVariable %_ptr_UniformConstant_21 UniformConstant
7038 %23 = OpTypeSampledImage %19
7039 %6 = OpVariable %_ptr_UniformConstant_19 UniformConstant
7040 %2 = OpFunction %void None %8
7041 %24 = OpLabel
7042 %25 = OpVariable %_ptr_Function_v2uint Function
7043 %26 = OpLoad %19 %4
7044 %27 = OpLoad %21 %5
7045 %28 = OpSampledImage %23 %26 %27
7046 %29 = OpLoad %v2uint %25
7047 %30 = OpLoad %19 %6
7048 %31 = OpLoad %21 %5
7049 %32 = OpSampledImage %23 %30 %31
7050 %33 = OpImageBlockMatchSADQCOM %v4float %28 %29 %32 %29 %29
7051 OpStore %3 %33
7052 OpReturn
7053 OpFunctionEnd
7054 )";
7055 CompileSuccessfully(text, SPV_ENV_UNIVERSAL_1_4);
7056 EXPECT_EQ(SPV_ERROR_INVALID_DATA,
7057 ValidateInstructions(SPV_ENV_UNIVERSAL_1_4));
7058 EXPECT_THAT(getDiagnosticString(),
7059 HasSubstr("Missing decoration BlockMatchTextureQCOM"));
7060 }
7061
7062 TEST_F(ValidateImage, QCOMImageProcessingBlockMatchSADNoDecorationB) {
7063 std::string text = R"(
7064 OpCapability Shader
7065 OpCapability TextureBlockMatchQCOM
7066 OpExtension "SPV_QCOM_image_processing"
7067 %1 = OpExtInstImport "GLSL.std.450"
7068 OpMemoryModel Logical GLSL450
7069 OpEntryPoint Fragment %2 "main" %3 %4 %5 %6
7070 OpExecutionMode %2 OriginUpperLeft
7071 OpDecorate %3 Location 0
7072 OpDecorate %4 DescriptorSet 0
7073 OpDecorate %4 Binding 1
7074 OpDecorate %5 DescriptorSet 0
7075 OpDecorate %5 Binding 3
7076 OpDecorate %5 BlockMatchTextureQCOM
7077 OpDecorate %6 DescriptorSet 0
7078 OpDecorate %6 Binding 2
7079 %void = OpTypeVoid
7080 %8 = OpTypeFunction %void
7081 %uint = OpTypeInt 32 0
7082 %v2uint = OpTypeVector %uint 2
7083 %_ptr_Function_v2uint = OpTypePointer Function %v2uint
7084 %float = OpTypeFloat 32
7085 %v4float = OpTypeVector %float 4
7086 %_ptr_Input_float = OpTypePointer Input %float
7087 %_ptr_Function_uint = OpTypePointer Function %uint
7088 %uint_4 = OpConstant %uint 4
7089 %17 = OpConstantComposite %v2uint %uint_4 %uint_4
7090 %_ptr_Output_v4float = OpTypePointer Output %v4float
7091 %3 = OpVariable %_ptr_Output_v4float Output
7092 %19 = OpTypeImage %float 2D 0 0 0 1 Unknown
7093 %_ptr_UniformConstant_19 = OpTypePointer UniformConstant %19
7094 %4 = OpVariable %_ptr_UniformConstant_19 UniformConstant
7095 %21 = OpTypeSampler
7096 %_ptr_UniformConstant_21 = OpTypePointer UniformConstant %21
7097 %5 = OpVariable %_ptr_UniformConstant_21 UniformConstant
7098 %23 = OpTypeSampledImage %19
7099 %6 = OpVariable %_ptr_UniformConstant_19 UniformConstant
7100 %2 = OpFunction %void None %8
7101 %24 = OpLabel
7102 %25 = OpVariable %_ptr_Function_v2uint Function
7103 %26 = OpLoad %19 %4
7104 %27 = OpLoad %21 %5
7105 %28 = OpSampledImage %23 %26 %27
7106 %29 = OpLoad %v2uint %25
7107 %30 = OpLoad %19 %6
7108 %31 = OpLoad %21 %5
7109 %32 = OpSampledImage %23 %30 %31
7110 %33 = OpImageBlockMatchSADQCOM %v4float %28 %29 %32 %29 %29
7111 OpStore %3 %33
7112 OpReturn
7113 OpFunctionEnd
7114 )";
7115 CompileSuccessfully(text, SPV_ENV_UNIVERSAL_1_4);
7116 EXPECT_EQ(SPV_ERROR_INVALID_DATA,
7117 ValidateInstructions(SPV_ENV_UNIVERSAL_1_4));
7118 EXPECT_THAT(getDiagnosticString(),
7119 HasSubstr("Missing decoration BlockMatchTextureQCOM"));
7120 }
7121
7122 TEST_F(ValidateImage, QCOMImageProcessingBlockMatchSADNoDecorationC) {
7123 std::string text = R"(
7124 OpCapability Shader
7125 OpCapability TextureBlockMatchQCOM
7126 OpExtension "SPV_QCOM_image_processing"
7127 %1 = OpExtInstImport "GLSL.std.450"
7128 OpMemoryModel Logical GLSL450
7129 OpEntryPoint Fragment %2 "main" %3 %4 %5
7130 OpExecutionMode %2 OriginUpperLeft
7131 OpDecorate %3 Location 0
7132 OpDecorate %4 DescriptorSet 0
7133 OpDecorate %4 Binding 4
7134 OpDecorate %5 DescriptorSet 0
7135 OpDecorate %5 Binding 5
7136 OpDecorate %5 BlockMatchTextureQCOM
7137 %void = OpTypeVoid
7138 %7 = OpTypeFunction %void
7139 %uint = OpTypeInt 32 0
7140 %v2uint = OpTypeVector %uint 2
7141 %_ptr_Function_v2uint = OpTypePointer Function %v2uint
7142 %float = OpTypeFloat 32
7143 %v4float = OpTypeVector %float 4
7144 %_ptr_Input_v4float = OpTypePointer Input %v4float
7145 %_ptr_Input_float = OpTypePointer Input %float
7146 %_ptr_Function_uint = OpTypePointer Function %uint
7147 %_ptr_Output_v4float = OpTypePointer Output %v4float
7148 %3 = OpVariable %_ptr_Output_v4float Output
7149 %18 = OpTypeImage %float 2D 0 0 0 1 Unknown
7150 %19 = OpTypeSampledImage %18
7151 %_ptr_UniformConstant_19 = OpTypePointer UniformConstant %19
7152 %4 = OpVariable %_ptr_UniformConstant_19 UniformConstant
7153 %5 = OpVariable %_ptr_UniformConstant_19 UniformConstant
7154 %21 = OpTypeImage %float 2D 0 1 0 1 Unknown
7155 %2 = OpFunction %void None %7
7156 %22 = OpLabel
7157 %23 = OpVariable %_ptr_Function_v2uint Function
7158 %24 = OpLoad %19 %4
7159 %25 = OpLoad %v2uint %23
7160 %26 = OpLoad %19 %5
7161 %27 = OpLoad %v2uint %23
7162 %28 = OpLoad %v2uint %23
7163 %29 = OpImageBlockMatchSADQCOM %v4float %24 %25 %26 %27 %28
7164 OpStore %3 %29
7165 OpReturn
7166 OpFunctionEnd
7167 )";
7168 CompileSuccessfully(text, SPV_ENV_UNIVERSAL_1_4);
7169 EXPECT_EQ(SPV_ERROR_INVALID_DATA,
7170 ValidateInstructions(SPV_ENV_UNIVERSAL_1_4));
7171 EXPECT_THAT(getDiagnosticString(),
7172 HasSubstr("Missing decoration BlockMatchTextureQCOM"));
7173 }
7174
7175 TEST_F(ValidateImage, QCOMImageProcessingBlockMatchSADNoDecorationD) {
7176 std::string text = R"(
7177 OpCapability Shader
7178 OpCapability TextureBlockMatchQCOM
7179 OpExtension "SPV_QCOM_image_processing"
7180 %1 = OpExtInstImport "GLSL.std.450"
7181 OpMemoryModel Logical GLSL450
7182 OpEntryPoint Fragment %2 "main" %3 %4 %5
7183 OpExecutionMode %2 OriginUpperLeft
7184 OpDecorate %3 Location 0
7185 OpDecorate %4 DescriptorSet 0
7186 OpDecorate %4 Binding 4
7187 OpDecorate %4 BlockMatchTextureQCOM
7188 OpDecorate %5 DescriptorSet 0
7189 OpDecorate %5 Binding 5
7190 %void = OpTypeVoid
7191 %7 = OpTypeFunction %void
7192 %uint = OpTypeInt 32 0
7193 %v2uint = OpTypeVector %uint 2
7194 %_ptr_Function_v2uint = OpTypePointer Function %v2uint
7195 %float = OpTypeFloat 32
7196 %v4float = OpTypeVector %float 4
7197 %_ptr_Input_v4float = OpTypePointer Input %v4float
7198 %_ptr_Input_float = OpTypePointer Input %float
7199 %_ptr_Function_uint = OpTypePointer Function %uint
7200 %_ptr_Output_v4float = OpTypePointer Output %v4float
7201 %3 = OpVariable %_ptr_Output_v4float Output
7202 %18 = OpTypeImage %float 2D 0 0 0 1 Unknown
7203 %19 = OpTypeSampledImage %18
7204 %_ptr_UniformConstant_19 = OpTypePointer UniformConstant %19
7205 %4 = OpVariable %_ptr_UniformConstant_19 UniformConstant
7206 %5 = OpVariable %_ptr_UniformConstant_19 UniformConstant
7207 %21 = OpTypeImage %float 2D 0 1 0 1 Unknown
7208 %2 = OpFunction %void None %7
7209 %22 = OpLabel
7210 %23 = OpVariable %_ptr_Function_v2uint Function
7211 %24 = OpLoad %19 %4
7212 %25 = OpLoad %v2uint %23
7213 %26 = OpLoad %19 %5
7214 %27 = OpLoad %v2uint %23
7215 %28 = OpLoad %v2uint %23
7216 %29 = OpImageBlockMatchSADQCOM %v4float %24 %25 %26 %27 %28
7217 OpStore %3 %29
7218 OpReturn
7219 OpFunctionEnd
7220 )";
7221 CompileSuccessfully(text, SPV_ENV_UNIVERSAL_1_4);
7222 EXPECT_EQ(SPV_ERROR_INVALID_DATA,
7223 ValidateInstructions(SPV_ENV_UNIVERSAL_1_4));
7224 EXPECT_THAT(getDiagnosticString(),
7225 HasSubstr("Missing decoration BlockMatchTextureQCOM"));
7226 }
7227
7228 TEST_F(ValidateImage, QCOMImageProcessingBlockMatchSSDNoDecorationA) {
7229 std::string text = R"(
7230 OpCapability Shader
7231 OpCapability TextureBlockMatchQCOM
7232 OpExtension "SPV_QCOM_image_processing"
7233 %1 = OpExtInstImport "GLSL.std.450"
7234 OpMemoryModel Logical GLSL450
7235 OpEntryPoint Fragment %2 "main" %3 %4 %5 %6
7236 OpExecutionMode %2 OriginUpperLeft
7237 OpDecorate %3 Location 0
7238 OpDecorate %4 DescriptorSet 0
7239 OpDecorate %4 Binding 1
7240 OpDecorate %5 DescriptorSet 0
7241 OpDecorate %5 Binding 3
7242 OpDecorate %6 DescriptorSet 0
7243 OpDecorate %6 Binding 2
7244 OpDecorate %6 BlockMatchTextureQCOM
7245 %void = OpTypeVoid
7246 %8 = OpTypeFunction %void
7247 %uint = OpTypeInt 32 0
7248 %v2uint = OpTypeVector %uint 2
7249 %_ptr_Function_v2uint = OpTypePointer Function %v2uint
7250 %float = OpTypeFloat 32
7251 %v4float = OpTypeVector %float 4
7252 %_ptr_Input_float = OpTypePointer Input %float
7253 %_ptr_Function_uint = OpTypePointer Function %uint
7254 %uint_4 = OpConstant %uint 4
7255 %17 = OpConstantComposite %v2uint %uint_4 %uint_4
7256 %_ptr_Output_v4float = OpTypePointer Output %v4float
7257 %3 = OpVariable %_ptr_Output_v4float Output
7258 %19 = OpTypeImage %float 2D 0 0 0 1 Unknown
7259 %_ptr_UniformConstant_19 = OpTypePointer UniformConstant %19
7260 %4 = OpVariable %_ptr_UniformConstant_19 UniformConstant
7261 %21 = OpTypeSampler
7262 %_ptr_UniformConstant_21 = OpTypePointer UniformConstant %21
7263 %5 = OpVariable %_ptr_UniformConstant_21 UniformConstant
7264 %23 = OpTypeSampledImage %19
7265 %6 = OpVariable %_ptr_UniformConstant_19 UniformConstant
7266 %2 = OpFunction %void None %8
7267 %24 = OpLabel
7268 %25 = OpVariable %_ptr_Function_v2uint Function
7269 %26 = OpLoad %19 %4
7270 %27 = OpLoad %21 %5
7271 %28 = OpSampledImage %23 %26 %27
7272 %29 = OpLoad %v2uint %25
7273 %30 = OpLoad %19 %6
7274 %31 = OpLoad %21 %5
7275 %32 = OpSampledImage %23 %30 %31
7276 %33 = OpImageBlockMatchSSDQCOM %v4float %28 %29 %32 %29 %29
7277 OpStore %3 %33
7278 OpReturn
7279 OpFunctionEnd
7280 )";
7281 CompileSuccessfully(text, SPV_ENV_UNIVERSAL_1_4);
7282 EXPECT_EQ(SPV_ERROR_INVALID_DATA,
7283 ValidateInstructions(SPV_ENV_UNIVERSAL_1_4));
7284 EXPECT_THAT(getDiagnosticString(),
7285 HasSubstr("Missing decoration BlockMatchTextureQCOM"));
7286 }
7287
7288 TEST_F(ValidateImage, QCOMImageProcessingBlockMatchSSDNoDecorationB) {
7289 std::string text = R"(
7290 OpCapability Shader
7291 OpCapability TextureBlockMatchQCOM
7292 OpExtension "SPV_QCOM_image_processing"
7293 %1 = OpExtInstImport "GLSL.std.450"
7294 OpMemoryModel Logical GLSL450
7295 OpEntryPoint Fragment %2 "main" %3 %4 %5 %6
7296 OpExecutionMode %2 OriginUpperLeft
7297 OpDecorate %3 Location 0
7298 OpDecorate %4 DescriptorSet 0
7299 OpDecorate %4 Binding 1
7300 OpDecorate %5 DescriptorSet 0
7301 OpDecorate %5 Binding 3
7302 OpDecorate %5 BlockMatchTextureQCOM
7303 OpDecorate %6 DescriptorSet 0
7304 OpDecorate %6 Binding 2
7305 %void = OpTypeVoid
7306 %8 = OpTypeFunction %void
7307 %uint = OpTypeInt 32 0
7308 %v2uint = OpTypeVector %uint 2
7309 %_ptr_Function_v2uint = OpTypePointer Function %v2uint
7310 %float = OpTypeFloat 32
7311 %v4float = OpTypeVector %float 4
7312 %_ptr_Input_float = OpTypePointer Input %float
7313 %_ptr_Function_uint = OpTypePointer Function %uint
7314 %uint_4 = OpConstant %uint 4
7315 %17 = OpConstantComposite %v2uint %uint_4 %uint_4
7316 %_ptr_Output_v4float = OpTypePointer Output %v4float
7317 %3 = OpVariable %_ptr_Output_v4float Output
7318 %19 = OpTypeImage %float 2D 0 0 0 1 Unknown
7319 %_ptr_UniformConstant_19 = OpTypePointer UniformConstant %19
7320 %4 = OpVariable %_ptr_UniformConstant_19 UniformConstant
7321 %21 = OpTypeSampler
7322 %_ptr_UniformConstant_21 = OpTypePointer UniformConstant %21
7323 %5 = OpVariable %_ptr_UniformConstant_21 UniformConstant
7324 %23 = OpTypeSampledImage %19
7325 %6 = OpVariable %_ptr_UniformConstant_19 UniformConstant
7326 %2 = OpFunction %void None %8
7327 %24 = OpLabel
7328 %25 = OpVariable %_ptr_Function_v2uint Function
7329 %26 = OpLoad %19 %4
7330 %27 = OpLoad %21 %5
7331 %28 = OpSampledImage %23 %26 %27
7332 %29 = OpLoad %v2uint %25
7333 %30 = OpLoad %19 %6
7334 %31 = OpLoad %21 %5
7335 %32 = OpSampledImage %23 %30 %31
7336 %33 = OpImageBlockMatchSSDQCOM %v4float %28 %29 %32 %29 %29
7337 OpStore %3 %33
7338 OpReturn
7339 OpFunctionEnd
7340 )";
7341 CompileSuccessfully(text, SPV_ENV_UNIVERSAL_1_4);
7342 EXPECT_EQ(SPV_ERROR_INVALID_DATA,
7343 ValidateInstructions(SPV_ENV_UNIVERSAL_1_4));
7344 EXPECT_THAT(getDiagnosticString(),
7345 HasSubstr("Missing decoration BlockMatchTextureQCOM"));
7346 }
7347
7348 TEST_F(ValidateImage, QCOMImageProcessingBlockMatchSSDNoDecorationC) {
7349 std::string text = R"(
7350 OpCapability Shader
7351 OpCapability TextureBlockMatchQCOM
7352 OpExtension "SPV_QCOM_image_processing"
7353 %1 = OpExtInstImport "GLSL.std.450"
7354 OpMemoryModel Logical GLSL450
7355 OpEntryPoint Fragment %2 "main" %3 %4 %5
7356 OpExecutionMode %2 OriginUpperLeft
7357 OpDecorate %3 Location 0
7358 OpDecorate %4 DescriptorSet 0
7359 OpDecorate %4 Binding 4
7360 OpDecorate %5 DescriptorSet 0
7361 OpDecorate %5 Binding 5
7362 OpDecorate %5 BlockMatchTextureQCOM
7363 %void = OpTypeVoid
7364 %7 = OpTypeFunction %void
7365 %uint = OpTypeInt 32 0
7366 %v2uint = OpTypeVector %uint 2
7367 %_ptr_Function_v2uint = OpTypePointer Function %v2uint
7368 %float = OpTypeFloat 32
7369 %v4float = OpTypeVector %float 4
7370 %_ptr_Input_v4float = OpTypePointer Input %v4float
7371 %_ptr_Input_float = OpTypePointer Input %float
7372 %_ptr_Function_uint = OpTypePointer Function %uint
7373 %_ptr_Output_v4float = OpTypePointer Output %v4float
7374 %3 = OpVariable %_ptr_Output_v4float Output
7375 %18 = OpTypeImage %float 2D 0 0 0 1 Unknown
7376 %19 = OpTypeSampledImage %18
7377 %_ptr_UniformConstant_19 = OpTypePointer UniformConstant %19
7378 %4 = OpVariable %_ptr_UniformConstant_19 UniformConstant
7379 %5 = OpVariable %_ptr_UniformConstant_19 UniformConstant
7380 %21 = OpTypeImage %float 2D 0 1 0 1 Unknown
7381 %2 = OpFunction %void None %7
7382 %22 = OpLabel
7383 %23 = OpVariable %_ptr_Function_v2uint Function
7384 %24 = OpLoad %19 %4
7385 %25 = OpLoad %v2uint %23
7386 %26 = OpLoad %19 %5
7387 %27 = OpLoad %v2uint %23
7388 %28 = OpLoad %v2uint %23
7389 %29 = OpImageBlockMatchSSDQCOM %v4float %24 %25 %26 %27 %28
7390 OpStore %3 %29
7391 OpReturn
7392 OpFunctionEnd
7393 )";
7394 CompileSuccessfully(text, SPV_ENV_UNIVERSAL_1_4);
7395 EXPECT_EQ(SPV_ERROR_INVALID_DATA,
7396 ValidateInstructions(SPV_ENV_UNIVERSAL_1_4));
7397 EXPECT_THAT(getDiagnosticString(),
7398 HasSubstr("Missing decoration BlockMatchTextureQCOM"));
7399 }
7400
7401 TEST_F(ValidateImage, QCOMImageProcessingBlockMatchSSDNoDecorationD) {
7402 std::string text = R"(
7403 OpCapability Shader
7404 OpCapability TextureBlockMatchQCOM
7405 OpExtension "SPV_QCOM_image_processing"
7406 %1 = OpExtInstImport "GLSL.std.450"
7407 OpMemoryModel Logical GLSL450
7408 OpEntryPoint Fragment %2 "main" %3 %4 %5
7409 OpExecutionMode %2 OriginUpperLeft
7410 OpDecorate %3 Location 0
7411 OpDecorate %4 DescriptorSet 0
7412 OpDecorate %4 Binding 4
7413 OpDecorate %4 BlockMatchTextureQCOM
7414 OpDecorate %5 DescriptorSet 0
7415 OpDecorate %5 Binding 5
7416 %void = OpTypeVoid
7417 %7 = OpTypeFunction %void
7418 %uint = OpTypeInt 32 0
7419 %v2uint = OpTypeVector %uint 2
7420 %_ptr_Function_v2uint = OpTypePointer Function %v2uint
7421 %float = OpTypeFloat 32
7422 %v4float = OpTypeVector %float 4
7423 %_ptr_Input_v4float = OpTypePointer Input %v4float
7424 %_ptr_Input_float = OpTypePointer Input %float
7425 %_ptr_Function_uint = OpTypePointer Function %uint
7426 %_ptr_Output_v4float = OpTypePointer Output %v4float
7427 %3 = OpVariable %_ptr_Output_v4float Output
7428 %18 = OpTypeImage %float 2D 0 0 0 1 Unknown
7429 %19 = OpTypeSampledImage %18
7430 %_ptr_UniformConstant_19 = OpTypePointer UniformConstant %19
7431 %4 = OpVariable %_ptr_UniformConstant_19 UniformConstant
7432 %5 = OpVariable %_ptr_UniformConstant_19 UniformConstant
7433 %21 = OpTypeImage %float 2D 0 1 0 1 Unknown
7434 %2 = OpFunction %void None %7
7435 %22 = OpLabel
7436 %23 = OpVariable %_ptr_Function_v2uint Function
7437 %24 = OpLoad %19 %4
7438 %25 = OpLoad %v2uint %23
7439 %26 = OpLoad %19 %5
7440 %27 = OpLoad %v2uint %23
7441 %28 = OpLoad %v2uint %23
7442 %29 = OpImageBlockMatchSSDQCOM %v4float %24 %25 %26 %27 %28
7443 OpStore %3 %29
7444 OpReturn
7445 OpFunctionEnd
7446 )";
7447 CompileSuccessfully(text, SPV_ENV_UNIVERSAL_1_4);
7448 EXPECT_EQ(SPV_ERROR_INVALID_DATA,
7449 ValidateInstructions(SPV_ENV_UNIVERSAL_1_4));
7450 EXPECT_THAT(getDiagnosticString(),
7451 HasSubstr("Missing decoration BlockMatchTextureQCOM"));
7452 }
7453
7454 TEST_F(ValidateImage, QCOMImageProcessingSampleWeightedNoDecorationA) {
7455 std::string text = R"(
7456 OpCapability Shader
7457 OpCapability TextureSampleWeightedQCOM
7458 OpExtension "SPV_QCOM_image_processing"
7459 %1 = OpExtInstImport "GLSL.std.450"
7460 OpMemoryModel Logical GLSL450
7461 OpEntryPoint Fragment %2 "main" %3 %4 %5 %6 %7
7462 OpExecutionMode %2 OriginUpperLeft
7463 OpDecorate %3 Location 0
7464 OpDecorate %4 DescriptorSet 0
7465 OpDecorate %4 Binding 1
7466 OpDecorate %5 DescriptorSet 0
7467 OpDecorate %5 Binding 3
7468 OpDecorate %6 Location 0
7469 OpDecorate %7 DescriptorSet 0
7470 OpDecorate %7 Binding 0
7471 %void = OpTypeVoid
7472 %9 = OpTypeFunction %void
7473 %float = OpTypeFloat 32
7474 %v4float = OpTypeVector %float 4
7475 %_ptr_Output_v4float = OpTypePointer Output %v4float
7476 %3 = OpVariable %_ptr_Output_v4float Output
7477 %13 = OpTypeImage %float 2D 0 0 0 1 Unknown
7478 %_ptr_UniformConstant_13 = OpTypePointer UniformConstant %13
7479 %4 = OpVariable %_ptr_UniformConstant_13 UniformConstant
7480 %15 = OpTypeSampler
7481 %_ptr_UniformConstant_15 = OpTypePointer UniformConstant %15
7482 %5 = OpVariable %_ptr_UniformConstant_15 UniformConstant
7483 %17 = OpTypeSampledImage %13
7484 %_ptr_Input_v4float = OpTypePointer Input %v4float
7485 %6 = OpVariable %_ptr_Input_v4float Input
7486 %v2float = OpTypeVector %float 2
7487 %20 = OpTypeImage %float 2D 0 1 0 1 Unknown
7488 %_ptr_UniformConstant_20 = OpTypePointer UniformConstant %20
7489 %7 = OpVariable %_ptr_UniformConstant_20 UniformConstant
7490 %22 = OpTypeSampledImage %20
7491 %_ptr_UniformConstant_17 = OpTypePointer UniformConstant %17
7492 %2 = OpFunction %void None %9
7493 %24 = OpLabel
7494 %25 = OpLoad %13 %4
7495 %26 = OpLoad %15 %5
7496 %27 = OpSampledImage %17 %25 %26
7497 %28 = OpLoad %v4float %6
7498 %29 = OpVectorShuffle %v2float %28 %28 0 1
7499 %30 = OpLoad %20 %7
7500 %31 = OpLoad %15 %5
7501 %32 = OpSampledImage %22 %30 %31
7502 %33 = OpImageSampleWeightedQCOM %v4float %27 %29 %32
7503 OpStore %3 %33
7504 OpReturn
7505 OpFunctionEnd
7506 )";
7507 CompileSuccessfully(text, SPV_ENV_UNIVERSAL_1_4);
7508 EXPECT_EQ(SPV_ERROR_INVALID_DATA,
7509 ValidateInstructions(SPV_ENV_UNIVERSAL_1_4));
7510 EXPECT_THAT(getDiagnosticString(),
7511 HasSubstr("Missing decoration WeightTextureQCOM"));
7512 }
7513
7514 TEST_F(ValidateImage, QCOMImageProcessingSampleWeightedNoDecorationB) {
7515 std::string text = R"(
7516 OpCapability Shader
7517 OpCapability TextureSampleWeightedQCOM
7518 OpExtension "SPV_QCOM_image_processing"
7519 %1 = OpExtInstImport "GLSL.std.450"
7520 OpMemoryModel Logical GLSL450
7521 OpEntryPoint Fragment %2 "main" %3 %4 %5 %6
7522 OpExecutionMode %2 OriginUpperLeft
7523 OpDecorate %3 Location 0
7524 OpDecorate %4 Location 0
7525 OpDecorate %5 DescriptorSet 0
7526 OpDecorate %5 Binding 4
7527 OpDecorate %6 DescriptorSet 0
7528 OpDecorate %6 Binding 5
7529 %void = OpTypeVoid
7530 %8 = OpTypeFunction %void
7531 %float = OpTypeFloat 32
7532 %v4float = OpTypeVector %float 4
7533 %_ptr_Output_v4float = OpTypePointer Output %v4float
7534 %3 = OpVariable %_ptr_Output_v4float Output
7535 %12 = OpTypeImage %float 2D 0 0 0 1 Unknown
7536 %_ptr_UniformConstant_12 = OpTypePointer UniformConstant %12
7537 %14 = OpTypeSampler
7538 %_ptr_UniformConstant_14 = OpTypePointer UniformConstant %14
7539 %16 = OpTypeSampledImage %12
7540 %_ptr_Input_v4float = OpTypePointer Input %v4float
7541 %4 = OpVariable %_ptr_Input_v4float Input
7542 %v2float = OpTypeVector %float 2
7543 %19 = OpTypeImage %float 2D 0 1 0 1 Unknown
7544 %_ptr_UniformConstant_19 = OpTypePointer UniformConstant %19
7545 %21 = OpTypeSampledImage %19
7546 %_ptr_UniformConstant_16 = OpTypePointer UniformConstant %16
7547 %5 = OpVariable %_ptr_UniformConstant_16 UniformConstant
7548 %_ptr_UniformConstant_21 = OpTypePointer UniformConstant %21
7549 %6 = OpVariable %_ptr_UniformConstant_21 UniformConstant
7550 %2 = OpFunction %void None %8
7551 %24 = OpLabel
7552 %25 = OpLoad %16 %5
7553 %26 = OpLoad %v4float %4
7554 %27 = OpVectorShuffle %v2float %26 %26 0 1
7555 %28 = OpLoad %21 %6
7556 %29 = OpImageSampleWeightedQCOM %v4float %25 %27 %28
7557 OpStore %3 %29
7558 OpReturn
7559 OpFunctionEnd
7560 )";
7561 CompileSuccessfully(text, SPV_ENV_UNIVERSAL_1_4);
7562 EXPECT_EQ(SPV_ERROR_INVALID_DATA,
7563 ValidateInstructions(SPV_ENV_UNIVERSAL_1_4));
7564 EXPECT_THAT(getDiagnosticString(),
7565 HasSubstr("Missing decoration WeightTextureQCOM"));
7566 }
7567
7568 TEST_F(ValidateImage, QCOMImageProcessingBlockMatchWindowSADInvalidUseA) {
7569 std::string text = R"(
7570 ; SPIR-V
7571 ; Version: 1.0
7572 ; Generator: Khronos Glslang Reference Front End; 11
7573 ; Bound: 79
7574 ; Schema: 0
7575 OpCapability Shader
7576 OpCapability TextureBlockMatchQCOM
7577 OpExtension "SPV_QCOM_image_processing"
7578 %1 = OpExtInstImport "GLSL.std.450"
7579 OpMemoryModel Logical GLSL450
7580 OpEntryPoint Fragment %main "main" %100 %101 %102 %103 %104
7581 OpExecutionMode %main OriginUpperLeft
7582 OpDecorate %100 Location 0
7583 OpDecorate %101 Location 0
7584 OpDecorate %102 DescriptorSet 0
7585 OpDecorate %102 Binding 1
7586 OpDecorate %103 DescriptorSet 0
7587 OpDecorate %103 Binding 3
7588 OpDecorate %104 DescriptorSet 0
7589 OpDecorate %104 Binding 2
7590 OpDecorate %102 BlockMatchTextureQCOM
7591 OpDecorate %104 BlockMatchTextureQCOM
7592 %void = OpTypeVoid
7593 %3 = OpTypeFunction %void
7594 %uint = OpTypeInt 32 0
7595 %v2uint = OpTypeVector %uint 2
7596 %_ptr_Function_v2uint = OpTypePointer Function %v2uint
7597 %float = OpTypeFloat 32
7598 %v4float = OpTypeVector %float 4
7599 %_ptr_Input_v4float = OpTypePointer Input %v4float
7600 %100 = OpVariable %_ptr_Input_v4float Input
7601 %_ptr_Output_v4float = OpTypePointer Output %v4float
7602 %101 = OpVariable %_ptr_Output_v4float Output
7603 %42 = OpTypeImage %float 2D 0 0 0 1 Unknown
7604 %_ptr_UniformConstant_42 = OpTypePointer UniformConstant %42
7605 %102 = OpVariable %_ptr_UniformConstant_42 UniformConstant
7606 %46 = OpTypeSampler
7607 %_ptr_UniformConstant_46 = OpTypePointer UniformConstant %46
7608 %103 = OpVariable %_ptr_UniformConstant_46 UniformConstant
7609 %50 = OpTypeSampledImage %42
7610 %104 = OpVariable %_ptr_UniformConstant_42 UniformConstant
7611 %v2float = OpTypeVector %float 2
7612 %main = OpFunction %void None %3
7613 %5 = OpLabel
7614 %15 = OpVariable %_ptr_Function_v2uint Function
7615 %45 = OpLoad %42 %102
7616 %49 = OpLoad %46 %103
7617 %51 = OpSampledImage %50 %45 %49
7618 %52 = OpLoad %v2uint %15
7619 %54 = OpLoad %42 %104
7620 %55 = OpLoad %46 %103
7621 %56 = OpSampledImage %50 %54 %55
7622 %57 = OpLoad %v2uint %15
7623 %58 = OpLoad %v2uint %15
7624 %59 = OpImageBlockMatchSADQCOM %v4float %51 %52 %56 %57 %58
7625 OpStore %101 %59
7626 %69 = OpLoad %42 %102
7627 %70 = OpLoad %46 %103
7628 %71 = OpSampledImage %50 %69 %70
7629 %73 = OpLoad %v4float %100
7630 %74 = OpVectorShuffle %v2float %73 %73 0 0
7631 %75 = OpImageSampleImplicitLod %v4float %71 %74
7632 OpStore %101 %75
7633 OpReturn
7634 OpFunctionEnd
7635 )";
7636 CompileSuccessfully(text, SPV_ENV_UNIVERSAL_1_4);
7637 EXPECT_EQ(SPV_ERROR_INVALID_DATA,
7638 ValidateInstructions(SPV_ENV_UNIVERSAL_1_4));
7639 EXPECT_THAT(
7640 getDiagnosticString(),
7641 HasSubstr("Illegal use of QCOM image processing decorated texture"));
7642 }
7643
7644 TEST_F(ValidateImage, QCOMImageProcessingBlockMatchSADInvalidUseB) {
7645 std::string text = R"(
7646 ; SPIR-V
7647 ; Version: 1.0
7648 ; Generator: Khronos Glslang Reference Front End; 11
7649 ; Bound: 79
7650 ; Schema: 0
7651 OpCapability Shader
7652 OpCapability TextureBlockMatchQCOM
7653 OpExtension "SPV_QCOM_image_processing"
7654 %1 = OpExtInstImport "GLSL.std.450"
7655 OpMemoryModel Logical GLSL450
7656 OpEntryPoint Fragment %main "main" %100 %101 %102 %103 %104
7657 OpExecutionMode %main OriginUpperLeft
7658 OpDecorate %100 Location 0
7659 OpDecorate %101 Location 0
7660 OpDecorate %102 DescriptorSet 0
7661 OpDecorate %102 Binding 1
7662 OpDecorate %103 DescriptorSet 0
7663 OpDecorate %103 Binding 3
7664 OpDecorate %104 DescriptorSet 0
7665 OpDecorate %104 Binding 2
7666 OpDecorate %102 BlockMatchTextureQCOM
7667 OpDecorate %104 BlockMatchTextureQCOM
7668 %void = OpTypeVoid
7669 %3 = OpTypeFunction %void
7670 %uint = OpTypeInt 32 0
7671 %v2uint = OpTypeVector %uint 2
7672 %_ptr_Function_v2uint = OpTypePointer Function %v2uint
7673 %float = OpTypeFloat 32
7674 %v4float = OpTypeVector %float 4
7675 %_ptr_Input_v4float = OpTypePointer Input %v4float
7676 %100 = OpVariable %_ptr_Input_v4float Input
7677 %_ptr_Output_v4float = OpTypePointer Output %v4float
7678 %101 = OpVariable %_ptr_Output_v4float Output
7679 %42 = OpTypeImage %float 2D 0 0 0 1 Unknown
7680 %_ptr_UniformConstant_42 = OpTypePointer UniformConstant %42
7681 %102 = OpVariable %_ptr_UniformConstant_42 UniformConstant
7682 %46 = OpTypeSampler
7683 %_ptr_UniformConstant_46 = OpTypePointer UniformConstant %46
7684 %103 = OpVariable %_ptr_UniformConstant_46 UniformConstant
7685 %50 = OpTypeSampledImage %42
7686 %104 = OpVariable %_ptr_UniformConstant_42 UniformConstant
7687 %v2float = OpTypeVector %float 2
7688 %main = OpFunction %void None %3
7689 %5 = OpLabel
7690 %15 = OpVariable %_ptr_Function_v2uint Function
7691 %45 = OpLoad %42 %102
7692 %49 = OpLoad %46 %103
7693 %51 = OpSampledImage %50 %45 %49
7694 %52 = OpLoad %v2uint %15
7695 %54 = OpLoad %42 %104
7696 %55 = OpLoad %46 %103
7697 %56 = OpSampledImage %50 %54 %55
7698 %57 = OpLoad %v2uint %15
7699 %58 = OpLoad %v2uint %15
7700 %59 = OpImageBlockMatchSADQCOM %v4float %51 %52 %56 %57 %58
7701 OpStore %101 %59
7702 %69 = OpLoad %42 %104
7703 %70 = OpLoad %46 %103
7704 %71 = OpSampledImage %50 %69 %70
7705 %73 = OpLoad %v4float %100
7706 %74 = OpVectorShuffle %v2float %73 %73 0 0
7707 %75 = OpImageSampleImplicitLod %v4float %71 %74
7708 OpStore %101 %75
7709 OpReturn
7710 OpFunctionEnd
7711 )";
7712 CompileSuccessfully(text, SPV_ENV_UNIVERSAL_1_4);
7713 EXPECT_EQ(SPV_ERROR_INVALID_DATA,
7714 ValidateInstructions(SPV_ENV_UNIVERSAL_1_4));
7715 EXPECT_THAT(
7716 getDiagnosticString(),
7717 HasSubstr("Illegal use of QCOM image processing decorated texture"));
7718 }
7719
7720 TEST_F(ValidateImage, QCOMImageProcessingBlockMatchSADInvalidUseC) {
7721 std::string text = R"(
7722 OpCapability Shader
7723 OpCapability TextureBlockMatchQCOM
7724 OpExtension "SPV_QCOM_image_processing"
7725 %1 = OpExtInstImport "GLSL.std.450"
7726 OpMemoryModel Logical GLSL450
7727 OpEntryPoint Fragment %2 "main" %3 %4 %5 %6
7728 OpExecutionMode %2 OriginUpperLeft
7729 OpDecorate %3 Location 0
7730 OpDecorate %4 Location 0
7731 OpDecorate %5 DescriptorSet 0
7732 OpDecorate %5 Binding 4
7733 OpDecorate %6 DescriptorSet 0
7734 OpDecorate %6 Binding 5
7735 OpDecorate %5 BlockMatchTextureQCOM
7736 OpDecorate %6 BlockMatchTextureQCOM
7737 %void = OpTypeVoid
7738 %8 = OpTypeFunction %void
7739 %uint = OpTypeInt 32 0
7740 %v2uint = OpTypeVector %uint 2
7741 %_ptr_Function_v2uint = OpTypePointer Function %v2uint
7742 %float = OpTypeFloat 32
7743 %v4float = OpTypeVector %float 4
7744 %_ptr_Input_v4float = OpTypePointer Input %v4float
7745 %3 = OpVariable %_ptr_Input_v4float Input
7746 %uint_4 = OpConstant %uint 4
7747 %16 = OpConstantComposite %v2uint %uint_4 %uint_4
7748 %_ptr_Output_v4float = OpTypePointer Output %v4float
7749 %4 = OpVariable %_ptr_Output_v4float Output
7750 %18 = OpTypeImage %float 2D 0 0 0 1 Unknown
7751 %_ptr_UniformConstant_18 = OpTypePointer UniformConstant %18
7752 %20 = OpTypeSampledImage %18
7753 %_ptr_UniformConstant_20 = OpTypePointer UniformConstant %20
7754 %5 = OpVariable %_ptr_UniformConstant_20 UniformConstant
7755 %6 = OpVariable %_ptr_UniformConstant_20 UniformConstant
7756 %v2float = OpTypeVector %float 2
7757 %23 = OpTypeImage %float 2D 0 1 0 1 Unknown
7758 %2 = OpFunction %void None %8
7759 %24 = OpLabel
7760 %25 = OpVariable %_ptr_Function_v2uint Function
7761 OpStore %25 %16
7762 %26 = OpLoad %20 %5
7763 %27 = OpLoad %v2uint %25
7764 %28 = OpLoad %20 %6
7765 %29 = OpLoad %v2uint %25
7766 %30 = OpLoad %v2uint %25
7767 %31 = OpImageBlockMatchSADQCOM %v4float %26 %27 %28 %29 %30
7768 OpStore %4 %31
7769 %32 = OpLoad %20 %5
7770 %33 = OpLoad %v4float %3
7771 %34 = OpVectorShuffle %v2float %33 %33 0 2
7772 %35 = OpImageSampleImplicitLod %v4float %32 %34
7773 OpStore %4 %35
7774 OpReturn
7775 OpFunctionEnd
7776 )";
7777 CompileSuccessfully(text, SPV_ENV_UNIVERSAL_1_4);
7778 EXPECT_EQ(SPV_ERROR_INVALID_DATA,
7779 ValidateInstructions(SPV_ENV_UNIVERSAL_1_4));
7780 EXPECT_THAT(
7781 getDiagnosticString(),
7782 HasSubstr("Illegal use of QCOM image processing decorated texture"));
7783 }
7784
7785 TEST_F(ValidateImage, QCOMImageProcessingBlockMatchSADInvalidUseD) {
7786 std::string text = R"(
7787 OpCapability Shader
7788 OpCapability TextureBlockMatchQCOM
7789 OpExtension "SPV_QCOM_image_processing"
7790 %1 = OpExtInstImport "GLSL.std.450"
7791 OpMemoryModel Logical GLSL450
7792 OpEntryPoint Fragment %2 "main" %3 %4 %5 %6
7793 OpExecutionMode %2 OriginUpperLeft
7794 OpDecorate %3 Location 0
7795 OpDecorate %4 Location 0
7796 OpDecorate %5 DescriptorSet 0
7797 OpDecorate %5 Binding 4
7798 OpDecorate %6 DescriptorSet 0
7799 OpDecorate %6 Binding 5
7800 OpDecorate %5 BlockMatchTextureQCOM
7801 OpDecorate %6 BlockMatchTextureQCOM
7802 %void = OpTypeVoid
7803 %8 = OpTypeFunction %void
7804 %uint = OpTypeInt 32 0
7805 %v2uint = OpTypeVector %uint 2
7806 %_ptr_Function_v2uint = OpTypePointer Function %v2uint
7807 %float = OpTypeFloat 32
7808 %v4float = OpTypeVector %float 4
7809 %_ptr_Input_v4float = OpTypePointer Input %v4float
7810 %3 = OpVariable %_ptr_Input_v4float Input
7811 %uint_4 = OpConstant %uint 4
7812 %16 = OpConstantComposite %v2uint %uint_4 %uint_4
7813 %_ptr_Output_v4float = OpTypePointer Output %v4float
7814 %4 = OpVariable %_ptr_Output_v4float Output
7815 %18 = OpTypeImage %float 2D 0 0 0 1 Unknown
7816 %_ptr_UniformConstant_18 = OpTypePointer UniformConstant %18
7817 %20 = OpTypeSampledImage %18
7818 %_ptr_UniformConstant_20 = OpTypePointer UniformConstant %20
7819 %5 = OpVariable %_ptr_UniformConstant_20 UniformConstant
7820 %6 = OpVariable %_ptr_UniformConstant_20 UniformConstant
7821 %v2float = OpTypeVector %float 2
7822 %23 = OpTypeImage %float 2D 0 1 0 1 Unknown
7823 %2 = OpFunction %void None %8
7824 %24 = OpLabel
7825 %25 = OpVariable %_ptr_Function_v2uint Function
7826 OpStore %25 %16
7827 %26 = OpLoad %20 %5
7828 %27 = OpLoad %v2uint %25
7829 %28 = OpLoad %20 %6
7830 %29 = OpLoad %v2uint %25
7831 %30 = OpLoad %v2uint %25
7832 %31 = OpImageBlockMatchSADQCOM %v4float %26 %27 %28 %29 %30
7833 OpStore %4 %31
7834 %32 = OpLoad %20 %6
7835 %33 = OpLoad %v4float %3
7836 %34 = OpVectorShuffle %v2float %33 %33 0 2
7837 %35 = OpImageSampleImplicitLod %v4float %32 %34
7838 OpStore %4 %35
7839 OpReturn
7840 OpFunctionEnd
7841 )";
7842 CompileSuccessfully(text, SPV_ENV_UNIVERSAL_1_4);
7843 EXPECT_EQ(SPV_ERROR_INVALID_DATA,
7844 ValidateInstructions(SPV_ENV_UNIVERSAL_1_4));
7845 EXPECT_THAT(
7846 getDiagnosticString(),
7847 HasSubstr("Illegal use of QCOM image processing decorated texture"));
7848 }
7849
7850 TEST_F(ValidateImage, QCOMImageProcessingBlockMatchSSDInvalidUseA) {
7851 std::string text = R"(
7852 ; SPIR-V
7853 ; Version: 1.0
7854 ; Generator: Khronos Glslang Reference Front End; 11
7855 ; Bound: 79
7856 ; Schema: 0
7857 OpCapability Shader
7858 OpCapability TextureBlockMatchQCOM
7859 OpExtension "SPV_QCOM_image_processing"
7860 %1 = OpExtInstImport "GLSL.std.450"
7861 OpMemoryModel Logical GLSL450
7862 OpEntryPoint Fragment %main "main" %100 %101 %102 %103 %104
7863 OpExecutionMode %main OriginUpperLeft
7864 OpDecorate %100 Location 0
7865 OpDecorate %101 Location 0
7866 OpDecorate %102 DescriptorSet 0
7867 OpDecorate %102 Binding 1
7868 OpDecorate %103 DescriptorSet 0
7869 OpDecorate %103 Binding 3
7870 OpDecorate %104 DescriptorSet 0
7871 OpDecorate %104 Binding 2
7872 OpDecorate %102 BlockMatchTextureQCOM
7873 OpDecorate %104 BlockMatchTextureQCOM
7874 %void = OpTypeVoid
7875 %3 = OpTypeFunction %void
7876 %uint = OpTypeInt 32 0
7877 %v2uint = OpTypeVector %uint 2
7878 %_ptr_Function_v2uint = OpTypePointer Function %v2uint
7879 %float = OpTypeFloat 32
7880 %v4float = OpTypeVector %float 4
7881 %_ptr_Input_v4float = OpTypePointer Input %v4float
7882 %100 = OpVariable %_ptr_Input_v4float Input
7883 %_ptr_Output_v4float = OpTypePointer Output %v4float
7884 %101 = OpVariable %_ptr_Output_v4float Output
7885 %42 = OpTypeImage %float 2D 0 0 0 1 Unknown
7886 %_ptr_UniformConstant_42 = OpTypePointer UniformConstant %42
7887 %102 = OpVariable %_ptr_UniformConstant_42 UniformConstant
7888 %46 = OpTypeSampler
7889 %_ptr_UniformConstant_46 = OpTypePointer UniformConstant %46
7890 %103 = OpVariable %_ptr_UniformConstant_46 UniformConstant
7891 %50 = OpTypeSampledImage %42
7892 %104 = OpVariable %_ptr_UniformConstant_42 UniformConstant
7893 %v2float = OpTypeVector %float 2
7894 %main = OpFunction %void None %3
7895 %5 = OpLabel
7896 %15 = OpVariable %_ptr_Function_v2uint Function
7897 %45 = OpLoad %42 %102
7898 %49 = OpLoad %46 %103
7899 %51 = OpSampledImage %50 %45 %49
7900 %52 = OpLoad %v2uint %15
7901 %54 = OpLoad %42 %104
7902 %55 = OpLoad %46 %103
7903 %56 = OpSampledImage %50 %54 %55
7904 %57 = OpLoad %v2uint %15
7905 %58 = OpLoad %v2uint %15
7906 %59 = OpImageBlockMatchSSDQCOM %v4float %51 %52 %56 %57 %58
7907 OpStore %101 %59
7908 %69 = OpLoad %42 %102
7909 %70 = OpLoad %46 %103
7910 %71 = OpSampledImage %50 %69 %70
7911 %73 = OpLoad %v4float %100
7912 %74 = OpVectorShuffle %v2float %73 %73 0 0
7913 %75 = OpImageSampleImplicitLod %v4float %71 %74
7914 OpStore %101 %75
7915 OpReturn
7916 OpFunctionEnd
7917 )";
7918 CompileSuccessfully(text, SPV_ENV_UNIVERSAL_1_4);
7919 EXPECT_EQ(SPV_ERROR_INVALID_DATA,
7920 ValidateInstructions(SPV_ENV_UNIVERSAL_1_4));
7921 EXPECT_THAT(
7922 getDiagnosticString(),
7923 HasSubstr("Illegal use of QCOM image processing decorated texture"));
7924 }
7925
7926 TEST_F(ValidateImage, QCOMImageProcessingBlockMatchSSDInvalidUseB) {
7927 std::string text = R"(
7928 ; SPIR-V
7929 ; Version: 1.0
7930 ; Generator: Khronos Glslang Reference Front End; 11
7931 ; Bound: 79
7932 ; Schema: 0
7933 OpCapability Shader
7934 OpCapability TextureBlockMatchQCOM
7935 OpExtension "SPV_QCOM_image_processing"
7936 %1 = OpExtInstImport "GLSL.std.450"
7937 OpMemoryModel Logical GLSL450
7938 OpEntryPoint Fragment %main "main" %100 %101 %102 %103 %104
7939 OpExecutionMode %main OriginUpperLeft
7940 OpDecorate %100 Location 0
7941 OpDecorate %101 Location 0
7942 OpDecorate %102 DescriptorSet 0
7943 OpDecorate %102 Binding 1
7944 OpDecorate %103 DescriptorSet 0
7945 OpDecorate %103 Binding 3
7946 OpDecorate %104 DescriptorSet 0
7947 OpDecorate %104 Binding 2
7948 OpDecorate %102 BlockMatchTextureQCOM
7949 OpDecorate %104 BlockMatchTextureQCOM
7950 %void = OpTypeVoid
7951 %3 = OpTypeFunction %void
7952 %uint = OpTypeInt 32 0
7953 %v2uint = OpTypeVector %uint 2
7954 %_ptr_Function_v2uint = OpTypePointer Function %v2uint
7955 %float = OpTypeFloat 32
7956 %v4float = OpTypeVector %float 4
7957 %_ptr_Input_v4float = OpTypePointer Input %v4float
7958 %100 = OpVariable %_ptr_Input_v4float Input
7959 %_ptr_Output_v4float = OpTypePointer Output %v4float
7960 %101 = OpVariable %_ptr_Output_v4float Output
7961 %42 = OpTypeImage %float 2D 0 0 0 1 Unknown
7962 %_ptr_UniformConstant_42 = OpTypePointer UniformConstant %42
7963 %102 = OpVariable %_ptr_UniformConstant_42 UniformConstant
7964 %46 = OpTypeSampler
7965 %_ptr_UniformConstant_46 = OpTypePointer UniformConstant %46
7966 %103 = OpVariable %_ptr_UniformConstant_46 UniformConstant
7967 %50 = OpTypeSampledImage %42
7968 %104 = OpVariable %_ptr_UniformConstant_42 UniformConstant
7969 %v2float = OpTypeVector %float 2
7970 %main = OpFunction %void None %3
7971 %5 = OpLabel
7972 %15 = OpVariable %_ptr_Function_v2uint Function
7973 %45 = OpLoad %42 %102
7974 %49 = OpLoad %46 %103
7975 %51 = OpSampledImage %50 %45 %49
7976 %52 = OpLoad %v2uint %15
7977 %54 = OpLoad %42 %104
7978 %55 = OpLoad %46 %103
7979 %56 = OpSampledImage %50 %54 %55
7980 %57 = OpLoad %v2uint %15
7981 %58 = OpLoad %v2uint %15
7982 %59 = OpImageBlockMatchSSDQCOM %v4float %51 %52 %56 %57 %58
7983 OpStore %101 %59
7984 %69 = OpLoad %42 %104
7985 %70 = OpLoad %46 %103
7986 %71 = OpSampledImage %50 %69 %70
7987 %73 = OpLoad %v4float %100
7988 %74 = OpVectorShuffle %v2float %73 %73 0 0
7989 %75 = OpImageSampleImplicitLod %v4float %71 %74
7990 OpStore %101 %75
7991 OpReturn
7992 OpFunctionEnd
7993 )";
7994 CompileSuccessfully(text, SPV_ENV_UNIVERSAL_1_4);
7995 EXPECT_EQ(SPV_ERROR_INVALID_DATA,
7996 ValidateInstructions(SPV_ENV_UNIVERSAL_1_4));
7997 EXPECT_THAT(
7998 getDiagnosticString(),
7999 HasSubstr("Illegal use of QCOM image processing decorated texture"));
8000 }
8001
8002 TEST_F(ValidateImage, QCOMImageProcessingBlockMatchSSDInvalidUseC) {
8003 std::string text = R"(
8004 OpCapability Shader
8005 OpCapability TextureBlockMatchQCOM
8006 OpExtension "SPV_QCOM_image_processing"
8007 %1 = OpExtInstImport "GLSL.std.450"
8008 OpMemoryModel Logical GLSL450
8009 OpEntryPoint Fragment %2 "main" %3 %4 %5 %6
8010 OpExecutionMode %2 OriginUpperLeft
8011 OpDecorate %3 Location 0
8012 OpDecorate %4 Location 0
8013 OpDecorate %5 DescriptorSet 0
8014 OpDecorate %5 Binding 4
8015 OpDecorate %6 DescriptorSet 0
8016 OpDecorate %6 Binding 5
8017 OpDecorate %5 BlockMatchTextureQCOM
8018 OpDecorate %6 BlockMatchTextureQCOM
8019 %void = OpTypeVoid
8020 %8 = OpTypeFunction %void
8021 %uint = OpTypeInt 32 0
8022 %v2uint = OpTypeVector %uint 2
8023 %_ptr_Function_v2uint = OpTypePointer Function %v2uint
8024 %float = OpTypeFloat 32
8025 %v4float = OpTypeVector %float 4
8026 %_ptr_Input_v4float = OpTypePointer Input %v4float
8027 %3 = OpVariable %_ptr_Input_v4float Input
8028 %uint_4 = OpConstant %uint 4
8029 %16 = OpConstantComposite %v2uint %uint_4 %uint_4
8030 %_ptr_Output_v4float = OpTypePointer Output %v4float
8031 %4 = OpVariable %_ptr_Output_v4float Output
8032 %18 = OpTypeImage %float 2D 0 0 0 1 Unknown
8033 %_ptr_UniformConstant_18 = OpTypePointer UniformConstant %18
8034 %20 = OpTypeSampledImage %18
8035 %_ptr_UniformConstant_20 = OpTypePointer UniformConstant %20
8036 %5 = OpVariable %_ptr_UniformConstant_20 UniformConstant
8037 %6 = OpVariable %_ptr_UniformConstant_20 UniformConstant
8038 %v2float = OpTypeVector %float 2
8039 %23 = OpTypeImage %float 2D 0 1 0 1 Unknown
8040 %2 = OpFunction %void None %8
8041 %24 = OpLabel
8042 %25 = OpVariable %_ptr_Function_v2uint Function
8043 OpStore %25 %16
8044 %26 = OpLoad %20 %5
8045 %27 = OpLoad %v2uint %25
8046 %28 = OpLoad %20 %6
8047 %29 = OpLoad %v2uint %25
8048 %30 = OpLoad %v2uint %25
8049 %31 = OpImageBlockMatchSSDQCOM %v4float %26 %27 %28 %29 %30
8050 OpStore %4 %31
8051 %32 = OpLoad %20 %5
8052 %33 = OpLoad %v4float %3
8053 %34 = OpVectorShuffle %v2float %33 %33 0 2
8054 %35 = OpImageSampleImplicitLod %v4float %32 %34
8055 OpStore %4 %35
8056 OpReturn
8057 OpFunctionEnd
8058 )";
8059 CompileSuccessfully(text, SPV_ENV_UNIVERSAL_1_4);
8060 EXPECT_EQ(SPV_ERROR_INVALID_DATA,
8061 ValidateInstructions(SPV_ENV_UNIVERSAL_1_4));
8062 EXPECT_THAT(
8063 getDiagnosticString(),
8064 HasSubstr("Illegal use of QCOM image processing decorated texture"));
8065 }
8066
8067 TEST_F(ValidateImage, QCOMImageProcessingBlockMatchSSDInvalidUseD) {
8068 std::string text = R"(
8069 OpCapability Shader
8070 OpCapability TextureBlockMatchQCOM
8071 OpExtension "SPV_QCOM_image_processing"
8072 %1 = OpExtInstImport "GLSL.std.450"
8073 OpMemoryModel Logical GLSL450
8074 OpEntryPoint Fragment %2 "main" %3 %4 %5 %6
8075 OpExecutionMode %2 OriginUpperLeft
8076 OpDecorate %3 Location 0
8077 OpDecorate %4 Location 0
8078 OpDecorate %5 DescriptorSet 0
8079 OpDecorate %5 Binding 4
8080 OpDecorate %6 DescriptorSet 0
8081 OpDecorate %6 Binding 5
8082 OpDecorate %5 BlockMatchTextureQCOM
8083 OpDecorate %6 BlockMatchTextureQCOM
8084 %void = OpTypeVoid
8085 %8 = OpTypeFunction %void
8086 %uint = OpTypeInt 32 0
8087 %v2uint = OpTypeVector %uint 2
8088 %_ptr_Function_v2uint = OpTypePointer Function %v2uint
8089 %float = OpTypeFloat 32
8090 %v4float = OpTypeVector %float 4
8091 %_ptr_Input_v4float = OpTypePointer Input %v4float
8092 %3 = OpVariable %_ptr_Input_v4float Input
8093 %uint_4 = OpConstant %uint 4
8094 %16 = OpConstantComposite %v2uint %uint_4 %uint_4
8095 %_ptr_Output_v4float = OpTypePointer Output %v4float
8096 %4 = OpVariable %_ptr_Output_v4float Output
8097 %18 = OpTypeImage %float 2D 0 0 0 1 Unknown
8098 %_ptr_UniformConstant_18 = OpTypePointer UniformConstant %18
8099 %20 = OpTypeSampledImage %18
8100 %_ptr_UniformConstant_20 = OpTypePointer UniformConstant %20
8101 %5 = OpVariable %_ptr_UniformConstant_20 UniformConstant
8102 %6 = OpVariable %_ptr_UniformConstant_20 UniformConstant
8103 %v2float = OpTypeVector %float 2
8104 %23 = OpTypeImage %float 2D 0 1 0 1 Unknown
8105 %2 = OpFunction %void None %8
8106 %24 = OpLabel
8107 %25 = OpVariable %_ptr_Function_v2uint Function
8108 OpStore %25 %16
8109 %26 = OpLoad %20 %5
8110 %27 = OpLoad %v2uint %25
8111 %28 = OpLoad %20 %6
8112 %29 = OpLoad %v2uint %25
8113 %30 = OpLoad %v2uint %25
8114 %31 = OpImageBlockMatchSSDQCOM %v4float %26 %27 %28 %29 %30
8115 OpStore %4 %31
8116 %32 = OpLoad %20 %6
8117 %33 = OpLoad %v4float %3
8118 %34 = OpVectorShuffle %v2float %33 %33 0 2
8119 %35 = OpImageSampleImplicitLod %v4float %32 %34
8120 OpStore %4 %35
8121 OpReturn
8122 OpFunctionEnd
8123 )";
8124 CompileSuccessfully(text, SPV_ENV_UNIVERSAL_1_4);
8125 EXPECT_EQ(SPV_ERROR_INVALID_DATA,
8126 ValidateInstructions(SPV_ENV_UNIVERSAL_1_4));
8127 EXPECT_THAT(
8128 getDiagnosticString(),
8129 HasSubstr("Illegal use of QCOM image processing decorated texture"));
8130 }
8131
8132 TEST_F(ValidateImage, QCOMImageProcessingSampleWeightedInvalidUseA) {
8133 std::string text = R"(
8134 OpCapability Shader
8135 OpCapability TextureSampleWeightedQCOM
8136 OpExtension "SPV_QCOM_image_processing"
8137 %1 = OpExtInstImport "GLSL.std.450"
8138 OpMemoryModel Logical GLSL450
8139 OpEntryPoint Fragment %2 "main" %3 %4 %5 %6
8140 OpExecutionMode %2 OriginUpperLeft
8141 OpDecorate %3 Location 0
8142 OpDecorate %4 Location 0
8143 OpDecorate %5 DescriptorSet 0
8144 OpDecorate %5 Binding 4
8145 OpDecorate %6 DescriptorSet 0
8146 OpDecorate %6 Binding 5
8147 OpDecorate %6 WeightTextureQCOM
8148 %void = OpTypeVoid
8149 %8 = OpTypeFunction %void
8150 %float = OpTypeFloat 32
8151 %v4float = OpTypeVector %float 4
8152 %_ptr_Output_v4float = OpTypePointer Output %v4float
8153 %3 = OpVariable %_ptr_Output_v4float Output
8154 %12 = OpTypeImage %float 2D 0 0 0 1 Unknown
8155 %_ptr_UniformConstant_12 = OpTypePointer UniformConstant %12
8156 %14 = OpTypeSampledImage %12
8157 %_ptr_Input_v4float = OpTypePointer Input %v4float
8158 %4 = OpVariable %_ptr_Input_v4float Input
8159 %v2float = OpTypeVector %float 2
8160 %17 = OpTypeImage %float 2D 0 1 0 1 Unknown
8161 %_ptr_UniformConstant_17 = OpTypePointer UniformConstant %17
8162 %19 = OpTypeSampledImage %17
8163 %_ptr_UniformConstant_14 = OpTypePointer UniformConstant %14
8164 %5 = OpVariable %_ptr_UniformConstant_14 UniformConstant
8165 %_ptr_UniformConstant_19 = OpTypePointer UniformConstant %19
8166 %6 = OpVariable %_ptr_UniformConstant_19 UniformConstant
8167 %v3float = OpTypeVector %float 3
8168 %2 = OpFunction %void None %8
8169 %23 = OpLabel
8170 %24 = OpLoad %v4float %4
8171 %25 = OpVectorShuffle %v2float %24 %24 0 1
8172 %26 = OpLoad %14 %5
8173 %27 = OpLoad %v4float %4
8174 %28 = OpVectorShuffle %v2float %27 %27 0 1
8175 %29 = OpLoad %19 %6
8176 %30 = OpImageSampleWeightedQCOM %v4float %26 %28 %29
8177 OpStore %3 %30
8178 %31 = OpLoad %19 %6
8179 %32 = OpLoad %v4float %4
8180 %33 = OpVectorShuffle %v3float %32 %32 0 1 0
8181 %34 = OpCompositeExtract %float %33 0
8182 %35 = OpCompositeExtract %float %33 1
8183 %36 = OpCompositeExtract %float %33 2
8184 %37 = OpCompositeConstruct %v3float %34 %35 %36
8185 %38 = OpImageSampleImplicitLod %v4float %31 %37
8186 OpStore %3 %38
8187 OpReturn
8188 OpFunctionEnd
8189 )";
8190 CompileSuccessfully(text, SPV_ENV_UNIVERSAL_1_4);
8191 EXPECT_EQ(SPV_ERROR_INVALID_DATA,
8192 ValidateInstructions(SPV_ENV_UNIVERSAL_1_4));
8193 EXPECT_THAT(
8194 getDiagnosticString(),
8195 HasSubstr("Illegal use of QCOM image processing decorated texture"));
8196 }
8197
8198 TEST_F(ValidateImage, QCOMImageProcessingSampleWeightedInvalidUseB) {
8199 std::string text = R"(
8200 OpCapability Shader
8201 OpCapability TextureSampleWeightedQCOM
8202 OpExtension "SPV_QCOM_image_processing"
8203 %1 = OpExtInstImport "GLSL.std.450"
8204 OpMemoryModel Logical GLSL450
8205 OpEntryPoint Fragment %2 "main" %3 %4 %5 %6 %7
8206 OpExecutionMode %2 OriginUpperLeft
8207 OpDecorate %3 Location 0
8208 OpDecorate %5 DescriptorSet 0
8209 OpDecorate %5 Binding 1
8210 OpDecorate %6 DescriptorSet 0
8211 OpDecorate %6 Binding 3
8212 OpDecorate %4 Location 0
8213 OpDecorate %7 DescriptorSet 0
8214 OpDecorate %7 Binding 0
8215 OpDecorate %7 WeightTextureQCOM
8216 %void = OpTypeVoid
8217 %9 = OpTypeFunction %void
8218 %float = OpTypeFloat 32
8219 %v4float = OpTypeVector %float 4
8220 %_ptr_Output_v4float = OpTypePointer Output %v4float
8221 %3 = OpVariable %_ptr_Output_v4float Output
8222 %13 = OpTypeImage %float 2D 0 0 0 1 Unknown
8223 %_ptr_UniformConstant_13 = OpTypePointer UniformConstant %13
8224 %5 = OpVariable %_ptr_UniformConstant_13 UniformConstant
8225 %15 = OpTypeSampler
8226 %_ptr_UniformConstant_15 = OpTypePointer UniformConstant %15
8227 %6 = OpVariable %_ptr_UniformConstant_15 UniformConstant
8228 %17 = OpTypeSampledImage %13
8229 %_ptr_Input_v4float = OpTypePointer Input %v4float
8230 %4 = OpVariable %_ptr_Input_v4float Input
8231 %v2float = OpTypeVector %float 2
8232 %20 = OpTypeImage %float 2D 0 1 0 1 Unknown
8233 %_ptr_UniformConstant_20 = OpTypePointer UniformConstant %20
8234 %7 = OpVariable %_ptr_UniformConstant_20 UniformConstant
8235 %22 = OpTypeSampledImage %20
8236 %v3float = OpTypeVector %float 3
8237 %2 = OpFunction %void None %9
8238 %24 = OpLabel
8239 %25 = OpLoad %13 %5
8240 %26 = OpLoad %15 %6
8241 %27 = OpSampledImage %17 %25 %26
8242 %28 = OpLoad %v4float %4
8243 %29 = OpVectorShuffle %v2float %28 %28 0 1
8244 %30 = OpLoad %20 %7
8245 %31 = OpLoad %15 %6
8246 %32 = OpSampledImage %22 %30 %31
8247 %33 = OpImageSampleWeightedQCOM %v4float %27 %29 %32
8248 OpStore %3 %33
8249 %34 = OpLoad %20 %7
8250 %35 = OpLoad %15 %6
8251 %36 = OpSampledImage %22 %34 %35
8252 %37 = OpLoad %v4float %4
8253 %38 = OpVectorShuffle %v3float %37 %37 0 1 0
8254 %39 = OpCompositeExtract %float %38 0
8255 %40 = OpCompositeExtract %float %38 1
8256 %41 = OpCompositeExtract %float %38 2
8257 %42 = OpCompositeConstruct %v3float %39 %40 %41
8258 %43 = OpImageSampleImplicitLod %v4float %36 %42
8259 OpStore %3 %43
8260 OpReturn
8261 OpFunctionEnd
8262 )";
8263 CompileSuccessfully(text, SPV_ENV_UNIVERSAL_1_4);
8264 EXPECT_EQ(SPV_ERROR_INVALID_DATA,
8265 ValidateInstructions(SPV_ENV_UNIVERSAL_1_4));
8266 EXPECT_THAT(
8267 getDiagnosticString(),
8268 HasSubstr("Illegal use of QCOM image processing decorated texture"));
8269 }
8270
8271 TEST_F(ValidateImage, QCOMImageProcessing2BlockMatchWindowSADNoDecorTargetIT) {
8272 const std::string text = R"(
8273 OpCapability Shader
8274 OpCapability TextureBlockMatchQCOM
8275 OpCapability TextureBlockMatch2QCOM
8276 OpExtension "SPV_QCOM_image_processing"
8277 OpExtension "SPV_QCOM_image_processing2"
8278 %1 = OpExtInstImport "GLSL.std.450"
8279 OpMemoryModel Logical GLSL450
8280 OpEntryPoint Fragment %2 "main" %3 %4 %5
8281 OpExecutionMode %2 OriginUpperLeft
8282 OpDecorate %3 Location 0
8283 OpDecorate %4 DescriptorSet 0
8284 OpDecorate %4 Binding 4
8285 OpDecorate %4 BlockMatchSamplerQCOM
8286 OpDecorate %5 DescriptorSet 0
8287 OpDecorate %5 Binding 5
8288 OpDecorate %5 BlockMatchTextureQCOM
8289 OpDecorate %5 BlockMatchSamplerQCOM
8290 %void = OpTypeVoid
8291 %7 = OpTypeFunction %void
8292 %uint = OpTypeInt 32 0
8293 %v2uint = OpTypeVector %uint 2
8294 %_ptr_Function_v2uint = OpTypePointer Function %v2uint
8295 %float = OpTypeFloat 32
8296 %v4float = OpTypeVector %float 4
8297 %_ptr_Input_v4float = OpTypePointer Input %v4float
8298 %_ptr_Input_float = OpTypePointer Input %float
8299 %_ptr_Function_uint = OpTypePointer Function %uint
8300 %_ptr_Output_v4float = OpTypePointer Output %v4float
8301 %3 = OpVariable %_ptr_Output_v4float Output
8302 %18 = OpTypeImage %float 2D 0 0 0 1 Unknown
8303 %19 = OpTypeSampledImage %18
8304 %_ptr_UniformConstant_19 = OpTypePointer UniformConstant %19
8305 %4 = OpVariable %_ptr_UniformConstant_19 UniformConstant
8306 %5 = OpVariable %_ptr_UniformConstant_19 UniformConstant
8307 %21 = OpTypeImage %float 2D 0 1 0 1 Unknown
8308 %2 = OpFunction %void None %7
8309 %22 = OpLabel
8310 %23 = OpVariable %_ptr_Function_v2uint Function
8311 %24 = OpLoad %19 %4
8312 %25 = OpLoad %v2uint %23
8313 %26 = OpLoad %19 %5
8314 %27 = OpLoad %v2uint %23
8315 %28 = OpLoad %v2uint %23
8316 %29 = OpImageBlockMatchWindowSADQCOM %v4float %24 %25 %26 %27 %28
8317 OpStore %3 %29
8318 OpReturn
8319 OpFunctionEnd
8320 )";
8321 CompileSuccessfully(text, SPV_ENV_UNIVERSAL_1_4);
8322 EXPECT_EQ(SPV_ERROR_INVALID_DATA,
8323 ValidateInstructions(SPV_ENV_UNIVERSAL_1_4));
8324 EXPECT_THAT(getDiagnosticString(),
8325 HasSubstr("Missing decoration BlockMatchTextureQCOM"));
8326 }
8327
8328 TEST_F(ValidateImage, QCOMImageProcessing2BlockMatchWindowSADNoDecorTargetIS) {
8329 const std::string text = R"(
8330 OpCapability Shader
8331 OpCapability TextureBlockMatchQCOM
8332 OpCapability TextureBlockMatch2QCOM
8333 OpExtension "SPV_QCOM_image_processing"
8334 OpExtension "SPV_QCOM_image_processing2"
8335 %1 = OpExtInstImport "GLSL.std.450"
8336 OpMemoryModel Logical GLSL450
8337 OpEntryPoint Fragment %2 "main" %3 %4 %5
8338 OpExecutionMode %2 OriginUpperLeft
8339 OpDecorate %3 Location 0
8340 OpDecorate %4 DescriptorSet 0
8341 OpDecorate %4 Binding 4
8342 OpDecorate %4 BlockMatchTextureQCOM
8343 OpDecorate %5 DescriptorSet 0
8344 OpDecorate %5 Binding 5
8345 OpDecorate %5 BlockMatchTextureQCOM
8346 OpDecorate %5 BlockMatchSamplerQCOM
8347 %void = OpTypeVoid
8348 %7 = OpTypeFunction %void
8349 %uint = OpTypeInt 32 0
8350 %v2uint = OpTypeVector %uint 2
8351 %_ptr_Function_v2uint = OpTypePointer Function %v2uint
8352 %float = OpTypeFloat 32
8353 %v4float = OpTypeVector %float 4
8354 %_ptr_Input_v4float = OpTypePointer Input %v4float
8355 %_ptr_Input_float = OpTypePointer Input %float
8356 %_ptr_Function_uint = OpTypePointer Function %uint
8357 %_ptr_Output_v4float = OpTypePointer Output %v4float
8358 %3 = OpVariable %_ptr_Output_v4float Output
8359 %18 = OpTypeImage %float 2D 0 0 0 1 Unknown
8360 %19 = OpTypeSampledImage %18
8361 %_ptr_UniformConstant_19 = OpTypePointer UniformConstant %19
8362 %4 = OpVariable %_ptr_UniformConstant_19 UniformConstant
8363 %5 = OpVariable %_ptr_UniformConstant_19 UniformConstant
8364 %21 = OpTypeImage %float 2D 0 1 0 1 Unknown
8365 %2 = OpFunction %void None %7
8366 %22 = OpLabel
8367 %23 = OpVariable %_ptr_Function_v2uint Function
8368 %24 = OpLoad %19 %4
8369 %25 = OpLoad %v2uint %23
8370 %26 = OpLoad %19 %5
8371 %27 = OpLoad %v2uint %23
8372 %28 = OpLoad %v2uint %23
8373 %29 = OpImageBlockMatchWindowSADQCOM %v4float %24 %25 %26 %27 %28
8374 OpStore %3 %29
8375 OpReturn
8376 OpFunctionEnd
8377 )";
8378 CompileSuccessfully(text, SPV_ENV_UNIVERSAL_1_4);
8379 EXPECT_EQ(SPV_ERROR_INVALID_DATA,
8380 ValidateInstructions(SPV_ENV_UNIVERSAL_1_4));
8381 EXPECT_THAT(getDiagnosticString(),
8382 HasSubstr("Missing decoration BlockMatchSamplerQCOM"));
8383 }
8384
8385 TEST_F(ValidateImage, QCOMImageProcessing2BlockMatchWindowSADNoDecorRefIT) {
8386 const std::string text = R"(
8387 OpCapability Shader
8388 OpCapability TextureBlockMatchQCOM
8389 OpCapability TextureBlockMatch2QCOM
8390 OpExtension "SPV_QCOM_image_processing"
8391 OpExtension "SPV_QCOM_image_processing2"
8392 %1 = OpExtInstImport "GLSL.std.450"
8393 OpMemoryModel Logical GLSL450
8394 OpEntryPoint Fragment %2 "main" %3 %4 %5
8395 OpExecutionMode %2 OriginUpperLeft
8396 OpDecorate %3 Location 0
8397 OpDecorate %4 DescriptorSet 0
8398 OpDecorate %4 Binding 4
8399 OpDecorate %4 BlockMatchTextureQCOM
8400 OpDecorate %4 BlockMatchSamplerQCOM
8401 OpDecorate %5 DescriptorSet 0
8402 OpDecorate %5 Binding 5
8403 OpDecorate %5 BlockMatchSamplerQCOM
8404 %void = OpTypeVoid
8405 %7 = OpTypeFunction %void
8406 %uint = OpTypeInt 32 0
8407 %v2uint = OpTypeVector %uint 2
8408 %_ptr_Function_v2uint = OpTypePointer Function %v2uint
8409 %float = OpTypeFloat 32
8410 %v4float = OpTypeVector %float 4
8411 %_ptr_Input_v4float = OpTypePointer Input %v4float
8412 %_ptr_Input_float = OpTypePointer Input %float
8413 %_ptr_Function_uint = OpTypePointer Function %uint
8414 %_ptr_Output_v4float = OpTypePointer Output %v4float
8415 %3 = OpVariable %_ptr_Output_v4float Output
8416 %18 = OpTypeImage %float 2D 0 0 0 1 Unknown
8417 %19 = OpTypeSampledImage %18
8418 %_ptr_UniformConstant_19 = OpTypePointer UniformConstant %19
8419 %4 = OpVariable %_ptr_UniformConstant_19 UniformConstant
8420 %5 = OpVariable %_ptr_UniformConstant_19 UniformConstant
8421 %21 = OpTypeImage %float 2D 0 1 0 1 Unknown
8422 %2 = OpFunction %void None %7
8423 %22 = OpLabel
8424 %23 = OpVariable %_ptr_Function_v2uint Function
8425 %24 = OpLoad %19 %4
8426 %25 = OpLoad %v2uint %23
8427 %26 = OpLoad %19 %5
8428 %27 = OpLoad %v2uint %23
8429 %28 = OpLoad %v2uint %23
8430 %29 = OpImageBlockMatchWindowSADQCOM %v4float %24 %25 %26 %27 %28
8431 OpStore %3 %29
8432 OpReturn
8433 OpFunctionEnd
8434 )";
8435 CompileSuccessfully(text, SPV_ENV_UNIVERSAL_1_4);
8436 EXPECT_EQ(SPV_ERROR_INVALID_DATA,
8437 ValidateInstructions(SPV_ENV_UNIVERSAL_1_4));
8438 EXPECT_THAT(getDiagnosticString(),
8439 HasSubstr("Missing decoration BlockMatchTextureQCOM"));
8440 }
8441
8442 TEST_F(ValidateImage, QCOMImageProcessing2BlockMatchWindowSADNoDecorRefIS) {
8443 const std::string text = R"(
8444 OpCapability Shader
8445 OpCapability TextureBlockMatchQCOM
8446 OpCapability TextureBlockMatch2QCOM
8447 OpExtension "SPV_QCOM_image_processing"
8448 OpExtension "SPV_QCOM_image_processing2"
8449 %1 = OpExtInstImport "GLSL.std.450"
8450 OpMemoryModel Logical GLSL450
8451 OpEntryPoint Fragment %2 "main" %3 %4 %5
8452 OpExecutionMode %2 OriginUpperLeft
8453 OpDecorate %3 Location 0
8454 OpDecorate %4 DescriptorSet 0
8455 OpDecorate %4 Binding 4
8456 OpDecorate %4 BlockMatchTextureQCOM
8457 OpDecorate %4 BlockMatchSamplerQCOM
8458 OpDecorate %5 DescriptorSet 0
8459 OpDecorate %5 Binding 5
8460 OpDecorate %5 BlockMatchTextureQCOM
8461 %void = OpTypeVoid
8462 %7 = OpTypeFunction %void
8463 %uint = OpTypeInt 32 0
8464 %v2uint = OpTypeVector %uint 2
8465 %_ptr_Function_v2uint = OpTypePointer Function %v2uint
8466 %float = OpTypeFloat 32
8467 %v4float = OpTypeVector %float 4
8468 %_ptr_Input_v4float = OpTypePointer Input %v4float
8469 %_ptr_Input_float = OpTypePointer Input %float
8470 %_ptr_Function_uint = OpTypePointer Function %uint
8471 %_ptr_Output_v4float = OpTypePointer Output %v4float
8472 %3 = OpVariable %_ptr_Output_v4float Output
8473 %18 = OpTypeImage %float 2D 0 0 0 1 Unknown
8474 %19 = OpTypeSampledImage %18
8475 %_ptr_UniformConstant_19 = OpTypePointer UniformConstant %19
8476 %4 = OpVariable %_ptr_UniformConstant_19 UniformConstant
8477 %5 = OpVariable %_ptr_UniformConstant_19 UniformConstant
8478 %21 = OpTypeImage %float 2D 0 1 0 1 Unknown
8479 %2 = OpFunction %void None %7
8480 %22 = OpLabel
8481 %23 = OpVariable %_ptr_Function_v2uint Function
8482 %24 = OpLoad %19 %4
8483 %25 = OpLoad %v2uint %23
8484 %26 = OpLoad %19 %5
8485 %27 = OpLoad %v2uint %23
8486 %28 = OpLoad %v2uint %23
8487 %29 = OpImageBlockMatchWindowSADQCOM %v4float %24 %25 %26 %27 %28
8488 OpStore %3 %29
8489 OpReturn
8490 OpFunctionEnd
8491 )";
8492 CompileSuccessfully(text, SPV_ENV_UNIVERSAL_1_4);
8493 EXPECT_EQ(SPV_ERROR_INVALID_DATA,
8494 ValidateInstructions(SPV_ENV_UNIVERSAL_1_4));
8495 EXPECT_THAT(getDiagnosticString(),
8496 HasSubstr("Missing decoration BlockMatchSamplerQCOM"));
8497 }
8498
8499 TEST_F(ValidateImage, QCOMImageProcessing2BlockMatchWindowSADNoDecorTargetNIT) {
8500 const std::string text = R"(
8501 OpCapability Shader
8502 OpCapability TextureBlockMatchQCOM
8503 OpCapability TextureBlockMatch2QCOM
8504 OpExtension "SPV_QCOM_image_processing"
8505 OpExtension "SPV_QCOM_image_processing2"
8506 %1 = OpExtInstImport "GLSL.std.450"
8507 OpMemoryModel Logical GLSL450
8508 OpEntryPoint Fragment %2 "main" %3 %4 %5 %6
8509 OpExecutionMode %2 OriginUpperLeft
8510 OpDecorate %3 Location 0
8511 OpDecorate %4 DescriptorSet 0
8512 OpDecorate %4 Binding 1
8513 OpDecorate %4 BlockMatchSamplerQCOM
8514 OpDecorate %5 DescriptorSet 0
8515 OpDecorate %5 Binding 3
8516 OpDecorate %6 DescriptorSet 0
8517 OpDecorate %6 Binding 2
8518 OpDecorate %6 BlockMatchTextureQCOM
8519 OpDecorate %6 BlockMatchSamplerQCOM
8520 %void = OpTypeVoid
8521 %8 = OpTypeFunction %void
8522 %uint = OpTypeInt 32 0
8523 %v2uint = OpTypeVector %uint 2
8524 %_ptr_Function_v2uint = OpTypePointer Function %v2uint
8525 %float = OpTypeFloat 32
8526 %v4float = OpTypeVector %float 4
8527 %_ptr_Input_float = OpTypePointer Input %float
8528 %_ptr_Function_uint = OpTypePointer Function %uint
8529 %uint_4 = OpConstant %uint 4
8530 %17 = OpConstantComposite %v2uint %uint_4 %uint_4
8531 %_ptr_Output_v4float = OpTypePointer Output %v4float
8532 %3 = OpVariable %_ptr_Output_v4float Output
8533 %19 = OpTypeImage %float 2D 0 0 0 1 Unknown
8534 %_ptr_UniformConstant_19 = OpTypePointer UniformConstant %19
8535 %4 = OpVariable %_ptr_UniformConstant_19 UniformConstant
8536 %21 = OpTypeSampler
8537 %_ptr_UniformConstant_21 = OpTypePointer UniformConstant %21
8538 %5 = OpVariable %_ptr_UniformConstant_21 UniformConstant
8539 %23 = OpTypeSampledImage %19
8540 %6 = OpVariable %_ptr_UniformConstant_19 UniformConstant
8541 %2 = OpFunction %void None %8
8542 %24 = OpLabel
8543 %25 = OpVariable %_ptr_Function_v2uint Function
8544 %26 = OpLoad %19 %4
8545 %27 = OpLoad %21 %5
8546 %28 = OpSampledImage %23 %26 %27
8547 %29 = OpLoad %v2uint %25
8548 %30 = OpLoad %19 %6
8549 %31 = OpLoad %21 %5
8550 %32 = OpSampledImage %23 %30 %31
8551 %33 = OpImageBlockMatchWindowSADQCOM %v4float %28 %29 %32 %29 %29
8552 OpStore %3 %33
8553 OpReturn
8554 OpFunctionEnd
8555 )";
8556 CompileSuccessfully(text, SPV_ENV_UNIVERSAL_1_4);
8557 EXPECT_EQ(SPV_ERROR_INVALID_DATA,
8558 ValidateInstructions(SPV_ENV_UNIVERSAL_1_4));
8559 EXPECT_THAT(getDiagnosticString(),
8560 HasSubstr("Missing decoration BlockMatchTextureQCOM"));
8561 }
8562
8563 TEST_F(ValidateImage, QCOMImageProcessing2BlockMatchWindowSADNoDecorTargetNIS) {
8564 const std::string text = R"(
8565 OpCapability Shader
8566 OpCapability TextureBlockMatchQCOM
8567 OpCapability TextureBlockMatch2QCOM
8568 OpExtension "SPV_QCOM_image_processing"
8569 OpExtension "SPV_QCOM_image_processing2"
8570 %1 = OpExtInstImport "GLSL.std.450"
8571 OpMemoryModel Logical GLSL450
8572 OpEntryPoint Fragment %2 "main" %3 %4 %5 %6
8573 OpExecutionMode %2 OriginUpperLeft
8574 OpDecorate %3 Location 0
8575 OpDecorate %4 DescriptorSet 0
8576 OpDecorate %4 Binding 1
8577 OpDecorate %4 BlockMatchTextureQCOM
8578 OpDecorate %5 DescriptorSet 0
8579 OpDecorate %5 Binding 3
8580 OpDecorate %6 DescriptorSet 0
8581 OpDecorate %6 Binding 2
8582 OpDecorate %6 BlockMatchTextureQCOM
8583 OpDecorate %6 BlockMatchSamplerQCOM
8584 %void = OpTypeVoid
8585 %8 = OpTypeFunction %void
8586 %uint = OpTypeInt 32 0
8587 %v2uint = OpTypeVector %uint 2
8588 %_ptr_Function_v2uint = OpTypePointer Function %v2uint
8589 %float = OpTypeFloat 32
8590 %v4float = OpTypeVector %float 4
8591 %_ptr_Input_float = OpTypePointer Input %float
8592 %_ptr_Function_uint = OpTypePointer Function %uint
8593 %uint_4 = OpConstant %uint 4
8594 %17 = OpConstantComposite %v2uint %uint_4 %uint_4
8595 %_ptr_Output_v4float = OpTypePointer Output %v4float
8596 %3 = OpVariable %_ptr_Output_v4float Output
8597 %19 = OpTypeImage %float 2D 0 0 0 1 Unknown
8598 %_ptr_UniformConstant_19 = OpTypePointer UniformConstant %19
8599 %4 = OpVariable %_ptr_UniformConstant_19 UniformConstant
8600 %21 = OpTypeSampler
8601 %_ptr_UniformConstant_21 = OpTypePointer UniformConstant %21
8602 %5 = OpVariable %_ptr_UniformConstant_21 UniformConstant
8603 %23 = OpTypeSampledImage %19
8604 %6 = OpVariable %_ptr_UniformConstant_19 UniformConstant
8605 %2 = OpFunction %void None %8
8606 %24 = OpLabel
8607 %25 = OpVariable %_ptr_Function_v2uint Function
8608 %26 = OpLoad %19 %4
8609 %27 = OpLoad %21 %5
8610 %28 = OpSampledImage %23 %26 %27
8611 %29 = OpLoad %v2uint %25
8612 %30 = OpLoad %19 %6
8613 %31 = OpLoad %21 %5
8614 %32 = OpSampledImage %23 %30 %31
8615 %33 = OpImageBlockMatchWindowSADQCOM %v4float %28 %29 %32 %29 %29
8616 OpStore %3 %33
8617 OpReturn
8618 OpFunctionEnd
8619 )";
8620 CompileSuccessfully(text, SPV_ENV_UNIVERSAL_1_4);
8621 EXPECT_EQ(SPV_ERROR_INVALID_DATA,
8622 ValidateInstructions(SPV_ENV_UNIVERSAL_1_4));
8623 EXPECT_THAT(getDiagnosticString(),
8624 HasSubstr("Missing decoration BlockMatchSamplerQCOM"));
8625 }
8626
8627 TEST_F(ValidateImage, QCOMImageProcessing2BlockMatchWindowSADNoDecorRefNIT) {
8628 const std::string text = R"(
8629 OpCapability Shader
8630 OpCapability TextureBlockMatchQCOM
8631 OpCapability TextureBlockMatch2QCOM
8632 OpExtension "SPV_QCOM_image_processing"
8633 OpExtension "SPV_QCOM_image_processing2"
8634 %1 = OpExtInstImport "GLSL.std.450"
8635 OpMemoryModel Logical GLSL450
8636 OpEntryPoint Fragment %2 "main" %3 %4 %5 %6
8637 OpExecutionMode %2 OriginUpperLeft
8638 OpDecorate %3 Location 0
8639 OpDecorate %4 DescriptorSet 0
8640 OpDecorate %4 Binding 1
8641 OpDecorate %4 BlockMatchTextureQCOM
8642 OpDecorate %5 DescriptorSet 0
8643 OpDecorate %5 Binding 3
8644 OpDecorate %5 BlockMatchSamplerQCOM
8645 OpDecorate %6 DescriptorSet 0
8646 OpDecorate %6 Binding 2
8647 OpDecorate %6 BlockMatchSamplerQCOM
8648 %void = OpTypeVoid
8649 %8 = OpTypeFunction %void
8650 %uint = OpTypeInt 32 0
8651 %v2uint = OpTypeVector %uint 2
8652 %_ptr_Function_v2uint = OpTypePointer Function %v2uint
8653 %float = OpTypeFloat 32
8654 %v4float = OpTypeVector %float 4
8655 %_ptr_Input_float = OpTypePointer Input %float
8656 %_ptr_Function_uint = OpTypePointer Function %uint
8657 %uint_4 = OpConstant %uint 4
8658 %17 = OpConstantComposite %v2uint %uint_4 %uint_4
8659 %_ptr_Output_v4float = OpTypePointer Output %v4float
8660 %3 = OpVariable %_ptr_Output_v4float Output
8661 %19 = OpTypeImage %float 2D 0 0 0 1 Unknown
8662 %_ptr_UniformConstant_19 = OpTypePointer UniformConstant %19
8663 %4 = OpVariable %_ptr_UniformConstant_19 UniformConstant
8664 %21 = OpTypeSampler
8665 %_ptr_UniformConstant_21 = OpTypePointer UniformConstant %21
8666 %5 = OpVariable %_ptr_UniformConstant_21 UniformConstant
8667 %23 = OpTypeSampledImage %19
8668 %6 = OpVariable %_ptr_UniformConstant_19 UniformConstant
8669 %2 = OpFunction %void None %8
8670 %24 = OpLabel
8671 %25 = OpVariable %_ptr_Function_v2uint Function
8672 %26 = OpLoad %19 %4
8673 %27 = OpLoad %21 %5
8674 %28 = OpSampledImage %23 %26 %27
8675 %29 = OpLoad %v2uint %25
8676 %30 = OpLoad %19 %6
8677 %31 = OpLoad %21 %5
8678 %32 = OpSampledImage %23 %30 %31
8679 %33 = OpImageBlockMatchWindowSADQCOM %v4float %28 %29 %32 %29 %29
8680 OpStore %3 %33
8681 OpReturn
8682 OpFunctionEnd
8683 )";
8684 CompileSuccessfully(text, SPV_ENV_UNIVERSAL_1_4);
8685 EXPECT_EQ(SPV_ERROR_INVALID_DATA,
8686 ValidateInstructions(SPV_ENV_UNIVERSAL_1_4));
8687 EXPECT_THAT(getDiagnosticString(),
8688 HasSubstr("Missing decoration BlockMatchTextureQCOM"));
8689 }
8690
8691 TEST_F(ValidateImage, QCOMImageProcessing2BlockMatchWindowSADNoDecorRefNIS) {
8692 const std::string text = R"(
8693 OpCapability Shader
8694 OpCapability TextureBlockMatchQCOM
8695 OpCapability TextureBlockMatch2QCOM
8696 OpExtension "SPV_QCOM_image_processing"
8697 OpExtension "SPV_QCOM_image_processing2"
8698 %1 = OpExtInstImport "GLSL.std.450"
8699 OpMemoryModel Logical GLSL450
8700 OpEntryPoint Fragment %2 "main" %3 %4 %5 %6
8701 OpExecutionMode %2 OriginUpperLeft
8702 OpDecorate %3 Location 0
8703 OpDecorate %4 DescriptorSet 0
8704 OpDecorate %4 Binding 1
8705 OpDecorate %4 BlockMatchTextureQCOM
8706 OpDecorate %4 BlockMatchSamplerQCOM
8707 OpDecorate %5 DescriptorSet 0
8708 OpDecorate %5 Binding 3
8709 OpDecorate %6 DescriptorSet 0
8710 OpDecorate %6 Binding 2
8711 OpDecorate %6 BlockMatchTextureQCOM
8712 %void = OpTypeVoid
8713 %8 = OpTypeFunction %void
8714 %uint = OpTypeInt 32 0
8715 %v2uint = OpTypeVector %uint 2
8716 %_ptr_Function_v2uint = OpTypePointer Function %v2uint
8717 %float = OpTypeFloat 32
8718 %v4float = OpTypeVector %float 4
8719 %_ptr_Input_float = OpTypePointer Input %float
8720 %_ptr_Function_uint = OpTypePointer Function %uint
8721 %uint_4 = OpConstant %uint 4
8722 %17 = OpConstantComposite %v2uint %uint_4 %uint_4
8723 %_ptr_Output_v4float = OpTypePointer Output %v4float
8724 %3 = OpVariable %_ptr_Output_v4float Output
8725 %19 = OpTypeImage %float 2D 0 0 0 1 Unknown
8726 %_ptr_UniformConstant_19 = OpTypePointer UniformConstant %19
8727 %4 = OpVariable %_ptr_UniformConstant_19 UniformConstant
8728 %21 = OpTypeSampler
8729 %_ptr_UniformConstant_21 = OpTypePointer UniformConstant %21
8730 %5 = OpVariable %_ptr_UniformConstant_21 UniformConstant
8731 %23 = OpTypeSampledImage %19
8732 %6 = OpVariable %_ptr_UniformConstant_19 UniformConstant
8733 %2 = OpFunction %void None %8
8734 %24 = OpLabel
8735 %25 = OpVariable %_ptr_Function_v2uint Function
8736 %26 = OpLoad %19 %4
8737 %27 = OpLoad %21 %5
8738 %28 = OpSampledImage %23 %26 %27
8739 %29 = OpLoad %v2uint %25
8740 %30 = OpLoad %19 %6
8741 %31 = OpLoad %21 %5
8742 %32 = OpSampledImage %23 %30 %31
8743 %33 = OpImageBlockMatchWindowSADQCOM %v4float %28 %29 %32 %29 %29
8744 OpStore %3 %33
8745 OpReturn
8746 OpFunctionEnd
8747 )";
8748 CompileSuccessfully(text, SPV_ENV_UNIVERSAL_1_4);
8749 EXPECT_EQ(SPV_ERROR_INVALID_DATA,
8750 ValidateInstructions(SPV_ENV_UNIVERSAL_1_4));
8751 EXPECT_THAT(getDiagnosticString(),
8752 HasSubstr("Missing decoration BlockMatchSamplerQCOM"));
8753 }
8754
8755 TEST_F(ValidateImage, QCOMImageProcessing2BlockMatchWindowSSDNoDecorTargetIT) {
8756 const std::string text = R"(
8757 OpCapability Shader
8758 OpCapability TextureBlockMatchQCOM
8759 OpCapability TextureBlockMatch2QCOM
8760 OpExtension "SPV_QCOM_image_processing"
8761 OpExtension "SPV_QCOM_image_processing2"
8762 %1 = OpExtInstImport "GLSL.std.450"
8763 OpMemoryModel Logical GLSL450
8764 OpEntryPoint Fragment %2 "main" %3 %4 %5
8765 OpExecutionMode %2 OriginUpperLeft
8766 OpDecorate %3 Location 0
8767 OpDecorate %4 DescriptorSet 0
8768 OpDecorate %4 Binding 4
8769 OpDecorate %4 BlockMatchSamplerQCOM
8770 OpDecorate %5 DescriptorSet 0
8771 OpDecorate %5 Binding 5
8772 OpDecorate %5 BlockMatchTextureQCOM
8773 OpDecorate %5 BlockMatchSamplerQCOM
8774 %void = OpTypeVoid
8775 %7 = OpTypeFunction %void
8776 %uint = OpTypeInt 32 0
8777 %v2uint = OpTypeVector %uint 2
8778 %_ptr_Function_v2uint = OpTypePointer Function %v2uint
8779 %float = OpTypeFloat 32
8780 %v4float = OpTypeVector %float 4
8781 %_ptr_Input_v4float = OpTypePointer Input %v4float
8782 %_ptr_Input_float = OpTypePointer Input %float
8783 %_ptr_Function_uint = OpTypePointer Function %uint
8784 %_ptr_Output_v4float = OpTypePointer Output %v4float
8785 %3 = OpVariable %_ptr_Output_v4float Output
8786 %18 = OpTypeImage %float 2D 0 0 0 1 Unknown
8787 %19 = OpTypeSampledImage %18
8788 %_ptr_UniformConstant_19 = OpTypePointer UniformConstant %19
8789 %4 = OpVariable %_ptr_UniformConstant_19 UniformConstant
8790 %5 = OpVariable %_ptr_UniformConstant_19 UniformConstant
8791 %21 = OpTypeImage %float 2D 0 1 0 1 Unknown
8792 %2 = OpFunction %void None %7
8793 %22 = OpLabel
8794 %23 = OpVariable %_ptr_Function_v2uint Function
8795 %24 = OpLoad %19 %4
8796 %25 = OpLoad %v2uint %23
8797 %26 = OpLoad %19 %5
8798 %27 = OpLoad %v2uint %23
8799 %28 = OpLoad %v2uint %23
8800 %29 = OpImageBlockMatchWindowSSDQCOM %v4float %24 %25 %26 %27 %28
8801 OpStore %3 %29
8802 OpReturn
8803 OpFunctionEnd
8804 )";
8805 CompileSuccessfully(text, SPV_ENV_UNIVERSAL_1_4);
8806 EXPECT_EQ(SPV_ERROR_INVALID_DATA,
8807 ValidateInstructions(SPV_ENV_UNIVERSAL_1_4));
8808 EXPECT_THAT(getDiagnosticString(),
8809 HasSubstr("Missing decoration BlockMatchTextureQCOM"));
8810 }
8811
8812 TEST_F(ValidateImage, QCOMImageProcessing2BlockMatchWindowSSDNoDecorTargetIS) {
8813 const std::string text = R"(
8814 OpCapability Shader
8815 OpCapability TextureBlockMatchQCOM
8816 OpCapability TextureBlockMatch2QCOM
8817 OpExtension "SPV_QCOM_image_processing"
8818 OpExtension "SPV_QCOM_image_processing2"
8819 %1 = OpExtInstImport "GLSL.std.450"
8820 OpMemoryModel Logical GLSL450
8821 OpEntryPoint Fragment %2 "main" %3 %4 %5
8822 OpExecutionMode %2 OriginUpperLeft
8823 OpDecorate %3 Location 0
8824 OpDecorate %4 DescriptorSet 0
8825 OpDecorate %4 Binding 4
8826 OpDecorate %4 BlockMatchTextureQCOM
8827 OpDecorate %5 DescriptorSet 0
8828 OpDecorate %5 Binding 5
8829 OpDecorate %5 BlockMatchTextureQCOM
8830 OpDecorate %5 BlockMatchSamplerQCOM
8831 %void = OpTypeVoid
8832 %7 = OpTypeFunction %void
8833 %uint = OpTypeInt 32 0
8834 %v2uint = OpTypeVector %uint 2
8835 %_ptr_Function_v2uint = OpTypePointer Function %v2uint
8836 %float = OpTypeFloat 32
8837 %v4float = OpTypeVector %float 4
8838 %_ptr_Input_v4float = OpTypePointer Input %v4float
8839 %_ptr_Input_float = OpTypePointer Input %float
8840 %_ptr_Function_uint = OpTypePointer Function %uint
8841 %_ptr_Output_v4float = OpTypePointer Output %v4float
8842 %3 = OpVariable %_ptr_Output_v4float Output
8843 %18 = OpTypeImage %float 2D 0 0 0 1 Unknown
8844 %19 = OpTypeSampledImage %18
8845 %_ptr_UniformConstant_19 = OpTypePointer UniformConstant %19
8846 %4 = OpVariable %_ptr_UniformConstant_19 UniformConstant
8847 %5 = OpVariable %_ptr_UniformConstant_19 UniformConstant
8848 %21 = OpTypeImage %float 2D 0 1 0 1 Unknown
8849 %2 = OpFunction %void None %7
8850 %22 = OpLabel
8851 %23 = OpVariable %_ptr_Function_v2uint Function
8852 %24 = OpLoad %19 %4
8853 %25 = OpLoad %v2uint %23
8854 %26 = OpLoad %19 %5
8855 %27 = OpLoad %v2uint %23
8856 %28 = OpLoad %v2uint %23
8857 %29 = OpImageBlockMatchWindowSSDQCOM %v4float %24 %25 %26 %27 %28
8858 OpStore %3 %29
8859 OpReturn
8860 OpFunctionEnd
8861 )";
8862 CompileSuccessfully(text, SPV_ENV_UNIVERSAL_1_4);
8863 EXPECT_EQ(SPV_ERROR_INVALID_DATA,
8864 ValidateInstructions(SPV_ENV_UNIVERSAL_1_4));
8865 EXPECT_THAT(getDiagnosticString(),
8866 HasSubstr("Missing decoration BlockMatchSamplerQCOM"));
8867 }
8868
8869 TEST_F(ValidateImage, QCOMImageProcessing2BlockMatchWindowSSDNoDecorRefIT) {
8870 const std::string text = R"(
8871 OpCapability Shader
8872 OpCapability TextureBlockMatchQCOM
8873 OpCapability TextureBlockMatch2QCOM
8874 OpExtension "SPV_QCOM_image_processing"
8875 OpExtension "SPV_QCOM_image_processing2"
8876 %1 = OpExtInstImport "GLSL.std.450"
8877 OpMemoryModel Logical GLSL450
8878 OpEntryPoint Fragment %2 "main" %3 %4 %5
8879 OpExecutionMode %2 OriginUpperLeft
8880 OpDecorate %3 Location 0
8881 OpDecorate %4 DescriptorSet 0
8882 OpDecorate %4 Binding 4
8883 OpDecorate %4 BlockMatchTextureQCOM
8884 OpDecorate %4 BlockMatchSamplerQCOM
8885 OpDecorate %5 DescriptorSet 0
8886 OpDecorate %5 Binding 5
8887 OpDecorate %5 BlockMatchSamplerQCOM
8888 %void = OpTypeVoid
8889 %7 = OpTypeFunction %void
8890 %uint = OpTypeInt 32 0
8891 %v2uint = OpTypeVector %uint 2
8892 %_ptr_Function_v2uint = OpTypePointer Function %v2uint
8893 %float = OpTypeFloat 32
8894 %v4float = OpTypeVector %float 4
8895 %_ptr_Input_v4float = OpTypePointer Input %v4float
8896 %_ptr_Input_float = OpTypePointer Input %float
8897 %_ptr_Function_uint = OpTypePointer Function %uint
8898 %_ptr_Output_v4float = OpTypePointer Output %v4float
8899 %3 = OpVariable %_ptr_Output_v4float Output
8900 %18 = OpTypeImage %float 2D 0 0 0 1 Unknown
8901 %19 = OpTypeSampledImage %18
8902 %_ptr_UniformConstant_19 = OpTypePointer UniformConstant %19
8903 %4 = OpVariable %_ptr_UniformConstant_19 UniformConstant
8904 %5 = OpVariable %_ptr_UniformConstant_19 UniformConstant
8905 %21 = OpTypeImage %float 2D 0 1 0 1 Unknown
8906 %2 = OpFunction %void None %7
8907 %22 = OpLabel
8908 %23 = OpVariable %_ptr_Function_v2uint Function
8909 %24 = OpLoad %19 %4
8910 %25 = OpLoad %v2uint %23
8911 %26 = OpLoad %19 %5
8912 %27 = OpLoad %v2uint %23
8913 %28 = OpLoad %v2uint %23
8914 %29 = OpImageBlockMatchWindowSSDQCOM %v4float %24 %25 %26 %27 %28
8915 OpStore %3 %29
8916 OpReturn
8917 OpFunctionEnd
8918 )";
8919 CompileSuccessfully(text, SPV_ENV_UNIVERSAL_1_4);
8920 EXPECT_EQ(SPV_ERROR_INVALID_DATA,
8921 ValidateInstructions(SPV_ENV_UNIVERSAL_1_4));
8922 EXPECT_THAT(getDiagnosticString(),
8923 HasSubstr("Missing decoration BlockMatchTextureQCOM"));
8924 }
8925
8926 TEST_F(ValidateImage, QCOMImageProcessing2BlockMatchWindowSSDNoDecorRefIS) {
8927 const std::string text = R"(
8928 OpCapability Shader
8929 OpCapability TextureBlockMatchQCOM
8930 OpCapability TextureBlockMatch2QCOM
8931 OpExtension "SPV_QCOM_image_processing"
8932 OpExtension "SPV_QCOM_image_processing2"
8933 %1 = OpExtInstImport "GLSL.std.450"
8934 OpMemoryModel Logical GLSL450
8935 OpEntryPoint Fragment %2 "main" %3 %4 %5
8936 OpExecutionMode %2 OriginUpperLeft
8937 OpDecorate %3 Location 0
8938 OpDecorate %4 DescriptorSet 0
8939 OpDecorate %4 Binding 4
8940 OpDecorate %4 BlockMatchTextureQCOM
8941 OpDecorate %4 BlockMatchSamplerQCOM
8942 OpDecorate %5 DescriptorSet 0
8943 OpDecorate %5 Binding 5
8944 OpDecorate %5 BlockMatchTextureQCOM
8945 %void = OpTypeVoid
8946 %7 = OpTypeFunction %void
8947 %uint = OpTypeInt 32 0
8948 %v2uint = OpTypeVector %uint 2
8949 %_ptr_Function_v2uint = OpTypePointer Function %v2uint
8950 %float = OpTypeFloat 32
8951 %v4float = OpTypeVector %float 4
8952 %_ptr_Input_v4float = OpTypePointer Input %v4float
8953 %_ptr_Input_float = OpTypePointer Input %float
8954 %_ptr_Function_uint = OpTypePointer Function %uint
8955 %_ptr_Output_v4float = OpTypePointer Output %v4float
8956 %3 = OpVariable %_ptr_Output_v4float Output
8957 %18 = OpTypeImage %float 2D 0 0 0 1 Unknown
8958 %19 = OpTypeSampledImage %18
8959 %_ptr_UniformConstant_19 = OpTypePointer UniformConstant %19
8960 %4 = OpVariable %_ptr_UniformConstant_19 UniformConstant
8961 %5 = OpVariable %_ptr_UniformConstant_19 UniformConstant
8962 %21 = OpTypeImage %float 2D 0 1 0 1 Unknown
8963 %2 = OpFunction %void None %7
8964 %22 = OpLabel
8965 %23 = OpVariable %_ptr_Function_v2uint Function
8966 %24 = OpLoad %19 %4
8967 %25 = OpLoad %v2uint %23
8968 %26 = OpLoad %19 %5
8969 %27 = OpLoad %v2uint %23
8970 %28 = OpLoad %v2uint %23
8971 %29 = OpImageBlockMatchWindowSSDQCOM %v4float %24 %25 %26 %27 %28
8972 OpStore %3 %29
8973 OpReturn
8974 OpFunctionEnd
8975 )";
8976 CompileSuccessfully(text, SPV_ENV_UNIVERSAL_1_4);
8977 EXPECT_EQ(SPV_ERROR_INVALID_DATA,
8978 ValidateInstructions(SPV_ENV_UNIVERSAL_1_4));
8979 EXPECT_THAT(getDiagnosticString(),
8980 HasSubstr("Missing decoration BlockMatchSamplerQCOM"));
8981 }
8982
8983 TEST_F(ValidateImage, QCOMImageProcessing2BlockMatchWindowSSDNoDecorTargetNIT) {
8984 const std::string text = R"(
8985 OpCapability Shader
8986 OpCapability TextureBlockMatchQCOM
8987 OpCapability TextureBlockMatch2QCOM
8988 OpExtension "SPV_QCOM_image_processing"
8989 OpExtension "SPV_QCOM_image_processing2"
8990 %1 = OpExtInstImport "GLSL.std.450"
8991 OpMemoryModel Logical GLSL450
8992 OpEntryPoint Fragment %2 "main" %3 %4 %5 %6
8993 OpExecutionMode %2 OriginUpperLeft
8994 OpDecorate %3 Location 0
8995 OpDecorate %4 DescriptorSet 0
8996 OpDecorate %4 Binding 1
8997 OpDecorate %4 BlockMatchSamplerQCOM
8998 OpDecorate %5 DescriptorSet 0
8999 OpDecorate %5 Binding 3
9000 OpDecorate %6 DescriptorSet 0
9001 OpDecorate %6 Binding 2
9002 OpDecorate %6 BlockMatchTextureQCOM
9003 OpDecorate %6 BlockMatchSamplerQCOM
9004 %void = OpTypeVoid
9005 %8 = OpTypeFunction %void
9006 %uint = OpTypeInt 32 0
9007 %v2uint = OpTypeVector %uint 2
9008 %_ptr_Function_v2uint = OpTypePointer Function %v2uint
9009 %float = OpTypeFloat 32
9010 %v4float = OpTypeVector %float 4
9011 %_ptr_Input_float = OpTypePointer Input %float
9012 %_ptr_Function_uint = OpTypePointer Function %uint
9013 %uint_4 = OpConstant %uint 4
9014 %17 = OpConstantComposite %v2uint %uint_4 %uint_4
9015 %_ptr_Output_v4float = OpTypePointer Output %v4float
9016 %3 = OpVariable %_ptr_Output_v4float Output
9017 %19 = OpTypeImage %float 2D 0 0 0 1 Unknown
9018 %_ptr_UniformConstant_19 = OpTypePointer UniformConstant %19
9019 %4 = OpVariable %_ptr_UniformConstant_19 UniformConstant
9020 %21 = OpTypeSampler
9021 %_ptr_UniformConstant_21 = OpTypePointer UniformConstant %21
9022 %5 = OpVariable %_ptr_UniformConstant_21 UniformConstant
9023 %23 = OpTypeSampledImage %19
9024 %6 = OpVariable %_ptr_UniformConstant_19 UniformConstant
9025 %2 = OpFunction %void None %8
9026 %24 = OpLabel
9027 %25 = OpVariable %_ptr_Function_v2uint Function
9028 %26 = OpLoad %19 %4
9029 %27 = OpLoad %21 %5
9030 %28 = OpSampledImage %23 %26 %27
9031 %29 = OpLoad %v2uint %25
9032 %30 = OpLoad %19 %6
9033 %31 = OpLoad %21 %5
9034 %32 = OpSampledImage %23 %30 %31
9035 %33 = OpImageBlockMatchWindowSSDQCOM %v4float %28 %29 %32 %29 %29
9036 OpStore %3 %33
9037 OpReturn
9038 OpFunctionEnd
9039 )";
9040 CompileSuccessfully(text, SPV_ENV_UNIVERSAL_1_4);
9041 EXPECT_EQ(SPV_ERROR_INVALID_DATA,
9042 ValidateInstructions(SPV_ENV_UNIVERSAL_1_4));
9043 EXPECT_THAT(getDiagnosticString(),
9044 HasSubstr("Missing decoration BlockMatchTextureQCOM"));
9045 }
9046
9047 TEST_F(ValidateImage, QCOMImageProcessing2BlockMatchWindowSSDNoDecorTargetNIS) {
9048 const std::string text = R"(
9049 OpCapability Shader
9050 OpCapability TextureBlockMatchQCOM
9051 OpCapability TextureBlockMatch2QCOM
9052 OpExtension "SPV_QCOM_image_processing"
9053 OpExtension "SPV_QCOM_image_processing2"
9054 %1 = OpExtInstImport "GLSL.std.450"
9055 OpMemoryModel Logical GLSL450
9056 OpEntryPoint Fragment %2 "main" %3 %4 %5 %6
9057 OpExecutionMode %2 OriginUpperLeft
9058 OpDecorate %3 Location 0
9059 OpDecorate %4 DescriptorSet 0
9060 OpDecorate %4 Binding 1
9061 OpDecorate %4 BlockMatchTextureQCOM
9062 OpDecorate %5 DescriptorSet 0
9063 OpDecorate %5 Binding 3
9064 OpDecorate %6 DescriptorSet 0
9065 OpDecorate %6 Binding 2
9066 OpDecorate %6 BlockMatchTextureQCOM
9067 OpDecorate %6 BlockMatchSamplerQCOM
9068 %void = OpTypeVoid
9069 %8 = OpTypeFunction %void
9070 %uint = OpTypeInt 32 0
9071 %v2uint = OpTypeVector %uint 2
9072 %_ptr_Function_v2uint = OpTypePointer Function %v2uint
9073 %float = OpTypeFloat 32
9074 %v4float = OpTypeVector %float 4
9075 %_ptr_Input_float = OpTypePointer Input %float
9076 %_ptr_Function_uint = OpTypePointer Function %uint
9077 %uint_4 = OpConstant %uint 4
9078 %17 = OpConstantComposite %v2uint %uint_4 %uint_4
9079 %_ptr_Output_v4float = OpTypePointer Output %v4float
9080 %3 = OpVariable %_ptr_Output_v4float Output
9081 %19 = OpTypeImage %float 2D 0 0 0 1 Unknown
9082 %_ptr_UniformConstant_19 = OpTypePointer UniformConstant %19
9083 %4 = OpVariable %_ptr_UniformConstant_19 UniformConstant
9084 %21 = OpTypeSampler
9085 %_ptr_UniformConstant_21 = OpTypePointer UniformConstant %21
9086 %5 = OpVariable %_ptr_UniformConstant_21 UniformConstant
9087 %23 = OpTypeSampledImage %19
9088 %6 = OpVariable %_ptr_UniformConstant_19 UniformConstant
9089 %2 = OpFunction %void None %8
9090 %24 = OpLabel
9091 %25 = OpVariable %_ptr_Function_v2uint Function
9092 %26 = OpLoad %19 %4
9093 %27 = OpLoad %21 %5
9094 %28 = OpSampledImage %23 %26 %27
9095 %29 = OpLoad %v2uint %25
9096 %30 = OpLoad %19 %6
9097 %31 = OpLoad %21 %5
9098 %32 = OpSampledImage %23 %30 %31
9099 %33 = OpImageBlockMatchWindowSSDQCOM %v4float %28 %29 %32 %29 %29
9100 OpStore %3 %33
9101 OpReturn
9102 OpFunctionEnd
9103 )";
9104 CompileSuccessfully(text, SPV_ENV_UNIVERSAL_1_4);
9105 EXPECT_EQ(SPV_ERROR_INVALID_DATA,
9106 ValidateInstructions(SPV_ENV_UNIVERSAL_1_4));
9107 EXPECT_THAT(getDiagnosticString(),
9108 HasSubstr("Missing decoration BlockMatchSamplerQCOM"));
9109 }
9110
9111 TEST_F(ValidateImage, QCOMImageProcessing2BlockMatchWindowSSDNoDecorRefNIT) {
9112 const std::string text = R"(
9113 OpCapability Shader
9114 OpCapability TextureBlockMatchQCOM
9115 OpCapability TextureBlockMatch2QCOM
9116 OpExtension "SPV_QCOM_image_processing"
9117 OpExtension "SPV_QCOM_image_processing2"
9118 %1 = OpExtInstImport "GLSL.std.450"
9119 OpMemoryModel Logical GLSL450
9120 OpEntryPoint Fragment %2 "main" %3 %4 %5 %6
9121 OpExecutionMode %2 OriginUpperLeft
9122 OpDecorate %3 Location 0
9123 OpDecorate %4 DescriptorSet 0
9124 OpDecorate %4 Binding 1
9125 OpDecorate %4 BlockMatchTextureQCOM
9126 OpDecorate %5 DescriptorSet 0
9127 OpDecorate %5 Binding 3
9128 OpDecorate %5 BlockMatchSamplerQCOM
9129 OpDecorate %6 DescriptorSet 0
9130 OpDecorate %6 Binding 2
9131 OpDecorate %6 BlockMatchSamplerQCOM
9132 %void = OpTypeVoid
9133 %8 = OpTypeFunction %void
9134 %uint = OpTypeInt 32 0
9135 %v2uint = OpTypeVector %uint 2
9136 %_ptr_Function_v2uint = OpTypePointer Function %v2uint
9137 %float = OpTypeFloat 32
9138 %v4float = OpTypeVector %float 4
9139 %_ptr_Input_float = OpTypePointer Input %float
9140 %_ptr_Function_uint = OpTypePointer Function %uint
9141 %uint_4 = OpConstant %uint 4
9142 %17 = OpConstantComposite %v2uint %uint_4 %uint_4
9143 %_ptr_Output_v4float = OpTypePointer Output %v4float
9144 %3 = OpVariable %_ptr_Output_v4float Output
9145 %19 = OpTypeImage %float 2D 0 0 0 1 Unknown
9146 %_ptr_UniformConstant_19 = OpTypePointer UniformConstant %19
9147 %4 = OpVariable %_ptr_UniformConstant_19 UniformConstant
9148 %21 = OpTypeSampler
9149 %_ptr_UniformConstant_21 = OpTypePointer UniformConstant %21
9150 %5 = OpVariable %_ptr_UniformConstant_21 UniformConstant
9151 %23 = OpTypeSampledImage %19
9152 %6 = OpVariable %_ptr_UniformConstant_19 UniformConstant
9153 %2 = OpFunction %void None %8
9154 %24 = OpLabel
9155 %25 = OpVariable %_ptr_Function_v2uint Function
9156 %26 = OpLoad %19 %4
9157 %27 = OpLoad %21 %5
9158 %28 = OpSampledImage %23 %26 %27
9159 %29 = OpLoad %v2uint %25
9160 %30 = OpLoad %19 %6
9161 %31 = OpLoad %21 %5
9162 %32 = OpSampledImage %23 %30 %31
9163 %33 = OpImageBlockMatchWindowSSDQCOM %v4float %28 %29 %32 %29 %29
9164 OpStore %3 %33
9165 OpReturn
9166 OpFunctionEnd
9167 )";
9168 CompileSuccessfully(text, SPV_ENV_UNIVERSAL_1_4);
9169 EXPECT_EQ(SPV_ERROR_INVALID_DATA,
9170 ValidateInstructions(SPV_ENV_UNIVERSAL_1_4));
9171 EXPECT_THAT(getDiagnosticString(),
9172 HasSubstr("Missing decoration BlockMatchTextureQCOM"));
9173 }
9174
9175 TEST_F(ValidateImage, QCOMImageProcessing2BlockMatchWindowSSDNoDecorRefNIS) {
9176 const std::string text = R"(
9177 OpCapability Shader
9178 OpCapability TextureBlockMatchQCOM
9179 OpCapability TextureBlockMatch2QCOM
9180 OpExtension "SPV_QCOM_image_processing"
9181 OpExtension "SPV_QCOM_image_processing2"
9182 %1 = OpExtInstImport "GLSL.std.450"
9183 OpMemoryModel Logical GLSL450
9184 OpEntryPoint Fragment %2 "main" %3 %4 %5 %6
9185 OpExecutionMode %2 OriginUpperLeft
9186 OpDecorate %3 Location 0
9187 OpDecorate %4 DescriptorSet 0
9188 OpDecorate %4 Binding 1
9189 OpDecorate %4 BlockMatchTextureQCOM
9190 OpDecorate %4 BlockMatchSamplerQCOM
9191 OpDecorate %5 DescriptorSet 0
9192 OpDecorate %5 Binding 3
9193 OpDecorate %6 DescriptorSet 0
9194 OpDecorate %6 Binding 2
9195 OpDecorate %6 BlockMatchTextureQCOM
9196 %void = OpTypeVoid
9197 %8 = OpTypeFunction %void
9198 %uint = OpTypeInt 32 0
9199 %v2uint = OpTypeVector %uint 2
9200 %_ptr_Function_v2uint = OpTypePointer Function %v2uint
9201 %float = OpTypeFloat 32
9202 %v4float = OpTypeVector %float 4
9203 %_ptr_Input_float = OpTypePointer Input %float
9204 %_ptr_Function_uint = OpTypePointer Function %uint
9205 %uint_4 = OpConstant %uint 4
9206 %17 = OpConstantComposite %v2uint %uint_4 %uint_4
9207 %_ptr_Output_v4float = OpTypePointer Output %v4float
9208 %3 = OpVariable %_ptr_Output_v4float Output
9209 %19 = OpTypeImage %float 2D 0 0 0 1 Unknown
9210 %_ptr_UniformConstant_19 = OpTypePointer UniformConstant %19
9211 %4 = OpVariable %_ptr_UniformConstant_19 UniformConstant
9212 %21 = OpTypeSampler
9213 %_ptr_UniformConstant_21 = OpTypePointer UniformConstant %21
9214 %5 = OpVariable %_ptr_UniformConstant_21 UniformConstant
9215 %23 = OpTypeSampledImage %19
9216 %6 = OpVariable %_ptr_UniformConstant_19 UniformConstant
9217 %2 = OpFunction %void None %8
9218 %24 = OpLabel
9219 %25 = OpVariable %_ptr_Function_v2uint Function
9220 %26 = OpLoad %19 %4
9221 %27 = OpLoad %21 %5
9222 %28 = OpSampledImage %23 %26 %27
9223 %29 = OpLoad %v2uint %25
9224 %30 = OpLoad %19 %6
9225 %31 = OpLoad %21 %5
9226 %32 = OpSampledImage %23 %30 %31
9227 %33 = OpImageBlockMatchWindowSSDQCOM %v4float %28 %29 %32 %29 %29
9228 OpStore %3 %33
9229 OpReturn
9230 OpFunctionEnd
9231 )";
9232 CompileSuccessfully(text, SPV_ENV_UNIVERSAL_1_4);
9233 EXPECT_EQ(SPV_ERROR_INVALID_DATA,
9234 ValidateInstructions(SPV_ENV_UNIVERSAL_1_4));
9235 EXPECT_THAT(getDiagnosticString(),
9236 HasSubstr("Missing decoration BlockMatchSamplerQCOM"));
9237 }
9238
9239 TEST_F(ValidateImage, QCOMImageProcessing2BlockMatchGatherSADNoDecorTargetIT) {
9240 const std::string text = R"(
9241 OpCapability Shader
9242 OpCapability TextureBlockMatchQCOM
9243 OpCapability TextureBlockMatch2QCOM
9244 OpExtension "SPV_QCOM_image_processing"
9245 OpExtension "SPV_QCOM_image_processing2"
9246 %1 = OpExtInstImport "GLSL.std.450"
9247 OpMemoryModel Logical GLSL450
9248 OpEntryPoint Fragment %2 "main" %3 %4 %5
9249 OpExecutionMode %2 OriginUpperLeft
9250 OpDecorate %3 Location 0
9251 OpDecorate %4 DescriptorSet 0
9252 OpDecorate %4 Binding 4
9253 OpDecorate %5 DescriptorSet 0
9254 OpDecorate %5 Binding 5
9255 OpDecorate %5 BlockMatchTextureQCOM
9256 %void = OpTypeVoid
9257 %7 = OpTypeFunction %void
9258 %uint = OpTypeInt 32 0
9259 %v2uint = OpTypeVector %uint 2
9260 %_ptr_Function_v2uint = OpTypePointer Function %v2uint
9261 %float = OpTypeFloat 32
9262 %v4float = OpTypeVector %float 4
9263 %_ptr_Input_v4float = OpTypePointer Input %v4float
9264 %_ptr_Input_float = OpTypePointer Input %float
9265 %_ptr_Function_uint = OpTypePointer Function %uint
9266 %_ptr_Output_v4float = OpTypePointer Output %v4float
9267 %3 = OpVariable %_ptr_Output_v4float Output
9268 %18 = OpTypeImage %float 2D 0 0 0 1 Unknown
9269 %19 = OpTypeSampledImage %18
9270 %_ptr_UniformConstant_19 = OpTypePointer UniformConstant %19
9271 %4 = OpVariable %_ptr_UniformConstant_19 UniformConstant
9272 %5 = OpVariable %_ptr_UniformConstant_19 UniformConstant
9273 %21 = OpTypeImage %float 2D 0 1 0 1 Unknown
9274 %2 = OpFunction %void None %7
9275 %22 = OpLabel
9276 %23 = OpVariable %_ptr_Function_v2uint Function
9277 %24 = OpLoad %19 %4
9278 %25 = OpLoad %v2uint %23
9279 %26 = OpLoad %19 %5
9280 %27 = OpLoad %v2uint %23
9281 %28 = OpLoad %v2uint %23
9282 %29 = OpImageBlockMatchGatherSADQCOM %v4float %24 %25 %26 %27 %28
9283 OpStore %3 %29
9284 OpReturn
9285 OpFunctionEnd
9286 )";
9287 CompileSuccessfully(text, SPV_ENV_UNIVERSAL_1_4);
9288 EXPECT_EQ(SPV_ERROR_INVALID_DATA,
9289 ValidateInstructions(SPV_ENV_UNIVERSAL_1_4));
9290 EXPECT_THAT(getDiagnosticString(),
9291 HasSubstr("Missing decoration BlockMatchTextureQCOM"));
9292 }
9293
9294 TEST_F(ValidateImage, QCOMImageProcessing2BlockMatchGatherSADNoDecorRefIT) {
9295 const std::string text = R"(
9296 OpCapability Shader
9297 OpCapability TextureBlockMatchQCOM
9298 OpCapability TextureBlockMatch2QCOM
9299 OpExtension "SPV_QCOM_image_processing"
9300 OpExtension "SPV_QCOM_image_processing2"
9301 %1 = OpExtInstImport "GLSL.std.450"
9302 OpMemoryModel Logical GLSL450
9303 OpEntryPoint Fragment %2 "main" %3 %4 %5
9304 OpExecutionMode %2 OriginUpperLeft
9305 OpDecorate %3 Location 0
9306 OpDecorate %4 DescriptorSet 0
9307 OpDecorate %4 Binding 4
9308 OpDecorate %4 BlockMatchTextureQCOM
9309 OpDecorate %5 DescriptorSet 0
9310 OpDecorate %5 Binding 5
9311 %void = OpTypeVoid
9312 %7 = OpTypeFunction %void
9313 %uint = OpTypeInt 32 0
9314 %v2uint = OpTypeVector %uint 2
9315 %_ptr_Function_v2uint = OpTypePointer Function %v2uint
9316 %float = OpTypeFloat 32
9317 %v4float = OpTypeVector %float 4
9318 %_ptr_Input_v4float = OpTypePointer Input %v4float
9319 %_ptr_Input_float = OpTypePointer Input %float
9320 %_ptr_Function_uint = OpTypePointer Function %uint
9321 %_ptr_Output_v4float = OpTypePointer Output %v4float
9322 %3 = OpVariable %_ptr_Output_v4float Output
9323 %18 = OpTypeImage %float 2D 0 0 0 1 Unknown
9324 %19 = OpTypeSampledImage %18
9325 %_ptr_UniformConstant_19 = OpTypePointer UniformConstant %19
9326 %4 = OpVariable %_ptr_UniformConstant_19 UniformConstant
9327 %5 = OpVariable %_ptr_UniformConstant_19 UniformConstant
9328 %21 = OpTypeImage %float 2D 0 1 0 1 Unknown
9329 %2 = OpFunction %void None %7
9330 %22 = OpLabel
9331 %23 = OpVariable %_ptr_Function_v2uint Function
9332 %24 = OpLoad %19 %4
9333 %25 = OpLoad %v2uint %23
9334 %26 = OpLoad %19 %5
9335 %27 = OpLoad %v2uint %23
9336 %28 = OpLoad %v2uint %23
9337 %29 = OpImageBlockMatchGatherSADQCOM %v4float %24 %25 %26 %27 %28
9338 OpStore %3 %29
9339 OpReturn
9340 OpFunctionEnd
9341 )";
9342 CompileSuccessfully(text, SPV_ENV_UNIVERSAL_1_4);
9343 EXPECT_EQ(SPV_ERROR_INVALID_DATA,
9344 ValidateInstructions(SPV_ENV_UNIVERSAL_1_4));
9345 EXPECT_THAT(getDiagnosticString(),
9346 HasSubstr("Missing decoration BlockMatchTextureQCOM"));
9347 }
9348
9349 TEST_F(ValidateImage, QCOMImageProcessing2BlockMatchGatherSADNoDecorTargetNIT) {
9350 const std::string text = R"(
9351 OpCapability Shader
9352 OpCapability TextureBlockMatchQCOM
9353 OpCapability TextureBlockMatch2QCOM
9354 OpExtension "SPV_QCOM_image_processing"
9355 OpExtension "SPV_QCOM_image_processing2"
9356 %1 = OpExtInstImport "GLSL.std.450"
9357 OpMemoryModel Logical GLSL450
9358 OpEntryPoint Fragment %2 "main" %3 %4 %5 %6
9359 OpExecutionMode %2 OriginUpperLeft
9360 OpDecorate %3 Location 0
9361 OpDecorate %4 DescriptorSet 0
9362 OpDecorate %4 Binding 1
9363 OpDecorate %5 DescriptorSet 0
9364 OpDecorate %5 Binding 3
9365 OpDecorate %6 DescriptorSet 0
9366 OpDecorate %6 Binding 2
9367 OpDecorate %6 BlockMatchTextureQCOM
9368 %void = OpTypeVoid
9369 %8 = OpTypeFunction %void
9370 %uint = OpTypeInt 32 0
9371 %v2uint = OpTypeVector %uint 2
9372 %_ptr_Function_v2uint = OpTypePointer Function %v2uint
9373 %float = OpTypeFloat 32
9374 %v4float = OpTypeVector %float 4
9375 %_ptr_Input_float = OpTypePointer Input %float
9376 %_ptr_Function_uint = OpTypePointer Function %uint
9377 %uint_4 = OpConstant %uint 4
9378 %17 = OpConstantComposite %v2uint %uint_4 %uint_4
9379 %_ptr_Output_v4float = OpTypePointer Output %v4float
9380 %3 = OpVariable %_ptr_Output_v4float Output
9381 %19 = OpTypeImage %float 2D 0 0 0 1 Unknown
9382 %_ptr_UniformConstant_19 = OpTypePointer UniformConstant %19
9383 %4 = OpVariable %_ptr_UniformConstant_19 UniformConstant
9384 %21 = OpTypeSampler
9385 %_ptr_UniformConstant_21 = OpTypePointer UniformConstant %21
9386 %5 = OpVariable %_ptr_UniformConstant_21 UniformConstant
9387 %23 = OpTypeSampledImage %19
9388 %6 = OpVariable %_ptr_UniformConstant_19 UniformConstant
9389 %2 = OpFunction %void None %8
9390 %24 = OpLabel
9391 %25 = OpVariable %_ptr_Function_v2uint Function
9392 %26 = OpLoad %19 %4
9393 %27 = OpLoad %21 %5
9394 %28 = OpSampledImage %23 %26 %27
9395 %29 = OpLoad %v2uint %25
9396 %30 = OpLoad %19 %6
9397 %31 = OpLoad %21 %5
9398 %32 = OpSampledImage %23 %30 %31
9399 %33 = OpImageBlockMatchGatherSADQCOM %v4float %28 %29 %32 %29 %29
9400 OpStore %3 %33
9401 OpReturn
9402 OpFunctionEnd
9403 )";
9404 CompileSuccessfully(text, SPV_ENV_UNIVERSAL_1_4);
9405 EXPECT_EQ(SPV_ERROR_INVALID_DATA,
9406 ValidateInstructions(SPV_ENV_UNIVERSAL_1_4));
9407 EXPECT_THAT(getDiagnosticString(),
9408 HasSubstr("Missing decoration BlockMatchTextureQCOM"));
9409 }
9410
9411 TEST_F(ValidateImage, QCOMImageProcessing2BlockMatchGatherSADNoDecorRefNIT) {
9412 const std::string text = R"(
9413 OpCapability Shader
9414 OpCapability TextureBlockMatchQCOM
9415 OpCapability TextureBlockMatch2QCOM
9416 OpExtension "SPV_QCOM_image_processing"
9417 OpExtension "SPV_QCOM_image_processing2"
9418 %1 = OpExtInstImport "GLSL.std.450"
9419 OpMemoryModel Logical GLSL450
9420 OpEntryPoint Fragment %2 "main" %3 %4 %5 %6
9421 OpExecutionMode %2 OriginUpperLeft
9422 OpDecorate %3 Location 0
9423 OpDecorate %4 DescriptorSet 0
9424 OpDecorate %4 Binding 1
9425 OpDecorate %4 BlockMatchTextureQCOM
9426 OpDecorate %5 DescriptorSet 0
9427 OpDecorate %5 Binding 3
9428 OpDecorate %6 DescriptorSet 0
9429 OpDecorate %6 Binding 2
9430 %void = OpTypeVoid
9431 %8 = OpTypeFunction %void
9432 %uint = OpTypeInt 32 0
9433 %v2uint = OpTypeVector %uint 2
9434 %_ptr_Function_v2uint = OpTypePointer Function %v2uint
9435 %float = OpTypeFloat 32
9436 %v4float = OpTypeVector %float 4
9437 %_ptr_Input_float = OpTypePointer Input %float
9438 %_ptr_Function_uint = OpTypePointer Function %uint
9439 %uint_4 = OpConstant %uint 4
9440 %17 = OpConstantComposite %v2uint %uint_4 %uint_4
9441 %_ptr_Output_v4float = OpTypePointer Output %v4float
9442 %3 = OpVariable %_ptr_Output_v4float Output
9443 %19 = OpTypeImage %float 2D 0 0 0 1 Unknown
9444 %_ptr_UniformConstant_19 = OpTypePointer UniformConstant %19
9445 %4 = OpVariable %_ptr_UniformConstant_19 UniformConstant
9446 %21 = OpTypeSampler
9447 %_ptr_UniformConstant_21 = OpTypePointer UniformConstant %21
9448 %5 = OpVariable %_ptr_UniformConstant_21 UniformConstant
9449 %23 = OpTypeSampledImage %19
9450 %6 = OpVariable %_ptr_UniformConstant_19 UniformConstant
9451 %2 = OpFunction %void None %8
9452 %24 = OpLabel
9453 %25 = OpVariable %_ptr_Function_v2uint Function
9454 %26 = OpLoad %19 %4
9455 %27 = OpLoad %21 %5
9456 %28 = OpSampledImage %23 %26 %27
9457 %29 = OpLoad %v2uint %25
9458 %30 = OpLoad %19 %6
9459 %31 = OpLoad %21 %5
9460 %32 = OpSampledImage %23 %30 %31
9461 %33 = OpImageBlockMatchGatherSADQCOM %v4float %28 %29 %32 %29 %29
9462 OpStore %3 %33
9463 OpReturn
9464 OpFunctionEnd
9465 )";
9466 CompileSuccessfully(text, SPV_ENV_UNIVERSAL_1_4);
9467 EXPECT_EQ(SPV_ERROR_INVALID_DATA,
9468 ValidateInstructions(SPV_ENV_UNIVERSAL_1_4));
9469 EXPECT_THAT(getDiagnosticString(),
9470 HasSubstr("Missing decoration BlockMatchTextureQCOM"));
9471 }
9472
9473 TEST_F(ValidateImage, QCOMImageProcessing2BlockMatchGatherSSDNoDecorTargetIT) {
9474 const std::string text = R"(
9475 OpCapability Shader
9476 OpCapability TextureBlockMatchQCOM
9477 OpCapability TextureBlockMatch2QCOM
9478 OpExtension "SPV_QCOM_image_processing"
9479 OpExtension "SPV_QCOM_image_processing2"
9480 %1 = OpExtInstImport "GLSL.std.450"
9481 OpMemoryModel Logical GLSL450
9482 OpEntryPoint Fragment %2 "main" %3 %4 %5
9483 OpExecutionMode %2 OriginUpperLeft
9484 OpDecorate %3 Location 0
9485 OpDecorate %4 DescriptorSet 0
9486 OpDecorate %4 Binding 4
9487 OpDecorate %5 DescriptorSet 0
9488 OpDecorate %5 Binding 5
9489 OpDecorate %5 BlockMatchTextureQCOM
9490 %void = OpTypeVoid
9491 %7 = OpTypeFunction %void
9492 %uint = OpTypeInt 32 0
9493 %v2uint = OpTypeVector %uint 2
9494 %_ptr_Function_v2uint = OpTypePointer Function %v2uint
9495 %float = OpTypeFloat 32
9496 %v4float = OpTypeVector %float 4
9497 %_ptr_Input_v4float = OpTypePointer Input %v4float
9498 %_ptr_Input_float = OpTypePointer Input %float
9499 %_ptr_Function_uint = OpTypePointer Function %uint
9500 %_ptr_Output_v4float = OpTypePointer Output %v4float
9501 %3 = OpVariable %_ptr_Output_v4float Output
9502 %18 = OpTypeImage %float 2D 0 0 0 1 Unknown
9503 %19 = OpTypeSampledImage %18
9504 %_ptr_UniformConstant_19 = OpTypePointer UniformConstant %19
9505 %4 = OpVariable %_ptr_UniformConstant_19 UniformConstant
9506 %5 = OpVariable %_ptr_UniformConstant_19 UniformConstant
9507 %21 = OpTypeImage %float 2D 0 1 0 1 Unknown
9508 %2 = OpFunction %void None %7
9509 %22 = OpLabel
9510 %23 = OpVariable %_ptr_Function_v2uint Function
9511 %24 = OpLoad %19 %4
9512 %25 = OpLoad %v2uint %23
9513 %26 = OpLoad %19 %5
9514 %27 = OpLoad %v2uint %23
9515 %28 = OpLoad %v2uint %23
9516 %29 = OpImageBlockMatchGatherSSDQCOM %v4float %24 %25 %26 %27 %28
9517 OpStore %3 %29
9518 OpReturn
9519 OpFunctionEnd
9520 )";
9521 CompileSuccessfully(text, SPV_ENV_UNIVERSAL_1_4);
9522 EXPECT_EQ(SPV_ERROR_INVALID_DATA,
9523 ValidateInstructions(SPV_ENV_UNIVERSAL_1_4));
9524 EXPECT_THAT(getDiagnosticString(),
9525 HasSubstr("Missing decoration BlockMatchTextureQCOM"));
9526 }
9527
9528 TEST_F(ValidateImage, QCOMImageProcessing2BlockMatchGatherSSDNoDecorRefIT) {
9529 const std::string text = R"(
9530 OpCapability Shader
9531 OpCapability TextureBlockMatchQCOM
9532 OpCapability TextureBlockMatch2QCOM
9533 OpExtension "SPV_QCOM_image_processing"
9534 OpExtension "SPV_QCOM_image_processing2"
9535 %1 = OpExtInstImport "GLSL.std.450"
9536 OpMemoryModel Logical GLSL450
9537 OpEntryPoint Fragment %2 "main" %3 %4 %5
9538 OpExecutionMode %2 OriginUpperLeft
9539 OpDecorate %3 Location 0
9540 OpDecorate %4 DescriptorSet 0
9541 OpDecorate %4 Binding 4
9542 OpDecorate %4 BlockMatchTextureQCOM
9543 OpDecorate %5 DescriptorSet 0
9544 OpDecorate %5 Binding 5
9545 %void = OpTypeVoid
9546 %7 = OpTypeFunction %void
9547 %uint = OpTypeInt 32 0
9548 %v2uint = OpTypeVector %uint 2
9549 %_ptr_Function_v2uint = OpTypePointer Function %v2uint
9550 %float = OpTypeFloat 32
9551 %v4float = OpTypeVector %float 4
9552 %_ptr_Input_v4float = OpTypePointer Input %v4float
9553 %_ptr_Input_float = OpTypePointer Input %float
9554 %_ptr_Function_uint = OpTypePointer Function %uint
9555 %_ptr_Output_v4float = OpTypePointer Output %v4float
9556 %3 = OpVariable %_ptr_Output_v4float Output
9557 %18 = OpTypeImage %float 2D 0 0 0 1 Unknown
9558 %19 = OpTypeSampledImage %18
9559 %_ptr_UniformConstant_19 = OpTypePointer UniformConstant %19
9560 %4 = OpVariable %_ptr_UniformConstant_19 UniformConstant
9561 %5 = OpVariable %_ptr_UniformConstant_19 UniformConstant
9562 %21 = OpTypeImage %float 2D 0 1 0 1 Unknown
9563 %2 = OpFunction %void None %7
9564 %22 = OpLabel
9565 %23 = OpVariable %_ptr_Function_v2uint Function
9566 %24 = OpLoad %19 %4
9567 %25 = OpLoad %v2uint %23
9568 %26 = OpLoad %19 %5
9569 %27 = OpLoad %v2uint %23
9570 %28 = OpLoad %v2uint %23
9571 %29 = OpImageBlockMatchGatherSSDQCOM %v4float %24 %25 %26 %27 %28
9572 OpStore %3 %29
9573 OpReturn
9574 OpFunctionEnd
9575 )";
9576 CompileSuccessfully(text, SPV_ENV_UNIVERSAL_1_4);
9577 EXPECT_EQ(SPV_ERROR_INVALID_DATA,
9578 ValidateInstructions(SPV_ENV_UNIVERSAL_1_4));
9579 EXPECT_THAT(getDiagnosticString(),
9580 HasSubstr("Missing decoration BlockMatchTextureQCOM"));
9581 }
9582
9583 TEST_F(ValidateImage, QCOMImageProcessing2BlockMatchGatherSSDNoDecorTargetNIT) {
9584 const std::string text = R"(
9585 OpCapability Shader
9586 OpCapability TextureBlockMatchQCOM
9587 OpCapability TextureBlockMatch2QCOM
9588 OpExtension "SPV_QCOM_image_processing"
9589 OpExtension "SPV_QCOM_image_processing2"
9590 %1 = OpExtInstImport "GLSL.std.450"
9591 OpMemoryModel Logical GLSL450
9592 OpEntryPoint Fragment %2 "main" %3 %4 %5 %6
9593 OpExecutionMode %2 OriginUpperLeft
9594 OpDecorate %3 Location 0
9595 OpDecorate %4 DescriptorSet 0
9596 OpDecorate %4 Binding 1
9597 OpDecorate %5 DescriptorSet 0
9598 OpDecorate %5 Binding 3
9599 OpDecorate %6 DescriptorSet 0
9600 OpDecorate %6 Binding 2
9601 OpDecorate %6 BlockMatchTextureQCOM
9602 %void = OpTypeVoid
9603 %8 = OpTypeFunction %void
9604 %uint = OpTypeInt 32 0
9605 %v2uint = OpTypeVector %uint 2
9606 %_ptr_Function_v2uint = OpTypePointer Function %v2uint
9607 %float = OpTypeFloat 32
9608 %v4float = OpTypeVector %float 4
9609 %_ptr_Input_float = OpTypePointer Input %float
9610 %_ptr_Function_uint = OpTypePointer Function %uint
9611 %uint_4 = OpConstant %uint 4
9612 %17 = OpConstantComposite %v2uint %uint_4 %uint_4
9613 %_ptr_Output_v4float = OpTypePointer Output %v4float
9614 %3 = OpVariable %_ptr_Output_v4float Output
9615 %19 = OpTypeImage %float 2D 0 0 0 1 Unknown
9616 %_ptr_UniformConstant_19 = OpTypePointer UniformConstant %19
9617 %4 = OpVariable %_ptr_UniformConstant_19 UniformConstant
9618 %21 = OpTypeSampler
9619 %_ptr_UniformConstant_21 = OpTypePointer UniformConstant %21
9620 %5 = OpVariable %_ptr_UniformConstant_21 UniformConstant
9621 %23 = OpTypeSampledImage %19
9622 %6 = OpVariable %_ptr_UniformConstant_19 UniformConstant
9623 %2 = OpFunction %void None %8
9624 %24 = OpLabel
9625 %25 = OpVariable %_ptr_Function_v2uint Function
9626 %26 = OpLoad %19 %4
9627 %27 = OpLoad %21 %5
9628 %28 = OpSampledImage %23 %26 %27
9629 %29 = OpLoad %v2uint %25
9630 %30 = OpLoad %19 %6
9631 %31 = OpLoad %21 %5
9632 %32 = OpSampledImage %23 %30 %31
9633 %33 = OpImageBlockMatchGatherSSDQCOM %v4float %28 %29 %32 %29 %29
9634 OpStore %3 %33
9635 OpReturn
9636 OpFunctionEnd
9637 )";
9638 CompileSuccessfully(text, SPV_ENV_UNIVERSAL_1_4);
9639 EXPECT_EQ(SPV_ERROR_INVALID_DATA,
9640 ValidateInstructions(SPV_ENV_UNIVERSAL_1_4));
9641 EXPECT_THAT(getDiagnosticString(),
9642 HasSubstr("Missing decoration BlockMatchTextureQCOM"));
9643 }
9644
9645 TEST_F(ValidateImage, QCOMImageProcessing2BlockMatchGatherSSDNoDecorRefNIT) {
9646 const std::string text = R"(
9647 OpCapability Shader
9648 OpCapability TextureBlockMatchQCOM
9649 OpCapability TextureBlockMatch2QCOM
9650 OpExtension "SPV_QCOM_image_processing"
9651 OpExtension "SPV_QCOM_image_processing2"
9652 %1 = OpExtInstImport "GLSL.std.450"
9653 OpMemoryModel Logical GLSL450
9654 OpEntryPoint Fragment %2 "main" %3 %4 %5 %6
9655 OpExecutionMode %2 OriginUpperLeft
9656 OpDecorate %3 Location 0
9657 OpDecorate %4 DescriptorSet 0
9658 OpDecorate %4 Binding 1
9659 OpDecorate %4 BlockMatchTextureQCOM
9660 OpDecorate %5 DescriptorSet 0
9661 OpDecorate %5 Binding 3
9662 OpDecorate %6 DescriptorSet 0
9663 OpDecorate %6 Binding 2
9664 %void = OpTypeVoid
9665 %8 = OpTypeFunction %void
9666 %uint = OpTypeInt 32 0
9667 %v2uint = OpTypeVector %uint 2
9668 %_ptr_Function_v2uint = OpTypePointer Function %v2uint
9669 %float = OpTypeFloat 32
9670 %v4float = OpTypeVector %float 4
9671 %_ptr_Input_float = OpTypePointer Input %float
9672 %_ptr_Function_uint = OpTypePointer Function %uint
9673 %uint_4 = OpConstant %uint 4
9674 %17 = OpConstantComposite %v2uint %uint_4 %uint_4
9675 %_ptr_Output_v4float = OpTypePointer Output %v4float
9676 %3 = OpVariable %_ptr_Output_v4float Output
9677 %19 = OpTypeImage %float 2D 0 0 0 1 Unknown
9678 %_ptr_UniformConstant_19 = OpTypePointer UniformConstant %19
9679 %4 = OpVariable %_ptr_UniformConstant_19 UniformConstant
9680 %21 = OpTypeSampler
9681 %_ptr_UniformConstant_21 = OpTypePointer UniformConstant %21
9682 %5 = OpVariable %_ptr_UniformConstant_21 UniformConstant
9683 %23 = OpTypeSampledImage %19
9684 %6 = OpVariable %_ptr_UniformConstant_19 UniformConstant
9685 %2 = OpFunction %void None %8
9686 %24 = OpLabel
9687 %25 = OpVariable %_ptr_Function_v2uint Function
9688 %26 = OpLoad %19 %4
9689 %27 = OpLoad %21 %5
9690 %28 = OpSampledImage %23 %26 %27
9691 %29 = OpLoad %v2uint %25
9692 %30 = OpLoad %19 %6
9693 %31 = OpLoad %21 %5
9694 %32 = OpSampledImage %23 %30 %31
9695 %33 = OpImageBlockMatchGatherSSDQCOM %v4float %28 %29 %32 %29 %29
9696 OpStore %3 %33
9697 OpReturn
9698 OpFunctionEnd
9699 )";
9700 CompileSuccessfully(text, SPV_ENV_UNIVERSAL_1_4);
9701 EXPECT_EQ(SPV_ERROR_INVALID_DATA,
9702 ValidateInstructions(SPV_ENV_UNIVERSAL_1_4));
9703 EXPECT_THAT(getDiagnosticString(),
9704 HasSubstr("Missing decoration BlockMatchTextureQCOM"));
9705 }
9706
9707 TEST_F(ValidateImage,
9708 QCOMImageProcessing2BlockMatchWindowSADInvalidUseTargetI) {
9709 const std::string text = R"(
9710 OpCapability Shader
9711 OpCapability TextureBlockMatchQCOM
9712 OpCapability TextureBlockMatch2QCOM
9713 OpExtension "SPV_QCOM_image_processing"
9714 OpExtension "SPV_QCOM_image_processing2"
9715 %1 = OpExtInstImport "GLSL.std.450"
9716 OpMemoryModel Logical GLSL450
9717 OpEntryPoint Fragment %2 "main" %3 %4 %5 %6
9718 OpExecutionMode %2 OriginUpperLeft
9719 OpDecorate %3 Location 0
9720 OpDecorate %4 Location 0
9721 OpDecorate %5 DescriptorSet 0
9722 OpDecorate %5 Binding 4
9723 OpDecorate %6 DescriptorSet 0
9724 OpDecorate %6 Binding 5
9725 OpDecorate %5 BlockMatchTextureQCOM
9726 OpDecorate %5 BlockMatchSamplerQCOM
9727 OpDecorate %6 BlockMatchTextureQCOM
9728 OpDecorate %6 BlockMatchSamplerQCOM
9729 %void = OpTypeVoid
9730 %8 = OpTypeFunction %void
9731 %uint = OpTypeInt 32 0
9732 %v2uint = OpTypeVector %uint 2
9733 %_ptr_Function_v2uint = OpTypePointer Function %v2uint
9734 %float = OpTypeFloat 32
9735 %v4float = OpTypeVector %float 4
9736 %_ptr_Input_v4float = OpTypePointer Input %v4float
9737 %3 = OpVariable %_ptr_Input_v4float Input
9738 %uint_4 = OpConstant %uint 4
9739 %16 = OpConstantComposite %v2uint %uint_4 %uint_4
9740 %_ptr_Output_v4float = OpTypePointer Output %v4float
9741 %4 = OpVariable %_ptr_Output_v4float Output
9742 %18 = OpTypeImage %float 2D 0 0 0 1 Unknown
9743 %_ptr_UniformConstant_18 = OpTypePointer UniformConstant %18
9744 %20 = OpTypeSampledImage %18
9745 %_ptr_UniformConstant_20 = OpTypePointer UniformConstant %20
9746 %5 = OpVariable %_ptr_UniformConstant_20 UniformConstant
9747 %6 = OpVariable %_ptr_UniformConstant_20 UniformConstant
9748 %v2float = OpTypeVector %float 2
9749 %23 = OpTypeImage %float 2D 0 1 0 1 Unknown
9750 %2 = OpFunction %void None %8
9751 %24 = OpLabel
9752 %25 = OpVariable %_ptr_Function_v2uint Function
9753 OpStore %25 %16
9754 %26 = OpLoad %20 %5
9755 %27 = OpLoad %v2uint %25
9756 %28 = OpLoad %20 %6
9757 %29 = OpLoad %v2uint %25
9758 %30 = OpLoad %v2uint %25
9759 %31 = OpImageBlockMatchWindowSADQCOM %v4float %26 %27 %28 %29 %30
9760 OpStore %4 %31
9761 %32 = OpLoad %20 %5
9762 %33 = OpLoad %v4float %3
9763 %34 = OpVectorShuffle %v2float %33 %33 0 2
9764 %35 = OpImageSampleImplicitLod %v4float %32 %34
9765 OpStore %4 %35
9766 OpReturn
9767 OpFunctionEnd
9768 )";
9769 CompileSuccessfully(text, SPV_ENV_UNIVERSAL_1_4);
9770 EXPECT_EQ(SPV_ERROR_INVALID_DATA,
9771 ValidateInstructions(SPV_ENV_UNIVERSAL_1_4));
9772 EXPECT_THAT(
9773 getDiagnosticString(),
9774 HasSubstr("Illegal use of QCOM image processing decorated texture"));
9775 }
9776
9777 TEST_F(ValidateImage, QCOMImageProcessing2BlockMatchWindowSADInvalidUseRefI) {
9778 const std::string text = R"(
9779 OpCapability Shader
9780 OpCapability TextureBlockMatchQCOM
9781 OpCapability TextureBlockMatch2QCOM
9782 OpExtension "SPV_QCOM_image_processing"
9783 OpExtension "SPV_QCOM_image_processing2"
9784 %1 = OpExtInstImport "GLSL.std.450"
9785 OpMemoryModel Logical GLSL450
9786 OpEntryPoint Fragment %2 "main" %3 %4 %5 %6
9787 OpExecutionMode %2 OriginUpperLeft
9788 OpDecorate %3 Location 0
9789 OpDecorate %4 Location 0
9790 OpDecorate %5 DescriptorSet 0
9791 OpDecorate %5 Binding 4
9792 OpDecorate %6 DescriptorSet 0
9793 OpDecorate %6 Binding 5
9794 OpDecorate %5 BlockMatchTextureQCOM
9795 OpDecorate %5 BlockMatchSamplerQCOM
9796 OpDecorate %6 BlockMatchTextureQCOM
9797 OpDecorate %6 BlockMatchSamplerQCOM
9798 %void = OpTypeVoid
9799 %8 = OpTypeFunction %void
9800 %uint = OpTypeInt 32 0
9801 %v2uint = OpTypeVector %uint 2
9802 %_ptr_Function_v2uint = OpTypePointer Function %v2uint
9803 %float = OpTypeFloat 32
9804 %v4float = OpTypeVector %float 4
9805 %_ptr_Input_v4float = OpTypePointer Input %v4float
9806 %3 = OpVariable %_ptr_Input_v4float Input
9807 %uint_4 = OpConstant %uint 4
9808 %16 = OpConstantComposite %v2uint %uint_4 %uint_4
9809 %_ptr_Output_v4float = OpTypePointer Output %v4float
9810 %4 = OpVariable %_ptr_Output_v4float Output
9811 %18 = OpTypeImage %float 2D 0 0 0 1 Unknown
9812 %_ptr_UniformConstant_18 = OpTypePointer UniformConstant %18
9813 %20 = OpTypeSampledImage %18
9814 %_ptr_UniformConstant_20 = OpTypePointer UniformConstant %20
9815 %5 = OpVariable %_ptr_UniformConstant_20 UniformConstant
9816 %6 = OpVariable %_ptr_UniformConstant_20 UniformConstant
9817 %v2float = OpTypeVector %float 2
9818 %23 = OpTypeImage %float 2D 0 1 0 1 Unknown
9819 %2 = OpFunction %void None %8
9820 %24 = OpLabel
9821 %25 = OpVariable %_ptr_Function_v2uint Function
9822 OpStore %25 %16
9823 %26 = OpLoad %20 %5
9824 %27 = OpLoad %v2uint %25
9825 %28 = OpLoad %20 %6
9826 %29 = OpLoad %v2uint %25
9827 %30 = OpLoad %v2uint %25
9828 %31 = OpImageBlockMatchWindowSADQCOM %v4float %26 %27 %28 %29 %30
9829 OpStore %4 %31
9830 %32 = OpLoad %20 %6
9831 %33 = OpLoad %v4float %3
9832 %34 = OpVectorShuffle %v2float %33 %33 0 2
9833 %35 = OpImageSampleImplicitLod %v4float %32 %34
9834 OpStore %4 %35
9835 OpReturn
9836 OpFunctionEnd
9837 )";
9838 CompileSuccessfully(text, SPV_ENV_UNIVERSAL_1_4);
9839 EXPECT_EQ(SPV_ERROR_INVALID_DATA,
9840 ValidateInstructions(SPV_ENV_UNIVERSAL_1_4));
9841 EXPECT_THAT(
9842 getDiagnosticString(),
9843 HasSubstr("Illegal use of QCOM image processing decorated texture"));
9844 }
9845
9846 TEST_F(ValidateImage,
9847 QCOMImageProcessing2BlockMatchWindowSADInvalidUseTargetNI) {
9848 const std::string text = R"(
9849 OpCapability Shader
9850 OpCapability TextureBlockMatchQCOM
9851 OpCapability TextureBlockMatch2QCOM
9852 OpExtension "SPV_QCOM_image_processing"
9853 OpExtension "SPV_QCOM_image_processing2"
9854 %1 = OpExtInstImport "GLSL.std.450"
9855 OpMemoryModel Logical GLSL450
9856 OpEntryPoint Fragment %main "main" %100 %101 %102 %103 %104
9857 OpExecutionMode %main OriginUpperLeft
9858 OpDecorate %100 Location 0
9859 OpDecorate %101 Location 0
9860 OpDecorate %102 DescriptorSet 0
9861 OpDecorate %102 Binding 1
9862 OpDecorate %103 DescriptorSet 0
9863 OpDecorate %103 Binding 3
9864 OpDecorate %104 DescriptorSet 0
9865 OpDecorate %104 Binding 2
9866 OpDecorate %102 BlockMatchTextureQCOM
9867 OpDecorate %103 BlockMatchSamplerQCOM
9868 OpDecorate %104 BlockMatchTextureQCOM
9869 %void = OpTypeVoid
9870 %3 = OpTypeFunction %void
9871 %uint = OpTypeInt 32 0
9872 %v2uint = OpTypeVector %uint 2
9873 %_ptr_Function_v2uint = OpTypePointer Function %v2uint
9874 %float = OpTypeFloat 32
9875 %v4float = OpTypeVector %float 4
9876 %_ptr_Input_v4float = OpTypePointer Input %v4float
9877 %100 = OpVariable %_ptr_Input_v4float Input
9878 %_ptr_Output_v4float = OpTypePointer Output %v4float
9879 %101 = OpVariable %_ptr_Output_v4float Output
9880 %42 = OpTypeImage %float 2D 0 0 0 1 Unknown
9881 %_ptr_UniformConstant_42 = OpTypePointer UniformConstant %42
9882 %102 = OpVariable %_ptr_UniformConstant_42 UniformConstant
9883 %46 = OpTypeSampler
9884 %_ptr_UniformConstant_46 = OpTypePointer UniformConstant %46
9885 %103 = OpVariable %_ptr_UniformConstant_46 UniformConstant
9886 %50 = OpTypeSampledImage %42
9887 %104 = OpVariable %_ptr_UniformConstant_42 UniformConstant
9888 %v2float = OpTypeVector %float 2
9889 %main = OpFunction %void None %3
9890 %5 = OpLabel
9891 %15 = OpVariable %_ptr_Function_v2uint Function
9892 %45 = OpLoad %42 %102
9893 %49 = OpLoad %46 %103
9894 %51 = OpSampledImage %50 %45 %49
9895 %52 = OpLoad %v2uint %15
9896 %54 = OpLoad %42 %104
9897 %55 = OpLoad %46 %103
9898 %56 = OpSampledImage %50 %54 %55
9899 %57 = OpLoad %v2uint %15
9900 %58 = OpLoad %v2uint %15
9901 %59 = OpImageBlockMatchWindowSADQCOM %v4float %51 %52 %56 %57 %58
9902 OpStore %101 %59
9903 %69 = OpLoad %42 %102
9904 %70 = OpLoad %46 %103
9905 %71 = OpSampledImage %50 %69 %70
9906 %73 = OpLoad %v4float %100
9907 %74 = OpVectorShuffle %v2float %73 %73 0 0
9908 %75 = OpImageSampleImplicitLod %v4float %71 %74
9909 OpStore %101 %75
9910 OpReturn
9911 OpFunctionEnd
9912 )";
9913 CompileSuccessfully(text, SPV_ENV_UNIVERSAL_1_4);
9914 EXPECT_EQ(SPV_ERROR_INVALID_DATA,
9915 ValidateInstructions(SPV_ENV_UNIVERSAL_1_4));
9916 EXPECT_THAT(
9917 getDiagnosticString(),
9918 HasSubstr("Illegal use of QCOM image processing decorated texture"));
9919 }
9920
9921 TEST_F(ValidateImage, QCOMImageProcessing2BlockMatchWindowSADInvalidUseRefNI) {
9922 const std::string text = R"(
9923 OpCapability Shader
9924 OpCapability TextureBlockMatchQCOM
9925 OpCapability TextureBlockMatch2QCOM
9926 OpExtension "SPV_QCOM_image_processing"
9927 OpExtension "SPV_QCOM_image_processing2"
9928 %1 = OpExtInstImport "GLSL.std.450"
9929 OpMemoryModel Logical GLSL450
9930 OpEntryPoint Fragment %main "main" %100 %101 %102 %103 %104
9931 OpExecutionMode %main OriginUpperLeft
9932 OpDecorate %100 Location 0
9933 OpDecorate %101 Location 0
9934 OpDecorate %102 DescriptorSet 0
9935 OpDecorate %102 Binding 1
9936 OpDecorate %103 DescriptorSet 0
9937 OpDecorate %103 Binding 3
9938 OpDecorate %104 DescriptorSet 0
9939 OpDecorate %104 Binding 2
9940 OpDecorate %102 BlockMatchTextureQCOM
9941 OpDecorate %103 BlockMatchSamplerQCOM
9942 OpDecorate %104 BlockMatchTextureQCOM
9943 %void = OpTypeVoid
9944 %3 = OpTypeFunction %void
9945 %uint = OpTypeInt 32 0
9946 %v2uint = OpTypeVector %uint 2
9947 %_ptr_Function_v2uint = OpTypePointer Function %v2uint
9948 %float = OpTypeFloat 32
9949 %v4float = OpTypeVector %float 4
9950 %_ptr_Input_v4float = OpTypePointer Input %v4float
9951 %100 = OpVariable %_ptr_Input_v4float Input
9952 %_ptr_Output_v4float = OpTypePointer Output %v4float
9953 %101 = OpVariable %_ptr_Output_v4float Output
9954 %42 = OpTypeImage %float 2D 0 0 0 1 Unknown
9955 %_ptr_UniformConstant_42 = OpTypePointer UniformConstant %42
9956 %102 = OpVariable %_ptr_UniformConstant_42 UniformConstant
9957 %46 = OpTypeSampler
9958 %_ptr_UniformConstant_46 = OpTypePointer UniformConstant %46
9959 %103 = OpVariable %_ptr_UniformConstant_46 UniformConstant
9960 %50 = OpTypeSampledImage %42
9961 %104 = OpVariable %_ptr_UniformConstant_42 UniformConstant
9962 %v2float = OpTypeVector %float 2
9963 %main = OpFunction %void None %3
9964 %5 = OpLabel
9965 %15 = OpVariable %_ptr_Function_v2uint Function
9966 %45 = OpLoad %42 %102
9967 %49 = OpLoad %46 %103
9968 %51 = OpSampledImage %50 %45 %49
9969 %52 = OpLoad %v2uint %15
9970 %54 = OpLoad %42 %104
9971 %55 = OpLoad %46 %103
9972 %56 = OpSampledImage %50 %54 %55
9973 %57 = OpLoad %v2uint %15
9974 %58 = OpLoad %v2uint %15
9975 %59 = OpImageBlockMatchWindowSADQCOM %v4float %51 %52 %56 %57 %58
9976 OpStore %101 %59
9977 %69 = OpLoad %42 %104
9978 %70 = OpLoad %46 %103
9979 %71 = OpSampledImage %50 %69 %70
9980 %73 = OpLoad %v4float %100
9981 %74 = OpVectorShuffle %v2float %73 %73 0 0
9982 %75 = OpImageSampleImplicitLod %v4float %71 %74
9983 OpStore %101 %75
9984 OpReturn
9985 OpFunctionEnd
9986 )";
9987 CompileSuccessfully(text, SPV_ENV_UNIVERSAL_1_4);
9988 EXPECT_EQ(SPV_ERROR_INVALID_DATA,
9989 ValidateInstructions(SPV_ENV_UNIVERSAL_1_4));
9990 EXPECT_THAT(
9991 getDiagnosticString(),
9992 HasSubstr("Illegal use of QCOM image processing decorated texture"));
9993 }
9994
9995 TEST_F(ValidateImage,
9996 QCOMImageProcessing2BlockMatchWindowSSDInvalidUseTargetI) {
9997 const std::string text = R"(
9998 OpCapability Shader
9999 OpCapability TextureBlockMatchQCOM
10000 OpCapability TextureBlockMatch2QCOM
10001 OpExtension "SPV_QCOM_image_processing"
10002 OpExtension "SPV_QCOM_image_processing2"
10003 %1 = OpExtInstImport "GLSL.std.450"
10004 OpMemoryModel Logical GLSL450
10005 OpEntryPoint Fragment %2 "main" %3 %4 %5 %6
10006 OpExecutionMode %2 OriginUpperLeft
10007 OpDecorate %3 Location 0
10008 OpDecorate %4 Location 0
10009 OpDecorate %5 DescriptorSet 0
10010 OpDecorate %5 Binding 4
10011 OpDecorate %6 DescriptorSet 0
10012 OpDecorate %6 Binding 5
10013 OpDecorate %5 BlockMatchTextureQCOM
10014 OpDecorate %5 BlockMatchSamplerQCOM
10015 OpDecorate %6 BlockMatchTextureQCOM
10016 OpDecorate %6 BlockMatchSamplerQCOM
10017 %void = OpTypeVoid
10018 %8 = OpTypeFunction %void
10019 %uint = OpTypeInt 32 0
10020 %v2uint = OpTypeVector %uint 2
10021 %_ptr_Function_v2uint = OpTypePointer Function %v2uint
10022 %float = OpTypeFloat 32
10023 %v4float = OpTypeVector %float 4
10024 %_ptr_Input_v4float = OpTypePointer Input %v4float
10025 %3 = OpVariable %_ptr_Input_v4float Input
10026 %uint_4 = OpConstant %uint 4
10027 %16 = OpConstantComposite %v2uint %uint_4 %uint_4
10028 %_ptr_Output_v4float = OpTypePointer Output %v4float
10029 %4 = OpVariable %_ptr_Output_v4float Output
10030 %18 = OpTypeImage %float 2D 0 0 0 1 Unknown
10031 %_ptr_UniformConstant_18 = OpTypePointer UniformConstant %18
10032 %20 = OpTypeSampledImage %18
10033 %_ptr_UniformConstant_20 = OpTypePointer UniformConstant %20
10034 %5 = OpVariable %_ptr_UniformConstant_20 UniformConstant
10035 %6 = OpVariable %_ptr_UniformConstant_20 UniformConstant
10036 %v2float = OpTypeVector %float 2
10037 %23 = OpTypeImage %float 2D 0 1 0 1 Unknown
10038 %2 = OpFunction %void None %8
10039 %24 = OpLabel
10040 %25 = OpVariable %_ptr_Function_v2uint Function
10041 OpStore %25 %16
10042 %26 = OpLoad %20 %5
10043 %27 = OpLoad %v2uint %25
10044 %28 = OpLoad %20 %6
10045 %29 = OpLoad %v2uint %25
10046 %30 = OpLoad %v2uint %25
10047 %31 = OpImageBlockMatchWindowSSDQCOM %v4float %26 %27 %28 %29 %30
10048 OpStore %4 %31
10049 %32 = OpLoad %20 %5
10050 %33 = OpLoad %v4float %3
10051 %34 = OpVectorShuffle %v2float %33 %33 0 2
10052 %35 = OpImageSampleImplicitLod %v4float %32 %34
10053 OpStore %4 %35
10054 OpReturn
10055 OpFunctionEnd
10056 )";
10057 CompileSuccessfully(text, SPV_ENV_UNIVERSAL_1_4);
10058 EXPECT_EQ(SPV_ERROR_INVALID_DATA,
10059 ValidateInstructions(SPV_ENV_UNIVERSAL_1_4));
10060 EXPECT_THAT(
10061 getDiagnosticString(),
10062 HasSubstr("Illegal use of QCOM image processing decorated texture"));
10063 }
10064
10065 TEST_F(ValidateImage, QCOMImageProcessing2BlockMatchWindowSSDInvalidUseRefI) {
10066 const std::string text = R"(
10067 OpCapability Shader
10068 OpCapability TextureBlockMatchQCOM
10069 OpCapability TextureBlockMatch2QCOM
10070 OpExtension "SPV_QCOM_image_processing"
10071 OpExtension "SPV_QCOM_image_processing2"
10072 %1 = OpExtInstImport "GLSL.std.450"
10073 OpMemoryModel Logical GLSL450
10074 OpEntryPoint Fragment %2 "main" %3 %4 %5 %6
10075 OpExecutionMode %2 OriginUpperLeft
10076 OpDecorate %3 Location 0
10077 OpDecorate %4 Location 0
10078 OpDecorate %5 DescriptorSet 0
10079 OpDecorate %5 Binding 4
10080 OpDecorate %6 DescriptorSet 0
10081 OpDecorate %6 Binding 5
10082 OpDecorate %5 BlockMatchTextureQCOM
10083 OpDecorate %5 BlockMatchSamplerQCOM
10084 OpDecorate %6 BlockMatchTextureQCOM
10085 OpDecorate %6 BlockMatchSamplerQCOM
10086 %void = OpTypeVoid
10087 %8 = OpTypeFunction %void
10088 %uint = OpTypeInt 32 0
10089 %v2uint = OpTypeVector %uint 2
10090 %_ptr_Function_v2uint = OpTypePointer Function %v2uint
10091 %float = OpTypeFloat 32
10092 %v4float = OpTypeVector %float 4
10093 %_ptr_Input_v4float = OpTypePointer Input %v4float
10094 %3 = OpVariable %_ptr_Input_v4float Input
10095 %uint_4 = OpConstant %uint 4
10096 %16 = OpConstantComposite %v2uint %uint_4 %uint_4
10097 %_ptr_Output_v4float = OpTypePointer Output %v4float
10098 %4 = OpVariable %_ptr_Output_v4float Output
10099 %18 = OpTypeImage %float 2D 0 0 0 1 Unknown
10100 %_ptr_UniformConstant_18 = OpTypePointer UniformConstant %18
10101 %20 = OpTypeSampledImage %18
10102 %_ptr_UniformConstant_20 = OpTypePointer UniformConstant %20
10103 %5 = OpVariable %_ptr_UniformConstant_20 UniformConstant
10104 %6 = OpVariable %_ptr_UniformConstant_20 UniformConstant
10105 %v2float = OpTypeVector %float 2
10106 %23 = OpTypeImage %float 2D 0 1 0 1 Unknown
10107 %2 = OpFunction %void None %8
10108 %24 = OpLabel
10109 %25 = OpVariable %_ptr_Function_v2uint Function
10110 OpStore %25 %16
10111 %26 = OpLoad %20 %5
10112 %27 = OpLoad %v2uint %25
10113 %28 = OpLoad %20 %6
10114 %29 = OpLoad %v2uint %25
10115 %30 = OpLoad %v2uint %25
10116 %31 = OpImageBlockMatchWindowSSDQCOM %v4float %26 %27 %28 %29 %30
10117 OpStore %4 %31
10118 %32 = OpLoad %20 %6
10119 %33 = OpLoad %v4float %3
10120 %34 = OpVectorShuffle %v2float %33 %33 0 2
10121 %35 = OpImageSampleImplicitLod %v4float %32 %34
10122 OpStore %4 %35
10123 OpReturn
10124 OpFunctionEnd
10125 )";
10126 CompileSuccessfully(text, SPV_ENV_UNIVERSAL_1_4);
10127 EXPECT_EQ(SPV_ERROR_INVALID_DATA,
10128 ValidateInstructions(SPV_ENV_UNIVERSAL_1_4));
10129 EXPECT_THAT(
10130 getDiagnosticString(),
10131 HasSubstr("Illegal use of QCOM image processing decorated texture"));
10132 }
10133
10134 TEST_F(ValidateImage,
10135 QCOMImageProcessing2BlockMatchWindowSSDInvalidUseTargetNI) {
10136 const std::string text = R"(
10137 OpCapability Shader
10138 OpCapability TextureBlockMatchQCOM
10139 OpCapability TextureBlockMatch2QCOM
10140 OpExtension "SPV_QCOM_image_processing"
10141 OpExtension "SPV_QCOM_image_processing2"
10142 %1 = OpExtInstImport "GLSL.std.450"
10143 OpMemoryModel Logical GLSL450
10144 OpEntryPoint Fragment %main "main" %100 %101 %102 %103 %104
10145 OpExecutionMode %main OriginUpperLeft
10146 OpDecorate %100 Location 0
10147 OpDecorate %101 Location 0
10148 OpDecorate %102 DescriptorSet 0
10149 OpDecorate %102 Binding 1
10150 OpDecorate %103 DescriptorSet 0
10151 OpDecorate %103 Binding 3
10152 OpDecorate %104 DescriptorSet 0
10153 OpDecorate %104 Binding 2
10154 OpDecorate %102 BlockMatchTextureQCOM
10155 OpDecorate %103 BlockMatchSamplerQCOM
10156 OpDecorate %104 BlockMatchTextureQCOM
10157 %void = OpTypeVoid
10158 %3 = OpTypeFunction %void
10159 %uint = OpTypeInt 32 0
10160 %v2uint = OpTypeVector %uint 2
10161 %_ptr_Function_v2uint = OpTypePointer Function %v2uint
10162 %float = OpTypeFloat 32
10163 %v4float = OpTypeVector %float 4
10164 %_ptr_Input_v4float = OpTypePointer Input %v4float
10165 %100 = OpVariable %_ptr_Input_v4float Input
10166 %_ptr_Output_v4float = OpTypePointer Output %v4float
10167 %101 = OpVariable %_ptr_Output_v4float Output
10168 %42 = OpTypeImage %float 2D 0 0 0 1 Unknown
10169 %_ptr_UniformConstant_42 = OpTypePointer UniformConstant %42
10170 %102 = OpVariable %_ptr_UniformConstant_42 UniformConstant
10171 %46 = OpTypeSampler
10172 %_ptr_UniformConstant_46 = OpTypePointer UniformConstant %46
10173 %103 = OpVariable %_ptr_UniformConstant_46 UniformConstant
10174 %50 = OpTypeSampledImage %42
10175 %104 = OpVariable %_ptr_UniformConstant_42 UniformConstant
10176 %v2float = OpTypeVector %float 2
10177 %main = OpFunction %void None %3
10178 %5 = OpLabel
10179 %15 = OpVariable %_ptr_Function_v2uint Function
10180 %45 = OpLoad %42 %102
10181 %49 = OpLoad %46 %103
10182 %51 = OpSampledImage %50 %45 %49
10183 %52 = OpLoad %v2uint %15
10184 %54 = OpLoad %42 %104
10185 %55 = OpLoad %46 %103
10186 %56 = OpSampledImage %50 %54 %55
10187 %57 = OpLoad %v2uint %15
10188 %58 = OpLoad %v2uint %15
10189 %59 = OpImageBlockMatchWindowSSDQCOM %v4float %51 %52 %56 %57 %58
10190 OpStore %101 %59
10191 %69 = OpLoad %42 %102
10192 %70 = OpLoad %46 %103
10193 %71 = OpSampledImage %50 %69 %70
10194 %73 = OpLoad %v4float %100
10195 %74 = OpVectorShuffle %v2float %73 %73 0 0
10196 %75 = OpImageSampleImplicitLod %v4float %71 %74
10197 OpStore %101 %75
10198 OpReturn
10199 OpFunctionEnd
10200 )";
10201 CompileSuccessfully(text, SPV_ENV_UNIVERSAL_1_4);
10202 EXPECT_EQ(SPV_ERROR_INVALID_DATA,
10203 ValidateInstructions(SPV_ENV_UNIVERSAL_1_4));
10204 EXPECT_THAT(
10205 getDiagnosticString(),
10206 HasSubstr("Illegal use of QCOM image processing decorated texture"));
10207 }
10208
10209 TEST_F(ValidateImage, QCOMImageProcessing2BlockMatchWindowSSDInvalidUseRefNI) {
10210 const std::string text = R"(
10211 OpCapability Shader
10212 OpCapability TextureBlockMatchQCOM
10213 OpCapability TextureBlockMatch2QCOM
10214 OpExtension "SPV_QCOM_image_processing"
10215 OpExtension "SPV_QCOM_image_processing2"
10216 %1 = OpExtInstImport "GLSL.std.450"
10217 OpMemoryModel Logical GLSL450
10218 OpEntryPoint Fragment %main "main" %100 %101 %102 %103 %104
10219 OpExecutionMode %main OriginUpperLeft
10220 OpDecorate %100 Location 0
10221 OpDecorate %101 Location 0
10222 OpDecorate %102 DescriptorSet 0
10223 OpDecorate %102 Binding 1
10224 OpDecorate %103 DescriptorSet 0
10225 OpDecorate %103 Binding 3
10226 OpDecorate %104 DescriptorSet 0
10227 OpDecorate %104 Binding 2
10228 OpDecorate %102 BlockMatchTextureQCOM
10229 OpDecorate %103 BlockMatchSamplerQCOM
10230 OpDecorate %104 BlockMatchTextureQCOM
10231 %void = OpTypeVoid
10232 %3 = OpTypeFunction %void
10233 %uint = OpTypeInt 32 0
10234 %v2uint = OpTypeVector %uint 2
10235 %_ptr_Function_v2uint = OpTypePointer Function %v2uint
10236 %float = OpTypeFloat 32
10237 %v4float = OpTypeVector %float 4
10238 %_ptr_Input_v4float = OpTypePointer Input %v4float
10239 %100 = OpVariable %_ptr_Input_v4float Input
10240 %_ptr_Output_v4float = OpTypePointer Output %v4float
10241 %101 = OpVariable %_ptr_Output_v4float Output
10242 %42 = OpTypeImage %float 2D 0 0 0 1 Unknown
10243 %_ptr_UniformConstant_42 = OpTypePointer UniformConstant %42
10244 %102 = OpVariable %_ptr_UniformConstant_42 UniformConstant
10245 %46 = OpTypeSampler
10246 %_ptr_UniformConstant_46 = OpTypePointer UniformConstant %46
10247 %103 = OpVariable %_ptr_UniformConstant_46 UniformConstant
10248 %50 = OpTypeSampledImage %42
10249 %104 = OpVariable %_ptr_UniformConstant_42 UniformConstant
10250 %v2float = OpTypeVector %float 2
10251 %main = OpFunction %void None %3
10252 %5 = OpLabel
10253 %15 = OpVariable %_ptr_Function_v2uint Function
10254 %45 = OpLoad %42 %102
10255 %49 = OpLoad %46 %103
10256 %51 = OpSampledImage %50 %45 %49
10257 %52 = OpLoad %v2uint %15
10258 %54 = OpLoad %42 %104
10259 %55 = OpLoad %46 %103
10260 %56 = OpSampledImage %50 %54 %55
10261 %57 = OpLoad %v2uint %15
10262 %58 = OpLoad %v2uint %15
10263 %59 = OpImageBlockMatchWindowSSDQCOM %v4float %51 %52 %56 %57 %58
10264 OpStore %101 %59
10265 %69 = OpLoad %42 %104
10266 %70 = OpLoad %46 %103
10267 %71 = OpSampledImage %50 %69 %70
10268 %73 = OpLoad %v4float %100
10269 %74 = OpVectorShuffle %v2float %73 %73 0 0
10270 %75 = OpImageSampleImplicitLod %v4float %71 %74
10271 OpStore %101 %75
10272 OpReturn
10273 OpFunctionEnd
10274 )";
10275 CompileSuccessfully(text, SPV_ENV_UNIVERSAL_1_4);
10276 EXPECT_EQ(SPV_ERROR_INVALID_DATA,
10277 ValidateInstructions(SPV_ENV_UNIVERSAL_1_4));
10278 EXPECT_THAT(
10279 getDiagnosticString(),
10280 HasSubstr("Illegal use of QCOM image processing decorated texture"));
10281 }
10282
10283 TEST_F(ValidateImage,
10284 QCOMImageProcessing2BlockMatchGatherSADInvalidUseTargetI) {
10285 const std::string text = R"(
10286 OpCapability Shader
10287 OpCapability TextureBlockMatchQCOM
10288 OpCapability TextureBlockMatch2QCOM
10289 OpExtension "SPV_QCOM_image_processing"
10290 OpExtension "SPV_QCOM_image_processing2"
10291 %1 = OpExtInstImport "GLSL.std.450"
10292 OpMemoryModel Logical GLSL450
10293 OpEntryPoint Fragment %2 "main" %3 %4 %5 %6
10294 OpExecutionMode %2 OriginUpperLeft
10295 OpDecorate %3 Location 0
10296 OpDecorate %4 Location 0
10297 OpDecorate %5 DescriptorSet 0
10298 OpDecorate %5 Binding 4
10299 OpDecorate %6 DescriptorSet 0
10300 OpDecorate %6 Binding 5
10301 OpDecorate %5 BlockMatchTextureQCOM
10302 OpDecorate %6 BlockMatchTextureQCOM
10303 %void = OpTypeVoid
10304 %8 = OpTypeFunction %void
10305 %uint = OpTypeInt 32 0
10306 %v2uint = OpTypeVector %uint 2
10307 %_ptr_Function_v2uint = OpTypePointer Function %v2uint
10308 %float = OpTypeFloat 32
10309 %v4float = OpTypeVector %float 4
10310 %_ptr_Input_v4float = OpTypePointer Input %v4float
10311 %3 = OpVariable %_ptr_Input_v4float Input
10312 %uint_4 = OpConstant %uint 4
10313 %16 = OpConstantComposite %v2uint %uint_4 %uint_4
10314 %_ptr_Output_v4float = OpTypePointer Output %v4float
10315 %4 = OpVariable %_ptr_Output_v4float Output
10316 %18 = OpTypeImage %float 2D 0 0 0 1 Unknown
10317 %_ptr_UniformConstant_18 = OpTypePointer UniformConstant %18
10318 %20 = OpTypeSampledImage %18
10319 %_ptr_UniformConstant_20 = OpTypePointer UniformConstant %20
10320 %5 = OpVariable %_ptr_UniformConstant_20 UniformConstant
10321 %6 = OpVariable %_ptr_UniformConstant_20 UniformConstant
10322 %v2float = OpTypeVector %float 2
10323 %23 = OpTypeImage %float 2D 0 1 0 1 Unknown
10324 %2 = OpFunction %void None %8
10325 %24 = OpLabel
10326 %25 = OpVariable %_ptr_Function_v2uint Function
10327 OpStore %25 %16
10328 %26 = OpLoad %20 %5
10329 %27 = OpLoad %v2uint %25
10330 %28 = OpLoad %20 %6
10331 %29 = OpLoad %v2uint %25
10332 %30 = OpLoad %v2uint %25
10333 %31 = OpImageBlockMatchGatherSADQCOM %v4float %26 %27 %28 %29 %30
10334 OpStore %4 %31
10335 %32 = OpLoad %20 %5
10336 %33 = OpLoad %v4float %3
10337 %34 = OpVectorShuffle %v2float %33 %33 0 2
10338 %35 = OpImageSampleImplicitLod %v4float %32 %34
10339 OpStore %4 %35
10340 OpReturn
10341 OpFunctionEnd
10342 )";
10343 CompileSuccessfully(text, SPV_ENV_UNIVERSAL_1_4);
10344 EXPECT_EQ(SPV_ERROR_INVALID_DATA,
10345 ValidateInstructions(SPV_ENV_UNIVERSAL_1_4));
10346 EXPECT_THAT(
10347 getDiagnosticString(),
10348 HasSubstr("Illegal use of QCOM image processing decorated texture"));
10349 }
10350
10351 TEST_F(ValidateImage, QCOMImageProcessing2BlockMatchGatherSADInvalidUseRefI) {
10352 const std::string text = R"(
10353 OpCapability Shader
10354 OpCapability TextureBlockMatchQCOM
10355 OpCapability TextureBlockMatch2QCOM
10356 OpExtension "SPV_QCOM_image_processing"
10357 OpExtension "SPV_QCOM_image_processing2"
10358 %1 = OpExtInstImport "GLSL.std.450"
10359 OpMemoryModel Logical GLSL450
10360 OpEntryPoint Fragment %2 "main" %3 %4 %5 %6
10361 OpExecutionMode %2 OriginUpperLeft
10362 OpDecorate %3 Location 0
10363 OpDecorate %4 Location 0
10364 OpDecorate %5 DescriptorSet 0
10365 OpDecorate %5 Binding 4
10366 OpDecorate %6 DescriptorSet 0
10367 OpDecorate %6 Binding 5
10368 OpDecorate %5 BlockMatchTextureQCOM
10369 OpDecorate %6 BlockMatchTextureQCOM
10370 %void = OpTypeVoid
10371 %8 = OpTypeFunction %void
10372 %uint = OpTypeInt 32 0
10373 %v2uint = OpTypeVector %uint 2
10374 %_ptr_Function_v2uint = OpTypePointer Function %v2uint
10375 %float = OpTypeFloat 32
10376 %v4float = OpTypeVector %float 4
10377 %_ptr_Input_v4float = OpTypePointer Input %v4float
10378 %3 = OpVariable %_ptr_Input_v4float Input
10379 %uint_4 = OpConstant %uint 4
10380 %16 = OpConstantComposite %v2uint %uint_4 %uint_4
10381 %_ptr_Output_v4float = OpTypePointer Output %v4float
10382 %4 = OpVariable %_ptr_Output_v4float Output
10383 %18 = OpTypeImage %float 2D 0 0 0 1 Unknown
10384 %_ptr_UniformConstant_18 = OpTypePointer UniformConstant %18
10385 %20 = OpTypeSampledImage %18
10386 %_ptr_UniformConstant_20 = OpTypePointer UniformConstant %20
10387 %5 = OpVariable %_ptr_UniformConstant_20 UniformConstant
10388 %6 = OpVariable %_ptr_UniformConstant_20 UniformConstant
10389 %v2float = OpTypeVector %float 2
10390 %23 = OpTypeImage %float 2D 0 1 0 1 Unknown
10391 %2 = OpFunction %void None %8
10392 %24 = OpLabel
10393 %25 = OpVariable %_ptr_Function_v2uint Function
10394 OpStore %25 %16
10395 %26 = OpLoad %20 %5
10396 %27 = OpLoad %v2uint %25
10397 %28 = OpLoad %20 %6
10398 %29 = OpLoad %v2uint %25
10399 %30 = OpLoad %v2uint %25
10400 %31 = OpImageBlockMatchGatherSADQCOM %v4float %26 %27 %28 %29 %30
10401 OpStore %4 %31
10402 %32 = OpLoad %20 %6
10403 %33 = OpLoad %v4float %3
10404 %34 = OpVectorShuffle %v2float %33 %33 0 2
10405 %35 = OpImageSampleImplicitLod %v4float %32 %34
10406 OpStore %4 %35
10407 OpReturn
10408 OpFunctionEnd
10409 )";
10410 CompileSuccessfully(text, SPV_ENV_UNIVERSAL_1_4);
10411 EXPECT_EQ(SPV_ERROR_INVALID_DATA,
10412 ValidateInstructions(SPV_ENV_UNIVERSAL_1_4));
10413 EXPECT_THAT(
10414 getDiagnosticString(),
10415 HasSubstr("Illegal use of QCOM image processing decorated texture"));
10416 }
10417
10418 TEST_F(ValidateImage,
10419 QCOMImageProcessing2BlockMatchGatherSADInvalidUseTargetNI) {
10420 const std::string text = R"(
10421 OpCapability Shader
10422 OpCapability TextureBlockMatchQCOM
10423 OpCapability TextureBlockMatch2QCOM
10424 OpExtension "SPV_QCOM_image_processing"
10425 OpExtension "SPV_QCOM_image_processing2"
10426 %1 = OpExtInstImport "GLSL.std.450"
10427 OpMemoryModel Logical GLSL450
10428 OpEntryPoint Fragment %main "main" %100 %101 %102 %103 %104
10429 OpExecutionMode %main OriginUpperLeft
10430 OpDecorate %100 Location 0
10431 OpDecorate %101 Location 0
10432 OpDecorate %102 DescriptorSet 0
10433 OpDecorate %102 Binding 1
10434 OpDecorate %103 DescriptorSet 0
10435 OpDecorate %103 Binding 3
10436 OpDecorate %104 DescriptorSet 0
10437 OpDecorate %104 Binding 2
10438 OpDecorate %102 BlockMatchTextureQCOM
10439 OpDecorate %104 BlockMatchTextureQCOM
10440 %void = OpTypeVoid
10441 %3 = OpTypeFunction %void
10442 %uint = OpTypeInt 32 0
10443 %v2uint = OpTypeVector %uint 2
10444 %_ptr_Function_v2uint = OpTypePointer Function %v2uint
10445 %float = OpTypeFloat 32
10446 %v4float = OpTypeVector %float 4
10447 %_ptr_Input_v4float = OpTypePointer Input %v4float
10448 %100 = OpVariable %_ptr_Input_v4float Input
10449 %_ptr_Output_v4float = OpTypePointer Output %v4float
10450 %101 = OpVariable %_ptr_Output_v4float Output
10451 %42 = OpTypeImage %float 2D 0 0 0 1 Unknown
10452 %_ptr_UniformConstant_42 = OpTypePointer UniformConstant %42
10453 %102 = OpVariable %_ptr_UniformConstant_42 UniformConstant
10454 %46 = OpTypeSampler
10455 %_ptr_UniformConstant_46 = OpTypePointer UniformConstant %46
10456 %103 = OpVariable %_ptr_UniformConstant_46 UniformConstant
10457 %50 = OpTypeSampledImage %42
10458 %104 = OpVariable %_ptr_UniformConstant_42 UniformConstant
10459 %v2float = OpTypeVector %float 2
10460 %main = OpFunction %void None %3
10461 %5 = OpLabel
10462 %15 = OpVariable %_ptr_Function_v2uint Function
10463 %45 = OpLoad %42 %102
10464 %49 = OpLoad %46 %103
10465 %51 = OpSampledImage %50 %45 %49
10466 %52 = OpLoad %v2uint %15
10467 %54 = OpLoad %42 %104
10468 %55 = OpLoad %46 %103
10469 %56 = OpSampledImage %50 %54 %55
10470 %57 = OpLoad %v2uint %15
10471 %58 = OpLoad %v2uint %15
10472 %59 = OpImageBlockMatchGatherSADQCOM %v4float %51 %52 %56 %57 %58
10473 OpStore %101 %59
10474 %69 = OpLoad %42 %102
10475 %70 = OpLoad %46 %103
10476 %71 = OpSampledImage %50 %69 %70
10477 %73 = OpLoad %v4float %100
10478 %74 = OpVectorShuffle %v2float %73 %73 0 0
10479 %75 = OpImageSampleImplicitLod %v4float %71 %74
10480 OpStore %101 %75
10481 OpReturn
10482 OpFunctionEnd
10483 )";
10484 CompileSuccessfully(text, SPV_ENV_UNIVERSAL_1_4);
10485 EXPECT_EQ(SPV_ERROR_INVALID_DATA,
10486 ValidateInstructions(SPV_ENV_UNIVERSAL_1_4));
10487 EXPECT_THAT(
10488 getDiagnosticString(),
10489 HasSubstr("Illegal use of QCOM image processing decorated texture"));
10490 }
10491
10492 TEST_F(ValidateImage, QCOMImageProcessing2BlockMatchGatherSADInvalidUseRefNI) {
10493 const std::string text = R"(
10494 OpCapability Shader
10495 OpCapability TextureBlockMatchQCOM
10496 OpCapability TextureBlockMatch2QCOM
10497 OpExtension "SPV_QCOM_image_processing"
10498 OpExtension "SPV_QCOM_image_processing2"
10499 %1 = OpExtInstImport "GLSL.std.450"
10500 OpMemoryModel Logical GLSL450
10501 OpEntryPoint Fragment %main "main" %100 %101 %102 %103 %104
10502 OpExecutionMode %main OriginUpperLeft
10503 OpDecorate %100 Location 0
10504 OpDecorate %101 Location 0
10505 OpDecorate %102 DescriptorSet 0
10506 OpDecorate %102 Binding 1
10507 OpDecorate %103 DescriptorSet 0
10508 OpDecorate %103 Binding 3
10509 OpDecorate %104 DescriptorSet 0
10510 OpDecorate %104 Binding 2
10511 OpDecorate %102 BlockMatchTextureQCOM
10512 OpDecorate %104 BlockMatchTextureQCOM
10513 %void = OpTypeVoid
10514 %3 = OpTypeFunction %void
10515 %uint = OpTypeInt 32 0
10516 %v2uint = OpTypeVector %uint 2
10517 %_ptr_Function_v2uint = OpTypePointer Function %v2uint
10518 %float = OpTypeFloat 32
10519 %v4float = OpTypeVector %float 4
10520 %_ptr_Input_v4float = OpTypePointer Input %v4float
10521 %100 = OpVariable %_ptr_Input_v4float Input
10522 %_ptr_Output_v4float = OpTypePointer Output %v4float
10523 %101 = OpVariable %_ptr_Output_v4float Output
10524 %42 = OpTypeImage %float 2D 0 0 0 1 Unknown
10525 %_ptr_UniformConstant_42 = OpTypePointer UniformConstant %42
10526 %102 = OpVariable %_ptr_UniformConstant_42 UniformConstant
10527 %46 = OpTypeSampler
10528 %_ptr_UniformConstant_46 = OpTypePointer UniformConstant %46
10529 %103 = OpVariable %_ptr_UniformConstant_46 UniformConstant
10530 %50 = OpTypeSampledImage %42
10531 %104 = OpVariable %_ptr_UniformConstant_42 UniformConstant
10532 %v2float = OpTypeVector %float 2
10533 %main = OpFunction %void None %3
10534 %5 = OpLabel
10535 %15 = OpVariable %_ptr_Function_v2uint Function
10536 %45 = OpLoad %42 %102
10537 %49 = OpLoad %46 %103
10538 %51 = OpSampledImage %50 %45 %49
10539 %52 = OpLoad %v2uint %15
10540 %54 = OpLoad %42 %104
10541 %55 = OpLoad %46 %103
10542 %56 = OpSampledImage %50 %54 %55
10543 %57 = OpLoad %v2uint %15
10544 %58 = OpLoad %v2uint %15
10545 %59 = OpImageBlockMatchGatherSADQCOM %v4float %51 %52 %56 %57 %58
10546 OpStore %101 %59
10547 %69 = OpLoad %42 %104
10548 %70 = OpLoad %46 %103
10549 %71 = OpSampledImage %50 %69 %70
10550 %73 = OpLoad %v4float %100
10551 %74 = OpVectorShuffle %v2float %73 %73 0 0
10552 %75 = OpImageSampleImplicitLod %v4float %71 %74
10553 OpStore %101 %75
10554 OpReturn
10555 OpFunctionEnd
10556 )";
10557 CompileSuccessfully(text, SPV_ENV_UNIVERSAL_1_4);
10558 EXPECT_EQ(SPV_ERROR_INVALID_DATA,
10559 ValidateInstructions(SPV_ENV_UNIVERSAL_1_4));
10560 EXPECT_THAT(
10561 getDiagnosticString(),
10562 HasSubstr("Illegal use of QCOM image processing decorated texture"));
10563 }
10564
10565 TEST_F(ValidateImage,
10566 QCOMImageProcessing2BlockMatchGatherSSDInvalidUseTargetI) {
10567 const std::string text = R"(
10568 OpCapability Shader
10569 OpCapability TextureBlockMatchQCOM
10570 OpCapability TextureBlockMatch2QCOM
10571 OpExtension "SPV_QCOM_image_processing"
10572 OpExtension "SPV_QCOM_image_processing2"
10573 %1 = OpExtInstImport "GLSL.std.450"
10574 OpMemoryModel Logical GLSL450
10575 OpEntryPoint Fragment %2 "main" %3 %4 %5 %6
10576 OpExecutionMode %2 OriginUpperLeft
10577 OpDecorate %3 Location 0
10578 OpDecorate %4 Location 0
10579 OpDecorate %5 DescriptorSet 0
10580 OpDecorate %5 Binding 4
10581 OpDecorate %6 DescriptorSet 0
10582 OpDecorate %6 Binding 5
10583 OpDecorate %5 BlockMatchTextureQCOM
10584 OpDecorate %6 BlockMatchTextureQCOM
10585 %void = OpTypeVoid
10586 %8 = OpTypeFunction %void
10587 %uint = OpTypeInt 32 0
10588 %v2uint = OpTypeVector %uint 2
10589 %_ptr_Function_v2uint = OpTypePointer Function %v2uint
10590 %float = OpTypeFloat 32
10591 %v4float = OpTypeVector %float 4
10592 %_ptr_Input_v4float = OpTypePointer Input %v4float
10593 %3 = OpVariable %_ptr_Input_v4float Input
10594 %uint_4 = OpConstant %uint 4
10595 %16 = OpConstantComposite %v2uint %uint_4 %uint_4
10596 %_ptr_Output_v4float = OpTypePointer Output %v4float
10597 %4 = OpVariable %_ptr_Output_v4float Output
10598 %18 = OpTypeImage %float 2D 0 0 0 1 Unknown
10599 %_ptr_UniformConstant_18 = OpTypePointer UniformConstant %18
10600 %20 = OpTypeSampledImage %18
10601 %_ptr_UniformConstant_20 = OpTypePointer UniformConstant %20
10602 %5 = OpVariable %_ptr_UniformConstant_20 UniformConstant
10603 %6 = OpVariable %_ptr_UniformConstant_20 UniformConstant
10604 %v2float = OpTypeVector %float 2
10605 %23 = OpTypeImage %float 2D 0 1 0 1 Unknown
10606 %2 = OpFunction %void None %8
10607 %24 = OpLabel
10608 %25 = OpVariable %_ptr_Function_v2uint Function
10609 OpStore %25 %16
10610 %26 = OpLoad %20 %5
10611 %27 = OpLoad %v2uint %25
10612 %28 = OpLoad %20 %6
10613 %29 = OpLoad %v2uint %25
10614 %30 = OpLoad %v2uint %25
10615 %31 = OpImageBlockMatchGatherSSDQCOM %v4float %26 %27 %28 %29 %30
10616 OpStore %4 %31
10617 %32 = OpLoad %20 %5
10618 %33 = OpLoad %v4float %3
10619 %34 = OpVectorShuffle %v2float %33 %33 0 2
10620 %35 = OpImageSampleImplicitLod %v4float %32 %34
10621 OpStore %4 %35
10622 OpReturn
10623 OpFunctionEnd
10624 )";
10625 CompileSuccessfully(text, SPV_ENV_UNIVERSAL_1_4);
10626 EXPECT_EQ(SPV_ERROR_INVALID_DATA,
10627 ValidateInstructions(SPV_ENV_UNIVERSAL_1_4));
10628 EXPECT_THAT(
10629 getDiagnosticString(),
10630 HasSubstr("Illegal use of QCOM image processing decorated texture"));
10631 }
10632
10633 TEST_F(ValidateImage, QCOMImageProcessing2BlockMatchGatherSSDInvalidUseRefI) {
10634 const std::string text = R"(
10635 OpCapability Shader
10636 OpCapability TextureBlockMatchQCOM
10637 OpCapability TextureBlockMatch2QCOM
10638 OpExtension "SPV_QCOM_image_processing"
10639 OpExtension "SPV_QCOM_image_processing2"
10640 %1 = OpExtInstImport "GLSL.std.450"
10641 OpMemoryModel Logical GLSL450
10642 OpEntryPoint Fragment %2 "main" %3 %4 %5 %6
10643 OpExecutionMode %2 OriginUpperLeft
10644 OpDecorate %3 Location 0
10645 OpDecorate %4 Location 0
10646 OpDecorate %5 DescriptorSet 0
10647 OpDecorate %5 Binding 4
10648 OpDecorate %6 DescriptorSet 0
10649 OpDecorate %6 Binding 5
10650 OpDecorate %5 BlockMatchTextureQCOM
10651 OpDecorate %6 BlockMatchTextureQCOM
10652 %void = OpTypeVoid
10653 %8 = OpTypeFunction %void
10654 %uint = OpTypeInt 32 0
10655 %v2uint = OpTypeVector %uint 2
10656 %_ptr_Function_v2uint = OpTypePointer Function %v2uint
10657 %float = OpTypeFloat 32
10658 %v4float = OpTypeVector %float 4
10659 %_ptr_Input_v4float = OpTypePointer Input %v4float
10660 %3 = OpVariable %_ptr_Input_v4float Input
10661 %uint_4 = OpConstant %uint 4
10662 %16 = OpConstantComposite %v2uint %uint_4 %uint_4
10663 %_ptr_Output_v4float = OpTypePointer Output %v4float
10664 %4 = OpVariable %_ptr_Output_v4float Output
10665 %18 = OpTypeImage %float 2D 0 0 0 1 Unknown
10666 %_ptr_UniformConstant_18 = OpTypePointer UniformConstant %18
10667 %20 = OpTypeSampledImage %18
10668 %_ptr_UniformConstant_20 = OpTypePointer UniformConstant %20
10669 %5 = OpVariable %_ptr_UniformConstant_20 UniformConstant
10670 %6 = OpVariable %_ptr_UniformConstant_20 UniformConstant
10671 %v2float = OpTypeVector %float 2
10672 %23 = OpTypeImage %float 2D 0 1 0 1 Unknown
10673 %2 = OpFunction %void None %8
10674 %24 = OpLabel
10675 %25 = OpVariable %_ptr_Function_v2uint Function
10676 OpStore %25 %16
10677 %26 = OpLoad %20 %5
10678 %27 = OpLoad %v2uint %25
10679 %28 = OpLoad %20 %6
10680 %29 = OpLoad %v2uint %25
10681 %30 = OpLoad %v2uint %25
10682 %31 = OpImageBlockMatchGatherSSDQCOM %v4float %26 %27 %28 %29 %30
10683 OpStore %4 %31
10684 %32 = OpLoad %20 %6
10685 %33 = OpLoad %v4float %3
10686 %34 = OpVectorShuffle %v2float %33 %33 0 2
10687 %35 = OpImageSampleImplicitLod %v4float %32 %34
10688 OpStore %4 %35
10689 OpReturn
10690 OpFunctionEnd
10691 )";
10692 CompileSuccessfully(text, SPV_ENV_UNIVERSAL_1_4);
10693 EXPECT_EQ(SPV_ERROR_INVALID_DATA,
10694 ValidateInstructions(SPV_ENV_UNIVERSAL_1_4));
10695 EXPECT_THAT(
10696 getDiagnosticString(),
10697 HasSubstr("Illegal use of QCOM image processing decorated texture"));
10698 }
10699
10700 TEST_F(ValidateImage,
10701 QCOMImageProcessing2BlockMatchGatherSSDInvalidUseTargetNI) {
10702 const std::string text = R"(
10703 OpCapability Shader
10704 OpCapability TextureBlockMatchQCOM
10705 OpCapability TextureBlockMatch2QCOM
10706 OpExtension "SPV_QCOM_image_processing"
10707 OpExtension "SPV_QCOM_image_processing2"
10708 %1 = OpExtInstImport "GLSL.std.450"
10709 OpMemoryModel Logical GLSL450
10710 OpEntryPoint Fragment %main "main" %100 %101 %102 %103 %104
10711 OpExecutionMode %main OriginUpperLeft
10712 OpDecorate %100 Location 0
10713 OpDecorate %101 Location 0
10714 OpDecorate %102 DescriptorSet 0
10715 OpDecorate %102 Binding 1
10716 OpDecorate %103 DescriptorSet 0
10717 OpDecorate %103 Binding 3
10718 OpDecorate %104 DescriptorSet 0
10719 OpDecorate %104 Binding 2
10720 OpDecorate %102 BlockMatchTextureQCOM
10721 OpDecorate %104 BlockMatchTextureQCOM
10722 %void = OpTypeVoid
10723 %3 = OpTypeFunction %void
10724 %uint = OpTypeInt 32 0
10725 %v2uint = OpTypeVector %uint 2
10726 %_ptr_Function_v2uint = OpTypePointer Function %v2uint
10727 %float = OpTypeFloat 32
10728 %v4float = OpTypeVector %float 4
10729 %_ptr_Input_v4float = OpTypePointer Input %v4float
10730 %100 = OpVariable %_ptr_Input_v4float Input
10731 %_ptr_Output_v4float = OpTypePointer Output %v4float
10732 %101 = OpVariable %_ptr_Output_v4float Output
10733 %42 = OpTypeImage %float 2D 0 0 0 1 Unknown
10734 %_ptr_UniformConstant_42 = OpTypePointer UniformConstant %42
10735 %102 = OpVariable %_ptr_UniformConstant_42 UniformConstant
10736 %46 = OpTypeSampler
10737 %_ptr_UniformConstant_46 = OpTypePointer UniformConstant %46
10738 %103 = OpVariable %_ptr_UniformConstant_46 UniformConstant
10739 %50 = OpTypeSampledImage %42
10740 %104 = OpVariable %_ptr_UniformConstant_42 UniformConstant
10741 %v2float = OpTypeVector %float 2
10742 %main = OpFunction %void None %3
10743 %5 = OpLabel
10744 %15 = OpVariable %_ptr_Function_v2uint Function
10745 %45 = OpLoad %42 %102
10746 %49 = OpLoad %46 %103
10747 %51 = OpSampledImage %50 %45 %49
10748 %52 = OpLoad %v2uint %15
10749 %54 = OpLoad %42 %104
10750 %55 = OpLoad %46 %103
10751 %56 = OpSampledImage %50 %54 %55
10752 %57 = OpLoad %v2uint %15
10753 %58 = OpLoad %v2uint %15
10754 %59 = OpImageBlockMatchGatherSSDQCOM %v4float %51 %52 %56 %57 %58
10755 OpStore %101 %59
10756 %69 = OpLoad %42 %102
10757 %70 = OpLoad %46 %103
10758 %71 = OpSampledImage %50 %69 %70
10759 %73 = OpLoad %v4float %100
10760 %74 = OpVectorShuffle %v2float %73 %73 0 0
10761 %75 = OpImageSampleImplicitLod %v4float %71 %74
10762 OpStore %101 %75
10763 OpReturn
10764 OpFunctionEnd
10765 )";
10766 CompileSuccessfully(text, SPV_ENV_UNIVERSAL_1_4);
10767 EXPECT_EQ(SPV_ERROR_INVALID_DATA,
10768 ValidateInstructions(SPV_ENV_UNIVERSAL_1_4));
10769 EXPECT_THAT(
10770 getDiagnosticString(),
10771 HasSubstr("Illegal use of QCOM image processing decorated texture"));
10772 }
10773
10774 TEST_F(ValidateImage, QCOMImageProcessing2BlockMatchGatherSSDInvalidUseRefNI) {
10775 const std::string text = R"(
10776 OpCapability Shader
10777 OpCapability TextureBlockMatchQCOM
10778 OpCapability TextureBlockMatch2QCOM
10779 OpExtension "SPV_QCOM_image_processing"
10780 OpExtension "SPV_QCOM_image_processing2"
10781 %1 = OpExtInstImport "GLSL.std.450"
10782 OpMemoryModel Logical GLSL450
10783 OpEntryPoint Fragment %main "main" %100 %101 %102 %103 %104
10784 OpExecutionMode %main OriginUpperLeft
10785 OpDecorate %100 Location 0
10786 OpDecorate %101 Location 0
10787 OpDecorate %102 DescriptorSet 0
10788 OpDecorate %102 Binding 1
10789 OpDecorate %103 DescriptorSet 0
10790 OpDecorate %103 Binding 3
10791 OpDecorate %104 DescriptorSet 0
10792 OpDecorate %104 Binding 2
10793 OpDecorate %102 BlockMatchTextureQCOM
10794 OpDecorate %104 BlockMatchTextureQCOM
10795 %void = OpTypeVoid
10796 %3 = OpTypeFunction %void
10797 %uint = OpTypeInt 32 0
10798 %v2uint = OpTypeVector %uint 2
10799 %_ptr_Function_v2uint = OpTypePointer Function %v2uint
10800 %float = OpTypeFloat 32
10801 %v4float = OpTypeVector %float 4
10802 %_ptr_Input_v4float = OpTypePointer Input %v4float
10803 %100 = OpVariable %_ptr_Input_v4float Input
10804 %_ptr_Output_v4float = OpTypePointer Output %v4float
10805 %101 = OpVariable %_ptr_Output_v4float Output
10806 %42 = OpTypeImage %float 2D 0 0 0 1 Unknown
10807 %_ptr_UniformConstant_42 = OpTypePointer UniformConstant %42
10808 %102 = OpVariable %_ptr_UniformConstant_42 UniformConstant
10809 %46 = OpTypeSampler
10810 %_ptr_UniformConstant_46 = OpTypePointer UniformConstant %46
10811 %103 = OpVariable %_ptr_UniformConstant_46 UniformConstant
10812 %50 = OpTypeSampledImage %42
10813 %104 = OpVariable %_ptr_UniformConstant_42 UniformConstant
10814 %v2float = OpTypeVector %float 2
10815 %main = OpFunction %void None %3
10816 %5 = OpLabel
10817 %15 = OpVariable %_ptr_Function_v2uint Function
10818 %45 = OpLoad %42 %102
10819 %49 = OpLoad %46 %103
10820 %51 = OpSampledImage %50 %45 %49
10821 %52 = OpLoad %v2uint %15
10822 %54 = OpLoad %42 %104
10823 %55 = OpLoad %46 %103
10824 %56 = OpSampledImage %50 %54 %55
10825 %57 = OpLoad %v2uint %15
10826 %58 = OpLoad %v2uint %15
10827 %59 = OpImageBlockMatchGatherSSDQCOM %v4float %51 %52 %56 %57 %58
10828 OpStore %101 %59
10829 %69 = OpLoad %42 %104
10830 %70 = OpLoad %46 %103
10831 %71 = OpSampledImage %50 %69 %70
10832 %73 = OpLoad %v4float %100
10833 %74 = OpVectorShuffle %v2float %73 %73 0 0
10834 %75 = OpImageSampleImplicitLod %v4float %71 %74
10835 OpStore %101 %75
10836 OpReturn
10837 OpFunctionEnd
10838 )";
10839 CompileSuccessfully(text, SPV_ENV_UNIVERSAL_1_4);
10840 EXPECT_EQ(SPV_ERROR_INVALID_DATA,
10841 ValidateInstructions(SPV_ENV_UNIVERSAL_1_4));
10842 EXPECT_THAT(
10843 getDiagnosticString(),
10844 HasSubstr("Illegal use of QCOM image processing decorated texture"));
10845 }
10846
10847 TEST_F(ValidateImage, ImageMSArray_ArrayedSampledTypeRequiresCapability) {
10848 const std::string code = R"(
10849 OpCapability Shader
10850 OpCapability StorageImageMultisample
10851 OpCapability StorageImageReadWithoutFormat
10852 OpMemoryModel Logical GLSL450
10853 OpEntryPoint Fragment %main "main"
10854 OpExecutionMode %main OriginUpperLeft
10855 OpDecorate %var_image DescriptorSet 0
10856 OpDecorate %var_image Binding 1
10857 %void = OpTypeVoid
10858 %func = OpTypeFunction %void
10859 %f32 = OpTypeFloat 32
10860 %u32 = OpTypeInt 32 0
10861 %uint_2 = OpConstant %u32 2
10862 %uint_1 = OpConstant %u32 1
10863 %v2uint = OpTypeVector %u32 2
10864 %v4float = OpTypeVector %f32 4
10865 %image = OpTypeImage %f32 2D 2 1 1 2 Unknown
10866 %ptr_image = OpTypePointer UniformConstant %image
10867 %10 = OpConstantComposite %v2uint %uint_1 %uint_2
10868 %var_image = OpVariable %ptr_image UniformConstant
10869 %main = OpFunction %void None %func
10870 %main_lab = OpLabel
10871 %18 = OpLoad %image %var_image
10872 %19 = OpImageRead %v4float %18 %10 Sample %uint_2
10873 OpReturn
10874 OpFunctionEnd
10875 )";
10876
10877 const spv_target_env env = SPV_ENV_VULKAN_1_0;
10878 CompileSuccessfully(code, env);
10879 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions(env));
10880 EXPECT_THAT(
10881 getDiagnosticString(),
10882 HasSubstr("Capability ImageMSArray is required to access storage image"));
10883 }
10884
10885 TEST_F(ValidateImage, ImageMSArray_SampledTypeDoesNotRequireCapability) {
10886 const std::string code = R"(
10887 OpCapability Shader
10888 OpCapability StorageImageMultisample
10889 OpCapability StorageImageReadWithoutFormat
10890 OpMemoryModel Logical GLSL450
10891 OpEntryPoint Fragment %main "main"
10892 OpExecutionMode %main OriginUpperLeft
10893 OpDecorate %var_image DescriptorSet 0
10894 OpDecorate %var_image Binding 1
10895 %void = OpTypeVoid
10896 %func = OpTypeFunction %void
10897 %f32 = OpTypeFloat 32
10898 %u32 = OpTypeInt 32 0
10899 %uint_2 = OpConstant %u32 2
10900 %uint_1 = OpConstant %u32 1
10901 %v2uint = OpTypeVector %u32 2
10902 %v4float = OpTypeVector %f32 4
10903 %image = OpTypeImage %f32 2D 2 0 1 2 Unknown
10904 %ptr_image = OpTypePointer UniformConstant %image
10905 %10 = OpConstantComposite %v2uint %uint_1 %uint_2
10906 %var_image = OpVariable %ptr_image UniformConstant
10907 %main = OpFunction %void None %func
10908 %main_lab = OpLabel
10909 %18 = OpLoad %image %var_image
10910 %19 = OpImageRead %v4float %18 %10 Sample %uint_2
10911 OpReturn
10912 OpFunctionEnd
10913 )";
10914
10915 const spv_target_env env = SPV_ENV_VULKAN_1_0;
10916 CompileSuccessfully(code, env);
10917 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions(env));
10918 EXPECT_THAT(getDiagnosticString(), Eq(""));
10919 }
10920
10921 TEST_F(ValidateImage, ImageMSArray_ArrayedTypeDoesNotRequireCapability) {
10922 const std::string code = R"(
10923 OpCapability Shader
10924 OpCapability StorageImageReadWithoutFormat
10925 OpMemoryModel Logical GLSL450
10926 OpEntryPoint Fragment %main "main"
10927 OpExecutionMode %main OriginUpperLeft
10928 OpDecorate %var_image DescriptorSet 0
10929 OpDecorate %var_image Binding 1
10930 %void = OpTypeVoid
10931 %func = OpTypeFunction %void
10932 %f32 = OpTypeFloat 32
10933 %u32 = OpTypeInt 32 0
10934 %uint_3 = OpConstant %u32 3
10935 %uint_2 = OpConstant %u32 2
10936 %uint_1 = OpConstant %u32 1
10937 %v3uint = OpTypeVector %u32 3
10938 %v4float = OpTypeVector %f32 4
10939 %image = OpTypeImage %f32 2D 2 1 0 2 Unknown
10940 %ptr_image = OpTypePointer UniformConstant %image
10941 %10 = OpConstantComposite %v3uint %uint_1 %uint_2 %uint_3
10942 %var_image = OpVariable %ptr_image UniformConstant
10943 %main = OpFunction %void None %func
10944 %main_lab = OpLabel
10945 %18 = OpLoad %image %var_image
10946 %19 = OpImageRead %v4float %18 %10
10947 OpReturn
10948 OpFunctionEnd
10949 )";
10950
10951 const spv_target_env env = SPV_ENV_VULKAN_1_0;
10952 CompileSuccessfully(code, env);
10953 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions(env));
10954 EXPECT_THAT(getDiagnosticString(), Eq(""));
10955 }
10956
10957 TEST_F(ValidateImage, SampledImageTypeDepthMismatch) {
10958 const std::string code = R"(
10959 OpCapability Shader
10960 OpMemoryModel Logical GLSL450
10961 OpEntryPoint GLCompute %main "main"
10962 OpExecutionMode %main LocalSize 1 1 1
10963 OpDecorate %im_var DescriptorSet 0
10964 OpDecorate %im_var Binding 0
10965 OpDecorate %s_var DescriptorSet 1
10966 OpDecorate %s_var Binding 0
10967 %void = OpTypeVoid
10968 %float = OpTypeFloat 32
10969 %im1_ty = OpTypeImage %float 2D 0 0 0 1 Unknown
10970 %im2_ty = OpTypeImage %float 2D 1 0 0 1 Unknown
10971 %s_ty = OpTypeSampler
10972 %s_im_ty = OpTypeSampledImage %im2_ty
10973 %ptr_im = OpTypePointer UniformConstant %im1_ty
10974 %ptr_s = OpTypePointer UniformConstant %s_ty
10975 %im_var = OpVariable %ptr_im UniformConstant
10976 %s_var = OpVariable %ptr_s UniformConstant
10977 %void_fn = OpTypeFunction %void
10978 %main = OpFunction %void None %void_fn
10979 %entry = OpLabel
10980 %im_ld = OpLoad %im1_ty %im_var
10981 %s_ld = OpLoad %s_ty %s_var
10982 %sampled_image = OpSampledImage %s_im_ty %im_ld %s_ld
10983 OpReturn
10984 OpFunctionEnd
10985 )";
10986
10987 const spv_target_env env = SPV_ENV_VULKAN_1_0;
10988 CompileSuccessfully(code, env);
10989 EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(env));
10990 }
10991
10992 TEST_F(ValidateImage, SampledImageTypeArrayedMismatch) {
10993 const std::string code = R"(
10994 OpCapability Shader
10995 OpMemoryModel Logical GLSL450
10996 OpEntryPoint GLCompute %main "main"
10997 OpExecutionMode %main LocalSize 1 1 1
10998 OpDecorate %im_var DescriptorSet 0
10999 OpDecorate %im_var Binding 0
11000 OpDecorate %s_var DescriptorSet 1
11001 OpDecorate %s_var Binding 0
11002 %void = OpTypeVoid
11003 %float = OpTypeFloat 32
11004 %im1_ty = OpTypeImage %float 2D 0 0 0 1 Unknown
11005 %im2_ty = OpTypeImage %float 2D 0 1 0 1 Unknown
11006 %s_ty = OpTypeSampler
11007 %s_im_ty = OpTypeSampledImage %im2_ty
11008 %ptr_im = OpTypePointer UniformConstant %im1_ty
11009 %ptr_s = OpTypePointer UniformConstant %s_ty
11010 %im_var = OpVariable %ptr_im UniformConstant
11011 %s_var = OpVariable %ptr_s UniformConstant
11012 %void_fn = OpTypeFunction %void
11013 %main = OpFunction %void None %void_fn
11014 %entry = OpLabel
11015 %im_ld = OpLoad %im1_ty %im_var
11016 %s_ld = OpLoad %s_ty %s_var
11017 %sampled_image = OpSampledImage %s_im_ty %im_ld %s_ld
11018 OpReturn
11019 OpFunctionEnd
11020 )";
11021
11022 const spv_target_env env = SPV_ENV_VULKAN_1_0;
11023 CompileSuccessfully(code, env);
11024 EXPECT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions(env));
11025 EXPECT_THAT(
11026 getDiagnosticString(),
11027 HasSubstr(
11028 "Image operands must match result image operands except for depth"));
11029 }
11030
11031 TEST_F(ValidateImage, SampledImageTypeMultisampledMismatch) {
11032 const std::string code = R"(
11033 OpCapability Shader
11034 OpMemoryModel Logical GLSL450
11035 OpEntryPoint GLCompute %main "main"
11036 OpExecutionMode %main LocalSize 1 1 1
11037 OpDecorate %im_var DescriptorSet 0
11038 OpDecorate %im_var Binding 0
11039 OpDecorate %s_var DescriptorSet 1
11040 OpDecorate %s_var Binding 0
11041 %void = OpTypeVoid
11042 %float = OpTypeFloat 32
11043 %im1_ty = OpTypeImage %float 2D 0 0 0 1 Unknown
11044 %im2_ty = OpTypeImage %float 2D 0 0 1 1 Unknown
11045 %s_ty = OpTypeSampler
11046 %s_im_ty = OpTypeSampledImage %im2_ty
11047 %ptr_im = OpTypePointer UniformConstant %im1_ty
11048 %ptr_s = OpTypePointer UniformConstant %s_ty
11049 %im_var = OpVariable %ptr_im UniformConstant
11050 %s_var = OpVariable %ptr_s UniformConstant
11051 %void_fn = OpTypeFunction %void
11052 %main = OpFunction %void None %void_fn
11053 %entry = OpLabel
11054 %im_ld = OpLoad %im1_ty %im_var
11055 %s_ld = OpLoad %s_ty %s_var
11056 %sampled_image = OpSampledImage %s_im_ty %im_ld %s_ld
11057 OpReturn
11058 OpFunctionEnd
11059 )";
11060
11061 const spv_target_env env = SPV_ENV_VULKAN_1_0;
11062 CompileSuccessfully(code, env);
11063 EXPECT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions(env));
11064 EXPECT_THAT(
11065 getDiagnosticString(),
11066 HasSubstr(
11067 "Image operands must match result image operands except for depth"));
11068 }
11069
11070 TEST_F(ValidateImage, SampledImageTypeSampledMismatch) {
11071 const std::string code = R"(
11072 OpCapability Shader
11073 OpMemoryModel Logical GLSL450
11074 OpEntryPoint GLCompute %main "main"
11075 OpExecutionMode %main LocalSize 1 1 1
11076 OpDecorate %im_var DescriptorSet 0
11077 OpDecorate %im_var Binding 0
11078 OpDecorate %s_var DescriptorSet 1
11079 OpDecorate %s_var Binding 0
11080 %void = OpTypeVoid
11081 %float = OpTypeFloat 32
11082 %im1_ty = OpTypeImage %float 2D 0 0 0 1 Unknown
11083 %im2_ty = OpTypeImage %float 2D 0 0 0 0 Unknown
11084 %s_ty = OpTypeSampler
11085 %s_im_ty = OpTypeSampledImage %im2_ty
11086 %ptr_im = OpTypePointer UniformConstant %im1_ty
11087 %ptr_s = OpTypePointer UniformConstant %s_ty
11088 %im_var = OpVariable %ptr_im UniformConstant
11089 %s_var = OpVariable %ptr_s UniformConstant
11090 %void_fn = OpTypeFunction %void
11091 %main = OpFunction %void None %void_fn
11092 %entry = OpLabel
11093 %im_ld = OpLoad %im1_ty %im_var
11094 %s_ld = OpLoad %s_ty %s_var
11095 %sampled_image = OpSampledImage %s_im_ty %im_ld %s_ld
11096 OpReturn
11097 OpFunctionEnd
11098 )";
11099
11100 const spv_target_env env = SPV_ENV_UNIVERSAL_1_0;
11101 CompileSuccessfully(code, env);
11102 EXPECT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions(env));
11103 EXPECT_THAT(
11104 getDiagnosticString(),
11105 HasSubstr(
11106 "Image operands must match result image operands except for depth"));
11107 }
11108
11109 TEST_F(ValidateImage, SampledImageTypeFormatMismatch) {
11110 const std::string code = R"(
11111 OpCapability Shader
11112 OpMemoryModel Logical GLSL450
11113 OpEntryPoint GLCompute %main "main"
11114 OpExecutionMode %main LocalSize 1 1 1
11115 OpDecorate %im_var DescriptorSet 0
11116 OpDecorate %im_var Binding 0
11117 OpDecorate %s_var DescriptorSet 1
11118 OpDecorate %s_var Binding 0
11119 %void = OpTypeVoid
11120 %float = OpTypeFloat 32
11121 %im1_ty = OpTypeImage %float 2D 0 0 0 1 Unknown
11122 %im2_ty = OpTypeImage %float 2D 0 0 0 1 R32f
11123 %s_ty = OpTypeSampler
11124 %s_im_ty = OpTypeSampledImage %im2_ty
11125 %ptr_im = OpTypePointer UniformConstant %im1_ty
11126 %ptr_s = OpTypePointer UniformConstant %s_ty
11127 %im_var = OpVariable %ptr_im UniformConstant
11128 %s_var = OpVariable %ptr_s UniformConstant
11129 %void_fn = OpTypeFunction %void
11130 %main = OpFunction %void None %void_fn
11131 %entry = OpLabel
11132 %im_ld = OpLoad %im1_ty %im_var
11133 %s_ld = OpLoad %s_ty %s_var
11134 %sampled_image = OpSampledImage %s_im_ty %im_ld %s_ld
11135 OpReturn
11136 OpFunctionEnd
11137 )";
11138
11139 const spv_target_env env = SPV_ENV_UNIVERSAL_1_0;
11140 CompileSuccessfully(code, env);
11141 EXPECT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions(env));
11142 EXPECT_THAT(
11143 getDiagnosticString(),
11144 HasSubstr(
11145 "Image operands must match result image operands except for depth"));
11146 }
11147
11148 TEST_F(ValidateImage, SampledImageTypeAccessQualifierMismatch) {
11149 const std::string code = R"(
11150 OpCapability Kernel
11151 OpCapability Linkage
11152 OpMemoryModel Logical OpenCL
11153 %void = OpTypeVoid
11154 %float = OpTypeFloat 32
11155 %im1_ty = OpTypeImage %float 2D 0 0 0 0 Unknown ReadWrite
11156 %im2_ty = OpTypeImage %float 2D 0 0 0 0 Unknown ReadOnly
11157 %s_ty = OpTypeSampler
11158 %s_im_ty = OpTypeSampledImage %im2_ty
11159 %ptr_im = OpTypePointer UniformConstant %im1_ty
11160 %ptr_s = OpTypePointer UniformConstant %s_ty
11161 %im_var = OpVariable %ptr_im UniformConstant
11162 %s_var = OpVariable %ptr_s UniformConstant
11163 %void_fn = OpTypeFunction %void
11164 %main = OpFunction %void None %void_fn
11165 %entry = OpLabel
11166 %im_ld = OpLoad %im1_ty %im_var
11167 %s_ld = OpLoad %s_ty %s_var
11168 %sampled_image = OpSampledImage %s_im_ty %im_ld %s_ld
11169 OpReturn
11170 OpFunctionEnd
11171 )";
11172
11173 const spv_target_env env = SPV_ENV_UNIVERSAL_1_0;
11174 CompileSuccessfully(code, env);
11175 EXPECT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions(env));
11176 EXPECT_THAT(
11177 getDiagnosticString(),
11178 HasSubstr(
11179 "Image operands must match result image operands except for depth"));
11180 }
11181
11182 TEST_F(ValidateImage, ImageTexelPointerNotAPointer) {
11183 const std::string code = R"(
11184 OpCapability ClipDistance
11185 OpMemoryModel Logical Simple
11186 %void = OpTypeVoid
11187 %57 = OpTypeFunction %void
11188 %int = OpTypeInt 32 1
11189 %int_538976288 = OpConstant %int 538976288
11190 %int_538976288_0 = OpConstant %int 538976288
11191 %8224 = OpFunction %void None %57
11192 %65312 = OpLabel
11193 %2097184 = OpImageTexelPointer %void %int_538976288 %int_538976288 %int_538976288_0
11194 OpUnreachable
11195 OpFunctionEnd
11196 )";
11197
11198 CompileSuccessfully(code);
11199 EXPECT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
11200 EXPECT_THAT(getDiagnosticString(),
11201 HasSubstr("Expected Result Type to be a pointer"));
11202 }
11203
11204 } // namespace
11205 } // namespace val
11206 } // namespace spvtools