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

Merged
emirduran707 merged 1 commit from upstream-pr/1922 into main 2026-11-25 01:34:10 +00:00
emirduran707 commented 2026-11-24 23:15:17 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by emirduran707 on 2026-11-24T23:15:17Z.


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.
<!-- greyfinch-sync:ivall/xcl:issue:6593336901 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1922). Originally posted by [emirduran707](https://github.com/emirduran707) on 2026-11-24T23:15:17Z. --- 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.
towiice commented 2026-11-25 00:08:23 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by towiice on 2026-11-24T23:52:23Z.

Review: COMMENTED


Verified on Windows 11 (NVIDIA GeForce GTX 1650 SUPER, 4 GB Turing TU116, wave32, driver 610.88, DXC 1.9.2609.5):

  • \cargo test -p xcl --lib gpu_direct_unaligned_multi_dword_format_store: 1 passed; 0 failed (0.63s)

Iterating over each dword \k\ (\4 * k < n) at \ + 4 * k\ in the partial path of \st_bytes\ properly preserves bytes \4..n\ for unaligned 8-, 12-, and 16-byte \uffer_store_format_\ / \ buffer_store_format_\ stores.

<!-- greyfinch-sync:ivall/xcl:review:6049334599 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1922#pullrequestreview-6049334599). Originally posted by [towiice](https://github.com/towiice) on 2026-11-24T23:52:23Z. **Review:** COMMENTED --- Verified on Windows 11 (NVIDIA GeForce GTX 1650 SUPER, 4 GB Turing TU116, wave32, driver 610.88, DXC 1.9.2609.5): - \cargo test -p xcl --lib gpu_direct_unaligned_multi_dword_format_store\: **1 passed; 0 failed** (0.63s) Iterating over each dword \k\ (\4 * k < n\) at \ + 4 * k\ in the partial path of \st_bytes\ properly preserves bytes \4..n\ for unaligned 8-, 12-, and 16-byte \uffer_store_format_*\ / \ buffer_store_format_*\ stores.
upipibi commented 2026-11-25 00:08:51 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by upipibi on 2026-11-24T23:20:48Z.


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.

<!-- greyfinch-sync:ivall/xcl:comment:7147295739 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1922#issuecomment-7147295739). Originally posted by [upipibi](https://github.com/upipibi) on 2026-11-24T23:20:48Z. --- 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.
WebIdentity1 commented 2026-11-25 00:08:57 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by WebIdentity1 on 2026-11-24T23:35:57Z.


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.

<!-- greyfinch-sync:ivall/xcl:comment:7147582961 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1922#issuecomment-7147582961). Originally posted by [WebIdentity1](https://github.com/WebIdentity1) on 2026-11-24T23:35:57Z. --- 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.
raylitebull commented 2026-11-25 01:11:06 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by raylitebull on 2026-11-25T01:08:02Z.


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.

<!-- greyfinch-sync:ivall/xcl:comment:7149239326 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1922#issuecomment-7149239326). Originally posted by [raylitebull](https://github.com/raylitebull) on 2026-11-25T01:08:02Z. --- 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.
upstream-sync closed this pull request 2026-11-25 02:07:50 +00:00
DavidM1911 commented 2026-11-25 03:05:46 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-25T02:33:55Z.


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

<!-- greyfinch-sync:ivall/xcl:comment:7150886179 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1922#issuecomment-7150886179). Originally posted by [DavidM1911](https://github.com/DavidM1911) on 2026-11-25T02:33:55Z. --- Verification on RTX 3060 Ti (Windows 11): **merge conflict with current `main`** — needs a rebase before it can be tested.
DavidM1911 commented 2026-11-26 01:05:42 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-26T00:42:46Z.


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

<!-- greyfinch-sync:ivall/xcl:comment:7179038562 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1922#issuecomment-7179038562). Originally posted by [DavidM1911](https://github.com/DavidM1911) on 2026-11-26T00:42:46Z. --- 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
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
xcl-dev/xcl!1912
No description provided.