fix(shader): run DS src2 lanes one at a time in lane order #5498
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/5498"
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 billythemenace2 on 2026-10-13T21:21:19Z.
What
Before:
ds_*_src2_*was translated as an LDS load ofDS[B]followed by an atomic update ofDS[A]. Every active lane loaded itsBbefore any lane updated itsA. When a lane'sBis theAof a lower active lane (a chain such asDS[A] += DS[A - 4]across lanes), the result differed from the hardware.After: each src2 instruction is a single IR operation,
SharedSrc2U32orSharedSrc2U64. It carries the update as a constant and has no data operand. The SPIR-V backend runs the active lanes of each host subgroup one at a time:OpGroupNonUniformElectpicks the lowest pending lane, which readsBand updatesA, and a workgroup memory barrier follows each lane. This is the loop shape of the existing locked 64-bit LDS update. A wave64 program run as two lane halves emits each half in turn, so lanes 0-31 run before 32-63.The updates themselves are unchanged: the same replacement for each 32-bit and 64-bit op, and the same f32/f64 flush, 64-bit alignment and bounds rules as in #5474.
Hardware semantics, measured on RDNA1 (gfx1010, AMD Radeon RX 5700 XT), which has the src2 opcodes. The
tools/hw-oracletemplate was assembled with the Windows driver'samd_comgr_2.dlland launched with its HIP runtime. The kernel of the new test was run unchanged on the RX 5700 XT in wave32 and wave64:ds_add_src2_u32at offset -1 dwordds_add_src2_u64at offset -2 dwordsds_write_src2_b32with the lanes in reverse address orderds_add_src2_u32at offset +1, whereBis the next lane'sAAAll 512 (wave32) and 1024 (wave64) LDS words equal a model where the active lanes run in lane order and each lane sees the writes of lower lanes. The old reads-first model gets 7 of the chain words wrong in each wave size.
measurement-results-ds-src2-lane-order-gfx1010.md
Tested
agc_driver_lds_src2_lane_orderruns the kernel above in wave32 and in wave64. The wave64 variant only swaps the exec save and restore opcodes. It compares every LDS word with the lane-ordered model, which matches the hardware run. It passes, and without the change it fails at the first chain word.agc_driver_lds_src2andagc_driver_lds_src2_widepass on the new path.ctest -R "lds_|shader_memory|decoder|recompil|agc_shader": everything passes exceptagc_driver_lds_mixed_width_atomics, which also fails on unchangedmain(dacd78525) on this machine.python3 tools/check_conventions.py --base origin/mainpasses.Functionstorage and lane order cannot matter. The update uses the sameAtomicUpdatehelper as the existing LDS atomics, which #5160 addresses for that storage class.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)Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-13T21:25:24Z.
The conventions check is failing only because the PR title is not Conventional Commits:
Fix/shader ds src2 lane order. The body already gives a suitable title:fix(shader): run DS src2 lanes one at a time in lane order. Please update the PR title to that (or another validtype(scope): description) to clear the check; the source checks shown here pass.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-13T21:28:37Z.
Review: COMMENTED
state.laneCount == 2maps one guest wave64 to two host 32-lane subgroups (SpirvEmitter.cpp), but this loop elects and ballots withScopeSubgrouponly. The two host subgroups therefore advance independently: subgroup 1 can execute guest lanes 32–63 before subgroup 0 has completed lanes 0–31. The generated instruction order inEmitStructuredBlockdoes not impose execution order between those subgroups. Could you add a split-wave64 regression where a dependency chain crosses lanes 31/32 and make the scheduler serialize both halves (or otherwise demonstrate the required ordering)? The described RX 5700 test runs natively as a single wave64 and does not cover this host-subgroup32 path.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-13T21:30:52Z.
Code review location:
core/shader/recompiler/SpirvBackend/src/SpirvMemory/SpirvMemoryInstructions.cpp; line 1351On the split wave64 path, each half is a distinct host subgroup. This loop’s
OpGroupNonUniformElectand ballot therefore only order lanes within that subgroup; emitted block order does not order the two subgroups at runtime. A dependency from lane 32 to a write by lane 31 can still read the old value. Please add a regression that exercises wave64 on a subgroup32 host and serialize across the halves (or show another mechanism that does so). The RX 5700 native wave64 test does not cover this path.Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-13T21:39:05Z.
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)docs/dev/debt/shader.mdL106-107docs/dev/debt/shader.mdL106Imported from boykopovar/AnyPS5. Originally posted by billythemenace2 on 2026-10-13T21:44:40Z.
Code review location:
core/shader/recompiler/SpirvBackend/src/SpirvMemory/SpirvMemoryInstructions.cpp; line 1351Thanks, good catch that the test did not cover this layout. There are three wave64 layouts, and only one of them splits a wave across host subgroups:
laneCount == 2): each invocation holds lanes n and n + 32, andEmitStructuredBlock(SpirvFlowEmitter.cpp, thefor (half ...)loop) emits every instruction for half 0 and then half 1 in the same invocation. TheSharedSrc2loop for lanes 0-31 therefore finishes in each invocation before the loop for lanes 32-63 starts. The halves are not different subgroups here, so lane 32 reads after lane 31's write.APS5_SINGLE_LANEon a host whose real subgroups are narrower than 64: the wave spans two real subgroups, and ordering holds only within each one. That is the debug layoutWaveLdsScopealready describes, where ballots,readlane, DPP andds_appendare also only subgroup-wide. I documented it in the technical-debt entry instead of adding a cross-subgroup turnstile, which would need every invocation of the wave to reach the instruction.I added a regression for the 32-lane layout (
9ced724de).agc_driver_lds_src2_lane_ordernow also runs the wave64 kernel withtarget.subgroupSize = 32. It checks that the program is laid out for a 32-lane host subgroup and that the pipeline requires 32-lane subgroups. It passes on the RX 5700 XT, which supports both sizes. The chain crosses lanes 31 and 32 and is compared word for word with the lane-ordered result the hardware gives. If you meant a different split path, tell me which and I'll cover it.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-13T21:45:23Z.
Code review location:
core/shader/recompiler/SpirvBackend/src/SpirvMemory/SpirvMemoryInstructions.cpp; line 1351Thanks, this covers the layout I meant. The new 32-lane test exercises the laneCount == 2 mapping where both halves run in one invocation, and the 64-lane host keeps the wave in one subgroup. The APS5_SINGLE_LANE limitation is now clearly scoped as the existing debug-layout limitation. I consider the ordering concern addressed for this PR.
Imported from boykopovar/AnyPS5. Originally posted by simonbbby on 2026-10-13T22:23:46Z.
Found a reproducible SPIR-V validation failure on exact head
9ced724de704410db8114dbb0a64d6cdf3ffc3b4(including the carried #5474 dependency), withANYPS5_ENABLE_SPIRV_TOOLS=ON.Linux Release build, RTX 3090 / NVIDIA 595.99.02 and RDNA2 gfx1036 (
1002:13c0) / RADV Mesa 25.2.8. On the unmodified head, all three tests fail before GPU dispatch:LaneOrderedUpdateemitsOpSelectionMerge, then evaluateswaiting(done)inside the followingAddFunctionargument. That lambda emits the logical-not/and instructions between the merge and branch. Computing the predicate first fixes the validation error:With only that local correction, all three tests pass three consecutive runs on each GPU (18 passes total), with SPIR-V validation still ON, shader caching disabled, GPU execution required, pinned ICDs, serial CTest and unchanged 30-second timeouts. No internal subgroup skips were printed: the lane-order test executed its wave32, wave64 and explicitly required subgroup32 wave64 checks, including the chain across lanes 31/32. Totals: NVIDIA 3.53 s; RADV 1.36 s.
Restoring the original file and rebuilding makes
agc_driver_lds_src2_lane_orderfail with the same validation error again on NVIDIA. The isolated checkout is restored clean. This is focused synthetic compute coverage; I did not run a full suite, pixel-stage src2,APS5_SINGLE_LANE, or a title.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-13T22:26:02Z.
Review: COMMENTED
Thanks for the targeted validation. I agree this is a merge blocker: the exact head fails SPIR-V validation before dispatch, and the one-line predicate-hoist fix passes the affected tests on both reported GPUs. Please push that fix and retain the validation-enabled regression run. The existing CI does not run
ANYPS5_ENABLE_SPIRV_TOOLS=ON, so the passing workflow checks did not catch this.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-13T23:45:03Z.
Thanks for the follow-up validation: the explicit subgroup32 wave64 test and dependency chain across lanes 31/32 address my earlier scheduling concern. The other reported blocker is still outstanding on the published head
9ced724de704410db8114dbb0a64d6cdf3ffc3b4: with SPIR-V validation enabled, the three src2 tests fail before dispatch because instructions are emitted betweenOpSelectionMergeandOpBranchConditional. The local predicate-hoist change passed the reporter's targeted GPU runs, but it is not in this PR head yet. Please push that fix and keep the validation-enabled regression coverage in the branch.AI-assisted: yes; reviewed by MarcZX100.
Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-14T00:24:25Z.
Windows test of #5498: Windows 10 (19045), MinGW-w64 GCC 15.2, Release,
ninja -j 4, ctest called directly, GPU selected by the tests: NVIDIA GeForce RTX 4080 SUPER (the log lineSelected GPU name=NVIDIA GeForce RTX 4080 SUPER; an AMD Radeon RX 6400 is also present and was not selected). Tree:maind1670009f+ merge of PR head9ced724de704410db8114dbb0a64d6cdf3ffc3b4(local mergeb4f6d0a95). Logs:rtx5498_agc_driver_lds_src2*_N.log.Result:
agc_driver_lds_src2,agc_driver_lds_src2_lane_orderandagc_driver_lds_src2_wideall end withException: SegFault(FATAL: unhandled exception 0xc0000005, read of address 0x10 insidenvoglv64.dll+0x12178aa, the NVIDIA driver) in every run: 0 of 9 pass (3 tests x 3 runs). The crash comes right after the Vulkan device is ready.Baseline, same machine and build directory:
agc_driver_lds_src2(a test that already exists onmain) passes onmainfeddf7f4cin 3 of 3 runs (exit code 0), so the crash does not come from the environment alone.lane_orderandwidedo not exist onmain, so there is no baseline for them.Not tested: which shader of the PR triggers the driver crash (not narrowed down), another NVIDIA driver version (driver here: 610.74, Windows 32.0.16.1074), the AMD GPU, Linux, a title run. I do not claim that the PR code is wrong: the fault is inside the driver, the trigger is unknown.
AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-14T00:25:54Z.
Thanks for the controlled Windows baseline and the 0/9 result. That shows the NVIDIA crash is triggered by the PR head on this setup, while the current report does not isolate which generated shader triggers it; I agree it does not yet identify whether the driver or emitted code is at fault. It is also separate from the SPIR-V Tools failure previously reproduced on the exact head (
OpSelectionMergefollowed by emitted predicate instructions), which remains unresolved. I would keep both findings visible and avoid treating passing non-validation CI as covering either case.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-14T00:42:55Z.
@KauaSantos702: since you offered Windows AGC GPU runs in #5503, would you be able to run
agc_driver_lds_src2,agc_driver_lds_src2_lane_order, andagc_driver_lds_src2_wideat this PR head (9ced724de704410db8114dbb0a64d6cdf3ffc3b4) on the RTX 5070, if convenient? The current RTX 4080 report is 0/9 with the crash innvoglv64.dll; a second GPU/driver result would help scope it. Separately, the SPIR-V validator failure already reported on this head remains unresolved, so the GPU run would not clear that blocker.Imported from boykopovar/AnyPS5. Originally posted by KauaSantos702 on 2026-10-14T01:07:30Z.
Ran the three tests at this head (
9ced724de704410db8114dbb0a64d6cdf3ffc3b4) on a second NVIDIA card and driver. It crashes the same way as the RTX 4080: 0/9, an access violation insidenvoglv64.dllin every run.Setup
0x2f04), driver 32.0.16.1714, Vulkan 1.4.351BUILD_TESTING=ONctest -j1agc_driver_lds_src2agc_driver_lds_src2_lane_orderagc_driver_lds_src2_wideAll runs fail at the same point. The device comes up (
Wave32 programs run on subgroups of 32: compute 1, mesh 1,Vulkan device ready) and the first dispatch faults in the driver:gdb shows the fault under
AgcDriver::VulkanDevice::dispatch, 14 frames deep insidenvoglv64.dll. The driver has no symbols, so gdb names those frames after the nearest exports, which tells nothing about the real functions:Scope:
agc_driver_lds_src2already exists onmain. On the same machine atmaind1670009fit passes 3/3 (~0.4 s), and it passed in a full-suite run there too: 1103 tests, 1094 passed, 9 skipped, 0 failed. This PR is based ondacd78525. So on two NVIDIA cards and drivers (Ada and Blackwell), the change makes the driver crash, most likely while compiling the dispatch's pipeline. That would fit the SPIR-V validator failure already reported here, though I did not run the validator myself.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-14T02:25:51Z.
Closing: no title is known to reach this. With the queue at 700+ open PRs, please hold off on new PRs that don't name a title needing the change until it's down. If a title stops on this on current main, reopen with the title ID and the log line.
Pull request closed