Skip to content

gpu/recomp: implement DS_WRITE_ADDTID_B32 and DS_READ_ADDTID_B32 - #79

Merged
ivall merged 1 commit into
xcl-dev:mainfrom
certified-retart:feat/recomp-ds-addtid
Nov 23, 2026
Merged

ivall merged 1 commit into
xcl-dev:mainfrom
certified-retart:feat/recomp-ds-addtid

Conversation

@certified-retart

Copy link
Copy Markdown
Contributor

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).

@Lum7nt

Lum7nt commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

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
ivall merged commit c94d6b7 into xcl-dev:main Nov 23, 2026
ivall added a commit that referenced this pull request Nov 23, 2026
@ivall

ivall commented Nov 23, 2026

Copy link
Copy Markdown
Collaborator

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!

kacper-serewis pushed a commit to kacper-serewis/xcl that referenced this pull request Nov 24, 2026
Only ds_write_addtid_b32 / ds_read_addtid_b32 checked the GDS bit (xcl-dev#79).
Every other DS instruction with GDS=1 (plain and read2/write2 forms,
d16 and 8/16-bit forms, wrxchg2, the read-modify-write atomics) was
translated as an access to the group's LDS (xcl_lds): it overwrote the
title's groupshared data, read LDS instead of the global data share,
and nothing was recorded as unsupported.

The GDS check now runs for every DS instruction that reaches LDS
memory, after the "LDS outside compute" check, so the ADDTID forms
behave exactly as before. ds_swizzle_b32 / ds_bpermute_b32 use no
memory and are left as they were.

ds_gds_plain_forms_are_unsupported translates DS_ADD_U32, DS_WRITE_B32
and DS_READ_B32 with GDS=1; before the change none was recorded as
unsupported and each declared groupshared xcl_lds.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
(cherry picked from commit e642921)
(cherry picked from commit 42ab6021e76a5a49cac8dbf3c82c3616e98cc782)
CalvyPZ pushed a commit to CalvyPZ/xcl that referenced this pull request Nov 24, 2026
Only ds_write_addtid_b32 / ds_read_addtid_b32 checked the GDS bit (xcl-dev#79).
Every other DS instruction with GDS=1 (plain and read2/write2 forms,
d16 and 8/16-bit forms, wrxchg2, the read-modify-write atomics) was
translated as an access to the group's LDS (xcl_lds): it overwrote the
title's groupshared data, read LDS instead of the global data share,
and nothing was recorded as unsupported.

The GDS check now runs for every DS instruction that reaches LDS
memory, after the "LDS outside compute" check, so the ADDTID forms
behave exactly as before. ds_swizzle_b32 / ds_bpermute_b32 use no
memory and are left as they were.

ds_gds_plain_forms_are_unsupported translates DS_ADD_U32, DS_WRITE_B32
and DS_READ_B32 with GDS=1; before the change none was recorded as
unsupported and each declared groupshared xcl_lds.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
rootw0rm pushed a commit to rootw0rm/xcl that referenced this pull request Nov 27, 2026
…nd backend

1d split 1 of 2 (honest split: route halves stay under the line budget).
Device frame-clock slots route on Vulkan objects only: xcl-dev#78
SetFrameIntervalX, xcl-dev#79 ScheduleFrameEventX (with ancillary handle routing),
xcl-dev#80 WaitFrameEventX, xcl-dev#81 GetFrameStatisticsX — thin adapters over the Linux
twin (d3d12x_frame_linux). register_ancillary remembers the schedule block's
handles per type (E_INVALIDARG past the 63-handle cap, like Windows; Linux
trusts the block — readable() is windows-only); the clock thread signals
each with kernelx SetEvent at fire. Unscheduling clears. Null device keeps
logging stubs: no behavior change while XCL_VULKAN_BACKEND is unset. Queue
xcl-dev#30 PresentX + the real present follow in 1d(ii).

Failing-first: the routing test failed pre-fix (E0599 no VulkanQueue;
then E_FAIL at xcl-dev#81 with PresentX still stubbed); passes now (slots +
ancillary-signal asserts, serialised on CLOCK_SERIAL with the twin's tests).
Gates: check -p xcl --tests EXIT 0 (40 pre-existing warnings, none new);
check --workspace EXIT 0; lib 794 passed/0 failed/1 ignored (+1 new).
Title e2e + retail controls run at 1d(ii).
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.

3 participants