diff options
| author | Pankaj Mistry <63069047+pmistryNV@users.noreply.github.com> | 2024-04-07 14:32:19 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-04-07 14:32:19 -0700 |
| commit | 4a23ba5293916795741479c55c5d0ecc597f8986 (patch) | |
| tree | 364a871d76690b11255259d7463986ea47c10f76 | |
| parent | 1b3887f462d01b83690200b9cbcb0dd902b2c0e9 (diff) | |
Add decoration PerPrimitiveEXT for all OutputPrimitives members for mesh (#3900)
| -rw-r--r-- | source/slang/slang-emit-spirv.cpp | 27 | ||||
| -rw-r--r-- | tests/pipeline/rasterization/mesh/mesh-PerPrimitiveEXT.slang | 6 |
2 files changed, 19 insertions, 14 deletions
diff --git a/source/slang/slang-emit-spirv.cpp b/source/slang/slang-emit-spirv.cpp index 9f116a1e2..2b85be8c7 100644 --- a/source/slang/slang-emit-spirv.cpp +++ b/source/slang/slang-emit-spirv.cpp @@ -2094,6 +2094,18 @@ struct SPIRVEmitContext return false; } } + void emitSystemVarDecoration(IRInst* var, SpvInst* varInst) + { + for (auto decor : var->getDecorations()) + { + switch (decor->getOp()) + { + case kIROp_GLSLPrimitivesRateDecoration: + emitOpDecorate(getSection(SpvLogicalSectionID::Annotations), decor, varInst, SpvDecorationPerPrimitiveEXT); + break; + } + } + } void emitVarLayout(IRInst* var, SpvInst* varInst, IRVarLayout* layout) { @@ -2256,6 +2268,7 @@ struct SPIRVEmitContext } if (auto systemValInst = maybeEmitSystemVal(param)) { + emitSystemVarDecoration(param, systemValInst); registerInst(param, systemValInst); return systemValInst; } @@ -3827,7 +3840,6 @@ 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) @@ -3837,10 +3849,6 @@ 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::Amplification: @@ -3856,14 +3864,7 @@ struct SPIRVEmitContext } if (needGeometryCapability) requireSPIRVCapability(SpvCapabilityGeometry); - auto varInst = getBuiltinGlobalVar(inst->getFullType(), SpvBuiltInPrimitiveId); - if (needPerPrimitiveEXTDecoration) - emitOpDecorate( - getSection(SpvLogicalSectionID::Annotations), - nullptr, - varInst, - SpvDecorationPerPrimitiveEXT); - return varInst; + return getBuiltinGlobalVar(inst->getFullType(), SpvBuiltInPrimitiveId); } else if (semanticName == "sv_rendertargetarrayindex") { diff --git a/tests/pipeline/rasterization/mesh/mesh-PerPrimitiveEXT.slang b/tests/pipeline/rasterization/mesh/mesh-PerPrimitiveEXT.slang index bf46cce63..4294314a6 100644 --- a/tests/pipeline/rasterization/mesh/mesh-PerPrimitiveEXT.slang +++ b/tests/pipeline/rasterization/mesh/mesh-PerPrimitiveEXT.slang @@ -4,6 +4,9 @@ // CHECK: OpDecorate %gl_PrimitiveID BuiltIn PrimitiveId // CHECK: OpDecorate %gl_PrimitiveID PerPrimitiveNV +// CHECK: OpDecorate {{.*}} BuiltIn CullPrimitiveEXT +// CHECK: OpDecorate {{.*}} PerPrimitiveNV + const static let color: float3[] = { float3(1.0, 0.0, 0.0), float3(0.0, 1.0, 0.0), @@ -23,6 +26,7 @@ struct SVertexOutput { struct SPrimitiveOutput { uint PrimitiveId: SV_PrimitiveID; + bool cull : SV_CullPrimitive; }; [shader("mesh")] @@ -39,6 +43,6 @@ func main( outputVertices[2] = { float4(position[2], 1.0), color[2] }; outputIndices[0] = uint3(0, 1, 2); - outputPrimitives[0] = { 0 }; + outputPrimitives[0] = { 0, false }; } |
