Skip to content

feat(shader): implement global_store_dword_addtid - #569

Merged
oneandonlydean merged 1 commit into
boykopovar:mainfrom
adriadam10:feat/global-store-addtid
Oct 5, 2026
Merged

oneandonlydean merged 1 commit into
boykopovar:mainfrom
adriadam10:feat/global-store-addtid

Conversation

@adriadam10

@adriadam10 adriadam10 commented Oct 4, 2026 •

Copy link
Copy Markdown
Collaborator

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

@github-actions

github-actions Bot commented Oct 4, 2026 •

Copy link
Copy Markdown

Progress report (3655c2a → d044384)

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

✅ 1 implemented
Encoding Name
GLOBAL GLOBAL_STORE_DWORD_ADDTID

@oneandonlydean

Copy link
Copy Markdown
Collaborator

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.

@github-actions github-actions Bot added the needs rebase Conflicts with main, rebase needed label Oct 5, 2026
Decode FLAT opcode 0x17 in the global segment and store the data VGPR of
each active lane at the SGPR pair base plus the signed offset plus four
times the lane id, sharing the address path of global_load_dword_addtid.

Co-Authored-By: Claude <noreply@anthropic.com>
@adriadam10
adriadam10 force-pushed the feat/global-store-addtid branch from f0730c0 to d044384 Compare October 5, 2026 06:44
@adriadam10

Copy link
Copy Markdown
Collaborator Author

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

Copy link
Copy Markdown
Collaborator

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.

@oneandonlydean
oneandonlydean merged commit 56acdef into boykopovar:main Oct 5, 2026
3 checks passed
@adriadam10
adriadam10 deleted the feat/global-store-addtid branch October 6, 2026 20:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agc libSceAgc* needs rebase Conflicts with main, rebase needed shader core/shader

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants