Recompiler: saturate UINT/SINT and use RTZ in direct DXIL fmt_encode #2043
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
goal:world-load
good first issue
help wanted
invalid
keep-open
off-goal
question
stale
test-only
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/xcl-dev--xcl!2043
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/2043/head"
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?
@Decodere on GitHub · 2026-11-25 01:47 UTC · original
Decodere:fix-1488-dxil-fmt-encode→main· +101 −8 · 2 files · 1 commits · merged 2026-11-25 01:56 UTCBrings direct DXIL
Lw::fmt_encode(crates/xcl/src/gpu/dxil/lower_mem.rs) into parity with RDNA2 hardware and merged PR #1929 (recomp/emit.rsHLSLfmt_encode) for buffer format stores (BUFFER_STORE_FORMAT_*/TBUFFER_STORE_FORMAT_*). Part of #1269, Part of #1488 (XCL-BT-026).Merged PR #1929 fixed
XCL-BT-026in the HLSL emitter only, leaving direct DXILLw::fmt_encodereturning raw unclamped integers forUINT(ty == 4) andSINT(ty == 5) whenw < 32and rounding 16-, 11-, and 10-bitFLOATvalues with round-to-nearest-even (f32_to_f16) instead of round-toward-zero (f16_rtz).What is in it
crates/xcl/src/gpu/dxil/lower_mem.rs:Lw::fmt_encode, saturatety == 4(UINT) to[0, mu]viaumin(x, mu)andty == 5(SINT) to[!ms, ms]viaimin(imax(x, !ms), ms)whenw < 32, preserving passthrough forw >= 32.self.s.f32_to_f16(f)withself.f16_rtz(f)for 16-, 11-, and 10-bitFLOATstores so finite values above65504.0saturate to max finite (0x7BFF/0xFBFF,0x7BF/0x3DF) and normal/subnormal intermediates round toward zero while preserving true±InfandNaN.crates/xcl/src/gpu/recomp/tests.rs:gpu_fmt_encode_direct_dxil_int_sat_and_f16_rtz, compiling and running both HLSL and direct DXIL unconditionally on the GPU across16_16_UINT,16_16_SINT,8_8_8_8_UINT,8_8_8_8_SINT,2_10_10_10_SINT,32_UINT/32_SINTpassthrough,16_16_FLOAT(finite overflow, normal RTZ,±Inf, subnormal RTZ,-0.0), and11_11_10_FLOAT(finite overflow,+Inf,NaN, negative, RTZ boundary).Tested
0ef1bc386), DXC 1.9.2609.5 (01b62ad4), release build.gpu_fmt_encode_direct_dxil_int_sat_and_f16_rtzfails before the fix on RTX 4060 (hlslpassed all 13 cases whiledirect_dxilwrapped16_16_UINT: got0xFFFF_1170instead of0xFFFF_FFFF).cargo test --release -p xcl --lib gpu_fmt_encode_direct_dxil_int_sat_and_f16_rtz -- --nocapture: 1 passed, 0 failed, 0 ignored (both HLSL and direct DXIL executed on RTX 4060).XCL_DIRECT_DXIL=1ongpu_fmt_encode_int_sat_and_f16_rtzandgpu_pknorm_i16_f32_nan_and_fmt_encode_snorm_ufloat: both passed, 0 failed.cargo build --release --workspace+cargo test --release --workspace -- --test-threads=4: 1103 passed, 0 failed, 46 ignored across 20 test binaries.SKIPPEDGPU/runtime tests on this adapter (24 lines):no wave64subcases acrossgpu::recomp::lower::tests(4),gpu::recomp::lower_dxil::tests(13), andgpu::recomp::tests(2)#1426refusals (V_MUL_F16,V_PK_MUL_F16,V_CVT_F16_F32) ingpu::recomp::lower_dxil::testsshaders::tests::pso_measurement_compiles_an_exact_synthetic_record: cannot disable the driver cache (Windows Developer Mode is required)heap_window_out_of_memory_falls_back_to_the_switch_form: no heap windowsRegression run
scripts/smoke.ps1onmain(8f5fca5bb9ad6e695093d75294ad2cec023bba60) and on this PR's head commit (6c9f9473e5cbe38cf0d01ec890eced284a9bb711):Not tested
D16buffer format loads (lower_mem.rslines 1291/1336/1364) and image format stores (lower_image.rs), which are outsideLw::fmt_encode.--release).AI use
Lw::fmt_encodeagainst HLSLfmt_encode(#1929), implemented the saturation and RTZ fix, HLSL/direct DXIL GPU regression test, and PR description; all tests and paired 60s smoke runs were verified locally on RTX 4060 hardware.@raylitebull on GitHub · 2026-11-25 01:51 UTC · original
Diff audit passed on
6c9f947(Lw::fmt_encodesaturatingty == 4UINT to[0, mu]andty == 5SINT to[!ms, ms]forw < 32, and usingf16_rtz(f)for float formats matching HLSLfmt_encode, plusgpu_fmt_encode_direct_dxil_int_sat_and_f16_rtz).PR descriptionis green and RTX 4060 passed (1103workspace + paired smoke).Remaining before merge:
Build and test (Windows, no GPU)completion plus one independent AMD GPU verification pass on6c9f947.@WebIdentity1 on GitHub · 2026-11-25 01:52 UTC · original · edited 2026-11-25 01:54 UTC
Independent AMD verification of
6c9f9473e5cbe38cf0d01ec890eced284a9bb711: integer saturation is fixed; the fixture's float outputs already matched RTZ on the parent on this GPU, consistent with @upipibi's NVIDIA observation.Tested
Windows 10 Home 19045, Ryzen 7 7800X3D, AMD Radeon(TM) Graphics iGPU driver
32.0.21030.2001, native wave64; Rust/Cargo 1.98.1 x64 MSVC, DXC/DXIL 1.8.2502.11, unoptimized debug test profile.XCL_ADAPTER=AMD; adapter/native64 printed by the fixture.Compared parent
8f5fca5bb9ad6e695093d75294ad2cec023bba60with the same added regression versus PR head. The only head overlay is two diagnosticprintln!lines: adapter and all 13 packed outputs before assertions. No runtime or expected-value changes. Both 317-file source manifests matched before/after and the local snapshots; XCL recompiled both.cargo test --locked -p xcl --lib -- gpu_fmt_encode_direct_dxil_int_sat_and_f16_rtz --test-threads=1 --show-output: parent 0 passed / 1 failed / 0 ignored, head 1 / 0 / 0, zero skips both. Each fixture explicitly compiles and dispatches HLSL and Direct DXIL. Parent HLSL passes; parent Direct DXIL fails first at16_16_UINT(ffff1170instead offfffffff). Outputs logged before that assertion establish five integer mismatches and zero float mismatches.XCL_DIRECT_DXIL=1:cargo test --locked -p xcl --lib -- gpu_fmt_encode_int_sat_and_f16_rtz gpu_pknorm_i16_f32_nan_and_fmt_encode_snorm_ufloat --test-threads=1 --show-output: 2 / 0 / 0, zero skips.All 13 head words match HLSL and the fixture's CPU constants. Parent and head float words are identical:
fbff7bff bc003c00 fc007c00 80000000 f7ff03df 780003f0(finite overflow, normal RTZ, infinities, subnormal/-0, and 11/11/10 cases). This verifies the selected float cases; it is not exhaustive proof of conversion equivalence or a native RDNA2 instruction oracle. The fixture uses uniform lane values and checks packed memory outputs, not distinct per-lane addresses.Not tested
Full workspace, retail smoke/gameplay, NVIDIA/Intel in this pass, exhaustive float inputs/NaN payloads, image stores/D16 loads, release profile, or compilation/runtime performance and memory cost. The floating-point replacement makes the implementation explicit; this experiment does not show changed float results or a speed benefit. Required full-suite/retail gates remain separate.
AI use — Codex (GPT-6) inspected the source, added the two diagnostic lines, transferred/ran/verified the native comparison and controls, and drafted this report. The fix and regression remain the PR author's work.
Two-line diagnostic overlay on PR head
@nnonno91 on GitHub · 2026-11-25 01:54 UTC · original
I checked the immediate-format stores (
TBUFFER_STORE_FORMAT_*, MTBUF) on the Radeon. These take the storage format from the instruction. The regression test in this PR uses descriptor-format stores (BUFFER_STORE_FORMAT_*, MUBUF).Tested
6c9f9473e5cbe38cf0d01ec890eced284a9bb711and its parent8f5fca5bb9ad6e695093d75294ad2cec023bba60. AMD Radeon(TM) Graphics, driver 32.0.21042.62, Ryzen 7 9800X3D, Windows 11 25H2 build 26200.9974, Rust 1.100.0 MSVC, SDK DXC/DXIL 1.8.2502.11, unoptimized test profile. The runner reported the Radeon and native wave64 support.32_UINT. Both shader translation paths ran. Command on both revisions wascargo test --locked -p xcl --lib gpu::recomp::tests::local_mtbuf_format_stores -- --exact --nocapture --test-threads=1withXCL_ADAPTER=AMD RadeonandXCL_REQUIRE_GPU=wave64. This was a temporary local test. I printed all 13 readbacks before the first assertion.gpu::recomp::tests::gpu_fmt_encode_direct_dxil_int_sat_and_f16_rtzalso passed on the head with the same command and its exact test name. All three runs had 0 ignored and no skips.Not tested
Retail gameplay, the full workspace suite, and other adapters in this check.
AI use
OpenAI Codex (GPT-6) adapted the test, ran the comparisons and wrote this report.
@upipibi on GitHub · 2026-11-25 01:51 UTC · original · edited 2026-11-25 01:58 UTC
A data point on the float half, from measuring on an RTX 3070 (616.56) and WARP, not on this branch.
self.s.f32_to_f16is DXIL'slegacyF32ToF16(dxil/ops.rs:442), and on D3D12 it already rounds toward zero.1 + 3·2⁻¹¹gives0x3c01, 70000 gives0x7bffand −70000 gives0xfbff, the same asf16_rtz. So switchingfmt_encode's FLOAT stores tof16_rtzdoesn't change the bits on those devices. It makes the rounding explicit rather than driver-defined, which is still worth having. The UINT/SINT saturation is the part that changes results. The details are in #2026, where the same truncation shows up on the D16 read side.Evidence for the integer half, measured on
mainc00f3fc(RTX 3070):gpu_fmt_encode_int_sat_and_f16_rtzfails withXCL_DIRECT_DXIL=1(16_16_UINT saturates 70000 -> 65535, left0xffff1170), so this PR is what makes that test pass on the direct path.AI-assisted (Claude Code).