Skip to content

perf(agc): leave read-trapped small storage images to their traps at the flip - #16898

Merged
oneandonlydean merged 1 commit into
boykopovar:mainfrom
imellag:perf/agc-flip-skip-read-trapped
Nov 9, 2026
Merged

oneandonlydean merged 1 commit into
boykopovar:mainfrom
imellag:perf/agc-flip-skip-read-trapped

Conversation

@imellag

@imellag imellag commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

What

At every flip, StorageTexture::StoreSmallPending("flip") writes back each small pending storage image that has a host import, and each write-back waits for the GPU. On macOS a pending image can carry a read trap (StoreReadbackBeforeLabel sets them, #13499): its pages are inaccessible until a CPU read faults, and the fault stores the image right then. Storing such an image at the flip writes back results that the trap would store on the first read anyway, and costs a GPU wait at every flip for images the title may never read.

StoreSmallPending now leaves images with readTrapped set to their trap. Images without a trap are stored as before, and readTrapped is only ever set on macOS, so Linux and Windows do not change.

In Stray (PPSA02100) on macOS, about 94 of these flip write-backs ran per second; with this change about 16 per second are stored instead, by trap faults when the title actually reads those pages, so about 85 % of the flip write-backs were never read.

Tested

macOS 27.2, Apple M4 Pro (24 GiB), MoltenVK from Vulkan SDK 1.4.363.0, x86_64 Release under Rosetta 2. main is 8f7c957 with the macOS build fixes of #16591 (commit 0a0b87e2cb), the change on top of it (9c8e6a9b55).

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: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: Apple M4 Pro, MoltenVK from Vulkan SDK 1.4.363.0, macOS 27.2
  • AI-assisted: yes

@oneandonlydean oneandonlydean self-assigned this Nov 7, 2026
@github-actions github-actions Bot added perf Performance change perf numbers missing perf pull request without a before and after summary line agc libSceAgc* labels Nov 7, 2026
@github-actions

github-actions Bot commented Nov 7, 2026

Copy link
Copy Markdown

This pull request is labeled perf, so it needs the summary line of a capture on main and one with the change, from the same title, scene and machine, as the Performance report form asks. Please paste both aps5-summary.jsonl lines, attach the two traces and add the output of tools/trace_digest.py.

@github-actions

github-actions Bot commented Nov 7, 2026 •

Copy link
Copy Markdown

Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 1368 core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp
core/libs/prx/libSceAgcDriver/tests/Recorder.cpp
PR 1395 core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp
core/libs/prx/libSceAgcDriver/tests/Recorder.cpp
PR 5021 core/libs/prx/libSceAgcDriver/tests/Recorder.cpp
PR 5609 core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp
PR 5925 core/libs/prx/libSceAgcDriver/tests/Recorder.cpp
PR 6186 core/libs/prx/libSceAgcDriver/tests/Recorder.cpp
PR 6188 core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp
core/libs/prx/libSceAgcDriver/tests/Recorder.cpp
PR 6192 core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp
core/libs/prx/libSceAgcDriver/tests/Recorder.cpp
PR 6197 core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp
PR 6209 core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp
core/libs/prx/libSceAgcDriver/tests/Recorder.cpp
PR 6280 core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp
PR 6481 core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp
PR 7457 core/libs/prx/libSceAgcDriver/tests/Recorder.cpp
PR 7514 core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp
PR 7604 core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp
core/libs/prx/libSceAgcDriver/tests/Recorder.cpp
PR 7642 core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp
core/libs/prx/libSceAgcDriver/tests/Recorder.cpp
PR 8484 core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp
core/libs/prx/libSceAgcDriver/tests/Recorder.cpp
PR 8707 core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp
core/libs/prx/libSceAgcDriver/tests/Recorder.cpp
PR 9289 core/libs/prx/libSceAgcDriver/tests/Recorder.cpp
PR 9508 core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp
core/libs/prx/libSceAgcDriver/tests/Recorder.cpp
PR 9875 core/libs/prx/libSceAgcDriver/tests/Recorder.cpp
PR 9884 core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp
core/libs/prx/libSceAgcDriver/tests/Recorder.cpp
PR 10049 core/libs/prx/libSceAgcDriver/tests/Recorder.cpp
PR 10193 core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp
core/libs/prx/libSceAgcDriver/tests/Recorder.cpp
PR 10249 core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp
PR 10442 core/libs/prx/libSceAgcDriver/tests/Recorder.cpp
PR 11444 core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp
PR 12840 core/libs/prx/libSceAgcDriver/tests/Recorder.cpp
PR 13251 core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp
core/libs/prx/libSceAgcDriver/tests/Recorder.cpp
PR 13796 core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp
PR 13809 core/libs/prx/libSceAgcDriver/tests/Recorder.cpp
PR 13863 core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp
core/libs/prx/libSceAgcDriver/tests/Recorder.cpp
PR 13920 core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp
core/libs/prx/libSceAgcDriver/tests/Recorder.cpp
PR 13928 core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp
core/libs/prx/libSceAgcDriver/tests/Recorder.cpp
PR 13929 core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp
core/libs/prx/libSceAgcDriver/tests/Recorder.cpp
PR 14262 core/libs/prx/libSceAgcDriver/tests/Recorder.cpp
PR 15136 core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp
core/libs/prx/libSceAgcDriver/tests/Recorder.cpp
PR 15570 core/libs/prx/libSceAgcDriver/tests/Recorder.cpp
PR 15621 core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp
PR 16572 core/libs/prx/libSceAgcDriver/tests/Recorder.cpp

@gabichuuuuu gabichuuuuu left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ran 0e85cea381 merged on main 302864d on Windows 11 x64 (WinLibs GCC 15.2), on an NVIDIA laptop GPU (Turing, driver 610) and an Intel iGPU (driver 101.70xx), with ANYPS5_REQUIRE_VULKAN=1, ANYPS5_NO_SHADER_CACHE=1 and VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation (Khronos validation layer 1.4.368), ctest -R <pattern> -V.

Windows only checks that nothing changes here: as the description says, readTrapped is only set on macOS, and the new check in smallTiledShadowLabelTests sits inside #ifdef __APPLE__.

Tests main change
^(agc_driver_recorder|agc_driver_graphics)$, NVIDIA 1/1 2/2
same, Intel 0/1 1/2
agc_small_tiled_shadow_label, NVIDIA 1/1 2/2
same, Intel skipped skipped 2/2
  • The Intel failures are the same on both: agc_driver_recorder stops at vkQueueSubmit recorder: Vulkan result -4 (device lost), intermittently, on main too. It isn't this change.
  • On Intel agc_small_tiled_shadow_label skips on both ("host imports are unavailable: the test block is not imported and watched"). On NVIDIA it runs and passes, without the new check, which is macOS only.
  • The layer was inserted in every test that opens a Vulkan device; agc_driver_graphics runs against MockVulkan and opens none. No log has was not found but was requested by env var VK_INSTANCE_LAYERS, and no log on either side has a VUID-. To be sure validation messages reach these logs, the same layer with best practices on printed 28 BestPractices- warnings into the agc_driver_recorder log on each GPU.

No finding in the code: the condition only adds readTrapped to the existing skip, under the same pending.mutex, and it reads the flag with the acquire order used elsewhere in Texture.cpp.

AI-assisted: yes.

@imellag

imellag commented Nov 8, 2026

Copy link
Copy Markdown
Contributor Author

Summary lines and data for the perf label, as the Performance report form asks. These runs used APS5_TRACE_SUMMARY_EVERY=10, so there is no frame trace to attach; every interval line and the tools/trace_digest.py output of each run are in https://github.com/imellag/AnyPS5/releases/tag/perf-flip-skip-trapped-20261107 (env, phase and commit fields dropped below for length; they are in the files).

Stray (PPSA02100) does not run on main, so its pair is the support tree without and with the change (last interval of each run):

without: {"gpu":"Apple M4 Pro","driver":"MoltenVK 1.4.2","os":"Darwin 27.2.0","cpu":"VirtualApple @ 2.50GHz","cpu_threads":12,"memory_mib":24576,"title_id":"PPSA02100","title":"Stray","content_version":"01.002.000","resolution":"3840x2160","window":{"spec":"summary_every 10","first_present":1519,"ms":10051.727},"interval_start_s":121.279,"interval_end_s":131.33,"presents":118,"frame_ms":{"p50":81.795,"p90":102.844,"p99":112.862,"max":116.886},"gpu_busy_ms_per_present":71.313,"worker_busy_pct":{"queue worker 0x0":98.125,"queue worker 0x20":100.086}}
with:    {"gpu":"Apple M4 Pro","driver":"MoltenVK 1.4.2","os":"Darwin 27.2.0","cpu":"VirtualApple @ 2.50GHz","cpu_threads":12,"memory_mib":24576,"title_id":"PPSA02100","title":"Stray","content_version":"01.002.000","resolution":"3840x2160","window":{"spec":"summary_every 10","first_present":1812,"ms":10050.155},"interval_start_s":120.6,"interval_end_s":130.65,"presents":154,"frame_ms":{"p50":63.247,"p90":83.911,"p99":105.395,"max":109.601},"gpu_busy_ms_per_present":43.034,"worker_busy_pct":{"queue worker 0x0":97.937,"queue worker 0x20":86.919}}

God of War Sons of Sparta (PPSA28997), main and the change (last interval):

main:   {"gpu":"Apple M4 Pro","driver":"MoltenVK 1.4.2","os":"Darwin 27.2.0","cpu":"VirtualApple @ 2.50GHz","cpu_threads":12,"memory_mib":24576,"title_id":"PPSA28997","title":"God of War Sons of Sparta","content_version":"01.008.001","resolution":"1920x1080","window":{"spec":"summary_every 10","first_present":7548,"ms":10010.527},"interval_start_s":140.137,"interval_end_s":150.148,"presents":513,"frame_ms":{"p50":19.43,"p90":20.13,"p99":21.005,"max":21.654},"gpu_busy_ms_per_present":17.963,"worker_busy_pct":{"queue worker 0x0":32.439}}
change: {"gpu":"Apple M4 Pro","driver":"MoltenVK 1.4.2","os":"Darwin 27.2.0","cpu":"VirtualApple @ 2.50GHz","cpu_threads":12,"memory_mib":24576,"title_id":"PPSA28997","title":"God of War Sons of Sparta","content_version":"01.008.001","resolution":"1920x1080","window":{"spec":"summary_every 10","first_present":7513,"ms":10017.596},"interval_start_s":140.139,"interval_end_s":150.157,"presents":517,"frame_ms":{"p50":19.299,"p90":19.964,"p99":21.13,"max":22.555},"gpu_busy_ms_per_present":17.852,"worker_busy_pct":{"queue worker 0x0":32.101}}

@oneandonlydean
oneandonlydean merged commit 01cadc1 into boykopovar:main Nov 9, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agc libSceAgc* perf numbers missing perf pull request without a before and after summary line perf Performance change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants