Shaders: ds_swizzle_b32 offsets from 0xC000 are the rotate and FFT modes #606
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!606
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-606"
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?
@upipibi on GitHub · 2026-11-24 05:27 UTC · original
upipibi:fix/ds-swizzle-rotate-fft→main· +238 −6 · 2 files · 3 commits · openTwo commits on
maind2a4bae:3ad06fb(the two modes),da1a1f7(rotations with a mask).What
ds_swizzle_b32incrates/victory-shader/src/emit/lower.rstook bit 15 of the offset as "quad permutation" for every offset from 0x8000. Offsets from 0xC000 are two other modes, and were lowered as a quad permutation of offset[7:0]:(reverse5(i) >> popcount(mask)) | (i & mask), mask = offset[4:0].((i & mask) | ((i + rot) & ~mask)) & 31, rot = offset[9:5], negated when offset[10] is set, mask = offset[4:0]. Bits 11 and 12 are not read.Both modes stay inside the lane's group of 32 (
i & 32is kept), like the and/or/xor mode. Offsets below 0xC000 are unchanged. As before, reads of invalid lanes are not zeroed.Why
RDNA2 ISA (30-November-2020), 12.13.1 "DS_SWIZZLE_B32 Details", pp. 207-209:
Pseudocode, same section:
Rotations with a mask. The ISA's two worked examples for mask 1 disagree with this pseudocode (rotate left by 1: the pseudocode makes lanes read 0, 3, 2, 5, ...; the example lists 1, 0, 3, 6, ...). The first version of this PR refused that case. @Lyrnc then measured it on RDNA2 hardware (gfx1036, comment below): the pseudocode is what the hardware does, for all 2048 offsets 0xC000-0xC7FF in wave32 and wave64, bits 11 and 12 are ignored, and the FFT formula matches all 37 offsets tried.
da1a1f7lowers masked rotations accordingly.Tests
Four tests in
valu_tests.rs, from hand-written instruction words: one 32-thread wave32 compute program whose lanes hold 1..=32 (the input of the ISA's examples), swizzle, and store what they read.build_valu_csis split so that the lowering part (build_cs) takes the thread count; modules go throughdxil.dllvalidation (the Windows SDK's) as before.Where the expected values come from:
ds_swizzle_fft_modeds_swizzle_rotate_modeds_swizzle_masked_rotationsds_swizzle_basic_modescargo test -p victory-shader -- --test-threads=1:maind2a4bae: 69 passed.offset 0xe000: left[1, 1, 1, 1, 5, 5, 5, 5, 9, ...], right[1, 17, 9, 25, 5, 21, 13, 29, 3, ...]offset 0xc020: left[1, 1, 3, 1, 5, 5, 7, 5, ...], right[2, 3, 4, ..., 32, 1]3ad06fb: 72 passed, 0 failed.da1a1f7: 73 passed, 0 failed.The swizzle tests need a host with 32-lane waves (
WaveSize(32)). They ran on the GPU; WARP refuses the pipeline and is skipped by name, so on a WARP-only runner they pass without checking anything.cargo xtask policy: ok (151 files).cargo build -p victoryandcargo build -p victory --profile diag --features diagnostics: both build;cargo clippy -p victory-shader --testsadds no warnings.GPU: NVIDIA RTX 3070, driver 616.56, Windows 11. These runs show what the translated DXIL computes; that the lanes are the hardware's rests on the ISA and on Lyrnc's RDNA2 measurement.
Not tested here: wave64 programs, mesh and pixel stages (cross-lane swizzles are refused there as before), a title's shaders. I know of no compiler that emits these two modes, so this is correctness for legal ISA, not a known in-game fix.
No game files were used. AI-assisted (Claude Code).
🤖 Generated with Claude Code
@Lyrnc on GitHub · 2026-11-24 05:49 UTC · original · edited 2026-11-24 05:52 UTC
Hardware answer to the open question (the masked rotation), plus a check of both modes: on RDNA2 the ISA's pseudocode is what the hardware does; the mask = 1 example is not.
Setup. AMD Radeon iGPU of a Ryzen 7 9800X3D, gfx1036 (RDNA2), AMD driver 32.0.21042.62, Windows 11 Pro 26200. Hand-written
ds_swizzle_b32 vN, v4 offset:<raw 16-bit value>in a HIP kernel (assembled by the AMD driver's amd_comgr), one wave, laneiholdingi + 1, so each output names its source lane. Wave32 and wave64 kernels. RDNA2 desktop silicon, not the console's. No game data.0xC000-0xC7FF: every mask, amount and direction (bits 11-12 clear)j = ((i & mask) | ((i + rot) & ~mask)) & 31,rotnegated when bit 10 is set, thenj |= i & 320xE000-0xE01F,0xE3E0,0xE800,0xF000,0xFFF0,0xFFFF(reverse5(i) >> popcount(mask)) | (i & mask) | (i & 32)Rotate left by 1 with mask 1 (
0xC021), the lane each lane reads:0, 3, 2, 5, 4, 7, 6, 9, 8, ..., 28, 31, 30, 1That is the pseudocode's list, not the example's
1, 0, 3, 6, .... Two more, for a test if you want one: right by 1 with mask 1 (0xC421) gives30, 1, 0, 3, 2, 5, 4, ..., and left by 1 with mask 3 (0xC023) gives0, 1, 2, 7, 4, 5, 6, 11, ....Against this PR:
0x1f(no swizzle) and0xFFF0=0x10.j = ((i & mask) | ((i + rot) & ~mask)) & 31plus the group bits, instead of refused. I can run a GPU check of that if you add it.The raw lane lists (JSON, every offset above, both wave sizes) are available if useful.
AI use: Claude Code (Claude Opus 5.5) wrote the probes, ran them on the GPU above and drafted this comment; the numbers come from the hardware run.
@upipibi on GitHub · 2026-11-24 06:05 UTC · original
@Lyrnc thank you, that settles the one thing this PR had to leave open, and it is a far better check than anything I could run here.
Pushed
da1a1f7on top of3ad06fb:j = ((i & mask) | ((i + rot) & ~mask)) & 31,rotnegated when offset[10] is set, plus the lane's group bits (i & 32). Bits 11 and 12 were already not read.ds_swizzle_masked_rotationswith your lane lists as the expected values, citing your comment as the source:0xC021(0, 3, 2, 5, 4, ..., 28, 31, 30, 1),0xC421(30, 1, 0, 3, 2, 5, 4, ...),0xC023(0, 1, 2, 7, 4, 5, 6, 11, ...), and0xD821(bits 11 and 12 set, same as0xC021). You posted the first and last entries of each list; the entries between them in the test follow the formula you report as matching 2048/2048.a masked ds_swizzle rotationno longer exists.On the RTX 3070 (driver 616.56):
cargo test -p victory-shader -- --test-threads=1gives 73 passed, 0 failed (72 before this commit);cargo build -p victory, the diag build and clippy are clean. That only shows the translated DXIL computes those lists; your run is what says they are the hardware's.If you still have the probe set up, would you run your GPU check against
da1a1f7? What I cannot see from here is a wave64 program (the lowering keepsi & 32and takes everything else fromi & 31, as your table says the hardware does, but my tests are wave32 only).AI-assisted (Claude Code).
@Lyrnc on GitHub · 2026-11-24 06:18 UTC · original
@upipibi ran it against
da1a1f7, including the wave64 case. The translated programs reproduce the hardware lane lists exactly, wave64 included.What ran.
da1a1f7merged withmaind2a4bae, plus #94 so the test host can pick the adapter (VICTORY_ADAPTER). A local test (not pushed) uses yourswizzle_32program shape withthreads= 32 or 64, setswave64inbuild_csfor the 64-thread run, and compares each lane's result with the list measured on the gfx1036 hardware (the probe from my comment above, laneiholdingi + 1). There are 115 offsets: rotations with masks 0, 1, 2, 3, 5, 0x10, 0x15 and 0x1F at amounts 0, 1, 5, 17 and 31 in both directions, all 32 FFT masks,0xFFF0, and0xD821/0xC821(bits 11-12 set).The parameter is incorrect), no 64-lane wavesSo in wave64 every lane 32-63 reads within its own half, as on the hardware. Your four
ds_swizzle_*tests also pass on both adapters (Windows 11 26200, RTX 5080 driver 610.88, iGPU driver 32.0.21042.62, debug).AI use: Claude Code (Claude Opus 5.5) wrote the local test, ran it on both GPUs and drafted this comment.
@slint6614-dev on GitHub · 2026-11-24 10:16 UTC · original
AMD hardware check, Windows 11, Adrenalin driver: RX 9070 (RDNA4) and Ryzen 9600X iGPU (RDNA2, gfx1036), each picked as the hardware device of
run_cases(local adapter-selection patch, not part of this PR);cargo test -p victory-shader --release valu_testsat the PR head. Negative control: the PR's non-test files reverted to its merge base, its new tests kept.ds_swizzle_*tests pass on both AMD GPUs.ds_swizzle_fft_mode,ds_swizzle_rotate_modeandds_swizzle_masked_rotationsfail on both GPUs without the fix, so the tests do catch the change on AMD hardware.ds_swizzle_basic_modesalso passes without the fix (those modes already worked on main), as expected.@upipibi on GitHub · 2026-11-24 10:45 UTC · original · edited 2026-11-24 13:07 UTC
Rebased onto
mainffe310e(conflicts only in appended tests invalu_tests.rs; the change itself is unchanged) and pushed: new head95b58c1.cargo test -p victory-shader -- --test-threads=1gives 124 passed, 0 failed, 1 ignored on an RTX 3070 (driver 616.56), andcargo build -p victoryplus the diag build are clean. Thanks @slint6614-dev for the AMD runs with the negative control.AI-assisted (Claude Code).
@bvtterbroot on GitHub · 2026-11-24 17:54 UTC · original
AMD check at
95b58c1(baseffe310e), on an RDNA3 and an RDNA2 GPU:run_caseswith a local adapter-selection patch that is not part of this PR. WARP runs in each pass as well.cargo test -p victory-shader -p victory-gpu --locked: 174 passed, 0 failed, 2 ignored, on both GPUs. That includes its 4 new tests (ds_swizzle_basic_modes,ds_swizzle_fft_mode,ds_swizzle_masked_rotations,ds_swizzle_rotate_mode).Synthetic tests only, no game files. Tested with AI assistance (Claude Code).
@upipibi on GitHub · 2026-11-24 23:35 UTC · original · edited 2026-11-25 22:08 UTC
Rebased again 22:08Z onto
mainf3578e3(now09f5e93). The only conflict was invalu_tests.rs: main's newv_mul_legacy_f32_treats_denormals_as_zeroand this PR'sds_swizzle_masked_rotationswere added at the same place; both are kept. RTX 3070 (driver 616.56):cargo test -p victory-shader --lib -- swizzle mul_legacy --test-threads=1: 7 passed, 0 failed; clippy--all-targets -D warningsclean. (cargo fmt --checkreports lines elsewhere invalu_tests.rsand inbitcode.rsthat main has as well; none in this PR's lines.)Rebased onto
main70564ae(now05babc0). The only conflict was invalu_tests.rs, next to the new FSPX / dot4 tests.try_build_valu_csnow returns aResult, so the swizzle tests'build_csdoes too (third commit). RTX 3070 (driver 616.56) plus WARP: the fourds_swizzle_*tests pass;cargo test -p victory-shader --lockedgives 210 passed, 3 failed, and the 3 are #1744's NVIDIA heap-cap failures onmain. Thanks to bvtterbroot for the RDNA3 / RDNA2 check of the previous head.@Marvisak on GitHub · 2026-11-25 01:28 UTC · original · edited 2026-11-26 01:23 UTC
Automated triage for the maintainers.
Merge candidate (re-checked on
09f5e93). This push is a rebase ontomain, and the lowering is unchanged. Incrates/victory-shader/src/emit/lower.rs,ds_swizzle_b32offsets from 0xE000 use FFT order: the lane's 5 index bits are reversed (Bfrev>> 27), shifted right bypopcount(mask), and the masked bits are ORed back in. Offsets 0xC000-0xDFFF rotate:(i & mask) | ((i + rot) & ~mask & 0x1F), withrotnegated when bit 10 is set. Both keep the lane's group of 32, as in the RDNA2 ISA pseudocode quoted in the PR. Offsets below 0xC000 take the old path. The new commit only adaptsbuild_cs/swizzle_32invalu_tests.rstomain'sResult-returningtry_build_valu_cs.Note: the swizzle tests are skipped on hosts without 32-lane waves.
CI: passing (
check).Generated by Claude Code
@fuzeofficlal on GitHub · 2026-11-26 01:21 UTC · original
Code review and RTX 5090 (Wave32) + WARP + DXIL verification at head
09f5e93dfd36merged cleanly ontomain(63bcca43c6a0;emit/lower.rs=522,681B,1,607B under the 512 KiB cap):crates/victory-shader/src/emit/lower.rs:3193-3241):offset >= 0xE000) and rotate (0xC000..0xE000) cleanly from quad-perm (!(fft || rotate)), computes intra-32-lane indices (i = lane & 0x1F,group = lane & !0x1F) compatible with both Wave32 and Wave64 (bit-reverse via DXIL op 30 for FFT;offset[9:5]shift +offset[10]direction + mask preservation for rotate), and preserves inactive-source zeroing throughsrc_lane_active.dxil.dll10.0.26100.0,VICTORY_D3D12_DEBUG=1, Rust 1.98.1):cargo xtask policy:191 files ok;cargo clippy -p victory-shader --all-targets -- -D warnings(default +--features diagnostics): 0 warningsemit::lower::tests(33/33),ds_swizzle(5/5 on RTX 5090 Wave32),emit::crosslane_tests(5/5 on both RTX 5090 and WARP), andemit::semantics_tests(34/34 on both RTX 5090 and WARP, 1 ignored) all passed.LGTM.
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.