fix(agc): store an occasionally written image before a label #14311
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/14311"
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 XatiX on 2026-11-01T09:17:36Z.
What
A title can render a tiled image by compute and read it on the CPU after a label.
StoreReadbackBeforeLabelstores only linear images and those up to 64 KiB, so a larger tiled image stays on the GPU and the CPU reads the old bytes at that address.PPSA06866 renders its save thumbnail into a 768 KiB tiled image this way. Every save stored noise as its PNG. The PNG was valid, and its pixels were BC1 blocks of a ground texture that had been at that address.
An image up to 1 MiB that was not written in the last 8 flips is now stored before the label too, and so is an image's first write. That takes one store: the label clears the flag when it chooses the image, so with no flips it cannot store the image at every label. An image written on consecutive flips stays on the GPU, because storing those at every label is the cost the 64 KiB limit avoids.
The 1 MiB and 8 flip limits come from this one case. An image above 1 MiB, a write after that one store with no gap, or an image the CPU reads while it is rewritten every few flips still reads stale bytes. The debt entry records this. Other values, or another way to tell these images apart, would be welcome.
Tested
Windows 11 Pro 10.0.26300, GCC 15.2.0 (WinLibs), NVIDIA GeForce RTX 5080 (617.42).
agc_driver_linear_readback_labelgains a 256 KiB tiled image: a first write is stored before its label and chosen once, a second write with no flip between is not chosen, a write on the next flip is not, and a write after a gap of more than 8 flips is. The "not chosen" steps read a counter of label choices, so the idle store cannot fail them. Restoring the old behaviour fails on the second-write step. The earlier revision was also checked without the change, with every image up to 1 MiB stored, and with the gap never reached. The test advances the flip counter by hand, so theNoteFlipcall inDriver::executehas no assertion.VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation,ANYPS5_NO_SHADER_CACHE=1andANYPS5_REQUIRE_VULKAN=1usingctest -V -R 'label|readback|video_out_flip', 64 of 64 pass onmainf2d874c1fdand on this change at84946a6af6, on the same machine, with none skipped. Neither log reports a missing layer, and neither has aVUID-line. The logs are on this pull request. Themainrun usesmain's version of the test, so it does not contain the new cases.mainstops earlier, at the unsupported stencil copy, so the title cannot reach this code there. On a local branch that also carries #9717 and #13021, three saves before the last rebase have correct, different thumbnails. A probe build showed the one save it recorded writing the image once and taking one store, so these saves may all be first writes. The gap path is not shown in the title.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)main🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-01T09:00:57Z.
Review: CHANGES_REQUESTED
Reviewed — changes requested
The exact head has a reproducible conflict with open PR #13879, and the repository-required paired AGC Vulkan validation is not evidenced; both are needed before this can be cleared.
What I ran
Reviewed head
c1a81eb25b5d7f1634f12f4ba1159cfd10f66068against PR base5c9837bfe7c5533f2c77c968dd8193157a8c342a. GitHub reports the PR mergeable withmain; the pairwise preview against #13879 used merge base5e936063e3a74b7f03ff06905be04c5a00be60a7and conflicted inTexture.hppandTexture.cpp. Environment: Linux 6.1.0-54-amd64; no compiler was invoked. I did not configure, build, or run local CTest under the no-build initial-review rule.Results
git diff --checktests/execution/*.cpptarget discovery and the test fragment.mainclean.core/libs/prx/libSceAgcDriver/Graphics/include/Texture.hppandGraphics/src/Texture.cpp.agc_driver_linear_readback_labelandagc_driver_linear_readback_label_offwere skipped.The precheck's aggregate status was
checks failedbecause its detached exact-head checkout lacks the workspace-only ABI and test-quality helper scripts. I reran those helpers from the workspace: the ABI audit found no applicable ABI changes, and the test-quality warning is explained by CMake's automatic source discovery.Unedited outputs from the relevant checks
Negative control
_offCTest variantFindings
Blocking
Texture.hppandTexture.cpp, and the repository asks authors of overlapping PRs to agree on landing order and declare it withDepends on. The body currently saysDepends on: none. Please coordinate with #13879's author, then update the dependency/landing-order line and branch so the two changes integrate cleanly.mainand this change withVK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation,ANYPS5_NO_SHADER_CACHE=1, andANYPS5_REQUIRE_VULKAN=1, with logs checked for a missing validation layer and newVUID-errors. The hosted Windows run skipped both changed readback tests, and the PR description does not include comparable baseline/change logs. Please attach the focused outputs from the same machine and GPU; if this new test cannot run onmainunchanged, describe the equivalent baseline procedure and include both logs.Non-blocking
Sources
Not verified
VUID-comparison, other GPU vendors, Linux behavior, and console behavior.To get this to a good state
Coordinate the overlapping PR order and update
Depends on, then attach the paired focused AGC validation logs. I will re-check the new head, repeat the no-build review commands, and verify the new CI and integration state.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-01T10:27:51Z.
Review: COMMENTED
Re-checked — new head, no blocking findings
The two blocking items from c1a81eb25b (the #13879 merge conflict and the paired AGC validation logs) appear resolved at 48f5fce43a on the evidence below, and the remaining items are non-blocking; this review does not replace the earlier CHANGES_REQUESTED review 5727300304.
What I ran
Head reviewed:
48f5fce43a4cf850b4833cb6543a9aa096c432bf. PR base:26fa1212b82f76dd49cf12d65e445d6ff3e0844c. Merge previews, allgit merge-tree --write-treewith exit 0 (clean): head against current mainba8dcc6ae82a5c4443efd93bbb99dfa91faf7fa4, against #13879 head90f0b5fd3b22d57a8d42a8bd133005003e93dcf4, and against #13678 heada3046f449ce09fabc19f7564816272ea115a4dad. Environment: Linux 6.1.0-54-amd64, Python 3.11.2, git 2.39.5. No compiler was invoked; no configure, build, CTest, or GPU run.The precheck ran at the exact head, and head and base were unchanged at completion. Its ABI audit and test-quality steps failed only because
tools/pr_abi_audit.pyandtools/pr_test_quality.pyare absent from the detached head tree, so I ran both by hand from/marc/AnyPS5/toolsas shown above.Results
git diff --check(precheck)not_applicable: no APS5_VABI or APS5_EXPORT change recognizedpossible-unregistered-cpp-testfinding; false positive, see Findingsba8dcc6a90f0b5fda3046f44agc_driver_linear_readback_labelis built from anExecutionTestNotBuilt.cppstub and reported Skippedmainand head, RTX 5080)VUID-lines and no missing-layer lines. Author-reported; I did not reproduce themUnedited output
Negative control
Texture.cppline 4753 would make the same-flip second write choose the image again.agc_driver_linear_readback_label_off(setsAPS5_NO_LABEL_READBACK_STORE=1)ReadAfterLabelbeforeReadOccasionalAfterLabelruns.Findings
Blocking
None.
The first blocker is resolved on the evidence: the head merges cleanly with #13879, #13678 and current main. The second is resolved on the evidence in the attachments: both logs report the same focused tests passing on
mainand on the head, the validation layer is active (both logs contain sixValidation Warninglines, none of themVUID-errors), and neither log has a missing-layer message.Non-blocking
StoreReadbackBeforeLabelon main with an Apple-only trap path. The non-Apple selection of linear and small images is unchanged, so the Windows evidence still covers that branch. The new tiled-image loop at head (lines 4751 to 4757) is not gated on the Apple trap path, and the body does not say whether that is intended on macOS. The smallest useful step is to state how the two interact on macOS, or to check on current main.Depends on. The merges are clean, and the author says the lines differ from #13879, so this may not apply. The body still saysDepends on: none. A reply on #13879 or a short note in the body would settle it; if #13879 lands first, the merge should be previewed again.NoteFlip()call inDriver::execute(PacketExecution.cpp line 399) has no assertion, because the test advances the counter by hand.The test-quality finding for
LinearReadbackLabel.cppis a false positive:CMakeLists.txtline 555 globstests/execution/*.cpp, andtests/cmake/agc_driver_linear_readback_label_tests.cmakeregisters the executable.Sources
StoreReadbackBeforeLabelwith the Apple trap path:github.com/boykopovar/AnyPS5@ba8dcc6ae8/core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp (L4752-L4782)github.com/boykopovar/AnyPS5@48f5fce43a/core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp (L4741-L4759)github.com/boykopovar/AnyPS5@48f5fce43a/core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp (L3940-L3943)NoteFlip()in the flip branch:github.com/boykopovar/AnyPS5@48f5fce43a/core/libs/prx/libSceAgcDriver/Execution/src/Driver/Packets/PacketExecution.cpp (L399)github.com/boykopovar/AnyPS5@48f5fce43a/core/libs/prx/libSceAgcDriver/CMakeLists.txt (L553-L555)_offCTest fragment:github.com/boykopovar/AnyPS5@48f5fce43a/core/libs/prx/libSceAgcDriver/tests/cmake/agc_driver_linear_readback_label_tests.cmake (L3)github.com/boykopovar/AnyPS5@26fa1212b8/CONTRIBUTING.md (L68-L73)Not verified
mainand head identities are the author's statement. Themainrun usesmain's version of the test, which has no new cases, as the author notes.To get this to a good state
Imported from boykopovar/AnyPS5. Originally posted by CnRJay on 2026-11-01T19:41:11Z.
Review: COMMENTED
The bug is real and well described: a CPU read after a label of a tiled image that stayed on the GPU. oneandonlydean has covered the flag logic and the debt entry. The part I'd add is the cost of the fix on the GPU side, which the description handles as "no speed claim".
1. Storing before the label is a GPU→CPU round trip.
StoreReadbackBeforeLabelrecords a copy of the image into host memory and the label has to wait for it. For 1 MiB that is a readback and a queue wait on the label's path, in the middle of a frame. The 64 KiB limit for tiled images exists because that cost adds up. This change raises it 16× for images that are "written occasionally", chosen by a heuristic of 8 flips and 1 MiB that the description itself says comes from one case.2. The cost is paid per qualifying write, not once. The description says an armed image "takes one store until the next first write or long gap". An image written once every 9+ flips is therefore stored again at each such write. A dynamic atlas, a UI or minimap target that is redrawn every second or two (which is 9+ flips at 60 fps) takes a 1 MiB readback and wait on every redraw, indefinitely. That is the pattern the limit of 8 flips lets through. The test covers "write after a gap of more than 8 flips is chosen" but not how often a real title does it.
3. The numbers shown cover only the quiet case. 76 label stores with and without the change over 45 s of play is "no harm on a route that never hits the path". The PR needs a trace from a scene where it does: a count of selected images and bytes stored per second, and the
Driver.Packet.memory_waitor label-wait phase fromtools/trace_digest.py,mainagainst the change, same machine and scene. Without that the "no speed claim" line leaves the one thing a reviewer must judge unmeasured.4. Can the store be deferred? The only reader of this image is the CPU after the label. If the title reads it later than the label, the copy can be issued at the label and waited on only when the CPU's read happens (the existing write-watch/trap path on the destination page). That removes the wait from the GPU path for every image size and makes the 1 MiB / 8-flip thresholds unnecessary. If there's a reason it can't be, state it in the debt entry.
5. Thresholds from one title. AGENTS.md and CONTRIBUTING say not to special-case a value seen in one title's trace. The 1 MiB and 8-flip values are exactly that. If a general rule is unknown, the convention is to throw and record the gap in
docs/dev/debt/libSceAgcDriver.md, not to ship a heuristic tuned to PPSA06866.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-02T07:51:02Z.
Review: COMMENTED
Reviewed — no blocking findings in the code read; the new label-store path runs only in an execution test that is a stub on Windows
This PR stores an occasionally written image's guest range before a label is set. A texture is marked "occasionally written" when it was written once or after more than 8 flips since its last write, and only textures between
SmallStoreBytesand 1 MiB are stored. I read the production change in full. The Windows run passed 2594 of 2594, but the test for this path,agc_driver_linear_readback_label, was Skipped, so the new behaviour has no hosted pass.What I ran
84946a6af663f18da7bae6ac99178cbc443a20da; basef2d874c1fdccf781c0fa5d86619bb5dd8894b958. 5 files, +81/-6:Driver/Packets/PacketExecution.cpp(+1),Graphics/include/Texture.hpp(+6),Graphics/src/Texture.cpp(+23),tests/execution/LinearReadbackLabel.cpp(+56/-6), anddocs/dev/debt/libSceAgcDriver.md(+1; not read).NoteFlipincrements a process-wide flip counter. Each texture records the flip at its last write. ItswrittenOccasionallyflag is set when it was written once or the flip count has moved more than 8 since. The label path skips linear textures, textures no larger thanSmallStoreBytes(value not read here), and textures larger than 1 MiB. For the rest, it stores the range only if the flag was set, and it counts those stores.agc_driver_linear_readback_label(Test #1107) is Skipped, as are the other label-order execution tests (Test #808, #845, #953). Those are the stubs for execution tests that are not inANYPS5_AGC_EXECUTION_TESTS.Results
agc_driver_linear_readback_label(the changed test)SmallStoreBytesRead-only check output
Precheck was not run: no PR-head code is run here. Diff check: passed. Conventions: passed. ABI audit: not applicable. Stack check: clean, no declared dependencies, no errors. Hosted:
gh api repos/boykopovar/AnyPS5/commits/84946a6af663f18da7bae6ac99178cbc443a20da/check-runs, and the Windows job log (2594 of 2594).Negative control
Not run here. A negative control needs a local build and run of the label test, and code from this head is not run here.
Findings
Blocking
None from the code read.
Non-blocking
SmallStoreBytes) are fixed in the code, and the basis for them is not stated in the diff.Sources
github.com/boykopovar/AnyPS5@84946a6af6/core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppgithub.com/boykopovar/AnyPS5@84946a6af6/core/libs/prx/libSceAgcDriver/Graphics/include/Texture.hppgithub.com/boykopovar/AnyPS5@84946a6af6/core/libs/prx/libSceAgcDriver/tests/execution/LinearReadbackLabel.cppwindowson 84946a6af663f18da7bae6ac99178cbc443a20daNot verified
SmallStoreBytes.To get this to a good state
agc_driver_linear_readback_labelat this head on a host that builds the execution tests, and say where the thresholds come from.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-02T18:34:21Z.
Review: APPROVED
Reviewed — looks good
I reviewed all six changed files at head
54fad51133fe12a637c0b395e4b5c6d420691c89and found no blocking issue; the earlier overlap is resolved and the paired AGC validation is reported for this head.What I ran
Reviewed against PR base
a4eca2a056bf3bbbec98ab42e9d28163e4ea9cb8. The stack precheck reported a clean merge preview against currentmain. The former overlap, #13879, merged on November 1. The author reports a paired Vulkan run againstmainbc12e152250ce963451f3e25c4adbe799abfb656and this head on Windows 11 Pro 10.0.26300, GCC 15.2.0, NVIDIA RTX 5080, driver 617.42. I checked that currentmainhas no changes to the touched AGC source or test files since that baseline.Reviewer environment: Debian 12, Linux 6.1.0-54-amd64, Python 3.11.2, GCC 12.2.0 (not used for a build).
The author’s paired GPU results are reported in the follow-up, not independently run by me. The precheck’s isolated snapshot lacks the optional ABI and test-quality helpers; I ran the ABI audit separately and checked the test’s CMake glob and CTest fragment manually. I did not configure or build AnyPS5 or run local CTest.
Results
main; #13879 is merged.Precheck table and selected unedited outputs
Conventions output:
Standalone ABI audit:
Test-quality heuristic output:
Hosted Windows output:
Current PR check summary: conventions, labels, eligibility, library-portability, report and Windows passed. Linux, relinker, ASan, edge-watch, register-context and write-watch were skipped.
Negative control
Findings
Blocking
None.
Non-blocking
None.
Sources
Not verified
I did not run local build/CTest, Linux/macOS tests, the PS5 console, or a reviewer-side negative control. Hosted Linux and specialized jobs were skipped. The paired GPU run and its validation-layer/VUID results are author-reported.
To get this to a good state
No further author action is required for this review. Approval covers only head
54fad51133fe12a637c0b395e4b5c6d420691c89.