Direct DXIL: avoid 2 - off underflow in s_setreg_b32 targeting HW_REG_MODE bit 3 #1869

Manually merged
github merged 1 commit from gh-pr/1869/head into gh-pr/1869/base 2026-11-26 05:07:58 +00:00
Owner

@⁠emirduran707 on GitHub · 2026-11-24 22:19 UTC · original
emirduran707:dxil-setreg-mode-bit3-underflow → main · +32 −3 · 2 files · 1 commits · merged 2026-11-24 23:54 UTC

When s_setreg_b32 writes only bit 3 of HW_REG_MODE (off == 3, dp_mask == 2, e.g. SIMM16 = 0x00C1) in a shader with dynamic f16 rounding, Lw::setreg computed let sh = 2 - off; before matching dp_mask, panicking with integer underflow (attempt to subtract with overflow).

recomp/emit.rs computes 2 - off only inside the dp_mask == 3 and dp_mask == 1 arms (where off <= 2). This moves 2 - off into those two arms in dxil/lower.rs.

What is in it

  • crates/xcl/src/gpu/dxil/lower.rs: compute 2 - off only inside the dp_mask == 3 and dp_mask == 1 arms of Lw::setreg.
  • crates/xcl/src/gpu/dxil/core_tests.rs: GPU parity test s_setreg_b32_mode_bit3_does_not_underflow against HLSL.

Tested

  • AMD Radeon RX 9060 XT (driver 32.0.31044.16), Ryzen 5 5600, Windows 11 Pro 26300, Rust 1.100.0; tests debug, smoke release
  • cargo test --workspace -- --test-threads=4 on ecb7547: 960 passed, 0 failed, 43 ignored; 8 SKIPPED (6 in lower_dxil::tests::{f16,f32}_programs_on_the_gpu; heap_window_out_of_memory_falls_back_to_the_switch_form; pso_measurement_compiles_an_exact_synthetic_record)
  • s_setreg_b32_mode_bit3_does_not_underflow before the change panicked (the direct DXIL translator panicked: attempt to subtract with overflow); passes and matches HLSL (0x3C00, 0xBC01) after

Regression run

main:

xcl-smoke v1
commit: c4d37bec1bb4286eb373aea963404a23f13401fa
gpu: AMD Radeon RX 9060 XT
title: 21222967
seconds: 60
exit: 0x0
frames shown: 1539 (PresentX 1539)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14791 MB

this PR:

xcl-smoke v1
commit: ecb75479bc77e2ac2b34175754b046468a034c3c
gpu: AMD Radeon RX 9060 XT
title: 21222967
seconds: 60
exit: 0x0
frames shown: 1580 (PresentX 1580)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14781 MB

Not tested

  • NVIDIA and Intel GPUs.
  • The smoke title's run is a regression check only.

AI use

  • Antigravity with Gemini 4 Neon: found the bug, wrote the fix, GPU parity test and this description, and ran the test suite and smoke runs above.
