Skip to content

Shaders: guard wave64 graphics direct DXIL - #1913

Open
mokkamokacaffe wants to merge 1 commit into
xcl-dev:mainfrom
mokkamokacaffe:dxil/guard-wave64-graphics-cache
Open

mokkamokacaffe wants to merge 1 commit into
xcl-dev:mainfrom
mokkamokacaffe:dxil/guard-wave64-graphics-cache

Conversation

@mokkamokacaffe

@mokkamokacaffe mokkamokacaffe commented Nov 24, 2026 •

Copy link
Copy Markdown

What is in it

Fixes #1895.

  • Passes the adapter's wave32/split requirement into the Direct DXIL VS/PS route.
  • Falls back to the HLSL upper_lanes implementation when a wave64 graphics shader reads data from lanes 32-63 that Direct DXIL cannot represent in a 32-lane wave.
  • Applies the same refusal to xcl shaders --direct, keeping coverage results consistent with runtime routing.
  • Disables the translated shader caches while XCL_DXIL_NO_OPT is set, so diagnostic, deliberately unoptimized DXIL cannot poison later normal runs.
  • Adds focused unit coverage for upper-lane classification and the cache override.

Tested

  • git diff --check
  • Source-level call-site audit for direct_graphics and needs_upper_lanes.

The current Linux workspace does not contain Cargo/Rust or the Windows D3D12/DXIL toolchain, so Rust unit tests and DXIL validation were not run here.

Regression run

Not run: this change needs the maintainer's Windows/GPU smoke pass on both this exact head commit and its main base. Please apply test-only until those two matching xcl-smoke v1 blocks are available.

Not tested

  • Runtime smoke test in a retail title.
  • DXIL validator execution.
  • AMD and NVIDIA GPU execution of affected wave64 VS/PS shaders.

AI use

OpenAI Codex was used to inspect issue #1895 and current source, implement the routing/cache guard, add focused tests, and perform source-level validation. No generated test results or hardware claims are included.

@mokkamokacaffe
mokkamokacaffe force-pushed the dxil/guard-wave64-graphics-cache branch from e9d23be to 5e89ca2 Compare November 24, 2026 23:10
gustavsi added a commit to gustavsi/xcl that referenced this pull request Nov 24, 2026

@Melow-code Melow-code left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Routing is correct — wave64 VS/PS reading lanes 32-63 goes to HLSL upper_lanes. Three points:

  1. needs_upper_lanes stops at the first decode error and returns the partial result. For a guard, the safe answer is true when decode fails before S_ENDPGM.
  2. The new check in coverage.rs runs before catch_unwind. A panic in upper_lanes::analyze stops the whole coverage run. Put it inside the closure.
  3. split stays false — if direct graphics has no split form, a one-line comment would clarify this.

Please run the Rust tests on Windows before merge.

@WebIdentity1

Copy link
Copy Markdown

I tested commit e9d23bed39c766d071325f9c63dff8e5d5ff6115 on native Windows 10 19045, RTX 3090 (driver 591.74), Rust 1.98.1 MSVC, DXC 1.8.2502.11. The current head 5e89ca2bf2bb25758d5c2e7eb9cafd2e43f1433c has the identical tree (3a69a738801756a4b5b1908eb8a3513cfd32c2a1) and parent; only the commit object changed. OpenAI Codex (GPT-6) prepared the synthetic test and ran the checks over SSH. Source-only archives were SHA-256 checked before and after each run; no game files were used.

The existing a_whole_wave_reduction_reads_its_identity, shader_cache_bypasses_debug_overrides, gpu_wave64_ps_whole_wave_reductions, gpu_wave64_vs_spill_slots_and_identity, and direct_and_hlsl_graphics_stages_link tests each passed 1/0/0, with no GPU skips. I also added a local test-only overlay to exercise coverage::translate_mode for both VS and PS with a written lane 32. It passed 1/0/0 on this PR; on parent 689f2db477c3c062cf162649781640ef8a977c18, the same test (minus the new needs_upper_lanes assertion, which the parent does not define) failed because direct translation returned Ok. Here is the head-side test to add if useful:

