AGC: the background LTO pipeline link uses the Pipeline's layout after ~Pipeline destroys it (faults in igc-default64.dll on Intel) #2777
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by Silverash-i8 on 2026-10-10T14:26:51Z.
The background link-time-optimized link in
LinkPipelineFromLibrariescan create its pipeline with aVkPipelineLayoutthat has already been destroyed. On Intel's Windows driver this faults inside the shader compiler (igc-default64.dll) in fouragc_tests.Setup: Windows 11 Home (26200), WinLibs GCC 15.2.0 r7, Release,
-DBUILD_TESTING=ON,main8b812318. Intel Graphics in a Core Ultra 9 275HX (Arrow Lake, device 0x7d67, driver 32.0.101.8991), selected withANYPS5_GPU=Intel; the driver reportsVK_EXT_graphics_pipeline_library.Measured
mainAPS5_NO_GPL=1APS5_NO_PIPELINE_LTO=1agc_driver_vertex_fetchagc_driver_pixel_interlockagc_driver_prepared_exportsagc_driver_pixel_barycentric_emulationctest --parallel 6onlyagc_driver_meshEvery fault is in the driver's compiler;
vertex_fetchandpixel_interlockstop at the same instruction:The other addresses were
igc-default64.dll+0x2705734(prepared_exports, read of0xfffffffff8000000) and+0x2754974(vertex_fetch); the stack candidates are all insideigc-default64.dll. Since the faults go away withAPS5_NO_PIPELINE_LTO=1and the fast-linked pipelines keep working, they come from the backgroundVK_PIPELINE_CREATE_LINK_TIME_OPTIMIZATION_BIT_EXTlink.Cause
The job enqueued at
Graphics/src/PipelineLibrary.cpp:203capturesinfo.layout, which is thePipeline's ownlayout:Pipeline::release()(Graphics/src/Pipeline.cpp:392) callsoptimized->Release(), which only setsreleased, and then destroyslayout. A job already pastif (slot->released.load()) return;(PipelineLibrary.cpp:204) goes on tovkCreateGraphicsPipelineswith the destroyed layout.ClearCachedPipelines(Pipeline.cpp:773) erases the cached pipelines, destroying their layouts, beforeClearPipelineLibrarieswaits 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 commit758eeb9fonmaindb343a93, three lines. The job links with the library store's layout (pipelineLayout->second) instead of thePipeline's. That layout is created from the sameVkPipelineLayoutCreateInfo, is already the layout the four libraries are built with, and is destroyed only inClearPipelineLibrariesafterpendingreaches 0.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_unaryandvopc_compare(#2114),f64_fma_subnormalsandfp16_overflow(missing shaderFloat64 skip, also #2114; that fix is now onfix/agc-tests-skip-without-float64,7217a416),lds_beyond_device_limit(VK_ERROR_DEVICE_LOST, not investigated yet) andmesh.tools/check_conventions.pyandtools/check_skips.py --job windowspass.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_meshno 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 listsagc_driver_meshamong the AMD tests that pass withAPS5_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.
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\VkCacheandbuild/tests/shader_cacheemptied first (see the correction on #2755: a stale driver cache inflated my earlier numbers):maindb343a93maindb343a93+ 758eeb9fmaindb343a93withAPS5_NO_PIPELINE_LTO=1maindb343a93withAPS5_NO_GPL=1The 27 are the graphics tests listed in that correction (
agc_driver_mesh,vertex_fetch,pixel_interlock,prepared_exports,pixel_barycentric_emulationamong 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).
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:
ClearCachedPipelineswaits for pending links inClearPipelineLibraries, and thePipelineCachegoes later in device teardown.keepRecordedDraw(Draw.cpp:1425) holds ashared_ptr<Pipeline>per recorded draw, soOptimizedPipeline::Release()only runs after the batch is done.Could you paste the
riplines from a couple of the AMD access violations? If they land inamdxc64.dllit'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_limitdevice 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,
maindb343a93:VK_ERROR_DEVICE_LOSTLockedLdsUpdatebypassedSo the smallest repro is the device memory path with two subgroups in one workgroup. With the lock bypassed, the 32-bit
ds_add_rtn_u32and the other device memory LDS checks came back right up to the 64-bit counter, so it's the spin inLockedLdsUpdatethat hangs.Things I tried on the lock that made no difference, it still hangs with each of these:
OpAtomicStoreinstead of the plainOpStoreat entryOpAtomicExchangeinstead ofOpAtomicStoreThe SPIR-V passes
spirv-val --target-env vulkan1.3and the lock looks right to me: one elected lane per subgroup spins, acquire on the compare-exchange, release on the store,workgroup_memorydecoratedCoherent. 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:
shaderBufferInt64Atomicsand 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.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.
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
main57f96fd2, caches emptied, 5 of the crashing tests:interpolation_f16,uint8x4_color_targetandscalar_swappc_fetchfault atamdvlk64.dll+0x4bc8c0(read of0x8),pixel_uint16_exportandvertex_fetchatamdvlk64.dll+0x2cc1120/+0x2cc1204. All on an unnamed thread, and the whole frame chain and return candidates stay insideamdvlk64.dll. The other failing tests end with wrong results and no fault. So it looks like the driver's LTO link, as you suggested.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,
main57f96fd2): SEGFAULTs atnvoglv64.dll+0xed5110reading0xffffffffffffffff, in up to 16agc_driver_tests,pixel_interlockandprepared_exportsamong 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=1and #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.