feat(shader): implement global_store_dword_addtid #569

Merged
adriadam10 merged 1 commit from upstream-pr/569 into main 2026-10-05 07:27:37 +00:00
adriadam10 commented 2026-10-04 22:10:42 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-04T22:10:42Z.


What

Implements global_store_dword_addtid (FLAT opcode 0x17, global segment), the store half of global_load_dword_addtid (#530). Each active lane stores its data VGPR at saddr + offset + lane * 4. It reuses the load's decode checks (global segment only, SGPR pair base) and its address path. The two now share globalAddtid(inst, write), like dsAddtid.

Encoding: the RDNA2 ISA lists it as GLOBAL opcode 23. llvm-mc encodes it from gfx1030 on (dc5c....), but not for gfx1013, same as the load.

The store goes through the flat/global store path that #390 added (merged with #491 as be866e4).

Behaviour measured on HW (gfx1035, wave32 and wave64)

The oracle kernel runs the same instruction list as the test shader and reads back an 8 KiB window around the base. I measured:

  • tid is the lane in the wave, 0 to 63 in wave64.
  • The offset is signed 12-bit (-2048 and 2044 rows).
  • M0 is ignored. Stores with M0 = 0x40 and 0xffff land at the same address as with M0 = 0, unlike ds_write_addtid_b32.
  • EXEC masks the store.
  • Nothing outside the stored dwords changes.
    HW matched the model on every dword (184 written in wave32, 368 in wave64), and the test's expected memory comes from that same model.

Tested

Linux (CachyOS), RADV and lavapipe. New agc_driver_global_store_addtid test: six stores (offsets 0, -256, -1024, 512 masked by EXEC, -2048, 2044; M0 0, 0x40 and 0xffff) in wave32, wave64 native and wave64 split (ComputeTarget(32)). After each dispatch it compares the whole 64 KiB guest block. It also checks the three decode refusals (flat segment, scratch segment, no SGPR base).
The test fails without the fix. I checked this with mutations: lane ignored in the address, EXEC ignored, data read from vdst, M0 added to the address, and wrong refusal text all fail. Like agc_driver_lds_addtid, the dispatch part skips when subgroups are narrower than a wave (lavapipe, 8 lanes), because LaneId is the subgroup invocation there. The refusals still run on lavapipe.
Release build with full ctest. Failing locally, all also failing on main without this PR, on RADV:

  • agc_driver_pixel_helper_lanes
  • agc_driver_vop3_carry_out
  • agc_driver_global_load_addtid: "wave32 128 threads thread 32 reports lane 32", from RADV's 64-lane subgroup.

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
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4738003932 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/569). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-04T22:10:42Z. --- ### What Implements `global_store_dword_addtid` (FLAT opcode 0x17, global segment), the store half of `global_load_dword_addtid` (#530). Each active lane stores its data VGPR at `saddr + offset + lane * 4`. It reuses the load's decode checks (global segment only, SGPR pair base) and its address path. The two now share `globalAddtid(inst, write)`, like `dsAddtid`. Encoding: the RDNA2 ISA lists it as GLOBAL opcode 23. llvm-mc encodes it from gfx1030 on (`dc5c....`), but not for gfx1013, same as the load. The store goes through the flat/global store path that #390 added (merged with #491 as be866e4). #### Behaviour measured on HW (gfx1035, wave32 and wave64) The oracle kernel runs the same instruction list as the test shader and reads back an 8 KiB window around the base. I measured: - tid is the lane in the wave, 0 to 63 in wave64. - The offset is signed 12-bit (-2048 and 2044 rows). - M0 is ignored. Stores with M0 = 0x40 and 0xffff land at the same address as with M0 = 0, unlike `ds_write_addtid_b32`. - EXEC masks the store. - Nothing outside the stored dwords changes. HW matched the model on every dword (184 written in wave32, 368 in wave64), and the test's expected memory comes from that same model. ### Tested Linux (CachyOS), RADV and lavapipe. New `agc_driver_global_store_addtid` test: six stores (offsets 0, -256, -1024, 512 masked by EXEC, -2048, 2044; M0 0, 0x40 and 0xffff) in wave32, wave64 native and wave64 split (`ComputeTarget(32)`). After each dispatch it compares the whole 64 KiB guest block. It also checks the three decode refusals (flat segment, scratch segment, no SGPR base). The test fails without the fix. I checked this with mutations: lane ignored in the address, EXEC ignored, data read from `vdst`, M0 added to the address, and wrong refusal text all fail. Like `agc_driver_lds_addtid`, the dispatch part skips when subgroups are narrower than a wave (lavapipe, 8 lanes), because `LaneId` is the subgroup invocation there. The refusals still run on lavapipe. Release build with full ctest. Failing locally, all also failing on `main` without this PR, on RADV: - `agc_driver_pixel_helper_lanes` - `agc_driver_vop3_carry_out` - `agc_driver_global_load_addtid`: "wave32 128 threads thread 32 reports lane 32", from RADV's 64-lane subgroup. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [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 - [x] AI-assisted: yes
github-actions[bot] commented 2026-10-04 22:11:06 +00:00 (Migrated from github.com)

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


Progress report (3655c2a → d044384)

📈 GPU shader instructions: 95.88% (+0.08%, +1 implemented instructions)

