Recompiler: saturate UINT/SINT and use RTZ in fmt_encode #1929

Manually merged
github merged 1 commit from gh-pr/1929/head into gh-pr/1929/base 2026-11-26 05:10:08 +00:00
Owner

@⁠n-romanovich on GitHub · 2026-11-24 23:40 UTC · original
n-romanovich:recomp/fmt-encode-sat-rtz-unorm → main · +47 −4 · 2 files · 1 commits · merged 2026-11-25 01:00 UTC

Addresses #1489 (XCL-BT-026).

In fmt_encode:

  1. UINT (ty == 4u) and SINT (ty == 5u) channels narrower than 32 bits previously returned raw x and relied on put_bits masking, wrapping out-of-range integers instead of saturating them to [0, (1 << w) - 1] / [-(1 << (w - 1)), (1 << (w - 1)) - 1].
  2. 16-, 11-, and 10-bit FLOAT stores previously used f32tof16, overflowing finite values above 65504.0 to +Inf instead of saturating to max finite via f16_rtz (while preserving true ±Inf).

What is in it

  • crates/xcl/src/gpu/recomp/emit.rs:
    • Move f16_rtz before fmt_encode.
    • Saturate UINT (ty == 4u) and SINT (ty == 5u) values when w < 32u.
    • Use f16_rtz(f) for 16-, 11-, and 10-bit FLOAT formats.
  • crates/xcl/src/gpu/recomp/tests.rs:
    • Add GPU test gpu_fmt_encode_int_sat_and_f16_rtz covering 16_16_UINT, 16_16_SINT, 16_16_FLOAT, and 11_11_10_FLOAT.

Tested
Hardware: Windows 11 x64, NVIDIA GeForce RTX 5060 Ti.

  • cargo test -p xcl --lib fmt_encode -- --test-threads=4: 2 passed, 0 failed, 0 ignored (951 filtered out)
  • cargo test --workspace -- --test-threads=4: 977 passed, 0 failed, 45 ignored
    • SKIPPED: 21 gpu::recomp wave64 / refused per-lane f16 tests (no wave64 / refused per-lane f16), shaders::tests::pso_measurement_compiles_an_exact_synthetic_record (Windows Developer Mode is required, 0x887A002D), heap_window_out_of_memory_falls_back_to_the_switch_form (no heap windows)

Regression run
Main (20cf13022f764208384c610c2ae6a3f4eed201a2):

xcl-smoke v1
commit: 20cf13022f764208384c610c2ae6a3f4eed201a2
gpu: NVIDIA GeForce RTX 5060 Ti
title: FILES
seconds: 60
exit: 0x0
frames shown: 1530 (PresentX 1530)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 17380 MB

PR (ffc90817f895a943b1bd885afc6cd6270d3c0441):

xcl-smoke v1
commit: ffc90817f895a943b1bd885afc6cd6270d3c0441
gpu: NVIDIA GeForce RTX 5060 Ti
title: FILES
seconds: 60
exit: 0x0
frames shown: 1506 (PresentX 1506)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14857 MB

Not tested

  • macOS / Linux (crate targets Windows only).
  • AMD / wave64-capable GPU.

AI use

  • Antigravity (model name not provided): implemented the fix and GPU test, ran the test suite and smoke.ps1 runs.
