Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions crates/xcl/src/gpu/dxil/core_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,60 @@ fn branchy_graphics_stages_validate() {
}
}

/// On 32-lane hardware waves (`split: true`), wave64 vertex / pixel shaders that read lanes
/// 32–63 (as found by `upper_lanes::analyze`) must be refused by direct DXIL so `pso.rs` falls
/// back to the HLSL `upper_lanes` path instead of caching broken wave64-only DXIL under
/// `split=1`. Wave64 VS/PS with no upper-lane reads still translate under `split: true`, and
/// native wave64 (`split: false`) still translates both (#1895).
#[test]
fn wave64_graphics_with_upper_lane_reads_refused_in_32_lane_mode() {
use crate::gpu::recomp::{Mode, PsInterface, VsInterface};
let vsi = VsInterface { inputs: vec![], outputs: vec![sig("SV_Position", 0, 1, 3, 0, 0xF)], attr_base: 4, params: None };
let psi = PsInterface { inputs: vec![sig("SV_Position", 0, 1, 3, 0, 0xF)], outputs: vec![sig("SV_Target", 0, 64, 3, 0, 0xF)], input_ena: 0x2, attrs: None };
// Whole-wave write into lanes 32..63 followed by `v_readlane_b32` of lane 63.
let upper_body = |exp| {
prog(&[
("S_OR_SAVEEXEC_B64", "ENC_SOP1", &[("SDST", 0), ("SSRC0", 193)], None), // -1
("V_MOV_B32", "ENC_VOP1", &[("VDST", 4), ("SRC0", 133)], None), // 5
("S_MOV_B64", "ENC_SOP1", &[("SDST", 126), ("SSRC0", 0)], None),
("V_READLANE_B32", "ENC_VOP3", &[("VDST", 2), ("SRC0", 256 + 4), ("SRC1", 191)], None), // lane 63
("V_MOV_B32", "ENC_VOP1", &[("VDST", 5), ("SRC0", 2)], None),
exp,
])
};
let native_body = |exp| {
prog(&[
("V_MOV_B32", "ENC_VOP1", &[("VDST", 4), ("SRC0", 242)], None),
("V_MOV_B32", "ENC_VOP1", &[("VDST", 5), ("SRC0", 242)], None),
exp,
])
};
let vs_exp = ("EXP", "ENC_EXP", &[("TGT", 12), ("EN", 0xF), ("VSRC0", 4), ("VSRC1", 5), ("VSRC2", 4), ("VSRC3", 5), ("DONE", 1)][..], None);
let ps_exp = ("EXP", "ENC_EXP", &[("TGT", 0), ("EN", 0xF), ("VSRC0", 4), ("VSRC1", 5), ("VSRC2", 4), ("VSRC3", 5), ("DONE", 1), ("VM", 1)][..], None);

let split_o = KernelOptions { wave64: true, split: true, mem_windows: 1, sampler_base: 0 };
let native_o = KernelOptions { wave64: true, split: false, mem_windows: 1, sampler_base: 0 };

let vs_upper = upper_body(vs_exp);
let ps_upper = upper_body(ps_exp);
let err_vs = super::kernel::translate_vertex(&vs_upper, split_o, &vsi).err().expect("VS upper-lane read must be refused when split=true");
assert!(err_vs.contains("lanes 32–63"), "unexpected VS error: {err_vs}");
let err_ps = super::kernel::translate_pixel(&ps_upper, split_o, &psi).err().expect("PS upper-lane read must be refused when split=true");
assert!(err_ps.contains("lanes 32–63"), "unexpected PS error: {err_ps}");
assert!(super::coverage::translate_mode(&vs_upper, &Mode::Vertex(vsi.clone()), split_o, false).is_err());
assert!(super::coverage::translate_mode(&ps_upper, &Mode::Pixel(psi.clone()), split_o, false).is_err());

// Native wave64 (`split: false`) still translates both.
super::kernel::translate_vertex(&vs_upper, native_o, &vsi).expect("VS native wave64");
super::kernel::translate_pixel(&ps_upper, native_o, &psi).expect("PS native wave64");

// Wave64 VS/PS with no upper-lane reads still translate under `split: true`.
let vs_native = native_body(vs_exp);
let ps_native = native_body(ps_exp);
super::kernel::translate_vertex(&vs_native, split_o, &vsi).expect("VS without upper-lane reads");
super::kernel::translate_pixel(&ps_native, split_o, &psi).expect("PS without upper-lane reads");
}

