Debian Codegraph @

test/val/val_interfaces_test.cpp

raw
1 // Copyright (c) 2018 Google LLC.
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 <string>
16
17 #include "gmock/gmock.h"
18 #include "test/unit_spirv.h"
19 #include "test/val/val_fixtures.h"
20
21 namespace spvtools {
22 namespace val {
23 namespace {
24
25 using ::testing::HasSubstr;
26
27 using ValidateInterfacesTest = spvtest::ValidateBase<bool>;
28
29 TEST_F(ValidateInterfacesTest, EntryPointMissingInput) {
30 std::string text = R"(
31 OpCapability Shader
32 OpMemoryModel Logical GLSL450
33 OpEntryPoint Fragment %1 "func"
34 OpExecutionMode %1 OriginUpperLeft
35 %2 = OpTypeVoid
36 %3 = OpTypeInt 32 0
37 %4 = OpTypePointer Input %3
38 %5 = OpVariable %4 Input
39 %6 = OpTypeFunction %2
40 %1 = OpFunction %2 None %6
41 %7 = OpLabel
42 %8 = OpLoad %3 %5
43 OpReturn
44 OpFunctionEnd
45 )";
46
47 CompileSuccessfully(text);
48 ASSERT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions());
49 EXPECT_THAT(
50 getDiagnosticString(),
51 HasSubstr(
52 "Interface variable id <5> is used by entry point 'func' id <1>, "
53 "but is not listed as an interface"));
54 }
55
56 TEST_F(ValidateInterfacesTest, EntryPointMissingOutput) {
57 std::string text = R"(
58 OpCapability Shader
59 OpMemoryModel Logical GLSL450
60 OpEntryPoint Fragment %1 "func"
61 OpExecutionMode %1 OriginUpperLeft
62 %2 = OpTypeVoid
63 %3 = OpTypeInt 32 0
64 %4 = OpTypePointer Output %3
65 %5 = OpVariable %4 Output
66 %6 = OpTypeFunction %2
67 %1 = OpFunction %2 None %6
68 %7 = OpLabel
69 %8 = OpLoad %3 %5
70 OpReturn
71 OpFunctionEnd
72 )";
73
74 CompileSuccessfully(text);
75 ASSERT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions());
76 EXPECT_THAT(
77 getDiagnosticString(),
78 HasSubstr(
79 "Interface variable id <5> is used by entry point 'func' id <1>, "
80 "but is not listed as an interface"));
81 }
82
83 TEST_F(ValidateInterfacesTest, InterfaceMissingUseInSubfunction) {
84 std::string text = R"(
85 OpCapability Shader
86 OpMemoryModel Logical GLSL450
87 OpEntryPoint Fragment %1 "func"
88 OpExecutionMode %1 OriginUpperLeft
89 %2 = OpTypeVoid
90 %3 = OpTypeInt 32 0
91 %4 = OpTypePointer Input %3
92 %5 = OpVariable %4 Input
93 %6 = OpTypeFunction %2
94 %1 = OpFunction %2 None %6
95 %7 = OpLabel
96 %8 = OpFunctionCall %2 %9
97 OpReturn
98 OpFunctionEnd
99 %9 = OpFunction %2 None %6
100 %10 = OpLabel
101 %11 = OpLoad %3 %5
102 OpReturn
103 OpFunctionEnd
104 )";
105
106 CompileSuccessfully(text);
107 ASSERT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions());
108 EXPECT_THAT(
109 getDiagnosticString(),
110 HasSubstr(
111 "Interface variable id <5> is used by entry point 'func' id <1>, "
112 "but is not listed as an interface"));
113 }
114
115 TEST_F(ValidateInterfacesTest, TwoEntryPointsOneFunction) {
116 std::string text = R"(
117 OpCapability Shader
118 OpMemoryModel Logical GLSL450
119 OpEntryPoint Fragment %1 "func" %2
120 OpEntryPoint Fragment %1 "func2"
121 OpExecutionMode %1 OriginUpperLeft
122 %3 = OpTypeVoid
123 %4 = OpTypeInt 32 0
124 %5 = OpTypePointer Input %4
125 %2 = OpVariable %5 Input
126 %6 = OpTypeFunction %3
127 %1 = OpFunction %3 None %6
128 %7 = OpLabel
129 %8 = OpLoad %4 %2
130 OpReturn
131 OpFunctionEnd
132 )";
133
134 CompileSuccessfully(text);
135 ASSERT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions());
136 EXPECT_THAT(
137 getDiagnosticString(),
138 HasSubstr(
139 "Interface variable id <2> is used by entry point 'func2' id <1>, "
140 "but is not listed as an interface"));
141 }
142
143 TEST_F(ValidateInterfacesTest, MissingInterfaceThroughInitializer) {
144 const std::string text = R"(
145 OpCapability Shader
146 OpCapability VariablePointers
147 OpMemoryModel Logical GLSL450
148 OpEntryPoint Fragment %1 "func"
149 OpExecutionMode %1 OriginUpperLeft
150 %2 = OpTypeVoid
151 %3 = OpTypeInt 32 0
152 %4 = OpTypePointer Input %3
153 %5 = OpTypePointer Function %4
154 %6 = OpVariable %4 Input
155 %7 = OpTypeFunction %2
156 %1 = OpFunction %2 None %7
157 %8 = OpLabel
158 %9 = OpVariable %5 Function %6
159 OpReturn
160 OpFunctionEnd
161 )";
162
163 getValidatorOptions()->relax_logical_pointer = true;
164 CompileSuccessfully(text, SPV_ENV_UNIVERSAL_1_3);
165 ASSERT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions(SPV_ENV_UNIVERSAL_1_3));
166 EXPECT_THAT(
167 getDiagnosticString(),
168 HasSubstr(
169 "Interface variable id <6> is used by entry point 'func' id <1>, "
170 "but is not listed as an interface"));
171 }
172
173 TEST_F(ValidateInterfacesTest, NonUniqueInterfacesSPV1p3) {
174 const std::string text = R"(
175 OpCapability Shader
176 OpMemoryModel Logical GLSL450
177 OpEntryPoint GLCompute %main "main" %var %var
178 OpExecutionMode %main LocalSize 1 1 1
179 %void = OpTypeVoid
180 %uint = OpTypeInt 32 0
181 %uint3 = OpTypeVector %uint 3
182 %struct = OpTypeStruct %uint3
183 %ptr_struct = OpTypePointer Input %struct
184 %var = OpVariable %ptr_struct Input
185 %func_ty = OpTypeFunction %void
186 %main = OpFunction %void None %func_ty
187 %1 = OpLabel
188 OpReturn
189 OpFunctionEnd
190 )";
191
192 CompileSuccessfully(text, SPV_ENV_UNIVERSAL_1_3);
193 EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_UNIVERSAL_1_3));
194 }
195
196 TEST_F(ValidateInterfacesTest, NonUniqueInterfacesSPV1p4) {
197 const std::string text = R"(
198 OpCapability Shader
199 OpMemoryModel Logical GLSL450
200 OpEntryPoint GLCompute %main "main" %var %var
201 OpExecutionMode %main LocalSize 1 1 1
202 OpName %main "main"
203 OpName %var "var"
204 %void = OpTypeVoid
205 %uint = OpTypeInt 32 0
206 %uint3 = OpTypeVector %uint 3
207 %struct = OpTypeStruct %uint3
208 %ptr_struct = OpTypePointer Input %struct
209 %var = OpVariable %ptr_struct Input
210 %func_ty = OpTypeFunction %void
211 %main = OpFunction %void None %func_ty
212 %1 = OpLabel
213 OpReturn
214 OpFunctionEnd
215 )";
216
217 CompileSuccessfully(text, SPV_ENV_UNIVERSAL_1_4);
218 EXPECT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions(SPV_ENV_UNIVERSAL_1_4));
219 EXPECT_THAT(getDiagnosticString(),
220 HasSubstr("In SPIR-V 1.4 or later, non-unique OpEntryPoint "
221 "interface '2[%var]' is disallowed"));
222 }
223
224 TEST_F(ValidateInterfacesTest, MissingGlobalVarSPV1p3) {
225 const std::string text = R"(
226 OpCapability Shader
227 OpMemoryModel Logical GLSL450
228 OpEntryPoint GLCompute %main "main"
229 OpExecutionMode %main LocalSize 1 1 1
230 %void = OpTypeVoid
231 %uint = OpTypeInt 32 0
232 %uint3 = OpTypeVector %uint 3
233 %struct = OpTypeStruct %uint3
234 %ptr_struct = OpTypePointer StorageBuffer %struct
235 %var = OpVariable %ptr_struct StorageBuffer
236 %func_ty = OpTypeFunction %void
237 %main = OpFunction %void None %func_ty
238 %1 = OpLabel
239 %ld = OpLoad %struct %var
240 OpReturn
241 OpFunctionEnd
242 )";
243
244 CompileSuccessfully(text, SPV_ENV_UNIVERSAL_1_3);
245 EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_UNIVERSAL_1_3));
246 }
247
248 TEST_F(ValidateInterfacesTest, MissingGlobalVarSPV1p4) {
249 const std::string text = R"(
250 OpCapability Shader
251 OpMemoryModel Logical GLSL450
252 OpEntryPoint GLCompute %main "main"
253 OpExecutionMode %main LocalSize 1 1 1
254 OpName %var "var"
255 %void = OpTypeVoid
256 %uint = OpTypeInt 32 0
257 %uint3 = OpTypeVector %uint 3
258 %struct = OpTypeStruct %uint3
259 %ptr_struct = OpTypePointer StorageBuffer %struct
260 %var = OpVariable %ptr_struct StorageBuffer
261 %func_ty = OpTypeFunction %void
262 %main = OpFunction %void None %func_ty
263 %1 = OpLabel
264 %ld = OpLoad %struct %var
265 OpReturn
266 OpFunctionEnd
267 )";
268
269 CompileSuccessfully(text, SPV_ENV_UNIVERSAL_1_4);
270 EXPECT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions(SPV_ENV_UNIVERSAL_1_4));
271 EXPECT_THAT(getDiagnosticString(),
272 HasSubstr("Interface variable id <2> is used by entry point "
273 "'main' id <1>, but is not listed as an interface"));
274 }
275
276 TEST_F(ValidateInterfacesTest, FunctionInterfaceVarSPV1p3) {
277 const std::string text = R"(
278 OpCapability Shader
279 OpMemoryModel Logical GLSL450
280 OpEntryPoint GLCompute %main "main" %var
281 OpExecutionMode %main LocalSize 1 1 1
282 OpName %var "var"
283 %void = OpTypeVoid
284 %uint = OpTypeInt 32 0
285 %uint3 = OpTypeVector %uint 3
286 %struct = OpTypeStruct %uint3
287 %ptr_struct = OpTypePointer Function %struct
288 %func_ty = OpTypeFunction %void
289 %main = OpFunction %void None %func_ty
290 %1 = OpLabel
291 %var = OpVariable %ptr_struct Function
292 OpReturn
293 OpFunctionEnd
294 )";
295
296 CompileSuccessfully(text, SPV_ENV_UNIVERSAL_1_3);
297 EXPECT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions(SPV_ENV_UNIVERSAL_1_3));
298 EXPECT_THAT(getDiagnosticString(),
299 HasSubstr("OpEntryPoint interfaces must be OpVariables with "
300 "Storage Class of Input(1) or Output(3). Found Storage "
301 "Class 7 for Entry Point id 1."));
302 }
303
304 TEST_F(ValidateInterfacesTest, FunctionInterfaceVarSPV1p4) {
305 const std::string text = R"(
306 OpCapability Shader
307 OpMemoryModel Logical GLSL450
308 OpEntryPoint GLCompute %main "main" %var
309 OpExecutionMode %main LocalSize 1 1 1
310 OpName %var "var"
311 %void = OpTypeVoid
312 %uint = OpTypeInt 32 0
313 %uint3 = OpTypeVector %uint 3
314 %struct = OpTypeStruct %uint3
315 %ptr_struct = OpTypePointer Function %struct
316 %func_ty = OpTypeFunction %void
317 %main = OpFunction %void None %func_ty
318 %1 = OpLabel
319 %var = OpVariable %ptr_struct Function
320 OpReturn
321 OpFunctionEnd
322 )";
323
324 CompileSuccessfully(text, SPV_ENV_UNIVERSAL_1_4);
325 EXPECT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions(SPV_ENV_UNIVERSAL_1_4));
326 EXPECT_THAT(
327 getDiagnosticString(),
328 HasSubstr("OpEntryPoint interfaces should only list global variables"));
329 }
330
331 TEST_F(ValidateInterfacesTest, ModuleSPV1p3ValidateSPV1p4_NotAllUsedGlobals) {
332 const std::string text = R"(
333 OpCapability Shader
334 OpMemoryModel Logical GLSL450
335 OpEntryPoint GLCompute %main "main"
336 OpExecutionMode %main LocalSize 1 1 1
337 OpName %var "var"
338 %void = OpTypeVoid
339 %uint = OpTypeInt 32 0
340 %uint3 = OpTypeVector %uint 3
341 %struct = OpTypeStruct %uint3
342 %ptr_struct = OpTypePointer StorageBuffer %struct
343 %var = OpVariable %ptr_struct StorageBuffer
344 %func_ty = OpTypeFunction %void
345 %main = OpFunction %void None %func_ty
346 %1 = OpLabel
347 %ld = OpLoad %struct %var
348 OpReturn
349 OpFunctionEnd
350 )";
351
352 CompileSuccessfully(text, SPV_ENV_UNIVERSAL_1_3);
353 EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_UNIVERSAL_1_4));
354 }
355
356 TEST_F(ValidateInterfacesTest, ModuleSPV1p3ValidateSPV1p4_DuplicateInterface) {
357 const std::string text = R"(
358 OpCapability Shader
359 OpMemoryModel Logical GLSL450
360 OpEntryPoint GLCompute %main "main" %gid %gid
361 OpExecutionMode %main LocalSize 1 1 1
362 OpDecorate %gid BuiltIn GlobalInvocationId
363 %void = OpTypeVoid
364 %int = OpTypeInt 32 0
365 %int3 = OpTypeVector %int 3
366 %ptr_input_int3 = OpTypePointer Input %int3
367 %gid = OpVariable %ptr_input_int3 Input
368 %void_fn = OpTypeFunction %void
369 %main = OpFunction %void None %void_fn
370 %entry = OpLabel
371 OpReturn
372 OpFunctionEnd
373 )";
374
375 CompileSuccessfully(text, SPV_ENV_UNIVERSAL_1_3);
376 EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_UNIVERSAL_1_4));
377 }
378
379 TEST_F(ValidateInterfacesTest, SPV14MultipleEntryPointsSameFunction) {
380 const std::string text = R"(
381 OpCapability Shader
382 OpMemoryModel Logical GLSL450
383 OpEntryPoint GLCompute %main "main1" %gid
384 OpEntryPoint GLCompute %main "main2" %gid
385 OpExecutionMode %main LocalSize 1 1 1
386 OpDecorate %gid BuiltIn GlobalInvocationId
387 %void = OpTypeVoid
388 %int = OpTypeInt 32 0
389 %int3 = OpTypeVector %int 3
390 %ptr_input_int3 = OpTypePointer Input %int3
391 %gid = OpVariable %ptr_input_int3 Input
392 %void_fn = OpTypeFunction %void
393 %main = OpFunction %void None %void_fn
394 %entry = OpLabel
395 OpReturn
396 OpFunctionEnd
397 )";
398
399 CompileSuccessfully(text, SPV_ENV_UNIVERSAL_1_4);
400 EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_UNIVERSAL_1_4));
401 }
402
403 TEST_F(ValidateInterfacesTest, VulkanLocationsDoubleAssignmentVariable) {
404 const std::string text = R"(
405 OpCapability Shader
406 OpMemoryModel Logical GLSL450
407 OpEntryPoint Fragment %main "main" %var
408 OpExecutionMode %main OriginUpperLeft
409 OpDecorate %var Location 0
410 OpDecorate %var Location 1
411 %void = OpTypeVoid
412 %void_fn = OpTypeFunction %void
413 %float = OpTypeFloat 32
414 %ptr_input_float = OpTypePointer Input %float
415 %var = OpVariable %ptr_input_float Input
416 %main = OpFunction %void None %void_fn
417 %entry = OpLabel
418 OpReturn
419 OpFunctionEnd
420 )";
421
422 CompileSuccessfully(text, SPV_ENV_VULKAN_1_0);
423 EXPECT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions(SPV_ENV_VULKAN_1_0));
424 EXPECT_THAT(
425 getDiagnosticString(),
426 HasSubstr("decorated with Location multiple times is not allowed"));
427 }
428
429 TEST_F(ValidateInterfacesTest, VulkanLocationsVariableAndMemberAssigned) {
430 const std::string text = R"(
431 OpCapability Shader
432 OpMemoryModel Logical GLSL450
433 OpEntryPoint Fragment %main "main" %var
434 OpExecutionMode %main OriginUpperLeft
435 OpDecorate %var Location 0
436 OpDecorate %struct Block
437 OpMemberDecorate %struct 0 Location 0
438 %void = OpTypeVoid
439 %void_fn = OpTypeFunction %void
440 %float = OpTypeFloat 32
441 %struct = OpTypeStruct %float
442 %ptr_input_struct = OpTypePointer Input %struct
443 %var = OpVariable %ptr_input_struct Input
444 %main = OpFunction %void None %void_fn
445 %entry = OpLabel
446 OpReturn
447 OpFunctionEnd
448 )";
449
450 CompileSuccessfully(text, SPV_ENV_VULKAN_1_0);
451 EXPECT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions(SPV_ENV_VULKAN_1_0));
452 EXPECT_THAT(getDiagnosticString(),
453 AnyVUID("VUID-StandaloneSpirv-Location-04918"));
454 EXPECT_THAT(getDiagnosticString(),
455 HasSubstr("Members cannot be assigned a location"));
456 }
457
458 TEST_F(ValidateInterfacesTest, VulkanLocationsMemberAndSubMemberAssigned) {
459 const std::string text = R"(
460 OpCapability Shader
461 OpMemoryModel Logical GLSL450
462 OpEntryPoint Fragment %main "main" %var
463 OpExecutionMode %main OriginUpperLeft
464 OpDecorate %outer Block
465 OpMemberDecorate %outer 0 Location 0
466 OpMemberDecorate %struct 0 Location 0
467 %void = OpTypeVoid
468 %void_fn = OpTypeFunction %void
469 %float = OpTypeFloat 32
470 %struct = OpTypeStruct %float
471 %outer = OpTypeStruct %struct
472 %ptr_input_outer = OpTypePointer Input %outer
473 %var = OpVariable %ptr_input_outer Input
474 %main = OpFunction %void None %void_fn
475 %entry = OpLabel
476 OpReturn
477 OpFunctionEnd
478 )";
479
480 CompileSuccessfully(text, SPV_ENV_VULKAN_1_0);
481 EXPECT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions(SPV_ENV_VULKAN_1_0));
482 EXPECT_THAT(getDiagnosticString(),
483 AnyVUID("VUID-StandaloneSpirv-Location-04918"));
484 EXPECT_THAT(getDiagnosticString(),
485 HasSubstr("Members cannot be assigned a location"));
486 }
487
488 TEST_F(ValidateInterfacesTest, VulkanLocationsDoubleAssignmentStructMember) {
489 const std::string text = R"(
490 OpCapability Shader
491 OpMemoryModel Logical GLSL450
492 OpEntryPoint Fragment %main "main" %var
493 OpExecutionMode %main OriginUpperLeft
494 OpDecorate %struct Block
495 OpMemberDecorate %struct 1 Location 0
496 OpMemberDecorate %struct 1 Location 1
497 %void = OpTypeVoid
498 %void_fn = OpTypeFunction %void
499 %float = OpTypeFloat 32
500 %struct = OpTypeStruct %float %float
501 %ptr_input_struct = OpTypePointer Input %struct
502 %var = OpVariable %ptr_input_struct Input
503 %main = OpFunction %void None %void_fn
504 %entry = OpLabel
505 OpReturn
506 OpFunctionEnd
507 )";
508
509 CompileSuccessfully(text, SPV_ENV_VULKAN_1_0);
510 EXPECT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions(SPV_ENV_VULKAN_1_0));
511 EXPECT_THAT(
512 getDiagnosticString(),
513 HasSubstr("decorated with Location multiple times is not allowed"));
514 }
515
516 TEST_F(ValidateInterfacesTest, VulkanLocationsMissingAssignmentStructMember) {
517 const std::string text = R"(
518 OpCapability Shader
519 OpMemoryModel Logical GLSL450
520 OpEntryPoint Fragment %main "main" %var
521 OpExecutionMode %main OriginUpperLeft
522 OpDecorate %struct Block
523 OpMemberDecorate %struct 1 Location 1
524 %void = OpTypeVoid
525 %void_fn = OpTypeFunction %void
526 %float = OpTypeFloat 32
527 %struct = OpTypeStruct %float %float
528 %ptr_input_struct = OpTypePointer Input %struct
529 %var = OpVariable %ptr_input_struct Input
530 %main = OpFunction %void None %void_fn
531 %entry = OpLabel
532 OpReturn
533 OpFunctionEnd
534 )";
535
536 CompileSuccessfully(text, SPV_ENV_VULKAN_1_0);
537 EXPECT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions(SPV_ENV_VULKAN_1_0));
538 EXPECT_THAT(getDiagnosticString(),
539 HasSubstr("Member index 0 is missing a location assignment"));
540 }
541
542 TEST_F(ValidateInterfacesTest, VulkanLocationsMissingAssignmentNonBlockStruct) {
543 const std::string text = R"(
544 OpCapability Shader
545 OpMemoryModel Logical GLSL450
546 OpEntryPoint Fragment %main "main" %var
547 OpExecutionMode %main OriginUpperLeft
548 %void = OpTypeVoid
549 %void_fn = OpTypeFunction %void
550 %float = OpTypeFloat 32
551 %struct = OpTypeStruct %float %float
552 %ptr_input_struct = OpTypePointer Input %struct
553 %var = OpVariable %ptr_input_struct Input
554 %main = OpFunction %void None %void_fn
555 %entry = OpLabel
556 OpReturn
557 OpFunctionEnd
558 )";
559
560 CompileSuccessfully(text, SPV_ENV_VULKAN_1_0);
561 EXPECT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions(SPV_ENV_VULKAN_1_0));
562 EXPECT_THAT(getDiagnosticString(),
563 HasSubstr("Variable must be decorated with a location"));
564 }
565
566 TEST_F(ValidateInterfacesTest, VulkanLocationsVariableConflictInput) {
567 const std::string text = R"(
568 OpCapability Shader
569 OpMemoryModel Logical GLSL450
570 OpEntryPoint Fragment %main "main" %var1 %var2
571 OpExecutionMode %main OriginUpperLeft
572 OpDecorate %var1 Location 0
573 OpDecorate %var2 Location 0
574 %void = OpTypeVoid
575 %void_fn = OpTypeFunction %void
576 %float = OpTypeFloat 32
577 %struct = OpTypeStruct %float %float
578 %ptr_input_struct = OpTypePointer Input %struct
579 %var1 = OpVariable %ptr_input_struct Input
580 %var2 = OpVariable %ptr_input_struct Input
581 %main = OpFunction %void None %void_fn
582 %entry = OpLabel
583 OpReturn
584 OpFunctionEnd
585 )";
586
587 CompileSuccessfully(text, SPV_ENV_VULKAN_1_0);
588 EXPECT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions(SPV_ENV_VULKAN_1_0));
589 EXPECT_THAT(getDiagnosticString(),
590 AnyVUID("VUID-StandaloneSpirv-OpEntryPoint-08721"));
591 EXPECT_THAT(getDiagnosticString(),
592 HasSubstr("Entry-point has conflicting input location assignment "
593 "at location 0"));
594 }
595
596 TEST_F(ValidateInterfacesTest, VulkanLocationsVariableConflictOutput) {
597 const std::string text = R"(
598 OpCapability Shader
599 OpMemoryModel Logical GLSL450
600 OpEntryPoint Fragment %main "main" %var1 %var2
601 OpExecutionMode %main OriginUpperLeft
602 OpDecorate %var1 Location 1
603 OpDecorate %var2 Location 1
604 %void = OpTypeVoid
605 %void_fn = OpTypeFunction %void
606 %float = OpTypeFloat 32
607 %struct = OpTypeStruct %float %float
608 %ptr_output_struct = OpTypePointer Output %struct
609 %var1 = OpVariable %ptr_output_struct Output
610 %var2 = OpVariable %ptr_output_struct Output
611 %main = OpFunction %void None %void_fn
612 %entry = OpLabel
613 OpReturn
614 OpFunctionEnd
615 )";
616
617 CompileSuccessfully(text, SPV_ENV_VULKAN_1_0);
618 EXPECT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions(SPV_ENV_VULKAN_1_0));
619 EXPECT_THAT(getDiagnosticString(),
620 AnyVUID("VUID-StandaloneSpirv-OpEntryPoint-08722"));
621 EXPECT_THAT(
622 getDiagnosticString(),
623 HasSubstr("Entry-point has conflicting output location assignment "
624 "at location 1"));
625 }
626
627 TEST_F(ValidateInterfacesTest, VulkanPatchAndNonPatchOverlap) {
628 const std::string text = R"(
629 OpCapability Tessellation
630 OpMemoryModel Logical GLSL450
631 OpEntryPoint TessellationControl %main "main" %a %b
632 OpExecutionMode %main OutputVertices 4
633 OpDecorate %a Location 0
634 OpDecorate %b Patch
635 OpDecorate %b Location 0
636 %void = OpTypeVoid
637 %3 = OpTypeFunction %void
638 %float = OpTypeFloat 32
639 %uint = OpTypeInt 32 0
640 %uint_4 = OpConstant %uint 4
641 %_arr_float_uint_4 = OpTypeArray %float %uint_4
642 %_ptr_Output__arr_float_uint_4 = OpTypePointer Output %_arr_float_uint_4
643 %a = OpVariable %_ptr_Output__arr_float_uint_4 Output
644 %_ptr_Output_float = OpTypePointer Output %float
645 %b = OpVariable %_ptr_Output_float Output
646 %main = OpFunction %void None %3
647 %5 = OpLabel
648 OpReturn
649 OpFunctionEnd
650 )";
651
652 CompileSuccessfully(text, SPV_ENV_VULKAN_1_2);
653 EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_2));
654 }
655
656 TEST_F(ValidateInterfacesTest, VulkanPatchOverlap) {
657 const std::string text = R"(
658 OpCapability Tessellation
659 OpMemoryModel Logical GLSL450
660 OpEntryPoint TessellationControl %main "main" %a %b %c
661 OpExecutionMode %main OutputVertices 4
662 OpDecorate %a Location 0
663 OpDecorate %b Patch
664 OpDecorate %b Location 6
665 OpDecorate %c Patch
666 OpDecorate %c Location 6
667 %void = OpTypeVoid
668 %3 = OpTypeFunction %void
669 %float = OpTypeFloat 32
670 %uint = OpTypeInt 32 0
671 %uint_4 = OpConstant %uint 4
672 %_arr_float_uint_4 = OpTypeArray %float %uint_4
673 %_ptr_Output__arr_float_uint_4 = OpTypePointer Output %_arr_float_uint_4
674 %a = OpVariable %_ptr_Output__arr_float_uint_4 Output
675 %_ptr_Output_float = OpTypePointer Output %float
676 %b = OpVariable %_ptr_Output_float Output
677 %c = OpVariable %_ptr_Output_float Output
678 %main = OpFunction %void None %3
679 %5 = OpLabel
680 OpReturn
681 OpFunctionEnd
682 )";
683
684 CompileSuccessfully(text, SPV_ENV_VULKAN_1_2);
685 EXPECT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions(SPV_ENV_VULKAN_1_2));
686 EXPECT_THAT(getDiagnosticString(),
687 AnyVUID("VUID-StandaloneSpirv-OpEntryPoint-08722"));
688 EXPECT_THAT(getDiagnosticString(),
689 HasSubstr("Entry-point has conflicting output location "
690 "assignment at location 6, component 0"));
691 }
692
693 TEST_F(ValidateInterfacesTest,
694 VulkanLocationsSameLocationInputAndOutputNoConflict) {
695 const std::string text = R"(
696 OpCapability Shader
697 OpMemoryModel Logical GLSL450
698 OpEntryPoint Fragment %main "main" %var1 %var2
699 OpExecutionMode %main OriginUpperLeft
700 OpDecorate %var1 Location 1
701 OpDecorate %var2 Location 1
702 %void = OpTypeVoid
703 %void_fn = OpTypeFunction %void
704 %float = OpTypeFloat 32
705 %struct = OpTypeStruct %float %float
706 %ptr_input_struct = OpTypePointer Input %struct
707 %ptr_output_struct = OpTypePointer Output %struct
708 %var1 = OpVariable %ptr_input_struct Input
709 %var2 = OpVariable %ptr_output_struct Output
710 %main = OpFunction %void None %void_fn
711 %entry = OpLabel
712 OpReturn
713 OpFunctionEnd
714 )";
715
716 CompileSuccessfully(text, SPV_ENV_VULKAN_1_0);
717 EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_0));
718 }
719
720 TEST_F(ValidateInterfacesTest, VulkanLocationsVariableInGap) {
721 const std::string text = R"(
722 OpCapability Shader
723 OpMemoryModel Logical GLSL450
724 OpEntryPoint Fragment %main "main" %var1 %var2
725 OpExecutionMode %main OriginUpperLeft
726 OpDecorate %struct Block
727 OpMemberDecorate %struct 0 Location 0
728 OpMemberDecorate %struct 1 Location 2
729 OpDecorate %var2 Location 1
730 %void = OpTypeVoid
731 %void_fn = OpTypeFunction %void
732 %float = OpTypeFloat 32
733 %struct = OpTypeStruct %float %float
734 %ptr_input_struct = OpTypePointer Input %struct
735 %ptr_input_float = OpTypePointer Input %float
736 %var1 = OpVariable %ptr_input_struct Input
737 %var2 = OpVariable %ptr_input_float Input
738 %main = OpFunction %void None %void_fn
739 %entry = OpLabel
740 OpReturn
741 OpFunctionEnd
742 )";
743
744 CompileSuccessfully(text, SPV_ENV_VULKAN_1_0);
745 EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_0));
746 }
747
748 TEST_F(ValidateInterfacesTest, VulkanLocationsLargeFloatVectorConflict) {
749 const std::string text = R"(
750 OpCapability Shader
751 OpCapability Float64
752 OpMemoryModel Logical GLSL450
753 OpEntryPoint Fragment %main "main" %var1 %var2
754 OpExecutionMode %main OriginUpperLeft
755 OpDecorate %var1 Location 0
756 OpDecorate %var2 Location 1
757 %void = OpTypeVoid
758 %void_fn = OpTypeFunction %void
759 %float = OpTypeFloat 32
760 %double = OpTypeFloat 64
761 %vector = OpTypeVector %double 3
762 %ptr_input_float = OpTypePointer Input %float
763 %ptr_input_vector = OpTypePointer Input %vector
764 %var1 = OpVariable %ptr_input_vector Input
765 %var2 = OpVariable %ptr_input_float Input
766 %main = OpFunction %void None %void_fn
767 %entry = OpLabel
768 OpReturn
769 OpFunctionEnd
770 )";
771
772 CompileSuccessfully(text, SPV_ENV_VULKAN_1_0);
773 EXPECT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions(SPV_ENV_VULKAN_1_0));
774 EXPECT_THAT(getDiagnosticString(),
775 AnyVUID("VUID-StandaloneSpirv-OpEntryPoint-08721"));
776 EXPECT_THAT(getDiagnosticString(),
777 HasSubstr("Entry-point has conflicting input location assignment "
778 "at location 1"));
779 }
780
781 TEST_F(ValidateInterfacesTest, VulkanLocationsLargeIntVectorConflict) {
782 const std::string text = R"(
783 OpCapability Shader
784 OpCapability Int64
785 OpMemoryModel Logical GLSL450
786 OpEntryPoint Fragment %main "main" %var1 %var2
787 OpExecutionMode %main OriginUpperLeft
788 OpDecorate %var1 Location 0
789 OpDecorate %var1 Flat
790 OpDecorate %var2 Location 1
791 OpDecorate %var2 Flat
792 %void = OpTypeVoid
793 %void_fn = OpTypeFunction %void
794 %float = OpTypeFloat 32
795 %long = OpTypeInt 64 0
796 %vector = OpTypeVector %long 4
797 %ptr_input_float = OpTypePointer Input %float
798 %ptr_input_vector = OpTypePointer Input %vector
799 %var1 = OpVariable %ptr_input_vector Input
800 %var2 = OpVariable %ptr_input_float Input
801 %main = OpFunction %void None %void_fn
802 %entry = OpLabel
803 OpReturn
804 OpFunctionEnd
805 )";
806
807 CompileSuccessfully(text, SPV_ENV_VULKAN_1_0);
808 EXPECT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions(SPV_ENV_VULKAN_1_0));
809 EXPECT_THAT(getDiagnosticString(),
810 AnyVUID("VUID-StandaloneSpirv-OpEntryPoint-08721"));
811 EXPECT_THAT(getDiagnosticString(),
812 HasSubstr("Entry-point has conflicting input location assignment "
813 "at location 1"));
814 }
815
816 TEST_F(ValidateInterfacesTest, VulkanLocationsMatrix2x2Conflict) {
817 const std::string text = R"(
818 OpCapability Shader
819 OpMemoryModel Logical GLSL450
820 OpEntryPoint Fragment %main "main" %var1 %var2
821 OpExecutionMode %main OriginUpperLeft
822 OpDecorate %var1 Location 0
823 OpDecorate %var2 Location 1
824 %void = OpTypeVoid
825 %void_fn = OpTypeFunction %void
826 %float = OpTypeFloat 32
827 %vector = OpTypeVector %float 2
828 %matrix = OpTypeMatrix %vector 2
829 %ptr_input_float = OpTypePointer Input %float
830 %ptr_input_matrix = OpTypePointer Input %matrix
831 %var1 = OpVariable %ptr_input_matrix Input
832 %var2 = OpVariable %ptr_input_float Input
833 %main = OpFunction %void None %void_fn
834 %entry = OpLabel
835 OpReturn
836 OpFunctionEnd
837 )";
838
839 CompileSuccessfully(text, SPV_ENV_VULKAN_1_0);
840 EXPECT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions(SPV_ENV_VULKAN_1_0));
841 EXPECT_THAT(getDiagnosticString(),
842 AnyVUID("VUID-StandaloneSpirv-OpEntryPoint-08721"));
843 EXPECT_THAT(getDiagnosticString(),
844 HasSubstr("Entry-point has conflicting input location assignment "
845 "at location 1"));
846 }
847
848 TEST_F(ValidateInterfacesTest, VulkanLocationsMatrix3x3Conflict) {
849 const std::string text = R"(
850 OpCapability Shader
851 OpMemoryModel Logical GLSL450
852 OpEntryPoint Fragment %main "main" %var1 %var2
853 OpExecutionMode %main OriginUpperLeft
854 OpDecorate %var1 Location 0
855 OpDecorate %var2 Location 2
856 %void = OpTypeVoid
857 %void_fn = OpTypeFunction %void
858 %float = OpTypeFloat 32
859 %vector = OpTypeVector %float 3
860 %matrix = OpTypeMatrix %vector 3
861 %ptr_input_float = OpTypePointer Input %float
862 %ptr_input_matrix = OpTypePointer Input %matrix
863 %var1 = OpVariable %ptr_input_matrix Input
864 %var2 = OpVariable %ptr_input_float Input
865 %main = OpFunction %void None %void_fn
866 %entry = OpLabel
867 OpReturn
868 OpFunctionEnd
869 )";
870
871 CompileSuccessfully(text, SPV_ENV_VULKAN_1_0);
872 EXPECT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions(SPV_ENV_VULKAN_1_0));
873 EXPECT_THAT(getDiagnosticString(),
874 AnyVUID("VUID-StandaloneSpirv-OpEntryPoint-08721"));
875 EXPECT_THAT(getDiagnosticString(),
876 HasSubstr("Entry-point has conflicting input location assignment "
877 "at location 2"));
878 }
879
880 TEST_F(ValidateInterfacesTest, VulkanLocationsMatrix4x4Conflict) {
881 const std::string text = R"(
882 OpCapability Shader
883 OpMemoryModel Logical GLSL450
884 OpEntryPoint Fragment %main "main" %var1 %var2
885 OpExecutionMode %main OriginUpperLeft
886 OpDecorate %var1 Location 0
887 OpDecorate %var2 Location 3
888 %void = OpTypeVoid
889 %void_fn = OpTypeFunction %void
890 %float = OpTypeFloat 32
891 %vector = OpTypeVector %float 4
892 %matrix = OpTypeMatrix %vector 4
893 %ptr_input_float = OpTypePointer Input %float
894 %ptr_input_matrix = OpTypePointer Input %matrix
895 %var1 = OpVariable %ptr_input_matrix Input
896 %var2 = OpVariable %ptr_input_float Input
897 %main = OpFunction %void None %void_fn
898 %entry = OpLabel
899 OpReturn
900 OpFunctionEnd
901 )";
902
903 CompileSuccessfully(text, SPV_ENV_VULKAN_1_0);
904 EXPECT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions(SPV_ENV_VULKAN_1_0));
905 EXPECT_THAT(getDiagnosticString(),
906 AnyVUID("VUID-StandaloneSpirv-OpEntryPoint-08721"));
907 EXPECT_THAT(getDiagnosticString(),
908 HasSubstr("Entry-point has conflicting input location assignment "
909 "at location 3"));
910 }
911
912 TEST_F(ValidateInterfacesTest, VulkanLocationsLargeMatrix2x2Conflict) {
913 const std::string text = R"(
914 OpCapability Shader
915 OpCapability Float64
916 OpMemoryModel Logical GLSL450
917 OpEntryPoint Fragment %main "main" %var1 %var2
918 OpExecutionMode %main OriginUpperLeft
919 OpDecorate %var1 Location 0
920 OpDecorate %var2 Location 1
921 %void = OpTypeVoid
922 %void_fn = OpTypeFunction %void
923 %float = OpTypeFloat 32
924 %double = OpTypeFloat 64
925 %vector = OpTypeVector %double 2
926 %matrix = OpTypeMatrix %vector 2
927 %ptr_input_float = OpTypePointer Input %float
928 %ptr_input_matrix = OpTypePointer Input %matrix
929 %var1 = OpVariable %ptr_input_matrix Input
930 %var2 = OpVariable %ptr_input_float Input
931 %main = OpFunction %void None %void_fn
932 %entry = OpLabel
933 OpReturn
934 OpFunctionEnd
935 )";
936
937 CompileSuccessfully(text, SPV_ENV_VULKAN_1_0);
938 EXPECT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions(SPV_ENV_VULKAN_1_0));
939 EXPECT_THAT(getDiagnosticString(),
940 AnyVUID("VUID-StandaloneSpirv-OpEntryPoint-08721"));
941 EXPECT_THAT(getDiagnosticString(),
942 HasSubstr("Entry-point has conflicting input location assignment "
943 "at location 1"));
944 }
945
946 TEST_F(ValidateInterfacesTest, VulkanLocationsLargeMatrix3x3Conflict) {
947 const std::string text = R"(
948 OpCapability Shader
949 OpCapability Float64
950 OpMemoryModel Logical GLSL450
951 OpEntryPoint Fragment %main "main" %var1 %var2
952 OpExecutionMode %main OriginUpperLeft
953 OpDecorate %var1 Location 0
954 OpDecorate %var2 Location 5
955 %void = OpTypeVoid
956 %void_fn = OpTypeFunction %void
957 %float = OpTypeFloat 32
958 %double = OpTypeFloat 64
959 %vector = OpTypeVector %double 3
960 %matrix = OpTypeMatrix %vector 3
961 %ptr_input_float = OpTypePointer Input %float
962 %ptr_input_matrix = OpTypePointer Input %matrix
963 %var1 = OpVariable %ptr_input_matrix Input
964 %var2 = OpVariable %ptr_input_float Input
965 %main = OpFunction %void None %void_fn
966 %entry = OpLabel
967 OpReturn
968 OpFunctionEnd
969 )";
970
971 CompileSuccessfully(text, SPV_ENV_VULKAN_1_0);
972 EXPECT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions(SPV_ENV_VULKAN_1_0));
973 EXPECT_THAT(getDiagnosticString(),
974 AnyVUID("VUID-StandaloneSpirv-OpEntryPoint-08721"));
975 EXPECT_THAT(getDiagnosticString(),
976 HasSubstr("Entry-point has conflicting input location assignment "
977 "at location 5"));
978 }
979
980 TEST_F(ValidateInterfacesTest, VulkanLocationsLargeMatrix4x4Conflict) {
981 const std::string text = R"(
982 OpCapability Shader
983 OpCapability Float64
984 OpMemoryModel Logical GLSL450
985 OpEntryPoint Fragment %main "main" %var1 %var2
986 OpExecutionMode %main OriginUpperLeft
987 OpDecorate %var1 Location 0
988 OpDecorate %var2 Location 7
989 %void = OpTypeVoid
990 %void_fn = OpTypeFunction %void
991 %float = OpTypeFloat 32
992 %double = OpTypeFloat 64
993 %vector = OpTypeVector %double 4
994 %matrix = OpTypeMatrix %vector 4
995 %ptr_input_float = OpTypePointer Input %float
996 %ptr_input_matrix = OpTypePointer Input %matrix
997 %var1 = OpVariable %ptr_input_matrix Input
998 %var2 = OpVariable %ptr_input_float Input
999 %main = OpFunction %void None %void_fn
1000 %entry = OpLabel
1001 OpReturn
1002 OpFunctionEnd
1003 )";
1004
1005 CompileSuccessfully(text, SPV_ENV_VULKAN_1_0);
1006 EXPECT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions(SPV_ENV_VULKAN_1_0));
1007 EXPECT_THAT(getDiagnosticString(),
1008 AnyVUID("VUID-StandaloneSpirv-OpEntryPoint-08721"));
1009 EXPECT_THAT(getDiagnosticString(),
1010 HasSubstr("Entry-point has conflicting input location assignment "
1011 "at location 7"));
1012 }
1013
1014 TEST_F(ValidateInterfacesTest, VulkanLocationsArray2Conflict) {
1015 const std::string text = R"(
1016 OpCapability Shader
1017 OpMemoryModel Logical GLSL450
1018 OpEntryPoint Fragment %main "main" %var1 %var2
1019 OpExecutionMode %main OriginUpperLeft
1020 OpDecorate %var1 Location 0
1021 OpDecorate %var2 Location 1
1022 %void = OpTypeVoid
1023 %void_fn = OpTypeFunction %void
1024 %float = OpTypeFloat 32
1025 %int = OpTypeInt 32 0
1026 %int_2 = OpConstant %int 2
1027 %array = OpTypeArray %int %int_2
1028 %struct = OpTypeStruct %array
1029 %ptr_input_float = OpTypePointer Input %float
1030 %ptr_input_struct = OpTypePointer Input %struct
1031 %var1 = OpVariable %ptr_input_struct Input
1032 %var2 = OpVariable %ptr_input_float Input
1033 %main = OpFunction %void None %void_fn
1034 %entry = OpLabel
1035 OpReturn
1036 OpFunctionEnd
1037 )";
1038
1039 CompileSuccessfully(text, SPV_ENV_VULKAN_1_0);
1040 EXPECT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions(SPV_ENV_VULKAN_1_0));
1041 EXPECT_THAT(getDiagnosticString(),
1042 AnyVUID("VUID-StandaloneSpirv-OpEntryPoint-08721"));
1043 EXPECT_THAT(getDiagnosticString(),
1044 HasSubstr("Entry-point has conflicting input location assignment "
1045 "at location 1"));
1046 }
1047
1048 TEST_F(ValidateInterfacesTest, VulkanLocationsArray4Conflict) {
1049 const std::string text = R"(
1050 OpCapability Shader
1051 OpMemoryModel Logical GLSL450
1052 OpEntryPoint Fragment %main "main" %var1 %var2
1053 OpExecutionMode %main OriginUpperLeft
1054 OpDecorate %var1 Location 0
1055 OpDecorate %var2 Location 3
1056 %void = OpTypeVoid
1057 %void_fn = OpTypeFunction %void
1058 %float = OpTypeFloat 32
1059 %int = OpTypeInt 32 0
1060 %int_4 = OpConstant %int 4
1061 %array = OpTypeArray %int %int_4
1062 %struct = OpTypeStruct %array
1063 %ptr_input_float = OpTypePointer Input %float
1064 %ptr_input_struct = OpTypePointer Input %struct
1065 %var1 = OpVariable %ptr_input_struct Input
1066 %var2 = OpVariable %ptr_input_float Input
1067 %main = OpFunction %void None %void_fn
1068 %entry = OpLabel
1069 OpReturn
1070 OpFunctionEnd
1071 )";
1072
1073 CompileSuccessfully(text, SPV_ENV_VULKAN_1_0);
1074 EXPECT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions(SPV_ENV_VULKAN_1_0));
1075 EXPECT_THAT(getDiagnosticString(),
1076 AnyVUID("VUID-StandaloneSpirv-OpEntryPoint-08721"));
1077 EXPECT_THAT(getDiagnosticString(),
1078 HasSubstr("Entry-point has conflicting input location assignment "
1079 "at location 3"));
1080 }
1081
1082 TEST_F(ValidateInterfacesTest, VulkanLocationsMatrix4x4Array4Conflict) {
1083 const std::string text = R"(
1084 OpCapability Shader
1085 OpMemoryModel Logical GLSL450
1086 OpEntryPoint Fragment %main "main" %var1 %var2
1087 OpExecutionMode %main OriginUpperLeft
1088 OpDecorate %var1 Location 0
1089 OpDecorate %var2 Location 15
1090 %void = OpTypeVoid
1091 %void_fn = OpTypeFunction %void
1092 %float = OpTypeFloat 32
1093 %int = OpTypeInt 32 0
1094 %int_4 = OpConstant %int 4
1095 %vector = OpTypeVector %float 4
1096 %matrix = OpTypeMatrix %vector 4
1097 %array = OpTypeArray %matrix %int_4
1098 %struct = OpTypeStruct %array
1099 %ptr_input_float = OpTypePointer Input %float
1100 %ptr_input_struct = OpTypePointer Input %struct
1101 %var1 = OpVariable %ptr_input_struct Input
1102 %var2 = OpVariable %ptr_input_float Input
1103 %main = OpFunction %void None %void_fn
1104 %entry = OpLabel
1105 OpReturn
1106 OpFunctionEnd
1107 )";
1108
1109 CompileSuccessfully(text, SPV_ENV_VULKAN_1_0);
1110 EXPECT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions(SPV_ENV_VULKAN_1_0));
1111 EXPECT_THAT(getDiagnosticString(),
1112 AnyVUID("VUID-StandaloneSpirv-OpEntryPoint-08721"));
1113 EXPECT_THAT(getDiagnosticString(),
1114 HasSubstr("Entry-point has conflicting input location assignment "
1115 "at location 15"));
1116 }
1117
1118 TEST_F(ValidateInterfacesTest, VulkanLocationsComponentDisambiguates) {
1119 const std::string text = R"(
1120 OpCapability Shader
1121 OpMemoryModel Logical GLSL450
1122 OpEntryPoint Fragment %main "main" %var1
1123 OpExecutionMode %main OriginUpperLeft
1124 OpDecorate %struct Block
1125 OpMemberDecorate %struct 0 Location 0
1126 OpMemberDecorate %struct 0 Component 0
1127 OpMemberDecorate %struct 1 Location 0
1128 OpMemberDecorate %struct 1 Component 1
1129 %void = OpTypeVoid
1130 %void_fn = OpTypeFunction %void
1131 %float = OpTypeFloat 32
1132 %struct = OpTypeStruct %float %float
1133 %ptr_input_struct = OpTypePointer Input %struct
1134 %var1 = OpVariable %ptr_input_struct Input
1135 %main = OpFunction %void None %void_fn
1136 %entry = OpLabel
1137 OpReturn
1138 OpFunctionEnd
1139 )";
1140
1141 CompileSuccessfully(text, SPV_ENV_VULKAN_1_0);
1142 EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_0));
1143 }
1144
1145 TEST_F(ValidateInterfacesTest, VulkanLocationsComponentIn64BitVec3) {
1146 const std::string text = R"(
1147 OpCapability Shader
1148 OpCapability Float64
1149 OpMemoryModel Logical GLSL450
1150 OpEntryPoint Fragment %main "main" %var
1151 OpExecutionMode %main OriginUpperLeft
1152 OpDecorate %struct Block
1153 OpMemberDecorate %struct 0 Location 0
1154 OpMemberDecorate %struct 1 Location 1
1155 OpMemberDecorate %struct 1 Component 1
1156 %void = OpTypeVoid
1157 %void_fn = OpTypeFunction %void
1158 %float = OpTypeFloat 32
1159 %double = OpTypeFloat 64
1160 %double3 = OpTypeVector %double 3
1161 %struct = OpTypeStruct %double3 %float
1162 %ptr_input_struct = OpTypePointer Input %struct
1163 %var = OpVariable %ptr_input_struct Input
1164 %main = OpFunction %void None %void_fn
1165 %entry = OpLabel
1166 OpReturn
1167 OpFunctionEnd
1168 )";
1169
1170 CompileSuccessfully(text, SPV_ENV_VULKAN_1_0);
1171 EXPECT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions(SPV_ENV_VULKAN_1_0));
1172 EXPECT_THAT(getDiagnosticString(),
1173 AnyVUID("VUID-StandaloneSpirv-OpEntryPoint-08721"));
1174 EXPECT_THAT(getDiagnosticString(),
1175 HasSubstr("Entry-point has conflicting input location assignment "
1176 "at location 1, component 1"));
1177 }
1178
1179 TEST_F(ValidateInterfacesTest, VulkanLocationsComponentAfter64BitVec3) {
1180 const std::string text = R"(
1181 OpCapability Shader
1182 OpCapability Float64
1183 OpMemoryModel Logical GLSL450
1184 OpEntryPoint Fragment %main "main" %var
1185 OpExecutionMode %main OriginUpperLeft
1186 OpDecorate %struct Block
1187 OpMemberDecorate %struct 0 Location 0
1188 OpMemberDecorate %struct 1 Location 1
1189 OpMemberDecorate %struct 1 Component 2
1190 %void = OpTypeVoid
1191 %void_fn = OpTypeFunction %void
1192 %float = OpTypeFloat 32
1193 %double = OpTypeFloat 64
1194 %double3 = OpTypeVector %double 3
1195 %struct = OpTypeStruct %double3 %float
1196 %ptr_input_struct = OpTypePointer Input %struct
1197 %var = OpVariable %ptr_input_struct Input
1198 %main = OpFunction %void None %void_fn
1199 %entry = OpLabel
1200 OpReturn
1201 OpFunctionEnd
1202 )";
1203
1204 CompileSuccessfully(text, SPV_ENV_VULKAN_1_0);
1205 EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_0));
1206 }
1207
1208 TEST_F(ValidateInterfacesTest, VulkanLocationsConflictingComponentVariable) {
1209 const std::string text = R"(
1210 OpCapability Shader
1211 OpMemoryModel Logical GLSL450
1212 OpEntryPoint Fragment %main "main" %var
1213 OpExecutionMode %main OriginUpperLeft
1214 OpDecorate %var Location 0
1215 OpDecorate %var Component 0
1216 OpDecorate %var Component 1
1217 %void = OpTypeVoid
1218 %void_fn = OpTypeFunction %void
1219 %float = OpTypeFloat 32
1220 %ptr_input_float = OpTypePointer Input %float
1221 %var = OpVariable %ptr_input_float Input
1222 %main = OpFunction %void None %void_fn
1223 %entry = OpLabel
1224 OpReturn
1225 OpFunctionEnd
1226 )";
1227
1228 CompileSuccessfully(text, SPV_ENV_VULKAN_1_0);
1229 EXPECT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions(SPV_ENV_VULKAN_1_0));
1230 EXPECT_THAT(
1231 getDiagnosticString(),
1232 HasSubstr("decorated with Component multiple times is not allowed"));
1233 }
1234
1235 TEST_F(ValidateInterfacesTest,
1236 VulkanLocationsConflictingComponentStructMember) {
1237 const std::string text = R"(
1238 OpCapability Shader
1239 OpMemoryModel Logical GLSL450
1240 OpEntryPoint Fragment %main "main" %var
1241 OpExecutionMode %main OriginUpperLeft
1242 OpDecorate %struct Block
1243 OpMemberDecorate %struct 0 Location 0
1244 OpMemberDecorate %struct 0 Component 0
1245 OpMemberDecorate %struct 0 Component 1
1246 %void = OpTypeVoid
1247 %void_fn = OpTypeFunction %void
1248 %float = OpTypeFloat 32
1249 %struct = OpTypeStruct %float
1250 %ptr_input_struct = OpTypePointer Input %struct
1251 %var = OpVariable %ptr_input_struct Input
1252 %main = OpFunction %void None %void_fn
1253 %entry = OpLabel
1254 OpReturn
1255 OpFunctionEnd
1256 )";
1257
1258 CompileSuccessfully(text, SPV_ENV_VULKAN_1_0);
1259 EXPECT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions(SPV_ENV_VULKAN_1_0));
1260 EXPECT_THAT(
1261 getDiagnosticString(),
1262 HasSubstr("decorated with Component multiple times is not allowed"));
1263 }
1264
1265 TEST_F(ValidateInterfacesTest, VulkanLocationsVariableConflictOutputIndex1) {
1266 const std::string text = R"(
1267 OpCapability Shader
1268 OpMemoryModel Logical GLSL450
1269 OpEntryPoint Fragment %main "main" %var1 %var2
1270 OpExecutionMode %main OriginUpperLeft
1271 OpDecorate %var1 Location 1
1272 OpDecorate %var1 Index 1
1273 OpDecorate %var2 Location 1
1274 OpDecorate %var2 Index 1
1275 %void = OpTypeVoid
1276 %void_fn = OpTypeFunction %void
1277 %float = OpTypeFloat 32
1278 %struct = OpTypeStruct %float %float
1279 %ptr_output_struct = OpTypePointer Output %struct
1280 %var1 = OpVariable %ptr_output_struct Output
1281 %var2 = OpVariable %ptr_output_struct Output
1282 %main = OpFunction %void None %void_fn
1283 %entry = OpLabel
1284 OpReturn
1285 OpFunctionEnd
1286 )";
1287
1288 CompileSuccessfully(text, SPV_ENV_VULKAN_1_0);
1289 EXPECT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions(SPV_ENV_VULKAN_1_0));
1290 EXPECT_THAT(getDiagnosticString(),
1291 AnyVUID("VUID-StandaloneSpirv-OpEntryPoint-08722"));
1292 EXPECT_THAT(
1293 getDiagnosticString(),
1294 HasSubstr("Entry-point has conflicting output location assignment "
1295 "at location 1"));
1296 }
1297
1298 TEST_F(ValidateInterfacesTest,
1299 VulkanLocationsVariableNoConflictDifferentIndex) {
1300 const std::string text = R"(
1301 OpCapability Shader
1302 OpMemoryModel Logical GLSL450
1303 OpEntryPoint Fragment %main "main" %var1 %var2
1304 OpExecutionMode %main OriginUpperLeft
1305 OpDecorate %var1 Location 1
1306 OpDecorate %var1 Index 0
1307 OpDecorate %var2 Location 1
1308 OpDecorate %var2 Index 1
1309 %void = OpTypeVoid
1310 %void_fn = OpTypeFunction %void
1311 %float = OpTypeFloat 32
1312 %struct = OpTypeStruct %float %float
1313 %ptr_output_struct = OpTypePointer Output %struct
1314 %var1 = OpVariable %ptr_output_struct Output
1315 %var2 = OpVariable %ptr_output_struct Output
1316 %main = OpFunction %void None %void_fn
1317 %entry = OpLabel
1318 OpReturn
1319 OpFunctionEnd
1320 )";
1321
1322 CompileSuccessfully(text, SPV_ENV_VULKAN_1_0);
1323 EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_0));
1324 }
1325
1326 TEST_F(ValidateInterfacesTest, VulkanLocationsIndexGLCompute) {
1327 const std::string text = R"(
1328 OpCapability Shader
1329 OpCapability Geometry
1330 OpMemoryModel Logical GLSL450
1331 OpEntryPoint Geometry %main "main" %var1
1332 OpExecutionMode %main Triangles
1333 OpExecutionMode %main OutputPoints
1334 OpDecorate %var1 Location 1
1335 OpDecorate %var1 Index 1
1336 %void = OpTypeVoid
1337 %void_fn = OpTypeFunction %void
1338 %float = OpTypeFloat 32
1339 %struct = OpTypeStruct %float %float
1340 %ptr_output_struct = OpTypePointer Output %struct
1341 %var1 = OpVariable %ptr_output_struct Output
1342 %main = OpFunction %void None %void_fn
1343 %entry = OpLabel
1344 OpReturn
1345 OpFunctionEnd
1346 )";
1347
1348 CompileSuccessfully(text, SPV_ENV_VULKAN_1_0);
1349 EXPECT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions(SPV_ENV_VULKAN_1_0));
1350 EXPECT_THAT(
1351 getDiagnosticString(),
1352 HasSubstr("Index can only be applied to Fragment output variables"));
1353 }
1354
1355 TEST_F(ValidateInterfacesTest, VulkanLocationsIndexInput) {
1356 const std::string text = R"(
1357 OpCapability Shader
1358 OpMemoryModel Logical GLSL450
1359 OpEntryPoint Fragment %main "main" %var1
1360 OpExecutionMode %main OriginUpperLeft
1361 OpDecorate %var1 Location 1
1362 OpDecorate %var1 Index 1
1363 %void = OpTypeVoid
1364 %void_fn = OpTypeFunction %void
1365 %float = OpTypeFloat 32
1366 %struct = OpTypeStruct %float %float
1367 %ptr_input_struct = OpTypePointer Input %struct
1368 %var1 = OpVariable %ptr_input_struct Input
1369 %main = OpFunction %void None %void_fn
1370 %entry = OpLabel
1371 OpReturn
1372 OpFunctionEnd
1373 )";
1374
1375 CompileSuccessfully(text, SPV_ENV_VULKAN_1_0);
1376 EXPECT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions(SPV_ENV_VULKAN_1_0));
1377 EXPECT_THAT(getDiagnosticString(),
1378 HasSubstr("must be in the Output storage class"));
1379 }
1380
1381 TEST_F(ValidateInterfacesTest, VulkanLocationsArrayWithComponent) {
1382 const std::string text = R"(
1383 OpCapability Shader
1384 OpMemoryModel Logical GLSL450
1385 OpEntryPoint Fragment %4 "main" %11 %18 %28 %36 %40
1386 OpExecutionMode %4 OriginUpperLeft
1387 OpDecorate %11 Location 0
1388 OpDecorate %18 Component 0
1389 OpDecorate %18 Location 0
1390 OpDecorate %28 Component 1
1391 OpDecorate %28 Location 0
1392 OpDecorate %36 Location 1
1393 OpDecorate %40 Component 0
1394 OpDecorate %40 Location 1
1395 %void = OpTypeVoid
1396 %3 = OpTypeFunction %void
1397 %float = OpTypeFloat 32
1398 %v4float = OpTypeVector %float 4
1399 %_ptr_Input_v4float = OpTypePointer Input %v4float
1400 %11 = OpVariable %_ptr_Input_v4float Input
1401 %_ptr_Output_float = OpTypePointer Output %float
1402 %18 = OpVariable %_ptr_Output_float Output
1403 %uint = OpTypeInt 32 0
1404 %v3float = OpTypeVector %float 3
1405 %uint_2 = OpConstant %uint 2
1406 %_arr_v3float_uint_2 = OpTypeArray %v3float %uint_2
1407 %_ptr_Output__arr_v3float_uint_2 = OpTypePointer Output %_arr_v3float_uint_2
1408 %28 = OpVariable %_ptr_Output__arr_v3float_uint_2 Output
1409 %_ptr_Output_v3float = OpTypePointer Output %v3float
1410 %36 = OpVariable %_ptr_Input_v4float Input
1411 %40 = OpVariable %_ptr_Output_float Output
1412 %4 = OpFunction %void None %3
1413 %5 = OpLabel
1414 OpReturn
1415 OpFunctionEnd
1416 )";
1417
1418 CompileSuccessfully(text, SPV_ENV_VULKAN_1_0);
1419 EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_0));
1420 }
1421
1422 TEST_F(ValidateInterfacesTest, VulkanLocationsArrayWithComponentBad) {
1423 const std::string text = R"(
1424 OpCapability Shader
1425 OpMemoryModel Logical GLSL450
1426 OpEntryPoint Fragment %4 "main" %11 %18 %28 %36 %40
1427 OpExecutionMode %4 OriginUpperLeft
1428 OpDecorate %11 Location 0
1429 OpDecorate %18 Component 0
1430 OpDecorate %18 Location 0
1431 OpDecorate %28 Component 1
1432 OpDecorate %28 Location 0
1433 OpDecorate %36 Location 1
1434 OpDecorate %40 Component 1
1435 OpDecorate %40 Location 1
1436 %void = OpTypeVoid
1437 %3 = OpTypeFunction %void
1438 %float = OpTypeFloat 32
1439 %v4float = OpTypeVector %float 4
1440 %_ptr_Input_v4float = OpTypePointer Input %v4float
1441 %11 = OpVariable %_ptr_Input_v4float Input
1442 %_ptr_Output_float = OpTypePointer Output %float
1443 %18 = OpVariable %_ptr_Output_float Output
1444 %uint = OpTypeInt 32 0
1445 %v3float = OpTypeVector %float 3
1446 %uint_2 = OpConstant %uint 2
1447 %_arr_v3float_uint_2 = OpTypeArray %v3float %uint_2
1448 %_ptr_Output__arr_v3float_uint_2 = OpTypePointer Output %_arr_v3float_uint_2
1449 %28 = OpVariable %_ptr_Output__arr_v3float_uint_2 Output
1450 %_ptr_Output_v3float = OpTypePointer Output %v3float
1451 %36 = OpVariable %_ptr_Input_v4float Input
1452 %40 = OpVariable %_ptr_Output_float Output
1453 %4 = OpFunction %void None %3
1454 %5 = OpLabel
1455 OpReturn
1456 OpFunctionEnd
1457 )";
1458
1459 CompileSuccessfully(text, SPV_ENV_VULKAN_1_0);
1460 EXPECT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions(SPV_ENV_VULKAN_1_0));
1461 EXPECT_THAT(getDiagnosticString(),
1462 AnyVUID("VUID-StandaloneSpirv-OpEntryPoint-08722"));
1463 EXPECT_THAT(getDiagnosticString(),
1464 HasSubstr("Entry-point has conflicting output location "
1465 "assignment at location 1, component 1"));
1466 }
1467
1468 TEST_F(ValidateInterfacesTest, VulkanLocationsLargeLocation) {
1469 const std::string text = R"(
1470 OpCapability Shader
1471 OpMemoryModel Logical GLSL450
1472 OpEntryPoint Fragment %4 "????????" %17
1473 OpExecutionMode %4 OriginUpperLeft
1474 OpDecorate %17 Location 4227868160
1475 %void = OpTypeVoid
1476 %3 = OpTypeFunction %void
1477 %float = OpTypeFloat 32
1478 %v3float = OpTypeVector %float 3
1479 %_ptr_Input_v3float = OpTypePointer Input %v3float
1480 %17 = OpVariable %_ptr_Input_v3float Input
1481 %4 = OpFunction %void None %3
1482 %5 = OpLabel
1483 OpUnreachable
1484 OpFunctionEnd
1485 )";
1486
1487 CompileSuccessfully(text, SPV_ENV_VULKAN_1_0);
1488 EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_0));
1489 }
1490
1491 TEST_F(ValidateInterfacesTest, VulkanLocationMeshShader) {
1492 const std::string text = R"(
1493 OpCapability Shader
1494 OpCapability MeshShadingNV
1495 OpExtension "SPV_NV_mesh_shader"
1496 OpMemoryModel Logical GLSL450
1497 OpEntryPoint MeshNV %foo "foo" %in
1498 OpExecutionMode %foo LocalSize 1 1 1
1499 OpDecorate %block Block
1500 OpMemberDecorate %block 0 PerTaskNV
1501 OpMemberDecorate %block 0 Offset 0
1502 %void = OpTypeVoid
1503 %int = OpTypeInt 32 0
1504 %int_32 = OpConstant %int 32
1505 %array = OpTypeArray %int %int_32
1506 %block = OpTypeStruct %array
1507 %ptr_input_block = OpTypePointer Input %block
1508 %in = OpVariable %ptr_input_block Input
1509 %void_fn = OpTypeFunction %void
1510 %foo = OpFunction %void None %void_fn
1511 %entry = OpLabel
1512 OpReturn
1513 OpFunctionEnd
1514 )";
1515
1516 CompileSuccessfully(text, SPV_ENV_VULKAN_1_2);
1517 EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_2));
1518 }
1519
1520 TEST_F(ValidateInterfacesTest, VulkanLocationArrayWithComponent1) {
1521 const std::string text = R"(
1522 OpCapability Shader
1523 OpMemoryModel Logical GLSL450
1524 OpEntryPoint Fragment %main "main" %in
1525 OpExecutionMode %main OriginUpperLeft
1526 OpDecorate %struct Block
1527 OpMemberDecorate %struct 0 Location 0
1528 OpMemberDecorate %struct 0 Component 0
1529 OpMemberDecorate %struct 1 Location 0
1530 OpMemberDecorate %struct 1 Component 1
1531 %void = OpTypeVoid
1532 %void_fn = OpTypeFunction %void
1533 %float = OpTypeFloat 32
1534 %int = OpTypeInt 32 0
1535 %int_2 = OpConstant %int 2
1536 %float_arr = OpTypeArray %float %int_2
1537 %struct = OpTypeStruct %float_arr %float_arr
1538 %ptr = OpTypePointer Input %struct
1539 %in = OpVariable %ptr Input
1540 %main = OpFunction %void None %void_fn
1541 %entry = OpLabel
1542 OpReturn
1543 OpFunctionEnd
1544 )";
1545
1546 CompileSuccessfully(text, SPV_ENV_VULKAN_1_0);
1547 EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_0));
1548 }
1549
1550 TEST_F(ValidateInterfacesTest, VulkanLocationArrayWithComponent2) {
1551 const std::string text = R"(
1552 OpCapability Shader
1553 OpCapability Float64
1554 OpMemoryModel Logical GLSL450
1555 OpEntryPoint Fragment %main "main" %in
1556 OpExecutionMode %main OriginUpperLeft
1557 OpDecorate %struct Block
1558 OpMemberDecorate %struct 0 Location 0
1559 OpMemberDecorate %struct 0 Component 0
1560 OpMemberDecorate %struct 1 Location 0
1561 OpMemberDecorate %struct 1 Component 2
1562 %void = OpTypeVoid
1563 %void_fn = OpTypeFunction %void
1564 %float = OpTypeFloat 32
1565 %double = OpTypeFloat 64
1566 %int = OpTypeInt 32 0
1567 %int_2 = OpConstant %int 2
1568 %double_arr = OpTypeArray %double %int_2
1569 %struct = OpTypeStruct %float %double_arr
1570 %ptr = OpTypePointer Input %struct
1571 %in = OpVariable %ptr Input
1572 %main = OpFunction %void None %void_fn
1573 %entry = OpLabel
1574 OpReturn
1575 OpFunctionEnd
1576 )";
1577
1578 CompileSuccessfully(text, SPV_ENV_VULKAN_1_0);
1579 EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_0));
1580 }
1581
1582 TEST_F(ValidateInterfacesTest, DuplicateInterfaceVariableSuccess) {
1583 const std::string text = R"(
1584 OpCapability Shader
1585 OpMemoryModel Logical GLSL450
1586 OpEntryPoint Fragment %main "main" %in %out %in
1587 OpExecutionMode %main OriginUpperLeft
1588 OpDecorate %in Location 0
1589 OpDecorate %out Location 0
1590 %void = OpTypeVoid
1591 %float = OpTypeFloat 32
1592 %in_ptr = OpTypePointer Input %float
1593 %out_ptr = OpTypePointer Output %float
1594 %in = OpVariable %in_ptr Input
1595 %out = OpVariable %out_ptr Output
1596 %void_fn = OpTypeFunction %void
1597 %main = OpFunction %void None %void_fn
1598 %entry = OpLabel
1599 OpReturn
1600 OpFunctionEnd
1601 )";
1602
1603 CompileSuccessfully(text, SPV_ENV_VULKAN_1_0);
1604 EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_0));
1605 }
1606
1607 TEST_F(ValidateInterfacesTest, StructWithBuiltinsMissingBlock_Bad) {
1608 // See https://github.com/KhronosGroup/SPIRV-Registry/issues/134
1609 //
1610 // When a shader input or output is a struct that does not have Block,
1611 // then it must have a Location.
1612 // But BuiltIns must not have locations.
1613 const std::string text = R"(
1614 OpCapability Shader
1615 OpMemoryModel Logical GLSL450
1616 OpEntryPoint Fragment %main "main" %in
1617 OpExecutionMode %main OriginUpperLeft
1618 ; %struct needs a Block decoration
1619 OpMemberDecorate %struct 0 BuiltIn Position
1620 %void = OpTypeVoid
1621 %float = OpTypeFloat 32
1622 %v4float = OpTypeVector %float 4
1623 %struct = OpTypeStruct %v4float
1624 %in_ptr = OpTypePointer Input %struct
1625 %in = OpVariable %in_ptr Input
1626 %void_fn = OpTypeFunction %void
1627 %main = OpFunction %void None %void_fn
1628 %entry = OpLabel
1629 OpReturn
1630 OpFunctionEnd
1631 )";
1632
1633 CompileSuccessfully(text, SPV_ENV_VULKAN_1_0);
1634 EXPECT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions(SPV_ENV_VULKAN_1_0));
1635 EXPECT_THAT(getDiagnosticString(),
1636 AnyVUID("VUID-StandaloneSpirv-Location-04919"));
1637 EXPECT_THAT(
1638 getDiagnosticString(),
1639 HasSubstr(
1640 "Interface struct has no Block decoration but has BuiltIn members."));
1641 }
1642
1643 TEST_F(ValidateInterfacesTest, InvalidLocationTypePointer) {
1644 const std::string text = R"(
1645 OpCapability Shader
1646 OpMemoryModel Logical Simple
1647 OpEntryPoint Vertex %1 "Aiqn0" %2 %3
1648 OpDecorate %2 Location 0
1649 %void = OpTypeVoid
1650 %5 = OpTypeFunction %void
1651 %float = OpTypeFloat 32
1652 %_ptr_Private_void = OpTypePointer Private %void
1653 %uint = OpTypeInt 32 0
1654 %uint_4278132784 = OpConstant %uint 4278132784
1655 %_arr__ptr_Private_void_uint_4278132784 = OpTypeArray %_ptr_Private_void %uint_4278132784
1656 %_ptr_Output__arr__ptr_Private_void_uint_4278132784 = OpTypePointer Output %_arr__ptr_Private_void_uint_4278132784
1657 %2 = OpVariable %_ptr_Output__arr__ptr_Private_void_uint_4278132784 Output
1658 %_ptr_Output__ptr_Private_void = OpTypePointer Output %_ptr_Private_void
1659 %3 = OpVariable %_ptr_Output__arr__ptr_Private_void_uint_4278132784 Output
1660 %1 = OpFunction %void None %5
1661 %15 = OpLabel
1662 OpReturn
1663 OpFunctionEnd
1664 )";
1665
1666 CompileSuccessfully(text, SPV_ENV_VULKAN_1_1);
1667 EXPECT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions(SPV_ENV_VULKAN_1_1));
1668 EXPECT_THAT(getDiagnosticString(),
1669 HasSubstr("Invalid type to assign a location"));
1670 }
1671
1672 TEST_F(ValidateInterfacesTest, PhysicalStorageBufferPointer) {
1673 const std::string text = R"(
1674 OpCapability Shader
1675 OpCapability PhysicalStorageBufferAddresses
1676 OpMemoryModel PhysicalStorageBuffer64 GLSL450
1677 OpEntryPoint Vertex %main "main" %var
1678 OpDecorate %var Location 0
1679 OpDecorate %var RestrictPointer
1680 %void = OpTypeVoid
1681 %uint = OpTypeInt 32 0
1682 %psb_ptr = OpTypePointer PhysicalStorageBuffer %uint
1683 %in_ptr = OpTypePointer Input %psb_ptr
1684 %var = OpVariable %in_ptr Input
1685 %void_fn = OpTypeFunction %void
1686 %main = OpFunction %void None %void_fn
1687 %entry = OpLabel
1688 OpReturn
1689 OpFunctionEnd
1690 )";
1691 CompileSuccessfully(text, SPV_ENV_VULKAN_1_3);
1692 EXPECT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions(SPV_ENV_VULKAN_1_3));
1693 EXPECT_THAT(getDiagnosticString(),
1694 AnyVUID("VUID-StandaloneSpirv-Input-09557"));
1695 EXPECT_THAT(getDiagnosticString(),
1696 HasSubstr("Input/Output interface variable id <2> contains a "
1697 "PhysicalStorageBuffer pointer, which is not allowed"));
1698 }
1699
1700 TEST_F(ValidateInterfacesTest, PhysicalStorageBufferPointerArray) {
1701 const std::string text = R"(
1702 OpCapability Shader
1703 OpCapability PhysicalStorageBufferAddresses
1704 OpMemoryModel PhysicalStorageBuffer64 GLSL450
1705 OpEntryPoint Vertex %main "main" %var
1706 OpDecorate %var Location 0
1707 OpDecorate %var RestrictPointer
1708 %void = OpTypeVoid
1709 %uint = OpTypeInt 32 0
1710 %uint_3 = OpConstant %uint 3
1711 %psb_ptr = OpTypePointer PhysicalStorageBuffer %uint
1712 %array = OpTypeArray %psb_ptr %uint_3
1713 %in_ptr = OpTypePointer Input %array
1714 %var = OpVariable %in_ptr Input
1715 %void_fn = OpTypeFunction %void
1716 %main = OpFunction %void None %void_fn
1717 %entry = OpLabel
1718 OpReturn
1719 OpFunctionEnd
1720 )";
1721 CompileSuccessfully(text, SPV_ENV_VULKAN_1_3);
1722 EXPECT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions(SPV_ENV_VULKAN_1_3));
1723 EXPECT_THAT(getDiagnosticString(),
1724 AnyVUID("VUID-StandaloneSpirv-Input-09557"));
1725 EXPECT_THAT(getDiagnosticString(),
1726 HasSubstr("Input/Output interface variable id <2> contains a "
1727 "PhysicalStorageBuffer pointer, which is not allowed"));
1728 }
1729 TEST_F(ValidateInterfacesTest, PhysicalStorageBufferPointerStruct) {
1730 const std::string text = R"(
1731 OpCapability Shader
1732 OpCapability PhysicalStorageBufferAddresses
1733 OpMemoryModel PhysicalStorageBuffer64 GLSL450
1734 OpEntryPoint Vertex %main "main" %var
1735 OpDecorate %var Location 0
1736 OpDecorate %var RestrictPointer
1737 %void = OpTypeVoid
1738 %int = OpTypeInt 32 1
1739 OpTypeForwardPointer %psb_ptr PhysicalStorageBuffer
1740 %struct_0 = OpTypeStruct %int %psb_ptr
1741 %struct_1 = OpTypeStruct %int %int
1742 %psb_ptr = OpTypePointer PhysicalStorageBuffer %struct_1
1743 %in_ptr = OpTypePointer Input %struct_0
1744 %var = OpVariable %in_ptr Input
1745 %void_fn = OpTypeFunction %void
1746 %main = OpFunction %void None %void_fn
1747 %entry = OpLabel
1748 OpReturn
1749 OpFunctionEnd
1750 )";
1751 CompileSuccessfully(text, SPV_ENV_VULKAN_1_3);
1752 EXPECT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions(SPV_ENV_VULKAN_1_3));
1753 EXPECT_THAT(getDiagnosticString(),
1754 AnyVUID("VUID-StandaloneSpirv-Input-09557"));
1755 EXPECT_THAT(getDiagnosticString(),
1756 HasSubstr("Input/Output interface variable id <2> contains a "
1757 "PhysicalStorageBuffer pointer, which is not allowed"));
1758 }
1759
1760 TEST_F(ValidateInterfacesTest, PhysicalStorageBufferPointerArrayOfStruct) {
1761 const std::string text = R"(
1762 OpCapability Shader
1763 OpCapability PhysicalStorageBufferAddresses
1764 OpMemoryModel PhysicalStorageBuffer64 GLSL450
1765 OpEntryPoint Vertex %main "main" %var
1766 OpDecorate %var Location 0
1767 OpDecorate %var RestrictPointer
1768 %void = OpTypeVoid
1769 %int = OpTypeInt 32 1
1770 %uint = OpTypeInt 32 0
1771 %uint_3 = OpConstant %uint 3
1772 OpTypeForwardPointer %psb_ptr PhysicalStorageBuffer
1773 %array_1 = OpTypeArray %psb_ptr %uint_3
1774 %struct_0 = OpTypeStruct %int %array_1
1775 %struct_1 = OpTypeStruct %int %int
1776 %psb_ptr = OpTypePointer PhysicalStorageBuffer %struct_1
1777 %array_0 = OpTypeArray %struct_0 %uint_3
1778 %in_ptr = OpTypePointer Input %array_0
1779 %var = OpVariable %in_ptr Input
1780 %void_fn = OpTypeFunction %void
1781 %main = OpFunction %void None %void_fn
1782 %entry = OpLabel
1783 OpReturn
1784 OpFunctionEnd
1785 )";
1786 CompileSuccessfully(text, SPV_ENV_VULKAN_1_3);
1787 EXPECT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions(SPV_ENV_VULKAN_1_3));
1788 EXPECT_THAT(getDiagnosticString(),
1789 AnyVUID("VUID-StandaloneSpirv-Input-09557"));
1790 EXPECT_THAT(getDiagnosticString(),
1791 HasSubstr("Input/Output interface variable id <2> contains a "
1792 "PhysicalStorageBuffer pointer, which is not allowed"));
1793 }
1794
1795 TEST_F(ValidateInterfacesTest, PhysicalStorageBufferPointerNestedStruct) {
1796 const std::string text = R"(
1797 OpCapability Shader
1798 OpCapability PhysicalStorageBufferAddresses
1799 OpMemoryModel PhysicalStorageBuffer64 GLSL450
1800 OpEntryPoint Vertex %main "main" %var
1801 OpDecorate %var Location 0
1802 OpDecorate %var RestrictPointer
1803 %void = OpTypeVoid
1804 %int = OpTypeInt 32 1
1805 OpTypeForwardPointer %psb_ptr PhysicalStorageBuffer
1806 %struct_0 = OpTypeStruct %int %psb_ptr
1807 %struct_1 = OpTypeStruct %int %int
1808 %psb_ptr = OpTypePointer PhysicalStorageBuffer %struct_1
1809 %struct_2 = OpTypeStruct %int %struct_0
1810 %in_ptr = OpTypePointer Input %struct_2
1811 %var = OpVariable %in_ptr Input
1812 %void_fn = OpTypeFunction %void
1813 %main = OpFunction %void None %void_fn
1814 %entry = OpLabel
1815 OpReturn
1816 OpFunctionEnd
1817 )";
1818 CompileSuccessfully(text, SPV_ENV_VULKAN_1_3);
1819 EXPECT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions(SPV_ENV_VULKAN_1_3));
1820 EXPECT_THAT(getDiagnosticString(),
1821 AnyVUID("VUID-StandaloneSpirv-Input-09557"));
1822 EXPECT_THAT(getDiagnosticString(),
1823 HasSubstr("Input/Output interface variable id <2> contains a "
1824 "PhysicalStorageBuffer pointer, which is not allowed"));
1825 }
1826
1827 TEST_F(ValidateInterfacesTest, UntypedVariableInputMissing) {
1828 const std::string text = R"(
1829 OpCapability Kernel
1830 OpCapability UntypedPointersKHR
1831 OpExtension "SPV_KHR_untyped_pointers"
1832 OpMemoryModel Logical OpenCL
1833 OpEntryPoint Kernel %main "main"
1834 OpExecutionMode %main LocalSize 1 1 1
1835 OpName %var "var"
1836 OpDecorate %var BuiltIn LocalInvocationId
1837 %void = OpTypeVoid
1838 %int = OpTypeInt 32 0
1839 %int3 = OpTypeVector %int 3
1840 %ptr = OpTypeUntypedPointerKHR Input
1841 %var = OpUntypedVariableKHR %ptr Input %int3
1842 %void_fn = OpTypeFunction %void
1843 %main = OpFunction %void None %void_fn
1844 %entry = OpLabel
1845 %load = OpLoad %int3 %var
1846 OpReturn
1847 OpFunctionEnd
1848 )";
1849 CompileSuccessfully(text);
1850 EXPECT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions());
1851 EXPECT_THAT(getDiagnosticString(),
1852 HasSubstr("Interface variable id <2> is used by entry point "
1853 "'main' id <1>, but is not listed as an interface"));
1854 }
1855
1856 TEST_F(ValidateInterfacesTest, UntypedVariableWorkgroupMissingSpv1p4) {
1857 const std::string text = R"(
1858 OpCapability Shader
1859 OpCapability UntypedPointersKHR
1860 OpCapability WorkgroupMemoryExplicitLayoutKHR
1861 OpExtension "SPV_KHR_workgroup_memory_explicit_layout"
1862 OpExtension "SPV_KHR_untyped_pointers"
1863 OpMemoryModel Logical GLSL450
1864 OpEntryPoint GLCompute %main "main"
1865 OpName %var "var"
1866 %void = OpTypeVoid
1867 %int = OpTypeInt 32 0
1868 %ptr = OpTypeUntypedPointerKHR Workgroup
1869 %var = OpUntypedVariableKHR %ptr Workgroup %int
1870 %void_fn = OpTypeFunction %void
1871 %main = OpFunction %void None %void_fn
1872 %entry = OpLabel
1873 %load = OpLoad %int %var
1874 OpReturn
1875 OpFunctionEnd
1876 )";
1877
1878 CompileSuccessfully(text, SPV_ENV_UNIVERSAL_1_4);
1879 EXPECT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions(SPV_ENV_UNIVERSAL_1_4));
1880 EXPECT_THAT(getDiagnosticString(),
1881 HasSubstr("Interface variable id <2> is used by entry point "
1882 "'main' id <1>, but is not listed as an interface"));
1883 }
1884
1885 TEST_F(ValidateInterfacesTest, UntypedIdMatchesInputVulkan1p3) {
1886 const std::string text = R"(
1887 OpCapability Shader
1888 OpCapability UntypedPointersKHR
1889 OpExtension "SPV_KHR_untyped_pointers"
1890 OpMemoryModel Logical GLSL450
1891 OpEntryPoint Fragment %main "main" %var
1892 OpExecutionMode %main OriginUpperLeft
1893 OpDecorate %var DescriptorSet 0
1894 OpDecorate %var Binding 0
1895 OpDecorate %1 Block
1896 OpMemberDecorate %1 0 Offset 0
1897 %void = OpTypeVoid
1898 %float = OpTypeFloat 32
1899 %1 = OpTypeStruct %float ; this id matches Input storage class
1900 %ptr = OpTypeUntypedPointerKHR Uniform
1901 %var = OpUntypedVariableKHR %ptr Uniform %1
1902 %void_fn = OpTypeFunction %void
1903 %main = OpFunction %void None %void_fn
1904 %entry = OpLabel
1905 OpReturn
1906 OpFunctionEnd
1907 )";
1908
1909 SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
1910 CompileSuccessfully(text, SPV_ENV_VULKAN_1_3);
1911 EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_3));
1912 }
1913
1914 TEST_F(ValidateInterfacesTest, UntypedIdMatchesPushConstantVulkan1p3) {
1915 const std::string text = R"(
1916 OpCapability Shader
1917 OpCapability UntypedPointersKHR
1918 OpExtension "SPV_KHR_untyped_pointers"
1919 OpMemoryModel Logical GLSL450
1920 OpEntryPoint Fragment %main "main" %var
1921 OpExecutionMode %main OriginUpperLeft
1922 OpDecorate %var DescriptorSet 0
1923 OpDecorate %var Binding 0
1924 OpDecorate %9 Block
1925 OpMemberDecorate %9 0 Offset 0
1926 %void = OpTypeVoid
1927 %float = OpTypeFloat 32
1928 %9 = OpTypeStruct %float ; this id matches PushConstant storage class
1929 %ptr = OpTypeUntypedPointerKHR Uniform
1930 %var = OpUntypedVariableKHR %ptr Uniform %9
1931 %void_fn = OpTypeFunction %void
1932 %main = OpFunction %void None %void_fn
1933 %entry = OpLabel
1934 OpReturn
1935 OpFunctionEnd
1936 )";
1937
1938 SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
1939 CompileSuccessfully(text, SPV_ENV_VULKAN_1_3);
1940 EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_3));
1941 }
1942
1943 TEST_F(ValidateInterfacesTest,
1944 InvalidBfloat16VariableWithInputOutputStorageClass) {
1945 const std::string text = R"(
1946 OpCapability Shader
1947 OpCapability BFloat16TypeKHR
1948 OpExtension "SPV_KHR_bfloat16"
1949 OpMemoryModel Logical GLSL450
1950 OpEntryPoint Fragment %main "main" %in %out
1951 OpExecutionMode %main OriginUpperLeft
1952 OpDecorate %in Location 0
1953 OpDecorate %out Location 0
1954 %void = OpTypeVoid
1955 %bfloat16 = OpTypeFloat 16 BFloat16KHR
1956 %in_ptr = OpTypePointer Input %bfloat16
1957 %out_ptr = OpTypePointer Output %bfloat16
1958 %in = OpVariable %in_ptr Input
1959 %out = OpVariable %out_ptr Output
1960 %void_fn = OpTypeFunction %void
1961 %main = OpFunction %void None %void_fn
1962 %entry = OpLabel
1963 OpReturn
1964 OpFunctionEnd
1965 )";
1966
1967 CompileSuccessfully(text, SPV_ENV_VULKAN_1_3);
1968 ASSERT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions(SPV_ENV_VULKAN_1_3));
1969 EXPECT_THAT(getDiagnosticString(),
1970 HasSubstr("Bfloat16 OpVariable <id> '2[%2]' must not be declared "
1971 "with a Storage Class of Input or Output.\n"));
1972 }
1973
1974 TEST_F(ValidateInterfacesTest,
1975 InvalidFP8E4M3VariableWithInputOutputStorageClass) {
1976 const std::string text = R"(
1977 OpCapability Shader
1978 OpCapability Float8EXT
1979 OpExtension "SPV_EXT_float8"
1980 OpMemoryModel Logical GLSL450
1981 OpEntryPoint Fragment %main "main" %in %out
1982 OpExecutionMode %main OriginUpperLeft
1983 OpDecorate %in Location 0
1984 OpDecorate %out Location 0
1985 %void = OpTypeVoid
1986 %fp8e4m3 = OpTypeFloat 8 Float8E4M3EXT
1987 %in_ptr = OpTypePointer Input %fp8e4m3
1988 %out_ptr = OpTypePointer Output %fp8e4m3
1989 %in = OpVariable %in_ptr Input
1990 %out = OpVariable %out_ptr Output
1991 %void_fn = OpTypeFunction %void
1992 %main = OpFunction %void None %void_fn
1993 %entry = OpLabel
1994 OpReturn
1995 OpFunctionEnd
1996 )";
1997
1998 CompileSuccessfully(text, SPV_ENV_VULKAN_1_3);
1999 ASSERT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions(SPV_ENV_VULKAN_1_3));
2000 EXPECT_THAT(getDiagnosticString(),
2001 AnyVUID("VUID-StandaloneSpirv-OpTypeFloat-10823"));
2002 EXPECT_THAT(
2003 getDiagnosticString(),
2004 HasSubstr("FP8 E4M3/E5M2 OpVariable <id> '2[%2]' must not be declared "
2005 "with a Storage Class of Input or Output.\n"));
2006 }
2007
2008 TEST_F(ValidateInterfacesTest,
2009 InvalidFP8E5M2VariableWithInputOutputStorageClass) {
2010 const std::string text = R"(
2011 OpCapability Shader
2012 OpCapability Float8EXT
2013 OpExtension "SPV_EXT_float8"
2014 OpMemoryModel Logical GLSL450
2015 OpEntryPoint Fragment %main "main" %in %out
2016 OpExecutionMode %main OriginUpperLeft
2017 OpDecorate %in Location 0
2018 OpDecorate %out Location 0
2019 %void = OpTypeVoid
2020 %fp8e5m2 = OpTypeFloat 8 Float8E5M2EXT
2021 %in_ptr = OpTypePointer Input %fp8e5m2
2022 %out_ptr = OpTypePointer Output %fp8e5m2
2023 %in = OpVariable %in_ptr Input
2024 %out = OpVariable %out_ptr Output
2025 %void_fn = OpTypeFunction %void
2026 %main = OpFunction %void None %void_fn
2027 %entry = OpLabel
2028 OpReturn
2029 OpFunctionEnd
2030 )";
2031
2032 CompileSuccessfully(text, SPV_ENV_VULKAN_1_3);
2033 ASSERT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions(SPV_ENV_VULKAN_1_3));
2034 EXPECT_THAT(getDiagnosticString(),
2035 AnyVUID("VUID-StandaloneSpirv-OpTypeFloat-10823"));
2036 EXPECT_THAT(
2037 getDiagnosticString(),
2038 HasSubstr("FP8 E4M3/E5M2 OpVariable <id> '2[%2]' must not be declared "
2039 "with a Storage Class of Input or Output.\n"));
2040 }
2041
2042 TEST_F(ValidateInterfacesTest, VectorIdFragmentInputOutputPass) {
2043 const std::string text = R"(
2044 OpCapability Shader
2045 OpCapability LongVectorEXT
2046 OpExtension "SPV_EXT_long_vector"
2047 OpMemoryModel Logical GLSL450
2048 OpEntryPoint Fragment %main "main" %in %out
2049 OpExecutionMode %main OriginUpperLeft
2050 OpDecorate %in Location 0
2051 OpDecorate %out Location 0
2052 %void = OpTypeVoid
2053 %f32 = OpTypeFloat 32
2054 %u32 = OpTypeInt 32 0
2055 %u4 = OpConstant %u32 4
2056 %f32vec = OpTypeVectorIdEXT %f32 %u4
2057 %in_ptr = OpTypePointer Input %f32vec
2058 %out_ptr = OpTypePointer Output %f32vec
2059 %in = OpVariable %in_ptr Input
2060 %out = OpVariable %out_ptr Output
2061 %void_fn = OpTypeFunction %void
2062 %main = OpFunction %void None %void_fn
2063 %entry = OpLabel
2064 OpReturn
2065 OpFunctionEnd
2066 )";
2067
2068 CompileSuccessfully(text, SPV_ENV_VULKAN_1_3);
2069 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_3));
2070 }
2071
2072 TEST_F(ValidateInterfacesTest, VectorIdVertexInputOutputPass) {
2073 const std::string text = R"(
2074 OpCapability Shader
2075 OpCapability LongVectorEXT
2076 OpExtension "SPV_EXT_long_vector"
2077 OpMemoryModel Logical GLSL450
2078 OpEntryPoint Vertex %main "main" %in %out
2079 OpDecorate %in Location 0
2080 OpDecorate %out Location 0
2081 %void = OpTypeVoid
2082 %f32 = OpTypeFloat 32
2083 %u32 = OpTypeInt 32 0
2084 %u4 = OpConstant %u32 4
2085 %f32vec = OpTypeVectorIdEXT %f32 %u4
2086 %in_ptr = OpTypePointer Input %f32vec
2087 %out_ptr = OpTypePointer Output %f32vec
2088 %in = OpVariable %in_ptr Input
2089 %out = OpVariable %out_ptr Output
2090 %void_fn = OpTypeFunction %void
2091 %main = OpFunction %void None %void_fn
2092 %entry = OpLabel
2093 OpReturn
2094 OpFunctionEnd
2095 )";
2096
2097 CompileSuccessfully(text, SPV_ENV_VULKAN_1_3);
2098 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_3));
2099 }
2100
2101 } // namespace
2102 } // namespace val
2103 } // namespace spvtools