diff options
| author | Yong He <yonghe@outlook.com> | 2024-03-07 14:04:30 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-03-07 14:04:30 -0800 |
| commit | 6492906ebe59b573f6243e7c44476944b9dd5592 (patch) | |
| tree | 09188282d9b405ccf8d6b420d609e09fe98b8a1d /source | |
| parent | 240727db40552180446c1f14acc371f690db10e4 (diff) | |
Fix SPIRV emit logic of `PrimitiveId` in fragment shader. (#3705)
Diffstat (limited to 'source')
| -rw-r--r-- | source/slang/slang-emit-spirv.cpp | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/source/slang/slang-emit-spirv.cpp b/source/slang/slang-emit-spirv.cpp index e37d09af7..098c2cc2b 100644 --- a/source/slang/slang-emit-spirv.cpp +++ b/source/slang/slang-emit-spirv.cpp @@ -3461,6 +3461,17 @@ struct SPIRVEmitContext varInst, builtinVal ); + + if (storageClass == SpvStorageClassInput || + storageClass == SpvStorageClassOutput) + { + switch (builtinVal) + { + case SpvBuiltInPrimitiveId: + _maybeEmitInterpolationModifierDecoration(IRInterpolationMode::NoInterpolation, varInst); + break; + } + } m_builtinGlobalVars[key] = varInst; return varInst; } @@ -3565,6 +3576,37 @@ struct SPIRVEmitContext } else if (semanticName == "sv_primitiveid") { + auto entryPoints = m_referencingEntryPoints.tryGetValue(inst); + // SPIRV requires `Geometry` capability being declared for a fragment + // shader, if that shader uses sv_primitiveid. + // We will check if this builtin is used by non-ray-tracing, non-geometry or + // non-tessellation shader stages, and if so include a declaration of + // Geometry capability. + bool needGeometryCapability = true; + if (entryPoints) + { + for (auto entryPoint : *entryPoints) + { + if (auto entryPointDecor = entryPoint->findDecoration<IREntryPointDecoration>()) + { + switch (entryPointDecor->getProfile().getStage()) + { + case Stage::Geometry: + case Stage::Intersection: + case Stage::Mesh: + case Stage::Amplification: + case Stage::AnyHit: + case Stage::ClosestHit: + case Stage::Hull: + case Stage::Domain: + needGeometryCapability = false; + break; + } + } + } + } + if (needGeometryCapability) + requireSPIRVCapability(SpvCapabilityGeometry); return getBuiltinGlobalVar(inst->getFullType(), SpvBuiltInPrimitiveId); } else if (semanticName == "sv_rendertargetarrayindex") |