#[test]
fn split_wave64_graphics_refuses_upper_lane_read() {
    let mut code = rdna2::encode("V_WRITELANE_B32", "ENC_VOP3", &[("VDST", 6), ("SRC0", 20), ("SRC1", 128 + 32)], None).expect("encode");
    code.extend(rdna2::encode("V_READLANE_B32", "ENC_VOP3", &[("VDST", 10), ("SRC0", 256 + 6), ("SRC1", 128 + 32)], None).expect("encode"));
    code.extend(rdna2::encode("S_ENDPGM", "ENC_SOPP", &[], None).expect("encode"));
    assert!(crate::gpu::recomp::needs_upper_lanes(&code));
    let o = KernelOptions { wave64: true, split: true, mem_windows: 1, sampler_base: 0 };
    for mode in [Mode::Vertex(Default::default()), Mode::Pixel(Default::default())] {
        let err = translate_mode(&code, &mode, o, false).unwrap_err();
        assert!(err.contains("upper-lane emulation"), "{mode:?}: {err}");
    }
}

I ran cargo test --locked --workspace -- --test-threads=4 on the clean PR head. The xcl library test binary stopped the workspace run: 922 passed, 4 failed, 25 ignored, 0 SKIPPED. The same four failures and 922/4/25 count occurred on the parent with only the regression test overlaid and excluded (--skip split_wave64_graphics_refuses_upper_lane_read): gpu_clamp_and_omod_per_instruction, placed_title_textures_share_vram_and_preserve_pixels, and two lock-poisoned texture/VRAM tests. These failures predate this PR on this machine; the remaining workspace packages did not run after the library failure.

This validates the split-wave refusal at the offline translator and adjacent GPU graphics output. It does not exercise a retail shader container through the live PSO route or satisfy the required paired retail smoke.ps1 gate. I did not run a proprietary title.

@eizispark

Copy link
Copy Markdown

Hardware test report — commit 5e89ca2

Verified 5e89ca2bf2bb25758d5c2e7eb9cafd2e43f1433c (based on 689f2db477c3c062cf162649781640ef8a977c18; clean merge with current main 20cf130): pass (0 new failures vs 689f2db).

Tested

  • Hardware: Windows 11 x64, AMD Ryzen 7 9800X3D, AMD Radeon RX 9070 XT (RDNA4, native wave32 + wave64, driver 32.0.32015.16001), 32 GB RAM, rustc 1.100.0 (0ef1bc386 2026-11-09) (stable-x86_64-pc-windows-msvc), debug tests + release smoke
  • cargo test --workspace --no-fail-fast -- --test-threads=4 --skip gpu::dxil::msaa_tests::gpu_direct_msaa_image_loads: 972 passed, 2 failed, 45 ignored (8 skipped), matching 689f2db (972 passed, 2 failed, 45 ignored, 8 skipped) on this adapter:
    • --skip gpu::dxil::msaa_tests::gpu_direct_msaa_image_loads avoids the pre-#1900 RDNA4 amdxc64 crash on base 689f2db, and the 2 failures (gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1, gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_3) are the pre-existing 689f2db AMD fuzz seeds; 0 new failures
    • 8 skipped: 6 gpu::recomp::lower_dxil::tests f16/f32 direct-DXIL per-lane cases refused where #1426 semantics differ from the console's; shaders::tests::pso_measurement_compiles_an_exact_synthetic_record (Windows Developer Mode required, 0x887A002D); heap_window_out_of_memory_falls_back_to_the_switch_form: no heap windows
  • gpu::recomp::upper_lanes::tests::a_whole_wave_reduction_reads_its_identity (9/9 upper_lanes::tests), gpu::recomp::pso::shader_cache_tests::shader_cache_bypasses_debug_overrides, and native RDNA4 wave64 GPU tests (gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware, console_wave64_compute_through_the_pso_hook_dispatch_and_read_back) all passed

Regression run
main (689f2db477c3c062cf162649781640ef8a977c18):

xcl-smoke v1
commit: 689f2db477c3c062cf162649781640ef8a977c18
gpu: AMD Radeon RX 9070 XT
title: 9cc6a39e
seconds: 60
exit: 0x0
frames shown: 1674 (PresentX 1674)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14862 MB

PR (5e89ca2bf2bb25758d5c2e7eb9cafd2e43f1433c):

xcl-smoke v1
commit: 5e89ca2bf2bb25758d5c2e7eb9cafd2e43f1433c
gpu: AMD Radeon RX 9070 XT
title: 9cc6a39e
seconds: 60
exit: 0x0
frames shown: 1679 (PresentX 1679)
presents per 2 s (last 3): 61 60 60
device removals: 0
crashes: 0
peak commit: 14730 MB

Not tested

  • wave32-only GPUs (NVIDIA / Intel) where wave64 graphics shaders hit the needs_upper_lanes direct-DXIL fallback, XCL_SHADER_BACKEND=dxil retail run, gameplay past the menus

