feat(shader): implement global_load_dword_addtid #530

Merged
DotDebian merged 1 commit from upstream-pr/530 into main 2026-10-04 21:10:42 +00:00
DotDebian commented 2026-10-04 15:10:15 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by DotDebian on 2026-10-04T15:10:15Z.


What

Implements global_load_dword_addtid (FLAT opcode 0x16, global segment), which was rejected as FLAT opcode is not supported.

  • Address per lane: SGPR[saddr] (64-bit) + sign-extended 12-bit offset + lane * 4; one dword is loaded into vdst for each lane active in EXEC. The instruction has no vaddr.
  • The lane is the same LaneId that ds_read_addtid_b32 already uses.
  • Rejected with a specific error: the opcode outside the global segment, and a base that is not an SGPR pair (off, VCC). The off form would read from a null base.
  • tools/progress.py is unchanged: the new enum name maps to GLOBAL_LOAD_DWORD_ADDTID by itself.

global_store_dword_addtid is not included: main still rejects stores through global addresses, which #390 adds. It can follow once that lands.

Sources: encoding from LLVM (FLATInstructions.td, test/MC/AMDGPU/gfx1030_new.s); semantics from AMD's rocjitsu emulator (ROCm/rocm-systems, emulation/rocjitsu, generated rdna2/flat_exec.cpp, GlobalLoadDwordAddtidFlat).

Tested

Windows 11, MinGW-w64 GCC 15.2.0, NVIDIA RTX 5080 (subgroup size 32). No title.

  • New agc_driver_global_load_addtid (tests/execution/GlobalLoadAddtid.cpp): a compute shader reports its lane with v_mbcnt_lo/hi_u32_b32 and loads with a positive offset, a negative offset and under a partial EXEC mask; run as wave32 and wave64 with 32, 64 and 128 threads. It also checks the two rejections. The expected values use the lane the shader reports, so the test does not assume a host lane order.
  • The test fails on main (FLAT opcode is not supported) and passes with this change. Scaling the lane by 8 instead of 4 makes it fail.
  • Full ctest: 184/184 passed.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none. Touches the same files as #491, #495 and #506 (flat and global atomics, cache bits) and #390; trial merges with each are clean.
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4735367742 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/530). Originally posted by [DotDebian](https://github.com/DotDebian) on 2026-10-04T15:10:15Z. --- ### What Implements `global_load_dword_addtid` (FLAT opcode `0x16`, global segment), which was rejected as `FLAT opcode is not supported`. - Address per lane: `SGPR[saddr] (64-bit) + sign-extended 12-bit offset + lane * 4`; one dword is loaded into `vdst` for each lane active in EXEC. The instruction has no `vaddr`. - The lane is the same `LaneId` that `ds_read_addtid_b32` already uses. - Rejected with a specific error: the opcode outside the global segment, and a base that is not an SGPR pair (`off`, VCC). The `off` form would read from a null base. - `tools/progress.py` is unchanged: the new enum name maps to `GLOBAL_LOAD_DWORD_ADDTID` by itself. `global_store_dword_addtid` is not included: main still rejects stores through global addresses, which #390 adds. It can follow once that lands. Sources: encoding from LLVM (`FLATInstructions.td`, `test/MC/AMDGPU/gfx1030_new.s`); semantics from AMD's rocjitsu emulator (`ROCm/rocm-systems`, `emulation/rocjitsu`, generated `rdna2/flat_exec.cpp`, `GlobalLoadDwordAddtidFlat`). ### Tested Windows 11, MinGW-w64 GCC 15.2.0, NVIDIA RTX 5080 (subgroup size 32). No title. - New `agc_driver_global_load_addtid` (`tests/execution/GlobalLoadAddtid.cpp`): a compute shader reports its lane with `v_mbcnt_lo/hi_u32_b32` and loads with a positive offset, a negative offset and under a partial EXEC mask; run as wave32 and wave64 with 32, 64 and 128 threads. It also checks the two rejections. The expected values use the lane the shader reports, so the test does not assume a host lane order. - The test fails on main (`FLAT opcode is not supported`) and passes with this change. Scaling the lane by 8 instead of 4 makes it fail. - Full `ctest`: 184/184 passed. ### Checklist - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md#silent-stubs) - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none. Touches the same files as #491, #495 and #506 (flat and global atomics, cache bits) and #390; trial merges with each are clean. - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
github-actions[bot] commented 2026-10-04 15:10:37 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-04T15:10:37Z.


Progress report (2cf901b → a701cfb)

📈 GPU shader instructions: 80.36% (+0.09%, +1 implemented instructions)

✅ 1 implemented
Encoding Name
GLOBAL GLOBAL_LOAD_DWORD_ADDTID
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5981423346 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/530#issuecomment-5981423346). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-04T15:10:37Z. --- <!-- progress-report --> ### Progress report (2cf901b → a701cfb) 📈 **GPU shader instructions**: 80.36% (+0.09%, +1 implemented instructions) <details> <summary>✅ 1 implemented</summary> | Encoding | Name | | - | - | | GLOBAL | `GLOBAL_LOAD_DWORD_ADDTID` | </details>
oneandonlydean commented 2026-10-04 21:08:20 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-04T21:08:20Z.


Thanks. Checked against AMD's RDNA2 ISA (opcode 22 in the global table, SGPR base plus lane ID as the offset) and the encoding against LLVM. The address is built the same way as the existing SADDR global loads with the lane times 4 in place of the VGPR offset, EXEC masks the load, and the test covers wave32, wave64 on a 32-lane host, a negative offset and a partial EXEC; it fails on main with FLAT opcode is not supported and passes here.

One note, not a blocker: LLVM only enables this instruction for targets with FeatureGFX10_BEncoding, which its gfx1013 model doesn't have (llvm-mc -mcpu=gfx1013 rejects it, gfx1030 accepts it). If that model is right for the PS5 GPU, no compiled shader will contain it, so it is harmless either way.

Ready to merge from my side.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5984398922 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/530#issuecomment-5984398922). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-04T21:08:20Z. --- Thanks. Checked against AMD's RDNA2 ISA (opcode 22 in the global table, SGPR base plus lane ID as the offset) and the encoding against LLVM. The address is built the same way as the existing SADDR global loads with the lane times 4 in place of the VGPR offset, EXEC masks the load, and the test covers wave32, wave64 on a 32-lane host, a negative offset and a partial EXEC; it fails on main with `FLAT opcode is not supported` and passes here. One note, not a blocker: LLVM only enables this instruction for targets with `FeatureGFX10_BEncoding`, which its gfx1013 model doesn't have (`llvm-mc -mcpu=gfx1013` rejects it, gfx1030 accepts it). If that model is right for the PS5 GPU, no compiled shader will contain it, so it is harmless either way. Ready to merge from my side.
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
boykopovar/AnyPS5!530
No description provided.