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! |
What is in it
Fixes #1895.
upper_lanesimplementation when a wave64 graphics shader reads data from lanes 32-63 that Direct DXIL cannot represent in a 32-lane wave.xcl shaders --direct, keeping coverage results consistent with runtime routing.XCL_DXIL_NO_OPTis set, so diagnostic, deliberately unoptimized DXIL cannot poison later normal runs.Tested
git diff --checkdirect_graphicsandneeds_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
mainbase. Please applytest-onlyuntil those two matchingxcl-smoke v1blocks are available.Not tested
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.