perf(agc): import storage surfaces that cross the import window through a joined import #6197
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/6197"
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 mcsilva-dev on 2026-10-15T02:25:37Z.
What
HostImportForkeeps an import run inside one 8 MiB import window (SetHostImportWindow(8 MiB)), andimportAccessreturns no import when the window run does not cover the range. A storage surface that crosses a window boundary therefore never has an import, and every upload of it takes the CPU path inStorageTexture::upload:GuestMemory::ReadCommittedof the whole surface, a staging copy, a detile in aCommandBatchof its own andSubmitAndWait.EA SPORTS UFC 6 (PPSA23566) builds its transient render targets in a pool it reserves at
0x11c0000000(+0x6f424000) and maps in 8 MiB pages (remap fixed ... +0x800000 prot=0xf3, each page on unrelated physical memory). The engine packs surfaces across page boundaries, so most of its storage surfaces cross a window. WithAPS5_PROFILE_DRAW=1at the title screen, per 10 s:i.e. about half of the queue worker's time went to these uploads. A temporary diagnostic that recorded the import refusal for each CPU upload named a single cause: every one was refused as not registered because the window run did not cover it, all inside the
0x11c0000000pool. The pool is remapped only during start-up (82 remaps, none after the title screen appears), so an import over it stays valid.HostImportSpanningkeepsHostImportFor's per-window contract (importWindowTestsstill requires that a view crossing the window is not imported) and, when it finds no import, falls back to a joined import over the contiguous registered ranges the range covers (crossedRun→importJoined, as buffers already do). The storage texture paths that look up an import for a whole surface use it.Tested
agc_driver_graphics_tests(Windows 11, WinLibs GCC 15.2.0, Release, AMD Radeon RX 9070 XT, driver 26.8.1): the newimportSpanningTestsfails onmainwitha surface crossing the import window was not imported through a joined import(checked by turningHostImportSpanninginto a plainHostImportFor) and passes with this change; the whole executable passes (Graphics validation tests passed).tools/check_conventions.py --base origin/mainpasses.APS5_TRACE_SUMMARY_EVERY=10. Both builds aremain760ffa683plus one local change that the title needs to reach the title screen on 32 GB (registered shaders prepared at first use, see #6139); they differ only by this commit:APS5_PROFILE_DRAW=1main760ffa683(+ local change)With the CPU uploads gone, the largest remaining storage cost on
mainis the alias round trip:storage refreshwrite-backs of ~8,800 surfaces (~9.6 GiB) per 10 s, the hand-overs #4286 targeted.Together with #4286. On the UFC bring-up fork from #5996 (c222bd2c2), same machine and scene, without
APS5_PROFILE_DRAW:The first two rows ran with the game on a hard disk and the third on the NVMe SSD; moving the same build between the two disks shortened start-up but did not change the title-screen frame time.
The hand-over takes an aliased surface's units on the device only when the surface is imported, and in this title the aliased surfaces were exactly the ones crossing a window. So this change is what lets #4286 act on Windows here; it may be worth another look at #4286 on top of it.
The title screen picture is the same with and without the change (compared on screenshots); I have not checked later scenes beyond the first cutscene starting.
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.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by copilot-pull-request-reviewer[bot] on 2026-10-15T02:25:44Z.
Review: COMMENTED
Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.
Imported from boykopovar/AnyPS5. Originally posted by Celegans12 on 2026-10-15T17:11:48Z.
@mcsilva-dev I tried this on our Ghost of Yōtei branch today, and two of main's storage write-back tests fail with it. They fail on your head
d7f5ffb043by itself too, without our changes:agc_storage_split_writebackandagc_driver_storage_write_back_overhang, on Windows 11 with an RTX 3080 Laptop.agc_storage_split_writebackstops at "64 KiB R_X 200x150, 3 mips, ranges split inside a 64 KiB unit: the write-back took the GPU-direct path". A split inside one 64 KiB unit now goes through the joined import instead of the CPU path.agc_driver_storage_write_back_overhangstops at "byte 0x5 differs from the fully registered surface (15360 texels, 768 past pitch x height)". The write-back for the image does run, but its data only shows up in guest memory with the next submission. An extra flush and wait before the check doesn't help.Replacing the six
HostImportSpanningcalls inTexture.cppwithHostImportFormakes both pass again, so it looks like it's in the joined-import path itself. Limiting the joined import to 64 KiB-aligned splits wasn't enough (an aligned split still lost data), and neither was turning unit shadows off. We've taken it back out of our game branch for now, but I'm happy to rerun a fix on Yōtei.Details
d7f5ffb043in a clean worktree, and on our branch (maina5e2a80c6bplus our stack) with the PR merged. Both tests pass on that branch with the merge reverted.Imported from boykopovar/AnyPS5. Originally posted by AlxcBTW on 2026-10-16T04:12:21Z.
With this PR two existing tests fail under Mesa lavapipe, on Linux and on Windows:
agc_storage_split_writebackandagc_driver_storage_write_back_overhang. Both pass on the base of this PR and on currentmain. The stored data is right once the GPU work is complete; both failures are in the tests, which assumed the CPU write-back for a surface over several registered ranges. One line in each test makes both pass.Runs. The fork CI builds the tests and runs the two ctest entries under lavapipe. Linux is ubuntu-latest (llvmpipe, LLVM 20.1.2). Windows is windows-latest with Mesa 26.2.4 lavapipe (llvmpipe, LLVM 23.1.2), where the test memory is private committed memory and the imports are host-pointer imports.
main5d9dcc42d760ffa683(the base of this PR)d7f5ffb04(this PR)d7f5ffb04plus the two lines belowMessages, the same on both platforms:
agc_storage_split_writeback:64 KiB R_X 200x150, 3 mips, ranges split inside a 64 KiB unit: the write-back took the GPU-direct path. Nothing else is reported for that case, so its checks of the stored texels, of the words changed outside the surface and of the second store pass on the GPU-direct path.agc_driver_storage_write_back_overhang:AGC graphics: storage write-back overhang: the fully registered surface received no texels.Cause.
splitWriteBackTestsintests/Recorder.cppexpects the CPU write-back when the two registered ranges split inside a 64 KiB unit and unit shadows are on (direct = !UnitShadowEnabled()).importSegments()gives up on that case (unitAligned && from % 65536 != 0): it would need two imports under one unit.writeBackLayersnow asksHostImportSpanningfirst, which returns one joined import over both ranges, so the unit lies in a single import and the write-back goes GPU-direct.HostImportFor(...) == nullptrstill holds (the test asserts it) and the GPU-direct path leaves both ranges covered by an import (the test asserts that too).Write()intests/execution/StorageWriteBackOverhang.cppends withFlushAllPending("test")andAgcDriverWaitIdle_nid_postfix(), and the test then reads the guest memory through plain pointers. A GPU-direct write-back is recorded behind the work that produced the image and completes after that call. The other tests intests/executioncallAgcDriver::GuestMemory::FlushGpuWrites(address, bytes)afterAgcDriverWaitIdle_nid_postfix()before they read raw memory for that reason. This test did not need it so far, because itssplitsurface took the CPU write-back, which waits for the GPU and so also completed the GPU-direct write-back of thewholesurface made before it. Builds of the same tree with and without this PR and a texel count after eachWrite: without it thewholesurface has 0 texels after its ownWriteand both have 15360 after the second (38846022767); with it thesplitsurface is GPU-direct as well, nothing waits, and both are still at 0 when the test reads (38846017110). WithFlushGpuWritesadded toWrite()and nothing else changed, the test passes on the build with this PR, the two surfaces equal byte for byte and the padding kept (38846544700; that run is red only becauseagc_storage_split_writebackstill fails there without its own change).Change. One line in each test file; with both, all 34 tests of that job pass on a tree that contains this PR (38846598673):
The first change makes the case expect the GPU-direct path whatever
UnitShadowEnabled()says. The case's data checks pass on that path (the stored texels, the words changed outside the surface, the second store); whether a split inside a unit should leave the rule ofimportSegments()behind is for the author and the reviewers to decide. Tested on lavapipe only (Linux and Windows); no hardware GPU.AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-17T04:51:39Z.
A second title with storage surfaces that cross the import window: MXGP 26 (PPSA30839). Its 2560x1440 storage images are 15 MiB (
0xf00000), so each one crosses an 8 MiB window. Without this PR, a local log line per CPU-path upload shows every one of them going throughStorageTexture::upload's CPU path withHostImportForreturning null. That also keeps the alias exemption inStorageTexture::Refreshfrom applying, since it requires an import.Linux 6.8, RTX 4070 Ti (595.99.02), Release, pad input, 130 s runs.
maindoesn't reach this scene, so the base ismain143f130553+ #6814, #6094, #6160, #6308, #6184, #6455 + #6917. This PR's head (d7f5ffb043) merged on top, clean merge:APS5_PROFILE_*(2 rounds)In normal runs the frame rate doesn't change, because those runs upload only about 10 storage images in all. The difference is in the runs where several overlapping 2560x1440 images keep flushing and re-uploading each other (#6998): with this PR that didn't happen in 6 of 6. All 18 runs reached their limits.
AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-18T17:14:43Z.
Review: CHANGES_REQUESTED
Thanks, the measurements on UFC 6 and MXGP 26 make the case for this clear. Before it can merge:
maininGuestBufferMemory.hppandGuestBufferMemory.cpp(real content conflicts, not just adjacency). Please rebase and rerunagc_driver_graphics_testsafter it.agc_storage_split_writeback("ranges split inside a 64 KiB unit: the write-back took the GPU-direct path") andagc_driver_storage_write_back_overhang. Both pass on your base. Please update them in this PR. @AlxcBTW's analysis and one-line fixes are in the thread: expect the GPU-direct path insplitWriteBackTests(Recorder.cpp, the "split inside a 64 KiB unit" row) and callAgcDriver::GuestMemory::FlushGpuWrites(...)at the end ofWrite()intests/execution/StorageWriteBackOverhang.cpp.importSegments()rule behind.Imported from boykopovar/AnyPS5. Originally posted by JJenkx on 2026-10-19T07:09:15Z.
Additional hardware regression coverage for this PR: AMD Radeon RX 6650 XT, RADV / Mesa 26.2.4-arch1.1, Arch Linux, Khronos validation enabled and shader caches disabled.
I adapted head
d7f5ffb043d61c9d1ed40469f0622089ba9d04d9onto mainc1ca83479f4e3faad4064fce33afcbebb3ba60d0(preserving main’sExistingHostImportForalongsideHostImportSpanning) and ran a GPU readback regression against CPU-detiled reference pixels. It covers adjacent imports, initial uploads and partial refreshes, uploads outside and inside explicit temporary-recorder scopes, both single-pass settings, nine mip levels, two array layers, and a 256-byte offset that clips the import windows.libsbuild: passed.agc_driver_graphics: passed, 2.63 s.agc_driver_storage_segmented_upload: passed, 0.11 s.The reproducible comparison branch and regression are at 6ce9eadd702a. Build the
libs,agc_driver_graphics_testsandagc_driver_storage_segmented_upload_teststargets, withANYPS5_AGC_EXECUTION_TESTS=StorageSegmentedUploadenabled, then run:The regression restores the device's outer recorder after its temporary recorder is destroyed. Without that fixture restoration, teardown can leave the outer recorder's retained imports pinned and produce a misleading unregister timeout; the corrected regression passes here.
This is upload correctness coverage, not a title performance claim or a validation of all write-back paths. I have kept my overlapping segmented-copy implementation local rather than opening a competing upload PR. The test is available to reuse here.
AI-assisted: yes.
Hardware write-back follow-up: I also reproduced both existing test failures on this adapted branch before applying the two test corrections proposed above by @AlxcBTW.
agc_storage_split_writebackreported only the unexpected GPU-direct path for the intra-unit split;agc_driver_storage_write_back_overhangreported byte0x5differing from the fully registered surface.With those exact two corrections (expect the joined GPU-direct path; call
GuestMemory::FlushGpuWritesbefore the raw CPU read), all six focused tests pass on the same RX 6650 XT with RADV, Khronos validation, and shader caches disabled:agc_storage_written_buffer_orderagc_storage_split_writebackagc_storage_write_backagc_driver_graphicsagc_driver_storage_segmented_uploadagc_driver_storage_write_back_overhangZero validation errors and zero skips. The split test retains its texel, padding, import-coverage, and second-store checks; the overhang test retains its byte-for-byte and padding checks. The write-watch probe reports dma-buf imports retaining write protection. No production driver changes were needed for these corrections.
Reproduction: hardware-test branch, with the two-line patch in its final commit, credited to @AlxcBTW. Add
StorageWriteBackOverhangtoANYPS5_AGC_EXECUTION_TESTSand buildagc_driver_recorder_testsandagc_driver_storage_write_back_overhang_tests; run the two write-back tests using the same environment shown above. This is hardware corroboration of the proposed test corrections, not a whole-suite or title performance claim.Imported from boykopovar/AnyPS5. Originally posted by eliasbruno124-dev on 2026-10-20T16:47:47Z.
Windows hardware follow-up on
main77e31219c835: RTX 3060 Laptop GPU, NVIDIA 617.42, Windows 11, WinLibs GCC 15.2.0, Release.I adapted
d7f5ffb043d6locally, preserving current main'sExistingHostImportForand stale-import/LRU refresh checks. Both sides include #8527 to correct the Windows deferred-settle ordering hazard;APS5_NO_DEFERRED_SETTLESis unset. These results therefore include that unmerged dependency.The same 22 focused native tests pass before and after, with the real Khronos synchronization-validation layer, shader caches disabled, zero validation errors and zero skips. Each finishes within 14 seconds. This includes the split-writeback, overhang, storage-written-buffer ordering and eight import-settle cases.
For the review's two fixture changes, current main already flushes GPU writes before the overhang CPU read. I changed the intra-64-KiB split expectation to GPU-direct while retaining its stored-texel, padding and second-store checks. Those checks pass on this NVIDIA hardware.
I also compared automatic startup of GTA III, PPSA03527/01.003.000, with complete matching runtimes and unchanged original content. Across the emitted 10-second storage reports in each 180-second observation, CPU uploads fell from 3 (14.9 MiB) to 1 (3.0 MiB). All eight corresponding early renderer exports are byte-identical. Neither observation reached confirmed gameplay; logging and frame readbacks were enabled. This small startup difference does not establish an FPS or loading-time improvement, and does not yet reproduce the much heavier upload churn observed in the first mission.
Prepared with AI assistance.
Imported from boykopovar/AnyPS5. Originally posted by LeandroLP23 on 2026-10-21T22:29:07Z.
A third title with storage surfaces that cross the import window, plus a test conflict with current
mainthat came in with #6457.Title. SuperTuxKart (PPSA69421 00.001.000), a ps5-opengl port, in a race. Its two-slice 1920x1080 color targets are 17,694,720 bytes each, at
0x2bf200000and0x2bfc00000. The title maps that memory in 10 MiB pieces; the import trace shows0x2bf600000+0xa00000,0x2c0000000+0xa00000and0x2c0a00000+0xa00000. So each target spans two or three registered ranges and gets no import fromHostImportFor. A temporary log at the CPU path ofStorageTexture::uploadshowed only these two images there, each withExistingHostImportFornull. Their write-backs were already GPU-direct throughimportSegments(); only the uploads took the CPU path.Setup.
main0c6a5bd593, andmainwithd7f5ffb043merged locally.GuestBufferMemory.hppandTexture.cpp. I keptmain's side, added theHostImportSpanningdeclaration, and usedHostImportSpanningin the three refresh/upload call sites and inCopyRefusal, whichmainsplit out of the copy check.APS5_PROFILE_DRAW=1, per 10 s of the race:mainmain+ this PRreadTargetFPS doesn't move measurably: 4.97 and 6.12 with this PR against 5.90–8.43 on
mainover four rounds. GPU time per present varies by 30–80 ms between runs here and hides a ~0.7 s per 10 s saving on the draw thread. The race renders as onmain.Tests on this machine (merged build,
ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1).agc_driver_graphics: passes,importSpanningTestsincluded.agc_driver_storage_write_back_overhang: passes on this hardware driver.agc_storage_split_writeback: fails as reported above, "ranges split inside a 64 KiB unit: the write-back took the GPU-direct path".agc_storage_writeback_blocks: new since #6457 (a24aafb75c, "import adjacent registered ranges as aligned power-of-two blocks").writeBackBlockTestsexpects the write-back of "a 4 MiB image at 64 KiB over 66 adjacent 64 KiB pieces" to make 2 imports (aligned blocks throughimportSegments()). With this PR the image already holds one joined import, so it makes 1. The rest of the row holds: GPU-direct write-back, 1048576 of 1048576 texels stored. Both tests pass onmain.So the rebase also has to settle which rule a surface over several adjacent ranges follows: one joined import from
HostImportSpanning, or the aligned power-of-two blocks #6457 introduced. Then that row's expectation needs to match.AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by JJenkx on 2026-10-22T06:15:02Z.
@mcsilva-dev a heads-up, as #9652 touches the same area. It relaxes
joinedRunso that a buffer bound from the start of a run of adjacent registered ranges joins the ranges it crosses. Before, it had to cover the run exactly. That is the buffer-descriptor side of imports that do not span a run, where this PR covers storage surfaces throughHostImportSpanning. The two change different functions and should merge independently; I mention it in case you see a reason they should share one rule.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-23T02:56:49Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this change; the reviewed code adds a joined-import fallback for storage surfaces that cross an import window while preserving the existing per-window lookup contract.
What I ran
Reviewed head
d7f5ffb043d61c9d1ed40469f0622089ba9d04d9againstmainusing the prepared diff and the pinned repository reader. No build or tests were run.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
The author reports the graphics validation suite, conventions check, and UFC 6 performance measurements in
description.md; these were not independently run. I did not verify later game scenes, physical-console behavior, or files excluded by the prepared review folder. All four files listed as reviewed inmanifest.jsonwere read:core/libs/prx/libSceAgcDriver/Graphics/include/GuestBufferMemory.hpp,core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp,core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp, andcore/libs/prx/libSceAgcDriver/tests/BdaResources.cpp. No changed files were excluded.To get this to a good state
Nothing is required.
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.