Debian Codegraph @

test/val/val_composites_test.cpp

raw
1 // Copyright (c) 2017 Google Inc.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 #include <sstream>
16 #include <string>
17
18 #include "gmock/gmock.h"
19 #include "test/unit_spirv.h"
20 #include "test/val/val_code_generator.h"
21 #include "test/val/val_fixtures.h"
22
23 namespace spvtools {
24 namespace val {
25 namespace {
26
27 using ::testing::HasSubstr;
28 using ::testing::Not;
29 using ::testing::Values;
30
31 using ValidateComposites = spvtest::ValidateBase<bool>;
32
33 std::string GenerateShaderCode(
34 const std::string& body,
35 const std::string& capabilities_and_extensions = "",
36 const std::string& execution_model = "Fragment") {
37 std::ostringstream ss;
38 ss << R"(
39 OpCapability Shader
40 OpCapability Float64
41 )";
42
43 ss << capabilities_and_extensions;
44 ss << "OpMemoryModel Logical GLSL450\n";
45 ss << "OpEntryPoint " << execution_model << " %main \"main\"\n";
46 if (execution_model == "Fragment") {
47 ss << "OpExecutionMode %main OriginUpperLeft\n";
48 }
49
50 ss << R"(
51 %void = OpTypeVoid
52 %func = OpTypeFunction %void
53 %bool = OpTypeBool
54 %f32 = OpTypeFloat 32
55 %f64 = OpTypeFloat 64
56 %u32 = OpTypeInt 32 0
57 %s32 = OpTypeInt 32 1
58 %f32vec2 = OpTypeVector %f32 2
59 %f32vec3 = OpTypeVector %f32 3
60 %f32vec4 = OpTypeVector %f32 4
61 %f64vec2 = OpTypeVector %f64 2
62 %u32vec2 = OpTypeVector %u32 2
63 %u32vec4 = OpTypeVector %u32 4
64 %f64mat22 = OpTypeMatrix %f64vec2 2
65 %f32mat22 = OpTypeMatrix %f32vec2 2
66 %f32mat23 = OpTypeMatrix %f32vec2 3
67 %f32mat32 = OpTypeMatrix %f32vec3 2
68
69 %f32_0 = OpConstant %f32 0
70 %f32_1 = OpConstant %f32 1
71 %f32_2 = OpConstant %f32 2
72 %f32_3 = OpConstant %f32 3
73 %f32vec2_01 = OpConstantComposite %f32vec2 %f32_0 %f32_1
74 %f32vec2_12 = OpConstantComposite %f32vec2 %f32_1 %f32_2
75 %f32vec4_0123 = OpConstantComposite %f32vec4 %f32_0 %f32_1 %f32_2 %f32_3
76
77 %u32_0 = OpConstant %u32 0
78 %u32_1 = OpConstant %u32 1
79 %u32_2 = OpConstant %u32 2
80 %u32_3 = OpConstant %u32 3
81
82 %u32vec2_01 = OpConstantComposite %u32vec2 %u32_0 %u32_1
83 %u32vec4_0123 = OpConstantComposite %u32vec4 %u32_0 %u32_1 %u32_2 %u32_3
84
85 %f32mat22_1212 = OpConstantComposite %f32mat22 %f32vec2_12 %f32vec2_12
86 %f32mat23_121212 = OpConstantComposite %f32mat23 %f32vec2_12 %f32vec2_12 %f32vec2_12
87
88 %f32vec2arr3 = OpTypeArray %f32vec2 %u32_3
89 %f32vec2arr2 = OpTypeArray %f32vec2 %u32_2
90
91 %f32u32struct = OpTypeStruct %f32 %u32
92 %big_struct = OpTypeStruct %f32 %f32vec4 %f32mat23 %f32vec2arr3 %f32vec2arr2 %f32u32struct
93
94 %ptr_big_struct = OpTypePointer Uniform %big_struct
95 %var_big_struct = OpVariable %ptr_big_struct Uniform
96
97 %main = OpFunction %void None %func
98 %main_entry = OpLabel
99 )";
100
101 ss << body;
102
103 ss << R"(
104 OpReturn
105 OpFunctionEnd)";
106
107 return ss.str();
108 }
109
110 // Returns header for legacy tests taken from val_id_test.cpp.
111 std::string GetHeaderForTestsFromValId() {
112 return R"(
113 OpCapability Shader
114 OpCapability Linkage
115 OpCapability Addresses
116 OpCapability Pipes
117 OpCapability LiteralSampler
118 OpCapability DeviceEnqueue
119 OpCapability Vector16
120 OpCapability Int8
121 OpCapability Int16
122 OpCapability Int64
123 OpCapability Float64
124 OpMemoryModel Logical GLSL450
125 %void = OpTypeVoid
126 %void_f = OpTypeFunction %void
127 %int = OpTypeInt 32 0
128 %float = OpTypeFloat 32
129 %v3float = OpTypeVector %float 3
130 %mat4x3 = OpTypeMatrix %v3float 4
131 %_ptr_Private_mat4x3 = OpTypePointer Private %mat4x3
132 %_ptr_Private_float = OpTypePointer Private %float
133 %my_matrix = OpVariable %_ptr_Private_mat4x3 Private
134 %my_float_var = OpVariable %_ptr_Private_float Private
135 %_ptr_Function_float = OpTypePointer Function %float
136 %int_0 = OpConstant %int 0
137 %int_1 = OpConstant %int 1
138 %int_2 = OpConstant %int 2
139 %int_3 = OpConstant %int 3
140 %int_5 = OpConstant %int 5
141
142 ; Making the following nested structures.
143 ;
144 ; struct S {
145 ; bool b;
146 ; vec4 v[5];
147 ; int i;
148 ; mat4x3 m[5];
149 ; }
150 ; uniform blockName {
151 ; S s;
152 ; bool cond;
153 ; }
154
155 %f32arr = OpTypeRuntimeArray %float
156 %v4float = OpTypeVector %float 4
157 %array5_mat4x3 = OpTypeArray %mat4x3 %int_5
158 %array5_vec4 = OpTypeArray %v4float %int_5
159 %_ptr_Uniform_float = OpTypePointer Uniform %float
160 %_ptr_Function_vec4 = OpTypePointer Function %v4float
161 %_ptr_Uniform_vec4 = OpTypePointer Uniform %v4float
162 %struct_s = OpTypeStruct %int %array5_vec4 %int %array5_mat4x3
163 %struct_blockName = OpTypeStruct %struct_s %int
164 %_ptr_Uniform_blockName = OpTypePointer Uniform %struct_blockName
165 %_ptr_Uniform_struct_s = OpTypePointer Uniform %struct_s
166 %_ptr_Uniform_array5_mat4x3 = OpTypePointer Uniform %array5_mat4x3
167 %_ptr_Uniform_mat4x3 = OpTypePointer Uniform %mat4x3
168 %_ptr_Uniform_v3float = OpTypePointer Uniform %v3float
169 %blockName_var = OpVariable %_ptr_Uniform_blockName Uniform
170 %spec_int = OpSpecConstant %int 2
171 %func = OpFunction %void None %void_f
172 %my_label = OpLabel
173 )";
174 }
175
176 TEST_F(ValidateComposites, VectorExtractDynamicSuccess) {
177 const std::string body = R"(
178 %val1 = OpVectorExtractDynamic %f32 %f32vec4_0123 %u32_0
179 )";
180
181 CompileSuccessfully(GenerateShaderCode(body).c_str());
182 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
183 }
184
185 TEST_F(ValidateComposites, VectorExtractDynamicWrongResultType) {
186 const std::string body = R"(
187 %val1 = OpVectorExtractDynamic %f32vec4 %f32vec4_0123 %u32_0
188 )";
189
190 CompileSuccessfully(GenerateShaderCode(body).c_str());
191 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
192 EXPECT_THAT(getDiagnosticString(),
193 HasSubstr("Expected Result Type to be a scalar type"));
194 }
195
196 TEST_F(ValidateComposites, VectorExtractDynamicNotVector) {
197 const std::string body = R"(
198 %val1 = OpVectorExtractDynamic %f32 %f32mat22_1212 %u32_0
199 )";
200
201 CompileSuccessfully(GenerateShaderCode(body).c_str());
202 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
203 EXPECT_THAT(getDiagnosticString(),
204 HasSubstr("Expected Vector type to be OpTypeVector"));
205 }
206
207 TEST_F(ValidateComposites, VectorExtractDynamicWrongVectorComponent) {
208 const std::string body = R"(
209 %val1 = OpVectorExtractDynamic %f32 %u32vec4_0123 %u32_0
210 )";
211
212 CompileSuccessfully(GenerateShaderCode(body).c_str());
213 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
214 EXPECT_THAT(
215 getDiagnosticString(),
216 HasSubstr("Expected Vector component type to be equal to Result Type"));
217 }
218
219 TEST_F(ValidateComposites, VectorExtractDynamicWrongIndexType) {
220 const std::string body = R"(
221 %val1 = OpVectorExtractDynamic %f32 %f32vec4_0123 %f32_0
222 )";
223
224 CompileSuccessfully(GenerateShaderCode(body).c_str());
225 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
226 EXPECT_THAT(getDiagnosticString(),
227 HasSubstr("Expected Index to be int scalar"));
228 }
229
230 TEST_F(ValidateComposites, VectorInsertDynamicSuccess) {
231 const std::string body = R"(
232 %val1 = OpVectorInsertDynamic %f32vec4 %f32vec4_0123 %f32_1 %u32_0
233 )";
234
235 CompileSuccessfully(GenerateShaderCode(body).c_str());
236 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
237 }
238
239 TEST_F(ValidateComposites, VectorInsertDynamicWrongResultType) {
240 const std::string body = R"(
241 %val1 = OpVectorInsertDynamic %f32 %f32vec4_0123 %f32_1 %u32_0
242 )";
243
244 CompileSuccessfully(GenerateShaderCode(body).c_str());
245 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
246 EXPECT_THAT(getDiagnosticString(),
247 HasSubstr("Expected Result Type to be OpTypeVector"));
248 }
249
250 TEST_F(ValidateComposites, VectorInsertDynamicNotVector) {
251 const std::string body = R"(
252 %val1 = OpVectorInsertDynamic %f32vec4 %f32mat22_1212 %f32_1 %u32_0
253 )";
254
255 CompileSuccessfully(GenerateShaderCode(body).c_str());
256 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
257 EXPECT_THAT(getDiagnosticString(),
258 HasSubstr("Expected Vector type to be equal to Result Type"));
259 }
260
261 TEST_F(ValidateComposites, VectorInsertDynamicWrongComponentType) {
262 const std::string body = R"(
263 %val1 = OpVectorInsertDynamic %f32vec4 %f32vec4_0123 %u32_1 %u32_0
264 )";
265
266 CompileSuccessfully(GenerateShaderCode(body).c_str());
267 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
268 EXPECT_THAT(getDiagnosticString(),
269 HasSubstr("Expected Component type to be equal to Result Type "
270 "component type"));
271 }
272
273 TEST_F(ValidateComposites, VectorInsertDynamicWrongIndexType) {
274 const std::string body = R"(
275 %val1 = OpVectorInsertDynamic %f32vec4 %f32vec4_0123 %f32_1 %f32_0
276 )";
277
278 CompileSuccessfully(GenerateShaderCode(body).c_str());
279 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
280 EXPECT_THAT(getDiagnosticString(),
281 HasSubstr("Expected Index to be int scalar"));
282 }
283
284 TEST_F(ValidateComposites, CompositeConstructNotComposite) {
285 const std::string body = R"(
286 %val1 = OpCompositeConstruct %f32 %f32_1
287 )";
288
289 CompileSuccessfully(GenerateShaderCode(body).c_str());
290 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
291 EXPECT_THAT(getDiagnosticString(),
292 HasSubstr("Expected Result Type to be a composite type"));
293 }
294
295 TEST_F(ValidateComposites, CompositeConstructVectorSuccess) {
296 const std::string body = R"(
297 %val1 = OpCompositeConstruct %f32vec4 %f32vec2_12 %f32vec2_12
298 %val2 = OpCompositeConstruct %f32vec4 %f32vec2_12 %f32_0 %f32_0
299 %val3 = OpCompositeConstruct %f32vec4 %f32_0 %f32_0 %f32vec2_12
300 %val4 = OpCompositeConstruct %f32vec4 %f32_0 %f32_1 %f32_2 %f32_3
301 )";
302
303 CompileSuccessfully(GenerateShaderCode(body).c_str());
304 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
305 }
306
307 TEST_F(ValidateComposites, CompositeConstructVectorOnlyOneConstituent) {
308 const std::string body = R"(
309 %val1 = OpCompositeConstruct %f32vec4 %f32vec4_0123
310 )";
311
312 CompileSuccessfully(GenerateShaderCode(body).c_str());
313 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
314 EXPECT_THAT(getDiagnosticString(),
315 HasSubstr("Expected number of constituents to be at least 2"));
316 }
317
318 TEST_F(ValidateComposites, CompositeConstructLongVectorOnlyOneConstituent) {
319 const std::string body = R"(
320 %val1 = OpCompositeConstruct %f32vec4 %f32vec4_0123
321 )";
322 const std::string caps = R"(
323 OpCapability LongVectorEXT
324 OpExtension "SPV_EXT_long_vector"
325 )";
326
327 CompileSuccessfully(GenerateShaderCode(body, caps).c_str());
328 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
329 }
330
331 TEST_F(ValidateComposites, CompositeConstructVectorWrongConsituent1) {
332 const std::string body = R"(
333 %val1 = OpCompositeConstruct %f32vec4 %f32 %f32vec2_12
334 )";
335
336 CompileSuccessfully(GenerateShaderCode(body).c_str());
337 ASSERT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions());
338 EXPECT_THAT(getDiagnosticString(),
339 HasSubstr("Operand '5[%float]' cannot be a "
340 "type"));
341 }
342
343 TEST_F(ValidateComposites, CompositeConstructVectorWrongConsituent2) {
344 const std::string body = R"(
345 %val1 = OpCompositeConstruct %f32vec4 %f32vec2_12 %u32vec2_01
346 )";
347
348 CompileSuccessfully(GenerateShaderCode(body).c_str());
349 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
350 EXPECT_THAT(
351 getDiagnosticString(),
352 HasSubstr("Expected Constituents to be scalars or vectors of the same "
353 "type as Result Type components"));
354 }
355
356 TEST_F(ValidateComposites, CompositeConstructVectorWrongConsituent3) {
357 const std::string body = R"(
358 %val1 = OpCompositeConstruct %f32vec4 %f32vec2_12 %u32_0 %f32_0
359 )";
360
361 CompileSuccessfully(GenerateShaderCode(body).c_str());
362 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
363 EXPECT_THAT(
364 getDiagnosticString(),
365 HasSubstr("Expected Constituents to be scalars or vectors of the same "
366 "type as Result Type components"));
367 }
368
369 TEST_F(ValidateComposites, CompositeConstructVectorWrongComponentNumber1) {
370 const std::string body = R"(
371 %val1 = OpCompositeConstruct %f32vec4 %f32vec2_12 %f32_0
372 )";
373
374 CompileSuccessfully(GenerateShaderCode(body).c_str());
375 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
376 EXPECT_THAT(
377 getDiagnosticString(),
378 HasSubstr("Expected total number of given components to be equal to the "
379 "size of Result Type vector"));
380 }
381
382 TEST_F(ValidateComposites, CompositeConstructVectorWrongComponentNumber2) {
383 const std::string body = R"(
384 %val1 = OpCompositeConstruct %f32vec4 %f32vec2_12 %f32vec2_12 %f32_0
385 )";
386
387 CompileSuccessfully(GenerateShaderCode(body).c_str());
388 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
389 EXPECT_THAT(
390 getDiagnosticString(),
391 HasSubstr("Expected total number of given components to be equal to the "
392 "size of Result Type vector"));
393 }
394
395 TEST_F(ValidateComposites, CompositeConstructMatrixSuccess) {
396 const std::string body = R"(
397 %val1 = OpCompositeConstruct %f32mat22 %f32vec2_12 %f32vec2_12
398 %val2 = OpCompositeConstruct %f32mat23 %f32vec2_12 %f32vec2_12 %f32vec2_12
399 )";
400
401 CompileSuccessfully(GenerateShaderCode(body).c_str());
402 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
403 }
404
405 TEST_F(ValidateComposites, CompositeConstructVectorWrongConsituentNumber1) {
406 const std::string body = R"(
407 %val1 = OpCompositeConstruct %f32mat22 %f32vec2_12
408 )";
409
410 CompileSuccessfully(GenerateShaderCode(body).c_str());
411 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
412 EXPECT_THAT(
413 getDiagnosticString(),
414 HasSubstr("Expected total number of Constituents to be equal to the "
415 "number of columns of Result Type matrix"));
416 }
417
418 TEST_F(ValidateComposites, CompositeConstructVectorWrongConsituentNumber2) {
419 const std::string body = R"(
420 %val1 = OpCompositeConstruct %f32mat22 %f32vec2_12 %f32vec2_12 %f32vec2_12
421 )";
422
423 CompileSuccessfully(GenerateShaderCode(body).c_str());
424 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
425 EXPECT_THAT(
426 getDiagnosticString(),
427 HasSubstr("Expected total number of Constituents to be equal to the "
428 "number of columns of Result Type matrix"));
429 }
430
431 TEST_F(ValidateComposites, CompositeConstructVectorWrongConsituent) {
432 const std::string body = R"(
433 %val1 = OpCompositeConstruct %f32mat22 %f32vec2_12 %u32vec2_01
434 )";
435
436 CompileSuccessfully(GenerateShaderCode(body).c_str());
437 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
438 EXPECT_THAT(
439 getDiagnosticString(),
440 HasSubstr("Expected Constituent type to be equal to the column type "
441 "Result Type matrix"));
442 }
443
444 TEST_F(ValidateComposites, CompositeConstructArraySuccess) {
445 const std::string body = R"(
446 %val1 = OpCompositeConstruct %f32vec2arr3 %f32vec2_12 %f32vec2_12 %f32vec2_12
447 )";
448
449 CompileSuccessfully(GenerateShaderCode(body).c_str());
450 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
451 }
452
453 TEST_F(ValidateComposites, CompositeConstructArrayWrongConsituentNumber1) {
454 const std::string body = R"(
455 %val1 = OpCompositeConstruct %f32vec2arr3 %f32vec2_12 %f32vec2_12
456 )";
457
458 CompileSuccessfully(GenerateShaderCode(body).c_str());
459 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
460 EXPECT_THAT(
461 getDiagnosticString(),
462 HasSubstr("Expected total number of Constituents to be equal to the "
463 "number of elements of Result Type array"));
464 }
465
466 TEST_F(ValidateComposites, CompositeConstructArrayWrongConsituentNumber2) {
467 const std::string body = R"(
468 %val1 = OpCompositeConstruct %f32vec2arr3 %f32vec2_12 %f32vec2_12 %f32vec2_12 %f32vec2_12
469 )";
470
471 CompileSuccessfully(GenerateShaderCode(body).c_str());
472 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
473 EXPECT_THAT(
474 getDiagnosticString(),
475 HasSubstr("Expected total number of Constituents to be equal to the "
476 "number of elements of Result Type array"));
477 }
478
479 TEST_F(ValidateComposites, CompositeConstructArrayWrongConsituent) {
480 const std::string body = R"(
481 %val1 = OpCompositeConstruct %f32vec2arr3 %f32vec2_12 %u32vec2_01 %f32vec2_12
482 )";
483
484 CompileSuccessfully(GenerateShaderCode(body).c_str());
485 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
486 EXPECT_THAT(
487 getDiagnosticString(),
488 HasSubstr("Expected Constituent type to be equal to the column type "
489 "Result Type array"));
490 }
491
492 TEST_F(ValidateComposites, CompositeConstructStructSuccess) {
493 const std::string body = R"(
494 %val1 = OpCompositeConstruct %f32u32struct %f32_0 %u32_1
495 )";
496
497 CompileSuccessfully(GenerateShaderCode(body).c_str());
498 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
499 }
500
501 TEST_F(ValidateComposites, CompositeConstructStructWrongConstituentNumber1) {
502 const std::string body = R"(
503 %val1 = OpCompositeConstruct %f32u32struct %f32_0
504 )";
505
506 CompileSuccessfully(GenerateShaderCode(body).c_str());
507 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
508 EXPECT_THAT(
509 getDiagnosticString(),
510 HasSubstr("Expected total number of Constituents to be equal to the "
511 "number of members of Result Type struct"));
512 }
513
514 TEST_F(ValidateComposites, CompositeConstructStructWrongConstituentNumber2) {
515 const std::string body = R"(
516 %val1 = OpCompositeConstruct %f32u32struct %f32_0 %u32_1 %u32_1
517 )";
518
519 CompileSuccessfully(GenerateShaderCode(body).c_str());
520 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
521 EXPECT_THAT(
522 getDiagnosticString(),
523 HasSubstr("Expected total number of Constituents to be equal to the "
524 "number of members of Result Type struct"));
525 }
526
527 TEST_F(ValidateComposites, CompositeConstructStructWrongConstituent) {
528 const std::string body = R"(
529 %val1 = OpCompositeConstruct %f32u32struct %f32_0 %f32_1
530 )";
531
532 CompileSuccessfully(GenerateShaderCode(body).c_str());
533 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
534 EXPECT_THAT(getDiagnosticString(),
535 HasSubstr("Expected Constituent type to be equal to the "
536 "corresponding member type of Result Type struct"));
537 }
538
539 TEST_F(ValidateComposites, CopyObjectSuccess) {
540 const std::string body = R"(
541 %val1 = OpCopyObject %f32 %f32_0
542 %val2 = OpCopyObject %f32vec4 %f32vec4_0123
543 )";
544
545 CompileSuccessfully(GenerateShaderCode(body).c_str());
546 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
547 }
548
549 TEST_F(ValidateComposites, CopyObjectResultTypeNotType) {
550 const std::string body = R"(
551 %val1 = OpCopyObject %f32_0 %f32_0
552 )";
553
554 CompileSuccessfully(GenerateShaderCode(body).c_str());
555 ASSERT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions());
556 EXPECT_THAT(getDiagnosticString(),
557 HasSubstr("ID '19[%float_0]' is not a type id"));
558 }
559
560 TEST_F(ValidateComposites, CopyObjectWrongOperandType) {
561 const std::string body = R"(
562 %val1 = OpCopyObject %f32 %u32_0
563 )";
564
565 CompileSuccessfully(GenerateShaderCode(body).c_str());
566 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
567 EXPECT_THAT(
568 getDiagnosticString(),
569 HasSubstr("Expected Result Type and Operand type to be the same"));
570 }
571
572 TEST_F(ValidateComposites, TransposeSuccess) {
573 const std::string body = R"(
574 %val1 = OpTranspose %f32mat32 %f32mat23_121212
575 %val2 = OpTranspose %f32mat22 %f32mat22_1212
576 )";
577
578 CompileSuccessfully(GenerateShaderCode(body).c_str());
579 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
580 }
581
582 TEST_F(ValidateComposites, TransposeResultTypeNotMatrix) {
583 const std::string body = R"(
584 %val1 = OpTranspose %f32vec4 %f32mat22_1212
585 )";
586
587 CompileSuccessfully(GenerateShaderCode(body).c_str());
588 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
589 EXPECT_THAT(getDiagnosticString(),
590 HasSubstr("Expected Result Type to be a matrix type"));
591 }
592
593 TEST_F(ValidateComposites, TransposeDifferentComponentTypes) {
594 const std::string body = R"(
595 %val1 = OpTranspose %f64mat22 %f32mat22_1212
596 )";
597
598 CompileSuccessfully(GenerateShaderCode(body).c_str());
599 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
600 EXPECT_THAT(
601 getDiagnosticString(),
602 HasSubstr("Expected component types of Matrix and Result Type to be "
603 "identical"));
604 }
605
606 TEST_F(ValidateComposites, TransposeIncompatibleDimensions1) {
607 const std::string body = R"(
608 %val1 = OpTranspose %f32mat23 %f32mat22_1212
609 )";
610
611 CompileSuccessfully(GenerateShaderCode(body).c_str());
612 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
613 EXPECT_THAT(getDiagnosticString(),
614 HasSubstr("Expected number of columns and the column size "
615 "of Matrix to be the reverse of those of Result Type"));
616 }
617
618 TEST_F(ValidateComposites, TransposeIncompatibleDimensions2) {
619 const std::string body = R"(
620 %val1 = OpTranspose %f32mat32 %f32mat22_1212
621 )";
622
623 CompileSuccessfully(GenerateShaderCode(body).c_str());
624 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
625 EXPECT_THAT(getDiagnosticString(),
626 HasSubstr("Expected number of columns and the column size "
627 "of Matrix to be the reverse of those of Result Type"));
628 }
629
630 TEST_F(ValidateComposites, TransposeIncompatibleDimensions3) {
631 const std::string body = R"(
632 %val1 = OpTranspose %f32mat23 %f32mat23_121212
633 )";
634
635 CompileSuccessfully(GenerateShaderCode(body).c_str());
636 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
637 EXPECT_THAT(getDiagnosticString(),
638 HasSubstr("Expected number of columns and the column size "
639 "of Matrix to be the reverse of those of Result Type"));
640 }
641
642 TEST_F(ValidateComposites, CompositeExtractSuccess) {
643 const std::string body = R"(
644 %val1 = OpCompositeExtract %f32 %f32vec4_0123 1
645 %val2 = OpCompositeExtract %u32 %u32vec4_0123 0
646 %val3 = OpCompositeExtract %f32 %f32mat22_1212 0 1
647 %val4 = OpCompositeExtract %f32vec2 %f32mat22_1212 0
648 %array = OpCompositeConstruct %f32vec2arr3 %f32vec2_12 %f32vec2_12 %f32vec2_12
649 %val5 = OpCompositeExtract %f32vec2 %array 2
650 %val6 = OpCompositeExtract %f32 %array 2 1
651 %struct = OpLoad %big_struct %var_big_struct
652 %val7 = OpCompositeExtract %f32 %struct 0
653 %val8 = OpCompositeExtract %f32vec4 %struct 1
654 %val9 = OpCompositeExtract %f32 %struct 1 2
655 %val10 = OpCompositeExtract %f32mat23 %struct 2
656 %val11 = OpCompositeExtract %f32vec2 %struct 2 2
657 %val12 = OpCompositeExtract %f32 %struct 2 2 1
658 %val13 = OpCompositeExtract %f32vec2 %struct 3 2
659 %val14 = OpCompositeExtract %f32 %struct 3 2 1
660 %val15 = OpCompositeExtract %f32vec2 %struct 4 1
661 %val16 = OpCompositeExtract %f32 %struct 4 0 1
662 %val17 = OpCompositeExtract %f32 %struct 5 0
663 %val18 = OpCompositeExtract %u32 %struct 5 1
664 )";
665
666 CompileSuccessfully(GenerateShaderCode(body));
667 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
668 }
669
670 TEST_F(ValidateComposites, CompositeExtractNotObject) {
671 const std::string body = R"(
672 %val1 = OpCompositeExtract %f32 %f32vec4 1
673 )";
674
675 CompileSuccessfully(GenerateShaderCode(body));
676 ASSERT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions());
677 EXPECT_THAT(getDiagnosticString(), HasSubstr("Operand '11[%v4float]' cannot "
678 "be a type"));
679 }
680
681 TEST_F(ValidateComposites, CompositeExtractNotComposite) {
682 const std::string body = R"(
683 %val1 = OpCompositeExtract %f32 %f32_1 0
684 )";
685
686 CompileSuccessfully(GenerateShaderCode(body));
687 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
688 EXPECT_THAT(getDiagnosticString(),
689 HasSubstr("Reached non-composite type while indexes still remain "
690 "to be traversed."));
691 }
692
693 TEST_F(ValidateComposites, CompositeExtractVectorOutOfBounds) {
694 const std::string body = R"(
695 %val1 = OpCompositeExtract %f32 %f32vec4_0123 4
696 )";
697
698 CompileSuccessfully(GenerateShaderCode(body));
699 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
700 EXPECT_THAT(getDiagnosticString(),
701 HasSubstr("Vector access is out of bounds, "
702 "vector size is 4, but access index is 4"));
703 }
704
705 TEST_F(ValidateComposites, CompositeExtractMatrixOutOfCols) {
706 const std::string body = R"(
707 %val1 = OpCompositeExtract %f32 %f32mat23_121212 3 1
708 )";
709
710 CompileSuccessfully(GenerateShaderCode(body));
711 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
712 EXPECT_THAT(getDiagnosticString(),
713 HasSubstr("Matrix access is out of bounds, "
714 "matrix has 3 columns, but access index is 3"));
715 }
716
717 TEST_F(ValidateComposites, CompositeExtractMatrixOutOfRows) {
718 const std::string body = R"(
719 %val1 = OpCompositeExtract %f32 %f32mat23_121212 2 5
720 )";
721
722 CompileSuccessfully(GenerateShaderCode(body));
723 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
724 EXPECT_THAT(getDiagnosticString(),
725 HasSubstr("Vector access is out of bounds, "
726 "vector size is 2, but access index is 5"));
727 }
728
729 TEST_F(ValidateComposites, CompositeExtractArrayOutOfBounds) {
730 const std::string body = R"(
731 %array = OpCompositeConstruct %f32vec2arr3 %f32vec2_12 %f32vec2_12 %f32vec2_12
732 %val1 = OpCompositeExtract %f32vec2 %array 3
733 )";
734
735 CompileSuccessfully(GenerateShaderCode(body));
736 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
737 EXPECT_THAT(getDiagnosticString(),
738 HasSubstr("Array access is out of bounds, "
739 "array size is 3, but access index is 3"));
740 }
741
742 TEST_F(ValidateComposites, CompositeExtractStructOutOfBounds) {
743 const std::string body = R"(
744 %struct = OpLoad %big_struct %var_big_struct
745 %val1 = OpCompositeExtract %f32 %struct 6
746 )";
747
748 CompileSuccessfully(GenerateShaderCode(body));
749 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
750 EXPECT_THAT(getDiagnosticString(),
751 HasSubstr("Index is out of bounds, can not find index 6 in the "
752 "structure <id> '37'. This structure has 6 members. "
753 "Largest valid index is 5."));
754 }
755
756 TEST_F(ValidateComposites, CompositeExtractNestedVectorOutOfBounds) {
757 const std::string body = R"(
758 %struct = OpLoad %big_struct %var_big_struct
759 %val1 = OpCompositeExtract %f32 %struct 3 1 5
760 )";
761
762 CompileSuccessfully(GenerateShaderCode(body));
763 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
764 EXPECT_THAT(getDiagnosticString(),
765 HasSubstr("Vector access is out of bounds, "
766 "vector size is 2, but access index is 5"));
767 }
768
769 TEST_F(ValidateComposites, CompositeExtractTooManyIndices) {
770 const std::string body = R"(
771 %struct = OpLoad %big_struct %var_big_struct
772 %val1 = OpCompositeExtract %f32 %struct 3 1 1 2
773 )";
774
775 CompileSuccessfully(GenerateShaderCode(body));
776 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
777 EXPECT_THAT(getDiagnosticString(),
778 HasSubstr("Reached non-composite type while "
779 "indexes still remain to be traversed."));
780 }
781
782 TEST_F(ValidateComposites, CompositeExtractNoIndices) {
783 const std::string body = R"(
784 %struct = OpLoad %big_struct %var_big_struct
785 %val1 = OpCompositeExtract %big_struct %struct
786 )";
787
788 CompileSuccessfully(GenerateShaderCode(body));
789 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
790 EXPECT_THAT(getDiagnosticString(),
791 HasSubstr("Expected at least one index to OpCompositeExtract"));
792 }
793
794 TEST_F(ValidateComposites, CompositeExtractWrongType1) {
795 const std::string body = R"(
796 %struct = OpLoad %big_struct %var_big_struct
797 %val1 = OpCompositeExtract %f32vec2 %struct 3 1 1
798 )";
799
800 CompileSuccessfully(GenerateShaderCode(body));
801 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
802 EXPECT_THAT(
803 getDiagnosticString(),
804 HasSubstr(
805 "Result type (OpTypeVector) does not match the type that results "
806 "from indexing into the composite (OpTypeFloat)."));
807 }
808
809 TEST_F(ValidateComposites, CompositeExtractWrongType2) {
810 const std::string body = R"(
811 %struct = OpLoad %big_struct %var_big_struct
812 %val1 = OpCompositeExtract %f32 %struct 3 1
813 )";
814
815 CompileSuccessfully(GenerateShaderCode(body));
816 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
817 EXPECT_THAT(getDiagnosticString(),
818 HasSubstr("Result type (OpTypeFloat) does not match the type "
819 "that results from indexing into the composite "
820 "(OpTypeVector)."));
821 }
822
823 TEST_F(ValidateComposites, CompositeExtractWrongType3) {
824 const std::string body = R"(
825 %struct = OpLoad %big_struct %var_big_struct
826 %val1 = OpCompositeExtract %f32 %struct 2 1
827 )";
828
829 CompileSuccessfully(GenerateShaderCode(body));
830 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
831 EXPECT_THAT(getDiagnosticString(),
832 HasSubstr("Result type (OpTypeFloat) does not match the type "
833 "that results from indexing into the composite "
834 "(OpTypeVector)."));
835 }
836
837 TEST_F(ValidateComposites, CompositeExtractWrongType4) {
838 const std::string body = R"(
839 %struct = OpLoad %big_struct %var_big_struct
840 %val1 = OpCompositeExtract %f32 %struct 4 1
841 )";
842
843 CompileSuccessfully(GenerateShaderCode(body));
844 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
845 EXPECT_THAT(getDiagnosticString(),
846 HasSubstr("Result type (OpTypeFloat) does not match the type "
847 "that results from indexing into the composite "
848 "(OpTypeVector)."));
849 }
850
851 TEST_F(ValidateComposites, CompositeExtractWrongType5) {
852 const std::string body = R"(
853 %struct = OpLoad %big_struct %var_big_struct
854 %val1 = OpCompositeExtract %f32 %struct 5 1
855 )";
856
857 CompileSuccessfully(GenerateShaderCode(body));
858 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
859 EXPECT_THAT(
860 getDiagnosticString(),
861 HasSubstr(
862 "Result type (OpTypeFloat) does not match the "
863 "type that results from indexing into the composite (OpTypeInt)."));
864 }
865
866 TEST_F(ValidateComposites, CompositeInsertSuccess) {
867 const std::string body = R"(
868 %val1 = OpCompositeInsert %f32vec4 %f32_1 %f32vec4_0123 0
869 %val2 = OpCompositeInsert %u32vec4 %u32_1 %u32vec4_0123 0
870 %val3 = OpCompositeInsert %f32mat22 %f32_2 %f32mat22_1212 0 1
871 %val4 = OpCompositeInsert %f32mat22 %f32vec2_01 %f32mat22_1212 0
872 %array = OpCompositeConstruct %f32vec2arr3 %f32vec2_12 %f32vec2_12 %f32vec2_12
873 %val5 = OpCompositeInsert %f32vec2arr3 %f32vec2_01 %array 2
874 %val6 = OpCompositeInsert %f32vec2arr3 %f32_3 %array 2 1
875 %struct = OpLoad %big_struct %var_big_struct
876 %val7 = OpCompositeInsert %big_struct %f32_3 %struct 0
877 %val8 = OpCompositeInsert %big_struct %f32vec4_0123 %struct 1
878 %val9 = OpCompositeInsert %big_struct %f32_3 %struct 1 2
879 %val10 = OpCompositeInsert %big_struct %f32mat23_121212 %struct 2
880 %val11 = OpCompositeInsert %big_struct %f32vec2_01 %struct 2 2
881 %val12 = OpCompositeInsert %big_struct %f32_3 %struct 2 2 1
882 %val13 = OpCompositeInsert %big_struct %f32vec2_01 %struct 3 2
883 %val14 = OpCompositeInsert %big_struct %f32_3 %struct 3 2 1
884 %val15 = OpCompositeInsert %big_struct %f32vec2_01 %struct 4 1
885 %val16 = OpCompositeInsert %big_struct %f32_3 %struct 4 0 1
886 %val17 = OpCompositeInsert %big_struct %f32_3 %struct 5 0
887 %val18 = OpCompositeInsert %big_struct %u32_3 %struct 5 1
888 )";
889
890 CompileSuccessfully(GenerateShaderCode(body));
891 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
892 }
893
894 TEST_F(ValidateComposites, CompositeInsertResultTypeDifferentFromComposite) {
895 const std::string body = R"(
896 %val1 = OpCompositeInsert %f32 %f32_1 %f32vec4_0123 0
897 )";
898
899 CompileSuccessfully(GenerateShaderCode(body));
900 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
901 EXPECT_THAT(getDiagnosticString(),
902 HasSubstr("The Result Type must be the same as Composite type in "
903 "OpCompositeInsert yielding Result Id 5."));
904 }
905
906 TEST_F(ValidateComposites, CompositeInsertNotComposite) {
907 const std::string body = R"(
908 %val1 = OpCompositeInsert %f32 %f32_1 %f32_0 0
909 )";
910
911 CompileSuccessfully(GenerateShaderCode(body));
912 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
913 EXPECT_THAT(getDiagnosticString(),
914 HasSubstr("Reached non-composite type while indexes still remain "
915 "to be traversed."));
916 }
917
918 TEST_F(ValidateComposites, CompositeInsertVectorOutOfBounds) {
919 const std::string body = R"(
920 %val1 = OpCompositeInsert %f32vec4 %f32_1 %f32vec4_0123 4
921 )";
922
923 CompileSuccessfully(GenerateShaderCode(body));
924 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
925 EXPECT_THAT(getDiagnosticString(),
926 HasSubstr("Vector access is out of bounds, "
927 "vector size is 4, but access index is 4"));
928 }
929
930 TEST_F(ValidateComposites, CompositeInsertMatrixOutOfCols) {
931 const std::string body = R"(
932 %val1 = OpCompositeInsert %f32mat23 %f32_1 %f32mat23_121212 3 1
933 )";
934
935 CompileSuccessfully(GenerateShaderCode(body));
936 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
937 EXPECT_THAT(getDiagnosticString(),
938 HasSubstr("Matrix access is out of bounds, "
939 "matrix has 3 columns, but access index is 3"));
940 }
941
942 TEST_F(ValidateComposites, CompositeInsertMatrixOutOfRows) {
943 const std::string body = R"(
944 %val1 = OpCompositeInsert %f32mat23 %f32_1 %f32mat23_121212 2 5
945 )";
946
947 CompileSuccessfully(GenerateShaderCode(body));
948 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
949 EXPECT_THAT(getDiagnosticString(),
950 HasSubstr("Vector access is out of bounds, "
951 "vector size is 2, but access index is 5"));
952 }
953
954 TEST_F(ValidateComposites, CompositeInsertArrayOutOfBounds) {
955 const std::string body = R"(
956 %array = OpCompositeConstruct %f32vec2arr3 %f32vec2_12 %f32vec2_12 %f32vec2_12
957 %val1 = OpCompositeInsert %f32vec2arr3 %f32vec2_01 %array 3
958 )";
959
960 CompileSuccessfully(GenerateShaderCode(body));
961 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
962 EXPECT_THAT(getDiagnosticString(),
963 HasSubstr("Array access is out of bounds, array "
964 "size is 3, but access index is 3"));
965 }
966
967 TEST_F(ValidateComposites, CompositeInsertStructOutOfBounds) {
968 const std::string body = R"(
969 %struct = OpLoad %big_struct %var_big_struct
970 %val1 = OpCompositeInsert %big_struct %f32_1 %struct 6
971 )";
972
973 CompileSuccessfully(GenerateShaderCode(body));
974 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
975 EXPECT_THAT(getDiagnosticString(),
976 HasSubstr("Index is out of bounds, can not find index 6 in the "
977 "structure <id> '37'. This structure has 6 members. "
978 "Largest valid index is 5."));
979 }
980
981 TEST_F(ValidateComposites, CompositeInsertNestedVectorOutOfBounds) {
982 const std::string body = R"(
983 %struct = OpLoad %big_struct %var_big_struct
984 %val1 = OpCompositeInsert %big_struct %f32_1 %struct 3 1 5
985 )";
986
987 CompileSuccessfully(GenerateShaderCode(body));
988 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
989 EXPECT_THAT(getDiagnosticString(),
990 HasSubstr("Vector access is out of bounds, "
991 "vector size is 2, but access index is 5"));
992 }
993
994 TEST_F(ValidateComposites, CompositeInsertTooManyIndices) {
995 const std::string body = R"(
996 %struct = OpLoad %big_struct %var_big_struct
997 %val1 = OpCompositeInsert %big_struct %f32_1 %struct 3 1 1 2
998 )";
999
1000 CompileSuccessfully(GenerateShaderCode(body));
1001 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1002 EXPECT_THAT(getDiagnosticString(),
1003 HasSubstr("Reached non-composite type while indexes still remain "
1004 "to be traversed."));
1005 }
1006
1007 TEST_F(ValidateComposites, CompositeInsertWrongType1) {
1008 const std::string body = R"(
1009 %struct = OpLoad %big_struct %var_big_struct
1010 %val1 = OpCompositeInsert %big_struct %f32vec2_01 %struct 3 1 1
1011 )";
1012
1013 CompileSuccessfully(GenerateShaderCode(body));
1014 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1015 EXPECT_THAT(getDiagnosticString(),
1016 HasSubstr("The Object type (OpTypeVector) does not match the "
1017 "type that results from indexing into the Composite "
1018 "(OpTypeFloat)."));
1019 }
1020
1021 TEST_F(ValidateComposites, CompositeInsertWrongType2) {
1022 const std::string body = R"(
1023 %struct = OpLoad %big_struct %var_big_struct
1024 %val1 = OpCompositeInsert %big_struct %f32_1 %struct 3 1
1025 )";
1026
1027 CompileSuccessfully(GenerateShaderCode(body));
1028 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1029 EXPECT_THAT(getDiagnosticString(),
1030 HasSubstr("The Object type (OpTypeFloat) does not match the type "
1031 "that results from indexing into the Composite "
1032 "(OpTypeVector)."));
1033 }
1034
1035 TEST_F(ValidateComposites, CompositeInsertWrongType3) {
1036 const std::string body = R"(
1037 %struct = OpLoad %big_struct %var_big_struct
1038 %val1 = OpCompositeInsert %big_struct %f32_1 %struct 2 1
1039 )";
1040
1041 CompileSuccessfully(GenerateShaderCode(body));
1042 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1043 EXPECT_THAT(getDiagnosticString(),
1044 HasSubstr("The Object type (OpTypeFloat) does not match the type "
1045 "that results from indexing into the Composite "
1046 "(OpTypeVector)."));
1047 }
1048
1049 TEST_F(ValidateComposites, CompositeInsertWrongType4) {
1050 const std::string body = R"(
1051 %struct = OpLoad %big_struct %var_big_struct
1052 %val1 = OpCompositeInsert %big_struct %f32_1 %struct 4 1
1053 )";
1054
1055 CompileSuccessfully(GenerateShaderCode(body));
1056 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1057 EXPECT_THAT(getDiagnosticString(),
1058 HasSubstr("The Object type (OpTypeFloat) does not match the type "
1059 "that results from indexing into the Composite "
1060 "(OpTypeVector)."));
1061 }
1062
1063 TEST_F(ValidateComposites, CompositeInsertWrongType5) {
1064 const std::string body = R"(
1065 %struct = OpLoad %big_struct %var_big_struct
1066 %val1 = OpCompositeInsert %big_struct %f32_1 %struct 5 1
1067 )";
1068
1069 CompileSuccessfully(GenerateShaderCode(body));
1070 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1071 EXPECT_THAT(getDiagnosticString(),
1072 HasSubstr("The Object type (OpTypeFloat) does not match the type "
1073 "that results from indexing into the Composite "
1074 "(OpTypeInt)."));
1075 }
1076
1077 // Tests ported from val_id_test.cpp.
1078
1079 // Valid. Tests both CompositeExtract and CompositeInsert with 255 indexes.
1080 TEST_F(ValidateComposites, CompositeExtractInsertLimitsGood) {
1081 int depth = 255;
1082 std::string header = GetHeaderForTestsFromValId();
1083 header.erase(header.find("%func"));
1084 std::ostringstream spirv;
1085 spirv << header << std::endl;
1086
1087 // Build nested structures. Struct 'i' contains struct 'i-1'
1088 spirv << "%s_depth_1 = OpTypeStruct %float\n";
1089 for (int i = 2; i <= depth; ++i) {
1090 spirv << "%s_depth_" << i << " = OpTypeStruct %s_depth_" << i - 1 << "\n";
1091 }
1092
1093 // Define Pointer and Variable to use for CompositeExtract/Insert.
1094 spirv << "%_ptr_Uniform_deep_struct = OpTypePointer Uniform %s_depth_"
1095 << depth << "\n";
1096 spirv << "%deep_var = OpVariable %_ptr_Uniform_deep_struct Uniform\n";
1097
1098 // Function Start
1099 spirv << R"(
1100 %func = OpFunction %void None %void_f
1101 %my_label = OpLabel
1102 )";
1103
1104 // OpCompositeExtract/Insert with 'n' indexes (n = depth)
1105 spirv << "%deep = OpLoad %s_depth_" << depth << " %deep_var" << std::endl;
1106 spirv << "%entry = OpCompositeExtract %float %deep";
1107 for (int i = 0; i < depth; ++i) {
1108 spirv << " 0";
1109 }
1110 spirv << std::endl;
1111 spirv << "%new_composite = OpCompositeInsert %s_depth_" << depth
1112 << " %entry %deep";
1113 for (int i = 0; i < depth; ++i) {
1114 spirv << " 0";
1115 }
1116 spirv << std::endl;
1117
1118 // Function end
1119 spirv << R"(
1120 OpReturn
1121 OpFunctionEnd
1122 )";
1123 CompileSuccessfully(spirv.str());
1124 EXPECT_EQ(SPV_SUCCESS, ValidateInstructions());
1125 }
1126
1127 // Invalid: 256 indexes passed to OpCompositeExtract. Limit is 255.
1128 TEST_F(ValidateComposites, CompositeExtractArgCountExceededLimitBad) {
1129 std::ostringstream spirv;
1130 spirv << GetHeaderForTestsFromValId() << std::endl;
1131 spirv << "%matrix = OpLoad %mat4x3 %my_matrix" << std::endl;
1132 spirv << "%entry = OpCompositeExtract %float %matrix";
1133 for (int i = 0; i < 256; ++i) {
1134 spirv << " 0";
1135 }
1136 spirv << R"(
1137 OpReturn
1138 OpFunctionEnd
1139 )";
1140 CompileSuccessfully(spirv.str());
1141 EXPECT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1142 EXPECT_THAT(getDiagnosticString(),
1143 HasSubstr("The number of indexes in OpCompositeExtract may not "
1144 "exceed 255. Found 256 indexes."));
1145 }
1146
1147 // Invalid: 256 indexes passed to OpCompositeInsert. Limit is 255.
1148 TEST_F(ValidateComposites, CompositeInsertArgCountExceededLimitBad) {
1149 std::ostringstream spirv;
1150 spirv << GetHeaderForTestsFromValId() << std::endl;
1151 spirv << "%matrix = OpLoad %mat4x3 %my_matrix" << std::endl;
1152 spirv << "%new_composite = OpCompositeInsert %mat4x3 %int_0 %matrix";
1153 for (int i = 0; i < 256; ++i) {
1154 spirv << " 0";
1155 }
1156 spirv << R"(
1157 OpReturn
1158 OpFunctionEnd
1159 )";
1160 CompileSuccessfully(spirv.str());
1161 EXPECT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1162 EXPECT_THAT(getDiagnosticString(),
1163 HasSubstr("The number of indexes in OpCompositeInsert may not "
1164 "exceed 255. Found 256 indexes."));
1165 }
1166
1167 // Invalid: In OpCompositeInsert, result type must be the same as composite type
1168 TEST_F(ValidateComposites, CompositeInsertWrongResultTypeBad) {
1169 std::ostringstream spirv;
1170 spirv << GetHeaderForTestsFromValId() << std::endl;
1171 spirv << "%matrix = OpLoad %mat4x3 %my_matrix" << std::endl;
1172 spirv << "%float_entry = OpCompositeExtract %float %matrix 0 1" << std::endl;
1173 spirv << "%new_composite = OpCompositeInsert %float %float_entry %matrix 0 1"
1174 << std::endl;
1175 spirv << R"(OpReturn
1176 OpFunctionEnd)";
1177 CompileSuccessfully(spirv.str());
1178 EXPECT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1179 EXPECT_THAT(getDiagnosticString(),
1180 HasSubstr("The Result Type must be the same as Composite type"));
1181 }
1182
1183 // Invalid: No Indexes were passed to OpCompositeExtract.
1184 TEST_F(ValidateComposites, CompositeExtractNoIndices2) {
1185 std::ostringstream spirv;
1186 spirv << GetHeaderForTestsFromValId() << std::endl;
1187 spirv << "%matrix = OpLoad %mat4x3 %my_matrix" << std::endl;
1188 spirv << "%float_entry = OpCompositeExtract %mat4x3 %matrix" << std::endl;
1189 spirv << R"(OpReturn
1190 OpFunctionEnd)";
1191 CompileSuccessfully(spirv.str());
1192 EXPECT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1193 EXPECT_THAT(
1194 getDiagnosticString(),
1195 HasSubstr(
1196 "Expected at least one index to OpCompositeExtract, zero found"));
1197 }
1198
1199 // Invalid: No Indexes were passed to OpCompositeExtract.
1200 TEST_F(ValidateComposites, CompositeExtractNoIndicesWrongResultType) {
1201 std::ostringstream spirv;
1202 spirv << GetHeaderForTestsFromValId() << std::endl;
1203 spirv << "%matrix = OpLoad %mat4x3 %my_matrix" << std::endl;
1204 spirv << "%float_entry = OpCompositeExtract %float %matrix" << std::endl;
1205 spirv << R"(OpReturn
1206 OpFunctionEnd)";
1207 CompileSuccessfully(spirv.str());
1208 EXPECT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1209 EXPECT_THAT(
1210 getDiagnosticString(),
1211 HasSubstr(
1212 "Expected at least one index to OpCompositeExtract, zero found"));
1213 }
1214
1215 // Invalid: No Indices were passed to OpCompositeInsert, and the type of the
1216 // Object<id> argument matches the Composite type.
1217 TEST_F(ValidateComposites, CompositeInsertMissingIndices) {
1218 std::ostringstream spirv;
1219 spirv << GetHeaderForTestsFromValId() << std::endl;
1220 spirv << "%matrix = OpLoad %mat4x3 %my_matrix" << std::endl;
1221 spirv << "%matrix_2 = OpLoad %mat4x3 %my_matrix" << std::endl;
1222 spirv << "%new_composite = OpCompositeInsert %mat4x3 %matrix_2 %matrix";
1223 spirv << R"(
1224 OpReturn
1225 OpFunctionEnd)";
1226 CompileSuccessfully(spirv.str());
1227 EXPECT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1228 EXPECT_THAT(
1229 getDiagnosticString(),
1230 HasSubstr(
1231 "Expected at least one index to OpCompositeInsert, zero found"));
1232 }
1233
1234 // Invalid: No Indices were passed to OpCompositeInsert, but the type of the
1235 // Object<id> argument does not match the Composite type.
1236 TEST_F(ValidateComposites, CompositeInsertMissingIndices2) {
1237 std::ostringstream spirv;
1238 spirv << GetHeaderForTestsFromValId() << std::endl;
1239 spirv << "%matrix = OpLoad %mat4x3 %my_matrix" << std::endl;
1240 spirv << "%new_composite = OpCompositeInsert %mat4x3 %int_0 %matrix";
1241 spirv << R"(
1242 OpReturn
1243 OpFunctionEnd)";
1244 CompileSuccessfully(spirv.str());
1245 EXPECT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1246 EXPECT_THAT(
1247 getDiagnosticString(),
1248 HasSubstr(
1249 "Expected at least one index to OpCompositeInsert, zero found"));
1250 }
1251
1252 // Valid: Tests that we can index into Struct, Array, Matrix, and Vector!
1253 TEST_F(ValidateComposites, CompositeExtractInsertIndexIntoAllTypesGood) {
1254 // indexes that we are passing are: 0, 3, 1, 2, 0
1255 // 0 will select the struct_s within the base struct (blockName)
1256 // 3 will select the Array that contains 5 matrices
1257 // 1 will select the Matrix that is at index 1 of the array
1258 // 2 will select the column (which is a vector) within the matrix at index 2
1259 // 0 will select the element at the index 0 of the vector. (which is a float).
1260 std::ostringstream spirv;
1261 spirv << GetHeaderForTestsFromValId() << R"(
1262 %myblock = OpLoad %struct_blockName %blockName_var
1263 %ss = OpCompositeExtract %struct_s %myblock 0
1264 %sa = OpCompositeExtract %array5_mat4x3 %myblock 0 3
1265 %sm = OpCompositeExtract %mat4x3 %myblock 0 3 1
1266 %sc = OpCompositeExtract %v3float %myblock 0 3 1 2
1267 %fl = OpCompositeExtract %float %myblock 0 3 1 2 0
1268 ;
1269 ; Now let's insert back at different levels...
1270 ;
1271 %b1 = OpCompositeInsert %struct_blockName %ss %myblock 0
1272 %b2 = OpCompositeInsert %struct_blockName %sa %myblock 0 3
1273 %b3 = OpCompositeInsert %struct_blockName %sm %myblock 0 3 1
1274 %b4 = OpCompositeInsert %struct_blockName %sc %myblock 0 3 1 2
1275 %b5 = OpCompositeInsert %struct_blockName %fl %myblock 0 3 1 2 0
1276 OpReturn
1277 OpFunctionEnd
1278 )";
1279
1280 CompileSuccessfully(spirv.str());
1281 EXPECT_EQ(SPV_SUCCESS, ValidateInstructions());
1282 }
1283
1284 // Invalid. More indexes are provided than needed for OpCompositeExtract.
1285 TEST_F(ValidateComposites, CompositeExtractReachedScalarBad) {
1286 // indexes that we are passing are: 0, 3, 1, 2, 0
1287 // 0 will select the struct_s within the base struct (blockName)
1288 // 3 will select the Array that contains 5 matrices
1289 // 1 will select the Matrix that is at index 1 of the array
1290 // 2 will select the column (which is a vector) within the matrix at index 2
1291 // 0 will select the element at the index 0 of the vector. (which is a float).
1292 std::ostringstream spirv;
1293 spirv << GetHeaderForTestsFromValId() << R"(
1294 %myblock = OpLoad %struct_blockName %blockName_var
1295 %fl = OpCompositeExtract %float %myblock 0 3 1 2 0 1
1296 OpReturn
1297 OpFunctionEnd
1298 )";
1299
1300 CompileSuccessfully(spirv.str());
1301 EXPECT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1302 EXPECT_THAT(getDiagnosticString(),
1303 HasSubstr("Reached non-composite type while indexes still remain "
1304 "to be traversed."));
1305 }
1306
1307 // Invalid. More indexes are provided than needed for OpCompositeInsert.
1308 TEST_F(ValidateComposites, CompositeInsertReachedScalarBad) {
1309 // indexes that we are passing are: 0, 3, 1, 2, 0
1310 // 0 will select the struct_s within the base struct (blockName)
1311 // 3 will select the Array that contains 5 matrices
1312 // 1 will select the Matrix that is at index 1 of the array
1313 // 2 will select the column (which is a vector) within the matrix at index 2
1314 // 0 will select the element at the index 0 of the vector. (which is a float).
1315 std::ostringstream spirv;
1316 spirv << GetHeaderForTestsFromValId() << R"(
1317 %myblock = OpLoad %struct_blockName %blockName_var
1318 %fl = OpCompositeExtract %float %myblock 0 3 1 2 0
1319 %b5 = OpCompositeInsert %struct_blockName %fl %myblock 0 3 1 2 0 1
1320 OpReturn
1321 OpFunctionEnd
1322 )";
1323
1324 CompileSuccessfully(spirv.str());
1325 EXPECT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1326 EXPECT_THAT(getDiagnosticString(),
1327 HasSubstr("Reached non-composite type while indexes still remain "
1328 "to be traversed."));
1329 }
1330
1331 // Invalid. Result type doesn't match the type we get from indexing into
1332 // the composite.
1333 TEST_F(ValidateComposites,
1334 CompositeExtractResultTypeDoesntMatchIndexedTypeBad) {
1335 // indexes that we are passing are: 0, 3, 1, 2, 0
1336 // 0 will select the struct_s within the base struct (blockName)
1337 // 3 will select the Array that contains 5 matrices
1338 // 1 will select the Matrix that is at index 1 of the array
1339 // 2 will select the column (which is a vector) within the matrix at index 2
1340 // 0 will select the element at the index 0 of the vector. (which is a float).
1341 std::ostringstream spirv;
1342 spirv << GetHeaderForTestsFromValId() << R"(
1343 %myblock = OpLoad %struct_blockName %blockName_var
1344 %fl = OpCompositeExtract %int %myblock 0 3 1 2 0
1345 OpReturn
1346 OpFunctionEnd
1347 )";
1348
1349 CompileSuccessfully(spirv.str());
1350 EXPECT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1351 EXPECT_THAT(getDiagnosticString(),
1352 HasSubstr("Result type (OpTypeInt) does not match the type that "
1353 "results from indexing into the composite "
1354 "(OpTypeFloat)."));
1355 }
1356
1357 // Invalid. Given object type doesn't match the type we get from indexing into
1358 // the composite.
1359 TEST_F(ValidateComposites, CompositeInsertObjectTypeDoesntMatchIndexedTypeBad) {
1360 // indexes that we are passing are: 0, 3, 1, 2, 0
1361 // 0 will select the struct_s within the base struct (blockName)
1362 // 3 will select the Array that contains 5 matrices
1363 // 1 will select the Matrix that is at index 1 of the array
1364 // 2 will select the column (which is a vector) within the matrix at index 2
1365 // 0 will select the element at the index 0 of the vector. (which is a float).
1366 // We are trying to insert an integer where we should be inserting a float.
1367 std::ostringstream spirv;
1368 spirv << GetHeaderForTestsFromValId() << R"(
1369 %myblock = OpLoad %struct_blockName %blockName_var
1370 %b5 = OpCompositeInsert %struct_blockName %int_0 %myblock 0 3 1 2 0
1371 OpReturn
1372 OpFunctionEnd
1373 )";
1374
1375 CompileSuccessfully(spirv.str());
1376 EXPECT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1377 EXPECT_THAT(getDiagnosticString(),
1378 HasSubstr("The Object type (OpTypeInt) does not match the type "
1379 "that results from indexing into the Composite "
1380 "(OpTypeFloat)."));
1381 }
1382
1383 // Invalid. Index into a struct is larger than the number of struct members.
1384 TEST_F(ValidateComposites, CompositeExtractStructIndexOutOfBoundBad) {
1385 // struct_blockName has 3 members (index 0,1,2). We'll try to access index 3.
1386 std::ostringstream spirv;
1387 spirv << GetHeaderForTestsFromValId() << R"(
1388 %myblock = OpLoad %struct_blockName %blockName_var
1389 %ss = OpCompositeExtract %struct_s %myblock 3
1390 OpReturn
1391 OpFunctionEnd
1392 )";
1393
1394 CompileSuccessfully(spirv.str());
1395 EXPECT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1396 EXPECT_THAT(getDiagnosticString(),
1397 HasSubstr("Index is out of bounds, can not find index 3 in the "
1398 "structure <id> '25'. This structure has 2 members. "
1399 "Largest valid index is 1."));
1400 }
1401
1402 // Invalid. Index into a struct is larger than the number of struct members.
1403 TEST_F(ValidateComposites, CompositeInsertStructIndexOutOfBoundBad) {
1404 // struct_blockName has 3 members (index 0,1,2). We'll try to access index 3.
1405 std::ostringstream spirv;
1406 spirv << GetHeaderForTestsFromValId() << R"(
1407 %myblock = OpLoad %struct_blockName %blockName_var
1408 %ss = OpCompositeExtract %struct_s %myblock 0
1409 %new_composite = OpCompositeInsert %struct_blockName %ss %myblock 3
1410 OpReturn
1411 OpFunctionEnd
1412 )";
1413
1414 CompileSuccessfully(spirv.str());
1415 EXPECT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1416 EXPECT_THAT(
1417 getDiagnosticString(),
1418 HasSubstr("Index is out of bounds, can not find index 3 in the structure "
1419 "<id> '25'. This structure has 2 members. Largest valid index "
1420 "is 1."));
1421 }
1422
1423 // #1403: Ensure that the default spec constant value is not used to check the
1424 // extract index.
1425 TEST_F(ValidateComposites, ExtractFromSpecConstantSizedArray) {
1426 std::string spirv = R"(
1427 OpCapability Kernel
1428 OpCapability Linkage
1429 OpMemoryModel Logical OpenCL
1430 OpDecorate %spec_const SpecId 1
1431 %void = OpTypeVoid
1432 %uint = OpTypeInt 32 0
1433 %spec_const = OpSpecConstant %uint 3
1434 %uint_array = OpTypeArray %uint %spec_const
1435 %undef = OpUndef %uint_array
1436 %voidf = OpTypeFunction %void
1437 %func = OpFunction %void None %voidf
1438 %1 = OpLabel
1439 %2 = OpCompositeExtract %uint %undef 4
1440 OpReturn
1441 OpFunctionEnd
1442 )";
1443
1444 CompileSuccessfully(spirv);
1445 EXPECT_EQ(SPV_SUCCESS, ValidateInstructions());
1446 }
1447
1448 // #1403: Ensure that spec constant ops do not produce false positives.
1449 TEST_F(ValidateComposites, ExtractFromSpecConstantOpSizedArray) {
1450 std::string spirv = R"(
1451 OpCapability Kernel
1452 OpCapability Linkage
1453 OpMemoryModel Logical OpenCL
1454 OpDecorate %spec_const SpecId 1
1455 %void = OpTypeVoid
1456 %uint = OpTypeInt 32 0
1457 %const = OpConstant %uint 1
1458 %spec_const = OpSpecConstant %uint 3
1459 %spec_const_op = OpSpecConstantOp %uint IAdd %spec_const %const
1460 %uint_array = OpTypeArray %uint %spec_const_op
1461 %undef = OpUndef %uint_array
1462 %voidf = OpTypeFunction %void
1463 %func = OpFunction %void None %voidf
1464 %1 = OpLabel
1465 %2 = OpCompositeExtract %uint %undef 4
1466 OpReturn
1467 OpFunctionEnd
1468 )";
1469
1470 CompileSuccessfully(spirv);
1471 EXPECT_EQ(SPV_SUCCESS, ValidateInstructions());
1472 }
1473
1474 // #1403: Ensure that the default spec constant value is not used to check the
1475 // size of the array for a composite construct. This code has limited actual
1476 // value as it is incorrect unless the specialization constant is assigned the
1477 // value of 2, but it is still a valid module.
1478 TEST_F(ValidateComposites, CompositeConstructSpecConstantSizedArray) {
1479 std::string spirv = R"(
1480 OpCapability Kernel
1481 OpCapability Linkage
1482 OpMemoryModel Logical OpenCL
1483 OpDecorate %spec_const SpecId 1
1484 %void = OpTypeVoid
1485 %uint = OpTypeInt 32 0
1486 %uint_0 = OpConstant %uint 0
1487 %spec_const = OpSpecConstant %uint 3
1488 %uint_array = OpTypeArray %uint %spec_const
1489 %voidf = OpTypeFunction %void
1490 %func = OpFunction %void None %voidf
1491 %1 = OpLabel
1492 %2 = OpCompositeConstruct %uint_array %uint_0 %uint_0
1493 OpReturn
1494 OpFunctionEnd
1495 )";
1496
1497 CompileSuccessfully(spirv);
1498 EXPECT_EQ(SPV_SUCCESS, ValidateInstructions());
1499 }
1500
1501 TEST_F(ValidateComposites, CoopMatConstantCompositeMismatchFail) {
1502 const std::string body = R"(
1503 OpCapability Shader
1504 OpCapability Float16
1505 OpCapability CooperativeMatrixNV
1506 OpExtension "SPV_NV_cooperative_matrix"
1507 OpMemoryModel Logical GLSL450
1508 OpEntryPoint GLCompute %main "main"
1509 %void = OpTypeVoid
1510 %func = OpTypeFunction %void
1511 %bool = OpTypeBool
1512 %f16 = OpTypeFloat 16
1513 %f32 = OpTypeFloat 32
1514 %u32 = OpTypeInt 32 0
1515
1516 %u32_8 = OpConstant %u32 8
1517 %subgroup = OpConstant %u32 3
1518
1519 %f16mat = OpTypeCooperativeMatrixNV %f16 %subgroup %u32_8 %u32_8
1520
1521 %f32_1 = OpConstant %f32 1
1522
1523 %f16mat_1 = OpConstantComposite %f16mat %f32_1
1524
1525 %main = OpFunction %void None %func
1526 %main_entry = OpLabel
1527
1528 OpReturn
1529 OpFunctionEnd)";
1530
1531 CompileSuccessfully(body.c_str());
1532 ASSERT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions());
1533 EXPECT_THAT(
1534 getDiagnosticString(),
1535 HasSubstr("OpConstantComposite Constituent <id> '11[%float_1]' type does "
1536 "not match the Result Type <id> '10[%10]'s component type."));
1537 }
1538
1539 TEST_F(ValidateComposites, CoopMatCompositeConstructMismatchFail) {
1540 const std::string body = R"(
1541 OpCapability Shader
1542 OpCapability Float16
1543 OpCapability CooperativeMatrixNV
1544 OpExtension "SPV_NV_cooperative_matrix"
1545 OpMemoryModel Logical GLSL450
1546 OpEntryPoint GLCompute %main "main"
1547 %void = OpTypeVoid
1548 %func = OpTypeFunction %void
1549 %bool = OpTypeBool
1550 %f16 = OpTypeFloat 16
1551 %f32 = OpTypeFloat 32
1552 %u32 = OpTypeInt 32 0
1553
1554 %u32_8 = OpConstant %u32 8
1555 %subgroup = OpConstant %u32 3
1556
1557 %f16mat = OpTypeCooperativeMatrixNV %f16 %subgroup %u32_8 %u32_8
1558
1559 %f32_1 = OpConstant %f32 1
1560
1561 %main = OpFunction %void None %func
1562 %main_entry = OpLabel
1563
1564 %f16mat_1 = OpCompositeConstruct %f16mat %f32_1
1565
1566 OpReturn
1567 OpFunctionEnd)";
1568
1569 CompileSuccessfully(body.c_str());
1570 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1571 EXPECT_THAT(
1572 getDiagnosticString(),
1573 HasSubstr("Expected Constituent type to be equal to the component type"));
1574 }
1575
1576 TEST_F(ValidateComposites, CoopMatKHRConstantCompositeMismatchFail) {
1577 const std::string body = R"(
1578 OpCapability Shader
1579 OpCapability Float16
1580 OpCapability CooperativeMatrixKHR
1581 OpCapability VulkanMemoryModelKHR
1582 OpExtension "SPV_KHR_cooperative_matrix"
1583 OpExtension "SPV_KHR_vulkan_memory_model"
1584 OpMemoryModel Logical VulkanKHR
1585 OpEntryPoint GLCompute %main "main"
1586 %void = OpTypeVoid
1587 %func = OpTypeFunction %void
1588 %bool = OpTypeBool
1589 %f16 = OpTypeFloat 16
1590 %f32 = OpTypeFloat 32
1591 %u32 = OpTypeInt 32 0
1592
1593 %u32_16 = OpConstant %u32 16
1594 %useA = OpConstant %u32 0
1595 %subgroup = OpConstant %u32 3
1596
1597 %f16mat = OpTypeCooperativeMatrixKHR %f16 %subgroup %u32_16 %u32_16 %useA
1598
1599 %f32_1 = OpConstant %f32 1
1600
1601 %f16mat_1 = OpConstantComposite %f16mat %f32_1
1602
1603 %main = OpFunction %void None %func
1604 %main_entry = OpLabel
1605
1606 OpReturn
1607 OpFunctionEnd)";
1608
1609 CompileSuccessfully(body.c_str(), SPV_ENV_UNIVERSAL_1_3);
1610 ASSERT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions(SPV_ENV_UNIVERSAL_1_3));
1611 EXPECT_THAT(
1612 getDiagnosticString(),
1613 HasSubstr(
1614 "OpConstantComposite Constituent <id> '12[%float_1]' type "
1615 "does not match the Result Type <id> '11[%11]'s component type."));
1616 }
1617
1618 TEST_F(ValidateComposites, CoopMatKHRCompositeConstructMismatchFail) {
1619 const std::string body = R"(
1620 OpCapability Shader
1621 OpCapability Float16
1622 OpCapability CooperativeMatrixKHR
1623 OpCapability VulkanMemoryModelKHR
1624 OpExtension "SPV_KHR_cooperative_matrix"
1625 OpExtension "SPV_KHR_vulkan_memory_model"
1626 OpMemoryModel Logical VulkanKHR
1627 OpEntryPoint GLCompute %main "main"
1628 %void = OpTypeVoid
1629 %func = OpTypeFunction %void
1630 %bool = OpTypeBool
1631 %f16 = OpTypeFloat 16
1632 %f32 = OpTypeFloat 32
1633 %u32 = OpTypeInt 32 0
1634
1635 %u32_16 = OpConstant %u32 16
1636 %useA = OpConstant %u32 0
1637 %subgroup = OpConstant %u32 3
1638
1639 %f16mat = OpTypeCooperativeMatrixKHR %f16 %subgroup %u32_16 %u32_16 %useA
1640
1641 %f32_1 = OpConstant %f32 1
1642
1643 %main = OpFunction %void None %func
1644 %main_entry = OpLabel
1645
1646 %f16mat_1 = OpCompositeConstruct %f16mat %f32_1
1647
1648 OpReturn
1649 OpFunctionEnd)";
1650
1651 CompileSuccessfully(body.c_str(), SPV_ENV_UNIVERSAL_1_3);
1652 ASSERT_EQ(SPV_ERROR_INVALID_DATA,
1653 ValidateInstructions(SPV_ENV_UNIVERSAL_1_3));
1654 EXPECT_THAT(
1655 getDiagnosticString(),
1656 HasSubstr("Expected Constituent type to be equal to the component type"));
1657 }
1658
1659 TEST_F(ValidateComposites, ExtractDynamicLabelIndex) {
1660 const std::string spirv = R"(
1661 OpCapability Shader
1662 OpCapability Linkage
1663 OpMemoryModel Logical GLSL450
1664 %void = OpTypeVoid
1665 %float = OpTypeFloat 32
1666 %v4float = OpTypeVector %float 4
1667 %void_fn = OpTypeFunction %void
1668 %float_0 = OpConstant %float 0
1669 %v4float_0 = OpConstantComposite %v4float %float_0 %float_0 %float_0 %float_0
1670 %func = OpFunction %void None %void_fn
1671 %1 = OpLabel
1672 %ex = OpVectorExtractDynamic %float %v4float_0 %v4float_0
1673 OpReturn
1674 OpFunctionEnd
1675 )";
1676
1677 CompileSuccessfully(spirv);
1678 EXPECT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1679 EXPECT_THAT(getDiagnosticString(),
1680 HasSubstr("Expected Index to be int scalar"));
1681 }
1682
1683 TEST_F(ValidateComposites, CopyLogicalSameType) {
1684 const std::string spirv = R"(
1685 OpCapability Shader
1686 OpCapability Linkage
1687 OpMemoryModel Logical GLSL450
1688 %void = OpTypeVoid
1689 %struct = OpTypeStruct
1690 %const_struct = OpConstantComposite %struct
1691 %void_fn = OpTypeFunction %void
1692 %func = OpFunction %void None %void_fn
1693 %1 = OpLabel
1694 %copy = OpCopyLogical %struct %const_struct
1695 OpReturn
1696 OpFunctionEnd
1697 )";
1698
1699 CompileSuccessfully(spirv, SPV_ENV_UNIVERSAL_1_4);
1700 EXPECT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions(SPV_ENV_UNIVERSAL_1_4));
1701 EXPECT_THAT(getDiagnosticString(),
1702 HasSubstr("Result Type must not equal the Operand type"));
1703 }
1704
1705 TEST_F(ValidateComposites, CopyLogicalSameStructDifferentId) {
1706 const std::string spirv = R"(
1707 OpCapability Shader
1708 OpCapability Linkage
1709 OpMemoryModel Logical GLSL450
1710 %void = OpTypeVoid
1711 %struct1 = OpTypeStruct
1712 %struct2 = OpTypeStruct
1713 %const_struct = OpConstantComposite %struct1
1714 %void_fn = OpTypeFunction %void
1715 %func = OpFunction %void None %void_fn
1716 %1 = OpLabel
1717 %copy = OpCopyLogical %struct2 %const_struct
1718 OpReturn
1719 OpFunctionEnd
1720 )";
1721
1722 CompileSuccessfully(spirv, SPV_ENV_UNIVERSAL_1_4);
1723 EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_UNIVERSAL_1_4));
1724 }
1725
1726 TEST_F(ValidateComposites, CopyLogicalArrayDifferentLength) {
1727 const std::string spirv = R"(
1728 OpCapability Shader
1729 OpCapability Linkage
1730 OpMemoryModel Logical GLSL450
1731 %void = OpTypeVoid
1732 %int = OpTypeInt 32 0
1733 %int_4 = OpConstant %int 4
1734 %int_5 = OpConstant %int 5
1735 %array1 = OpTypeArray %int %int_4
1736 %array2 = OpTypeArray %int %int_5
1737 %const_array = OpConstantComposite %array1 %int_4 %int_4 %int_4 %int_4
1738 %void_fn = OpTypeFunction %void
1739 %func = OpFunction %void None %void_fn
1740 %1 = OpLabel
1741 %copy = OpCopyLogical %array2 %const_array
1742 OpReturn
1743 OpFunctionEnd
1744 )";
1745
1746 CompileSuccessfully(spirv, SPV_ENV_UNIVERSAL_1_4);
1747 EXPECT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions(SPV_ENV_UNIVERSAL_1_4));
1748 EXPECT_THAT(
1749 getDiagnosticString(),
1750 HasSubstr("Result Type does not logically match the Operand type"));
1751 }
1752
1753 TEST_F(ValidateComposites, CopyLogicalArrayDifferentElement) {
1754 const std::string spirv = R"(
1755 OpCapability Shader
1756 OpCapability Linkage
1757 OpMemoryModel Logical GLSL450
1758 %void = OpTypeVoid
1759 %float = OpTypeFloat 32
1760 %int = OpTypeInt 32 0
1761 %int_4 = OpConstant %int 4
1762 %array1 = OpTypeArray %int %int_4
1763 %array2 = OpTypeArray %float %int_4
1764 %const_array = OpConstantComposite %array1 %int_4 %int_4 %int_4 %int_4
1765 %void_fn = OpTypeFunction %void
1766 %func = OpFunction %void None %void_fn
1767 %1 = OpLabel
1768 %copy = OpCopyLogical %array2 %const_array
1769 OpReturn
1770 OpFunctionEnd
1771 )";
1772
1773 CompileSuccessfully(spirv, SPV_ENV_UNIVERSAL_1_4);
1774 EXPECT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions(SPV_ENV_UNIVERSAL_1_4));
1775 EXPECT_THAT(
1776 getDiagnosticString(),
1777 HasSubstr("Result Type does not logically match the Operand type"));
1778 }
1779
1780 TEST_F(ValidateComposites, CopyLogicalArrayLogicallyMatchedElement) {
1781 const std::string spirv = R"(
1782 OpCapability Shader
1783 OpCapability Linkage
1784 OpMemoryModel Logical GLSL450
1785 %void = OpTypeVoid
1786 %float = OpTypeFloat 32
1787 %int = OpTypeInt 32 0
1788 %int_1 = OpConstant %int 1
1789 %inner1 = OpTypeArray %int %int_1
1790 %inner2 = OpTypeArray %int %int_1
1791 %array1 = OpTypeArray %inner1 %int_1
1792 %array2 = OpTypeArray %inner2 %int_1
1793 %const_inner = OpConstantComposite %inner1 %int_1
1794 %const_array = OpConstantComposite %array1 %const_inner
1795 %void_fn = OpTypeFunction %void
1796 %func = OpFunction %void None %void_fn
1797 %1 = OpLabel
1798 %copy = OpCopyLogical %array2 %const_array
1799 OpReturn
1800 OpFunctionEnd
1801 )";
1802
1803 CompileSuccessfully(spirv, SPV_ENV_UNIVERSAL_1_4);
1804 EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_UNIVERSAL_1_4));
1805 }
1806
1807 TEST_F(ValidateComposites, CopyLogicalStructDifferentNumberElements) {
1808 const std::string spirv = R"(
1809 OpCapability Shader
1810 OpCapability Linkage
1811 OpMemoryModel Logical GLSL450
1812 %void = OpTypeVoid
1813 %int = OpTypeInt 32 0
1814 %struct1 = OpTypeStruct
1815 %struct2 = OpTypeStruct %int
1816 %const_struct = OpConstantComposite %struct1
1817 %void_fn = OpTypeFunction %void
1818 %func = OpFunction %void None %void_fn
1819 %1 = OpLabel
1820 %copy = OpCopyLogical %struct2 %const_struct
1821 OpReturn
1822 OpFunctionEnd
1823 )";
1824
1825 CompileSuccessfully(spirv, SPV_ENV_UNIVERSAL_1_4);
1826 EXPECT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions(SPV_ENV_UNIVERSAL_1_4));
1827 EXPECT_THAT(
1828 getDiagnosticString(),
1829 HasSubstr("Result Type does not logically match the Operand type"));
1830 }
1831
1832 TEST_F(ValidateComposites, CopyLogicalStructDifferentElement) {
1833 const std::string spirv = R"(
1834 OpCapability Shader
1835 OpCapability Linkage
1836 OpMemoryModel Logical GLSL450
1837 %void = OpTypeVoid
1838 %uint = OpTypeInt 32 0
1839 %int = OpTypeInt 32 1
1840 %int_0 = OpConstant %int 0
1841 %uint_0 = OpConstant %uint 0
1842 %struct1 = OpTypeStruct %int %uint
1843 %struct2 = OpTypeStruct %int %int
1844 %const_struct = OpConstantComposite %struct1 %int_0 %uint_0
1845 %void_fn = OpTypeFunction %void
1846 %func = OpFunction %void None %void_fn
1847 %1 = OpLabel
1848 %copy = OpCopyLogical %struct2 %const_struct
1849 OpReturn
1850 OpFunctionEnd
1851 )";
1852
1853 CompileSuccessfully(spirv, SPV_ENV_UNIVERSAL_1_4);
1854 EXPECT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions(SPV_ENV_UNIVERSAL_1_4));
1855 EXPECT_THAT(
1856 getDiagnosticString(),
1857 HasSubstr("Result Type does not logically match the Operand type"));
1858 }
1859
1860 TEST_F(ValidateComposites, CopyLogicalStructLogicallyMatch) {
1861 const std::string spirv = R"(
1862 OpCapability Shader
1863 OpCapability Linkage
1864 OpMemoryModel Logical GLSL450
1865 %void = OpTypeVoid
1866 %int = OpTypeInt 32 0
1867 %int_1 = OpConstant %int 1
1868 %array1 = OpTypeArray %int %int_1
1869 %array2 = OpTypeArray %int %int_1
1870 %struct1 = OpTypeStruct %int %array1
1871 %struct2 = OpTypeStruct %int %array2
1872 %const_array = OpConstantComposite %array1 %int_1
1873 %const_struct = OpConstantComposite %struct1 %int_1 %const_array
1874 %void_fn = OpTypeFunction %void
1875 %func = OpFunction %void None %void_fn
1876 %1 = OpLabel
1877 %copy = OpCopyLogical %struct2 %const_struct
1878 OpReturn
1879 OpFunctionEnd
1880 )";
1881
1882 CompileSuccessfully(spirv, SPV_ENV_UNIVERSAL_1_4);
1883 EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_UNIVERSAL_1_4));
1884 }
1885
1886 using ValidateSmallComposites = spvtest::ValidateBase<std::string>;
1887
1888 CodeGenerator GetSmallCompositesCodeGenerator() {
1889 CodeGenerator generator;
1890 generator.capabilities_ = R"(
1891 OpCapability Shader
1892 OpCapability Linkage
1893 OpCapability UniformAndStorageBuffer16BitAccess
1894 OpCapability UniformAndStorageBuffer8BitAccess
1895 )";
1896 generator.extensions_ = R"(
1897 OpExtension "SPV_KHR_16bit_storage"
1898 OpExtension "SPV_KHR_8bit_storage"
1899 )";
1900 generator.memory_model_ = "OpMemoryModel Logical GLSL450\n";
1901 generator.before_types_ = R"(
1902 OpDecorate %char_block Block
1903 OpMemberDecorate %char_block 0 Offset 0
1904 OpDecorate %short_block Block
1905 OpMemberDecorate %short_block 0 Offset 0
1906 OpDecorate %half_block Block
1907 OpMemberDecorate %half_block 0 Offset 0
1908 )";
1909 generator.types_ = R"(
1910 %void = OpTypeVoid
1911 %int = OpTypeInt 32 0
1912 %int_0 = OpConstant %int 0
1913 %int_1 = OpConstant %int 1
1914 %char = OpTypeInt 8 0
1915 %char2 = OpTypeVector %char 2
1916 %short = OpTypeInt 16 0
1917 %short2 = OpTypeVector %short 2
1918 %half = OpTypeFloat 16
1919 %half2 = OpTypeVector %half 2
1920 %char_block = OpTypeStruct %char2
1921 %short_block = OpTypeStruct %short2
1922 %half_block = OpTypeStruct %half2
1923 %ptr_ssbo_char_block = OpTypePointer StorageBuffer %char_block
1924 %ptr_ssbo_char2 = OpTypePointer StorageBuffer %char2
1925 %ptr_ssbo_char = OpTypePointer StorageBuffer %char
1926 %ptr_ssbo_short_block = OpTypePointer StorageBuffer %short_block
1927 %ptr_ssbo_short2 = OpTypePointer StorageBuffer %short2
1928 %ptr_ssbo_short = OpTypePointer StorageBuffer %short
1929 %ptr_ssbo_half_block = OpTypePointer StorageBuffer %half_block
1930 %ptr_ssbo_half2 = OpTypePointer StorageBuffer %half2
1931 %ptr_ssbo_half = OpTypePointer StorageBuffer %half
1932 %void_fn = OpTypeFunction %void
1933 %char_var = OpVariable %ptr_ssbo_char_block StorageBuffer
1934 %short_var = OpVariable %ptr_ssbo_short_block StorageBuffer
1935 %half_var = OpVariable %ptr_ssbo_half_block StorageBuffer
1936 )";
1937 generator.after_types_ = R"(
1938 %func = OpFunction %void None %void_fn
1939 %entry = OpLabel
1940 %char2_gep = OpAccessChain %ptr_ssbo_char2 %char_var %int_0
1941 %ld_char2 = OpLoad %char2 %char2_gep
1942 %char_gep = OpAccessChain %ptr_ssbo_char %char_var %int_0 %int_0
1943 %ld_char = OpLoad %char %char_gep
1944 %short2_gep = OpAccessChain %ptr_ssbo_short2 %short_var %int_0
1945 %ld_short2 = OpLoad %short2 %short2_gep
1946 %short_gep = OpAccessChain %ptr_ssbo_short %short_var %int_0 %int_0
1947 %ld_short = OpLoad %short %short_gep
1948 %half2_gep = OpAccessChain %ptr_ssbo_half2 %half_var %int_0
1949 %ld_half2 = OpLoad %half2 %half2_gep
1950 %half_gep = OpAccessChain %ptr_ssbo_half %half_var %int_0 %int_0
1951 %ld_half = OpLoad %half %half_gep
1952 )";
1953 generator.add_at_the_end_ = R"(
1954 OpReturn
1955 OpFunctionEnd
1956 )";
1957 return generator;
1958 }
1959
1960 TEST_P(ValidateSmallComposites, VectorExtractDynamic) {
1961 std::string type = GetParam();
1962 CodeGenerator generator = GetSmallCompositesCodeGenerator();
1963 std::string inst =
1964 "%inst = OpVectorExtractDynamic %" + type + " %ld_" + type + "2 %int_0\n";
1965 generator.after_types_ += inst;
1966 CompileSuccessfully(generator.Build(), SPV_ENV_UNIVERSAL_1_3);
1967 EXPECT_EQ(SPV_ERROR_INVALID_DATA,
1968 ValidateInstructions(SPV_ENV_UNIVERSAL_1_3));
1969 EXPECT_THAT(getDiagnosticString(),
1970 HasSubstr("Cannot extract from a vector of 8- or 16-bit types"));
1971 }
1972
1973 TEST_P(ValidateSmallComposites, VectorInsertDynamic) {
1974 std::string type = GetParam();
1975 CodeGenerator generator = GetSmallCompositesCodeGenerator();
1976 std::string inst = "%inst = OpVectorInsertDynamic %" + type + "2 %ld_" +
1977 type + "2 %ld_" + type + " %int_0\n";
1978 generator.after_types_ += inst;
1979 CompileSuccessfully(generator.Build(), SPV_ENV_UNIVERSAL_1_3);
1980 EXPECT_EQ(SPV_ERROR_INVALID_DATA,
1981 ValidateInstructions(SPV_ENV_UNIVERSAL_1_3));
1982 EXPECT_THAT(getDiagnosticString(),
1983 HasSubstr("Cannot insert into a vector of 8- or 16-bit types"));
1984 }
1985
1986 TEST_P(ValidateSmallComposites, VectorShuffle) {
1987 std::string type = GetParam();
1988 CodeGenerator generator = GetSmallCompositesCodeGenerator();
1989 std::string inst = "%inst = OpVectorShuffle %" + type + "2 %ld_" + type +
1990 "2 %ld_" + type + "2 0 0\n";
1991 generator.after_types_ += inst;
1992 CompileSuccessfully(generator.Build(), SPV_ENV_UNIVERSAL_1_3);
1993 EXPECT_EQ(SPV_ERROR_INVALID_DATA,
1994 ValidateInstructions(SPV_ENV_UNIVERSAL_1_3));
1995 EXPECT_THAT(getDiagnosticString(),
1996 HasSubstr("Cannot shuffle a vector of 8- or 16-bit types"));
1997 }
1998
1999 TEST_P(ValidateSmallComposites, CompositeConstruct) {
2000 std::string type = GetParam();
2001 CodeGenerator generator = GetSmallCompositesCodeGenerator();
2002 std::string inst = "%inst = OpCompositeConstruct %" + type + "2 %ld_" + type +
2003 " %ld_" + type + "\n";
2004 generator.after_types_ += inst;
2005 CompileSuccessfully(generator.Build(), SPV_ENV_UNIVERSAL_1_3);
2006 EXPECT_EQ(SPV_ERROR_INVALID_DATA,
2007 ValidateInstructions(SPV_ENV_UNIVERSAL_1_3));
2008 EXPECT_THAT(
2009 getDiagnosticString(),
2010 HasSubstr("Cannot create a composite containing 8- or 16-bit types"));
2011 }
2012
2013 TEST_P(ValidateSmallComposites, CompositeExtract) {
2014 std::string type = GetParam();
2015 CodeGenerator generator = GetSmallCompositesCodeGenerator();
2016 std::string inst =
2017 "%inst = OpCompositeExtract %" + type + " %ld_" + type + "2 0\n";
2018 generator.after_types_ += inst;
2019 CompileSuccessfully(generator.Build(), SPV_ENV_UNIVERSAL_1_3);
2020 EXPECT_EQ(SPV_ERROR_INVALID_DATA,
2021 ValidateInstructions(SPV_ENV_UNIVERSAL_1_3));
2022 EXPECT_THAT(
2023 getDiagnosticString(),
2024 HasSubstr("Cannot extract from a composite of 8- or 16-bit types"));
2025 }
2026
2027 TEST_P(ValidateSmallComposites, CompositeInsert) {
2028 std::string type = GetParam();
2029 CodeGenerator generator = GetSmallCompositesCodeGenerator();
2030 std::string inst = "%inst = OpCompositeInsert %" + type + "2 %ld_" + type +
2031 " %ld_" + type + "2 0\n";
2032 generator.after_types_ += inst;
2033 CompileSuccessfully(generator.Build(), SPV_ENV_UNIVERSAL_1_3);
2034 EXPECT_EQ(SPV_ERROR_INVALID_DATA,
2035 ValidateInstructions(SPV_ENV_UNIVERSAL_1_3));
2036 EXPECT_THAT(
2037 getDiagnosticString(),
2038 HasSubstr("Cannot insert into a composite of 8- or 16-bit types"));
2039 }
2040
2041 TEST_P(ValidateSmallComposites, CopyObject) {
2042 std::string type = GetParam();
2043 CodeGenerator generator = GetSmallCompositesCodeGenerator();
2044 std::string inst = "%inst = OpCopyObject %" + type + "2 %ld_" + type + "2\n";
2045 generator.after_types_ += inst;
2046 CompileSuccessfully(generator.Build(), SPV_ENV_UNIVERSAL_1_3);
2047 EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_UNIVERSAL_1_3));
2048 }
2049
2050 INSTANTIATE_TEST_SUITE_P(SmallCompositeInstructions, ValidateSmallComposites,
2051 Values("char", "short", "half"));
2052
2053 TEST_F(ValidateComposites, HalfMatrixCannotTranspose) {
2054 const std::string spirv = R"(
2055 OpCapability Shader
2056 OpCapability Linkage
2057 OpCapability UniformAndStorageBuffer16BitAccess
2058 OpExtension "SPV_KHR_16bit_storage"
2059 OpMemoryModel Logical GLSL450
2060 OpDecorate %block Block
2061 OpMemberDecorate %block 0 Offset 0
2062 OpMemberDecorate %block 0 RowMajor
2063 OpMemberDecorate %block 0 MatrixStride 8
2064 %void = OpTypeVoid
2065 %int = OpTypeInt 32 0
2066 %int_0 = OpConstant %int 0
2067 %float = OpTypeFloat 16
2068 %float2 = OpTypeVector %float 2
2069 %mat2x2 = OpTypeMatrix %float2 2
2070 %block = OpTypeStruct %mat2x2
2071 %ptr_ssbo_block = OpTypePointer StorageBuffer %block
2072 %ptr_ssbo_mat2x2 = OpTypePointer StorageBuffer %mat2x2
2073 %var = OpVariable %ptr_ssbo_block StorageBuffer
2074 %void_fn = OpTypeFunction %void
2075 %func = OpFunction %void None %void_fn
2076 %entry = OpLabel
2077 %gep = OpAccessChain %ptr_ssbo_mat2x2 %var %int_0
2078 %ld = OpLoad %mat2x2 %gep
2079 %inst = OpTranspose %mat2x2 %ld
2080 OpReturn
2081 OpFunctionEnd
2082 )";
2083
2084 CompileSuccessfully(spirv, SPV_ENV_UNIVERSAL_1_3);
2085 EXPECT_EQ(SPV_ERROR_INVALID_DATA,
2086 ValidateInstructions(SPV_ENV_UNIVERSAL_1_3));
2087 EXPECT_THAT(getDiagnosticString(),
2088 HasSubstr("Cannot transpose matrices of 16-bit floats"));
2089 }
2090
2091 TEST_F(ValidateComposites, CopyObjectVoid) {
2092 const std::string spirv = R"(
2093 OpCapability Shader
2094 %1 = OpExtInstImport "GLSL.std.450"
2095 OpMemoryModel Logical GLSL450
2096 OpEntryPoint Fragment %4 "main"
2097 OpExecutionMode %4 OriginUpperLeft
2098 OpSource ESSL 320
2099 OpName %4 "main"
2100 OpName %6 "foo("
2101 %2 = OpTypeVoid
2102 %3 = OpTypeFunction %2
2103 %4 = OpFunction %2 None %3
2104 %5 = OpLabel
2105 %8 = OpFunctionCall %2 %6
2106 %20 = OpCopyObject %2 %8
2107 OpReturn
2108 OpFunctionEnd
2109 %6 = OpFunction %2 None %3
2110 %7 = OpLabel
2111 OpReturn
2112 OpFunctionEnd
2113 )";
2114
2115 CompileSuccessfully(spirv);
2116 EXPECT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
2117 EXPECT_THAT(getDiagnosticString(),
2118 HasSubstr("OpCopyObject cannot have void result type"));
2119 }
2120
2121 TEST_F(ValidateComposites, CoopVecConstantCompositePass) {
2122 const std::string body = R"(
2123 OpCapability Shader
2124 OpCapability Float16
2125 OpCapability CooperativeVectorNV
2126 OpExtension "SPV_NV_cooperative_vector"
2127 OpMemoryModel Logical GLSL450
2128 OpEntryPoint GLCompute %main "main"
2129 %void = OpTypeVoid
2130 %func = OpTypeFunction %void
2131 %bool = OpTypeBool
2132 %f16 = OpTypeFloat 16
2133 %f32 = OpTypeFloat 32
2134 %u32 = OpTypeInt 32 0
2135
2136 %u32_16 = OpConstant %u32 16
2137 %useA = OpConstant %u32 0
2138 %subgroup = OpConstant %u32 3
2139
2140 %f16vec = OpTypeCooperativeVectorNV %f16 %u32_16
2141
2142 %f16_1 = OpConstant %f16 1
2143
2144 %f16vec_1 = OpConstantComposite %f16vec %f16_1 %f16_1 %f16_1 %f16_1 %f16_1 %f16_1 %f16_1 %f16_1 %f16_1 %f16_1 %f16_1 %f16_1 %f16_1 %f16_1 %f16_1 %f16_1
2145
2146 %main = OpFunction %void None %func
2147 %main_entry = OpLabel
2148
2149 OpReturn
2150 OpFunctionEnd)";
2151
2152 CompileSuccessfully(body.c_str());
2153 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
2154 }
2155
2156 TEST_F(ValidateComposites, CoopVecConstantCompositeMismatchFail) {
2157 const std::string body = R"(
2158 OpCapability Shader
2159 OpCapability Float16
2160 OpCapability CooperativeVectorNV
2161 OpExtension "SPV_NV_cooperative_vector"
2162 OpMemoryModel Logical GLSL450
2163 OpEntryPoint GLCompute %main "main"
2164 %void = OpTypeVoid
2165 %func = OpTypeFunction %void
2166 %bool = OpTypeBool
2167 %f16 = OpTypeFloat 16
2168 %f32 = OpTypeFloat 32
2169 %u32 = OpTypeInt 32 0
2170
2171 %u32_16 = OpConstant %u32 16
2172 %useA = OpConstant %u32 0
2173 %subgroup = OpConstant %u32 3
2174
2175 %f16vec = OpTypeCooperativeVectorNV %f16 %u32_16
2176
2177 %f32_1 = OpConstant %f32 1
2178
2179 %f16vec_1 = OpConstantComposite %f16vec %f32_1
2180
2181 %main = OpFunction %void None %func
2182 %main_entry = OpLabel
2183
2184 OpReturn
2185 OpFunctionEnd)";
2186
2187 CompileSuccessfully(body.c_str());
2188 ASSERT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions());
2189 EXPECT_THAT(
2190 getDiagnosticString(),
2191 HasSubstr("OpConstantComposite Constituent <id> count does not match "
2192 "Result Type <id> '11[%11]'s vector component count"));
2193 }
2194
2195 TEST_F(ValidateComposites, CoopVecCompositeConstructPass) {
2196 const std::string body = R"(
2197 OpCapability Shader
2198 OpCapability Float16
2199 OpCapability CooperativeVectorNV
2200 OpExtension "SPV_NV_cooperative_vector"
2201 OpMemoryModel Logical GLSL450
2202 OpEntryPoint GLCompute %main "main"
2203 %void = OpTypeVoid
2204 %func = OpTypeFunction %void
2205 %bool = OpTypeBool
2206 %f16 = OpTypeFloat 16
2207 %f32 = OpTypeFloat 32
2208 %u32 = OpTypeInt 32 0
2209
2210 %u32_16 = OpConstant %u32 16
2211 %useA = OpConstant %u32 0
2212 %subgroup = OpConstant %u32 3
2213
2214 %f16vec = OpTypeCooperativeVectorNV %f16 %u32_16
2215
2216 %f16_1 = OpConstant %f16 1
2217
2218 %main = OpFunction %void None %func
2219 %main_entry = OpLabel
2220
2221 %f16vec_1 = OpCompositeConstruct %f16vec %f16_1 %f16_1 %f16_1 %f16_1 %f16_1 %f16_1 %f16_1 %f16_1 %f16_1 %f16_1 %f16_1 %f16_1 %f16_1 %f16_1 %f16_1 %f16_1
2222
2223 OpReturn
2224 OpFunctionEnd)";
2225
2226 CompileSuccessfully(body.c_str());
2227 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
2228 }
2229
2230 TEST_F(ValidateComposites, CoopVecCompositeConstructMismatchFail) {
2231 const std::string body = R"(
2232 OpCapability Shader
2233 OpCapability Float16
2234 OpCapability CooperativeVectorNV
2235 OpExtension "SPV_NV_cooperative_vector"
2236 OpMemoryModel Logical GLSL450
2237 OpEntryPoint GLCompute %main "main"
2238 %void = OpTypeVoid
2239 %func = OpTypeFunction %void
2240 %bool = OpTypeBool
2241 %f16 = OpTypeFloat 16
2242 %f32 = OpTypeFloat 32
2243 %u32 = OpTypeInt 32 0
2244
2245 %u32_16 = OpConstant %u32 16
2246 %useA = OpConstant %u32 0
2247 %subgroup = OpConstant %u32 3
2248
2249 %f16vec = OpTypeCooperativeVectorNV %f16 %u32_16
2250
2251 %f32_1 = OpConstant %f32 1
2252
2253 %main = OpFunction %void None %func
2254 %main_entry = OpLabel
2255
2256 %f16vec_1 = OpCompositeConstruct %f16vec %f32_1
2257
2258 OpReturn
2259 OpFunctionEnd)";
2260
2261 CompileSuccessfully(body.c_str());
2262 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
2263 EXPECT_THAT(getDiagnosticString(),
2264 HasSubstr("Expected Constituents to be scalars or vectors of the "
2265 "same type as Result Type components"));
2266 }
2267
2268 TEST_F(ValidateComposites, CoopVecInsertExtractDynamicPass) {
2269 const std::string body = R"(
2270 OpCapability Shader
2271 OpCapability Float16
2272 OpCapability CooperativeVectorNV
2273 OpExtension "SPV_NV_cooperative_vector"
2274 OpMemoryModel Logical GLSL450
2275 OpEntryPoint GLCompute %main "main"
2276 %void = OpTypeVoid
2277 %func = OpTypeFunction %void
2278 %bool = OpTypeBool
2279 %f16 = OpTypeFloat 16
2280 %f32 = OpTypeFloat 32
2281 %u32 = OpTypeInt 32 0
2282
2283 %u32_1 = OpConstant %u32 1
2284 %u32_16 = OpConstant %u32 16
2285 %useA = OpConstant %u32 0
2286 %subgroup = OpConstant %u32 3
2287
2288 %f16vec = OpTypeCooperativeVectorNV %f16 %u32_16
2289
2290 %f16_1 = OpConstant %f16 1
2291 %f16vec_1 = OpConstantComposite %f16vec %f16_1 %f16_1 %f16_1 %f16_1 %f16_1 %f16_1 %f16_1 %f16_1 %f16_1 %f16_1 %f16_1 %f16_1 %f16_1 %f16_1 %f16_1 %f16_1
2292
2293 %main = OpFunction %void None %func
2294 %main_entry = OpLabel
2295
2296 %insert = OpVectorInsertDynamic %f16vec %f16vec_1 %f16_1 %u32_1
2297 %extract = OpVectorExtractDynamic %f16 %insert %u32_1
2298
2299 OpReturn
2300 OpFunctionEnd)";
2301
2302 CompileSuccessfully(body.c_str());
2303 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
2304 }
2305
2306 TEST_F(ValidateComposites, CoopMatVecConvBitCastArrayQCOM1) {
2307 const std::string body = R"(
2308 OpCapability Shader
2309 OpCapability Float16
2310 OpCapability Int8
2311 OpCapability CooperativeMatrixKHR
2312 OpCapability VulkanMemoryModelKHR
2313 OpCapability CooperativeMatrixConversionQCOM
2314 OpExtension "SPV_KHR_cooperative_matrix"
2315 OpExtension "SPV_KHR_vulkan_memory_model"
2316 OpExtension "SPV_QCOM_cooperative_matrix_conversion"
2317 OpMemoryModel Logical VulkanKHR
2318 OpEntryPoint GLCompute %main "main"
2319 %void = OpTypeVoid
2320 %3 = OpTypeFunction %void
2321 %u8int = OpTypeInt 8 0
2322 %uint = OpTypeInt 32 0
2323 %half = OpTypeFloat 16
2324 %uint_8 = OpConstant %uint 8
2325 %uint_16 = OpConstant %uint 16
2326 %_arr_u8int_uint_8 = OpTypeArray %u8int %uint_8
2327 %_arr_half_uint_16 = OpTypeArray %half %uint_16
2328 %_ptr_Function__arr_half_uint_16 = OpTypePointer Function %_arr_half_uint_16
2329 %main = OpFunction %void None %3
2330 %5 = OpLabel
2331 %hvec8A = OpVariable %_ptr_Function__arr_half_uint_16 Function
2332 %16 = OpLoad %_arr_half_uint_16 %hvec8A
2333 %18 = OpBitCastArrayQCOM %_arr_u8int_uint_8 %16
2334 OpReturn
2335 OpFunctionEnd)";
2336
2337 CompileSuccessfully(body.c_str(), SPV_ENV_UNIVERSAL_1_3);
2338 ASSERT_EQ(SPV_ERROR_INVALID_DATA,
2339 ValidateInstructions(SPV_ENV_UNIVERSAL_1_3));
2340 EXPECT_THAT(getDiagnosticString(),
2341 HasSubstr("Opcode BitCastArrayQCOM requires the result element "
2342 "type be one of 32-bit OpTypeInt (signed/unsigned), "
2343 "32-bit OpTypeFloat and 16-bit OpTypeFloat"));
2344 }
2345
2346 TEST_F(ValidateComposites, CoopMatVecConvBitCastArrayQCOM2) {
2347 const std::string body = R"(
2348 OpCapability Shader
2349 OpCapability Float16
2350 OpCapability Int8
2351 OpCapability CooperativeMatrixKHR
2352 OpCapability VulkanMemoryModelKHR
2353 OpCapability CooperativeMatrixConversionQCOM
2354 OpExtension "SPV_KHR_cooperative_matrix"
2355 OpExtension "SPV_KHR_vulkan_memory_model"
2356 OpExtension "SPV_QCOM_cooperative_matrix_conversion"
2357 OpMemoryModel Logical VulkanKHR
2358 OpEntryPoint GLCompute %main "main"
2359 %void = OpTypeVoid
2360 %3 = OpTypeFunction %void
2361 %u8int = OpTypeInt 8 0
2362 %uint = OpTypeInt 32 0
2363 ;%half = OpTypeFloat 16
2364 %uint_8 = OpConstant %uint 8
2365 %uint_32 = OpConstant %uint 32
2366 %_arr_uint_uint_8 = OpTypeArray %uint %uint_8
2367 %_arr_u8int_uint_32 = OpTypeArray %u8int %uint_32
2368 %_ptr_Function__arr_u8int_uint_32 = OpTypePointer Function %_arr_u8int_uint_32
2369 %main = OpFunction %void None %3
2370 %5 = OpLabel
2371 %u8A = OpVariable %_ptr_Function__arr_u8int_uint_32 Function
2372 %16 = OpLoad %_arr_u8int_uint_32 %u8A
2373 %18 = OpBitCastArrayQCOM %_arr_uint_uint_8 %16
2374 OpReturn
2375 OpFunctionEnd)";
2376
2377 CompileSuccessfully(body.c_str(), SPV_ENV_UNIVERSAL_1_3);
2378 ASSERT_EQ(SPV_ERROR_INVALID_DATA,
2379 ValidateInstructions(SPV_ENV_UNIVERSAL_1_3));
2380 EXPECT_THAT(getDiagnosticString(),
2381 HasSubstr("Opcode BitCastArrayQCOM requires the source element "
2382 "type be one of 32-bit OpTypeInt (signed/unsigned), "
2383 "32-bit OpTypeFloat and 16-bit OpTypeFloat"));
2384 }
2385
2386 TEST_F(ValidateComposites, CoopMatVecConvBitCastArrayQCOM3) {
2387 const std::string body = R"(
2388 OpCapability Shader
2389 OpCapability Float16
2390 OpCapability Int8
2391 OpCapability CooperativeMatrixKHR
2392 OpCapability VulkanMemoryModelKHR
2393 OpCapability CooperativeMatrixConversionQCOM
2394 OpExtension "SPV_KHR_cooperative_matrix"
2395 OpExtension "SPV_KHR_vulkan_memory_model"
2396 OpExtension "SPV_QCOM_cooperative_matrix_conversion"
2397 OpMemoryModel Logical VulkanKHR
2398 OpEntryPoint GLCompute %main "main"
2399 %void = OpTypeVoid
2400 %3 = OpTypeFunction %void
2401 %uint = OpTypeInt 32 0
2402 %half = OpTypeFloat 16
2403 %uint_16 = OpConstant %uint 16
2404 %_arr_uint_uint_16 = OpTypeArray %uint %uint_16
2405 %_arr_half_uint_16 = OpTypeArray %half %uint_16
2406 %_ptr_Function__arr_half_uint_16 = OpTypePointer Function %_arr_half_uint_16
2407 %main = OpFunction %void None %3
2408 %5 = OpLabel
2409 %hvec8A = OpVariable %_ptr_Function__arr_half_uint_16 Function
2410 %16 = OpLoad %_arr_half_uint_16 %hvec8A
2411 %18 = OpBitCastArrayQCOM %_arr_uint_uint_16 %16
2412 OpReturn
2413 OpFunctionEnd)";
2414
2415 CompileSuccessfully(body.c_str(), SPV_ENV_UNIVERSAL_1_3);
2416 ASSERT_EQ(SPV_ERROR_INVALID_DATA,
2417 ValidateInstructions(SPV_ENV_UNIVERSAL_1_3));
2418 EXPECT_THAT(getDiagnosticString(),
2419 HasSubstr("Opcode BitCastArrayQCOM requires source and result "
2420 "types be compatible for conversion."));
2421 }
2422
2423 TEST_F(ValidateComposites, CoopMatVecConvExtractSubArrayQCOM1) {
2424 const std::string body = R"(
2425 OpCapability Shader
2426 OpCapability Float16
2427 OpCapability Int8
2428 OpCapability CooperativeMatrixKHR
2429 OpCapability VulkanMemoryModelKHR
2430 OpCapability CooperativeMatrixConversionQCOM
2431 OpExtension "SPV_KHR_cooperative_matrix"
2432 OpExtension "SPV_KHR_vulkan_memory_model"
2433 OpExtension "SPV_QCOM_cooperative_matrix_conversion"
2434 OpMemoryModel Logical VulkanKHR
2435 OpEntryPoint GLCompute %main "main"
2436 %void = OpTypeVoid
2437 %3 = OpTypeFunction %void
2438 %uint = OpTypeInt 32 0
2439 %float = OpTypeFloat 32
2440 %uint_0 = OpConstant %uint 0
2441 %uint_8 = OpConstant %uint 8
2442 %uint_64 = OpConstant %uint 64
2443 %_arr_uint_uint_64 = OpTypeArray %uint %uint_64
2444 %_arr_float_uint_8 = OpTypeArray %float %uint_8
2445 %_ptr_Function__arr_uint_uint_64 = OpTypePointer Function %_arr_uint_uint_64
2446 %main = OpFunction %void None %3
2447 %5 = OpLabel
2448 %uvec64Acc = OpVariable %_ptr_Function__arr_uint_uint_64 Function
2449 %83 = OpLoad %_arr_uint_uint_64 %uvec64Acc
2450 %86 = OpExtractSubArrayQCOM %_arr_float_uint_8 %83 %uint_0
2451 OpReturn
2452 OpFunctionEnd)";
2453
2454 CompileSuccessfully(body.c_str(), SPV_ENV_UNIVERSAL_1_3);
2455 ASSERT_EQ(SPV_ERROR_INVALID_DATA,
2456 ValidateInstructions(SPV_ENV_UNIVERSAL_1_3));
2457 EXPECT_THAT(getDiagnosticString(),
2458 HasSubstr("Opcode ExtractSubArrayQCOM requires the input "
2459 "and result element types match."));
2460 }
2461
2462 TEST_F(ValidateComposites, CoopMatVecConvConstructQCOMTy) {
2463 const std::string body = R"(
2464 OpCapability Shader
2465 OpCapability Float16
2466 OpCapability Int8
2467 OpCapability CooperativeMatrixKHR
2468 OpCapability VulkanMemoryModelKHR
2469 OpCapability CooperativeMatrixConversionQCOM
2470 OpExtension "SPV_KHR_cooperative_matrix"
2471 OpExtension "SPV_KHR_vulkan_memory_model"
2472 OpExtension "SPV_QCOM_cooperative_matrix_conversion"
2473 OpMemoryModel Logical VulkanKHR
2474 OpEntryPoint GLCompute %main "main"
2475 %void = OpTypeVoid
2476 %3 = OpTypeFunction %void
2477 %uint = OpTypeInt 32 0
2478 %u8int = OpTypeInt 8 0
2479 %float = OpTypeFloat 32
2480 %uint_0 = OpConstant %uint 0
2481 %uint_3 = OpConstant %uint 3
2482 %uint_8 = OpConstant %uint 8
2483 %uint_32 = OpConstant %uint 32
2484 %uint_64 = OpConstant %uint 64
2485 %_arr_u8int_uint_32 = OpTypeArray %u8int %uint_32
2486 %_ptr_Function__arr_u8int_uint_32 = OpTypePointer Function %_arr_u8int_uint_32
2487 %113 = OpTypeCooperativeMatrixKHR %float %uint_3 %uint_64 %uint_8 %uint_0
2488 %main = OpFunction %void None %3
2489 %5 = OpLabel
2490 %u8_32 = OpVariable %_ptr_Function__arr_u8int_uint_32 Function
2491 %116 = OpLoad %_arr_u8int_uint_32 %u8_32
2492 %118 = OpCompositeConstructCoopMatQCOM %113 %116
2493 OpReturn
2494 OpFunctionEnd)";
2495
2496 CompileSuccessfully(body.c_str(), SPV_ENV_UNIVERSAL_1_3);
2497 ASSERT_EQ(SPV_ERROR_INVALID_DATA,
2498 ValidateInstructions(SPV_ENV_UNIVERSAL_1_3));
2499 EXPECT_THAT(getDiagnosticString(),
2500 HasSubstr("Opcode CompositeConstructCoopMatQCOM requires ether "
2501 "the input element type is equal to the result element "
2502 "type or it is the unsigned 32-bit integer."));
2503 }
2504
2505 TEST_F(ValidateComposites, CoopMatVecConvConstructQCOMA1) {
2506 const std::string body = R"(
2507 OpCapability Shader
2508 OpCapability Float16
2509 OpCapability Int8
2510 OpCapability CooperativeMatrixKHR
2511 OpCapability VulkanMemoryModelKHR
2512 OpCapability CooperativeMatrixConversionQCOM
2513 OpExtension "SPV_KHR_cooperative_matrix"
2514 OpExtension "SPV_KHR_vulkan_memory_model"
2515 OpExtension "SPV_QCOM_cooperative_matrix_conversion"
2516 OpMemoryModel Logical VulkanKHR
2517 OpEntryPoint GLCompute %main "main"
2518 %void = OpTypeVoid
2519 %3 = OpTypeFunction %void
2520 %uint = OpTypeInt 32 0
2521 %u8int = OpTypeInt 8 0
2522 %float = OpTypeFloat 32
2523 %uint_0 = OpConstant %uint 0
2524 %uint_3 = OpConstant %uint 3
2525 %uint_8 = OpConstant %uint 8
2526 %uint_32 = OpConstant %uint 32
2527 %uint_64 = OpConstant %uint 64
2528 %_arr_uint_uint_8 = OpTypeArray %uint %uint_8
2529 %_ptr_Function__arr_uint_uint_8 = OpTypePointer Function %_arr_uint_uint_8
2530 %113 = OpTypeCooperativeMatrixKHR %uint %uint_3 %uint_64 %uint_8 %uint_0
2531 %main = OpFunction %void None %3
2532 %5 = OpLabel
2533 %u32_8 = OpVariable %_ptr_Function__arr_uint_uint_8 Function
2534 %116 = OpLoad %_arr_uint_uint_8 %u32_8
2535 %118 = OpCompositeConstructCoopMatQCOM %113 %116
2536 OpReturn
2537 OpFunctionEnd)";
2538
2539 CompileSuccessfully(body.c_str(), SPV_ENV_UNIVERSAL_1_3);
2540 ASSERT_EQ(SPV_ERROR_INVALID_DATA,
2541 ValidateInstructions(SPV_ENV_UNIVERSAL_1_3));
2542 EXPECT_THAT(getDiagnosticString(),
2543 HasSubstr("Opcode CompositeConstructCoopMatQCOM requires "
2544 "the result element type is one of 8-bit OpTypeInt "
2545 "signed/unsigned, 16- or 32-bit OpTypeFloat when "
2546 "result coopmat's use is MatrixAKHR"));
2547 }
2548
2549 TEST_F(ValidateComposites, CoopMatVecConvConstructQCOMA2) {
2550 const std::string body = R"(
2551 OpCapability Shader
2552 OpCapability Float16
2553 OpCapability Int8
2554 OpCapability CooperativeMatrixKHR
2555 OpCapability VulkanMemoryModelKHR
2556 OpCapability CooperativeMatrixConversionQCOM
2557 OpExtension "SPV_KHR_cooperative_matrix"
2558 OpExtension "SPV_KHR_vulkan_memory_model"
2559 OpExtension "SPV_QCOM_cooperative_matrix_conversion"
2560 OpMemoryModel Logical VulkanKHR
2561 OpEntryPoint GLCompute %main "main"
2562 %void = OpTypeVoid
2563 %3 = OpTypeFunction %void
2564 %uint = OpTypeInt 32 0
2565 %u8int = OpTypeInt 8 0
2566 %float = OpTypeFloat 32
2567 %uint_0 = OpConstant %uint 0
2568 %uint_3 = OpConstant %uint 3
2569 %uint_8 = OpConstant %uint 8
2570 %uint_16 = OpConstant %uint 16
2571 %uint_32 = OpConstant %uint 32
2572 %uint_64 = OpConstant %uint 64
2573 %_arr_uint_uint_8 = OpTypeArray %uint %uint_8
2574 %_ptr_Function__arr_uint_uint_8 = OpTypePointer Function %_arr_uint_uint_8
2575 %113 = OpTypeCooperativeMatrixKHR %float %uint_3 %uint_64 %uint_16 %uint_0
2576 %main = OpFunction %void None %3
2577 %5 = OpLabel
2578 %u32_8 = OpVariable %_ptr_Function__arr_uint_uint_8 Function
2579 %116 = OpLoad %_arr_uint_uint_8 %u32_8
2580 %118 = OpCompositeConstructCoopMatQCOM %113 %116
2581 OpReturn
2582 OpFunctionEnd)";
2583
2584 CompileSuccessfully(body.c_str(), SPV_ENV_UNIVERSAL_1_3);
2585 ASSERT_EQ(SPV_ERROR_INVALID_DATA,
2586 ValidateInstructions(SPV_ENV_UNIVERSAL_1_3));
2587 EXPECT_THAT(getDiagnosticString(),
2588 HasSubstr("Opcode CompositeConstructCoopMatQCOM requires "
2589 "the columns of the result coopmat have the bit "
2590 "length of 256 when result coopmat's use is "
2591 "MatrixAKHR"));
2592 }
2593
2594 TEST_F(ValidateComposites, CoopMatVecConvConstructQCOMA3) {
2595 const std::string body = R"(
2596 OpCapability Shader
2597 OpCapability Float16
2598 OpCapability Int8
2599 OpCapability CooperativeMatrixKHR
2600 OpCapability VulkanMemoryModelKHR
2601 OpCapability CooperativeMatrixConversionQCOM
2602 OpExtension "SPV_KHR_cooperative_matrix"
2603 OpExtension "SPV_KHR_vulkan_memory_model"
2604 OpExtension "SPV_QCOM_cooperative_matrix_conversion"
2605 OpMemoryModel Logical VulkanKHR
2606 OpEntryPoint GLCompute %main "main"
2607 %void = OpTypeVoid
2608 %3 = OpTypeFunction %void
2609 %uint = OpTypeInt 32 0
2610 %u8int = OpTypeInt 8 0
2611 %float = OpTypeFloat 32
2612 %uint_0 = OpConstant %uint 0
2613 %uint_3 = OpConstant %uint 3
2614 %uint_8 = OpConstant %uint 8
2615 %uint_16 = OpConstant %uint 16
2616 %uint_32 = OpConstant %uint 32
2617 %uint_64 = OpConstant %uint 64
2618 %_arr_u8int_uint_16 = OpTypeArray %u8int %uint_16
2619 %_ptr_Function__arr_u8int_uint_16 = OpTypePointer Function %_arr_u8int_uint_16
2620 %113 = OpTypeCooperativeMatrixKHR %u8int %uint_3 %uint_64 %uint_32 %uint_0
2621 %main = OpFunction %void None %3
2622 %5 = OpLabel
2623 %u8_16 = OpVariable %_ptr_Function__arr_u8int_uint_16 Function
2624 %116 = OpLoad %_arr_u8int_uint_16 %u8_16
2625 %118 = OpCompositeConstructCoopMatQCOM %113 %116
2626 OpReturn
2627 OpFunctionEnd)";
2628
2629 CompileSuccessfully(body.c_str(), SPV_ENV_UNIVERSAL_1_3);
2630 ASSERT_EQ(SPV_ERROR_INVALID_DATA,
2631 ValidateInstructions(SPV_ENV_UNIVERSAL_1_3));
2632 EXPECT_THAT(getDiagnosticString(),
2633 HasSubstr("Opcode CompositeConstructCoopMatQCOM requires "
2634 "the source array length be 8 if its elt type is "
2635 "32-bit unsigned OpTypeInt and be the result's "
2636 "number of columns, otherwise when result coopmat's "
2637 "use is MatrixAKHR"));
2638 }
2639
2640 TEST_F(ValidateComposites, CoopMatVecConvConstructQCOMB1) {
2641 const std::string body = R"(
2642 OpCapability Shader
2643 OpCapability Float16
2644 OpCapability Int8
2645 OpCapability CooperativeMatrixKHR
2646 OpCapability VulkanMemoryModelKHR
2647 OpCapability CooperativeMatrixConversionQCOM
2648 OpExtension "SPV_KHR_cooperative_matrix"
2649 OpExtension "SPV_KHR_vulkan_memory_model"
2650 OpExtension "SPV_QCOM_cooperative_matrix_conversion"
2651 OpMemoryModel Logical VulkanKHR
2652 OpEntryPoint GLCompute %main "main"
2653 %void = OpTypeVoid
2654 %3 = OpTypeFunction %void
2655 %uint = OpTypeInt 32 0
2656 %u8int = OpTypeInt 8 0
2657 %float = OpTypeFloat 32
2658 %uint_1 = OpConstant %uint 1
2659 %uint_3 = OpConstant %uint 3
2660 %uint_8 = OpConstant %uint 8
2661 %uint_32 = OpConstant %uint 32
2662 %uint_64 = OpConstant %uint 64
2663 %_arr_uint_uint_8 = OpTypeArray %uint %uint_8
2664 %_ptr_Function__arr_uint_uint_8 = OpTypePointer Function %_arr_uint_uint_8
2665 %113 = OpTypeCooperativeMatrixKHR %uint %uint_3 %uint_8 %uint_64 %uint_1
2666 %main = OpFunction %void None %3
2667 %5 = OpLabel
2668 %u32_8 = OpVariable %_ptr_Function__arr_uint_uint_8 Function
2669 %116 = OpLoad %_arr_uint_uint_8 %u32_8
2670 %118 = OpCompositeConstructCoopMatQCOM %113 %116
2671 OpReturn
2672 OpFunctionEnd)";
2673
2674 CompileSuccessfully(body.c_str(), SPV_ENV_UNIVERSAL_1_3);
2675 ASSERT_EQ(SPV_ERROR_INVALID_DATA,
2676 ValidateInstructions(SPV_ENV_UNIVERSAL_1_3));
2677 EXPECT_THAT(getDiagnosticString(),
2678 HasSubstr("Opcode CompositeConstructCoopMatQCOM requires "
2679 "the result element type is one of 8-bit OpTypeInt "
2680 "signed/unsigned, 16- or 32-bit OpTypeFloat when "
2681 "result coopmat's use is MatrixBKHR"));
2682 }
2683
2684 TEST_F(ValidateComposites, CoopMatVecConvConstructQCOMB2) {
2685 const std::string body = R"(
2686 OpCapability Shader
2687 OpCapability Float16
2688 OpCapability Int8
2689 OpCapability CooperativeMatrixKHR
2690 OpCapability VulkanMemoryModelKHR
2691 OpCapability CooperativeMatrixConversionQCOM
2692 OpExtension "SPV_KHR_cooperative_matrix"
2693 OpExtension "SPV_KHR_vulkan_memory_model"
2694 OpExtension "SPV_QCOM_cooperative_matrix_conversion"
2695 OpMemoryModel Logical VulkanKHR
2696 OpEntryPoint GLCompute %main "main"
2697 %void = OpTypeVoid
2698 %3 = OpTypeFunction %void
2699 %uint = OpTypeInt 32 0
2700 %u8int = OpTypeInt 8 0
2701 %float = OpTypeFloat 32
2702 %uint_1 = OpConstant %uint 1
2703 %uint_3 = OpConstant %uint 3
2704 %uint_8 = OpConstant %uint 8
2705 %uint_16 = OpConstant %uint 16
2706 %uint_32 = OpConstant %uint 32
2707 %uint_64 = OpConstant %uint 64
2708 %_arr_uint_uint_8 = OpTypeArray %uint %uint_8
2709 %_ptr_Function__arr_uint_uint_8 = OpTypePointer Function %_arr_uint_uint_8
2710 %113 = OpTypeCooperativeMatrixKHR %float %uint_3 %uint_16 %uint_64 %uint_1
2711 %main = OpFunction %void None %3
2712 %5 = OpLabel
2713 %u32_8 = OpVariable %_ptr_Function__arr_uint_uint_8 Function
2714 %116 = OpLoad %_arr_uint_uint_8 %u32_8
2715 %118 = OpCompositeConstructCoopMatQCOM %113 %116
2716 OpReturn
2717 OpFunctionEnd)";
2718
2719 CompileSuccessfully(body.c_str(), SPV_ENV_UNIVERSAL_1_3);
2720 ASSERT_EQ(SPV_ERROR_INVALID_DATA,
2721 ValidateInstructions(SPV_ENV_UNIVERSAL_1_3));
2722 EXPECT_THAT(getDiagnosticString(),
2723 HasSubstr("Opcode CompositeConstructCoopMatQCOM requires "
2724 "the rows of the result operand have the bit "
2725 "length of 256 when result coopmat's use is "
2726 "MatrixBKHR"));
2727 }
2728
2729 TEST_F(ValidateComposites, CoopMatVecConvConstructQCOMB3) {
2730 const std::string body = R"(
2731 OpCapability Shader
2732 OpCapability Float16
2733 OpCapability Int8
2734 OpCapability CooperativeMatrixKHR
2735 OpCapability VulkanMemoryModelKHR
2736 OpCapability CooperativeMatrixConversionQCOM
2737 OpExtension "SPV_KHR_cooperative_matrix"
2738 OpExtension "SPV_KHR_vulkan_memory_model"
2739 OpExtension "SPV_QCOM_cooperative_matrix_conversion"
2740 OpMemoryModel Logical VulkanKHR
2741 OpEntryPoint GLCompute %main "main"
2742 %void = OpTypeVoid
2743 %3 = OpTypeFunction %void
2744 %uint = OpTypeInt 32 0
2745 %u8int = OpTypeInt 8 0
2746 %float = OpTypeFloat 32
2747 %uint_0 = OpConstant %uint 0
2748 %uint_1 = OpConstant %uint 1
2749 %uint_3 = OpConstant %uint 3
2750 %uint_8 = OpConstant %uint 8
2751 %uint_16 = OpConstant %uint 16
2752 %uint_32 = OpConstant %uint 32
2753 %uint_64 = OpConstant %uint 64
2754 %_arr_u8int_uint_16 = OpTypeArray %u8int %uint_16
2755 %_ptr_Function__arr_u8int_uint_16 = OpTypePointer Function %_arr_u8int_uint_16
2756 %113 = OpTypeCooperativeMatrixKHR %u8int %uint_3 %uint_32 %uint_64 %uint_1
2757 %main = OpFunction %void None %3
2758 %5 = OpLabel
2759 %u8_16 = OpVariable %_ptr_Function__arr_u8int_uint_16 Function
2760 %116 = OpLoad %_arr_u8int_uint_16 %u8_16
2761 %118 = OpCompositeConstructCoopMatQCOM %113 %116
2762 OpReturn
2763 OpFunctionEnd)";
2764
2765 CompileSuccessfully(body.c_str(), SPV_ENV_UNIVERSAL_1_3);
2766 ASSERT_EQ(SPV_ERROR_INVALID_DATA,
2767 ValidateInstructions(SPV_ENV_UNIVERSAL_1_3));
2768 EXPECT_THAT(
2769 getDiagnosticString(),
2770 HasSubstr("Opcode CompositeConstructCoopMatQCOM requires "
2771 "the source array length be 8 if its elt type "
2772 "is 32-bit unsigned OpTypeInt and be the result's "
2773 "number of rows, otherwise when result coopmat's use is "
2774 "MatrixBKHR"));
2775 }
2776
2777 TEST_F(ValidateComposites, CoopMatVecConvConstructQCOMAcc1) {
2778 const std::string body = R"(
2779 OpCapability Shader
2780 OpCapability Float16
2781 OpCapability Int8
2782 OpCapability CooperativeMatrixKHR
2783 OpCapability VulkanMemoryModelKHR
2784 OpCapability CooperativeMatrixConversionQCOM
2785 OpExtension "SPV_KHR_cooperative_matrix"
2786 OpExtension "SPV_KHR_vulkan_memory_model"
2787 OpExtension "SPV_QCOM_cooperative_matrix_conversion"
2788 OpMemoryModel Logical VulkanKHR
2789 OpEntryPoint GLCompute %main "main"
2790 %void = OpTypeVoid
2791 %3 = OpTypeFunction %void
2792 %uint = OpTypeInt 32 0
2793 %u8int = OpTypeInt 8 0
2794 %float = OpTypeFloat 32
2795 %uint_0 = OpConstant %uint 0
2796 %uint_2 = OpConstant %uint 2
2797 %uint_3 = OpConstant %uint 3
2798 %uint_8 = OpConstant %uint 8
2799 %uint_32 = OpConstant %uint 32
2800 %uint_64 = OpConstant %uint 64
2801 %_arr_u8int_uint_32 = OpTypeArray %u8int %uint_32
2802 %_ptr_Function__arr_u8int_uint_32 = OpTypePointer Function %_arr_u8int_uint_32
2803 %113 = OpTypeCooperativeMatrixKHR %u8int %uint_3 %uint_64 %uint_64 %uint_2
2804 %main = OpFunction %void None %3
2805 %5 = OpLabel
2806 %u8_32 = OpVariable %_ptr_Function__arr_u8int_uint_32 Function
2807 %116 = OpLoad %_arr_u8int_uint_32 %u8_32
2808 %118 = OpCompositeConstructCoopMatQCOM %113 %116
2809 OpReturn
2810 OpFunctionEnd)";
2811
2812 CompileSuccessfully(body.c_str(), SPV_ENV_UNIVERSAL_1_3);
2813 ASSERT_EQ(SPV_ERROR_INVALID_DATA,
2814 ValidateInstructions(SPV_ENV_UNIVERSAL_1_3));
2815 EXPECT_THAT(getDiagnosticString(),
2816 HasSubstr("Opcode CompositeConstructCoopMatQCOM requires "
2817 "the result element type is one of 32-bit "
2818 "OpTypeInt signed/unsigned, 16- or 32-bit "
2819 "OpTypeFloat when result coopmat's use is "
2820 "MatrixAccumulatorKHR"));
2821 }
2822
2823 TEST_F(ValidateComposites, CoopMatVecConvConstructQCOMAcc2) {
2824 const std::string body = R"(
2825 OpCapability Shader
2826 OpCapability Float16
2827 OpCapability CooperativeMatrixKHR
2828 OpCapability VulkanMemoryModelKHR
2829 OpCapability CooperativeMatrixConversionQCOM
2830 OpExtension "SPV_KHR_cooperative_matrix"
2831 OpExtension "SPV_KHR_vulkan_memory_model"
2832 OpExtension "SPV_QCOM_cooperative_matrix_conversion"
2833 OpMemoryModel Logical VulkanKHR
2834 OpEntryPoint GLCompute %main "main"
2835 %void = OpTypeVoid
2836 %3 = OpTypeFunction %void
2837 %uint = OpTypeInt 32 0
2838 %half = OpTypeFloat 16
2839 %uint_2 = OpConstant %uint 2
2840 %uint_3 = OpConstant %uint 3
2841 %uint_16 = OpConstant %uint 16
2842 %uint_64 = OpConstant %uint 64
2843 %_arr_uint_uint_16 = OpTypeArray %uint %uint_16
2844 %_ptr_Function__arr_uint_uint_16 = OpTypePointer Function %_arr_uint_uint_16
2845 %113 = OpTypeCooperativeMatrixKHR %half %uint_3 %uint_64 %uint_64 %uint_2
2846 %main = OpFunction %void None %3
2847 %5 = OpLabel
2848 %u32_16 = OpVariable %_ptr_Function__arr_uint_uint_16 Function
2849 %116 = OpLoad %_arr_uint_uint_16 %u32_16
2850 %118 = OpCompositeConstructCoopMatQCOM %113 %116
2851 OpReturn
2852 OpFunctionEnd)";
2853
2854 CompileSuccessfully(body.c_str(), SPV_ENV_UNIVERSAL_1_3);
2855 ASSERT_EQ(SPV_ERROR_INVALID_DATA,
2856 ValidateInstructions(SPV_ENV_UNIVERSAL_1_3));
2857 EXPECT_THAT(getDiagnosticString(),
2858 HasSubstr("Opcode CompositeConstructCoopMatQCOM requires "
2859 "the source array length be a half of the number "
2860 "of columns of the resulting cooerative matrix if "
2861 "the matrix's componet type is 16-bit OpTypeFloat "
2862 "and be equal to the number of columns, otherwise, "
2863 "when result coopmat's use is "
2864 "MatrixAccumulatorKHR"));
2865 }
2866
2867 TEST_F(ValidateComposites, CoopMatVecConvExtractQCOMA1) {
2868 const std::string body = R"(
2869 OpCapability Shader
2870 OpCapability Float16
2871 OpCapability Int8
2872 OpCapability CooperativeMatrixKHR
2873 OpCapability VulkanMemoryModelKHR
2874 OpCapability CooperativeMatrixConversionQCOM
2875 OpExtension "SPV_KHR_cooperative_matrix"
2876 OpExtension "SPV_KHR_vulkan_memory_model"
2877 OpExtension "SPV_QCOM_cooperative_matrix_conversion"
2878 OpMemoryModel Logical VulkanKHR
2879 OpEntryPoint GLCompute %main "main"
2880 %void = OpTypeVoid
2881 %3 = OpTypeFunction %void
2882 %uint = OpTypeInt 32 0
2883 %uint_0 = OpConstant %uint 0
2884 %uint_3 = OpConstant %uint 3
2885 %uint_8 = OpConstant %uint 8
2886 %uint_64 = OpConstant %uint 64
2887 %_arr_uint_uint_8 = OpTypeArray %uint %uint_8
2888 %_ptr_Function__arr_uint_uint_8 = OpTypePointer Function %_arr_uint_uint_8
2889 %113 = OpTypeCooperativeMatrixKHR %uint %uint_3 %uint_64 %uint_8 %uint_0
2890 %_ptr_Function_113 = OpTypePointer Function %113
2891 %main = OpFunction %void None %3
2892 %5 = OpLabel
2893 %matA_u32_64_8 = OpVariable %_ptr_Function_113 Function
2894 %249 = OpLoad %113 %matA_u32_64_8
2895 %251 = OpCompositeExtractCoopMatQCOM %_arr_uint_uint_8 %249
2896 OpReturn
2897 OpFunctionEnd)";
2898
2899 CompileSuccessfully(body.c_str(), SPV_ENV_UNIVERSAL_1_3);
2900 ASSERT_EQ(SPV_ERROR_INVALID_DATA,
2901 ValidateInstructions(SPV_ENV_UNIVERSAL_1_3));
2902 EXPECT_THAT(getDiagnosticString(),
2903 HasSubstr("Opcode CompositeExtractCoopMatQCOM requires "
2904 "the source element type be one of 8-bit "
2905 "OpTypeInt signed/unsigned, 16- or 32-bit "
2906 "OpTypeFloat when source coopmat's use is "
2907 "MatrixAKHR"));
2908 }
2909
2910 TEST_F(ValidateComposites, CoopMatVecConvExtractQCOMA2) {
2911 const std::string body = R"(
2912 OpCapability Shader
2913 OpCapability Float16
2914 OpCapability Int8
2915 OpCapability CooperativeMatrixKHR
2916 OpCapability VulkanMemoryModelKHR
2917 OpCapability CooperativeMatrixConversionQCOM
2918 OpExtension "SPV_KHR_cooperative_matrix"
2919 OpExtension "SPV_KHR_vulkan_memory_model"
2920 OpExtension "SPV_QCOM_cooperative_matrix_conversion"
2921 OpMemoryModel Logical VulkanKHR
2922 OpEntryPoint GLCompute %main "main"
2923 %void = OpTypeVoid
2924 %3 = OpTypeFunction %void
2925 %uint = OpTypeInt 32 0
2926 %float = OpTypeFloat 32
2927 %uint_0 = OpConstant %uint 0
2928 %uint_3 = OpConstant %uint 3
2929 %uint_8 = OpConstant %uint 8
2930 %uint_16 = OpConstant %uint 16
2931 %uint_64 = OpConstant %uint 64
2932 %_arr_uint_uint_8 = OpTypeArray %uint %uint_8
2933 %_ptr_Function__arr_uint_uint_8 = OpTypePointer Function %_arr_uint_uint_8
2934 %113 = OpTypeCooperativeMatrixKHR %float %uint_3 %uint_64 %uint_16 %uint_0
2935 %_ptr_Function_113 = OpTypePointer Function %113
2936 %main = OpFunction %void None %3
2937 %5 = OpLabel
2938 %matA_u32_64_8 = OpVariable %_ptr_Function_113 Function
2939 %249 = OpLoad %113 %matA_u32_64_8
2940 %251 = OpCompositeExtractCoopMatQCOM %_arr_uint_uint_8 %249
2941 OpReturn
2942 OpFunctionEnd)";
2943
2944 CompileSuccessfully(body.c_str(), SPV_ENV_UNIVERSAL_1_3);
2945 ASSERT_EQ(SPV_ERROR_INVALID_DATA,
2946 ValidateInstructions(SPV_ENV_UNIVERSAL_1_3));
2947 EXPECT_THAT(getDiagnosticString(),
2948 HasSubstr("Opcode CompositeExtractCoopMatQCOM "
2949 "requires the columns of the source "
2950 "coopmat have the bit length of 256 "
2951 "when source coopmat's use is "
2952 "MatrixAKHR"));
2953 }
2954
2955 TEST_F(ValidateComposites, CoopMatVecConvExtractQCOMA3) {
2956 const std::string body = R"(
2957 OpCapability Shader
2958 OpCapability Float16
2959 OpCapability Int8
2960 OpCapability CooperativeMatrixKHR
2961 OpCapability VulkanMemoryModelKHR
2962 OpCapability CooperativeMatrixConversionQCOM
2963 OpExtension "SPV_KHR_cooperative_matrix"
2964 OpExtension "SPV_KHR_vulkan_memory_model"
2965 OpExtension "SPV_QCOM_cooperative_matrix_conversion"
2966 OpMemoryModel Logical VulkanKHR
2967 OpEntryPoint GLCompute %main "main"
2968 %void = OpTypeVoid
2969 %3 = OpTypeFunction %void
2970 %uint = OpTypeInt 32 0
2971 %u8int = OpTypeInt 8 0
2972 %uint_0 = OpConstant %uint 0
2973 %uint_3 = OpConstant %uint 3
2974 %uint_8 = OpConstant %uint 8
2975 %uint_32 = OpConstant %uint 32
2976 %uint_64 = OpConstant %uint 64
2977 %_arr_u8int_uint_64 = OpTypeArray %u8int %uint_64
2978 %_ptr_Function__arr_u8int_uint_64 = OpTypePointer Function %_arr_u8int_uint_64
2979 %113 = OpTypeCooperativeMatrixKHR %u8int %uint_3 %uint_64 %uint_32 %uint_0
2980 %_ptr_Function_113 = OpTypePointer Function %113
2981 %main = OpFunction %void None %3
2982 %5 = OpLabel
2983 %matA_u8_64_32 = OpVariable %_ptr_Function_113 Function
2984 %249 = OpLoad %113 %matA_u8_64_32
2985 %251 = OpCompositeExtractCoopMatQCOM %_arr_u8int_uint_64 %249
2986 OpReturn
2987 OpFunctionEnd)";
2988
2989 CompileSuccessfully(body.c_str(), SPV_ENV_UNIVERSAL_1_3);
2990 ASSERT_EQ(SPV_ERROR_INVALID_DATA,
2991 ValidateInstructions(SPV_ENV_UNIVERSAL_1_3));
2992 EXPECT_THAT(getDiagnosticString(),
2993 HasSubstr("Opcode CompositeExtractCoopMatQCOM requires "
2994 "either the result element type be the same as "
2995 "the source cooperative matrix's component type "
2996 "and its length be the same as the number of "
2997 "columns of the matrix or the result element "
2998 "type be unsigned 32-bit OpTypeInt and the "
2999 "length be 8 when source coopmat's use is "
3000 "MatrixAKHR"));
3001 }
3002
3003 TEST_F(ValidateComposites, CoopMatVecConvExtractQCOMA4) {
3004 const std::string body = R"(
3005 OpCapability Shader
3006 OpCapability Float16
3007 OpCapability Int8
3008 OpCapability CooperativeMatrixKHR
3009 OpCapability VulkanMemoryModelKHR
3010 OpCapability CooperativeMatrixConversionQCOM
3011 OpExtension "SPV_KHR_cooperative_matrix"
3012 OpExtension "SPV_KHR_vulkan_memory_model"
3013 OpExtension "SPV_QCOM_cooperative_matrix_conversion"
3014 OpMemoryModel Logical VulkanKHR
3015 OpEntryPoint GLCompute %main "main"
3016 %void = OpTypeVoid
3017 %3 = OpTypeFunction %void
3018 %uint = OpTypeInt 32 0
3019 %u8int = OpTypeInt 8 0
3020 %uint_0 = OpConstant %uint 0
3021 %uint_3 = OpConstant %uint 3
3022 %uint_8 = OpConstant %uint 8
3023 %uint_16 = OpConstant %uint 16
3024 %uint_32 = OpConstant %uint 32
3025 %uint_64 = OpConstant %uint 64
3026 %_arr_uint_uint_16 = OpTypeArray %uint %uint_16
3027 %_ptr_Function__arr_uint_uint_16 = OpTypePointer Function %_arr_uint_uint_16
3028 %113 = OpTypeCooperativeMatrixKHR %u8int %uint_3 %uint_64 %uint_32 %uint_0
3029 %_ptr_Function_113 = OpTypePointer Function %113
3030 %main = OpFunction %void None %3
3031 %5 = OpLabel
3032 %matA_u8_64_32 = OpVariable %_ptr_Function_113 Function
3033 %249 = OpLoad %113 %matA_u8_64_32
3034 %251 = OpCompositeExtractCoopMatQCOM %_arr_uint_uint_16 %249
3035 OpReturn
3036 OpFunctionEnd)";
3037
3038 CompileSuccessfully(body.c_str(), SPV_ENV_UNIVERSAL_1_3);
3039 ASSERT_EQ(SPV_ERROR_INVALID_DATA,
3040 ValidateInstructions(SPV_ENV_UNIVERSAL_1_3));
3041 EXPECT_THAT(getDiagnosticString(),
3042 HasSubstr("Opcode CompositeExtractCoopMatQCOM requires "
3043 "either the result element type be the same as "
3044 "the source cooperative matrix's component type "
3045 "and its length be the same as the number of "
3046 "columns of the matrix or the result element "
3047 "type be unsigned 32-bit OpTypeInt and the "
3048 "length be 8 when source coopmat's use is "
3049 "MatrixAKHR"));
3050 }
3051
3052 TEST_F(ValidateComposites, CoopMatVecConvExtractQCOMB1) {
3053 const std::string body = R"(
3054 OpCapability Shader
3055 OpCapability Float16
3056 OpCapability Int8
3057 OpCapability CooperativeMatrixKHR
3058 OpCapability VulkanMemoryModelKHR
3059 OpCapability CooperativeMatrixConversionQCOM
3060 OpExtension "SPV_KHR_cooperative_matrix"
3061 OpExtension "SPV_KHR_vulkan_memory_model"
3062 OpExtension "SPV_QCOM_cooperative_matrix_conversion"
3063 OpMemoryModel Logical VulkanKHR
3064 OpEntryPoint GLCompute %main "main"
3065 %void = OpTypeVoid
3066 %3 = OpTypeFunction %void
3067 %uint = OpTypeInt 32 0
3068 %uint_0 = OpConstant %uint 0
3069 %uint_1 = OpConstant %uint 1
3070 %uint_3 = OpConstant %uint 3
3071 %uint_8 = OpConstant %uint 8
3072 %uint_64 = OpConstant %uint 64
3073 %_arr_uint_uint_8 = OpTypeArray %uint %uint_8
3074 %_ptr_Function__arr_uint_uint_8 = OpTypePointer Function %_arr_uint_uint_8
3075 %113 = OpTypeCooperativeMatrixKHR %uint %uint_3 %uint_8 %uint_64 %uint_1
3076 %_ptr_Function_113 = OpTypePointer Function %113
3077 %main = OpFunction %void None %3
3078 %5 = OpLabel
3079 %matA_u32_64_8 = OpVariable %_ptr_Function_113 Function
3080 %249 = OpLoad %113 %matA_u32_64_8
3081 %251 = OpCompositeExtractCoopMatQCOM %_arr_uint_uint_8 %249
3082 OpReturn
3083 OpFunctionEnd)";
3084
3085 CompileSuccessfully(body.c_str(), SPV_ENV_UNIVERSAL_1_3);
3086 ASSERT_EQ(SPV_ERROR_INVALID_DATA,
3087 ValidateInstructions(SPV_ENV_UNIVERSAL_1_3));
3088 EXPECT_THAT(getDiagnosticString(),
3089 HasSubstr("Opcode CompositeExtractCoopMatQCOM "
3090 "requires the source element type be "
3091 "one of 8-bit OpTypeInt signed/unsigned, "
3092 "16- or 32-bit OpTypeFloat when source "
3093 "coopmat's use is "
3094 "MatrixBKHR"));
3095 }
3096
3097 TEST_F(ValidateComposites, CoopMatVecConvExtractQCOMB2) {
3098 const std::string body = R"(
3099 OpCapability Shader
3100 OpCapability Float16
3101 OpCapability Int8
3102 OpCapability CooperativeMatrixKHR
3103 OpCapability VulkanMemoryModelKHR
3104 OpCapability CooperativeMatrixConversionQCOM
3105 OpExtension "SPV_KHR_cooperative_matrix"
3106 OpExtension "SPV_KHR_vulkan_memory_model"
3107 OpExtension "SPV_QCOM_cooperative_matrix_conversion"
3108 OpMemoryModel Logical VulkanKHR
3109 OpEntryPoint GLCompute %main "main"
3110 %void = OpTypeVoid
3111 %3 = OpTypeFunction %void
3112 %uint = OpTypeInt 32 0
3113 %float = OpTypeFloat 32
3114 %uint_0 = OpConstant %uint 0
3115 %uint_1 = OpConstant %uint 1
3116 %uint_3 = OpConstant %uint 3
3117 %uint_8 = OpConstant %uint 8
3118 %uint_16 = OpConstant %uint 16
3119 %uint_64 = OpConstant %uint 64
3120 %_arr_uint_uint_8 = OpTypeArray %uint %uint_8
3121 %_ptr_Function__arr_uint_uint_8 = OpTypePointer Function %_arr_uint_uint_8
3122 %113 = OpTypeCooperativeMatrixKHR %float %uint_3 %uint_16 %uint_64 %uint_1
3123 %_ptr_Function_113 = OpTypePointer Function %113
3124 %main = OpFunction %void None %3
3125 %5 = OpLabel
3126 %matA_u32_64_8 = OpVariable %_ptr_Function_113 Function
3127 %249 = OpLoad %113 %matA_u32_64_8
3128 %251 = OpCompositeExtractCoopMatQCOM %_arr_uint_uint_8 %249
3129 OpReturn
3130 OpFunctionEnd)";
3131
3132 CompileSuccessfully(body.c_str(), SPV_ENV_UNIVERSAL_1_3);
3133 ASSERT_EQ(SPV_ERROR_INVALID_DATA,
3134 ValidateInstructions(SPV_ENV_UNIVERSAL_1_3));
3135 EXPECT_THAT(getDiagnosticString(),
3136 HasSubstr("Opcode CompositeExtractCoopMatQCOM requires "
3137 "the rows of the source coopmat have the bit "
3138 "length of 256 when source coopmat's use is "
3139 "MatrixBKHR"));
3140 }
3141
3142 TEST_F(ValidateComposites, CoopMatVecConvExtractQCOMB3) {
3143 const std::string body = R"(
3144 OpCapability Shader
3145 OpCapability Float16
3146 OpCapability Int8
3147 OpCapability CooperativeMatrixKHR
3148 OpCapability VulkanMemoryModelKHR
3149 OpCapability CooperativeMatrixConversionQCOM
3150 OpExtension "SPV_KHR_cooperative_matrix"
3151 OpExtension "SPV_KHR_vulkan_memory_model"
3152 OpExtension "SPV_QCOM_cooperative_matrix_conversion"
3153 OpMemoryModel Logical VulkanKHR
3154 OpEntryPoint GLCompute %main "main"
3155 %void = OpTypeVoid
3156 %3 = OpTypeFunction %void
3157 %uint = OpTypeInt 32 0
3158 %u8int = OpTypeInt 8 0
3159 %uint_0 = OpConstant %uint 0
3160 %uint_1 = OpConstant %uint 1
3161 %uint_3 = OpConstant %uint 3
3162 %uint_8 = OpConstant %uint 8
3163 %uint_16 = OpConstant %uint 16
3164 %uint_32 = OpConstant %uint 32
3165 %uint_64 = OpConstant %uint 64
3166 %_arr_u8int_uint_16 = OpTypeArray %u8int %uint_16
3167 %_ptr_Function__arr_u8int_uint_16 = OpTypePointer Function %_arr_u8int_uint_16
3168 %113 = OpTypeCooperativeMatrixKHR %u8int %uint_3 %uint_32 %uint_64 %uint_1
3169 %_ptr_Function_113 = OpTypePointer Function %113
3170 %main = OpFunction %void None %3
3171 %5 = OpLabel
3172 %matA_u8_16_64 = OpVariable %_ptr_Function_113 Function
3173 %249 = OpLoad %113 %matA_u8_16_64
3174 %251 = OpCompositeExtractCoopMatQCOM %_arr_u8int_uint_16 %249
3175 OpReturn
3176 OpFunctionEnd)";
3177
3178 CompileSuccessfully(body.c_str(), SPV_ENV_UNIVERSAL_1_3);
3179 ASSERT_EQ(SPV_ERROR_INVALID_DATA,
3180 ValidateInstructions(SPV_ENV_UNIVERSAL_1_3));
3181 EXPECT_THAT(getDiagnosticString(),
3182 HasSubstr("Opcode CompositeExtractCoopMatQCOM requires "
3183 "either the result element type be the same as "
3184 "the source cooperative matrix's component type "
3185 "and its length be the same as the number of "
3186 "rows of the matrix or the result element "
3187 "type be unsigned 32-bit OpTypeInt and the "
3188 "length be 8 when source coopmat's use is "
3189 "MatrixBKHR"));
3190 }
3191
3192 TEST_F(ValidateComposites, CoopMatVecConvExtractQCOMB4) {
3193 const std::string body = R"(
3194 OpCapability Shader
3195 OpCapability Float16
3196 OpCapability Int8
3197 OpCapability CooperativeMatrixKHR
3198 OpCapability VulkanMemoryModelKHR
3199 OpCapability CooperativeMatrixConversionQCOM
3200 OpExtension "SPV_KHR_cooperative_matrix"
3201 OpExtension "SPV_KHR_vulkan_memory_model"
3202 OpExtension "SPV_QCOM_cooperative_matrix_conversion"
3203 OpMemoryModel Logical VulkanKHR
3204 OpEntryPoint GLCompute %main "main"
3205 %void = OpTypeVoid
3206 %3 = OpTypeFunction %void
3207 %uint = OpTypeInt 32 0
3208 %u8int = OpTypeInt 8 0
3209 %uint_0 = OpConstant %uint 0
3210 %uint_1 = OpConstant %uint 1
3211 %uint_3 = OpConstant %uint 3
3212 %uint_16 = OpConstant %uint 16
3213 %uint_32 = OpConstant %uint 32
3214 %uint_64 = OpConstant %uint 64
3215 %_arr_uint_uint_16 = OpTypeArray %uint %uint_16
3216 %_ptr_Function__arr_uint_uint_16 = OpTypePointer Function %_arr_uint_uint_16
3217 %113 = OpTypeCooperativeMatrixKHR %u8int %uint_3 %uint_32 %uint_64 %uint_1
3218 %_ptr_Function_113 = OpTypePointer Function %113
3219 %main = OpFunction %void None %3
3220 %5 = OpLabel
3221 %matA_u8_32_64 = OpVariable %_ptr_Function_113 Function
3222 %249 = OpLoad %113 %matA_u8_32_64
3223 %251 = OpCompositeExtractCoopMatQCOM %_arr_uint_uint_16 %249
3224 OpReturn
3225 OpFunctionEnd)";
3226
3227 CompileSuccessfully(body.c_str(), SPV_ENV_UNIVERSAL_1_3);
3228 ASSERT_EQ(SPV_ERROR_INVALID_DATA,
3229 ValidateInstructions(SPV_ENV_UNIVERSAL_1_3));
3230 EXPECT_THAT(getDiagnosticString(),
3231 HasSubstr("Opcode CompositeExtractCoopMatQCOM requires "
3232 "either the result element type be the same as "
3233 "the source cooperative matrix's component type "
3234 "and its length be the same as the number of "
3235 "rows of the matrix or the result element "
3236 "type be unsigned 32-bit OpTypeInt and the "
3237 "length be 8 when source coopmat's use is "
3238 "MatrixBKHR"));
3239 }
3240
3241 TEST_F(ValidateComposites, CoopMatVecConvExtractQCOMAcc1) {
3242 const std::string body = R"(
3243 OpCapability Shader
3244 OpCapability Float16
3245 OpCapability Int8
3246 OpCapability CooperativeMatrixKHR
3247 OpCapability VulkanMemoryModelKHR
3248 OpCapability CooperativeMatrixConversionQCOM
3249 OpExtension "SPV_KHR_cooperative_matrix"
3250 OpExtension "SPV_KHR_vulkan_memory_model"
3251 OpExtension "SPV_QCOM_cooperative_matrix_conversion"
3252 OpMemoryModel Logical VulkanKHR
3253 OpEntryPoint GLCompute %main "main"
3254 %void = OpTypeVoid
3255 %3 = OpTypeFunction %void
3256 %u8int = OpTypeInt 8 0
3257 %uint = OpTypeInt 32 0
3258 %uint_0 = OpConstant %uint 0
3259 %uint_2 = OpConstant %uint 2
3260 %uint_3 = OpConstant %uint 3
3261 %uint_8 = OpConstant %uint 8
3262 %uint_64 = OpConstant %uint 64
3263 %_arr_uint_uint_8 = OpTypeArray %uint %uint_8
3264 %_ptr_Function__arr_uint_uint_8 = OpTypePointer Function %_arr_uint_uint_8
3265 %113 = OpTypeCooperativeMatrixKHR %u8int %uint_3 %uint_64 %uint_64 %uint_2
3266 %_ptr_Function_113 = OpTypePointer Function %113
3267 %main = OpFunction %void None %3
3268 %5 = OpLabel
3269 %matA_u32_64_64 = OpVariable %_ptr_Function_113 Function
3270 %249 = OpLoad %113 %matA_u32_64_64
3271 %251 = OpCompositeExtractCoopMatQCOM %_arr_uint_uint_8 %249
3272 OpReturn
3273 OpFunctionEnd)";
3274
3275 CompileSuccessfully(body.c_str(), SPV_ENV_UNIVERSAL_1_3);
3276 ASSERT_EQ(SPV_ERROR_INVALID_DATA,
3277 ValidateInstructions(SPV_ENV_UNIVERSAL_1_3));
3278 EXPECT_THAT(getDiagnosticString(),
3279 HasSubstr("Opcode CompositeExtractCoopMatQCOM "
3280 "requires the source element type be "
3281 "one of 32-bit OpTypeInt signed/unsigned, "
3282 "16- or 32-bit OpTypeFloat when source "
3283 "coopmat's use is "
3284 "MatrixAccumulatorKHR"));
3285 }
3286
3287 TEST_F(ValidateComposites, CoopMatVecConvExtractQCOMAcc2) {
3288 const std::string body = R"(
3289 OpCapability Shader
3290 OpCapability Float16
3291 OpCapability Int8
3292 OpCapability CooperativeMatrixKHR
3293 OpCapability VulkanMemoryModelKHR
3294 OpCapability CooperativeMatrixConversionQCOM
3295 OpExtension "SPV_KHR_cooperative_matrix"
3296 OpExtension "SPV_KHR_vulkan_memory_model"
3297 OpExtension "SPV_QCOM_cooperative_matrix_conversion"
3298 OpMemoryModel Logical VulkanKHR
3299 OpEntryPoint GLCompute %main "main"
3300 %void = OpTypeVoid
3301 %3 = OpTypeFunction %void
3302 %uint = OpTypeInt 32 0
3303 %uint_0 = OpConstant %uint 0
3304 %uint_2 = OpConstant %uint 2
3305 %uint_3 = OpConstant %uint 3
3306 %uint_32 = OpConstant %uint 32
3307 %uint_64 = OpConstant %uint 64
3308 %_arr_uint_uint_32 = OpTypeArray %uint %uint_32
3309 %_ptr_Function__arr_uint_uint_32 = OpTypePointer Function %_arr_uint_uint_32
3310 %113 = OpTypeCooperativeMatrixKHR %uint %uint_3 %uint_64 %uint_64 %uint_2
3311 %_ptr_Function_113 = OpTypePointer Function %113
3312 %main = OpFunction %void None %3
3313 %5 = OpLabel
3314 %matA_u32_64_64 = OpVariable %_ptr_Function_113 Function
3315 %249 = OpLoad %113 %matA_u32_64_64
3316 %251 = OpCompositeExtractCoopMatQCOM %_arr_uint_uint_32 %249
3317 OpReturn
3318 OpFunctionEnd)";
3319
3320 CompileSuccessfully(body.c_str(), SPV_ENV_UNIVERSAL_1_3);
3321 ASSERT_EQ(SPV_ERROR_INVALID_DATA,
3322 ValidateInstructions(SPV_ENV_UNIVERSAL_1_3));
3323 EXPECT_THAT(getDiagnosticString(),
3324 HasSubstr("Opcode CompositeExtractCoopMatQCOM requires "
3325 "either the result element type be the same as "
3326 "the source cooperative matrix's component type "
3327 "and its length be the same as the number of "
3328 "columns of the matrix or the result element "
3329 "type be unsigned 32-bit OpTypeInt and the length "
3330 "be the number of the columns of the matrix if "
3331 "its component type is 32-bit OpTypeFloat and be "
3332 "a half of the number of the columns of the matrix "
3333 "if its component type is 16-bit OpTypeFloat when "
3334 "source coopmat's use is "
3335 "MatrixAccumulatorKHR"));
3336 }
3337
3338 TEST_F(ValidateComposites, CoopMatVecConvExtractQCOMAcc3) {
3339 const std::string body = R"(
3340 OpCapability Shader
3341 OpCapability Float16
3342 OpCapability Int8
3343 OpCapability CooperativeMatrixKHR
3344 OpCapability VulkanMemoryModelKHR
3345 OpCapability CooperativeMatrixConversionQCOM
3346 OpExtension "SPV_KHR_cooperative_matrix"
3347 OpExtension "SPV_KHR_vulkan_memory_model"
3348 OpExtension "SPV_QCOM_cooperative_matrix_conversion"
3349 OpMemoryModel Logical VulkanKHR
3350 OpEntryPoint GLCompute %main "main"
3351 %void = OpTypeVoid
3352 %3 = OpTypeFunction %void
3353 %uint = OpTypeInt 32 0
3354 %half = OpTypeFloat 16
3355 %uint_0 = OpConstant %uint 0
3356 %uint_2 = OpConstant %uint 2
3357 %uint_3 = OpConstant %uint 3
3358 %uint_64 = OpConstant %uint 64
3359 %_arr_uint_uint_64 = OpTypeArray %uint %uint_64
3360 %_ptr_Function__arr_uint_uint_64 = OpTypePointer Function %_arr_uint_uint_64
3361 %113 = OpTypeCooperativeMatrixKHR %half %uint_3 %uint_64 %uint_64 %uint_2
3362 %_ptr_Function_113 = OpTypePointer Function %113
3363 %main = OpFunction %void None %3
3364 %5 = OpLabel
3365 %matA_f16_64_64 = OpVariable %_ptr_Function_113 Function
3366 %249 = OpLoad %113 %matA_f16_64_64
3367 %251 = OpCompositeExtractCoopMatQCOM %_arr_uint_uint_64 %249
3368 OpReturn
3369 OpFunctionEnd)";
3370
3371 CompileSuccessfully(body.c_str(), SPV_ENV_UNIVERSAL_1_3);
3372 ASSERT_EQ(SPV_ERROR_INVALID_DATA,
3373 ValidateInstructions(SPV_ENV_UNIVERSAL_1_3));
3374 EXPECT_THAT(getDiagnosticString(),
3375 HasSubstr("Opcode CompositeExtractCoopMatQCOM requires "
3376 "either the result element type be the same as "
3377 "the source cooperative matrix's component type "
3378 "and its length be the same as the number of "
3379 "columns of the matrix or the result element "
3380 "type be unsigned 32-bit OpTypeInt and the length "
3381 "be the number of the columns of the matrix if "
3382 "its component type is 32-bit OpTypeFloat and be "
3383 "a half of the number of the columns of the matrix "
3384 "if its component type is 16-bit OpTypeFloat when "
3385 "source coopmat's use is "
3386 "MatrixAccumulatorKHR"));
3387 }
3388
3389 TEST_F(ValidateComposites, CoopMatVecConvExtractSubArrayQCOM2) {
3390 const std::string body = R"(
3391 OpCapability Shader
3392 OpCapability Float16
3393 OpCapability Int8
3394 OpCapability CooperativeMatrixKHR
3395 OpCapability VulkanMemoryModelKHR
3396 OpCapability CooperativeMatrixConversionQCOM
3397 OpExtension "SPV_KHR_cooperative_matrix"
3398 OpExtension "SPV_KHR_vulkan_memory_model"
3399 OpExtension "SPV_QCOM_cooperative_matrix_conversion"
3400 OpMemoryModel Logical VulkanKHR
3401 OpEntryPoint GLCompute %main "main"
3402 %void = OpTypeVoid
3403 %3 = OpTypeFunction %void
3404 %u8int = OpTypeInt 8 0
3405 %uint = OpTypeInt 32 0
3406 %uint_0 = OpConstant %uint 0
3407 %uint_8 = OpConstant %uint 8
3408 %uint_64 = OpConstant %uint 64
3409 %_arr_u8int_uint_8 = OpTypeArray %u8int %uint_8
3410 %_arr_u8int_uint_64 = OpTypeArray %u8int %uint_64
3411 %_ptr_Function__arr_u8int_uint_64 = OpTypePointer Function %_arr_u8int_uint_64
3412 %main = OpFunction %void None %3
3413 %5 = OpLabel
3414 %uvec64Acc = OpVariable %_ptr_Function__arr_u8int_uint_64 Function
3415 %83 = OpLoad %_arr_u8int_uint_64 %uvec64Acc
3416 %86 = OpExtractSubArrayQCOM %_arr_u8int_uint_8 %83 %uint_0
3417 OpReturn
3418 OpFunctionEnd)";
3419
3420 CompileSuccessfully(body.c_str(), SPV_ENV_UNIVERSAL_1_3);
3421 ASSERT_EQ(SPV_ERROR_INVALID_DATA,
3422 ValidateInstructions(SPV_ENV_UNIVERSAL_1_3));
3423 EXPECT_THAT(getDiagnosticString(),
3424 HasSubstr("Opcode ExtractSubArrayQCOM requires the element type "
3425 "be one of 32-bit OpTypeInt (signed/unsigned), 32-bit "
3426 "OpTypeFloat and 16-bit OpTypeFloat"));
3427 }
3428
3429 TEST_F(ValidateComposites, CoopMatVecConvExtractSubArrayQCOM3) {
3430 const std::string body = R"(
3431 OpCapability Shader
3432 OpCapability Float16
3433 OpCapability Int16
3434 OpCapability CooperativeMatrixKHR
3435 OpCapability VulkanMemoryModelKHR
3436 OpCapability CooperativeMatrixConversionQCOM
3437 OpExtension "SPV_KHR_cooperative_matrix"
3438 OpExtension "SPV_KHR_vulkan_memory_model"
3439 OpExtension "SPV_QCOM_cooperative_matrix_conversion"
3440 OpMemoryModel Logical VulkanKHR
3441 OpEntryPoint GLCompute %main "main"
3442 %void = OpTypeVoid
3443 %3 = OpTypeFunction %void
3444 %ui16 = OpTypeInt 16 0
3445 %uint = OpTypeInt 32 0
3446 %f16 = OpTypeFloat 16
3447 %u16int_0 = OpConstant %ui16 0
3448 %uint_8 = OpConstant %uint 8
3449 %uint_64 = OpConstant %uint 64
3450 %_arr_f16_uint_8 = OpTypeArray %f16 %uint_8
3451 %_arr_f16_uint_64 = OpTypeArray %f16 %uint_64
3452 %_ptr_Function__arr_f16_uint_64 = OpTypePointer Function %_arr_f16_uint_64
3453 %main = OpFunction %void None %3
3454 %5 = OpLabel
3455 %f16vec64Acc = OpVariable %_ptr_Function__arr_f16_uint_64 Function
3456 %83 = OpLoad %_arr_f16_uint_64 %f16vec64Acc
3457 %86 = OpExtractSubArrayQCOM %_arr_f16_uint_8 %83 %u16int_0
3458 OpReturn
3459 OpFunctionEnd)";
3460
3461 CompileSuccessfully(body.c_str(), SPV_ENV_UNIVERSAL_1_3);
3462 ASSERT_EQ(SPV_ERROR_INVALID_DATA,
3463 ValidateInstructions(SPV_ENV_UNIVERSAL_1_3));
3464 EXPECT_THAT(getDiagnosticString(),
3465 HasSubstr("Opcode ExtractSubArrayQCOM requires the type of the "
3466 "start index operand be 32-bit OpTypeInt"));
3467 }
3468
3469 } // namespace
3470 } // namespace val
3471 } // namespace spvtools