fix(agc): note BDA-written pages at full address width and read back only the claimed ones #3175
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3175"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by Raghav314 on 2026-10-11T00:11:35Z.
What
A shader store through the BDA table records its 4 KiB page in the BDA fault buffer, and after the use the driver marks those pages written (
markWrittenPages), so the CPU sees what the GPU stored. Two problems with the record:address >> 12plus one), so a store above 16 TiB was recorded, and marked, as a page at another address. On Linux the guest's own image and libraries sit far above that: in PPSA36082 the BDA table has writable ranges up to0x562…(about 86 TiB). In my runs no shader stored there, but nothing kept one from doing it.Now:
ForEachWrittenRange(inBdaAbi.hpp) is the decoding, a plain function the tests call too. It checks every claim before it marks any.Tested
Linux, RTX 4090, NVIDIA 615.71.09, local run of the Linux CI job on main
69685646(SPIRV tools on): ctest 778/779. The failure,agc_driver_dcc_keys_first_write, fails the same way on main.agc_driver_bda_device: the decoding of an empty record, pages near the top of the address space and above 16 TiB, whole, first-page and last-page chunks, and bad slots or counts. The dword-write cases now check that exactly the stored pages are noted and that each chunk is claimed once, also when 64 workgroups store to the same page.agc_driver_flat_store(Linux) stores into write-watched guest blocks at 8 TiB and at 32 TiB, twice each, and checks that the stored block is stamped written and the other one is not. On main the 32 TiB block fails ("the stored block is not stamped as written") and the 8 TiB block passes. Where host imports are compared instead of write-watched (RADV), the case prints that and skips.I ran PPSA36082 on my machine (main
aa79dbdfplus local multisampled-target support it needs to get in game), standing still in the hub, 20 s of fps and 10 s ofperf, one run each in the same session. This was an earlier revision of the branch with 4096 slots; the changes since only shrink the fault buffer and check the record before marking:markWrittenPages, share of the queue workerThe worker stays about 97% busy in both, so the frame rate change is within noise; the time goes to the next hot spots (shader memory captures, allocation).
Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by Dextroid17 on 2026-10-11T00:27:56Z.
Review: COMMENTED
This is the most careful fix in the batch, and it is careful in the way that matters: both problems are stated with the evidence that makes them problems, and one of them is explicitly labelled as latent.
The 32-bit truncation is a real bug, and the write-up says how it was found and how narrow it is. A page number cut to 32 bits covers 16 TiB of 4 KiB pages, so a store above that was recorded and marked at a page number which wrapped — and PPSA36082's BDA table has writable ranges up to about 86 TiB. "In my runs no shader stored there, but nothing kept one from doing it" is the honest form of that finding, and the test makes it checkable rather than argued: on
mainthe 32 TiB block fails and the 8 TiB one passes, which draws the boundary exactly where the arithmetic puts it.The redesign removes the scan rather than shortening it, and the details are the ones that decide whether that holds. A slot holding a 128 KiB chunk, its number and a 32-page mask; claiming through a list the driver reads only up to its count; loading the mask before writing a bit so an already-noted page costs no atomic write; reading only the claimed slots and clearing only those; and refusing a writable range past 512 TiB at build time instead of recording its pages under the wrong chunk.
ForEachWrittenRangechecking every claim before it marks any is the part that makes the decode safe on a record that arrives from the guest.Refusing to claim the frame rate is the right call. 7.36% of the queue worker becoming 0.24%, with the frame rate inside noise and the author saying so and pointing at the next hot spots, is more useful than a figure that would not survive a second run — and the discrimination at 8 and 32 TiB is where the argument actually lives. Noting that the one failing ctest fails identically on
main, and that the profile predates the final slot layout, is the same discipline.The race the redesign has to survive is covered, and it is worth pointing at. A slot is claimed by an atomic compare-exchange on the chunk key — zero to the key, first writer wins — with the count raised by an atomic add and the page bit set through an atomic load-and-or, which is also what lets an already-noted page cost no atomic write. The 64-workgroup case against one page asserts the claimed count is exactly the number of chunks rather than merely non-zero, so the assertion is as strong as the mechanism. That is the part of this change I would point a future reader at first.
Written with AI assistance.
Imported from boykopovar/AnyPS5. Originally posted by Silverash-i8 on 2026-10-11T01:31:52Z.
Windows run, since the PR was tested on Linux: Windows 11, WinLibs GCC 15.2.0 r7, Release, head
f0f02ccamerged ontomaind31b57a4(alone, and in a batch with #3039, #3134 and #3194).agc_driver_bda_deviceandagc_driver_bda_span_readspass, butagc_driver_flat_storefails on both GPUs here (RTX 5060 Laptop and the Arrow Lake iGPU), in the new_WIN32branch ofRunStampedBlocks:So on Windows the write-watched
GuestArenablock isn't imported in place: the driver serves it through a mirror and puts it in the BDA table read-only, the firstDispatchstore into it is refused, and theCollectWritesthat follows returns 0. The same test passes onmainhere, where the watched block doesn't exist. The rest of theagc_*suite shows nothing else new from this PR on either GPU.If a GPU store into a write-watched block can't happen on Windows by design, maybe the stamped-block case belongs in the Linux-only branch like the fixed-address blocks, or the Windows branch could expect the refusal instead. I haven't changed anything on your branch.
AI-assisted (Claude Code); I ran this on my machine.
Imported from boykopovar/AnyPS5. Originally posted by Raghav314 on 2026-10-11T01:36:55Z.
@Silverash-i8 thanks for testing on Windows. On Windows the arena block gets mirrored instead of imported in place, so it ends up read-only in the BDA table and the store never lands, which is why nothing gets stamped. That's just how Windows handles arena memory right now, so I moved the watched-block case to Linux only, next to the fixed-address blocks (8 TiB and 32 TiB). The Windows side of the test is the same as main again.
LLM assistance used.
Imported from boykopovar/AnyPS5. Originally posted by Silverash-i8 on 2026-10-11T02:00:30Z.
@Raghav314 confirmed on the new head
bb6ac3e2(merged ontomaind31b57a4, same Windows 11 / WinLibs GCC 15.2.0 setup):agc_driver_flat_store,agc_driver_bda_device,agc_driver_bda_span_readsandagc_driver_dcc_keys_first_writeall pass on both the RTX 5060 and the Arrow Lake iGPU.AI-assisted (Claude Code); I ran this on my machine.
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-11T07:06:13Z.
Review: CHANGES_REQUESTED
Thanks, the design looks right to me: the decoding validates every claim before marking, the slot/list bounds hold, and
agc_driver_bda_devicepasses here.One problem with the new
agc_driver_flat_storecase (tests/execution/FlatStore.cpp,RunStampedBlocks):flat store: the watched guest blocks are not collected. After the firstDispatchthe mmap'd block is no longer write-watched (GuestWriteWatchCoversreturns false), because on that driver host imports resolve write protection ([write-watch] host imports resolve write protection: yes ... imported ranges are compared). SoCollectWritesreturns 0 and the test asserts instead of skipping. It passes on lavapipe and, per your run, on NVIDIA, where the imports stay watched.GuestMemory::Watchedafter the warm-upDispatch, and skip that case when it is false), or check the stamping through the compared-range path as well, so the test doesn't depend on the driver.Rest of the checks (build, other libSceAgc/AgcDriver tests) green on RADV.
Imported from boykopovar/AnyPS5. Originally posted by Raghav314 on 2026-10-11T07:28:15Z.
@adriadam10 thanks, good catch. I went with your first option: after the warm-up
Dispatch, the stamped-block case checksGuestMemory::Watchedover both blocks and skips with a message if the import isn't watched, same as the snapshot-reuse test inRecorder.cppdoes. On NVIDIA it still runs both the 8 TiB and 32 TiB blocks. I don't have an AMD card, so I couldn't run it on RADV myself.Also rebased onto current main (
69685646); the full Linux CI job passes locally exceptagc_driver_dcc_keys_first_write, which fails on main too.LLM assistance used.
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-11T08:00:04Z.
Review: APPROVED
Checked the decoding (
ForEachWrittenRangevalidates every claim before marking), the slot/list bounds and the 512 TiB limit on writable ranges; build +agc_driver_bda_device,agc_driver_bda_span_readsandagc_driver_flat_storepass on RADV here (flat_store skips the stamped-block case there, as intended), and the new decode tests don't compile without the change. Windows run by @Silverash-i8 and the NVIDIA run by the author cover the rest. The RADV skip from my earlier review is addressed; merging.