fix(agc): do not wait for a storage image's own stamped writes before flushing it #12070
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/12070"
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 imellag on 2026-10-27T18:41:04Z.
What
StorageTexture::FlushPendingsyncs when an unfinished batch writes the flushed range (#6364,9fffceaa9a): a writer that stamps guest memory only when its batch completes (an address-based dispatch) must have its marks land before the write-back decides which 64 KiB blocks to keep. When the writer is in the open batch, that is a fullRecorder::Sync.Some writers need no such wait: storage image write-backs (
writeBackLayers,writeBackWindows) callGuestMemory::MarkWrittenfor what they store while they are recorded, and a unit shadow publish copies bytes those write-backs already stamped. The next write-back of the same range is recorded after them in the same queue, so it lands after them on the GPU anyway. Today the flush still waits for them. Example: an image is written back at one label, written again by a dispatch, then flushed again at the next label; the second flush finds the first one's publish in the open batch and drains the queue.Recorder::NoteStampedWritesnotes such ranges likeNotePendingWritesand also keeps their write notes in the batch (stampedNotes). The two write-back paths andrecordCopiesin UnitShadow.cpp note their writes this way. The staged publish (the copy into a host buffer that writes guest memory at completion) does not.FlushPendingkeeps the stamped notes that flush recorded (the image's write-backs and its publish), fromRecorder::StampedNotesSince, in the image'sflushNotes(the last 32). A flush that stores several images keeps none, so no image takes another's notes.flushNotesto the existingownNotesexception of #9685, so it applies only where that one does: the flush stores a single image and that image has a host import. OtherwiseownNotesis cleared as onmain. Any other writer over the range (another image's write-back or publish, a dispatch, draw, fill, label, CPU-resolved copy, address-based lease) still makes the flush wait, and CPU readers still sync on these writes through the pending-write snapshot as before.tests/execution/StorageFlushOrdering.cppgains a stored-again case: images are stored, written again by a dispatch and flushed again in the same open batch, and the newer texels must land. With one image and a host import the second flush must not submit the open batch. It must wait with two adjacent images flushed together, without a host import, when another stamped write that is not the image's own (noted withNoteStampedWritesover the image) is in the open batch, or when the image is flushed alone after a joint flush with its neighbour. A second registration,agc_driver_storage_flush_ordering_no_import, runs the stored-again cases withAPS5_NO_HOST_IMPORT=1.mainfails the one-image case (it waits), the first head of this PR failed the two-image case, the second head failed the unrelated stamped write case and the third the alone-after-joint case (they did not wait), the current head passes all of them. The two existing cases (writer in flight, writer in the open batch) still pass.Overlaps:
FlushPendingand in this test. #8887 merged on 2026-11-02 and this branch contains it (mainmerge41f3e3c20e).recordCopieswith a write kind (ShadowPublishWrite) and conflicts with this PR inRecorder.hpp,UnitShadow.cpp, the AGCCMakeLists.txtand the AGC debt file. Order agreed with ee6aba54 on #6186 (2026-10-31): this PR first, then #6186 rebases onto it and carries the stamped flag through its write kind. This PR does not need #6186, so it is not in Depends on.writeBackWindows' imported pieces) is noted as stamped here too.Tested
No performance claim:
maincannot run titles or the AGC execution tests on macOS yet, and I have no other platform for amain-vs-change capture.@chitters2004 measured it on GTA V (PPSA04263, RTX 3080, Windows,
mainplus open GTA performance PRs, comment): the committerRecorder::SyncfromFlushPendingwent from 2.24 per frame (6.87 ms per frame) to 0, and every wait it removed came from the flushed image's own write-back notes.Current head
7d6f6c27cf:maind4efd8b82emerged in. One conflict, inRecorder.hpp:mainaddedReachValueandNotePendingReachnext to this PR'sNoteStampedWrites; both are kept. Reach notes are never stamped, so a flush still waits for them. macOS 27.2, Apple M4 Pro, MoltenVK 1.4.2, x86_64 Release under Rosetta 2, now on plainmain(its AGC test targets build on macOS):ctest -R '^agc_driver_storage_flush_ordering'withANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation.main: 1 of 1 passes; this head: 2 of 2 (storage flush ordering tests passed,storage flush ordering stored-again tests passed). NoVUID-and no missing-layer line in either log.Previous head
a8306d56f5:41f3e3c20emergedmain88e804b0a7with #8887 (combined results in this comment),2b211c7231mergedmain5b1d381d5a, anda8306d56f5fixes the test's expectation on hosts that compare host imports instead of watching them (details). The runs below are of the earlier heads.Head
e7e78cff0e, rebased ontomain98ddd9c179. One conflict, in the AGCCMakeLists.txt:mainregistersagc_driver_registration_prepare_budgetwhere this PR registersagc_driver_storage_flush_ordering_no_import; both are kept. The other files merged without conflicts, and what this PR builds on is unchanged onmain:noteWriteandNotePendingWritesstill give each range its own write note, andPendingWriterSerialwithownNotesstill skips a write by its note. With #8887's head1f15e200f7the only conflict is inStorageFlushOrdering.cpp, where both add cases.macOS 27.2, Apple M4 Pro, MoltenVK 1.4.2 (Vulkan SDK 1.4.363.0), x86_64 Release under Rosetta. Support branch, not
main: fork branchsupport/macos-boot-1030(6747733e89) =main98ddd9c179+ only the open macOS PRs #11447 #11554 #10552 #7631 #7804 #4630 and #13220 (the duplicatewrite_watchtest registration that stopsmain's CMake on macOS), plus one local line that readsenvironthrough_NSGetEnviron()inHostReportSources.cpp(maindoesn't compile it on macOS; no open PR covers it yet). The conflicts of #11554, #10552, #7631, #7804 and #4630 withmainare resolved in the merge commits. Change: fork branchsupport/macos-boot-1030-pr12070(f426fc662b) = that branch + the four commits of this PR.Focused tests on both with
ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation VK_LOADER_DEBUG=layer,ctest -R 'storage_flush_ordering|linear_readback_label|linear_target|agc_driver_storage_(cache_budget|one_slice_alias|read_during_idle_store|write_back)|storage_cache_retained|depth_storage_reuse|flip_stores_small' -V:agc_driver_storage_flush_ordering_no_import. Bothstorage_flush_orderingregistrations pass (storage flush ordering tests passed,storage flush ordering stored-again tests passed);VK_LAYER_KHRONOS_validationas enabled byVK_INSTANCE_LAYERS, there is nowas not found but was requested by env var VK_INSTANCE_LAYERS, and noVUID-line.The 10 failures of the previous run (the "two different device resolvers" abort) are gone: #11705 has merged. Logs attached.
Previous head
3b3cd7377f(support branchsupport/macos-boot-1027,maind13b3d7c55): the same tests failed the same 10 tests on both sides for the resolver abort and passed otherwise, bothstorage_flush_orderingregistrations passed on the change, noVUID-. God of War (PPSA28997) ran through the Cyclops fight on the second head with no crash or device loss; not rerun since.python3 tools/check_conventions.py --base upstream/main(98ddd9c179): passed.tools/pr_overlap.py: conflicting lines only with #8887 (StorageFlushOrdering.cpp).Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-27T18:58:34Z.
Review: CHANGES_REQUESTED
I reviewed the recorder changes and the new ordering test, and I agree with the concern already raised by the collaborator:
PendingUnstampedWriterSerialskips every stamped note beforeFlushPendingcan apply the existingownNotesexception, which is deliberately restricted to a single image with an existing host import. The new test covers a repeated store for one image, but not multiple flushed images or an image without a host import. Please explain why the #9685 restriction does not apply to those stamped writes, or constrain the skip to the same safe cases and add the requested multi-image/no-import regression case. I am not treating the current test as evidence for those cases.The performance report also does not use the repository
mainbaseline: it names a custom tree containing open macOS boot PRs and #11705. Please rerun the matched capture against currentmainand this exact change, and refresh the attached digest/traces as requested by the performance-report check. Finally, coordinate the same-line/test overlap with open #8887 and record the agreed ordering inDepends onper CONTRIBUTING; the overlap section currently says either PR may land second while the checklist saysnone.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-27T19:32:38Z.
Review: CHANGES_REQUESTED
Re-reviewed exact head 156bbaaaba0ebdf4f647df103377874358c38b29. The new guard and the no-import/multi-image regression cases address the broad skip outside the existing single-image, host-import case. I found three remaining blockers:
When ownStoresSkipped is true, PendingUnstampedWriterSerial ignores every overlapping note in batch.stampedNotes, not only this flush's ownNotes. NoteStampedWrites is used both for storage write-backs and UnitShadow::recordCopies. The single-image/host-import guard does not establish that every overlapping stamped note belongs to the image being flushed; a pending unit-shadow publish or another overlapping stamped writer can still be skipped. Please narrow the exception to the flush's own writes, or document the invariant that rules out unrelated stamped writers and add a regression with an unrelated stamped publish overlapping a single imported image.
The current heads of #8887 and #6186 both conflict with this head in shared AGC code. Pairwise merge-tree reports conflicts for #8887 in Recorder.hpp, Recorder.cpp, Texture.cpp and StorageFlushOrdering.cpp; for #6186 it reports conflicts in CMakeLists.txt, Recorder.hpp, UnitShadow.cpp and the debt file. The PR describes these overlaps but still says Depends on: none. CONTRIBUTING requires agreement on order and a declared dependency for same-line overlaps. Please coordinate and declare the agreed order. I checked #11694 as well; its current head merges cleanly with this PR, so I do not see a required ordering there.
The updated report includes matched traces and digests, but its baseline is e5d3b0097f from a custom tree with macOS boot PRs and #11705, rather than current upstream main
d13b3d7c55. The perf contribution rule requires a current-main/change comparison on the same machine and scene. Please provide that comparison on a supported platform or remove the performance claim and label.The current-main merge preview for this head is clean. I am requesting these specific corrections; this is not an approval of the performance or ordering claims.
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-28T10:31:43Z.
Review: DISMISSED
Thanks for narrowing the skip to the image's own notes. One ownership problem remains, confirmed in the source (same point @mashingaan raised):
core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp:4319-4328:StampedNotesSince(firstNote)returns every stamped note recorded during the whole flush, and the same vector is appended toflushNotesof every texture inflush. After a joint A+B flush, A'sflushNotescontain B's write-back/publish notes. A later flush of A alone with a host import adds them toownNotes(line 4253-4254), so B's write over an overlapping range is treated as A's own and the flush does not wait. Keep per-texture notes (collect them around each texture's own write-back, and decide how a shared unit-shadow publish is attributed), or only recordflushNoteswhen the flush stored a single image.tests/execution/StorageFlushOrdering.cpp: add the sequence joint A+B flush, then A dirtied and flushed alone with a host import, with B's range overlapping A's flush range. It must wait. The current "unrelated" case notes the foreign write after the first flush, so it does not cover this.FlushPendingand in this test will conflict).perflabel asks for themainvs change summary lines andtools/trace_digest.pyoutput (or drop the label/perf framing if this is a correctness-only change, as the body says "No performance claim").Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-29T06:18:21Z.
Review: CHANGES_REQUESTED
Re-checked — changes requested
The latest head
3b3cd7377fa40e6d98828bfcbf877feca04fe96aaddresses the stamped-note ownership blocker: only single-image flushes retain their own notes, while multi-image flushes retain none, and the author added the joint A+B then single-A regression. The author also removed the performance claim and recordsDepends on: #8887; I verified #8887 is still open.One integration blocker remains. A pairwise merge preview with open #6186 still conflicts in
CMakeLists.txt,Recorder.hpp,UnitShadow.cpp, and the AGC debt file. The #6186 author has not recorded an agreed landing order, and this PR does not list it as a dependency. Please coordinate that order and update the checklist/branch accordingly. This branch is also 1,367 commits behind currentmain2960e9a6e7e1fc99c4ed180c71495b5eb83464c7; five touched paths changed on main since its base, so please integrate current main and rerun the focused storage-flush ordering tests after resolving the stack.The author reports both storage-flush CTest registrations passing on the updated head in a support branch; I did not run GPU tests locally. The performance comparison has been removed, so I am not requiring a performance report.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-14T06:54:34Z.
Review: APPROVED
Reviewed — looks good
The change tracks stamped writes created by a single-image flush and exempts those notes from the next eligible wait; I found no concrete correctness defect in the inspected code.
What I ran
Reviewed head
7d6f6c27cf18c5171220cb223acfd0646e4aa464. No commands or tests were run by me; test results below are author-reported in the PR description.Results
Findings
Blocking
None.
Non-blocking
None.
Sources
Reviewed changed code in
Recorder.hpp,Texture.hpp,Recorder.cpp,Texture.cpp,UnitShadow.cpp,agc_driver_storage_flush_ordering_tests.cmake, andStorageFlushOrdering.cppat the pinned head.Not verified
I did not run tests, build, or convention checks. Author-reported macOS focused test results and Windows performance measurements were not independently verified.
Texture.cppwas read through the repository reader because its full text was excluded from the review folder;review/files.jsonwas not available from the reader, so the complete exclusion inventory could not be confirmed. Other repository files and behavior outside the targeted ranges were not reviewed.To get this to a good state
Nothing is required.