Skip to content

rdna2spirv: s_getreg_b32 of MODE.FP_ROUND - #2980

Open
Vonsek wants to merge 5 commits into
ItsNotRexed:mainfrom
Vonsek:claude/s-getreg
Open

Vonsek wants to merge 5 commits into
ItsNotRexed:mainfrom
Vonsek:claude/s-getreg

Conversation

@Vonsek

@Vonsek Vonsek commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Requested by Lucas · project thread

Claimed in the coordination issue as: EGEN-SALU-GETREG, #2716 (comment)

What and why

Every s_getreg_b32 raised Unsupported. This translates it for the one hardware-register field the translator can answer for, MODE.FP_ROUND (MODE[3:0]). The result is D = field (offset, size) shifted down to bit 0, and SCC is not written.

  • MODE[1:0] (f32 rounding) reads 0. The translator always rounds f32 to nearest even.
  • MODE[3:2] (f16/f64 rounding) reads the value it already tracks through s_setreg_imm32_b32 (%mode_r16, 0 at the start).

Everything else stays Unsupported, and the message names the bits or the register:

  • Other MODE bits (denormal modes, DX10_CLAMP, IEEE, exception enables): the game's shader descriptor sets them, and the translator never sees it.
  • Other registers (HW_ID, STATUS, TRAPSTS, GPR_ALLOC, ...): they describe the console's wave.

s_setreg_b32 from an SGPR (restoring a saved FP_ROUND) is still refused by the existing MODE write rule. This PR doesn't change that.

Measured on RDNA2 gfx1036 (Radeon iGPU of a Ryzen 9 9950X3D, driver 26.10.1, tools/hw_oracle raw wave32 kernels with three kernel MODE settings, registers within v0-v15 / s4-s15):

read default descriptor round16_64 = 3 IEEE 0, DX10_CLAMP 1
hwreg(HW_REG_MODE) at start 0x3c0 0x3cc 0x1c0
(0,4) / (2,2) / (4,4) at start 0 / 0 / 0xc 0xc / 3 / 0xc 0 / 0 / 0xc
after s_setreg_imm32_b32 hwreg(HW_REG_MODE, 2, 2), 3: (2,2), (0,4), (3,1), (1,3) 3, 0xc, 1, 6 same same
writing 0 back, then (2,2) 0 0 0
SCC set before the read, s_cselect after it kept (1, and 0 when clear) same same

So the layout is FP_ROUND [3:0] (f32 [1:0], f16/f64 [3:2]), FP_DENORM [7:4], DX10_CLAMP bit 8 and IEEE bit 9, and the field is returned right-justified.

New contract row in docs/design.md.

Tested

Windows 11, LLVM llvm-mc, VK_LOADER_LAYERS_DISABLE=~implicit~, one GPU at a time, python -I scripts/run_gpu_tests.py --filter cs_w32_getreg_mode:

GPU Driver Result
AMD Radeon RDNA2 iGPU, Ryzen 9 9950X3D 26.10.1 PASS 0 0 3 12 1 6 0 5
NVIDIA GeForce RTX 5080 616.92 PASS, same words
  • New runtime/test/shaders/cs_w32_getreg_mode.asm: the hardware reads above, with the words derived in its header. It is registered in check.py, run_gpu_tests.py and regen_fixtures.py.
  • GetregMode in test_value_semantics.py checks the words against a plain-Python model of MODE[3:0], and checks that unmodelled MODE bits and other registers are refused.
  • Before the fix: GetregMode fails on main (Unsupported: s_getreg_b32).
  • Negative control: I made FP_ROUND[3:2] land in bits 1:0. GetregMode fails, and the Radeon run fails with 0 0 0 3 0 1 0 5. Then I reverted it.
  • Passing: python -m unittest discover -s tests/semantic, python tests/semantic/regen_fixtures.py --check (clean), python -I tests/test_shader_checks.py, and pytest tests/test_docs_design_rows.py tests/test_run_gpu_tests.py.

AI-assisted.

Checklist

  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed.

D = MODE field (offset, size) right-justified, SCC kept. MODE[1:0] reads 0
(f32 always nearest even here), MODE[3:2] the f16/f64 rounding tracked from
s_setreg (%mode_r16). Other MODE bits and other hardware registers stay
Unsupported with a message naming them. Layout and reads measured on RDNA2
gfx1036. GPU fixture cs_w32_getreg_mode, semantic test GetregMode,
design.md row.

AI-assisted.
@hidrogenone

Copy link
Copy Markdown
Contributor

Tested 36545603 on NVIDIA GeForce RTX 5080 (Blackwell), driver 32.0.16.2124, Windows 11, Vulkan SDK 1.4.357.0. llvm-mc LLVM 21.1.8 (WSL Ubuntu).

scripts/run_gpu_tests.py --filter getreg_mode:

cs_w32_getreg_mode   1/1 passed

Translator: 1 shader translated, spirv-val clean. NVIDIA Blackwell (RTX 50-series) coverage. AI-assisted.

@Rainmaker33

Copy link
Copy Markdown

Tested 3654560 on NVIDIA GeForce RTX 3090 (Ampere, subgroup 32..32), driver 610.88 (Vulkan 1.4.341), Windows 11 Pro 26300: pass.

The PR's diff applied cleanly to main 1628210. VS 2022, Vulkan SDK 1.4.363.0, llvm-mc 21.1.8; harness programs from a CMake build of main; overlay layers off.

@emirduran707

Copy link
Copy Markdown
Contributor