**@⁠n-romanovich** on GitHub · 2026-11-24 23:40 UTC · [original](https://github.com/xcl-dev/xcl/pull/1929) `n-romanovich:recomp/fmt-encode-sat-rtz-unorm` → `main` · +47 −4 · 2 files · 1 commits · merged 2026-11-25 01:00 UTC Addresses #1489 (`XCL-BT-026`). In `fmt_encode`: 1. `UINT` (`ty == 4u`) and `SINT` (`ty == 5u`) channels narrower than 32 bits previously returned raw `x` and relied on `put_bits` masking, wrapping out-of-range integers instead of saturating them to `[0, (1 << w) - 1]` / `[-(1 << (w - 1)), (1 << (w - 1)) - 1]`. 2. 16-, 11-, and 10-bit `FLOAT` stores previously used `f32tof16`, overflowing finite values above `65504.0` to `+Inf` instead of saturating to max finite via `f16_rtz` (while preserving true `±Inf`). **What is in it** - `crates/xcl/src/gpu/recomp/emit.rs`: - Move `f16_rtz` before `fmt_encode`. - Saturate `UINT` (`ty == 4u`) and `SINT` (`ty == 5u`) values when `w < 32u`. - Use `f16_rtz(f)` for 16-, 11-, and 10-bit `FLOAT` formats. - `crates/xcl/src/gpu/recomp/tests.rs`: - Add GPU test `gpu_fmt_encode_int_sat_and_f16_rtz` covering `16_16_UINT`, `16_16_SINT`, `16_16_FLOAT`, and `11_11_10_FLOAT`. **Tested** Hardware: Windows 11 x64, NVIDIA GeForce RTX 5060 Ti. - `cargo test -p xcl --lib fmt_encode -- --test-threads=4`: 2 passed, 0 failed, 0 ignored (`951 filtered out`) - `cargo test --workspace -- --test-threads=4`: 977 passed, 0 failed, 45 ignored - `SKIPPED`: 21 `gpu::recomp` wave64 / refused per-lane f16 tests (`no wave64` / refused per-lane f16), `shaders::tests::pso_measurement_compiles_an_exact_synthetic_record` (`Windows Developer Mode is required`, `0x887A002D`), `heap_window_out_of_memory_falls_back_to_the_switch_form` (`no heap windows`) **Regression run** Main (`20cf13022f764208384c610c2ae6a3f4eed201a2`): ``` xcl-smoke v1 commit: 20cf13022f764208384c610c2ae6a3f4eed201a2 gpu: NVIDIA GeForce RTX 5060 Ti title: FILES seconds: 60 exit: 0x0 frames shown: 1530 (PresentX 1530) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 17380 MB ``` PR (`ffc90817f895a943b1bd885afc6cd6270d3c0441`): ``` xcl-smoke v1 commit: ffc90817f895a943b1bd885afc6cd6270d3c0441 gpu: NVIDIA GeForce RTX 5060 Ti title: FILES seconds: 60 exit: 0x0 frames shown: 1506 (PresentX 1506) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 14857 MB ``` **Not tested** - macOS / Linux (crate targets Windows only). - AMD / wave64-capable GPU. **AI use** - Antigravity (model name not provided): implemented the fix and GPU test, ran the test suite and `smoke.ps1` runs.
Addresses #1489 (XCL-BT-026).

In fmt_encode:
- Saturate UINT and SINT values to the target channel bit width when
  w < 32 instead of letting put_bits mask/wrap out-of-range integers.
- Use f16_rtz for 16-, 11-, and 10-bit FLOAT stores so finite values
  above 65504 saturate to max finite instead of overflowing to +Inf,
  while preserving true +-Inf.

Tested: cargo test --workspace -- --test-threads=4.

Assisted-by: Antigravity (model name not provided)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:10:05 +00:00
github manually merged commit ffc90817f8 into gh-pr/1929/base 2026-11-26 05:10:08 +00:00
Author
Owner

@⁠futurepro62 on GitHub · 2026-11-24 23:56 UTC · original · edited 2026-11-25 00:03 UTC

Full-suite run, since this PR has no test report yet. Tested exact head ffc9081 (on its base 20cf130).

Tested

  • NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 621.40, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.100.0 MSVC, DXC + dxil.dll 1.9.2602.17 (Windows SDK 10.0.26100), debug, D3D12 debug layer installed.
  • cargo build --workspace, then XCL_REQUIRE_GPU=mesh cargo test --workspace -- --test-threads=4 --skip heap_window_out_of_memory_falls_back_to_the_switch_form --skip gpu::recomp::lower_dxil::tests::f16_programs_on_the_gpu --skip gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu --skip gpu::recomp::lower_dxil::tests::integer_programs_on_the_gpu --skip gpu::recomp::lower_dxil::tests::f64_programs_on_the_gpu --skip gpu::dxil::fuzz_tests: 967 passed, 0 failed, 43 ignored. SKIPPED (no wave64): a_2d_or_3d_group_agrees_with_the_hlsl_path_on_the_gpu, a_per_lane_2d_or_3d_group_runs_on_the_gpu, coalesced_guarded_runs_agree_with_the_hlsl_path_on_the_gpu, cross_lane_reads_agree_with_the_hlsl_path_on_the_gpu, gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware, the_wave64_lowering_agrees_with_the_hlsl_path_on_the_gpu.
  • The new tests ran and passed: gpu_fmt_encode_int_sat_and_f16_rtz.
  • Same head on the AMD Radeon integrated GPU (iGPU) of the Ryzen 7 9800X3D (RDNA2, XCL_ADAPTER=radeon), cargo test --workspace -- --test-threads=4 --skip gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1: 976 passed, 0 failed, 45 ignored. SKIPPED: f16_programs_on_the_gpu (f16 arithmetic, wave32, per-lane form: refused (unsupported V_MUL_F16 (its #1426 semantics differ from the console's))), f16_programs_on_the_gpu (f16 arithmetic, wave64, per-lane form: refused (unsupported V_MUL_F16 (its #1426 semantics differ from the console's))), f16_programs_on_the_gpu (f16 packed, wave32, per-lane form: refused (unsupported V_PK_MUL_F16: VOP3 modifiers (its #1426 semantics differ from the console's))), f16_programs_on_the_gpu (f16 packed, wave64, per-lane form: refused (unsupported V_PK_MUL_F16: VOP3 modifiers (its #1426 semantics differ from the console's))), f32_programs_on_the_gpu (f32 conversions, wave32, per-lane form: refused (unsupported V_CVT_F16_F32 (its #1426 semantics differ from the console's))), f32_programs_on_the_gpu (f32 conversions, wave64, per-lane form: refused (unsupported V_CVT_F16_F32 (its #1426 semantics differ from the console's))), heap_window_out_of_memory_falls_back_to_the_switch_form (no heap windows).
  • --skip leaves out tests that fail on main 62265d3 too, not because of this PR. On NVIDIA: heap_window_out_of_memory_falls_back_to_the_switch_form (#1651) and the four gpu::recomp::lower_dxil::tests::*_programs_on_the_gpu tests (follow-up on #1651) fail because runner::skip_test turns their skips into failures under XCL_REQUIRE_GPU=mesh, and gpu::dxil::fuzz_tests seeds 70, 545, 1019 and 1507 fail CreateComputePipelineState with E_OUTOFMEMORY on this card (drivers 616.64 and 621.40). On AMD: fuzz_validate_and_gpu_1 fails on seed 540 (res[833] 0x7 vs CPU 0x6). The AMD run does not set XCL_REQUIRE_GPU.

Not tested

  • a release build, a game (test run only).

AI use

  • Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.
**@⁠futurepro62** on GitHub · 2026-11-24 23:56 UTC · [original](https://github.com/xcl-dev/xcl/pull/1929#issuecomment-7147956317) · edited 2026-11-25 00:03 UTC Full-suite run, since this PR has no test report yet. Tested exact head `ffc9081` (on its base `20cf130`). **Tested** - NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 621.40, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.100.0 MSVC, DXC + dxil.dll 1.9.2602.17 (Windows SDK 10.0.26100), debug, D3D12 debug layer installed. - `cargo build --workspace`, then `XCL_REQUIRE_GPU=mesh cargo test --workspace -- --test-threads=4 --skip heap_window_out_of_memory_falls_back_to_the_switch_form --skip gpu::recomp::lower_dxil::tests::f16_programs_on_the_gpu --skip gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu --skip gpu::recomp::lower_dxil::tests::integer_programs_on_the_gpu --skip gpu::recomp::lower_dxil::tests::f64_programs_on_the_gpu --skip gpu::dxil::fuzz_tests`: **967 passed, 0 failed, 43 ignored**. SKIPPED (no wave64): `a_2d_or_3d_group_agrees_with_the_hlsl_path_on_the_gpu`, `a_per_lane_2d_or_3d_group_runs_on_the_gpu`, `coalesced_guarded_runs_agree_with_the_hlsl_path_on_the_gpu`, `cross_lane_reads_agree_with_the_hlsl_path_on_the_gpu`, `gpu_geometry_wave32_prefix_count_over_a_mask`, `gpu_wave32_program_in_wave64_hardware`, `the_wave64_lowering_agrees_with_the_hlsl_path_on_the_gpu`. - The new tests ran and passed: `gpu_fmt_encode_int_sat_and_f16_rtz`. - Same head on the AMD Radeon integrated GPU (iGPU) of the Ryzen 7 9800X3D (RDNA2, `XCL_ADAPTER=radeon`), `cargo test --workspace -- --test-threads=4 --skip gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1`: **976 passed, 0 failed, 45 ignored**. SKIPPED: `f16_programs_on_the_gpu` (f16 arithmetic, wave32, per-lane form: refused (unsupported V_MUL_F16 (its #1426 semantics differ from the console's))), `f16_programs_on_the_gpu` (f16 arithmetic, wave64, per-lane form: refused (unsupported V_MUL_F16 (its #1426 semantics differ from the console's))), `f16_programs_on_the_gpu` (f16 packed, wave32, per-lane form: refused (unsupported V_PK_MUL_F16: VOP3 modifiers (its #1426 semantics differ from the console's))), `f16_programs_on_the_gpu` (f16 packed, wave64, per-lane form: refused (unsupported V_PK_MUL_F16: VOP3 modifiers (its #1426 semantics differ from the console's))), `f32_programs_on_the_gpu` (f32 conversions, wave32, per-lane form: refused (unsupported V_CVT_F16_F32 (its #1426 semantics differ from the console's))), `f32_programs_on_the_gpu` (f32 conversions, wave64, per-lane form: refused (unsupported V_CVT_F16_F32 (its #1426 semantics differ from the console's))), `heap_window_out_of_memory_falls_back_to_the_switch_form` (no heap windows). - `--skip` leaves out tests that fail on main `62265d3` too, not because of this PR. On NVIDIA: `heap_window_out_of_memory_falls_back_to_the_switch_form` (#1651) and the four `gpu::recomp::lower_dxil::tests::*_programs_on_the_gpu` tests ([follow-up on #1651](https://git.gtahub.st/github/xcl-dev--xcl/issues/1651)) fail because `runner::skip_test` turns their skips into failures under `XCL_REQUIRE_GPU=mesh`, and `gpu::dxil::fuzz_tests` seeds 70, 545, 1019 and 1507 fail `CreateComputePipelineState` with `E_OUTOFMEMORY` on this card (drivers 616.64 and 621.40). On AMD: `fuzz_validate_and_gpu_1` fails on seed 540 (`res[833]` 0x7 vs CPU 0x6). The AMD run does not set `XCL_REQUIRE_GPU`. **Not tested** - a release build, a game (test run only). **AI use** - Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.
Author
Owner

@⁠DarkPanda69 on GitHub · 2026-11-25 00:11 UTC · original

AMD run with native 64-lane waves, which this PR lists as not tested (the other report here is NVIDIA).

Tested: pass, head ffc9081 applied on main 80f4819, debug, Rust 1.100.0, Windows 11 Pro 26200, Ryzen 7 5800X, DXC 1.9.2602.17.
cargo test -p xcl --lib -- gpu:: --test-threads=4:

  • AMD RX 9070 XT (RDNA4), driver 32.0.32029.2010, waves 32..64: 463 passed, 2 failed, 21 ignored. gpu_fmt_encode_int_sat_and_f16_rtz ok. The 2 failures are gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1 and _3, which fail the same way on main 80f4819 without this PR on this card, so they are not from this change.
  • NVIDIA RTX 3060, driver 32.0.16.1088: 465 passed, 0 failed, 21 ignored. gpu_fmt_encode_int_sat_and_f16_rtz ok.

Not tested: Linux; the whole workspace suite; a title.

AI use: Claude Code (Claude Opus 5.5) ran the tests on this machine and wrote this report.

**@⁠DarkPanda69** on GitHub · 2026-11-25 00:11 UTC · [original](https://github.com/xcl-dev/xcl/pull/1929#issuecomment-7148251155) AMD run with native 64-lane waves, which this PR lists as not tested (the other report here is NVIDIA). **Tested:** pass, head `ffc9081` applied on `main` `80f4819`, debug, Rust 1.100.0, Windows 11 Pro 26200, Ryzen 7 5800X, DXC 1.9.2602.17. `cargo test -p xcl --lib -- gpu:: --test-threads=4`: - AMD RX 9070 XT (RDNA4), driver 32.0.32029.2010, waves 32..64: 463 passed, 2 failed, 21 ignored. `gpu_fmt_encode_int_sat_and_f16_rtz` ok. The 2 failures are `gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1` and `_3`, which fail the same way on `main` `80f4819` without this PR on this card, so they are not from this change. - NVIDIA RTX 3060, driver 32.0.16.1088: 465 passed, 0 failed, 21 ignored. `gpu_fmt_encode_int_sat_and_f16_rtz` ok. **Not tested:** Linux; the whole workspace suite; a title. AI use: Claude Code (Claude Opus 5.5) ran the tests on this machine and wrote this report.
Author
Owner

@⁠DavidM1911 on GitHub · 2026-11-25 02:33 UTC · original

Verification on RTX 3060 Ti (Windows 11), branch merged with current main:

  • cargo test -p xcl --lib: all passed, 0 failed, ~26 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling — tracked in #1978; clean on single-threaded rerun.)

Thanks!

**@⁠DavidM1911** on GitHub · 2026-11-25 02:33 UTC · [original](https://github.com/xcl-dev/xcl/pull/1929#issuecomment-7150885142) Verification on RTX 3060 Ti (Windows 11), branch merged with current `main`: - `cargo test -p xcl --lib`: all passed, 0 failed, ~26 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling — tracked in #1978; clean on single-threaded rerun.) Thanks!
This discussion has been locked. Commenting is limited to contributors.
No description provided.