fix(shader): load a BDA span in place from its own function #5022

Merged
oneandonlydean merged 1 commit from upstream-pr/5022 into main 2026-10-13 08:44:22 +00:00
oneandonlydean commented 2026-10-13 08:42:17 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-13T08:42:17Z.


What

read_bda_span chooses between a span's in-place dword loads and its per-dword byte fallback, which calls read_bda_dword_bytes. Both shapes of that choice so far hang a group of NVIDIA drivers (a dispatch never finishes and the device is lost), and #4975 shows that reverting #4759 only moves the hang:

shape hangs reports
one selection, the loads emitted in its arm (before #4759) 591.86, 590.48.01 #3291
two selections, loads under the condition and fallback under its negation (#4759) 595.97, 596.36, 610.62, 610.74, 610.57.04 #4975, #4759 comment, here

The loads now live in load_bda_span, a DontInline function that calls nothing, and read_bda_span is one selection again: one arm calls load_bda_span, the other is the fallback as before. Neither earlier shape is emitted: the selection is single, and no function holds both the in-place loads and the nested calls. The probe, the loads, the lookups, the fault records and the invocation stops are unchanged for every lane. A read site in main is unchanged, so its size is too.

This is the shape described in a comment on #3291 as passing on 591.86 (RTX 4060 Laptop) with no pipeline creation cost over main (1.95 s and 7.2 s for 256 and 512 read sites). That was another implementation of it, not this commit.

docs/dev/debt/shader.md: the BDA span reads entry now lists both hanging shapes with their drivers and says where the current one is measured.

Tested

Linux (CachyOS, kernel 7.2, GCC 16.2), RTX 4090, NVIDIA 610.57.04, Release, BUILD_TESTING=ON, built with -DANYPS5_ENABLE_SPIRV_TOOLS=ON and OFF. main was measured at c2565f0149 and the branch is on cac4e9688f; nothing under core/shader or libSceAgcDriver differs between the two.

The 23 tests of #4759 plus agc_driver_scalar_wide_loads, run one at a time with ANYPS5_NO_SHADER_CACHE=1:

SPIRV-Tools on SPIRV-Tools off
main (1 run) 9 of 24: agc_driver_scalar_wide_loads and agc_driver_flat_apertures_0 to _13 hang 22 of 24: agc_driver_bda_span_reads and agc_driver_pixel_interlock hang
main with SpirvBdaRead.cpp from e51428bf2^1 (4 of the tests) 4 of 4 4 of 4
this branch (3 runs) 24 of 24, slowest 5.9 s (agc_driver_bda_device) 24 of 24, slowest 2.1 s
  • Each hang prints [gpu] recorded batch still running on the GPU after 5 s, logs one NVIDIA Xid 109 in the kernel log and ends in guest allocation ... is still pinned by GPU work or an import. No Xid with the branch.
  • A 3D title also loses the device on this driver, 0.2 to 0.4 s after a level starts (vkQueueSubmit recorder: Vulkan result -4, Xid 109), in a build without SPIRV-Tools. Bisected to e51428bf2: its parent doesn't, and main with only #4759 reverted ran 5 times without it. This branch was not run in that title.
  • So on this driver the optimizer decides which tests the #4759 shape hangs, and the two that fail without SPIRV-Tools are the two reported on Windows in #4975.
  • The emitted module of agc_driver_scalar_wide_loads passes spirv-val --target-env vulkan1.3 in all three shapes; nothing invalid was found in the hanging one.
  • agc_shader_memory, "BDA read functions": a span read function must hold no load and call its load function once, and the load function must hold the four loads and no call. On main it fails with the span load function does not hold the four in-place loads and nothing else. It needs no GPU, so it runs on lavapipe CI.
  • ctest -R "agc|shader" with SPIRV-Tools on: 476 of 476 pass, no Xid. On main the 15 hangs above are the failures.
  • python3 tools/check_conventions.py --base origin/main and git diff --check pass.

Not tested: drivers 591.86, 590.48.01, 595.97, 596.36, 610.62 and 610.74, any Windows build, AMD, Intel, and any title. A run on one driver of each group would settle it; the #4759 comment above offers one on 595.97 and a #4975 comment one on 610.74.

#4976 and #3655 change the same function, so whichever merges later needs a rebase.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Unblocks: none (#4975)
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4840659926 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5022). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-13T08:42:17Z. --- ### What `read_bda_span` chooses between a span's in-place dword loads and its per-dword byte fallback, which calls `read_bda_dword_bytes`. Both shapes of that choice so far hang a group of NVIDIA drivers (a dispatch never finishes and the device is lost), and #4975 shows that reverting #4759 only moves the hang: | shape | hangs | reports | | - | - | - | | one selection, the loads emitted in its arm (before #4759) | 591.86, 590.48.01 | #3291 | | two selections, loads under the condition and fallback under its negation (#4759) | 595.97, 596.36, 610.62, 610.74, 610.57.04 | #4975, [#4759 comment](https://github.com/boykopovar/AnyPS5/pull/4759#issuecomment-6139879773), here | The loads now live in `load_bda_span`, a `DontInline` function that calls nothing, and `read_bda_span` is one selection again: one arm calls `load_bda_span`, the other is the fallback as before. Neither earlier shape is emitted: the selection is single, and no function holds both the in-place loads and the nested calls. The probe, the loads, the lookups, the fault records and the invocation stops are unchanged for every lane. A read site in `main` is unchanged, so its size is too. This is the shape described in a [comment on #3291](https://github.com/boykopovar/AnyPS5/issues/3291#issuecomment-6111873986) as passing on 591.86 (RTX 4060 Laptop) with no pipeline creation cost over `main` (1.95 s and 7.2 s for 256 and 512 read sites). That was another implementation of it, not this commit. `docs/dev/debt/shader.md`: the BDA span reads entry now lists both hanging shapes with their drivers and says where the current one is measured. ### Tested Linux (CachyOS, kernel 7.2, GCC 16.2), RTX 4090, NVIDIA 610.57.04, Release, `BUILD_TESTING=ON`, built with `-DANYPS5_ENABLE_SPIRV_TOOLS=ON` and `OFF`. `main` was measured at c2565f0149 and the branch is on cac4e9688f; nothing under `core/shader` or `libSceAgcDriver` differs between the two. The 23 tests of #4759 plus `agc_driver_scalar_wide_loads`, run one at a time with `ANYPS5_NO_SHADER_CACHE=1`: | | SPIRV-Tools on | SPIRV-Tools off | | - | - | - | | `main` (1 run) | 9 of 24: `agc_driver_scalar_wide_loads` and `agc_driver_flat_apertures_0` to `_13` hang | 22 of 24: `agc_driver_bda_span_reads` and `agc_driver_pixel_interlock` hang | | `main` with `SpirvBdaRead.cpp` from e51428bf2^1 (4 of the tests) | 4 of 4 | 4 of 4 | | this branch (3 runs) | 24 of 24, slowest 5.9 s (`agc_driver_bda_device`) | 24 of 24, slowest 2.1 s | - Each hang prints `[gpu] recorded batch still running on the GPU after 5 s`, logs one NVIDIA Xid 109 in the kernel log and ends in `guest allocation ... is still pinned by GPU work or an import`. No Xid with the branch. - A 3D title also loses the device on this driver, 0.2 to 0.4 s after a level starts (`vkQueueSubmit recorder: Vulkan result -4`, Xid 109), in a build without SPIRV-Tools. Bisected to e51428bf2: its parent doesn't, and `main` with only #4759 reverted ran 5 times without it. This branch was not run in that title. - So on this driver the optimizer decides which tests the #4759 shape hangs, and the two that fail without SPIRV-Tools are the two reported on Windows in #4975. - The emitted module of `agc_driver_scalar_wide_loads` passes `spirv-val --target-env vulkan1.3` in all three shapes; nothing invalid was found in the hanging one. - `agc_shader_memory`, "BDA read functions": a span read function must hold no load and call its load function once, and the load function must hold the four loads and no call. On `main` it fails with `the span load function does not hold the four in-place loads and nothing else`. It needs no GPU, so it runs on lavapipe CI. - `ctest -R "agc|shader"` with SPIRV-Tools on: 476 of 476 pass, no Xid. On `main` the 15 hangs above are the failures. - `python3 tools/check_conventions.py --base origin/main` and `git diff --check` pass. Not tested: drivers 591.86, 590.48.01, 595.97, 596.36, 610.62 and 610.74, any Windows build, AMD, Intel, and any title. A run on one driver of each group would settle it; the #4759 comment above offers one on 595.97 and a #4975 comment one on 610.74. #4976 and #3655 change the same function, so whichever merges later needs a rebase. ### Checklist - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Unblocks: none (#4975) - [x] AI-assisted: yes
kr4y4 commented 2026-10-13 14:58:47 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by kr4y4 on 2026-10-13T14:58:47Z.


Driver 595.97, which the commit message lists as not tested, passes with this change, in a default build and in one with SPIRV-Tools.

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), main 0f2683cb7. This is the machine from my report on #4759, where agc_driver_bda_span_reads and agc_driver_pixel_interlock lost the device on main ea2bbefb2.

  • 25 tests, run with ANYPS5_NO_SHADER_CACHE=1, --repeat until-fail:3 and --parallel 4: agc_shader_memory, agc_driver_scalar_wide_loads, agc_driver_bda_device, agc_driver_bda_span_reads, agc_driver_pixel_interlock, agc_driver_flat_apertures_0 to 13, and the six flat_loads and global_loads tests.
    • Default build: 25 of 25 on both GPUs. The slowest test took 2.8 s on NVIDIA and 3.5 s on Intel.
    • With -DANYPS5_ENABLE_SPIRV_TOOLS=ON: 25 of 25 on both GPUs. The slowest took 7.3 s on NVIDIA and 27.0 s on Intel.
  • Full suite (ctest --timeout 120 --parallel 4), default build: 1069 of 1069 on both GPUs.
  • Windows logged no nvlddmkm events during these runs.

