fix(shader): leave the BDA lookup functions through one return #7571
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/7571"
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 milescoviello on 2026-10-18T14:53:14Z.
What
agc_driver_bda_devicehangs the GPU on NVIDIA since #5859. Onmaina62c724c38it fails 3 of 3 withvkWaitForFences graphics: Vulkan result 2(the 5 s fence timeout), and the kernel logsNVRM: Xid 109 ... CTX SWITCH TIMEOUTfor it.385ed71f2c, just before #5859, passes.mainpasses on an Intel Arrow Lake iGPU (Mesa 26.1 ANV). The dispatch that hangs is in #5859's newRunBdaAnchorTests, but in the plain program, which reads throughget_bda_pointerandprobe_bda_pointer, lookup code #5859 didn't change.I reduced it with a temporary hook in the test (not part of this PR). It takes a program that doesn't stop invocations at a fault, as
BdaInvocationsMayStopdecides for programs with barriers, reading one dword per lane in 64 lanes. That program hangs when invocations in one subgroup leave the lookup through three different returns:index == 0, unmapped);Any two of the three don't hang, and neither do 8-bit reads or the program that stops invocations. It doesn't need the address overflows #5859's test inputs produce either. With a table whose first range is [0x100000, 0x100010) and lanes at 0xfff01, 0x100010 and 0x100000, it hangs the same way. Without
DontInlineon the lookups it doesn't hang. Without it on the dword read functions or on the fault recorder, it still hangs.The change. The lookups returned from each failed check (
ReturnBdaZeroIf,ReturnBdaFailureIf). Now their body sits in a single-pass loop. Each failed check records its fault (inget_bda_pointer) and branches to the loop's merge block. A phi there takes the result, and the function's oneOpReturnValuereturns it. The early checks are all outside the binary-search loop, so each exit is a break of the new loop. The lookups stayDontInline:5693c77efbmeasured minutes of NVIDIA compile time per shader when they are inlined.ReturnBdaFailureIfno longer has a caller. I left it inSpirvBdaFault.cppbecause #6416, #6751 and #7392 add code right after it, so removing it can wait for a follow-up.Test.
RunBdaAnchorTestsnow ends with that subgroup in the 64-lane program that doesn't stop invocations, over the table above. The program reads one dword at 0xfff00 plus one lane's offset, with lanes below the first range, past its end, at its last dword and at its start. The unmapped lanes must read zero with the unmapped fault recorded, the others their dword, and every read kind must match the anchored program.Tested
Ubuntu 24.04 (Linux 6.8), GCC 13.3, NVIDIA RTX 4070 Ti (595.99.02); Intel Arrow Lake iGPU (Mesa 26.1 ANV).
agc_driver_bda_device:maina62c724c38fails 3 of 3 on NVIDIA. With this PR (head8e7d8874c8, including the new case) it passes 3 of 3 on NVIDIA and 3 of 3 on the Intel iGPU.INTEL_DEBUG=csand Mesa's shader cache off,agc_driver_bda_device's 107 compiled variants are identical onmainfd58ca321eand with this PR. The statistics match (211,249 instructions, 0:0 spills:fills in every variant), and so does the full assembly (0 of 1,041,924 lines differ). Run times are unchanged: 1614-1660 ms against 1623-1646 ms with a warm Mesa cache, 20.8-20.9 s against 21.1-21.4 s with it off. Gen9 (HD 520) isn't covered (details).8e7d8874c8on Windows with an RTX 5080, driver 610.62 (comment): it passes 3 of 3.main's lookup with the new case also passes 3 of 3 there, so that driver doesn't hang. @simonbbby saw the same with 595.99.02 on an RTX 3090 (Ampere) (comment):main's lookup with the new case lost the device, while this head passes 3 of 3, and RADV (gfx1036, Mesa 25.2.8) passes both. @Dextroid17 saw it with Linux 615.78.08 on an RTX 3080 Ti (Ampere) (comment):mainfails 3 of 3, each with an Xid 109, and this head passes 3 of 3. @jotitadev ran it on an Apple M2 Max through MoltenVK 1.4.2 and through MoltenVKmainwith SPIRV-Cross #2704 (comment). This head andmain's lookup with the new case both pass 3 of 3, and the^agc|^shadersuite has the same 46 failures with and without this PR, none of them a BDA test. So the hang is seen with Linux drivers 595.99.02 (Ada, Ampere) and 615.78.08 (Ampere), and not with 610.62 on Windows on a Blackwell card, which differs in OS, GPU generation and tree.ctest -R "^agc_|^shader_ir": 711/711 pass on NVIDIA. With the hook, every reduced case completes with the fix: the overflow and no-overflow repros, 1 and 4 dwords, plain and anchored.agc_shader_replay --spv(Release,ANYPS5_ENABLE_SPIRV_TOOLSoff,ANYPS5_NO_SHADER_CACHE=1) over the 466 shader requests I had dumped, from PPSA30839 (MXGP 26), PPSA31162 (Super Meat Boy 3D) and one other app:main's.spirv-val --target-env vulkan1.2reports the sameCullPrimitiveEXTerror for them before and after this PR.DontInline.Title level: no claim. I don't know a title that hits this. It needs a program with a barrier in which one subgroup reads mapped, below-table and past-end guest addresses at once.
tools/check_conventions.py --base upstream/mainpasses.tools/pr_overlap.pylists two pull requests that conflict withmain, so it couldn't compare them. #6947 also editsDefineBdaLookup, and #6373 editstests/BdaExecution.cpp. I'll rebase onto whichever lands first.main84c1a4d9afails 3 of 3 (-4). With this PR it passes 3 of 3, and withmain'sSpirvBdaLookup.cppit fails 3 of 3 again. So it isn't specific to the 596.21 driver: Ada fails on newer drivers too, while the RTX 5080 (Blackwell) passed.mainad502d717fails 5 of 5 (Vulkan result 2, then-4), and with this PR it passes 3 of 3. Two of themainruns came after the PR runs, so it doesn't depend on cache state.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-18T15:09:01Z.
Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
core/shader/recompiler/SpirvBackend/src/SpirvBdaLookup.cppcore/shader/recompiler/SpirvBackend/src/SpirvBdaLookup.cppImported from boykopovar/AnyPS5. Originally posted by Amoenus on 2026-10-18T15:32:26Z.
@milescoviello Windows/another NVIDIA-driver datapoint for your exact head
8e7d8874c8:10de:2c02), driver 610.62 / 32.0.16.1062, WinLibs GCC 15.2.0 r7 Release;ANYPS5_REQUIRE_VULKAN=1,ANYPS5_NO_SHADER_CACHE=1, Khronos validation layer 1.4.363.0 actually loaded.dafbd21b78. Matching full relinker/library build passes;agc_driver_bda_devicepasses 3/3, each within30s, with actual NVIDIA device identity verified and zero logged VUIDs/validation errors.726bffc791also passes 3/3 on this Windows/610.62 setup. That control adds your exact14-line regression, with original authorship retained, to the same integration using the original lookup. OnlySpirvBdaLookup.cppdiffers between the two tested trees. Thus I do not reproduce the Linux/595.99 hang here; these runs show no regression with your fix on this host, not an additional fail-before/pass-after confirmation.These are composition-scoped results, not an unchanged-main suite or a title fix. The private BDA fixture selected NVIDIA; no AMD coverage is attributed to an environment-variable request.
AI-assisted independent validation: yes (Codex).
Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-18T15:34:32Z.
Thanks @Amoenus, that narrows it. With your RTX 5080 on driver 610.62, the original lookup runs the new case without hanging, so it isn't every NVIDIA driver. Here it's an RTX 4070 Ti (Ada) on Linux with 595.99.02, where
mainhangs 3 of 3 (Xid 109). I can't try a 610 driver on this Linux host, so I can't tell whether the driver version or the GPU generation matters. I've added your result to the description. The change works around the drivers that hang, like 595.99 here, and in the replay corpus it changes only the lookup bodies of the 5 modules that use them.AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by simonbbby on 2026-10-18T16:26:12Z.
Independent Linux Ampere and RADV comparison for exact head
8e7d8874c8ee078aa0d932a70d0eb92cff853f33:Ubuntu 24.04, kernel
7.0.0-38-generic, GCC 13.3, Release.ANYPS5_REQUIRE_VULKAN=1, application shader cache and pipeline journal disabled; ICD selected explicitly, withVK_LOADER_DEBUG=driverrecording the device used.SpirvBdaLookup.cppfrom maina62c724c3873b1dee9c6ee5af7a420e924bd9d25, PR fixture retainedAGC graphics: vkWaitForFences graphics: Vulkan result -4(VK_ERROR_DEVICE_LOST)The exact fixed head also passed once per device before the original-lookup control. Only
SpirvBdaLookup.cppchanged for that control; the expandedBdaExecution.cppfixture hash stayed identical throughout. After restoration the worktree is clean. Each positive process reachesBDA store boundary tests passedandVulkan BDA allocation and execution tests passed, with the loader confirming RTX 3090 or RADV respectively. The host has two RTX 3090s; I used the fixture's existing first-ranked physical-device selection within the NVIDIA ICD, not a pinned GPU UUID.This extends the affected NVIDIA hardware beyond Ada on the reported driver version. The observed original-lookup failure here is device loss (-4), not the reported timeout (2); I did not reproduce the exact Xid 109 signature (the accessible kernel journal query returned no matching entries). I ran the original NVIDIA control once, then restored the fix and observed the three passes above; this is not a failure-frequency measurement or proof of the driver compiler's internal cause.
No title or full-suite result, and no Khronos validation-layer coverage. I did not count lavapipe as read/anchor coverage because this fixture skips
RunBdaExecutionTestson a CPU Vulkan device.Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-18T16:28:35Z.
Thanks @simonbbby. So it isn't specific to Ada. I added your result to the description.
AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by Dextroid17 on 2026-10-18T16:37:10Z.
@milescoviello on "it follows the 595.99 driver rather than the GPU generation": on this Linux Ampere host the hang is still there on 615.78.08. That's a higher version than the 610.62 that passed for @Amoenus on Windows, so the version number alone doesn't explain his pass. His run also differs in GPU generation (RTX 5080, Blackwell), OS and tree (his integration), and this run doesn't separate those.
CachyOS, kernel 7.2.9-2-cachyos, GCC 16.2.1, Release build. RTX 3080 Ti (Ampere), NVIDIA driver 615.78.08. Only the NVIDIA ICD was in
VK_ICD_FILENAMESandVK_DRIVER_FILES, withANYPS5_REQUIRE_VULKAN=1and a clean environment. Shader cache was not disabled.ctest -R '^agc_driver_bda_device$', 3 runs per tree:maina62c724c38(where this PR branched)vkWaitForFences graphics: Vulkan result -4in 2 runs,Vulkan result 2in 18e7d8874c8withSpirvBdaLookup.cppfroma62c724c388e7d8874c8Each failing run logged one kernel line,
NVRM: Xid ... 109, ... name=agc_driver_bda_, ... errorString CTX SWITCH TIMEOUT, whether the test reported -4 or 2. The passing runs logged none. In one more direct run of the test binary on your head (it passed),/proc/<pid>/mapsshowed NVIDIA's driver libraries loaded and no lavapipe.Compared with @simonbbby's RTX 3090 run, this adds a newer driver, a plain
mainarm, 3 of 3 failures in each failing arm, and an Xid 109 line for every failure. The passes on your head match his.Not checked: any title, validation layers, other driver versions on this card. lavapipe isn't counted, since the fixture skips BDA execution on CPU devices.
AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-18T16:38:35Z.
Thanks @Dextroid17, that corrects my comment above: a newer driver on Linux hangs too, so it doesn't follow 595.99. I've changed that comment and the description. The pass on 610.62 now differs in OS (Windows), GPU generation (Blackwell) and tree, as you say.
AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-18T17:38:23Z.
Apple GPU / MoltenVK datapoint for head
8e7d8874c. Here the SPIR-V goes through SPIRV-Cross to MSL and the Metal compiler, so this is a different lookup codegen from the NVIDIA, Intel and AMD runs above.Machine: Apple M2 Max, macOS 27.2, x86-64 build under Rosetta. Method: main
81cb86339+ @mugurc'sci/macos-series-2(fa6d8ae0b, which has the MoltenVK device bring-up) + the open fixes it uses as stand-ins (#6667, #6668, #6853, #6836, #6620, #6969, #7524, #6928), then this PR merged on top (clean). Drivers: MoltenVK 1.4.2 (Vulkan SDK 1.4.363), and MoltenVK main with SPIRV-Cross #2704.ANYPS5_REQUIRE_VULKAN=1,ANYPS5_NO_SHADER_CACHE=1.agc_driver_bda_deviceBdaExecution.cppcase, lookups unchangedRunBdaAnchorTestsis called with no device condition.^agc|^shadersuite with the PR (MoltenVK 1.4.2,-j1 --timeout 30, flip/display/lds_atomics64 excluded): the same 46 failures out of 700 as the tree without the PR. None of them is a BDA test. Most are device gaps (-0 and denormals, no geometry shaders, no cull distance, descriptor limits) or macOS host gaps. One extra run hadagc_driver_prepared_shaders_lazytime out once. It passed 5 of 5 reruns at 0.13 s and doesn't go through these lookups.GPUs tested: Apple M2 Max (MoltenVK 1.4.2; MoltenVK main + SPIRV-Cross #2704)
Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-18T17:53:02Z.
Thanks @jotitadev, that's a useful datapoint because it goes through a different compiler. I added it to the description.
AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-18T20:43:55Z.
Register pressure on Intel, since #5814 was closed over spills on Gen9 and this PR also restructures the BDA lookup. Intel Arrow Lake iGPU (Gen12.7, Core Ultra 7 265K), Mesa 26.1.6 ANV, Debian 13, kernel 6.12.
agc_driver_bda_device_testsonmainfd58ca321eand on thatmainwith this PR merged (6b6871cd92). The two builds'libSceAgcDriver.prxand test binaries differ.Compiled code.
INTEL_DEBUG=cswithMESA_SHADER_CACHE_DISABLE=true. Without the second variable my first pass printed nothing, because every shader came from Mesa's disk cache.So on this GPU, ANV reduces both forms of the lookup to the same machine code.
Run time of the whole test binary, 3 runs each:
mainLimits: this is Gen12.7, not the Gen9 HD 520 where #5814 regressed, and the backend differs between them, so it doesn't replace that run. I also haven't checked which of the 107 variants contain the lookup.
RunBdaAnchorTests, the case that hangs NVIDIA onmain, is among the shaders compiled here.AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by m335671 on 2026-10-18T23:56:41Z.
Windows on Ada with a newer driver, the combination the thread was missing: RTX 4070 (
10de:2786), NVIDIA 616.92, Windows 11 Pro 26200, Ryzen 9 7900, WinLibs GCC 15.2.0 r7, Release,BUILD_TESTING=ON.ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1,ctest -R '^agc_driver_bda_device$' -j1, one fresh process per run. All three trees share the same base:main84c1a4d9a. This head merges into it cleanly.main84c1a4d9avkWaitForFences graphics: Vulkan result -4main+ this PR (8e7d8874c8)main+ this PR withSpirvBdaLookup.cppfrommain(control)Vulkan result -4So on Windows the failure isn't specific to the 596.21 driver from the report: an Ada card on 616.92, newer than the 610.62 that passed on the RTX 5080, fails on
mainand passes with this change. With the RTX 5080 pass, that points at the GPU generation rather than the driver version or the OS. The reporter's card (RTX 4070) behaves the same on this newer driver. In an earlier full-suite run (parallel CTest, other software injecting into processes), the samemaintest hit the 300 s timeout instead of-4. I'm not counting that run.AI-assisted: yes (Claude Code). The builds, the runs and this comment were done and written by Claude Code on my machine.
Imported from boykopovar/AnyPS5. Originally posted by m335671 on 2026-10-19T00:09:04Z.
Same on NVIDIA 617.42 (updated driver, same machine and trees):
mainfails 3 of 3 (-4),main+ this PR passes 3 of 3.AI-assisted: yes (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-19T01:06:15Z.
Thanks @m335671, that's the run the thread needed. An Ada card failing on 616.92 and 617.42, with the
SpirvBdaLookup.cppcontrol failing again, points at the GPU generation rather than the 595.99 driver. I added it to the description.AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by MaxLikesCode on 2026-10-19T01:18:23Z.
Windows data from a GPU where
mainfails: NVIDIA GeForce RTX 4090, driver 617.42, Windows 11 Pro 26200, WinLibs GCC 15.2.0 r7, Release,BUILD_TESTING=ONwith the Windows CI configure flags.agc_driver_bda_devicemainad502d717vkWaitForFences graphics: Vulkan result 2on the first run,-4(device lost) on the others8e7d8874c) merged intoad502d717Two of the
mainruns came after the PR runs, so the difference does not depend on shader or pipeline cache state. On this RTX 4090 the change fixes the failure that the RTX 5080 control did not show.AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-19T01:19:07Z.
Thanks @MaxLikesCode. A second Ada card (RTX 4090, 617.42) failing on
mainand passing with this change, withmainruns after the PR runs, settles the cache question. Added to the description.AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by elliot1377 on 2026-10-19T08:17:27Z.
Windows NVIDIA run where
mainfails, which the RTX 5080 control couldn't show sincemainpasses there.Windows 11 (10.0.26200), NVIDIA GeForce RTX 4050 Laptop GPU, driver 617.42, WinLibs GCC 15.2.0 r7, Release,
BUILD_TESTING=ON,ctest -R '^agc_driver_bda_device$'one run at a time.agc_driver_bda_devicemainf71a31193vkWaitForFences graphics: Vulkan result -4(VK_ERROR_DEVICE_LOST, not theVK_TIMEOUTseen on the 4070/4070 Ti), after about 2.5 s8e7d8874cmerged ontof71a31193(clean)Before this, I bisected the failure on this machine to the #5859 merge:
385ed71f2passes 2 of 2, and644e38480fails 2 of 2 with the same device loss. So on this GPU and driver #5859 loses the device rather than hanging, and this PR fixes that here too.Not checked: Linux, AMD, the Intel iGPU (disabled on this laptop right now), or a title.
AI-assisted
Imported from boykopovar/AnyPS5. Originally posted by Rajkamalcode on 2026-10-19T09:52:24Z.
For the record, the matrix cell I can't find above: Windows + Ampere. GeForce RTX 3070 (GA104, driver 32.0.16.1088), Windows 11 (22635.5305), Ryzen 5 5600X, WinLibs GCC 15.2.0 r7, Release.
main2eb4de8e1: fails 3/3 —AGC graphics: vkWaitForFences graphics: Vulkan result -4(onmain, no pass today in 10 attempts across two revisions)8e7d8874c8: passes 5/5 (cold 8.18 s, warm 1.17 s)So the generation effect holds on Windows too: Ampere fails on
main, and the single-return lookup fixes it, same as the Ada Windows results above.Details in #7584: https://github.com/boykopovar/AnyPS5/issues/7584#issuecomment-6264471497
AI-assisted: yes.
Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-19T11:24:19Z.
@elliot1377 @Rajkamalcode thank you both. The RTX 4050 Laptop and RTX 3070 runs fill the two cells the thread was missing: an Ada laptop part that loses the device rather than timing out, and Ampere on Windows. Both fail on
mainand pass with this change. Your bisect to the #5859 merge on the 4050 also agrees with where this issue says the failure started.AI-assisted: yes (Claude Code)