perf(agc): relink library pipelines with link-time optimization in the background #2713

Merged
adriadam10 merged 1 commit from upstream-pr/2713 into main 2026-10-10 12:36:44 +00:00
adriadam10 commented 2026-10-10 11:55:05 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-10T11:55:05Z.


What

A graphics pipeline linked from libraries (#2636) is fast-linked at the draw, as before. A background thread then links the same libraries again with VK_PIPELINE_CREATE_LINK_TIME_OPTIMIZATION_BIT_EXT, and the pipeline binds the optimized one from the next draw on. This is the TechnicalDebt entry #2636 added.

Why: a fast link cannot drop the vertex outputs the fragment stage doesn't read. I measured it with VK_KHR_pipeline_executable_properties on RADV (Radeon 660M, Mesa 26.2.4), using Astro's Playroom's 483 prepared vertex shaders, each paired with a fragment stage that reads none of their outputs:

fast link vs whole pipeline (vertex stage) worse in median max
VGPRs 346/483 +8 +40 (2.5×)
instructions 259/483 +49 +727
code size 258/483 +220 B +4140 B

The optimized link equals the whole pipeline on every statistic in 483/483. On NVIDIA (RTX 4090, Raghav314's run in #2242) 13 of 15 PPSA36082 vertex shaders went from 38 to up to 68 registers fast-linked, and the optimized link gave back the whole pipeline's code.

Changes:

  • PipelineLibrary: libraries are created with RETAIN_LINK_TIME_OPTIMIZATION_INFO. LinkPipelineFromLibraries returns the fast link and queues the optimized link on one detached worker. The result goes into an OptimizedPipeline slot shared with the Pipeline. Whichever side comes second (the Pipeline being destroyed, or the job finishing) destroys it, through an atomic exchange, so it is destroyed exactly once.
  • Pipeline::Continue binds the optimized handle once it exists. The fast pipeline stays alive until the Pipeline is destroyed, since recorded draws may still reference it.
  • ClearPipelineLibraries, and so ClearCachedPipelines at device teardown, waits for the device's pending jobs. WaitForOptimizedPipelines does the same for tests.
  • APS5_NO_PIPELINE_LTO=1 keeps fast links only.

Tested

Linux, AMD Radeon 660M (RADV, Mesa 26.2.4), and CI's lavapipe (Mesa 25.2.8).

result
ctest -R '^agc_|^shader', GPL on (default) 320/320
same with APS5_NO_GPL=1 (today's path) 320/320
^agc_ on CI's lavapipe (GPL on), without the 4-minute buffer_format 318/318
same under VK_LAYER_KHRONOS_validation, GPL on and off no VUID only with GPL (both report the same 3 already on main: VUID-vkCmdPipelineBarrier-dstAccessMask-02816, VUID-vkCmdPipelineBarrier-srcAccessMask-02815, VUID-VkPipelineColorBlendStateCreateInfo-pAttachments-00605)
pipeline tests (agc_pipeline_library, recorder, depth bias per face, dual-source blend, mesh) --repeat until-fail:20 all passed

agc_pipeline_library now waits for the worker and checks two things: every linked pipeline got its optimized link, and two of them bind it. The new agc_pipeline_library_fast_only runs the same test with APS5_NO_PIPELINE_LTO=1 and expects none.

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 in TechnicalDebt
  • 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
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4811004255 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2713). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-10T11:55:05Z. --- ### What A graphics pipeline linked from libraries (#2636) is fast-linked at the draw, as before. A background thread then links the same libraries again with `VK_PIPELINE_CREATE_LINK_TIME_OPTIMIZATION_BIT_EXT`, and the pipeline binds the optimized one from the next draw on. This is the TechnicalDebt entry #2636 added. Why: a fast link cannot drop the vertex outputs the fragment stage doesn't read. I measured it with `VK_KHR_pipeline_executable_properties` on RADV (Radeon 660M, Mesa 26.2.4), using Astro's Playroom's 483 prepared vertex shaders, each paired with a fragment stage that reads none of their outputs: | fast link vs whole pipeline (vertex stage) | worse in | median | max | |---|---|---|---| | VGPRs | 346/483 | +8 | +40 (2.5×) | | instructions | 259/483 | +49 | +727 | | code size | 258/483 | +220 B | +4140 B | The optimized link equals the whole pipeline on every statistic in 483/483. On NVIDIA (RTX 4090, Raghav314's run in #2242) 13 of 15 PPSA36082 vertex shaders went from 38 to up to 68 registers fast-linked, and the optimized link gave back the whole pipeline's code. Changes: - `PipelineLibrary`: libraries are created with `RETAIN_LINK_TIME_OPTIMIZATION_INFO`. `LinkPipelineFromLibraries` returns the fast link and queues the optimized link on one detached worker. The result goes into an `OptimizedPipeline` slot shared with the `Pipeline`. Whichever side comes second (the `Pipeline` being destroyed, or the job finishing) destroys it, through an atomic exchange, so it is destroyed exactly once. - `Pipeline::Continue` binds the optimized handle once it exists. The fast pipeline stays alive until the `Pipeline` is destroyed, since recorded draws may still reference it. - `ClearPipelineLibraries`, and so `ClearCachedPipelines` at device teardown, waits for the device's pending jobs. `WaitForOptimizedPipelines` does the same for tests. - `APS5_NO_PIPELINE_LTO=1` keeps fast links only. ### Tested Linux, AMD Radeon 660M (RADV, Mesa 26.2.4), and CI's lavapipe (Mesa 25.2.8). | | result | |---|---| | `ctest -R '^agc_\|^shader'`, GPL on (default) | 320/320 | | same with `APS5_NO_GPL=1` (today's path) | 320/320 | | `^agc_` on CI's lavapipe (GPL on), without the 4-minute `buffer_format` | 318/318 | | same under `VK_LAYER_KHRONOS_validation`, GPL on and off | no VUID only with GPL (both report the same 3 already on main: `VUID-vkCmdPipelineBarrier-dstAccessMask-02816`, `VUID-vkCmdPipelineBarrier-srcAccessMask-02815`, `VUID-VkPipelineColorBlendStateCreateInfo-pAttachments-00605`) | | pipeline tests (`agc_pipeline_library`, recorder, depth bias per face, dual-source blend, mesh) `--repeat until-fail:20` | all passed | `agc_pipeline_library` now waits for the worker and checks two things: every linked pipeline got its optimized link, and two of them bind it. The new `agc_pipeline_library_fast_only` runs the same test with `APS5_NO_PIPELINE_LTO=1` and expects none. ### 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 in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md#silent-stubs) - [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] AI-assisted: yes
adriadam10 commented 2026-10-10 12:25:04 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-10T12:25:04Z.


Fixed: agc_pipeline_library_fast_only lacked the Windows PATH to libc's DLL (exit 0xc0000135 in the full build). It now gets the same ENVIRONMENT_MODIFICATION as the other two pipeline-library tests.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6097466974 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2713#issuecomment-6097466974). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-10T12:25:04Z. --- Fixed: `agc_pipeline_library_fast_only` lacked the Windows PATH to libc's DLL (exit 0xc0000135 in the full build). It now gets the same ENVIRONMENT_MODIFICATION as the other two pipeline-library tests.
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!2713
No description provided.