Recompiler: direct pixel shaders read lane reads once more from the first live lane #3689
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3689"
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 ivall/xcl. Originally posted by lucsoft on 2026-12-02T13:07:23Z.
On AMD under RADV the tiled-lighting pixel shaders of the retail title (
vs 73e9322e…+ oneTL_PS_PBR_MATERIAL_*each, ~45 passes a frame) cost about 21 ms each, about half of a 2 s frame. The console's scalar values reach them per lane, so the PC compiler treats every heap index derived from av_readlane/v_readfirstlaneas divergent. This reads those results once more from the console wave's first live lane, so the compiler sees them as wave-uniform. Where one hardware wave is one console wave (RADV withRADV_PERFTEST=pswave32), each lighting pass drops from ~21 ms to 1.5–2.6 ms.Part of #1269. Based on
main(c53e9696); it does not need #3547. The measurements below come from our #3547 test stack, where long runs are stable on this machine; a measurement onmainis pending.Review (Foniass) addressed in this push: the conflict with #3655 (main's split-form early returns first), the helper-only fallback (no wave op; each lane keeps its own value, which is also per console half),
XCL_PS_UNIFORM_READS=0= main exactly, the wave-size gate (branch on the lane count for wave32 programs), and a GPU test of the values.What is in it
v_readfirstlane/v_readlaneresult is an SGPR: one value for the wave. In the direct translation it is built from quad reads and helper-lane selects that pick per lane (rla's quad reads; on amd-dev alsohelper_reads_own). The PC compiler cannot prove every live lane holds the same value, so everything derived from it is divergent: heap window indices, descriptor indices, branches. In an RGP capture of the retail title, each lighting PS compiled to 120–190 KB of wave64 code at 252–256 VGPRs, with ~59 waterfall loops, 40 of them inside the per-light loop.dxil/lanes.rsLw::ps_uniform_read, called from thev_readfirstlane_b32/v_readlane_b32lowering inlower_valu.rs, after main's split-form early returns):WaveReadLaneAt, from the console wave's first live lane (ballot-derived). Live lanes get the same value as before; helper lanes now get the console wave's value.v_readfirstlane's source for a helper lane (helper_reads_own), so a helper-only waterfall loop ends in one pass. No wave read happens there.xcl_half). For wave32 programs the read is therefore behind a branch onWaveGetLaneCount() == 32: on 64-lane hardware only the branch is added and main's value is kept; on 32-lane hardware (RADV_PERFTEST=pswave32, NVIDIA) the read is uniform. Split wave64 forms are left as they were.helper_reads_own(a helper lane'sv_readfirstlanetakes its own value, so a helper-only waterfall loop converges in one pass) comes over from raylitebull's amd-dev work (6fa964de, part of #3547); it is the helper valueps_uniform_readfalls back to.XCL_PS_UNIFORM_READS=0restores main's form exactly (nohelper_reads_owneither), with its own translated-cache identity (pso.rs).direct_ps_lane_reads_end_in_a_uniform_read(both lane reads, wave32 and wave64 programs: DXIL validates, has the live-lane ballot, nowaveReadLaneFirst, the lane-count gate exactly for wave32), and on the GPUgpu_direct_ps_readfirstlane_reads_the_first_live_lane: a triangle whose edge quads hold helper lanes; every live lane'sv_readfirstlaneof its own index must equal the lanes_ff1of EXEC names.Measurements (RX 7800 XT, RADV, retail title, the same commit on our #3547 test stack,
XCL_GPU_TIMESover 8 frames from 790 s, 900 s runs, 0 page faults in each)pswave32pswave32+ this PRTested
570a8741):gpu::dxil::lanes::10 passed, 0 failed, both with RADV's default (pixel shaders wave64: the gated path) and withRADV_PERFTEST=pswave32(the uniform read), incl. the new GPU value test and the two triangle-edge helper-lane tests.cdaf44e2, on maindf0cfef6): workspace suite (Wine, 2 threads, one module per process) lib 2738 passed, 17 failed, 31 ignored, 1 died vs main 1c8b5514's 2735 / 17 / 31 / 1; integration 143 / 5 / 20 for both; no failure only on that head. The suite on this head is pending.pswave32alone): no regression shown, none ruled out; two runs of the same build already differ a lot in the light-accumulation target (SSIM 0.56 with matching G-buffers).Regression run
Both from the previous head
cdaf44e2(on maindf0cfef6), withRADV_PERFTEST=pswave32, 180 s; 0 page faults, ring timeouts and resets for each. On this head's base, mainc53e9696ends a few seconds after start under Wine with any GPU until #3707 is merged (#3655's helper functions abort dxil-spirv), so the smoke pair is rerun then.main:
PR:
Not tested
AI use
🤖 Generated with Claude Code
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-02T13:17:48Z.
Review (head
cdaf44e2, diff read, not a merge-check; draft, conflicts with maind71578f8, so not built or run):The commit adds
Lw::ps_uniform_read, which reads every direct-PSv_readlane/v_readfirstlaneresult once more withWaveReadLaneAtfrom the first lane ofWaveActiveBallot(true)(per console half whengfx_halfis set), falling back toWaveReadLaneFirstof a newhelper_reads_ownvalue when that ballot is empty; it's on by default for every direct PS and off withXCL_PS_UNIFORM_READS=0.crates/xcl/src/gpu/dxil/lower_valu.rs, in thev_readfirstlane_b32/v_readlane_b32arms (~1056), against #3655's65f89f04(uniform_reads/read_first_lane_uniform) and685008d1(lane_waits/keep_lane/How::OwnFirst). Those plans are only built for split compute / mesh (kernel.rs~350,planned), so keeping main's early returns and putting this PR's two calls in the non-uniform_readsbranch resolves it.anyis false only when the ballot sees no non-helper lane, which this module assumes leaves helpers out (ballot_ps_localdoc);WaveReadLaneFirst(helper)(lanes.rs~1098) then has no participating lane, so its result is undefined in exactly the helper-only waterfall case it's meant to end. A driver value matching no helper's index would never drain that loop, a GPU hang.gfx_half(wave32 console PS in 64-lane hardware: the RADV default, and probably AMD's Windows driver),uis read per half butWaveReadLaneFirstreads the whole hardware wave, so a helper-only half next to a live half gets the other console wave's value (lanes.rs~1097-1099).XCL_PS_UNIFORM_READS=0doesn't restore main. The off path returnsown=helper_reads_own(a, t)(lower_valu.rs), so helper lanes take their own value: amd-dev's6fa964debehaviour, not main's, though the description says it "restores the previous form".helper_reads_ownis a second behaviour change with no switch or test of its own, and its doc comment ("converge in one pass on AMD RDNA4") no longer holds once the fallback gives all helpers one value.is_pixel/!split/ the env var, nothing on wave size. On 64-lane hardwarekdepends on the per-lanexcl_half, so it isn't uniform there and each lane read gains a ballot, twofirstbitlow,WaveReadLaneAt,WaveReadLaneFirst,isHelperLaneand selects for no gain. On NVIDIA (32-lane) it should fold to a uniform read, but neither NVIDIA nor Windows was run; the suite, smoke and visual check are all pending.direct_ps_lane_reads_end_in_a_uniform_readonly checks thatwaveReadLaneFirst.i32(appears in the disassembly. Nothing checks the value live lanes get, the per-half path, or the helper-only fallback, thoughgpu_direct_ps_masks_hold_helper_lanes_on_triangle_edges(lanes.rs~1287) shows a GPU PS harness exists for such a test. All measurements are from the #3547 stack, none from main.Fine: for live lanes, "first live lane" gives the console's value, since
tis built from the samefirst_lane(exec)/rlain every live lane; split forms are left alone; the rebase needs nothing from amd-dev beyondhelper_reads_own, which the commit carries (GraphicsIo::is_helper_laneexists on main); the translated-cache identity is right for both settings.AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.
Imported from ivall/xcl. Originally posted by gut0to on 2026-12-02T19:45:51Z.
Review: COMMENTED
AI-assisted review: GPT-6 helped inspect the DXIL path and HLSL wave contract; I verified the behavior.
Imported from ivall/xcl. Originally posted by gut0to on 2026-12-02T19:45:51Z.
Code review location:
crates/xcl/src/gpu/dxil/lanes.rs; line 1106Medium:
WaveActiveBallot(true)can include helper lanes in pixel shaders. If a helper has a lower lane index than the first live lane,firstbitlowselects it andwaveReadLaneAtbroadcasts its per-lanetto the live lanes, so this does not guarantee the first live lane's value.helper_reads_ownonly handles an empty-ballot fallback; it does not exclude helpers when the ballot is nonempty. Could the ballot predicate exclude helper lanes while retaining the empty-ballot fallback, with a test where a lower-index helper precedes a live lane? AI-assisted review: GPT-6 helped inspect the DXIL path; I verified this against Microsoft's Shader Model 6 documentation and WaveActiveBallot documentation.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.