perf(agc): prebuild registration libraries on half the hardware threads by default #10388

Merged
Tamalero merged 1 commit from upstream-pr/10388 into main 2026-10-27 01:59:12 +00:00
Tamalero commented 2026-10-23 20:39:54 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Tamalero on 2026-10-23T20:39:54Z.


What

On a device with graphics pipeline libraries, the registration-form vertex and pixel libraries are linked on the library prebuild pool. Since 361c7e202 that pool has one thread unless APS5_PREBUILD_THREADS says otherwise. On NVIDIA it is the startup bottleneck. With a warm shader cache, High on Life (PPSA15388) spends about 50 s with a single busy thread before its first present. perf record -g on that thread shows VulkanDevice::PrebuildGraphicsLibraries → Graphics::Pipeline::Prebuild → LinkPipelineFromLibraries → the NVIDIA compiler, with 96% of its samples in the compiler.

Change: the prebuild pool now defaults to the size of the registration preparation pool: half the hardware threads, at least two. APS5_PREBUILD_THREADS still sets the count, and APS5_PREBUILD_THREADS=1 gives the old behaviour. RegistrationPrepareStack counts the new default, and the docs/dev/ENVIRONMENT.md row describes it. agc_driver_shutdown_threads_queued_prebuilds now runs with APS5_PREBUILD_THREADS=1. It blocks one prebuild and checks that close drops the tasks queued behind it, and with more workers those tasks start right away on the other threads.

Tested

Hosts:

  • Linux 7.3 (CachyOS), i9-14900K (32 threads), RTX 4090 with NVIDIA 615.78.08, GCC 16.2, Release.
  • AMD leg: Ubuntu 24.04, EPYC 7452 (24 vCPUs), Radeon Pro V620 with RADV (Mesa 25.2.8).

Method: warm shader cache, no input. Time is measured from launch to the title's first present.

Title GPU Build Threads First present
PPSA15388 RTX 4090 main e13027a1f 1 76 s, 64 s
PPSA15388 RTX 4090 this PR 2a3cc3458 16 (default) 11 s, 9 s
PPSA15388 RTX 4090 main 74f6fa8e3 / the same change on it 1 / 16 61 s, 62 s, 60 s, 71 s, 62 s / 10 s, 11 s, 10 s, 10 s, 9 s, 9 s, 9 s
PPSA15388 RTX 4090 main c188e01a4 1 / APS5_PREBUILD_THREADS=16 61 s, 60 s / 10 s, 9 s
PPSA01474 RTX 4090 main c188e01a4 1 / APS5_PREBUILD_THREADS=16 21 s, 13 s / 7 s, 5 s
PPSA01474 V620 (RADV) 74700a08d APS5_PREBUILD_THREADS=1 / =12 25 s, 24 s / 25 s, 25 s, 25 s
  • Four runs (three on main, one with this change) crashed after their first present, in a guest-side race of this title that predates both builds. Their first-present times are included.
  • On NVIDIA, startup to the first present is about 6× faster for PPSA15388 and 2–3× faster for PPSA01474. While prebuilding, 15–17 threads are busy instead of one.
  • On RADV the device also takes the pipeline-library path (pipelineLibrary=1), but the start time doesn't change. Linking isn't the bottleneck there, so the change neither helps nor hurts.
  • Gameplay: I checked whether the extra prebuild threads compete with the title during play. The test was PPSA15388 on c188e01a4, the same walking route twice, with APS5_TRACE_SUMMARY_EVERY=10. Over the walking intervals:
Threads Intervals / frames Frame p50 p90 p99 Worst
1 8 / 588 116 ms 248 ms 538 ms 950 ms
16 6 / 451 109 ms 229 ms 490 ms 876 ms

No regression.

Summary lines: PPSA15388 title screen, APS5_TRACE_SECONDS=10:10, same machine. These are the runs whose traces are attached. Once the title is up, frame times and GPU time are unchanged:

