perf(agc): take an aliased storage image's units on the device without a host import #13251

Open
EagleBearerYS wants to merge 16 commits from upstream-pr/13251 into main
EagleBearerYS commented 2026-10-30 07:54:06 +00:00 (Migrated from github.com)

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::refresh can take those results on the device. borrowUnits records one vkCmdCopyImage of the other image's pending units. On main that 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.cpp L2196 and L2342 on 08a10d2253).

Without an import, the refresh takes the round trip instead:

  1. it waits for the other image's writer;
  2. it reads that image back and stores it to guest memory, the storage refresh write-back;
  3. it uploads the whole refreshed image again from guest memory on the CPU path, the flushed upload.

The four commits:

  1. 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:
    • The upload runs before the borrow. The upload is then the CPU path, and for a 2D image it replaces the whole image, borrowed units included. Units held from an earlier borrow that the upload replaced (forgetBorrowed) are borrowed again.
    • The refresh's own reads don't store the alias. The compare with the saved bytes and the CPU upload's ReadCommitted go through the recorder's memory-access hook, which would store the alias anyway. While a kept alias is being refreshed over, FlushPending leaves it out, exactly as the refresh's own flush already does. A thread-local refreshingAlias sits next to refreshing.
  2. fix(agc): advance a borrower's generation past its lender's write-back.
    • The gap: after a borrow, the borrower keeps the generation it had at the borrow. If the lender then stores those units (any flush or CPU read of the range), and the borrower is written without another refresh, the borrower's own write-back takes those blocks as CPU-stamped. It keeps the guest bytes and loses its newer results.
    • On main: the gap exists only with a write-watched host import. Commit 1 would widen it to every surface.
    • The fix: a lender now remembers its borrowers. Its write-back advances the units they still hold at the lent version past its own stamps, as it already does for adjacent pending images (advanceAdjacent).
  3. fix(agc): store a kept alias when the refreshed image's keys aren't uncompressed.
    • The gap: the alias is kept on the keys proved before the refresh's flush, and that flush can store keys itself (main's comment above L2196). If the keys proved after it aren't Uncompressed, the borrow doesn't run while the alias is still exempt.
    • The fix: the refresh ends the exemption there, drops the alias, stores it as a refresh without an alias does, and proves the keys again. All of this happens before anything reads the surface for the upload.
    • On main: the same gap exists on the import path.
  4. test(agc): measure the round trip and assert what the handoff removes (below).

Unchanged: the conditions for keeping the alias are main's.

  • The keys must be Uncompressed and the memory tracked.
  • Each pending unit of the alias must be either borrowable (unstamped since its generation, and not pending in the refreshed image) or stamped since. A stamped unit is one the alias's own write-back would drop anyway.
  • An untracked surface, a pending unit with generation 0, or an unstamped unit pending in both images still refuses the alias.
  • The alias stays pending until the refreshed image is written and supersedes those units, so a CPU read still stores it.

