agc: background LTO relink loses the device for pipelines with a depth attachment (NVIDIA) #2866
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 ps54all on 2026-10-10T16:53:53Z.
After
perf(agc): relink library pipelines with link-time optimization in the background(#2713), a pipeline built from libraries that renders to a depth attachment hitsVK_ERROR_DEVICE_LOSTthe first time the optimized pipeline is bound (AGC graphics: vkWaitForFences graphics: Vulkan result -4).Reproduced on origin/main
eb94c554d, RTX 3080, Windows, with a minimal execution test: one color target plus oneD32_SFLOAT(alsoD16_UNORM) depth target, a triangle list, several draws withWaitIdleafter each. The first draws use the fast-linked pipeline and succeed; the first draw after the background relink finishes loses the device.What changes the outcome
APS5_NO_PIPELINE_LTO=1: works.VK_PIPELINE_CREATE_LINK_TIME_OPTIMIZATION_BIT_EXT: works.Tried without effect:
VkPipelineRenderingCreateInfoon the fragment shader or all library parts, or chained into the LTO link; making depth test/write/compare static; dropping the stencil and depth-bounds dynamic state commands; a zeroed depth-stencil state for the fragment shader library.Workaround (local branch, not proposed as the fix): skip the background relink when
rendering.depthAttachmentFormatorstencilAttachmentFormatis notVK_FORMAT_UNDEFINED.The existing library tests only count
optimizedand never execute an optimized pipeline with a depth target; a test that draws twice into a depth target afterWaitForOptimizedPipelinesreproduces it.Imported from boykopovar/AnyPS5. Originally posted by Silverash-i8 on 2026-10-10T17:24:30Z.
A data point from a different NVIDIA card: I can't reproduce this on an RTX 5060 Laptop GPU (Blackwell, driver 617.42), Windows 11,
main57f96fd2, LTO on.I used
agc_driver_depth_bias_per_faceas the depth test, since it draws into aD32_SFLOATtarget with depth test on. Its per-face draws don't use libraries (depthBiasPerFaceopts out), but the "both faces pulled closer" draw does. I drew that one, slept 2 s, and drew it again, with a temporary print inPipeline::Continueto confirm what was bound. The second draw binds the optimized pipeline (libraries=1 optimized=1), finishes, and gives the right pixels. With depth writes turned on as well, the optimized draw still completes. The colors change because the test's expectations assume no depth writes, but it's the same result as withAPS5_NO_PIPELINE_LTO=1, and there's no device loss.So on this setup a library-linked pipeline with a depth attachment survives the LTO relink. That points at something specific to your card or driver (RTX 3080, Ampere), or at a state your test sets that this one doesn't. Which driver version were you on? And if you can push the minimal test somewhere, I'm happy to run it as-is on this card and on the Arrow Lake iGPU in the same laptop.
AI-assisted (Claude Code); I ran the above on my machine.
Imported from boykopovar/AnyPS5. Originally posted by fma-rc on 2026-10-10T18:04:18Z.
Linux data point: it does not reproduce on an RTX 5080 either, so with the report above that is two Blackwell cards without the loss, on both operating systems.
Setup:
main57f96fd2, Arch Linux 7.2.9, GCC 16.2.1, Release. RTX 5080 (NVIDIA 615.78.08) and Radeon 610M (RADV, Mesa 26.1.4).Test (temporary): the "both faces pulled closer" draw of
agc_driver_depth_bias_per_face(color target plusD32_SFLOATdepth target, triangle list, pipeline built from libraries), drawn once, then a 3 s sleep, then five more times, withWaitIdleand a pixel check after each draw. A temporary print wherePipeline.cpppicks the handle to bind shows which pipeline each draw used.APS5_NO_PIPELINE_LTO=1No
VK_ERROR_DEVICE_LOSTin any run.Not run: depth writes on,
D16_UNORM, an RTX 30-series card, Windows.AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by ps54all on 2026-10-11T07:04:33Z.
Thanks for testing, both. Our card is an RTX 3080 (Ampere), driver 610.74, Windows 11, so two Blackwell cards without the loss fits a driver or architecture specific problem rather than a generic one. Not yet run on our side: depth writes on,
D16_UNORM, and a second driver version. The minimal reproduction is a depth-tested draw (no HTILE, D32 or D16, even with the depth test off) on a library-linked pipeline after the background LTO relink finished; color-only draws survive. We skip the relink when the pipeline has a depth or stencil attachment as a local workaround and the problem disappears. If either of you has an Ampere or Ada card to try, that would settle whether it is the generation.Written with AI assistance.
Imported from boykopovar/AnyPS5. Originally posted by Yuva1024 on 2026-10-11T09:36:55Z.
Data point from an Ada card, and the loss does not need a depth attachment.
Windows 11 (26200), WinLibs GCC 15.2.0 r7, Release,
BUILD_TESTING=ON, RTX 4060 (Ada, driver 617.42),mainac2c5c08. The test is the existingagc_driver_pixel_valid_mask(tests/execution/PixelValidMask.cpp): one R8G8B8A8_UNORM color target, no depth or stencil attachment, four draws withWaitIdleafter each.AGC graphics: vkWaitForFences graphics: Vulkan result -4.APS5_NO_PIPELINE_LTO=1: 20 of 20 pass.ctest --parallel 3on that build: 816 of 817 pass; this is the one failure. It also fails when run alone.Pipeline::Continue: draws 1 and 2 bind the fast-linked pipeline (optimized handle null) and pass; draws 3 and 4 bind the optimized handle. Draw 3 passes. Draw 4 (wave32, the masked pixel shader) loses the device in every traced run (6 of 6).depthAttachmentFormatorstencilAttachmentFormatis set, as in the workaround above, changes nothing here: 0 of 30 passed, because this test has no depth attachment.So on this card the loss happens for a color-only pipeline too, and only when the optimized link is bound. I have not found why, and I have no fix to propose. I did not test other drivers or the Ampere card from the report.
AI-assisted: yes (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by Silverash-i8 on 2026-10-11T09:42:53Z.
Same driver, different architecture: RTX 5060 Laptop (Blackwell), driver 617.42 like your RTX 4060, Windows 11, WinLibs GCC 15.2.0 r7, Release,
main9a1f6f44, default settings (pipeline LTO on, noAPS5_NO_PIPELINE_LTO):agc_driver_pixel_valid_maskpasses 20 of 20.So with the driver held constant, Ada (your 4060, 16 of 20 failing) loses the device and Blackwell doesn't, which fits the earlier picture of the Ampere report failing and two Blackwell cards passing. That points at something architecture-specific in how the optimized link is compiled or run, not a driver-wide problem. I didn't add a trace of which handle is bound, so I can't say whether draw 4 here also uses the optimized pipeline, only that it doesn't lose the device.
AI-assisted (Claude Code); I ran this on my machine.
Imported from boykopovar/AnyPS5. Originally posted by ps54all on 2026-10-11T15:14:40Z.
Another data point, Ampere this time: RTX 3080, driver 610.74, Windows 11, WinLibs GCC 15.2.0, Release, default settings (pipeline LTO on).
agc_driver_pixel_valid_maskpasses 20 of 20 here, and the full ctest run does not lose the device in it. Silksong at its menu also holds 59.9 FPS with LTO on.So the table is now: Ada 4060 on 617.42 fails (16 of 20), Blackwell 5060 on 617.42 passes, Ampere 3080 on 610.74 passes. That leaves two variables I cannot separate from here, the architecture and the driver branch (610 against 617). Someone with an Ampere or Ada card on both driver branches would settle it; I only have the 610.74 install.
AI-assisted (Claude Code); I ran this on my machine.
Imported from boykopovar/AnyPS5. Originally posted by pipe1os on 2026-10-12T05:51:15Z.
Data point from the same GPU model and driver as the failing report: RTX 4060 desktop (Ada, PCI device 0x2882), driver 617.42, Windows 11 26200, WinLibs GCC 15.2.0 r7, Release. It does not lose the device.
mainac2c5c08(the commit from the report), default settings:agc_driver_pixel_valid_maskpasses 20 of 20 through ctest.Pipeline::Continue: draw 4 (wave32, masked pixel shader) bound the optimized handle in 22 of 30 runs, and all 30 runs passed. In the other 8 the relink had not finished yet, so draw 4 used the fast-linked pipeline.main7a84b2226with the NVIDIA gate from #3434 bypassed locally: 20 of 20 pass, with the masked draw repeated 6 times per wave size. Same on driver 616.56 before upgrading.So Ada on 617.42 is not enough to reproduce it; something else on the failing machine matters. @Yuva1024, is yours a laptop 4060? The
deviceIDfromvulkaninfo --summarywould tell.I also have a local change that emits
OpTerminateInvocationinstead ofOpKillwhenVK_KHR_shader_terminate_invocationis available, since #3434 says only kill shaders lose the device. It passes here, but I can't reproduce the loss, so I can't tell whether it helps. If you can run it on your machine, I'll push the branch.AI-assisted (Claude Code); I ran the above on my machine.
Imported from boykopovar/AnyPS5. Originally posted by simonbbby on 2026-10-12T13:04:58Z.
An RTX 3090 (Ampere, GA102, device 0x2204) on Linux with NVIDIA 595.99.02 does not lose the device. Every case that binds the optimized LTO pipeline passes on current
main, oneb94c554dfrom the report, and on Yuva1024'sac2c5c08.Setup: Ubuntu 24.04, Linux 7.0, GCC 13.3, Release with
BUILD_TESTING=ONandANYPS5_ENABLE_SPIRV_TOOLS=ON.mainisffa19840. The 59 commits since then, up to33ae282e, don't touch the shader recompiler. UnderlibSceAgcDriverthey only add a--prepareflag to theagc_shader_replaytool.Readback test from #3741,
--force-lto, 20 runs per cell:mainffa19840main,APS5_NO_PIPELINE_LTO=1main+ #4445 (2919dd38)main+ #4363 (0b46084c)eb94c554d(no gate, LTO on), test portedeb94c554d,APS5_NO_PIPELINE_LTO=1Every LTO-on run printed
pipeline readback passed: fast draws 1, optimized draws 1, optimized creations 1, so each run drew with the optimized handle. Without--force-lto, all 8 readback ctests onmainprintLTO disabled (production policy), so the #3434 gate is active on 595.agc_driver_pixel_valid_maskwith LTO on:ac2c5c08, unmodified: 20 of 20 pass through ctest.ac2c5c08with a temporary print inPipeline::Continue: 30 of 30 pass. Draw 4 (wave32, masked pixel shader) bound the optimized handle in 30 of 30 runs, and draw 3 in 29 of 30. A draw gets the optimized handle only if its background link has finished, so this count depends on host load. Those 30 runs were at load average 17. In 10 later runs at load average 54, draw 4 got the optimized handle in 8, and all 10 passed.eb94c554d: 20 of 20.mainwith the gate bypassed (true ||in front ofPipelineLinkTimeOptimizationUsableatVulkanDevice.cpp:1317): 20 of 20, with draws 3 and 4 optimized in all 20.Full ctest on the 3090 (
ANYPS5_REQUIRE_VULKAN=1,--parallel 8 --timeout 300): 0 failures out of 957, both with the gate and with the gate bypassed. Each run passed 947 tests and skipped 10.agc_driver_stencil_ref_exportskipped because the 3090 lacksVK_EXT_shader_stencil_export, and 9 video_out tests skipped because SDL's offscreen driver has no Vulkan here. A traced gate-bypassed run had the same counts and drew 216 times with an optimized pipeline across 37 tests. Examples:pixel_wave_reduction(58),depth_fast_clear_submit(13),color1555_target(12),depth_fast_clear(6).No run logged
Vulkan result -4, and the kernel log has no NVRM Xid lines for the whole session.Two side results:
main,Pipeline.cppdestroys the shader modules right afterLinkPipelineFromLibrariesreturns, and the readback test holds the LTO create until after the first draw. So themainarm linked after the modules were gone. NVIDIA 595 still passed, so nothing here suggests that NVIDIA reads destroyed modules the way #4435 describes for AMD on Windows.agc_driver_recorder_tests --pipeline-library-only) passes on the 3090. The PR says that check fails onmain, so that arm does differ frommain. Neither PR changes the outcome here, becausemaindoesn't fail.So the GPU generation alone doesn't explain the loss, and the driver version doesn't either. On 617.42, Yuva1024's RTX 4060 fails and pipe1os's desktop RTX 4060 passes. Silverash-i8's 5060 Laptop also passes on 617.42, and ps54all's 3080 passes
pixel_valid_maskon 610.74. Both failing reports are on Windows, but so are those three passing machines. No Linux report fails so far: fma-rc's 5080 on 615.78 and this 3090 on 595. That rests on two cards, and this run can't separate the OS from the driver branch. On this configuration the #3434 gate turns LTO off without need, but the data doesn't yet point at one condition to narrow the gate to.Not tested: Windows, the 610/616/617 drivers, game workloads with the gate bypassed, the Khronos validation layer (not installed here), and #4363 with #4445 together (
maindidn't fail).Commands and local changes
HV_TRACE_BIND=1turns on the bind print below.eb94c554dhas no print, so the variable does nothing there.eb94c554dpredates #3741. I copiedmain'sPipelineOptimizedReadback.cppin and setoptimizefromAPS5_NO_PIPELINE_LTOalone, because that commit has no gate. I also addedfriend struct VulkanDeviceTestAccess;toVulkanDevice.hpp.Bind trace in
Pipeline::Continue:Imported from boykopovar/AnyPS5. Originally posted by ps54all on 2026-10-12T15:28:41Z.
Thanks pipe1os and simonbbby. Table so far, same test (
agc_driver_pixel_valid_mask, default LTO on): Ada 4060 desktop, 617.42 passes (pipe1os); Ampere 3090, Linux 595.99.02 passes (simonbbby); Blackwell 5060 passes; Ampere 3080 desktop, Windows, 610.74 passes here (20 of 20). The original report is the only failure, so it does not follow architecture or driver branch alone. Reporter: could you post the GPU model, driver version and whether other machine-specific settings apply (hybrid graphics, overlays)? Without a pattern I would not chase it further.AI-assisted (Claude Code); I ran this on my machine.
Imported from boykopovar/AnyPS5. Originally posted by Sevthered on 2026-10-13T21:07:49Z.
Another data point: RTX 3080 Ti (Ampere, device
0x2208), Windows 11, driver 616.56, no hybrid graphics.agc_driver_pixel_valid_maskwith default LTO passes 20 of 20 on a build based ona0f5916a2.AI-assisted: yes; run on my machine.
Imported from boykopovar/AnyPS5. Originally posted by ps54all on 2026-10-13T22:27:06Z.
Thanks simonbbby and Sevthered. Updated table for
agc_driver_pixel_valid_maskwith default LTO (the case from the report):Three Ampere cards on three drivers and two OSes all pass, and the one Ada pass and one Ada fail share a driver, so neither architecture nor driver version separates them. The only failing machine remains the original report. Yuva1024, could you post whether the machine has hybrid graphics, which GPU the test selects (
ANYPS5_GPU), and whether the failure still happens with overlays (Afterburner, Discord, Steam) closed? Without a discriminating condition I would not narrow the #3434 gate further.AI-assisted (Claude Code); I ran the 3080 numbers on my machine.
Imported from boykopovar/AnyPS5. Originally posted by ArekatlaNishanthchowdary on 2026-10-14T05:05:12Z.
Another data point for the table: RTX 4060 Laptop GPU (Ada), Windows 11 26200, driver 32.0.16.1742, hybrid graphics with Intel UHD (Raptor Lake).
agc_driver_pixel_valid_maskwith default LTO passes 20 of 20 onmaincac4e9688, WinLibs GCC 15.2.0 r7, Release. So hybrid graphics with a 4060 Laptop doesn't reproduce it either.Imported from boykopovar/AnyPS5. Originally posted by ps54all on 2026-10-14T06:42:33Z.
Thanks ArekatlaNishanthchowdary. Added to the table for
agc_driver_pixel_valid_maskwith default LTO:That is two Ada cards on Windows that pass (desktop 4060 on 617.42, this laptop 4060 with hybrid graphics) against the one failing 4060 in the report, so hybrid graphics does not separate them either. Still open for the reporter: the GPU the test selects (
ANYPS5_GPU), the exact driver build, and whether an overlay is running.AI-assisted (Claude Code); table maintained from the reports in this thread.
Imported from boykopovar/AnyPS5. Originally posted by GustavoGamarra95 on 2026-10-17T23:31:29Z.
Another data point, Ampere laptop on Linux: RTX 3050 Laptop 4 GB (GA107), NVIDIA 615.78.08, CachyOS (kernel 7.2.9), hybrid graphics with an AMD Radeon 660M iGPU (the tests pick the RTX), GCC Release,
BUILD_TESTING=ON. The build ismain922dc8999plus #5987, which only changes device-memory allocation, not pipelines.Readback test from #3741, 20 runs per cell. On this driver the production policy from #3434 turns the relink off, so I forced it with
--force-lto:--force-lto(optimized draws 1)agc_driver_pixel_valid_maskpasses 20 of 20 withctest --repeat until-fail:20. Under the policy it never binds an optimized pipeline here. With the relink forced through the switch below, it also passes 20 of 20.A title with the relink forced. I ran Beast of Reincarnation (PPSA29343) with a local switch,
APS5_FORCE_PIPELINE_LTO=1. It ORs intopipelineLinkTimeOptimizationinVulkanDevice.cpp, andAPS5_NO_PIPELINE_LTOstill wins. The run also counts relinks and binds. Setup: one warm-up run, then 6 runs of 600 s with alternating order (off, LTO, LTO, off, off, LTO), the same scripted input and a warm shader and pipeline cache:VK_ERROR_DEVICE_LOSTin any of the three runs. About 99.9% of binds inPipeline::Continueused the optimized handle (≈1 047 000 optimized, ≈900 fast-linked).gpu_busy_ms_per_presentwas 328 and 328 ms without the relink and 334, 325 and 307 ms with it.WAIT_REG_MEMtimeouts. It isn't related to the relink.So an Ampere laptop with hybrid graphics on the 615 branch doesn't reproduce it, either in the readback cases or across about 3 million optimized binds in a title.
Proposal: a switch plus counters, to measure this on other machines. Today the only way to force the relink on NVIDIA is the readback test's
--force-lto. A title run also doesn't say whether the relink is on, or how many draws used an optimized pipeline. What I used locally:APS5_FORCE_PIPELINE_LTO=1to turn the relink on whatever the driver table says. Device creation also logs one line saying whether the relink is on or off, and why: driver table, force switch orAPS5_NO_PIPELINE_LTO.vkCreateGraphicsPipelinesresult is dropped without a log. The counters also report optimized vs fast-linked binds inPipeline::Continue, which is the share of draws that LTO can affect.To judge whether LTO pays off, compare
mainand the switch on the same machine and scene:gpu_busy_ms_per_present, frame p50/p99 andworker_busy_pct. Use at least 3 runs per side in alternating order, starting from a warm cache, and posttools/trace_digest.pyoutput for both sides. The scene must not be GPU-bound for another reason, which is the limit of my run above.There's also a side effect to check: the libraries are always created with
VK_PIPELINE_CREATE_RETAIN_LINK_TIME_OPTIMIZATION_INFO_BIT_EXT, even when the relink is off. On NVIDIA the driver then keeps link-time data for a relink that never runs. I haven't measured how much memory that costs.With data from more machines, the driver table in
PipelineLinkOptimization.hppcould be narrowed to what actually fails, instead of every driver from one vendor. So far the failures in this thread are on Windows, and every other card in the table passes. If the switch looks useful, I can open it as a separate PR.AI-assisted: yes