Debian Codegraph @

test/val/val_mesh_shading_test.cpp

raw
1 // Copyright (c) 2022 The Khronos Group Inc.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 // Tests instructions from SPV_EXT_mesh_shader
16
17 #include <string>
18
19 #include "gmock/gmock.h"
20 #include "test/val/val_fixtures.h"
21
22 namespace spvtools {
23 namespace val {
24 namespace {
25
26 using ::testing::HasSubstr;
27 using ::testing::Values;
28
29 using ValidateMeshShading = spvtest::ValidateBase<bool>;
30
31 TEST_F(ValidateMeshShading, EmitMeshTasksEXTNotLastInstructionUniversal) {
32 const std::string body = R"(
33 OpCapability MeshShadingEXT
34 OpExtension "SPV_EXT_mesh_shader"
35 OpMemoryModel Logical GLSL450
36 OpEntryPoint TaskEXT %main "main" %p
37 OpExecutionModeId %main LocalSizeId %uint_1 %uint_1 %uint_1
38 %void = OpTypeVoid
39 %func = OpTypeFunction %void
40 %uint = OpTypeInt 32 0
41 %uint_1 = OpConstant %uint 1
42 %float = OpTypeFloat 32
43 %arr_float = OpTypeArray %float %uint_1
44 %Payload = OpTypeStruct %arr_float
45 %ptr_Payload = OpTypePointer TaskPayloadWorkgroupEXT %Payload
46 %p = OpVariable %ptr_Payload TaskPayloadWorkgroupEXT
47 %main = OpFunction %void None %func
48 %label1 = OpLabel
49 OpEmitMeshTasksEXT %uint_1 %uint_1 %uint_1 %p
50 OpBranch %label2
51 %label2 = OpLabel
52 OpReturn
53 OpFunctionEnd
54 )";
55
56 CompileSuccessfully(body, SPV_ENV_UNIVERSAL_1_4);
57 EXPECT_EQ(SPV_ERROR_INVALID_LAYOUT,
58 ValidateInstructions(SPV_ENV_UNIVERSAL_1_4));
59 EXPECT_THAT(getDiagnosticString(),
60 HasSubstr("Branch must appear in a block"));
61 }
62
63 TEST_F(ValidateMeshShading, EmitMeshTasksEXTNotLastInstructionVulkan) {
64 const std::string body = R"(
65 OpCapability MeshShadingEXT
66 OpExtension "SPV_EXT_mesh_shader"
67 OpMemoryModel Logical GLSL450
68 OpEntryPoint TaskEXT %main "main" %p
69 OpExecutionModeId %main LocalSizeId %uint_1 %uint_1 %uint_1
70 %void = OpTypeVoid
71 %func = OpTypeFunction %void
72 %uint = OpTypeInt 32 0
73 %uint_1 = OpConstant %uint 1
74 %float = OpTypeFloat 32
75 %arr_float = OpTypeArray %float %uint_1
76 %Payload = OpTypeStruct %arr_float
77 %ptr_Payload = OpTypePointer TaskPayloadWorkgroupEXT %Payload
78 %p = OpVariable %ptr_Payload TaskPayloadWorkgroupEXT
79 %main = OpFunction %void None %func
80 %label1 = OpLabel
81 OpEmitMeshTasksEXT %uint_1 %uint_1 %uint_1 %p
82 OpReturn
83 OpFunctionEnd
84 )";
85
86 CompileSuccessfully(body, SPV_ENV_VULKAN_1_2);
87 EXPECT_EQ(SPV_ERROR_INVALID_LAYOUT, ValidateInstructions(SPV_ENV_VULKAN_1_2));
88 EXPECT_THAT(getDiagnosticString(),
89 HasSubstr("Return must appear in a block"));
90 }
91
92 TEST_F(ValidateMeshShading, BasicTaskSuccess) {
93 const std::string body = R"(
94 OpCapability MeshShadingEXT
95 OpExtension "SPV_EXT_mesh_shader"
96 OpMemoryModel Logical GLSL450
97 OpEntryPoint TaskEXT %main "main"
98 %void = OpTypeVoid
99 %func = OpTypeFunction %void
100 %main = OpFunction %void None %func
101 %label = OpLabel
102 OpReturn
103 OpFunctionEnd
104 )";
105
106 CompileSuccessfully(body, SPV_ENV_UNIVERSAL_1_5);
107 EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_UNIVERSAL_1_5));
108 }
109
110 TEST_F(ValidateMeshShading, BasicMeshSuccess) {
111 const std::string body = R"(
112 OpCapability MeshShadingEXT
113 OpExtension "SPV_EXT_mesh_shader"
114 OpMemoryModel Logical GLSL450
115 OpEntryPoint MeshEXT %main "main"
116 OpExecutionMode %main OutputVertices 1
117 OpExecutionMode %main OutputPrimitivesEXT 1
118 OpExecutionMode %main OutputTrianglesEXT
119 %void = OpTypeVoid
120 %func = OpTypeFunction %void
121 %main = OpFunction %void None %func
122 %label = OpLabel
123 OpReturn
124 OpFunctionEnd
125 )";
126
127 CompileSuccessfully(body, SPV_ENV_UNIVERSAL_1_5);
128 EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_UNIVERSAL_1_5));
129 }
130
131 // https://godbolt.org/z/Kvb1rsceP
132 TEST_F(ValidateMeshShading, BasicMeshBuiltinSuccess) {
133 const std::string body = R"(
134 OpCapability MeshShadingEXT
135 OpExtension "SPV_EXT_mesh_shader"
136 OpMemoryModel Logical GLSL450
137 OpEntryPoint MeshEXT %main "main" %gl_MeshVerticesEXT %vertexOutput %gl_MeshPrimitivesEXT %gl_LocalInvocationIndex %gl_PrimitiveTriangleIndicesEXT
138 OpExecutionModeId %main LocalSizeId %uint_1 %uint_1 %uint_1
139 OpExecutionMode %main OutputVertices 3
140 OpExecutionMode %main OutputPrimitivesEXT 1
141 OpExecutionMode %main OutputTrianglesEXT
142 OpDecorate %gl_MeshPerVertexEXT Block
143 OpMemberDecorate %gl_MeshPerVertexEXT 0 BuiltIn Position
144 OpMemberDecorate %gl_MeshPerVertexEXT 1 BuiltIn PointSize
145 OpMemberDecorate %gl_MeshPerVertexEXT 2 BuiltIn ClipDistance
146 OpMemberDecorate %gl_MeshPerVertexEXT 3 BuiltIn CullDistance
147 OpDecorate %VertexOutput Block
148 OpDecorate %vertexOutput Location 0
149 OpDecorate %gl_MeshPerPrimitiveEXT Block
150 OpMemberDecorate %gl_MeshPerPrimitiveEXT 0 BuiltIn PrimitiveId
151 OpMemberDecorate %gl_MeshPerPrimitiveEXT 0 PerPrimitiveEXT
152 OpMemberDecorate %gl_MeshPerPrimitiveEXT 1 BuiltIn Layer
153 OpMemberDecorate %gl_MeshPerPrimitiveEXT 1 PerPrimitiveEXT
154 OpMemberDecorate %gl_MeshPerPrimitiveEXT 2 BuiltIn ViewportIndex
155 OpMemberDecorate %gl_MeshPerPrimitiveEXT 2 PerPrimitiveEXT
156 OpMemberDecorate %gl_MeshPerPrimitiveEXT 3 BuiltIn CullPrimitiveEXT
157 OpMemberDecorate %gl_MeshPerPrimitiveEXT 3 PerPrimitiveEXT
158 OpDecorate %gl_LocalInvocationIndex BuiltIn LocalInvocationIndex
159 OpDecorate %gl_PrimitiveTriangleIndicesEXT BuiltIn PrimitiveTriangleIndicesEXT
160 %void = OpTypeVoid
161 %4 = OpTypeFunction %void
162 %uint = OpTypeInt 32 0
163 %uint_1 = OpConstant %uint 1
164 %uint_3 = OpConstant %uint 3
165 %float = OpTypeFloat 32
166 %v4float = OpTypeVector %float 4
167 %_arr_float_uint_1 = OpTypeArray %float %uint_1
168 %gl_MeshPerVertexEXT = OpTypeStruct %v4float %float %_arr_float_uint_1 %_arr_float_uint_1
169 %_arr_gl_MeshPerVertexEXT_uint_3 = OpTypeArray %gl_MeshPerVertexEXT %uint_3
170 %_ptr_Output__arr_gl_MeshPerVertexEXT_uint_3 = OpTypePointer Output %_arr_gl_MeshPerVertexEXT_uint_3
171 %gl_MeshVerticesEXT = OpVariable %_ptr_Output__arr_gl_MeshPerVertexEXT_uint_3 Output
172 %int = OpTypeInt 32 1
173 %int_0 = OpConstant %int 0
174 %float_0 = OpConstant %float 0
175 %20 = OpConstantComposite %v4float %float_0 %float_0 %float_0 %float_0
176 %_ptr_Output_v4float = OpTypePointer Output %v4float
177 %int_1 = OpConstant %int 1
178 %int_2 = OpConstant %int 2
179 %VertexOutput = OpTypeStruct %v4float
180 %_arr_VertexOutput_uint_3 = OpTypeArray %VertexOutput %uint_3
181 %_ptr_Output__arr_VertexOutput_uint_3 = OpTypePointer Output %_arr_VertexOutput_uint_3
182 %vertexOutput = OpVariable %_ptr_Output__arr_VertexOutput_uint_3 Output
183 %bool = OpTypeBool
184 %gl_MeshPerPrimitiveEXT = OpTypeStruct %int %int %int %bool
185 %_arr_gl_MeshPerPrimitiveEXT_uint_1 = OpTypeArray %gl_MeshPerPrimitiveEXT %uint_1
186 %_ptr_Output__arr_gl_MeshPerPrimitiveEXT_uint_1 = OpTypePointer Output %_arr_gl_MeshPerPrimitiveEXT_uint_1
187 %gl_MeshPrimitivesEXT = OpVariable %_ptr_Output__arr_gl_MeshPerPrimitiveEXT_uint_1 Output
188 %_ptr_Input_uint = OpTypePointer Input %uint
189 %gl_LocalInvocationIndex = OpVariable %_ptr_Input_uint Input
190 %int_3 = OpConstant %int 3
191 %false = OpConstantFalse %bool
192 %_ptr_Output_bool = OpTypePointer Output %bool
193 %v3uint = OpTypeVector %uint 3
194 %_arr_v3uint_uint_1 = OpTypeArray %v3uint %uint_1
195 %_ptr_Output__arr_v3uint_uint_1 = OpTypePointer Output %_arr_v3uint_uint_1
196 %gl_PrimitiveTriangleIndicesEXT = OpVariable %_ptr_Output__arr_v3uint_uint_1 Output
197 %uint_0 = OpConstant %uint 0
198 %52 = OpConstantComposite %v3uint %uint_0 %uint_0 %uint_0
199 %_ptr_Output_v3uint = OpTypePointer Output %v3uint
200 %main = OpFunction %void None %4
201 %6 = OpLabel
202 OpSetMeshOutputsEXT %uint_3 %uint_1
203 %22 = OpAccessChain %_ptr_Output_v4float %gl_MeshVerticesEXT %int_0 %int_0
204 OpStore %22 %20
205 %24 = OpAccessChain %_ptr_Output_v4float %gl_MeshVerticesEXT %int_1 %int_0
206 OpStore %24 %20
207 %26 = OpAccessChain %_ptr_Output_v4float %gl_MeshVerticesEXT %int_2 %int_0
208 OpStore %26 %20
209 %31 = OpAccessChain %_ptr_Output_v4float %vertexOutput %int_0 %int_0
210 OpStore %31 %20
211 %32 = OpAccessChain %_ptr_Output_v4float %vertexOutput %int_1 %int_0
212 OpStore %32 %20
213 %33 = OpAccessChain %_ptr_Output_v4float %vertexOutput %int_2 %int_0
214 OpStore %33 %20
215 %41 = OpLoad %uint %gl_LocalInvocationIndex
216 %45 = OpAccessChain %_ptr_Output_bool %gl_MeshPrimitivesEXT %41 %int_3
217 OpStore %45 %false
218 %50 = OpLoad %uint %gl_LocalInvocationIndex
219 %54 = OpAccessChain %_ptr_Output_v3uint %gl_PrimitiveTriangleIndicesEXT %50
220 OpStore %54 %52
221 OpReturn
222 OpFunctionEnd
223 )";
224
225 CompileSuccessfully(body, SPV_ENV_VULKAN_1_3);
226 EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_3));
227 }
228
229 TEST_F(ValidateMeshShading, VulkanBasicMeshAndTaskSuccess) {
230 const std::string body = R"(
231 OpCapability MeshShadingEXT
232 OpExtension "SPV_EXT_mesh_shader"
233 OpExtension "SPV_NV_mesh_shader"
234 OpMemoryModel Logical GLSL450
235 OpEntryPoint MeshEXT %mainMesh "mainMesh"
236 OpEntryPoint TaskEXT %mainTask "mainTask"
237 OpExecutionMode %mainMesh LocalSize 1 1 1
238 OpExecutionMode %mainTask LocalSize 1 1 1
239 OpExecutionMode %mainMesh OutputVertices 1
240 OpExecutionMode %mainMesh OutputPrimitivesEXT 1
241 OpExecutionMode %mainMesh OutputTrianglesEXT
242 %void = OpTypeVoid
243 %func = OpTypeFunction %void
244 %mainMesh = OpFunction %void None %func
245 %labelMesh = OpLabel
246 OpReturn
247 OpFunctionEnd
248 %mainTask = OpFunction %void None %func
249 %labelTask = OpLabel
250 OpReturn
251 OpFunctionEnd
252 )";
253
254 CompileSuccessfully(body, SPV_ENV_VULKAN_1_2);
255 EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_2));
256 }
257
258 TEST_F(ValidateMeshShading, VulkanBasicMeshAndTaskBad) {
259 const std::string body = R"(
260 OpCapability MeshShadingEXT
261 OpCapability MeshShadingNV
262 OpExtension "SPV_EXT_mesh_shader"
263 OpExtension "SPV_NV_mesh_shader"
264 OpMemoryModel Logical GLSL450
265 OpEntryPoint MeshEXT %mainMesh "mainMesh"
266 OpEntryPoint TaskNV %mainTask "mainTask"
267 OpExecutionMode %mainMesh OutputVertices 1
268 OpExecutionMode %mainMesh OutputPrimitivesEXT 1
269 OpExecutionMode %mainMesh OutputTrianglesEXT
270 %void = OpTypeVoid
271 %func = OpTypeFunction %void
272 %mainMesh = OpFunction %void None %func
273 %labelMesh = OpLabel
274 OpReturn
275 OpFunctionEnd
276 %mainTask = OpFunction %void None %func
277 %labelTask = OpLabel
278 OpReturn
279 OpFunctionEnd
280 )";
281
282 CompileSuccessfully(body, SPV_ENV_VULKAN_1_2);
283 EXPECT_EQ(SPV_ERROR_INVALID_LAYOUT, ValidateInstructions(SPV_ENV_VULKAN_1_2));
284 EXPECT_THAT(getDiagnosticString(),
285 AnyVUID("VUID-StandaloneSpirv-MeshEXT-07102"));
286 EXPECT_THAT(getDiagnosticString(),
287 HasSubstr("Module can't mix MeshEXT/TaskEXT with MeshNV/TaskNV "
288 "Execution Model."));
289 }
290
291 TEST_F(ValidateMeshShading, MeshMissingOutputVertices) {
292 const std::string body = R"(
293 OpCapability MeshShadingEXT
294 OpExtension "SPV_EXT_mesh_shader"
295 OpMemoryModel Logical GLSL450
296 OpEntryPoint MeshEXT %main "main"
297 OpExecutionMode %main OutputPrimitivesEXT 1
298 OpExecutionMode %main OutputTrianglesEXT
299 %void = OpTypeVoid
300 %func = OpTypeFunction %void
301 %main = OpFunction %void None %func
302 %label = OpLabel
303 OpReturn
304 OpFunctionEnd
305 )";
306
307 CompileSuccessfully(body, SPV_ENV_UNIVERSAL_1_5);
308 EXPECT_EQ(SPV_ERROR_INVALID_DATA,
309 ValidateInstructions(SPV_ENV_UNIVERSAL_1_5));
310 EXPECT_THAT(
311 getDiagnosticString(),
312 HasSubstr("MeshEXT execution model entry points must specify both "
313 "OutputPrimitivesEXT and OutputVertices Execution Modes."));
314 }
315
316 TEST_F(ValidateMeshShading, MeshMissingOutputPrimitivesEXT) {
317 const std::string body = R"(
318 OpCapability MeshShadingEXT
319 OpExtension "SPV_EXT_mesh_shader"
320 OpMemoryModel Logical GLSL450
321 OpEntryPoint MeshEXT %main "main"
322 OpExecutionMode %main OutputVertices 1
323 OpExecutionMode %main OutputTrianglesEXT
324 %void = OpTypeVoid
325 %func = OpTypeFunction %void
326 %main = OpFunction %void None %func
327 %label = OpLabel
328 OpReturn
329 OpFunctionEnd
330 )";
331
332 CompileSuccessfully(body, SPV_ENV_UNIVERSAL_1_5);
333 EXPECT_EQ(SPV_ERROR_INVALID_DATA,
334 ValidateInstructions(SPV_ENV_UNIVERSAL_1_5));
335 EXPECT_THAT(
336 getDiagnosticString(),
337 HasSubstr("MeshEXT execution model entry points must specify both "
338 "OutputPrimitivesEXT and OutputVertices Execution Modes."));
339 }
340
341 TEST_F(ValidateMeshShading, MeshMissingOutputType) {
342 const std::string body = R"(
343 OpCapability MeshShadingEXT
344 OpExtension "SPV_EXT_mesh_shader"
345 OpMemoryModel Logical GLSL450
346 OpEntryPoint MeshEXT %main "main"
347 OpExecutionMode %main OutputVertices 1
348 OpExecutionMode %main OutputPrimitivesEXT 1
349 %void = OpTypeVoid
350 %func = OpTypeFunction %void
351 %main = OpFunction %void None %func
352 %label = OpLabel
353 OpReturn
354 OpFunctionEnd
355 )";
356
357 CompileSuccessfully(body, SPV_ENV_UNIVERSAL_1_5);
358 EXPECT_EQ(SPV_ERROR_INVALID_DATA,
359 ValidateInstructions(SPV_ENV_UNIVERSAL_1_5));
360 EXPECT_THAT(getDiagnosticString(),
361 HasSubstr("MeshEXT execution model entry points must specify "
362 "exactly one of OutputPoints, OutputLinesEXT, or "
363 "OutputTrianglesEXT Execution Modes."));
364 }
365
366 TEST_F(ValidateMeshShading, MeshMultipleOutputType) {
367 const std::string body = R"(
368 OpCapability MeshShadingEXT
369 OpExtension "SPV_EXT_mesh_shader"
370 OpMemoryModel Logical GLSL450
371 OpEntryPoint MeshEXT %main "main"
372 OpExecutionMode %main OutputVertices 1
373 OpExecutionMode %main OutputPrimitivesEXT 1
374 OpExecutionMode %main OutputLinesEXT
375 OpExecutionMode %main OutputTrianglesEXT
376 %void = OpTypeVoid
377 %func = OpTypeFunction %void
378 %main = OpFunction %void None %func
379 %label = OpLabel
380 OpReturn
381 OpFunctionEnd
382 )";
383
384 CompileSuccessfully(body, SPV_ENV_UNIVERSAL_1_5);
385 EXPECT_EQ(SPV_ERROR_INVALID_DATA,
386 ValidateInstructions(SPV_ENV_UNIVERSAL_1_5));
387 EXPECT_THAT(getDiagnosticString(),
388 HasSubstr("MeshEXT execution model entry points must specify "
389 "exactly one of OutputPoints, OutputLinesEXT, or "
390 "OutputTrianglesEXT Execution Modes."));
391 }
392
393 TEST_F(ValidateMeshShading, BadExecutionModelOutputLinesEXT) {
394 const std::string body = R"(
395 OpCapability MeshShadingEXT
396 OpExtension "SPV_EXT_mesh_shader"
397 OpMemoryModel Logical GLSL450
398 OpEntryPoint GLCompute %main "main"
399 OpExecutionMode %main OutputLinesEXT
400 %void = OpTypeVoid
401 %func = OpTypeFunction %void
402 %main = OpFunction %void None %func
403 %label = OpLabel
404 OpReturn
405 OpFunctionEnd
406 )";
407
408 CompileSuccessfully(body, SPV_ENV_UNIVERSAL_1_5);
409 EXPECT_EQ(SPV_ERROR_INVALID_DATA,
410 ValidateInstructions(SPV_ENV_UNIVERSAL_1_5));
411 EXPECT_THAT(getDiagnosticString(),
412 HasSubstr("Execution mode can only be used with the MeshEXT or "
413 "MeshNV execution model."));
414 }
415
416 TEST_F(ValidateMeshShading, BadExecutionModelOutputTrianglesEXT) {
417 const std::string body = R"(
418 OpCapability MeshShadingEXT
419 OpExtension "SPV_EXT_mesh_shader"
420 OpMemoryModel Logical GLSL450
421 OpEntryPoint GLCompute %main "main"
422 OpExecutionMode %main OutputTrianglesEXT
423 %void = OpTypeVoid
424 %func = OpTypeFunction %void
425 %main = OpFunction %void None %func
426 %label = OpLabel
427 OpReturn
428 OpFunctionEnd
429 )";
430
431 CompileSuccessfully(body, SPV_ENV_UNIVERSAL_1_5);
432 EXPECT_EQ(SPV_ERROR_INVALID_DATA,
433 ValidateInstructions(SPV_ENV_UNIVERSAL_1_5));
434 EXPECT_THAT(getDiagnosticString(),
435 HasSubstr("Execution mode can only be used with the MeshEXT or "
436 "MeshNV execution model."));
437 }
438
439 TEST_F(ValidateMeshShading, BadExecutionModelOutputPrimitivesEXT) {
440 const std::string body = R"(
441 OpCapability MeshShadingEXT
442 OpExtension "SPV_EXT_mesh_shader"
443 OpMemoryModel Logical GLSL450
444 OpEntryPoint GLCompute %main "main"
445 OpExecutionMode %main OutputPrimitivesEXT 1
446 %void = OpTypeVoid
447 %func = OpTypeFunction %void
448 %main = OpFunction %void None %func
449 %label = OpLabel
450 OpReturn
451 OpFunctionEnd
452 )";
453
454 CompileSuccessfully(body, SPV_ENV_UNIVERSAL_1_5);
455 EXPECT_EQ(SPV_ERROR_INVALID_DATA,
456 ValidateInstructions(SPV_ENV_UNIVERSAL_1_5));
457 EXPECT_THAT(getDiagnosticString(),
458 HasSubstr("Execution mode can only be used with the MeshEXT or "
459 "MeshNV execution model."));
460 }
461
462 TEST_F(ValidateMeshShading, OpEmitMeshTasksBadGroupCountSignedInt) {
463 const std::string body = R"(
464 OpCapability MeshShadingEXT
465 OpExtension "SPV_EXT_mesh_shader"
466 OpMemoryModel Logical GLSL450
467 OpEntryPoint TaskEXT %main "main"
468 %void = OpTypeVoid
469 %func = OpTypeFunction %void
470 %int = OpTypeInt 32 1
471 %uint = OpTypeInt 32 0
472 %int_1 = OpConstant %int 1
473 %uint_1 = OpConstant %uint 1
474 %main = OpFunction %void None %func
475 %label = OpLabel
476 OpEmitMeshTasksEXT %int_1 %uint_1 %uint_1
477 OpFunctionEnd
478 )";
479
480 CompileSuccessfully(body, SPV_ENV_UNIVERSAL_1_5);
481 EXPECT_EQ(SPV_ERROR_INVALID_DATA,
482 ValidateInstructions(SPV_ENV_UNIVERSAL_1_5));
483 EXPECT_THAT(getDiagnosticString(),
484 HasSubstr("Group Count X must be a 32-bit unsigned int scalar"));
485 }
486
487 TEST_F(ValidateMeshShading, OpEmitMeshTasksBadGroupCountVector) {
488 const std::string body = R"(
489 OpCapability MeshShadingEXT
490 OpExtension "SPV_EXT_mesh_shader"
491 OpMemoryModel Logical GLSL450
492 OpEntryPoint TaskEXT %main "main"
493 %void = OpTypeVoid
494 %func = OpTypeFunction %void
495 %uint = OpTypeInt 32 0
496 %v2uint = OpTypeVector %uint 2
497 %_ptr_v2uint = OpTypePointer Function %v2uint
498 %uint_1 = OpConstant %uint 1
499 %composite = OpConstantComposite %v2uint %uint_1 %uint_1
500 %_ptr_uint = OpTypePointer Function %uint
501 %main = OpFunction %void None %func
502 %label = OpLabel
503 %x = OpVariable %_ptr_v2uint Function
504 OpStore %x %composite
505 %13 = OpAccessChain %_ptr_uint %x %uint_1
506 %14 = OpLoad %uint %13
507 OpEmitMeshTasksEXT %14 %composite %uint_1
508 OpFunctionEnd
509 )";
510
511 CompileSuccessfully(body, SPV_ENV_UNIVERSAL_1_5);
512 EXPECT_EQ(SPV_ERROR_INVALID_DATA,
513 ValidateInstructions(SPV_ENV_UNIVERSAL_1_5));
514 EXPECT_THAT(getDiagnosticString(),
515 HasSubstr("Group Count Y must be a 32-bit unsigned int scalar"));
516 }
517
518 TEST_F(ValidateMeshShading, OpEmitMeshTasksBadPayload) {
519 const std::string body = R"(
520 OpCapability MeshShadingEXT
521 OpExtension "SPV_EXT_mesh_shader"
522 OpMemoryModel Logical GLSL450
523 OpEntryPoint TaskEXT %main "main" %payload
524 %void = OpTypeVoid
525 %func = OpTypeFunction %void
526 %uint = OpTypeInt 32 0
527 %task = OpTypeStruct %uint
528 %_ptr_Uniform = OpTypePointer Uniform %task
529 %payload = OpVariable %_ptr_Uniform Uniform
530 %uint_1 = OpConstant %uint 1
531 %main = OpFunction %void None %func
532 %label = OpLabel
533 OpEmitMeshTasksEXT %uint_1 %uint_1 %uint_1 %payload
534 OpFunctionEnd
535 )";
536
537 CompileSuccessfully(body, SPV_ENV_UNIVERSAL_1_5);
538 EXPECT_EQ(SPV_ERROR_INVALID_DATA,
539 ValidateInstructions(SPV_ENV_UNIVERSAL_1_5));
540 EXPECT_THAT(getDiagnosticString(),
541 HasSubstr("Payload OpVariable must have a storage class of "
542 "TaskPayloadWorkgroupEXT"));
543 }
544
545 TEST_F(ValidateMeshShading, TaskPayloadWorkgroupBadExecutionModel) {
546 const std::string body = R"(
547 OpCapability MeshShadingEXT
548 OpExtension "SPV_EXT_mesh_shader"
549 OpMemoryModel Logical GLSL450
550 OpEntryPoint GLCompute %main "main" %payload
551 %void = OpTypeVoid
552 %func = OpTypeFunction %void
553 %uint = OpTypeInt 32 0
554 %_ptr_TaskPayloadWorkgroupEXT = OpTypePointer TaskPayloadWorkgroupEXT %uint
555 %payload = OpVariable %_ptr_TaskPayloadWorkgroupEXT TaskPayloadWorkgroupEXT
556 %main = OpFunction %void None %func
557 %label = OpLabel
558 %load = OpLoad %uint %payload
559 OpReturn
560 OpFunctionEnd
561 )";
562
563 CompileSuccessfully(body, SPV_ENV_UNIVERSAL_1_5);
564 EXPECT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions(SPV_ENV_UNIVERSAL_1_5));
565 EXPECT_THAT(getDiagnosticString(),
566 HasSubstr("TaskPayloadWorkgroupEXT Storage Class is limited to "
567 "TaskEXT and MeshKHR execution model"));
568 }
569
570 TEST_F(ValidateMeshShading, BadMultipleTaskPayloadWorkgroupEXT) {
571 const std::string body = R"(
572 OpCapability MeshShadingEXT
573 OpExtension "SPV_EXT_mesh_shader"
574 OpMemoryModel Logical GLSL450
575 OpEntryPoint TaskEXT %main "main" %payload %payload1
576 %void = OpTypeVoid
577 %func = OpTypeFunction %void
578 %uint = OpTypeInt 32 0
579 %_ptr_TaskPayloadWorkgroupEXT = OpTypePointer TaskPayloadWorkgroupEXT %uint
580 %payload = OpVariable %_ptr_TaskPayloadWorkgroupEXT TaskPayloadWorkgroupEXT
581 %payload1 = OpVariable %_ptr_TaskPayloadWorkgroupEXT TaskPayloadWorkgroupEXT
582 %main = OpFunction %void None %func
583 %label = OpLabel
584 %load = OpLoad %uint %payload
585 OpReturn
586 OpFunctionEnd
587 )";
588 CompileSuccessfully(body, SPV_ENV_UNIVERSAL_1_5);
589 EXPECT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions(SPV_ENV_UNIVERSAL_1_5));
590 EXPECT_THAT(getDiagnosticString(),
591 HasSubstr("There can be at most one "
592 "OpVariable with storage "
593 "class TaskPayloadWorkgroupEXT associated with "
594 "an OpEntryPoint"));
595 }
596
597 TEST_F(ValidateMeshShading, TaskPayloadWorkgroupTaskExtExecutionModel) {
598 const std::string body = R"(
599 OpCapability MeshShadingEXT
600 OpExtension "SPV_EXT_mesh_shader"
601 OpMemoryModel Logical GLSL450
602 OpEntryPoint TaskEXT %main "main" %payload
603 %void = OpTypeVoid
604 %func = OpTypeFunction %void
605 %uint = OpTypeInt 32 0
606 %_ptr_TaskPayloadWorkgroupEXT = OpTypePointer TaskPayloadWorkgroupEXT %uint
607 %payload = OpVariable %_ptr_TaskPayloadWorkgroupEXT TaskPayloadWorkgroupEXT
608 %main = OpFunction %void None %func
609 %label = OpLabel
610 %load = OpLoad %uint %payload
611 OpReturn
612 OpFunctionEnd
613 )";
614
615 CompileSuccessfully(body, SPV_ENV_UNIVERSAL_1_5);
616 EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_UNIVERSAL_1_5));
617 }
618
619 TEST_F(ValidateMeshShading, TaskPayloadWorkgroupMeshExtExecutionModel) {
620 const std::string body = R"(
621 OpCapability MeshShadingEXT
622 OpExtension "SPV_EXT_mesh_shader"
623 OpMemoryModel Logical GLSL450
624 OpEntryPoint MeshEXT %main "main" %payload
625 OpExecutionMode %main OutputVertices 1
626 OpExecutionMode %main OutputPrimitivesEXT 1
627 OpExecutionMode %main OutputTrianglesEXT
628 %void = OpTypeVoid
629 %func = OpTypeFunction %void
630 %uint = OpTypeInt 32 0
631 %_ptr_TaskPayloadWorkgroupEXT = OpTypePointer TaskPayloadWorkgroupEXT %uint
632 %payload = OpVariable %_ptr_TaskPayloadWorkgroupEXT TaskPayloadWorkgroupEXT
633 %main = OpFunction %void None %func
634 %label = OpLabel
635 %load = OpLoad %uint %payload
636 OpReturn
637 OpFunctionEnd
638 )";
639
640 CompileSuccessfully(body, SPV_ENV_UNIVERSAL_1_5);
641 EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_UNIVERSAL_1_5));
642 }
643
644 TEST_F(ValidateMeshShading, OpSetMeshOutputsBadVertexCount) {
645 const std::string body = R"(
646 OpCapability MeshShadingEXT
647 OpExtension "SPV_EXT_mesh_shader"
648 OpMemoryModel Logical GLSL450
649 OpEntryPoint MeshEXT %main "main"
650 OpExecutionMode %main OutputVertices 1
651 OpExecutionMode %main OutputPrimitivesNV 1
652 OpExecutionMode %main OutputTrianglesNV
653 %void = OpTypeVoid
654 %3 = OpTypeFunction %void
655 %int = OpTypeInt 32 1
656 %uint = OpTypeInt 32 0
657 %_ptr_int = OpTypePointer Function %int
658 %int_1 = OpConstant %int 1
659 %uint_1 = OpConstant %uint 1
660 %main = OpFunction %void None %3
661 %5 = OpLabel
662 %x = OpVariable %_ptr_int Function
663 OpStore %x %int_1
664 %load = OpLoad %int %x
665 OpSetMeshOutputsEXT %load %uint_1
666 OpReturn
667 OpFunctionEnd
668 )";
669
670 CompileSuccessfully(body, SPV_ENV_UNIVERSAL_1_5);
671 EXPECT_EQ(SPV_ERROR_INVALID_DATA,
672 ValidateInstructions(SPV_ENV_UNIVERSAL_1_5));
673 EXPECT_THAT(getDiagnosticString(),
674 HasSubstr("Vertex Count must be a 32-bit unsigned int scalar"));
675 }
676
677 TEST_F(ValidateMeshShading, OpSetMeshOutputsBadPrimitiveCount) {
678 const std::string body = R"(
679 OpCapability MeshShadingEXT
680 OpExtension "SPV_EXT_mesh_shader"
681 OpMemoryModel Logical GLSL450
682 OpEntryPoint MeshEXT %main "main"
683 OpExecutionMode %main OutputVertices 1
684 OpExecutionMode %main OutputPrimitivesNV 1
685 OpExecutionMode %main OutputTrianglesNV
686 %void = OpTypeVoid
687 %3 = OpTypeFunction %void
688 %int = OpTypeInt 32 1
689 %uint = OpTypeInt 32 0
690 %int_1 = OpConstant %int 1
691 %uint_1 = OpConstant %uint 1
692 %main = OpFunction %void None %3
693 %5 = OpLabel
694 OpSetMeshOutputsEXT %uint_1 %int_1
695 OpReturn
696 OpFunctionEnd
697 )";
698
699 CompileSuccessfully(body, SPV_ENV_UNIVERSAL_1_5);
700 EXPECT_EQ(SPV_ERROR_INVALID_DATA,
701 ValidateInstructions(SPV_ENV_UNIVERSAL_1_5));
702 EXPECT_THAT(
703 getDiagnosticString(),
704 HasSubstr("Primitive Count must be a 32-bit unsigned int scalar"));
705 }
706
707 TEST_F(ValidateMeshShading, OpSetMeshOutputsBadExecutionModel) {
708 const std::string body = R"(
709 OpCapability MeshShadingEXT
710 OpExtension "SPV_EXT_mesh_shader"
711 OpMemoryModel Logical GLSL450
712 OpEntryPoint TaskEXT %main "main"
713 %void = OpTypeVoid
714 %3 = OpTypeFunction %void
715 %uint = OpTypeInt 32 0
716 %uint_1 = OpConstant %uint 1
717 %main = OpFunction %void None %3
718 %5 = OpLabel
719 OpSetMeshOutputsEXT %uint_1 %uint_1
720 OpReturn
721 OpFunctionEnd
722 )";
723
724 CompileSuccessfully(body, SPV_ENV_UNIVERSAL_1_5);
725 EXPECT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions(SPV_ENV_UNIVERSAL_1_5));
726 EXPECT_THAT(
727 getDiagnosticString(),
728 HasSubstr("OpSetMeshOutputsEXT requires MeshEXT execution model"));
729 }
730
731 TEST_F(ValidateMeshShading, OpSetMeshOutputsZeroSuccess) {
732 const std::string body = R"(
733 OpCapability MeshShadingEXT
734 OpExtension "SPV_EXT_mesh_shader"
735 OpMemoryModel Logical GLSL450
736 OpEntryPoint MeshEXT %main "main"
737 OpExecutionMode %main OutputVertices 1
738 OpExecutionMode %main OutputPrimitivesNV 1
739 OpExecutionMode %main OutputTrianglesNV
740 %void = OpTypeVoid
741 %3 = OpTypeFunction %void
742 %uint = OpTypeInt 32 0
743 %uint_0 = OpConstant %uint 0
744 %main = OpFunction %void None %3
745 %5 = OpLabel
746 OpSetMeshOutputsEXT %uint_0 %uint_0
747 OpReturn
748 OpFunctionEnd
749 )";
750
751 CompileSuccessfully(body, SPV_ENV_UNIVERSAL_1_5);
752 EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_UNIVERSAL_1_5));
753 }
754
755 TEST_F(ValidateMeshShading, OpEmitMeshTasksZeroSuccess) {
756 const std::string body = R"(
757 OpCapability MeshShadingEXT
758 OpExtension "SPV_EXT_mesh_shader"
759 OpMemoryModel Logical GLSL450
760 OpEntryPoint TaskEXT %main "main"
761 %void = OpTypeVoid
762 %func = OpTypeFunction %void
763 %uint = OpTypeInt 32 0
764 %uint_0 = OpConstant %uint 1
765 %main = OpFunction %void None %func
766 %label = OpLabel
767 OpEmitMeshTasksEXT %uint_0 %uint_0 %uint_0
768 OpFunctionEnd
769 )";
770
771 CompileSuccessfully(body, SPV_ENV_UNIVERSAL_1_5);
772 EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_UNIVERSAL_1_5));
773 }
774
775 TEST_F(ValidateMeshShading, MeshOutputScalar) {
776 const std::string body = R"(
777 OpCapability MeshShadingEXT
778 OpExtension "SPV_EXT_mesh_shader"
779 OpMemoryModel Logical GLSL450
780 OpEntryPoint MeshEXT %main "main" %x
781 OpExecutionModeId %main LocalSizeId %uint_1 %uint_1 %uint_1
782 OpExecutionMode %main OutputVertices 3
783 OpExecutionMode %main OutputPrimitivesEXT 1
784 OpExecutionMode %main OutputTrianglesEXT
785 OpDecorate %x Location 0
786 %void = OpTypeVoid
787 %4 = OpTypeFunction %void
788 %uint = OpTypeInt 32 0
789 %uint_1 = OpConstant %uint 1
790 %uint_3 = OpConstant %uint 3
791 %o_ptr = OpTypePointer Output %uint
792 %x = OpVariable %o_ptr Output
793 %main = OpFunction %void None %4
794 %6 = OpLabel
795 OpSetMeshOutputsEXT %uint_3 %uint_1
796 OpReturn
797 OpFunctionEnd
798 )";
799
800 CompileSuccessfully(body, SPV_ENV_VULKAN_1_3);
801 EXPECT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions(SPV_ENV_VULKAN_1_3));
802 EXPECT_THAT(getDiagnosticString(),
803 HasSubstr("In the MeshEXT Execution Mode, all Output Variables "
804 "must contain an Array."));
805 }
806
807 TEST_F(ValidateMeshShading, MeshOutputScalarStruct) {
808 const std::string body = R"(
809 OpCapability MeshShadingEXT
810 OpExtension "SPV_EXT_mesh_shader"
811 OpMemoryModel Logical GLSL450
812 OpEntryPoint MeshEXT %main "main" %vertexOutput
813 OpExecutionModeId %main LocalSizeId %uint_1 %uint_1 %uint_1
814 OpExecutionMode %main OutputVertices 3
815 OpExecutionMode %main OutputPrimitivesEXT 1
816 OpExecutionMode %main OutputTrianglesEXT
817 OpDecorate %VertexOutput Block
818 OpMemberDecorate %VertexOutput 0 Location 0
819 %void = OpTypeVoid
820 %4 = OpTypeFunction %void
821 %uint = OpTypeInt 32 0
822 %uint_1 = OpConstant %uint 1
823 %uint_3 = OpConstant %uint 3
824 %float = OpTypeFloat 32
825 %v4float = OpTypeVector %float 4
826 %VertexOutput = OpTypeStruct %v4float
827 %_ptr_Output_uint_3 = OpTypePointer Output %VertexOutput
828 %vertexOutput = OpVariable %_ptr_Output_uint_3 Output
829 %int = OpTypeInt 32 1
830 %int_0 = OpConstant %int 0
831 %float_0 = OpConstant %float 0
832 %19 = OpConstantComposite %v4float %float_0 %float_0 %float_0 %float_0
833 %_ptr_Output_v4float = OpTypePointer Output %v4float
834 %main = OpFunction %void None %4
835 %6 = OpLabel
836 OpSetMeshOutputsEXT %uint_3 %uint_1
837 %21 = OpAccessChain %_ptr_Output_v4float %vertexOutput %int_0
838 OpStore %21 %19
839 OpReturn
840 OpFunctionEnd
841 )";
842
843 CompileSuccessfully(body, SPV_ENV_VULKAN_1_3);
844 EXPECT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions(SPV_ENV_VULKAN_1_3));
845 EXPECT_THAT(getDiagnosticString(),
846 HasSubstr("In the MeshEXT Execution Mode, all Output Variables "
847 "must contain an Array."));
848 }
849
850 TEST_F(ValidateMeshShading, BadPerPrimitiveEXTStorageClassInMeshEXT) {
851 const std::string body = R"(
852 OpCapability MeshShadingEXT
853 OpExtension "SPV_EXT_mesh_shader"
854 %1 = OpExtInstImport "GLSL.std.450"
855 OpMemoryModel Logical GLSL450
856 OpEntryPoint MeshEXT %main "main" %gl_LocalInvocationID %blk %triangleNormal
857 OpExecutionMode %main LocalSize 32 1 1
858 OpExecutionMode %main OutputVertices 81
859 OpExecutionMode %main OutputPrimitivesNV 32
860 OpExecutionMode %main OutputTrianglesNV
861 OpSource GLSL 450
862 OpSourceExtension "GL_EXT_mesh_shader"
863 OpName %main "main"
864 OpName %iid "iid"
865 OpName %gl_LocalInvocationID "gl_LocalInvocationID"
866 OpName %myblock "myblock"
867 OpMemberName %myblock 0 "f"
868 OpName %blk "blk"
869 OpName %triangleNormal "triangleNormal"
870 OpDecorate %gl_LocalInvocationID BuiltIn LocalInvocationId
871 OpMemberDecorate %myblock 0 PerPrimitiveEXT
872 OpDecorate %myblock Block
873 OpDecorate %blk Location 0
874 OpDecorate %triangleNormal PerPrimitiveEXT
875 OpDecorate %triangleNormal Location 0
876 OpDecorate %gl_WorkGroupSize BuiltIn WorkgroupSize
877 %void = OpTypeVoid
878 %3 = OpTypeFunction %void
879 %uint = OpTypeInt 32 0
880 %_ptr_Function_uint = OpTypePointer Function %uint
881 %v3uint = OpTypeVector %uint 3
882 %_ptr_Input_v3uint = OpTypePointer Input %v3uint
883 %gl_LocalInvocationID = OpVariable %_ptr_Input_v3uint Input
884 %uint_0 = OpConstant %uint 0
885 %_ptr_Input_uint = OpTypePointer Input %uint
886 %float = OpTypeFloat 32
887 %myblock = OpTypeStruct %float
888 %uint_32 = OpConstant %uint 32
889 %_arr_myblock_uint_32 = OpTypeArray %myblock %uint_32
890 %_ptr_Output__arr_myblock_uint_32 = OpTypePointer Output %_arr_myblock_uint_32
891 %blk = OpVariable %_ptr_Output__arr_myblock_uint_32 Output
892 %int = OpTypeInt 32 1
893 %int_0 = OpConstant %int 0
894 %float_11 = OpConstant %float 11
895 %_ptr_Output_float = OpTypePointer Output %float
896 %v3float = OpTypeVector %float 3
897 %_arr_v3float_uint_32 = OpTypeArray %v3float %uint_32
898 %_ptr_Output__arr_v3float_uint_32 = OpTypePointer Input %_arr_v3float_uint_32
899 %triangleNormal = OpVariable %_ptr_Output__arr_v3float_uint_32 Input
900 %33 = OpConstantComposite %v3float %float_11 %float_11 %float_11
901 %_ptr_Output_v3float = OpTypePointer Output %v3float
902 %uint_1 = OpConstant %uint 1
903 %gl_WorkGroupSize = OpConstantComposite %v3uint %uint_32 %uint_1 %uint_1
904 %main = OpFunction %void None %3
905 %5 = OpLabel
906 %iid = OpVariable %_ptr_Function_uint Function
907 %14 = OpAccessChain %_ptr_Input_uint %gl_LocalInvocationID %uint_0
908 %15 = OpLoad %uint %14
909 OpStore %iid %15
910 %22 = OpLoad %uint %iid
911 %27 = OpAccessChain %_ptr_Output_float %blk %22 %int_0
912 OpStore %27 %float_11
913 OpReturn
914 OpFunctionEnd
915 )";
916
917 CompileSuccessfully(body, SPV_ENV_UNIVERSAL_1_5);
918 EXPECT_EQ(SPV_ERROR_INVALID_DATA,
919 ValidateInstructions(SPV_ENV_UNIVERSAL_1_5));
920 EXPECT_THAT(getDiagnosticString(),
921 HasSubstr("PerPrimitiveEXT decoration must be applied only to "
922 "variables in the Output Storage Class in the Storage "
923 "Class in the MeshEXT Execution Model."));
924 }
925
926 TEST_F(ValidateMeshShading, VulkanPerPrimitiveEXTStorageClassInMeshEXT) {
927 const std::string body = R"(
928 OpCapability MeshShadingEXT
929 OpExtension "SPV_EXT_mesh_shader"
930 %1 = OpExtInstImport "GLSL.std.450"
931 OpMemoryModel Logical GLSL450
932 OpEntryPoint MeshEXT %main "main" %gl_LocalInvocationID %blk %triangleNormal
933 OpExecutionMode %main LocalSize 32 1 1
934 OpExecutionMode %main OutputVertices 81
935 OpExecutionMode %main OutputPrimitivesNV 32
936 OpExecutionMode %main OutputTrianglesNV
937 OpSource GLSL 450
938 OpSourceExtension "GL_EXT_mesh_shader"
939 OpName %main "main"
940 OpName %iid "iid"
941 OpName %gl_LocalInvocationID "gl_LocalInvocationID"
942 OpName %myblock "myblock"
943 OpMemberName %myblock 0 "f"
944 OpName %blk "blk"
945 OpName %triangleNormal "triangleNormal"
946 OpDecorate %gl_LocalInvocationID BuiltIn LocalInvocationId
947 OpMemberDecorate %myblock 0 PerPrimitiveEXT
948 OpDecorate %myblock Block
949 OpDecorate %blk Location 0
950 OpDecorate %triangleNormal PerPrimitiveEXT
951 OpDecorate %triangleNormal Location 0
952 OpDecorate %gl_WorkGroupSize BuiltIn WorkgroupSize
953 %void = OpTypeVoid
954 %3 = OpTypeFunction %void
955 %uint = OpTypeInt 32 0
956 %_ptr_Function_uint = OpTypePointer Function %uint
957 %v3uint = OpTypeVector %uint 3
958 %_ptr_Input_v3uint = OpTypePointer Input %v3uint
959 %gl_LocalInvocationID = OpVariable %_ptr_Input_v3uint Input
960 %uint_0 = OpConstant %uint 0
961 %_ptr_Input_uint = OpTypePointer Input %uint
962 %float = OpTypeFloat 32
963 %myblock = OpTypeStruct %float
964 %uint_32 = OpConstant %uint 32
965 %_arr_myblock_uint_32 = OpTypeArray %myblock %uint_32
966 %_ptr_Output__arr_myblock_uint_32 = OpTypePointer Output %_arr_myblock_uint_32
967 %blk = OpVariable %_ptr_Output__arr_myblock_uint_32 Output
968 %int = OpTypeInt 32 1
969 %int_0 = OpConstant %int 0
970 %float_11 = OpConstant %float 11
971 %_ptr_Output_float = OpTypePointer Output %float
972 %v3float = OpTypeVector %float 3
973 %_arr_v3float_uint_32 = OpTypeArray %v3float %uint_32
974 %_ptr_Output__arr_v3float_uint_32 = OpTypePointer Input %_arr_v3float_uint_32
975 %triangleNormal = OpVariable %_ptr_Output__arr_v3float_uint_32 Input
976 %33 = OpConstantComposite %v3float %float_11 %float_11 %float_11
977 %_ptr_Output_v3float = OpTypePointer Output %v3float
978 %uint_1 = OpConstant %uint 1
979 %gl_WorkGroupSize = OpConstantComposite %v3uint %uint_32 %uint_1 %uint_1
980 %main = OpFunction %void None %3
981 %5 = OpLabel
982 %iid = OpVariable %_ptr_Function_uint Function
983 %14 = OpAccessChain %_ptr_Input_uint %gl_LocalInvocationID %uint_0
984 %15 = OpLoad %uint %14
985 OpStore %iid %15
986 %22 = OpLoad %uint %iid
987 %27 = OpAccessChain %_ptr_Output_float %blk %22 %int_0
988 OpStore %27 %float_11
989 OpReturn
990 OpFunctionEnd
991 )";
992
993 CompileSuccessfully(body, SPV_ENV_VULKAN_1_2);
994 EXPECT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions(SPV_ENV_VULKAN_1_2));
995 EXPECT_THAT(getDiagnosticString(),
996 AnyVUID("VUID-PrimitiveId-PrimitiveId-04336"));
997 }
998
999 TEST_F(ValidateMeshShading, BadPerPrimitiveEXTStorageClassInFrag) {
1000 const std::string body = R"(
1001 OpCapability Shader
1002 OpCapability MeshShadingEXT
1003 OpExtension "SPV_EXT_mesh_shader"
1004 %1 = OpExtInstImport "GLSL.std.450"
1005 OpMemoryModel Logical GLSL450
1006 OpEntryPoint Fragment %main "main" %triangleNormal
1007 OpExecutionMode %main OriginUpperLeft
1008 OpSource GLSL 450
1009 OpSourceExtension "GL_EXT_mesh_shader"
1010 OpName %main "main"
1011 OpName %triangleNormal "triangleNormal"
1012 OpDecorate %triangleNormal PerPrimitiveNV
1013 OpDecorate %triangleNormal Location 0
1014 %void = OpTypeVoid
1015 %3 = OpTypeFunction %void
1016 %float = OpTypeFloat 32
1017 %v3float = OpTypeVector %float 3
1018 %uint = OpTypeInt 32 0
1019 %uint_3 = OpConstant %uint 3
1020 %_arr_v3float_uint_3 = OpTypeArray %v3float %uint_3
1021 %_ptr_Input__arr_v3float_uint_3 = OpTypePointer Output %_arr_v3float_uint_3
1022 %triangleNormal = OpVariable %_ptr_Input__arr_v3float_uint_3 Output
1023 %int = OpTypeInt 32 1
1024 %int_0 = OpConstant %int 0
1025 %_ptr_Input_v3float = OpTypePointer Input %v3float
1026 %main = OpFunction %void None %3
1027 %5 = OpLabel
1028 %18 = OpAccessChain %_ptr_Input_v3float %triangleNormal %int_0
1029 %19 = OpLoad %v3float %18
1030 OpReturn
1031 OpFunctionEnd
1032 )";
1033
1034 CompileSuccessfully(body, SPV_ENV_UNIVERSAL_1_5);
1035 EXPECT_EQ(SPV_ERROR_INVALID_DATA,
1036 ValidateInstructions(SPV_ENV_UNIVERSAL_1_5));
1037 EXPECT_THAT(getDiagnosticString(),
1038 HasSubstr("PerPrimitiveEXT decoration must be applied only to "
1039 "variables in the Input Storage Class in the Fragment "
1040 "Execution Model."));
1041 }
1042
1043 TEST_F(ValidateMeshShading, PerPrimitiveEXTStorageClassInFrag) {
1044 const std::string body = R"(
1045 OpCapability Shader
1046 OpCapability MeshShadingEXT
1047 OpExtension "SPV_EXT_mesh_shader"
1048 %1 = OpExtInstImport "GLSL.std.450"
1049 OpMemoryModel Logical GLSL450
1050 OpEntryPoint Fragment %main "main" %res3 %triangleNormal
1051 OpExecutionMode %main OriginUpperLeft
1052 OpSource GLSL 450
1053 OpSourceExtension "GL_EXT_mesh_shader"
1054 OpName %main "main"
1055 OpName %res3 "res3"
1056 OpName %triangleNormal "triangleNormal"
1057 OpDecorate %res3 Location 0
1058 OpDecorate %triangleNormal PerPrimitiveNV
1059 OpDecorate %triangleNormal Location 0
1060 %void = OpTypeVoid
1061 %3 = OpTypeFunction %void
1062 %float = OpTypeFloat 32
1063 %v3float = OpTypeVector %float 3
1064 %_ptr_Output_v3float = OpTypePointer Output %v3float
1065 %res3 = OpVariable %_ptr_Output_v3float Output
1066 %uint = OpTypeInt 32 0
1067 %uint_3 = OpConstant %uint 3
1068 %_arr_v3float_uint_3 = OpTypeArray %v3float %uint_3
1069 %_ptr_Input__arr_v3float_uint_3 = OpTypePointer Input %_arr_v3float_uint_3
1070 %triangleNormal = OpVariable %_ptr_Input__arr_v3float_uint_3 Input
1071 %int = OpTypeInt 32 1
1072 %int_0 = OpConstant %int 0
1073 %_ptr_Input_v3float = OpTypePointer Input %v3float
1074 %main = OpFunction %void None %3
1075 %5 = OpLabel
1076 %18 = OpAccessChain %_ptr_Input_v3float %triangleNormal %int_0
1077 %19 = OpLoad %v3float %18
1078 OpStore %res3 %19
1079 OpReturn
1080 OpFunctionEnd
1081 )";
1082
1083 CompileSuccessfully(body, SPV_ENV_UNIVERSAL_1_5);
1084 EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_UNIVERSAL_1_5));
1085 }
1086
1087 TEST_F(ValidateMeshShading, PerPrimitiveEXTStorageClassInMeshEXT) {
1088 const std::string body = R"(
1089 OpCapability MeshShadingEXT
1090 OpExtension "SPV_EXT_mesh_shader"
1091 %1 = OpExtInstImport "GLSL.std.450"
1092 OpMemoryModel Logical GLSL450
1093 OpEntryPoint MeshEXT %main "main" %gl_LocalInvocationID %blk %triangleNormal
1094 OpExecutionMode %main LocalSize 32 1 1
1095 OpExecutionMode %main OutputVertices 81
1096 OpExecutionMode %main OutputPrimitivesNV 32
1097 OpExecutionMode %main OutputTrianglesNV
1098 OpSource GLSL 450
1099 OpSourceExtension "GL_EXT_mesh_shader"
1100 OpName %main "main"
1101 OpName %iid "iid"
1102 OpName %gl_LocalInvocationID "gl_LocalInvocationID"
1103 OpName %myblock "myblock"
1104 OpMemberName %myblock 0 "f"
1105 OpName %blk "blk"
1106 OpName %triangleNormal "triangleNormal"
1107 OpDecorate %gl_LocalInvocationID BuiltIn LocalInvocationId
1108 OpMemberDecorate %myblock 0 PerPrimitiveNV
1109 OpDecorate %myblock Block
1110 OpDecorate %blk Location 0
1111 OpDecorate %triangleNormal PerPrimitiveNV
1112 OpDecorate %triangleNormal Location 0
1113 OpDecorate %gl_WorkGroupSize BuiltIn WorkgroupSize
1114 %void = OpTypeVoid
1115 %3 = OpTypeFunction %void
1116 %uint = OpTypeInt 32 0
1117 %_ptr_Function_uint = OpTypePointer Function %uint
1118 %v3uint = OpTypeVector %uint 3
1119 %_ptr_Input_v3uint = OpTypePointer Input %v3uint
1120 %gl_LocalInvocationID = OpVariable %_ptr_Input_v3uint Input
1121 %uint_0 = OpConstant %uint 0
1122 %_ptr_Input_uint = OpTypePointer Input %uint
1123 %float = OpTypeFloat 32
1124 %myblock = OpTypeStruct %float
1125 %uint_32 = OpConstant %uint 32
1126 %_arr_myblock_uint_32 = OpTypeArray %myblock %uint_32
1127 %_ptr_Output__arr_myblock_uint_32 = OpTypePointer Output %_arr_myblock_uint_32
1128 %blk = OpVariable %_ptr_Output__arr_myblock_uint_32 Output
1129 %int = OpTypeInt 32 1
1130 %int_0 = OpConstant %int 0
1131 %float_11 = OpConstant %float 11
1132 %_ptr_Output_float = OpTypePointer Output %float
1133 %v3float = OpTypeVector %float 3
1134 %_arr_v3float_uint_32 = OpTypeArray %v3float %uint_32
1135 %_ptr_Output__arr_v3float_uint_32 = OpTypePointer Output %_arr_v3float_uint_32
1136 %triangleNormal = OpVariable %_ptr_Output__arr_v3float_uint_32 Output
1137 %33 = OpConstantComposite %v3float %float_11 %float_11 %float_11
1138 %_ptr_Output_v3float = OpTypePointer Output %v3float
1139 %uint_1 = OpConstant %uint 1
1140 %gl_WorkGroupSize = OpConstantComposite %v3uint %uint_32 %uint_1 %uint_1
1141 %main = OpFunction %void None %3
1142 %5 = OpLabel
1143 %iid = OpVariable %_ptr_Function_uint Function
1144 %14 = OpAccessChain %_ptr_Input_uint %gl_LocalInvocationID %uint_0
1145 %15 = OpLoad %uint %14
1146 OpStore %iid %15
1147 %22 = OpLoad %uint %iid
1148 %27 = OpAccessChain %_ptr_Output_float %blk %22 %int_0
1149 OpStore %27 %float_11
1150 %32 = OpLoad %uint %iid
1151 %35 = OpAccessChain %_ptr_Output_v3float %triangleNormal %32
1152 OpStore %35 %33
1153 OpReturn
1154 OpFunctionEnd
1155 )";
1156
1157 CompileSuccessfully(body, SPV_ENV_UNIVERSAL_1_5);
1158 EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_UNIVERSAL_1_5));
1159 }
1160
1161 TEST_F(ValidateMeshShading, MeshWriteOutput) {
1162 const std::string body = R"(
1163 OpCapability MeshShadingEXT
1164 OpExtension "SPV_EXT_mesh_shader"
1165 OpMemoryModel Logical GLSL450
1166 OpEntryPoint MeshEXT %main "main" %x %y
1167 OpExecutionModeId %main LocalSizeId %uint_1 %uint_1 %uint_1
1168 OpExecutionMode %main OutputVertices 3
1169 OpExecutionMode %main OutputPrimitivesEXT 1
1170 OpExecutionMode %main OutputTrianglesEXT
1171 OpDecorate %x Location 1
1172 OpDecorate %y Location 0
1173 %void = OpTypeVoid
1174 %4 = OpTypeFunction %void
1175 %uint = OpTypeInt 32 0
1176 %uint_1 = OpConstant %uint 1
1177 %uint_3 = OpConstant %uint 3
1178 %_arr_uint_uint_3 = OpTypeArray %uint %uint_3
1179 %_ptr_Output__arr_uint_uint_3 = OpTypePointer Output %_arr_uint_uint_3
1180 %x = OpVariable %_ptr_Output__arr_uint_uint_3 Output
1181 %int = OpTypeInt 32 1
1182 %int_0 = OpConstant %int 0
1183 %_ptr_Output_uint = OpTypePointer Output %uint
1184 %float = OpTypeFloat 32
1185 %v4float = OpTypeVector %float 4
1186 %_arr_v4float_uint_3 = OpTypeArray %v4float %uint_3
1187 %_ptr_Output__arr_v4float_uint_3 = OpTypePointer Output %_arr_v4float_uint_3
1188 %y = OpVariable %_ptr_Output__arr_v4float_uint_3 Output
1189 %float_0 = OpConstant %float 0
1190 %23 = OpConstantComposite %v4float %float_0 %float_0 %float_0 %float_0
1191 %_ptr_Output_v4float = OpTypePointer Output %v4float
1192 %main = OpFunction %void None %4
1193 %6 = OpLabel
1194 %16 = OpAccessChain %_ptr_Output_uint %x %int_0
1195 OpStore %16 %uint_1
1196 %25 = OpAccessChain %_ptr_Output_v4float %y %int_0
1197 OpStore %25 %23
1198 OpSetMeshOutputsEXT %uint_3 %uint_1
1199 OpReturn
1200 OpFunctionEnd
1201 )";
1202
1203 CompileSuccessfully(body, SPV_ENV_VULKAN_1_3);
1204 EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_3));
1205 }
1206
1207 TEST_F(ValidateMeshShading, MeshReadOutputInt) {
1208 const std::string body = R"(
1209 OpCapability MeshShadingEXT
1210 OpExtension "SPV_EXT_mesh_shader"
1211 OpMemoryModel Logical GLSL450
1212 OpEntryPoint MeshEXT %main "main" %x
1213 OpExecutionModeId %main LocalSizeId %uint_1 %uint_1 %uint_1
1214 OpExecutionMode %main OutputVertices 3
1215 OpExecutionMode %main OutputPrimitivesEXT 1
1216 OpExecutionMode %main OutputTrianglesEXT
1217 OpDecorate %x Location 0
1218 %void = OpTypeVoid
1219 %4 = OpTypeFunction %void
1220 %uint = OpTypeInt 32 0
1221 %uint_1 = OpConstant %uint 1
1222 %_ptr_Function_uint = OpTypePointer Function %uint
1223 %uint_3 = OpConstant %uint 3
1224 %_arr_uint_uint_3 = OpTypeArray %uint %uint_3
1225 %_ptr_Output__arr_uint_uint_3 = OpTypePointer Output %_arr_uint_uint_3
1226 %x = OpVariable %_ptr_Output__arr_uint_uint_3 Output
1227 %int = OpTypeInt 32 1
1228 %int_1 = OpConstant %int 1
1229 %_ptr_Output_uint = OpTypePointer Output %uint
1230 %main = OpFunction %void None %4
1231 %6 = OpLabel
1232 %y = OpVariable %_ptr_Function_uint Function
1233 %18 = OpAccessChain %_ptr_Output_uint %x %int_1
1234 %19 = OpLoad %uint %18
1235 OpStore %y %19
1236 OpSetMeshOutputsEXT %uint_3 %uint_1
1237 OpReturn
1238 OpFunctionEnd
1239 )";
1240
1241 CompileSuccessfully(body, SPV_ENV_VULKAN_1_3);
1242 EXPECT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions(SPV_ENV_VULKAN_1_3));
1243 EXPECT_THAT(getDiagnosticString(),
1244 AnyVUID("VUID-StandaloneSpirv-MeshEXT-07107"));
1245 EXPECT_THAT(getDiagnosticString(),
1246 HasSubstr("The Output Storage Class in a Mesh Execution Model "
1247 "must not be read from"));
1248 }
1249
1250 TEST_F(ValidateMeshShading, MeshReadOutputVec) {
1251 const std::string body = R"(
1252 OpCapability MeshShadingEXT
1253 OpExtension "SPV_EXT_mesh_shader"
1254 %2 = OpExtInstImport "GLSL.std.450"
1255 OpMemoryModel Logical GLSL450
1256 OpEntryPoint MeshEXT %main "main" %x
1257 OpExecutionModeId %main LocalSizeId %uint_1 %uint_1 %uint_1
1258 OpExecutionMode %main OutputVertices 3
1259 OpExecutionMode %main OutputPrimitivesEXT 1
1260 OpExecutionMode %main OutputTrianglesEXT
1261 OpDecorate %x Location 0
1262 %void = OpTypeVoid
1263 %4 = OpTypeFunction %void
1264 %uint = OpTypeInt 32 0
1265 %uint_1 = OpConstant %uint 1
1266 %float = OpTypeFloat 32
1267 %v4float = OpTypeVector %float 4
1268 %_ptr_Function_v4float = OpTypePointer Function %v4float
1269 %uint_3 = OpConstant %uint 3
1270 %_arr_v4float_uint_3 = OpTypeArray %v4float %uint_3
1271 %_ptr_Output__arr_v4float_uint_3 = OpTypePointer Output %_arr_v4float_uint_3
1272 %x = OpVariable %_ptr_Output__arr_v4float_uint_3 Output
1273 %int = OpTypeInt 32 1
1274 %int_1 = OpConstant %int 1
1275 %_ptr_Output_v4float = OpTypePointer Output %v4float
1276 %main = OpFunction %void None %4
1277 %6 = OpLabel
1278 %y = OpVariable %_ptr_Function_v4float Function
1279 %20 = OpAccessChain %_ptr_Output_v4float %x %int_1
1280 %21 = OpLoad %v4float %20
1281 OpStore %y %21
1282 OpSetMeshOutputsEXT %uint_3 %uint_1
1283 OpReturn
1284 OpFunctionEnd
1285 )";
1286
1287 CompileSuccessfully(body, SPV_ENV_VULKAN_1_3);
1288 EXPECT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions(SPV_ENV_VULKAN_1_3));
1289 EXPECT_THAT(getDiagnosticString(),
1290 AnyVUID("VUID-StandaloneSpirv-MeshEXT-07107"));
1291 EXPECT_THAT(getDiagnosticString(),
1292 HasSubstr("The Output Storage Class in a Mesh Execution Model "
1293 "must not be read from"));
1294 }
1295
1296 TEST_F(ValidateMeshShading, MeshReadOutputStruct) {
1297 const std::string body = R"(
1298 OpCapability MeshShadingEXT
1299 OpExtension "SPV_EXT_mesh_shader"
1300 %2 = OpExtInstImport "GLSL.std.450"
1301 OpMemoryModel Logical GLSL450
1302 OpEntryPoint MeshEXT %main "main" %x_0
1303 OpExecutionModeId %main LocalSizeId %uint_1 %uint_1 %uint_1
1304 OpExecutionMode %main OutputVertices 3
1305 OpExecutionMode %main OutputPrimitivesEXT 1
1306 OpExecutionMode %main OutputTrianglesEXT
1307 OpDecorate %x_0 Location 0
1308 %void = OpTypeVoid
1309 %4 = OpTypeFunction %void
1310 %uint = OpTypeInt 32 0
1311 %uint_1 = OpConstant %uint 1
1312 %_ptr_Function_uint = OpTypePointer Function %uint
1313 %Bar = OpTypeStruct %uint
1314 %Foo = OpTypeStruct %Bar
1315 %uint_3 = OpConstant %uint 3
1316 %_arr_Foo_uint_3 = OpTypeArray %Foo %uint_3
1317 %_ptr_Output__arr_Foo_uint_3 = OpTypePointer Output %_arr_Foo_uint_3
1318 %x_0 = OpVariable %_ptr_Output__arr_Foo_uint_3 Output
1319 %int = OpTypeInt 32 1
1320 %int_2 = OpConstant %int 2
1321 %int_0 = OpConstant %int 0
1322 %_ptr_Output_uint = OpTypePointer Output %uint
1323 %main = OpFunction %void None %4
1324 %6 = OpLabel
1325 %x = OpVariable %_ptr_Function_uint Function
1326 %21 = OpAccessChain %_ptr_Output_uint %x_0 %int_2 %int_0 %int_0
1327 %22 = OpLoad %uint %21
1328 OpStore %x %22
1329 OpSetMeshOutputsEXT %uint_3 %uint_1
1330 OpReturn
1331 OpFunctionEnd
1332 )";
1333
1334 CompileSuccessfully(body, SPV_ENV_VULKAN_1_3);
1335 EXPECT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions(SPV_ENV_VULKAN_1_3));
1336 EXPECT_THAT(getDiagnosticString(),
1337 AnyVUID("VUID-StandaloneSpirv-MeshEXT-07107"));
1338 EXPECT_THAT(getDiagnosticString(),
1339 HasSubstr("The Output Storage Class in a Mesh Execution Model "
1340 "must not be read from"));
1341 }
1342
1343 TEST_F(ValidateMeshShading, MeshReadOutputIntUntyped) {
1344 const std::string body = R"(
1345 OpCapability MeshShadingEXT
1346 OpCapability UntypedPointersKHR
1347 OpExtension "SPV_EXT_mesh_shader"
1348 OpExtension "SPV_KHR_untyped_pointers"
1349 OpMemoryModel Logical GLSL450
1350 OpEntryPoint MeshEXT %main "main" %x
1351 OpExecutionModeId %main LocalSizeId %uint_1 %uint_1 %uint_1
1352 OpExecutionMode %main OutputVertices 3
1353 OpExecutionMode %main OutputPrimitivesEXT 1
1354 OpExecutionMode %main OutputTrianglesEXT
1355 OpDecorate %x Location 0
1356 %void = OpTypeVoid
1357 %4 = OpTypeFunction %void
1358 %uint = OpTypeInt 32 0
1359 %uint_1 = OpConstant %uint 1
1360 %_ptr_Function_uint = OpTypePointer Function %uint
1361 %uint_3 = OpConstant %uint 3
1362 %_arr_uint_uint_3 = OpTypeArray %uint %uint_3
1363 %_ptr_Output__arr_uint_uint_3 = OpTypePointer Output %_arr_uint_uint_3
1364 %x = OpVariable %_ptr_Output__arr_uint_uint_3 Output
1365 %int = OpTypeInt 32 1
1366 %int_1 = OpConstant %int 1
1367 %_ptr_Output_uint = OpTypeUntypedPointerKHR Output
1368 %main = OpFunction %void None %4
1369 %6 = OpLabel
1370 %y = OpVariable %_ptr_Function_uint Function
1371 %18 = OpUntypedAccessChainKHR %_ptr_Output_uint %_arr_uint_uint_3 %x %int_1
1372 %19 = OpLoad %uint %18
1373 OpStore %y %19
1374 OpSetMeshOutputsEXT %uint_3 %uint_1
1375 OpReturn
1376 OpFunctionEnd
1377 )";
1378
1379 CompileSuccessfully(body, SPV_ENV_VULKAN_1_3);
1380 EXPECT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions(SPV_ENV_VULKAN_1_3));
1381 EXPECT_THAT(getDiagnosticString(),
1382 HasSubstr("In Vulkan, untyped pointers can only be used in an "
1383 "explicitly laid out storage class"));
1384 }
1385
1386 } // namespace
1387 } // namespace val
1388 } // namespace spvtools