fix(agc): hold small labels behind completions that store guest memory #11995
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/11995"
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 josealissonbr on 2026-10-27T15:57:41Z.
What
A small label (8 bytes or less) recorded on the GPU could become visible before guest memory that an earlier batch of the same queue still had to store on the CPU at its completion. A title that polls the label then reads that memory before the store lands. In PPSA99903 the stage floor and buildings were drawn with stale constants and geometry (#11562).
WriteLabelOnGpualready held a small label behind the completion of pending work when a copied writer was listed. Two other kinds of completion also change what the driver knows about guest memory and were not counted:BdaResources::markWrittenPages), so until then a CPU snapshot of those pages (constants, geometry) still counts as current;applyStoredSave).Neither stores guest memory itself; a title that sees the label before them gets its next reads served from stale driver state.
Recorder::OnCompletenow takes whether the completion updates guest state, and the recorder counts those completions until their batch finishes or is discarded, like the existing write-back completions. A completion updates guest state when its shader resources have copied writes (the write-back stores guest memory) or a BDA table that is not read-only (ShaderResources::UpdatesGuestStateAtCompletion), or when it applies a stored save. While any such completion is pending (Recorder::PendingGuestStateCompletions), a small label takes the existing held path (reason 5) instead of being recorded directly. The label line indocs/dev/debt/libSceAgcDriver.mdlists the new condition.agc_driver_indirect_thread_dimensionsnow expects reason 5 for the argument label written after a producer that stores through its BDA table; it fails onmain.agc_driver_alias_copy_labelasserts the reason that matches the pending completions (5 behind the image copy's stored save) instead of skipping when the label is held, and checks the copied bytes in both cases.Tested
Windows 11 Pro 26200, NVIDIA GeForce RTX 5070 (driver 616.64), MinGW GCC 15.2 Release build.
ae17955d2before merging currentmain: the floor and buildings draw correctly with no flicker, at 15-28 presents per second depending on the scene. Without it they flicker;APS5_SYNC_DRAWS=1orAPS5_CPU_STORES=1hid the bug at about 4 and 2-3 presents per second. A replay of an earlier frame capture of the stage withagc_frame_replayis also correct with it. Not retested in game after the merge with currentmain.40adf0a901(mainbb04a4f1eamerged), after review: the 65 tests matchingindirect_thread|label|completion|copied_writ|write_back|writeback|agc_recorder|agc_driver_bda|agc_storage|agc_driver_storage|store_at|fenceran on this head and onmainbb04a4f1eawithANYPS5_REQUIRE_VULKAN=1,ANYPS5_NO_SHADER_CACHE=1andVK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation,ctest -R <pattern> -j 4 -V: 65 of 65 passed on both, none skipped, noVUID-line and nowas not found but was requested by env var VK_INSTANCE_LAYERSin either log.agc_driver_alias_copy_labelprints "the label after the image copy was stored at the reap" and passes. The full suite on48c61f5289plus the same merge passed 3027 of 3029:agc_driver_alias_copy_labeltimed out waiting for the held label (fixed in40adf0a901, which only changes that test) andguest_freebsd_clocksexits with 0xc0000409, as it does onmainbb04a4f1eaon this machine.mainmerged: the full CTest suite withANYPS5_REQUIRE_VULKAN=1andANYPS5_NO_SHADER_CACHE=1, 2668 of 2669 passed.agc_driver_mesh_barycentric_emulationfails ("the pixel shader did not emulate barycentrics"); it fails the same way onmaine0cd1259a, so it is not from this change.tools/vulkan_validation_gate.pyrefuses to run on Windows, so I followed the manual comparison of AGENTS.md. Every^agc_test ran onmaine0cd1259aand on this branch withANYPS5_REQUIRE_VULKAN=1,ANYPS5_NO_SHADER_CACHE=1andVK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation(Khronos nightly layer, commit b2b44c0, API 1.4.366, throughVK_LAYER_PATH), withctest --test-dir build -R "^agc_" -j 6 -V. Neither log containswas not found but was requested by env var VK_INSTANCE_LAYERS. Both ran 1096 tests with the sameagc_driver_mesh_barycentric_emulationfailure; the same 19 tests logged validation messages on both, with the same IDs and counts (9VUID-VkPipelineColorBlendStateCreateInfo-pAttachments-00605, the rest warnings), so this change adds no new ID.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)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by XairRrR on 2026-10-29T16:10:18Z.
Review: CHANGES_REQUESTED
Reviewed — changes requested
The change merges cleanly, builds, and the label and completion tests pass, but it makes the existing
agc_driver_alias_copy_labeltest skip itself instead of running, so that ordering check no longer runs.What I ran
368bdbcc0c9c4c18293153550d0f264f68194d4dmain:bb04a4f1ea0175e9e4f149f0359a764d62ff3296mainwith--no-ff, no conflicts):314b83a3a7705575f0416cd9e6fc06b618b28d93BUILD_TESTING=ON, in a clean worktree.Results
maingit diff --checktools/check_conventions.py --base origin/mainAll conventions checks passed.--target libs(merged tree)main, with validationagc_driver_alias_copy_labelmain; skips on the merged tree ("the label was not recorded on the GPU (reason 5)")VUID-lineswas not found but was requested by env var VK_INSTANCE_LAYERSVK_LAYER_KHRONOS_validationagc_driver_indirect_thread_dimensions)Skipped tests, merged tree vs main
Merged tree:
main:Negative control output
Negative control
I restored the six production files from
main, kept the PR'sIndirectThreadDimensions.cpp, and rebuilt.agc_driver_indirect_thread_dimensionsthen failed with the PR's new message, so the changed expectation does depend on the change. The_cpuvariant (APS5_NO_GPU_THREAD_DIMENSIONS=1) passes both ways. After this check I restored the merged files.Findings
Blocking
agc_driver_alias_copy_label. The test stores to an image with a compute dispatch, copies that image withCopyBuffer(path 3), and records a 4-byte label. It then checks that a CPU read after the label sees the copied bytes. WhenWriteLabelOnGpureturns anything other than 0, the test returnsVulkanTestSkipped(AliasCopyLabel.cpp#L113-L117). Onmainthe label returns 0 and the test passes. On the merged tree it returns 5, and the only difference inWriteLabelOnGpuis the newPendingGuestStoreCompletions() != 0term (VulkanDevice.cpp#L2542). Skip exit code 77 counts as passed in CTest, so the full-suite run in the description and the NVIDIA bot's "0 new" failures both miss this. The image-copy-then-label ordering that this test guards is now untested.Suggested fix: make the test handle reason 5, since the label is now stored at the reap. Accept 5, reap or sync the recorder until the label lands, then compare the destination bytes as before. Keep the GPU-store case covered too, either by a setup where no guest-store completion is pending or by asserting which path was taken. A skip should mean the device lacks something, not that the driver took a different path.
Non-blocking
markWrittenPagesonly callsGuestMemory::MarkPossiblyWritten, which stamps the write tracker (BdaResources.cpp#L340-L356).applyStoredSavecopies into the texture's host-sideoriginalbaseline, not guest memory (Texture.cpp#L4425-L4437). The hazard is therefore driver bookkeeping (snapshot or compare state) lagging behind the label, not memory the title reads directly.StoresAtCompletion/PendingGuestStoreCompletionsand the PR text point readers at the wrong mechanism.Suggested fix: rename to something like
UpdatesTrackingAtCompletion/PendingTrackingCompletions, and correct the description.Suggested fix: update that line in this PR.
StoresAtCompletionholds for every shader with a non-read-only BDA table, and the counter is process-wide. So every fence orRELEASE_MEMlabel now goes through the CPU-at-reap path while such work is in flight. The description gives presents per second for PPSA99903 only. I could not measure other titles; atools/trace_digest.pycomparison ofmainand this change on one more title that uses BDA writes would show whether label latency regresses.IndirectThreadDimensions.cppfrom 0 to 5. A focused test would close that gap: a BDA-writing dispatch, then a small label, then a check that a cached snapshot of the written range is invalidated once the label is observed. It would fail onmainand pass here.Not verified
To get this to a good state
agc_driver_alias_copy_labelrun again on the merged tree, accepting or asserting the held path (reason 5), and confirm it no longer skips.docs/dev/debt/libSceAgcDriver.mdfor the new condition.Imported from boykopovar/AnyPS5. Originally posted by XairRrR on 2026-11-02T20:03:58Z.
Review: CHANGES_REQUESTED
Re-checked — changes still requested
The new commits (
48c61f5289,40adf0a901, then the mergede8ef8f64d) fix theagc_driver_alias_copy_labelskip, rename the helpers and update the debt entry. But merged with currentmain, the change makesagc_driver_linear_target_completion_storesfail. That test arrived onmainin0ec6032d23, after this branch last mergedmain.What changed since my last review
AliasCopyLabel.cppno longer skips. It checks for reason 5 when a guest-state completion or a completion store is pending, and reason 0 otherwise. When the label is held, it waits for the epoch, checks the label is still not visible, reaps the batch, and then compares the bytes.StoresAtCompletion,PendingGuestStoreCompletionsandstoresGuestare renamed toUpdatesGuestStateAtCompletion,PendingGuestStateCompletionsandupdatesGuestState. The description now says that the BDA and stored-save completions update driver state, not guest memory.docs/dev/debt/libSceAgcDriver.mdlists the new condition.main0278ca9831.tools/trace_digest.pycomparison on PPSA01325 or PPSA28997 is promised. It has not been posted yet.What I ran
de8ef8f64d9ec636b4d497a52d180ce7b302f671,mainc955a63d3d20822e13bb1c6b55ac5800ca5e4176, merged tree1a0b24c261730d50517d9a85e3f393e655b355eb(clean--no-ffmerge).git diff --checkcheck_conventions.pyAll conventions checks passed.libs(script)agc_driver_linear_target_completion_stores. The 7 failures listed as known also fail onmain. The 2main_sync_renames_*tests listed as fixed are tool tests this change does not touch.agc_driver_alias_copy_labelthe label after the image copy was stored at the reapagc_driver_indirect_thread_dimensions,_cpuagc_driver_linear_target_completion_storesthe first label: the label was not recorded on the GPU (outcome 5)main's production filesmainyet)Negative control output
Negative control result:
agc_driver_indirect_thread_dimensionsfails without the production change, as before.AliasCopyLabel.cppcallsRecorder::PendingGuestStateCompletions, so it does not build againstmain'sRecorder.hpp, and I could not run it in the negative control. After restoring the merged files,git status --porcelainwas empty, and the merged-tree results were reproduced.Previous findings
agc_driver_alias_copy_labelskipped: Resolved. It runs and passes on the merged tree on lavapipe and takes the held path. The GPU-store path is now asserted rather than skipped.UpdatesGuestStateAtCompletionandPendingGuestStateCompletions, and the description is corrected.docs/dev/debt/libSceAgcDriver.mdnow lists pending completions of address-table writers and of stored saves.trace_digest.pypair has not been posted. The new failure below is a concrete case of this widening.IndirectThreadDimensionsproves the label is now held: it fails onmain. No test checks that the stale snapshot or baseline is what the hold prevents. This is still optional.New findings
Blocking
agc_driver_linear_target_completion_storesfails with this change.main0ec6032d23made a graphics-queue label store resident linear color targets first and then record the label on the GPU behind that store (core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp:2601). The test requires reason 0 for that label (core/libs/prx/libSceAgcDriver/tests/execution/LinearTargetCompletionStores.cpp:228).FlushPending, which very likely reachescommitStoredSave. This PR now registers the stored-save completion withupdatesGuestState = true(core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp:4827-4829). The newPendingGuestStateCompletions() != 0term (VulkanDevice.cpp:2648) then holds the label.main's production files the test passes.0ec6032d23relies on, and it is a failing test on the merged tree.StoreDrawnLineartriggers from withinWriteLabelOnGpu. If it does, change that test's expectation and say why in the description and the debt entry. Either way, merge currentmainand rerun the label tests.Non-blocking
None.
Not verified
main: the script had no validation baseline formain0278ca9831, and I did not run one myself.AliasCopyLabel.cpp: it does not build without the PR'sRecorder.hpp.0ec6032d23onmain.To get this to a good state
mainand makeagc_driver_linear_target_completion_storespass: either stop counting the stored save that a label's own linear-target store triggers, or justify and change its expectation.trace_digest.pycomparison on a second title.Pull request closed