From d61f81374272c2abc34eecab19e916b979b08a55 Mon Sep 17 00:00:00 2001 From: Pankaj Mistry <63069047+pmistryNV@users.noreply.github.com> Date: Fri, 5 Apr 2024 14:52:50 -0700 Subject: Add decoration PerPrimitiveEXT when a mesh output variable is decorated with PrimitiveID (#3895) Fixes bug 3872 --- source/slang/slang-emit-spirv.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'source/slang') diff --git a/source/slang/slang-emit-spirv.cpp b/source/slang/slang-emit-spirv.cpp index 942e089db..9f116a1e2 100644 --- a/source/slang/slang-emit-spirv.cpp +++ b/source/slang/slang-emit-spirv.cpp @@ -3827,6 +3827,7 @@ struct SPIRVEmitContext // non-tessellation shader stages, and if so include a declaration of // Geometry capability. bool needGeometryCapability = true; + bool needPerPrimitiveEXTDecoration = false; if (entryPoints) { for (auto entryPoint : *entryPoints) @@ -3835,9 +3836,13 @@ struct SPIRVEmitContext { switch (entryPointDecor->getProfile().getStage()) { + case Stage::Mesh: + // For outputs decorated with PrimitiveID it must be decorated + // with PerPrimitiveEXT to comply with Vulkan validation rules + if (m_capabilities.contains(SpvCapabilityMeshShadingEXT)) + needPerPrimitiveEXTDecoration = true; case Stage::Geometry: case Stage::Intersection: - case Stage::Mesh: case Stage::Amplification: case Stage::AnyHit: case Stage::ClosestHit: @@ -3851,7 +3856,14 @@ struct SPIRVEmitContext } if (needGeometryCapability) requireSPIRVCapability(SpvCapabilityGeometry); - return getBuiltinGlobalVar(inst->getFullType(), SpvBuiltInPrimitiveId); + auto varInst = getBuiltinGlobalVar(inst->getFullType(), SpvBuiltInPrimitiveId); + if (needPerPrimitiveEXTDecoration) + emitOpDecorate( + getSection(SpvLogicalSectionID::Annotations), + nullptr, + varInst, + SpvDecorationPerPrimitiveEXT); + return varInst; } else if (semanticName == "sv_rendertargetarrayindex") { -- cgit v1.2.3