Skip to content

rdna2_decode: name hwreg ids as GFX10 does (HW_ID1 is 23, HW_ID2 24, POPS_PACKER 25) - #7300

Open
hmodymac8-droid wants to merge 3 commits into
ItsNotRexed:mainfrom
hmodymac8-droid:fix/rdna2-decode-hwreg-names
Open

hmodymac8-droid wants to merge 3 commits into
ItsNotRexed:mainfrom
hmodymac8-droid:fix/rdna2-decode-hwreg-names

Conversation

@hmodymac8-droid

Copy link
Copy Markdown

What changed and why

_HWREG_NAMES in tools/rdna2_decode.py was shifted against GFX10:

id rdna2_decode on main llvm-mc 23.1.6 (gfx1013, gfx1030)
4 HW_REG_HW_ID1 hwreg(4) (no GFX10 name)
23 HW_REG_HW_ID2 HW_REG_HW_ID1
24 HW_REG_POPS_PACKER HW_REG_HW_ID2
25 hwreg(25) HW_REG_POPS_PACKER
26 HW_REG_SHADER_CYCLES hwreg(26)
29 hwreg(29) HW_REG_SHADER_CYCLES on gfx1030+, hwreg(29) on gfx101x
22 HW_REG_XNACK_MASK the same on gfx101x, hwreg(22) on gfx1030+

So the wave-id read s_getreg_b32 s4, hwreg(HW_REG_HW_ID1) (id 23, the one tools/vinterp_hw_probe.py emits) decoded as HW_REG_HW_ID2.
The two target-dependent names use the mcpu the decoder already has; _format_hwreg now takes it.
The translator reads only HW_REG_MODE (id 1), which is unchanged, so translation is not affected; this is about the listing matching llvm-mc.

Found by decoding random SOPK words with both rdna2_decode and llvm-mc and comparing.

Claim: #7231 (new item).

Test

  • python -I -m unittest tests.test_rdna2_decode: OK (1 skipped without LLVM_MC). The new test_hwreg_names_follow_gfx10 has 11 cases; eight fail on main and all pass with this change.
  • Every id 0-63, whole register and a 16/9 field, s_getreg_b32 and s_setreg_b32, on gfx1010, gfx1013, gfx1030 and gfx1036: all 1024 listings match llvm-mc 23.1.6.
  • tests/test_shader_ir.py, tests/test_shader_disasm.py: OK.

GPU and driver

No GPU needed.

AI-assisted (Claude Code).

🤖 Generated with Claude Code

…POPS_PACKER 25)

_HWREG_NAMES was shifted against GFX10. It named id 4 HW_REG_HW_ID1, 23
HW_REG_HW_ID2, 24 HW_REG_POPS_PACKER and 26 HW_REG_SHADER_CYCLES. llvm-mc
23.1.6 has 4 unnamed, 23 HW_REG_HW_ID1, 24 HW_REG_HW_ID2, 25
HW_REG_POPS_PACKER and 26 unnamed. So the wave-id read
`s_getreg_b32 s4, hwreg(HW_REG_HW_ID1)` (id 23, the one
tools/vinterp_hw_probe.py emits) decoded as HW_REG_HW_ID2.

Two names depend on the target, and the decoder already has mcpu: XNACK_MASK
(22) exists only before gfx1030 and SHADER_CYCLES (29) only from gfx1030,
so _format_hwreg now takes mcpu. The translator reads only HW_REG_MODE (id
1), which is unchanged.

Checked every id 0-63, whole register and a 16/9 field, s_getreg_b32 and
s_setreg_b32, on gfx1010, gfx1013, gfx1030 and gfx1036: all 1024 listings
match llvm-mc 23.1.6. Found by decoding random SOPK words with both and
comparing.

tests/test_rdna2_decode.py: test_hwreg_names_follow_gfx10 (eight of its
cases fail on main, all pass with this change); the file: OK.

AI-assisted (Claude Code).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@tikD1337

Copy link
Copy Markdown
Contributor

Review: PR #7300: rdna2_decode: name hwreg ids as GFX10 does

Verdict: Approve. The new table matches the GFX10 hwreg numbering and the per-target split matches what llvm-mc does. It changes no translator behaviour. I have two small nits below and neither blocks the merge.

Environment

Windows 11, CPython 3.13, run with python -I. No GPU, LLVM toolchain or game files were needed.

What changed

