Recomp: clamp 64-bit float results to [0.0, 1.0] instead of saturate (#105) #243
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/246"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from ivall/xcl. Originally posted by slopgobblercobbler on 2026-11-23T21:47:34Z.
Addresses #105 Item 4 (Recompiler 64-bit float clamp precision):
In
crates/xcl/src/gpu/recomp/emit.rs,valu64emittedsaturate(double)whenCLAMP=1. HLSL SM 6.6 does not have an intrinsicsaturateoverload fordouble, narrowing the argument tofloatand losing 29 bits of mantissa precision.Replaces
saturate(...)withclamp(..., 0.0, 1.0)on 64-bit floats, preserving full double precision across 64-bit float instructions (V_ADD_F64,V_MUL_F64,V_FMA_F64).What is in it
crates/xcl/src/gpu/recomp/emit.rs:valu64clamp emission usesclamp(expr, 0.0, 1.0).crates/xcl/src/gpu/recomp/tests.rs:valu64_clamp_and_omod_hlsltesting clamp and omod generation and validating compilation with DXC.Tested
cargo test -p xcl -- recomp(172 passed, 0 failed).cargo test --workspace(603 passed, 0 failed).Not tested
AI use
author-recomp-fp64,verify-recomp-fp64). Verified and reviewed independently.Imported from ivall/xcl. Originally posted by Kalmarv on 2026-11-23T22:00:15Z.
The premise doesn't hold on the DXC versions I tried:
saturateon adoublecompiles to the double-precision DXIL op, with no narrowing to float. Compilingdouble s = saturate(d); double c = clamp(d, 0.0, 1.0);ascs_6_6:fptrunc.Saturate", andgpu_clamp_and_omod_per_instructionchecks that the f64 clamp keeps double precision on main.Saturate(NaN)= 0, andFMaxreturns the non-NaN operand, soclamp(NaN, 0.0, 1.0)=FMin(0, 1)= 0. The change is harmless, but it doesn't change any result.60565c4emitssaturate(...)and compiles with both DXC versions, and so does this PR'sclamp(..., 0.0, 1.0). Only the string assertions tell the two apart.Tested
V_ADD_F64CLAMP,V_MUL_F64OMOD,V_FMA_F64OMOD + CLAMP), translated on main60565c4and on this PR'se120969:Saturate.f64FMax/FMin.f64fptrunc60565c4with #202 and this PR merged on top passesgpu::recomp::: 187 passed, 0 failed, 18 ignored,gpu_clamp_and_omod_per_instructionincluded.Not tested
🤖 Claude Opus 5.5
Imported from ivall/xcl. Originally posted by slopgobblercobbler on 2026-11-23T22:09:27Z.
Thanks @Kalmarv for the thorough DXIL disassembly audit across SDK DXC 1.7 and DXC 1.9.
You're completely right—@dx.op.unary.f64(i32 7, ...)\ emits a native 64-bit \Saturate\ in DXIL without narrowing, which is cleaner and produces 1 DXIL op instead of 2 (\FMax\ + \FMin.f64). We investigated the note from #105, but your DXIL trace clearly demonstrates that the existing \saturate\ emission on \main\ is already optimal and precise.
Closing this PR in light of your findings. Thank you!
Imported from ivall/xcl. Originally posted by PHeitor1 on 2026-11-23T22:22:21Z.
Tested on RTX 5060 Ti 8 GB, driver 621.24, Ryzen 5 5600X, Windows 11 Pro 26300 (native), Rust 1.100.0 msvc, debug.
cargo test --workspace --no-fail-fast -- --test-threads=4on the heade120969: 622 passed, 0 failed, 40 ignored. SKIPPED: only the usual twono wave64(gpu_geometry_wave32_prefix_count_over_a_mask,gpu_wave32_program_in_wave64_hardware). Note: the branch is 52 commits behindmain(base6da33fa), so the count is lower than main's 651; a rebase would make the numbers comparable.Run and written with Claude Code (Claude Opus 5.5).
Pull request closed