Repository navigation
D3D12.X: encode BGRA8, BGRX8, and A8 typed buffer V# formats and swizzles - #3419
Conversation
|
I checked this descriptor producer together with the MUBUF store change in #3421. The fixture builds the actual
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)--- a/crates/xcl/src/hle/d3d12x/real.rs
+++ b/crates/xcl/src/hle/d3d12x/real.rs
@@ -13531,6 +13531,70 @@
}
}
+ #[test]
+ fn gpu_typed_buffer_swizzled_views_and_indexed_stores() {
+ use crate::gpu::dxil::kernel::{translate as dxil_translate, KernelOptions};
+ use crate::gpu::rdna2::encode;
+ use crate::gpu::recomp::{dxc, runner::{self, KernelState}, Options};
+ use windows::Win32::Graphics::Dxgi::Common::{DXGI_FORMAT_A8_UNORM, DXGI_FORMAT_B8G8R8A8_UNORM, DXGI_FORMAT_B8G8R8X8_UNORM};
+
+ if runner::adapter().is_err() || dxc::location().is_err() {
+ return runner::skip_test("no GPU or DXC");
+ }
+ let formats = [(DXGI_FORMAT_B8G8R8A8_UNORM, 0x100, 2), (DXGI_FORMAT_B8G8R8X8_UNORM, 0x140, 2), (DXGI_FORMAT_A8_UNORM, 0x180, 3)];
+ let colors = [[255u8, 128, 0, 64], [0, 51, 102, 153], [204, 17, 238, 85], [1, 2, 3, 4]];
+ let mut state = KernelState::default();
+ let mut expected = vec![0x5a; 512];
+ for lane in 0..4 {
+ let regs = &mut state.vgpr[lane];
+ regs[0] = lane as u32;
+ for (reg, byte) in regs[4..8].iter_mut().zip(colors[lane]) {
+ *reg = (f32::from(byte) / 255.0).to_bits();
+ }
+ if lane < 3 {
+ let [r, g, b, a] = colors[lane];
+ expected[0x108 + lane * 4..0x10c + lane * 4].copy_from_slice(&[b, g, r, a]);
+ expected[0x148 + lane * 4..0x14c + lane * 4].copy_from_slice(&[b, g, r, 0]);
+ expected[0x183 + lane] = a;
+ }
+ }
+ for (i, (format, base, first)) in formats.into_iter().enumerate() {
+ let (words, _, _) = buffer_words_at(base, format, first, 3, 0, false);
+ state.sgpr[12 + 4 * i..16 + 4 * i].copy_from_slice(&words);
+ }
+
+ let program = |store| {
+ let mut code = encode("V_CMPX_GT_U32", "ENC_VOPC", &[("SRC0", 132), ("VSRC1", 0)], None).unwrap();
+ for i in 0..3 {
+ let (op, vdata) = if store { ("BUFFER_STORE_FORMAT_XYZW", 4) } else { ("BUFFER_LOAD_FORMAT_XYZW", 10 + 4 * i) };
+ code.extend(encode(op, "ENC_MUBUF", &[("VDATA", vdata), ("VADDR", 0), ("SRSRC", 3 + i), ("SOFFSET", 128), ("IDXEN", 1)], None).unwrap());
+ }
+ code.extend(encode("S_ENDPGM", "ENC_SOPP", &[], None).unwrap());
+ let direct = dxil_translate(&code, KernelOptions { wave64: false, split: false, mem_windows: 1, sampler_base: 0 }).unwrap();
+ let translated = crate::gpu::recomp::translate(&code, &Options { wave64: false, ..Default::default() }).unwrap();
+ assert!(translated.complete(), "{:?}", translated.unsupported);
+ [direct, dxc::compile(&translated.hlsl, "main", "cs_6_6", &[]).unwrap()]
+ };
+ let stores = program(true);
+ let loads = program(false);
+ for ((backend, store), load) in ["Direct DXIL", "HLSL"].into_iter().zip(stores).zip(loads) {
+ let written = runner::run(&store, &state, &[0x5a5a_5a5a; 128]).unwrap();
+ let bytes: Vec<_> = written.mem.iter().flat_map(|word| word.to_le_bytes()).collect();
+ for (i, (&got, &want)) in bytes.iter().zip(&expected).enumerate() {
+ assert_eq!(got, want, "{backend}: byte {i:#x}");
+ }
+ assert_eq!(bytes.len(), expected.len(), "{backend}: readback length");
+ let read = runner::run(&load, &state, &written.mem).unwrap();
+ for (lane, &[r, g, b, a]) in colors[..3].iter().enumerate() {
+ for (i, byte) in [r, g, b, a, r, g, b, 255, 0, 0, 0, a].into_iter().enumerate() {
+ let expected = (f32::from(byte) / 255.0).to_bits();
+ let actual = read.vgpr[lane][10 + i];
+ assert!(actual.abs_diff(expected) <= 2, "{backend}: lane {lane}, channel {i}: {actual:#x} vs {expected:#x}");
+ }
+ }
+ }
+ }
+
/// A constant buffer view in a GPU view carries its address: shaders read the view window
/// there (its tiles show the CPU view). It was left empty: the address is no CPU memory.
#[test]
AI disclosure: OpenAI Codex (GPT-6.2 Sol) implemented and ran the integration fixture and wrote this report. |
cc302ce to
fb594f1
Compare
|
Ran the typed-buffer format tests at System
Results
What this adds Not tested 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. |
|
merge-check AI-written and posted by Foniass without a human check of each point. |
|
merge-check claim |
|
merge-check claim withdrawn AI use: an agent posted this withdrawal. |
|
merge-check claim |
|
merge-check
AI-written; posted without a human check of each point. |
bmjask
left a comment
There was a problem hiding this comment.
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.
| /// otherwise truncate in the 7-bit V# `FORMAT` field. | ||
| pub fn dxgi_buffer_format(f: DXGI_FORMAT) -> Option<(u32, [u32; 4])> { | ||
| match f { | ||
| DXGI_FORMAT_B8G8R8A8_UNORM => Some((56, [6, 5, 4, 7])), |
There was a problem hiding this comment.
The new format-56 + BGRA/BGR1 and format-1 + 000X V#s are also used for typed buffer UAVs (dev_create_uav_x -> buffer_view at real.rs:3763, dev_create_uav_at_x -> buffer_words_at at real.rs:3468). Neither translator applies DST_SEL on stores: lower_mem.rs fmt_pack packs 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.
| return [0; 4]; | ||
| }; | ||
| let fmt = crate::gpu::desc::gfx10_format(format).unwrap_or(22); | ||
| let (fmt, dst_sel) = crate::gpu::desc::dxgi_buffer_format(format).unwrap_or((22, [4, 5, 6, 7])); |
There was a problem hiding this comment.
Formats that dxgi_buffer_format now rejects (B5G6R5_UNORM=133, B5G5R5A1_UNORM=134, B4G4R4A4_UNORM=136, R8G8B8A8_UNORM_SRGB=130) fall back to (22, identity) with stride format_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 and records = min(n, room/4) cuts the view short. buffer_words_at (~3480) does the same and also over-requests tiles from view_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.
|
@Prime1997 could you take a look at this one for review and merge? My automated review notes are above, if any. |
|
Linux / AMD RDNA4 (RADV, Wine + vkd3d-proton): full test suite on Merged onto Setup
Tested:
About the failures on
|
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 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, 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.