Skip to content

Recompiler: honor V# DST_SEL inverse swizzle on MUBUF buffer_store_format - #3421

Open
Kalmarv wants to merge 1 commit into
xcl-dev:mainfrom
Kalmarv:samplers/format-store-dst-sel
Open

Kalmarv wants to merge 1 commit into
xcl-dev:mainfrom
Kalmarv:samplers/format-store-dst-sel

Conversation

@Kalmarv

@Kalmarv Kalmarv commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

What is in it

MUBUF buffer_store_format_* (including d16 variants) previously ignored the V# resource descriptor's DST_SEL fields (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 typed RWBuffer store through a swizzled V# (such as B8G8R8A8_UNORM [6, 5, 4, 7], B8G8R8X8_UNORM [6, 5, 4, 1], A8_UNORM [0, 0, 0, 4], or swapped 2-channel YX01 [5, 4, 0, 1]) therefore wrote swapped or zeroed components to memory:

  • Adds dst_sel_store in crates/xcl/src/gpu/dxil/lower_mem.rs and crates/xcl/src/gpu/recomp/emit.rs to route each memory channel m (0..4, selector 4 + m) from the VGPR component k whose DST_SEL[k] == 4 + m (or 0 when unmapped).
  • Applies dst_sel_store in BufKind::FormatStore for MUBUF buffer_store_format_* (both 32-bit and d16 forms), while keeping MTBUF tbuffer_store_format_* unswizzled (matching RDNA2 hardware, where tbuffer_store_format_* ignores DST_SEL).
  • Adds 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 test buffer_store_format_emits_dst_sel_store_for_mubuf_only in crates/xcl/src/gpu/dxil/core_tests.rs.

Tested

  • Causal reproduction + fix verification (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):
    • Before fix: gpu_buffer_store_format_honors_vsharp_dst_sel failed on direct-dxil BGRA8 store with [255, 128, 0, 64] instead of [0, 128, 255, 64].
    • After fix: 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.
  • Full workspace test suite (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 on main (3b6a91ed, tracked in Tests: fix 4 geometry tests broken on main by split-ES safe-barrier and no-store epilogue merges #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, and gpu::dxil::lower_mem::stage_guard_tests::geometry_export_rejected.

Regression run

xcl-smoke v1
commit: f0e8fdd5c3942ddd399d5ee11384c8595c5aacff
gpu: NVIDIA GeForce RTX 5070 Ti
title: ea3b5e4d
seconds: 150
exit: 0x0
frames shown: 1695 (PresentX 1695)
presents per 2 s (last 3): 0 0 0
device removals: 0
crashes: 0
peak commit: 31546 MB
xcl-smoke v1
commit: c0e7aa24c6dd29db5cb2e43c333ade4749b70a72
gpu: NVIDIA GeForce RTX 5070 Ti
title: ea3b5e4d
seconds: 150
exit: 0x0
frames shown: 1555 (PresentX 1555)
presents per 2 s (last 3): 0 0 0
device removals: 0
crashes: 0
peak commit: 33539 MB
  • Head 6a05c038: gpu_buffer_store_format_honors_vsharp_dst_sel now 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 at CreateComputePipelineState (E_INVALIDARG) for every single instruction of the test, with or without dst_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

  • Hardware adapters with wave64-only shaders or non-NVIDIA drivers (22 wave64 tests skipped on RTX 5070 Ti).
  • Full title execution for games other than ea3b5e4d or paths requiring uma_driver::tests:: kernel driver tests.
  • Swizzled V# descriptor creation in D3D12.X buffer_view / buffer_words_at (handled separately in D3D12.X: encode BGRA8, BGRX8, and A8 typed buffer V# formats and swizzles #3419).
  • The GPU part of gpu_buffer_store_format_honors_vsharp_dst_sel on the CI runner and WARP (no wave32 there: it skips).

AI use

Used an AI coding assistant to audit BufKind::FormatStore in lower_mem.rs and emit.rs, reproduce the BGRA8 store mismatch on GPU, implement dst_sel_store and synthetic GPU/codegen tests, and run local verification.

Claude Code (Claude Opus 5.5) added the wave32 skip in head 6a05c038 and the lines about it above.

@github-actions github-actions Bot added area:recompiler RDNA2 decoder, HLSL/direct-DXIL recompiler, wave64/wave32 area:tests Unit, integration, e2e tests, or testtitle gpu:amd Code is specific to AMD / RDNA / wave64 GPUs (scope tag; see needs:amd-test) labels Nov 29, 2026
@Kalmarv
Kalmarv force-pushed the samplers/format-store-dst-sel branch from c0e7aa2 to 6a05c03 Compare December 1, 2026 01:03
@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Review (head 6a05c03, diff read, not a merge-check: the PR description check fails, so not built or run here yet):

  • The PR's smoke block is on c0e7aa2, not the head 6a05c03, which is why PR description fails. It needs a rerun on the head. The stale run is within the limits (92 % of main's frames, 106 % of its peak commit).
  • No source is cited for MUBUF format stores applying the inverse of DST_SEL. For swizzles that can't be inverted, the PR picks its own behaviour: a channel selected twice takes the first matching VGPR, and a channel no DST_SEL maps is written as 0. So a title-built V# with a 0/1 select on a data channel now writes zeros where main wrote the data (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.
  • MTBUF load and store now disagree: tbuffer_store ignores DST_SEL while tbuffer_load on main applies it in both backends (lower_mem.rs FormatLoad, emit.rs ~2250/2272). Low impact, but worth a line in the description.
  • On CI the GPU test skips (no wave32), so CI only checks the HLSL string and that the Direct DXIL output validates.
  • AI use names Claude Opus 5.5 for the follow-up commit only; the original work is credited to an unnamed "AI coding assistant".

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_pack drops 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.

@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Test report (not a merge-check: PR description red)
base: b2b1f10
head: 6a05c03
merge: 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 #3421 (comment), 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:recompiler RDNA2 decoder, HLSL/direct-DXIL recompiler, wave64/wave32 area:tests Unit, integration, e2e tests, or testtitle gpu:amd Code is specific to AMD / RDNA / wave64 GPUs (scope tag; see needs:amd-test)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants