Recompiler: pixel shader loops end on primitive edges (helper lanes) #2305
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
goal:world-load
good first issue
help wanted
invalid
keep-open
off-goal
question
stale
test-only
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/xcl-dev--xcl!2305
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/2305/head"
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?
@madaraXor on GitHub · 2026-11-25 13:21 UTC · original
madaraXor:recomp-readfirstlane-live-lane→main· +220 −2 · 2 files · 2 commits · merged 2026-11-25 15:18 UTCIn a pixel shader EXEC holds helper lanes (
s_wqm). On AMD's Windows driver (RX 6700 XT, RDNA2) a helper lane's registers stop being kept inside loops: once a wave op ran in a loop, or from a loop's second pass when the shader has another loop before it, everything a helper lane holds reads as 0. Two shapes of console loop then never end, and run every lane to the loop budget:v_readfirstlane(v_mov v, s…v_readfirstlane s, v) when the first lane of EXEC is a helper lane: it reads 0 back each time round;s_andn2 mask, mask, vcc; s_cbranch_scc1): a helper lane's "done" condition comes from registers that no longer change, so its bit stays in the mask.A retail title's spot-light volumetric pass has both. On this card it was the draw running when the GPU was reset at the title's world start (#675, comment 7158635084): 72 vertices × ~6 000 instances, running for seconds. Part of #675.
What is in it
Recompiler: v_readfirstlane in a pixel shader reads a live lane first(gpu/recomp/emit.rs):first_lane_livereads the first lane of EXEC that is live (ballot(true), per half in the wave32-in-64 form) when EXEC has one, else the first lane of EXEC as before. The value is the same: the console's compiler reads the first lane of a value equal in every lane, or of a lane it then removes from EXEC. Testgpu_ps_readfirstlane_loop_on_a_primitive_edge_ends(gpu/recomp/tests.rs).Recompiler: a lane-mask test in a pixel shader counts live lanes only(gpu/recomp/emit.rs): in a pixel shader the SCC ofs_and_b32/s_andn2_b32with EXEC or VCC as an operand or destination counts the live lanes only (mask_live); the helper lanes leave the loop with the live ones (they only feed derivatives of live lanes, which have left too). Testgpu_ps_mask_loop_on_a_primitive_edge_ends.Both tests draw the loop shape on two triangles sharing a diagonal, so that waves on it start with helper lanes, and check every pixel's pass count.
Tested
AMD Radeon RX 6700 XT 12 GB (RDNA2, driver 32.0.21045), Ryzen 5 5600X, 16 GB RAM, Windows 10 22H2 (19045), rustc 1.90.0; debug tests, release smoke. On
8fcc111(these two commits onmain06c9f55).The new tests, alone, on this card:
emit.rsgpu_ps_readfirstlane_loop_on_a_primitive_edge_endsgpu_ps_mask_loop_on_a_primitive_edge_ends(For the second, "without" was run with its HLSL-text assertion on
mask_liveremoved, so the GPU result shows.)The title's volumetric draw, replayed alone from a capture of it on this card (a local capture/replay tool, not part of this PR): before, the device was removed after 4 852 ms; with the loop budget lowered to 1024, 782 passes per lane on average. With both commits and the full budget: 7.20 passes per lane, 13 at most, 13.8 ms of GPU time.
The title itself (a local tree with other open PRs,
XCL_DIRECT_DXIL=1 XCL_HEAP_WINDOWS=1): with both changes the world drew for about 25 s, up to 30 presents, 7 900 draws and 47 000 dispatches per 2 s, and the volumetric draw never showed among the slow ops; before, the GPU was reset in that draw within seconds of the world start in every run. The run then ended in another GPU reset that the profiler did not name; that is not this PR.cargo test --workspace --no-fail-fast -- --test-threads=4: 1263 passed, 4 failed, 46 ignored. The 4:gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1(seed 540),hle::kernelx::tests::xmem_virtual_query_marks_cpu_readable_memory(#650), and the e2e teststest_title_runs_and_game_folder_is_untouched,test_title_draws_with_a_root_signature_under_the_debug_layer; they fail onmainon this machine too. SKIPPED: the six per-lane cases off16_programs_on_the_gpu/f32_programs_on_the_gpu(refused),heap_window_out_of_memory_falls_back_to_the_switch_form(no heap windows).Regression run
scripts/smoke.ps1, 60 s, release builds, run back to back.main:
PR:
Not tested
execz/vcczbranches and the direct DXIL graphics path are unchanged.AI use
🤖 Generated with Claude Code
@SlopTart on GitHub · 2026-11-25 13:54 UTC · original
Third AMD data point, Linux/RADV (RDNA3) over Wine: the new test fails deterministically, 39 of 1024 pixels wrong.
Tested:
origin/main379725ae+ PR head6ec402b1(mergec76cb974, no conflicts). Linux (Arch, kernel 7.2.15), Mesa 26.2.5 RADV, Radeon RX 7900 XT (NAVI31), cargo targetx86_64-pc-windows-gnurun under wine-11.0 (Proton), rustc 1.94.0, official MS DXC (binaries 2026-09-29).gpu_suite (--release --locked,--test-threads=2): 142 passed / 4 failed / 1 ignored. The 3 other failures are this rig's known baseline (fuzz seed 1003 of #2115,gpu_nonfused_mad_and_mac_prevent_fma_contraction,gpu_depth_buffer_created_for_unordered_access_is_placed), so the PR's only net change on this rig is its own new test.gpu_ps_readfirstlane_loop_on_a_primitive_edge_endssolo,--exact --test-threads=1: red 3 of 3.39 of 1024 pixels wrong; most iterations 21 (the bit loop should need at most 16); first bad pixels e.g. x=4,y=6 with iterations 21, wave OR 1057746300, own word 16400;WaveGetLaneCount()reads 64 for every pixel (adapter:AMD Radeon RX 7900 XT (RADV NAVI31)).This lines up with DarkPanda69's shape: the loop now ends, but pixels are still wrong, and the hardware wave runs 64 lanes even though the recompiler emits the wave32-in-64 form. On RDNA3 with Mesa 26.2.5 the damage is larger (39 wrong pixels, some past the 16 iteration bound) than their RDNA4 observation (5).
Not tested: Windows on this card; RDNA2.
AI use: Hermes agent (local Qwen-class) ran both machines and drafted this; I checked it before posting.
@ivall on GitHub · 2026-11-25 14:36 UTC · original
On AMD RDNA4, Windows, DXC 1.8.2502.11 the pass still hung the GPU with this PR in my run, and a loop budget of 1024 for that one shader went past it. Same title and shader as in your description. (Edited: the first version of this comment said two runs and "nothing else changed"; both were wrong.)
lane counts {64}; most iterations 16; 5 of 1024 pixels wrong, the same five pixels as DarkPanda69's report (it fails, so I am not merging the PR as it is).DrawIndexedInstancedas two runs without this PR: the spot light volume's draw (the pixel shader of your description). A run with this PR and without #1798 did not reach the draw (the title waited on compiles) and says nothing.static uint xcl_budget = 1024uinstead of1u << 16. The card passed the draw and drew frames of the world for ~100 s; that run ended in 0x887a0007 with no list left unfinished. The last two of those runs also left out big compute programs that were not built (XCL_PSO_IMAGE_SKIP=1, and programs over a size cap refused), so I cannot say the budget alone did it; the first, with only the budget, had not reached the draw when I stopped it.[WaveOpsIncludeHelperLanes]withps_6_7and entry EXEC, live-lane reads from!IsHelperLane()gave the same five wrong pixels in your test, so that attribute does not fix it here.My reading, not tested: the whole-wave OR reductions (
s_or_saveexec -1,v_cndmask, dpp8 x3, dpp row_mirror, permlanex16, readlane 0) lose live lanes' words on a partly covered 64-lane wave, so the loop range is wrong. A recogniser that lowers them to a wave op over the half's live lanes is what I would try.AI use: Claude Code (Claude Opus 5.5) ran this and wrote the comment on the maintainer's behalf.
@madaraXor on GitHub · 2026-11-25 15:00 UTC · original
Thanks for the runs. Updated to
8fcc111(rebased onmain06c9f55), with a second commit for what was left in 64-lane waves:Recompiler: a lane-mask test in a pixel shader counts live lanes only. In a pixel shader, the SCC ofs_and_b32/s_andn2_b32with EXEC or VCC now counts only the live lanes. On this RX 6700 XT, the helper lanes' registers also read as 0 from a loop's second pass on, so a loop that runs while a lane is left in a mask taken from EXEC never ended. New test:gpu_ps_mask_loop_on_a_primitive_edge_ends. Here the driver runs it in 64-lane waves: 256 of 1024 pixels run to the budget without the change, and none with it.@DarkPanda69, @SlopTart: could you rerun both
gpu_ps_*_on_a_primitive_edge_endstests at the new head on RDNA4 and RADV? I can't reproduce the 5 / 39 wrong pixels here, because this driver runs the readfirstlane test in 32-lane waves.AI use: Claude Code (Claude Opus 5.5) wrote this comment.
@SlopTart on GitHub · 2026-11-25 15:12 UTC · original
@madaraXor rerun at the new head on the Wine/RDNA3 lane, as asked.
Head:
8fcc1113(both commits) merged onto currentorigin/main, clean merge.Env: Linux (Arch, kernel 7.2.15), Mesa 26.2.5 RADV, Radeon RX 7900 XT (NAVI31),
x86_64-pc-windows-gnuunder wine-11.0 (Proton), rustc 1.94.0, vkd3d-proton 3.1 with the XCL patch, official MS DXC.gpu_ps_mask_loop_on_a_primitive_edge_ends: passes on this lane (in thegpu_suite, no failure recorded).gpu_ps_readfirstlane_loop_on_a_primitive_edge_ends: still fails, 3/3 solo runs, same assertion (crates/xcl/src/gpu/recomp/tests.rs:9432). Shape changed though:lane counts {64}, most iterations now 32 (the loop ends; it is no longer running to the budget), still 39 of 1024 pixels wrong, first entries changed values, e.g.(4, 6, [13.0, 4278239200.0, 16400.0, 64.0]),(12, 14, [25.0, 4290692000.0, 16400.0, 64.0])(iterations, wave OR, own word, lane count).gpu_nonfused_mad_and_mac_prevent_fma_contraction,gpu_depth_buffer_created_for_unordered_access_is_placed) + the known wave32-prefix flake (solo 2/2 green on the sibling branch today) + this test.So the live-lane mask commit fixed the mask-loop case for this driver (64-lane waves, RADV, Wine) but the readfirstlane case still lands 39 wrong pixels here, now with different per-pixel values than at the first head. Consistent with the NVIDIA lane (wave32) never seeing it: this remains a wave64 readfirstlane-selection issue on AMD.
AI use: Hermes agent (local Qwen-class) ran the rig and drafted this; I checked it before posting.
@DarkPanda69 on GitHub · 2026-11-25 13:40 UTC · original · edited 2026-11-25 15:13 UTC
Update for head
8fcc111(rerun as asked by @madaraXor): the new mask test passes on RDNA4, the readfirstlane test still has the same 5 wrong pixels.Head
8fcc111as is (onmain06c9f55), debug,cargo test -p xcl --lib -- _on_a_primitive_edge_ends --test-threads=1 --nocapture, RX 9070 XT 3 runs, RTX 3060 1 run:gpu_ps_mask_loop_on_a_primitive_edge_ends(new)gpu_ps_readfirstlane_loop_on_a_primitive_edge_ends6ec402b(listed below)So the second commit doesn't change the readfirstlane case on 64-lane waves. Whole
gpu::filter at this head: RX 9070 XT 639 passed, 3 failed (the readfirstlane test plus the #2115 fuzz seeds); RTX 3060 642 passed, 0 failed.With 64-lane pixel waves the new test still fails: the loop now ends, but 5 pixels are wrong. On an RX 9070 XT (RDNA4) the driver runs this test's pixel shader in 64-lane waves (
lane counts {64}), where your RX 6700 XT ran it in 32-lane waves.Tested: head
6ec402bapplied onmainafc5ee8, debug, Windows 11 Pro 26200,cargo test -p xcl --lib -- gpu_ps_readfirstlane_loop_on_a_primitive_edge_ends --test-threads=1 --nocapture:emit.rschangeThe 5 pixels with this PR (iterations, wave OR, own word, lane count):
So the change ends the runaway loop on 64-lane waves too (no pixel reaches the budget any more), but at least two 64-lane waves on primitive edges finish with a wave OR (
65143,16368) that misses some live lanes' words: on these pixels the loop stops after 10 or 13 passes while their own word is not yet in the OR.Whole
gpu::filter with this PR: RX 9070 XT 629 passed, 3 failed (this test, plus the AMD fuzz seeds tracked in #2115, which fail onmaintoo); RTX 3060 632 passed, 0 failed.Not tested: RDNA2/RDNA3 in 64-lane pixel waves, a title.
AI use: Claude Code (Claude Opus 5.5) ran the tests on this machine and wrote this report.
@fromthemoonx on GitHub · 2026-11-25 13:43 UTC · original · edited 2026-11-25 15:16 UTC
Rerun on the new head
8fcc111(rebased ontomain06c9f55, plus the lane-mask commit): passes on NVIDIA. Here too both new GPU tests pass without their fix, so on this card only themask_livetext check catches a missing fix.cargo test --workspace --no-fail-fast -- --test-threads=4at8fcc111SKIPPEDlines (no wave64, refused per-lane forms)gpu_ps_readfirstlane_loop_on_a_primitive_edge_ends, 10 runslane counts {32}; most iterations 16; 0 of 1024 pixels wronggpu_ps_mask_loop_on_a_primitive_edge_ends, 10 runslane counts {32}; 0 of 1024 pixels wrongemit.rsfrom0306d10(the second fix removed), 3 runstests.rs:9495, theassert!(pt.hlsl.contains("scc = (uint)(mask_live("))text check0 of 1024 pixels wrongThe driver ran these pixel shaders in 32-lane waves, so this card runs the 32-bit
s_and_b32/s_andn2_b32forms the new commit changes. As with the first commit, the driver keeps the helper lanes' values in the loop, so the GPU result is the same with or without the change.First run, on
6ec402b: Whole suite passed on NVIDIA (wave32), at the head and merged ontomain379725a, and the new test passed here without the fix too. At the head: 1251 passed, 0 failed, 46 ignored. Merged: 1255 passed, 0 failed, 46 ignored.gpu_ps_readfirstlane_loop_on_a_primitive_edge_endspassed 10 of 10, and 3 of 3 with only theemit.rscall reverted tofirst_lane(0 of 1024 pixels wrong).Tested: RTX 3060 12 GB (driver 610.88), Ryzen 7 5700X, Windows 11 Pro 26300, Rust 1.100.0 MSVC, debug.
Not tested: a title, a release build, Intel.
AI use: Claude Code (Claude Opus 5.5) ran the tests and wrote this report.
@nnonno91 on GitHub · 2026-11-25 13:57 UTC · original · edited 2026-11-25 15:17 UTC
@madaraXor I retested both pixel-loop fixtures on the updated head
8fcc11131f9fe3daec6cfb207bacf87f73f75463with the same Windows/DXC setup as below and added the RTX 5090 (driver 32.0.16.1742).cargo test --locked -p xcl --lib _loop_on_a_primitive_edge_ends -- --nocapture --test-threads=1on each adapter selected viaXCL_ADAPTER. Both runs reported 2 passed, 0 failed, 0 ignored, no skips.This covers 64-lane execution of the mask test on this Radeon driver. The 64-lane readfirstlane case and retail-title hang were outside this run.
Independent Windows Radeon iGPU check of exact PR head
6ec402b16a2d5ce076361a1fb6d01cfa7e15370band parent1a0bbe3a2ba91ea8f5b6fc29130a053868d3c9e6. This driver ran the pixel shader in 32-lane waves on both revisions and reproduced the 69-pixel failure before the fix.Tested
cargo test --locked -p xcl --lib gpu::recomp::tests::gpu_ps_readfirstlane_loop_on_a_primitive_edge_ends -- --exact --nocapture --test-threads=1withXCL_ADAPTER=AMD RadeonandXCL_REQUIRE_GPU=wave64. The test itself read back the pixel shader wave size as 32. The parent had only the PR's test source diff applied temporarily.Not tested
64-lane execution of this pixel shader, other adapters, retail smoke, and the full workspace suite.
AI use
OpenAI Codex (GPT-6.2 Sol) ran the tests, verified the logged results and wrote this report.
@ivall on GitHub · 2026-11-25 15:18 UTC · original
Merged as part of
mainwith your second commit, plus one of mine on top (12f25f1, below). It fixes my test too, so my earlier comment about 5 wrong pixels is out of date.gpu_ps_readfirstlane_loop_on_a_primitive_edge_endsandgpu_ps_mask_loop_on_a_primitive_edge_ends: 0 of 1024 pixels wrong in both, most iterations 16.cargo test --workspace --no-fail-fast -- --test-threads=4: 1265 passed, 2 failed (#2115, as onmain), 46 ignored.s_or_saveexec -1,v_cndmask, three DPP8 steps, row mirror,v_permlanex16,v_readlane 0) pass partial results through lanes that were never launched. Here those lanes do not exist, so a 64-lane wave that is not full lost the words of live lanes: 5 wrong pixels of 1024 in your test before it, 0 after. A wave32 VS / PS now takes the reduction from a wave operation over its half, and a helper lane from a live lane of its quad. Integer OR / AND / min / max with their identity as the seed; nothing else is touched.8fcc111, with mine) ran 306 s from start (about 180 s of them in its world) with no device removal in the log, with the loop budget of this shader at 4096. It ended when the machine ran out of memory and froze, which is a separate problem of that build. The final state has not been run in a title yet.Read before the merge: both commits.
AI use: Claude Code (Claude Opus 5.5) wrote the second commit, ran the tests and wrote this on the maintainer's behalf.
@SlopTart on GitHub · 2026-11-25 15:21 UTC · original
All-clear follow-up:
gpu_ps_readfirstlane_loop_on_a_primitive_edge_endsnow passes on this lane, 3/3 solo runs, atorigin/main08294413(so with12f25f14included). Same rig and env as the failing rows above (RX 7900 XT / RADV / wine-11.0, wave64):lane counts {64}, most iterations 16, 0 of 1024 pixels wrong.So
12f25f14closed the 39-pixel case on RDNA3 under Wine as well; the RDNA3/Wine lane is back to its normal baseline.