/// A long pixel shader (guarded memory accesses make thousands of joins between a
/// register's write and the output stores) translates quickly and stays small: the
/// SSA builder drops trivial phis, `Module::optimize` cleans up the rest.
Expand Down
4 changes: 2 additions & 2 deletions crates/xcl/src/gpu/dxil/coverage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,8 +251,8 @@ pub fn translate_mode(code: &[u8], mode: &Mode, o: KernelOptions, validate: bool
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::Vertex(vs) => kernel::translate_vertex(code, o, vs),
Mode::Pixel(ps) => kernel::translate_pixel(code, o, ps),
Mode::Mesh(ms) => kernel::translate_mesh(code, o, ms),
Mode::Geometry(g) => kernel::translate_geometry(code, o, g),
}));
Expand Down
10 changes: 10 additions & 0 deletions crates/xcl/src/gpu/dxil/kernel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,16 @@ fn translate_on_this_thread(
let kernel = matches!(entry, Entry::Kernel);
let follow_loads = matches!(entry, Entry::Kernel | Entry::Compute(_));
let gfx = matches!(entry, Entry::Vertex(_) | Entry::Pixel(_));
if gfx
&& o.wave64
&& o.split
&& crate::gpu::recomp::upper_lanes::analyze(&cfg.insts)
.reads
.values()
.any(|&r| r != crate::gpu::recomp::upper_lanes::Read::Native)
{
return Err("wave64 VS / PS in 32-lane waves: a read of lanes 32–63".into());
}
let compute = matches!(entry, Entry::Compute(_));
let split = o.wave64 && o.split && !gfx;
let leaders: BTreeSet<u64> = cfg.blocks.iter().filter_map(|b| b.insts.first().map(|&i| cfg.insts[i].pc)).collect();
Expand Down
7 changes: 4 additions & 3 deletions crates/xcl/src/gpu/recomp/pso.rs
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,7 @@ fn compile_console_shader(blob: &[u8], stage: Stage, sampler_base: u32, windows:
if dxc::defer() {
return Err("DXIL not compiled yet".into());
}
match direct_graphics(blob, stage, sampler_base, windows) {
match direct_graphics(blob, stage, sampler_base, windows, split_wave64) {
Ok(c) => {
crate::gpu::dxil::coverage::record_translated(if stage == Stage::Vertex { "VS" } else { "PS" });
return Ok((c, false));
Expand Down Expand Up @@ -995,14 +995,15 @@ fn dump_direct(blob: &[u8], dxil: &[u8]) {
}

/// A console vertex / pixel shader through the direct DXIL translator.
fn direct_graphics(blob: &[u8], stage: Stage, sampler_base: u32, windows: u32) -> Result<Compiled, String> {
fn direct_graphics(blob: &[u8], stage: Stage, sampler_base: u32, windows: u32, split_wave64: bool) -> Result<Compiled, String> {
let sh = xbox::parse(blob).ok_or("not a console shader container")?;
let want = if stage == Stage::Vertex { 4 } else { 5 };
let f = sh.fssm.iter().find(|f| f.stages.first().is_some_and(|s| s.hw == want)).ok_or("no hardware variant")?;
let mode = interface(blob, &sh, f).ok_or("unknown shader interface")?;
let p = f.programs.first().ok_or("FSSM without a program")?;
let code = &f.data[p.offset..p.offset + p.len];
let o = crate::gpu::dxil::kernel::KernelOptions { wave64: super::fssm_wave64(f, code), split: false, mem_windows: windows, sampler_base };
let wave64 = super::fssm_wave64(f, code);
let o = crate::gpu::dxil::kernel::KernelOptions { wave64, split: wave64 && split_wave64, mem_windows: windows, sampler_base };
let k = match (&mode, stage) {
(Mode::Vertex(vs), Stage::Vertex) => crate::gpu::dxil::kernel::translate_vertex(code, o, vs)?,
(Mode::Pixel(ps), Stage::Pixel) => crate::gpu::dxil::kernel::translate_pixel(code, o, ps)?,
Expand Down
Loading