Shaders: lower ds_permute_b32 and ds_nop #2501
No reviewers
Labels
No labels
AMD
audio
bug
confirmed
crash
cutscene
dlss
documentation
duplicate
enhancement
fixed-on-main
frame-generation
good first issue
help wanted
input
INTEL
invalid
lighting
linux-proton
memory
needs-info
needs-logs
needs-rebase
NVIDIA
performance
pr-diagnostics
pr-docs
pr-feature
pr-fix
pr-performance
pr-refactor
pr-tests
question
RAYTRACING
rendering
report
series-s
shaders
spam
startup
upstream
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/trustno1-coder--VIctory-NVIDIA!2501
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2501"
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?
@fuzeofficlal on GitHub · 2026-11-29 13:42 UTC · original
fuzeofficlal:fix/shader-ds-permute-b32→main· +735 −2 · 3 files · 1 commits · merged 2026-11-30 14:12 UTCProblem
gfx10::opcodes,gfx10::fields, andLower::instalready recognizeds_permute_b32(0x0b2) andds_nop(0x014), whereasLower::ds(crates/victory-shader/src/emit/lower.rs) only lowersds_swizzle_b32andds_bpermute_b32before requiring an LDS allocation and falling through toErr("an LDS operation"). Neither instruction accesses physical LDS memory.Changes
ds_nop(0x014): ReturnOk(())as a no-op without requiring allocated LDS, and excludeds_nopfromhas_memory_or_export_side_effectandsplit_ldsbarriers.ds_permute_b32(0x0b2): Lower forward cross-lane scatter within each 32-lane sub-vector (0..31, and32..63independently in Wave64 per RDNA2 ISA §10.4.4, matchingself.s.wave_size == Some(64)so split Wave32 halves on NVIDIA also work without out-of-bounds lane reads) usingwaveActiveBallotand uniform-lanewaveReadLaneAt: active lanes routevdatato((vaddr + offset) >> 2) & 31within their half, unwritten active destinations read0, and inactive destination lanes retain their priorvdstvalue.emit::ds_permute_testscovering Wave32 bijection/unaligned/offset/partial-EXEC/collision arbitration, Wave64 32-lane half isolation, zero-LDSds_nopexecution, and non-compute stage refusal.Verification
cargo test --locked -p victory-shader --lib emit::ds_permute_tests:: -- --test-threads=1— 4/4 pass on RTX 5090, AMD iGPU, WARP, anddxil.dll.cargo test --locked -p victory-shader --lib emit::lds::— all pass.cargo clippy --locked -p victory-shader --all-targets— 0 new warnings in touched files.cargo run --quiet --locked -p xtask -- policy --staged— pass.@Lyrnc on GitHub · 2026-11-30 06:11 UTC · original
Checked
ds_permute_b32against a Radeon gfx1036 (RDNA 2) running the same kernels natively in wave32 and wave64, and ran the translator's output for main and for this PR on an RTX 5080 and on that Radeon through D3D12.Setup
mainat41adb551with this PR's head (63e4858) merged locally, no conflict. The victory-shader test binary was built from that merged tree (own tree and target directory).o32) or one wave64 (o64). Data = 0x100 + 3 * lane; outputs v10.. stored per lane.super::emitwith a 32-lane host (5080 and Radeon) and with 64 host lanes (Radeon), andsuper::folded, each throughdxil.dllvalidation (VICTORY_ADAPTER=radeonfor the Radeon).Cases (one
ds_permute_b32per output)offset:4ds_bpermute_b32of lane ^ 33 and of the reversal (control)ds_nop(control)permute_cmpx(wave64): rotate, reverse, lane ^ 33 and "all to lane 5" under a partial EXEC made byv_cmpx_ne_u32from a per-lane table (the same 64-bit mask), with v18..v21 preset to 0xDEAD0000 | lane.Results (values that differ from the gfx1036)
o32/permute(15 outputs)an LDS address)o64/permute(15 outputs)an LDS address)o64/permuteLDS the program does not allocate)o64/permute_cmpx(4 outputs)o64/permute,permute_cmpxsuper::folded, both cardsds_(b)permute, fold.rs)The 64-bit forms translate for a 32-lane host as wave 32 (PSV0) and for the 64-lane Radeon as wave 64.
Verdict: the lowering matches the gfx1036. Every output of every case is exact in wave32 and in wave64, on both cards and both host widths, wherever EXEC comes from compares: the per-half routing, the highest lane winning a collision, 0 in active lanes nobody writes, the old value in lanes outside EXEC, the dropped low address bits,
offset:, andds_nop.The 44 values in
o64/permuteare not the permute's. There EXEC iss_mov_b64 exec, s[30:31]from twos_mov_b32constants (lo 0x5555F00F, hi 0x0FF0AAA5), and in the upper half the translation's active lanes follow the low dword's bits instead of the high dword's. Lane 33 (outside EXEC) is written with 0x160 where the gfx1036 keeps 0xDEAD0021; lane 53 (inside) keeps 0xDEAD0035 where the hardware writes 0x19C; the other differing lanes get their data from a sender whose EXEC bit is taken the same wrong way. With that mask the results are exactly what the low dword predicts. The same happens without any LDS instruction on main:s_mov_b64 exec, s[30:31]with s31 = 0, then av_mov_b32 v41, 7, writes 7 into lanes 32..63 withsuper::emiton both cards and with 64 host lanes (the gfx1036 leaves them 0). So does ans_andn2_saveexec_b64of S0 = (lo 0xFFFF0000, hi 0x0000FFFF) with EXEC on lanes 0..31: the new EXEC's high dword comes out 0xFFFF0000 (from S0's low dword), the gfx1036 0x0000FFFF; the folded form is exact there. Compilers build EXEC from compares, aspermute_cmpxdoes, and that form is exact here.Not covered: the folded form still refuses
ds_permute_b32(andds_bpermute_b32) infold.rs; this PR does not touch it.(The upper-half value from EXEC built out of two
s_mov_b32constants looks like what #3402 fixes: "a lane mask written a dword at a time keeps its high dword".)AI use: Claude Code (Claude Opus 5.5) ran the oracle and host cases and wrote this comment.