Skip to content

Commit 7806d0a

Browse files
spirv-val: Add PrimitiveID check (KhronosGroup#6209)
1 parent 08f1e75 commit 7806d0a

File tree

3 files changed

+49
-0
lines changed

3 files changed

+49
-0
lines changed

source/val/validate_builtins.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2383,6 +2383,19 @@ spv_result_t BuiltInsValidator::ValidatePrimitiveIdAtReference(
23832383
referenced_from_inst, std::placeholders::_1));
23842384
}
23852385

2386+
if (!_.HasCapability(spv::Capability::MeshShadingEXT) &&
2387+
!_.HasCapability(spv::Capability::MeshShadingNV) &&
2388+
!_.HasCapability(spv::Capability::Geometry) &&
2389+
!_.HasCapability(spv::Capability::Tessellation)) {
2390+
id_to_at_reference_checks_[referenced_from_inst.id()].push_back(std::bind(
2391+
&BuiltInsValidator::ValidateNotCalledWithExecutionModel, this, 4333,
2392+
"Vulkan spec doesn't allow BuiltIn PrimitiveId to be used for "
2393+
"variables in the Fragment execution model unless it declares "
2394+
"Geometry, Tessellation, or MeshShader capabilities.",
2395+
spv::ExecutionModel::Fragment, decoration, built_in_inst,
2396+
referenced_from_inst, std::placeholders::_1));
2397+
}
2398+
23862399
for (const spv::ExecutionModel execution_model : execution_models_) {
23872400
switch (execution_model) {
23882401
case spv::ExecutionModel::Fragment:

source/val/validation_state.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2219,6 +2219,8 @@ std::string ValidationState_t::VkErrorID(uint32_t id,
22192219
return VUID_WRAP(VUID-Position-Position-04321);
22202220
case 4330:
22212221
return VUID_WRAP(VUID-PrimitiveId-PrimitiveId-04330);
2222+
case 4333:
2223+
return VUID_WRAP(VUID-PrimitiveId-PrimitiveId-04333);
22222224
case 4334:
22232225
return VUID_WRAP(VUID-PrimitiveId-PrimitiveId-04334);
22242226
case 4336:

test/val/val_builtins_test.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6516,6 +6516,40 @@ TEST_F(ValidateBuiltIns, BadVulkanBuiltinViewportIndexAsArrayOfIntSizeMeshEXT) {
65166516
AnyVUID("VUID-ViewportIndex-ViewportIndex-10602"));
65176517
}
65186518

6519+
TEST_F(ValidateBuiltIns, BadVulkanBuiltinPrimitiveIdFragmentWithRayTracing) {
6520+
const std::string text = R"(
6521+
OpCapability Shader
6522+
OpCapability RayTracingKHR
6523+
OpExtension "SPV_KHR_ray_tracing"
6524+
OpMemoryModel Logical GLSL450
6525+
OpEntryPoint Fragment %main "main" %outVar %gl_PrimitiveID
6526+
OpExecutionMode %main OriginUpperLeft
6527+
OpDecorate %outVar Location 0
6528+
OpDecorate %gl_PrimitiveID BuiltIn PrimitiveId
6529+
OpDecorate %gl_PrimitiveID Flat
6530+
%void = OpTypeVoid
6531+
%4 = OpTypeFunction %void
6532+
%int = OpTypeInt 32 1
6533+
%v4int = OpTypeVector %int 4
6534+
%ptrOut = OpTypePointer Output %v4int
6535+
%outVar = OpVariable %ptrOut Output
6536+
%ptrIn = OpTypePointer Input %int
6537+
%gl_PrimitiveID = OpVariable %ptrIn Input
6538+
%main = OpFunction %void None %4
6539+
%6 = OpLabel
6540+
%13 = OpLoad %int %gl_PrimitiveID
6541+
%14 = OpCompositeConstruct %v4int %13 %13 %13 %13
6542+
OpStore %outVar %14
6543+
OpReturn
6544+
OpFunctionEnd
6545+
)";
6546+
6547+
CompileSuccessfully(text, SPV_ENV_VULKAN_1_3);
6548+
EXPECT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions(SPV_ENV_VULKAN_1_3));
6549+
EXPECT_THAT(getDiagnosticString(),
6550+
AnyVUID("VUID-PrimitiveId-PrimitiveId-04333"));
6551+
}
6552+
65196553
} // namespace
65206554
} // namespace val
65216555
} // namespace spvtools

0 commit comments

Comments
 (0)