AGC: the background LTO pipeline link uses the Pipeline's layout after ~Pipeline destroys it (faults in igc-default64.dll on Intel) #2777

Closed
opened 2026-10-10 14:26:51 +00:00 by Silverash-i8 · 4 comments
Silverash-i8 commented 2026-10-10 14:26:51 +00:00 (Migrated from github.com)
Contributor

Imported from boykopovar/AnyPS5. Originally posted by Silverash-i8 on 2026-10-10T14:26:51Z.


The background link-time-optimized link in LinkPipelineFromLibraries can create its pipeline with a VkPipelineLayout that has already been destroyed. On Intel's Windows driver this faults inside the shader compiler (igc-default64.dll) in four agc_ tests.

Setup: Windows 11 Home (26200), WinLibs GCC 15.2.0 r7, Release, -DBUILD_TESTING=ON, main 8b812318. Intel Graphics in a Core Ultra 9 275HX (Arrow Lake, device 0x7d67, driver 32.0.101.8991), selected with ANYPS5_GPU=Intel; the driver reports VK_EXT_graphics_pipeline_library.

Measured

Test main APS5_NO_GPL=1 APS5_NO_PIPELINE_LTO=1 with the fix below
agc_driver_vertex_fetch 0xc0000005, 3/3 passes passes passes 5/5
agc_driver_pixel_interlock 0xc0000005, 3/3 passes passes passes 5/5
agc_driver_prepared_exports 0xc0000005, intermittent passes passes passes 5/5
agc_driver_pixel_barycentric_emulation 0xc0000005 under ctest --parallel 6 only passes in the full parallel run
agc_driver_mesh 0xc0000005 fails without a fault (see below) same same

Every fault is in the driver's compiler; vertex_fetch and pixel_interlock stop at the same instruction:

FATAL: unhandled exception 0xc0000005 on thread 52120 ''
  rip 0x00007ffbad9143c6 igc-default64.dll+0x27543c6
  read of 0x000002020000207a

The other addresses were igc-default64.dll+0x2705734 (prepared_exports, read of 0xfffffffff8000000) and +0x2754974 (vertex_fetch); the stack candidates are all inside igc-default64.dll. Since the faults go away with APS5_NO_PIPELINE_LTO=1 and the fast-linked pipelines keep working, they come from the background VK_PIPELINE_CREATE_LINK_TIME_OPTIMIZATION_BIT_EXT link.

Cause

The job enqueued at Graphics/src/PipelineLibrary.cpp:203 captures info.layout, which is the Pipeline's own layout:

  • Pipeline::release() (Graphics/src/Pipeline.cpp:392) calls optimized->Release(), which only sets released, and then destroys layout. A job already past if (slot->released.load()) return; (PipelineLibrary.cpp:204) goes on to vkCreateGraphicsPipelines with the destroyed layout.
  • ClearCachedPipelines (Pipeline.cpp:773) erases the cached pipelines, destroying their layouts, before ClearPipelineLibraries waits for the pending links. So any link still queued or running at device teardown uses a destroyed layout. The execution tests tear the device down right after their draws, which is why they hit it every time on a driver whose LTO link is slow.

A faster driver usually finishes the link before teardown, which would explain why this doesn't show on NVIDIA.

Fix

Silverash-i8/AnyPS5-fork:fix/agc-lto-link-layout-lifetime, one commit 758eeb9f on main db343a93, three lines. The job links with the library store's layout (pipelineLayout->second) instead of the Pipeline's. That layout is created from the same VkPipelineLayoutCreateInfo, is already the layout the four libraries are built with, and is destroyed only in ClearPipelineLibraries after pending reaches 0.