tools/rdna2_decode.py

  • _HWREG_NAMES now uses GFX10 ids. The old table mixed GFX9 and GFX10 numbering:

    • 4: HW_ID1 is the GFX6–9 HW_REG_HW_ID, which GFX10 removed.
    • HW_ID2, POPS_PACKER and SHADER_CYCLES were each one or more ids off.

    After this PR, HW_ID1, HW_ID2 and POPS_PACKER are 23, 24 and 25. Ids 4 and 26 fall back to the number. This matches the ID_* enum in LLVM's AMDGPU SIDefines.h (Mesa/LLVM reference).

  • Ids that depend on the target are split out:

    • _HWREG_NAMES_GFX101 = {22: XNACK_MASK}: LLVM names it only before gfx1030.
    • _HWREG_NAMES_GFX103 = {29: SHADER_CYCLES}: LLVM names it only from gfx1030 on.

    The choice uses mcpu.startswith("gfx103"), the same test that already gates opcode 0x140 at tools/rdna2_decode.py:933. So gfx1030–gfx1036 get the 10.3 table and the default gfx1013 gets the 10.1 table. A GFX11 target would also get the 10.1 table, but the decoder does not handle GFX11 anywhere else either.

  • Both callers now pass mcpu through. These are s_getreg_b32/s_setreg_b32 at :787 and s_setreg_imm32_b32 at :792. _format_hwreg keeps its "gfx1013" default, so any direct caller still works.

tests/test_rdna2_decode.py

  • New test test_hwreg_names_follow_gfx10. It hand-encodes the word 0xB9010000 | id | 31<<11 (SOPK s_getreg_b32 s1, full 32-bit field) and checks the printed name across both targets. That covers:
    • ids that keep the same name on both targets (1, 23);
    • ids that move between targets (22, 29);
    • the ids that changed in this PR (4, 23–26).

Effect on code downstream