AI use

  • Antigravity (Google DeepMind, Gemini 4 Carbon) ran the workspace test suite and 60-second retail smoke check and formatted this report.

@WebIdentity1

Copy link
Copy Markdown

I tested a local patch for @ruipedro-pinheiro's three review points on the source tree of 5e89ca2 (identical to tested e9d23be). OpenAI Codex (GPT-6) prepared it and ran the native Windows checks; no code was pushed. The patch below applies to the clean PR tree (git apply --check passed).

The guard now returns true for an unknown instruction, a decoded instruction extending beyond the byte slice, or trailing incomplete bytes. This is conservative even after S_ENDPGM; the direct CFG decoder also rejects unknown instructions, and the extra fallback avoids acting on a partial lane analysis. The offline guard is inside catch_unwind, and the split: false choice is documented at the live graphics call site.

diff --git a/crates/xcl/src/gpu/recomp/mod.rs b/crates/xcl/src/gpu/recomp/mod.rs
--- a/crates/xcl/src/gpu/recomp/mod.rs
+++ b/crates/xcl/src/gpu/recomp/mod.rs
@@ -1200,9 +1200,15 @@
     let mut insts = Vec::new();
     let mut off = 0;
     while off + 4 <= code.len() {
-        let Ok(d) = rdna2::decode(&code[off..], off as u64) else { break };
+        let Ok(d) = rdna2::decode(&code[off..], off as u64) else { return true };
+        if d.len > code.len() - off {
+            return true;
+        }
         off += d.len;
         insts.push(d);
+    }
+    if off != code.len() {
+        return true;
     }
     rdna2::resolve_far_jumps(&mut insts);
     upper_lanes::analyze(&insts).reads.values().any(|&r| r != upper_lanes::Read::Native)
