Skip to content

perf(agc): wait for the display keys' writer before a present takes the device lock's time - #10160

Merged
oneandonlydean merged 3 commits into
boykopovar:mainfrom
EagleBearerYS:port/fable-fix-present-key-wait
Oct 26, 2026
Merged

oneandonlydean merged 3 commits into
boykopovar:mainfrom
EagleBearerYS:port/fable-fix-present-key-wait

Conversation

@EagleBearerYS

@EagleBearerYS EagleBearerYS commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

What

The presenter checks a display buffer's DCC keys under the device lock.

  • What went wrong: when the batch with the kernel that writes those keys hadn't finished, the check waited for the GPU while holding the lock, and the queue worker recording the next frame waited behind the presenter.
  • The fix: PresentDisplayBuffer now first syncs through the key range with the unlocked wait the flush hook uses.
    • The presenter's acquisition is the outermost on its thread, and nothing has been decided yet, so the lock is released for the GPU wait and retaken for the completions.
    • The key check that follows finds the batch finished.
    • It's one line, for tiled display buffers with DCC keys (dccAddress != 0, tilingMode == 0).

Authorship: the fix is @fable-void's (fable-void/AnyPS5@9ed1466f35), carried unchanged under his authorship as 96bccd4. His message reports, in a title's menu on Windows: GPU waits under the lock went from 721 (1.38 s) to 1 (0 ms) per 10 s, and the queue worker's waits for the lock from 1.47 s to 0.18 s per 10 s. The counter and the test are ours.

The commits:

  1. 96bccd4 (fable-void): the fix.
  2. a3af6b1: a profile-only counter on the [present] line behind APS5_PROFILE_DRAW: waits outside the GPU mutex for the display keys' writer: N, X ms. With the profile off it costs one test of a static const bool.
  3. 5419643: the test, agc_driver_present_key_writer_wait (tests/execution/PresentKeyWriterWait.cpp).
    • It calls the real VulkanDevice::PresentDisplayBuffer headless, holding the GPU mutex once, as Driver::Present does, over a display buffer whose keys a recorded GPU copy is still writing.
    • It requires three things: the present reached the swapchain (the key check saw the written keys); GuestMemory::GpuHoldSerial() advanced (the presenter released and retook the mutex for the writer); and the writer is no longer pending.
    • A control with no writer must leave the serial unchanged.
    • There's no test-only hook.