✅ 1 implemented
Encoding Name
GLOBAL GLOBAL_STORE_DWORD_ADDTID
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5984985254 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/569#issuecomment-5984985254). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-04T22:11:06Z. --- <!-- progress-report --> ### Progress report (3655c2a → d044384) 📈 **GPU shader instructions**: 95.88% (+0.08%, +1 implemented instructions) <details> <summary>✅ 1 implemented</summary> | Encoding | Name | | - | - | | GLOBAL | `GLOBAL_STORE_DWORD_ADDTID` | </details>
oneandonlydean commented 2026-10-04 23:43:57 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-04T23:43:57Z.


Thanks. The first commit is #390's head unchanged (same patch), so I only reviewed the last one.

I disassembled the test shader with llvm-mc (gfx1030, since gfx1013 has no addtid encoding, as for #530): the six stores are opcode 0x17 with the offsets, M0 values and EXEC mask in the Stores table, the data is 0x101 * tid + 0x5100 xor the pattern, and none of the six ranges overlap, so Expected() checks every store separately. The store goes through the same StoreAddressU32 argument order that StoreAddress reads (data second to last, exec last), and the data VGPR comes from the DATA field because the opcode is now in isFlatStoreOpcode. The decode checks are shared with the load, and llvm-mc also rejects the flat and scratch segment words.

Order: this needs #390 first. #491 and #495 also carry #390 and change the same BDA files further (ResourceTracker.cpp, SpirvBda.hpp, SpirvBdaRead.cpp, plus RdnaOpcode.hpp), so whichever of them lands after this one needs a rebase. Once #390 is in, a rebase down to the last commit is all this needs.

agc_driver_global_store_addtid and agc_driver_flat_store pass here on NVIDIA with this head merged into current main, and both fail on main's code (the decoder refusal and the GPU ownership error). PPSA21564 has no addtid instructions, so this doesn't affect my runs. Ready to merge from my side after #390.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5985702180 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/569#issuecomment-5985702180). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-04T23:43:57Z. --- Thanks. The first commit is #390's head unchanged (same patch), so I only reviewed the last one. I disassembled the test shader with llvm-mc (gfx1030, since gfx1013 has no addtid encoding, as for #530): the six stores are opcode 0x17 with the offsets, M0 values and EXEC mask in the `Stores` table, the data is `0x101 * tid + 0x5100` xor the pattern, and none of the six ranges overlap, so `Expected()` checks every store separately. The store goes through the same `StoreAddressU32` argument order that `StoreAddress` reads (data second to last, exec last), and the data VGPR comes from the DATA field because the opcode is now in `isFlatStoreOpcode`. The decode checks are shared with the load, and llvm-mc also rejects the flat and scratch segment words. Order: this needs #390 first. #491 and #495 also carry #390 and change the same BDA files further (ResourceTracker.cpp, SpirvBda.hpp, SpirvBdaRead.cpp, plus RdnaOpcode.hpp), so whichever of them lands after this one needs a rebase. Once #390 is in, a rebase down to the last commit is all this needs. `agc_driver_global_store_addtid` and `agc_driver_flat_store` pass here on NVIDIA with this head merged into current main, and both fail on main's code (the decoder refusal and the GPU ownership error). PPSA21564 has no addtid instructions, so this doesn't affect my runs. Ready to merge from my side after #390.
adriadam10 commented 2026-10-05 06:44:03 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-05T06:44:03Z.


Rebased on current main. #390 landed with #491 (be866e4), so this branch is now only the global_store_dword_addtid commit (d044384); the cherry-picked #390 commit is gone and the description no longer says it is stacked. The rebase only resolved the RdnaOpcode.hpp enum next to the new flat atomics; the code is unchanged. agc_driver_global_store_addtid passes on RADV (lavapipe skips it, 8-lane subgroups) and the full Release ctest passes except agc_driver_pixel_helper_lanes and agc_driver_pixel_lds, which fail the same way on main here.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5989490880 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/569#issuecomment-5989490880). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-05T06:44:03Z. --- Rebased on current main. #390 landed with #491 (be866e4), so this branch is now only the `global_store_dword_addtid` commit (d044384); the cherry-picked #390 commit is gone and the description no longer says it is stacked. The rebase only resolved the `RdnaOpcode.hpp` enum next to the new flat atomics; the code is unchanged. `agc_driver_global_store_addtid` passes on RADV (lavapipe skips it, 8-lane subgroups) and the full Release ctest passes except `agc_driver_pixel_helper_lanes` and `agc_driver_pixel_lds`, which fail the same way on main here.
oneandonlydean commented 2026-10-05 07:26:35 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-05T07:26:35Z.


Thanks for the quick rebase. The branch is now only your addtid commit on main, and the range-diff against f0730c0 shows just the enum context: GlobalStoreDwordAddtid now follows the new flat atomic entries. I had tried the same replay here before your push, and the tree is identical to d044384. The full ctest passes with it, agc_driver_global_store_addtid included.

PPSA21564 has no global_store_dword_addtid in the 5,688 shaders I have dumped, so this doesn't need my PPSA21564 check. Ready to merge from my side once CI is green.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5990012682 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/569#issuecomment-5990012682). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-05T07:26:35Z. --- Thanks for the quick rebase. The branch is now only your addtid commit on main, and the range-diff against f0730c0 shows just the enum context: `GlobalStoreDwordAddtid` now follows the new flat atomic entries. I had tried the same replay here before your push, and the tree is identical to d044384. The full ctest passes with it, `agc_driver_global_store_addtid` included. PPSA21564 has no `global_store_dword_addtid` in the 5,688 shaders I have dumped, so this doesn't need my PPSA21564 check. Ready to merge from my side once CI is green.
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!569
No description provided.