diff --git a/crates/xcl/src/gpu/dxil/coverage.rs b/crates/xcl/src/gpu/dxil/coverage.rs
--- a/crates/xcl/src/gpu/dxil/coverage.rs
+++ b/crates/xcl/src/gpu/dxil/coverage.rs
@@ -248,20 +248,22 @@
 /// own thread) come back as `"panic: …"`; `validate` runs DXC's validator on the result
 /// (the translator itself only validates in debug / test builds).
 pub fn translate_mode(code: &[u8], mode: &Mode, o: KernelOptions, validate: bool) -> Result<Vec<u8>, String> {
-    if o.wave64
-        && o.split
-        && matches!(mode, Mode::Vertex(_) | Mode::Pixel(_))
-        && crate::gpu::recomp::needs_upper_lanes(code)
-    {
-        return Err("wave64 VS / PS in 32-lane waves needs upper-lane emulation".into());
-    }
-    let r = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| match mode {
-        Mode::Kernel => kernel::translate_full(code, o),
-        Mode::Compute(cs) => kernel::translate_compute(code, o, cs),
-        Mode::Vertex(vs) => kernel::translate_vertex(code, KernelOptions { split: false, ..o }, vs),
-        Mode::Pixel(ps) => kernel::translate_pixel(code, KernelOptions { split: false, ..o }, ps),
-        Mode::Mesh(ms) => kernel::translate_mesh(code, o, ms),
-        Mode::Geometry(g) => kernel::translate_geometry(code, o, g),
+    let r = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| {
+        if o.wave64
+            && o.split
+            && matches!(mode, Mode::Vertex(_) | Mode::Pixel(_))
+            && crate::gpu::recomp::needs_upper_lanes(code)
+        {
+            return Err("wave64 VS / PS in 32-lane waves needs upper-lane emulation".into());
+        }
+        match mode {
+            Mode::Kernel => kernel::translate_full(code, o),
+            Mode::Compute(cs) => kernel::translate_compute(code, o, cs),
+            Mode::Vertex(vs) => kernel::translate_vertex(code, KernelOptions { split: false, ..o }, vs),
+            Mode::Pixel(ps) => kernel::translate_pixel(code, KernelOptions { split: false, ..o }, ps),
+            Mode::Mesh(ms) => kernel::translate_mesh(code, o, ms),
+            Mode::Geometry(g) => kernel::translate_geometry(code, o, g),
+        }
     }));
     let k = match r {
         Ok(r) => r?,
diff --git a/crates/xcl/src/gpu/recomp/pso.rs b/crates/xcl/src/gpu/recomp/pso.rs
--- a/crates/xcl/src/gpu/recomp/pso.rs
+++ b/crates/xcl/src/gpu/recomp/pso.rs
@@ -659,6 +659,7 @@
     if wave64 && split_wave64 && super::needs_upper_lanes(code) {
         return Err("wave64 VS / PS in 32-lane waves needs upper-lane emulation".into());
     }
+    // Direct graphics has no split-wave64 form; programs needing upper-lane emulation fell back above.
     let o = crate::gpu::dxil::kernel::KernelOptions { wave64, split: false, mem_windows: windows, sampler_base };
     let k = match (&mode, stage) {
         (Mode::Vertex(vs), Stage::Vertex) => crate::gpu::dxil::kernel::translate_vertex(code, o, vs)?,

I also added this focused test alongside the written-lane-32 test from my previous comment; it failed on the original PR code and passed with the patch:

#[test]
fn split_wave64_graphics_refuses_incomplete_decode() {
    let unknown = 0x0000_003fu32.to_le_bytes();
    let mut truncated = rdna2::encode("S_NOP", "ENC_SOPP", &[("SIMM16", 0)], None).expect("encode");
    truncated.extend([1, 2]);
    let o = KernelOptions { wave64: true, split: true, mem_windows: 1, sampler_base: 0 };
    for code in [&unknown[..], &truncated[..]] {
        assert!(crate::gpu::recomp::needs_upper_lanes(code));
        for mode in [Mode::Vertex(Default::default()), Mode::Pixel(Default::default())] {
            let err = translate_mode(code, &mode, o, false).unwrap_err();
            assert!(err.contains("upper-lane emulation"), "{mode:?}: {err}");
        }
    }
}

Tested: Native Windows 10 19045, RTX 3090 driver 591.74, Rust 1.98.1 MSVC, DXC 1.8.2502.11; 310 source files per snapshot matched SHA-256 manifests before/after. cargo test --locked -p xcl --lib split_wave64_graphics_refuses_incomplete_decode -- --test-threads=1 --show-output: original PR plus test 0/1/0 (expected negative); patched PR 1/0/0. The written-lane-32 guard, classifier, cache, and two wave64 graphics output tests each passed 1/0/0 on the patched PR, no focused GPU skips.

Paired cargo test --locked --workspace --no-fail-fast -- --test-threads=4: clean PR tree 970 passed / 5 failed / 45 ignored, patch plus two tests 972 / 5 / 45 across 20 targets. Both runs had the same five failures (gpu_clamp_and_omod_per_instruction, placed_title_textures_share_vram_and_preserve_pixels, two poisoned texture/VRAM tests, test_title_runs_and_game_folder_is_untouched) and the same 23 explicit GPU skip notices. Cargo recompiled XCL in both runs. This is a same-tree comparison, not a claim that the pre-existing failures are fixed.

Not tested: Paired retail smoke.ps1 with this local patch, AMD, or a retail wave64 VS/PS through the live direct-DXIL PSO route. The other tester's retail smoke covered the unpatched PR head.

anoyarou pushed a commit to anoyarou/xcl that referenced this pull request Nov 24, 2026
@mokkamokacaffe
mokkamokacaffe force-pushed the dxil/guard-wave64-graphics-cache branch 2 times, most recently from 34eb8d4 to 74822df Compare November 24, 2026 23:30
@WebIdentity1

Copy link
Copy Markdown

One additional test closes part of the live graphics container coverage gap. It uses the repository's existing synthetic xbox::tests::{fssm, sample} helpers, calls pso::direct_graphics with split_wave64=true for both VS and PS, checks the upper-lane refusal, then checks that console_translation produces complete HLSL and DXC compiles it. It does not set global environment variables or need game data. This test-only patch applies to the clean current PR tree:

diff --git a/crates/xcl/src/gpu/recomp/pso.rs b/crates/xcl/src/gpu/recomp/pso.rs
--- a/crates/xcl/src/gpu/recomp/pso.rs
+++ b/crates/xcl/src/gpu/recomp/pso.rs
@@ -915,6 +915,27 @@
 #[cfg(test)]
 mod shader_cache_tests {
     use super::*;
+
+    #[test]
+    fn direct_graphics_routes_written_upper_lane_to_hlsl() {
+        use crate::gpu::{rdna2, xbox::tests::{fssm, sample}};
+
+        let mut code = rdna2::encode("V_WRITELANE_B32", "ENC_VOP3", &[("VDST", 6), ("SRC0", 20), ("SRC1", 128 + 32)], None).unwrap();
+        code.extend(rdna2::encode("V_READLANE_B32", "ENC_VOP3", &[("VDST", 10), ("SRC0", 256 + 6), ("SRC1", 128 + 32)], None).unwrap());
+        code.extend(rdna2::encode("S_ENDPGM", "ENC_SOPP", &[], None).unwrap());
+        for (kind, hw, api, stage) in [(1, 4, 0, Stage::Vertex), (0, 5, 1, Stage::Pixel)] {
+            let blob = sample(kind, &[fssm(&code, &[(hw, api)])]);
+            let err = match direct_graphics(&blob, stage, 0, 1, true) {
+                Err(e) => e,
+                Ok(_) => panic!("{stage:?}: direct graphics accepted a written upper lane"),
+            };
+            assert!(err.contains("upper-lane emulation"), "{stage:?}: {err}");
+            let (hlsl, profile) = console_translation(&blob, stage, 0, 1, true).unwrap();
+            assert!(hlsl.complete(), "{stage:?}: {:?}", hlsl.unsupported_why);
+            let dxil = dxc::compile(&hlsl.hlsl, "main", profile, &[]).unwrap();
+            assert!(!dxil.is_empty(), "{stage:?}: DXC produced no DXIL");
+        }
+    }
 
     #[test]
     fn translated_identity_tracks_sources_and_dxc() {

Tested: OpenAI Codex (GPT-6) ran cargo test --locked -p xcl --lib direct_graphics_routes_written_upper_lane_to_hlsl -- --test-threads=1 --show-output on native Windows 10 19045 with RTX 3090 driver 591.74, Rust 1.98.1 MSVC and DXC 1.8.2502.11. 1 passed / 0 failed / 0 ignored. The test uses DXC but does not execute the GPU. The 310-file source archive was the unchanged PR tree plus this test only and matched its SHA-256 manifest before/after; Cargo recompiled XCL. I also ran it successfully on the candidate with my earlier review fixes, but the unchanged-tree result is the one relevant to adoption.

This checks container parsing, the direct graphics guard and DXC compilation of the fallback. It does not execute a draw, prove final GPU pixels, exercise XCL_DIRECT_DXIL=all dispatch through compile_console_shader, or replace the paired retail smoke gate. No code was pushed.

@mokkamokacaffe
mokkamokacaffe force-pushed the dxil/guard-wave64-graphics-cache branch from 74822df to 51738bb Compare November 24, 2026 23:36
anoyarou added a commit to anoyarou/xcl that referenced this pull request Nov 25, 2026
Brings main to full parity with upstream/main (80f4819):
- xcl-dev#1836: cache direct-DXIL mesh shaders, coalesce shader builds,
  make MS/GS lazy, and cache two-pass/graphics PSO blobs

Conflict in crates/xcl/src/gpu/recomp/pso.rs resolved by keeping both xcl-dev#1836's
Vertex|Pixel stage check + dxc::defer() guard and xcl-dev#1913's split_wave64 argument
to direct_graphics.

Assisted-by: Antigravity (Gemini 4)
gustavsi added a commit to gustavsi/xcl that referenced this pull request Nov 25, 2026
Pulls in xcl-dev#1836 (graphics and two-pass PSO disk cache + lazy MS/GS + shader build coalescing), xcl-dev#1930 (DXIL CSE across discard), xcl-dev#1900, xcl-dev#1005, xcl-dev#1053, xcl-dev#1864, xcl-dev#1866, xcl-dev#1869, xcl-dev#1876, and xcl-dev#1898 while keeping our RDNA4 MSAA clamp (xcl-dev#1908), wave64 graphics Direct DXIL guard (xcl-dev#1913), atomic writable-range tracking, static-sampler cache keys, and 4M-group indirect dispatch clamp.
@Melow-code

Copy link
Copy Markdown

The three points look addressed: the alias-key behaviour is now pinned by the live-graphics-container test (a direct graphics PSO with split_wave64 for VS and PS exercises the CSE path my first point asked a core test for), and the other two were notes, not blockers. Nothing else from my side. Thanks for the clean follow-up. (Reply written with DeepSeek V4 Pro, OpenCode.)

@mokkamokacaffe
mokkamokacaffe force-pushed the dxil/guard-wave64-graphics-cache branch from 51738bb to cf70b66 Compare November 25, 2026 01:16
@DavidM1911

Copy link
Copy Markdown
Contributor

Verification on RTX 3060 Ti (Windows 11), branch merged with current main:

Thanks!

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Shaders: XCL_DIRECT_DXIL=all ignores split_wave64 / upper_lanes for wave64 VS/PS (poisoning split=1 cache), and XCL_DXIL_NO_OPT bypasses cache_allowed()

5 participants