Skip to content
Open
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
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ and pure renames need no test.
title in `tests/testtitle` / `tests/testgamedll`: extend it when a change concerns the path a title
takes.
- **GPU tests** must run without a GPU too: when the adapter cannot run them, call
`gpu::recomp::runner::skip_test("no GPU" | "no DXC" | "no wave64" | "no mesh shaders")` and return.
`gpu::recomp::runner::skip_test("no GPU" | "no DXC" | "no wave64" | "no mesh shaders" | "no f64")` and return.
Never mark a test `#[ignore]` only so that it passes.
- **Tests on game data** read files the contributor owns through the `XCL_SAMPLE_*` variables
(see README / `scripts/test.ps1`), and pass without doing anything when the variable is not set.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ xcl rpf D:\data\shaders.rpf --extract NAME --out folder
Unit tests, an end-to-end test with our own "console title" (`tests/testtitle`) and GPU tests
(D3D12, SM 6.6; skipped without a GPU / DXC; `XCL_ADAPTER=1` or `XCL_ADAPTER=radeon` picks
another adapter than the first high-performance one, for titles too). A GPU test that cannot run on
the adapter (no GPU / DXC / wave64 / mesh shaders) passes too, but prints `SKIPPED <test>: <reason>`, and
the adapter (no GPU / DXC / wave64 / mesh shaders / f64) passes too, but prints `SKIPPED <test>: <reason>`, and
`scripts/test.ps1` counts them at the end; `XCL_REQUIRE_GPU=wave64` (or `mesh`, or `wave64,mesh`) makes
those skips fail. Tests on real game data are opt-in through
environment variables pointing at your own files – `XCL_SAMPLE_RPF` (shader pack),
Expand Down
20 changes: 16 additions & 4 deletions crates/xcl/src/gpu/recomp/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ struct Gpu {
wave32: bool,
/// mesh shader tier 1 or higher (`mesh_draw`)
mesh: bool,
/// doubles in shaders (`DoublePrecisionFloatShaderOps`; Apple's D3DMetal has none)
f64: bool,
}

// D3D12 objects are free-threaded; access is serialised by the mutex.
Expand Down Expand Up @@ -114,11 +116,14 @@ fn init() -> Result<Gpu, String> {
let mut o7 = D3D12_FEATURE_DATA_D3D12_OPTIONS7::default();
let mesh = dev.CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS7, &mut o7 as *mut _ as _, std::mem::size_of_val(&o7) as u32).is_ok()
&& o7.MeshShaderTier.0 >= D3D12_MESH_SHADER_TIER_1.0;
let mut o = D3D12_FEATURE_DATA_D3D12_OPTIONS::default();
let f64 = dev.CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS, &mut o as *mut _ as _, std::mem::size_of_val(&o) as u32).is_ok()
&& o.DoublePrecisionFloatShaderOps.as_bool();
let queue: ID3D12CommandQueue =
dev.CreateCommandQueue(&D3D12_COMMAND_QUEUE_DESC { Type: D3D12_COMMAND_LIST_TYPE_DIRECT, ..Default::default() }).map_err(e)?;
let rs = root_signature(&dev, false)?;
let fence: ID3D12Fence = dev.CreateFence(0, D3D12_FENCE_FLAG_NONE).map_err(e)?;
Ok(Gpu { dev, queue, rs, fence, value: 0, adapter: name, wave64, wave32, mesh })
Ok(Gpu { dev, queue, rs, fence, value: 0, adapter: name, wave64, wave32, mesh, f64 })
}
}

Expand Down Expand Up @@ -353,6 +358,13 @@ pub fn adapter() -> Result<String, String> {
gpu.as_ref().map(|x| x.adapter.clone()).map_err(|x| x.clone())
}

/// Whether shaders may use doubles on this adapter.
pub fn f64_supported() -> Result<bool, String> {
let mut g = GPU.lock().unwrap();
let gpu = g.get_or_insert_with(init);
gpu.as_ref().map(|x| x.f64).map_err(|x| x.clone())
}

