gpu/recomp: implement DS_WRITE_ADDTID_B32 and DS_READ_ADDTID_B32 #79

Manually merged
github merged 1 commit from gh-pr/79/head into gh-pr/79/base 2026-11-26 04:08:31 +00:00
Owner

@⁠certified-retart on GitHub · 2026-11-23 01:36 UTC · original
certified-retart:feat/recomp-ds-addtid → main · +102 −1 · 2 files · 1 commits · merged 2026-11-23 10:29 UTC

Summary

Implements DS_WRITE_ADDTID_B32 (opcode 0xB0) and DS_READ_ADDTID_B32 (opcode 0xB1) in the RDNA2 → HLSL shader recompiler (gpu::recomp::emit::Emitter::ds).

Both opcodes already decoded in rdna2_spec.rs, but Emitter::ds previously fell through to the unsupported DS path (after also unnecessarily looking up the unused ADDR VGPR).

Changes

  • crates/xcl/src/gpu/recomp/emit.rs (Emitter::ds):
    • Handle ds_write_addtid_b32 and ds_read_addtid_b32 before the generic ADDR VGPR lookup so unused ADDR / DATA1 fields are not read or spuriously declared.
    • Reject GDS=1 with Err("GDS") before setting self.uses_lds = true.
    • Compute the RDNA2 byte address ((m0 & 0xFFFFu) + offset16 + 4u * lane_id) (where offset16 = OFFSET0 | (OFFSET1 << 8) and m0 is SGPR 124), indexing xcl_lds[((at) >> 2) & 8191u] consistently with the rest of Emitter::ds.
    • Gate both writes (DATA0) and reads (VDST) on the active lane predicate (EXEC), and update xcl_gs_base on active writes during geometry-shader phase.
  • crates/xcl/src/gpu/recomp/tests.rs:
    • ds_addtid_translates_with_m0_offset_and_lane_id: verifies zero unsupported ops, xcl_lds allocation, exact address expression, ignored nonzero ADDR/DATA1 VGPR fields, and GDS=1 rejection without xcl_lds allocation.
    • gpu_ds_addtid_roundtrip_and_exec_masking: verifies bidirectional LDS placement (DS_WRITE_B32 → DS_READ_ADDTID_B32 and DS_WRITE_ADDTID_B32 → DS_READ_B32) with nonzero M0[31:16] and OFFSET1 = 0x40, plus wave64 EXEC masking on both writes and reads.

Verification

  • cargo test -p xcl --lib ds_addtid_translates — passed (1 passed; 0 failed).
  • Live wave64 GPU verification on Windows 10 Pro + AMD Radeon(TM) Graphics (Ryzen 7 9800X3D RDNA2 iGPU, XCL_ADAPTER=1, XCL_REQUIRE_GPU=wave64, D3D12 Agility SDK 1.620.2):
    • cargo test -p xcl --lib gpu_ds_addtid_roundtrip_and_exec_masking -- --test-threads=1 — passed (1 passed; 0 failed).
