feat(shader): store through flat and global addresses #390

Closed
DotDebian wants to merge 1 commit from upstream-pr/390 into main
DotDebian commented 2026-10-02 17:10:07 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by DotDebian on 2026-10-02T17:10:07Z.


What

flat_store_* and global_store_* (byte, short, dword, dwordx2/x3/x4) decode and translate on main, but a store whose segment is not scratch never reaches the GPU: AnalyzeProgramRequirements throws writable FLAT/GLOBAL addresses require GPU ownership tracking, and StoreAddress has no emitter for a guest address.

Since 21cb5676 (stores through GPU-selected V#s) the BDA page table has that tracking: a write lookup that needs Write permission, and a set of written pages the host marks GPU-written once the work completed. This PR sends FLAT and GLOBAL stores through it.

  • StoreAddress emits a Flat/Global store with the new EmitBdaStore, on the address the loads already form (GuestAddress: 64-bit vector address, or scalar base + vector offset, plus the immediate), under the instruction's EXEC bit.
  • A dword store to a dword-aligned address is one get_bda_write_pointer lookup and one store, the code EmitBdaWrite already had (now shared as EmitBdaStoreAt). Byte and short stores, and a dword store to an unaligned address, store each byte through its own lookup, so a store may straddle two ranges like the byte path of the loads. EmitBdaWrite itself (V# stores) is unchanged: an unaligned V# store still faults.
  • ResourceTracker sets bdaWrites for an address store, which is what defines the write lookup and note_bda_write.
  • The two host messages that named only GPU-selected descriptors now cover FLAT/GLOBAL stores too.

The rules of the write path are unchanged and apply as they are: a store lands only in a writable registered range the host imported in place; into a read-only range, a mirror or a copy it is refused and reported as a BDA fault (Permission).

Not part of this PR: the FLAT/GLOBAL atomics and global_store_dword_addtid (still FLAT opcode is not supported). They need this store path first.

Tested

Windows 11, MinGW-w64 GCC 15.2.0, NVIDIA GeForce RTX 5080 (32-wide subgroups), ctest from PowerShell: 109/109 pass.

New test agc_driver_flat_store (tests/execution/FlatStore.cpp): a 64-thread compute program runs on a real Vulkan device against a 64 KiB registered guest range, as wave32 and as wave64, and the whole first 8 KiB of the range are compared with a CPU reference. It covers global_store_dword with a scalar base and a vector offset, flat_store_dword and global_store_dword with a 64-bit vector address, negative immediates, global_store_byte, global_store_short, a dword store to an unaligned address, dwordx2/x3/x4, a global_load_dword of a dword stored by the same thread, and a store under v_cmpx_gt_u32 (threads outside EXEC must not store). A second range registered read-only takes the same program and must stay unchanged.

On main the test fails with ShaderRecompiler::Recompile: writable FLAT/GLOBAL addresses require GPU ownership tracking. With the EXEC gate removed from the new emitter it fails on the masked threads.

Not tested: Linux (the test allocates with std::aligned_alloc there, as tests/Recorder.cpp does, and has not been run on lavapipe or RADV), any title, stages other than compute, a host with 64-wide subgroups (wave64 ran as two lanes per invocation). The test only checks that the read-only range is unchanged; the fault itself is reported by the recorder on stderr (deferred write-back failed) and is not asserted.

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

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4719251229 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/390). Originally posted by [DotDebian](https://github.com/DotDebian) on 2026-10-02T17:10:07Z. --- ### What `flat_store_*` and `global_store_*` (byte, short, dword, dwordx2/x3/x4) decode and translate on `main`, but a store whose segment is not scratch never reaches the GPU: `AnalyzeProgramRequirements` throws `writable FLAT/GLOBAL addresses require GPU ownership tracking`, and `StoreAddress` has no emitter for a guest address. Since 21cb5676 (stores through GPU-selected V#s) the BDA page table has that tracking: a write lookup that needs `Write` permission, and a set of written pages the host marks GPU-written once the work completed. This PR sends FLAT and GLOBAL stores through it. - `StoreAddress` emits a `Flat`/`Global` store with the new `EmitBdaStore`, on the address the loads already form (`GuestAddress`: 64-bit vector address, or scalar base + vector offset, plus the immediate), under the instruction's EXEC bit. - A dword store to a dword-aligned address is one `get_bda_write_pointer` lookup and one store, the code `EmitBdaWrite` already had (now shared as `EmitBdaStoreAt`). Byte and short stores, and a dword store to an unaligned address, store each byte through its own lookup, so a store may straddle two ranges like the byte path of the loads. `EmitBdaWrite` itself (V# stores) is unchanged: an unaligned V# store still faults. - `ResourceTracker` sets `bdaWrites` for an address store, which is what defines the write lookup and `note_bda_write`. - The two host messages that named only GPU-selected descriptors now cover FLAT/GLOBAL stores too. The rules of the write path are unchanged and apply as they are: a store lands only in a writable registered range the host imported in place; into a read-only range, a mirror or a copy it is refused and reported as a BDA fault (`Permission`). Not part of this PR: the FLAT/GLOBAL atomics and `global_store_dword_addtid` (still `FLAT opcode is not supported`). They need this store path first. ### Tested Windows 11, MinGW-w64 GCC 15.2.0, NVIDIA GeForce RTX 5080 (32-wide subgroups), `ctest` from PowerShell: 109/109 pass. New test `agc_driver_flat_store` (`tests/execution/FlatStore.cpp`): a 64-thread compute program runs on a real Vulkan device against a 64 KiB registered guest range, as wave32 and as wave64, and the whole first 8 KiB of the range are compared with a CPU reference. It covers `global_store_dword` with a scalar base and a vector offset, `flat_store_dword` and `global_store_dword` with a 64-bit vector address, negative immediates, `global_store_byte`, `global_store_short`, a dword store to an unaligned address, `dwordx2`/`x3`/`x4`, a `global_load_dword` of a dword stored by the same thread, and a store under `v_cmpx_gt_u32` (threads outside EXEC must not store). A second range registered read-only takes the same program and must stay unchanged. On `main` the test fails with `ShaderRecompiler::Recompile: writable FLAT/GLOBAL addresses require GPU ownership tracking`. With the EXEC gate removed from the new emitter it fails on the masked threads. Not tested: Linux (the test allocates with `std::aligned_alloc` there, as `tests/Recorder.cpp` does, and has not been run on lavapipe or RADV), any title, stages other than compute, a host with 64-wide subgroups (wave64 ran as two lanes per invocation). The test only checks that the read-only range is unchanged; the fault itself is reported by the recorder on stderr (`deferred write-back failed`) and is not asserted. ### 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 - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
oneandonlydean commented 2026-10-04 22:38:00 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-04T22:38:00Z.


Thanks for this, and sorry it sat without a comment for a while. I reviewed it as part of #491, which carries this commit unchanged: flat and global stores go through the BDA write path, and read-only, unmapped and misaligned addresses are reported instead of written. agc_driver_flat_store passes on my NVIDIA machine on current main, and fails on main's code.

Since it adds a new guest write path, I'll run it (with #491 on top) through my PPSA21564 test runs and merge it first if they pass. The one red CI job on this head is Linux agc_driver_vopc_compare, the f16 compare flake on llvmpipe that every PR hit at the time, not this change.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5985219197 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/390#issuecomment-5985219197). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-04T22:38:00Z. --- Thanks for this, and sorry it sat without a comment for a while. I reviewed it as part of #491, which carries this commit unchanged: flat and global stores go through the BDA write path, and read-only, unmapped and misaligned addresses are reported instead of written. `agc_driver_flat_store` passes on my NVIDIA machine on current main, and fails on main's code. Since it adds a new guest write path, I'll run it (with #491 on top) through my PPSA21564 test runs and merge it first if they pass. The one red CI job on this head is Linux `agc_driver_vopc_compare`, the f16 compare flake on llvmpipe that every PR hit at the time, not this change.
oneandonlydean commented 2026-10-05 05:03:46 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-05T05:03:46Z.


Thanks for this one. #491 (adriadam10) carries your commit rebased onto current main as be866e4, the same patch with your authorship, and #491, #495 and #506 build on it. Merging this branch at 673401b and then #491 conflicts in ResourceTracker.cpp, SpirvBda.hpp and SpirvBdaRead.cpp, so to keep things moving I've merged #491, which brings in your commit as it is, and I'm closing this PR as included there.

I gated be866e4 on PPSA21564 together with #491, #495 and #506: no visual or FPS change, and the full ctest passes. If anything in your branch isn't in be866e4, let me know and we can follow up.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5988440018 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/390#issuecomment-5988440018). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-05T05:03:46Z. --- Thanks for this one. #491 (adriadam10) carries your commit rebased onto current main as be866e4, the same patch with your authorship, and #491, #495 and #506 build on it. Merging this branch at 673401b and then #491 conflicts in `ResourceTracker.cpp`, `SpirvBda.hpp` and `SpirvBdaRead.cpp`, so to keep things moving I've merged #491, which brings in your commit as it is, and I'm closing this PR as included there. I gated be866e4 on PPSA21564 together with #491, #495 and #506: no visual or FPS change, and the full ctest passes. If anything in your branch isn't in be866e4, let me know and we can follow up.
adriadam10 commented 2026-10-05 15:38:58 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-05T15:38:58Z.


@DotDebian heads-up on agc_driver_flat_store (your FlatStore.cpp, which landed on main through #491): it takes 83 s on main's Linux CI, against ctest's 120 s timeout. Cold on CI's lavapipe (Ubuntu Mesa 25.2.8, LLVM 20, no shader cache) it took 250 s here. The cost is LLVM compiling the BDA accesses, and the test compiles its kernel three times (wave32, wave64, read-only). One of my tests from the same family, flat_cache_bits, sat at 113 s on main and timed out on other people's PRs (#545 #593 #668 #672). This one is next in line.

I'm trimming my own ones the same way: #677 (fewer BDA ops), #688 and #689 (split by cost, opcodes and HW rows kept). Since this test came in through my PR, I'm happy to do the same for FlatStore unless you'd rather handle it yourself. Let me know.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5997796424 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/390#issuecomment-5997796424). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-05T15:38:58Z. --- @DotDebian heads-up on `agc_driver_flat_store` (your `FlatStore.cpp`, which landed on main through #491): it takes 83 s on main's Linux CI, against ctest's 120 s timeout. Cold on CI's lavapipe (Ubuntu Mesa 25.2.8, LLVM 20, no shader cache) it took 250 s here. The cost is LLVM compiling the BDA accesses, and the test compiles its kernel three times (wave32, wave64, read-only). One of my tests from the same family, `flat_cache_bits`, sat at 113 s on main and timed out on other people's PRs (#545 #593 #668 #672). This one is next in line. I'm trimming my own ones the same way: #677 (fewer BDA ops), #688 and #689 (split by cost, opcodes and HW rows kept). Since this test came in through my PR, I'm happy to do the same for `FlatStore` unless you'd rather handle it yourself. Let me know.

Pull request closed

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!390
No description provided.