Repository navigation
Recompiler: pixel shader loops end on primitive edges (helper lanes) - #2305
Conversation
|
Update for head Head
So the second commit doesn't change the readfirstlane case on 64-lane waves. Whole 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 ( Tested: head
The 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 ( Whole Not tested: RDNA2/RDNA3 in 64-lane pixel waves, a title. |
|
Rerun on the new head
The driver ran these pixel shaders in 32-lane waves, so this card runs the 32-bit First run, on 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. |
|
Third AMD data point, Linux/RADV (RDNA3) over Wine: the new test fails deterministically, 39 of 1024 pixels wrong. Tested:
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. |
|
@madaraXor I retested both pixel-loop fixtures on the updated head
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 Tested
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. |
|
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.)
My reading, not tested: the whole-wave OR reductions ( AI use: Claude Code (Claude Opus 5.5) ran this and wrote the comment on the maintainer's behalf. |
In a pixel shader EXEC holds helper lanes (s_wqm), and on a primitive's edge the first lane of EXEC is often one. v_readfirstlane read that lane. An RDNA2 driver (RX 6700 XT, 32.0.21045) gives 0 for everything a helper lane holds once a WaveReadLaneAt ran inside a loop, quad reads included. A loop whose state the console's compiler carries in a vector register (v_mov v, s ... v_readfirstlane s, v) then read 0 back on each pass and ran to the loop budget: a retail title's volumetric light pass took seconds per draw at its world start and Windows reset the GPU (xcl-dev#675). v_readfirstlane now reads the first lane of EXEC that is live (ballot(true), per half in the wave32-in-64 form) when EXEC has one, and the first lane of EXEC as before when it has none. 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 (a waterfall loop). The new GPU test draws that title's list-loop shape on two triangles sharing a diagonal. Without the change, on the RX 6700 XT, 69 of 1024 pixels run the loop 65 536 times (the budget) with wrong results; with it, none, and at most 16 passes. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A retail title's volumetric light pass (72 vertices x 6003 instances) ran nearly every lane to the loop budget on an RX 6700 XT, and Windows reset the GPU at its world start (xcl-dev#675). Replayed alone from a capture of that draw: with the budget at 1024, 782 loop passes per lane on average, 99 % of them in the march loop that follows the light list; the light list's data was sane. The march goes on as long as a lane is left in a mask taken from EXEC (s_andn2 mask, mask, vcc; s_cbranch_scc1). Probes in the replayed HLSL showed the helper lanes' registers right through the first pass and reading as 0 from the second pass on (their pass counter included) when the shader has another loop before the march; the driver ran it in 64-lane waves. A helper lane's "done" condition then never became true, its bit stayed in the mask and the live lanes waited for it. In a pixel shader, the SCC of s_and_b32 / s_andn2_b32 with EXEC or VCC as an operand or destination now counts the live lanes only (mask_live): the helper lanes leave the loop with the live ones. Helper lanes only feed derivatives of the live lanes, which have left too. Replay of the captured draw with the full budget: 7.20 passes per lane, 13 at most, 13.8 ms of GPU time, no device removal (before: removed after 4 852 ms). gpu_ps_mask_loop_on_a_primitive_edge_ends draws that loop shape on two triangles sharing a diagonal: without the change, 256 of 1024 pixels run to the budget on the RX 6700 XT (64-lane waves); with it, none. Not changed: 64-bit mask ops (wave64 pixel programs), masks only kept in SGPR copies, the direct DXIL path. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
6ec402b to
8fcc111
Compare
|
Thanks for the runs. Updated to
@DarkPanda69, @SlopTart: could you rerun both AI use: Claude Code (Claude Opus 5.5) wrote this comment. |
|
@madaraXor rerun at the new head on the Wine/RDNA3 lane, as asked. Head:
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. |
|
Merged as part of
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. |
|
All-clear follow-up: So |
In 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(Tests: align XMemVirtualQuery buffers and verify CPU flags #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