Written with AI assistance.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6148478749 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5022#issuecomment-6148478749). Originally posted by [kr4y4](https://github.com/kr4y4) on 2026-10-13T14:58:47Z. --- Driver 595.97, which the commit message lists as not tested, passes with this change, in a default build and in one with SPIRV-Tools. 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), `main` 0f2683cb7. This is the machine from my report on #4759, where `agc_driver_bda_span_reads` and `agc_driver_pixel_interlock` lost the device on `main` ea2bbefb2. - 25 tests, run with `ANYPS5_NO_SHADER_CACHE=1`, `--repeat until-fail:3` and `--parallel 4`: `agc_shader_memory`, `agc_driver_scalar_wide_loads`, `agc_driver_bda_device`, `agc_driver_bda_span_reads`, `agc_driver_pixel_interlock`, `agc_driver_flat_apertures_0` to `13`, and the six `flat_loads` and `global_loads` tests. - Default build: 25 of 25 on both GPUs. The slowest test took 2.8 s on NVIDIA and 3.5 s on Intel. - With `-DANYPS5_ENABLE_SPIRV_TOOLS=ON`: 25 of 25 on both GPUs. The slowest took 7.3 s on NVIDIA and 27.0 s on Intel. - Full suite (`ctest --timeout 120 --parallel 4`), default build: 1069 of 1069 on both GPUs. - Windows logged no `nvlddmkm` events during these runs. Written with AI assistance.
Sign in to join this conversation.
No reviewers
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!5022
No description provided.