From 7feda433d018c6db6721f03e227822838f157ce2 Mon Sep 17 00:00:00 2001 From: kirigayakazima <46666711+kirigayakazima@users.noreply.github.com> Date: Tue, 1 Dec 2026 21:01:29 +0800 Subject: [PATCH] d3d12: fix remaining workspace clippy warnings --- d3d12/crates/leonida-gpu/src/pipeline/host.rs | 30 ++++++++++++++----- .../crates/leonida-gpu/src/pipeline/known.rs | 7 +++-- .../leonida-hle/src/modules/glyphs/live.rs | 27 ++++++++++++++++- 3 files changed, 53 insertions(+), 11 deletions(-) diff --git a/d3d12/crates/leonida-gpu/src/pipeline/host.rs b/d3d12/crates/leonida-gpu/src/pipeline/host.rs index 3ab7cbc626..c948ed821b 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, + MeshStages { amplify: None, ms: code(0), ps: code(1) }, + g, + depth_bounds, library.name(&name).as_deref(), ) { Ok(pso) => pso, @@ -935,7 +939,14 @@ 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, + MeshStages { 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)) @@ -1211,16 +1222,21 @@ fn graphics_depth_bounds_pipeline( /// "already exists"). The translation makes triangle mesh shaders only /// (`mesh_prologue` refuses others), and the debug layer wants the two to /// agree (1323). -fn mesh_pipeline( - device: &ID3D12Device, - root: &ID3D12RootSignature, +struct MeshStages { amplify: Option, ms: D3D12_SHADER_BYTECODE, ps: D3D12_SHADER_BYTECODE, +} + +fn mesh_pipeline( + device: &ID3D12Device, + root: &ID3D12RootSignature, + stages: MeshStages, g: &GraphicsState, depth_bounds: bool, name: Option<&str>, ) -> windows::core::Result { + let MeshStages { amplify, ms, ps } = stages; use windows::core::Interface; /// `A`: the amplification stage's subobject, or nothing (`()`, no bytes in the stream). #[repr(C)] @@ -1533,9 +1549,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, MeshStages { 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, MeshStages { 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..03985824d0 100644 --- a/d3d12/crates/leonida-gpu/src/pipeline/known.rs +++ b/d3d12/crates/leonida-gpu/src/pipeline/known.rs @@ -243,7 +243,9 @@ 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)))); + 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 +267,7 @@ 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 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..d2e3d79752 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| (0.0..1e9).contains(&v) && v.fract() == 0.0; counters(memory, slot).is_some_and(|c| whole(c.made) && whole(c.shown)) } @@ -727,6 +727,31 @@ mod tests { assert_eq!(heap.writes.get(), 2, "one write a change"); } + #[test] + fn plausible_checks_nonnegative_whole_counters_below_one_billion() { + let heap = Fake::new(BASE, 1 << 14); + heap.slots(BASE + 0x200, 24, slot_bits(Family::Xbox)); + let slot = scan(&heap, 4096).slots[0]; + let set = |made: f64, shown: f64| { + heap.put(BASE + 0x200 + 72, made.to_bits()); + heap.put(BASE + 0x200 + 96, shown.to_bits()); + }; + + for &(made, shown, want) in &[ + (0.0, 0.0, true), + (-0.0, 999_999_999.0, true), + (1e9, 0.0, false), + (-1.0, 0.0, false), + (0.5, 0.0, false), + (f64::NAN, 0.0, false), + (f64::INFINITY, 0.0, false), + (f64::NEG_INFINITY, 0.0, false), + ] { + set(made, shown); + assert_eq!(plausible(&heap, slot), want, "made={made:?} shown={shown:?}"); + } + } + /// `follow` with the first look due at once. fn follow_from( memory: &Fake,