Recompiler: translate s_getreg_b32 for MODE's round modes #938

Closed
github-bot wants to merge 1 commit from gh-pr/938/head into gh-pr/938/base
Owner

@⁠maximecmb on GitHub · 2026-11-24 08:52 UTC · original
recomp-s-getreg → main · +98 −1 · 2 files · 1 commits · closed without merging

s_getreg_b32 was untranslated (the isa_coverage census lists it as missing; no open PR or issue covers it). It reads a field of a hardware register into an SGPR. The common use in compiled shaders is reading the current round mode (hwreg(HW_REG_MODE, 0, 4), what LLVM's llvm.get.rounding becomes), often to restore it later.

XCL already models MODE's round modes: [1:0] (f32) is always 0, since any other value is refused, and [3:2] (f16 / f64) is xcl_fp16_rm where a program changes it. So a read of a field inside MODE[3:0] is exact. The rest is refused, with a reason that names the register (which then shows in report.json), not answered with 0: the other MODE bits (denormals, clamps, IEEE) come from the console's program set-up, and registers such as HW_ID1 / HW_ID2 (wave, SIMD, CU ids), STATUS or SHADER_CYCLES from its hardware. A made-up value would be wrong for some programs, e.g. two waves with the same wave id indexing per-wave slots.

What is in it

  • crates/xcl/src/gpu/recomp/emit.rs: getreg for s_getreg_b32 (MODE fields within [3:0]; refusals for the rest, named). configure_round_modes also follows MODE[3:2] at run time when the program reads it back, not only when an f16 op rounds by it: before, a change of it in a program without f16 ops was dropped, and a read would have given 0.
  • crates/xcl/src/gpu/recomp/tests.rs: s_getreg_b32_reads_the_round_modes_and_refuses_the_rest (the HLSL for a constant and a followed MODE, and the refusals with their reasons) and gpu_s_getreg_b32_round_modes (MODE read before and after s_round_mode and s_setreg_imm32_b32, in a program with no f16 op: 0, 0xC, single bits, a field straddling [1:0] / [3:2]). Without the configure_round_modes change the GPU test fails (every read gives 0).

Tested

  • NVIDIA GeForce RTX 5080 (driver 617.42, 32-lane waves), AMD Ryzen 7 9800X3D, Windows 11 build 26300, Rust 1.100.0 stable-x86_64-pc-windows-msvc, debug, DXC 1.9.2602.17
  • cargo build --workspace && cargo test --workspace --no-fail-fast -- --test-threads=4: 715 passed, 3 failed, 41 ignored. The 3 are main's memory-pressure failures of #913 (placed_title_textures_share_vram_and_preserve_pixels, then transitions_apply_when_their_list_is_submitted and d32s8_targets_take_their_own_size_of_video_memory on its poisoned lock), which #923 addresses
  • cargo test -p xcl --lib -- --test-threads=4 --skip a_freed_block_is_decommitted_before_its_address_is_reused: 676 passed, 0 failed, 21 ignored
  • SKIPPED on this adapter (no wave64): gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware; no XCL_SAMPLE_* set
  • isa_coverage still lists s_getreg_b32: it encodes each instruction with zero operands, which for this one is hardware register 0, refused on purpose

Regression run
main:

xcl-smoke v1
commit: 077ce40c3e371cf3df8c57985b1cc6b1db39e75a
gpu: NVIDIA GeForce RTX 5080
title: 3c290c16
seconds: 60
exit: 0x0
frames shown: 1670 (PresentX 1670)
presents per 2 s (last 3): 60 60 61
device removals: 0
crashes: 0
peak commit: 14600 MB

This PR:

xcl-smoke v1
commit: 50939319dcddbca8bf58e2d7b60a5e4211ff6a36
gpu: NVIDIA GeForce RTX 5080
title: 3c290c16
seconds: 60
exit: 0x0
frames shown: 1651 (PresentX 1651)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14604 MB

Not tested

  • an AMD GPU; the native wave64 form
  • the save / restore pattern end to end: restoring MODE with s_setreg_b32 hwreg(MODE, 0, 4), sN from an SGPR is still refused (dynamic f32 round mode), as before this change
  • a title that uses the instruction: the regression run will not show whether one does

AI use

  • Claude Code, Claude Opus 5.5: wrote the code, the tests and this description, and ran the tests above.

🤖 Generated with Claude Code

**@⁠maximecmb** on GitHub · 2026-11-24 08:52 UTC · [original](https://github.com/xcl-dev/xcl/pull/938) `recomp-s-getreg` → `main` · +98 −1 · 2 files · 1 commits · closed without merging `s_getreg_b32` was untranslated (the `isa_coverage` census lists it as missing; no open PR or issue covers it). It reads a field of a hardware register into an SGPR. The common use in compiled shaders is reading the current round mode (`hwreg(HW_REG_MODE, 0, 4)`, what LLVM's `llvm.get.rounding` becomes), often to restore it later. XCL already models MODE's round modes: `[1:0]` (f32) is always 0, since any other value is refused, and `[3:2]` (f16 / f64) is `xcl_fp16_rm` where a program changes it. So a read of a field inside `MODE[3:0]` is exact. The rest is refused, with a reason that names the register (which then shows in `report.json`), not answered with 0: the other MODE bits (denormals, clamps, IEEE) come from the console's program set-up, and registers such as `HW_ID1` / `HW_ID2` (wave, SIMD, CU ids), `STATUS` or `SHADER_CYCLES` from its hardware. A made-up value would be wrong for some programs, e.g. two waves with the same wave id indexing per-wave slots. **What is in it** - `crates/xcl/src/gpu/recomp/emit.rs`: `getreg` for `s_getreg_b32` (MODE fields within `[3:0]`; refusals for the rest, named). `configure_round_modes` also follows `MODE[3:2]` at run time when the program reads it back, not only when an f16 op rounds by it: before, a change of it in a program without f16 ops was dropped, and a read would have given 0. - `crates/xcl/src/gpu/recomp/tests.rs`: `s_getreg_b32_reads_the_round_modes_and_refuses_the_rest` (the HLSL for a constant and a followed MODE, and the refusals with their reasons) and `gpu_s_getreg_b32_round_modes` (MODE read before and after `s_round_mode` and `s_setreg_imm32_b32`, in a program with no f16 op: `0`, `0xC`, single bits, a field straddling `[1:0]` / `[3:2]`). Without the `configure_round_modes` change the GPU test fails (every read gives 0). **Tested** - NVIDIA GeForce RTX 5080 (driver 617.42, 32-lane waves), AMD Ryzen 7 9800X3D, Windows 11 build 26300, Rust 1.100.0 `stable-x86_64-pc-windows-msvc`, debug, DXC 1.9.2602.17 - `cargo build --workspace && cargo test --workspace --no-fail-fast -- --test-threads=4`: 715 passed, 3 failed, 41 ignored. The 3 are `main`'s memory-pressure failures of #913 (`placed_title_textures_share_vram_and_preserve_pixels`, then `transitions_apply_when_their_list_is_submitted` and `d32s8_targets_take_their_own_size_of_video_memory` on its poisoned lock), which #923 addresses - `cargo test -p xcl --lib -- --test-threads=4 --skip a_freed_block_is_decommitted_before_its_address_is_reused`: 676 passed, 0 failed, 21 ignored - SKIPPED on this adapter (no wave64): `gpu_geometry_wave32_prefix_count_over_a_mask`, `gpu_wave32_program_in_wave64_hardware`; no `XCL_SAMPLE_*` set - `isa_coverage` still lists `s_getreg_b32`: it encodes each instruction with zero operands, which for this one is hardware register 0, refused on purpose **Regression run** `main`: ``` xcl-smoke v1 commit: 077ce40c3e371cf3df8c57985b1cc6b1db39e75a gpu: NVIDIA GeForce RTX 5080 title: 3c290c16 seconds: 60 exit: 0x0 frames shown: 1670 (PresentX 1670) presents per 2 s (last 3): 60 60 61 device removals: 0 crashes: 0 peak commit: 14600 MB ``` This PR: ``` xcl-smoke v1 commit: 50939319dcddbca8bf58e2d7b60a5e4211ff6a36 gpu: NVIDIA GeForce RTX 5080 title: 3c290c16 seconds: 60 exit: 0x0 frames shown: 1651 (PresentX 1651) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 14604 MB ``` **Not tested** - an AMD GPU; the native wave64 form - the save / restore pattern end to end: restoring MODE with `s_setreg_b32 hwreg(MODE, 0, 4), sN` from an SGPR is still refused (`dynamic f32 round mode`), as before this change - a title that uses the instruction: the regression run will not show whether one does **AI use** - Claude Code, Claude Opus 5.5: wrote the code, the tests and this description, and ran the tests above. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
It was untranslated (the isa_coverage census listed it as missing). The
common use is reading the current round mode, hwreg(MODE, 0, 4).

XCL already models MODE[3:0]: [1:0] (f32) is always 0, as any other value
is refused, and [3:2] (f16 / f64) is xcl_fp16_rm where a program changes
it. A read of a field within MODE[3:0] is therefore exact. MODE[3:2] is
now also followed at run time when the program reads it back, not only
when an f16 op rounds by it: a change of it in a program without f16 ops
was dropped before.

Other registers and MODE bits depend on the console's hardware and
program set-up (HW_ID1 / HW_ID2, STATUS, SHADER_CYCLES, denormal and
clamp bits): refused, naming the register, instead of a made-up value.

Tests: the HLSL for constant and followed MODE reads and the refusals,
and a GPU test reading MODE around s_round_mode / s_setreg_imm32_b32 in a
program without f16 ops.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:37:36 +00:00
github-bot closed this pull request 2026-11-26 04:37:36 +00:00
Author
Owner

@⁠dcastell1 on GitHub · 2026-11-24 09:11 UTC · original

Verified on Windows 11 10.0.26300, NVIDIA GeForce RTX 5090 (driver 621.24), Rust 1.100.0 MSVC 14.44.35207, debug build, on clean main@beaa245 (713 passed, 0 failed, 41 ignored on this box):

patch -p1 < this PR            # clean, no fuzz
cargo test --workspace -- --test-threads=4
715 passed; 0 failed; 41 ignored   (exit 0)

Two more passing tests than main: s_getreg_b32 for MODE's round modes translates and its fixtures are green here.

Tree restored afterwards (md5 and a full diff against a clean checkout), hardware adapter, no Wine, no game data. AI-assisted (opencode): applied the patch to a built tree, ran the suite, reverted it.

**@⁠dcastell1** on GitHub · 2026-11-24 09:11 UTC · [original](https://github.com/xcl-dev/xcl/pull/938#issuecomment-7127071635) Verified on Windows 11 10.0.26300, NVIDIA GeForce RTX 5090 (driver 621.24), Rust 1.100.0 MSVC 14.44.35207, debug build, on clean `main@beaa245` (713 passed, 0 failed, 41 ignored on this box): ``` patch -p1 < this PR # clean, no fuzz cargo test --workspace -- --test-threads=4 715 passed; 0 failed; 41 ignored (exit 0) ``` Two more passing tests than main: `s_getreg_b32` for MODE's round modes translates and its fixtures are green here. Tree restored afterwards (md5 and a full diff against a clean checkout), hardware adapter, no Wine, no game data. AI-assisted (opencode): applied the patch to a built tree, ran the suite, reverted it.
Author
Owner

@⁠eizispark on GitHub · 2026-11-24 09:17 UTC · original

Hardware check of 50939319dcddbca8bf58e2d7b60a5e4211ff6a36 (verified clean merge with main 077ce40): pass.

Tested

  • Hardware: AMD Radeon RX 9070 XT (RDNA4, driver 32.0.32015.16001), AMD Ryzen 7 9800X3D, 32 GB RAM, Windows 11, rustc 1.100.0 (0ef1bc386 2026-11-09), release + test profile
  • cargo test --workspace -- --test-threads=4: 715 passed, 3 failed, 41 ignored (GPU tests skipped on this adapter: none; the 3 failures are the pre-existing concurrent VRAM test race in placed_title_textures_share_vram_and_preserve_pixels plus 2 downstream PoisonErrors — cargo test -p xcl --lib hle::d3d12x -- --test-threads=1: 115 passed, 0 failed, 1 ignored)
  • Native wave64 + wave32 recompiler checks on RDNA4: gpu::recomp::tests::gpu_s_getreg_b32_round_modes (native wave64), gpu::recomp::tests::s_getreg_b32_reads_the_round_modes_and_refuses_the_rest, gpu::recomp::tests::gpu_wave32_program_in_wave64_hardware, and gpu::recomp::tests::gpu_geometry_wave32_prefix_count_over_a_mask all ok

Regression run
main (beaa245):

xcl-smoke v1
commit: beaa245ca04e212f064efc7cafcdce104bc5c0a2
gpu: AMD Radeon RX 9070 XT
title: GTA6.Xbox.v1.0.2.1
seconds: 60
exit: 0x0
frames shown: 1660 (PresentX 1660)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14862 MB

PR (5093931):

xcl-smoke v1
commit: 50939319dcddbca8bf58e2d7b60a5e4211ff6a36
gpu: AMD Radeon RX 9070 XT
title: GTA6.Xbox.v1.0.2.1
seconds: 60
exit: 0x0
frames shown: 1659 (PresentX 1659)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14729 MB

Not tested

  • wave32-only GPUs (NVIDIA / Intel); gameplay past the menus

AI use

  • Antigravity (Gemini 4 Carbon) ran the build, test suite, and scripts/smoke.ps1 harness on this machine and formatted this report.
**@⁠eizispark** on GitHub · 2026-11-24 09:17 UTC · [original](https://github.com/xcl-dev/xcl/pull/938#issuecomment-7127218722) Hardware check of `50939319dcddbca8bf58e2d7b60a5e4211ff6a36` (verified clean merge with `main` `077ce40`): **pass**. **Tested** - Hardware: AMD Radeon RX 9070 XT (RDNA4, driver 32.0.32015.16001), AMD Ryzen 7 9800X3D, 32 GB RAM, Windows 11, `rustc 1.100.0 (0ef1bc386 2026-11-09)`, release + test profile - `cargo test --workspace -- --test-threads=4`: `715 passed, 3 failed, 41 ignored` (GPU tests skipped on this adapter: `none`; the 3 failures are the pre-existing concurrent VRAM test race in `placed_title_textures_share_vram_and_preserve_pixels` plus 2 downstream `PoisonError`s — `cargo test -p xcl --lib hle::d3d12x -- --test-threads=1`: `115 passed, 0 failed, 1 ignored`) - Native wave64 + wave32 recompiler checks on RDNA4: `gpu::recomp::tests::gpu_s_getreg_b32_round_modes` (native wave64), `gpu::recomp::tests::s_getreg_b32_reads_the_round_modes_and_refuses_the_rest`, `gpu::recomp::tests::gpu_wave32_program_in_wave64_hardware`, and `gpu::recomp::tests::gpu_geometry_wave32_prefix_count_over_a_mask` all `ok` **Regression run** `main` (`beaa245`): ``` xcl-smoke v1 commit: beaa245ca04e212f064efc7cafcdce104bc5c0a2 gpu: AMD Radeon RX 9070 XT title: GTA6.Xbox.v1.0.2.1 seconds: 60 exit: 0x0 frames shown: 1660 (PresentX 1660) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 14862 MB ``` PR (`5093931`): ``` xcl-smoke v1 commit: 50939319dcddbca8bf58e2d7b60a5e4211ff6a36 gpu: AMD Radeon RX 9070 XT title: GTA6.Xbox.v1.0.2.1 seconds: 60 exit: 0x0 frames shown: 1659 (PresentX 1659) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 14729 MB ``` **Not tested** - wave32-only GPUs (NVIDIA / Intel); gameplay past the menus **AI use** - Antigravity (Gemini 4 Carbon) ran the build, test suite, and `scripts/smoke.ps1` harness on this machine and formatted this report.
Author
Owner

@⁠DarkPanda69 on GitHub · 2026-11-24 09:43 UTC · original · edited 2026-11-24 10:26 UTC

Test report for head 50939319d.

Setup

  • Each PR's diff applied on main 077ce40 (all applied cleanly), debug build, Rust 1.100.0, Windows 11 Pro 26200, Ryzen 7 5800X, DXC 1.9.2602.17.
  • cargo test -p xcl --lib -- gpu::recomp --test-threads=4, once with XCL_ADAPTER=radeon and once with XCL_ADAPTER=3060.
    • AMD RX 9070 XT (RDNA4), driver 32.0.32029.2010: waves 32..64, so wave64 programs run in native 64-lane waves.
    • NVIDIA RTX 3060 (Ampere), driver 32.0.16.1088: 32 only, so wave64 programs run in the split form.
  • Not run per PR: the whole workspace suite (the recompiler tests only) and a retail smoke run.

Tested: pass on both GPUs, including an AMD GPU and the native wave64 form you listed as not tested.

  • RX 9070 XT (native wave64): 190 passed, 0 failed, 18 ignored, 0 SKIPPED. gpu_s_getreg_b32_round_modes ok.
  • RTX 3060 (split wave64): 190 passed, 0 failed, 18 ignored, 2 SKIPPED (no wave64). gpu_s_getreg_b32_round_modes ok.

Not tested: the save / restore pattern end to end; a title that uses the instruction.
AI use: Claude Code (Claude Opus 5.5) ran the tests on this machine and wrote this report.

Note: these runs check that the translated HLSL matches the test's reference model, in 64-lane and in 32-lane waves. They cannot show that the model matches the hardware (on #925 both had the same mistake, and the test still passed).

**@⁠DarkPanda69** on GitHub · 2026-11-24 09:43 UTC · [original](https://github.com/xcl-dev/xcl/pull/938#issuecomment-7127793873) · edited 2026-11-24 10:26 UTC Test report for head `50939319d`. **Setup** - Each PR's diff applied on `main` `077ce40` (all applied cleanly), debug build, Rust 1.100.0, Windows 11 Pro 26200, Ryzen 7 5800X, DXC 1.9.2602.17. - `cargo test -p xcl --lib -- gpu::recomp --test-threads=4`, once with `XCL_ADAPTER=radeon` and once with `XCL_ADAPTER=3060`. - AMD RX 9070 XT (RDNA4), driver 32.0.32029.2010: waves 32..64, so wave64 programs run in native 64-lane waves. - NVIDIA RTX 3060 (Ampere), driver 32.0.16.1088: 32 only, so wave64 programs run in the split form. - Not run per PR: the whole workspace suite (the recompiler tests only) and a retail smoke run. Tested: pass on both GPUs, including an AMD GPU and the native wave64 form you listed as not tested. - RX 9070 XT (native wave64): 190 passed, 0 failed, 18 ignored, 0 SKIPPED. `gpu_s_getreg_b32_round_modes` ok. - RTX 3060 (split wave64): 190 passed, 0 failed, 18 ignored, 2 SKIPPED (no wave64). `gpu_s_getreg_b32_round_modes` ok. Not tested: the save / restore pattern end to end; a title that uses the instruction. AI use: Claude Code (Claude Opus 5.5) ran the tests on this machine and wrote this report. Note: these runs check that the translated HLSL matches the test's reference model, in 64-lane and in 32-lane waves. They cannot show that the model matches the hardware (on #925 both had the same mistake, and the test still passed).
Author
Owner

@⁠SlopTart on GitHub · 2026-11-24 10:37 UTC · original

Linux / AMD RDNA3 datapoint.

Merged state: head 5093931 onto main 9aec53d, clean merge.

Full suite, cargo test --workspace --release --no-fail-fast --target x86_64-pc-windows-gnu -- --test-threads=4: 718 passed, 8 failed, 41 ignored; failures are the known Wine-lane set from my #42 rows plus this rig's title-textures flake family (see #718). s_getreg_b32 MODE round-modes green; see flake footnote.

Footnote: gpu::recomp::tests::gpu_geometry_wave32_prefix_count_over_a_mask failed once in-lane but passes 2/2 in isolation on the same merge, and current main passes the same isolated runs - ordering flake on this rig, not attributed to this PR.

Not tested: retail titles (none here), Windows, RDNA4.
Counts only, no game data.

Machine: RX 7900 XT (RADV NAVI31), Mesa 26.2.5, kernel 7.2 (Arch), Proton Experimental (wine-11.0), patched vkd3d-proton v3.1, Rust cross x86_64-pc-windows-gnu, XCL_NETWORK=0, release profile, --test-threads=4. My Linux rows: #42 / #718.

AI use: Hermes agent (local Qwen-class) ran the suite and drafted this; I checked it before posting.

**@⁠SlopTart** on GitHub · 2026-11-24 10:37 UTC · [original](https://github.com/xcl-dev/xcl/pull/938#issuecomment-7129035084) Linux / AMD RDNA3 datapoint. **Merged state:** head `5093931` onto main `9aec53d`, clean merge. **Full suite, `cargo test --workspace --release --no-fail-fast --target x86_64-pc-windows-gnu -- --test-threads=4`:** **718 passed, 8 failed, 41 ignored**; failures are the known Wine-lane set from my #42 rows plus this rig's title-textures flake family (see #718). s_getreg_b32 MODE round-modes green; see flake footnote. Footnote: `gpu::recomp::tests::gpu_geometry_wave32_prefix_count_over_a_mask` failed once in-lane but passes 2/2 in isolation on the same merge, and current main passes the same isolated runs - ordering flake on this rig, not attributed to this PR. **Not tested:** retail titles (none here), Windows, RDNA4. Counts only, no game data. **Machine:** RX 7900 XT (RADV NAVI31), Mesa 26.2.5, kernel 7.2 (Arch), Proton Experimental (wine-11.0), patched vkd3d-proton v3.1, Rust cross `x86_64-pc-windows-gnu`, `XCL_NETWORK=0`, release profile, `--test-threads=4`. My Linux rows: #42 / #718. AI use: Hermes agent (local Qwen-class) ran the suite and drafted this; I checked it before posting.
Author
Owner

@⁠DavidM1911 on GitHub · 2026-11-24 12:37 UTC · original

Independent verification, merged onto current main 384f7f7 locally (clean merge).

Machine: Windows 11, Ryzen 9 7900X + RTX 3060 Ti; Rust stable MSVC, debug; DXC 1.8.2502.11.

  • cargo test -p xcl --lib s_getreg: 2 passed, 0 failed — s_getreg_b32_reads_the_round_modes_and_refuses_the_rest (emission) and gpu_s_getreg_b32_round_modes (GPU) both pass.

AI use: test runs by Devin (Cognition, SWE-2); no code changes.

**@⁠DavidM1911** on GitHub · 2026-11-24 12:37 UTC · [original](https://github.com/xcl-dev/xcl/pull/938#issuecomment-7131707371) Independent verification, merged onto current `main` `384f7f7` locally (clean merge). **Machine:** Windows 11, Ryzen 9 7900X + RTX 3060 Ti; Rust stable MSVC, debug; DXC 1.8.2502.11. - `cargo test -p xcl --lib s_getreg`: **2 passed, 0 failed** — `s_getreg_b32_reads_the_round_modes_and_refuses_the_rest` (emission) and `gpu_s_getreg_b32_round_modes` (GPU) both pass. AI use: test runs by Devin (Cognition, SWE-2); no code changes.
Author
Owner

@⁠DavidM1911 on GitHub · 2026-11-26 03:11 UTC · original

Re-verification on RTX 3060 Ti (Windows 11), new head merged with current main:

  • cargo test -p xcl --lib: all passed, 0 failed, 27 ignored. The earlier merge conflict is resolved.

Thanks!

— Devin

**@⁠DavidM1911** on GitHub · 2026-11-26 03:11 UTC · [original](https://github.com/xcl-dev/xcl/pull/938#issuecomment-7181475928) Re-verification on RTX 3060 Ti (Windows 11), new head merged with current `main`: - `cargo test -p xcl --lib`: all passed, 0 failed, 27 ignored. The earlier merge conflict is resolved. Thanks! — Devin

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.