Skip to content
Draft
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
45 changes: 45 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,51 @@ fn branchy_graphics_stages_validate() {
}
}

/// Wave64 graphics shaders that need `upper_lanes` are refused in 32-lane mode so the PSO
/// route falls back to HLSL. Native wave64 and shaders without upper-lane reads stay direct.
#[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 };
let upper_body = |exp| {
prog(&[
("S_OR_SAVEEXEC_B64", "ENC_SOP1", &[("SDST", 0), ("SSRC0", 193)], None),
("V_MOV_B32", "ENC_VOP1", &[("VDST", 4), ("SRC0", 133)], None),
("S_MOV_B64", "ENC_SOP1", &[("SDST", 126), ("SSRC0", 0)], None),
("V_READLANE_B32", "ENC_VOP3", &[("VDST", 2), ("SRC0", 256 + 4), ("SRC1", 191)], None),
("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 = KernelOptions { wave64: true, split: true, mem_windows: 1, sampler_base: 0 };
let native = KernelOptions { wave64: true, split: false, mem_windows: 1, sampler_base: 0 };

let (vs_upper, ps_upper) = (upper_body(vs_exp), upper_body(ps_exp));
for e in [
super::kernel::translate_vertex(&vs_upper, split, &vsi).err().expect("split VS upper read"),
super::kernel::translate_pixel(&ps_upper, split, &psi).err().expect("split PS upper read"),
] {
assert!(e.contains("lanes 32–63"), "{e}");
}
assert!(super::coverage::translate_mode(&vs_upper, &Mode::Vertex(vsi.clone()), split, false).is_err());
assert!(super::coverage::translate_mode(&ps_upper, &Mode::Pixel(psi.clone()), split, false).is_err());
super::kernel::translate_vertex(&vs_upper, native, &vsi).expect("native wave64 VS");
super::kernel::translate_pixel(&ps_upper, native, &psi).expect("native wave64 PS");

super::kernel::translate_vertex(&native_body(vs_exp), split, &vsi).expect("split VS without upper reads");
super::kernel::translate_pixel(&native_body(ps_exp), split, &psi).expect("split PS without upper 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 @@ -232,6 +232,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;
if split && !matches!(entry, Entry::Geometry(_)) && cfg.insts.iter().any(real_lds_access) {
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 @@ -735,7 +735,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 @@ -1154,14 +1154,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