perf(agc): build large graphics pipelines in the background #19119

Merged
Remi-Bon merged 5 commits from upstream-pr/19119 into main 2026-11-18 23:47:32 +00:00
Remi-Bon commented 2026-11-12 19:57:40 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Remi-Bon on 2026-11-12T19:57:40Z.


What

A cold graphics pipeline whose shaders are large blocks the draw while the driver compiles it; on Gran Turismo 7 (PPSA01317) each such pipeline takes 3.5 to 4.4 s on amdvlk, and the World Map and Garage freeze for minutes on a cold cache.

APS5_ASYNC_PIPELINE_WORDS=<n> (unset by default, so nothing changes without it):

  • a draw whose shaders total at least n SPIR-V words and whose pipeline is not resident is skipped, and the pipeline is built on worker threads (a quarter of the hardware threads, at least two) from copies of the draw's context, state, vertex layout, set-layout keys and programs;
  • the store key is the same one CachedPipeline computes, so the next draw of that configuration finds the pipeline resident;
  • a configuration already queued is not queued twice; a failed build is retried synchronously by the next draw so its error surfaces;
  • ClearCachedPipelines waits for running builds before the device's pipelines are destroyed.

#5925 builds the pipelines of a submission ahead of its draws, which still wait for them; this change skips the draw instead, and the two can be combined.

Skipped draws are missing from the frames rendered while their pipeline builds, which is the trade-off the variable opts into.

Tested

  • Windows 11, AMD Radeon RX 9070 (driver 32.0.32015.7029), Gran Turismo 7 (PPSA01317), cold shader cache, APS5_ASYNC_PIPELINE_WORDS=50000: no freeze at the title, World Map or Garage; 433 background builds of 3.5 to 4.4 s, 0 failures. Objects are missing until the queue drains. Without the variable the same scenes freeze for 8 to 25 minutes.
  • Warm cache, APS5_ASYNC_PIPELINE_WORDS=200000: 8 builds, 1.6 s median, 0 failures.
  • New mock-Vulkan test agc_pipeline_deferred_build: a cold configuration is skipped, its build becomes resident under the key CachedPipeline uses even after the caller's programs and keys are freed, a second configuration is queued, and ClearCachedPipelines leaves no Vulkan object alive. agc_pipeline_store_*, agc_pipeline_journal* and agc_pipeline_library_clear_waits_for_build pass.
  • ctest --test-dir build -R 'agc_pipeline|agc_driver_pm4|agc_predication|agc_driver_pipelined_predica' -V on main (5634912b95) and on this branch, same machine and GPU, with ANYPS5_REQUIRE_VULKAN=1, ANYPS5_NO_SHADER_CACHE=1 and VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation (SDK 1.4.363.1, layer load confirmed with VK_LOADER_DEBUG=layer): 56/60 on main, 57/61 here (the extra one is agc_pipeline_deferred_build); the same four tests are Not Run on both (agc_pipeline_link_optimization, agc_pipeline_queue_failure_wait|clear|stop, executables not built). Neither log has VUID- or the layer-not-found message.
  • Not measured with tools/trace_digest.py: the change removes stalls rather than changing steady-state frame time.
  • After rebasing onto main (b99796f81b), agc_pipeline_deferred_build, agc_pipeline_store_*, agc_driver_pm4 and agc_predication_tests pass again under the same validation settings, with no VUID-.

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: PPSA01317 #4697
  • GPUs tested: AMD Radeon RX 9070, driver 32.0.32015.7029, Windows 11 Pro 26300
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5284266908 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/19119). Originally posted by [Remi-Bon](https://github.com/Remi-Bon) on 2026-11-12T19:57:40Z. --- ### What A cold graphics pipeline whose shaders are large blocks the draw while the driver compiles it; on Gran Turismo 7 (PPSA01317) each such pipeline takes 3.5 to 4.4 s on amdvlk, and the World Map and Garage freeze for minutes on a cold cache. `APS5_ASYNC_PIPELINE_WORDS=<n>` (unset by default, so nothing changes without it): - a draw whose shaders total at least n SPIR-V words and whose pipeline is not resident is skipped, and the pipeline is built on worker threads (a quarter of the hardware threads, at least two) from copies of the draw's context, state, vertex layout, set-layout keys and programs; - the store key is the same one `CachedPipeline` computes, so the next draw of that configuration finds the pipeline resident; - a configuration already queued is not queued twice; a failed build is retried synchronously by the next draw so its error surfaces; - `ClearCachedPipelines` waits for running builds before the device's pipelines are destroyed. #5925 builds the pipelines of a submission ahead of its draws, which still wait for them; this change skips the draw instead, and the two can be combined. Skipped draws are missing from the frames rendered while their pipeline builds, which is the trade-off the variable opts into. ### Tested <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> - Windows 11, AMD Radeon RX 9070 (driver 32.0.32015.7029), Gran Turismo 7 (PPSA01317), cold shader cache, `APS5_ASYNC_PIPELINE_WORDS=50000`: no freeze at the title, World Map or Garage; 433 background builds of 3.5 to 4.4 s, 0 failures. Objects are missing until the queue drains. Without the variable the same scenes freeze for 8 to 25 minutes. - Warm cache, `APS5_ASYNC_PIPELINE_WORDS=200000`: 8 builds, 1.6 s median, 0 failures. - New mock-Vulkan test `agc_pipeline_deferred_build`: a cold configuration is skipped, its build becomes resident under the key `CachedPipeline` uses even after the caller's programs and keys are freed, a second configuration is queued, and `ClearCachedPipelines` leaves no Vulkan object alive. `agc_pipeline_store_*`, `agc_pipeline_journal*` and `agc_pipeline_library_clear_waits_for_build` pass. - `ctest --test-dir build -R 'agc_pipeline|agc_driver_pm4|agc_predication|agc_driver_pipelined_predica' -V` on `main` (5634912b95) and on this branch, same machine and GPU, with `ANYPS5_REQUIRE_VULKAN=1`, `ANYPS5_NO_SHADER_CACHE=1` and `VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation` (SDK 1.4.363.1, layer load confirmed with `VK_LOADER_DEBUG=layer`): 56/60 on `main`, 57/61 here (the extra one is `agc_pipeline_deferred_build`); the same four tests are Not Run on both (`agc_pipeline_link_optimization`, `agc_pipeline_queue_failure_wait|clear|stop`, executables not built). Neither log has `VUID-` or the layer-not-found message. - Not measured with `tools/trace_digest.py`: the change removes stalls rather than changing steady-state frame time. - After rebasing onto `main` (b99796f81b), `agc_pipeline_deferred_build`, `agc_pipeline_store_*`, `agc_driver_pm4` and `agc_predication_tests` pass again under the same validation settings, with no `VUID-`. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [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: PPSA01317 #4697 - [x] GPUs tested: AMD Radeon RX 9070, driver 32.0.32015.7029, Windows 11 Pro 26300 - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
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!19119
No description provided.