xtask/print_gpu.rs
1//! `cargo xtask print-gpu`: describe the device the tests draw with.
2//!
3//! A snapshot mismatch is usually a disagreement between drivers, so a CI log
4//! that names the backend, adapter, features and limits is what turns a score
5//! into something a reader can act on. The task runner links no graphics code,
6//! so the description comes from `unlit_wgpu_test_util`'s `gpu-info` binary,
7//! which is built and run here.
8//!
9//! A test run draws through two tiers -- the default one, then `webgl2` -- so
10//! both are described, each labelled with the tier it belongs to.
11
12use std::process::Command;
13
14use crate::{PrintGpuArgs, step};
15
16/// The environment variable that picks the device tier.
17///
18/// Repeated from `unlit_wgpu_test_util`, which this crate does not depend on.
19const TIER_ENV: &str = "UNLIT3D_DEVICE_TIER";
20
21/// The tiers `cargo xtask test` runs its passes at, in the order it runs them.
22///
23/// The first is the default tier, named by its `UNLIT3D_DEVICE_TIER` spelling so
24/// a reader can look the name up; the second asks only for what a browser
25/// grants, so the two describe different capability sets even on one device.
26const TEST_TIERS: &[&str] = &["webgpu", "webgl2"];
27
28/// Print the device a test run at this tier would draw with.
29pub fn run(args: &PrintGpuArgs) -> Result<(), String> {
30 match &args.tier {
31 Some(tier) => print_tier(tier),
32 None => TEST_TIERS.iter().try_for_each(|tier| print_tier(tier)),
33 }
34}
35
36/// Print the device one tier would draw with.
37fn print_tier(tier: &str) -> Result<(), String> {
38 let mut command = Command::new("cargo");
39 command.args([
40 "run",
41 "--quiet",
42 "-p",
43 "unlit_wgpu_test_util",
44 "--bin",
45 "gpu-info",
46 ]);
47 command.env(TIER_ENV, tier);
48 step::run(&mut command, &format!("printing the device ({tier})"))
49}