Shaders: mask v_readlane/v_writelane lane index and bypass EXEC on writelane #1312
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/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?
Imported from Marvisak/VIctory. Originally posted by ashrafsdrop on 2026-11-24T17:20:50Z.
Summary
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.Imported from Marvisak/VIctory. Originally posted by DenRakEiw on 2026-11-24T17:26:50Z.
Review: APPROVED
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).
Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-24T17:47:52Z.
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).Imported from Marvisak/VIctory. Originally posted by ashrafsdrop on 2026-11-24T17:55:16Z.
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.Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-24T20:09:44Z.
Review: APPROVED
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.
Imported from Marvisak/VIctory. Originally posted by wbkepler on 2026-11-24T20:59:47Z.
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.
Imported from Marvisak/VIctory. Originally posted by ashrafsdrop on 2026-11-25T00:50:35Z.
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.Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T02:35:14Z.
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
Imported from Marvisak/VIctory. Originally posted by ashrafsdrop on 2026-11-25T11:30:37Z.
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).Imported from Marvisak/VIctory. Originally posted by Lyrnc on 2026-11-26T18:38:38Z.
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.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.