{"commit":"e13027a1f399","dirty":false,"env":{"APS5_PLAYGO_UNLISTED_CHUNKS":"installed","APS5_TRACE_SECONDS":"10:10"},"gpu":"NVIDIA GeForce RTX 4090","driver":"NVIDIA 615.78.08","os":"Linux 7.3.0-3-cachyos","cpu":"Intel(R) Core(TM) i9-14900K","cpu_threads":32,"memory_mib":64108,"title_id":"PPSA15388","title":"High on Life","content_version":"01.120.000","resolution":"3840x2160","window":{"spec":"seconds 10:10","first_present":362,"ms":10010.008},"presents":507,"frame_ms":{"p50":16.684,"p90":16.881,"p99":61.894,"max":789.127},"gpu_busy_ms_per_present":7.541,"worker_busy_pct":{"queue worker 0x0":69.483,"queue worker 0x20":58.327},"top_phases_ms_per_frame":{"Driver.Packet":25.107,"VideoOut.Flip":13.152,"VideoOut.Flip.vblank_wait":11.167,"Driver.Packet.memory_wait":10.184,"Driver.Packet.dispatch":6.601,"Driver.Dispatch":4.337,"Driver.Packet.pipeline_drain":4.113,"Graphics.Draw":3.794},"trace_dropped":false,"trace":"aps5-trace-e13027a1f399-2.json.gz"}
{"commit":"2a3cc34582af","dirty":false,"env":{"APS5_PLAYGO_UNLISTED_CHUNKS":"installed","APS5_TRACE_SECONDS":"10:10"},"gpu":"NVIDIA GeForce RTX 4090","driver":"NVIDIA 615.78.08","os":"Linux 7.3.0-3-cachyos","cpu":"Intel(R) Core(TM) i9-14900K","cpu_threads":32,"memory_mib":64108,"title_id":"PPSA15388","title":"High on Life","content_version":"01.120.000","resolution":"3840x2160","window":{"spec":"seconds 10:10","first_present":350,"ms":10011.932},"presents":500,"frame_ms":{"p50":16.683,"p90":18.011,"p99":69.776,"max":852.701},"gpu_busy_ms_per_present":7.070,"worker_busy_pct":{"queue worker 0x0":72.595,"queue worker 0x20":61.289},"top_phases_ms_per_frame":{"Driver.Packet":26.666,"VideoOut.Flip":12.675,"Driver.Packet.memory_wait":10.893,"VideoOut.Flip.vblank_wait":10.636,"Driver.Packet.pipeline_drain":5.999,"Driver.Packet.dispatch":5.616,"Driver.Dispatch":4.671,"Graphics.Draw":3.941},"trace_dropped":false,"trace":"aps5-trace-2a3cc34582af-2.json.gz"}

AGC tests:

  • On this PR's head and main e13027a1f, the 39 tests matching prebuild|registration_prepare|prepared_|shutdown_threads pass on both, with the same validation errors: vkCreateDevice-ppEnabledExtensionNames-01387 ×108 and VkPipelineColorBlendStateCreateInfo-pAttachments-00605 ×14.
  • Before the rebase, all 686 agc_driver tests were run with ctest -V -j8 on main 74f6fa8e3 and this change, with VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation ANYPS5_NO_SHADER_CACHE=1 ANYPS5_REQUIRE_VULKAN=1, on the RTX 4090.
  • Neither log reports the layer as not found.
  • Both logs have the same validation errors with the same counts, so this PR adds no new VUID-: vkCreateDevice-ppEnabledExtensionNames-01387 ×1506, VkWriteDescriptorSet-descriptorType-00337 ×18, VkPipelineColorBlendStateCreateInfo-pAttachments-00605 ×18, VkImageMemoryBarrier-image-03320 ×6.
  • Failures:
    • agc_driver_sample_order, _grid_reference and _recipe_depth_locations fail on both. #9056 and #9503 are open for them.
    • This PR also fails agc_driver_pixel_lds, with a device fault. It fails the same way on main 74f6fa8e3 when run alone (3 of 3 runs, and 5 of 5 on this PR with APS5_PREBUILD_THREADS=1), so it isn't caused by this change. It passed once in main's parallel run.
  • Fixed in this PR: agc_driver_shutdown_threads_queued_prebuilds failed with the new default ("closing ran the queued library prebuilds"). With one blocked worker, the other workers ran the queued prebuilds. Its environment now pins APS5_PREBUILD_THREADS=1. All nine agc_driver_shutdown_threads* tests pass.
  • Negative check: with ShaderRegistry.cpp from main, agc_driver_registration_prepare_stack fails with "the preparation and prebuild pools count 17 live threads of the 32 they started". With this PR it passes.
  • tools/check_conventions.py passes. tools/env_reference.py --check reports only APS5_NO_WGI, which is undocumented on main too.

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: NVIDIA GeForce RTX 4090, 615.78.08, Linux 7.3 (all agc_driver tests and titles); AMD Radeon Pro V620, RADV Mesa 25.2.8, Ubuntu 24.04 (title start only)
  • AI-assisted: yes

🤖 Generated with Claude Code