**@⁠certified-retart** on GitHub · 2026-11-23 01:36 UTC · [original](https://github.com/xcl-dev/xcl/pull/79) `certified-retart:feat/recomp-ds-addtid` → `main` · +102 −1 · 2 files · 1 commits · merged 2026-11-23 10:29 UTC ## Summary Implements `DS_WRITE_ADDTID_B32` (opcode `0xB0`) and `DS_READ_ADDTID_B32` (opcode `0xB1`) in the RDNA2 → HLSL shader recompiler (`gpu::recomp::emit::Emitter::ds`). Both opcodes already decoded in `rdna2_spec.rs`, but `Emitter::ds` previously fell through to the unsupported DS path (after also unnecessarily looking up the unused `ADDR` VGPR). ### Changes - **`crates/xcl/src/gpu/recomp/emit.rs` (`Emitter::ds`)**: - Handle `ds_write_addtid_b32` and `ds_read_addtid_b32` before the generic `ADDR` VGPR lookup so unused `ADDR` / `DATA1` fields are not read or spuriously declared. - Reject `GDS=1` with `Err("GDS")` before setting `self.uses_lds = true`. - Compute the RDNA2 byte address `((m0 & 0xFFFFu) + offset16 + 4u * lane_id)` (where `offset16 = OFFSET0 | (OFFSET1 << 8)` and `m0` is SGPR `124`), indexing `xcl_lds[((at) >> 2) & 8191u]` consistently with the rest of `Emitter::ds`. - Gate both writes (`DATA0`) and reads (`VDST`) on the active lane predicate (`EXEC`), and update `xcl_gs_base` on active writes during geometry-shader phase. - **`crates/xcl/src/gpu/recomp/tests.rs`**: - `ds_addtid_translates_with_m0_offset_and_lane_id`: verifies zero unsupported ops, `xcl_lds` allocation, exact address expression, ignored nonzero `ADDR`/`DATA1` VGPR fields, and `GDS=1` rejection without `xcl_lds` allocation. - `gpu_ds_addtid_roundtrip_and_exec_masking`: verifies bidirectional LDS placement (`DS_WRITE_B32` → `DS_READ_ADDTID_B32` and `DS_WRITE_ADDTID_B32` → `DS_READ_B32`) with nonzero `M0[31:16]` and `OFFSET1 = 0x40`, plus wave64 `EXEC` masking on both writes and reads. ### Verification - `cargo test -p xcl --lib ds_addtid_translates` — passed (`1 passed; 0 failed`). - Live wave64 GPU verification on Windows 10 Pro + AMD Radeon(TM) Graphics (Ryzen 7 9800X3D RDNA2 iGPU, `XCL_ADAPTER=1`, `XCL_REQUIRE_GPU=wave64`, D3D12 Agility SDK 1.620.2): - `cargo test -p xcl --lib gpu_ds_addtid_roundtrip_and_exec_masking -- --test-threads=1` — passed (`1 passed; 0 failed`).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:08:28 +00:00
github manually merged commit 3b74cda9a5 into gh-pr/79/base 2026-11-26 04:08:31 +00:00
Author
Owner

@⁠Lum7nt on GitHub · 2026-11-23 05:57 UTC · original

Tested locally on Windows — both ds_addtid_translates_with_m0_offset_and_lane_id and the GPU dispatch test gpu_ds_addtid_roundtrip_and_exec_masking pass cleanly.

Key implementation details verified:

  1. Instruction encoding: Intercepts DS_WRITE_ADDTID_B32 and DS_READ_ADDTID_B32 before the generic ADDR VGPR lookup, ensuring unused VGPR operands are not spuriously emitted into the recompiled shader.
  2. RDNA2 address calculation: Accurate formula ((m0 & 0xFFFFu) + offset16 + 4u * lane_id) & 0xFFFFu with proper masking into xcl_lds[((at >> 2) & 8191u)].
  3. Wave64 EXEC gating: Both write and read operations are properly guarded under active lane predicates.

Clean and direct implementation.

**@⁠Lum7nt** on GitHub · 2026-11-23 05:57 UTC · [original](https://github.com/xcl-dev/xcl/pull/79#issuecomment-7092885722) Tested locally on Windows — both `ds_addtid_translates_with_m0_offset_and_lane_id` and the GPU dispatch test `gpu_ds_addtid_roundtrip_and_exec_masking` pass cleanly. Key implementation details verified: 1. **Instruction encoding**: Intercepts `DS_WRITE_ADDTID_B32` and `DS_READ_ADDTID_B32` before the generic `ADDR` VGPR lookup, ensuring unused VGPR operands are not spuriously emitted into the recompiled shader. 2. **RDNA2 address calculation**: Accurate formula `((m0 & 0xFFFFu) + offset16 + 4u * lane_id) & 0xFFFFu` with proper masking into `xcl_lds[((at >> 2) & 8191u)]`. 3. **Wave64 EXEC gating**: Both write and read operations are properly guarded under active lane predicates. Clean and direct implementation.
Author
Owner

@⁠ivall on GitHub · 2026-11-23 10:29 UTC · original

Merged. It conflicted with #67 in Emitter::ds; resolved keeping #67's split-aware LDS slot, and the addtid forms also clamp below the split wave64 exchange (XCL_X_LDS_TOP) in the split form. Tested on Windows 11 with an RX 9070 (RDNA4): cargo test --workspace green with the retail samples (shader pack, console DLLs, texture archive), also with XCL_SPLIT_WAVE64=1 (the 32-lane split path forced on RDNA). Unicorn Overlord and XDefiant run with this round merged. Thanks!

**@⁠ivall** on GitHub · 2026-11-23 10:29 UTC · [original](https://github.com/xcl-dev/xcl/pull/79#issuecomment-7098055661) Merged. It conflicted with #67 in `Emitter::ds`; resolved keeping #67's split-aware LDS slot, and the addtid forms also clamp below the split wave64 exchange (`XCL_X_LDS_TOP`) in the split form. Tested on Windows 11 with an RX 9070 (RDNA4): `cargo test --workspace` green with the retail samples (shader pack, console DLLs, texture archive), also with `XCL_SPLIT_WAVE64=1` (the 32-lane split path forced on RDNA). Unicorn Overlord and XDefiant run with this round merged. Thanks!
This discussion has been locked. Commenting is limited to contributors.
No description provided.