Recompiler: swizzled buffer V#s address records in dword-interleaved groups #2325
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
goal:world-load
good first issue
help wanted
invalid
keep-open
off-goal
question
stale
test-only
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/xcl-dev--xcl!2325
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2325"
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-25 14:33 UTC · original
upipibi:buffer-swizzle→main· +394 −31 · 3 files · 4 commits · openDepends on: #2066. Stacked on it: the branch is #2066's commit
b81d47c, then this PR's commits:4ee401e(the swizzle), a merge ofmain06c9f550that adapts the direct path to main's 32-bit window carry (547886ca), and68b6034(a test for swizzled accesses across memory windows).A V# with its swizzle bit set (word 1 bit 31) and a nonzero stride interleaves records in dword groups. XCL addressed every buffer access linearly, as
offset + stride * index, on both translators. That includes the per-lane index #2066 adds for ADD_TID. So a swizzled access read and wrote the wrong bytes: with stride 16 and ADD_TID, lane 1 reads byte offset 16 instead of 4.The rule, as boykopovar/AnyPS5#21970 measured it on gfx1036 (RDNA2, compute loads and stores, through HIP; that PR is still open):
step = 8 << INDEX_STRIDE(word 3 [22:21]).((index / step) * stride + (off & ~3)) * step + (index % step) * 4 + (off & 3), plus SOFFSET unscaled. Hereoffis the VGPR offset plus the instruction offset. ELEMENT_SIZE has no effect.off + 4k. With IDXEN the dwords are contiguous from the first one's address.What is in it
recomp/emit.rs(HLSL path):Em::buf_relcomputes the relative address, including the 64-bit windowed form. Loads, stores, atomics and the D16 forms use it, and multi-dword accesses space their dwords by the swizzle step.dxil/lower_mem.rs(direct path):Lw::buf_addr, the same rule. A multi-dword load without IDXEN keeps its single vector load when the V# is linear, and does a guarded per-dword load when it's swizzled. The V# is uniform, so only one of the two runs.dxil/lower_mem.rs, windowed form:buf_addrcomputes the high half of the swizzled (or linear) offset with 32-bit carries, as main'swindow_atdoes since547886ca, and adds it to the V# base, so the window is chosen from the swizzled offset and the direct path keeps no 64-bit integer ops.dxil/lower_window.rsis main's, unchanged.recomp/tests.rs:gpu_buffer_swizzle_window_from_swizzled_offset, three swizzled loads with two memory windows: an offset carry from window 0 into window 1, anindex * strideproduct that carries into window 1, and a product past 2^32 that must read 0.recomp/tests.rs: six GPU tests (gpu_buffer_swizzle_*). They cover ADD_TID (lane 1 at +4, not +16), INDEX_STRIDE 3, IDXEN with a vindex and DWORDX2, DWORDX2 without IDXEN, a two-dword store, and controls (SWIZZLE_EN=0 stays linear; SWIZZLE_EN=1 with neither IDXEN nor ADD_TID is linear too).Tested
At
68b6034(this tree is main06c9f550+ #2066 + this PR), RTX 3070 (616.56), Windows 11, debug:gpu_buffertests, 5 fail (the five swizzled cases), and 2 pass (#2066's ADD_TID test and the linear control).gpu_buffer_swizzle_window_from_swizzled_offsetfails at its first case (lane 0 reads window 0 + 0x1000). Both onXCL_DIRECT_DXIL=0and=1. With the PR:gpu_buffer8 of 8 on both paths.XCL_DIRECT_DXIL=1). (Edited: I removed a second mutation I had listed, because it has no log.)gpu_suite (--skip gpu_sparse_vram, single-threaded): main06c9f550144 passed, 0 failed, 1 ignored on both paths; this PR 152 passed, 0 failed, 1 ignored on both paths (the +8 are #2066's test, the six swizzle tests and the window test).SKIPPED(counted as passed):gpu_geometry_wave32_prefix_count_over_a_maskandgpu_wave32_program_in_wave64_hardware(no wave64), on both.windowtests 32 of 32, including main'swindow_at_lowers_to_32bit_carry_without_int64andgpu_window_at_32bit_carry_edge_cases, on both paths.gpu::dxil::157 passed, 3 ignored.git merge-treeagainst currentmain08294413: clean.4ee401e(before the merge): nnonno91 (comment, thanks) rangpu_buffer7 of 7 on an AMD Radeon iGPU (32.0.21042.62) and an RTX 5090 (32.0.16.1742) on both paths, plus a temporary nonzero-SOFFSET fixture, 128 of 128 readbacks matched. That run predates the 32-bit window change.DXIL size (direct path, wave32, one access per program,
insts= non-comment lines of themainbody; main + #2066 → this PR):That's +17 to +39 instructions per access with one window (+17 % to +45 % of these small programs) and +26 to +60 with two windows (+21 % to +53 %), linear V#s included, because the V# is only known at run time. A multi-dword load without IDXEN costs the most: it carries a second, guarded per-dword load for the swizzled case (only one of the two runs, the V# is uniform). Static counts only; I didn't measure compile or run time.
A question for the maintainer, given #2088's DXIL-size work: is this cost acceptable, or should the swizzle math be emitted only where it can apply? Options, none done here: skip it when the V# bits are known at translation time (rare), share the per-V# values between accesses through the same SRSRC in a block, or branch on the uniform swizzle bit instead of selecting.
Regression run
I have no retail title here. Could someone with one post
xcl-smokeblocks formainand this head? I'll paste them with credit.Not tested
(off & 3)term in DWORD alignment mode is not covered (#21970 measured it in UNALIGNED mode).gpu_buffer_swizzle_window_from_swizzled_offset). Swizzled stores and atomics across windows are not.NUM_RECORDS * stridefor swizzled groups, and this PR doesn't model that.AI use
Claude Code (Claude Opus 5.5) wrote the change and the tests and ran them. I reviewed the diff against the rule before opening this.
🤖 Generated with Claude Code
Neither path implemented the buffer swizzle: a V# with SWIZZLE_EN (word 1 bit 31) and a nonzero stride was addressed linearly, base + soffset + offset + stride * index. Both paths now use the rule AnyPS5#21970 measured on RDNA2 (gfx1036 through HIP, compute loads and stores, wave32 and wave64): step = 8 << INDEX_STRIDE (word 3 [22:21]) addr = ((index / step) * stride + (off & ~3)) * step + (index % step) * 4 + (off & 3) + soffset where off is the VGPR offset plus the instruction offset and ELEMENT_SIZE has no effect. The swizzle applies only with IDXEN, or with ADD_TID and no IDXEN; anything else stays linear. Without IDXEN each dword of a multi-dword access is swizzled at off + 4k (4 * step bytes apart); with IDXEN the dwords are contiguous from the first one's swizzled address. The V# is dynamic, so the address is a runtime select. On the direct path a multi-dword load without IDXEN keeps its single vector load for the linear case and takes a second guarded per-dword load when swizzled (the V# is uniform, so one of the two runs); the window is chosen from the swizzled 64-bit offset (new Ea::W term). The bounds check is unchanged (index < num_records when the stride is nonzero). Atomics, d16 and sub-dword accesses and MTBUF / format loads and stores go through the same address code, so a swizzled V# swizzles their first byte too, but #21970 did not measure atomics, tbuffer, typed accesses or SOFFSET, and a multi-component format access still reads its components contiguously. Not measured either: that the console GPU swizzles like gfx1036, and the (off & 3) term in DWORD alignment mode (#21970 ran UNALIGNED). New GPU tests gpu_buffer_swizzle_* (ADD_TID with and without an instruction offset, INDEX_STRIDE 3, IDXEN x2 with a VGPR index and ADD_TID set, ADD_TID x2 load and store, linear controls) fail on the parent and pass here with XCL_DIRECT_DXIL=0 and =1. Co-Authored-By: Claude Opus 5.5 <[email protected]>06c9f550into buffer-swizzle 9130586b40@nnonno91 on GitHub · 2026-11-25 14:40 UTC · original
Independent Radeon and RTX 5090 check of
4ee401eff0c97db43d87c570a0a572f14e8ef900, including a nonzero scalar offset.Tested
cargo test --locked -p xcl --lib gpu_buffer -- --nocapture --test-threads=1gave 7 passed, 0 failed, 0 ignored per adapter/backend pair. Selected adapters withXCL_ADAPTER, and ranXCL_DIRECT_DXIL=0and1in separate processes on each.local_swizzle_scalar_offset_stays_unscaledfixture used a DWORD load with instruction offset 4 and scalar offset 4. It covered bothADD_TIDand reversed VGPR indices withIDXEN, checking all 64 lanes for each. It compared the readback to the swizzled address plus 4 unscaled bytes.cargo test --locked -p xcl --lib local_swizzle_scalar_offset_stays_unscaled -- --nocapture --test-threads=1gave 1 passed, 0 failed, 0 ignored and 128 matching readbacks per adapter/backend pair. No skips in any run. The temporary fixture was removed.Not tested
Retail shader inputs, the parent, title smoke, and the full workspace suite.
AI use
OpenAI Codex (GPT-6.2 Sol) added the temporary offset fixture, ran the tests and wrote this report.
@DavidM1911 on GitHub · 2026-11-25 18:09 UTC · original
Verification on RTX 3060 Ti (Windows 11), branch merged with current
main:cargo test -p xcl --lib: 1038 passed, 1 failed in one parallel run; the failing test passes on a single-threaded rerun (1039/0). Intermittent single-test flake / 0xc0000005 abort under parallel scheduling — tracked in #1978; clean on single-threaded rerun.Thanks!
@DavidM1911 on GitHub · 2026-11-26 08:15 UTC · original
Re-verification on RTX 3060 Ti (Windows 11), new head merged with current
main:cargo test -p xcl --lib: 1 failure under parallel scheduling; clean on--test-threads=1rerun (1312 passed, 0 failed, 27 ignored, 82s). Intermittent single-test flake — tracked in #1978.Thanks!
— Devin
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.