From 82418b16a135825e51a2afda3c6a00758615ba27 Mon Sep 17 00:00:00 2001 From: dubiousconst282 <87553666+dubiousconst282@users.noreply.github.com> Date: Wed, 18 Jun 2025 21:13:29 -0300 Subject: Always emit DepthReplacing execution mode when writing to FragDepth (#7450) --- source/slang/slang-emit-spirv.cpp | 10 +++++++++- tests/spirv/depth-replacing-gt-lt.slang | 16 ++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 tests/spirv/depth-replacing-gt-lt.slang diff --git a/source/slang/slang-emit-spirv.cpp b/source/slang/slang-emit-spirv.cpp index 8e8e7327b..018f833aa 100644 --- a/source/slang/slang-emit-spirv.cpp +++ b/source/slang/slang-emit-spirv.cpp @@ -4850,7 +4850,15 @@ struct SPIRVEmitContext : public SourceEmitterBase, public SPIRVEmitSharedContex if (mode == SpvExecutionModeMax) return; - requireSPIRVExecutionMode(nullptr, getIRInstSpvID(entryPoint), mode); + // Vulkan spec requires DepthReplacing exec mode when storing to FragDepth, + // in addition to DepthLess/DepthGreater modes. + requireSPIRVExecutionMode( + nullptr, + getIRInstSpvID(entryPoint), + SpvExecutionModeDepthReplacing); + + if (mode != SpvExecutionModeDepthReplacing) + requireSPIRVExecutionMode(nullptr, getIRInstSpvID(entryPoint), mode); } // Make user type name conform to `SPV_GOOGLE_user_type` spec. diff --git a/tests/spirv/depth-replacing-gt-lt.slang b/tests/spirv/depth-replacing-gt-lt.slang new file mode 100644 index 000000000..8e0ce6b79 --- /dev/null +++ b/tests/spirv/depth-replacing-gt-lt.slang @@ -0,0 +1,16 @@ +//TEST:SIMPLE(filecheck=CHECK): -target spirv +// CHECK: OpExecutionMode {{.*}} DepthReplacing +// CHECK: OpExecutionMode %FS_WriteDepthGt DepthGreater +// CHECK: OpExecutionMode %FS_WriteDepthLt DepthLess + +[shader("fragment")] +void FS_WriteDepthGt(out float depth: SV_DepthGreaterEqual) +{ + depth = 0.5; +} + +[shader("fragment")] +void FS_WriteDepthLt(out float depth: SV_DepthLessEqual) +{ + depth = 0.5; +} -- cgit v1.2.3