diff --git a/apps/victory/src/main.rs b/apps/victory/src/main.rs index 1b7ca05..b7ee76f 100644 --- a/apps/victory/src/main.rs +++ b/apps/victory/src/main.rs @@ -192,6 +192,8 @@ struct Cli { command: Command, } +// Parsed once at start: the size of its largest variant does not matter. +#[allow(clippy::large_enum_variant)] #[derive(Subcommand)] enum Command { /// Summarise one PE image: headers, sections, imports, TLS, build id. @@ -575,6 +577,20 @@ fn show_config() -> Result<()> { Ok(()) } +/// Paths given on the command line, or the configured game + test titles. +pub(crate) fn default_paths(paths: Vec) -> Result> { + if !paths.is_empty() { + return Ok(paths); + } + let cfg = victory_core::Config::load()?; + let all: Vec = cfg.game_dir.into_iter().chain(cfg.test_titles).collect(); + anyhow::ensure!( + !all.is_empty(), + "no paths given and none configured (see victory.example.toml)" + ); + Ok(all) +} + #[cfg(test)] mod tests { /// A D3D12Core.dll's VS_FIXEDFILEINFO: signature, structure version, then @@ -611,17 +627,3 @@ mod tests { assert_eq!(super::exported_sdk_version(b"MZ"), None); } } - -/// Paths given on the command line, or the configured game + test titles. -pub(crate) fn default_paths(paths: Vec) -> Result> { - if !paths.is_empty() { - return Ok(paths); - } - let cfg = victory_core::Config::load()?; - let all: Vec = cfg.game_dir.into_iter().chain(cfg.test_titles).collect(); - anyhow::ensure!( - !all.is_empty(), - "no paths given and none configured (see victory.example.toml)" - ); - Ok(all) -} diff --git a/apps/victory/src/play.rs b/apps/victory/src/play.rs index 562d078..7236f10 100644 --- a/apps/victory/src/play.rs +++ b/apps/victory/src/play.rs @@ -730,20 +730,20 @@ fn check_shader_model() -> Result<()> { }; if yes { match fetch_d3d12(&to) { - Ok(()) => match { + Ok(()) => { // This process is yet to load Direct3D 12: it asks for the file now there. crate::match_d3d12_core(); - shader_model() - } { - Some(now) if now >= needed => { - println!("Shader model {}.{} with Microsoft's runtime. Starting the game.", now.0, now.1); - return Ok(()); + match shader_model() { + Some(now) if now >= needed => { + println!("Shader model {}.{} with Microsoft's runtime. Starting the game.", now.0, now.1); + return Ok(()); + } + now => { + let now = now.unwrap_or(found); + println!("With Microsoft's runtime the GPU still runs shader model {}.{}.", now.0, now.1); + } } - now => { - let now = now.unwrap_or(found); - println!("With Microsoft's runtime the GPU still runs shader model {}.{}.", now.0, now.1); - } - }, + } Err(e) => println!("{e:#}"), } } diff --git a/apps/victory/src/warm.rs b/apps/victory/src/warm.rs index 1314dc0..6d3ee9f 100644 --- a/apps/victory/src/warm.rs +++ b/apps/victory/src/warm.rs @@ -105,7 +105,7 @@ pub fn run(jobs: Option, limit: Option, again: bool, used: bool, t state.0.push(ms); state.1 += usize::from(!there); let count = state.0.len(); - if count % 1000 == 0 { + if count.is_multiple_of(1000) { println!("{count} of {}, {:.0} s", all.len(), began.elapsed().as_secs_f64()); } drop(state); diff --git a/crates/victory-formats/src/texture.rs b/crates/victory-formats/src/texture.rs index 474ab84..61aca75 100644 --- a/crates/victory-formats/src/texture.rs +++ b/crates/victory-formats/src/texture.rs @@ -1431,7 +1431,7 @@ mod tests { let needs: Vec = (0..9).map(|mip| l.bytes_from(mip)).collect(); assert!(needs.windows(2).all(|w| w[0] >= w[1]), "{needs:?}"); assert!(needs[3] * 4 < l.size, "{needs:?}"); - let tiled: Vec = (0..l.size).map(|i| (i * 7 >> 3) as u8).collect(); + let tiled: Vec = (0..l.size).map(|i| ((i * 7) >> 3) as u8).collect(); for mip in 1..9 { let m = l.mips[mip as usize]; let pitch = m.width as usize * 8; diff --git a/crates/victory-gpu/src/book.rs b/crates/victory-gpu/src/book.rs index b8b8b4e..b88632c 100644 --- a/crates/victory-gpu/src/book.rs +++ b/crates/victory-gpu/src/book.rs @@ -257,7 +257,11 @@ pub(crate) fn address(texture: &ID3D12Resource) -> Option { /// The address of a texture: the base its descriptor has. fn texture_address(texture: &ID3D12Resource, desc: &D3D12_RESOURCE_DESC) -> Option { - struct Slot(ID3D12DescriptorHeap, usize); + struct Slot { + /// Kept alive: `at` is in it. + _heap: ID3D12DescriptorHeap, + at: usize, + } // SAFETY: a descriptor heap, used under the lock. unsafe impl Send for Slot {} static SLOT: Mutex> = Mutex::new(None); @@ -278,9 +282,9 @@ fn texture_address(texture: &ID3D12Resource, desc: &D3D12_RESOURCE_DESC) -> Opti .ok()?; // SAFETY: a live heap. let at = unsafe { heap.GetCPUDescriptorHandleForHeapStart().ptr }; - *slot = Some(Slot(heap, at)); + *slot = Some(Slot { _heap: heap, at }); } - let at = slot.as_ref()?.1; + let at = slot.as_ref()?.at; let format = viewable(desc.Format.0)?; let mut view = D3D12_SHADER_RESOURCE_VIEW_DESC { Format: DXGI_FORMAT(format), diff --git a/crates/victory-gpu/src/copystat.rs b/crates/victory-gpu/src/copystat.rs index 948da32..44a91db 100644 --- a/crates/victory-gpu/src/copystat.rs +++ b/crates/victory-gpu/src/copystat.rs @@ -1236,7 +1236,7 @@ pub(crate) fn log(frames: f64) { ); tracing::info!( "waits for the write trackers' locks per frame, all threads (number, time): {}", - crate::watch::lock_waits(frames as f64) + crate::watch::lock_waits(frames) ); let [copies, blocks, opened, stores, unknown, full, stayed, copied_same, records] = [0, 1, 2, 3, 4, 5, 6, 7, 8].map(|n| crate::titlewrite::DONE[n].load(std::sync::atomic::Ordering::Relaxed)); diff --git a/crates/victory-gpu/src/descriptor/host.rs b/crates/victory-gpu/src/descriptor/host.rs index 475c564..d331dd4 100644 --- a/crates/victory-gpu/src/descriptor/host.rs +++ b/crates/victory-gpu/src/descriptor/host.rs @@ -1342,8 +1342,8 @@ impl Due { fn ordered(self, max: usize) -> (Vec<(u32, u64)>, Vec>) { let Due { mut again, mut fresh } = self; // By the number of the write, counted over the run. - again.sort_unstable_by(|a, b| b.2.cmp(&a.2)); - fresh.sort_unstable_by(|a, b| b.2.cmp(&a.2)); + again.sort_unstable_by_key(|e| std::cmp::Reverse(e.2)); + fresh.sort_unstable_by_key(|e| std::cmp::Reverse(e.2)); let mut order: Vec<(u32, u64)> = again.iter().map(|&(_, index, write, _)| (index, write)).collect(); let mut known: Vec> = again.iter().map(|a| a.3).collect(); let (mut new, mut old) = (0, fresh.len()); diff --git a/crates/victory-gpu/src/draw.rs b/crates/victory-gpu/src/draw.rs index 6f2e4fb..e3a7be8 100644 --- a/crates/victory-gpu/src/draw.rs +++ b/crates/victory-gpu/src/draw.rs @@ -1979,7 +1979,7 @@ impl State { } else { crate::memory::Use::Reads }; - let Some(ready) = self.memory_ready(list, &t, compute, use_) else { + let Some(ready) = self.memory_ready(list, t, compute, use_) else { once!("a shader that reads title memory by address without a view heap to hold its views: the draw is dropped"); return false; }; @@ -4410,7 +4410,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) diff --git a/crates/victory-gpu/src/host.rs b/crates/victory-gpu/src/host.rs index 90c3195..7b3dbc6 100644 --- a/crates/victory-gpu/src/host.rs +++ b/crates/victory-gpu/src/host.rs @@ -3095,6 +3095,9 @@ struct Flight { } /// One thing in the line of what waits for the card, in order. +// A flight is far larger than the other variants; boxing it would add an +// allocation per flight on the submission path, so it stays inline. +#[allow(clippy::large_enum_variant)] enum Late { Run(Flight), /// A bottom-of-pipe write of the flight before it: address, what, bytes. @@ -3321,7 +3324,7 @@ fn blame_stale(stale: &[(std::sync::Arc, usize, usize)]) /// title memory read, took `us`. #[cfg(feature = "diagnostics")] fn blamed(why: usize, us: u64) { - let (named, refused) = std::mem::replace(&mut *BLAMED.lock().unwrap_or_else(|e| e.into_inner()), (None, "")); + let (named, refused) = std::mem::take(&mut *BLAMED.lock().unwrap_or_else(|e| e.into_inner())); let (key, at) = match (why, named) { (WHY_READ | WHY_STALE, Some(named)) => named, (WHY_READ, None) => (("a host copy of what a copy done on the card wrote", refused, 0, 0, 0), 0), @@ -4193,6 +4196,7 @@ fn late_line(frames: f64) { pub(crate) mod aside; pub(crate) mod awake; mod card_steps; +#[cfg(feature = "diagnostics")] pub(crate) mod indirects; mod font; mod menu; @@ -8638,7 +8642,9 @@ enum Touch { Refresh(usize, usize, usize), /// The copy is given to shaders. Write(usize), - /// Title memory is written. + /// Title memory is written. The callers stop their walk there instead + /// (`refresh_ahead`); the tests of [`written_spans`] use it. + #[cfg_attr(not(test), allow(dead_code))] Title, Nothing, /// Another part of the submission begins. diff --git a/crates/victory-gpu/src/host/send.rs b/crates/victory-gpu/src/host/send.rs index a397db8..68e9967 100644 --- a/crates/victory-gpu/src/host/send.rs +++ b/crates/victory-gpu/src/host/send.rs @@ -32,7 +32,7 @@ const SHORT: usize = 256; /// Whether a run of `len` bytes at offset `at` of a copy goes as pairs. fn short(at: usize, len: usize) -> bool { - len <= SHORT && at % 4 == 0 && len % 4 == 0 + len <= SHORT && at.is_multiple_of(4) && len.is_multiple_of(4) } /// Whether a run of `len` bytes at offset `at` of a copy in the card's memory diff --git a/crates/victory-gpu/src/indirect.rs b/crates/victory-gpu/src/indirect.rs index 4670740..2f1beef 100644 --- a/crates/victory-gpu/src/indirect.rs +++ b/crates/victory-gpu/src/indirect.rs @@ -305,8 +305,6 @@ fn rest() -> u32 { /// The clamp compiled from `source` (ours, or in the benchmark the one it /// replaced). fn make_from(device: &ID3D12Device, source: &str) -> windows::core::Result { - #[cfg(feature = "diagnostics")] - let batched = source == batch::SOURCE; let source = &format!("#define WIDEST {}u\n#define REST {}\n{source}", widest(amd(device)), rest()); let mut code: Option = None; let mut errors: Option = None; @@ -2697,7 +2695,10 @@ void main(uint3 g : SV_GroupID, uint i : SV_GroupIndex) { } sig.unwrap() }; - // Three records of 65,535 x 16 groups: about half the budget each. + // Two records of 65,535 x 16 groups (64 threads each, 2^26 - 2,048 + // threads), then one of 32 groups (2,048 threads): together exactly + // the budget, so the small record after them does not fit whether + // or not a record that does not fit takes the rest (`rest`). let Some((big, big_ptr)) = host.shared_buffer(3 * u64::from(STRIDE)) else { return; }; @@ -2710,7 +2711,7 @@ void main(uint3 g : SV_GroupID, uint i : SV_GroupIndex) { // SAFETY: mapped buffers of these sizes; nothing runs yet. unsafe { for i in 0..3 { - let words = [65535u32, 16, 1]; + let words = if i < 2 { [65535u32, 16, 1] } else { [32, 1, 1] }; std::ptr::copy_nonoverlapping( words.as_ptr().cast::(), big_ptr.add(i * STRIDE as usize), @@ -3193,7 +3194,20 @@ void main(uint3 group : SV_GroupID, uint3 thread : SV_DispatchThreadID) { }; assert_eq!(out.iter().filter(|&&v| v == 1 << 22).count(), filled, "{times} times {records}: {out:?}"); assert!(out.iter().all(|&v| v == 0 || v == 1 << 22)); - assert_eq!(spent, BUDGET.min((1 << 26) * times * records as u32)); + // Each record's job charges 2^26 for every execution, in order: + // one that does not fit takes the rest with `REST`, else nothing. + let rest = super::rest() != 0; + let expected = (0..records).fold(0u32, |at, _| { + let cost = (1u32 << 26) * times; + if BUDGET - at >= cost { + at + cost + } else if rest { + BUDGET + } else { + at + } + }); + assert_eq!(spent, expected, "{times} times {records}"); } } @@ -3530,7 +3544,6 @@ void work() { heap_pairs: [[Option; 2]; 2], tables: [D3D12_GPU_DESCRIPTOR_HANDLE; 2], targets: [D3D12_CPU_DESCRIPTOR_HANDLE; 2], - depth_written: D3D12_CPU_DESCRIPTOR_HANDLE, depth_tested: D3D12_CPU_DESCRIPTOR_HANDLE, stamps: ID3D12QueryHeap, back: ID3D12Resource, @@ -3877,7 +3890,6 @@ void work() { heap_pairs, tables, targets, - depth_written, depth_tested, stamps, back, diff --git a/crates/victory-gpu/src/land.rs b/crates/victory-gpu/src/land.rs index 9b23018..eb6200d 100644 --- a/crates/victory-gpu/src/land.rs +++ b/crates/victory-gpu/src/land.rs @@ -572,6 +572,7 @@ pub(crate) unsafe fn piece( /// /// # Safety /// [`piece`]'s. +#[allow(clippy::too_many_arguments)] unsafe fn piece_at( title: usize, now: *const u8, diff --git a/crates/victory-gpu/src/land/tests.rs b/crates/victory-gpu/src/land/tests.rs index 7e59e9d..dc93e36 100644 --- a/crates/victory-gpu/src/land/tests.rs +++ b/crates/victory-gpu/src/land/tests.rs @@ -293,7 +293,7 @@ fn landings_beside_the_title_and_its_refreshes_lose_nothing() { while !stop.load(Ordering::Relaxed) { // Its own dwords, in every other block (in the rest // only landings change anything). - for i in (w..LEN / 4).step_by(4 * 97).filter(|i| i * 4 / BLOCK % 2 == 0) { + for i in (w..LEN / 4).step_by(4 * 97).filter(|i| (i * 4 / BLOCK).is_multiple_of(2)) { assert_eq!(dword(i).swap(value, Ordering::Relaxed), value - 1, "dword {i}: undone"); } value += 1; @@ -343,7 +343,7 @@ fn landings_beside_the_title_and_its_refreshes_lose_nothing() { stop.store(true, Ordering::Relaxed); for (w, writer) in writers.into_iter().enumerate() { let last = writer.join().expect("nothing undone"); - for i in (w..LEN / 4).step_by(4 * 97).filter(|i| i * 4 / BLOCK % 2 == 0) { + for i in (w..LEN / 4).step_by(4 * 97).filter(|i| (i * 4 / BLOCK).is_multiple_of(2)) { assert_eq!(dword(i).load(Ordering::Relaxed), last); } } diff --git a/crates/victory-gpu/src/list/thin.rs b/crates/victory-gpu/src/list/thin.rs index e2371c3..eb7e115 100644 --- a/crates/victory-gpu/src/list/thin.rs +++ b/crates/victory-gpu/src/list/thin.rs @@ -970,7 +970,7 @@ mod tests { fn a_target_is_the_one_at_the_call() { let mut slot = [0x5256_5476u64, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]; let kept = record(slot.as_ptr() as u64); - slot[1] = 99; + std::hint::black_box(&mut slot)[1] = 99; assert_eq!(kept[1], 2); assert_eq!(record(0), [0; RECORD]); } diff --git a/crates/victory-gpu/src/pipeline/known.rs b/crates/victory-gpu/src/pipeline/known.rs index 51ab642..ea478bb 100644 --- a/crates/victory-gpu/src/pipeline/known.rs +++ b/crates/victory-gpu/src/pipeline/known.rs @@ -61,7 +61,9 @@ fn book() -> Option<&'static Mutex> { let mut keys = HashSet::new(); let mut shaders = HashSet::new(); let ends = [ - walk_shaders(&dir, |_, hash, _, _| drop(shaders.insert(hash))), + walk_shaders(&dir, |_, hash, _, _| { + shaders.insert(hash); + }), walk_pipelines(&dir, |_, bytes| { keys.extend(bytes.first_chunk::<16>().copied()); }), @@ -234,7 +236,9 @@ pub fn keep_library() { /// there is one. pub fn make(dir: &Path, which: &[usize], mut each: impl FnMut(usize, Option<(f64, bool)>)) { 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| { + places.insert(hash, (stage, at, len)); + }); let Ok(mut file) = std::fs::File::open(dir.join(SHADERS)) else { return }; let wanted: HashSet = which.iter().copied().collect(); let mut entries = HashMap::new(); diff --git a/crates/victory-gpu/src/port.rs b/crates/victory-gpu/src/port.rs index 22edcf3..776bb89 100644 --- a/crates/victory-gpu/src/port.rs +++ b/crates/victory-gpu/src/port.rs @@ -326,7 +326,7 @@ mod tests { let low = |at: u64, len: u64| at.checked_add(len).is_some_and(|end| end <= LOW && len > 0); assert!(low(0x34e1_0000, 0xae0_0000)); assert!(!low(0xffff_0000, 0x2_0000)); - assert!(!low(0xe1c80_0000, 0x1000)); + assert!(!low(0x000e_1c80_0000, 0x1000)); assert!(!low(u64::MAX, 2)); } diff --git a/crates/victory-gpu/src/queue.rs b/crates/victory-gpu/src/queue.rs index 5c5de89..524c3dd 100644 --- a/crates/victory-gpu/src/queue.rs +++ b/crates/victory-gpu/src/queue.rs @@ -1377,7 +1377,7 @@ mod tests { #[test] fn a_pair_of_timestamps_shows_the_load_it_is_given() { - let (start, end) = (0xd0419_6698, 0xd0419_6690); + let (start, end) = (0x000d_0419_6698, 0x000d_0419_6690); assert_eq!(as_loaded(5_000_000, end, 4_000_000) - as_loaded(5_000_000, start, 4_000_000), 4_000_000); assert_eq!(as_loaded(5_000_000, start, 0), 5_000_000); assert_eq!(as_loaded(5, start, 100), 1); diff --git a/crates/victory-gpu/src/replay/play.rs b/crates/victory-gpu/src/replay/play.rs index 0f93400..9f3efd5 100644 --- a/crates/victory-gpu/src/replay/play.rs +++ b/crates/victory-gpu/src/replay/play.rs @@ -3154,7 +3154,7 @@ impl Player { continue; } for l in all { - self.worker.queue.ExecuteCommandLists(&[l.clone()]); + self.worker.queue.ExecuteCommandLists(std::slice::from_ref(l)); self.worker.idle()?; } } diff --git a/crates/victory-gpu/src/replay/play/diverge.rs b/crates/victory-gpu/src/replay/play/diverge.rs index 8655b1b..2bc864c 100644 --- a/crates/victory-gpu/src/replay/play/diverge.rs +++ b/crates/victory-gpu/src/replay/play/diverge.rs @@ -1212,7 +1212,7 @@ impl Player { word(if s.kind == slot::SRV { 4 } else { 2 }), word(if s.kind == slot::SRV { 6 } else { 4 }), word(if s.kind == slot::SRV { 7 } else { 5 }), - word(if s.kind == slot::SRV { 8 } else { 8 }), + word(8), ), } } diff --git a/crates/victory-gpu/src/replay/play/merge.rs b/crates/victory-gpu/src/replay/play/merge.rs index daddcd0..f30d73f 100644 --- a/crates/victory-gpu/src/replay/play/merge.rs +++ b/crates/victory-gpu/src/replay/play/merge.rs @@ -277,7 +277,7 @@ impl Player { .map(|i| (all[i * 3 + 2], i)) .filter(|w| w.0 > 0) .collect(); - worst.sort_by(|a, b| b.0.cmp(&a.0)); + worst.sort_by_key(|w| std::cmp::Reverse(w.0)); for (n, i) in worst.into_iter().take(8) { let (id, at, len) = calls[i]; out.push(format!( diff --git a/crates/victory-gpu/src/replay/play/pixel.rs b/crates/victory-gpu/src/replay/play/pixel.rs index e79fce9..03172f2 100644 --- a/crates/victory-gpu/src/replay/play/pixel.rs +++ b/crates/victory-gpu/src/replay/play/pixel.rs @@ -488,6 +488,7 @@ impl Player { /// The commands that copy the texels of `spots` to [`PROBE`] from `first` /// on; `copied`: a copy to them went before. + #[allow(clippy::too_many_arguments)] fn take( &self, spots: &[Spot], diff --git a/crates/victory-gpu/src/resource.rs b/crates/victory-gpu/src/resource.rs index f5c893d..597ede5 100644 --- a/crates/victory-gpu/src/resource.rs +++ b/crates/victory-gpu/src/resource.rs @@ -101,7 +101,7 @@ pub(crate) struct ResourceDesc { #[cfg(windows)] impl ResourceDesc { /// The texture of this one's levels from `base` on. - fn from_level(&self, base: u32) -> ResourceDesc { + fn levels_from(&self, base: u32) -> ResourceDesc { let mut d = *self; if base > 0 { d.width = (d.width >> base).max(1); @@ -1765,7 +1765,7 @@ fn hosted(this: This, make: bool) -> Option { } let texture = match texture { Some(texture) => Some(texture), - None => host_texture(&r.desc.from_level(base), r.host.state, clear), + None => host_texture(&r.desc.levels_from(base), r.host.state, clear), }; let Some(texture) = texture else { r.host.refused.store(true, Relaxed); @@ -3076,7 +3076,7 @@ fn host_texture_as( } }; if let Err(e) = &made { - crate::residency::allocation_error(&e); + crate::residency::allocation_error(e); tracing::warn!(error = %e, desc = ?d, reserved, "no host texture"); } if !reserved diff --git a/crates/victory-gpu/src/shadow.rs b/crates/victory-gpu/src/shadow.rs index 7c9b773..2ac83e4 100644 --- a/crates/victory-gpu/src/shadow.rs +++ b/crates/victory-gpu/src/shadow.rs @@ -2542,7 +2542,7 @@ fn dword_runs(at: usize, title: &[u8], merged: &[u8], gap: usize) -> Vec<(usize, /// 12 MB this way and finds 80,000 runs. fn word_runs(at: usize, title: &[u8], held: &[u8]) -> Vec<(usize, usize)> { #[cfg(target_arch = "x86_64")] - if at % 4 == 0 && title.len() % 4 == 0 && title.len() == held.len() && std::arch::is_x86_feature_detected!("avx2") { + if at.is_multiple_of(4) && title.len().is_multiple_of(4) && title.len() == held.len() && std::arch::is_x86_feature_detected!("avx2") { // SAFETY: the processor has AVX2, and the lengths are the same. return unsafe { word_runs_avx2(title, held) }; } @@ -5192,7 +5192,7 @@ mod land_tests { }); let mut now = vec![0u8; LEN]; for round in 1..200u32 { - for block in (0..BLOCKS).filter(|b| (*b as u32 * 5 + round) % 3 != 0) { + for block in (0..BLOCKS).filter(|b| !(*b as u32 * 5 + round).is_multiple_of(3)) { for i in (block * PIECE / 4 + 3..(block + 1) * PIECE / 4).step_by(4) { now[i * 4..i * 4 + 4].copy_from_slice(&(round << 20 | i as u32).to_le_bytes()); } diff --git a/crates/victory-gpu/src/streamline.rs b/crates/victory-gpu/src/streamline.rs index 5132426..d6c743f 100644 --- a/crates/victory-gpu/src/streamline.rs +++ b/crates/victory-gpu/src/streamline.rs @@ -1802,7 +1802,7 @@ pub(crate) fn present_begins(frame: u64, planes: Planes<'_>) -> Option 0 { static PRESENTS: AtomicU32 = AtomicU32::new(0); let n = PRESENTS.fetch_add(1, Relaxed); - if n % every == 0 { + if n.is_multiple_of(every) { set_framegen([2, 4, 0, 6][(n / every % 4) as usize]); } } diff --git a/crates/victory-gpu/src/texture.rs b/crates/victory-gpu/src/texture.rs index 17955a1..301b045 100644 --- a/crates/victory-gpu/src/texture.rs +++ b/crates/victory-gpu/src/texture.rs @@ -2570,7 +2570,7 @@ mod allocation_costs { seen.push(digest(&bytes)); } } - let text: Vec = (0..400u32).map(|i| (i * 37 >> 2) as u8).collect(); + let text: Vec = (0..400u32).map(|i| ((i * 37) >> 2) as u8).collect(); for at in 0..399 { let mut bytes = text.clone(); bytes.swap(at, at + 1); diff --git a/crates/victory-gpu/src/titlewrite/decode.rs b/crates/victory-gpu/src/titlewrite/decode.rs index 11343c9..c6f984d 100644 --- a/crates/victory-gpu/src/titlewrite/decode.rs +++ b/crates/victory-gpu/src/titlewrite/decode.rs @@ -604,7 +604,7 @@ mod tests { f.extend([0x9c, 0x41, 0x5a, 0x48, 0x8b, 0x4c, 0x24, 0x28]); f.extend([0x4c, 0x89, 0x11, 0x48, 0x89, 0x51, 0x08, 0x48, 0x89, 0x41, 0x10, 0xc3]); type F = unsafe extern "system" fn(*mut u64, u64, u64, u64, *mut [u64; 3]); - let (there, operand, compared) = (spread(1), spread(2), if seed % 3 == 0 { spread(1) } else { spread(3) }); + let (there, operand, compared) = (spread(1), spread(2), if seed.is_multiple_of(3) { spread(1) } else { spread(3) }); let flags = 0x202 | (spread(4) & 0x8d5) as u32; let (mut memory, mut out) = (there, [0; 3]); // SAFETY: the code above, which keeps to the calling convention. diff --git a/crates/victory-gpu/src/watch.rs b/crates/victory-gpu/src/watch.rs index 151de09..1e63f34 100644 --- a/crates/victory-gpu/src/watch.rs +++ b/crates/victory-gpu/src/watch.rs @@ -476,7 +476,7 @@ fn ask_early(every: std::time::Duration) { idle = 0; } round += 1; - if round % 64 == 0 { + if round.is_multiple_of(64) { hot.retain(|_, n| { *n /= 2; *n > 0 diff --git a/crates/victory-hle/src/modules/dsp/convolve.rs b/crates/victory-hle/src/modules/dsp/convolve.rs index 88311f4..ced4e8c 100644 --- a/crates/victory-hle/src/modules/dsp/convolve.rs +++ b/crates/victory-hle/src/modules/dsp/convolve.rs @@ -91,7 +91,7 @@ pub(super) struct Convolver { impl Convolver { /// `None` when the response is not in the layout described above. pub(super) fn new(ir: &[f32]) -> Option { - if ir.is_empty() || ir.len() % N != 0 { + if ir.is_empty() || !ir.len().is_multiple_of(N) { return None; } let mut blocks = ir.len() / N; diff --git a/crates/victory-hle/src/modules/dstorage.rs b/crates/victory-hle/src/modules/dstorage.rs index 8659474..b86fcde 100644 --- a/crates/victory-hle/src/modules/dstorage.rs +++ b/crates/victory-hle/src/modules/dstorage.rs @@ -439,7 +439,7 @@ fn read_direct(file: &std::fs::File, out: &mut [u8], offset: u64) -> std::io::Re /// Read at a time. const MOST: usize = 1 << 20; let sector = SECTOR as u64; - if offset % sector == 0 && out.len() % SECTOR == 0 && out.as_ptr() as usize % SECTOR == 0 { + if offset.is_multiple_of(sector) && out.len().is_multiple_of(SECTOR) && (out.as_ptr() as usize).is_multiple_of(SECTOR) { return read_overlapped(file, out, offset); } thread_local! { @@ -2168,7 +2168,7 @@ mod tests { for round in 0..2 { for mode in [Io::One, Io::Handles, Io::Overlapped, Io::Direct] { let file = Files::open_for_test(&path, mode); - let at: Vec = (0..READS).map(|_| random() % (len - SIZE as u64) & !15).collect(); + let at: Vec = (0..READS).map(|_| (random() % (len - SIZE as u64)) & !15).collect(); for pass in ["cold", "again"] { let next = std::sync::atomic::AtomicUsize::new(0); let busy = AtomicU64::new(0); diff --git a/crates/victory-hle/src/modules/xmem.rs b/crates/victory-hle/src/modules/xmem.rs index 99f728d..6c4f0f6 100644 --- a/crates/victory-hle/src/modules/xmem.rs +++ b/crates/victory-hle/src/modules/xmem.rs @@ -3155,7 +3155,7 @@ mod tests { assert!(lazy(c)); assert_eq!(map_pages(c, 3, std::ptr::null(), true), c); assert!(!lazy(c)); - assert!(physical().views.get(&(c as usize)).is_none()); + assert!(!physical().views.contains_key(&(c as usize))); assert_eq!(host(c), MEM_RESERVE); assert_eq!(map_pages(c, 3, pages.as_ptr(), false), c); // SAFETY: mapped. @@ -3166,7 +3166,7 @@ mod tests { assert_eq!(map_pages(d, 3, pages.as_ptr(), true), d); assert_eq!(map_pages(at(d, 1), 1, std::ptr::null(), true), at(d, 1)); assert!(lazy(d) && lazy(at(d, 2))); - assert!(physical().views.get(&(at(d, 1) as usize)).is_none()); + assert!(!physical().views.contains_key(&(at(d, 1) as usize))); assert!(materialize(at(d, 2) as usize, 1)); assert!(!lazy(at(d, 2)) && lazy(d)); // SAFETY: mapped now. @@ -3259,7 +3259,7 @@ mod tests { assert_eq!(read(heap, 1), ((true, 1), vec![2])); // Unmapped: gone, with no view of the host's ever there. assert!(alias_as((heap + PAGE) as u64, 0, PAGE as u64, false, true)); - assert!(!lazy(heap + PAGE) && physical().views.get(&(heap + PAGE)).is_none()); + assert!(!lazy(heap + PAGE) && !physical().views.contains_key(&(heap + PAGE))); assert_eq!(soft_runs(heap, 4 * PAGE), [(heap, PAGE), (heap + 2 * PAGE, PAGE)]); assert_eq!(read(heap + PAGE, 2 * PAGE).0, (false, PAGE)); // The CPU touches one: the handler maps it with its page's bytes, diff --git a/crates/victory-loader/src/write_sites.rs b/crates/victory-loader/src/write_sites.rs index f1167e3..b7566a3 100644 --- a/crates/victory-loader/src/write_sites.rs +++ b/crates/victory-loader/src/write_sites.rs @@ -346,7 +346,7 @@ mod tests { let list = format!("other.dll {:x}\nT.dll 0x{at:x}\nt.dll {at:x}\nt.dll 5\nt.dll\n", at); assert_eq!(apply("t.dll", second, 0x1000, &list), 1); assert_eq!(std::ptr::read((second + at) as *const u8), 0xe9); - let (plain, changed): (F, F) = (std::mem::transmute(place), std::mem::transmute(second)); + let (plain, changed) = (std::mem::transmute::(place), std::mem::transmute::(second)); for was in 0..=255u8 { let mut bytes = [[0u8; 0x40]; 2]; bytes[0][0x31] = was; @@ -422,7 +422,7 @@ mod tests { if size == 0 { continue; } - let (plain, changed): (F, F) = (std::mem::transmute(place), std::mem::transmute(second)); + let (plain, changed) = (std::mem::transmute::(place), std::mem::transmute::(second)); let data = VirtualAlloc(std::ptr::null(), 4096, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE) as *mut u8; for seed in 0..200u64 { let value = seed.wrapping_mul(0x9e37_79b9_7f4a_7c15);