xshader: lower constant-lane v_readlane_b32 for Wave32 and portable Wave64 #185

Open
github-bot wants to merge 5 commits from github-bot/gh-185 into main AGit
Owner

@⁠Vladimir-Human on GitHub · 2026-11-25 17:55 UTC · original
Vladimir-Human:xshader/readlane-wave-reduction → main · +2446 −77 · 16 files · 5 commits · open

AI-assisted PR.

Summary

Lowers constant-lane v_readlane_b32 wave reductions in tools/shader-compiler:

  • Emits direct scalarized WaveReadLaneAt when the wave execution context and SGPR/SCC/Exec operands are proven uniform across a dataflow + control-dependence fixpoint, falling back cleanly to VGPR-indexed tb_swizzle LDS exchange otherwise.
  • Enforces Wave32/Wave64 mask width checks, s_bitset*/s_cmov*/Sopk/Smem uniformity rules, ExecLo/ExecHi conflict checks, v_mbcnt [WaveSize(32)] WaveActiveBallot handling, guarded partial-group OOB loads between unconditional barriers, and tb_guard loop checks rejecting preceding/nested non-uniform loops.
  • All modified Rust files remain <= 1,200 lines with zero inline #[cfg(test)] modules (exec_group.rs untouched).

Verification (commit 4ecbc63c)

  • Python hygiene & shader checks (test_repository_hygiene.py, test_translator_checks.py, test_wave_extrema.py, test_dpp8_exchange.py): 13 passed, 0 failed
  • cargo test --manifest-path tools/shader-compiler/Cargo.toml: 318 passed, 0 failed, 0 ignored (316 lib + 2 integration)
  • DXC (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 exact
  • git merge-tree --write-tree clean against origin/main and PR #176.
**@⁠Vladimir-Human** on GitHub · 2026-11-25 17:55 UTC · [original](https://github.com/brcly/TuxBox/pull/185) `Vladimir-Human:xshader/readlane-wave-reduction` → `main` · +2446 −77 · 16 files · 5 commits · open AI-assisted PR. ### Summary Lowers constant-lane `v_readlane_b32` wave reductions in `tools/shader-compiler`: - Emits direct scalarized `WaveReadLaneAt` when the wave execution context and SGPR/SCC/Exec operands are proven uniform across a dataflow + control-dependence fixpoint, falling back cleanly to VGPR-indexed `tb_swizzle` LDS exchange otherwise. - Enforces Wave32/Wave64 mask width checks, `s_bitset*`/`s_cmov*`/`Sopk`/`Smem` uniformity rules, `ExecLo`/`ExecHi` conflict checks, `v_mbcnt` `[WaveSize(32)]` `WaveActiveBallot` handling, guarded partial-group OOB loads between unconditional barriers, and `tb_guard` loop checks rejecting preceding/nested non-uniform loops. - All modified Rust files remain `<= 1,200` lines with zero inline `#[cfg(test)]` modules (`exec_group.rs` untouched). ### Verification (commit `4ecbc63c`) - Python hygiene & shader checks (`test_repository_hygiene.py`, `test_translator_checks.py`, `test_wave_extrema.py`, `test_dpp8_exchange.py`): **13 passed, 0 failed** - `cargo test --manifest-path tools/shader-compiler/Cargo.toml`: **318 passed, 0 failed, 0 ignored** (316 lib + 2 integration) - DXC (`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 exact** - `git merge-tree --write-tree` clean against `origin/main` and PR `#176`.
Lower non-spill constant-lane and upper-bound-proven SGPR v_readlane_b32
instructions in compute shaders with exact RDNA2 EXEC-ignoring semantics:

- Separate SGPR spill VGPRs (written by v_writelane_b32) from cross-lane
  VGPR broadcasts so shaders with both spills and constant readlanes compile.
- On 1D Wave32 groups where forward CFG analysis proves all lanes active in
  EXEC and uniform control flow/selector, emit zero-overhead WaveReadLaneAt
  with [WaveSize(32)].
- When EXEC may have disabled the target lane, on 2D/3D or partial groups,
  or for portable Wave64 running on Wave32 hosts, stage through groupshared
  tb_swizzle hoisted outside skip guards using the guest wave stride (32 or 64)
  without requiring [WaveSize(64)].
- Verify structured CFG and loop uniformity before allowing barrier/wave
  exchanges, and explicitly refuse out-of-range lanes, unproven dynamic SGPR
  selectors, non-uniform loops, interleaved loops, and early s_endpgm.
- F1: Reject non-uniform forward branches skipping an entire enclosing
  barrier loop (from < l && to > l), and reject barrier loops following
  non-uniform loops that could desync the function-wide tb_guard counter.
- F2: Couple analyze_uniformity with control dependence so any SGPR/SCC
  written inside a non-uniform branch or loop span is tainted to fixpoint.
- F3: Check dst reads on SOP1 RMW ops (s_bitset0/1, s_cmov), invert SCC
  tracking to explicit preserve/write allowlists (defaulting unknown ops
  to tainted SCC), and restrict uniform SMEM to loads with NULL/SGPR soffset.
- F4: Match all 32/64-bit scalar ops touching EXEC in wave-width marker
  detection and enforce conflict/width checks on count <= 32 groups too.
- F5: Restrict the indexed_lane tb_lane v_mbcnt fast path to -1 masks,
  preserving WaveActiveBallot for Wave32 EXEC masks (with WaveSize(32))
  and refusing unmodeled lane-mask v_mbcnt under indexed_lane.
- F6: Guard hoisted emit_indexed_read loads on active skip flags while
  keeping both barriers unconditional so skipped lanes never read OOB on
  partial groups.
- Minor: Reject incomplete or CLAMP/OMOD-flagged VOP3 v_readlane_b32.
- Wave width inference: remove inconclusive 32-bit EXEC_LO heuristic from
  has_wave32_markers, treat any ExecHi operand as a Wave64 marker, and refuse
  ambiguous 32-bit EXEC_LO operations lacking conclusive Wave32/Wave64 proof.
- Unproven-selector fallback: gate swizzle_group_reads / GROUP_READ strictly
  on complete 64-lane groups (count % 64 == 0, guest_width == 64, structured
  compute swizzle), publish every lane's actual VGPR unconditionally before
  the barrier in emit_compute_swizzle(GROUP_READ), guard only the load on
  active skip flags, and mask the selector with & 63u.
- Lone-lane retry: propagate cross-lane v_readlane_b32 refusals directly in
  translate_outputs instead of falling back to lone_lane::retry.
- SMEM uniformity: treat Enc::Smem scalar loads conservatively as non-uniform
  in analyze_uniformity_pass so mutable/coherent scalar loads cannot feed
  barrier loops enclosing v_readlane_b32.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 06:37:00 +00:00
Author
Owner

@⁠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-benchmark 15 times on each build.

Reading (µs) main median (min–max) With this PR, median (min–max)
submit 208.6 (202.4–215.1) 208.9 (204.6–211.4)
roundtrip 236.4 (229.5–253.3) 233.6 (227.6–246.1)
copy64k 386.1 (384.2–398.8) 385.9 (383.5–395.6)
frame 230.4 (223.6–236.4) 227.7 (222.1–234.0)
frame p99 363.0 (298.9–379.7) 366.8 (298.1–966.1)
shader pipeline 193.1 (170.8–208.9) 190.3 (173.6–199.2)
DXIL pipeline 130.1 (124.5–140.2) 126.8 (120.3–129.8)

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, 379
  • This PR: 298, 317, 322, 340, 353, 353, 365, 366, 371, 373, 489, 494, 568, 787, 966

The 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:37 UTC · [original](https://github.com/brcly/TuxBox/pull/185#issuecomment-7171156242) 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-benchmark` 15 times on each build. | Reading (µs) | `main` median (min–max) | With this PR, median (min–max) | |---|---|---| | submit | 208.6 (202.4–215.1) | 208.9 (204.6–211.4) | | roundtrip | 236.4 (229.5–253.3) | 233.6 (227.6–246.1) | | copy64k | 386.1 (384.2–398.8) | 385.9 (383.5–395.6) | | frame | 230.4 (223.6–236.4) | 227.7 (222.1–234.0) | | **frame p99** | **363.0 (298.9–379.7)** | **366.8 (298.1–966.1)** | | shader pipeline | 193.1 (170.8–208.9) | 190.3 (173.6–199.2) | | DXIL pipeline | 130.1 (124.5–140.2) | 126.8 (120.3–129.8) | 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, 379 - This PR: 298, 317, 322, 340, 353, 353, 365, 366, 371, 373, 489, 494, 568, 787, 966 The 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.
Author
Owner

@⁠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.

**@⁠brcly** on GitHub · 2026-11-25 18:56 UTC · [original](https://github.com/brcly/TuxBox/pull/185#issuecomment-7171614825) This ended up being noise, ignore me. will merge this and others soon. thank you.
Author
Owner

@⁠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.

**@⁠tsunderejay** on GitHub · 2026-11-25 21:04 UTC · [original](https://github.com/brcly/TuxBox/pull/185#issuecomment-7174568490) 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.
Author
Owner

@⁠Vladimir-Human on GitHub · 2026-11-25 23:35 UTC · original

@⁠tsunderejay Thank you for the detailed review — pushed monotonic fix commit 543999bd on top of 4ecbc63c addressing all 4 blocking correctness findings with regression tests:

  1. Wave width inference (indexed_lane.rs):

    • Removed the inconclusive _b32/_u32/_i32 touches_exec clause from has_wave32_markers so a Wave64 shader inspecting exec_lo with s_mov_b32/s_and_b32 can no longer be misclassified as Wave32.
    • Treated any Opnd::ExecHi reference as a Wave64 marker, and explicitly refused ambiguous 32-bit exec_lo instructions lacking conclusive Wave32 or Wave64 proof (wave64_exec_lo_b32_inspect_keeps_wave64_and_ambiguous_b32_exec_refuses).
  2. Unproven-selector fallback & GROUP_READ (pipeline.rs, indexed_lane.rs, exchange.rs):

    • Restricted swizzle_group_reads, can_swizzle_fallback, group_reads, and emit_compute_swizzle(GROUP_READ) strictly to proven-safe compute_swizzle shapes (count % 64 == 0, 1..=1024, guest_width == 64, scan_width.is_none(), !dispatched).
    • Updated emit_compute_swizzle(GROUP_READ) to publish tb_swizzle[tb_lane] = <src0>; unconditionally before the first GroupMemoryBarrierWithGroupSync(), 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).
  3. lone_lane::retry swallowing readlane refusals (pipeline.rs, indexed_lane.rs):

    • Short-circuited translate_outputs to return first directly whenever indexed_lane::has_non_spill_readlane(&original) is true so cross-lane v_readlane_b32 errors propagate cleanly instead of falling through to per-lane retry (refused_readlane_is_not_swallowed_by_lone_lane_retry).
  4. Enc::Smem uniformity (indexed_lane.rs):

    • Updated analyze_uniformity_pass so Enc::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)

  • Clean git merge-tree against origin/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) + DXC 10.0.26100.0 cs_6_6 compile: 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).
**@⁠Vladimir-Human** on GitHub · 2026-11-25 23:35 UTC · [original](https://github.com/brcly/TuxBox/pull/185#issuecomment-7177785884) @⁠tsunderejay Thank you for the detailed review — pushed monotonic fix commit `543999bd` on top of `4ecbc63c` addressing all 4 blocking correctness findings with regression tests: 1. **Wave width inference (`indexed_lane.rs`)**: - Removed the inconclusive `_b32`/`_u32`/`_i32` `touches_exec` clause from `has_wave32_markers` so a Wave64 shader inspecting `exec_lo` with `s_mov_b32`/`s_and_b32` can no longer be misclassified as Wave32. - Treated any `Opnd::ExecHi` reference as a Wave64 marker, and explicitly refused ambiguous 32-bit `exec_lo` instructions lacking conclusive Wave32 or Wave64 proof (`wave64_exec_lo_b32_inspect_keeps_wave64_and_ambiguous_b32_exec_refuses`). 2. **Unproven-selector fallback & `GROUP_READ` (`pipeline.rs`, `indexed_lane.rs`, `exchange.rs`)**: - Restricted `swizzle_group_reads`, `can_swizzle_fallback`, `group_reads`, and `emit_compute_swizzle(GROUP_READ)` strictly to proven-safe `compute_swizzle` shapes (`count % 64 == 0`, `1..=1024`, `guest_width == 64`, `scan_width.is_none()`, `!dispatched`). - Updated `emit_compute_swizzle(GROUP_READ)` to publish `tb_swizzle[tb_lane] = <src0>;` unconditionally before the first `GroupMemoryBarrierWithGroupSync()`, 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`). 3. **`lone_lane::retry` swallowing readlane refusals (`pipeline.rs`, `indexed_lane.rs`)**: - Short-circuited `translate_outputs` to return `first` directly whenever `indexed_lane::has_non_spill_readlane(&original)` is true so cross-lane `v_readlane_b32` errors propagate cleanly instead of falling through to per-lane retry (`refused_readlane_is_not_swallowed_by_lone_lane_retry`). 4. **`Enc::Smem` uniformity (`indexed_lane.rs`)**: - Updated `analyze_uniformity_pass` so `Enc::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`) - Clean `git merge-tree` against `origin/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) + DXC `10.0.26100.0` `cs_6_6` compile: **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`)**.
Author
Owner

@⁠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?

**@⁠brcly** on GitHub · 2026-11-26 02:05 UTC · [original](https://github.com/brcly/TuxBox/pull/185#issuecomment-7180447357) 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?
github-bot force-pushed github-bot/gh-185 from 543999bd6f to 4a153546ed 2026-11-26 10:56:01 +00:00 Compare
Author
Owner

@⁠Vladimir-Human on GitHub · 2026-11-26 09:46 UTC · original

@⁠brcly @⁠tsunderejay Rebased cleanly onto main (773278ad) and pushed 4a15354 addressing both remaining points and adding a runnable GPU check demonstrating where main computes wrong results on hardware:

1. Narrow lone_lane fallback suppression (pipeline.rs, indexed_lane.rs)

  • Removed the blanket if indexed_lane::has_non_spill_readlane(&original) { return first; } early return from translate_outputs, which was suppressing lone_lane::retry for shaders whose primary failure was unrelated to lane reads (the 124 shaders lost from that check).
  • translate_outputs_once_impl now sets lane_read_failed = true only 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 to lone_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)

  • Added ConstantReadPlan::group_read_width: Option<u32>. When a complete-wave compute group (count % guest_width == 0, 1..=1024, scan_width.is_none(), no ds_ordered*) contains a dynamic SGPR v_readlane_b32 without a static upper-bound proof (with or without ds_swizzle_b32, covering both Wave32 and Wave64, including the 4 shaders lacking a lane bound and host_profile_programs::lanes), lower_constant_reads hands off to GROUP_READ with the exact guest wave width (32 or 64).
  • emit_compute_swizzle(GROUP_READ) enforces !self.dispatched && count % width == 0, publishes tb_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) (31u for Wave32, 63u for Wave64) so every index is guaranteed in 0..count.
  • Partial / non-wave-multiple groups ([7, 3, 1], Wave64 [32, 1, 1], Wave64 [96, 1, 1]) stay refused without an upper-bound proof.
  • Updated tools/shader-compiler/src/tests/hlsl/host_profiles.txt for lanes (its dynamic SGPR s21 read is now masked & 63u instead of indexing tb_swizzle unbounded).

3. GPU check showing cases where main (773278ad) computes wrong results on hardware

Added tools/check_readlane_gpu.py (registered as "readlane" in tools/check_translator_gpu.py, using tools/shader-compiler/examples/readlane_probe.rs and tools/reference/independent-shaders/compute.cpp).

Side-by-side D3D12 readback on NVIDIA GeForce RTX 4070 SUPER (10de:2783, DXC 10.0.26100.0, 18 cases / 6,912 words):

  • This PR (4a15354): PASS: 18/18 cases, 6912 words, adapter 10de:2783
  • origin/main (773278ad): FAIL: 11/18 cases, 6528 words, adapter 10de:2783 — 6 cases silently compute wrong GPU outputs and 1 case is refused:
Case origin/main (773278ad) on GPU Why main is wrong This PR (4a15354)
wave32_64t_masked_31 32/64 words wrong (word 96: 0xceacd4cc != 0x7116aa5d) emit_indexed_read hardcodes ~63u; Wave 1 (32..63) reads lane 31 instead of lane 63 64/64 exact (~31u)
wave32_64t_and_exec_31 32/64 words wrong (word 96: 0xcbf84d32 != 0xff3481e9) Same hardcoded ~63u Wave32 multi-wave cross-wave read 64/64 exact (~31u)
wave32_mbcnt_exec_31 29/32 words wrong (word 34: 0x01ff23d4 != 0x02ff23d4) indexed_lane emits countbits(exec_lo & mask) on 1-bit per-lane exec_lo instead of WaveActiveBallot 32/32 exact ([WaveSize(32)] ballot)
wave64_swizzle_branch_dyn_63 63/64 words wrong (word 64: 0x00000000 != 0x50e1be49) GROUP_READ writes (!j...) ? v1 : 0u before barrier, zeroing branch-skipped lane 63 64/64 exact (unconditional publish)
wave64_dyn_sgpr_high_bits_47 64/64 words wrong (word 64: 0x00000000 != 0x75cfac71) GROUP_READ omits & 63u (s5 = 0x102f reads OOB tb_swizzle[0x102f]) 64/64 exact (& 63u)
wave32_64t_dyn_sgpr_31 64/64 words wrong (word 64: 0x00000000 != 0x56772646) GROUP_READ hardcodes ~63u and omits & 31u 64/64 exact (~31u, & 31u)
wave64_64t_spill_and_loop_lane31 Refused (v1 lane 31 read before any v_writelane) constant_reads rejects any shader with v_writelane_b32 or a backward branch 64/64 exact

Verification (4a15354)

  • cargo test --release --manifest-path tools/shader-compiler/Cargo.toml: 343 lib + 2 integration passed, 0 failed
  • cargo test --release --manifest-path runtime/dxbc/Cargo.toml: 21 passed, 0 failed
  • cargo check --manifest-path tools/shader-compiler/Cargo.toml --all-targets: 0 warnings
  • python -m unittest discover -s tests -p "test_translator_checks.py" -v: 4/4 passed
  • All modified Rust files stay <= 1,200 lines (indexed_lane.rs: 1,038; tests/hlsl/indexed_lane.rs: 990) with zero inline #[cfg(test)] modules.
**@⁠Vladimir-Human** on GitHub · 2026-11-26 09:46 UTC · [original](https://github.com/brcly/TuxBox/pull/185#issuecomment-7188452365) @⁠brcly @⁠tsunderejay Rebased cleanly onto `main` (`773278ad`) and pushed `4a15354` addressing both remaining points and adding a runnable GPU check demonstrating where `main` computes wrong results on hardware: ### 1. Narrow `lone_lane` fallback suppression (`pipeline.rs`, `indexed_lane.rs`) - Removed the blanket `if indexed_lane::has_non_spill_readlane(&original) { return first; }` early return from `translate_outputs`, which was suppressing `lone_lane::retry` for shaders whose primary failure was unrelated to lane reads (the 124 shaders lost from that check). - `translate_outputs_once_impl` now sets `lane_read_failed = true` **only** 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 to `lone_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`) - Added `ConstantReadPlan::group_read_width: Option<u32>`. When a complete-wave compute group (`count % guest_width == 0`, `1..=1024`, `scan_width.is_none()`, no `ds_ordered*`) contains a dynamic SGPR `v_readlane_b32` without a static upper-bound proof (with or without `ds_swizzle_b32`, covering both Wave32 and Wave64, including the 4 shaders lacking a lane bound and `host_profile_programs::lanes`), `lower_constant_reads` hands off to `GROUP_READ` with the exact guest wave width (`32` or `64`). - `emit_compute_swizzle(GROUP_READ)` enforces `!self.dispatched && count % width == 0`, publishes `tb_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)` (`31u` for Wave32, `63u` for Wave64) so every index is guaranteed in `0..count`. - Partial / non-wave-multiple groups (`[7, 3, 1]`, Wave64 `[32, 1, 1]`, Wave64 `[96, 1, 1]`) stay refused without an upper-bound proof. - Updated `tools/shader-compiler/src/tests/hlsl/host_profiles.txt` for `lanes` (its dynamic SGPR `s21` read is now masked `& 63u` instead of indexing `tb_swizzle` unbounded). ### 3. GPU check showing cases where `main` (`773278ad`) computes wrong results on hardware Added `tools/check_readlane_gpu.py` (registered as `"readlane"` in `tools/check_translator_gpu.py`, using `tools/shader-compiler/examples/readlane_probe.rs` and `tools/reference/independent-shaders/compute.cpp`). Side-by-side D3D12 readback on NVIDIA GeForce RTX 4070 SUPER (`10de:2783`, DXC `10.0.26100.0`, 18 cases / 6,912 words): - **This PR (`4a15354`)**: `PASS: 18/18 cases, 6912 words, adapter 10de:2783` - **`origin/main` (`773278ad`)**: `FAIL: 11/18 cases, 6528 words, adapter 10de:2783` — **6 cases silently compute wrong GPU outputs** and **1 case is refused**: | Case | `origin/main` (`773278ad`) on GPU | Why `main` is wrong | This PR (`4a15354`) | |---|---|---|---| | `wave32_64t_masked_31` | **32/64 words wrong** (`word 96: 0xceacd4cc != 0x7116aa5d`) | `emit_indexed_read` hardcodes `~63u`; Wave 1 (`32..63`) reads lane 31 instead of lane 63 | **64/64 exact** (`~31u`) | | `wave32_64t_and_exec_31` | **32/64 words wrong** (`word 96: 0xcbf84d32 != 0xff3481e9`) | Same hardcoded `~63u` Wave32 multi-wave cross-wave read | **64/64 exact** (`~31u`) | | `wave32_mbcnt_exec_31` | **29/32 words wrong** (`word 34: 0x01ff23d4 != 0x02ff23d4`) | `indexed_lane` emits `countbits(exec_lo & mask)` on 1-bit per-lane `exec_lo` instead of `WaveActiveBallot` | **32/32 exact** (`[WaveSize(32)]` ballot) | | `wave64_swizzle_branch_dyn_63` | **63/64 words wrong** (`word 64: 0x00000000 != 0x50e1be49`) | `GROUP_READ` writes `(!j...) ? v1 : 0u` before barrier, zeroing branch-skipped lane 63 | **64/64 exact** (unconditional publish) | | `wave64_dyn_sgpr_high_bits_47` | **64/64 words wrong** (`word 64: 0x00000000 != 0x75cfac71`) | `GROUP_READ` omits `& 63u` (`s5 = 0x102f` reads OOB `tb_swizzle[0x102f]`) | **64/64 exact** (`& 63u`) | | `wave32_64t_dyn_sgpr_31` | **64/64 words wrong** (`word 64: 0x00000000 != 0x56772646`) | `GROUP_READ` hardcodes `~63u` and omits `& 31u` | **64/64 exact** (`~31u`, `& 31u`) | | `wave64_64t_spill_and_loop_lane31` | **Refused** (`v1 lane 31 read before any v_writelane`) | `constant_reads` rejects any shader with `v_writelane_b32` or a backward branch | **64/64 exact** | ### Verification (`4a15354`) - `cargo test --release --manifest-path tools/shader-compiler/Cargo.toml`: **343 lib + 2 integration passed, 0 failed** - `cargo test --release --manifest-path runtime/dxbc/Cargo.toml`: **21 passed, 0 failed** - `cargo check --manifest-path tools/shader-compiler/Cargo.toml --all-targets`: **0 warnings** - `python -m unittest discover -s tests -p "test_translator_checks.py" -v`: **4/4 passed** - All modified Rust files stay `<= 1,200` lines (`indexed_lane.rs`: 1,038; `tests/hlsl/indexed_lane.rs`: 990) with zero inline `#[cfg(test)]` modules.
This pull request has changes conflicting with the target branch.
  • tools/shader-compiler/src/hlsl/driver/pipeline.rs
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.
git fetch -u origin '+refs/pull/185/head:github-bot/gh-185'
git switch 'github-bot/gh-185'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-185'
git switch 'github-bot/gh-185'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-185'
git switch 'github-bot/gh-185'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-185'
git switch 'main'
git merge --squash 'github-bot/gh-185'
git switch 'main'
git merge --ff-only 'github-bot/gh-185'
git switch 'main'
git merge 'github-bot/gh-185'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.