perf(agc): leave a linear storage write-back's row padding in the import #11615
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/11615"
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 dantdmdarealguy on 2026-10-26T22:52:56Z.
What
On ASTRO BOT (PPSA21564) the GPU spends most of each frame writing storage images back to guest memory. In the intro cutscene that is 41.8 ms of a 68.8 ms GPU batch per present (
APS5_PROFILE_GPU, classstorage-writeback,main6ea31b4e3awith #11307 applied). Most of it goes to three 240x135 linear images with 64 layers (format 71, 16.9 MiB each), each written back once per frame before a label. Each of those write-backs took 9.0 ms of GPU, and 7.2 ms of that was spent on padding.Why: a whole-layer GPU-direct write-back retiles the image into a device scratch buffer and copies whole ranges of the scratch into the host import. Since
a3ec50aefathe bytes no element holds are first copied from where they are current (a unit shadow, else the import) into the scratch, so that copying whole ranges back stores them unchanged. For a linear surface those bytes are the pitch padding of every row and the bytes between mips. Astro Bot's images have 1920-byte rows in a 2048-byte pitch, so each write-back recorded 8640 copies of 128 bytes out of host memory, followed by a copy of the whole range back into it. The many small reads of host memory cost far more than the elements themselves.The change: for a linear surface without tail mips,
CoveredMipBytesis exactly the bytes the retile writes, which are the rows without their padding. When every uncovered byte is current in the import (no unit shadow holds any of them) and no saved copy of the stored bytes is kept (saveUnitsempty, i.e. the memory is write-watched), the whole-layer write-back now leaves the padding where it is: it seeds nothing and copies only the rows from the scratch into the import. The import ends up holding the same bytes as before. Tiled surfaces, thick surfaces, surfaces with tail mips, shadowed padding and unwatched memory keep the seeded path, because there the covered bytes are not the whole retile, or the scratch's copy of the padding is needed.StorageTexture::PaddingSeedCopies()counts the padding pieces seeded into a write-back scratch, for the test.Tested
Rebased onto
main74acfad65as1f7bb91682(1 ahead, 0 behind, clean merge); the 32 focused tests (agc_storage_*,agc_driver_storage_*,agc_driver_linear_target_*,patched_libraries) pass there. The measurements below were taken on the commit before the rebase (same diff).Windows 11 Pro, Intel Core i9-14900K, 128 GB RAM, NVIDIA GeForce RTX 5080 (driver 32.0.16.1742), WinLibs GCC 15.2.0, Release.
agc_storage_write_back(agc_driver_recorder_tests --storage-write-back-only):PaddingSeedCopiesunchanged).(watched) linear 1000x700: the write-back copied 700 pieces of row padding from the import through its scratchand(watched) linear 1900x1100, 2 mips: ... 1650 pieces .... The byte checks pass either way.Validation layer:
^(agc_storage_|agc_driver_storage_|agc_driver_linear_target_), 31 tests.ctest -VandVK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation,ANYPS5_NO_SHADER_CACHE=1,ANYPS5_REQUIRE_VULKAN=1, the layer fromVK_ADD_LAYER_PATH.mainc7b4878fa8: 31/31 passed, 0VUID-. This change: 31/31 passed, 0VUID-.VK_LOADER_DEBUG=layershows the validation layer inserted 39 times in each log. Neither log containswas not found but was requested by env var VK_INSTANCE_LAYERS.Other checks:
ctest -R "^(agc_storage_|agc_driver_storage_|agc_driver_linear_target_)|patched_libraries": 32/32 passed.patched_libraries: 368 loaded, 0 failed.--target libspass, with no warnings in the touched files.tools/check_conventions.py --base origin/mainandtools/check_test_registration.pypass.ASTRO BOT (PPSA21564) 01.007.000: relinked with
--windows --registry --to-intel, 3840x2160, warm caches, scripted pad input. Same executable for every run; onlylibs/swapped. Runs alternated in one session.Plain
mainc7b4878fa8vs this change d1316d7cb0, logo phase,APS5_TRACE_SECONDS=5:30,APS5_TRACE_EVENTS=4194304:mainIntro cutscene with #11307 applied (on plain
mainthe intro is bound by the depth plane copy thrash #11307 fixes),main6ea31b4e3a+ #11307 (d92004fe06) vs the same + this change (0cbb504f20):APS5_TRACE_SECONDS=170:30and135:30respectively. The change loads the intro about 15-25 s earlier, so these put both windows 24-74 s into the intro cutscene, which the log confirms for every run.APS5_PROFILE_GPUin the intro: storage write-back 41.8 → 22.6 ms per present, GPU batch 68.8 → 49.5 ms. Every other class is unchanged.Traces (all
dropped: no):Every trace reports
dropped: no. Summary lines (rounds 1-3 onmain, then F-H with #11307):Round 1 on
mainc7b4878fa8vs this change,trace_digest.py --top 8main
c7b4878fa8seconds 5:30 from present 64: 498 presents, frame p50 61.8 / p90 66.9 / p99 70.4 / max 71.9 ms, GPU busy 50.7 ms per present
NVIDIA GeForce RTX 5080, NVIDIA 617.42, Windows 10.0.26300, 3840x2160, commit
c7b4878fa8, dropped: noSlowest frames (largest slices inside each, inclusive)
Threads (ms per frame)
Largest slices (ms per frame, inclusive, all threads): Driver.Packet 176.2, Driver.Packet.memory_wait 101.1, batch 50.7, Driver.WorkerWait 33.0, Driver.Packet.dispatch 27.9, Driver.WorkerWait.dequeue_order 27.1, Driver.Dispatch 21.7, Driver.Packet.prepare_memory 20.3
Longest waits
Largest GPU batches (GPU ranges inside, and the CPU slices that recorded each, inclusive)
this change d1316d7cb0
seconds 5:30 from present 98: 692 presents, frame p50 45.5 / p90 48.9 / p99 52.9 / max 56.1 ms, GPU busy 34.1 ms per present
NVIDIA GeForce RTX 5080, NVIDIA 617.42, Windows 10.0.26300, 3840x2160, commit d1316d7cb094, dropped: no
Slowest frames (largest slices inside each, inclusive)
Threads (ms per frame)
Largest slices (ms per frame, inclusive, all threads): Driver.Packet 125.4, Driver.Packet.memory_wait 71.7, batch 34.1, Driver.WorkerWait 30.9, Driver.WorkerWait.dequeue_order 24.2, Driver.Packet.dispatch 22.3, Driver.Dispatch 16.5, GpuMutex.wait.dispatch 11.3
Longest waits
Largest GPU batches (GPU ranges inside, and the CPU slices that recorded each, inclusive)
Round F, intro with #11307: d92004fe06 vs 0cbb504f20,
trace_digest.py --top 8#11307 (d92004fe06)
seconds 170:30 from present 2196: 376 presents, frame p50 79.6 / p90 84.3 / p99 90.6 / max 95.4 ms, GPU busy 65.7 ms per present
NVIDIA GeForce RTX 5080, NVIDIA 617.42, Windows 10.0.26300, 3840x2160, commit d92004fe067c, dropped: no
Slowest frames (largest slices inside each, inclusive)
Threads (ms per frame)
Largest slices (ms per frame, inclusive, all threads): Driver.Packet 240.1, Driver.Packet.memory_wait 142.4, Driver.WorkerWait 73.0, batch 65.9, Driver.WorkerWait.dequeue_order 52.2, Driver.Packet.prepare_memory 35.4, Driver.Packet.dispatch 29.2, Recorder.WaitSerial 29.0
Longest waits
Largest GPU batches (GPU ranges inside, and the CPU slices that recorded each, inclusive)
#11307 + this change (0cbb504f20)
seconds 135:30 from present 2258: 497 presents, frame p50 60.0 / p90 64.5 / p99 71.6 / max 84.6 ms, GPU busy 46.5 ms per present
NVIDIA GeForce RTX 5080, NVIDIA 617.42, Windows 10.0.26300, 3840x2160, commit 0cbb504f2038, dropped: no
Slowest frames (largest slices inside each, inclusive)
Threads (ms per frame)
Largest slices (ms per frame, inclusive, all threads): Driver.Packet 180.0, Driver.Packet.memory_wait 108.0, Driver.WorkerWait 55.5, batch 46.5, Driver.WorkerWait.dequeue_order 37.0, Driver.Packet.dispatch 23.3, Driver.Packet.prepare_memory 21.6, Driver.WorkerWait.idle_and_completion_poll 18.4
Longest waits
Largest GPU batches (GPU ranges inside, and the CPU slices that recorded each, inclusive)
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-10-26T23:02:10Z.
Review: APPROVED
Reviewed exact head
1f7bb916827e933dc8968649c6f029eb801f96d1; no actionable findings. The optimization is gated to linear, non-thick surfaces without tail mips, saved units or shadow-sourced padding. It writes back only ranges containing texel data and leaves the import’s current row padding in place; the tests check both byte preservation and that watched linear cases no longer seed padding pieces. Other layouts retain the existing seeded path.I independently downloaded and digested the round M1 main/change trace pair with
tools/trace_digest.py. Both identify ASTRO BOT PPSA21564 on the same RTX 5080 / NVIDIA 617.42 / Windows host, with no dropped events. The digest reproduces the report: main 498 presents, p50/p99 61.8/70.4 ms, GPU 50.7 ms/present; change 692 presents, p50/p99 45.5/52.9 ms, GPU 34.1 ms/present. The author reports the focused write-back and validation-layer suites, full build and repeated title runs; I did not rerun the GPU tests locally. Hosted eligibility, conventions, intake, labels and report checks pass; build/relinker/product checks are skipped by path policy.