xshader: lower constant-lane v_readlane_b32 for Wave32 and portable Wave64 #185
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/brcly--TuxBox!185
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-185"
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?
@Vladimir-Human on GitHub · 2026-11-25 17:55 UTC · original
Vladimir-Human:xshader/readlane-wave-reduction→main· +2446 −77 · 16 files · 5 commits · openAI-assisted PR.
Summary
Lowers constant-lane
v_readlane_b32wave reductions intools/shader-compiler:WaveReadLaneAtwhen the wave execution context and SGPR/SCC/Exec operands are proven uniform across a dataflow + control-dependence fixpoint, falling back cleanly to VGPR-indexedtb_swizzleLDS exchange otherwise.s_bitset*/s_cmov*/Sopk/Smemuniformity rules,ExecLo/ExecHiconflict checks,v_mbcnt[WaveSize(32)]WaveActiveBallothandling, guarded partial-group OOB loads between unconditional barriers, andtb_guardloop checks rejecting preceding/nested non-uniform loops.<= 1,200lines with zero inline#[cfg(test)]modules (exec_group.rsuntouched).Verification (commit
4ecbc63c)test_repository_hygiene.py,test_translator_checks.py,test_wave_extrema.py,test_dpp8_exchange.py): 13 passed, 0 failedcargo test --manifest-path tools/shader-compiler/Cargo.toml: 318 passed, 0 failed, 0 ignored (316 lib + 2 integration)cs_6_6/cs_6_0) + hardware D3D12 readback (RTX 4070 SUPER,10de:2783,readlane_probe+compute.cpp): 15/15 cases passed, 5,760/5,760 words exactgit merge-tree --write-treeclean againstorigin/mainand PR#176.@brcly on GitHub · 2026-11-25 18:37 UTC · original
Thanks for this. I trial-merged it onto
main(4cb6a4a) and ran the full check, which passed: 348 Python tests, 313 shader translator tests, 65 guest checks, the D3D12 regression controls and the translator GPU checks.Before merging, I'd like to understand a tail latency change in the Lanes benchmark. I ran
python tuxbox.py verify --only lanes-benchmark15 times on each build.mainmedian (min–max)The medians match, but frame p99 went over 450 µs in 5 of 15 runs with this PR and 0 of 15 on
main:main: 298, 325, 329, 335, 342, 351, 357, 363, 364, 367, 371, 374, 375, 378, 379The full check's own benchmark run on the merged tree also read 725.6 µs. The runs for each build were done in blocks (5, then 10), not strictly alternated. I haven't found the cause. The new wake-up path for waiting queues is the first place I'd look, but that's a guess.
Could you check whether you see the same spread over repeated runs, and either fix it or explain it?
On the elision logic: from reading it, only monotone waits at list start are skipped, and only with no tracked or in-flight write to the address. I found draws, dispatches, copies, markers, queries and bundles all recording writes. One case I don't see covered is the CPU lowering a label between submission and GPU execution. Is that something you considered?
I didn't test this in a retail title.
Host: NVIDIA GeForce RTX 4070 Ti SUPER (
10de:2705), driver 620.73.04, Proton Experimental 11.0-20261027b, Linux 7.3.5, AMD Ryzen 7 9800X3D.@brcly on GitHub · 2026-11-25 18:56 UTC · original
This ended up being noise, ignore me. will merge this and others soon. thank you.
@tsunderejay on GitHub · 2026-11-25 21:04 UTC · original
Automated review against current main found blocking correctness risks before merge: (1) wave width is inferred from b32/b64 EXEC operand width, which is not conclusive and can silently select Wave32 for a Wave64 program; (2) the unproven-selector fallback can use a hardcoded 64-lane base without bounds checks and can read stale values for branch-skipped lanes; (3) new readlane refusals may be swallowed by the lone-lane retry; (4) scalar memory loads are treated as workgroup-uniform for loop-convergence proofs, which can introduce barrier deadlocks. Please address these with regressions before merging.
@Vladimir-Human on GitHub · 2026-11-25 23:35 UTC · original
@tsunderejay Thank you for the detailed review — pushed monotonic fix commit
543999bdon top of4ecbc63caddressing all 4 blocking correctness findings with regression tests:Wave width inference (
indexed_lane.rs):_b32/_u32/_i32touches_execclause fromhas_wave32_markersso a Wave64 shader inspectingexec_lowiths_mov_b32/s_and_b32can no longer be misclassified as Wave32.Opnd::ExecHireference as a Wave64 marker, and explicitly refused ambiguous 32-bitexec_loinstructions lacking conclusive Wave32 or Wave64 proof (wave64_exec_lo_b32_inspect_keeps_wave64_and_ambiguous_b32_exec_refuses).Unproven-selector fallback &
GROUP_READ(pipeline.rs,indexed_lane.rs,exchange.rs):swizzle_group_reads,can_swizzle_fallback,group_reads, andemit_compute_swizzle(GROUP_READ)strictly to proven-safecompute_swizzleshapes (count % 64 == 0,1..=1024,guest_width == 64,scan_width.is_none(),!dispatched).emit_compute_swizzle(GROUP_READ)to publishtb_swizzle[tb_lane] = <src0>;unconditionally before the firstGroupMemoryBarrierWithGroupSync(), guard only the read/result assignment on active branches, and mask the selector with& 63u(unproven_swizzle_fallback_refuses_partial_groups_and_preserves_skipped_lanes).lone_lane::retryswallowing readlane refusals (pipeline.rs,indexed_lane.rs):translate_outputsto returnfirstdirectly wheneverindexed_lane::has_non_spill_readlane(&original)is true so cross-lanev_readlane_b32errors propagate cleanly instead of falling through to per-lane retry (refused_readlane_is_not_swallowed_by_lone_lane_retry).Enc::Smemuniformity (indexed_lane.rs):analyze_uniformity_passsoEnc::Smem(s_load_*,s_buffer_load_*) conservatively taints written SGPRs as non-uniform, preventing scalar memory load loops from proving convergence around barriers (smem_loads_are_not_treated_as_workgroup_uniform_for_readlane_loops).Verification (
543999bd6fafa17f)git merge-treeagainstorigin/main(cb8c38b) and PR#201(079143b1).python -m unittest discover -s tests -p "test_repository_hygiene.py" -v: 4/4 passed (max.rs= 1,106 lines;indexed_lane.rs= 1,031;tests/hlsl/indexed_lane.rs= 930).cargo test --manifest-path tools/shader-compiler/Cargo.toml: 320 lib + 2 integration passed; 0 failed.readlane_probe(15/15) + DXC10.0.26100.0cs_6_6compile: 15/15 passed.cargo test --manifest-path runtime/d3d12/Cargo.toml -- --test-threads=1: 111/111 passed.python build.py lanes+lanes.exe --adapter 10de:2783 --selftest all: passed (12/12).@brcly on GitHub · 2026-11-26 02:05 UTC · original
The 128 lost shaders are mostly from the early return in translate_outputs for has_non_spill_readlane: disabling it leaves 4 lost and 26 changed, with none gained.
Please suppress the fallbacks only when the lane read itself is what failed, and fall back for the 4 that lack a lane bound.
On recorded requests the PR doesn’t translate any of the 278 shaders refused for lane reads, so could you show a case it fixes, ideally a GPU check where main computes the wrong result?
543999bd6fto4a153546ed@Vladimir-Human on GitHub · 2026-11-26 09:46 UTC · original
@brcly @tsunderejay Rebased cleanly onto
main(773278ad) and pushed4a15354addressing both remaining points and adding a runnable GPU check demonstrating wheremaincomputes wrong results on hardware:1. Narrow
lone_lanefallback suppression (pipeline.rs,indexed_lane.rs)if indexed_lane::has_non_spill_readlane(&original) { return first; }early return fromtranslate_outputs, which was suppressinglone_lane::retryfor shaders whose primary failure was unrelated to lane reads (the 124 shaders lost from that check).translate_outputs_once_implnow setslane_read_failed = trueonly when the lane read itself fails (indexed_lane::lower_constant_reads, Wave32 lane-read/mbcnt width conflict, or readlane emission). Unrelated primary failures still fall back tolone_lane::retry(non_readlane_failure_still_allows_lone_lane_retry_when_readlane_present), while actual lane-read refusals propagate directly without being swallowed (refused_readlane_is_not_swallowed_by_lone_lane_retry).2. Bounds-safe fallback for shaders lacking a static lane bound (
indexed_lane.rs,pipeline.rs,emitter/exchange.rs)ConstantReadPlan::group_read_width: Option<u32>. When a complete-wave compute group (count % guest_width == 0,1..=1024,scan_width.is_none(), nods_ordered*) contains a dynamic SGPRv_readlane_b32without a static upper-bound proof (with or withoutds_swizzle_b32, covering both Wave32 and Wave64, including the 4 shaders lacking a lane bound andhost_profile_programs::lanes),lower_constant_readshands off toGROUP_READwith the exact guest wave width (32or64).emit_compute_swizzle(GROUP_READ)enforces!self.dispatched && count % width == 0, publishestb_swizzle[tb_lane] = <src0>;unconditionally before the first barrier (preserving branch-skipped lanes' actual VGPR values), guards only the load on active skip flags, and masks(tb_lane & ~{mask}u) | ({sel} & {mask}u)(31ufor Wave32,63ufor Wave64) so every index is guaranteed in0..count.[7, 3, 1], Wave64[32, 1, 1], Wave64[96, 1, 1]) stay refused without an upper-bound proof.tools/shader-compiler/src/tests/hlsl/host_profiles.txtforlanes(its dynamic SGPRs21read is now masked& 63uinstead of indexingtb_swizzleunbounded).3. GPU check showing cases where
main(773278ad) computes wrong results on hardwareAdded
tools/check_readlane_gpu.py(registered as"readlane"intools/check_translator_gpu.py, usingtools/shader-compiler/examples/readlane_probe.rsandtools/reference/independent-shaders/compute.cpp).Side-by-side D3D12 readback on NVIDIA GeForce RTX 4070 SUPER (
10de:2783, DXC10.0.26100.0, 18 cases / 6,912 words):4a15354):PASS: 18/18 cases, 6912 words, adapter 10de:2783origin/main(773278ad):FAIL: 11/18 cases, 6528 words, adapter 10de:2783— 6 cases silently compute wrong GPU outputs and 1 case is refused:origin/main(773278ad) on GPUmainis wrong4a15354)wave32_64t_masked_31word 96: 0xceacd4cc != 0x7116aa5d)emit_indexed_readhardcodes~63u; Wave 1 (32..63) reads lane 31 instead of lane 63~31u)wave32_64t_and_exec_31word 96: 0xcbf84d32 != 0xff3481e9)~63uWave32 multi-wave cross-wave read~31u)wave32_mbcnt_exec_31word 34: 0x01ff23d4 != 0x02ff23d4)indexed_laneemitscountbits(exec_lo & mask)on 1-bit per-laneexec_loinstead ofWaveActiveBallot[WaveSize(32)]ballot)wave64_swizzle_branch_dyn_63word 64: 0x00000000 != 0x50e1be49)GROUP_READwrites(!j...) ? v1 : 0ubefore barrier, zeroing branch-skipped lane 63wave64_dyn_sgpr_high_bits_47word 64: 0x00000000 != 0x75cfac71)GROUP_READomits& 63u(s5 = 0x102freads OOBtb_swizzle[0x102f])& 63u)wave32_64t_dyn_sgpr_31word 64: 0x00000000 != 0x56772646)GROUP_READhardcodes~63uand omits& 31u~31u,& 31u)wave64_64t_spill_and_loop_lane31v1 lane 31 read before any v_writelane)constant_readsrejects any shader withv_writelane_b32or a backward branchVerification (
4a15354)cargo test --release --manifest-path tools/shader-compiler/Cargo.toml: 343 lib + 2 integration passed, 0 failedcargo test --release --manifest-path runtime/dxbc/Cargo.toml: 21 passed, 0 failedcargo check --manifest-path tools/shader-compiler/Cargo.toml --all-targets: 0 warningspython -m unittest discover -s tests -p "test_translator_checks.py" -v: 4/4 passed<= 1,200lines (indexed_lane.rs: 1,038;tests/hlsl/indexed_lane.rs: 990) with zero inline#[cfg(test)]modules.View command line instructions
Manual merge helper
Use this merge commit message when completing the merge manually.
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.