fix(shader): inline read_bda_span on NVIDIA in wave64 modules that hold two lanes per invocation #27811
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/27811"
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 snoozedDev on 2026-11-27T13:25:48Z.
What
On NVIDIA's proprietary driver, a wave64 compute program that the recompiler lays out as two guest lanes per invocation (a multi-wave workgroup, or a single wave that cannot take the spanned form) can return wrong values in lanes 32 to 63 with no error. Three instructions after one
global_load_dwordx4show it:In a 512-thread wave64 workgroup on an RTX 3090, every upper-half lane whose carry-in is set gets
v6 + v4 + 1of lane L-32 instead of its own. RDNA2 (gfx1036) and the same module on RADV give the lane's own sum, and wave32 on the same NVIDIA driver is exact. The emitted SPIR-V is valid and computes the low and the high lane of an invocation independently.What decides it is the function control of
read_bda_span(DefineBdaSpanReadFunction,SpirvBdaRead.cpp), which such a module calls once for the low and once for the high lane. With that one functionInlinethe module is exact; with itDontInlinethe module is wrong (the two arms of the tables below). Hand-edited copies of the module onmain80781a0e94showed the rest: no control on that function is exact as well, each of the other twelve helper functions set toInlinealone leaves it wrong, and all of themInlinewithread_bda_spanalone keptDontInlineleaves it wrong.Change: a target option
twoLaneSpanReadInline, set forVK_DRIVER_ID_NVIDIA_PROPRIETARYbesidemeshInlineFunctionsand part of the shader cache key through the target. When it is set and the module holds two lanes per invocation (state.laneCount == 2u), the fourread_bda_spanvariants getInlinein place ofDontInline.load_bda_spankeepsDontInlinewith its four loads, so the loads stay out of the caller's arm (the shape of #3291 and #4975). Other drivers, spanned and one-lane modules, and every other helper emit whatmainemits.APS5_NO_TWO_LANE_SPAN_READ_INLINE=1keeps the call.Inlineagainst no control: both were exact on the hand-edited module, and one of Astro Bot's affected pipelines takes the same time to create either way (median of three 4.6 s withInline, 4.6 s with the control cleared in the capture, 3.2 to 3.6 s for the twoDontInlinepipelines of that size), so the driver inlines in both cases.Inlinestates the request, as #15917 does for mesh modules.Test: new
Wave64SpanReadLanes.cpp(agc_driver_wave64_span_read_lanes). It recompiles the kernel for 32-lane and 64-lane subgroups with the option off and on and checks the controls ofread_bda_spanandload_bda_spanin each module, on any device. It then runs two 512-thread wave64 dispatches and compares every lane with values computed on the CPU: the kernel above, and the same kernel with odd lanes reading from an address that is not dword-aligned, so one dispatch takes both arms ofread_bda_span. It also checks that the device target asks for the option on NVIDIA's proprietary driver only.ShaderDiskCache.cppgets the cache key case.Not covered: the fault is measured on one GPU and one driver version, and its cause inside the driver is not known. The other
DontInlinehelpers are not shown to fail and are left alone. The debt entry "Mesh helper functions on NVIDIA" (#15917) describes wrong data in other subgroups of mesh modules that keep helper calls; whether that is the same fault was not checked.Cost: Astro Bot (PPSA21564) creates eight compute pipelines in this form in a 200 s run, of four module sizes from 266,282 to 324,782 SPIR-V words. Captured with
APS5_DUMP_COMPUTE_PIPELINESonmainand on this branch and replayed withagc_compute_pipeline_replay(__GL_SHADER_DISK_CACHE=0, fresh application cache, median of three),pipeline_createfor the eight sums to 32.6 s onmainand 43.7 s on this branch, 1.34 times. Per pipeline: 3.2 to 4.8 s onmain, 4.6 to 6.3 s on this branch. The debt fragment records the workaround and this figure.Tested
Linux 7.2.8 (Arch-based), GCC 16.2.1, Release. NVIDIA GeForce RTX 3090, driver 615.78.08; AMD Ryzen 7 7700X iGPU (gfx1036), RADV Mesa 26.2.5; lavapipe Mesa 26.2.5 (subgroup size 8). Hardware side of the comparisons: the same iGPU through
tools/hw-oracle(hsa-rocr7.2.4). Measurements were made onmain028e6ad9f2and on this change on top of it; the branch was then rebased ontob7d960b95bwithout conflicts, and the runs marked "rebased" were repeated there.The three instructions above through
tools/hw-oracle, 1,024 rows, wave64, hardware againstagc_oracle_runner:mainAPS5_NO_TWO_LANE_SPAN_READ_INLINE=1Random integer programs (3 to 7 of compare,
v_cndmask_b32,v_add_co_u32,v_add_co_ci_u32and plain integer instructions, 1,024 rows each, the same seeds on both arms), programs with any row that differs from hardware, on the RTX 3090:mainagc_driver_wave64_span_read_lanes:main(the test without its option check)rows at aligned addresses: 127 of 512 lanes are wrong, 127 of them in lanes 32 to 63, of which 127 hold the sum of lane L-32 plus oneAPS5_NO_TWO_LANE_SPAN_READ_INLINE=1On
mainthe test stops at the aligned rows, so the mixed dispatch was not observed there.ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 APS5_SKIP_TIMING_TESTS=1 ctest -R '^agc_' --timeout 180:-j 6-j 4main(2,186 tests)No test timed out on either arm. RADV failures on
main:agc_driver_depth_bits_guest_memory,agc_driver_gcn_detile,agc_driver_host_import_windows,agc_driver_tessellation(SIGSEGV inside the driver). On this branch:agc_driver_gcn_detile,agc_driver_host_import_windows,agc_driver_pixel_float16_store,agc_driver_tessellation. The two that differ are intermittent on both arms on this iGPU: run alone ten times each,agc_driver_pixel_float16_storepasses 1 of 10 onmainand 3 of 10 on this branch,agc_driver_depth_bits_guest_memory7 of 10 and 3 of 10. The option is off on RADV, so both arms emit the same modules there. This iGPU has a workgroup shared-memory fault (#26038).Validation layer 1.4.363 (
VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation,VK_LOADER_DEBUG=layer),ctest -V -R '^agc_driver_(wave64_span_read_lanes|bda_span_reads|bda_device|bda_anchor_reads|global_loads|flat_loads|runtime_buffer_spans|global_load_addtid)'on this branch: 23 of 23 passed on the RTX 3090 and on RADV. Each log showsInsert instance layer "VK_LAYER_KHRONOS_validation"22 times (one of the 23 opens no device), none showswas not found but was requested, and none has aVUID-.Astro Bot (PPSA21564) through
tools/title_run.py, 240 s,main028e6ad9f2and the change on it, RTX 3090, headless gamescope, ordermain, branch,main, branch:mainThe 11 % fewer presents of a first run are the longer pipeline creation given under Cost; later runs and the steady frame rate are unchanged.
python3 tools/check_conventions.py --base origin/mainpasses.tools/pr_overlap.py --branch HEADreports conflicts with #25660 and #26716, which add their own target option on the lines afterspannedShuffleThroughMemory, and failed closed on 130 open PRs that conflict withmain. The nine open PRs that touchSpirvBdaRead.cpp(#7392, #9790, #9969, #14260, #15555, #16571, #18106, #18107, #22944) change no function control, and #27718 edits onlyBdaContracts.cpp.Rebased onto
b7d960b95b:agc_driver_wave64_span_read_lanespasses 5 of 5 on the RTX 3090 and on RADV and passes on lavapipe, the three-instruction comparison is 0 of 1,024 on the RTX 3090, andctest -R '^agc_' -j 6on the RTX 3090 passes 2,191 of 2,191 with 28 skipped in 309 s.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
Summary by CodeRabbit
APS5_NO_TWO_LANE_SPAN_READ_INLINEto retain non-inline span reads. Shader cache entries reflect this setting.--two-lane-span-read-inlineto enable inline two-lane span reads for a replay.Imported from boykopovar/AnyPS5. Originally posted by coderabbitai[bot] on 2026-11-27T13:34:44Z.
Review: COMMENTED
Actionable comments posted: 2
cad6f567-d3b3-4bff-ac29-4d52d213d8c8Reviewing files that changed from the base of the PR and between
15a9e02acband83ea403a99.core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/tests/ShaderDiskCache.cppcore/libs/prx/libSceAgcDriver/tests/execution/Wave64SpanReadLanes.cppcore/shader/recompiler/CacheKey.hppcore/shader/recompiler/Recompiler.cppcore/shader/recompiler/Recompiler.hppcore/shader/recompiler/SpirvBackend/include/SpirvBackend/SpirvEmitter.hppcore/shader/recompiler/SpirvBackend/include/SpirvBackend/SpirvEmitterState.hppcore/shader/recompiler/SpirvBackend/src/SpirvBdaRead.cppcore/shader/recompiler/SpirvBackend/src/SpirvEmitter.cppdocs/dev/ENVIRONMENT.mddocs/dev/debt/changes/nvidia-two-lane-span-read-inline.mdIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-27T13:37:57Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this change; the points below are optional.
What I ran
Reviewed head
83ea403a99e6f36c62f3514bdee6ed850723d96band its prepared diff; no commands or tests were run. The author reports extensive testing in the PR description; those results were not independently reproduced here. The target-building change inVulkanDevice.cppwas read through the pinned repository reader because the full file was excluded from the review folder. Other changed files were read at their changed lines. The review folder’sfiles.jsonwas not available; the manifest and README identify 11 changed files as included andVulkanDevice.cppas excluded for size.Results
Findings
Blocking
None.
Non-blocking
core/libs/prx/libSceAgcDriver/tests/execution/Wave64SpanReadLanes.cpp:129—Controlswalks SPIR-V instructions without checking that each instruction’s word count stays within the module, and constructs astring_viewfrom theOpNameoperand without bounding it to that instruction. The generated modules are trusted here, so this is not blocking, but adding bounds checks would make this test parser safer against malformed output.Not verified
VulkanDevice.cppwere not read; only its changed target-setting line was inspected.ShaderDiskCache.cpp,Wave64SpanReadLanes.cpp,CacheKey.hpp,Recompiler.cpp,Recompiler.hpp,SpirvEmitter.hpp,SpirvEmitterState.hpp,SpirvBdaRead.cpp,SpirvEmitter.cpp,ENVIRONMENT.md, andnvidia-two-lane-span-read-inline.md. Excluded from the review folder:VulkanDevice.cpp, inspected only at the changed line through the repository reader.To get this to a good state
Nothing is required. Consider bounding the SPIR-V instruction and name parsing in the test.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-27T14:03:52Z.
Review: COMMENTED
Reviewed — no blocking findings
Nothing blocks this change; the points below are optional.
What I ran
Reviewed head
a020d560c409c71cc5a84c125d1b39fdb15ef558from the prepared diff and source reader. I did not run commands or tests.Results
Findings
Blocking
None in the changed lines reviewed.
Non-blocking
OpNameIDs before matching laterOpFunctiondeclarations. This relies on debug names preceding functions in the emitted module; the parser otherwise silently fails to recognize named helpers. Consider asserting that the parser consumed the complete module and found the expected helper names. Seecore/libs/prx/libSceAgcDriver/tests/execution/Wave64SpanReadLanes.cpp:129.Not verified
core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppwas excluded from the review folder as too large; its changed line was read through the pinned-head reader, but the rest of that file was not reviewed.To get this to a good state
Nothing is required. The parser assertion is optional.
Sources
Changed lines were reviewed from the prepared diff and pinned-head reader at
a020d560c409c71cc5a84c125d1b39fdb15ef558. Files read:core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp,core/libs/prx/libSceAgcDriver/tests/ShaderDiskCache.cpp,core/libs/prx/libSceAgcDriver/tests/execution/Wave64SpanReadLanes.cpp,core/libs/prx/libSceAgcDriver/tools/ShaderReplay.cpp,core/shader/recompiler/CacheKey.hpp,core/shader/recompiler/Recompiler.cpp,core/shader/recompiler/Recompiler.hpp,core/shader/recompiler/SpirvBackend/include/SpirvBackend/SpirvEmitter.hpp,core/shader/recompiler/SpirvBackend/include/SpirvBackend/SpirvEmitterState.hpp,core/shader/recompiler/SpirvBackend/src/SpirvBdaRead.cpp,core/shader/recompiler/SpirvBackend/src/SpirvEmitter.cpp,docs/dev/ENVIRONMENT.md, anddocs/dev/debt/changes/nvidia-two-lane-span-read-inline.md. TheVulkanDevice.cppfile was excluded from the review bundle but its changed line was read through the reader.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-28T11:52:22Z.
Review: COMMENTED
Reviewed — no blocking findings
The inspected code has no verified blocking defect, but the full device-target setup was not verified because
VulkanDevice.cppwas excluded from the review bundle.What I ran
Reviewed head
d94bbec6843013e9bc0b50c65922174464aadcfausing the prepared diff andrepo_read.pyat the pinned head. No commands or tests were run; test results in the PR description are author-reported.Results
Findings
Blocking
None verified in the inspected code.
Non-blocking
None.
Not verified
core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppwas excluded as too large, so its full contents and the device target configuration were not verified. Hardware behavior and the author-reported test runs were not independently confirmed.Files read:
core/libs/prx/libSceAgcDriver/tests/ShaderDiskCache.cpp,core/libs/prx/libSceAgcDriver/tests/execution/Wave64SpanReadLanes.cpp,core/libs/prx/libSceAgcDriver/tools/ShaderReplay.cpp,core/shader/recompiler/CacheKey.hpp,core/shader/recompiler/Recompiler.cpp,core/shader/recompiler/Recompiler.hpp,core/shader/recompiler/SpirvBackend/include/SpirvBackend/SpirvEmitter.hpp,core/shader/recompiler/SpirvBackend/include/SpirvBackend/SpirvEmitterState.hpp,core/shader/recompiler/SpirvBackend/src/SpirvBdaRead.cpp,core/shader/recompiler/SpirvBackend/src/SpirvEmitter.cpp,docs/dev/ENVIRONMENT.md, anddocs/dev/debt/changes/nvidia-two-lane-span-read-inline.md.To get this to a good state
Nothing is required by the inspected code; the device-target setup remains unverified.
Imported from boykopovar/AnyPS5. Originally posted by Plyxen on 2026-12-03T12:37:51Z.
Review: APPROVED
I read the diff at
d94bbec684. Windows 11, GCC 15.2, merged intomainatdaa61711afetogether with other open PRs (so not an isolated build), withANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1andVK_LAYER_KHRONOS_validationon an RTX 5080 (621.24) and a Radeon iGPU (26.11.2).agc_driver_wave64_span_read_lanesandagc_shader_disk_cache: pass on both GPUs. The loader log shows the layer inserted and no "was not found" line, and neither run has aVUID-orSYNC-HAZARDline.APS5_NO_TWO_LANE_SPAN_READ_INLINE=1fails on the RTX 5080 in 2 of 2 runs: "127 of 512 lanes are wrong, 127 of them in lanes 32 to 63, of which 127 hold the sum of lane L-32 plus one". With the change it passes in 2 of 2. So the driver bug is still there on 621.24 and Blackwell.The open bot thread (captured requests do not store the flag) is answered in the conversation and only affects replays.
Not checked: a title.
AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T20:55:18Z.
Review: COMMENTED
A new NVIDIA shader capture can still replay with the wrong instruction form by default.
RequestSerializersaves the target subgroup and wave settings but omitstwoLaneSpanReadInline. Deserializing resets it to false, andShaderReplayrestores it only if the caller knows to pass--two-lane-span-read-inline. Could the request format preserve the captured setting and default older captures to false? A round-trip test can check both flag values.Source review at
d94bbec684. The head trial-merges onto6ef4f2f73b. Focused Linux checks are queued.AI-assisted: yes.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.