From 46695abf51ea2ceaae6b11eb4ed4f06440d5f383 Mon Sep 17 00:00:00 2001 From: Lucas Koplin Date: Tue, 24 Nov 2026 02:23:09 -0300 Subject: [PATCH] Tests: GPU tests of f64 instructions skip on an adapter without doubles An adapter that reports no DoublePrecisionFloatShaderOps still runs the recompiled f64 instructions, with wrong results: on Apple's D3DMetal (macOS, CrossOver) a program holding any f64 instruction gets 0 for its other results too (an integer add of 5 and 7 next to a v_add_f64 reads 0). The 9 f64 tests failed there, and so did gpu_clamp_and_omod_per_instruction and gpu_valu_16_and_64_bit, whose programs mix f64 with f16 and integer work. runner::f64_supported() reads the flag at init. Those 11 tests print "SKIPPED : no f64" there; gpu_float_compares_random, which builds one program per type, skips only its F64 program. XCL_REQUIRE_GPU=wave64 / mesh does not turn a "no f64" skip into a failure. Co-Authored-By: Claude Opus 5.5 --- CONTRIBUTING.md | 2 +- README.md | 2 +- crates/xcl/src/gpu/recomp/runner.rs | 20 ++++++++++--- crates/xcl/src/gpu/recomp/tests.rs | 45 +++++++++++++++++++++++++---- 4 files changed, 57 insertions(+), 12 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index dfdd78a9e..decd01311 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -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. diff --git a/README.md b/README.md index 9c047fd54..5c9f90be1 100644 --- a/README.md +++ b/README.md @@ -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 : `, and +the adapter (no GPU / DXC / wave64 / mesh shaders / f64) passes too, but prints `SKIPPED : `, 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), diff --git a/crates/xcl/src/gpu/recomp/runner.rs b/crates/xcl/src/gpu/recomp/runner.rs index c9748ab79..59b232694 100644 --- a/crates/xcl/src/gpu/recomp/runner.rs +++ b/crates/xcl/src/gpu/recomp/runner.rs @@ -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. @@ -114,11 +116,14 @@ fn init() -> Result { 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 }) } } @@ -353,6 +358,13 @@ pub fn adapter() -> Result { 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 { + 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 { let mut g = GPU.lock().unwrap(); let gpu = g.get_or_insert_with(init); @@ -421,7 +433,7 @@ pub fn mesh_shaders_supported() -> Result { } /// 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 : ` written to stderr itself, so the +/// "no wave64", "no mesh shaders", "no f64": `SKIPPED : ` 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. @@ -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 { diff --git a/crates/xcl/src/gpu/recomp/tests.rs b/crates/xcl/src/gpu/recomp/tests.rs index 5a8d73539..ce6068332 100644 --- a/crates/xcl/src/gpu/recomp/tests.rs +++ b/crates/xcl/src/gpu/recomp/tests.rs @@ -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 } @@ -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(&[ @@ -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(), @@ -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(&[ @@ -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); } @@ -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); } @@ -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); } @@ -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); @@ -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(&[ @@ -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); } @@ -6339,6 +6365,9 @@ fn ldexp_ref(x: f64, n: i32) -> Option { /// 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); } @@ -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 = 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(); @@ -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