feat: ds_read_addtid_b32 and ds_write_addtid_b32 in the RDNA 2 interpreter and HLSL — 1,208/1,490 #248

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

@⁠lcg007xd-c on GitHub · 2026-11-25 21:11 UTC · original
lcg007xd-c:feat/rdna2-ds-addtid → main · +142 −26 · 14 files · 1 commits · merged 2026-11-25 21:55 UTC

Change

The reference interpreter and the HLSL recompiler now run ds_write_addtid_b32 and ds_read_addtid_b32 (DS opcodes 176-177). Both raised Untranslated / Untranslatable until now.

Source: AMD, "RDNA 2" ISA, November 2020, §12.13 "LDS & GDS Instructions" (printed p. 204):

  • DS_WRITE_ADDTID_B32: "LDS_GS[LDS_BASE + {OFFSET1,OFFSET0} + M0[15:0] + TID*4].u32 = VGPR[DATA0].u32";
  • DS_READ_ADDTID_B32: "VGPR[VDST].u32 = LDS_GS[LDS_BASE + {OFFSET1,OFFSET0} + M0[15:0] + TID*4].u32".

These are the LDS counterpart of the global_*_dword_addtid of #226, and this PR follows the same pattern:

  • Interpreter (emu/rdna2_exec_memory.py): no VGPR address is read. The dword at M0[15:0] + offset + lane × 4 is written or read for the active lanes, and M0[31:16] is ignored. New LDS_ADD_TID table and _lds_add_tid.
  • HLSL (emu/rdna2_hlsl_memory.py): g_lds[(((s[124] & 0xFFFFu) + offset + lane * 4u) >> 2) % 8128u], with the same group barriers as the other LDS accesses.
  • Graphics shaders: the two names join CROSS_LANE_OPS in rdna2_hlsl_graphics.py, so a pixel shader using them takes the multi-lane path with real lane ids.
  • Wave64: translated through _specific in rdna2_hlsl_wave64.py, like global addtid (lane = SV_GroupIndex 0-63, the TID in the wave64).

Coverage (rdna2_exec.coverage()): 1,206 → 1,208 of 1,490. All 9 READMEs stay at 81%. Overlap: other open PRs change the same README number.

Linked issue: none.

Verification

Linux (Arch, Python 3.14.10), no C++ runtime, no GPU (runtime and GPU tests skip), rebased rebased on main affaf15:

python -m pytest                → 1092 passed, 322 skipped
python -m ruff check --select W605,F,E9 PrototypeScarlett tests tools → All checks passed!

The suite is green on this machine since #237 and #238 merged.

Not run here: the two GPU parity tests. I have no Windows, dxc or WARP, so they skip locally and will run in the Windows CI job. I did check on the CPU that both GPU programs translate (wave32 and wave64) and that the generated g_lds lines use s[124] & 0xFFFFu and lane. Please look at the CI result of test_ds_addtid_matches_interpreter_on_gpu and …_in_wave64_on_gpu.

Oracle and test data

  • New tests/test_rdna2_exec_ds_addtid.py (7 tests). Expected values are written by hand:
    • the write lands at 0x20 + 0x104 + lane × 4, with M0 = 0xABCD0020 (high half ignored) and offset {1, 4}, under a partial EXEC, with nothing written below;
    • the read fills only active lanes, each reading its neighbour's word, and lane 31 reads 0;
    • in wave64, lane 63 reaches byte 0x20 + 252;
    • the HLSL text;
    • graphics shaders flag the instructions as lane-dependent;
    • GPU parity in wave32 and wave64: a partial-EXEC write, then a full-EXEC read of the neighbour's word through LDS, stored and compared byte for byte.
  • Failure case: the 5 CPU tests fail on main (Untranslated / Untranslatable).
  • Test programs are built in the test with the existing encoders.

Checklist

  • The PR covers a single reviewable behaviour.
  • A test fails without this change and passes with it.
  • The commands and results of each check are given above. (GPU parity: CI only, see above.)
  • An unimplemented function returns an error (E_NOTIMPL), never a fake success.
  • README: the same change in all 9 languages (test_readme_sync.py checks it).
  • No game, console or SDK file, no key, no dump, no download link.
  • Findings drawn from a title: none.
  • Code taken from another project: none.

Made with AI assistance (Claude Code).

🤖 Generated with Claude Code

**@⁠lcg007xd-c** on GitHub · 2026-11-25 21:11 UTC · [original](https://github.com/LooperSalty/AnyXboxX/pull/248) `lcg007xd-c:feat/rdna2-ds-addtid` → `main` · +142 −26 · 14 files · 1 commits · merged 2026-11-25 21:55 UTC ## Change The reference interpreter and the HLSL recompiler now run `ds_write_addtid_b32` and `ds_read_addtid_b32` (DS opcodes 176-177). Both raised `Untranslated` / `Untranslatable` until now. Source: AMD, "RDNA 2" ISA, November 2020, §12.13 "LDS & GDS Instructions" (printed p. 204): - `DS_WRITE_ADDTID_B32`: "LDS_GS[LDS_BASE + {OFFSET1,OFFSET0} + M0[15:0] + TID*4].u32 = VGPR[DATA0].u32"; - `DS_READ_ADDTID_B32`: "VGPR[VDST].u32 = LDS_GS[LDS_BASE + {OFFSET1,OFFSET0} + M0[15:0] + TID*4].u32". These are the LDS counterpart of the `global_*_dword_addtid` of #226, and this PR follows the same pattern: - **Interpreter** (`emu/rdna2_exec_memory.py`): no VGPR address is read. The dword at `M0[15:0] + offset + lane × 4` is written or read for the active lanes, and `M0[31:16]` is ignored. New `LDS_ADD_TID` table and `_lds_add_tid`. - **HLSL** (`emu/rdna2_hlsl_memory.py`): `g_lds[(((s[124] & 0xFFFFu) + offset + lane * 4u) >> 2) % 8128u]`, with the same group barriers as the other LDS accesses. - **Graphics shaders**: the two names join `CROSS_LANE_OPS` in `rdna2_hlsl_graphics.py`, so a pixel shader using them takes the multi-lane path with real lane ids. - **Wave64**: translated through `_specific` in `rdna2_hlsl_wave64.py`, like global addtid (`lane` = `SV_GroupIndex` 0-63, the TID in the wave64). Coverage (`rdna2_exec.coverage()`): **1,206 → 1,208 of 1,490**. All 9 READMEs stay at 81%. **Overlap:** other open PRs change the same README number. Linked issue: none. ## Verification Linux (Arch, Python 3.14.10), no C++ runtime, no GPU (runtime and GPU tests skip), rebased rebased on `main` `affaf15`: ``` python -m pytest → 1092 passed, 322 skipped python -m ruff check --select W605,F,E9 PrototypeScarlett tests tools → All checks passed! ``` The suite is green on this machine since #237 and #238 merged. **Not run here: the two GPU parity tests.** I have no Windows, `dxc` or WARP, so they skip locally and will run in the Windows CI job. I did check on the CPU that both GPU programs translate (wave32 and wave64) and that the generated `g_lds` lines use `s[124] & 0xFFFFu` and `lane`. Please look at the CI result of `test_ds_addtid_matches_interpreter_on_gpu` and `…_in_wave64_on_gpu`. ## Oracle and test data - New `tests/test_rdna2_exec_ds_addtid.py` (7 tests). Expected values are written by hand: - the write lands at `0x20 + 0x104 + lane × 4`, with M0 = `0xABCD0020` (high half ignored) and offset `{1, 4}`, under a partial EXEC, with nothing written below; - the read fills only active lanes, each reading its neighbour's word, and lane 31 reads 0; - in wave64, lane 63 reaches byte `0x20 + 252`; - the HLSL text; - graphics shaders flag the instructions as lane-dependent; - GPU parity in wave32 and wave64: a partial-EXEC write, then a full-EXEC read of the neighbour's word through LDS, stored and compared byte for byte. - Failure case: the 5 CPU tests fail on `main` (`Untranslated` / `Untranslatable`). - Test programs are built in the test with the existing encoders. ## Checklist - [x] The PR covers a single reviewable behaviour. - [x] A test fails without this change and passes with it. - [x] The commands and results of each check are given above. (GPU parity: CI only, see above.) - [x] An unimplemented function returns an error (`E_NOTIMPL`), never a fake success. - [x] README: the same change in all 9 languages (`test_readme_sync.py` checks it). - [x] No game, console or SDK file, no key, no dump, no download link. - [x] Findings drawn from a title: none. - [x] Code taken from another project: none. Made with AI assistance (Claude Code). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
DS 176-177 raised Untranslated. No VGPR address: the LDS dword at
{OFFSET1,OFFSET0} + M0[15:0] + lane * 4 (ISA section 12.13, p. 204;
M0[31:16] ignored). The interpreter reads/writes it for active lanes; the
HLSL recompiler indexes g_lds with lane, like the global addtid of #226:
listed as lane-dependent for graphics shaders, and translated in wave64
(lane = SV_GroupIndex). Tests: addresses, partial EXEC, wave64 lane 63,
the HLSL text, and GPU parity in wave32 and wave64 (a lane reads its
neighbour's write through LDS). README: 1,206 -> 1,208 of 1,490 (81%).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:40:16 +00:00
github manually merged commit 7aa84f0eb5 into gh-pr/248/base 2026-11-26 05:40:17 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.