D3D12.X: encode BGRA8, BGRX8, and A8 typed buffer V# formats and swizzles #3419
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3419"
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:04:04Z.
What is in it
buffer_viewandbuffer_words_atincrates/xcl/src/hle/d3d12x/real.rspreviously looked up typed buffer formats solely viadesc::gfx10_format(format).unwrap_or(22)and encoded every V# with hardcoded identityDST_SEL = [4, 5, 6, 7](0xFAC):gfx10_format, so they silently fell back to GFX10 format22(R32_FLOAT, 4-byte stride, identity swizzle):DXGI_FORMAT_B8G8R8A8_UNORM: fell back toR32_FLOATinstead of GFX10 format56(8_8_8_8_UNORM, stride 4) with BGRADST_SEL = [6, 5, 4, 7].DXGI_FORMAT_B8G8R8X8_UNORM: fell back toR32_FLOATinstead of GFX10 format56(8_8_8_8_UNORM, stride 4) with BGR1DST_SEL = [6, 5, 4, 1].DXGI_FORMAT_A8_UNORM: fell back toR32_FLOAT(4-byte element stride and offset instead of 1 byte!) instead of GFX10 format1(8_UNORM, stride 1) withDST_SEL = [0, 0, 0, 4].> 77(such as130forR8G8B8A8_UNORM_SRGBor133forB5G6R5_UNORM) also wrapped modulo 128 in the 7-bit V#FORMATfield (format & 0x7F).This change adds
buffer_words_swizzledanddxgi_buffer_formatincrates/xcl/src/gpu/desc.rs, wires both intobuffer_viewandbuffer_words_atincrates/xcl/src/hle/d3d12x/real.rs, and adds unit testtyped_buffer_views_encode_bgra_bgrx_and_a8_formats_and_swizzlesplus end-to-end GPU testgpu_typed_buffer_vsharp_bgra_bgrx_and_a8_load_expected_channelsverifyingBUFFER_LOAD_FORMAT_XYZWon both Direct DXIL and HLSL.Tested
Causal reproduction + fix verification (
cargo test -p xcl --lib -- typed_buffer_vsharp_bgra typed_buffer_views_encode_bgra a_view_by_address_covers_its_elements gpu::desc::):typed_buffer_views_encode_bgra_bgrx_and_a8_formats_and_swizzlesfailed with(30064775172, 16, 4, 4, 22, [4, 5, 6, 7])instead of(30064775172, 16, 4, 4, 56, [6, 5, 4, 7]).14 passed, 0 failed, including both Direct DXIL and HLSL GPU execution ofBUFFER_LOAD_FORMAT_XYZWreturning exact expected(R, G, B, A)channels forB8G8R8A8_UNORM,B8G8R8X8_UNORM, andA8_UNORM(at non-zeroFirstElement).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 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.Rebased onto
37be0959withrunner::wave32_supported()no-GPU CI guard ongpu_typed_buffer_vsharp_bgra_bgrx_and_a8_load_expected_channels; targeted suite (cargo test -p xcl --lib -- typed_buffer_views_encode_bgra gpu_typed_buffer_vsharp_bgra gpu::desc::tests::):12 passed, 0 failed.Regression run
Not tested
22wave64 tests skipped on RTX 5070 Ti).ea3b5e4dor paths requiringuma_driver::tests::kernel driver tests.DST_SELswizzling onBUFFER_STORE_FORMAT_*writes to swizzled typed buffers (separate translator change, not part of this descriptor encoding PR).AI use
Used an AI coding assistant to audit typed buffer V# encoding in
desc.rsandreal.rs, reproduce the missingBGRA8/BGRX8/A8mapping, implement the fix and synthetic unit/GPU tests, and run local verification.Imported from ivall/xcl. Originally posted by andrewDoing on 2026-11-29T15:27:39Z.
I checked this descriptor producer together with the MUBUF store change in #3421. The fixture builds the actual
buffer_words_atdescriptors for BGRA8, BGRX8 and A8 with nonzeroFirstElement, runs three in-bounds indexed stores plus a fourth out-of-view index, and reads all 512 backing bytes before a separate translated load.cc302ce2): the stock descriptor load test passed. The combined store/load fixture failed at the first BGRA byte on Direct DXIL,0xffinstead of0x00at0x108.c0e7aa24): the combined fixture and both stock tests passed, 3 passed and zero skips. Both translators produced all expected bytes, left the fourth element and other canaries intact, and loaded the expected 36 channel values per translator. The A8 writes started at an unaligned byte and two lanes updated bytes in the same DWORD.This exercises production descriptor words and RTX 5070 shader execution (driver 616.92, DXC 1.8.2502.11). It supplies descriptor words directly to shader registers, so guest descriptor binding and title visuals remain outside the result. The load improvement is independently covered. The store side needs #3421 for these swizzled descriptors to round trip.
One-file integration fixture (applies on #3419)
AI disclosure: OpenAI Codex (GPT-6.2 Sol) implemented and ran the integration fixture and wrote this report.
Imported from ivall/xcl. Originally posted by Aniseto on 2026-11-29T20:24:19Z.
Ran the typed-buffer format tests at
fb594f15on an NVIDIA Blackwell desktop part.System
Results
XCL_ADAPTER=NVIDIA cargo test -p xcl --lib typed_buffer_views_encode_bgra_bgrx_and_a8_formats_and_swizzles -- --test-threads=1: 1 passed, 0 failed, 0 ignored.XCL_ADAPTER=NVIDIA cargo test -p xcl --lib gpu_typed_buffer_vsharp_bgra_bgrx_and_a8_load_expected_channels -- --test-threads=1: 1 passed, 0 failed, 0 ignored. The GPU draw ran here, with no SKIPPED line.XCL_ADAPTER=NVIDIA cargo test -p xcl --lib gpu::desc::tests:: -- --test-threads=1: 10 passed, 0 failed, 0 ignored.What this adds
The BGRA8/BGRX8/A8 V# encoding unit test, the GPU load test comparing Direct DXIL and HLSL, and the descriptor group all pass. The author also tested on an RTX 5070 Ti; this adds an independent run on driver 32.0.16.2140 at head
fb594f15. Synthetic GPU tests only, no title run.Not tested
A retail title, a paired smoke run, the full workspace suite here, AMD and Intel GPUs, native wave64 hosts, Wine, release profile, game data.
AI-assisted (OpenCode), model: DeepSeek V4.1 Flash Free - ran the commands above on this machine and wrote this report; no game data was used.
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T03:50:59Z.
merge-check
base:
d0832e614fhead:
fb594f1539merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2892 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: read the whole diff (desc.rs, real.rs). It changes the default path: these are the only two places that build typed buffer V#s for SRVs and UAVs, and on main
B8G8R8A8_UNORM,B8G8R8X8_UNORMandA8_UNORMfell back to format 22 (R32_FLOAT) with the identity swizzle (A8 with a 4-byte stride). Findings: (1) typed stores ignoreDST_SELon main (lower_mem.rsfmt_pack, and the HLSL format store inrecomp/emit.rs). So with this PR alone, a store to a BGRA8 UAV writes red and blue swapped and a load through the same view swaps them back, and an A8 store writes.xinstead of.w. Not a regression for stores (main wrote float bits), but loads and stores now disagree until #3421 (same author, applies the inverse DST_SEL on stores) lands. Better to stack this on #3421 or say so in the description. (2) AI use names no tool or model ("an AI coding assistant"). (3) Formats above 77 now fall back to R32_FLOAT with a 4-byte stride instead of wrapping, still wrong for B5G6R5 (stride 2) and similar. Fine: the DST_SEL packing ([4,5,6,7]gives back 0xFAC), format numbers 56 (8_8_8_8_UNORM) and 1 (8_UNORM), the swizzles BGRA[6,5,4,7], BGRX[6,5,4,1](alpha 1) and A8[0,0,0,4]against DXGI, both loaders already applying DST_SEL, and both tests failing on main's mapping (the GPU one uses skip_test).performance: 60 s smoke of a retail title, main
d0832e61vs this merge (4a1f1620): 1516 -> 1672 frames shown (110 %; last presents per 2 s: 60 60 60), peak commit 18133 -> 17755 MB, 0 device removals, 0 crashes.verdict: safe to merge (best together with or after #3421, so typed UAV loads and stores agree)
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 brainhay5 on 2026-12-01T05:32:37Z.
merge-check claim
head:
fb594f1539Imported from ivall/xcl. Originally posted by brainhay5 on 2026-12-01T11:48:05Z.
merge-check claim withdrawn
Our automated merge-check loop claimed this PR and then stopped before posting a check — two loops were running at once and both are now shut down. No check from us is coming, so this claim is void and the head is free for someone else to take.
AI use: an agent posted this withdrawal.
Imported from ivall/xcl. Originally posted by kole07139 on 2026-12-01T23:22:24Z.
merge-check claim
head:
fb594f1539Imported from ivall/xcl. Originally posted by kole07139 on 2026-12-02T00:08:38Z.
merge-check
base:
1c8b551475head:
fb594f1539merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2911 passed, 0 failed, 51 ignored; SKIPPED: 25 (22 no wave64, 2 no heap windows, 1 driver cache needs Developer Mode; the same set as main), and the PR's GPU test ran here (wave32) and passed; failing: none
review: read the whole diff (desc.rs, real.rs), and the paths it feeds, in both translators. Findings, most serious first:
DST_SEL(fmt_pack(uint4(...))inrecomp/emit.rs, theFormatStorepath indxil/lower_mem.rs), while loads apply it..x.6a05c038) merged on top, the fixture, this PR's GPU test and #3421'sgpu_buffer_store_format_honors_vsharp_dst_selpass (3 passed, none skipped).DST_SELon MUBUF stores and ignores it on MTBUF, is not checked here; that belongs to its own review.& 0x7F) decode to the requested format, so no format that worked before changes.needs:amd-test), the split-wave64 path, and VS/PS loads through these views (the GPU tests are compute only). The title does not reach these formats (see performance).buffer_viewandbuffer_words_atare the only producers of typed-buffer V#s (besidescbv_wordsand tests).format_bytes(fmt), so A8'sFirstElementoffset is now 1 byte.DST_SELpacking keeps 0xFAC for the identity, and the BGRA / BGRX / A8 swizzles match DXGI's byte order.DST_SEL.performance: only descriptor words change, no per-draw work. Retail title, main
1c8b5514vs this merge (b2fe43b6), 0 device removals and 0 crashes in every run:verdict: safe to merge (best in the same batch as #3421, so typed loads and stores through these views agree)
hardware / tool and model: NVIDIA GeForce RTX 3070 8 GB (driver 32.0.16.2140), Intel Core i9-9900K, Windows 11 Pro N 26200 / Claude Code with Claude Opus 5.5 (ran the merge, build, suite, smoke and the fixture, and wrote this check)
AI-written; posted without a human check of each point.
Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T05:15:51Z.
Code review location:
crates/xcl/src/gpu/desc.rs; line 718The new format-56 + BGRA/BGR1 and format-1 + 000X V#s are also used for typed buffer UAVs (
dev_create_uav_x->buffer_viewat real.rs:3763,dev_create_uav_at_x->buffer_words_atat real.rs:3468). Neither translator applies DST_SEL on stores:lower_mem.rsfmt_packpacks v[c] into component c, and recomp/emit.rs does the same. A BUFFER_STORE_FORMAT_XYZW of float4(r,g,b,a) to a B8G8R8A8_UNORM RWBuffer writes bytes [r,g,b,a] instead of D3D's [b,g,r,a], and a later load through the same view returns (b,g,r,a), so R and B swap on a round trip. Before, the R32_FLOAT view was at least self-consistent. For A8_UNORM, component x lands in the alpha byte instead of .a. No test covers a store or UAV.Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T05:15:51Z.
Code review location:
crates/xcl/src/hle/d3d12x/real.rs; line 1969Formats that
dxgi_buffer_formatnow rejects (B5G6R5_UNORM=133, B5G5R5A1_UNORM=134, B4G4R4A4_UNORM=136, R8G8B8A8_UNORM_SRGB=130) fall back to (22, identity) with strideformat_bytes(22)= 4, so 2-byte formats still get the wrong element size. A B5G6R5 SRV with FirstElement=10, NumElements=100 gets base = at + 40 (should be +20) and stride 4 (should be 2), so every element reads the wrong address andrecords = min(n, room/4)cuts the view short.buffer_words_at(~3480) does the same and also over-requests tiles fromview_want. The PR describes these as rejected, but a broken view is still emitted. Skipping the view, or using a size-correct fallback, would match the description.Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T05:15:51Z.
Review: COMMENTED
Review of
fb594f15: 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:08Z.
@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 ClosetPie107 on 2026-12-02T17:13:14Z.
Linux / AMD RDNA4 (RADV, Wine + vkd3d-proton): full test suite on
fb594f1Merged onto
main5eaadb54(clean merge) and compared withmainrun twice on the same machine.Setup
v3.1-83-gcae8353edand DXVKdxgi.dllfrom GE-Proton11-16, DXC 1.9.2609.5x86_64-pc-windows-msvcwithcargo-xwin; test binaries run under WineTested:
cargo xwin test --workspace --target x86_64-pc-windows-msvc --no-fail-fast -- --test-threads=4 --skip <31 tests>main5eaadb54main:hle::d3d12x::uma_driver::tests::failed_restore_stops_before_importing_an_unbacked_window.mainwhen run alone (0 of 5 runs pass onmain, 1 of 5 on this PR). It passed in both full-suite runs ofmain, so under Wine it depends on which tests ran before it.typed_buffer_views_encode_bgra_bgrx_and_a8_formats_and_swizzles).gpu_typed_buffer_vsharp_bgra_bgrx_and_a8_load_expected_channels: fails withInvalid parameter (0x80070057), the #175 failure above, asmain's tests of the same kind do here.About the failures on
mainand the 31 skipped tests (same for every PR in this batch)main's 177 failures under Wine come from #175: once a test has set up the real device, vkd3d-proton refuses the command allocators XCL adopts (d3d12_command_list_Reset: Invalid command allocator), and later tests getE_INVALIDARG(0x80070057). Running vkd3d-proton master with its vtable check taken out,hle::d3d12x::sparse::testsgoes from 106 passed / 38 failed to 144 / 0.std::terminate()(Cannot reliably convert LLVM pointer type, we cannot differentiate between Function and Private), which kills the whole test binary. They are the split-wave64, dispatch-chain and bridged-mask GPU tests,gpu_compute_mode_dispatch_abi,gpu_compute_thread_limits_leave_the_lanes_past_them_out, the twogpu_mesh_mode_*tests, andconsole_wave64_compute_through_the_pso_hook_dispatch_and_read_back, plusserialize_root_signature_strips_console_flags_and_preserves_pc_flags, whose null descriptor vkd3d-proton dereferences. The dxil-spirv ones crash the same way with vkd3d-proton master (f8c1cae8, dxil-spirv93ab44c5).mainwas run twice: same counts, same failure set.SKIPPEDlines (same asmain): no heap windows (2), no D3D12 debug layer (2-3), driver cache control not implemented in vkd3d-proton (1).Not tested: Windows, NVIDIA, a retail title /
scripts/smoke.ps1, a review of the diff. This is a test report, not amerge-check.AI use: omp (Claude Opus 5.5) merged, built and ran the suites on this machine, compared the results with
main, and drafted this report. The user asked for it to be posted.