From 6994837d0e15ae3d055e66b2c79408796df8a7ba Mon Sep 17 00:00:00 2001 From: Hakan Seven Date: Fri, 29 May 2026 21:16:21 +0300 Subject: [PATCH] fix(shader): satisfy DX12/FXC X3507 in hatch fs_main (#31) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Both hatch fragment shaders ended their `fs_main` with a bare `discard;` after the pattern-match for-loop falls through without matching. WGSL accepts this — discard kills the fragment, so there is nothing left to return — and naga (the Linux/Vulkan path wgpu defaults to) lowers it without complaint. DX12's FXC (the default Windows compiler) is stricter and rejects it with `X3507: 'fs_main': Not all control paths return a value`, taking the entire pipeline create-down on every drawing open. Append an unreachable `return vec4(0.0);` after each terminal `discard;` so every control path syntactically ends in a return. The return never executes at runtime; it only exists to make FXC's all-paths-return analysis succeed. Naga still accepts the shader unchanged, so the Vulkan / Metal / WebGPU paths are unaffected. Reported by @Ward-Vandepitte (Windows 11, DX12, wgpu 27.0.1). Co-Authored-By: Claude Opus 4.7 --- src/shaders/hatch.wgsl | 4 ++++ src/shaders/hatch_batched.wgsl | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/src/shaders/hatch.wgsl b/src/shaders/hatch.wgsl index bec6b0765..6bee8df29 100644 --- a/src/shaders/hatch.wgsl +++ b/src/shaders/hatch.wgsl @@ -242,4 +242,8 @@ fn check_family( } } discard; + // Unreachable: `discard` kills the fragment before this runs, but + // DX12/FXC reports E_FAIL X3507 ("not all control paths return a + // value") without an explicit return after every terminal discard. + return vec4(0.0); } diff --git a/src/shaders/hatch_batched.wgsl b/src/shaders/hatch_batched.wgsl index 00ecc3b5c..f7933ab54 100644 --- a/src/shaders/hatch_batched.wgsl +++ b/src/shaders/hatch_batched.wgsl @@ -253,4 +253,8 @@ fn check_family( } } discard; + // Unreachable: `discard` kills the fragment before this runs, but + // DX12/FXC reports E_FAIL X3507 ("not all control paths return a + // value") without an explicit return after every terminal discard. + return vec4(0.0); }