Tested

  • Resident Evil Village (PPSA01556), Windows, RTX 3070 Laptop GPU, clocks not held. Static menu, 5 minutes, APS5_PROFILE_DRAW=1, on our lane F tree (12aa911), which carries this fix with fable-void's other shared-code fixes:
    [present] ... waits outside the GPU mutex for the display keys' writer: 5, 9.8 ms
    
    That's per 10 s: GPU waits that main would make with the device lock held (this PR's commit alone was not run in the title).
  • The test (agc_driver_present_key_writer_wait):
    • Red, against this PR with only the fix's line removed: "AGC graphics: the presenter synchronized with the display keys' writer without releasing the GPU mutex".
    • Green with it.
  • Linux, CI's configure flags (lavapipe, on a cloud worker):
    • the test plus the present/display-buffer set, --repeat until-fail:20: 17 tests ran 20 times each, and 17 video_out_* tests skip with no display;
    • CI's Linux job mirrored: 1,934 tests, of which 1,844 pass, 86 skip and 4 fail, the four being that machine's IPv6 tests.
  • GitHub's runners (run 39933804836, this head on main 44a59ed):
    • Linux: red with main's implementation (agc_driver_present_key_writer_wait: "the presenter synchronized with the display keys' writer without releasing the GPU mutex"): 2 pass, 1 fails. Green ×10 with this PR: all 3 run and pass (the new test, agc_display_buffer_dcc and agc_driver_dcc_key_presync), none skip.
    • Windows: builds. The runner has no Vulkan device, so on both trees 1 runs and passes (agc_display_buffer_dcc, ×10 with this PR) and the 2 device tests skip.
    • The libc and libkernel suites pass on both.
  • Validation layer (Khronos 1.3.275, lavapipe): main's driver and this PR over the 12 non-video_out tests give the same single VUID-VkDeviceCreateInfo-pNext-pNext in the same tests with the same counts. No new VUID-.
  • Resident Evil Village (PPSA01556), a menu pair, on an NVIDIA GeForce RTX 3070 Laptop GPU (driver 617.42), Windows 11. The static menu, 5 minutes per run, in the order with, without, without, with, from a warm shader cache with APS5_LAZY_SHADER_PREPARE=1, APS5_NO_GPL=1 and APS5_HOST_IMPORT_MIB=6400. GPU clocks weren't locked (P0 in 98.8–99.4 % of samples, mean 1,398–1,412 MHz).
    • The trees: without this PR, test/10160-village-base (d55142d, main 137a8fa plus fix(agc): put a retired import's unchanged ranges back in the write watch #8926's fix, which the title needs to get past its intro); with it, test/10160-village (0f8178c), the same tree plus this PR's three commits, the same as 96bccd4, a3af6b1 and 5419643 by patch-id.

    • Speed, from the 10-s summary rows over 399–461 s and 519–581 s of each run, after the menu stood in all four:

      run build fps frame p50 (median of rows) GPU busy per present (median of rows)
      1 with 0.389 2,535 ms 277.6 ms
      2 without 0.406 2,442 ms 279.5 ms
      3 without 0.368 2,727 ms 276.0 ms
      4 with 0.382 2,105 ms 278.9 ms

      The means are 0.386 fps with and 0.387 without, and the runs of one build differ as much as the builds do, so the frame rate is unchanged within noise. At this menu the presenter is busy 3.3–4.1 ms per frame in all four traces (trace_digest.py's thread table). This PR makes no frame-rate claim.

    • The menu takes this PR's path: in the 60-s traces of runs 1 and 4 (with), the presenter thread retakes the GPU mutex at the hook site, the site this PR's unlocked wait for the display keys' writer retakes it at, 3 and 6 times (GpuMutex.wait.hook; the trace records a retake only when it had to wait, so these are lower bounds). In runs 2 and 3 (without), the presenter has no such slice.

    • Memory, from 1 minute into the menu to the end of each run: private memory 18,481–19,381 MB at 1 minute, growing 723–907 MB per minute in all four, with no commit floor.

    • Closes: runs 1, 2 and 3 end with a crash in the presenter at close, after the measured window, in both builds; run 4 closed cleanly.

    • Summary lines (aps5-summary.jsonl), the rows of the 60-s trace windows (APS5_TRACE_SECONDS=460:60) of run 2 (without) and run 1 (with):

      {"commit":"d55142d279a0","dirty":false,"env":{"APS5_HOST_IMPORT_MIB":"6400","APS5_LAZY_SHADER_PREPARE":"1","APS5_NO_GPL":"1","APS5_PAD_INPUT_FILE":"<path>","APS5_TRACE_DIR":"<path>","APS5_TRACE_SECONDS":"460:60","APS5_TRACE_SUMMARY_EVERY":"10"},"gpu":"NVIDIA GeForce RTX 3070 Laptop GPU","driver":"NVIDIA 617.42","os":"Windows 10.0.26300","cpu":"AMD Ryzen 9 5900HS with Radeon Graphics","cpu_threads":16,"memory_mib":15776,"title_id":"PPSA01556","title":"Resident Evil Village","content_version":"01.210.000","resolution":"3840x2160","window":{"spec":"seconds 460:60","first_present":2587,"ms":61597.811},"presents":24,"frame_ms":{"p50":2532.486,"p90":2938.668,"p99":3711.990,"max":3711.990},"gpu_busy_ms_per_present":280.063,"worker_busy_pct":{"queue worker 0x0":99.698,"queue worker 0x38":0.138,"queue worker 0x20":93.610,"queue worker 0x28":96.828},"top_phases_ms_per_frame":{"Driver.Packet":7447.818,"Driver.Packet.memory_wait":4571.201,"Driver.Packet.draw":2059.353,"Driver.Draw":2058.176,"Graphics.Draw":1780.472,"Graphics.Draw.draw_and_resource_release":1755.706,"Resources.Complete":803.815,"Driver.Packet.dispatch":599.660},"trace_dropped":false,"trace":"aps5-trace-d55142d279a0-3524.json.gz"}
      {"commit":"0f8178cbca31","dirty":false,"env":{"APS5_HOST_IMPORT_MIB":"6400","APS5_LAZY_SHADER_PREPARE":"1","APS5_NO_GPL":"1","APS5_PAD_INPUT_FILE":"<path>","APS5_TRACE_DIR":"<path>","APS5_TRACE_SECONDS":"460:60","APS5_TRACE_SUMMARY_EVERY":"10"},"gpu":"NVIDIA GeForce RTX 3070 Laptop GPU","driver":"NVIDIA 617.42","os":"Windows 10.0.26300","cpu":"AMD Ryzen 9 5900HS with Radeon Graphics","cpu_threads":16,"memory_mib":15776,"title_id":"PPSA01556","title":"Resident Evil Village","content_version":"01.210.000","resolution":"3840x2160","window":{"spec":"seconds 460:60","first_present":1181,"ms":62201.146},"presents":23,"frame_ms":{"p50":2652.280,"p90":3043.922,"p99":3484.024,"max":3484.024},"gpu_busy_ms_per_present":278.929,"worker_busy_pct":{"queue worker 0x0":99.689,"queue worker 0x38":0.065,"queue worker 0x20":93.795,"queue worker 0x28":96.836},"top_phases_ms_per_frame":{"Driver.Packet":7849.574,"Driver.Packet.memory_wait":4808.638,"Driver.Packet.draw":2208.895,"Driver.Draw":2207.691,"Graphics.Draw":1908.668,"Graphics.Draw.draw_and_resource_release":1882.055,"Resources.Complete":855.785,"Driver.Packet.dispatch":651.564},"trace_dropped":false,"trace":"aps5-trace-0f8178cbca31-15520.json.gz"}
    • Files: each run's trace, its trace-window summary line and tools/trace_digest.py output: run 1, run 2, run 3, run 4.

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 (none added)
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none (lock time at present; PPSA01556 measured)
  • GPUs tested: NVIDIA GeForce RTX 3070 Laptop GPU (Windows, the title run); Mesa llvmpipe (Linux, tests)
  • AI-assisted: yes

fable-void and others added 3 commits October 23, 2026 08:38
…he device lock's time

The presenter checks a display buffer's DCC keys under the device lock.
When the batch of the kernel that writes those keys had not finished,
the check waited for the GPU while holding the lock, and the queue
worker recording the next frame waited behind the presenter.

PresentDisplayBuffer now first syncs through the key range with the
unlocked wait the flush hook uses: the presenter's acquisition is the
outermost on its thread and nothing has been decided yet, so the lock
is released for the GPU wait and retaken for the completions. The key
check that follows finds the batch finished.

Tested on Windows in a title's menu: the presenter's GPU waits under
the lock went from 721 (1.38 s) to 1 (0 ms) per 10 s, and the queue
worker's waits for the lock from 1.47 s to 0.18 s per 10 s.
…locked

With APS5_PROFILE_DRAW set, the [present] line now counts the presents
whose sync through the display buffer's DCC keys waited for the GPU
before the key check, outside the GPU mutex, and the milliseconds they
waited: the waits the presenter took under the mutex before.
…t the GPU mutex

A headless device presents a DCC display buffer while a recorded kernel
that copies over its keys is still pending, holding the GPU mutex once as
Driver::Present does. The present must release the mutex for that wait
(the hold serial advances), read the keys the kernel stored and reach the
swapchain; with nothing pending it must keep the mutex. It stops at the
missing swapchain, after the key check.
@github-actions github-actions Bot added perf Performance change perf numbers missing perf pull request without a before and after summary line labels Oct 23, 2026
@github-actions

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 Oct 23, 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 1395 core/libs/prx/libSceAgcDriver/Execution/include/VulkanDevice.hpp
core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
PR 2434 core/libs/prx/libSceAgcDriver/Execution/include/VulkanDevice.hpp
core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
PR 4040 core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
PR 5021 core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
PR 5441 core/libs/prx/libSceAgcDriver/Execution/include/VulkanDevice.hpp
core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
PR 5925 core/libs/prx/libSceAgcDriver/Execution/include/VulkanDevice.hpp
core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
PR 6188 core/libs/prx/libSceAgcDriver/Execution/include/VulkanDevice.hpp
core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
PR 6960 core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
PR 6977 core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
PR 7201 core/libs/prx/libSceAgcDriver/Execution/include/VulkanDevice.hpp
core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
PR 7275 core/libs/prx/libSceAgcDriver/Execution/src/Driver/Presentation.cpp
core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
PR 7369 core/libs/prx/libSceAgcDriver/Execution/include/VulkanDevice.hpp
core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
PR 7449 core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
PR 7484 core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
PR 8004 core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
PR 8014 core/libs/prx/libSceAgcDriver/Execution/include/VulkanDevice.hpp
core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
PR 9176 core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
PR 9287 core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
PR 9289 core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
PR 9356 core/libs/prx/libSceAgcDriver/Execution/include/VulkanDevice.hpp
core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
PR 9387 core/libs/prx/libSceAgcDriver/Execution/include/VulkanDevice.hpp
core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
PR 9431 core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
PR 9432 core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
PR 9489 core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
PR 9508 core/libs/prx/libSceAgcDriver/Execution/include/VulkanDevice.hpp
core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
PR 9672 core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
PR 9673 core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
PR 9674 core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
PR 9675 core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
PR 9676 core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
PR 9842 core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
PR 10193 core/libs/prx/libSceAgcDriver/Execution/include/VulkanDevice.hpp
core/libs/prx/libSceAgcDriver/Execution/src/Driver/Presentation.cpp
core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
PR 10435 core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
PR 10442 core/libs/prx/libSceAgcDriver/Execution/include/VulkanDevice.hpp
core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
PR 10547 core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp

@github-actions github-actions Bot added the agc libSceAgc* label Oct 23, 2026
EagleBearerYS added a commit to EagleBearerYS/AnyPS5 that referenced this pull request Oct 24, 2026
@github-actions github-actions Bot removed the perf numbers missing perf pull request without a before and after summary line label Oct 24, 2026
@EagleBearerYS
EagleBearerYS marked this pull request as ready for review October 24, 2026 21:54
@oneandonlydean oneandonlydean self-assigned this Oct 25, 2026
@oneandonlydean
oneandonlydean merged commit 3fcef22 into boykopovar:main Oct 26, 2026
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agc libSceAgc* perf Performance change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants