Shaders: v_writelane_b32 obeys EXEC guard and v_writelane_b32/v_readlane_b32 do not mask lane selectors (fix on a fork) #1044
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#1044
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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?
@AscilCH on GitHub · 2026-11-24 15:15 UTC · original
Pull requests are currently restricted to collaborators, so I am sharing this bug report and verified fix from a clean fork branch off
main(ffe310e).github.com/AscilCH/VIctory@79f162d899Bug
On RDNA2 (GFX10.3),
v_writelane_b32(VOP3 0x361) andv_readlane_b32(VOP3 0x360) both ignore theEXECmask and wrap theirsrc1lane selector modulo the wavefront size (src1[4:0]/& 31in Wave32,src1[5:0]/& 63in Wave64).Two issues existed on
main(ffe310e):EXEC guarding drops
v_writelane_b32writes to inactive lanes:crates/victory-shader/src/ir.rs:931-935unconditionally adds implicitEXECreads (r.extend(mask(EXEC))) for all vector instructions, includingv_readlane_b32andv_writelane_b32.crates/victory-shader/src/structure.rs:599-606attaches anEXECguard tov_writelane_b32wheneverEXECis narrowed without a branch (includingEXEC == 0, or whenexec_lois itself passed explicitly assrc0to spillEXECinto a VGPR lane).crates/victory-shader/src/emit/lower.rs:4217-4232writesv_writelane_b32's result viaint(self, r)(which forwardsguardtowrite_i), wrapping the write inselect(guard, r, old)so writes targeting inactive lanes are silently discarded.Unmasked lane selectors:
crates/victory-shader/src/emit/lower.rs:4205-4232passes rawsrc1directly intoread_lane(a, lane)(dx.op.waveReadLaneAt) andcmp(EQ, me, lane)without masking towave_size - 1. Anysrc1 >= wave_size(including negative or wrapped values such as inline32or-1, or computed SGPR indices) either dropsv_writelane_b32writes or passes an out-of-range lane index toWaveReadLaneAt.Reproduction (Before Fix)
With synthetic Wave32 RDNA2 compute shaders lowered to DXIL and executed on hardware (NVIDIA GeForce RTX 3050 6GB Laptop GPU, driver
32.0.16.1742, Windows 11, Windows SDKdxil.dll10.0.26100.0):EXEC(lanes16..31active),v_writelane_b32 v1, 0xcafebabe, 0:lane
0stayed0x00001000instead of0xcafebabe(while controlv_add_nc_u32correctly obeyedEXECon lanes16..31).v_writelane_b32with inline32-> lane0and-1-> lane31):lanes
0and31stayed0x00004000and0x0000401finstead of receivings0(0x13579bdf) ands1(0x2468ace0).Fix
crates/victory-shader/src/ir.rs: Skip implicitr.extend(mask(EXEC))forv_readlane_b32andv_writelane_b32while keeping the destination VGPR read for untouched lanes and preserving explicitexec_losource operands.crates/victory-shader/src/structure.rs: Keepv_readlane_b32andv_writelane_b32unguarded (None) even ifexec_loappears as an explicit operand.crates/victory-shader/src/emit/lower.rs:Lower::mask_lane()to mask console lane selectors byself.wave() - 1(0x1Fin Wave32,0x3Fin Wave64), folding constants so DXIL never receives out-of-range lane constants (and emitting zero extra ops for in-range constants).mask_lane()tov_readlane_b32(on the console-lane path, leaving dynamicMaskData::Hosthost-lane reads untouched) andv_writelane_b32.v_writelane_b32to write viaself.write_i(inst, r, None).ir::tests::readlane_and_writelane_do_not_read_exec_implicitly(Wave32 & Wave64)structure::tests::readlane_and_writelane_are_unguarded_under_narrowed_execemit::lower::tests::writelane_and_readlane_lower_and_validate_in_wave32_and_wave64(Wave32 & Wave64 +dxil.dllvalidation)emit::valu_tests::v_writelane_b32_ignores_exec_and_masks_lane(narrowedEXEC+ controlv_add_nc_u32,EXEC == 0, wrapped dynamic selectors32/37/u32::MAX/0x1000_001F, and explicitexec_lospill to inactive lane0)emit::valu_tests::v_readlane_and_writelane_wrap_constant_lane_selector(inline32and-1on bothv_writelane_b32andv_readlane_b32)valu_tests.rsenumerates SM 6.6 adapters supportingWaveSize(32), so hardware execution runs on capable GPUs while WARP-only CI (wave size 4) still runs fulldxil.dllvalidation without failing onCreateComputePipelineState.Verification
Tested on Windows 11, NVIDIA GeForce RTX 3050 6GB Laptop GPU (driver
32.0.16.1742), WARP, and Windows SDKdxil.dll(10.0.26100.0):rustfmt --edition 2024 --checkonir.rs,valu_tests.rs, and modified lines ofstructure.rs/lower.rs: cleancargo xtask policy:154 files okcargo clippy --workspace --all-targets --locked -- -D warnings: cleancargo clippy --workspace --all-targets --all-features --locked -- -D warnings: cleancargo test -p victory-shader --locked -- v_writelane_b32_ignores_exec_and_masks_lane v_readlane_and_writelane_wrap_constant_lane_selector --nocapture --test-threads=1: 2 passed (RTX 3050 +dxil.dll)VICTORY_WARP=1 cargo test -p victory-shader --locked -- --test-threads=1: 125 passed, 0 failed, 1 ignoredcargo test --workspace --locked -- --test-threads=1 --skip v_med3_f32_matches_rdna2_with_nan: 346 passed, 0 failed, 6 ignored (v_med3_f32_matches_rdna2_with_nanfails pre-existing on Adapter 0 Intel UHD Graphics and passes underVICTORY_WARP=1)@pickles976 on GitHub · 2026-11-24 15:17 UTC · original
Divergence report from the sibling runtime (ivall/xcl) — our emitter encodes the opposite assumptions on both axes of your finding, so your test matrix settles a second project, for free:\n\n- EXEC: our
v_writelane_b32emits an ungatedif (lane_id == (b & wmask)) v = a;with an inline comment asserting "ignores EXEC" (emit.rs:3534area) — if your rows show EXEC-gated writes on gfx103x, that comment is a load-bearing wrong belief.\n- Lane masking: we mask the selector —b & wmask(31/63) on both readlane and writelane — so lane 33 on a 32-lane wave wraps to lane 1; you claim the hardware does not mask. Those two behaviors differ observably exactly in your unmasks-the-selector rows: a selector with high bits set must hit the wrap on our side and (per you) nothing or lane-clamped on hardware.\n\nIf your harness (GPU + WARP rows) is still taking shape, two rows would close both questions: ① writer lane EXEC-off, selector = a lane whose EXEC is on, read back the target — does it change?; ② selector =wave_size + kwith distinct low/high half contents — wrap, no-op, or clamp? We have no gfx103x box here, so we would adopt your measured values wholesale with attribution, same as we did for the 16-bit-compareop_selquirk (#926 → our #1293). Posting before you land the fix so both projects converge on one measured table rather than two guessed ones.@DrDarkDK on GitHub · 2026-11-24 15:22 UTC · original
I compared
79f162dwith #320 atcbcef55using two synthetic Wave32 shaders. Both narrow EXEC to lanes 16–31 and write0x12345678to inactive lane 0. The second insertss_cbranch_execzbefore the write. Since lanes 16–31 are still active, the guest wave should reach the write.79f162d)cbcef55)0x123456780x00001000s_cbranch_execz0x000010000x12345678The active-lane control wrote the expected value on both branches. RTX 4070 Ti and Radeon iGPU agreed. This gives two cases to retain when integrating the fixes. The test ran translated DXIL on native Windows.
AI-assisted with Codex.
@AscilCH on GitHub · 2026-11-24 15:25 UTC · original
@pickles976 Quick clarification — the issue title describes VIctory's current bug on
main, not RDNA2 hardware behavior. Our fix (79f162d) agrees withivall/xclon both axes per the GFX10.3 ISA spec:v_writelane_b32andv_readlane_b32ignoreEXEC.src1modulo wavefront size (src1 & 31in Wave32,src1 & 63in Wave64).(Note also that our tests run translated DXIL on D3D12 hosts, not bare-metal RDNA2 hardware, so they verify the translator matches the GFX10.3 ISA rather than probing silicon directly.)
@DrDarkDK Thanks for testing
79f162dside-by-side with#320on RTX 4070 Ti and Radeon iGPU! That table pins down how the two changes complement each other:EXEC(no divergent branch): stays in per-lane mode, where#320does not activateCONSOLE_FLOWand still guardsv_writelane_b32;#1044fixes that path as well as lane-selector masking (mask_lane) in per-lane lowering.s_cbranch_execz(divergent branch): per-lane DXIL control flow skips the branch body on inactive lane 0 altogether, which is what#320's wave-uniformCONSOLE_FLOWsolves.Agree both cases are worth keeping when integrating the two fixes.
@Marvisak on GitHub · 2026-11-25 06:57 UTC · original · edited 2026-11-25 09:58 UTC
Automated triage for the maintainers.
Confirmed on
main. Incrates/victory-shader/src/emit/lower.rs, thev_writelane_b32arm compareslane_index()with the rawsrc1and writes throughint(self, r), which applies the instruction's EXEC guard. Thev_readlane_b32arm passes the rawsrc1toread_lane. Neither masks the selector to the wave size, and the lane write doesn't bypass EXEC as the ISA says. Open PRs #1312 ("mask v_readlane/v_writelane lane index and bypass EXEC on writelane") and #1336 (which includes readlane/writelane semantics) carry this, so review can continue there.One caution from DrDarkDK's comparison: with
s_cbranch_execzbefore the write,79f162dand #320 (lane reads and writes in the console flow) give opposite results. A fix should cover both cases.Generated by Claude Code
@StExpeditus on GitHub · 2026-11-25 09:35 UTC · original
Validated the fork branch on Windows 11 Pro 26200 (Intel Core i5-14600K, RTX 5060 Ti, driver 621.24, Rust 1.98.1 MSVC), commit
79f162d:cargo test -p victory-shader --locked --no-fail-fast-> 125 passed, 0 failed, 1 ignored. Synthetic tests only, no game files.@StExpeditus on GitHub · 2026-11-25 09:38 UTC · original
Addendum: this branch is far behind current main (the
victory-shaderdelta is 33 files, ~16.4k lines), so the run above is the branch as-is on its old base; it needs a rebase before a clean cherry-pick.