Direct DXIL: write every dword of an unaligned multi-dword format store #1922

Manually merged
github merged 1 commit from gh-pr/1922/head into gh-pr/1922/base 2026-11-26 05:09:45 +00:00
Owner

@⁠emirduran707 on GitHub · 2026-11-24 23:15 UTC · original
emirduran707:dxil-format-store-unaligned-dwords → main · +67 −28 · 2 files · 1 commits · merged 2026-11-25 01:34 UTC

In the Direct DXIL translator, st_bytes stores the low n bytes (up to 16) of four dwords for buffer_store_format_* / tbuffer_store_format_*. When the address was not dword aligned (or n was not a multiple of 4) it took the partial path, which only ever wrote r[0], so an 8-, 12- or 16-byte format store at such an address dropped bytes 4..n. The partial path now stores each dword k with 4k < n at b + 4k, with the same shift and mask as before, and spills into the next dword when it crosses one. (#312 fixes the same gap in the HLSL recompiler's st_bytes, recomp/emit.rs; this is the Direct DXIL path.)

What is in it

  • crates/xcl/src/gpu/dxil/lower_mem.rs: the partial path of st_bytes loops over the four dwords instead of writing only the first.
  • crates/xcl/src/gpu/dxil/core_tests.rs: GPU test gpu_direct_unaligned_multi_dword_format_store: lane 0 does a buffer_store_format_xyzw (32_32_32_32_FLOAT, 16 bytes) at byte offset 2 and the test checks the bytes around and inside the store.

Tested

  • AMD Radeon RX 9060 XT (driver 32.0.31044.16), Ryzen 5 5600, Windows 11 Pro 26300, Rust 1.100.0; tests debug, smoke release
  • cargo build --workspace, then cargo test --workspace --no-fail-fast -- --test-threads=4 on 4a6b414 (rebased onto main de36462): 1003 passed, 2 failed, 45 ignored; 8 SKIPPED (6 in lower_dxil::tests::{f16,f32}_programs_on_the_gpu; heap_window_out_of_memory_falls_back_to_the_switch_form; pso_measurement_compiles_an_exact_synthetic_record)
    • The 2 failures (gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1, gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_3) fail identically on unmodified main de36462 on this GPU (seeds 722 and 1599).
  • XCL_DIRECT_DXIL=1 cargo test -p xcl --lib gpu::recomp::tests on 6e61d29 (before the rebase): 123 passed, 0 failed, 17 ignored
  • gpu_direct_unaligned_multi_dword_format_store before the change failed: only the first dword landed (bytes 00 00 80 3f at 0x102), bytes 0x106..0x112 kept the 0xDEADBEEF fill; passes after

Regression run

main:

xcl-smoke v1
commit: de36462e0b1043b915a418d4591ed1e397622ede
gpu: AMD Radeon RX 9060 XT
title: 21222967
seconds: 60
exit: 0x0
frames shown: 1500 (PresentX 1500)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 18920 MB

this PR:

xcl-smoke v1
commit: 4a6b414f1deb13d4d89bd7de1cec660dfb2437ba
gpu: AMD Radeon RX 9060 XT
title: 21222967
seconds: 60
exit: 0x0
frames shown: 1549 (PresentX 1550)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 20495 MB

Not tested

  • NVIDIA and Intel GPUs.
  • 8- and 12-byte formats and MTBUF stores at unaligned addresses on the GPU (they take the same loop).
  • The smoke title's run is a regression check only.

AI use

  • Antigravity with Gemini 4 Neon and Claude Opus 5.5: found the bug, wrote the fix, GPU test and this description, and ran the test suite and smoke runs above.
  • Claude Code with Claude Opus 5.5: rebased the change onto main de36462 (a conflict in crates/xcl/src/gpu/dxil/core_tests.rs; both tests kept) and reran the suite and smoke runs above.
**@⁠emirduran707** on GitHub · 2026-11-24 23:15 UTC · [original](https://github.com/xcl-dev/xcl/pull/1922) `emirduran707:dxil-format-store-unaligned-dwords` → `main` · +67 −28 · 2 files · 1 commits · merged 2026-11-25 01:34 UTC In the Direct DXIL translator, `st_bytes` stores the low `n` bytes (up to 16) of four dwords for `buffer_store_format_*` / `tbuffer_store_format_*`. When the address was not dword aligned (or `n` was not a multiple of 4) it took the partial path, which only ever wrote `r[0]`, so an 8-, 12- or 16-byte format store at such an address dropped bytes 4..n. The partial path now stores each dword `k` with `4k < n` at `b + 4k`, with the same shift and mask as before, and spills into the next dword when it crosses one. (#312 fixes the same gap in the HLSL recompiler's `st_bytes`, `recomp/emit.rs`; this is the Direct DXIL path.) **What is in it** - `crates/xcl/src/gpu/dxil/lower_mem.rs`: the partial path of `st_bytes` loops over the four dwords instead of writing only the first. - `crates/xcl/src/gpu/dxil/core_tests.rs`: GPU test `gpu_direct_unaligned_multi_dword_format_store`: lane 0 does a `buffer_store_format_xyzw` (32_32_32_32_FLOAT, 16 bytes) at byte offset 2 and the test checks the bytes around and inside the store. **Tested** - AMD Radeon RX 9060 XT (driver 32.0.31044.16), Ryzen 5 5600, Windows 11 Pro 26300, Rust 1.100.0; tests debug, smoke release - `cargo build --workspace`, then `cargo test --workspace --no-fail-fast -- --test-threads=4` on 4a6b414 (rebased onto `main` `de36462`): 1003 passed, 2 failed, 45 ignored; 8 SKIPPED (6 in `lower_dxil::tests::{f16,f32}_programs_on_the_gpu`; `heap_window_out_of_memory_falls_back_to_the_switch_form`; `pso_measurement_compiles_an_exact_synthetic_record`) - The 2 failures (`gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1`, `gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_3`) fail identically on unmodified `main` `de36462` on this GPU (seeds 722 and 1599). - `XCL_DIRECT_DXIL=1 cargo test -p xcl --lib gpu::recomp::tests` on 6e61d29 (before the rebase): 123 passed, 0 failed, 17 ignored - `gpu_direct_unaligned_multi_dword_format_store` before the change failed: only the first dword landed (bytes `00 00 80 3f` at 0x102), bytes 0x106..0x112 kept the `0xDEADBEEF` fill; passes after **Regression run** main: ``` xcl-smoke v1 commit: de36462e0b1043b915a418d4591ed1e397622ede gpu: AMD Radeon RX 9060 XT title: 21222967 seconds: 60 exit: 0x0 frames shown: 1500 (PresentX 1500) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 18920 MB ``` this PR: ``` xcl-smoke v1 commit: 4a6b414f1deb13d4d89bd7de1cec660dfb2437ba gpu: AMD Radeon RX 9060 XT title: 21222967 seconds: 60 exit: 0x0 frames shown: 1549 (PresentX 1550) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 20495 MB ``` **Not tested** - NVIDIA and Intel GPUs. - 8- and 12-byte formats and MTBUF stores at unaligned addresses on the GPU (they take the same loop). - The smoke title's run is a regression check only. **AI use** - Antigravity with Gemini 4 Neon and Claude Opus 5.5: found the bug, wrote the fix, GPU test and this description, and ran the test suite and smoke runs above. - Claude Code with Claude Opus 5.5: rebased the change onto `main` `de36462` (a conflict in `crates/xcl/src/gpu/dxil/core_tests.rs`; both tests kept) and reran the suite and smoke runs above.
`st_bytes` stores the low `n` bytes of four dwords. When the address was not
dword aligned (or `n` not a multiple of 4) it took the partial path, which
only ever wrote `r[0]`: an 8-, 12- or 16-byte `buffer_store_format_*` /
`tbuffer_store_format_*` at such an address dropped bytes 4..n. The partial
path now stores each dword `k` with `4k < n` at `b + 4k`, shifted and masked
the same way, spilling into the next dword when it crosses one.

Assisted-by: Antigravity (Gemini 4 Neon, Claude Opus 5.5)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:09:44 +00:00
github manually merged commit 4a6b414f1d into gh-pr/1922/base 2026-11-26 05:09:45 +00:00
Author
Owner

@⁠upipibi on GitHub · 2026-11-24 23:20 UTC · original

NVIDIA counterpart to the Radeon run: RTX 3070 8 GB, driver 616.56, Windows 11, debug, 6e61d29 on main 689f2db. gpu_direct_unaligned_multi_dword_format_store and the tests matching format_store: 2 passed, 0 failed, with and without XCL_DIRECT_DXIL=1.

AI-assisted (Claude Code). Synthetic tests only.

**@⁠upipibi** on GitHub · 2026-11-24 23:20 UTC · [original](https://github.com/xcl-dev/xcl/pull/1922#issuecomment-7147295739) NVIDIA counterpart to the Radeon run: RTX 3070 8 GB, driver 616.56, Windows 11, debug, `6e61d29` on `main` `689f2db`. `gpu_direct_unaligned_multi_dword_format_store` and the tests matching `format_store`: 2 passed, 0 failed, with and without `XCL_DIRECT_DXIL=1`. AI-assisted (Claude Code). Synthetic tests only.
Author
Owner

@⁠WebIdentity1 on GitHub · 2026-11-24 23:35 UTC · original

Tested the two paths listed as untested here: 8- and 12-byte stores, including MTBUF. The test-only patch below adds 16 synthetic GPU readback cases: MUBUF/MTBUF × 8/12 bytes × offsets 0/1/2/3. It compares the entire 512-byte buffer with a bytewise expected result. MTBUF uses a deliberately different descriptor format to check that the instruction format wins.

On RTX 3090, driver 591.74, Ryzen 7 7800X3D, Windows 10 19045, Rust 1.98.1 MSVC, debug:

  • Base 689f2db plus both test functions: 0 passed / 1 failed / 0 ignored, no skips. All 12 unaligned cases mismatched; all four aligned controls matched.
  • Head 6e61d294c825a4d34156dea7c5f8eb0f35afa3c4 plus the new test: 1 passed / 0 failed / 0 ignored, no skips. All 16 cases matched.

Command: cargo test --locked -p xcl --lib gpu_direct_short_multi_dword_format_stores -- --test-threads=1 --show-output, with XCL_ADAPTER=3090. Each tree was rebuilt; 310-file source manifests matched before/after, with only lower_mem.rs differing between the pair.

This supports the existing fix; no additional production change is proposed. Not tested: full suite for this overlay, retail smoke/gameplay, AMD, or performance. The patch is available to fold into this PR.

Test-only patch
diff --git a/crates/xcl/src/gpu/dxil/core_tests.rs b/crates/xcl/src/gpu/dxil/core_tests.rs
index 41adc54..e60a18d 100644
--- a/crates/xcl/src/gpu/dxil/core_tests.rs
+++ b/crates/xcl/src/gpu/dxil/core_tests.rs
@@ -469,3 +469,48 @@ fn gpu_direct_unaligned_multi_dword_format_store() {
     let got: Vec<u8> = r.mem.iter().flat_map(|v| v.to_le_bytes()).collect();
     assert_eq!(&got[0xFC..0x118], &want[0xFC..0x118], "bytes 0xFC..0x118 after the store at 0x102");
 }
+
+/// Shorter multi-dword stores exercise both descriptor and instruction formats,
+/// every byte alignment, and preservation of the bytes outside the store.
+#[test]
+fn gpu_direct_short_multi_dword_format_stores() {
+    use crate::gpu::recomp::runner::{self, KernelState};
+    if runner::adapter().is_err() || runner::wave64_programs_supported() != Ok(true) || crate::gpu::recomp::dxc::location().is_err() {
+        return runner::skip_test("no GPU / DXC / wave64");
+    }
+    let vals = [1.0f32, -2.0, 3.5, -4.25].map(f32::to_bits);
+    let fill = 0xDEAD_BEEFu32;
+    let mut failures = Vec::new();
+    for (prefix, enc) in [("BUFFER", "ENC_MUBUF"), ("TBUFFER", "ENC_MTBUF")] {
+        for (suffix, fmt, count) in [("XY", 64u64, 2usize), ("XYZ", 74, 3)] {
+            let name = format!("{prefix}_STORE_FORMAT_{suffix}");
+            let mut fields = vec![("VDATA", 10), ("VADDR", 1), ("SRSRC", 3), ("SOFFSET", 128), ("OFFEN", 1)];
+            if enc == "ENC_MTBUF" { fields.push(("FORMAT", fmt)); }
+            let code = prog(&[
+                ("V_CMPX_EQ_U32", "ENC_VOPC", &[("SRC0", 128), ("VSRC1", 0)], None),
+                (&name, enc, &fields, None),
+            ]);
+            let dxil = runner::direct_kernel(&code, true).expect("direct translation");
+            super::validate::validate(&dxil).expect("validator");
+            for offset in 0..4usize {
+                let mut st = KernelState::default();
+                // MTBUF must use its instruction format, not this different V# format.
+                let descriptor_fmt = if enc == "ENC_MTBUF" { 77 } else { fmt as u32 };
+                st.sgpr[12..16].copy_from_slice(&[0x100, 0, 64, (4 | 5 << 3 | 6 << 6 | 7 << 9) | descriptor_fmt << 12]);
+                for (lane, r) in st.vgpr.iter_mut().enumerate() {
+                    r[0] = lane as u32;
+                    r[1] = offset as u32;
+                    r[10..14].copy_from_slice(&vals);
+                }
+                let result = runner::run(&dxil, &st, &vec![fill; 128]).expect("GPU run");
+                let mut want: Vec<u8> = std::iter::repeat_n(fill.to_le_bytes(), 128).flatten().collect();
+                let start = 0x100 + offset;
+                want[start..start + count * 4].copy_from_slice(&vals[..count].iter().flat_map(|v| v.to_le_bytes()).collect::<Vec<_>>());
+                let got: Vec<u8> = result.mem.iter().flat_map(|v| v.to_le_bytes()).collect();
+                if got != want { failures.push(format!("{name} offset {offset}")); }
+            }
+        }
+    }
+    println!("16 format-store cases, {} mismatches: {failures:?}", failures.len());
+    assert!(failures.is_empty(), "format-store byte mismatches: {failures:?}");
+}

AI use: Codex with GPT-6 Astra wrote the additional test, ran the Windows checks, and drafted this report.

**@⁠WebIdentity1** on GitHub · 2026-11-24 23:35 UTC · [original](https://github.com/xcl-dev/xcl/pull/1922#issuecomment-7147582961) Tested the two paths listed as untested here: 8- and 12-byte stores, including MTBUF. The test-only patch below adds 16 synthetic GPU readback cases: MUBUF/MTBUF × 8/12 bytes × offsets 0/1/2/3. It compares the entire 512-byte buffer with a bytewise expected result. MTBUF uses a deliberately different descriptor format to check that the instruction format wins. On **RTX 3090, driver 591.74, Ryzen 7 7800X3D, Windows 10 19045, Rust 1.98.1 MSVC**, debug: - Base `689f2db` plus both test functions: **0 passed / 1 failed / 0 ignored**, no skips. All 12 unaligned cases mismatched; all four aligned controls matched. - Head `6e61d294c825a4d34156dea7c5f8eb0f35afa3c4` plus the new test: **1 passed / 0 failed / 0 ignored**, no skips. All 16 cases matched. Command: `cargo test --locked -p xcl --lib gpu_direct_short_multi_dword_format_stores -- --test-threads=1 --show-output`, with `XCL_ADAPTER=3090`. Each tree was rebuilt; 310-file source manifests matched before/after, with only `lower_mem.rs` differing between the pair. This supports the existing fix; no additional production change is proposed. **Not tested:** full suite for this overlay, retail smoke/gameplay, AMD, or performance. The patch is available to fold into this PR. <details><summary>Test-only patch</summary> ```diff diff --git a/crates/xcl/src/gpu/dxil/core_tests.rs b/crates/xcl/src/gpu/dxil/core_tests.rs index 41adc54..e60a18d 100644 --- a/crates/xcl/src/gpu/dxil/core_tests.rs +++ b/crates/xcl/src/gpu/dxil/core_tests.rs @@ -469,3 +469,48 @@ fn gpu_direct_unaligned_multi_dword_format_store() { let got: Vec<u8> = r.mem.iter().flat_map(|v| v.to_le_bytes()).collect(); assert_eq!(&got[0xFC..0x118], &want[0xFC..0x118], "bytes 0xFC..0x118 after the store at 0x102"); } + +/// Shorter multi-dword stores exercise both descriptor and instruction formats, +/// every byte alignment, and preservation of the bytes outside the store. +#[test] +fn gpu_direct_short_multi_dword_format_stores() { + use crate::gpu::recomp::runner::{self, KernelState}; + if runner::adapter().is_err() || runner::wave64_programs_supported() != Ok(true) || crate::gpu::recomp::dxc::location().is_err() { + return runner::skip_test("no GPU / DXC / wave64"); + } + let vals = [1.0f32, -2.0, 3.5, -4.25].map(f32::to_bits); + let fill = 0xDEAD_BEEFu32; + let mut failures = Vec::new(); + for (prefix, enc) in [("BUFFER", "ENC_MUBUF"), ("TBUFFER", "ENC_MTBUF")] { + for (suffix, fmt, count) in [("XY", 64u64, 2usize), ("XYZ", 74, 3)] { + let name = format!("{prefix}_STORE_FORMAT_{suffix}"); + let mut fields = vec![("VDATA", 10), ("VADDR", 1), ("SRSRC", 3), ("SOFFSET", 128), ("OFFEN", 1)]; + if enc == "ENC_MTBUF" { fields.push(("FORMAT", fmt)); } + let code = prog(&[ + ("V_CMPX_EQ_U32", "ENC_VOPC", &[("SRC0", 128), ("VSRC1", 0)], None), + (&name, enc, &fields, None), + ]); + let dxil = runner::direct_kernel(&code, true).expect("direct translation"); + super::validate::validate(&dxil).expect("validator"); + for offset in 0..4usize { + let mut st = KernelState::default(); + // MTBUF must use its instruction format, not this different V# format. + let descriptor_fmt = if enc == "ENC_MTBUF" { 77 } else { fmt as u32 }; + st.sgpr[12..16].copy_from_slice(&[0x100, 0, 64, (4 | 5 << 3 | 6 << 6 | 7 << 9) | descriptor_fmt << 12]); + for (lane, r) in st.vgpr.iter_mut().enumerate() { + r[0] = lane as u32; + r[1] = offset as u32; + r[10..14].copy_from_slice(&vals); + } + let result = runner::run(&dxil, &st, &vec![fill; 128]).expect("GPU run"); + let mut want: Vec<u8> = std::iter::repeat_n(fill.to_le_bytes(), 128).flatten().collect(); + let start = 0x100 + offset; + want[start..start + count * 4].copy_from_slice(&vals[..count].iter().flat_map(|v| v.to_le_bytes()).collect::<Vec<_>>()); + let got: Vec<u8> = result.mem.iter().flat_map(|v| v.to_le_bytes()).collect(); + if got != want { failures.push(format!("{name} offset {offset}")); } + } + } + } + println!("16 format-store cases, {} mismatches: {failures:?}", failures.len()); + assert!(failures.is_empty(), "format-store byte mismatches: {failures:?}"); +} ``` </details> **AI use:** Codex with GPT-6 Astra wrote the additional test, ran the Windows checks, and drafted this report.
Author
Owner

@⁠raylitebull on GitHub · 2026-11-25 01:08 UTC · original

Both AMD and NVIDIA verification look good on 6e61d29. This is currently DIRTY with merge conflicts against main — please rebase onto main and let Build and test (Windows, no GPU) run cleanly so we can merge.

**@⁠raylitebull** on GitHub · 2026-11-25 01:08 UTC · [original](https://github.com/xcl-dev/xcl/pull/1922#issuecomment-7149239326) Both AMD and NVIDIA verification look good on `6e61d29`. This is currently `DIRTY` with merge conflicts against `main` — please rebase onto `main` and let `Build and test (Windows, no GPU)` run cleanly so we can merge.
Author
Owner

@⁠DavidM1911 on GitHub · 2026-11-25 02:33 UTC · original

Verification on RTX 3060 Ti (Windows 11): merge conflict with current main — needs a rebase before it can be tested.

**@⁠DavidM1911** on GitHub · 2026-11-25 02:33 UTC · [original](https://github.com/xcl-dev/xcl/pull/1922#issuecomment-7150886179) Verification on RTX 3060 Ti (Windows 11): **merge conflict with current `main`** — needs a rebase before it can be tested.
Author
Owner

@⁠DavidM1911 on GitHub · 2026-11-26 00:42 UTC · original

Re-verification on RTX 3060 Ti (Windows 11), new head merged with current main:

  • cargo test -p xcl --lib: all passed, 0 failed, 27 ignored. The earlier merge conflict is resolved.

Thanks!

— Devin

**@⁠DavidM1911** on GitHub · 2026-11-26 00:42 UTC · [original](https://github.com/xcl-dev/xcl/pull/1922#issuecomment-7179038562) Re-verification on RTX 3060 Ti (Windows 11), new head merged with current `main`: - `cargo test -p xcl --lib`: all passed, 0 failed, 27 ignored. The earlier merge conflict is resolved. Thanks! — Devin
This discussion has been locked. Commenting is limited to contributors.
No description provided.