I checked every place the decoder's hwreg text is used:

  • rdna2spirv.py:1116 / :16163. These only act on HW_REG_MODE, which is still id 1 with the same name. The regex hwreg\((\w+)…\) also matches the numbered forms (hwreg(22)), so a renamed id cannot cause a parse failure.
  • rdna2spirv.py:198. It records that s_getreg_b32 is unsupported, so the renamed read-only registers (HW_ID1/2, SHADER_CYCLES) never reach the translator.
  • shader_ir.py:155. It only checks for the hwreg( prefix.
  • No in-tree assembler encodes hwreg names, so nothing assembles these strings back into bytes. The hand-written probes (for example vinterp_hw_probe.py:182, hwreg(HW_REG_HW_ID1)) go through llvm-mc, which already uses the GFX10 numbering. Before this PR our disassembly disagreed with them, and now it agrees.

So the change only affects how the disassembly reads and whether it matches llvm-mc. The translated and spirv-val-valid counts cannot move, which is why skipping the full semantic suite is acceptable here.

Nits (non-blocking)

  1. The names dict is rebuilt on every call. _format_hwreg merges two dicts for each s_getreg/s_setreg. The cost is negligible at corpus scale. Two module-level merged tables picked by the prefix would be simpler and avoid the allocation.
  2. The test only covers the short form. Every case uses the full 32-bit field, so only hwreg(NAME) is checked. One case for a target-specific id with a partial field would cover the hwreg(NAME, off, size) branch too, for example s_setreg_imm32_b32 on gfx1030 id 29 with offset/size ≠ 0/32.
  3. The llvm-mc version is not proven by this run. The test comment cites llvm-mc 23.1.6 as the source of truth, but test_parity_with_llvm_mc_on_shader_fixtures was skipped here (no llvm-mc). The expected strings agree with LLVM's SIDefines.h / AMDGPUAsmUtils.cpp tables. Pasting the llvm-mc command line into the PR description would make the source checkable.

Test results (harness, no game files)

Check Result
git diff --check PASS
python -m compileall -q make_game.py tools tests PASS
python -I scripts/check_no_game_data.py on changed files PASS
python -I make_game.py --help PASS
python -I tests/test_rdna2_decode.py 17 run, 16 OK, 1 skipped (llvm-mc not available)
test_hwreg_names_follow_gfx10 OK, all 11 subtests
Existing hwreg(HW_REG_MODE, 2, 2) decode test (:174–183) OK, MODE unchanged

Project rules

  • No game data: the test input is one hand-built SOPK word. No shaders, disassembly or carved data are added.
  • No keys or protection workarounds, nothing online: not touched.
  • Fix, don't disable: this fixes the decoder's name table and adds no skip list. It is not a new translator rule, so it needs no contract-table entry in docs/design.md and no .asm fixture in tests/semantic/.
  • Conventions: standard library only. The decoder writes no new files, so the line-ending rule does not apply.

AI-assisted.

… from the other open rdna2_decode PRs

Each of the open rdna2_decode PRs added its test at the same spot, so they
conflicted with each other. No change to the test itself.

AI-assisted (Claude Code).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
hmodymac8-droid added a commit to hmodymac8-droid/Leonida that referenced this pull request Nov 23, 2026
It sat right above _HWREG_NAMES, which ItsNotRexed#7300 rewrites, so the two PRs
conflicted. No behaviour change.

AI-assisted (Claude Code).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@memorypressure

Copy link
Copy Markdown

Tested f76f6df, clean vs main 976b3ec: the new test_hwreg_names_follow_gfx10 fails on clean main in 8 of 11 subCases and passes merged. The suite's single remaining failure is the pre-existing op_sel parity red (test_parity_with_llvm_mc_on_shader_fixtures) — byte-identical before and after your change, so you neither fix nor regress it; it is a known main-side red. Note: the GFX103-side claim (SHADER_CYCLES from gfx1030) is asserted against the llvm-mc table in your comment, not re-derived here. Flag: the branch reports NO CI checks. AI-assisted: yes. Tested on Linux (RTX 5080 host, CPU-only run).

@AsgerCode

Copy link
Copy Markdown

Tested e4c64ea on Windows 11 (NTFS), Python 3.12.10 (CPU only, no GPU, no game files): pass

The earlier reviews checked the 11 test cases and the downstream users, and one of them said that the gfx103x names were not re-derived. This checks all 64 ids, on both gfx101x and gfx103x, against the LLVM source, and adds merge-order notes.

What I ran:

Nits, none blocking:

  1. The test covers only s_getreg_b32, so the mcpu argument at the s_setreg_b32/s_setreg_imm32_b32 call sites has no test. This matters for the rdna2_decode: ~30% faster listing and ~20% faster decode_bytes, output unchanged (PERF-RDNA2-DECODE) #7044 conflict. If that conflict is resolved with rdna2_decode: ~30% faster listing and ~20% faster decode_bytes, output unchanged (PERF-RDNA2-DECODE) #7044's line (_format_hwreg(simm16)), test_rdna2_decode.py still passes 17/17, but gfx1036 then prints s_setreg_imm32_b32 hwreg(29, 0, 31), 5 where LLVM prints hwreg(HW_REG_SHADER_CYCLES, 0, 31) (12 listings wrong). One s_setreg_imm32_b32 case on gfx1030 id 29 would catch it. Word: 0xBA80F81D, then literal 5.
  2. The target test here is mcpu.startswith("gfx103"). The 0x140 gate at tools/rdna2_decode.py:933 is mcpu.startswith("gfx101"), the other way round, so the two tests disagree for any other name. With mcpu="gfx10-3-generic", one listing gives hwreg(HW_REG_XNACK_MASK) and hwreg(29) (10.1 names) next to v_fma_legacy_f32 (10.3 name). LLVM 23.1.6 builds FeatureISAVersion10_3_Generic from FeatureISAVersion10_3_0.Features, so it prints hwreg(22) and HW_REG_SHADER_CYCLES there. No caller in the repo passes a generic name, but --mcpu in tools/shader_disasm.py is free text. One shared helper for both checks would keep them in step.

AI-assisted (Claude Code).

…st s_setreg_imm32

Review on ItsNotRexed#7300 (AsgerCode, tikD1337):
- The hwreg split used mcpu.startswith("gfx103") while the 0x140 gate used
  startswith("gfx101"), so a generic name got 10.1 hwreg names next to a
  10.3 opcode. Both now use _is_gfx101(), which also knows gfx10-1-generic.
  llvm-mc 23.1.6 on gfx1010, gfx1013, gfx1030, gfx1036, gfx10-1-generic and
  gfx10-3-generic: all 1536 s_getreg_b32 / s_setreg_imm32_b32 listings over
  ids 0-63 (fields 0/32 and 16/9) match, and the 0x140 opcode name matches
  on all four targets.
- The two merged name tables are built once, not per call.
- The test checks the s_setreg_imm32_b32 call site too (0xBA80F81D 0x5:
  hwreg(HW_REG_SHADER_CYCLES) on gfx1030, hwreg(29) on gfx1013), so a merge
  that drops mcpu there is caught.

AI-assisted (Claude Code).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@hmodymac8-droid

Copy link
Copy Markdown
Author

Thanks @tikD1337, @memorypressure and @AsgerCode. Pushed 7613fa5, which takes the nits:

  • One target test (AsgerCode nit 2): the hwreg split and the 0x140 gate both use _is_gfx101() now, and it also knows gfx10-1-generic. llvm-mc 23.1.6 (conda-forge llvm-tools, Windows) on gfx1010, gfx1013, gfx1030, gfx1036, gfx10-1-generic and gfx10-3-generic: all 1536 s_getreg_b32 / s_setreg_imm32_b32 listings over ids 0-63 (fields 0/32 and 16/9) match, and the 0x140 opcode name matches on all four of those targets.
  • s_setreg_imm32_b32 call site (AsgerCode nit 1): the test now has 0xBA80F81D 0x5, which gives hwreg(HW_REG_SHADER_CYCLES), 5 on gfx1030 and hwreg(29), 5 on gfx1013 (both checked with llvm-mc). A rdna2_decode: ~30% faster listing and ~20% faster decode_bytes, output unchanged (PERF-RDNA2-DECODE) #7044 merge that drops mcpu there will fail it.
  • Table built per call (tikD1337 nit 1): both merged tables are now built once at module level.
  • The llvm-mc command (tikD1337 nit 3): llvm-mc -arch=amdgcn -mcpu=<target> -disassemble on the raw words, LLVM 23.1.6.

tests/test_rdna2_decode.py, tests/test_shader_ir.py, tests/test_shader_disasm.py: OK. AI-assisted (Claude Code).

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.

4 participants