From 14e8af29547438078718786d54898b560ad1a813 Mon Sep 17 00:00:00 2001 From: ebosido444-ai Date: Fri, 23 Oct 2026 02:34:30 +0300 Subject: [PATCH 1/3] fix(gpu): return once at the end of blend_channel so FXC can build the compositor (#8733) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit FXC's flow analysis gives up inside blend_channel's 25-case switch, where every case returns, and reports `error X3507: 'blend_channel': Not all control paths return a value` for a function whose control flow is in fact total. naga validates the same shader, so nothing saw it: on DX12 without dxcompiler.dll on PATH no compositor pipeline builds and the whole session composites on the CPU (0.12.0 was fine; the module outgrew FXC's budget in 0.13.0). Each case now assigns and one return follows the switch, which FXC follows at any size. Semantics are unchanged: the GPU-vs-CPU parity tests, every blend mode at every depth, still pass. The new test builds every pipeline on a DX12 instance with FXC forced and InstanceFlags cleared — a debug build hides the failure, because wgpu then passes D3DCOMPILE_DEBUG and D3DCOMPILE_SKIP_OPTIMIZATION, and FXC accepts the same shader. --- crates/gpu/src/compose.wgsl | 74 ++++++++++++++++---------------- crates/gpu/tests/it/main.rs | 1 + crates/gpu/tests/it/pipelines.rs | 47 ++++++++++++++++++++ 3 files changed, 85 insertions(+), 37 deletions(-) create mode 100644 crates/gpu/tests/it/pipelines.rs diff --git a/crates/gpu/src/compose.wgsl b/crates/gpu/src/compose.wgsl index a6c0c63579..9e141678d4 100644 --- a/crates/gpu/src/compose.wgsl +++ b/crates/gpu/src/compose.wgsl @@ -166,61 +166,61 @@ fn vivid_light_generic(cb: f32, cs: f32) -> f32 { // WebGPU compiler rejects it, which left the web app without a GPU compositor. const F32_MAX: f32 = 0x1.fffffep+127f; +// FXC (the DX12 compiler between naga's HLSL and the driver) stops following a switch this size +// once every case returns: "error X3507: 'blend_channel': Not all control paths return a value", +// and then no compositor pipeline builds — the whole session composites on the CPU. Each case +// assigns instead; the one return at the end is what FXC's flow analysis can follow. fn blend_channel(mode: i32, cb: f32, cs: f32) -> f32 { // Linear Dodge / Divide clip at 1 at integer depths, at f32::MAX in 32-bit documents. let hi = select(1.0, F32_MAX, (op.flags & F_HDR) != 0u); + var r = cs; // Normal, Dissolve, PassThrough switch mode { - case 3: { return min(cb, cs); } // Darken - case 4: { return cb * cs; } // Multiply - case 5: { return color_burn(cb, cs); } // ColorBurn - case 6: { return max(cb + cs - 1.0, 0.0); } // LinearBurn - case 8: { return max(cb, cs); } // Lighten - case 9: { return cb + cs - cb * cs; } // Screen - case 10: { return color_dodge(cb, cs); } // ColorDodge - case 11: { return min(cb + cs, hi); } // LinearDodge - case 13: { return hard_light(cs, cb); } // Overlay - case 14: { return soft_light_ps(cb, cs); } // SoftLight - case 15: { return hard_light(cb, cs); } // HardLight - case 16: { return vivid_light_ps(cb, cs); } // VividLight (Photoshop) - case 17: { return clamp(cb + 2.0 * cs - 1.0, 0.0, 1.0); } // LinearLight + case 3: { r = min(cb, cs); } // Darken + case 4: { r = cb * cs; } // Multiply + case 5: { r = color_burn(cb, cs); } // ColorBurn + case 6: { r = max(cb + cs - 1.0, 0.0); } // LinearBurn + case 8: { r = max(cb, cs); } // Lighten + case 9: { r = cb + cs - cb * cs; } // Screen + case 10: { r = color_dodge(cb, cs); } // ColorDodge + case 11: { r = min(cb + cs, hi); } // LinearDodge + case 13: { r = hard_light(cs, cb); } // Overlay + case 14: { r = soft_light_ps(cb, cs); } // SoftLight + case 15: { r = hard_light(cb, cs); } // HardLight + case 16: { r = vivid_light_ps(cb, cs); } // VividLight (Photoshop) + case 17: { r = clamp(cb + 2.0 * cs - 1.0, 0.0, 1.0); } // LinearLight case 18: { // PinLight - if (cs <= 0.5) { return min(cb, 2.0 * cs); } - return max(cb, 2.0 * cs - 1.0); + if (cs <= 0.5) { r = min(cb, 2.0 * cs); } else { r = max(cb, 2.0 * cs - 1.0); } } case 19: { // HardMix (Photoshop) - return select(0.0, 1.0, vivid_light_generic(cb, cs) >= 0.5 - 1e-6); + r = select(0.0, 1.0, vivid_light_generic(cb, cs) >= 0.5 - 1e-6); } - case 20: { return abs(cb - cs); } // Difference - case 21: { return cb + cs - 2.0 * cb * cs; } // Exclusion - case 22: { return max(cb - cs, 0.0); } // Subtract + case 20: { r = abs(cb - cs); } // Difference + case 21: { r = cb + cs - 2.0 * cb * cs; } // Exclusion + case 22: { r = max(cb - cs, 0.0); } // Subtract case 23: { // Divide - if (cs <= 0.0) { return select(1.0, 0.0, cb <= 0.0); } - return min(cb / cs, hi); + if (cs <= 0.0) { r = select(1.0, 0.0, cb <= 0.0); } else { r = min(cb / cs, hi); } } - case 28: { // Reflect - if (cs >= 1.0) { return 1.0; } - return min(cb * cb / (1.0 - cs), 1.0); + case 28: { // Reflect + if (cs >= 1.0) { r = 1.0; } else { r = min(cb * cb / (1.0 - cs), 1.0); } } - case 29: { // Glow - if (cb >= 1.0) { return 1.0; } - return min(cs * cs / (1.0 - cb), 1.0); + case 29: { // Glow + if (cb >= 1.0) { r = 1.0; } else { r = min(cs * cs / (1.0 - cb), 1.0); } } - case 30: { return 1.0 - abs(1.0 - cb - cs); } // Negation - case 31: { // XOR (8-bit channel operation) + case 30: { r = 1.0 - abs(1.0 - cb - cs); } // Negation + case 31: { // XOR (8-bit channel operation) let b = u32(floor(clamp(cb, 0.0, 1.0) * 255.0 + 0.5)); let s = u32(floor(clamp(cs, 0.0, 1.0) * 255.0 + 0.5)); - return f32(b ^ s) / 255.0; + r = f32(b ^ s) / 255.0; } - case 32: { // Paint.NET Color Burn - if (cs <= 0.0) { return 0.0; } - return max(1.0 - (1.0 - cb) / cs, 0.0); + case 32: { // Paint.NET Color Burn + if (cs <= 0.0) { r = 0.0; } else { r = max(1.0 - (1.0 - cb) / cs, 0.0); } } - case 33: { // Paint.NET Color Dodge - if (cs >= 1.0) { return 1.0; } - return min(cb / (1.0 - cs), 1.0); + case 33: { // Paint.NET Color Dodge + if (cs >= 1.0) { r = 1.0; } else { r = min(cb / (1.0 - cs), 1.0); } } - default: { return cs; } // Normal, Dissolve, PassThrough + default: { r = cs; } } + return r; } fn lum(c: vec3) -> f32 { return 0.3 * c.r + 0.59 * c.g + 0.11 * c.b; } diff --git a/crates/gpu/tests/it/main.rs b/crates/gpu/tests/it/main.rs index f71972c5b9..bd0fec4a0f 100644 --- a/crates/gpu/tests/it/main.rs +++ b/crates/gpu/tests/it/main.rs @@ -6,6 +6,7 @@ static GPU_LOCK: std::sync::Mutex<()> = std::sync::Mutex::new(()); mod device_loss; mod parity; +mod pipelines; mod timing; mod uniform_limits; mod vector_mask; diff --git a/crates/gpu/tests/it/pipelines.rs b/crates/gpu/tests/it/pipelines.rs new file mode 100644 index 0000000000..20c3ab80d4 --- /dev/null +++ b/crates/gpu/tests/it/pipelines.rs @@ -0,0 +1,47 @@ +//! The compositor's WGSL must compile with the platform's own shader compiler, not only with naga. +//! +//! On DX12 wgpu translates the WGSL to HLSL and compiles it with FXC, unless `dxcompiler.dll` +//! happens to be on `PATH`, where it prefers DXC — which is why the first instance below forces +//! FXC. FXC's flow analysis stops following shapes WGSL allows (a switch whose every case returns, +//! past thirteen cases) and reports `error X3507: 'blend_channel': Not all control paths return a +//! value`. naga validates that same shader, so nothing caught it but the real compiler: no +//! compositor pipeline built, and DX12 users composited every document on the CPU for the session. +//! +//! The Windows CI runners have no GPU: their adapter is WARP over DX12, so this runs FXC there. + +use crate::GPU_LOCK; + +#[test] +fn every_compositor_pipeline_builds() { + let _lock = GPU_LOCK.lock().unwrap_or_else(std::sync::PoisonError::into_inner); + // FXC first: it is the compiler that rejected the shader, and the lowest shader model wgpu has. + // Every backend then covers the rest of their own translations (Vulkan, Metal, DX12 through DXC). + // `InstanceFlags::DEBUG` (the debug-build default) makes wgpu pass `D3DCOMPILE_DEBUG | + // D3DCOMPILE_SKIP_OPTIMIZATION`, and FXC then accepts what it rejects in a release build, so + // the flags are cleared here: a release build is what ships. + let mut fxc = wgpu::InstanceDescriptor { + backends: wgpu::Backends::DX12, + flags: wgpu::InstanceFlags::empty(), + ..wgpu::InstanceDescriptor::new_without_display_handle() + }; + fxc.backend_options.dx12.shader_compiler = wgpu::Dx12Compiler::Fxc; + let every = wgpu::InstanceDescriptor { + backends: wgpu::Backends::all(), + flags: wgpu::InstanceFlags::empty(), + ..wgpu::InstanceDescriptor::new_without_display_handle() + }; + for desc in [fxc, every] { + let instance = wgpu::Instance::new(desc); + let Ok(adapter) = pollster::block_on(instance.request_adapter(&wgpu::RequestAdapterOptions::default())) else { + continue; + }; + let Ok((device, _queue)) = pollster::block_on(adapter.request_device(&wgpu::DeviceDescriptor::default())) else { + continue; + }; + let info = adapter.get_info(); + let format = photocraft_gpu::Compositor::preferred_acc_format(&adapter); + if let Err(e) = photocraft_gpu::Compositor::try_new_with_format(&device, format) { + panic!("{:?} adapter {} (driver {}): {e}", info.backend, info.name, info.driver_info); + } + } +} From 1a86826ab7a514695b7b25733647ec052b004afd Mon Sep 17 00:00:00 2001 From: ebosido444-ai <316167330+ebosido444-ai@users.noreply.github.com> Date: Fri, 23 Oct 2026 15:36:55 +0300 Subject: [PATCH 2/3] test(gpu): fail the compositor pipeline check when Windows has no adapter MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The two acquisition arms in `every_compositor_pipeline_builds` used to `continue`, so on a Windows host whose adapter or device request failed the test passed without ever building a compositor pipeline and never reached FXC, the compiler this test exists for. The Windows CI runners are WARP over DX12, so a missing adapter there is a real regression, not a platform without the backend; keep the skip on the other platforms where DX12 (and so FXC) genuinely does not exist. `cargo clippy -p photocraft-gpu --all-targets -- -D warnings` rejects the `assert!(!cfg!(windows), …)` form of this (assertions_on_constants), hence the per-platform arms. --- crates/gpu/tests/it/pipelines.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/crates/gpu/tests/it/pipelines.rs b/crates/gpu/tests/it/pipelines.rs index 20c3ab80d4..1fe127531b 100644 --- a/crates/gpu/tests/it/pipelines.rs +++ b/crates/gpu/tests/it/pipelines.rs @@ -32,11 +32,19 @@ fn every_compositor_pipeline_builds() { }; for desc in [fxc, every] { let instance = wgpu::Instance::new(desc); + // The Windows runners always have an adapter (WARP over DX12), so a missing one there means + // the check this test exists for silently did not run. Elsewhere it is a plain skip. let Ok(adapter) = pollster::block_on(instance.request_adapter(&wgpu::RequestAdapterOptions::default())) else { + #[cfg(not(windows))] continue; + #[cfg(windows)] + panic!("no adapter on Windows: the DX12/FXC pipeline check did not run"); }; let Ok((device, _queue)) = pollster::block_on(adapter.request_device(&wgpu::DeviceDescriptor::default())) else { + #[cfg(not(windows))] continue; + #[cfg(windows)] + panic!("no device on Windows: the DX12/FXC pipeline check did not run"); }; let info = adapter.get_info(); let format = photocraft_gpu::Compositor::preferred_acc_format(&adapter); From 4825c6a704edc9890f0e22f9e72818291d221597 Mon Sep 17 00:00:00 2001 From: ebosido444-ai <316167330+ebosido444-ai@users.noreply.github.com> Date: Sat, 24 Oct 2026 00:46:56 +0300 Subject: [PATCH 3/3] test(gpu): build the compositor once per backend, not once per instance `Backends::all()` only enables the other backends on one instance; `request_adapter` then returns one adapter, so under the old loop the Vulkan and GL translations of the compositor WGSL were never built and a failure on either was invisible. Each backend now gets its own instance, its own adapter and its own compositor, so DX12/FXC, DX12/DXC-or-FXC, Vulkan and GL are all covered. Not one adapter per enumerated adapter: a second adapter of the same backend is a dual-GPU laptop's integrated GPU, and requesting a device on it is unrelated to this shader. On this machine that request segfaults on Vulkan Intel UHD (reproducible with the repo's own `zero_block_probe` example, `adapter=intel`), which would take the suite down with it. The DX12 arms keep their panic: the Windows runners always have WARP, so no adapter there means the FXC check did not run. Other backends skip, because `Backends::all()` also names backends the platform does not provide. `cargo test -p photocraft-gpu --test it every_compositor_pipeline_builds` passes in 33 s (21 s before); `cargo clippy -p photocraft-gpu --all-targets -- -D warnings` and `cargo fmt --all --check` clean. --- crates/gpu/tests/it/pipelines.rs | 59 ++++++++++++++++---------------- 1 file changed, 29 insertions(+), 30 deletions(-) diff --git a/crates/gpu/tests/it/pipelines.rs b/crates/gpu/tests/it/pipelines.rs index 1fe127531b..119ace7d72 100644 --- a/crates/gpu/tests/it/pipelines.rs +++ b/crates/gpu/tests/it/pipelines.rs @@ -19,37 +19,36 @@ fn every_compositor_pipeline_builds() { // `InstanceFlags::DEBUG` (the debug-build default) makes wgpu pass `D3DCOMPILE_DEBUG | // D3DCOMPILE_SKIP_OPTIMIZATION`, and FXC then accepts what it rejects in a release build, so // the flags are cleared here: a release build is what ships. - let mut fxc = wgpu::InstanceDescriptor { - backends: wgpu::Backends::DX12, - flags: wgpu::InstanceFlags::empty(), - ..wgpu::InstanceDescriptor::new_without_display_handle() + let describe = |backends: wgpu::Backends, compiler: wgpu::Dx12Compiler| { + let mut desc = wgpu::InstanceDescriptor { backends, flags: wgpu::InstanceFlags::empty(), ..wgpu::InstanceDescriptor::new_without_display_handle() }; + desc.backend_options.dx12.shader_compiler = compiler; + desc }; - fxc.backend_options.dx12.shader_compiler = wgpu::Dx12Compiler::Fxc; - let every = wgpu::InstanceDescriptor { - backends: wgpu::Backends::all(), - flags: wgpu::InstanceFlags::empty(), - ..wgpu::InstanceDescriptor::new_without_display_handle() - }; - for desc in [fxc, every] { - let instance = wgpu::Instance::new(desc); - // The Windows runners always have an adapter (WARP over DX12), so a missing one there means - // the check this test exists for silently did not run. Elsewhere it is a plain skip. - let Ok(adapter) = pollster::block_on(instance.request_adapter(&wgpu::RequestAdapterOptions::default())) else { - #[cfg(not(windows))] - continue; - #[cfg(windows)] - panic!("no adapter on Windows: the DX12/FXC pipeline check did not run"); - }; - let Ok((device, _queue)) = pollster::block_on(adapter.request_device(&wgpu::DeviceDescriptor::default())) else { - #[cfg(not(windows))] - continue; - #[cfg(windows)] - panic!("no device on Windows: the DX12/FXC pipeline check did not run"); - }; - let info = adapter.get_info(); - let format = photocraft_gpu::Compositor::preferred_acc_format(&adapter); - if let Err(e) = photocraft_gpu::Compositor::try_new_with_format(&device, format) { - panic!("{:?} adapter {} (driver {}): {e}", info.backend, info.name, info.driver_info); + // One instance per backend: `Backends::all()` only enables the others on one instance, and + // `request_adapter` then returns the single default adapter, so the other backends' own + // translation went untested. One adapter per backend keeps a second, unrelated adapter of the + // same backend (a dual-GPU laptop's integrated GPU) out of the run. + for (backends, compiler) in [(wgpu::Backends::DX12, wgpu::Dx12Compiler::Fxc), (wgpu::Backends::all(), wgpu::Dx12Compiler::Auto)] { + for backend in backends.iter() { + let instance = wgpu::Instance::new(describe(backend, compiler.clone())); + // The Windows runners always have a WARP adapter on DX12, so a missing one there means + // the check this test exists for silently did not run. Any other backend is a plain + // skip: `Backends::all()` also names backends this platform does not provide. + let Ok(adapter) = pollster::block_on(instance.request_adapter(&wgpu::RequestAdapterOptions::default())) else { + #[cfg(windows)] + assert!(backend != wgpu::Backends::DX12, "no adapter on Windows: the DX12/FXC pipeline check did not run"); + continue; + }; + let Ok((device, _queue)) = pollster::block_on(adapter.request_device(&wgpu::DeviceDescriptor::default())) else { + #[cfg(windows)] + assert!(backend != wgpu::Backends::DX12, "no device on Windows: the DX12/FXC pipeline check did not run"); + continue; + }; + let info = adapter.get_info(); + let format = photocraft_gpu::Compositor::preferred_acc_format(&adapter); + if let Err(e) = photocraft_gpu::Compositor::try_new_with_format(&device, format) { + panic!("{:?} adapter {} (driver {}): {e}", info.backend, info.name, info.driver_info); + } } } }