-        const auto pipelineLayout = info.layout;
-        enqueue(store, context.device, [slot, createPipelines, cache, pipelineLayout, libraries, &store, devicePointer = &device] {
+        const auto libraryLayout = pipelineLayout->second;
+        enqueue(store, context.device, [slot, createPipelines, cache, libraryLayout, libraries, &store, devicePointer = &device] {
 ...
-            create.layout = pipelineLayout;
+            create.layout = libraryLayout;

Full ctest with the fix on db343a93: 709/709 on the RTX 5060 Laptop GPU (driver 32.0.16.1742) in the same machine. On the Arrow Lake iGPU, 6 failures remain, none of them faults: vop1_float_unary and vopc_compare (#2114), f64_fma_subnormals and fp16_overflow (missing shaderFloat64 skip, also #2114; that fix is now on fix/agc-tests-skip-without-float64, 7217a416), lds_beyond_device_limit (VK_ERROR_DEVICE_LOST, not investigated yet) and mesh. tools/check_conventions.py and tools/check_skips.py --job windows pass.

No regression test is included: the race only fails on a driver slow enough to lose it, so a test would pass on the CI devices with or without the fix. The four tests above cover it on Intel.

Not fixed here

agc_driver_mesh no longer faults but still fails on the iGPU, with pipeline libraries on or off: indexed triangle list, one-wave subgroups: triangle 0 was not rendered in its color, pixel (16, 24, 40, 255). That looks like a separate mesh-shader issue. #2755 also lists agc_driver_mesh among the AMD tests that pass with APS5_NO_GPL=1. Those are wrong results rather than faults, so I don't know whether this race is involved there.

Written with AI assistance; I ran and checked every result above on this machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5792102669 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/2777). Originally posted by [Silverash-i8](https://github.com/Silverash-i8) on 2026-10-10T14:26:51Z. --- The background link-time-optimized link in `LinkPipelineFromLibraries` can create its pipeline with a `VkPipelineLayout` that has already been destroyed. On Intel's Windows driver this faults inside the shader compiler (`igc-default64.dll`) in four `agc_` tests. **Setup:** Windows 11 Home (26200), WinLibs GCC 15.2.0 r7, Release, `-DBUILD_TESTING=ON`, `main` `8b812318`. Intel Graphics in a Core Ultra 9 275HX (Arrow Lake, device 0x7d67, driver 32.0.101.8991), selected with `ANYPS5_GPU=Intel`; the driver reports `VK_EXT_graphics_pipeline_library`. ### Measured | Test | `main` | `APS5_NO_GPL=1` | `APS5_NO_PIPELINE_LTO=1` | with the fix below | |---|---|---|---|---| | `agc_driver_vertex_fetch` | 0xc0000005, 3/3 | passes | passes | passes 5/5 | | `agc_driver_pixel_interlock` | 0xc0000005, 3/3 | passes | passes | passes 5/5 | | `agc_driver_prepared_exports` | 0xc0000005, intermittent | passes | passes | passes 5/5 | | `agc_driver_pixel_barycentric_emulation` | 0xc0000005 under `ctest --parallel 6` only | | | passes in the full parallel run | | `agc_driver_mesh` | 0xc0000005 | fails without a fault (see below) | same | same | Every fault is in the driver's compiler; `vertex_fetch` and `pixel_interlock` stop at the same instruction: ``` FATAL: unhandled exception 0xc0000005 on thread 52120 '' rip 0x00007ffbad9143c6 igc-default64.dll+0x27543c6 read of 0x000002020000207a ``` The other addresses were `igc-default64.dll+0x2705734` (`prepared_exports`, read of `0xfffffffff8000000`) and `+0x2754974` (`vertex_fetch`); the stack candidates are all inside `igc-default64.dll`. Since the faults go away with `APS5_NO_PIPELINE_LTO=1` and the fast-linked pipelines keep working, they come from the background `VK_PIPELINE_CREATE_LINK_TIME_OPTIMIZATION_BIT_EXT` link. ### Cause The job enqueued at `Graphics/src/PipelineLibrary.cpp:203` captures `info.layout`, which is the `Pipeline`'s own `layout`: - `Pipeline::release()` (`Graphics/src/Pipeline.cpp:392`) calls `optimized->Release()`, which only sets `released`, and then destroys `layout`. A job already past `if (slot->released.load()) return;` (`PipelineLibrary.cpp:204`) goes on to `vkCreateGraphicsPipelines` with the destroyed layout. - `ClearCachedPipelines` (`Pipeline.cpp:773`) erases the cached pipelines, destroying their layouts, before `ClearPipelineLibraries` waits for the pending links. So any link still queued or running at device teardown uses a destroyed layout. The execution tests tear the device down right after their draws, which is why they hit it every time on a driver whose LTO link is slow. A faster driver usually finishes the link before teardown, which would explain why this doesn't show on NVIDIA. ### Fix [`Silverash-i8/AnyPS5-fork:fix/agc-lto-link-layout-lifetime`](https://github.com/Silverash-i8/AnyPS5-fork/tree/fix/agc-lto-link-layout-lifetime), one commit `758eeb9f` on `main` `db343a93`, three lines. The job links with the library store's layout (`pipelineLayout->second`) instead of the `Pipeline`'s. That layout is created from the same `VkPipelineLayoutCreateInfo`, is already the layout the four libraries are built with, and is destroyed only in `ClearPipelineLibraries` after `pending` reaches 0. ```diff - const auto pipelineLayout = info.layout; - enqueue(store, context.device, [slot, createPipelines, cache, pipelineLayout, libraries, &store, devicePointer = &device] { + const auto libraryLayout = pipelineLayout->second; + enqueue(store, context.device, [slot, createPipelines, cache, libraryLayout, libraries, &store, devicePointer = &device] { ... - create.layout = pipelineLayout; + create.layout = libraryLayout; ``` Full ctest with the fix on `db343a93`: 709/709 on the RTX 5060 Laptop GPU (driver 32.0.16.1742) in the same machine. On the Arrow Lake iGPU, 6 failures remain, none of them faults: `vop1_float_unary` and `vopc_compare` (#2114), `f64_fma_subnormals` and `fp16_overflow` (missing shaderFloat64 skip, also #2114; that fix is now on [`fix/agc-tests-skip-without-float64`](https://github.com/Silverash-i8/AnyPS5-fork/tree/fix/agc-tests-skip-without-float64), `7217a416`), `lds_beyond_device_limit` (`VK_ERROR_DEVICE_LOST`, not investigated yet) and `mesh`. `tools/check_conventions.py` and `tools/check_skips.py --job windows` pass. No regression test is included: the race only fails on a driver slow enough to lose it, so a test would pass on the CI devices with or without the fix. The four tests above cover it on Intel. ### Not fixed here `agc_driver_mesh` no longer faults but still fails on the iGPU, with pipeline libraries on or off: `indexed triangle list, one-wave subgroups: triangle 0 was not rendered in its color, pixel (16, 24, 40, 255)`. That looks like a separate mesh-shader issue. #2755 also lists `agc_driver_mesh` among the AMD tests that pass with `APS5_NO_GPL=1`. Those are wrong results rather than faults, so I don't know whether this race is involved there. Written with AI assistance; I ran and checked every result above on this machine.
LeandroLP23 commented 2026-10-10 15:10:56 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by LeandroLP23 on 2026-10-10T15:10:56Z.


AMD data point for the question at the end: the fix doesn't change the AMD failures. Radeon 860M (RDNA 3.5), AMD driver 32.0.13058.8001, Windows 11 (26300), WinLibs GCC 15.2.0 r7, Release, ctest -R agc_ -j1, with %LOCALAPPDATA%\AMD\VkCache and build/tests/shader_cache emptied first (see the correction on #2755: a stale driver cache inflated my earlier numbers):

Build Failed of 321
main db343a93 27, cold and warm
main db343a93 + 758eeb9f 27, cold and warm, the same tests
main db343a93 with APS5_NO_PIPELINE_LTO=1 0
main db343a93 with APS5_NO_GPL=1 0

The 27 are the graphics tests listed in that correction (agc_driver_mesh, vertex_fetch, pixel_interlock, prepared_exports, pixel_barycentric_emulation among them); several end with an access violation, the rest with wrong results. So on AMD there is a second problem with the background LTO pipelines besides the destroyed layout this fixes. I haven't traced it.

AI-assisted: yes (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6098934553 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/2777#issuecomment-6098934553). Originally posted by [LeandroLP23](https://github.com/LeandroLP23) on 2026-10-10T15:10:56Z. --- AMD data point for the question at the end: the fix doesn't change the AMD failures. Radeon 860M (RDNA 3.5), AMD driver 32.0.13058.8001, Windows 11 (26300), WinLibs GCC 15.2.0 r7, Release, `ctest -R agc_ -j1`, with `%LOCALAPPDATA%\AMD\VkCache` and `build/tests/shader_cache` emptied first (see the correction on #2755: a stale driver cache inflated my earlier numbers): | Build | Failed of 321 | |---|---| | `main` db343a93 | 27, cold and warm | | `main` db343a93 + 758eeb9f | 27, cold and warm, the same tests | | `main` db343a93 with `APS5_NO_PIPELINE_LTO=1` | 0 | | `main` db343a93 with `APS5_NO_GPL=1` | 0 | The 27 are the graphics tests listed in that correction (`agc_driver_mesh`, `vertex_fetch`, `pixel_interlock`, `prepared_exports`, `pixel_barycentric_emulation` among them); several end with an access violation, the rest with wrong results. So on AMD there is a second problem with the background LTO pipelines besides the destroyed layout this fixes. I haven't traced it. AI-assisted: yes (Claude Code).
Silverash-i8 commented 2026-10-10 15:28:51 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by Silverash-i8 on 2026-10-10T15:28:51Z.


@LeandroLP23 thanks for running it on AMD, that's really useful. On the Arrow Lake iGPU all five of those tests pass with 758eeb9f and LTO left on, so it does look like two separate problems that both live in the background LTO path. The destroyed layout was the one Intel's compiler tripped over, and AMD is hitting something else.

I went looking for a second lifetime bug in the same code and ruled out two things:

  • The pipeline cache the LTO job uses isn't destroyed early. ClearCachedPipelines waits for pending links in ClearPipelineLibraries, and the PipelineCache goes later in device teardown.
  • The optimized pipeline isn't destroyed while the GPU still uses it. keepRecordedDraw (Draw.cpp:1425) holds a shared_ptr<Pipeline> per recorded draw, so OptimizedPipeline::Release() only runs after the batch is done.

Could you paste the rip lines from a couple of the AMD access violations? If they land in amdxc64.dll it's probably the driver's LTO compile, and if they land in our code it's ours. Either way that tells us where to look next.


I also chased the agc_driver_lds_beyond_device_limit device loss that I left open above. Short version: the lock that guards 64-bit LDS atomics deadlocks on Intel when the LDS is moved to device memory and two subgroups of the same workgroup want it at once.

I added a few extra dispatches to the test locally, on the Arrow Lake iGPU, main db343a93:

Dispatch Result
LDS on chip, 64 threads (two wave32 subgroups), 6 groups completes
LDS in device memory, 32 threads (one subgroup), 6 groups completes
LDS in device memory, 64 threads, 1 group hangs, VK_ERROR_DEVICE_LOST
LDS in device memory, 64 threads, 6 groups (the test's own dispatch) hangs
same, with LockedLdsUpdate bypassed completes (wrong 64-bit counter, as expected)
the first four on the RTX 5060 complete

So the smallest repro is the device memory path with two subgroups in one workgroup. With the lock bypassed, the 32-bit ds_add_rtn_u32 and the other device memory LDS checks came back right up to the 64-bit counter, so it's the spin in LockedLdsUpdate that hangs.

Things I tried on the lock that made no difference, it still hangs with each of these:

  • Device scope instead of Workgroup scope on the compare-exchange and the release
  • Initialising the lock with OpAtomicStore instead of the plain OpStore at entry
  • Moving the lock dword onto its own cache line, away from the counter
  • Releasing with OpAtomicExchange instead of OpAtomicStore
  • Test-and-test-and-set (relaxed atomic load first, compare-exchange only when it reads 0)

The SPIR-V passes spirv-val --target-env vulkan1.3 and the lock looks right to me: one elected lane per subgroup spins, acquire on the compare-exchange, release on the store, workgroup_memory decorated Coherent. My guess is Intel just doesn't give the second subgroup forward progress while the first spins on a storage buffer, which Vulkan doesn't promise either.

I don't think there's a small patch here, so I'd rather ask before writing one. Two directions I can see:

  1. On the device memory path, use real 64-bit buffer atomics when the device has shaderBufferInt64Atomics and skip the lock. That needs a 64-bit view of the workgroup memory buffer, and it touches the 32-bit/64-bit interaction in #2297, which might actually get better since the hardware serialises both.
  2. Keep the lock but stop depending on one subgroup spinning while another holds it.

Is either of those something you'd take, or is there a reason the lock is needed on this path that I'm missing? Happy to put a branch together for whichever makes sense.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6099100598 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/2777#issuecomment-6099100598). Originally posted by [Silverash-i8](https://github.com/Silverash-i8) on 2026-10-10T15:28:51Z. --- @LeandroLP23 thanks for running it on AMD, that's really useful. On the Arrow Lake iGPU all five of those tests pass with 758eeb9f and LTO left on, so it does look like two separate problems that both live in the background LTO path. The destroyed layout was the one Intel's compiler tripped over, and AMD is hitting something else. I went looking for a second lifetime bug in the same code and ruled out two things: - The pipeline cache the LTO job uses isn't destroyed early. `ClearCachedPipelines` waits for pending links in `ClearPipelineLibraries`, and the `PipelineCache` goes later in device teardown. - The optimized pipeline isn't destroyed while the GPU still uses it. `keepRecordedDraw` (`Draw.cpp:1425`) holds a `shared_ptr<Pipeline>` per recorded draw, so `OptimizedPipeline::Release()` only runs after the batch is done. Could you paste the `rip` lines from a couple of the AMD access violations? If they land in `amdxc64.dll` it's probably the driver's LTO compile, and if they land in our code it's ours. Either way that tells us where to look next. --- I also chased the `agc_driver_lds_beyond_device_limit` device loss that I left open above. Short version: the lock that guards 64-bit LDS atomics deadlocks on Intel when the LDS is moved to device memory and two subgroups of the same workgroup want it at once. I added a few extra dispatches to the test locally, on the Arrow Lake iGPU, `main` db343a93: | Dispatch | Result | |---|---| | LDS on chip, 64 threads (two wave32 subgroups), 6 groups | completes | | LDS in device memory, 32 threads (one subgroup), 6 groups | completes | | LDS in device memory, 64 threads, 1 group | hangs, `VK_ERROR_DEVICE_LOST` | | LDS in device memory, 64 threads, 6 groups (the test's own dispatch) | hangs | | same, with `LockedLdsUpdate` bypassed | completes (wrong 64-bit counter, as expected) | | the first four on the RTX 5060 | complete | So the smallest repro is the device memory path with two subgroups in one workgroup. With the lock bypassed, the 32-bit `ds_add_rtn_u32` and the other device memory LDS checks came back right up to the 64-bit counter, so it's the spin in `LockedLdsUpdate` that hangs. Things I tried on the lock that made no difference, it still hangs with each of these: - Device scope instead of Workgroup scope on the compare-exchange and the release - Initialising the lock with `OpAtomicStore` instead of the plain `OpStore` at entry - Moving the lock dword onto its own cache line, away from the counter - Releasing with `OpAtomicExchange` instead of `OpAtomicStore` - Test-and-test-and-set (relaxed atomic load first, compare-exchange only when it reads 0) The SPIR-V passes `spirv-val --target-env vulkan1.3` and the lock looks right to me: one elected lane per subgroup spins, acquire on the compare-exchange, release on the store, `workgroup_memory` decorated `Coherent`. My guess is Intel just doesn't give the second subgroup forward progress while the first spins on a storage buffer, which Vulkan doesn't promise either. I don't think there's a small patch here, so I'd rather ask before writing one. Two directions I can see: 1. On the device memory path, use real 64-bit buffer atomics when the device has `shaderBufferInt64Atomics` and skip the lock. That needs a 64-bit view of the workgroup memory buffer, and it touches the 32-bit/64-bit interaction in #2297, which might actually get better since the hardware serialises both. 2. Keep the lock but stop depending on one subgroup spinning while another holds it. Is either of those something you'd take, or is there a reason the lock is needed on this path that I'm missing? Happy to put a branch together for whichever makes sense.
LeandroLP23 commented 2026-10-10 17:45:13 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by LeandroLP23 on 2026-10-10T17:45:13Z.


The faults land in AMD's driver, not in our code. On main 57f96fd2, caches emptied, 5 of the crashing tests: interpolation_f16, uint8x4_color_target and scalar_swappc_fetch fault at amdvlk64.dll+0x4bc8c0 (read of 0x8), pixel_uint16_export and vertex_fetch at amdvlk64.dll+0x2cc1120 / +0x2cc1204. All on an unnamed thread, and the whole frame chain and return candidates stay inside amdvlk64.dll. The other failing tests end with wrong results and no fault. So it looks like the driver's LTO link, as you suggested.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6100402295 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/2777#issuecomment-6100402295). Originally posted by [LeandroLP23](https://github.com/LeandroLP23) on 2026-10-10T17:45:13Z. --- The faults land in AMD's driver, not in our code. On `main` 57f96fd2, caches emptied, 5 of the crashing tests: `interpolation_f16`, `uint8x4_color_target` and `scalar_swappc_fetch` fault at `amdvlk64.dll+0x4bc8c0` (read of `0x8`), `pixel_uint16_export` and `vertex_fetch` at `amdvlk64.dll+0x2cc1120` / `+0x2cc1204`. All on an unnamed thread, and the whole frame chain and return candidates stay inside `amdvlk64.dll`. The other failing tests end with wrong results and no fault. So it looks like the driver's LTO link, as you suggested.
Zurisen commented 2026-10-10 17:50:41 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by Zurisen on 2026-10-10T17:50:41Z.


NVIDIA data point: the same use of the destroyed layout faults inside NVIDIA's driver too (RTX 4070 Laptop, driver 32.0.15.9636, main 57f96fd2): SEGFAULTs at nvoglv64.dll+0xed5110 reading 0xffffffffffffffff, in up to 16 agc_driver_ tests, pixel_interlock and prepared_exports among them. They are rare with warm caches and frequent with every cache cold under -j12 (8–14 crashed tests per batch of 252). APS5_NO_PIPELINE_LTO=1 and #2869 both bring that to 0 (#2869: 10 batches, 2520 test runs). Details and the command are in https://github.com/boykopovar/AnyPS5/pull/2869#issuecomment-6100448565.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6100449873 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/2777#issuecomment-6100449873). Originally posted by [Zurisen](https://github.com/Zurisen) on 2026-10-10T17:50:41Z. --- NVIDIA data point: the same use of the destroyed layout faults inside NVIDIA's driver too (RTX 4070 Laptop, driver 32.0.15.9636, `main` `57f96fd2`): SEGFAULTs at `nvoglv64.dll+0xed5110` reading `0xffffffffffffffff`, in up to 16 `agc_driver_` tests, `pixel_interlock` and `prepared_exports` among them. They are rare with warm caches and frequent with every cache cold under `-j12` (8–14 crashed tests per batch of 252). `APS5_NO_PIPELINE_LTO=1` and #2869 both bring that to 0 (#2869: 10 batches, 2520 test runs). Details and the command are in https://github.com/boykopovar/AnyPS5/pull/2869#issuecomment-6100448565.
Sign in to join this conversation.
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#2777
No description provided.