fix(shader): split a BDA span read's in-place loads from its fallback #4759
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/4759"
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 fdfawef324 on 2026-10-12T20:58:31Z.
What
Fixes #3291. Resubmits #3289 (closed by the intake bot) by its author, rebased onto current
main.On an RTX 3060 (Windows, driver 591.86) a dispatch that reads guest memory through
read_bda_spannever finishes when its lanes split between the span's in-place dword loads and its per-dword byte fallback (which callsread_bda_dword_bytes). Windows resets the GPU and the device is lost. How the tests then fail depends on where the loss is observed. Most tests fail in teardown: the lost batch keeps its lease, so the teardown waits 60 s for the pinned guest allocation and aborts withguest allocation ... is still pinned by GPU work or an import.agc_driver_pixel_interlockinstead fails after a few seconds withvkDeviceWaitIdle: Vulkan result -4(VK_ERROR_DEVICE_LOST) and never reaches the pin wait.The hang is not general to NVIDIA. The reports in #3291 show:
main(device lost after about 20 s, then the 60 s lease wait), and all 15 BDA tests pass with this change (tested as b54fe623, the same code patch).main, and the nine originally failing tests pass with this change (tested as 338917245, the same code patch). 21 of the 22 affected tests pass three serial repeats; the remaining failure,agc_driver_wave32_subgroup, is reported there as a separate problem. A RADV cross-check passes all 22.main, and the change causes no regression there (356 of 356 tests pass).agc_driver_flat_apertures_*parts time out onmain, but this change was never tested there, and theAPS5_BDA_BYTE_READS=1control also times out. That failure is unresolved and may be a different problem; this PR does not claim to fix it.The two paths were the arms of one
OpSelectionMergeselection inside theDontInlinefunction. They are now two selections, the loads under the span's condition and the fallback under its negation, each producing a zero vector on the lane that does not take it, and the result is chosen after both. Every lane still runs exactly the loads, page-table lookups, fault records and invocation stops it ran before, so no RDNA instruction semantics change; only the SPIR-V control-flow shape does (SPIR-V 2.11 structured control flow). The recompiler emits SPIR-V 1.3 for every stage except mesh shaders (1.4), andOpSelectcan only choose between composite values with a scalar condition from 1.4 on, so the final join stays a selection.The driver-side cause is not known, so the shape is recorded in
docs/dev/debt/shader.md(code comments are not allowed), so that it is not folded back into one selection.#3655 (open, RADV page-table walk inlining) changes the same lines of
SpirvBdaRead.cppfor another reason; whichever merges second rebases. #4224 carried this commit and was closed because it was not its author's.Tested
main3e0e01f35with the fix reverted (ANYPS5_NO_SHADER_CACHE=1,ctest -j 4): 9 of the 23 affected tests fail.agc_driver_flat_loads,agc_driver_flat_loads_x2_x3,agc_driver_flat_loads_x4,agc_driver_global_loads,agc_driver_global_loads_x2_x3,agc_driver_global_loads_x4,agc_driver_flat_apertures_2andagc_driver_flat_apertures_5abort after 64.2 to 70.6 s on the 60 s pin wait.agc_driver_pixel_interlockfails after 6.3 s withvkDeviceWaitIdle: Vulkan result -4.agc_driver_(flat|global)_loads*,agc_driver_pixel_interlock,agc_driver_flat_apertures_0to_13,agc_driver_bda_device,agc_driver_bda_span_reads) pass in 52.3 s at-j 4, the slowest in 18.6 s.ctest -R "^(agc_|shader_)" -j 4withANYPS5_SHADER_CACHE_DIRset to a new empty directory (most of these tests also setANYPS5_NO_SHADER_CACHE=1themselves):3e0e01f35: 444 of 444 pass (agc_driver_stencil_ref_exportskipped), 199.6 s, slowest test 16.0 s (agc_driver_prepared_shaders_debug_failure). An earlier run of the same set failedagc_driver_scalar_swappc_fetchonce (302.7 s, then a vertex value mismatch); it passed alone, in 8 of 8 repeats and in this rerun.44ab0c39e: 443 of 444 pass, 270.4 s, slowest test 29.6 s (agc_driver_swap_alt_blend) while other jobs shared the GPU.agc_driver_depth_storage_reusefailed once withvkWaitForFences graphics: Vulkan result 2(VK_TIMEOUT) after 10.7 s; it passed 8 of 8 repeats alone. All 23 affected tests passed in this run.main42496c5e5(one more AGC texture change, no shader change) and rechecked there: the 23 affected tests pass in 33.0 s at-j 4withANYPS5_NO_SHADER_CACHE=1, the slowest in 21.4 s (agc_driver_flat_apertures_8).main(lavapipe, run 38301611844 on3e0e01f35) passes these tests without the change, so the hang does not reproduce on lavapipe and CI passes either way. This comes from CI, not from a run on this machine.python -I tools/check_conventions.py --base upstream/main: passed.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-12T21:07:37Z.
Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.
main)core/shader/recompiler/SpirvBackend/src/SpirvBdaRead.cppL182-199, L201-203docs/dev/debt/shader.mdL102docs/dev/debt/shader.mdL102docs/dev/debt/shader.mdL102docs/dev/debt/shader.mdL102docs/dev/debt/shader.mdL102docs/dev/debt/shader.mdL102docs/dev/debt/shader.mdL102docs/dev/debt/shader.mdL102docs/dev/debt/shader.mdL102docs/dev/debt/shader.mdL102docs/dev/debt/shader.mdL102docs/dev/debt/shader.mdL102docs/dev/debt/shader.mdL102docs/dev/debt/shader.mdL102docs/dev/debt/shader.mdL102docs/dev/debt/shader.mdL102docs/dev/debt/shader.mdL102docs/dev/debt/shader.mdL102docs/dev/debt/shader.mdL102Imported from boykopovar/AnyPS5. Originally posted by johnohhh1 on 2026-10-12T23:12:29Z.
Tested this on an RTX 5070, Linux, NVIDIA 595.99.02. All 23 affected tests pass on both the baseline and with this PR applied, with zero skips or timeouts. The original hang does not reproduce on this GPU/driver combination, and I observed no regression from the patch in these tests.
ANYPS5_ENABLE_SPIRV_TOOLS=ON.43e3a70f8143f014f621c48abbdb137fffd7346e.f1b2e605e7597603f716abb3cc2924db5d5db8b3, applied without conflicts. The local patch ID matches the PR.agc_driver_(flat|global)_loads*,agc_driver_pixel_interlock,agc_driver_flat_apertures_0–_13,agc_driver_bda_device, andagc_driver_bda_span_reads.ANYPS5_NO_SHADER_CACHE=1,ANYPS5_REQUIRE_VULKAN=1, explicit RTX 5070 selection and NVIDIA Vulkan ICD. Logs confirm the selected GPU.Each version completed one 23-test run. The slowest test was
agc_driver_bda_deviceat about 8.1 seconds in both. NVIDIA's driver cache remained at its default; no performance claim. No game title or full graphics-suite testing.This adds RTX 5070 / 595.99.02 coverage to the no-reproduction side of #3291. It does not independently confirm the fix for the original hang. Build settings, hashes, JUnit results and verbose logs were retained for both runs.
AI-assisted validation and report: Codex. Tested the existing PR patch.
Imported from boykopovar/AnyPS5. Originally posted by kr4y4 on 2026-10-13T06:41:38Z.
On an RTX 4070 Laptop GPU with NVIDIA 595.97, this change causes the hang it fixes on 591.86.
agc_driver_bda_span_readsandagc_driver_pixel_interlocklose the device onmainea2bbefb2, and both pass withSpirvBdaRead.cppas it was before this PR.Setup: Windows 11 (26200), WinLibs GCC 15.2.0 r7, Release, CI configure flags, an RTX 4070 Laptop GPU (NVIDIA 595.97) and an Intel Raptor Lake-S iGPU (32.0.101.6790). I ran the 23 affected tests from the description with
ANYPS5_NO_SHADER_CACHE=1,--repeat until-fail:3and--parallel 4:mainea2bbefb2agc_driver_bda_span_readsandagc_driver_pixel_interlockfailmainea2bbefb2withSpirvBdaRead.cppfromf1b2e605e^[gpu] recorded batch still running on the GPU after 5 s, then the same at 10, 15 and 20 s. After that they fail withvkWaitForFences recorder: Vulkan result -4(span reads) andvkDeviceWaitIdle: Vulkan result -4(pixel interlock). Windows logged annvlddmkmevent 153 at each failure, and the display reset.agc_driver_bda_devicealso failed in some of these runs, while the device was lost.main495bf91a0, in a full-suite run and in a rerun of the three tests.main495bf91a0itself passed all 1023 on both GPUs.guest_video_out_*test time out. On the Intel iGPU, the full suite onea2bbefb2passes 1038 of 1038.So on 595.97 the split selections hang and the single selection doesn't, the reverse of 591.86. The description reports no regression with 616.92 on the same GPU model, so this depends on the driver version. I can run a candidate shape on 595.97 if that helps.
Written with AI assistance.
Imported from boykopovar/AnyPS5. Originally posted by ps54all on 2026-10-13T07:15:54Z.
Same result on an RTX 3080 (Ampere desktop, 0x2206), NVIDIA 610.74, Windows 11, WinLibs GCC 15.2.0 r7, Release. I bisected it in a clean
mainworktree, rebuilding only the two test targets between runs:agc_driver_bda_span_readsagc_driver_pixel_interlocke51428bf2^1(before this PR)e51428bf2(this PR merged)vkDeviceWaitIdle: Vulkan result -4)ea2bbefb2(currentmain)The failures are deterministic, both with and without
APS5_NO_PIPELINE_LTO=1.agc_driver_depth_fast_clearandagc_driver_pixel_valid_maskpass in the same session. With this PR reverted on my integration branch (currentmainplus a few open PRs), all 26bda/flat_/global_loads/pixel_interlocktests pass.Amoenus's comment in #3291 shows the same two tests failing at
e51428bf2on an RTX 5080 with 610.62. Results by driver so far:I can run a candidate shape on 610.74.
AI-assisted (Claude Code); I ran the above on my machine.