Skip to content

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

Closed
DotDebian wants to merge 1 commit into
boykopovar:mainfrom
DotDebian:feat/flat-global-stores
Closed

DotDebian wants to merge 1 commit into
boykopovar:mainfrom
DotDebian:feat/flat-global-stores

Conversation

@DotDebian

Copy link
Copy Markdown
Contributor

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 21cb567 (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

flat_store_* and global_store_* decoded and translated, but a store whose
segment is not scratch was refused when the SPIR-V was emitted ("writable
FLAT/GLOBAL addresses require GPU ownership tracking").

Such a store now goes through the BDA page table like a store through a
GPU-selected V#: the write lookup needs Write permission, which only a
writable registered range imported in place has, and the written page is
noted for the host to mark GPU-written. Byte and short stores, and dword
stores to an address that is not dword aligned, are stored byte by byte.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@oneandonlydean

Copy link
Copy Markdown
Collaborator

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

Copy link
Copy Markdown
Collaborator

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.

@github-actions github-actions Bot added the needs rebase Conflicts with main, rebase needed label Oct 5, 2026
oneandonlydean added a commit to oneandonlydean/AnyPS5 that referenced this pull request Oct 5, 2026
Conflicts resolved:
- libSceAudioPropagation/Export.cpp: upstream's boykopovar#482 + boykopovar#489 version taken; it is
  the same no-propagation model as astrobot's stand-in, with SourceRender and the
  handle-only UnregisterMaterial already in it.
- State.cpp (boykopovar#453): astrobot's resident depth model kept; it already skips the
  tests of an absent plane (boykopovar#453's test is on astrobot since e087a4f).
- Graphics.cpp, State.hpp, ShaderResources.cpp: astrobot's DepthTarget model kept
  (exportIndex, no DepthSurface.hpp), upstream's ThreadOwned include added.
- BdaResources.cpp: astrobot's form with boykopovar#390's message.
- VulkanDevice.cpp, Context.hpp, PacketExecution.cpp: both sides kept
  (calibrated timestamps, host query reset, GDS, memory budget; pipeline stats).
- Spirv: astrobot's split-wave rules first, then boykopovar#608's wave-mask ballot and
  boykopovar#587's host subgroup lane; astrobot's function LDS sizing and boykopovar#573's LDS lock
  both kept; conditionalDepth kept in the atomic update loops; upstream's
  buffer atomics (boykopovar#321 boykopovar#332 boykopovar#594) and 64-bit LDS atomics taken.
- TechnicalDebt.md: both sides, duplicate lines dropped.


Build fixes folded in: the upstream boykopovar#453 test block duplicated next to
astrobot's adapted copy removed; a lost closing brace after the host
query reset block restored; lookupLog() is a function since boykopovar#590; the
duplicate MUTEX_TYPE_ADAPTIVE constant (astrobot's 93b2d0e equals boykopovar#156)
removed; the ops boykopovar#596 drops removed from the masked-select list and the
BDA test message updated (the gate-batch-2 integ commits 559e4fab6 and
2ec968fb5).
@adriadam10

Copy link
Copy Markdown
Collaborator

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

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.

3 participants