From 91ed24cc35f72607e456fb731c8c85e4b4295050 Mon Sep 17 00:00:00 2001 From: GamerOG563 <199984693+GamerOG563@users.noreply.github.com> Date: Wed, 25 Nov 2026 13:57:51 +0200 Subject: [PATCH] shader, docs: skip GPU tests through one helper for XTP_REQUIRE_GPU Add xtp-testkit as a dev-dependency of xtp-shader and centralise test skip reporting in crates/xtp-shader/src/emit/host.rs (Host::test_device, Host::test_warp, Host::test_hosts, skip_gpu, and skip_once). When no host D3D12 device is available, GPU tests now fail if XTP_REQUIRE_GPU (or XTP_REQUIRE=no-gpu) is set and otherwise emit one canonical SKIPPED : marker through xtp_testkit::skip before returning. Non-returning optional validation and disassembly helpers emit plain notes so skip counts stay exact. Unpin tests that hardcoded Host::new(true) without a WARP-only reason so they follow XTP_TEST_ADAPTER, keep WARP where required (4-lane waves, root-signature-only heap binding, raw scalar reads of a structured slot, and undefined hardware behaviour on the old handle in smem), and update docs/analysis/hardware-tests.md and docs/contributing-without-a-gaming-pc.md. Fixes: #60 --- Cargo.lock | 1 + crates/xtp-shader/Cargo.toml | 3 + crates/xtp-shader/src/emit/buffer16_tests.rs | 13 +- crates/xtp-shader/src/emit/desc_data_tests.rs | 8 +- crates/xtp-shader/src/emit/diff_tests.rs | 34 +-- crates/xtp-shader/src/emit/geometry_tests.rs | 10 +- crates/xtp-shader/src/emit/group_id_tests.rs | 13 +- crates/xtp-shader/src/emit/helper_tests.rs | 84 +++++-- crates/xtp-shader/src/emit/host.rs | 207 ++++++++++++++++++ crates/xtp-shader/src/emit/image_tests.rs | 15 +- crates/xtp-shader/src/emit/input_tests.rs | 8 +- .../src/emit/lane_read_loop_tests.rs | 2 +- crates/xtp-shader/src/emit/lightloop_tests.rs | 9 +- crates/xtp-shader/src/emit/limits_tests.rs | 6 +- .../xtp-shader/src/emit/loop_limit_tests.rs | 17 +- crates/xtp-shader/src/emit/lower/flow.rs | 10 +- crates/xtp-shader/src/emit/lower/lds.rs | 12 +- crates/xtp-shader/src/emit/lower/salu.rs | 3 +- crates/xtp-shader/src/emit/lower/smem.rs | 7 +- crates/xtp-shader/src/emit/mesh_tests.rs | 5 +- crates/xtp-shader/src/emit/meshidx_tests.rs | 5 +- crates/xtp-shader/src/emit/mod.rs | 37 +++- crates/xtp-shader/src/emit/r1_tests.rs | 13 +- crates/xtp-shader/src/emit/r4_tests.rs | 8 +- crates/xtp-shader/src/emit/raw_tests.rs | 26 +-- crates/xtp-shader/src/emit/rayquery_tests.rs | 30 +-- crates/xtp-shader/src/emit/rect_gs.rs | 6 +- crates/xtp-shader/src/emit/sampler_tests.rs | 9 +- crates/xtp-shader/src/emit/smem_data_tests.rs | 48 +--- crates/xtp-shader/src/emit/smem_tests.rs | 16 +- crates/xtp-shader/src/emit/split_tests.rs | 2 +- crates/xtp-shader/src/emit/stride_tests.rs | 23 +- crates/xtp-shader/src/emit/userdata_tests.rs | 22 +- crates/xtp-shader/src/emit/validator_tests.rs | 8 +- crates/xtp-shader/src/emit/valu_tests.rs | 9 +- crates/xtp-shader/src/emit/waterfall_tests.rs | 24 +- docs/analysis/hardware-tests.md | 4 +- docs/contributing-without-a-gaming-pc.md | 5 +- 38 files changed, 452 insertions(+), 310 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 21113801..da8eef71 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -930,6 +930,7 @@ dependencies = [ "thiserror", "windows", "windows-sys", + "xtp-testkit", ] [[package]] diff --git a/crates/xtp-shader/Cargo.toml b/crates/xtp-shader/Cargo.toml index a8626883..121fcfee 100644 --- a/crates/xtp-shader/Cargo.toml +++ b/crates/xtp-shader/Cargo.toml @@ -27,6 +27,9 @@ windows = { workspace = true, optional = true, features = [ "Win32_Graphics_Dxgi_Common", ] } +[dev-dependencies] +xtp-testkit.workspace = true + [target.'cfg(windows)'.dev-dependencies] windows = { workspace = true, features = [ "Win32_Foundation", diff --git a/crates/xtp-shader/src/emit/buffer16_tests.rs b/crates/xtp-shader/src/emit/buffer16_tests.rs index 8797b717..2945c60a 100644 --- a/crates/xtp-shader/src/emit/buffer16_tests.rs +++ b/crates/xtp-shader/src/emit/buffer16_tests.rs @@ -226,16 +226,11 @@ fn translated_at( (shader, integer_loads) } -/// Runs `shader` with `views` on WARP and, when there is one, the hardware -/// adapter; `check` gets each run's first UAV as dwords. At least one runs. +/// Runs `shader` with `views` on each of [`Host::test_hosts`]; `check` gets +/// each run's first UAV as dwords. fn run(shader: &HostShader, views: &[View], check: impl Fn(&str, &[u32])) { let _one = ONE_AT_A_TIME.lock().unwrap_or_else(|e| e.into_inner()); - let mut ran = 0; - for (label, warp) in [("warp", true), ("hardware", false)] { - let Ok(host) = Host::new(warp) else { - eprintln!("no SM 6.6 {label} device; skipped"); - continue; - }; + for (label, host) in Host::test_hosts() { let (root, pso) = host .compute_pipeline(shader) .unwrap_or_else(|e| panic!("{label}: compute_pipeline failed: {e}")); @@ -260,9 +255,7 @@ fn run(shader: &HostShader, views: &[View], check: impl Fn(&str, &[u32])) { ) .unwrap_or_else(|e| panic!("{label}: dispatch failed: {e}")); check(label, &out[0]); - ran += 1; } - assert!(ran > 0, "no SM 6.6 device available"); } /// `v[1:2] = from[thread]` (four halves), `to[thread] = v[1:2]`, `from` the diff --git a/crates/xtp-shader/src/emit/desc_data_tests.rs b/crates/xtp-shader/src/emit/desc_data_tests.rs index 2452baf5..9b72023e 100644 --- a/crates/xtp-shader/src/emit/desc_data_tests.rs +++ b/crates/xtp-shader/src/emit/desc_data_tests.rs @@ -209,13 +209,7 @@ fn run( let _one = super::valu_tests::ONE_AT_A_TIME .lock() .unwrap_or_else(|e| e.into_inner()); - let host = match Host::new(false) { - Ok(host) => host, - Err(e) => { - eprintln!("no SM 6.6 device ({e}); skipped"); - return None; - } - }; + let host = Host::test_device()?; let mut roots = vec![( 0, Root::Constants(vec![0; cs.user_data_dwords().max(1) as usize]), diff --git a/crates/xtp-shader/src/emit/diff_tests.rs b/crates/xtp-shader/src/emit/diff_tests.rs index 4eb67135..a13f5d7c 100644 --- a/crates/xtp-shader/src/emit/diff_tests.rs +++ b/crates/xtp-shader/src/emit/diff_tests.rs @@ -652,12 +652,24 @@ const MS_CASES: &[(&str, u32, &str)] = &[ ]; fn tools() -> Option<(PathBuf, PathBuf)> { - let console = PathBuf::from(std::env::var_os("XTP_CONSOLE_DXC")?); + let Some(console) = std::env::var_os("XTP_CONSOLE_DXC") + .map(PathBuf::from) + .filter(|p| p.exists()) + else { + super::host::skip_once(xtp_testkit::reason::NO_CONSOLE_DXC); + return None; + }; let pc = match std::env::var_os("XTP_PC_DXC") { Some(p) => PathBuf::from(p), - None => super::validator::Validator::default_path()?.with_file_name("dxc.exe"), + None => super::validator::Validator::default_path() + .map(|p| p.with_file_name("dxc.exe")) + .unwrap_or_default(), }; - (console.exists() && pc.exists()).then_some((console, pc)) + if !pc.exists() { + super::host::skip_once(xtp_testkit::reason::NO_DXC); + return None; + } + Some((console, pc)) } fn compile(dxc: &Path, dir: &Path, src: &str, entry: &str, profile: &str) -> Vec { @@ -715,11 +727,9 @@ fn user_data(s: &HostShader, k: &[u32; 4]) -> Vec { #[test] fn translated_shaders_draw_as_pc_ones() { let Some((console, pc)) = tools() else { - eprintln!("no console or PC compiler; skipped"); return; }; - let Ok(host) = Host::new(false) else { - eprintln!("no SM 6.6 device; skipped"); + let Some(host) = Host::test_device() else { return; }; let dir = std::env::temp_dir().join(format!("xtp-diff-{}", std::process::id())); @@ -871,11 +881,9 @@ fn translated_shaders_draw_as_pc_ones() { #[test] fn translated_mesh_shaders_draw_as_pc_ones() { let Some((console, pc)) = tools() else { - eprintln!("no console or PC compiler; skipped"); return; }; - let Ok(host) = Host::new(false) else { - eprintln!("no SM 6.6 device; skipped"); + let Some(host) = Host::test_device() else { return; }; let dir = std::env::temp_dir().join(format!("xtp-diff-ms-{}", std::process::id())); @@ -988,11 +996,9 @@ fn translated_mesh_shaders_draw_as_pc_ones() { fn float_semantics_are_the_consoles() { use super::host::{Dispatch, View}; let Some((console, _)) = tools() else { - eprintln!("no console compiler; skipped"); return; }; - let Ok(host) = Host::new(false) else { - eprintln!("no SM 6.6 device; skipped"); + let Some(host) = Host::test_device() else { return; }; let dir = std::env::temp_dir().join(format!("xtp-float-{}", std::process::id())); @@ -1077,11 +1083,9 @@ fn close(a: u32, b: u32) -> bool { fn translated_compute_matches_pc() { use super::host::{Dispatch, Stride, View}; let Some((console, pc)) = tools() else { - eprintln!("no console or PC compiler; skipped"); return; }; - let Ok(host) = Host::new(false) else { - eprintln!("no SM 6.6 device; skipped"); + let Some(host) = Host::test_device() else { return; }; let dir = std::env::temp_dir().join(format!("xtp-diff-cs-{}", std::process::id())); diff --git a/crates/xtp-shader/src/emit/geometry_tests.rs b/crates/xtp-shader/src/emit/geometry_tests.rs index 00fc8cc6..53e16c88 100644 --- a/crates/xtp-shader/src/emit/geometry_tests.rs +++ b/crates/xtp-shader/src/emit/geometry_tests.rs @@ -1130,7 +1130,7 @@ fn validate(what: &str, container: &[u8]) { panic!("{what}: validation: {e}"); } } - Err(e) => eprintln!("SKIPPED validation of {what}: {e}"), + Err(e) => eprintln!("{what}: not validated ({e})"), } } @@ -1503,13 +1503,7 @@ fn device() -> Option<(Host, std::sync::MutexGuard<'static, ()>)> { let one = super::valu_tests::ONE_AT_A_TIME .lock() .unwrap_or_else(|e| e.into_inner()); - match Host::new(false) { - Ok(host) => Some((host, one)), - Err(e) => { - eprintln!("no SM 6.6 device ({e}); skipped"); - None - } - } + Some((Host::test_device()?, one)) } /// The probe vertex shader over [`item`] (positions, floats and uints per diff --git a/crates/xtp-shader/src/emit/group_id_tests.rs b/crates/xtp-shader/src/emit/group_id_tests.rs index 0944b63f..13a2930d 100644 --- a/crates/xtp-shader/src/emit/group_id_tests.rs +++ b/crates/xtp-shader/src/emit/group_id_tests.rs @@ -88,16 +88,9 @@ fn flat_ids_on_warp() { let _one = super::valu_tests::ONE_AT_A_TIME .lock() .unwrap_or_else(|e| e.into_inner()); - let host = match Host::new(true) { - Ok(host) => host, - Err(e) => { - assert!( - std::env::var("XTP_REQUIRE_GPU").as_deref() != Ok("1"), - "{e}" - ); - eprintln!("WARP: {e}; skipped"); - return; - } + // Kept on WARP to cover 4-lane waves; flat_ids_and_lanes_on_nvidia covers hardware. + let Some(host) = Host::test_warp() else { + return; }; check(&host, host.target().runs(32)); } diff --git a/crates/xtp-shader/src/emit/helper_tests.rs b/crates/xtp-shader/src/emit/helper_tests.rs index ccae2a3a..0190284e 100644 --- a/crates/xtp-shader/src/emit/helper_tests.rs +++ b/crates/xtp-shader/src/emit/helper_tests.rs @@ -393,20 +393,66 @@ fn vertex_shader(ps: &HostShader) -> HostShader { } /// The devices to draw on: WARP, then each hardware adapter (none where -/// `XTP_TEST_ADAPTER` keeps the tests off hardware). +/// `XTP_TEST_ADAPTER` keeps the tests off hardware), reporting missing or +/// disabled devices through [`super::host::skip_gpu`]. fn hosts() -> Vec<(String, Host)> { - let mut out = Vec::new(); - match Host::new(true) { - Ok(h) => out.push(("WARP".to_string(), h)), - Err(e) => eprintln!("WARP: no SM 6.6 device ({e}); not run there"), - } - for name in adapters().unwrap_or_default() { - match Host::on(&name) { - Ok(h) => out.push((name, h)), - Err(e) => eprintln!("{name}: {e}; not run there"), + match super::host::test_adapter().as_deref() { + Some("warp") => match Host::new(true) { + Ok(h) => vec![("WARP".to_string(), h)], + Err(e) => { + super::host::skip_gpu(&format!("WARP: {e}")); + Vec::new() + } + }, + Some(other) => { + super::host::skip_gpu(&format!("no device in tests (XTP_TEST_ADAPTER={other})")); + Vec::new() + } + None => { + let mut out = Vec::new(); + let warp_err = match Host::new(true) { + Ok(h) => { + out.push(("WARP".to_string(), h)); + None + } + Err(e) => { + eprintln!("WARP: no SM 6.6 device ({e}); not run there"); + Some(e) + } + }; + let mut hw = 0; + let mut last_hw_err = None; + match adapters() { + Ok(names) => { + for name in names { + match Host::on(&name) { + Ok(h) => { + hw += 1; + out.push((name, h)); + } + Err(e) => { + eprintln!("{name}: {e}; not run there"); + last_hw_err = Some(format!("{name}: {e}")); + } + } + } + } + Err(e) => last_hw_err = Some(e), + } + if hw == 0 && super::host::require_gpu() { + super::host::skip_gpu( + last_hw_err + .as_deref() + .unwrap_or("no hardware adapter with an SM 6.6 device"), + ); + } else if out.is_empty() { + let hw = last_hw_err.unwrap_or_else(|| "no hardware adapter".to_string()); + let warp = warp_err.unwrap_or_default(); + super::host::skip_gpu(&format!("hardware: {hw}; warp: {warp}")); + } + out } } - out } /// A pixel's key: x + 100 y of its centre. @@ -475,9 +521,9 @@ impl Drawn { } } -/// Draws `p` on every host and runs `check` on each target, which returns -/// its failures (empty: right). Panics with every host's failures, and -/// when no host drew at all: a test that drew nothing proves nothing. +/// Draws `p` on every host from [`hosts`] (skipping or failing through +/// [`super::host::skip_gpu`] when none is available) and runs `check` on +/// each target, which returns its failures (empty: right). fn draw_everywhere( p: &Program, marker: usize, @@ -488,9 +534,13 @@ fn draw_everywhere( let _one = super::valu_tests::ONE_AT_A_TIME .lock() .unwrap_or_else(|e| e.into_inner()); + let hosts = hosts(); + if hosts.is_empty() { + return Vec::new(); + } let mut failures = Vec::new(); let mut drawn = Vec::new(); - for (name, host) in hosts() { + for (name, host) in hosts { let (root, pso) = host .pipeline(&vs, &ps) .unwrap_or_else(|e| panic!("{name}: pipeline: {e}")); @@ -525,10 +575,6 @@ fn draw_everywhere( failures.extend(wrong.into_iter().map(|w| format!("{name}: {w}"))); drawn.push((name, t)); } - assert!( - !drawn.is_empty(), - "no device drew: neither WARP nor a hardware adapter (XTP_TEST_ADAPTER=none?)" - ); assert!(failures.is_empty(), "{failures:#?}"); drawn } diff --git a/crates/xtp-shader/src/emit/host.rs b/crates/xtp-shader/src/emit/host.rs index 8d8d381d..fc21c7b3 100644 --- a/crates/xtp-shader/src/emit/host.rs +++ b/crates/xtp-shader/src/emit/host.rs @@ -1812,3 +1812,210 @@ impl Host { } } } + +/// Whether GPU tests must fail instead of skipping when no host device is +/// available (`XTP_REQUIRE_GPU` set to anything other than `""` or `"0"`). +#[cfg(test)] +pub(crate) fn require_gpu() -> bool { + require_gpu_value(std::env::var_os("XTP_REQUIRE_GPU").as_deref()) +} + +#[cfg(test)] +fn require_gpu_value(value: Option<&std::ffi::OsStr>) -> bool { + value.is_some_and(|v| !v.is_empty() && v != "0") +} + +/// Reports a non-GPU test skip (`xtp_testkit::skip`) at most once per test and +/// reason, so helpers called in a loop do not repeat the marker. +#[cfg(test)] +pub(crate) fn skip_once(reason: &str) { + thread_local! { + static SEEN: std::cell::RefCell> = + const { std::cell::RefCell::new(Vec::new()) }; + } + let key = (xtp_testkit::current_test_name(), reason.to_owned()); + let first = SEEN.with(|seen| { + let mut seen = seen.borrow_mut(); + if seen.contains(&key) { + false + } else { + seen.push(key); + true + } + }); + if first { + xtp_testkit::skip(reason); + } +} + +/// Reports that the current test did not run because no host GPU device was +/// available (`reason`): fails when `XTP_REQUIRE_GPU` (or +/// `XTP_REQUIRE=no-gpu`) is set, else writes the standard `SKIPPED : +/// ` marker once. +#[cfg(test)] +pub(crate) fn skip_gpu(reason: &str) { + if require_gpu() { + let test = xtp_testkit::current_test_name(); + panic!("{test} needs a host GPU: {reason} (XTP_REQUIRE_GPU is set)"); + } + let require = std::env::var(xtp_testkit::REQUIRE_ENV).ok(); + if xtp_testkit::is_required(xtp_testkit::reason::NO_GPU, require.as_deref()) { + xtp_testkit::skip(xtp_testkit::reason::NO_GPU); + return; + } + skip_once(reason); +} + +#[cfg(test)] +impl Host { + /// The test adapter's SM 6.6 device (`Host::new(false)`), or `None` after + /// reporting the skip through [`skip_gpu`]. + pub(crate) fn test_device() -> Option { + Self::test_with(false) + } + + /// Like [`Host::test_device`], pinned to WARP unless `XTP_TEST_ADAPTER` + /// disables devices (`none`). + pub(crate) fn test_warp() -> Option { + Self::test_with(true) + } + + fn test_with(warp: bool) -> Option { + match Self::new(warp) { + Ok(host) => Some(host), + Err(reason) => { + skip_gpu(&reason); + None + } + } + } + + /// The SM 6.6 devices multi-backend tests run on, by label: `"warp"` when + /// `XTP_TEST_ADAPTER=warp`, `"hardware"` and `"warp"` when hardware is + /// allowed, or none (reported through [`skip_gpu`]) when `XTP_TEST_ADAPTER` + /// disables devices or none is available. With `XTP_REQUIRE_GPU` set and + /// hardware allowed, a missing hardware adapter fails the test rather than + /// letting WARP stand in for it. + pub(crate) fn test_hosts() -> Vec<(&'static str, Self)> { + match test_adapter().as_deref() { + Some("warp") => match Self::create(true, None) { + Ok(host) => vec![("warp", host)], + Err(e) => { + skip_gpu(&format!("warp: {e}")); + Vec::new() + } + }, + Some(other) => { + skip_gpu(&format!("no device in tests (XTP_TEST_ADAPTER={other})")); + Vec::new() + } + None => { + let mut out = Vec::new(); + let hardware = match std::env::var("XTP_ADAPTER") { + Ok(name) if !name.is_empty() => Self::on(&name), + _ => adapters().and_then(|a| match a.first() { + Some(name) => Self::on(name), + None => Err("no hardware adapter".to_string()), + }), + }; + let hw_err = match hardware { + Ok(host) => { + out.push(("hardware", host)); + None + } + Err(e) => { + if require_gpu() { + skip_gpu(&format!("hardware: {e}")); + } + Some(e) + } + }; + match Self::create(true, None) { + Ok(host) => out.push(("warp", host)), + Err(e) if out.is_empty() => { + let hw = hw_err.unwrap_or_default(); + skip_gpu(&format!("hardware: {hw}; warp: {e}")); + } + Err(e) => eprintln!("warp: {e}"), + } + out + } + } + } +} + +#[cfg(test)] +mod tests { + use std::ffi::OsStr; + use std::process::Command; + + use super::*; + + const CHILD_ENV: &str = "XTP_SHADER_SKIP_TEST_CHILD"; + + #[test] + fn require_gpu_reads_non_zero_values() { + assert!(!require_gpu_value(None)); + assert!(!require_gpu_value(Some(OsStr::new("")))); + assert!(!require_gpu_value(Some(OsStr::new("0")))); + assert!(require_gpu_value(Some(OsStr::new("1")))); + assert!(require_gpu_value(Some(OsStr::new("true")))); + } + + #[test] + fn child_gpu_skip_probe() { + if std::env::var_os(CHILD_ENV).is_none() { + return; + } + skip_gpu("synthetic missing adapter"); + skip_gpu("synthetic missing adapter"); + } + + #[test] + fn skip_gpu_prints_standard_marker_once_or_fails_when_required() { + let exe = std::env::current_exe().expect("test binary"); + let run = |require_gpu: Option<&str>, require: Option<&str>| { + let mut cmd = Command::new(&exe); + cmd.args(["--exact", "emit::host::tests::child_gpu_skip_probe"]) + .env(CHILD_ENV, "1") + .env_remove("XTP_REQUIRE_GPU") + .env_remove(xtp_testkit::REQUIRE_ENV); + if let Some(v) = require_gpu { + cmd.env("XTP_REQUIRE_GPU", v); + } + if let Some(v) = require { + cmd.env(xtp_testkit::REQUIRE_ENV, v); + } + cmd.output().expect("spawn child test") + }; + + let skipped = run(None, None); + assert!(skipped.status.success(), "{skipped:?}"); + let stderr = String::from_utf8_lossy(&skipped.stderr); + assert_eq!( + stderr + .lines() + .filter(|l| l.starts_with( + "SKIPPED emit::host::tests::child_gpu_skip_probe: synthetic missing adapter" + )) + .count(), + 1, + "expected exactly one canonical SKIPPED marker on stderr: {stderr}" + ); + + let strict_gpu = run(Some("1"), None); + assert!(!strict_gpu.status.success(), "XTP_REQUIRE_GPU=1 must fail"); + let combined = format!( + "{}\n{}", + String::from_utf8_lossy(&strict_gpu.stdout), + String::from_utf8_lossy(&strict_gpu.stderr) + ); + assert!(combined.contains("XTP_REQUIRE_GPU is set"), "{combined}"); + + let strict_testkit = run(None, Some(xtp_testkit::reason::NO_GPU)); + assert!( + !strict_testkit.status.success(), + "XTP_REQUIRE=no-gpu must fail" + ); + } +} diff --git a/crates/xtp-shader/src/emit/image_tests.rs b/crates/xtp-shader/src/emit/image_tests.rs index 7cd30633..b9b6d615 100644 --- a/crates/xtp-shader/src/emit/image_tests.rs +++ b/crates/xtp-shader/src/emit/image_tests.rs @@ -296,13 +296,10 @@ fn host() -> Option { let one = super::valu_tests::ONE_AT_A_TIME .lock() .unwrap_or_else(|e| e.into_inner()); - match Host::new(false) { - Ok(host) => Some(OneAtATime { host, _one: one }), - Err(e) => { - eprintln!("no SM 6.6 device ({e}); skipped"); - None - } - } + Some(OneAtATime { + host: Host::test_device()?, + _one: one, + }) } /// Point sampling, clamped; LESS_EQUAL for comparisons (passes when the @@ -1711,7 +1708,9 @@ mod atomic64 { fn host() -> Option { let host = super::host()?; if !host.int64_image_atomics() { - eprintln!("the device has no 64-bit atomics on heap typed resources; skipped"); + super::super::host::skip_once( + "the device has no 64-bit atomics on heap typed resources", + ); return None; } Some(host) diff --git a/crates/xtp-shader/src/emit/input_tests.rs b/crates/xtp-shader/src/emit/input_tests.rs index 8100a737..fa552475 100644 --- a/crates/xtp-shader/src/emit/input_tests.rs +++ b/crates/xtp-shader/src/emit/input_tests.rs @@ -357,13 +357,7 @@ fn draw_pixels(ps: &HostShader) -> Option> { let _one = super::valu_tests::ONE_AT_A_TIME .lock() .unwrap_or_else(|e| e.into_inner()); - let host = match Host::new(true) { - Ok(host) => host, - Err(e) => { - eprintln!("WARP indisponible ({e})"); - return None; - } - }; + let host = Host::test_device()?; let mut attr = element("TEXCOORD", 0, 0); attr.usage = 15; attr.interp = 2; diff --git a/crates/xtp-shader/src/emit/lane_read_loop_tests.rs b/crates/xtp-shader/src/emit/lane_read_loop_tests.rs index 707a12a5..5e24a8f0 100644 --- a/crates/xtp-shader/src/emit/lane_read_loop_tests.rs +++ b/crates/xtp-shader/src/emit/lane_read_loop_tests.rs @@ -113,7 +113,7 @@ fn devices() -> Vec<(String, Host)> { .filter_map(|name| match Host::on(&name) { Ok(host) => Some((name, host)), Err(e) => { - eprintln!("{name}: no SM 6.6 device ({e}); skipped"); + eprintln!("{name}: no SM 6.6 device ({e})"); None } }) diff --git a/crates/xtp-shader/src/emit/lightloop_tests.rs b/crates/xtp-shader/src/emit/lightloop_tests.rs index 55e07812..6baa38b0 100644 --- a/crates/xtp-shader/src/emit/lightloop_tests.rs +++ b/crates/xtp-shader/src/emit/lightloop_tests.rs @@ -329,12 +329,7 @@ fn refusal_with(parts: &[&[u32]], vgprs: u16) -> Option<&'static str> { /// WARP, and checks what it stores. fn run(shader: &HostShader, cases: &[[u32; 4]], want: impl Fn([u32; 4]) -> u32) { let _one = ONE_AT_A_TIME.lock().unwrap_or_else(|e| e.into_inner()); - let mut ran = 0; - for (label, warp) in [("hardware", false), ("warp", true)] { - let Ok(host) = Host::new(warp) else { - eprintln!("no SM 6.6 {label} device; skipped"); - continue; - }; + for (label, host) in Host::test_hosts() { let (root, pso) = host .compute_pipeline(shader) .unwrap_or_else(|e| panic!("{label}: {e}")); @@ -361,9 +356,7 @@ fn run(shader: &HostShader, cases: &[[u32; 4]], want: impl Fn([u32; 4]) -> u32) .unwrap_or_else(|e| panic!("{label}: {e}")); assert_eq!(out[0][0], want(case), "{label} {case:?}"); } - ran += 1; } - assert!(ran > 0, "neither hardware nor WARP SM 6.6 device available"); } const CASES: [[u32; 4]; 4] = [ diff --git a/crates/xtp-shader/src/emit/limits_tests.rs b/crates/xtp-shader/src/emit/limits_tests.rs index 7ae1be54..d6c3dd6b 100644 --- a/crates/xtp-shader/src/emit/limits_tests.rs +++ b/crates/xtp-shader/src/emit/limits_tests.rs @@ -382,10 +382,12 @@ fn heap_kinds(shader: &HostShader) -> Option> { static N: AtomicUsize = AtomicUsize::new(0); let dxc = match std::env::var_os("XTP_PC_DXC") { Some(p) => PathBuf::from(p), - None => super::validator::Validator::default_path()?.with_file_name("dxc.exe"), + None => super::validator::Validator::default_path() + .map(|p| p.with_file_name("dxc.exe")) + .unwrap_or_default(), }; if !dxc.exists() { - eprintln!("no dxc.exe; handle kinds not checked"); + eprintln!("no dxc.exe at {}; handle kinds not checked", dxc.display()); return None; } let file = std::env::temp_dir().join(format!( diff --git a/crates/xtp-shader/src/emit/loop_limit_tests.rs b/crates/xtp-shader/src/emit/loop_limit_tests.rs index 0ef7d6b9..55b7d9a6 100644 --- a/crates/xtp-shader/src/emit/loop_limit_tests.rs +++ b/crates/xtp-shader/src/emit/loop_limit_tests.rs @@ -173,9 +173,9 @@ fn emit(loops: Loops, bound: u32, target: Target) -> HostShader { .unwrap_or_else(|e| panic!("{loops:?}, {target:?}: {e}")) } -/// What WARP stores with lane `long` the long one (`u32::MAX`: none), or -/// none without a WARP device. Panics if the dispatch does not finish in -/// time. +/// What the test device stores with lane `long` the long one (`u32::MAX`: +/// none), or none without a device. Panics if the dispatch does not finish +/// in time. fn run(cs: &HostShader, long: u32) -> Option> { let _one = super::valu_tests::ONE_AT_A_TIME .lock() @@ -185,7 +185,7 @@ fn run(cs: &HostShader, long: u32) -> Option> { // The device lives on a thread of its own: a dispatch that never ends // stays there, and the test fails. std::thread::spawn(move || { - let out = Host::new(true).ok().map(|host| { + let out = Host::new(false).map(|host| { let (root, pso) = host.compute_pipeline(&cs).expect("pipeline"); let mut user = vec![0; (cs.user_data_dwords() as usize).max(2)]; user[1] = long; @@ -205,7 +205,11 @@ fn run(cs: &HostShader, long: u32) -> Option> { let _ = tx.send(out); }); match rx.recv_timeout(Duration::from_secs(120)) { - Ok(out) => out, + Ok(Ok(out)) => Some(out), + Ok(Err(e)) => { + super::host::skip_gpu(&e); + None + } Err(_) => panic!( "lane {long} long: the dispatch did not finish in 120 s (a group barrier waits for a lane that left?)" ), @@ -262,7 +266,6 @@ fn a_lane_stopped_through_a_conditional_back_edge_stores_nothing() { ); for long in [5, 37] { let Some(out) = run(&cs, long) else { - eprintln!("no WARP device; skipped"); return; }; assert_eq!(out, want(long, SHORT, None), "lane {long} long"); @@ -278,7 +281,6 @@ fn the_group_barrier_after_a_stopped_lane_is_passed() { let cs = emit(Loops::One(back), above_the_limit(), Target::ANY); for long in [u32::MAX, 0, 31, 32, 63] { let Some(out) = run(&cs, long) else { - eprintln!("no WARP device; skipped"); return; }; assert_eq!(out, want(long, SHORT, None), "{back:?}, lane {long} long"); @@ -300,7 +302,6 @@ fn nested_loops_stop_at_the_budget_of_all_loops_together() { let cs = emit(Loops::Nested, outer, Target::ANY); for long in [9, 40] { let Some(out) = run(&cs, long) else { - eprintln!("no WARP device; skipped"); return; }; let long_count = (!stops).then_some(outer * INNER); diff --git a/crates/xtp-shader/src/emit/lower/flow.rs b/crates/xtp-shader/src/emit/lower/flow.rs index 1351b01e..8fbc2517 100644 --- a/crates/xtp-shader/src/emit/lower/flow.rs +++ b/crates/xtp-shader/src/emit/lower/flow.rs @@ -2226,7 +2226,7 @@ mod tests { /// The descriptor edge of [`DESCRIPTOR_JOIN`] brings an undefined dword /// instead of stopping the program ("a descriptor's address or format - /// read as data"), and both edges give what the console does (on WARP). + /// read as data"), and both edges give what the console does on the host. #[test] fn descriptor_dwords_join_data_as_undefined_on_their_edge() { let cs = emit_for( @@ -2237,8 +2237,7 @@ mod tests { #[cfg(windows)] { use crate::emit::host::{Dispatch, Host, Root, Stride, View}; - let Ok(host) = Host::new(true) else { - eprintln!("no WARP device; skipped"); + let Some(host) = Host::test_device() else { return; }; let (root, pso) = host.compute_pipeline(&cs).unwrap(); @@ -2346,7 +2345,7 @@ mod tests { /// `s_or`, then `s_cbranch_vccnz` past the store). On the descriptor's /// edge the flag alone takes the branch, whatever s8 holds: the dword /// is dead there and the program translates; both edges give what the - /// console does (on WARP), as [`DESCRIPTOR_JOIN`] does. + /// console does on the host, as [`DESCRIPTOR_JOIN`] does. const FLAG_AND_WORD: [u32; 30] = [ 0x3408_0082, // v_lshlrev_b32 v4, 2, v0 0xBE84_0300, // s_mov_b32 s4, s0 @@ -2388,8 +2387,7 @@ mod tests { #[cfg(windows)] { use crate::emit::host::{Dispatch, Host, Root, Stride, View}; - let Ok(host) = Host::new(true) else { - eprintln!("no WARP device; skipped"); + let Some(host) = Host::test_device() else { return; }; let (root, pso) = host.compute_pipeline(&cs).unwrap(); diff --git a/crates/xtp-shader/src/emit/lower/lds.rs b/crates/xtp-shader/src/emit/lower/lds.rs index ad86e0e0..49e84968 100644 --- a/crates/xtp-shader/src/emit/lower/lds.rs +++ b/crates/xtp-shader/src/emit/lower/lds.rs @@ -668,19 +668,15 @@ mod tests { let _one = crate::emit::valu_tests::ONE_AT_A_TIME .lock() .unwrap_or_else(|e| e.into_inner()); - let host = match Host::new(false) { - Ok(h) => h, - Err(e) => { - translate(&words, Target::ANY).unwrap(); - eprintln!("no SM 6.6 device ({e}); skipped"); - return; - } + let Some(host) = Host::test_device() else { + translate(&words, Target::ANY).unwrap(); + return; }; // A group of one console wave using LDS declares its wave size. let s = match translate(&words, host.target()) { Ok(s) => s, Err(e) => { - eprintln!("not for this device ({e}); skipped"); + crate::emit::host::skip_once(&format!("not for this device ({e})")); return; } }; diff --git a/crates/xtp-shader/src/emit/lower/salu.rs b/crates/xtp-shader/src/emit/lower/salu.rs index e9bcb576..34892453 100644 --- a/crates/xtp-shader/src/emit/lower/salu.rs +++ b/crates/xtp-shader/src/emit/lower/salu.rs @@ -788,8 +788,7 @@ mod tests { /// it. #[test] fn a_join_of_two_code_tables_reads_each_paths_table() { - let Ok(host) = Host::new(false) else { - eprintln!("no SM 6.6 device; skipped"); + let Some(host) = Host::test_device() else { return; }; let out = run(&host, &joined()); diff --git a/crates/xtp-shader/src/emit/lower/smem.rs b/crates/xtp-shader/src/emit/lower/smem.rs index 2a353219..74eafd65 100644 --- a/crates/xtp-shader/src/emit/lower/smem.rs +++ b/crates/xtp-shader/src/emit/lower/smem.rs @@ -1312,8 +1312,8 @@ mod tests { let _one = crate::emit::valu_tests::ONE_AT_A_TIME .lock() .unwrap_or_else(|e| e.into_inner()); - let Ok(host) = Host::new(true) else { - eprintln!("no WARP device; skipped"); + // Kept on WARP: the old handle causes undefined behaviour on hardware. + let Some(host) = Host::test_warp() else { return; }; let (root, pso) = host.compute_pipeline(&cs).unwrap(); @@ -1387,8 +1387,7 @@ mod tests { let _one = crate::emit::valu_tests::ONE_AT_A_TIME .lock() .unwrap_or_else(|e| e.into_inner()); - let Ok(host) = Host::new(true) else { - eprintln!("no WARP device; skipped"); + let Some(host) = Host::test_device() else { return; }; let (root, pso) = host.compute_pipeline(&cs).unwrap(); diff --git a/crates/xtp-shader/src/emit/mesh_tests.rs b/crates/xtp-shader/src/emit/mesh_tests.rs index 3cfb5d14..a28c5c43 100644 --- a/crates/xtp-shader/src/emit/mesh_tests.rs +++ b/crates/xtp-shader/src/emit/mesh_tests.rs @@ -524,10 +524,7 @@ fn the_programs_decode_as_written() { /// on this PC), translated for the adapter's waves: the target, the mesh /// module's operations and the texels. `None` without an SM 6.6 device. fn draw_flat(native: &NativeProgram, size: (u32, u32)) -> Option<(Target, String, Vec<[f32; 4]>)> { - let Ok(host) = Host::new(false) else { - eprintln!("no SM 6.6 device; skipped"); - return None; - }; + let host = Host::test_device()?; Some(draw_flat_on(&host, native, size)) } diff --git a/crates/xtp-shader/src/emit/meshidx_tests.rs b/crates/xtp-shader/src/emit/meshidx_tests.rs index 15963c2d..3356b42c 100644 --- a/crates/xtp-shader/src/emit/meshidx_tests.rs +++ b/crates/xtp-shader/src/emit/meshidx_tests.rs @@ -16,9 +16,8 @@ fn repeated_exports_emit_indices_once_in_dxil() { } #[test] -fn warp_draws_the_last_primitive_export() { - let Ok(host) = Host::new(true) else { - eprintln!("WARP SM 6.6 indisponible, rendu ignoré"); +fn draws_the_last_primitive_export() { + let Some(host) = Host::test_device() else { return; }; let cases: [(&[u32], usize); 6] = [ diff --git a/crates/xtp-shader/src/emit/mod.rs b/crates/xtp-shader/src/emit/mod.rs index 17f72bf9..89c557d7 100644 --- a/crates/xtp-shader/src/emit/mod.rs +++ b/crates/xtp-shader/src/emit/mod.rs @@ -1144,8 +1144,7 @@ mod tests { #[test] #[cfg(windows)] fn stub_pipeline_is_created() { - let Ok(host) = super::host::Host::new(false) else { - eprintln!("no SM 6.6 device; skipped"); + let Some(host) = super::host::Host::test_device() else { return; }; let ps = super::HostShader { @@ -1206,7 +1205,7 @@ mod tests { let mut c = constant_color(); let path = super::validator::Validator::default_path(); let Ok(mut v) = super::validator::Validator::load(path.as_deref()) else { - eprintln!("no dxil.dll; skipped"); + super::host::skip_once(xtp_testkit::reason::NO_DXIL); return; }; let ours = c[4..20].to_vec(); @@ -1458,8 +1457,7 @@ mod tests { #[test] #[cfg(windows)] fn what_translates_for_the_host_creates_a_pipeline() { - let Ok(host) = super::host::Host::new(false) else { - eprintln!("no SM 6.6 device; skipped"); + let Some(host) = super::host::Host::test_device() else { return; }; let target = host.target(); @@ -1491,16 +1489,32 @@ mod tests { #[test] #[cfg(windows)] fn each_adapter_gets_what_it_runs() { - let Ok(names) = super::host::adapters() else { - eprintln!("no DXGI; skipped"); + if super::host::test_adapter().as_deref() == Some("warp") { + super::host::skip_once("hardware adapters kept out (XTP_TEST_ADAPTER=warp)"); return; + } + if super::host::test_adapter().is_some() { + let _ = super::host::Host::test_device(); + return; + } + let names = match super::host::adapters() { + Ok(names) => names, + Err(e) => { + super::host::skip_gpu(&format!("no DXGI ({e})")); + return; + } }; let words = [0xD760_0000, 0x0001_0B00, 0x7E02_0200, 0xBF81_0000]; + let mut ran = 0; for name in names { - let Ok(host) = super::host::Host::on(&name) else { - eprintln!("{name}: no SM 6.6 device; skipped"); - continue; + let host = match super::host::Host::on(&name) { + Ok(host) => host, + Err(e) => { + eprintln!("{name}: no SM 6.6 device ({e})"); + continue; + } }; + ran += 1; let target = host.target(); eprintln!("{name}: waves {}-{}", target.lanes_min, target.lanes_max); let one = match emit_for(&compute(&words, true), target) { @@ -1516,6 +1530,9 @@ mod tests { host.compute_pipeline(&two) .unwrap_or_else(|e| panic!("{name}: {e}")); } + if ran == 0 { + super::host::skip_gpu("no hardware adapter with an SM 6.6 device"); + } } #[test] diff --git a/crates/xtp-shader/src/emit/r1_tests.rs b/crates/xtp-shader/src/emit/r1_tests.rs index ba05f811..2939b650 100644 --- a/crates/xtp-shader/src/emit/r1_tests.rs +++ b/crates/xtp-shader/src/emit/r1_tests.rs @@ -5,7 +5,7 @@ //! descriptors at s0: entry 0 (dword 0) a constant buffer, entry 1 //! (dword 8) a raw UAV, entry 2 (dword 16) another constant buffer. Every //! translation is checked by the validator where `dxil.dll` is found, and -//! the one that translates is run on WARP. +//! the one that translates is run on the test device. //! //! The names start with `smem_`, so the task's check (`cargo test -p //! xtp-shader smem`) runs them. @@ -220,7 +220,7 @@ fn refusal(native: &NativeProgram) -> Option<&'static str> { /// The registers of a constant buffer read only by its `s_buffer_load`s and /// by a join with a number the program reads behind the flag that chose /// the number (r1smem's group B, `01d73927f08aed16` at 0x1cec): the -/// buffer's dwords are no data, the program translates, and on WARP the +/// buffer's dwords are no data, the program translates, and on the host the /// number's edge gives the number (77, the buffer's dword 1), the other /// edge 7. #[test] @@ -229,16 +229,15 @@ fn smem_a_constant_buffers_registers_reused_for_a_number_translate() { number_on_its_edge_only(&cs); } -/// Runs `cs`, a program of [`Reuse::Number`]'s form, on WARP: the -/// number's edge gives the number (77, the buffer's dword 1), the other -/// edge 7. Nothing where there is no WARP device. +/// Runs `cs`, a program of [`Reuse::Number`]'s form, on the test device: +/// the number's edge gives the number (77, the buffer's dword 1), the other +/// edge 7. Nothing where there is no device. fn number_on_its_edge_only(cs: &HostShader) { // One GPU test at a time (see `valu_tests::ONE_AT_A_TIME`). let _one = super::valu_tests::ONE_AT_A_TIME .lock() .unwrap_or_else(|e| e.into_inner()); - let Ok(host) = Host::new(true) else { - eprintln!("no WARP device; skipped"); + let Some(host) = Host::test_device() else { return; }; let (root, pso) = host.compute_pipeline(cs).expect("a pipeline"); diff --git a/crates/xtp-shader/src/emit/r4_tests.rs b/crates/xtp-shader/src/emit/r4_tests.rs index 367994f6..e13756d7 100644 --- a/crates/xtp-shader/src/emit/r4_tests.rs +++ b/crates/xtp-shader/src/emit/r4_tests.rs @@ -171,12 +171,8 @@ fn a_sampler_chosen_by_control_flow_samples_through_the_chosen_one() { let _one = super::valu_tests::ONE_AT_A_TIME .lock() .unwrap_or_else(|e| e.into_inner()); - let host = match Host::new(false) { - Ok(host) => host, - Err(e) => { - assert!(std::env::var_os("XTP_REQUIRE_GPU").is_none(), "{e}"); - return; - } + let Some(host) = Host::test_device() else { + return; }; let (root, pso) = host .pipeline(&vs, &ps) diff --git a/crates/xtp-shader/src/emit/raw_tests.rs b/crates/xtp-shader/src/emit/raw_tests.rs index c4aa9013..1edd9d18 100644 --- a/crates/xtp-shader/src/emit/raw_tests.rs +++ b/crates/xtp-shader/src/emit/raw_tests.rs @@ -266,31 +266,7 @@ fn hosts() -> ( let one = super::valu_tests::ONE_AT_A_TIME .lock() .unwrap_or_else(|e| e.into_inner()); - let mut hosts = Vec::new(); - for (name, warp) in [("WARP", true), ("the default adapter", false)] { - match Host::new(warp) { - Ok(h) => hosts.push((name, h)), - Err(e) => eprintln!("{name}: no SM 6.6 device ({e}); skipped"), - } - } - // In tests WARP may be the only device: once is enough. - hosts.truncate(if super::host::test_adapter().is_some() { - 1 - } else { - 2 - }); - if std::env::var("XTP_REQUIRE_GPU").as_deref() == Ok("1") { - let required = if super::host::test_adapter().is_some() { - "WARP" - } else { - "the default adapter" - }; - assert!( - hosts.iter().any(|(name, _)| *name == required), - "missing required {required}" - ); - } - (one, hosts) + (one, Host::test_hosts()) } /// Runs `cs` over the buffer of `kind` holding [`data`] (an unordered view diff --git a/crates/xtp-shader/src/emit/rayquery_tests.rs b/crates/xtp-shader/src/emit/rayquery_tests.rs index 3423ad79..705ab811 100644 --- a/crates/xtp-shader/src/emit/rayquery_tests.rs +++ b/crates/xtp-shader/src/emit/rayquery_tests.rs @@ -568,9 +568,12 @@ fn check_dxil(cs: &HostShader) { bindings(&cs.dxil) ); let path = super::validator::Validator::default_path(); - let Ok(mut v) = super::validator::Validator::load(path.as_deref()) else { - eprintln!("no dxil.dll; not validated"); - return; + let mut v = match super::validator::Validator::load(path.as_deref()) { + Ok(v) => v, + Err(e) => { + eprintln!("not validated: {e}"); + return; + } }; eprintln!( "dxil.dll {} (validator {:?})", @@ -1229,8 +1232,8 @@ fn rayquery_spliced_program_traces_on_warp() { assert!((a.t - t).abs() < 1e-5, "{a:?}, {t}"); } } - let Ok(host) = super::host::Host::new(true) else { - eprintln!("no WARP device; skipped"); + // Kept on WARP: warp::run binds only the view heap before a directly indexed root signature. + let Some(host) = super::host::Host::test_warp() else { return; }; // Ray n for thread n; the first rays again for the rest of the wave. @@ -1258,7 +1261,7 @@ fn rayquery_spliced_program_traces_on_warp() { let out = match warp::run(&host, &cs, &skeleton_scene(), &views, true) { Ok(Some(out)) => out, Ok(None) => { - eprintln!("WARP has no ray-tracing tier 1.1; skipped"); + super::host::skip_once("WARP has no ray-tracing tier 1.1"); return; } Err(e) => panic!("{e}"), @@ -1737,8 +1740,7 @@ fn rayquery_proof_refuses_what_the_walk_does_not_do() { fn rayquery_family_a_misses_rays_dxr_leaves_undefined_on_warp() { let (native, site) = family_a(); let cs = translate_with(&without_lds(&native), &site, false).unwrap(); - let Ok(host) = super::host::Host::new(true) else { - eprintln!("no WARP device; skipped"); + let Some(host) = super::host::Host::test_warp() else { return; }; let square = Blas { @@ -1799,7 +1801,7 @@ fn rayquery_family_a_misses_rays_dxr_leaves_undefined_on_warp() { let out = match warp::run(&host, &cs, &scene, &views, true) { Ok(Some(out)) => out, Ok(None) => { - eprintln!("WARP has no ray-tracing tier 1.1; skipped"); + super::host::skip_once("WARP has no ray-tracing tier 1.1"); return; } Err(e) => panic!("{e}"), @@ -2046,13 +2048,12 @@ fn rayquery_family_a_translates_validates_and_binds_alone() { check_dxil(&translate_with(&native, &site, true).unwrap()); let cs = translate_with(&without_lds(&native), &site, false).unwrap(); assert_eq!(cs.wave_size(), None); - let Ok(host) = super::host::Host::new(true) else { - eprintln!("no WARP device; skipped"); + let Some(host) = super::host::Host::test_warp() else { return; }; match warp::run(&host, &cs, &skeleton_scene(), &[], false) { Ok(Some(_)) => {} - Ok(None) => eprintln!("WARP has no ray-tracing tier 1.1; skipped"), + Ok(None) => super::host::skip_once("WARP has no ray-tracing tier 1.1"), Err(e) => panic!("{e}"), } } @@ -2106,8 +2107,7 @@ fn rayquery_family_a_end_to_end_on_warp() { .compare(11, &played, &mut proof::Report::default()) .unwrap_or_else(|f| panic!("{f:?}")); let cs = translate_with(&without_lds(&native), &site, false).unwrap(); - let Ok(host) = super::host::Host::new(true) else { - eprintln!("no WARP device; skipped"); + let Some(host) = super::host::Host::test_warp() else { return; }; let w = &played.world; @@ -2132,7 +2132,7 @@ fn rayquery_family_a_end_to_end_on_warp() { let out = match warp::run(&host, &cs, &scene, &views, true) { Ok(Some(out)) => out, Ok(None) => { - eprintln!("WARP has no ray-tracing tier 1.1; skipped"); + super::host::skip_once("WARP has no ray-tracing tier 1.1"); return; } Err(e) => panic!("{e}"), diff --git a/crates/xtp-shader/src/emit/rect_gs.rs b/crates/xtp-shader/src/emit/rect_gs.rs index 6cdac39f..61b60bfa 100644 --- a/crates/xtp-shader/src/emit/rect_gs.rs +++ b/crates/xtp-shader/src/emit/rect_gs.rs @@ -898,8 +898,8 @@ mod tests { use super::*; /// Validates `container` with the system's `dxil.dll` when there is - /// one (as the other emission tests do; a skip is said on standard - /// error). + /// one (as the other emission tests do; noted on standard error + /// without one). fn validate(what: &str, container: &[u8]) { use super::super::validator::Validator; match Validator::load(Validator::default_path().as_deref()) { @@ -908,7 +908,7 @@ mod tests { panic!("{what}: validation: {e}"); } } - Err(e) => eprintln!("SKIPPED validation of {what}: {e}"), + Err(e) => eprintln!("{what}: not validated ({e})"), } } diff --git a/crates/xtp-shader/src/emit/sampler_tests.rs b/crates/xtp-shader/src/emit/sampler_tests.rs index fb8ed93e..e8e73879 100644 --- a/crates/xtp-shader/src/emit/sampler_tests.rs +++ b/crates/xtp-shader/src/emit/sampler_tests.rs @@ -159,13 +159,8 @@ fn immediate_sampler_reads_depth_and_compares() { let _lock = super::valu_tests::ONE_AT_A_TIME .lock() .unwrap_or_else(|e| e.into_inner()); - let host = match Host::new(false) { - Ok(host) => host, - Err(e) => { - assert!(std::env::var_os("XTP_REQUIRE_GPU").is_none(), "{e}"); - eprintln!("skipped: {e}"); - return; - } + let Some(host) = Host::test_device() else { + return; }; for comparison_first in [false, true] { let shader = mixed_sampler(true, comparison_first, LESS_EQUAL); diff --git a/crates/xtp-shader/src/emit/smem_data_tests.rs b/crates/xtp-shader/src/emit/smem_data_tests.rs index ffeb9846..be7e944a 100644 --- a/crates/xtp-shader/src/emit/smem_data_tests.rs +++ b/crates/xtp-shader/src/emit/smem_data_tests.rs @@ -92,55 +92,23 @@ fn build(words: &[u32]) -> HostShader { /// `shader` checked by dxil.dll, where it is. fn validate(shader: &HostShader) { - if let Ok(mut v) = validator::Validator::load(validator::Validator::default_path().as_deref()) { - v.validate(&mut shader.dxil.clone()) - .unwrap_or_else(|e| panic!("DXIL validation failed: {e}")); - } else { - eprintln!("no dxil.dll; validation skipped"); + match validator::Validator::load(validator::Validator::default_path().as_deref()) { + Ok(mut v) => v + .validate(&mut shader.dxil.clone()) + .unwrap_or_else(|e| panic!("DXIL validation failed: {e}")), + Err(e) => eprintln!("not validated: {e}"), } } -/// The devices these tests run on, by label: the first hardware adapter -/// ("hardware"), unless `XTP_TEST_ADAPTER` keeps hardware out (`warp` on the -/// person's PC), and WARP. Without its device a run is left out, and with -/// `XTP_REQUIRE_GPU` set (the L4's `-GpuTests`) a missing hardware adapter -/// fails the test: there, "hardware" is a real GPU, never WARP standing in. -fn devices() -> Vec<(&'static str, Host)> { - let strict = std::env::var_os("XTP_REQUIRE_GPU").is_some_and(|v| !v.is_empty() && v != "0"); - let mut out = Vec::new(); - match super::host::test_adapter() { - Some(t) => eprintln!("hardware: kept out (XTP_TEST_ADAPTER={t})"), - None => { - let hardware = super::host::adapters().and_then(|a| match a.first() { - Some(name) => Host::on(name), - None => Err("no hardware adapter".to_string()), - }); - match hardware { - Ok(host) => out.push(("hardware", host)), - Err(e) if strict => panic!("hardware: {e} (XTP_REQUIRE_GPU is set)"), - Err(e) => eprintln!("hardware: {e}"), - } - } - } - match Host::new(true) { - Ok(host) => out.push(("warp", host)), - Err(e) => eprintln!("warp: {e}"), - } - if out.is_empty() { - eprintln!("no SM 6.6 device; skipped"); - } - out -} - /// Runs `shader` with `views` at heap indices 0.. (the UAV last) on each of -/// [`devices`] and returns, per one that ran, the UAV's 32 dwords. +/// [`Host::test_hosts`] and returns, per one that ran, the UAV's 32 dwords. fn run(shader: &HostShader, views: &[View]) -> Vec<(&'static str, Vec)> { let mut out = Vec::new(); // One GPU test at a time (see `valu_tests::ONE_AT_A_TIME`). let _one = super::valu_tests::ONE_AT_A_TIME .lock() .unwrap_or_else(|e| e.into_inner()); - for (label, host) in devices() { + for (label, host) in Host::test_hosts() { let (root, pso) = match host.compute_pipeline(shader) { Ok(p) => p, Err(e) => panic!("{label}: compute_pipeline failed: {e}"), @@ -683,7 +651,7 @@ fn a_mask_joined_with_a_number_exports_the_arms_number() { let _one = super::valu_tests::ONE_AT_A_TIME .lock() .unwrap_or_else(|e| e.into_inner()); - for (label, host) in devices() { + for (label, host) in Host::test_hosts() { for &(shape, body, s8, want) in &cases { let texels = draw(&host, label, &drawn(body), s8); assert_eq!(texels.len(), 2 * COLUMNS as usize, "{label}"); diff --git a/crates/xtp-shader/src/emit/smem_tests.rs b/crates/xtp-shader/src/emit/smem_tests.rs index 7fce818f..40d812d2 100644 --- a/crates/xtp-shader/src/emit/smem_tests.rs +++ b/crates/xtp-shader/src/emit/smem_tests.rs @@ -8,7 +8,7 @@ //! //! Two kinds of check: //! - the kind of every resource-heap handle of a translation, from dxc's -//! disassembly (the Windows SDK's `dxc.exe`, else skipped): one slot, +//! disassembly (the Windows SDK's `dxc.exe`, else not checked): one slot, //! one kind of view, whatever path the program reaches it by; //! - on WARP, what the loads read: a raw and a structured view in a heap //! slot, at constant, computed and unaligned offsets, past the view's @@ -169,10 +169,12 @@ pub(super) fn disassembly(shader: &HostShader) -> Option { static N: AtomicUsize = AtomicUsize::new(0); let dxc = match std::env::var_os("XTP_PC_DXC") { Some(p) => PathBuf::from(p), - None => super::validator::Validator::default_path()?.with_file_name("dxc.exe"), + None => super::validator::Validator::default_path() + .map(|p| p.with_file_name("dxc.exe")) + .unwrap_or_default(), }; if !dxc.exists() { - eprintln!("dxc.exe missing, disassembly skipped"); + eprintln!("no dxc.exe at {}; not disassembled", dxc.display()); return None; } let file = std::env::temp_dir().join(format!( @@ -450,10 +452,10 @@ fn run_scalar_reads(slot: View) -> Option> { // The table's raw buffer and the slot raw, the table's UAV. assert_eq!(distinct(kinds), [11, 11 | 0x1000]); } - let Ok(host) = Host::new(true) else { - eprintln!("no WARP device; skipped"); - return None; - }; + // Kept on WARP: the structured-slot test below reads a structured + // descriptor through a raw handle without the stride table (`stride_tests` + // covers hardware). + let host = Host::test_warp()?; let (root, pso) = host.compute_pipeline(&cs).unwrap(); let table = [2u32, 8, 0x40, 0x0e]; let views = [ diff --git a/crates/xtp-shader/src/emit/split_tests.rs b/crates/xtp-shader/src/emit/split_tests.rs index 3458de75..45e487a1 100644 --- a/crates/xtp-shader/src/emit/split_tests.rs +++ b/crates/xtp-shader/src/emit/split_tests.rs @@ -133,7 +133,7 @@ fn hardware() -> Vec<(String, Host)> { .filter_map(|name| match Host::on(&name) { Ok(host) => Some((name, host)), Err(e) => { - eprintln!("{name}: no SM 6.6 device ({e}); skipped"); + eprintln!("{name}: no SM 6.6 device ({e})"); None } }) diff --git a/crates/xtp-shader/src/emit/stride_tests.rs b/crates/xtp-shader/src/emit/stride_tests.rs index 5d2e24eb..b67c1d19 100644 --- a/crates/xtp-shader/src/emit/stride_tests.rs +++ b/crates/xtp-shader/src/emit/stride_tests.rs @@ -126,12 +126,10 @@ fn shader(words: &[u32], uav: u32, io: ComputeIo) -> HostShader { /// `dxil.dll` is, as a host shader. fn host_shader(mut l: super::lower::Lowered) -> HostShader { assert!(l.stride_table, "the program reads the table"); - if let Ok(mut v) = - super::validator::Validator::load(super::validator::Validator::default_path().as_deref()) + match super::validator::Validator::load(super::validator::Validator::default_path().as_deref()) { - v.validate(&mut l.dxil).expect("DXIL validation"); - } else { - eprintln!("no dxil.dll; validation skipped"); + Ok(mut v) => v.validate(&mut l.dxil).expect("DXIL validation"), + Err(e) => eprintln!("not validated: {e}"), } HostShader { stage: HwStage::Cs, @@ -158,20 +156,7 @@ fn hosts() -> ( let one = super::valu_tests::ONE_AT_A_TIME .lock() .unwrap_or_else(|e| e.into_inner()); - let mut hosts = Vec::new(); - for (name, warp) in [("WARP", true), ("the default adapter", false)] { - match Host::new(warp) { - Ok(h) => hosts.push((name, h)), - Err(e) => eprintln!("{name}: no SM 6.6 device ({e}); skipped"), - } - } - // In tests WARP may be the only device: once is enough. - hosts.truncate(if super::host::test_adapter().is_some() { - 1 - } else { - 2 - }); - (one, hosts) + (one, Host::test_hosts()) } /// What the GPU side makes for a buffer view of `count` elements of diff --git a/crates/xtp-shader/src/emit/userdata_tests.rs b/crates/xtp-shader/src/emit/userdata_tests.rs index 323407f8..cc13da1e 100644 --- a/crates/xtp-shader/src/emit/userdata_tests.rs +++ b/crates/xtp-shader/src/emit/userdata_tests.rs @@ -107,8 +107,7 @@ fn dispatch_reads_spilled_constants_and_the_spilled_table() { { validator.validate(&mut shader.dxil).unwrap(); } - let Ok(host) = Host::new(true) else { - eprintln!("no WARP device; skipped"); + let Some(host) = Host::test_device() else { return; }; let (root, pso) = host.compute_pipeline(&shader).unwrap(); @@ -303,7 +302,9 @@ fn reads_a_packed_address_and_an_adjacent_pair_from_spilled_constants() { assert!(track(&program(&words)).is_err()); let bytes = crate::dxbc::build(&[]); let cs = translate_program(&Container::parse(&bytes).unwrap(), &n).unwrap(); - let Ok(host) = Host::new(false) else { return }; + let Some(host) = Host::test_device() else { + return; + }; let (root, pso) = host.compute_pipeline(&cs).unwrap(); let mut ud = vec![0; cs.user_data_dwords() as usize]; for u in &cs.user_data { @@ -391,8 +392,7 @@ fn indexed_spilled_buffer_uses_the_matching_carry_and_gpu_offset() { let bytes = crate::dxbc::build(&[]); let cs = translate_program(&Container::parse(&bytes).unwrap(), &n).unwrap(); - let Ok(host) = Host::new(false) else { - assert!(std::env::var_os("XTP_REQUIRE_GPU").is_none()); + let Some(host) = Host::test_device() else { return; }; let (root, pso) = host.compute_pipeline(&cs).unwrap(); @@ -540,7 +540,9 @@ fn phi_reads_the_spilled_word_only_on_the_edge_that_keeps_it() { n.layout.push(param(RootType::Constants, 18, 2, 6)); let bytes = crate::dxbc::build(&[]); let cs = translate_program(&Container::parse(&bytes).unwrap(), &n).unwrap(); - let Ok(host) = Host::new(false) else { return }; + let Some(host) = Host::test_device() else { + return; + }; let (root, pso) = host.compute_pipeline(&cs).unwrap(); for (condition, expected) in [(0, 71), (1, 9)] { let mut ud = vec![0; cs.user_data_dwords() as usize]; @@ -603,7 +605,9 @@ fn partial_group_counts_lanes_and_preserves_the_end_of_the_root_uav() { let n = root_uav_program(&words, [64, 1, 1], true); let bytes = crate::dxbc::build(&[]); let c = Container::parse(&bytes).unwrap(); - let Ok(host) = Host::new(false) else { return }; + let Some(host) = Host::test_device() else { + return; + }; for lanes in [32, 64] { let target = super::Target { lanes_min: lanes, @@ -695,7 +699,9 @@ fn root_halfword_crosses_a_dword_and_typed_access_preserves_its_value() { let n = root_uav_program(&words, [1; 3], false); let bytes = crate::dxbc::build(&[]); let cs = translate_program(&Container::parse(&bytes).unwrap(), &n).unwrap(); - let Ok(host) = Host::new(false) else { return }; + let Some(host) = Host::test_device() else { + return; + }; let (root, pso) = host.compute_pipeline(&cs).unwrap(); let mut ud = vec![0; cs.user_data_dwords() as usize]; let bias = cs diff --git a/crates/xtp-shader/src/emit/validator_tests.rs b/crates/xtp-shader/src/emit/validator_tests.rs index 6d9d0b2b..9330750a 100644 --- a/crates/xtp-shader/src/emit/validator_tests.rs +++ b/crates/xtp-shader/src/emit/validator_tests.rs @@ -4,7 +4,7 @@ //! allows per signature row. Small modules built with [`Shader`] (their //! signatures as given), and one console pixel program translated whole. //! Each container is checked by the system's dxil.dll where there is one -//! (a skip is said on standard error). +//! (noted on standard error without one). use super::bitcode::{Attr, Cast, Term}; use super::container::{self, SigElement}; @@ -17,7 +17,7 @@ fn verdict(what: &str, container: &[u8]) -> Option> { match Validator::load(Validator::default_path().as_deref()) { Ok(mut v) => Some(v.validate(&mut container.to_vec())), Err(e) => { - eprintln!("SKIPPED validation of {what}: {e}"); + eprintln!("{what}: not validated ({e})"); None } } @@ -39,8 +39,8 @@ fn the_validator_knows_the_declared_version() { let path = Validator::default_path(); let v = match Validator::load(path.as_deref()) { Ok(v) => v, - Err(e) => { - eprintln!("SKIPPED: {e}"); + Err(_) => { + super::host::skip_once(xtp_testkit::reason::NO_DXIL); return; } }; diff --git a/crates/xtp-shader/src/emit/valu_tests.rs b/crates/xtp-shader/src/emit/valu_tests.rs index 14706a92..d9de6376 100644 --- a/crates/xtp-shader/src/emit/valu_tests.rs +++ b/crates/xtp-shader/src/emit/valu_tests.rs @@ -187,12 +187,7 @@ pub(super) fn run_cases( mut check: impl FnMut(&str, usize, [u32; 4], u32), ) { let _one = ONE_AT_A_TIME.lock().unwrap_or_else(|e| e.into_inner()); - let mut ran = 0; - for (label, warp) in [("hardware", false), ("warp", true)] { - let Ok(host) = Host::new(warp) else { - eprintln!("no SM 6.6 {label} device; skipped"); - continue; - }; + for (label, host) in Host::test_hosts() { let (root, pso) = host .compute_pipeline(shader) .unwrap_or_else(|e| panic!("{label}: compute_pipeline failed: {e}")); @@ -219,9 +214,7 @@ pub(super) fn run_cases( .unwrap_or_else(|e| panic!("{label}: dispatch failed: {e}")); check(label, i, inputs, out[0][0]); } - ran += 1; } - assert!(ran > 0, "neither hardware nor WARP SM 6.6 device available"); } fn is_f16_nan(bits: u16) -> bool { diff --git a/crates/xtp-shader/src/emit/waterfall_tests.rs b/crates/xtp-shader/src/emit/waterfall_tests.rs index 9d0b9340..4059e5fd 100644 --- a/crates/xtp-shader/src/emit/waterfall_tests.rs +++ b/crates/xtp-shader/src/emit/waterfall_tests.rs @@ -91,11 +91,11 @@ fn build(words: &[u32], buffers: bool) -> HostShader { stride_table: lowered.stride_table, run_time_buffers: lowered.run_time_buffers, }; - if let Ok(mut v) = validator::Validator::load(validator::Validator::default_path().as_deref()) { - v.validate(&mut shader.dxil.clone()) - .expect("DXIL validation failed"); - } else { - eprintln!("no dxil.dll; validation skipped"); + match validator::Validator::load(validator::Validator::default_path().as_deref()) { + Ok(mut v) => v + .validate(&mut shader.dxil.clone()) + .expect("DXIL validation failed"), + Err(e) => eprintln!("not validated: {e}"), } shader } @@ -120,11 +120,7 @@ fn run(shader: &HostShader, views: &[View]) -> Vec<(&'static str, Vec)> { let _one = super::valu_tests::ONE_AT_A_TIME .lock() .unwrap_or_else(|e| e.into_inner()); - for (label, warp) in [("hardware", false), ("warp", true)] { - let Ok(host) = Host::new(warp) else { - eprintln!("no SM 6.6 {label} device; skipped"); - continue; - }; + for (label, host) in Host::test_hosts() { let (root, pso) = match host.compute_pipeline(shader) { Ok(p) => p, Err(e) => panic!("{label}: compute_pipeline failed: {e}"), @@ -232,9 +228,7 @@ fn lanes_load_from_the_buffer_their_nested_arms_chose() { fn lanes_sample_the_entry_their_offset_names_in_the_console_waterfall() { use crate::resource::tests::WATERFALL_INDEXED_WAVE32; let shader = build(WATERFALL_INDEXED_WAVE32, false); - let results = sampled(&shader); - assert!(!results.is_empty()); - for (label, red) in results { + for (label, red) in sampled(&shader) { // Even lanes hold entry 0's offset, odd lanes entry 1's. let want: Vec = (0..32).map(|l| [1.0, 2.0][l & 1]).collect(); assert_eq!(red, want, "{label}"); @@ -248,9 +242,7 @@ fn lanes_sample_their_own_texture_in_a_waterfall_narrowed_by_v_cmpx() { let want: Vec = (0..32).map(|l| if l < 16 { 1.0 } else { 2.0 }).collect(); for folded in [false, true] { let shader = build(&cmpx_waterfall(false, folded), false); - let results = sampled(&shader); - assert!(!results.is_empty()); - for (label, red) in results { + for (label, red) in sampled(&shader) { assert_eq!(red, want, "{label}, folded {folded}"); } } diff --git a/docs/analysis/hardware-tests.md b/docs/analysis/hardware-tests.md index ff76ba48..90761f31 100644 --- a/docs/analysis/hardware-tests.md +++ b/docs/analysis/hardware-tests.md @@ -152,9 +152,9 @@ Every other test gives the same result on both adapters. In particular: | Test | Why | Owner | |------|-----|-------| | `emit::diff_tests::translated_mesh_shaders_draw_as_pc_ones`, `translated_shaders_draw_as_pc_ones`, `translated_compute_matches_pc`, `float_semantics_are_the_consoles` | need the console SDK's `dxc.exe` (`XTP_CONSOLE_DXC`), on no machine of ours: they skip on WARP and on the L4. Among them was the only test that drew a translated mesh program against the PC's. | the person (a console compiler on the VM is their call: it is the SDK's) | -| `emit::lower::flow::tests::descriptor_dwords_join_data_as_undefined_on_their_edge` | creates its device with `Host::new(true)`, WARP on every machine: it never runs on the L4. `Host::new(false)` would follow `XTP_TEST_ADAPTER` like the others. | loop-limits (holds `flow.rs`) | +| `emit::lower::flow::tests::descriptor_dwords_join_data_as_undefined_on_their_edge` | created its device with `Host::new(true)`, WARP on every machine, so it did not run on the L4 in section 2's run. | done: uses `Host::test_device()` (`XTP_TEST_ADAPTER`) | | `resource::tests::buffer_data_reaches_a_stand_in_texture_converted` | the reverse: skips on WARP ("the host has every use of B5G5R5A1"), runs and passes on the L4, whose driver lacks some. | – (as intended) | -| xtp-shader's GPU tests | return early, and pass, when they get no device, whatever `XTP_REQUIRE_GPU` says (`eprintln!("...; skipped")`); xtp-gpu's fail then (`testgpu::skip`). `-GpuTests` counts them as skips. | whoever next touches `emit/host.rs`: route them through one helper that honours `XTP_REQUIRE_GPU` | +| xtp-shader's GPU tests | returned early and passed when they got no device, whatever `XTP_REQUIRE_GPU` said (`eprintln!("...; skipped")`); xtp-gpu's failed (`testgpu::skip`). | done: routed through `emit::host::skip_gpu` (`XTP_REQUIRE_GPU`) | five-star's two hangs were mesh programs. XTP's mesh lowering already leaves out the `s_barrier`s of blocks that the allocation request dominates diff --git a/docs/contributing-without-a-gaming-pc.md b/docs/contributing-without-a-gaming-pc.md index da166ec8..a73b22c7 100644 --- a/docs/contributing-without-a-gaming-pc.md +++ b/docs/contributing-without-a-gaming-pc.md @@ -144,8 +144,9 @@ $env:XTP_TEST_ADAPTER = 'warp' cargo test -p xtp-shader -p xtp-gpu --locked ``` -- Without a device, an `xtp-gpu` test prints `SKIPPED : ` and - passes, unless `XTP_REQUIRE_GPU` is set: then it fails. +- Without a device, an `xtp-gpu` or `xtp-shader` test prints + `SKIPPED : ` and passes, unless `XTP_REQUIRE_GPU` is set: + then it fails. - CI runs the `xtp-gpu` tests on WARP under the D3D12 debug layer. Locally, with Windows' optional "Graphics Tools" feature installed: