fix(shader): inline mesh helper functions on NVIDIA #15917

Merged
SeifKaroui merged 4 commits from upstream-pr/15917 into main 2026-11-14 17:34:44 +00:00
SeifKaroui commented 2026-11-04 23:45:39 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by SeifKaroui on 2026-11-04T23:45:39Z.


What

On NVIDIA's proprietary driver a mesh program whose helper functions stay real calls (the DontInline BDA readers read_bda_span, probe_bda_pointer, read_bda_dword_bytes, ...) gets wrong data in subgroups 1-3 of the workgroup. In RESIDENT EVIL requiem's NGG point-culling mesh program (128 threads, wave64 run as two subgroups), s_buffer_load_dword of the cluster word through a descriptor read from memory returned the right value in wave 0 and 0xffffffff in wave 1 of every workgroup, with every input of the load equal in both waves. Wave 1 then emitted triangles and vertices past the cluster's counts: triangle shards across the 3D main menu.

SpirvTarget::meshInlineFunctions (set for VK_DRIVER_ID_NVIDIA_PROPRIETARY, part of the shader cache key, APS5_NO_MESH_INLINE_FUNCTIONS=1 turns it off) makes SpirvModule::InlineFunctions give every non-entry function of a mesh module the Inline control in place of DontInline, and the driver inlines them. Keeping only load_bda_span as a call, to avoid the shape that hung NVIDIA compute dispatches in #3291, hung the title's draw on this driver, so every function is inlined. The risk is recorded in the new debt entry "Mesh helper functions on NVIDIA". VulkanDevice::DriverId() lets agc_driver_mesh_waves check that the device asks for the inlining on that driver and on no other.

Tested

