fix(agc): keep a shader library part's modules until the part is destroyed #3149

Closed
poonasor wants to merge 1 commit from upstream-pr/3149 into main
poonasor commented 2026-10-10 23:17:37 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by poonasor on 2026-10-10T23:17:37Z.


What

Pipeline destroys its shader modules right after LinkPipelineFromLibraries returns, but the pre-rasterization and fragment shader library parts built from them stay cached and are relinked later by the background VK_PIPELINE_CREATE_LINK_TIME_OPTIMIZATION_BIT_EXT link (#2713). On AMD's Windows driver that link faults inside amdvlk64.dll, at varying offsets, reading freed heap memory. Destroying a module after pipeline creation is valid Vulkan, so this looks like a driver defect; the change works around it.

When the optimized link is enabled, the library store takes over the modules of each newly built shader part and destroys them in ClearPipelineLibraries, after the pending links have finished. Modules of a pipeline whose parts all came from the cache are destroyed as before, and nothing changes with APS5_NO_PIPELINE_LTO=1. Cost: one retained VkShaderModule per stage of each unique shader part, for the device's lifetime.

This is the AMD half of #2777: #2869 fixed the destroyed layout, which did not change the AMD failures (as noted there and in #2755). Addresses the segfaults in #2944 and #2755.

How the cause was narrowed down (RX 6700 XT, on 57f96fd2 + 51078717, agc_driver_vertex_fetch and agc_driver_provoking_vertex):

  • gdb puts the faulting thread in the LinkPipelineFromLibraries job, inside vkCreateGraphicsPipelines.
  • APS5_NO_PIPELINE_LTO=1: pass.
  • Optimized link run synchronously under the store lock instead of on the worker: still faults (2 of 3 runs each), so it is not a race in our code.
  • Optimized link with a null VkPipelineCache: still faults 3/3.
  • Shader modules never destroyed: pass 4/4 each (0/4 without).
  • Implicit layers disabled (VK_LOADER_LAYERS_DISABLE=~implicit~): still faults.

Tested

Windows 11 Pro 23H2 (22631), WinLibs GCC 15.2.0 r7, Ninja, Release, BUILD_TESTING=ON. AMD Radeon RX 6700 XT (Navi 22, 0x73df), Adrenalin 25.10.45.05 (driver 32.0.21045.5002), the only Vulkan device. %LOCALAPPDATA%\AMD\VkCache emptied before each agc_ run, ctest -R "^agc_" -j1:

Build Failed of 324
main 379d8b4e 24: 22 SEGFAULT in amdvlk64.dll, plus sdwa_float_selectors and sdwa_ldexp_f16
main 379d8b4e + this PR 3: pixel_interlock, sdwa_float_selectors, sdwa_ldexp_f16, no SEGFAULT

The 22: agc_pipeline_cache, agc_pipeline_library, and agc_driver_ mesh, conservative_rasterization, depth_bias_per_face, dual_source_blend, exec_host_lanes, ngg_vertex_wave_info, packed_unorm_color_target, pixel_fixed_point_position, pixel_helper_lanes, pixel_interlock, pixel_lds, pixel_lds_lane_slots, pixel_uint16_export, pixel_valid_mask, pixel_wave_reduction, prepared_exports, provoking_vertex, scalar_swappc_fetch, srgb8_color_target, vertex_fetch.

Full parallel ctest with this PR (warm driver cache): 724 of 732 passed, 5 skipped (video_out flip tests, guest_video_out_wqhd_detection_no_vulkan), the same 3 failed.

The 3 remaining failures are wrong results, not faults, and are not addressed here: the two sdwa f16 ones are the values already in #2944; pixel_interlock no longer faults and fails with pixel interlock wave64 BDA fault: pixel 0 counted 1 of 0 overlapping read-modify-writes, which it also does with APS5_NO_PIPELINE_LTO=1.

Title: Dreaming Sarah (PPSA02929), which faulted in amdvlk64.dll+0x21eef34 at its first graphics submission on this machine (discussion #3018), relinked against this build runs for 90 s with no fault in the log. I did not check the rendered output.

Not tested on NVIDIA, Intel or Linux.

python tools/check_conventions.py --base origin/main passes.

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 (Claude Code)

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4815133719 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3149). Originally posted by [poonasor](https://github.com/poonasor) on 2026-10-10T23:17:37Z. --- ### What `Pipeline` destroys its shader modules right after `LinkPipelineFromLibraries` returns, but the pre-rasterization and fragment shader library parts built from them stay cached and are relinked later by the background `VK_PIPELINE_CREATE_LINK_TIME_OPTIMIZATION_BIT_EXT` link (#2713). On AMD's Windows driver that link faults inside `amdvlk64.dll`, at varying offsets, reading freed heap memory. Destroying a module after pipeline creation is valid Vulkan, so this looks like a driver defect; the change works around it. When the optimized link is enabled, the library store takes over the modules of each newly built shader part and destroys them in `ClearPipelineLibraries`, after the pending links have finished. Modules of a pipeline whose parts all came from the cache are destroyed as before, and nothing changes with `APS5_NO_PIPELINE_LTO=1`. Cost: one retained `VkShaderModule` per stage of each unique shader part, for the device's lifetime. This is the AMD half of #2777: #2869 fixed the destroyed layout, which did not change the AMD failures (as noted there and in #2755). Addresses the segfaults in #2944 and #2755. How the cause was narrowed down (RX 6700 XT, on `57f96fd2` + `51078717`, `agc_driver_vertex_fetch` and `agc_driver_provoking_vertex`): - gdb puts the faulting thread in the `LinkPipelineFromLibraries` job, inside `vkCreateGraphicsPipelines`. - `APS5_NO_PIPELINE_LTO=1`: pass. - Optimized link run synchronously under the store lock instead of on the worker: still faults (2 of 3 runs each), so it is not a race in our code. - Optimized link with a null `VkPipelineCache`: still faults 3/3. - Shader modules never destroyed: pass 4/4 each (0/4 without). - Implicit layers disabled (`VK_LOADER_LAYERS_DISABLE=~implicit~`): still faults. ### Tested Windows 11 Pro 23H2 (22631), WinLibs GCC 15.2.0 r7, Ninja, Release, `BUILD_TESTING=ON`. AMD Radeon RX 6700 XT (Navi 22, 0x73df), Adrenalin 25.10.45.05 (driver 32.0.21045.5002), the only Vulkan device. `%LOCALAPPDATA%\AMD\VkCache` emptied before each `agc_` run, `ctest -R "^agc_" -j1`: | Build | Failed of 324 | |---|---| | `main` `379d8b4e` | 24: 22 SEGFAULT in `amdvlk64.dll`, plus `sdwa_float_selectors` and `sdwa_ldexp_f16` | | `main` `379d8b4e` + this PR | 3: `pixel_interlock`, `sdwa_float_selectors`, `sdwa_ldexp_f16`, no SEGFAULT | The 22: `agc_pipeline_cache`, `agc_pipeline_library`, and `agc_driver_` `mesh`, `conservative_rasterization`, `depth_bias_per_face`, `dual_source_blend`, `exec_host_lanes`, `ngg_vertex_wave_info`, `packed_unorm_color_target`, `pixel_fixed_point_position`, `pixel_helper_lanes`, `pixel_interlock`, `pixel_lds`, `pixel_lds_lane_slots`, `pixel_uint16_export`, `pixel_valid_mask`, `pixel_wave_reduction`, `prepared_exports`, `provoking_vertex`, `scalar_swappc_fetch`, `srgb8_color_target`, `vertex_fetch`. Full parallel `ctest` with this PR (warm driver cache): 724 of 732 passed, 5 skipped (`video_out` flip tests, `guest_video_out_wqhd_detection_no_vulkan`), the same 3 failed. The 3 remaining failures are wrong results, not faults, and are not addressed here: the two `sdwa` f16 ones are the values already in #2944; `pixel_interlock` no longer faults and fails with `pixel interlock wave64 BDA fault: pixel 0 counted 1 of 0 overlapping read-modify-writes`, which it also does with `APS5_NO_PIPELINE_LTO=1`. Title: Dreaming Sarah (PPSA02929), which faulted in `amdvlk64.dll+0x21eef34` at its first graphics submission on this machine (discussion #3018), relinked against this build runs for 90 s with no fault in the log. I did not check the rendered output. Not tested on NVIDIA, Intel or Linux. `python tools/check_conventions.py --base origin/main` passes. ### 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 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 (Claude Code) 🤖 Generated with [Claude Code](https://claude.com/claude-code)
github-actions[bot] commented 2026-10-10 23:17:59 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-10T23:17:59Z.


Thank you for your interest in the project! We are sorry, but we cannot accept more PRs while we work through the existing backlog. This PR has been automatically closed and labeled "intake paused". This is not a judgment of the quality of your changes.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6103239098 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3149#issuecomment-6103239098). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-10T23:17:59Z. --- Thank you for your interest in the project! We are sorry, but we cannot accept more PRs while we work through the existing backlog. This PR has been automatically closed and labeled "intake paused". This is not a judgment of the quality of your changes.
poonasor commented 2026-10-11 00:04:08 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by poonasor on 2026-10-11T00:04:08Z.


For when intake reopens: this fixes the amdvlk64.dll segfaults reported in #2944 (and matches #2755 / the AMD half of #2777). Title confirmation: Dreaming Sarah is playable on the RX 6700 XT with this commit, see discussion #3018. The branch stays available at poonasor:fix/agc-library-module-lifetime.

AI-assisted (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6103572696 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3149#issuecomment-6103572696). Originally posted by [poonasor](https://github.com/poonasor) on 2026-10-11T00:04:08Z. --- For when intake reopens: this fixes the `amdvlk64.dll` segfaults reported in #2944 (and matches #2755 / the AMD half of #2777). Title confirmation: Dreaming Sarah is playable on the RX 6700 XT with this commit, see [discussion #3018](https://github.com/boykopovar/AnyPS5/discussions/3018). The branch stays available at `poonasor:fix/agc-library-module-lifetime`. AI-assisted (Claude Code).

Pull request closed

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!3149
No description provided.