perf(agc): refresh only the layers a use of an array color target covers #6202
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/6202"
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 MiguelAdolfsen on 2026-10-15T02:42:57Z.
What
Fixes #6189.
ps5-opengl declares every color target as a 2D array of two slices and allocates the next target over the second one. A color view of slice 0, a 2D texture of it and a present of it each refreshed the whole array image (
StorageTexture::Refresh), so every pass:StorageTexture::RefreshLayers(first, count)refreshes only the tracked layers that hold the given array layers. It flushes and compares their memory alone, and results of other images pending over the other layers stay pending. A layer outside the range whose memory changed, or that holds another image's pending results, is left behind:StorageTexture::GenerationFor(address, bytes)reports a range over it as never current, so a later use over it takes the wholeRefresh. The sampled-texture caches and the present checkGenerationForof the range they read instead ofGeneration(). It falls back toRefreshfor volumes, single-layer and DCC images, an alias, or results of the image itself pending outside the range.It is used by:
DrawWithRecipe, and the resident lookup through the newCachedStorageLayers);refreshForViewinShaderResources.cpp);VulkanDevice::PresentDisplayBuffer).The compare memo of untracked memory (
compareUntracked, #4878) now keeps four entries keyed by range, so a layer refresh's compare is memoized like the whole image's.No switch. No change for single-layer targets.
Tested
Windows 11 Home 26200, NVIDIA GeForce RTX 4070 (driver 595.79), WinLibs GCC 15.2.0 r7, Release,
BUILD_TESTING=ON,ANYPS5_ENABLE_SPIRV_TOOLS=OFF. Tests, homebrew runs and frame dumps at60229fae6onmain92e50418f.agc_driver_array_layer_targetgainsOverlappingArrays: two two-slice arrays, the second starting at the first one's slice 1, with the second one's draw pending. A draw into slice 0 of the first array and a 2D texture sampled from that slice leave the second one's results pending; reading slice 1 of the first array then sees them, and every slice holds the right color.mainthe draw check fails.refreshForViewrefreshing the whole image, the 2D-texture check fails.60229fae6merged intomain44df21632: it passes, and onmainthe draw check fails (run by @coltken95).ctest -R agc_driver: 452 of 452 pass;agc_driver_sparse_dma_buf_importandagc_driver_stencil_ref_exportare skipped, as onmain.tools/check_conventions.py --base origin/main: passes.Three ps5-opengl homebrews, standing on their first screen without input:
Each run is the performance-report capture: a 30 s warm-up run without switches, then a run with
APS5_TRACE_SECONDS=15:10only. One build tree, built atmainand at this PR in turn, in the order PR,main, PR,main. Unrelated single-threaded jobs kept 2 to 3 of the 16 logical cores busy during all four runs.main, 1st pairmain, 2nd pairmain, 1st pairmain, 2nd pairmain, 1st pairmain, 2nd pairmainhas had #6060 since this PR was first measured: on Windows, host imports of write-watched private memory stay watched instead of being compared (its probe says yes on this machine). Onmain8cd937e29, before it, the three homebrews ran at 336 / 366, 66 / 59 and 48 / 50 ms p50, and this PR at 97 / 95, 21 / 20 and 34 / 27 ms.Frame dumps of
mainand of this PR (a separate 45 s run each,APS5_DUMP_FRAMES=5,APS5_DUMP_FRAMES_EVERY=20, five frames per homebrew):Summary lines (
aps5-summary.jsonl;APS5_TRACE_DIRpoints at the run's folder):The traces are linked from the table above.
Runs by others, with
60229fae6merged into a newermain:main5d9dcc42d: PS5 OpenGL Showcase at 3.64 and 3.75 FPS onmainand 5.47, 5.55 and 5.93 FPS with this PR (60 s runs; a thirdmainrun exited after 4 s on a cold shader cache).agc_driver_array_layer_targetpasses, and frame dumps show the same scene on both builds; both also draw a white band across the instanced cubes on this GPU (run by @LeandroLP23).main82ddae75bwith #6814 in both builds: PS5 OpenGL Showcase at 106.2 ms p50 onmainand 50.0 ms with this PR. PS5MC stays at vsync on both, but this PR drops its 600 uploads and 300 storage-refresh write-backs (about 20 GiB) per 10 s (run by @milescoviello).Not tested: Intel, AMD on Linux; on lavapipe only
agc_driver_array_layer_targetwas run, and on Linux with NVIDIA only the homebrews, without frame dumps.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)main)agc_driver_array_layer_target, by @coltken95); AMD Radeon 860M, driver 32.0.13058.8001, Windows 11 26300 (the test and the Showcase, by @LeandroLP23); NVIDIA GeForce RTX 4070 Ti, driver 595.99.02, Ubuntu 24.04 (the Showcase and PS5MC, by @milescoviello)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by coltken95 on 2026-10-15T19:56:53Z.
Tested on Linux x86-64 (Release build, lavapipe / llvmpipe LLVM 20.1.2), with
60229fae6merged into main44df21632:agc_driver_array_layer_targetpasses.AGC graphics: a draw into slice 0 of the first array stored the next target's results, which only its unused second slice overlaps.AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by LeandroLP23 on 2026-10-16T07:38:24Z.
An AMD run, for the iGPU side: about 1.5x on PS5 OpenGL Showcase on a Radeon 860M, no new failure.
Setup: Windows 11 Home 26300, AMD Radeon 860M (RDNA 3.5,
1002:1114, driver 32.0.13058.8001), Ryzen AI 7 350, WinLibs GCC 15.2.0, Release.main5d9dcc42dagainst this head60229fae6merged onto it (00d8240f6, clean merge). Catalog PPSA99005 1.0.1, relinked once with--windows; both builds use the same warm shader cache. 60 s runs, no input; FPS is the emulator's window-title counter at 60 s.mainmainThe title's own overlay agrees: 262–273 ms per frame on
main, 173–174 ms with this PR.agc_driver_array_layer_targetpasses 3 of 3 with this PR, includingOverlappingArrays.APS5_DUMP_FRAMES=5,APS5_DUMP_FRAMES_EVERY=20, one 45 s run each) show the same scene on both builds: grid, particles, torus, overlay text. On this GPU both builds also draw a large white band with black speckles across the middle of the screen, where the instanced cubes are. It is there onmaintoo, so it doesn't come from this PR. I haven't looked into it yet.Not tested: Linux, NVIDIA, other ps5-opengl titles.
AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-16T15:38:00Z.
A Linux/NVIDIA run, which the description hasn't covered: Ubuntu 24.04, RTX 4070 Ti (NVIDIA 595.99.02), GCC 13.3, Release. Head
60229fae6merged ontomain82ddae75b.Both builds also have #6814. Without it these apps segfault 0 s in on a warm cache on that
main(#6805).APS5_TRACE_SECONDS=15:10, no input, 60 s runs, summary lines fromaps5-summary.jsonl,[storage]lines fromAPS5_PROFILE_DRAW=1:[storage], 10 smain+ #6814[storage]line printedmain+ #6814So on Linux the Showcase goes from about 9.4 to 20 FPS. PS5MC is at vsync either way, but it stops moving about 20 GiB per 10 s. OpenNOW (PPSA99082) runs to the limit with both builds, but its log goes to its own console, so there is no summary for it.
Not checked: whether the frames match (no frame dumps in these runs), AMD/Intel on Linux.
AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by screamm on 2026-10-17T12:16:56Z.
Cross-validation on Windows 11 Pro 26220, NVIDIA GeForce RTX 4070 (driver 596.21), WinLibs MinGW-w64 GCC 15.2 r7, Release. Head
60229fae6merged on main673f7406c(clean). Before-runs on mainca82d7d88, which differs from673f7406conly by #6103 (libkernel).libspass.agc_driver_array_layer_target: 3 of 3. With the six changed source files taken from main (test kept) it fails 3 of 3 withAGC graphics: a draw into slice 0 of the first array stored the next target's results, which only its unused second slice overlaps; restored, 3 of 3 again.-j1 --timeout 300 -R '^agc_driver_'): 484 of 488 pass, 2 skipped. The two failures,agc_driver_f16_fma_denormal_modesandagc_driver_fma_mix_f16_denormal_modes, fail the same way on main here. Non-GPU suite: no real failures (5 load timeouts pass serially).check_conventions.pyandgit diff --checkpass.Titles, 60 s each, no input, order PR / main / PR / main,
APS5_PROFILE_DRAW=1 APS5_PROFILE_GPU=1 APS5_TRACE_SUMMARY_EVERY=10. Medians over the five 10 s summary lines of each run;storage-upload/storage-writebackare the[gputime]classes per present.None of the eight runs printed a stop line (all were still running at 60 s).
The
[storage]lines show where main loses the time. For the Showcase on main, every 10 s: 144-156 GPU-direct uploads (1.8-2.0 GiB), 503-545 CPU-path uploads (15.3-16.6 GiB), 113-139 refresh write-backs and 633-716 storage-refresh write-backs. With this PR, after the 16 first uploads (349 MiB) at start-up, only idle write-backs are left. For PS5MC on main: 290-361 direct uploads (5.1-6.4 GiB) and 144-179 storage-refresh write-backs (4.6-5.7 GiB) per 10 s. With this PR: none after start-up.Most of this is CPU-side.
[gputime]times only the GPU-direct uploads (about 0.5 ms per present for the Showcase on main), and[present]shows the frame time difference as idle gaps: 78.8 ms per frame on main against 19.4 ms with this PR, with GPU busy at 48.5 and 45.4 ms. On this machine GPU busy per present is not lower with this PR (thedrawclass is 26.5 / 29.8 ms against 17.3 / 17.5 ms on main). I haven't looked into why. The host was shared and the GPU clocks were not pinned. PS5MC runs at 35-44 FPS here, not at vsync, so its frame-time gain is small.Frame dumps (12 per run, every 30 presents): no black frame. The Showcase's mean brightness is 78-116 with this PR and 83-121 on main. It is animated, so I can't compare pixels between runs. PS5MC: every dump has mean 31.5. Between this PR and main 0.02-0.03 % of pixels differ, which is less than between two main runs (0.05 %).
Not checked: AMD or Intel, Linux, OpenNOW, a count of refreshed layers (this PR doesn't log one), an idle host.
Written with Claude Code assistance (validation by a subagent, reviewed in this session).
Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-17T14:08:54Z.
Linux data for this head (
60229fae64), from OliSe Player (PPSA01153). It's a single-preset copy with Rovastar's Dark Ritual, the preset whose two-slice 1920x1080 targets screamm measured on Windows in #6530. Square once, 120 s,APS5_PROFILE_DRAW=1 APS5_PROFILE_GPU=1. Ubuntu 24.04, RTX 4070 Ti (NVIDIA 595.99), Release. The merged-coverage draws need #6530, so both builds aremain40315fcf8c+ #6530, with and without this PR, 2 runs each. The rows are 10 s intervals after the first one:[storage]CPU uploads per 10 sflushed72–74,store57–60)memory no longer registered; 135 pending ranges droppedPer present, the linear-target write-backs stay at 2 (88/44.5 before, 115/57.5 after). On Linux, the CPU round trip of the whole two-slice image goes away entirely, and the visualiser runs about 29% faster. On Windows, screamm saw this PR remove the refresh write-backs, but the
untrackeduploads stayed. Linux has nountrackeduploads in either build, so the remainder there is the Windows path that compares resident targets against guest memory instead of write-tracking them.AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by karanvora2599 on 2026-10-18T08:19:06Z.
A data point from Windows, on a different machine and GPU. PS5 OpenGL Showcase (PPSA99005), RTX 4060 Laptop, driver 591.86,
APS5_TRACE_SECONDS=15:10,APS5_SPIRV_OPT=none. This PR at60229fae6was merged ontomain51cee9031locally, without conflicts. The 45 s runs were interleaved; the runs of this PR came in a second round, after a warm-up of their own.main51cee9031main51cee9031The title's own counter goes from about 5.0 fps to 9.7.
agc_driver_array_layer_targetpasses on the merge.Together with #6486 it is 46 ms and about 19.5 fps; that table is in #6486.
Imported from boykopovar/AnyPS5. Originally posted by DavidSamir on 2026-10-21T08:51:25Z.
Independent run on an AMD iGPU with the two ps5-opengl catalog titles. It confirms the PR on its base. Current
mainhas since got worse in this same path.Setup: Windows 11 Pro 26200, AMD Radeon 680M (RDNA 2 iGPU,
1002:1681), AMD driver 32.0.21030.2001, WinLibs GCC 15.2.0 r7, Release. This head (60229fae6) conflicts with currentmaininDraw.cpp,ShaderResources.cpp,Texture.cppandArrayLayerTarget.cpp, so I compared it with its own base92e50418f, in one build directory. Titles: homebrew catalog, relinked with--windows --registry, 3 runs of 60 s per side,APS5_TRACE_DRAWS=1 APS5_PROFILE_DRAW=1.Pulse PPSA99993 (ps5-opengl, a 2-slice array colour target with its depth buffer over the second slice, as the description says):
92e50418fStorageTexture upload submitreadTargetsumagc_driver_array_layer_targetwithVK_LAYER_KHRONOS_validation(SDK 1.4.363),ANYPS5_REQUIRE_VULKAN=1andANYPS5_NO_SHADER_CACHE=1:ArrayLayerTarget.cppbuilt against the base implementation fails:a draw into slice 0 of the first array stored the next target's results, which only its unused second slice overlaps.VUID-lines on either side.Current
main(1ff5c8ac5): the same title uploads before every draw. Each upload is the whole 33 MB 2-slice image (a depth-plane store into the second slice, then a CPU-path upload, about 22 ms on this GPU). The first ~90 draws then miss ps5-opengl's 2 s completion wait, and Pulse exits after 4 s with[ps5-agc] submission retirement failed; terminating application before cleanup, every run. An RTX 3070 on the samemainuploads before 85 of 86 draws and fails 2 of 3 runs. So on currentmainthis is a title that dies, and this PR's change addresses the cause. A rebase ontomainis needed to show it there, and I can rerun both titles on the 680M once it's rebased. I'm bisecting the change onmainthat turned the occasional upload into a per-draw one, and will report it here.Surround Sound Studio PPSA99051, the other ps5-opengl title, exits after 4 s with the same retirement line on both sides, after only 2 draws and no uploads. That's a separate cause, not this one.
AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-21T08:53:41Z.
@MiguelAdolfsen a strong data point from @DavidSamir: on current
mainthe 2-slice array target now uploads its whole image before nearly every draw and the title dies after 4 s, while this PR on its base cuts the uploads from about 1,200 to 3 and passes the validation-layer test. Could you rebase onto currentmain(it conflicts inDraw.cpp,ShaderResources.cpp,Texture.cppandArrayLayerTarget.cpp)? One thing to keep in mind there: #8707 replaces thedccAddress != 0 && uploadedKeys != DccKeys::Uncompressedcheck withother->storesWhole(), so if it lands first, this branch should use that. Thanks @DavidSamir for the runs, and the bisect of themainregression will be very useful.Imported from boykopovar/AnyPS5. Originally posted by DavidSamir on 2026-10-21T10:21:08Z.
Follow-up to my earlier comment: on current
mainthis PR turns a title that dies into one that runs.What broke it on
main: I bisected (first-parent)92e50418f..1ff5c8ac5with Pulse PPSA99993 on the Radeon 680M, counting uploads among the first 80 draws. Every step was either 1 of 80 and the title survives, or 78 of 80 and it exits after 3 s. The first bad commit is50e0624d7, the merge of #7154 (keep depth planes coherent with buffer reads and writes of their memory). Its parent26740077bis good. Since #7154, the colour target's lookup covers the whole 2-slice array, and itsFlushDepthPlanesover that range stores the depth plane that sits over the unused second slice ([flush] image 0x256200000+0x870000 for depth plane store). That store stamps the range, so the array'sRefreshreportsguest memory changedand uploads the whole 33 MB again before every draw.This PR merged locally into
main1ff5c8ac5. Test only, nothing pushed. It conflicts in 4 files. My resolutions, in case they help with the rebase:Draw.cpp: keptmain's slice-pitchRequires, and replacedCachedStorageSurface(context, array)withCachedStorageLayers(context, array, color.arraySlice, color.layers).color.layersrather than1, sincemainnow attachescolor.layersslices for layered draws.ShaderResources.cpp: keptmain'sBuildLookupsand itsArrayLayerWindow(requested, ...)lines incachedStorageTexture, added this PR'srefreshForViewand thelayersparameter, with the parameter renamed back torequestedsoviewedis the windowed resource.Texture.cpp(Refresh): keptmain'shandedOver/clearHandOverlines, with the flush as!handOverKeys.has_value() && FlushPending(scopeBegin, scopeBytes, ...).ArrayLayerTarget.cpp: keptmain'sUnregisteredUnusedLayerandRetiredArrayLayernext to this PR'sOverlappingArrays.Results on the 680M (AMD 32.0.21030.2001), 3 runs of 60 s per side:
mainmain+ this PRsubmission retirement failed)agc_driver_array_layer_targetpasses on the merge underVK_LAYER_KHRONOS_validation, with 0VUID-lines. I didn't run the full suite on the merge.Context, from a teammate: ps5-opengl raised its completion wait to 30 s upstream (ps5-opengl#12, SDK 1.0.2). The catalog builds of Pulse and Surround Sound Studio are older, so they still hit the 2 s wait. The per-draw 33 MB upload is a cost for every ps5-opengl title either way.
AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-21T10:39:55Z.
@MiguelAdolfsen @DavidSamir thanks, that bisect is very useful. We confirm the first bad commit:
50e0624d7is #7154's merge onmain's first-parent line, and it's whereFlushDepthPlanescame into the array-target refresh. So on currentmainthis PR fixes a regression, which makes it more than a perf change.On carrying it: #6718 already contains this PR's change, merged onto current
main, and it merges cleanly, so we'll land it there with the authorship kept. One of your resolutions is the right fix for a detail in that merge. The array target's lookup inDraw.cpphas to covercolor.layersslices, not1, because the attachment view spanscolor.layersslices fromcolor.arraySlice, and with1a layered draw would only refresh its first slice. We'll fix that before it goes in.Pull request closed