Skip to content
Open
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
55 changes: 45 additions & 10 deletions crates/xcl/src/gpu/recomp/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -644,26 +644,35 @@ pub fn mesh_shaders_supported() -> Result<bool, String> {
}

/// A GPU test (or a part of one) that cannot run here, `reason` one of "no GPU", "no DXC",
/// "no wave64", "no mesh shaders": `SKIPPED <test>: <reason>` written to stderr itself, so the
/// line shows without `--nocapture` (libtest captures only `print!` / `eprint!`), and
/// `scripts/test.ps1` counts them. `XCL_REQUIRE_GPU=wave64` or `=mesh` (or both, comma-separated)
/// turns a skip that leaves that coverage out into a failure.
/// "no wave64", "no mesh shaders" (or `<part>: <one of them>`, the part of a test that is
/// skipped): `SKIPPED <test>: <reason>` written to stderr itself, so the line shows without
/// `--nocapture` (libtest captures only `print!` / `eprint!`), and `scripts/test.ps1` counts
/// them. `XCL_REQUIRE_GPU=wave64` or `=mesh` (or both, comma-separated) turns a skip that leaves
/// that coverage out into a failure.
pub fn skip_test(reason: &str) {
use std::io::Write;
let thread = std::thread::current();
let test = thread.name().unwrap_or("?");
let required = std::env::var("XCL_REQUIRE_GPU").unwrap_or_default();
let fails = required.split(',').map(str::trim).any(|r| match r {
"wave64" => reason != "no mesh shaders",
"mesh" => reason != "no wave64",
_ => false,
});
if fails {
if skip_fails(&required, reason) {
panic!("{test}: {reason}, but XCL_REQUIRE_GPU={required}");
}
let _ = writeln!(std::io::stderr(), "SKIPPED {test}: {reason}");
}

/// Whether `XCL_REQUIRE_GPU=required` makes a skip for `reason` a failure (`skip_test`): every
/// skip but "no mesh shaders" under `wave64`, every one but "no wave64" under `mesh`. A part of
/// a test skipped for one of them (`"<part>: no wave64"`, as `lower_dxil`'s wave64 halves) is
/// that skip.
fn skip_fails(required: &str, reason: &str) -> bool {
let is = |what: &str| reason == what || reason.strip_suffix(what).is_some_and(|part| part.ends_with(": "));
required.split(',').map(str::trim).any(|r| match r {
"wave64" => !is("no mesh shaders"),
"mesh" => !is("no wave64"),
_ => false,
})
}

/// Run a compiled kernel (DXIL) with `state` and flat memory `mem`.
pub fn run(dxil: &[u8], state: &KernelState, mem: &[u32]) -> Result<KernelResult, String> {
run_with(dxil, state, mem, &[], &[])
Expand Down Expand Up @@ -1942,3 +1951,29 @@ fn dispatch_with(
Ok((out, ms))
}
}

#[cfg(test)]
mod skip_tests {
use super::skip_fails;

/// `XCL_REQUIRE_GPU` lets through the one hardware reason it names, alone or as the reason
/// of a part of a test, and nothing else.
#[test]
fn a_required_gpu_lets_through_its_hardware_reason_also_for_a_part() {
assert!(!skip_fails("", "no GPU"));
assert!(!skip_fails("mesh", "no wave64"));
assert!(!skip_fails("mesh", "f32 arithmetic, wave64: no wave64"));
assert!(!skip_fails("mesh", "const_mask, wave64: no wave64"));
assert!(skip_fails("mesh", "no GPU"));
assert!(skip_fails("mesh", "no mesh shaders"));
assert!(skip_fails("mesh", "no heap windows"));
assert!(skip_fails("mesh", "xno wave64"), "only a whole reason after ': '");
assert!(skip_fails("mesh", "f32: no wave64 and no GPU"));
assert!(!skip_fails("wave64", "no mesh shaders"));
assert!(!skip_fails("wave64", "mesh draw: no mesh shaders"));
assert!(skip_fails("wave64", "f32 arithmetic, wave64: no wave64"));
assert!(skip_fails("wave64, mesh", "no wave64"));
assert!(skip_fails("wave64,mesh", "no mesh shaders"));
assert!(!skip_fails("other", "no GPU"));
}
}
Loading