Shaders: mask v_readlane/v_writelane lane index and bypass EXEC on writelane #1312
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!1312
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-1312"
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?
@ashrafsdrop on GitHub · 2026-11-24 17:20 UTC · original
ashrafsdrop:shader/lane-ops-rdna2→main· +501 −10 · 6 files · 1 commits · openSummary
Resolves
VIC-BT-030andVIC-BT-031from #1249:Lane Index Masking (
VIC-BT-030):v_readlane_b32andv_writelane_b32mask the lane-select operand toS1 & 31(Wave32) orS1 & 63(Wave64).lower.rs, lane operands are now masked againstwave64 ? 63 : 31before reachingwaveReadLaneAt.i32or lane comparison, preventing DXIL undefined behavior on out-of-range lane indices. Constant lanes fold directly without emitting extra instructions.wave.rs,v_readlane_b32simulation masks constant lane indices againstwave - 1.EXEC Bypass on
v_writelane_b32(VIC-BT-031):v_writelane_b32ignoresEXECso compilers can spill SGPRs into inactive lanes of a spill VGPR across divergent branches.guard = None, preventingwrite_placedfrom suppressing spills when the target lane hasEXEC = 0.Tests:
v_readlane_and_writelane_mask_lane_and_ignore_execcovering zeroEXECmasks and out-of-range lane indices validated viadxil.dll.Verification
cargo test -p victory-shader: 121 tests passed, 0 failed.cargo clippy -p victory-shader: 0 warnings.cargo run -p xtask -- policy: 154 files ok.d192b2ae96tobf4837dc66@fuzeofficlal on GitHub · 2026-11-24 17:47 UTC · original
Reviewed
03913d9and tested Wave32 / native Wave64 / pixel-shader host-lane cases across NVIDIA GeForce RTX 5090, AMD Radeon(TM) Graphics, D3D12 WARP, anddxil.dll. Four subtleties worth addressing:v_readlane_b32in pixel/vertex shaders (MaskData::Host) gets truncated (emit/lower.rs:4207):lanebefore checkingself.mask_data == MaskData::Host && !matches!(lane, V::Const(_))clamps computed host lane indices (fromv_mbcntor a ballot mask) to& 31whennative.wave64 == false, breaking lanes32..63on 64-wide host waves. Only the non-MaskData::Host(or constant-selector) branch should masklanebyself.wave() - 1.self.write_ivsself.write(emit/lower.rs:4249):int(self, r)withself.write(inst, Reg::V(reg), r, None)skipswrite_i'sv.clamp/v.omodinteger output modifier checks;self.write_i(inst, r, None)preserves them while dropping theEXECguard.EXECread &Lanes::finishguard (ir.rs:930,structure.rs:601):ir::effectsstill appendsmask(EXEC)as an implicit read onv_readlane_b32/v_writelane_b32, andstructure::Lanes::finishstill attaches anEXECguard tov_readlane_b32(and ifexec_lois passed as an explicit source operand to spill the mask into an inactive lane,v_writelane_b32should still receiveguard = None).resource.rs:1619, 1653):Tracer::restoredandTracer::spilledcompare rawlane_of(...)without& (if self.p.wave64 { 63 } else { 31 }), so out-of-range constant selectors miss matching SGPR spill/restore pairs.Reference branch with all four fixes + Wave32/Wave64/WARP GPU readback tests:
fuzeofficlal/VIctory@d80c77a(fix/shader-readlane-writelane-exec-mask-1044).@ashrafsdrop on GitHub · 2026-11-24 17:55 UTC · original
Thanks @fuzeofficlal for the thorough review and hardware testing!
Integrated in commit d27838e:
MaskData::Hostlane selectors in pixel/vertex shaders now bypass console wave masking so 64-wide host lanes remain unclipped.v_writelane_b32viawrite_i(inst, r, None)while bypassing EXEC.v_readlane_b32/v_writelane_b32inir.rsandstructure.rs.resource.rs.cargo test -p victory-shader(126 tests passed),cargo clippy -p victory-shader --all-targets --all-features -- -D warnings, andcargo run -p xtask -- policypass with zero warnings.@wbkepler on GitHub · 2026-11-24 20:59 UTC · original
A merge note: #1336 (VIC-BT-030/031) changes the same two instructions. I compared the two diffs against
ffe310e:wave() - 1, so& 63for wave64 programs),v_writelane_b32writes throughwrite_i(inst, r, None)without the EXEC guard, and thewave.rssimulatehunk is identical.MaskData::Hostselector stays unmasked. #1336 masks it after the Host branch, which clips host lanes 32–63 when a wave32 console pixel or vertex program runs in a 64-wide host wave. That is harmless on 32-lane NVIDIA hosts but wrong on AMD.Tracer::restoredandTracer::spilledmask the selector too.For the wave64-on-32-lane case: a compute program that uses either instruction sets
console_lanes, so it declaresWaveSize(64)and is never split into two 32-lane host waves. Masking against the console wave is therefore correct. Pixel and vertex programs refuse constant cross-lane selectors incross_lane.So #1312 is the more complete version of these items. The
v_readlane_b32/v_writelane_b32arms inlower.rsand the test blocks at the end ofemit::lower::testswill conflict with whichever of the two lands second.AI-assisted review (Claude Code); checked on Windows 11 / RTX 5090.
@ashrafsdrop on GitHub · 2026-11-25 00:50 UTC · original
Thanks @wbkepler for the comparison against #1336 and detailed verification on RTX 5090.
Merged
main(42363ab) in commit31fd70eresolving all merge conflicts:MaskData::Hostlane selectors for 64-wide host pixel/vertex waves.v_readlane_b32/v_writelane_b32path alongside the newlast_guardcache.HostShaderbindless heap/memory fields.Verification on Windows 11 x64 (Rust 1.98.1 MSVC):
cargo test -p victory-shader: 252 passed, 0 failed.cargo clippy -p victory-shader --all-targets --all-features -- -D warnings: 0 warnings.cargo run -p xtask -- policy: 182 files ok.@Marvisak on GitHub · 2026-11-25 02:35 UTC · original · edited 2026-11-26 07:20 UTC
Automated triage for the maintainers.
Merge candidate. The new head is one rebased commit with the same content as before:
mask_laneinemit/lower.rsmasks thev_readlane_b32/v_writelane_b32selector to the console wave. A computedMaskData::Hostselector stays unmasked.v_writelane_b32writes throughwrite_i(inst, r, None).ir::effects) and thestructure::Lanesguard are dropped.wave::simulateandresource::Tracermask the selector too.This matches the RDNA2 ISA: both instructions ignore EXEC. The wave32/wave64 readback tests in
valu_tests.rsnow skip cleanly when no device is present. Note:lower.rsends at 523,623 bytes, about 660 under the policy's 512 KiB limit. The PR still competes with #1336 for the same arms.CI: passing.
Generated by Claude Code
@ashrafsdrop on GitHub · 2026-11-25 11:30 UTC · original
Updated in head
d192b2a:Rebase & Adapter Deduplication
origin/main.all_wave_hosts,open_wave_adapter,AdapterHost) and standardized onhost::Host.CI Runner Graceful Fallback
compute_pipelinewave checks skip gracefully when the host device or WARP does not support Wave32/Wave64, eliminating the panic on GPU-less CI runners.buffer_store_dword_offen) to set theoffenbit (w0bit 12), ensuring per-lane offset buffers index accurately during execution.Verification
cargo test -p victory-shader(252 passed, 0 failed, 3 ignored).cargo clippy -p victory-shader --all-targets --all-features -- -D warnings(clean).cargo run -p xtask -- policy(182 files ok).@DenRakEiw on GitHub · 2026-11-24 17:26 UTC · original · approved these changes
Tested head
542b36e(fast-forward onmainffe310e) on Windows 11 x64 (Rust 1.98.1 MSVC):cargo test -p victory-shader emit::lower: 12 passed, 0 failed (includingv_readlane_and_writelane_mask_lane_and_ignore_exec)cargo clippy -p victory-shader --all-targets: 0 warningscargo xtask policy: okClean fix masking
v_readlane/v_writelanelane indices and bypassing EXEC onv_writelane. Approving.AI-assisted (Gemini 4 Neon).
@catminou4 on GitHub · 2026-11-24 20:09 UTC · original · approved these changes
Tested locally on macOS arm64 (rustc 1.98.1): PR head merged cleanly into current main (
ffe310e), cargo test -p victory-shader --locked → 99 passed, 0 failed. Execution/valu tests are #[cfg(all(test, windows))] and only run on Windows; macOS covers lowering/structure/IR unit tests.Masks the v_readlane/v_writelane lane index by wave size and bypasses EXEC for writelane; adds wave32/wave64 lowering+validation tests and host-lane tests across backends including WARP.
@Lyrnc on GitHub · 2026-11-26 18:38 UTC · original
Wave64 hardware check of
bf4837d.Checked against a hardware table measured on an AMD Radeon iGPU (gfx1036, RDNA 2, Ryzen 7 9800X3D) in native
wave64: 64 cross-lane instructions x 8 EXEC masks (all, lo32, hi32, all but lane 0, alternate lanes, lane 40 alone,
lanes 31+32, a sparse mask). Each case was assembled with the same assembler, run through VIctory as a wave64
compute program of 64 threads on the same Radeon through D3D12 (WaveSize 64, dxil.dll validated), and all 64
lanes compared with the hardware. EXEC is narrowed two ways: straight-line (
v_cmpx_ne_u32, lowered with a laneguard) and branched (
s_and_saveexec_b64+s_cbranch_execz, a DXILif). Windows 11, Rust pinned, debug.No game files were used.
Tested (merged with #2830 onto main
63bcca4; Radeon, wave64):v_writelane_b32 d, s21, Lfor L = 5, 33, 63 is exact in all 24 cases with this PR.On main, 14 of 24 are wrong: every case whose lane is outside EXEC keeps its old value (lo32 / lane 33: hardware
0x777, main 0xdead0021; hi32 / lane 5: hardware 0x777, main 0xdead0005).
the write, so the bypass cannot reach it. (#320's console flow gives 24/24 there.)
v_readlane_b32(lanes 0, 31, 32, 40, 63): unchanged, exact under straight-line narrowing.Not tested: NVIDIA, out-of-range lane selectors, the title.
AI use: Claude Code (Claude Opus 5.5) built the harness and the hardware table, ran them on the GPU above and wrote this report; the numbers come from those runs.
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.