Direct DXIL: guard dp_mask in s_setreg_b32 when writing MODE[1:0] #2300

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

@⁠GustavoEllwanger on GitHub · 2026-11-25 13:03 UTC · original
GustavoEllwanger:fix/dxil-setreg-f32-mode-preserves-fp16-rm → main · +53 −2 · 2 files · 1 commits · merged 2026-11-25 18:16 UTC

When s_setreg_b32 writes only single-precision rounding bits (HW_REG_MODE[1:0], so sp_mask != 0 and dp_mask == 0), Lw::setreg in the direct DXIL translator entered the dp_mask path without checking dp_mask != 0 (unlike s_setreg_imm32_b32 right above it):

  1. When self.dyn_rm was true, match dp_mask fell through 0 into the _ => arm (written for dp_mask == 2) and overwrote bit 1 of VAR_FP16_RM with (src & 1) << 1, silently corrupting subsequent f16 rounding (e.g., turning RTZ 3 into RTP 1 when writing f32 RTN 2).
  2. When self.has_f64_round_op was true, it falsely returned Err("dynamic f64 round mode") even though MODE[3:2] was untouched.

What is in it

  • crates/xcl/src/gpu/dxil/lower.rs: guard the self.has_f64_round_op rejection and self.dyn_rm VAR_FP16_RM update in Lw::setreg for s_setreg_b32 with dp_mask != 0, matching s_setreg_imm32_b32.
  • crates/xcl/src/gpu/dxil/round_tests.rs:
    • gpu_s_setreg_b32_f32_mode_preserves_fp16_round_mode: sets MODE[3:2] to RTZ (3), updates only MODE[1:0] (SIMM16 = 0x0801) to RTN (2) via s_setreg_b32, and verifies both f32 RTN (v_add_f32) and preserved f16 RTZ (v_cvt_f16_f32) bit-exact on the GPU.
    • direct_s_setreg_b32_f32_mode_allows_f64_ops: verifies s_setreg_b32 targeting MODE[1:0] (0x0801, 0x0001, 0x0041) alongside v_add_f64 translates and validates cleanly.