Windows 11, NVIDIA GeForce RTX 5060 Laptop GPU, driver 617.42.

  • RESIDENT EVIL requiem (PPSA30803), 3D main menu over a full cycle of its four shots (corkboard, desk, office, papers): no shards, no geometry missing, on an October main and again on main b11c7bf84f (with the title's other open fixes applied). A replay of the captured first culling draw of the corkboard shot gives the shards image with APS5_NO_MESH_INLINE_FUNCTIONS=1 and the clean image without it, on both.
  • ctest --test-dir build -R "mesh|^agc_shader_disk_cache$" -V on main 1ff0fe98aa and on this branch, with ANYPS5_REQUIRE_VULKAN=1, ANYPS5_NO_SHADER_CACHE=1 and VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation (nightly validation layer): all pass (10 on main, 11 here with the new agc_driver_mesh_waves). Neither log contains was not found but was requested by env var VK_INSTANCE_LAYERS; neither has a VUID- error; both have the same 20 validation warnings (same IDs and counts). The same comparison on the earlier mains b11c7bf84f and 15454571d9 gave the same result. With the meshInlineFunctions line removed from VulkanDevice.cpp, agc_driver_mesh_waves fails: the device target does not ask for inlined mesh helper functions on Vulkan driver 4; NVIDIA's proprietary driver needs them unless APS5_NO_MESH_INLINE_FUNCTIONS is set, and other drivers keep the calls.
  • The whole AGC and shader suite, ctest --test-dir build -R "^agc_|^shader_|recompiler" -j 4 -V with the same three variables, on the earlier main b11c7bf84f (1378 tests) and on this change applied to it (1379): the same results apart from the new test. 1366 and 1367 pass, 11 skip on both, and agc_driver_direct_write_completion fails on both (a storage-image timing test without mesh programs). Both logs have the same 26 VUID- lines, from agc_driver_image_gather_volume, agc_driver_prepared_exports and agc_driver_srgb8_color_target, and the same 142 warnings.
  • Pipeline creation time, RESIDENT EVIL requiem from start to the 3D menu (240 s per run, empty ANYPS5_SHADER_CACHE_DIR, and a local timing build, not part of this PR, that also gave every run's SPIR-V its own generator word so the driver's cache could not serve it): the 8 mesh pipelines took 11.5 and 12.4 s to create with this change and 6.5 and 6.8 s with APS5_NO_MESH_INLINE_FUNCTIONS=1, about 1.7 times as long; the slowest one took 2.2 to 2.7 s against 1.75 s. The other 138 pipelines took 51.6 to 58.5 s in every run. A third run with the change reusing the first run's SPIR-V took 10.5 s, so the driver's cache did not hide the cost. The runs with the change showed no shards; the two without it showed them.
  • The branch is on current main 1ff0fe98aa. Rebasing put meshInlineFunctions after #11351's f16 NaN flags in CacheKey.hpp, Recompiler.cpp, Recompiler.hpp and SpirvEmitter.hpp; nothing else in the diff changed.
  • tools/check_conventions.py passes against 1ff0fe98aa with this title and description. Before opening, tools/pr_overlap.py --branch fix/mesh-inline-functions-nvidia against 15454571d9 over the 1880 open pull requests finds line conflicts only where another pull request adds its own line at the same place: #6751 and #7392 (BDA fault flags in SpirvEmitter.cpp), #11351 and #15719 (f16 NaN target flags in CacheKey.hpp, Recompiler.cpp and Recompiler.hpp) and #15668 (the debt entry above this one); none shares exports. It could not compare 89 pull requests that conflict with main. A search of their diffs finds no other inlining change; four of them (#7642, #10193, #13928, #13929) add a DontInline image-table helper in SpirvImageEmitter.cpp, which this change makes Inline in a mesh module on NVIDIA like every other helper.
  • Limitation: agc_driver_mesh_waves checks that the device target asks for the inlining exactly on NVIDIA's proprietary driver, that a mesh program there keeps no helper function without Inline, and that each wave's scalar buffer load through a descriptor read from memory returns its own value. That draw also passes with the calls kept, so the wrong data is reproduced only by the title's draw. Other NVIDIA GPUs and drivers are not tested, in particular the drivers listed in #3291 and #4975, and only the title's 3D main menu was played.

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
  • Fixes: none
  • Unblocks: PPSA30803 #11599 (RESIDENT EVIL requiem, 3D main menu; the discussion is filed under the game's other title ID)
  • GPUs tested: NVIDIA GeForce RTX 5060 Laptop GPU, driver 617.42, Windows 11
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5163486356 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/15917). Originally posted by [SeifKaroui](https://github.com/SeifKaroui) on 2026-11-04T23:45:39Z. --- ### What On NVIDIA's proprietary driver a mesh program whose helper functions stay real calls (the `DontInline` BDA readers `read_bda_span`, `probe_bda_pointer`, `read_bda_dword_bytes`, ...) gets wrong data in subgroups 1-3 of the workgroup. In RESIDENT EVIL requiem's NGG point-culling mesh program (128 threads, wave64 run as two subgroups), `s_buffer_load_dword` of the cluster word through a descriptor read from memory returned the right value in wave 0 and 0xffffffff in wave 1 of every workgroup, with every input of the load equal in both waves. Wave 1 then emitted triangles and vertices past the cluster's counts: triangle shards across the 3D main menu. `SpirvTarget::meshInlineFunctions` (set for `VK_DRIVER_ID_NVIDIA_PROPRIETARY`, part of the shader cache key, `APS5_NO_MESH_INLINE_FUNCTIONS=1` turns it off) makes `SpirvModule::InlineFunctions` give every non-entry function of a mesh module the `Inline` control in place of `DontInline`, and the driver inlines them. Keeping only `load_bda_span` as a call, to avoid the shape that hung NVIDIA compute dispatches in #3291, hung the title's draw on this driver, so every function is inlined. The risk is recorded in the new debt entry "Mesh helper functions on NVIDIA". `VulkanDevice::DriverId()` lets `agc_driver_mesh_waves` check that the device asks for the inlining on that driver and on no other. ### Tested <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> Windows 11, NVIDIA GeForce RTX 5060 Laptop GPU, driver 617.42. - RESIDENT EVIL requiem (PPSA30803), 3D main menu over a full cycle of its four shots (corkboard, desk, office, papers): no shards, no geometry missing, on an October main and again on main b11c7bf84f (with the title's other open fixes applied). A replay of the captured first culling draw of the corkboard shot gives the shards image with `APS5_NO_MESH_INLINE_FUNCTIONS=1` and the clean image without it, on both. - `ctest --test-dir build -R "mesh|^agc_shader_disk_cache$" -V` on main 1ff0fe98aa and on this branch, with `ANYPS5_REQUIRE_VULKAN=1`, `ANYPS5_NO_SHADER_CACHE=1` and `VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation` (nightly validation layer): all pass (10 on main, 11 here with the new `agc_driver_mesh_waves`). Neither log contains `was not found but was requested by env var VK_INSTANCE_LAYERS`; neither has a `VUID-` error; both have the same 20 validation warnings (same IDs and counts). The same comparison on the earlier mains b11c7bf84f and 15454571d9 gave the same result. With the `meshInlineFunctions` line removed from `VulkanDevice.cpp`, `agc_driver_mesh_waves` fails: `the device target does not ask for inlined mesh helper functions on Vulkan driver 4; NVIDIA's proprietary driver needs them unless APS5_NO_MESH_INLINE_FUNCTIONS is set, and other drivers keep the calls`. - The whole AGC and shader suite, `ctest --test-dir build -R "^agc_|^shader_|recompiler" -j 4 -V` with the same three variables, on the earlier main b11c7bf84f (1378 tests) and on this change applied to it (1379): the same results apart from the new test. 1366 and 1367 pass, 11 skip on both, and `agc_driver_direct_write_completion` fails on both (a storage-image timing test without mesh programs). Both logs have the same 26 `VUID-` lines, from `agc_driver_image_gather_volume`, `agc_driver_prepared_exports` and `agc_driver_srgb8_color_target`, and the same 142 warnings. - Pipeline creation time, RESIDENT EVIL requiem from start to the 3D menu (240 s per run, empty `ANYPS5_SHADER_CACHE_DIR`, and a local timing build, not part of this PR, that also gave every run's SPIR-V its own generator word so the driver's cache could not serve it): the 8 mesh pipelines took 11.5 and 12.4 s to create with this change and 6.5 and 6.8 s with `APS5_NO_MESH_INLINE_FUNCTIONS=1`, about 1.7 times as long; the slowest one took 2.2 to 2.7 s against 1.75 s. The other 138 pipelines took 51.6 to 58.5 s in every run. A third run with the change reusing the first run's SPIR-V took 10.5 s, so the driver's cache did not hide the cost. The runs with the change showed no shards; the two without it showed them. - The branch is on current main 1ff0fe98aa. Rebasing put `meshInlineFunctions` after #11351's f16 NaN flags in `CacheKey.hpp`, `Recompiler.cpp`, `Recompiler.hpp` and `SpirvEmitter.hpp`; nothing else in the diff changed. - `tools/check_conventions.py` passes against 1ff0fe98aa with this title and description. Before opening, `tools/pr_overlap.py --branch fix/mesh-inline-functions-nvidia` against 15454571d9 over the 1880 open pull requests finds line conflicts only where another pull request adds its own line at the same place: #6751 and #7392 (BDA fault flags in `SpirvEmitter.cpp`), #11351 and #15719 (f16 NaN target flags in `CacheKey.hpp`, `Recompiler.cpp` and `Recompiler.hpp`) and #15668 (the debt entry above this one); none shares exports. It could not compare 89 pull requests that conflict with main. A search of their diffs finds no other inlining change; four of them (#7642, #10193, #13928, #13929) add a `DontInline` image-table helper in `SpirvImageEmitter.cpp`, which this change makes `Inline` in a mesh module on NVIDIA like every other helper. - Limitation: `agc_driver_mesh_waves` checks that the device target asks for the inlining exactly on NVIDIA's proprietary driver, that a mesh program there keeps no helper function without `Inline`, and that each wave's scalar buffer load through a descriptor read from memory returns its own value. That draw also passes with the calls kept, so the wrong data is reproduced only by the title's draw. Other NVIDIA GPUs and drivers are not tested, in particular the drivers listed in #3291 and #4975, and only the title's 3D main menu was played. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [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: <!-- #PR, or none --> none - [x] Fixes: <!-- issue it closes as Fixes #N, or none --> none - [x] Unblocks: <!-- title ID and Game bring-up discussion, e.g. PPSA01325 #3232, or none --> PPSA30803 #11599 (RESIDENT EVIL requiem, 3D main menu; the discussion is filed under the game's other title ID) - [x] GPUs tested: <!-- for AGC, shader recompiler or VideoOut changes: vendor, model, driver and OS of each GPU the GPU tests ran on; otherwise n/a --> NVIDIA GeForce RTX 5060 Laptop GPU, driver 617.42, Windows 11 - [x] AI-assisted: <!-- yes / no --> yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
gabichuuuuu commented 2026-11-07 07:27:29 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by gabichuuuuu on 2026-11-07T07:27:29Z.

Review: COMMENTED


A Turing data point, and a note on replay.

  • System: Windows 11 x64, NVIDIA laptop GPU (Turing), driver 610, WinLibs GCC 15.2.0 r7 UCRT, Release, every AGC execution test built (ANYPS5_AGC_EXECUTION_TESTS empty). I merged head 378bf884 onto main c1e920e7 (clean merge). No validation layer installed.
  • Mesh tests: ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 ctest -R "mesh|shader_disk_cache" passes 15 of 15. agc_driver_mesh_waves selects the NVIDIA GPU (subgroup=32) and prints mesh wave tests passed, so on this driver the target asks for inlining and every helper of the scalar-load program has the Inline control.
  • Full AGC suite: not conclusive on this machine. With the PR, 39 of 1397 failed, nearly all timeouts. When I reran only those 39, 26 still failed. 24 of the 26 also fail on main c1e920e7 in the same session. The other two, agc_driver_image_memory_dedicated_images_failure_skip and agc_worker_sampler_process, pass on main in 11 s and 13 s, and time out with the PR at their 30 s and 20 s limits. Neither test's source mentions mesh, and the change only alters output for mesh programs, so I read those two as load on this machine rather than this change.
  • Replay: RequestSerializer::writeSpirvTarget does not store the driver-dependent target flags. shader_replay sets them again from options (--lds-lock-fences, --f16-widen-nans, --f16-narrow-nans, …), but has no option for meshInlineFunctions, so a mesh request captured on NVIDIA replays with the helper calls kept. That is the shape this PR moves away from. meshWindowBuffer has the same gap. An option such as --mesh-inline-functions would let the PPSA30803 program be replayed in the form the driver now receives.

AI-assisted: yes.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5810773084 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/15917#pullrequestreview-5810773084). Originally posted by [gabichuuuuu](https://github.com/gabichuuuuu) on 2026-11-07T07:27:29Z. **Review:** COMMENTED --- A Turing data point, and a note on replay. - **System:** Windows 11 x64, NVIDIA laptop GPU (Turing), driver 610, WinLibs GCC 15.2.0 r7 UCRT, Release, every AGC execution test built (`ANYPS5_AGC_EXECUTION_TESTS` empty). I merged head `378bf884` onto `main` `c1e920e7` (clean merge). No validation layer installed. - **Mesh tests:** `ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 ctest -R "mesh|shader_disk_cache"` passes 15 of 15. `agc_driver_mesh_waves` selects the NVIDIA GPU (`subgroup=32`) and prints `mesh wave tests passed`, so on this driver the target asks for inlining and every helper of the scalar-load program has the `Inline` control. - **Full AGC suite:** not conclusive on this machine. With the PR, 39 of 1397 failed, nearly all timeouts. When I reran only those 39, 26 still failed. 24 of the 26 also fail on `main` `c1e920e7` in the same session. The other two, `agc_driver_image_memory_dedicated_images_failure_skip` and `agc_worker_sampler_process`, pass on `main` in 11 s and 13 s, and time out with the PR at their 30 s and 20 s limits. Neither test's source mentions mesh, and the change only alters output for mesh programs, so I read those two as load on this machine rather than this change. - **Replay:** `RequestSerializer::writeSpirvTarget` does not store the driver-dependent target flags. `shader_replay` sets them again from options (`--lds-lock-fences`, `--f16-widen-nans`, `--f16-narrow-nans`, …), but has no option for `meshInlineFunctions`, so a mesh request captured on NVIDIA replays with the helper calls kept. That is the shape this PR moves away from. `meshWindowBuffer` has the same gap. An option such as `--mesh-inline-functions` would let the PPSA30803 program be replayed in the form the driver now receives. AI-assisted: yes.
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!15917
No description provided.