diff --git a/TODO.md b/TODO.md index 17ad16274..1cb51d247 100644 --- a/TODO.md +++ b/TODO.md @@ -73,7 +73,6 @@ The goal: a console-like experience on PC. The game starts straight into play, h | ID | Task | Where | Needs | |----|------|-------|-------| -| C-1 | CI is red on clippy: `resource.rs:2553` (`placed_filler_twins` unused), `indirect.rs:2453` (`depth_written` never read), `fpsbox.rs:174` (`contains_key` then `insert`), `draw.rs:2577` (`sort_unstable_by_key`), `queue.rs:672`, `shadow.rs:2803` and `shadow.rs:3325` (`is_multiple_of`). All in `leonida-gpu`, all inherited from victory-gta6. | `leonida-gpu` | - | | C-2 | Failing test `indirect::tests::warp_budget_saturates_without_wraparound_and_preserves_draw_fields`, inherited from victory-gta6. Upstream VIctory `4ab20fc` ("the indirect budget is charged in record order and no longer wraps") may fix it; not checked. | `leonida-gpu` | - | | C-3 | `cargo fmt --check` reports about 1,420 differences. Run `cargo fmt` once, in a pull request of its own, at a moment when no other pull request is open (it touches almost every file), then add the check to CI. | all | - | | C-4 | 163 `shortcut:` markers where the code approximates the console (79 in `leonida-gpu`, 55 in `leonida-shader`, 23 in `leonida-hle`, 4 in `leonida-formats`, 2 in `leonida-loader`). Replace them with the console's real behaviour, one per pull request. | all | game | diff --git a/crates/leonida-gpu/src/draw.rs b/crates/leonida-gpu/src/draw.rs index ecc892098..f4499107b 100644 --- a/crates/leonida-gpu/src/draw.rs +++ b/crates/leonida-gpu/src/draw.rs @@ -2574,7 +2574,7 @@ impl State { let draws: u32 = census.1.values().sum(); if draws > 0 { let mut rects: Vec<([i32; 4], u32)> = census.1.iter().map(|(r, n)| (*r, *n)).collect(); - rects.sort_unstable_by(|a, b| b.1.cmp(&a.1)); + rects.sort_unstable_by_key(|r| std::cmp::Reverse(r.1)); let scissors: Vec = rects .iter() .take(5) @@ -3321,7 +3321,7 @@ impl State { // the record drawn before it. if (6..=8).contains(&why_not) { static N: std::sync::atomic::AtomicU64 = std::sync::atomic::AtomicU64::new(0); - if N.fetch_add(1, std::sync::atomic::Ordering::Relaxed) % 256 == 0 { + if N.fetch_add(1, std::sync::atomic::Ordering::Relaxed) .is_multiple_of(256) { let (last_copy, last_offset) = self.last_indirect; tracing::info!( "a window miss (one in 256): cause {why_not}, kind {kind}, stride {stride}, buffer {} offset {offset:#x} ({} left); the command before it on the list: buffer {last_copy} offset \ diff --git a/crates/leonida-gpu/src/fpsbox.rs b/crates/leonida-gpu/src/fpsbox.rs index cc2e00b47..4298055bf 100644 --- a/crates/leonida-gpu/src/fpsbox.rs +++ b/crates/leonida-gpu/src/fpsbox.rs @@ -171,7 +171,7 @@ pub(crate) fn draw(host: &crate::host::Host, list: &ID3D12GraphicsCommandList, b made.clear(); } let key = (tenths, format.0, scale); - if !made.contains_key(&key) { + if let std::collections::hash_map::Entry::Vacant(e) = made.entry(key) { let (w, h, lit) = bitmap(&text(tenths), scale); let pitch = (w as usize * bytes).next_multiple_of(D3D12_TEXTURE_DATA_PITCH_ALIGNMENT as usize); let Some((buffer, data)) = host.shared_buffer((pitch * h as usize) as u64) else { @@ -185,7 +185,7 @@ pub(crate) fn draw(host: &crate::host::Host, list: &ID3D12GraphicsCommandList, b pixel(format, lit[y * w as usize + x], &mut out[at..at + bytes]); } } - made.insert(key, Made { buffer, width: w, height: h, pitch: pitch as u32 }); + e.insert(Made { buffer, width: w, height: h, pitch: pitch as u32 }); } let Some(m) = made.get(&key) else { return; diff --git a/crates/leonida-gpu/src/indirect.rs b/crates/leonida-gpu/src/indirect.rs index a3235334a..20b14f63c 100644 --- a/crates/leonida-gpu/src/indirect.rs +++ b/crates/leonida-gpu/src/indirect.rs @@ -2450,6 +2450,7 @@ void work() { heap_pairs: [[Option; 2]; 2], tables: [D3D12_GPU_DESCRIPTOR_HANDLE; 2], targets: [D3D12_CPU_DESCRIPTOR_HANDLE; 2], + #[allow(dead_code)] // TODO C-2: pending upstream VIctory 4ab20fc depth_written: D3D12_CPU_DESCRIPTOR_HANDLE, depth_tested: D3D12_CPU_DESCRIPTOR_HANDLE, stamps: ID3D12QueryHeap, diff --git a/crates/leonida-gpu/src/queue.rs b/crates/leonida-gpu/src/queue.rs index 86411ed00..fd19efb76 100644 --- a/crates/leonida-gpu/src/queue.rs +++ b/crates/leonida-gpu/src/queue.rs @@ -687,7 +687,7 @@ fn send_joined(joined: &mut Joined) { let sent = JOINED[1].fetch_add(1, Ordering::Relaxed) + 1; JOINED[2].fetch_add(order.len() as u64, Ordering::Relaxed); JOINED[3].fetch_add(joined.signals.len() as u64, Ordering::Relaxed); - if sent % 2048 == 0 { + if sent.is_multiple_of(2048) { let n: Vec = JOINED.iter().map(|n| n.swap(0, Ordering::Relaxed)).collect(); tracing::info!( "parts joined (LEONIDA_JOIN_PARTS=1): {} parts went to the host in {} submissions ({:.1} parts, {:.1} lists each), {} signals delivered behind them, {} waits passed for a write of a part not sent yet", diff --git a/crates/leonida-gpu/src/resource.rs b/crates/leonida-gpu/src/resource.rs index bebace985..7c04ed3d0 100644 --- a/crates/leonida-gpu/src/resource.rs +++ b/crates/leonida-gpu/src/resource.rs @@ -2553,10 +2553,12 @@ static PLACED_TWINS: std::sync::atomic::AtomicU64 = std::sync::atomic::AtomicU64 /// See [`PLACED_TWINS`]. #[cfg(windows)] +#[allow(dead_code)] // read by the copystat memory log (diagnostics builds) pub(crate) fn placed_filler_twins() -> u64 { PLACED_TWINS.load(std::sync::atomic::Ordering::Relaxed) } + /// Width, height and format of texture `this` (`None` for a buffer), for /// `crate::texback`'s kinds. #[cfg(windows)] diff --git a/crates/leonida-gpu/src/shadow.rs b/crates/leonida-gpu/src/shadow.rs index 05e8ff837..d22904001 100644 --- a/crates/leonida-gpu/src/shadow.rs +++ b/crates/leonida-gpu/src/shadow.rs @@ -2935,7 +2935,7 @@ impl Shadow { } OWN_WRITES[1].fetch_add(bytes.len() as u64, Ordering::Relaxed); let n = OWN_WRITES[0].fetch_add(1, Ordering::Relaxed) + 1; - if n % 16384 == 0 { + if n.is_multiple_of(16384) { tracing::info!( "what shaders wrote, stored through views of our own (LEONIDA_BACK_OWN_VIEW=1), since the start: {n} stretches {} MB, {} pages noted current for the copy that wrote them (not copied in again), {} stretches written the old way; with LEONIDA_BACK_OWN_CHECK=1: {} stores the title's address did not show, {} pages noted current whose CPU side differs from title memory, {} of those with the guard clean", OWN_WRITES[1].load(Ordering::Relaxed) >> 20, @@ -3457,7 +3457,7 @@ impl Shadow { COPY_CHANGED[1].fetch_add(sent as u64, Ordering::Relaxed); COPY_CHANGED[2].fetch_add(stretches.len() as u64, Ordering::Relaxed); let calls = COPY_CHANGED[3].fetch_add(1, Ordering::Relaxed) + 1; - if calls % 65536 == 0 { + if calls.is_multiple_of(65536) { tracing::info!( "copies in the card's memory, refreshed by what differs (LEONIDA_COPY_CHANGED=1), since the start: {calls} refreshes read {} MB of title memory the title had written to; {} MB of it differed from the copy and went on to the card, in {} stretches", COPY_CHANGED[0].load(Ordering::Relaxed) >> 20, diff --git a/crates/leonida-gpu/src/watch.rs b/crates/leonida-gpu/src/watch.rs index 79c449597..d4f4e4216 100644 --- a/crates/leonida-gpu/src/watch.rs +++ b/crates/leonida-gpu/src/watch.rs @@ -478,7 +478,7 @@ pub(crate) fn writes(start: usize, end: usize, guarded: bool) -> Option<(u64, Ve fn failed_asking(start: usize, end: usize) { use windows_sys::Win32::System::Memory::{MEMORY_BASIC_INFORMATION, VirtualQuery}; static N: std::sync::atomic::AtomicU64 = std::sync::atomic::AtomicU64::new(0); - if N.fetch_add(1, std::sync::atomic::Ordering::Relaxed) % 2048 != 0 { + if !N.fetch_add(1, std::sync::atomic::Ordering::Relaxed).is_multiple_of(2048) { return; } // SAFETY: plain data filled in by the query. @@ -869,7 +869,7 @@ fn protect_here(g: &mut Guards, from: usize, to: usize) { #[cfg(feature = "diagnostics")] { static N: std::sync::atomic::AtomicU64 = std::sync::atomic::AtomicU64::new(0); - if N.fetch_add(1, std::sync::atomic::Ordering::Relaxed) % 1024 == 0 { + if N.fetch_add(1, std::sync::atomic::Ordering::Relaxed) .is_multiple_of(1024) { tracing::info!("a block of title memory could not be made read-only (one in 1024): {:#x}: {error}", block * BLOCK); } }