fix(agc): order direct reads after copied writes #1359
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1359"
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 TibixDev on 2026-10-08T00:12:44Z.
What
Complete overlapping copied-buffer writebacks and CPU completion labels before fresh or reused shader resources read guest memory directly. Apply the same ordering to sampled/storage texture contents and compression metadata, before accepting current refresh/revalidation proofs. Disjoint work and GPU-only writes stay asynchronous; completion callbacks cannot recurse into these waits.
Rebased only this correctness change on
d146ec1b6. The old #1324/#1357 import stack is removed. Current import retirement, span/window behavior and storage refresh proofs are retained. The old TechnicalDebt addition belonged to the removed import stack and is absent from this diff.Depends on: none. Related #1157 is a separate DMA-wait optimization.
Tested
Fedora 44, GCC 16 Release, RX 6600/RADV and lavapipe. The standalone
agc_copied_direct_orderingtest passes on both with Vulkan core and synchronization validation and no validation diagnostics or skipped cases. It covers fresh/reused direct buffers, dispatch/draw copied-writer registries, overlapping completion labels, cached images, compression metadata, disjoint consumers and GPU-only no-wait behavior. Fixtures use the current typed-image binding ABI.With the same regression fixture and all production files restored to main
d146ec1b6, lavapipe fails withfresh direct consumer ran before copied write-back. Restoring this fix passes.Seven focused CTests pass: copied/direct ordering, graphics, guest memory, import unmap, storage upload lifetime/failure, and descriptor pool recycling (3.47 seconds total). Conventions and whitespace checks pass. No title attribution or Windows result is claimed for this change; full Linux/Windows CI and maintainer re-review remain.
Checklist
d146ec1b6; related work checked and unrelated prerequisites removed.Imported from boykopovar/AnyPS5. Originally posted by TibixDev on 2026-10-08T07:27:28Z.
Rebased on
eaa6ccea. Updated #1357 with #1051’s Linux writable-range check and owner-aware failure caching. This fixes the merge-build compile failure while retaining the byte budget and existing ordering/remap behavior.Fedora 44 Release:
agc_driver_graphics_tests,guest_memory_tests,agc_driver_recorder_tests,agc_recorder_kept_bytes_testsbuild; the targeted tests and contribution checks pass. Windows CI is pending.RADV and lavapipe:
--copied-direct-onlypass with core and synchronization validation; no validation errors.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-11T11:39:45Z.
Review: CHANGES_REQUESTED
Thanks for the work here. This can't be merged as is:
main, so nothing here can land before them.main(GuestBufferMemory.cpp,Texture.cpp,tests/Recorder.cpp,GuestAllocations.*,DirectMemory.cpp,tests/GuestMemory.cpp,TechnicalDebt.md). The conflicts are in the import/lifetime logic, so they need the author, not a mechanical rebase.TechnicalDebt.mdline is the last one of "### Functional"; everybody appends there, so move it away from the end of the section when you rebase.Please rebase once #1324 and #1357 are merged (or fold the stack so that each PR keeps one topic) and we will review it again.
Imported from boykopovar/AnyPS5. Originally posted by TibixDev on 2026-10-12T04:35:11Z.
@adriadam10 Rebased this fix alone onto
d146ec1b6; #1324 and #1357 are no longer prerequisites or included commits. Current import retirement/span logic and storage refresh proofs are preserved. The old TechnicalDebt addition was from the removed import stack and is no longer in this diff.The requested standalone Linux reproducer is now registered as
agc_copied_direct_ordering. With its fixture and unchanged main production files, lavapipe fails atfresh direct consumer ran before copied write-back. With the fix restored it passes on lavapipe and RX 6600/RADV, with core/synchronization validation and no diagnostics or skipped cases. Current typed-image ABI, fresh/reused buffers, both writer registries, cached images/metadata, labels, disjoint ranges and GPU-only no-wait behavior are covered.All seven focused integration CTests pass; conventions/whitespace checks pass. No fresh title attribution or Windows claim. Full platform CI and your re-review are still needed. AI-assisted implementation and validation.
Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-12T12:18:11Z.
Windows data point for this PR, with a title. Slay the Princess (PPSA24423) intermittently aborts with
AGC graphics: vertex buffer aliases the render target(#4369). The cause I found there: an indexed draw (explicitDRAW_INDEX, 6 32-bit indices, read in place from guest memory) occasionally reads garbage indices (0xff000000x 6) from its index buffer, so the vertex range becomes about 32 GiB; in other runs the same draws read valid indices (0 1 2 2 3 0), and no command in the stream writes that memory. That looks like an ordering problem between a write and a direct read, which is what this PR is about.Tree:
mainffa198407+ this PR (clean merge, head fromrefs/pull/1359), relinked, Windows 10, MinGW GCC Release, RTX 4080 SUPER, 150 s per run, 3 runs: no abort in any of the 3 runs (nowhat(), noFATAL; the logs end in normal[shadow] seed/ shader-cache lines). Earlier today on trees without this PR the same title aborted in 3 of the 4 runs I made (79 to 122 s in). I did not rerun the exact samemainas a control, so this is a suggestion, not a measurement of the effect: 0 of 3 against about 3 of 4 earlier. No claim about the image, and I did not run this PR's own tests on Windows.AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-12T12:32:40Z.
Correction to my comment above: I ran the control. Plain
mainffa198407(the same tree without this PR), relinked, same title, 3 runs of 150 s: no abort in any of them either (nowhat(), noFATAL). So the 0-of-3 result with this PR does not show an effect of the PR; the aborts I saw earlier today (3 of 4) came from trees on an oldermain(e7c70a2df, with #4408, #3840 and my diagnostic prints), and I do not know what removed them (a later change onmain, the diagnostic prints changing the timing, or chance). Please disregard my suggestion that this PR fixes the intermittent index data; I have no evidence for it.AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by Scramblrrrr on 2026-10-12T12:44:28Z.
Source-only older-stack Windows cross-test port prepared at https://github.com/Scramblrrrr/AnyPS5/tree/codex/first-light-copied-direct-ordering head6175e8551 (author retained from d799e5933). Resolved overlaps by preserving existing import build-floor bookkeeping, runtime table helper and depth retirement, with completion waits before those decisions. Conventions pass. Not built/staged and no native or 007 result for this port yet; current game still runs the preceding artifact. Will run the added ordering fixture after the quiet import-window comparison finishes. AI-assisted: yes (Codex).
Imported from boykopovar/AnyPS5. Originally posted by Scramblrrrr on 2026-10-12T13:00:26Z.
Native Windows cross-test of the isolated port6175e85512b0d8e76e930948f3635a0bab0825a9: copied/direct ordering, storage CPU snapshot, upload lifetime and upload failure all passed1.73s, no skips, RTX5070Ti/GCC15.2. Negative control restored only the three production source files to parentc4981fb10 while retaining your new fixture/shader: agc_copied_direct_ordering fails in0.35s with "fresh direct consumer ran before copied write-back" (CTest8). Production fix restored; rebuilding for the final restored check. Nothing staged into the game yet. SleglJan has reported a separate terrain readback/completion-label ordering case on share/007-hull-v1; coordinating comparison before combining changes. AI-assisted: yes (Codex).
Imported from boykopovar/AnyPS5. Originally posted by Scramblrrrr on 2026-10-12T14:22:51Z.
Combined Windows cross-test with #4017 now built: cfeae7db80d808fd33ad52827732fb922d15fb3c, https://github.com/Scramblrrrr/AnyPS5/tree/codex/first-light-retirement-ordering-cross-test . Your credited6175 port (canonical d799e5933f2c1c07510d117dde58ac73a19bfbc0) applies cleanly on the locked-retirement5dd integration. Native copied_direct_ordering, host_import_retirement, driver_host_import_at_map, storage_cpu_snapshot, storage_upload_lifetime/failure all pass2.05s; graphics, bda_device, tessellation pass5.32s. All nine execute without CTest skips. Separate production-only negative control for your ordering behavior is recorded above; no new causality claim from these combined checks.
Guarded warm007 run started with graphics SHA2560D503946D34725F16ECDAA41B581313ABE0021B5CC9CB2E0D063DFF192AE80AA. Same cache/config; no profile/capture or compute optimization disable. Goal is to distinguish copied-write ordering from the unsupported image-table operations that remain in the previous run. No gameplay/FPS success claim yet. AI-assisted: Codex.
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-13T09:14:13Z.
Review: APPROVED
Rebased onto current
main(conflicts were adjacency only: the test list inlibSceAgcDriver/CMakeLists.txtandGuestBufferMemory::UploadFinish, where I kept main'sStorageTexture::FlushPendingloop together with the new completion waits). Checked on RADV:agc_copied_direct_ordering,agc_storage_written_buffer_order,agc_host_import_*,agc_storage_*,agc_descriptor_pool_*,guest_memoryandagc_driver_graphicspass. The regression fixture failing without the fix is covered by the author's lavapipe run and @Scramblrrrr's Windows run (RTX 5070 Ti); merging once the full Build is green.Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-13T09:24:12Z.
Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.
main)core/libs/prx/libSceAgcDriver/tests/Recorder.cppL5755core/libs/prx/libSceAgcDriver/CMakeLists.txtImported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-13T10:47:09Z.
The full Build failed on Windows only in
agc_copied_direct_ordering(0xc0000135, DLL not found): the test was registered without thePATHprepend oflibcthat the other recorder tests get onWIN32, and withoutSKIP_RETURN_CODE 77for hosts with no Vulkan device. I rebased onto currentmain(clean) and added one commit with both. With the production changes revertedagc_copied_direct_orderingfails, with them it passes (RADV). Merging once the full Build is green.