Skip to content

[upstream #938] Recompiler: translate s_getreg_b32 for MODE's round modes - #156

Closed
ufoptg wants to merge 1 commit into
mainfrom
upstream-pr/938
Closed

ufoptg wants to merge 1 commit into
mainfrom
upstream-pr/938

Conversation

@ufoptg

@ufoptg ufoptg commented Nov 24, 2026

Copy link
Copy Markdown
Owner

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 Memory: a sparse alloc/free loop makes a new 64 MiB pool each cycle; lib tests fill a 12 GB card (#348's test) xcl-dev/xcl#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 D3D12.X: a sparse pool retired a moment ago is taken back (#913) xcl-dev/xcl#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: GTA6.Xbox.v1.0.2.1-CYBERLEEK
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: GTA6.Xbox.v1.0.2.1-CYBERLEEK
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


Mirror of xcl-dev#938 (auto-synced, do not edit).

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 <noreply@anthropic.com>
ufoptg pushed a commit that referenced this pull request Nov 24, 2026
…the switch form

NVIDIA 616.92 (RTX 5070 Ti, reported in #156) refuses some big programs whose
descriptor-heap index depends on the memory window with E_OUTOFMEMORY, and builds
the same programs in the switch form. A translated compute, graphics, mesh or GS
pipeline whose driver call fails that way with heap windows is now translated again
in the switch form (other cache keys; same root signature and binds) and built from
that before the stand-in or the error path.

Test: heap_window_out_of_memory_falls_back_to_the_switch_form injects the refusals
through the CreateComputePipelineState hook, then dispatches the rebuilt pipeline
and checks every thread's output.

From #187 by Remington Wilcox (41d4506).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@ufoptg

ufoptg commented Nov 25, 2026

Copy link
Copy Markdown
Owner Author

Upstream PR xcl-dev#938 was closed or merged.

@ufoptg ufoptg closed this Nov 25, 2026
@ufoptg
ufoptg deleted the upstream-pr/938 branch November 25, 2026 00:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants