perf(agc): fill an uploaded piece on the GPU when its guest memory holds one repeated word #24869
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/24869"
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 LeandroLP23 on 2026-11-21T08:15:47Z.
What
memset32loop), and they reach the driver as two partial uploads per frame over two import segments: 8.4 MiB per upload, all of it one repeated word, about 2.8 ms of GPU time per frame on an RTX 5060 Ti.StorageTexture::uploadWindowsnow fills such a piece on the GPU. Each piece the upload would read from an import (in place, or through the gather copy when the surface spans several imports) is scanned on the CPU; when it holds one 32-bit word repeated, it becomes a piece of a device-local buffer thatvkCmdFillBufferfills with that word, and the detile (or the gather copy) reads it from there. A filled piece is no longer a pending in-place read of the import. The scan ORs blocks of 1024 words against the first one and stops at the first differing block;std::all_ofreached 12.3 GB/s on the i5-10600K (DDR4) against 17.9 GB/s for the block loop on 16 MB of freshly written memory. In the same SuperTuxKart race (a run ofmain6bedd8e28dwith this change, #10442 and #24445 merged), the scan costs 665 to 685 us per upload on the draw committer (measured with a temporary counter), against about 1.4 ms of GPU time for the copy it replaces; creating the fill buffer costs 8 us.RefreshObligationalready used, moved intootherPendingInsideso both share it.APS5_NO_FILL_UPLOAD_UNITScopies as before (ENVIRONMENT.md).uploadBlockTests(agc_driver_recorder) gets five cases, on surfaces over 2 or 3 segment imports in resident memory:StorageUploadread, the last one still must, and the upload and write-back round trip must keep every byte. WithAPS5_NO_FILL_UPLOAD_UNITS=1both fail.settled), so this pins that condition.tools/pr_overlap.py --branchfailed closed (it could not confirm several PR branches); I compared the reported PRs that touchTexture.cpp,Texture.hpportests/Recorder.cpp(#18369, #19130, #20183, #20315, #22190, #22647, #20831) by hand: none touchesuploadWindows, the pending-unit test oruploadBlockTests.Tested
Tests, on the head (
a5365bed6d, onmain709342e209): AMD Radeon 860M (RDNA 3.5, AMD 26.10.2, Vulkan 1.4.359), Ryzen AI 7 350, Windows 11 (10.0.26300), WinLibs GCC 15.2.0 r7, Release.ctest -R '^(agc_driver_recorder|agc_sampled_import_pieces|agc_unit_shadow|agc_driver_dcc_keys_first_write|agc_driver_graphics)$' -VwithANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation VK_LOADER_DEBUG=layer: 5 of 5 in three runs, the layer inserted in each GPU test, 0VUID-lines.agc_driver_recorderprintsupload blocks: ok.APS5_NO_FILL_UPLOAD_UNITS=1,agc_driver_recorderfails on the two uniform cases (the upload read a piece holding one repeated word from guest memory instead of filling it on the GPU).count = bytes / 4 - 1inTexture.cpp), the two cases whose last byte differs fail in both layouts:the upload filled the piece whose last byte differs on the GPU instead of reading itandthe upload and write-back changed 1 guest bytes.f6f1333f23, onmainbe8e78cdde, same laptop and variables),agc_driver_recorder_tests --writeback-blocks-onlyrun directly because the fullagc_driver_recorderstops earlier on this laptop onmainas well (an earlier case's image is still in the live registry over the reused memory): the head andmainpass 2 of 2 (upload blocks: ok), the layer inserted, 0VUID-lines. With theHasQueuedStores()condition removed fromsettled, the case fails 3 of 3:the upload filled the piece under a queued store on the GPU instead of reading it after the store.Speed, on the RTX 5060 Ti (NVIDIA 621.24), Intel i5-10600K, Windows 11 (10.0.26300): SuperTuxKart (PPSA69421) tutorial race, driving straight from the start (title_run
--profile performancewith a pad timeline), 10 s trace window 80 s after the first present,tools/trace_digest.py.main709342e209against899c4ae9d5, this branch on thatmain(the head adds only the test change after it), alternated twice:GPU time per present drops by 2.0 and 2.6 ms in the two pairs, and frame p50 by 0.6 and 1.5 ms. On
mainthe frame is bound by the draw committer waiting inRecorder.Sync, so frame time follows the GPU time only in part. WithAPS5_PROFILE_GPU=1on the same build and scene, thestorage-uploadclass takes 4.05 ms per present with the fill and 6.63 ms withAPS5_NO_FILL_UPLOAD_UNITS=1(4.0 uploads and 32.7 MiB per present in both), so the race's upload pieces are still filled on the GPU with the resident-memory condition.Summary lines of the first pair:
main (
709342e209)this PR (
899c4ae9d5)Not run: the whole CTest suite, other titles, Linux and macOS (the fill is Windows only). The traces are available on request.
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)Summary by CodeRabbit
APS5_NO_FILL_UPLOAD_UNITSenvironment variable, including its default and effect.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-21T08:29:34Z.
Review: COMMENTED
Reviewed — no blocking findings
Nothing blocks this; the points below are optional.
What I ran
Read the prepared diff for head
95a20b527d4c36e5c1ccd560cd53743fab59c235and usedrepo_read.pyto inspect the changed lines and targeted callers. I did not run commands or tests.Results
Negative control
Not run by the reviewer. The author reports that both added cases fail with
APS5_NO_FILL_UPLOAD_UNITS=1.Findings
Blocking
None confirmed in the changed lines reviewed.
Non-blocking
Sources
Not verified
Read changed-line ranges in all four changed files:
Texture.hpp,Texture.cpp,Recorder.cpp, andENVIRONMENT.md. The full text ofTexture.cppandRecorder.cppwas unavailable in the review folder; only targeted ranges were read from the pinned head. Other lines in those files, the full CTest suite, other titles, and AMD/Intel GPU behavior were not verified. No files were excluded by rule in the manifest.To get this to a good state
Nothing is required. Optional: independently run the reported CTest cases and negative control on the reviewed head.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-22T04:25:47Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this change; the points below are optional.
What I ran
Reviewed head
60a241e0589b0f3d88c7413b307a9f35ceca4b96using the prepared diff and the pinned repository reader. No test commands were run.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
The full text of
core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppandcore/libs/prx/libSceAgcDriver/tests/Recorder.cppwas excluded as too large; I read the changed ranges and targeted surrounding code from both. I also read the changed ranges incore/libs/prx/libSceAgcDriver/Graphics/include/Texture.hppanddocs/dev/ENVIRONMENT.md. No other repository files were read. Tests, other titles, and GPU/OS configurations were not independently verified; the description’s test and performance results are author-reported.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-22T13:22:35Z.
Review: COMMENTED
Reviewed — comments
Changes are required before merge: ensure guest memory cannot change between the repeated-word scan and the GPU fill, or establish an appropriate synchronization guarantee.
What I ran
Reviewed head
6d2c7a4d017e85a7bc384e6ab67da1219c954903from the prepared patch and targeted source reads usingrepo_read.py. No tests or builds were run.Results
Findings
Blocking
None verified.
Non-blocking
Texture.cpp:4167scans guest memory on the CPU andTexture.cpp:4278later asks the GPU to fill with the scanned word. Thesettledcheck atTexture.cpp:4154and pending-image check atTexture.cpp:4161address recorded writes, but I could not confirm they prevent a concurrent CPU write between scan and fill. If guest memory can be updated concurrently, the fill may use a stale value and discard the upload’s actual contents. Please establish the synchronization guarantee or guard/revalidate the scanned range before using the fill path.Not verified
Texture.cppandRecorder.cpptexts were not read; only the upload path, related pending-write/residency APIs, and changed regression-test function were inspected.Texture.hppandENVIRONMENT.mdwere read at the changed declarations/entry.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-25T00:17:11Z.
Review: CHANGES_REQUESTED
Reviewed — changes requested
Changes are required before merge: prevent GPU filling a piece when an overlapping queued store can change its guest bytes before upload.
What I ran
a5365bed6d854ec9197fdb825bf59a1290561164throughrepo_read.py.Results
Findings
Blocking
Texture.cpp:4158-4167), but after that scan the upload path callsFlushStoresOverlappingfor guest reads (Texture.cpp:4261-4262). A queued store overlapping a candidate piece can therefore update guest memory after the repeated-word scan, while the source has already been replaced by a GPU fill (Texture.cpp:4180-4184). The detile can then consume the stale repeated value instead of the store’s final bytes. Exclude any candidate piece whose queued stores may be flushed, or flush relevant stores before scanning and verify that the pending-write condition still holds.Non-blocking
None.
Not verified
Texture.hpp,Texture.cpp,Recorder.cpp, andENVIRONMENT.md.Texture.cpp,Recorder.cpp, andENVIRONMENT.mdwere read through the pinned reader; the header was read through the prepared artifact path but that path was unavailable, so its declaration was checked at the pinned repository path.Texture.cppandRecorder.cppwas unavailable because they were too large; only targeted ranges were read. No tests, builds, other operating systems, or physical-console behavior were verified by me. The reported Windows GPU tests and performance measurements are author supplied.To get this to a good state
Ensure the fill decision observes guest bytes after all overlapping queued stores have landed, while preserving the existing pending-write safety checks. Re-run the focused upload tests, including a case with a queued overlapping store, on the new head.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-25T10:27:36Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this change; the inspected implementation and targeted test evidence support merging.
What I ran
Reviewed head
f6f1333f23468234a644c04fa06c9c88ce2dc6a. No commands or tests were run in this review; the description reports targeted Windows Vulkan tests and performance captures, which I did not independently run.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
The full text of
core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppandcore/libs/prx/libSceAgcDriver/tests/Recorder.cppwas excluded from the review folder; relevant ranges in both were read throughrepo_read.py. Full files reviewed:core/libs/prx/libSceAgcDriver/Graphics/include/Texture.hppanddocs/dev/ENVIRONMENT.md. No excluded files were inspected beyond the relevantTexture.cpprange. Tests, builds, and performance runs were not independently reproduced; other platforms and titles were not verified.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by coderabbitai[bot] on 2026-12-01T12:06:14Z.
Review: COMMENTED
🏛️ Architecture findings (1)
Advisory architecture findings (1)
💬 Code review
c691e561-1b33-4879-99ab-557c3a9796f0Reviewing files that changed from the base of the PR and between
184c5100c1and2c120da0b9.core/libs/prx/libSceAgcDriver/Graphics/include/Texture.hppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/tests/Recorder.cppdocs/dev/ENVIRONMENT.mdIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.