Tested

  • Hardware / toolchain: AMD Ryzen 7 7700, Windows 11, Rust 1.95.0 (59807616e 2026-04-14), DXC 1.8.2502.11, debug build.
    • GPU 1: NVIDIA GeForce RTX 5060 (driver 32.0.16.1088, split-wave64)
    • GPU 2: AMD Radeon(TM) Graphics (RDNA2 iGPU, driver 32.0.21042.62, native wave64)
  • Fail-first before the fix (XCL_ADAPTER=5060 cargo test -p xcl --lib gpu::dxil::round_tests::):
    • gpu_s_setreg_b32_f32_mode_preserves_fp16_round_mode: FAILED (left: 15361 [0x3C01], right: 15360 [0x3C00]).
    • direct_s_setreg_b32_f32_mode_allows_f64_ops: FAILED (s_setreg_b32 0x801, s0: dynamic f64 round mode).
  • Post-fix targeted tests:
    • NVIDIA RTX 5060 (XCL_ADAPTER=5060): gpu::dxil::round_tests:: 8 passed, 0 failed, 0 ignored (0 skipped); gpu::dxil::core_tests:: 16 passed, 0 failed, 1 ignored (0 skipped).
    • AMD Radeon RDNA2 (XCL_ADAPTER=Radeon): gpu::dxil::round_tests:: 8 passed, 0 failed, 0 ignored (0 skipped); gpu::dxil::core_tests:: 16 passed, 0 failed, 1 ignored (0 skipped).
    • Independent AMD Radeon RX 6800M (RDNA2, driver 30.0.13002.13003, courtesy of @⁠luckyteagirl in comment): gpu::dxil::round_tests:: 8 passed, 0 failed, 0 ignored (0 skipped).
  • Full workspace suite (XCL_ADAPTER=5060 cargo test --workspace -- --test-threads=4, NVIDIA RTX 5060): 1252 passed, 0 failed, 46 ignored (27 pre-existing runtime SKIPPED lines: 20 native-wave64 tests on 32-lane NVIDIA, 3 per-lane #1426 f16/f32 refusals, 2 missing D3D12 debug layer, 1 Developer Mode cache-disable, 1 heap windows).

Regression run

Paired 60 s scripts/smoke.ps1 regression run on a retail title (release, XCL_NETWORK=0; AMD Radeon RX 9070 RDNA4 driver 32.0.32029.2010, Ryzen 7 7800X3D, Windows 11 build 26300, Rust 1.100.0), courtesy of @⁠Toons29 (comment):

Base (1a0bbe3a):

xcl-smoke v1
commit: 1a0bbe3a2ba91ea8f5b6fc29130a053868d3c9e6
gpu: AMD Radeon RX 9070
title: 34df7c50
seconds: 60
exit: 0x0
frames shown: 1628 (PresentX 1628)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14561 MB

This PR (b758a7e8):

xcl-smoke v1
commit: b758a7e82d5ad541d7312c2a933462a865579479
gpu: AMD Radeon RX 9070
title: 34df7c50
seconds: 60
exit: 0x0
frames shown: 1631 (PresentX 1631)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14593 MB

Not tested

  • Whether the retail smoke run above reaches a shader using s_setreg_b32 on MODE[1:0] (that path is verified by the direct GPU and validation tests in round_tests.rs).
  • Non-Windows hosts and Intel GPUs.

AI use

  • Antigravity (Google Gemini): audited crates/xcl/src/gpu/dxil/lower.rs against recomp/emit.rs, wrote the fail-first GPU and validation tests in round_tests.rs, implemented the dp_mask != 0 guard in lower.rs, and ran the dual-GPU and workspace test suites.
**@⁠GustavoEllwanger** on GitHub · 2026-11-25 13:03 UTC · [original](https://github.com/xcl-dev/xcl/pull/2300) `GustavoEllwanger:fix/dxil-setreg-f32-mode-preserves-fp16-rm` → `main` · +53 −2 · 2 files · 1 commits · merged 2026-11-25 18:16 UTC When `s_setreg_b32` writes only single-precision rounding bits (`HW_REG_MODE[1:0]`, so `sp_mask != 0` and `dp_mask == 0`), `Lw::setreg` in the direct DXIL translator entered the `dp_mask` path without checking `dp_mask != 0` (unlike `s_setreg_imm32_b32` right above it): 1. When `self.dyn_rm` was true, `match dp_mask` fell through `0` into the `_ =>` arm (written for `dp_mask == 2`) and overwrote bit 1 of `VAR_FP16_RM` with `(src & 1) << 1`, silently corrupting subsequent f16 rounding (e.g., turning RTZ `3` into RTP `1` when writing f32 RTN `2`). 2. When `self.has_f64_round_op` was true, it falsely returned `Err("dynamic f64 round mode")` even though `MODE[3:2]` was untouched. **What is in it** - `crates/xcl/src/gpu/dxil/lower.rs`: guard the `self.has_f64_round_op` rejection and `self.dyn_rm` `VAR_FP16_RM` update in `Lw::setreg` for `s_setreg_b32` with `dp_mask != 0`, matching `s_setreg_imm32_b32`. - `crates/xcl/src/gpu/dxil/round_tests.rs`: - `gpu_s_setreg_b32_f32_mode_preserves_fp16_round_mode`: sets `MODE[3:2]` to RTZ (`3`), updates only `MODE[1:0]` (`SIMM16 = 0x0801`) to RTN (`2`) via `s_setreg_b32`, and verifies both f32 RTN (`v_add_f32`) and preserved f16 RTZ (`v_cvt_f16_f32`) bit-exact on the GPU. - `direct_s_setreg_b32_f32_mode_allows_f64_ops`: verifies `s_setreg_b32` targeting `MODE[1:0]` (`0x0801`, `0x0001`, `0x0041`) alongside `v_add_f64` translates and validates cleanly. **Tested** - Hardware / toolchain: AMD Ryzen 7 7700, Windows 11, Rust `1.95.0 (59807616e 2026-04-14)`, DXC `1.8.2502.11`, debug build. - GPU 1: NVIDIA GeForce RTX 5060 (driver `32.0.16.1088`, split-wave64) - GPU 2: AMD Radeon(TM) Graphics (RDNA2 iGPU, driver `32.0.21042.62`, native wave64) - Fail-first before the fix (`XCL_ADAPTER=5060 cargo test -p xcl --lib gpu::dxil::round_tests::`): - `gpu_s_setreg_b32_f32_mode_preserves_fp16_round_mode`: FAILED (`left: 15361` [`0x3C01`], `right: 15360` [`0x3C00`]). - `direct_s_setreg_b32_f32_mode_allows_f64_ops`: FAILED (`s_setreg_b32 0x801, s0: dynamic f64 round mode`). - Post-fix targeted tests: - NVIDIA RTX 5060 (`XCL_ADAPTER=5060`): `gpu::dxil::round_tests::` **8 passed, 0 failed, 0 ignored** (0 skipped); `gpu::dxil::core_tests::` **16 passed, 0 failed, 1 ignored** (0 skipped). - AMD Radeon RDNA2 (`XCL_ADAPTER=Radeon`): `gpu::dxil::round_tests::` **8 passed, 0 failed, 0 ignored** (0 skipped); `gpu::dxil::core_tests::` **16 passed, 0 failed, 1 ignored** (0 skipped). - Independent AMD Radeon RX 6800M (RDNA2, driver `30.0.13002.13003`, courtesy of @⁠luckyteagirl in [comment](https://git.gtahub.st/github/xcl-dev--xcl/pulls/2300)): `gpu::dxil::round_tests::` **8 passed, 0 failed, 0 ignored** (0 skipped). - Full workspace suite (`XCL_ADAPTER=5060 cargo test --workspace -- --test-threads=4`, NVIDIA RTX 5060): **1252 passed, 0 failed, 46 ignored** (27 pre-existing runtime `SKIPPED` lines: 20 native-wave64 tests on 32-lane NVIDIA, 3 per-lane `#1426` f16/f32 refusals, 2 missing D3D12 debug layer, 1 Developer Mode cache-disable, 1 heap windows). **Regression run** Paired 60 s `scripts/smoke.ps1` regression run on a retail title (release, `XCL_NETWORK=0`; AMD Radeon RX 9070 RDNA4 driver `32.0.32029.2010`, Ryzen 7 7800X3D, Windows 11 build 26300, Rust `1.100.0`), courtesy of @⁠Toons29 ([comment](https://git.gtahub.st/github/xcl-dev--xcl/pulls/2300)): Base (`1a0bbe3a`): ``` xcl-smoke v1 commit: 1a0bbe3a2ba91ea8f5b6fc29130a053868d3c9e6 gpu: AMD Radeon RX 9070 title: 34df7c50 seconds: 60 exit: 0x0 frames shown: 1628 (PresentX 1628) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 14561 MB ``` This PR (`b758a7e8`): ``` xcl-smoke v1 commit: b758a7e82d5ad541d7312c2a933462a865579479 gpu: AMD Radeon RX 9070 title: 34df7c50 seconds: 60 exit: 0x0 frames shown: 1631 (PresentX 1631) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 14593 MB ``` **Not tested** - Whether the retail smoke run above reaches a shader using `s_setreg_b32` on `MODE[1:0]` (that path is verified by the direct GPU and validation tests in `round_tests.rs`). - Non-Windows hosts and Intel GPUs. **AI use** - Antigravity (Google Gemini): audited `crates/xcl/src/gpu/dxil/lower.rs` against `recomp/emit.rs`, wrote the fail-first GPU and validation tests in `round_tests.rs`, implemented the `dp_mask != 0` guard in `lower.rs`, and ran the dual-GPU and workspace test suites.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:26:15 +00:00
github manually merged commit b758a7e82d into gh-pr/2300/base 2026-11-26 05:26:16 +00:00
Author
Owner

@⁠luckyteagirl on GitHub · 2026-11-25 13:34 UTC · original

Independent focused RX 6800M check of exact PR head b758a7e82d5ad541d7312c2a933462a865579479.

Environment: Windows 11 build 26200; Ryzen 9 5980HX; dedicated Radeon RX 6800M (RDNA2, driver 30.0.13002.13003); Rust 1.99.0 MSVC; DXC/DXIL 1.9.2609.5. Clean detached worktree and isolated Cargo target.

XCL_ADAPTER=6800M XCL_REQUIRE_GPU=wave64 XCL_DIRECT_DXIL=1 cargo test --locked -p xcl --lib -j 2 gpu::dxil::round_tests:: -- --test-threads=1 --show-output: 8 passed, 0 failed, 0 ignored, no SKIPPED lines. This includes the two new cases: gpu_s_setreg_b32_f32_mode_preserves_fp16_round_mode passed its GPU f32/f16 output checks, and direct_s_setreg_b32_f32_mode_allows_f64_ops passed its three DXIL translation/validation checks. The other six directed-rounding tests also passed.

This adds a dedicated RDNA2/RX 6800M check to the author's RTX 5060 and RDNA2 iGPU results. I did not run the full workspace suite, retail-title smoke, or a pre-fix A/B on this card.

AI use: OpenAI Codex (GPT-6; exact variant not exposed in this session) ran the native Windows tests, checked the clean exact head and test output, and drafted this report. No game data was used.

**@⁠luckyteagirl** on GitHub · 2026-11-25 13:34 UTC · [original](https://github.com/xcl-dev/xcl/pull/2300#issuecomment-7163967205) Independent focused RX 6800M check of exact PR head `b758a7e82d5ad541d7312c2a933462a865579479`. **Environment:** Windows 11 build 26200; Ryzen 9 5980HX; dedicated Radeon RX 6800M (RDNA2, driver `30.0.13002.13003`); Rust 1.99.0 MSVC; DXC/DXIL 1.9.2609.5. Clean detached worktree and isolated Cargo target. `XCL_ADAPTER=6800M XCL_REQUIRE_GPU=wave64 XCL_DIRECT_DXIL=1 cargo test --locked -p xcl --lib -j 2 gpu::dxil::round_tests:: -- --test-threads=1 --show-output`: **8 passed, 0 failed, 0 ignored**, no `SKIPPED` lines. This includes the two new cases: `gpu_s_setreg_b32_f32_mode_preserves_fp16_round_mode` passed its GPU f32/f16 output checks, and `direct_s_setreg_b32_f32_mode_allows_f64_ops` passed its three DXIL translation/validation checks. The other six directed-rounding tests also passed. This adds a dedicated RDNA2/RX 6800M check to the author's RTX 5060 and RDNA2 iGPU results. I did not run the full workspace suite, retail-title smoke, or a pre-fix A/B on this card. **AI use:** OpenAI Codex (GPT-6; exact variant not exposed in this session) ran the native Windows tests, checked the clean exact head and test output, and drafted this report. No game data was used.
Author
Owner

@⁠Toons29 on GitHub · 2026-11-25 13:34 UTC · original

Regression run of b758a7e8 on the retail title, for this PR's Regression run section. Both blocks are from scripts/smoke.ps1 as printed, not edited: main on 1a0bbe3a, this PR on its head commit with no uncommitted changes, same title and time.

xcl-smoke v1
commit: 1a0bbe3a2ba91ea8f5b6fc29130a053868d3c9e6
gpu: AMD Radeon RX 9070
title: 34df7c50
seconds: 60
exit: 0x0
frames shown: 1628 (PresentX 1628)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14561 MB
xcl-smoke v1
commit: b758a7e82d5ad541d7312c2a933462a865579479
gpu: AMD Radeon RX 9070
title: 34df7c50
seconds: 60
exit: 0x0
frames shown: 1631 (PresentX 1631)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14593 MB

Against the limits in CONTRIBUTING.md: 100 % of main's frames, 100 % of its peak commit, no crash, no device removal.

AMD Radeon RX 9070 (RDNA4, driver 32.0.32029.2010), Ryzen 7 7800X3D, 32 GB, Windows 11 build 26300, Rust 1.100.0, cargo build --release -p xcl, 60 s, XCL_NETWORK=0. This is a regression check only: it does not show whether the run reaches the code this PR changes.

AI use: Claude Code (Claude Opus 5.5) built both trees and ran scripts/smoke.ps1; a script posted this right after the run, with both blocks exactly as printed.

**@⁠Toons29** on GitHub · 2026-11-25 13:34 UTC · [original](https://github.com/xcl-dev/xcl/pull/2300#issuecomment-7163986524) Regression run of `b758a7e8` on the retail title, for this PR's **Regression run** section. Both blocks are from `scripts/smoke.ps1` as printed, not edited: `main` on `1a0bbe3a`, this PR on its head commit with no uncommitted changes, same title and time. ``` xcl-smoke v1 commit: 1a0bbe3a2ba91ea8f5b6fc29130a053868d3c9e6 gpu: AMD Radeon RX 9070 title: 34df7c50 seconds: 60 exit: 0x0 frames shown: 1628 (PresentX 1628) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 14561 MB ``` ``` xcl-smoke v1 commit: b758a7e82d5ad541d7312c2a933462a865579479 gpu: AMD Radeon RX 9070 title: 34df7c50 seconds: 60 exit: 0x0 frames shown: 1631 (PresentX 1631) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 14593 MB ``` Against the limits in CONTRIBUTING.md: 100 % of `main`'s frames, 100 % of its peak commit, no crash, no device removal. AMD Radeon RX 9070 (RDNA4, driver 32.0.32029.2010), Ryzen 7 7800X3D, 32 GB, Windows 11 build 26300, Rust 1.100.0, `cargo build --release -p xcl`, 60 s, `XCL_NETWORK=0`. This is a regression check only: it does not show whether the run reaches the code this PR changes. AI use: Claude Code (Claude Opus 5.5) built both trees and ran `scripts/smoke.ps1`; a script posted this right after the run, with both blocks exactly as printed.
Author
Owner

@⁠GustavoEllwanger on GitHub · 2026-11-25 13:39 UTC · original

Thanks @⁠Toons29 for the RX 9070 paired smoke run and @⁠luckyteagirl for the RX 6800M check! Added both to the PR description with credit so PR checks can turn green.

**@⁠GustavoEllwanger** on GitHub · 2026-11-25 13:39 UTC · [original](https://github.com/xcl-dev/xcl/pull/2300#issuecomment-7164108298) Thanks @⁠Toons29 for the RX 9070 paired smoke run and @⁠luckyteagirl for the RX 6800M check! Added both to the PR description with credit so PR checks can turn green.
Author
Owner

@⁠nnonno91 on GitHub · 2026-11-25 14:56 UTC · original

Extended the focused checks on b758a7e82d5ad541d7312c2a933462a865579479 to all 16 combinations of initial f16 and runtime f32 rounding modes.

Tested

  • Windows 11 25H2 build 26200.9974, Ryzen 7 9800X3D, Rust 1.100.0 MSVC, SDK DXC/DXIL 1.8.2502.11, unoptimized profile. Radeon(TM) Graphics driver 32.0.21042.62 and RTX 5090 driver 32.0.16.1742.
  • In a temporary GPU fixture I initialized each f16 mode with S_ROUND_MODE, then set only the two f32 mode bits using S_SETREG_B32 with the value supplied in s0. Positive and negative direct-DXIL f32 additions and f16 conversions were checked bit for bit for each mode pair. All 64 outputs matched on both GPUs.
  • cargo test --locked -p xcl --lib gpu::dxil::round_tests:: -- --nocapture --test-threads=1 with each GPU selected via XCL_ADAPTER gave 9 passed, 0 failed, 0 ignored and no skips per GPU (the 8 existing tests plus the matrix). The temporary fixture was removed.

Not tested

The parent revision, retail smoke and the full workspace suite.

AI use

OpenAI Codex (GPT-6.2 Sol) added the temporary matrix, ran the checks and wrote this report.

**@⁠nnonno91** on GitHub · 2026-11-25 14:56 UTC · [original](https://github.com/xcl-dev/xcl/pull/2300#issuecomment-7166052915) Extended the focused checks on `b758a7e82d5ad541d7312c2a933462a865579479` to all 16 combinations of initial f16 and runtime f32 rounding modes. **Tested** - Windows 11 25H2 build 26200.9974, Ryzen 7 9800X3D, Rust 1.100.0 MSVC, SDK DXC/DXIL 1.8.2502.11, unoptimized profile. Radeon(TM) Graphics driver 32.0.21042.62 and RTX 5090 driver 32.0.16.1742. - In a temporary GPU fixture I initialized each f16 mode with `S_ROUND_MODE`, then set only the two f32 mode bits using `S_SETREG_B32` with the value supplied in s0. Positive and negative direct-DXIL f32 additions and f16 conversions were checked bit for bit for each mode pair. All 64 outputs matched on both GPUs. - `cargo test --locked -p xcl --lib gpu::dxil::round_tests:: -- --nocapture --test-threads=1` with each GPU selected via `XCL_ADAPTER` gave 9 passed, 0 failed, 0 ignored and no skips per GPU (the 8 existing tests plus the matrix). The temporary fixture was removed. **Not tested** The parent revision, retail smoke and the full workspace suite. **AI use** OpenAI Codex (GPT-6.2 Sol) added the temporary matrix, ran the checks and wrote this report.
Author
Owner

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