gpu/recomp: implement DS_WRITE_ADDTID_B32 and DS_READ_ADDTID_B32 #78

Merged
certified-retart merged 1 commit from upstream-pr/79 into main 2026-11-23 10:29:16 +00:00
certified-retart commented 2026-11-23 01:36:28 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by certified-retart on 2026-11-23T01:36:28Z.


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).
<!-- greyfinch-sync:ivall/xcl:issue:6550482885 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/79). Originally posted by [certified-retart](https://github.com/certified-retart) on 2026-11-23T01:36:28Z. --- ## 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`).
upstream-sync closed this pull request 2026-11-24 06:57:03 +00:00
Lum7nt commented 2026-11-24 07:00:23 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Lum7nt on 2026-11-23T05:57:55Z.


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.

<!-- greyfinch-sync:ivall/xcl:comment:7092885722 --> Imported from [ivall/xcl](https://github.com/ivall/xcl/pull/79#issuecomment-7092885722). Originally posted by [Lum7nt](https://github.com/Lum7nt) on 2026-11-23T05:57:55Z. --- 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.
ivall commented 2026-11-24 07:00:27 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by ivall on 2026-11-23T10:29:33Z.


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!

<!-- greyfinch-sync:ivall/xcl:comment:7098055661 --> Imported from [ivall/xcl](https://github.com/ivall/xcl/pull/79#issuecomment-7098055661). Originally posted by [ivall](https://github.com/ivall) on 2026-11-23T10:29:33Z. --- 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!
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
xcl-dev/xcl!78
No description provided.