Tested 3654560 on AMD Radeon RX 9060 XT (RDNA4), AMD driver 26.10.44 (LLPC, Vulkan driver 2.0.395), Windows 11 Pro 10.0.26300, subgroup 32..64: pass. The checks above have no AMD run from outside the author; this adds an AMD card with native 64-wide subgroups.

  • python -I scripts/run_gpu_tests.py --build <build> --filter <fixture>, one run per new fixture:
    • cs_w32_getreg_mode: PASS, 0 0 3 12 1 6 0 5; same with LEONIDA_W64_EMULATE=1
  • Whole suite (native wave64): 195 shaders translated, 195 pass spirv-val; 176/190 passed, 14 skipped, 0 failed. The skips are the 14 fixtures the d3d12_* tests run.
  • build.py + check.py: 215 shaders: 215 translated, 215 pass spirv-val; 165 of 168 pass, 3 skipped; ok for cs_w32_getreg_mode.
  • CPU: python -I -m unittest discover -s tests/semantic -p test_value_semantics.py 36 OK, tests/test_shader_checks.py 69 OK, tests/test_run_gpu_tests.py 34 OK, tests/semantic/regen_fixtures.py --check clean. I did not run the whole tests/semantic suite.

Test programs: an MSVC 14.44 build of main ec8ec4c; this PR's runtime C++ and CMake are identical to that commit, and the translator, runner and check.py are this PR's. llvm-mc 21.1.8 (native), Vulkan SDK 1.4.363.0. No negative control run here. No game files. AI-assisted (Claude Code).

@crastinator

Copy link
Copy Markdown
Contributor

Tested 3654560 merged into main 16282101 (clean merge) on AMD Radeon RX 6700 XT (Navi 22, gfx1031, subgroup 32..64), RADV Mesa 26.3.1, CachyOS, Linux 7.3.5, GCC 16.2.1, llvm-mc 23.1.5: pass.

  • New test passes natively: cs_w32_getreg_mode (0 0 3 12 1 6 0 5).
  • Whole run_gpu_tests.py: 176/190 native, 176/190 with LEONIDA_W64_EMULATE=1 (the skips are the D3D12-only fixtures and ps_w64x_readlane, as on main). ctest 37/37.
  • tests/semantic/test_value_semantics.py: 36 passed, 254 subtests passed.

No game files. AI-assisted (Claude Code).

@kapitche

Copy link
Copy Markdown
Contributor

Tested on Windows 11 with two GPUs on one machine (runtime built from this PR's head, MSVC 14.51):

No problems found. ctest on the RTX 4080 SUPER: 129/129 passed. Intel UHD 770 ctest: only the two known base failures, d3d12_descriptor (fixed by #2948) and d3d12_subgroup (fixed by #2934). One further Intel failure, d3d12_present, appeared in the full run but passes 3/3 when run alone on Intel (same on #2965 and #2962 under load), so it looks like an intermittent failure under machine load, not caused by this PR.
Fixture cs_w32_getreg_mode: PASS on RTX 4080 SUPER and PASS on Intel UHD 770 (identical output).

docs/design.md
tools/rdna2spirv.py

AI-assisted.
@Yourrespawn

Copy link
Copy Markdown
Contributor

Tested eb542761 on NVIDIA GeForce RTX 4080 (Ada, subgroup 32..32), driver 617.14, Vulkan API 1.4.351, Windows 11 Pro 10.0.26200: pass.

  • New fixture on real hardware: cs_w32_getreg_mode PASS (0 0 3 12 1 6 0 5) — the MODE.FP_ROUND field reads (offset/size extraction, the shifted-down field value) return exactly what the rule says on NVIDIA
  • run_gpu_tests.py: 154/200 passed, 0 failed, 46 skipped (native wave64, expected on this 32-lane GPU)
  • Semantic suite: 7325 OK, 1 expected failure (Python 3.12.10)

AI-assisted (ZCode agent): builds and runs executed by a coding agent on this machine.

docs/design.md
runtime/test/shaders/check.py
scripts/run_gpu_tests.py

AI-assisted.
@Kev-Ball

Copy link
Copy Markdown

Tested 4e203adf on an NVIDIA GeForce RTX 3080 Ti (32-lane subgroups), driver 620.73.04, CachyOS Linux 7.3.5-2-cachyos. I rebuilt the Vulkan harnesses from this revision and selected the NVIDIA device explicitly.

Ran the PR’s synthetic fixture through scripts/run_gpu_tests.py --build runtime/build/linux --filter <fixture> --require-pass. The shader translated and passed Vulkan SPIR-V validation. GPU readback passed:

  • cs_w32_getreg_mode — 0 0 3 12 1 6 0 5.

AI-assisted verification with synthetic inputs.

docs/design.md

AI-assisted.
@bobcatchris

Copy link
Copy Markdown
Contributor

Apple M2 / MoltenVK validation of head afd6a8b3 (hardware reports Apple M2 / Mac14,3, not M1), macOS 26.4, MoltenVK 1.4.2, subgroup 4..32, llvm-mc 23.1.6. Python/translator-only; harness built from the PR's base 0db7fed5 and shared for the A/B.

  • New GPU fixture cs_w32_getreg_mode PASS: cs_w32_getreg_mode 0 0 3 12 1 6 0 5
  • Full suite: 153/218 passed, 58 skipped, 7 failed (known MoltenVK expected set), versus base 0db7fed5 at 152/217, 58 skipped, 7 failed. No common test changed status.

No code changes, no game data; synthetic fixture and counts only.

AI-assisted.

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.

9 participants