**@⁠emirduran707** on GitHub · 2026-11-24 22:19 UTC · [original](https://github.com/xcl-dev/xcl/pull/1869) `emirduran707:dxil-setreg-mode-bit3-underflow` → `main` · +32 −3 · 2 files · 1 commits · merged 2026-11-24 23:54 UTC When `s_setreg_b32` writes only bit 3 of `HW_REG_MODE` (`off == 3`, `dp_mask == 2`, e.g. `SIMM16 = 0x00C1`) in a shader with dynamic f16 rounding, `Lw::setreg` computed `let sh = 2 - off;` before matching `dp_mask`, panicking with integer underflow (`attempt to subtract with overflow`). `recomp/emit.rs` computes `2 - off` only inside the `dp_mask == 3` and `dp_mask == 1` arms (where `off <= 2`). This moves `2 - off` into those two arms in `dxil/lower.rs`. **What is in it** - `crates/xcl/src/gpu/dxil/lower.rs`: compute `2 - off` only inside the `dp_mask == 3` and `dp_mask == 1` arms of `Lw::setreg`. - `crates/xcl/src/gpu/dxil/core_tests.rs`: GPU parity test `s_setreg_b32_mode_bit3_does_not_underflow` against HLSL. **Tested** - AMD Radeon RX 9060 XT (driver 32.0.31044.16), Ryzen 5 5600, Windows 11 Pro 26300, Rust 1.100.0; tests debug, smoke release - `cargo test --workspace -- --test-threads=4` on ecb7547: 960 passed, 0 failed, 43 ignored; 8 SKIPPED (6 in `lower_dxil::tests::{f16,f32}_programs_on_the_gpu`; `heap_window_out_of_memory_falls_back_to_the_switch_form`; `pso_measurement_compiles_an_exact_synthetic_record`) - `s_setreg_b32_mode_bit3_does_not_underflow` before the change panicked (`the direct DXIL translator panicked: attempt to subtract with overflow`); passes and matches HLSL (`0x3C00`, `0xBC01`) after **Regression run** main: ``` xcl-smoke v1 commit: c4d37bec1bb4286eb373aea963404a23f13401fa gpu: AMD Radeon RX 9060 XT title: 21222967 seconds: 60 exit: 0x0 frames shown: 1539 (PresentX 1539) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 14791 MB ``` this PR: ``` xcl-smoke v1 commit: ecb75479bc77e2ac2b34175754b046468a034c3c gpu: AMD Radeon RX 9060 XT title: 21222967 seconds: 60 exit: 0x0 frames shown: 1580 (PresentX 1580) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 14781 MB ``` **Not tested** - NVIDIA and Intel GPUs. - The smoke title's run is a regression check only. **AI use** - Antigravity with Gemini 4 Neon: found the bug, wrote the fix, GPU parity test and this description, and ran the test suite and smoke runs above.
When `s_setreg_b32` writes only bit 3 of `HW_REG_MODE` (`off == 3`,
`dp_mask == 2`, e.g. `SIMM16 = 0x00C1`) in a shader with dynamic f16 rounding,
`Lw::setreg` computed `let sh = 2 - off;` before matching `dp_mask`, panicking
with integer underflow (`attempt to subtract with overflow`).

`emit.rs` only computes `2 - off` inside the `dp_mask == 3` and `dp_mask == 1`
arms where `off <= 2`. Move `2 - off` into those two arms in `dxil/lower.rs`
and add a GPU parity test against HLSL.

Assisted-by: Antigravity (Gemini 4 Neon)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:07:57 +00:00
github manually merged commit ecb75479bc into gh-pr/1869/base 2026-11-26 05:07:58 +00:00
Author
Owner

@⁠frenziedcoder on GitHub · 2026-11-24 22:25 UTC · original

NVIDIA test report for ecb7547: full suite green, its own test s_setreg_b32_mode_bit3_does_not_underflow passes, and a clean smoke pair on the retail title (1653 vs 1654 frames).

Tested

  • NVIDIA GeForce RTX 5080 16 GB (driver 617.14, 32-lane waves), AMD Ryzen 7 9800X3D, 64 GB, Windows 11 Pro 25H2 (26200.9974), rustc 1.100.0 stable-x86_64-pc-windows-msvc, DXC 1.8.2502.11 (SDK 10.0.26100.0). Exact head ecb75479bc77e2ac2b34175754b046468a034c3c, no local changes.
  • cargo build --workspace && cargo test --workspace -- --test-threads=4 (debug): 960 passed, 0 failed, 43 ignored; the PR's own test s_setreg_b32_mode_bit3_does_not_underflow passes. SKIPPED: gpu::recomp::lower::tests::a_2d_or_3d_group_agrees_with_the_hlsl_path_on_the_gpu (no wave64), gpu::recomp::lower::tests::coalesced_guarded_runs_agree_with_the_hlsl_path_on_the_gpu (no wave64), gpu::recomp::lower::tests::cross_lane_reads_agree_with_the_hlsl_path_on_the_gpu (no wave64), gpu::recomp::lower::tests::the_wave64_lowering_agrees_with_the_hlsl_path_on_the_gpu (no wave64), gpu::recomp::lower_dxil::tests::a_per_lane_2d_or_3d_group_runs_on_the_gpu (no wave64), gpu::recomp::lower_dxil::tests::f16_programs_on_the_gpu (f16 arithmetic, wave32, per-lane form: refused (unsupported V_MUL_F16 (its #1426 semantics differ from the console's))), gpu::recomp::lower_dxil::tests::f16_programs_on_the_gpu (f16 arithmetic, wave64: no wave64), gpu::recomp::lower_dxil::tests::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))), gpu::recomp::lower_dxil::tests::f16_programs_on_the_gpu (f16 packed, wave64: no wave64), gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu (f32 arithmetic, wave64: no wave64), gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu (f32 compares, wave64: no wave64), gpu::recomp::lower_dxil::tests::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))), gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu (f32 conversions, wave64: no wave64), gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu (f32 rounding, wave64: no wave64), gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu (f32 three-source, wave64: no wave64), gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu (f32 transcendentals, wave64: no wave64), gpu::recomp::lower_dxil::tests::f64_programs_on_the_gpu (f64, wave64: no wave64), gpu::recomp::lower_dxil::tests::integer_programs_on_the_gpu (integer arithmetic, wave64: no wave64), gpu::recomp::lower_dxil::tests::integer_programs_on_the_gpu (integer carries, wave64: no wave64), gpu_geometry_wave32_prefix_count_over_a_mask (no wave64), gpu_wave32_program_in_wave64_hardware (no wave64), heap_window_out_of_memory_falls_back_to_the_switch_form (no heap windows).
  • test_title_draws_with_a_root_signature_under_the_debug_layer reports ok, but this machine has no D3D12 debug layer (debug layer requested but unavailable … (0x887A002D)), so it ran without the layer and is no evidence either way.

Regression run (scripts/smoke.ps1 -Seconds 60, release, the retail title of #505 at its start screen; XCL_PSO_PRELOAD=0 for both builds, because this machine's preload list holds the program of #1307)

base (1d027e5, this PR's merge base with main):

xcl-smoke v1
commit: 1d027e5c76c9a86a7ee2ca1cc677edf0be95d331
gpu: NVIDIA GeForce RTX 5080
title: 16b5e5d4
seconds: 60
exit: 0x0
frames shown: 1654 (PresentX 1654)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14598 MB

this PR:

xcl-smoke v1
commit: ecb75479bc77e2ac2b34175754b046468a034c3c
gpu: NVIDIA GeForce RTX 5080
title: 16b5e5d4
seconds: 60
exit: 0x0
frames shown: 1653 (PresentX 1654)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14603 MB

Not tested: this code in the title: it is on the opt-in direct-DXIL path (XCL_DIRECT_DXIL), which the smoke runs leave unset (default HLSL backend), so they show only that nothing else regressed; the world load (the smoke runs stop at the start screen, so code that only runs later is not exercised there); AMD.

AI use: Claude Code (Claude Opus 5.5) built and ran the tests and smoke runs on my machine and wrote this report; I checked it.

**@⁠frenziedcoder** on GitHub · 2026-11-24 22:25 UTC · [original](https://github.com/xcl-dev/xcl/pull/1869#issuecomment-7146219741) **NVIDIA test report for `ecb7547`: full suite green, its own test `s_setreg_b32_mode_bit3_does_not_underflow` passes, and a clean smoke pair on the retail title (1653 vs 1654 frames).** **Tested** - NVIDIA GeForce RTX 5080 16 GB (driver 617.14, 32-lane waves), AMD Ryzen 7 9800X3D, 64 GB, Windows 11 Pro 25H2 (26200.9974), rustc 1.100.0 `stable-x86_64-pc-windows-msvc`, DXC 1.8.2502.11 (SDK 10.0.26100.0). Exact head `ecb75479bc77e2ac2b34175754b046468a034c3c`, no local changes. - `cargo build --workspace && cargo test --workspace -- --test-threads=4` (debug): **960 passed, 0 failed, 43 ignored**; the PR's own test `s_setreg_b32_mode_bit3_does_not_underflow` passes. SKIPPED: `gpu::recomp::lower::tests::a_2d_or_3d_group_agrees_with_the_hlsl_path_on_the_gpu` (no wave64), `gpu::recomp::lower::tests::coalesced_guarded_runs_agree_with_the_hlsl_path_on_the_gpu` (no wave64), `gpu::recomp::lower::tests::cross_lane_reads_agree_with_the_hlsl_path_on_the_gpu` (no wave64), `gpu::recomp::lower::tests::the_wave64_lowering_agrees_with_the_hlsl_path_on_the_gpu` (no wave64), `gpu::recomp::lower_dxil::tests::a_per_lane_2d_or_3d_group_runs_on_the_gpu` (no wave64), `gpu::recomp::lower_dxil::tests::f16_programs_on_the_gpu` (f16 arithmetic, wave32, per-lane form: refused (unsupported V_MUL_F16 (its #1426 semantics differ from the console's))), `gpu::recomp::lower_dxil::tests::f16_programs_on_the_gpu` (f16 arithmetic, wave64: no wave64), `gpu::recomp::lower_dxil::tests::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))), `gpu::recomp::lower_dxil::tests::f16_programs_on_the_gpu` (f16 packed, wave64: no wave64), `gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu` (f32 arithmetic, wave64: no wave64), `gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu` (f32 compares, wave64: no wave64), `gpu::recomp::lower_dxil::tests::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))), `gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu` (f32 conversions, wave64: no wave64), `gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu` (f32 rounding, wave64: no wave64), `gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu` (f32 three-source, wave64: no wave64), `gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu` (f32 transcendentals, wave64: no wave64), `gpu::recomp::lower_dxil::tests::f64_programs_on_the_gpu` (f64, wave64: no wave64), `gpu::recomp::lower_dxil::tests::integer_programs_on_the_gpu` (integer arithmetic, wave64: no wave64), `gpu::recomp::lower_dxil::tests::integer_programs_on_the_gpu` (integer carries, wave64: no wave64), `gpu_geometry_wave32_prefix_count_over_a_mask` (no wave64), `gpu_wave32_program_in_wave64_hardware` (no wave64), `heap_window_out_of_memory_falls_back_to_the_switch_form` (no heap windows). - `test_title_draws_with_a_root_signature_under_the_debug_layer` reports ok, but this machine has no D3D12 debug layer (`debug layer requested but unavailable … (0x887A002D)`), so it ran without the layer and is no evidence either way. **Regression run** (`scripts/smoke.ps1 -Seconds 60`, release, the retail title of #505 at its start screen; `XCL_PSO_PRELOAD=0` for both builds, because this machine's preload list holds the program of #1307) base (`1d027e5`, this PR's merge base with `main`): ``` xcl-smoke v1 commit: 1d027e5c76c9a86a7ee2ca1cc677edf0be95d331 gpu: NVIDIA GeForce RTX 5080 title: 16b5e5d4 seconds: 60 exit: 0x0 frames shown: 1654 (PresentX 1654) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 14598 MB ``` this PR: ``` xcl-smoke v1 commit: ecb75479bc77e2ac2b34175754b046468a034c3c gpu: NVIDIA GeForce RTX 5080 title: 16b5e5d4 seconds: 60 exit: 0x0 frames shown: 1653 (PresentX 1654) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 14603 MB ``` **Not tested:** this code in the title: it is on the opt-in direct-DXIL path (`XCL_DIRECT_DXIL`), which the smoke runs leave unset (default HLSL backend), so they show only that nothing else regressed; the world load (the smoke runs stop at the start screen, so code that only runs later is not exercised there); AMD. *AI use: Claude Code (Claude Opus 5.5) built and ran the tests and smoke runs on my machine and wrote this report; I checked it.*
Author
Owner

@⁠upipibi on GitHub · 2026-11-24 22:43 UTC · original

NVIDIA counterpart to the Radeon run: RTX 3070 8 GB, driver 616.56, Windows 11, debug, ecb7547 on main 689f2db.

  • s_setreg_b32_mode_bit3_does_not_underflow (direct DXIL against HLSL, MODE[3:2] = round toward −∞): passes, 2 of 2 runs.
  • dxil::core_tests and setreg: 13 passed, 0 failed, 1 ignored.

AI-assisted (Claude Code). Synthetic tests only.

**@⁠upipibi** on GitHub · 2026-11-24 22:43 UTC · [original](https://github.com/xcl-dev/xcl/pull/1869#issuecomment-7146568753) NVIDIA counterpart to the Radeon run: RTX 3070 8 GB, driver 616.56, Windows 11, debug, `ecb7547` on `main` `689f2db`. - `s_setreg_b32_mode_bit3_does_not_underflow` (direct DXIL against HLSL, MODE[3:2] = round toward −∞): passes, 2 of 2 runs. - `dxil::core_tests` and `setreg`: 13 passed, 0 failed, 1 ignored. AI-assisted (Claude Code). Synthetic tests only.
Author
Owner

@⁠DavidM1911 on GitHub · 2026-11-25 01:45 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 01:45 UTC · [original](https://github.com/xcl-dev/xcl/pull/1869#issuecomment-7149928862) 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.