Skip to content
Merged
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
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions crates/xtp-shader/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
13 changes: 3 additions & 10 deletions crates/xtp-shader/src/emit/buffer16_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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}"));
Expand All @@ -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
Expand Down
8 changes: 1 addition & 7 deletions crates/xtp-shader/src/emit/desc_data_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]),
Expand Down
34 changes: 19 additions & 15 deletions crates/xtp-shader/src/emit/diff_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u8> {
Expand Down Expand Up @@ -715,11 +727,9 @@ fn user_data(s: &HostShader, k: &[u32; 4]) -> Vec<u32> {
#[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()));
Expand Down Expand Up @@ -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()));
Expand Down Expand Up @@ -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()));
Expand Down Expand Up @@ -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()));
Expand Down
10 changes: 2 additions & 8 deletions crates/xtp-shader/src/emit/geometry_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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})"),
}
}

Expand Down Expand Up @@ -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
Expand Down
13 changes: 3 additions & 10 deletions crates/xtp-shader/src/emit/group_id_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down
84 changes: 65 additions & 19 deletions crates/xtp-shader/src/emit/helper_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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,
Expand All @@ -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}"));
Expand Down Expand Up @@ -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
}
Expand Down
Loading
Loading