pub fn wave64_supported() -> Result<bool, String> {
let mut g = GPU.lock().unwrap();
let gpu = g.get_or_insert_with(init);
Expand Down Expand Up @@ -421,7 +433,7 @@ 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
/// "no wave64", "no mesh shaders", "no f64": `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.
Expand All @@ -431,8 +443,8 @@ pub fn skip_test(reason: &str) {
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",
"wave64" => !matches!(reason, "no mesh shaders" | "no f64"),
"mesh" => !matches!(reason, "no wave64" | "no f64"),
_ => false,
});
if fails {
Expand Down
45 changes: 39 additions & 6 deletions crates/xcl/src/gpu/recomp/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,18 @@ fn wave64_hardware() -> bool {
w
}

/// The adapter runs shaders but has no doubles in them (`DoublePrecisionFloatShaderOps`; Apple's
/// D3DMetal: f64 instructions run and give wrong results): a test of f64 instructions skips them.
/// False without a GPU, which `gpu_ready` / `gpu_waves` report.
fn no_doubles() -> bool {
let none = runner::f64_supported() == Ok(false);
if none {
println!("no doubles in shaders on this GPU – skipping the f64 instructions");
runner::skip_test("no f64");
}
none
}

/// `o` for a program run on this adapter (the split wave64 form where it is needed).
fn on_gpu(o: Options) -> Options {
Options { split_wave64: runner::split_for(&o.mode), ..o }
Expand Down Expand Up @@ -486,7 +498,7 @@ fn f64_class_compare_vopc_and_vop3() {

#[test]
fn gpu_f64_class_compare() {
if !gpu_ready() {
if !gpu_ready() || no_doubles() {
return;
}
let p = prog(&[
Expand Down Expand Up @@ -675,7 +687,7 @@ fn rndne_f64_instructions() {

#[test]
fn gpu_rndne_f64() {
if !gpu_ready() { return; }
if !gpu_ready() || no_doubles() { return; }
let p = prog(&[("V_RNDNE_F64", "ENC_VOP1", &[("VDST", 2), ("SRC0", V)], None)]);
const INPUTS: [u64; 16] = [
0.0f64.to_bits(), (-0.0f64).to_bits(), 0.5f64.to_bits(), (-0.5f64).to_bits(),
Expand All @@ -700,7 +712,7 @@ fn gpu_rndne_f64() {

#[test]
fn gpu_frexp_f64_exp_and_mant() {
if !gpu_ready() {
if !gpu_ready() || no_doubles() {
return;
}
let p = prog(&[
Expand Down Expand Up @@ -803,6 +815,9 @@ fn pair(v: &[u32], i: usize) -> f64 {
/// the CPU's IEEE results, bit for bit, including the sign of zero, |x| ≥ 2^63, ±inf and NaN.
#[test]
fn gpu_f64_rounding_and_conversions() {
if no_doubles() {
return;
}
for wave64 in gpu_waves() {
f64_rounding_and_conversions(wave64);
}
Expand Down Expand Up @@ -858,6 +873,9 @@ fn f64_rounding_and_conversions(wave64: bool) {
/// range get real roots within an ulp of the CPU's, a negative x gives NaN and −0 gives −0.
#[test]
fn gpu_f64_roots() {
if no_doubles() {
return;
}
for wave64 in gpu_waves() {
f64_roots(wave64);
}
Expand Down Expand Up @@ -898,6 +916,9 @@ fn f64_roots(wave64: bool) {
/// denormal results, exponents beyond the f32 range of 2^n.
#[test]
fn gpu_ldexp_f64() {
if no_doubles() {
return;
}
for wave64 in gpu_waves() {
ldexp_f64(wave64);
}
Expand Down Expand Up @@ -1005,7 +1026,8 @@ fn gpu_valu_float_and_int() {
/// unsigned adds, the packed 16-bit adds and the integer dot products.
#[test]
fn gpu_clamp_and_omod_per_instruction() {
if !gpu_ready() {
// the f64 instructions share the program: without doubles its other results are wrong too
if !gpu_ready() || no_doubles() {
return;
}
let p = |name: &'static str, f: &'static [(&'static str, u64)]| (name, "ENC_VOP3P", f, None);
Expand Down Expand Up @@ -2654,7 +2676,8 @@ fn gpu_dword_addtid_per_lane_addresses() {

#[test]
fn gpu_valu_16_and_64_bit() {
if !gpu_ready() {
// f64 instructions share the program: without doubles its other results are wrong too
if !gpu_ready() || no_doubles() {
return;
}
let p = prog(&[
Expand Down Expand Up @@ -6187,6 +6210,9 @@ fn gpu_fract_f32_edges() {
/// when unordered, bit for bit against IEEE.
#[test]
fn gpu_f64_compares_with_nan() {
if no_doubles() {
return;
}
for wave64 in gpu_waves() {
f64_compares_with_nan(wave64);
}
Expand Down Expand Up @@ -6339,6 +6365,9 @@ fn ldexp_ref(x: f64, n: i32) -> Option<f64> {
/// one rounding. sqrt must be within 1 ulp and rsq within 2.
#[test]
fn gpu_f64_math_random() {
if no_doubles() {
return;
}
for wave64 in gpu_waves() {
f64_math_random(wave64);
}
Expand Down Expand Up @@ -6447,7 +6476,8 @@ fn float_compares_random(wave64: bool) {
};
let mut rng = Rng(0x1234_5678_9ABC_DEF1);
let mut total_bad = 0usize;
for ty in ["F32", "F64", "F16"] {
let doubles = !no_doubles();
for ty in ["F32", "F64", "F16"].into_iter().filter(|&t| doubles || t != "F64") {
let (s0, s1) = if ty == "F64" { (V + 2, 4u64) } else { (V, 1u64) };
let names: Vec<String> = OPS.iter().map(|o| format!("V_CMP_{o}_{ty}")).collect();
let f3: Vec<[(&str, u64); 3]> = (0..16).map(|i| [("VDST", 20 + 2 * i as u64), ("SRC0", s0), ("SRC1", V + s1)]).collect();
Expand Down Expand Up @@ -7015,6 +7045,9 @@ fn gpu_ldexp_f32() {

#[test]
fn gpu_f64_literal_high_word() {
if no_doubles() {
return;
}
for wave64 in gpu_waves() {
let p = prog(&[
// 1.0 + literal(1.5 = 0x3FF8_0000_0000_0000) == 2.5
Expand Down
Loading