The fifth commit merges main (f7f03daf52). #12559 and #12927 had added tests at the same places in tests/Recorder.cpp and the AGC CMakeLists.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.

  1. refactor(agc): keep a storage image's borrowed units per unit and per lender. No behaviour change on its own.
    • borrowedFrom/borrowedVersion become one BorrowedUnit{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.
    • A write (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). refreshingAlias becomes a set, and FlushPending without an except leaves out every kept alias, as it did for the single one.
  2. perf(agc): borrow an aliased storage image's units across bases and sizes, one 64 KiB tile at a time.
    • When two units are one tile with the same layout. A unit of image A and the unit of image B over the same 64 KiB guest block hold the same elements at the same bytes when all of these hold:
      • both are block-unit storage images (64 KiB-aligned base, thin, tiled);
      • they have the same tile mode, bytes per element and pipe/bank XOR, and no block compression;
      • the mode's swizzle equation uses only coordinate bits inside the block (swizzleWithinBlock; for SW_64KB_R_X at 4 bytes, x and y bits 0-6 plus the slice);
      • in each image the unit is exactly one tile block of a mip that isn't a tail;
      • both lie in the same array slice;
      • the element rectangle each image holds in that tile is the same size.
    • Then one vkCmdCopyImage region, from B's tile to A's tile at their own tile coordinates, moves the block bit for bit.
    • Equal extents are required, not just "fits inside": a lender holding elements the borrower lacks couldn't be superseded when the borrower writes, and both images would stay pending over the block.
    • The refresh, per alias and per overlapping unit, carries the rules above over unit by unit:
      • an untracked range, a generation-0 pending unit, or an unstamped unit pending in both still refuses the alias;
      • a unit another kept alias also has pending refuses the later alias, so no block has two lenders;
      • a stamped unit stays the alias's own;
      • a pending, unstamped unit that the copy can't take is stored before the refresh's flush, over that unit's range only.
    • The same-surface image keeps priority.
    • Still on the round trip, per unit:
      • mip-tail blocks;
      • a short last unit;
      • an edge tile of another extent;
      • another array slice, element size, pipe/bank XOR or tile mode;
      • swizzles that reach outside the block (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.

  • Its review asked for a before/after on a default configuration.
  • This change is on by default (APS5_NO_ALIAS_BORROW=1 turns it off), needs no host import, and copies image to image.
  • Its before/after is the round trip's bytes in the tests below. Village is covered below.

Resident Evil Village (PPSA01556)

Static menu, profiled boot (APS5_PROFILE_DRAW=1) on main ebb4075168 plus #12478, without this change. Its 10 s [storage] lines at the menu show:

  • 2.4-4.8 GB of storage refresh write-backs;
  • as much again in flushed CPU uploads;
  • 0 bytes on the device alias path.

The highest window:

[storage] uploads by path (count/MiB, 10 s): clear 27/101.2 direct 353/1386.4 cpu 357/5096.9 alias 0/0.0; by reason: cpu 28/446.2 flushed 356/4819.4 keys 27/101.2 shadow 298/325.1 store 28/892.5; write-backs by reason (count/MiB): imported buffer region 54/443.8 memory access 27/860.6 readback before label 189/11.8 refresh 83/262.9 stencil plane store 27/121.5 storage refresh 1150/4691.4 written buffer range 55/165.8; ...

The first four commits alone don't take Village's pairs.

  • The check: a boot with them and a per-pair refusal trace ran on the menu tree. Every refusal was "base differs" or "size differs".
  • Why: Village's images are a transient pool at other bases and sizes over the same memory: 1920x1080, 960x1080 with 4 mips, 120x2160 and 120x68. All are format 36, tile mode 7, 64 KiB-aligned.
  • Commits 6 and 7 are for that shape: with the same 64 KiB tile mode and element size, a 64 KiB block holds one whole tile in both images. Only tail blocks, partial edge tiles and other slices keep the round trip.
  • No Village speed claim. A diagnostic build that skips this round trip altogether, copying nothing and leaving the stale image, made the menu's frame rate move only within its run-to-run spread. That diagnostic was combined with one other switch, against its own control. The committer's per-frame draw time didn't fall either. Village's menu is limited elsewhere, so this PR stands on the bytes it removes in the cases the tests cover.

Tested

New tests. Each runs agc_driver_recorder_tests with its own --…-only switch. 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):

    • Case A: R32 is left pending on the GPU. The RGBA8 refresh must leave it pending, so it wasn't written back, and must sample its value.
    • Case B: R32 is pending on units 1-3 only, and a driver store hits unit 0.
      • The refresh must upload unit 0 and take units 1-3 after that upload.
      • A second store and refresh replaces the held units, and they must be borrowed again.
      • Then a write-back of the RGBA8 image leaves nothing pending, and guest memory holds the store and the R32 values.
  • 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.

    • Content: after every lookup, read back on the GPU, and guest memory after a flush, in a second pass.
    • Bytes: the counters behind the [storage] line, per step.
    • Assertion, for the pair this change covers (cached RGBA8/R32, copied memory): 0 storage refresh write-backs, 0 flushed uploads, no other reason taking their place, and one device copy per lookup after a write (7 × 256 KiB).
    • Before this change: the same steps moved 7 × 256 KiB each way through host memory.
    • Printed, not asserted: the other pairs (different dimensions; tiled against linear), images made outside the cache, and imported memory. On lavapipe imported memory is compared, not watched, so the alias is refused as untracked. All of these keep the round trip.
  • agc_storage_alias_blocks (commit 7): R32 images in tile mode 7 (R 64 KiB X), cached, over copied write-watched memory.

    • Each case: X is written, Y looked up, Y written, X looked up, for two rounds.
    • Two runs per case: stored (FlushPending after every write, the old path) and borrowed (no stores). The patterns differ per texel, mip, image and round.
    • Content: after every lookup, the looked-up image holds the same texels in both runs, at every mip. After the final flush, guest memory is byte-identical between the runs.
    • Bytes, borrowed run:
      • every block taken on the device is unchanged in guest memory by the lookup;
      • every fallback block received the other image's results first;
      • the alias copies are exactly the taken units × 64 KiB;
      • with no fallback blocks there is no storage refresh write-back.
      Case (Village's shapes, scaled) Y lookup X lookup
      512x128 two units into 256x256 takes blocks 2-3 (128 KiB), no store takes blocks 2-3, no store
      128x128 at the base of 256x256 takes block 0 (64 KiB) takes block 0
      128x64 at the base of 256x256 (a partial tile) nothing taken; block 0 stored (old path) nothing taken; block 0 stored
      512x128 over a 256x256 four-mip chain takes blocks 1-3 (192 KiB); tail block 0 stored, then uploaded takes blocks 1-3; block 0 stored
  • 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: no storage refresh write-back, no flushed upload, and 7 whole-surface alias copies (7 × 256 KiB).

Reds (Linux). Each was built from the named commit with only the named change:

commit change result
1 Texture.cpp from main agc_storage_alias_borrow case A: "refreshing the RGBA8 image over the surface wrote the pending R32 image back instead of taking its units on the device"
1 APS5_NO_ALIAS_BORROW=1 case A, same message
1 the borrow before the upload, as on main case B: "the RGBA8 image sampled 16.000000 after a refresh that uploaded unit 0 from guest memory and took units 1-3 from the R32 image, expected 4"
1 held units not borrowed again case B: "... sampled 16.000000 in a unit it held from the R32 image after a second driver store over unit 0 and refresh, expected 4"
1 hook flushes don't leave the alias out case B: "refreshing the RGBA8 image after a driver store over unit 0 wrote back the R32 image pending over units 1-3"
2 commit 2's change reverted, test from commit 4 agc_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"
3 commit 1's Texture.cpp agc_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"
4 Texture.cpp from main agc_storage_alias_round_trip: "'storage refresh' write-backs 7x 1835008 bytes, although the device handoff covers this pair"
7 commit 5's code, commit 7's tests 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"
7 the lender's region taken at the borrower's tile coordinates (a mutation) agc_storage_alias_blocks content 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_trip fails too

Linux 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:

    • commit 1: 1,135 tests, 0 failed, 75 skipped by their own skip code (no udmabuf, llvmpipe);
    • commit 3: 1,136 tests, 0 failed, 75 skipped;
    • commits 1, 2 and 4 together: 1,136 tests, 0 failed, 75 skipped.
  • commits 6 and 7: ctest -R '^agc' once, 1,139 tests (agc_storage_alias_blocks added), 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:

  • Commits 6 and 7 against commit 5 (run): the alias tests and the storage tests around them.
    • Linux: 84 tests, all 10 runs passed, 8 skipped. With commit 5's code, agc_storage_alias_blocks and agc_storage_alias_round_trip fail with the messages above.
    • Windows: 100 tests, 4 run and passed, 96 skipped (no Vulkan device).
    • Suites: libc and libkernel pass: 198 and 304 tests on Linux, 225 and 326 on Windows.
  • Commit 5, with the merge of main (run): the three new tests, main's new agc_storage_typed_fill_clear, and the storage tests around them.
    • Linux: 84 tests, all 10 runs passed, 8 skipped.
    • Windows: 100 tests, 4 run and passed, 96 skipped (no Vulkan device).
    • Suites: libc and libkernel pass: 198 and 304 tests on Linux, 225 and 326 on Windows.
  • The four commits on 08a10d2253 (run): the three new tests plus the storage tests around them.
    • Linux: 83 tests, all 10 runs passed, 8 skipped.
    • Windows: 99 tests, 4 run and passed, 95 skipped (no Vulkan device).
    • main's arm doesn't build there, because the round-trip test reads a test-only accessor in Texture.hpp. The reds above are the per-commit ones.
  • Earlier, commit 1 alone (run):
    • Linux: 81 tests ×10, all passed, 8 skipped.
    • Windows: 97 tests, 4 run and passed, 93 skipped. The runner has no Vulkan device, so the GPU tests skip there, these included. No Windows red is claimed.
    • An unrelated failure: in that run, main's code also failed agc_driver_storage_read_during_idle_store once, at its own precondition ("the GPU producer left no pending image"). It passed on main in 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):

  • The layer loaded: inserted 80 times on main and 81 with the change, with 0 "was not found".
  • VUIDs: the only one is VUID-VkDeviceCreateInfo-pNext-pNext, on both. The change adds none.
  • Commit 3 against commit 1 (run, ×10): the same single VUID on both. The change adds none.
  • Commits 6 and 7 against commit 5 (run, the change ×20):
    • The layer loaded: inserted 77 times in commit 5's run and 1,408 times over the change's 20 runs, with 0 "was not found".
    • VUIDs: none on either side, so the change adds none.

Windows hardware, by DonRyuzaki (report): an AMD Radeon RX 7800 XT on Windows, head f6e8382ef4 merged onto main a992b80376, with ANYPS5_REQUIRE_VULKAN=1 and ANYPS5_NO_SHADER_CACHE=1. It is the first run of these tests on Windows hardware, since GitHub's Windows runner has no Vulkan device.

  • The four alias tests: agc_storage_alias_round_trip, agc_storage_alias_borrow, agc_storage_alias_blocks and agc_storage_alias_keys, 3 of 3 each, none skipped.
  • Profiled counts (APS5_PROFILE_DRAW=1): on the cached pairs over copied write-watched memory, 0 storage refresh write-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. In agc_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.
  • Not covered: the validation layer was requested and the focused logs show no VUID, but there was no paired main run, 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.py and check_test_registration.py pass.
  • MinGW-w64 -fsyntax-only on Texture.cpp and tests/Recorder.cpp shows no new diagnostic. Recorder.cpp stops at the same _fflush_nolock declaration gap as on main.

Overlap: checked with git merge-tree of this head against every open pull request that changes Texture.cpp or Texture.hpp.

  • #11485 (QRMOE) widens direct to surfaces over several imports.
    • The clash is one line: its direct = line and this PR's borrow condition. They compose: take #11485's direct and this PR's keys == DccKeys::Uncompressed condition.
    • Merge order: this PR goes second.
  • #7514 (AlxcBTW) answers the same lookups from an index.
    • In direct, the clash is the same kind of one-line overlap (HostImportForCached): take its lookup and keep this PR's test.
    • In the candidate scan it is semantic. #7514 walks its pending index from the image's own base and considers only an equal base and size. Commit 7 takes lenders at other bases and sizes, so on top of #7514 the walk has to start at the lowest base that can overlap the surface (or be an interval query). Otherwise a lender below the base is never visited.
    • It conflicts with main already, so whichever lands second rebases.
  • #10886 (meh7an) is now in main. The merge below keeps its UnitFlags borrowedUnits as the held bitmap and adds this PR's per-unit lender beside it.
  • #11485's semantic overlap, in commit 7's terms: take #11485's multi-import direct with 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.
  • #10940 and #11920 clash textually with commit 7:
    • #10940: FlushPending's registry filter; keep both conditions.
    • #11920: the alias copy's barrier and copy calls, which it routes through Resolved. The per-tile copy's calls can take the same form.
  • #12921 (ours) adds HintedComparison to Texture.hpp next to where commit 2 adds the lender's borrowers list. The clash is textual only: whichever lands second keeps both.
  • Test registrations: #10472, #12070, #12662 and #12980 add tests at the same places in the AGC CMakeLists.txt or tests/Recorder.cpp. The clashes are textual only: whichever lands second keeps both. main now conflicts the same way, through #9565's agc_recorder_command_buffer_release on the WIN32 test-list line, and the next merge of main keeps both names.
  • #15569 (milescoviello) wraps refresh's FlushPending call 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 read aliases.empty() in its orderedEligible. Either order works (note).
  • Merges cleanly: #13044 (Gonic0).
  • 8968153aaa, a merge of main 0a148be963 (run). #12862 moved libSceAgcDriver's test registrations into tests/cmake/; the conflict in CMakeLists.txt is resolved with tools/agc_test_split.py resolve, which moves this PR's registrations into tests/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 -N gives 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 with APS5_SKIP_TIMING_TESTS=1, which relaxes precise_wait's median bounds on GitHub's hosted runners.
  • d79032ae0b, a merge of main 2ff700fddf, which brings meh7an's #10886 (run).
    • The conflicts were Texture.hpp and two functions of Texture.cpp, markLayersPending and forgetBorrowed. #10886 stores borrowedUnits as a UnitFlags, where commit 6 kept a BorrowedUnit per unit with its lender, the lender's version and unit, and a held flag.
    • The resolution:
      • Whether a unit is borrowed stays in #10886's UnitFlags borrowedUnits.
      • The lender moves to a per-unit std::vector<BorrowedSource> borrowedSources beside 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.
      • #10886's AnyIn gate in markLayersPending and its SetRange clear in forgetBorrowed are kept, and this PR's two scans for a held unit became UnitFlags::Any().
      • Nothing else conflicted, and this PR's other changed lines are the same.
    • The count: with -DBUILD_TESTING=ON, ctest -N gives 3,130 tests: main 2ff700fddf's 3,126 plus this PR's 4, each listed once.
    • ×10: the storage-alias set with ^agc_storage, ^agc_driver_storage and #10886's agc_unit_flags_allocation_failure_*.
      • Linux: 30 run, 29 pass, 1 skip, 0 fail. The skip is agc_storage_clear_hand_over, since lavapipe imports no watched host memory.
      • Windows: 31 run, 2 pass, 29 skip (no Vulkan device), 0 fail. The 2 that pass are #10886's allocation-failure tests, which need no device.
      • Suites: libc and libkernel pass on Linux (199 and 308) and on Windows (226 and 330). The suites ran with APS5_SKIP_TIMING_TESTS=1, which relaxes precise_wait's median bounds on GitHub's hosted runners.
    • On a cloud Linux machine (lavapipe):
      • the full build passes;
      • the storage-alias set ×10: 11 run, 11 pass, 0 skip, 0 fail;
      • every test of agc_driver_recorder_tests: 85 run, 77 pass, 8 skip (host imports and the pipeline cache, which lavapipe lacks), 0 fail.
  • 3731709269: merges of main 88e804b0a7 (e75bd22604) and 3c3b3cda73 (3731709269).
    • e75bd22604 brings winstrex's #10026, which forgets a unit's unwatch hash where refresh() and writeBackLayers record its generation. The merge keeps those calls inside this PR's reworked loops: borrowUnits(aliases, …) and the borrowed[unit] >= 0 check in refresh(), and the held.empty() early return in writeBackLayers. In agc_driver_recorder_tests.cmake, both sides' registrations are kept.
    • 3731709269 brings TechLevelZero's #10940, which gives FlushPending a device. The pending-texture filter there keeps both conditions: this PR's alias exemption and #10940's device check.
    • This PR's diff over main is otherwise unchanged.
    • ×10 (run): the storage, unit-flag, pending-surface, command-buffer and unwatch tests, with 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 with APS5_SKIP_TIMING_TESTS=1, which relaxes precise_wait's median bounds on GitHub's hosted runners.
    • Every agc test, 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 is agc_driver_pipeline_journal's 120-second timeout, which main 88e804b0a7's own run of every test hits too (run).
  • 86168db6b6, a merge of main 4f41f4c375 (run).
    • The conflicts: three, each resolved by keeping both sides. In Texture.hpp, the conflict is next to main's new OccasionalLabelStores declaration, which stays. In tests/Recorder.cpp, #6905's SmallElementDetileTest and this PR's storageAliasBorrowTests both landed before main(), and both stay. In tests/cmake/agc_driver_recorder_tests.cmake, the Windows ENVIRONMENT_MODIFICATION list, where main adds agc_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.
    • ×10: agc_changed_copy and every test matching ^agc_storage, which takes in this PR's agc_storage_alias_* tests and #14302's agc_storage_rewritten_blocks and agc_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 with APS5_SKIP_TIMING_TESTS=1, which relaxes precise_wait's median bounds on GitHub's hosted runners.
  • 13f688c15b, a merge of main 086c0686c8 (run).
    • The conflict: one, in tests/cmake/agc_driver_recorder_tests.cmake, in the same Windows ENVIRONMENT_MODIFICATION list, where savvaniss's #9898 adds agc_recorder_stored_bytes. The resolution is again the union of both sides' names, each once. This PR's diff over main is unchanged.
    • ×10: agc_changed_copy, agc_recorder_stored_bytes and 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 with APS5_SKIP_TIMING_TESTS=1, which relaxes precise_wait's median bounds on GitHub's hosted runners.
  • 2283625557, a merge of main 1c8c0efc8c, which brings PrivacyOnion's #14868 (run).
    • The conflict: one, in Texture.cpp's refresh. #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 over main is unchanged.
    • ×10: 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 with APS5_SKIP_TIMING_TESTS=1, which relaxes precise_wait's median bounds on GitHub's hosted runners.
  • f6e8382ef4, a merge of main c2eafe4461, which brings oneandonlydean's #14261 (×10).
    • The conflict: one, in tests/cmake/agc_driver_recorder_tests.cmake, in the same Windows ENVIRONMENT_MODIFICATION list, where #14261 adds agc_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.
    • ×10: agc_changed_copy, agc_recorder_stored_bytes, #14261's agc_untracked_forget 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 301 and 325 tests on Linux and 331 and 343 on Windows, with 0 failed. The suites ran with APS5_SKIP_TIMING_TESTS=1, which relaxes precise_wait's median bounds on GitHub's hosted runners.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: #11485 (merge order only)
  • Fixes: none
  • Unblocks: none
  • GPUs tested: llvmpipe (LLVM 20.1.2, Mesa 25.2.8) on Ubuntu 24.04 (GitHub's runner and Linux VMs); the Resident Evil Village menu profiled on an RTX 3070 Laptop GPU (without commits 6 and 7)
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5081238859 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/13251). Originally posted by [EagleBearerYS](https://github.com/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::refresh` can take those results on the device. `borrowUnits` records one `vkCmdCopyImage` of the other image's pending units. On `main` that 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.cpp` L2196 and L2342 on 08a10d2253). Without an import, the refresh takes the round trip instead: 1. it waits for the other image's writer; 2. it reads that image back and stores it to guest memory, the `storage refresh` write-back; 3. it uploads the whole refreshed image again from guest memory on the CPU path, the `flushed` upload. The four commits: 1. **`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: - **The upload runs before the borrow.** The upload is then the CPU path, and for a 2D image it replaces the whole image, borrowed units included. Units held from an earlier borrow that the upload replaced (`forgetBorrowed`) are borrowed again. - **The refresh's own reads don't store the alias.** The compare with the saved bytes and the CPU upload's `ReadCommitted` go through the recorder's memory-access hook, which would store the alias anyway. While a kept alias is being refreshed over, `FlushPending` leaves it out, exactly as the refresh's own flush already does. A thread-local `refreshingAlias` sits next to `refreshing`. 2. **`fix(agc)`: advance a borrower's generation past its lender's write-back.** - **The gap:** after a borrow, the borrower keeps the generation it had at the borrow. If the lender then stores those units (any flush or CPU read of the range), and the borrower is written without another refresh, the borrower's own write-back takes those blocks as CPU-stamped. It keeps the guest bytes and loses its newer results. - **On `main`:** the gap exists only with a write-watched host import. Commit 1 would widen it to every surface. - **The fix:** a lender now remembers its borrowers. Its write-back advances the units they still hold at the lent version past its own stamps, as it already does for adjacent pending images (`advanceAdjacent`). 3. **`fix(agc)`: store a kept alias when the refreshed image's keys aren't uncompressed.** - **The gap:** the alias is kept on the keys proved before the refresh's flush, and that flush can store keys itself (main's comment above L2196). If the keys proved after it aren't Uncompressed, the borrow doesn't run while the alias is still exempt. - **The fix:** the refresh ends the exemption there, drops the alias, stores it as a refresh without an alias does, and proves the keys again. All of this happens before anything reads the surface for the upload. - **On `main`:** the same gap exists on the import path. 4. **`test(agc)`: measure the round trip and assert what the handoff removes** (below). **Unchanged:** the conditions for keeping the alias are main's. - The keys must be Uncompressed and the memory tracked. - Each pending unit of the alias must be either borrowable (unstamped since its generation, and not pending in the refreshed image) or stamped since. A stamped unit is one the alias's own write-back would drop anyway. - An untracked surface, a pending unit with generation 0, or an unstamped unit pending in both images still refuses the alias. - The alias stays pending until the refreshed image is written and supersedes those units, so a CPU read still stores it. The fifth commit merges `main` (f7f03daf52). #12559 and #12927 had added tests at the same places in `tests/Recorder.cpp` and the AGC `CMakeLists.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.** 6. **`refactor(agc)`: keep a storage image's borrowed units per unit and per lender.** No behaviour change on its own. - `borrowedFrom`/`borrowedVersion` become one `BorrowedUnit{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. - A write (`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). `refreshingAlias` becomes a set, and `FlushPending` without an `except` leaves out every kept alias, as it did for the single one. 7. **`perf(agc)`: borrow an aliased storage image's units across bases and sizes, one 64 KiB tile at a time.** - **When two units are one tile with the same layout.** A unit of image A and the unit of image B over the same 64 KiB guest block hold the same elements at the same bytes when all of these hold: - both are block-unit storage images (64 KiB-aligned base, thin, tiled); - they have the same tile mode, bytes per element and pipe/bank XOR, and no block compression; - the mode's swizzle equation uses only coordinate bits inside the block (`swizzleWithinBlock`; for SW_64KB_R_X at 4 bytes, x and y bits 0-6 plus the slice); - in each image the unit is exactly one tile block of a mip that isn't a tail; - both lie in the same array slice; - the element rectangle each image holds in that tile is the same size. - Then one `vkCmdCopyImage` region, from B's tile to A's tile at their own tile coordinates, moves the block bit for bit. - Equal extents are required, not just "fits inside": a lender holding elements the borrower lacks couldn't be superseded when the borrower writes, and both images would stay pending over the block. - **The refresh,** per alias and per overlapping unit, carries the rules above over unit by unit: - an untracked range, a generation-0 pending unit, or an unstamped unit pending in both still refuses the alias; - a unit another kept alias also has pending refuses the later alias, so no block has two lenders; - a stamped unit stays the alias's own; - a pending, unstamped unit that the copy can't take is stored before the refresh's flush, over that unit's range only. - The same-surface image keeps priority. - **Still on the round trip,** per unit: - mip-tail blocks; - a short last unit; - an edge tile of another extent; - another array slice, element size, pipe/bank XOR or tile mode; - swizzles that reach outside the block (`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. - Its review asked for a before/after on a default configuration. - This change is on by default (`APS5_NO_ALIAS_BORROW=1` turns it off), needs no host import, and copies image to image. - Its before/after is the round trip's bytes in the tests below. Village is covered below. ### Resident Evil Village (PPSA01556) Static menu, profiled boot (`APS5_PROFILE_DRAW=1`) on `main` ebb4075168 plus #12478, without this change. Its 10 s `[storage]` lines at the menu show: - 2.4-4.8 GB of `storage refresh` write-backs; - as much again in `flushed` CPU uploads; - 0 bytes on the device alias path. The highest window: ``` [storage] uploads by path (count/MiB, 10 s): clear 27/101.2 direct 353/1386.4 cpu 357/5096.9 alias 0/0.0; by reason: cpu 28/446.2 flushed 356/4819.4 keys 27/101.2 shadow 298/325.1 store 28/892.5; write-backs by reason (count/MiB): imported buffer region 54/443.8 memory access 27/860.6 readback before label 189/11.8 refresh 83/262.9 stencil plane store 27/121.5 storage refresh 1150/4691.4 written buffer range 55/165.8; ... ``` **The first four commits alone don't take Village's pairs.** - **The check:** a boot with them and a per-pair refusal trace ran on the menu tree. Every refusal was "base differs" or "size differs". - **Why:** Village's images are a transient pool at other bases and sizes over the same memory: 1920x1080, 960x1080 with 4 mips, 120x2160 and 120x68. All are format 36, tile mode 7, 64 KiB-aligned. - **Commits 6 and 7 are for that shape:** with the same 64 KiB tile mode and element size, a 64 KiB block holds one whole tile in both images. Only tail blocks, partial edge tiles and other slices keep the round trip. - **No Village speed claim.** A diagnostic build that skips this round trip altogether, copying nothing and leaving the stale image, made the menu's frame rate move only within its run-to-run spread. That diagnostic was combined with one other switch, against its own control. The committer's per-frame draw time didn't fall either. Village's menu is limited elsewhere, so this PR stands on the bytes it removes in the cases the tests cover. ### Tested **New tests.** Each runs `agc_driver_recorder_tests` with its own `--…-only` switch. 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):** - **Case A:** R32 is left pending on the GPU. The RGBA8 refresh must leave it pending, so it wasn't written back, and must sample its value. - **Case B:** R32 is pending on units 1-3 only, and a driver store hits unit 0. - The refresh must upload unit 0 and take units 1-3 after that upload. - A second store and refresh replaces the held units, and they must be borrowed again. - Then a write-back of the RGBA8 image leaves nothing pending, and guest memory holds the store and the R32 values. - **`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. - **Content:** after every lookup, read back on the GPU, and guest memory after a flush, in a second pass. - **Bytes:** the counters behind the `[storage]` line, per step. - **Assertion, for the pair this change covers** (cached RGBA8/R32, copied memory): 0 `storage refresh` write-backs, 0 `flushed` uploads, no other reason taking their place, and one device copy per lookup after a write (7 × 256 KiB). - **Before this change:** the same steps moved 7 × 256 KiB each way through host memory. - **Printed, not asserted:** the other pairs (different dimensions; tiled against linear), images made outside the cache, and imported memory. On lavapipe imported memory is compared, not watched, so the alias is refused as untracked. All of these keep the round trip. - **`agc_storage_alias_blocks` (commit 7):** R32 images in tile mode 7 (R 64 KiB X), cached, over copied write-watched memory. - **Each case:** X is written, Y looked up, Y written, X looked up, for two rounds. - **Two runs per case:** *stored* (`FlushPending` after every write, the old path) and *borrowed* (no stores). The patterns differ per texel, mip, image and round. - **Content:** after every lookup, the looked-up image holds the same texels in both runs, at every mip. After the final flush, guest memory is byte-identical between the runs. - **Bytes, borrowed run:** - every block taken on the device is unchanged in guest memory by the lookup; - every fallback block received the other image's results first; - the `alias` copies are exactly the taken units × 64 KiB; - with no fallback blocks there is no `storage refresh` write-back. | Case (Village's shapes, scaled) | Y lookup | X lookup | |---|---|---| | 512x128 two units into 256x256 | takes blocks 2-3 (128 KiB), no store | takes blocks 2-3, no store | | 128x128 at the base of 256x256 | takes block 0 (64 KiB) | takes block 0 | | 128x64 at the base of 256x256 (a partial tile) | nothing taken; block 0 stored (old path) | nothing taken; block 0 stored | | 512x128 over a 256x256 four-mip chain | takes blocks 1-3 (192 KiB); tail block 0 stored, then uploaded | takes blocks 1-3; block 0 stored | - **`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: no `storage refresh` write-back, no `flushed` upload, and 7 whole-surface `alias` copies (7 × 256 KiB). **Reds** (Linux). Each was built from the named commit with only the named change: | commit | change | result | |---|---|---| | 1 | `Texture.cpp` from `main` | `agc_storage_alias_borrow` case A: "refreshing the RGBA8 image over the surface wrote the pending R32 image back instead of taking its units on the device" | | 1 | `APS5_NO_ALIAS_BORROW=1` | case A, same message | | 1 | the borrow before the upload, as on `main` | case B: "the RGBA8 image sampled 16.000000 after a refresh that uploaded unit 0 from guest memory and took units 1-3 from the R32 image, expected 4" | | 1 | held units not borrowed again | case B: "... sampled 16.000000 in a unit it held from the R32 image after a second driver store over unit 0 and refresh, expected 4" | | 1 | hook flushes don't leave the alias out | case B: "refreshing the RGBA8 image after a driver store over unit 0 wrote back the R32 image pending over units 1-3" | | 2 | commit 2's change reverted, test from commit 4 | `agc_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" | | 3 | commit 1's `Texture.cpp` | `agc_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" | | 4 | `Texture.cpp` from `main` | `agc_storage_alias_round_trip`: "'storage refresh' write-backs 7x 1835008 bytes, although the device handoff covers this pair" | | 7 | commit 5's code, commit 7's tests | `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" | | 7 | the lender's region taken at the borrower's tile coordinates (a mutation) | `agc_storage_alias_blocks` content 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_trip` fails too | **Linux 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: - commit 1: 1,135 tests, 0 failed, 75 skipped by their own skip code (no udmabuf, llvmpipe); - commit 3: 1,136 tests, 0 failed, 75 skipped; - commits 1, 2 and 4 together: 1,136 tests, 0 failed, 75 skipped. - commits 6 and 7: `ctest -R '^agc'` once, 1,139 tests (`agc_storage_alias_blocks` added), 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:** - **Commits 6 and 7 against commit 5** ([run](https://github.com/EagleBearerYS/AnyPS5/actions/runs/41033946475)): the alias tests and the storage tests around them. - **Linux:** 84 tests, all 10 runs passed, 8 skipped. With commit 5's code, `agc_storage_alias_blocks` and `agc_storage_alias_round_trip` fail with the messages above. - **Windows:** 100 tests, 4 run and passed, 96 skipped (no Vulkan device). - **Suites:** libc and libkernel pass: 198 and 304 tests on Linux, 225 and 326 on Windows. - **Commit 5, with the merge of `main`** ([run](https://github.com/EagleBearerYS/AnyPS5/actions/runs/41017805456)): the three new tests, `main`'s new `agc_storage_typed_fill_clear`, and the storage tests around them. - **Linux:** 84 tests, all 10 runs passed, 8 skipped. - **Windows:** 100 tests, 4 run and passed, 96 skipped (no Vulkan device). - **Suites:** libc and libkernel pass: 198 and 304 tests on Linux, 225 and 326 on Windows. - **The four commits on 08a10d2253** ([run](https://github.com/EagleBearerYS/AnyPS5/actions/runs/41014014638)): the three new tests plus the storage tests around them. - **Linux:** 83 tests, all 10 runs passed, 8 skipped. - **Windows:** 99 tests, 4 run and passed, 95 skipped (no Vulkan device). - **`main`'s arm doesn't build** there, because the round-trip test reads a test-only accessor in `Texture.hpp`. The reds above are the per-commit ones. - **Earlier, commit 1 alone** ([run](https://github.com/EagleBearerYS/AnyPS5/actions/runs/41007390863)): - **Linux:** 81 tests ×10, all passed, 8 skipped. - **Windows:** 97 tests, 4 run and passed, 93 skipped. The runner has no Vulkan device, so the GPU tests skip there, these included. No Windows red is claimed. - **An unrelated failure:** in that run, `main`'s code also failed `agc_driver_storage_read_during_idle_store` once, at its own precondition ("the GPU producer left no pending image"). It passed on `main` in 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](https://github.com/EagleBearerYS/AnyPS5/actions/runs/41010746081)): - **The layer loaded:** inserted 80 times on `main` and 81 with the change, with 0 "was not found". - **VUIDs:** the only one is `VUID-VkDeviceCreateInfo-pNext-pNext`, on both. The change adds none. - **Commit 3 against commit 1** ([run](https://github.com/EagleBearerYS/AnyPS5/actions/runs/41011011439), ×10): the same single VUID on both. The change adds none. - **Commits 6 and 7 against commit 5** ([run](https://github.com/EagleBearerYS/AnyPS5/actions/runs/41041151333), the change ×20): - **The layer loaded:** inserted 77 times in commit 5's run and 1,408 times over the change's 20 runs, with 0 "was not found". - **VUIDs:** none on either side, so the change adds none. **Windows hardware, by DonRyuzaki** ([report](https://github.com/boykopovar/AnyPS5/pull/13251#issuecomment-6645840164)): an AMD Radeon RX 7800 XT on Windows, head f6e8382ef4 merged onto `main` a992b80376, with `ANYPS5_REQUIRE_VULKAN=1` and `ANYPS5_NO_SHADER_CACHE=1`. It is the first run of these tests on Windows hardware, since GitHub's Windows runner has no Vulkan device. - **The four alias tests:** `agc_storage_alias_round_trip`, `agc_storage_alias_borrow`, `agc_storage_alias_blocks` and `agc_storage_alias_keys`, 3 of 3 each, none skipped. - **Profiled counts** (`APS5_PROFILE_DRAW=1`): on the cached pairs over copied write-watched memory, 0 `storage refresh` write-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. In `agc_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. - **Not covered:** the validation layer was requested and the focused logs show no VUID, but there was no paired `main` run, 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.py` and `check_test_registration.py` pass. - MinGW-w64 `-fsyntax-only` on `Texture.cpp` and `tests/Recorder.cpp` shows no new diagnostic. `Recorder.cpp` stops at the same `_fflush_nolock` declaration gap as on `main`. **Overlap:** checked with `git merge-tree` of this head against every open pull request that changes `Texture.cpp` or `Texture.hpp`. - **#11485 (QRMOE)** widens `direct` to surfaces over several imports. - The clash is one line: its `direct =` line and this PR's borrow condition. They compose: take #11485's `direct` and this PR's `keys == DccKeys::Uncompressed` condition. - Merge order: this PR goes second. - **#7514 (AlxcBTW)** answers the same lookups from an index. - In `direct`, the clash is the same kind of one-line overlap (`HostImportForCached`): take its lookup and keep this PR's test. - **In the candidate scan it is semantic.** #7514 walks its pending index from the image's own base and considers only an equal base and size. Commit 7 takes lenders at other bases and sizes, so on top of #7514 the walk has to start at the lowest base that can overlap the surface (or be an interval query). Otherwise a lender below the base is never visited. - It conflicts with `main` already, so whichever lands second rebases. - **#10886 (meh7an)** is now in `main`. The merge below keeps its `UnitFlags borrowedUnits` as the held bitmap and adds this PR's per-unit lender beside it. - **#11485's semantic overlap,** in commit 7's terms: take #11485's multi-import `direct` with 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. - **#10940 and #11920** clash textually with commit 7: - #10940: `FlushPending`'s registry filter; keep both conditions. - #11920: the alias copy's barrier and copy calls, which it routes through `Resolved`. The per-tile copy's calls can take the same form. - **#12921 (ours)** adds `HintedComparison` to `Texture.hpp` next to where commit 2 adds the lender's `borrowers` list. The clash is textual only: whichever lands second keeps both. - **Test registrations:** #10472, #12070, #12662 and #12980 add tests at the same places in the AGC `CMakeLists.txt` or `tests/Recorder.cpp`. The clashes are textual only: whichever lands second keeps both. `main` now conflicts the same way, through #9565's `agc_recorder_command_buffer_release` on the WIN32 test-list line, and the next merge of `main` keeps both names. - **#15569 (milescoviello)** wraps `refresh`'s `FlushPending` call 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 read `aliases.empty()` in its `orderedEligible`. Either order works ([note](https://github.com/boykopovar/AnyPS5/pull/15569#issuecomment-6616868752)). - **Merges cleanly:** #13044 (Gonic0). - **8968153aaa, a merge of `main` 0a148be963** ([run](https://github.com/EagleBearerYS/AnyPS5/actions/runs/41264782186)). #12862 moved `libSceAgcDriver`'s test registrations into `tests/cmake/`; the conflict in `CMakeLists.txt` is resolved with `tools/agc_test_split.py resolve`, which moves this PR's registrations into `tests/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 -N` gives 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 with `APS5_SKIP_TIMING_TESTS=1`, which relaxes `precise_wait`'s median bounds on GitHub's hosted runners. - **d79032ae0b, a merge of `main` 2ff700fddf**, which brings meh7an's #10886 ([run](https://github.com/EagleBearerYS/AnyPS5/actions/runs/41273284562)). - **The conflicts** were `Texture.hpp` and two functions of `Texture.cpp`, `markLayersPending` and `forgetBorrowed`. #10886 stores `borrowedUnits` as a `UnitFlags`, where commit 6 kept a `BorrowedUnit` per unit with its lender, the lender's version and unit, and a held flag. - **The resolution:** - Whether a unit is borrowed stays in #10886's `UnitFlags borrowedUnits`. - The lender moves to a per-unit `std::vector<BorrowedSource> borrowedSources` beside 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. - #10886's `AnyIn` gate in `markLayersPending` and its `SetRange` clear in `forgetBorrowed` are kept, and this PR's two scans for a held unit became `UnitFlags::Any()`. - Nothing else conflicted, and this PR's other changed lines are the same. - **The count:** with `-DBUILD_TESTING=ON`, `ctest -N` gives 3,130 tests: `main` 2ff700fddf's 3,126 plus this PR's 4, each listed once. - **×10:** the storage-alias set with `^agc_storage`, `^agc_driver_storage` and #10886's `agc_unit_flags_allocation_failure_*`. - Linux: 30 run, 29 pass, 1 skip, 0 fail. The skip is `agc_storage_clear_hand_over`, since lavapipe imports no watched host memory. - Windows: 31 run, 2 pass, 29 skip (no Vulkan device), 0 fail. The 2 that pass are #10886's allocation-failure tests, which need no device. - Suites: libc and libkernel pass on Linux (199 and 308) and on Windows (226 and 330). The suites ran with `APS5_SKIP_TIMING_TESTS=1`, which relaxes `precise_wait`'s median bounds on GitHub's hosted runners. - **On a cloud Linux machine (lavapipe):** - the full build passes; - the storage-alias set ×10: 11 run, 11 pass, 0 skip, 0 fail; - every test of `agc_driver_recorder_tests`: 85 run, 77 pass, 8 skip (host imports and the pipeline cache, which lavapipe lacks), 0 fail. - **3731709269: merges of `main` 88e804b0a7 (e75bd22604) and 3c3b3cda73 (3731709269).** - **e75bd22604** brings winstrex's #10026, which forgets a unit's unwatch hash where `refresh()` and `writeBackLayers` record its generation. The merge keeps those calls inside this PR's reworked loops: `borrowUnits(aliases, …)` and the `borrowed[unit] >= 0` check in `refresh()`, and the `held.empty()` early return in `writeBackLayers`. In `agc_driver_recorder_tests.cmake`, both sides' registrations are kept. - **3731709269** brings TechLevelZero's #10940, which gives `FlushPending` a device. The pending-texture filter there keeps both conditions: this PR's alias exemption and #10940's device check. - This PR's diff over `main` is otherwise unchanged. - **×10** ([run](https://github.com/EagleBearerYS/AnyPS5/actions/runs/41434007786)): the storage, unit-flag, pending-surface, command-buffer and unwatch tests, with `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 with `APS5_SKIP_TIMING_TESTS=1`, which relaxes `precise_wait`'s median bounds on GitHub's hosted runners. - **Every `agc` test, once** ([run](https://github.com/EagleBearerYS/AnyPS5/actions/runs/41437707672)): 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 is `agc_driver_pipeline_journal`'s 120-second timeout, which `main` 88e804b0a7's own run of every test hits too ([run](https://github.com/EagleBearerYS/AnyPS5/actions/runs/41424465991)). - **86168db6b6, a merge of `main` 4f41f4c375** ([run](https://github.com/EagleBearerYS/AnyPS5/actions/runs/41602318712)). - **The conflicts:** three, each resolved by keeping both sides. In `Texture.hpp`, the conflict is next to `main`'s new `OccasionalLabelStores` declaration, which stays. In `tests/Recorder.cpp`, #6905's `SmallElementDetileTest` and this PR's `storageAliasBorrowTests` both landed before `main()`, and both stay. In `tests/cmake/agc_driver_recorder_tests.cmake`, the Windows `ENVIRONMENT_MODIFICATION` list, where `main` adds `agc_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. - **×10:** `agc_changed_copy` and every test matching `^agc_storage`, which takes in this PR's `agc_storage_alias_*` tests and #14302's `agc_storage_rewritten_blocks` and `agc_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 with `APS5_SKIP_TIMING_TESTS=1`, which relaxes `precise_wait`'s median bounds on GitHub's hosted runners. - **13f688c15b, a merge of `main` 086c0686c8** ([run](https://github.com/EagleBearerYS/AnyPS5/actions/runs/41703731386)). - **The conflict:** one, in `tests/cmake/agc_driver_recorder_tests.cmake`, in the same Windows `ENVIRONMENT_MODIFICATION` list, where savvaniss's #9898 adds `agc_recorder_stored_bytes`. The resolution is again the union of both sides' names, each once. This PR's diff over `main` is unchanged. - **×10:** `agc_changed_copy`, `agc_recorder_stored_bytes` and 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 with `APS5_SKIP_TIMING_TESTS=1`, which relaxes `precise_wait`'s median bounds on GitHub's hosted runners. - **2283625557, a merge of `main` 1c8c0efc8c,** which brings PrivacyOnion's #14868 ([run](https://github.com/EagleBearerYS/AnyPS5/actions/runs/41731393886)). - **The conflict:** one, in `Texture.cpp`'s `refresh`. #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 over `main` is unchanged. - **×10:** `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 with `APS5_SKIP_TIMING_TESTS=1`, which relaxes `precise_wait`'s median bounds on GitHub's hosted runners. - **f6e8382ef4, a merge of `main` c2eafe4461,** which brings oneandonlydean's #14261 ([×10](https://github.com/EagleBearerYS/AnyPS5/actions/runs/41774245700)). - **The conflict:** one, in `tests/cmake/agc_driver_recorder_tests.cmake`, in the same Windows `ENVIRONMENT_MODIFICATION` list, where #14261 adds `agc_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. - **×10:** `agc_changed_copy`, `agc_recorder_stored_bytes`, #14261's `agc_untracked_forget` 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 301 and 325 tests on Linux and 331 and 343 on Windows, with 0 failed. The suites ran with `APS5_SKIP_TIMING_TESTS=1`, which relaxes `precise_wait`'s median bounds on GitHub's hosted runners. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: #11485 (merge order only) - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: llvmpipe (LLVM 20.1.2, Mesa 25.2.8) on Ubuntu 24.04 (GitHub's runner and Linux VMs); the Resident Evil Village menu profiled on an RTX 3070 Laptop GPU (without commits 6 and 7) - [x] AI-assisted: yes
MarcZX10 commented 2026-11-20 06:51:23 +00:00 (Migrated from github.com)

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 read review/description.md, review/commits.md, review/manifest.json, and review/diff.patch, then used repo_read.py to inspect targeted ranges in Texture.cpp, Texture.hpp, Recorder.cpp, and agc_driver_recorder_tests.cmake. No tests were run.

Results

Check Result Note
Diff and changed-file inventory passed Five changed files identified
Targeted implementation review passed Alias planning, refresh, copies, and write-back inspected
Tests not run Existing test claims were not independently run

Findings

Blocking

None.

Non-blocking

None.

Not verified

Texture.cpp and Recorder.cpp were excluded from the review folder because they were too large; only targeted ranges were read through repo_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.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5988645679 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/13251#pullrequestreview-5988645679). Originally posted by [MarcZX10](https://github.com/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 read `review/description.md`, `review/commits.md`, `review/manifest.json`, and `review/diff.patch`, then used `repo_read.py` to inspect targeted ranges in `Texture.cpp`, `Texture.hpp`, `Recorder.cpp`, and `agc_driver_recorder_tests.cmake`. No tests were run. ## Results | Check | Result | Note | |---|---|---| | Diff and changed-file inventory | passed | Five changed files identified | | Targeted implementation review | passed | Alias planning, refresh, copies, and write-back inspected | | Tests | not run | Existing test claims were not independently run | ## Findings ### Blocking None. ### Non-blocking None. ## Not verified `Texture.cpp` and `Recorder.cpp` were excluded from the review folder because they were too large; only targeted ranges were read through `repo_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.
ligmaSec commented 2026-12-03 22:54:21 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T22:54:21Z.

Review: COMMENTED


The trial merge against main conflicts in Texture.cpp, Recorder.cpp and the recorder test registration. In StorageTexture::refresh, CPU-backed uploads now come before the borrowed GPU copies, including units restored from heldBorrows. 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.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6180071313 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/13251#pullrequestreview-6180071313). Originally posted by [ligmaSec](https://github.com/ligmaSec) on 2026-12-03T22:54:21Z. **Review:** COMMENTED --- The trial merge against `main` conflicts in `Texture.cpp`, `Recorder.cpp` and the recorder test registration. In `StorageTexture::refresh`, CPU-backed uploads now come before the borrowed GPU copies, including units restored from `heldBorrows`. 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.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/13251:upstream-pr/13251'
git switch 'upstream-pr/13251'

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.

git switch 'main'
git merge --no-ff 'upstream-pr/13251'
git switch 'upstream-pr/13251'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/13251'
git switch 'upstream-pr/13251'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/13251'
git switch 'main'
git merge --squash 'upstream-pr/13251'
git switch 'main'
git merge --ff-only 'upstream-pr/13251'
git switch 'main'
git merge 'upstream-pr/13251'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!13251
No description provided.