perf(agc): take an aliased storage image's units on the device without a host import #13251
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/13251"
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 EagleBearerYS on 2026-10-30T07:54:06Z.
What
When a storage image is refreshed over memory where another storage image still has results on the GPU,
StorageTexture::refreshcan take those results on the device.borrowUnitsrecords onevkCmdCopyImageof the other image's pending units. Onmainthat path needs two images of the same shape over the same memory (for example an RGBA8 view and an R32 view of one surface), and it also needs the refreshed surface to have a host import (Texture.cppL2196 and L2342 on08a10d2253).Without an import, the refresh takes the round trip instead:
storage refreshwrite-back;flushedupload.The four commits:
perf(agc): take the units on the device without a host import. The import wasn't needed for correctness, but removing it needs two other changes, because without an import:forgetBorrowed) are borrowed again.ReadCommittedgo through the recorder's memory-access hook, which would store the alias anyway. While a kept alias is being refreshed over,FlushPendingleaves it out, exactly as the refresh's own flush already does. A thread-localrefreshingAliassits next torefreshing.fix(agc): advance a borrower's generation past its lender's write-back.main: the gap exists only with a write-watched host import. Commit 1 would widen it to every surface.advanceAdjacent).fix(agc): store a kept alias when the refreshed image's keys aren't uncompressed.main: the same gap exists on the import path.test(agc): measure the round trip and assert what the handoff removes (below).Unchanged: the conditions for keeping the alias are main's.
The fifth commit merges
main(f7f03daf52). #12559 and #12927 had added tests at the same places intests/Recorder.cppand the AGCCMakeLists.txt, and the merge keeps both sides.The last two commits take overlaps at other bases and sizes, one 64 KiB tile at a time.
refactor(agc): keep a storage image's borrowed units per unit and per lender. No behaviour change on its own.borrowedFrom/borrowedVersionbecome oneBorrowedUnit{from, version, unit, held}per unit, because one image can now hold units from several lenders, and a lender's unit index can differ from the borrower's.markLayersPending) supersedes exactly the lender unit recorded for each unit it writes, while the lender is still at the version lent. The lender's write-back maps its stored units to each borrower's own units (borrowersUnchanged).pendingAliases()returns alias plans (each unit mapped to a lender unit, with which units are copyable).refreshingAliasbecomes a set, andFlushPendingwithout anexceptleaves out every kept alias, as it did for the single one.perf(agc): borrow an aliased storage image's units across bases and sizes, one 64 KiB tile at a time.swizzleWithinBlock; for SW_64KB_R_X at 4 bytes, x and y bits 0-6 plus the slice);vkCmdCopyImageregion, from B's tile to A's tile at their own tile coordinates, moves the block bit for bit.kStandard*, GCN and 4 KiB modes are refused this way, conservatively).Prior art: #4286 (AlxcBTW, closed unmerged on 10-12) handed aliased storage memory over without the guest round trip, unit by unit and at any base. It retiled through a device buffer and needed a host import.
APS5_NO_ALIAS_BORROW=1turns it off), needs no host import, and copies image to image.Resident Evil Village (PPSA01556)
Static menu, profiled boot (
APS5_PROFILE_DRAW=1) onmainebb4075168plus #12478, without this change. Its 10 s[storage]lines at the menu show:storage refreshwrite-backs;flushedCPU uploads;The highest window:
The first four commits alone don't take Village's pairs.
Tested
New tests. Each runs
agc_driver_recorder_testswith its own--…-onlyswitch. All use a write-watched allocation with host imports off, and cached 256x256 RGBA8 and R32_UINT storage images over the same surface, with the same tiling.agc_storage_alias_borrow(commit 1):agc_storage_alias_keys(commit 3): a pending linear image over the RGBA8 image's DCC keys turns them single when the refresh's flush stores it. The RGBA8 image must still sample the R32 image's value, and the R32 image must no longer be pending.agc_storage_alias_round_trip(commit 4): four rounds of the pattern a frame makes. Each image is looked up, then written, over the same memory. Three pairs run in copied and imported memory, with images made directly and from the cache.[storage]line, per step.storage refreshwrite-backs, 0flusheduploads, no other reason taking their place, and one device copy per lookup after a write (7 × 256 KiB).agc_storage_alias_blocks(commit 7): R32 images in tile mode 7 (R 64 KiB X), cached, over copied write-watched memory.FlushPendingafter every write, the old path) and borrowed (no stores). The patterns differ per texel, mip, image and round.aliascopies are exactly the taken units × 64 KiB;storage refreshwrite-back.agc_storage_alias_round_trip, extended (commit 7): its R32 256x256/512x128 pair (same base and size, other width) now asserts the handoff for cached images over copied memory: nostorage refreshwrite-back, noflushedupload, and 7 whole-surfacealiascopies (7 × 256 KiB).Reds (Linux). Each was built from the named commit with only the named change:
Texture.cppfrommainagc_storage_alias_borrowcase A: "refreshing the RGBA8 image over the surface wrote the pending R32 image back instead of taking its units on the device"APS5_NO_ALIAS_BORROW=1mainagc_storage_alias_round_trip: "... cached images, other format, same bytes per texel (R32_UINT / RGBA8 256x256, R 64 KiB X), flushing, round 1: Y does not hold X's last results after its lookup"Texture.cppagc_storage_alias_keys: "the RGBA8 image sampled 17.000000 after a refresh whose flush turned its keys single over the R32 image's pending results, expected 48"Texture.cppfrommainagc_storage_alias_round_trip: "'storage refresh' write-backs 7x 1835008 bytes, although the device handoff covers this pair"agc_storage_alias_blocks: "a 512x128 image two units into a 256x256 one, round 0, Y looked up: took 0 bytes from the other image on the device, expected 2 units";agc_storage_alias_round_trip: "same format, other dimensions: 'storage refresh' write-backs 7x 1835008 bytes, although the device handoff covers this pair"agc_storage_alias_blockscontent check: "lookup 0 (Y) holds 32768 texels other than the store-and-upload path gives (first 0x10000000 where 0x10020000)", that is, X's row 0 where row 128 belonged;agc_storage_alias_round_tripfails tooLinux runs (Ubuntu 24.04, GCC 13.3, Release, CI's flags, lavapipe/llvmpipe 20.1.2, as an unprivileged user):
the new tests ×10 on their commits;
the 52 DCC and storage tests ×10 on commit 3: 44 passed every time, 8 skipped;
ctest -R '^agc'once:commits 6 and 7:
ctest -R '^agc'once, 1,139 tests (agc_storage_alias_blocksadded), 0 failed, 75 skipped, the same set as on commit 5; the 4 alias tests ×10, 40 of 40; commit 6 alone, the storage, clear hand-over, unit shadow and recorder tests, 18 of 18 (2 skipped, as on commit 5).GitHub, ×10 on both runners:
agc_storage_alias_blocksandagc_storage_alias_round_tripfail with the messages above.main(run): the three new tests,main's newagc_storage_typed_fill_clear, and the storage tests around them.08a10d2253(run): the three new tests plus the storage tests around them.main's arm doesn't build there, because the round-trip test reads a test-only accessor inTexture.hpp. The reds above are the per-commit ones.main's code also failedagc_driver_storage_read_during_idle_storeonce, at its own precondition ("the GPU producer left no pending image"). It passed onmainin the next run, and with this change in every run.Validation layer (CONTRIBUTING's AGC rule), on GitHub's Linux runner (llvmpipe, Mesa 25.2.8, Ubuntu 24.04.5), commit 1 against
main(run):mainand 81 with the change, with 0 "was not found".VUID-VkDeviceCreateInfo-pNext-pNext, on both. The change adds none.Windows hardware, by DonRyuzaki (report): an AMD Radeon RX 7800 XT on Windows, head
f6e8382ef4merged ontomaina992b80376, withANYPS5_REQUIRE_VULKAN=1andANYPS5_NO_SHADER_CACHE=1. It is the first run of these tests on Windows hardware, since GitHub's Windows runner has no Vulkan device.agc_storage_alias_round_trip,agc_storage_alias_borrow,agc_storage_alias_blocksandagc_storage_alias_keys, 3 of 3 each, none skipped.APS5_PROFILE_DRAW=1): on the cached pairs over copied write-watched memory, 0storage refreshwrite-backs, 0 flushed uploads and 7 alias copies (1,835,008 bytes). The uncached copied pairs keep their 7 write-backs and 7 flushed uploads. Inagc_storage_alias_blocks, the offset 512x128 image takes 131,072 bytes by alias per lookup, the partial 128x64 tile falls back, and the four-mip image takes 196,608 bytes by alias with its tail on the fallback.mainrun, and the layer's insertion wasn't checked. There was no game or performance capture, so the same-scene capture the performance bot asks for is still outstanding.Checks:
check_conventions.pyandcheck_test_registration.pypass.-fsyntax-onlyonTexture.cppandtests/Recorder.cppshows no new diagnostic.Recorder.cppstops at the same_fflush_nolockdeclaration gap as onmain.Overlap: checked with
git merge-treeof this head against every open pull request that changesTexture.cpporTexture.hpp.directto surfaces over several imports.direct =line and this PR's borrow condition. They compose: take #11485'sdirectand this PR'skeys == DccKeys::Uncompressedcondition.direct, the clash is the same kind of one-line overlap (HostImportForCached): take its lookup and keep this PR's test.mainalready, so whichever lands second rebases.main. The merge below keeps itsUnitFlags borrowedUnitsas the held bitmap and adds this PR's per-unit lender beside it.directwith this PR's alias test, then check that the upload still runs before the borrow (and held units are borrowed again after it) when the upload is #11485's GPU segment upload.FlushPending's registry filter; keep both conditions.Resolved. The per-tile copy's calls can take the same form.HintedComparisontoTexture.hppnext to where commit 2 adds the lender'sborrowerslist. The clash is textual only: whichever lands second keeps both.CMakeLists.txtortests/Recorder.cpp. The clashes are textual only: whichever lands second keeps both.mainnow conflicts the same way, through #9565'sagc_recorder_command_buffer_releaseon the WIN32 test-list line, and the next merge ofmainkeeps both names.refresh'sFlushPendingcall in a GPU-ordered flush scope. The clash is that call. They compose: keep this PR's alias plans and exempt scope, put #15569's scope around the call, and readaliases.empty()in itsorderedEligible. Either order works (note).8968153aaa, a merge ofmain0a148be963(run). #12862 movedlibSceAgcDriver's test registrations intotests/cmake/; the conflict inCMakeLists.txtis resolved withtools/agc_test_split.py resolve, which moves this PR's registrations intotests/cmake/agc_driver_recorder_tests.cmake(+13 −1 lines). Nothing else conflicted, and apart from the move this PR's diff is unchanged. With-DBUILD_TESTING=ON,ctest -Ngives 3109 tests:main's 3105 plus its 4 tests, each listed once. The tests of this PR's verify set pass 10 runs in a row. Linux: 11 run, 11 pass, 0 skip, 0 fail. Windows: 11 run, 0 pass, 11 skip (no Vulkan device), 0 fail. Suites: libc and libkernel pass on Linux (199 and 308) and on Windows (226 and 330). The suites ran withAPS5_SKIP_TIMING_TESTS=1, which relaxesprecise_wait's median bounds on GitHub's hosted runners.d79032ae0b, a merge ofmain2ff700fddf, which brings meh7an's #10886 (run).Texture.hppand two functions ofTexture.cpp,markLayersPendingandforgetBorrowed. #10886 storesborrowedUnitsas aUnitFlags, where commit 6 kept aBorrowedUnitper unit with its lender, the lender's version and unit, and a held flag.UnitFlags borrowedUnits.std::vector<BorrowedSource> borrowedSourcesbeside it, holding the lender, its version and its unit. It is read only when the unit's flag is set, and the two are sized and cleared together.AnyIngate inmarkLayersPendingand itsSetRangeclear inforgetBorrowedare kept, and this PR's two scans for a held unit becameUnitFlags::Any().-DBUILD_TESTING=ON,ctest -Ngives 3,130 tests:main2ff700fddf's 3,126 plus this PR's 4, each listed once.^agc_storage,^agc_driver_storageand #10886'sagc_unit_flags_allocation_failure_*.agc_storage_clear_hand_over, since lavapipe imports no watched host memory.APS5_SKIP_TIMING_TESTS=1, which relaxesprecise_wait's median bounds on GitHub's hosted runners.agc_driver_recorder_tests: 85 run, 77 pass, 8 skip (host imports and the pipeline cache, which lavapipe lacks), 0 fail.3731709269: merges ofmain88e804b0a7(e75bd22604) and3c3b3cda73(3731709269).e75bd22604brings winstrex's #10026, which forgets a unit's unwatch hash whererefresh()andwriteBackLayersrecord its generation. The merge keeps those calls inside this PR's reworked loops:borrowUnits(aliases, …)and theborrowed[unit] >= 0check inrefresh(), and theheld.empty()early return inwriteBackLayers. Inagc_driver_recorder_tests.cmake, both sides' registrations are kept.3731709269brings TechLevelZero's #10940, which givesFlushPendinga device. The pending-texture filter there keeps both conditions: this PR's alias exemption and #10940's device check.mainis otherwise unchanged.agc_repeated_neighbour_stores. Linux: 34 run, 33 pass, 1 skip (agc_storage_clear_hand_over), 0 fail. Windows: 35 run, 2 pass, 33 skip (no Vulkan device), 0 fail. Suites: libc and libkernel pass on Linux (214 and 316) and on Windows (241 and 337). The suites ran withAPS5_SKIP_TIMING_TESTS=1, which relaxesprecise_wait's median bounds on GitHub's hosted runners.agctest, once (run): Linux: 1,240 run, 1,161 pass, 78 skip, 1 fail. Windows: 1,276 run, 387 pass, 889 skip (no Vulkan device), 0 fail. The one failure isagc_driver_pipeline_journal's 120-second timeout, whichmain88e804b0a7's own run of every test hits too (run).86168db6b6, a merge ofmain4f41f4c375(run).Texture.hpp, the conflict is next tomain's newOccasionalLabelStoresdeclaration, which stays. Intests/Recorder.cpp, #6905'sSmallElementDetileTestand this PR'sstorageAliasBorrowTestsboth landed beforemain(), and both stay. Intests/cmake/agc_driver_recorder_tests.cmake, the WindowsENVIRONMENT_MODIFICATIONlist, wheremainaddsagc_changed_copy, the resolution is the union of both sides' names, each once. This PR's own lines are unchanged, and that list line is the only difference in its diff.agc_changed_copyand every test matching^agc_storage, which takes in this PR'sagc_storage_alias_*tests and #14302'sagc_storage_rewritten_blocksandagc_storage_rewritten_stale_units. Linux: 21 run, 20 pass, 1 skip (agc_storage_clear_hand_over), 0 fail. Windows: 22 run, 0 pass, 22 skip (no Vulkan device), 0 fail. The libc and libkernel suites run 300 and 322 tests on Linux and 327 and 342 on Windows, with 0 failed. The suites ran withAPS5_SKIP_TIMING_TESTS=1, which relaxesprecise_wait's median bounds on GitHub's hosted runners.13f688c15b, a merge ofmain086c0686c8(run).tests/cmake/agc_driver_recorder_tests.cmake, in the same WindowsENVIRONMENT_MODIFICATIONlist, where savvaniss's #9898 addsagc_recorder_stored_bytes. The resolution is again the union of both sides' names, each once. This PR's diff overmainis unchanged.agc_changed_copy,agc_recorder_stored_bytesand every test matching^agc_storage. Linux: 23 run, 22 pass, 1 skip (agc_storage_clear_hand_over), 0 fail. Windows: 24 run, 0 pass, 24 skip (no Vulkan device), 0 fail. The libc and libkernel suites run 300 and 324 tests on Linux and 330 and 342 on Windows, with 0 failed. The suites ran withAPS5_SKIP_TIMING_TESTS=1, which relaxesprecise_wait's median bounds on GitHub's hosted runners.2283625557, a merge ofmain1c8c0efc8c, which brings PrivacyOnion's #14868 (run).Texture.cpp'srefresh. #14868 prunes the sources an image adopted (pruneAdoptedSources()) right after the refresh's flush. This PR's flush with its alias plans stays, and the prune follows it. This PR's diff overmainis unchanged.agc_changed_copy,agc_recorder_stored_bytes,agc_driver_recorder(the whole recorder run, which takes in #14868's changed cases) and every test matching^agc_storage. Linux: 24 run, 23 pass, 1 skip (agc_storage_clear_hand_over), 0 fail. Windows: 25 run, 0 pass, 25 skip (no Vulkan device), 0 fail. The libc and libkernel suites run 300 and 324 tests on Linux and 330 and 342 on Windows, with 0 failed. The suites ran withAPS5_SKIP_TIMING_TESTS=1, which relaxesprecise_wait's median bounds on GitHub's hosted runners.f6e8382ef4, a merge ofmainc2eafe4461, which brings oneandonlydean's #14261 (×10).tests/cmake/agc_driver_recorder_tests.cmake, in the same WindowsENVIRONMENT_MODIFICATIONlist, where #14261 addsagc_untracked_forget. The resolution is again the union of both sides' names, each once. This PR's own lines are unchanged, and that list line is the only difference in its diff.agc_changed_copy,agc_recorder_stored_bytes, #14261'sagc_untracked_forgetand every test matching^agc_storage. Linux: 24 run, 23 pass, 1 skip (agc_storage_clear_hand_over), 0 fail. Windows: 25 run, 0 pass, 25 skip (no Vulkan device), 0 fail. The libc and libkernel suites run 301 and 325 tests on Linux and 331 and 343 on Windows, with 0 failed. The suites ran withAPS5_SKIP_TIMING_TESTS=1, which relaxesprecise_wait's median bounds on GitHub's hosted runners.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-11-20T06:51:23Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this change; the points below are optional.
What I ran
Reviewed head
f6e8382ef402a1bdefa70d1f9f7c61d107d8424b. I readreview/description.md,review/commits.md,review/manifest.json, andreview/diff.patch, then usedrepo_read.pyto inspect targeted ranges inTexture.cpp,Texture.hpp,Recorder.cpp, andagc_driver_recorder_tests.cmake. No tests were run.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
Texture.cppandRecorder.cppwere excluded from the review folder because they were too large; only targeted ranges were read throughrepo_read.py. The three other changed files were included and read. No build or test commands were run, so the reported test results and behavior on physical hardware were not independently verified.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T22:54:21Z.
Review: COMMENTED
The trial merge against
mainconflicts inTexture.cpp,Recorder.cppand the recorder test registration. InStorageTexture::refresh, CPU-backed uploads now come before the borrowed GPU copies, including units restored fromheldBorrows. Please keep a control where the destination has a newer overlapping CPU write for some units and the lender still holds the other units. Verify the destination write survives, the other units come from the lender, and the path uses neither a CPU import nor a device copy of unchanged units. A nonzero crop can exercise the lender-to-destination offset in the same fixture.AI-assisted: yes.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.