tombox-xshader: lower ds_swizzle_b32 rotate and FFT modes in compute shaders #186
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
library
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/omonkeyz--xbox-emulator!186
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/186/head"
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?
@MeNoSkills on GitHub · 2026-11-22 22:25 UTC · original
MeNoSkills:feat/ds-swizzle-rotate-fft→main· +98 −4 · 3 files · 2 commits · closed without mergingStacked on #184: this branch contains its commit (
7136d02) plus one more. Until #184 is merged the diff shows both; the change proper is the second commit,912069a, insrc/hlsl/ds_ext.rsandtests/exec_mem/ds.rs.#184 lowers the bit and quad modes of
ds_swizzle_b32in compute shaders and refuses offsets >= 0xc000 (rotate and FFT) because I had no ISA text to check them against. This adds those two modes.Semantics and where they come from
For each lane
iof a 32-lane group, the lane reads source lanej; an inactive source lane reads 0 (the same path asds_bpermute_b32).mask = offset[4:0].j = (i & mask) | (((i + amount) & 31) & ~mask), withamount = offset[9:5]whenoffset[10] = 0(left) and(32 - offset[9:5]) & 31whenoffset[10] = 1(right). Offset bits 12:11 are ignored.j = (reverse5(i) >> popcount(mask)) | (i & mask), wherereverse5reverses the low 5 bits. Offset bits 12:5 are ignored.Sources, all public:
swizzle(FFT,x)= 0xe000 | x,swizzle(ROTATE,dir,size)= 0xc000 | dir << 10 | size << 5, 0xd000 decodes as rotate), andROTATE_MODE_LO = 0xc000/FFT_MODE_LO = 0xe000in SIDefines.h.ds_pattern_rotate(delta, mask) = mask | (delta << 5) | 0xc000, called withmask = ~(cluster_size - 1) & 0x1ffor a rotate bydeltainside a cluster (emit_rotate_by_constant).The RDNA 2 guide's rotate examples disagree with its own pseudocode; I followed the pseudocode, as the measurements in those PRs do.
Change
source_laneinemit_ds_permutenow handles all four ranges (bit, quad, rotate, FFT) and the "rotate and FFT are not lowered" refusal is gone. For a mask of 0x1f, FFT is the identity, so the reversed term is omitted (a shift by 32 is undefined in HLSL).Tests
exec_mem::ds::ds_swizzle_rotate_and_fft_compute: 49 cases on 64 threads (two groups of 32) against reference functions written from the formulas above:It also pins literal values taken from the formulas: FFT 0xe000 maps lanes 0-3 to 0, 16, 8, 24; 0xe01f is the identity; FFT 0xe010 maps lanes 1, 16, 17 to 8, 16, 24; rotate left by 1 maps lanes 0-3 to 1-4, right by 1 maps them to 31, 0, 1, 2; a left rotate by 3 inside clusters of 8 maps lanes 0-7 to 3, 4, 5, 6, 7, 0, 1, 2.
All pass on WARP and on an NVIDIA RTX 4070 Ti (Windows 10 build 19045, MSVC,
TOMBOX_EXEC_HW=1). Regression runs on the RTX:--lib85,--test synthetic22,--test isa_sweep2 (541 mnemonics),--test mesh24,--test exec ds_18, all passing.pr_gate: 0 problems.Not verified
The reference functions encode the formulas above, so the tests check that the translation matches them, not AMD hardware. No title shader uses these offsets in anything I can run. Wave64 is not covered (compute here is two 32-lane groups). The pixel-shader path is unchanged and still handles only quad mode.
@omonkeyz on GitHub · 2026-11-22 23:23 UTC · original
Applied in
f6639fe(on top of #184's3828799, merged in42511d7) with your authorship kept, thanks.Pull request closed