Tested and written by Claude (AI assistant) on a contributor's machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4988976873 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10388). Originally posted by [Tamalero](https://github.com/Tamalero) on 2026-10-23T20:39:54Z. --- ### What On a device with graphics pipeline libraries, the registration-form vertex and pixel libraries are linked on the library prebuild pool. Since 361c7e202 that pool has one thread unless `APS5_PREBUILD_THREADS` says otherwise. On NVIDIA it is the startup bottleneck. With a warm shader cache, High on Life (PPSA15388) spends about 50 s with a single busy thread before its first present. `perf record -g` on that thread shows `VulkanDevice::PrebuildGraphicsLibraries` → `Graphics::Pipeline::Prebuild` → `LinkPipelineFromLibraries` → the NVIDIA compiler, with 96% of its samples in the compiler. **Change:** the prebuild pool now defaults to the size of the registration preparation pool: half the hardware threads, at least two. `APS5_PREBUILD_THREADS` still sets the count, and `APS5_PREBUILD_THREADS=1` gives the old behaviour. `RegistrationPrepareStack` counts the new default, and the `docs/dev/ENVIRONMENT.md` row describes it. `agc_driver_shutdown_threads_queued_prebuilds` now runs with `APS5_PREBUILD_THREADS=1`. It blocks one prebuild and checks that close drops the tasks queued behind it, and with more workers those tasks start right away on the other threads. ### Tested **Hosts:** - Linux 7.3 (CachyOS), i9-14900K (32 threads), RTX 4090 with NVIDIA 615.78.08, GCC 16.2, Release. - AMD leg: Ubuntu 24.04, EPYC 7452 (24 vCPUs), Radeon Pro V620 with RADV (Mesa 25.2.8). **Method:** warm shader cache, no input. Time is measured from launch to the title's first present. | Title | GPU | Build | Threads | First present | |---|---|---|---|---| | PPSA15388 | RTX 4090 | `main` e13027a1f | 1 | 76 s, 64 s | | PPSA15388 | RTX 4090 | this PR 2a3cc3458 | 16 (default) | 11 s, 9 s | | PPSA15388 | RTX 4090 | `main` 74f6fa8e3 / the same change on it | 1 / 16 | 61 s, 62 s, 60 s, 71 s, 62 s / 10 s, 11 s, 10 s, 10 s, 9 s, 9 s, 9 s | | PPSA15388 | RTX 4090 | `main` c188e01a4 | 1 / `APS5_PREBUILD_THREADS=16` | 61 s, 60 s / 10 s, 9 s | | PPSA01474 | RTX 4090 | `main` c188e01a4 | 1 / `APS5_PREBUILD_THREADS=16` | 21 s, 13 s / 7 s, 5 s | | PPSA01474 | V620 (RADV) | 74700a08d | `APS5_PREBUILD_THREADS=1` / `=12` | 25 s, 24 s / 25 s, 25 s, 25 s | - Four runs (three on `main`, one with this change) crashed after their first present, in a guest-side race of this title that predates both builds. Their first-present times are included. - **On NVIDIA**, startup to the first present is about 6× faster for PPSA15388 and 2–3× faster for PPSA01474. While prebuilding, 15–17 threads are busy instead of one. - **On RADV** the device also takes the pipeline-library path (`pipelineLibrary=1`), but the start time doesn't change. Linking isn't the bottleneck there, so the change neither helps nor hurts. - **Gameplay:** I checked whether the extra prebuild threads compete with the title during play. The test was PPSA15388 on c188e01a4, the same walking route twice, with `APS5_TRACE_SUMMARY_EVERY=10`. Over the walking intervals: | Threads | Intervals / frames | Frame p50 | p90 | p99 | Worst | |---|---|---|---|---|---| | 1 | 8 / 588 | 116 ms | 248 ms | 538 ms | 950 ms | | 16 | 6 / 451 | 109 ms | 229 ms | 490 ms | 876 ms | No regression. **Summary lines:** PPSA15388 title screen, `APS5_TRACE_SECONDS=10:10`, same machine. These are the runs whose traces are attached. Once the title is up, frame times and GPU time are unchanged: ``` {"commit":"e13027a1f399","dirty":false,"env":{"APS5_PLAYGO_UNLISTED_CHUNKS":"installed","APS5_TRACE_SECONDS":"10:10"},"gpu":"NVIDIA GeForce RTX 4090","driver":"NVIDIA 615.78.08","os":"Linux 7.3.0-3-cachyos","cpu":"Intel(R) Core(TM) i9-14900K","cpu_threads":32,"memory_mib":64108,"title_id":"PPSA15388","title":"High on Life","content_version":"01.120.000","resolution":"3840x2160","window":{"spec":"seconds 10:10","first_present":362,"ms":10010.008},"presents":507,"frame_ms":{"p50":16.684,"p90":16.881,"p99":61.894,"max":789.127},"gpu_busy_ms_per_present":7.541,"worker_busy_pct":{"queue worker 0x0":69.483,"queue worker 0x20":58.327},"top_phases_ms_per_frame":{"Driver.Packet":25.107,"VideoOut.Flip":13.152,"VideoOut.Flip.vblank_wait":11.167,"Driver.Packet.memory_wait":10.184,"Driver.Packet.dispatch":6.601,"Driver.Dispatch":4.337,"Driver.Packet.pipeline_drain":4.113,"Graphics.Draw":3.794},"trace_dropped":false,"trace":"aps5-trace-e13027a1f399-2.json.gz"} {"commit":"2a3cc34582af","dirty":false,"env":{"APS5_PLAYGO_UNLISTED_CHUNKS":"installed","APS5_TRACE_SECONDS":"10:10"},"gpu":"NVIDIA GeForce RTX 4090","driver":"NVIDIA 615.78.08","os":"Linux 7.3.0-3-cachyos","cpu":"Intel(R) Core(TM) i9-14900K","cpu_threads":32,"memory_mib":64108,"title_id":"PPSA15388","title":"High on Life","content_version":"01.120.000","resolution":"3840x2160","window":{"spec":"seconds 10:10","first_present":350,"ms":10011.932},"presents":500,"frame_ms":{"p50":16.683,"p90":18.011,"p99":69.776,"max":852.701},"gpu_busy_ms_per_present":7.070,"worker_busy_pct":{"queue worker 0x0":72.595,"queue worker 0x20":61.289},"top_phases_ms_per_frame":{"Driver.Packet":26.666,"VideoOut.Flip":12.675,"Driver.Packet.memory_wait":10.893,"VideoOut.Flip.vblank_wait":10.636,"Driver.Packet.pipeline_drain":5.999,"Driver.Packet.dispatch":5.616,"Driver.Dispatch":4.671,"Graphics.Draw":3.941},"trace_dropped":false,"trace":"aps5-trace-2a3cc34582af-2.json.gz"} ``` **AGC tests:** - On this PR's head and `main` e13027a1f, the 39 tests matching `prebuild|registration_prepare|prepared_|shutdown_threads` pass on both, with the same validation errors: `vkCreateDevice-ppEnabledExtensionNames-01387` ×108 and `VkPipelineColorBlendStateCreateInfo-pAttachments-00605` ×14. - Before the rebase, all 686 `agc_driver` tests were run with `ctest -V -j8` on `main` 74f6fa8e3 and this change, with `VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation ANYPS5_NO_SHADER_CACHE=1 ANYPS5_REQUIRE_VULKAN=1`, on the RTX 4090. - Neither log reports the layer as not found. - Both logs have the same validation errors with the same counts, so this PR adds no new `VUID-`: `vkCreateDevice-ppEnabledExtensionNames-01387` ×1506, `VkWriteDescriptorSet-descriptorType-00337` ×18, `VkPipelineColorBlendStateCreateInfo-pAttachments-00605` ×18, `VkImageMemoryBarrier-image-03320` ×6. - **Failures:** - `agc_driver_sample_order`, `_grid_reference` and `_recipe_depth_locations` fail on both. #9056 and #9503 are open for them. - This PR also fails `agc_driver_pixel_lds`, with a device fault. It fails the same way on `main` 74f6fa8e3 when run alone (3 of 3 runs, and 5 of 5 on this PR with `APS5_PREBUILD_THREADS=1`), so it isn't caused by this change. It passed once in `main`'s parallel run. - **Fixed in this PR:** `agc_driver_shutdown_threads_queued_prebuilds` failed with the new default ("closing ran the queued library prebuilds"). With one blocked worker, the other workers ran the queued prebuilds. Its environment now pins `APS5_PREBUILD_THREADS=1`. All nine `agc_driver_shutdown_threads*` tests pass. - **Negative check:** with `ShaderRegistry.cpp` from `main`, `agc_driver_registration_prepare_stack` fails with "the preparation and prebuild pools count 17 live threads of the 32 they started". With this PR it passes. - `tools/check_conventions.py` passes. `tools/env_reference.py --check` reports only `APS5_NO_WGI`, which is undocumented on `main` too. ### Checklist - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: NVIDIA GeForce RTX 4090, 615.78.08, Linux 7.3 (all `agc_driver` tests and titles); AMD Radeon Pro V620, RADV Mesa 25.2.8, Ubuntu 24.04 (title start only) - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code) *Tested and written by Claude (AI assistant) on a contributor's machine.*
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!10388
No description provided.