Repository navigation
Shaders: guard wave64 graphics direct DXIL - #1913
mokkamokacaffe wants to merge 1 commit into
Conversation
e9d23be to
5e89ca2
Compare
Melow-code
left a comment
There was a problem hiding this comment.
Routing is correct — wave64 VS/PS reading lanes 32-63 goes to HLSL upper_lanes. Three points:
needs_upper_lanesstops at the first decode error and returns the partial result. For a guard, the safe answer istruewhen decode fails before S_ENDPGM.- The new check in coverage.rs runs before
catch_unwind. A panic inupper_lanes::analyzestops the whole coverage run. Put it inside the closure. splitstays false — if direct graphics has no split form, a one-line comment would clarify this.
Please run the Rust tests on Windows before merge.
|
I tested commit The existing #[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 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 |
Hardware test report — commit
|
|
I tested a local patch for @ruipedro-pinheiro's three review points on the source tree of The guard now returns 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. Paired Not tested: Paired retail |
34eb8d4 to
74822df
Compare
|
One additional test closes part of the live graphics container coverage gap. It uses the repository's existing synthetic 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 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 |
74822df to
51738bb
Compare
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)
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.
|
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.) |
51738bb to
cf70b66
Compare
|
Verification on RTX 3060 Ti (Windows 11), branch merged with current
Thanks! |
|
PR #1913 — split-wave64 graphics compatibility Tested
cargo test --locked -p xcl --lib gpu::dxil::coverage::tests::split_wave64_graphics_refuses_upper_lane_read -- --exact --test-threads=1 --nocaptureResult — 1 passed, 0 failed, 0 ignored, 0 skipped, 1,066 filtered out. Cargo exited 0. The checked-in fixture writes and reads lane 32 of a valid synthetic wave64 program. It confirms that the classifier requires upper-lane emulation and that split-wave64 offline direct DXIL translation returns the expected upper-lane emulation error for both VS and PS. With direct graphics DXIL enabled and wave64 splitting required, the expected live route is to refuse direct DXIL and continue through HLSL upper-lane emulation. The fixture stops at the offline guard with Not tested Live PSO routing, HLSL fallback compilation, successful direct DXIL emission, DXIL validation, GPU execution or pixel output, malformed inputs, cache behavior, the workspace suite, and retail-title smoke. AI use T3 Code / Codex ( |
Melow-code
left a comment
There was a problem hiding this comment.
The routing change is correct. A wave64 VS or PS in 32-lane waves can read lanes 32 to 63 in a way that is not native. Such a shader now goes to the HLSL upper_lanes form. The XCL_DXIL_NO_OPT cache bypass is also correct. Three points:
- Decode errors.
needs_upper_lanesstops at the first decode error and returns the result for the part before it. For a guard, the safe answer istruewhen the decode fails beforeS_ENDPGM. translate_modeincoverage.rs. The new check runs beforecatch_unwind. A panic inupper_lanes::analyzethen stops the whole coverage run, where other panics come back as"panic: ...". Put the check inside the closure.splitstays false.direct_graphicsnow takessplit_wave64, but it still passessplit: falsetoKernelOptions. If the direct translator has no split form for graphics, add a short comment that says so.
The PR says that nobody ran the Rust tests, the DXIL validation or a GPU run yet. Please run the tests on Windows once before merge, with the new needs_upper_lanes test.
|
Regression run of Against the limits in CONTRIBUTING.md: 100 % of AMD Radeon RX 9070 (RDNA4, driver 32.0.32029.2010), Ryzen 7 7800X3D, 32 GB, Windows 11 build 26300, Rust 1.100.0, AI use: Claude Code (Claude Opus 5.5) built both trees and ran |
|
Two contributors checked independently and found that #2252 solves the same problem (for #1895) in a different way: #1607, group D74. You may want to compare them with the other author and agree on one, or say in the PR why both are needed. This is a hint from the community triage in #1607, not a maintainer decision. AI use: Claude Code (Claude Opus 5.5), posted by a script from the #1607 table. |
…1860, xcl-dev#1913, xcl-dev#2192, xcl-dev#1946, xcl-dev#2237 Integrates XG CopyFromSubresource 7-arg ABI (xcl-dev#684), DirectStorage physical-page list re-read (xcl-dev#1405), vkd3d-proton in-place vtable patching with UnadoptGuard composition (xcl-dev#1395), single-back-edge Direct DXIL CFG (xcl-dev#1860), wave64 graphics Direct DXIL guard (xcl-dev#1913), and AMD RDNA2-4 DXIL fuzz fixes (xcl-dev#2192, xcl-dev#1946, xcl-dev#2237).
Fixes #1895.
Wave64 vertex and pixel shaders can read lanes 32–63 while the selected adapter requires two 32-lane waves. Direct graphics DXIL has no split-wave64 form, so these programs must use the HLSL
upper_lanespath instead of producing incorrect direct DXIL or poisoning its cache.What is in it
crates/xcl/src/gpu/recomp/pso.rs: pass the adapter's wave32/split requirement into the live Direct DXIL VS/PS route and refuse programs that need upper-lane emulation, allowing the existing HLSL fallback to take them.crates/xcl/src/gpu/recomp/mod.rs: conservatively classify written/read upper lanes; incomplete or unknown instruction streams require fallback.crates/xcl/src/gpu/dxil/coverage.rs: apply the same refusal toxcl shaders --directinside its panic boundary, keeping offline coverage consistent with runtime routing.XCL_DXIL_NO_OPTis set so deliberately unoptimized diagnostic DXIL cannot be reused by later normal runs.Tested
cf70b66810cbc16ec312a63389ac6d510970e25d: passed.cf70b668, CPU fixture with Intel Arc A770 driver installed:cargo test --locked -p xcl --lib gpu::dxil::coverage::tests::split_wave64_graphics_refuses_upper_lane_read -- --exact --test-threads=1 --nocapture: 1 passed, 0 failed, 0 ignored, 0 skipped.Regression run
main:
this PR:
The PR produced 100% of main's frames and 102% of its peak commit, with no crash or device removal. This regression run does not establish that the title reached the changed routing path.
Not tested
XCL_SHADER_BACKEND=dxilgameplay past the menus.cf70b668.AI use