From 3e7b0c56389a43f0680dd7ec6d658cea1a753d84 Mon Sep 17 00:00:00 2001 From: fiestorra Date: Tue, 1 Dec 2026 14:29:02 +0100 Subject: [PATCH] d3d12: the last four clippy warnings, and why the six in valu_tests stay The cleanup that merged tonight (#2681, #2682) fixed 83 warnings; four came back by the time it landed, all from merges made after it: pipeline/host.rs this function has too many arguments (8/7) pipeline/known.rs drop on a value that implements Copy pipeline/known.rs this loop could be written as a `while let` loop glyphs/live.rs manual `Range::contains` implementation The first is the only one with a shape: the three shader bytecodes become a MeshShaders struct, so mesh_pipeline takes six arguments and the body destructures it on its first line, where the four call sites cannot see the difference. The other three are clippy's own wording, applied. And six in emit/valu_tests.rs are a different thing: clippy suggests `a != b` for `a < b || a > b` and equivalences for the negated compares, and in a table of RDNA2's sixteen f32 compare predicates those are not the same function: with a NaN, `a < b || a > b` is false and `a != b` is true. Allowing the two lints on that one test is the fix, and the comment above the table says why. After review (KelboLive, Neutron-0, imShangLi, merzleckeier), four things: - `send_published`'s parameter loses `mut`, which is only written under `diagnostics`; the `let mut h = h;` is behind that feature. Without it the tree produced by merging this into main carried `unused_mut` and "clippy is at zero" would not have been true of the result. - the struct is `MeshShaders`, not `Stages`: `stages` is already the name of the crate's actual stage set, and this holds shader bytecodes. - the doc that describes mesh_pipeline's stream goes back on `mesh_pipeline`; the struct gets two lines of its own. - `nonminimal_bool` leaves the allow: no warning asked for it, and with `--all-targets` the count is still zero. Measured on main dcda41f76: cargo clippy --workspace 0 warnings cargo clippy --workspace --all-targets 0 warnings cargo test -p leonida-gpu --lib -- --test-threads=1 633 passed; 0 failed cargo test -p leonida-shader 414 passed; 0 failed cargo test -p leonida-hle passed Written with an AI assistant. --- d3d12/crates/leonida-gpu/src/host.rs | 6 ++++- d3d12/crates/leonida-gpu/src/pipeline/host.rs | 25 +++++++++++++------ .../crates/leonida-gpu/src/pipeline/known.rs | 13 +++++++--- .../leonida-hle/src/modules/glyphs/live.rs | 2 +- .../leonida-shader/src/emit/valu_tests.rs | 4 +++ 5 files changed, 38 insertions(+), 12 deletions(-) diff --git a/d3d12/crates/leonida-gpu/src/host.rs b/d3d12/crates/leonida-gpu/src/host.rs index c5e110d4f0..c9f530cdb6 100644 --- a/d3d12/crates/leonida-gpu/src/host.rs +++ b/d3d12/crates/leonida-gpu/src/host.rs @@ -7432,7 +7432,11 @@ impl Host { } } - fn send_published(&self, mut h: Handoff) { + fn send_published(&self, h: Handoff) { + // The lists and the stamp are added to `h` only with `diagnostics`; without + // it nothing here writes it, and `mut` on the parameter is a warning. + #[cfg(feature = "diagnostics")] + let mut h = h; let started = std::time::Instant::now(); let waited = std::time::Instant::now(); drop(h.heaps); diff --git a/d3d12/crates/leonida-gpu/src/pipeline/host.rs b/d3d12/crates/leonida-gpu/src/pipeline/host.rs index 3ab7cbc626..b4f237a41f 100644 --- a/d3d12/crates/leonida-gpu/src/pipeline/host.rs +++ b/d3d12/crates/leonida-gpu/src/pipeline/host.rs @@ -913,7 +913,11 @@ impl HostPipeline { &state, ); let pso = match mesh_pipeline( - &host.device, &root, None, code(0), code(1), g, depth_bounds, + &host.device, + &root, + MeshShaders { amplify: None, ms: code(0), ps: code(1) }, + g, + depth_bounds, library.name(&name).as_deref(), ) { Ok(pso) => pso, @@ -935,7 +939,7 @@ impl HostPipeline { &[&code_bytes(&stage), &code_bytes(&code(0)), &code_bytes(&code(1))], &state, ); - match mesh_pipeline(&host.device, &root, Some(stage), code(0), code(1), g, depth_bounds, library.name(&name).as_deref()) { + match mesh_pipeline(&host.device, &root, MeshShaders { amplify: Some(stage), ms: code(0), ps: code(1) }, g, depth_bounds, library.name(&name).as_deref()) { Ok(amplified) => { crate::host::name(&lified, || format!("{shaders:?} amplified")); Some((amplified, at)) @@ -1200,6 +1204,14 @@ fn graphics_depth_bounds_pipeline( } } +/// The three shader bytecodes a mesh pipeline is made from: the amplification +/// stage when the title runs one indirectly, and the two the translation writes. +struct MeshShaders { + amplify: Option, + ms: D3D12_SHADER_BYTECODE, + ps: D3D12_SHADER_BYTECODE, +} + /// A mesh pipeline from the title's graphics state: the pipeline-state /// stream form (no input layout). /// @@ -1214,13 +1226,12 @@ fn graphics_depth_bounds_pipeline( fn mesh_pipeline( device: &ID3D12Device, root: &ID3D12RootSignature, - amplify: Option, - ms: D3D12_SHADER_BYTECODE, - ps: D3D12_SHADER_BYTECODE, + code: MeshShaders, g: &GraphicsState, depth_bounds: bool, name: Option<&str>, ) -> windows::core::Result { + let MeshShaders { amplify, ms, ps } = code; use windows::core::Interface; /// `A`: the amplification stage's subobject, or nothing (`()`, no bytes in the stream). #[repr(C)] @@ -1533,9 +1544,9 @@ mod tests { g.targets.NumRenderTargets = 1; g.targets.RTFormats[0] = DXGI_FORMAT_R8G8B8A8_UNORM; let name = super::super::library::name("mesh test", &root_blob, &[&ms, &ps], &g.describe()); - mesh_pipeline(&host.device, &root, None, code(&ms), code(&ps), &g, false, Some(&name)).expect("made"); + mesh_pipeline(&host.device, &root, MeshShaders { amplify: None, ms: code(&ms), ps: code(&ps) }, &g, false, Some(&name)).expect("made"); let loaded = super::super::library::LOADED.load(Ordering::Relaxed); - mesh_pipeline(&host.device, &root, None, code(&ms), code(&ps), &g, false, Some(&name)).expect("made again"); + mesh_pipeline(&host.device, &root, MeshShaders { amplify: None, ms: code(&ms), ps: code(&ps) }, &g, false, Some(&name)).expect("made again"); assert!( super::super::library::LOADED.load(Ordering::Relaxed) > loaded, "the mesh pipeline was compiled again instead of loaded from the library" diff --git a/d3d12/crates/leonida-gpu/src/pipeline/known.rs b/d3d12/crates/leonida-gpu/src/pipeline/known.rs index c5830e0b78..ad1f116c40 100644 --- a/d3d12/crates/leonida-gpu/src/pipeline/known.rs +++ b/d3d12/crates/leonida-gpu/src/pipeline/known.rs @@ -243,7 +243,11 @@ pub fn save_library() { /// right after a precompile (run d287, 2026-12-01). The library is ours: what is stored stays. pub fn store(dir: &Path, which: &[usize], threads: usize, each: impl FnMut(usize, Option<(f64, bool)>) + Send) { let mut places = HashMap::new(); - walk_shaders(dir, |stage, hash, at, len| drop(places.insert(hash, (stage, at, len)))); + // `let _ =` rather than `drop`, as `make` below does: the inserted value is `Copy`, so there + // is nothing for `drop` to run and clippy is right to say so. + walk_shaders(dir, |stage, hash, at, len| { + let _ = places.insert(hash, (stage, at, len)); + }); let wanted: HashSet = which.iter().copied().collect(); let mut entries = HashMap::new(); walk_pipelines(dir, |n, bytes| { @@ -265,8 +269,11 @@ pub fn store(dir: &Path, which: &[usize], threads: usize, each: impl FnMut(usize file.read_exact(&mut bytes).ok()?; Some(bytes) }; - loop { - let Some(&n) = which.get(next.fetch_add(1, std::sync::atomic::Ordering::Relaxed)) else { break }; + // `while let` rather than `loop` + `let ... else { break }`: the number is the + // condition, and clippy is right that the two say the same thing. + while let Some(&n) = + which.get(next.fetch_add(1, std::sync::atomic::Ordering::Relaxed)) + { let Some(entry) = entries.get(&n) else { continue }; tell(n, None); let began = std::time::Instant::now(); diff --git a/d3d12/crates/leonida-hle/src/modules/glyphs/live.rs b/d3d12/crates/leonida-hle/src/modules/glyphs/live.rs index 8028eccfd0..97fd61b0bd 100644 --- a/d3d12/crates/leonida-hle/src/modules/glyphs/live.rs +++ b/d3d12/crates/leonida-hle/src/modules/glyphs/live.rs @@ -118,7 +118,7 @@ pub fn counters(memory: &impl Memory, slot: Slot) -> Option { /// Whether a find's counters hold what the code puts there: whole numbers from 0, below a billion. pub fn plausible(memory: &impl Memory, slot: Slot) -> bool { - let whole = |v: f64| v.is_finite() && v >= 0.0 && v < 1e9 && v.fract() == 0.0; + let whole = |v: f64| v.is_finite() && (0.0..1e9).contains(&v) && v.fract() == 0.0; counters(memory, slot).is_some_and(|c| whole(c.made) && whole(c.shown)) } diff --git a/d3d12/crates/leonida-shader/src/emit/valu_tests.rs b/d3d12/crates/leonida-shader/src/emit/valu_tests.rs index 2143641e01..fa730c8323 100644 --- a/d3d12/crates/leonida-shader/src/emit/valu_tests.rs +++ b/d3d12/crates/leonida-shader/src/emit/valu_tests.rs @@ -1028,6 +1028,10 @@ fn v_cmp_lg_is_false_for_nan() { /// fast math cannot fold its NaN case away: ordered compares are false with a NaN, unordered ones /// true, `o` and `u` say whether there is one (RDNA2 ISA). After voidopcode/vilocity 598050b /// (INFIERNOXIII, GPL-3.0-or-later), its `float_compares_with_nan_on_the_device`. +/// The negations and the `a < b || a > b` in it are the instruction's own semantics, which is why +/// clippy's suggestions would change what this asserts: `!(a >= b)` is true when either operand is +/// NaN and `a != b` is not, and `!(a < b || a > b)` is true for a NaN pair where `a == b` is false. +#[allow(clippy::neg_cmp_op_on_partial_ord, clippy::double_comparisons)] #[test] fn float_compares_with_nan_on_the_device() { super::lower::TEST_NAN_EXACT.set(Some(true));