fix(shader): inline mesh helper functions on NVIDIA #15917
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/15917"
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 SeifKaroui on 2026-11-04T23:45:39Z.
What
On NVIDIA's proprietary driver a mesh program whose helper functions stay real calls (the
DontInlineBDA readersread_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_dwordof 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 forVK_DRIVER_ID_NVIDIA_PROPRIETARY, part of the shader cache key,APS5_NO_MESH_INLINE_FUNCTIONS=1turns it off) makesSpirvModule::InlineFunctionsgive every non-entry function of a mesh module theInlinecontrol in place ofDontInline, and the driver inlines them. Keeping onlyload_bda_spanas 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()letsagc_driver_mesh_wavescheck 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.
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 withAPS5_NO_MESH_INLINE_FUNCTIONS=1and the clean image without it, on both.ctest --test-dir build -R "mesh|^agc_shader_disk_cache$" -Von main1ff0fe98aaand on this branch, withANYPS5_REQUIRE_VULKAN=1,ANYPS5_NO_SHADER_CACHE=1andVK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation(nightly validation layer): all pass (10 on main, 11 here with the newagc_driver_mesh_waves). Neither log containswas not found but was requested by env var VK_INSTANCE_LAYERS; neither has aVUID-error; both have the same 20 validation warnings (same IDs and counts). The same comparison on the earlier mainsb11c7bf84fand15454571d9gave the same result. With themeshInlineFunctionsline removed fromVulkanDevice.cpp,agc_driver_mesh_wavesfails: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.ctest --test-dir build -R "^agc_|^shader_|recompiler" -j 4 -Vwith the same three variables, on the earlier mainb11c7bf84f(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, andagc_driver_direct_write_completionfails on both (a storage-image timing test without mesh programs). Both logs have the same 26VUID-lines, fromagc_driver_image_gather_volume,agc_driver_prepared_exportsandagc_driver_srgb8_color_target, and the same 142 warnings.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 withAPS5_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.1ff0fe98aa. Rebasing putmeshInlineFunctionsafter #11351's f16 NaN flags inCacheKey.hpp,Recompiler.cpp,Recompiler.hppandSpirvEmitter.hpp; nothing else in the diff changed.tools/check_conventions.pypasses against1ff0fe98aawith this title and description. Before opening,tools/pr_overlap.py --branch fix/mesh-inline-functions-nvidiaagainst15454571d9over 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 inSpirvEmitter.cpp), #11351 and #15719 (f16 NaN target flags inCacheKey.hpp,Recompiler.cppandRecompiler.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 aDontInlineimage-table helper inSpirvImageEmitter.cpp, which this change makesInlinein a mesh module on NVIDIA like every other helper.agc_driver_mesh_waveschecks that the device target asks for the inlining exactly on NVIDIA's proprietary driver, that a mesh program there keeps no helper function withoutInline, 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
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 gabichuuuuu on 2026-11-07T07:27:29Z.
Review: COMMENTED
A Turing data point, and a note on replay.
ANYPS5_AGC_EXECUTION_TESTSempty). I merged head378bf884ontomainc1e920e7(clean merge). No validation layer installed.ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 ctest -R "mesh|shader_disk_cache"passes 15 of 15.agc_driver_mesh_wavesselects the NVIDIA GPU (subgroup=32) and printsmesh wave tests passed, so on this driver the target asks for inlining and every helper of the scalar-load program has theInlinecontrol.mainc1e920e7in the same session. The other two,agc_driver_image_memory_dedicated_images_failure_skipandagc_worker_sampler_process, pass onmainin 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.RequestSerializer::writeSpirvTargetdoes not store the driver-dependent target flags.shader_replaysets them again from options (--lds-lock-fences,--f16-widen-nans,--f16-narrow-nans, …), but has no option formeshInlineFunctions, so a mesh request captured on NVIDIA replays with the helper calls kept. That is the shape this PR moves away from.meshWindowBufferhas the same gap. An option such as--mesh-inline-functionswould let the PPSA30803 program be replayed in the form the driver now receives.AI-assisted: yes.