Recompiler: swizzled buffer V#s address records in dword-interleaved groups #2315
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/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?
Imported from ivall/xcl. Originally posted by upipibi on 2026-11-25T14:33:05Z.
Depends 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
Imported from ivall/xcl. Originally posted by nnonno91 on 2026-11-25T14:40:00Z.
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.
Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-25T18:09:08Z.
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!
Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-26T08:15:33Z.
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
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T07:49:56Z.
Triage (#1607) – head
68b6034Stacked on #2066, whose ADD_TID commit (
b81d47c) is now on main; the swizzled addressing on top of it (Em::buf_relin recomp/emit.rs,Lw::buf_addrin dxil/lower_mem.rs) is not on main and no other open PR makes it (#3421 and #3419 are about format DST_SEL swizzles, not V# address swizzling).Checked the per-dword spacing without IDXEN (
4 << shbytes, matching(off + 4k) & ~3times the step) and the 32-bit carry for the windowed high half; both translators use the same rule and the tests cover IDXEN, ADD_TID, INDEX_STRIDE, multi-dword loads/stores and the window carry. The branch conflicts with main and needs a rebase that drops the #2066 commit.Recommendation: keep open.
AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.
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.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.