From 798ff0dbde42c3f21c455f19d6f2a02fa2fe4ff3 Mon Sep 17 00:00:00 2001 From: Graham Calihan Date: Sun, 22 Nov 2026 15:37:06 -0500 Subject: [PATCH] recomp: refuse split wave32 mesh programs with cross-half wave64 semantics A wave64 NGG program split into wave32 halves now runs the geometry hazard check first, as split geometry does, instead of building a pipeline that computes wrong results or hangs. --- crates/xcl/src/gpu/recomp/mod.rs | 16 ++++++++++++++-- crates/xcl/src/gpu/recomp/pso.rs | 7 +------ crates/xcl/src/gpu/recomp/tests.rs | 19 +++++++++++++++++++ 3 files changed, 34 insertions(+), 8 deletions(-) diff --git a/crates/xcl/src/gpu/recomp/mod.rs b/crates/xcl/src/gpu/recomp/mod.rs index 2adb651..1708451 100644 --- a/crates/xcl/src/gpu/recomp/mod.rs +++ b/crates/xcl/src/gpu/recomp/mod.rs @@ -1076,8 +1076,8 @@ pub fn wave_hazards(code: &[u8]) -> BTreeSet<&'static str> { } /// Operations that cannot be split into two independent native wave32 halves while -/// preserving one logical wave64. Split geometry translation rejects these rather than -/// silently changing cross-half lane or mask semantics. +/// preserving one logical wave64. Split geometry and split mesh translation reject these +/// rather than silently changing cross-half lane or mask semantics. pub fn geometry_wave32_hazards(code: &[u8]) -> BTreeSet<&'static str> { let mut out = BTreeSet::new(); let mut mask_regs = BTreeSet::from([106u64, 107, 126, 127]); // VCC and EXEC @@ -1161,6 +1161,18 @@ pub fn translate_geometry(code: &[u8], interface: GsInterface, geometry_wave32: translate(code, &Options { mode: Mode::Geometry(interface), wave64: true, geometry_wave32, ..Default::default() }) } +/// Translate an NGG mesh program; a wave64 program split into wave32 halves is refused +/// when it needs cross-half semantics, as for split geometry. +pub fn translate_mesh(code: &[u8], ms: MsInterface, wave64: bool, mesh_wave32: bool) -> Result { + if wave64 && mesh_wave32 { + let hazards = geometry_wave32_hazards(code); + if !hazards.is_empty() { + return Err(format!("mesh program requires unsupported cross-half wave64 semantics: {hazards:?}")); + } + } + translate(code, &Options { mode: Mode::Mesh(ms), wave64, mesh_wave32, ..Default::default() }) +} + /// Wave size the program was compiled for: 64-bit EXEC/VCC writes mean wave64. pub fn detect_wave64(code: &[u8]) -> bool { let mut off = 0; diff --git a/crates/xcl/src/gpu/recomp/pso.rs b/crates/xcl/src/gpu/recomp/pso.rs index 5432885..15ac366 100644 --- a/crates/xcl/src/gpu/recomp/pso.rs +++ b/crates/xcl/src/gpu/recomp/pso.rs @@ -179,11 +179,6 @@ pub struct TwoPass { pub samplers: Vec, } -fn two_pass(code: &[u8], mode: Mode, wave64: bool, geometry_wave32: bool, mesh_wave32: bool, record: super::MsInterface, ps: Option<&[u8]>) -> Result { - let t = translate(code, &Options { mode, wave64, geometry_wave32, mesh_wave32, ..Default::default() })?; - finish_two_pass(t, record, ps) -} - fn finish_two_pass(t: super::Translation, record: super::MsInterface, ps: Option<&[u8]>) -> Result { if !t.complete() { let missing: Vec<&String> = t.unsupported.keys().collect(); @@ -206,7 +201,7 @@ pub fn console_mesh(blob: &[u8], ps: Option<&[u8]>, mesh_wave32: bool) -> Result let record = ms.clone(); let p = f.programs.first().ok_or("FSSM without a program")?; let code = &f.data[p.offset..p.offset + p.len]; - two_pass(code, mode.clone(), super::detect_wave64(code), false, mesh_wave32, record, ps) + finish_two_pass(super::translate_mesh(code, ms.clone(), super::detect_wave64(code), mesh_wave32)?, record, ps) } /// Whether the adapter's supported wave range requires split geometry execution. diff --git a/crates/xcl/src/gpu/recomp/tests.rs b/crates/xcl/src/gpu/recomp/tests.rs index f0032a0..9c57f88 100644 --- a/crates/xcl/src/gpu/recomp/tests.rs +++ b/crates/xcl/src/gpu/recomp/tests.rs @@ -3648,3 +3648,22 @@ fn mesh_wave32_emits_wave32_logical_wave64() { assert!(split.hlsl.contains("lane_id = WaveGetLaneIndex() + 32u * xcl_half;")); assert!(split.complete(), "{:?}", split.unsupported_why); } + +#[test] +fn mesh_wave32_rejects_cross_half_operations() { + let ms = super::MsInterface { threads: 128, max_vertices: 64, max_primitives: 64, outputs: vec![] }; + let lane = prog(&[("V_READFIRSTLANE_B32", "ENC_VOP1", &[("VDST", 0), ("SRC0", V)], None)]); + let branch = prog(&[("S_CBRANCH_EXECZ", "ENC_SOPP", &[("SIMM16", 0)], None)]); + for (code, hazard) in [(&lane, "cross-half lane exchange"), (&branch, "branch on a whole-wave mask")] { + let e = super::translate_mesh(code, ms.clone(), true, true).err().expect("split mesh must refuse"); + assert!(e.contains("mesh program requires unsupported cross-half wave64 semantics") && e.contains(hazard), "{e}"); + // native wave64 and wave32 programs are not split, so nothing is refused + assert!(super::translate_mesh(code, ms.clone(), true, false).is_ok()); + assert!(super::translate_mesh(code, ms.clone(), false, true).is_ok()); + } + + let plain = prog(&[("V_MOV_B32", "ENC_VOP1", &[("VDST", 1), ("SRC0", V)], None)]); + let split = super::translate_mesh(&plain, ms, true, true).unwrap(); + assert!(split.hlsl.contains("xcl_logical_wave64 = true;")); + assert!(split.complete(), "{:?}", split.unsupported_why); +}