Recompiler: honor V# DST_SEL inverse swizzle on MUBUF buffer_store_format #3421
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3421"
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 Kalmarv on 2026-11-29T15:14:54Z.
What is in it
MUBUF
buffer_store_format_*(includingd16variants) previously ignored the V# resource descriptor'sDST_SELfields (d3[11:0]) in both Direct DXIL (crates/xcl/src/gpu/dxil/lower_mem.rs) and HLSL (crates/xcl/src/gpu/recomp/emit.rs), packing VGPR channels[v0, v1, v2, v3]straight to memory in identity order. Any typedRWBufferstore through a swizzled V# (such asB8G8R8A8_UNORM[6, 5, 4, 7],B8G8R8X8_UNORM[6, 5, 4, 1],A8_UNORM[0, 0, 0, 4], or swapped 2-channelYX01[5, 4, 0, 1]) therefore wrote swapped or zeroed components to memory:dst_sel_storeincrates/xcl/src/gpu/dxil/lower_mem.rsandcrates/xcl/src/gpu/recomp/emit.rsto route each memory channelm(0..4, selector4 + m) from the VGPR componentkwhoseDST_SEL[k] == 4 + m(or0when unmapped).dst_sel_storeinBufKind::FormatStorefor MUBUFbuffer_store_format_*(both 32-bit andd16forms), while keeping MTBUFtbuffer_store_format_*unswizzled (matching RDNA2 hardware, wheretbuffer_store_format_*ignoresDST_SEL).gpu_buffer_store_format_honors_vsharp_dst_sel(testing BGRA8, BGRX8, A8_UNORM, YX01, D16 BGRA8, MTBUF unswizzled control, and BGRA8/A8 round-trip loads on both Direct DXIL and HLSL) and no-GPU codegen/validation testbuffer_store_format_emits_dst_sel_store_for_mubuf_onlyincrates/xcl/src/gpu/dxil/core_tests.rs.Tested
cargo test -p xcl --lib -- gpu_buffer_store_format_honors_vsharp_dst_sel buffer_store_format_emits_dst_sel_store_for_mubuf_only gpu_typed_buffer_loads_and_stores gpu_format_stores_atomics_global_lds gpu_buffer_store_two_bit_snorm_rounds_half_away gpu_direct_unaligned_multi_dword_format_store):gpu_buffer_store_format_honors_vsharp_dst_selfailed ondirect-dxil BGRA8 storewith[255, 128, 0, 64]instead of[0, 128, 255, 64].6 passed, 0 failed, verifying Direct DXIL and HLSL on GPU across all 6 store cases and BGRA8/A8 round-trips, plus all existing typed-buffer store tests.cargo test --workspace --no-fail-fast -j 2 -- --test-threads=4 --skip test_title_runs_and_game_folder_is_untouched --skip uma_driver::tests::, RTX 5070 Ti + DXC 1.9):41 binaries, 2713 passed, 4 failed, 49 ignored, 9 filtered; 27 SKIPPED (22 no wave64, 3 refused #1426, 2 no heap windows). All 4 failures are pre-existing geometry test failures onmain(3b6a91ed, tracked in #3411):gpu::dxil::geometry_tests::gpu_geometry_msg_gs_done_records,gpu::dxil::geometry_tests::msg_gs_done_emits_in_dxil,gpu::dxil::lower_geom::tests::gpu_epilogue_filters_oob_triangles_and_no_store_emits, andgpu::dxil::lower_mem::stage_guard_tests::geometry_export_rejected.Regression run
6a05c038:gpu_buffer_store_format_honors_vsharp_dst_selnow also skips when the adapter has no wave32 (runner::wave32_supported(), as the neighbouring wave32 tests do). On the CI runner and WARP (4-lane waves) the wave32 kernel was refused atCreateComputePipelineState(E_INVALIDARG) for every single instruction of the test, with or withoutdst_sel_store. On WARP (XCL_ADAPTER=warp):SKIPPED … no GPU / wave32 / DXC, 1 passed;buffer_store_format_emits_dst_sel_store_for_mubuf_only: 1 passed.Not tested
22wave64 tests skipped on RTX 5070 Ti).ea3b5e4dor paths requiringuma_driver::tests::kernel driver tests.buffer_view/buffer_words_at(handled separately in #3419).gpu_buffer_store_format_honors_vsharp_dst_selon the CI runner and WARP (no wave32 there: it skips).AI use
Used an AI coding assistant to audit
BufKind::FormatStoreinlower_mem.rsandemit.rs, reproduce the BGRA8 store mismatch on GPU, implementdst_sel_storeand synthetic GPU/codegen tests, and run local verification.Claude Code (Claude Opus 5.5) added the wave32 skip in head
6a05c038and the lines about it above.Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T03:12:51Z.
Review (head
6a05c038, diff read, not a merge-check: thePR descriptioncheck fails, so not built or run here yet):c0e7aa24, not the head6a05c038, which is whyPR descriptionfails. It needs a rerun on the head. The stale run is within the limits (92 % of main's frames, 106 % of its peak commit).lower_mem.rs~1078-1094 / ~1665,emit.rs~2278). None of these cases is tested. A reference (ISA doc table or a hardware trace) would settle it.tbuffer_storeignores DST_SEL whiletbuffer_loadon main applies it in both backends (lower_mem.rsFormatLoad,emit.rs~2250/2272). Low impact, but worth a line in the description.Fine: Direct DXIL and HLSL route channels the same way. The expected values for BGRA8, BGRX8, A8, YX01, D16 BGRA8 and MTBUF check out by hand. D16 values are converted before routing, and
fmt_packdrops channels the format lacks and uses each memory channel's width. V#s that XCL builds itself (identity DST_SEL, desc.rs ~701) store as before. This is the store-side counterpart #3419 needs (with #3419 alone, BGRA8 UAV stores swap red and blue).AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T15:35:22Z.
Test report (not a merge-check:
PR descriptionred)base:
b2b1f109d2head:
6a05c0388amerge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2904 passed, 0 failed, 51 ignored; SKIPPED: 28 (20 no wave64, 2 no d3d12SDKLayers.dll, 1 no D3D12 debug layer, 1 no heap windows, 1 cannot disable the driver cache, 3 others; the same set as on main); failing: none
review: not repeated here; my review of this same head is at https://github.com/xcl-dev/xcl/pull/3421#issuecomment-7299460897, and its findings stand. This run adds what reading couldn't: whether the change merges, builds and passes the whole suite on current main.
performance: no smoke run.
assessment: merges, builds and passes the whole suite on current main; the findings in my review stand
hardware / tool and model: RTX 5070 Ti (driver 621.14), Ryzen 7 7800X3D, Windows 11 26300 / Claude Code with Claude Opus 5.5
AI-written and posted by Foniass without a human check of each point.
Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T05:15:53Z.
Code review location:
crates/xcl/src/gpu/dxil/lower_mem.rs; line 1665Not certain about this one:
dst_sel_storeruns on avalsarray that's zero-padded beyondcount/ d16components. When the V# routes a memory channel from a component the instruction doesn't supply, that channel is stored as 0 even though the shader provided data (emit.rs:2288/2293 do the same). buffer_store_format_x (or _d16_hi_x) of 0.5 through an A8_UNORM V# with DST_SEL [0,0,0,4] takes memory R from k=3, the padding, and stores 0x00 where it stored 0x80 before this PR. The test only covers XYZW for A8.Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T05:15:53Z.
Code review location:
crates/xcl/src/gpu/recomp/emit.rs; line 2278Not certain about this one, because it depends on hardware behaviour that hasn't been measured: MTBUF tbuffer_store_format_* skips DST_SEL while this codebase's tbuffer_load_format_* honors it (FormatLoad: "DST_SEL from the V#"). The asymmetry is described as matching RDNA2, but it was only checked against the emulation on NVIDIA. A tbuffer store then load through the same BGRA8 V# [6,5,4,7] with (1, .5, 0, .25) reads back (0, .5, 1, .25). If the hardware applies DST_SEL on both encodings, every tbuffer store through a swizzled V# is still channel-swapped (lower_mem.rs:1665 via
is_mubuftoo).Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T05:15:53Z.
Review: COMMENTED
Review of
6a05c038: 2 finding(s). 2 are inline.These findings come from an AI-assisted review (Claude Code) and focus on correctness. Each is a candidate; please check it before acting on it.
Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T14:14:04Z.
@Prime1997 could you take a look at this one for review and merge? My automated review notes are above, if any.
Imported from ivall/xcl. Originally posted by Kalmarv on 2026-12-02T19:39:52Z.
Closing: unsourced MUBUF
DST_SELstore swizzle with zero-padding and MTBUF inconsistency flagged in review.Pull request closed