From 2b9c4bf8f05948051346101ed89b370bbe448ffb Mon Sep 17 00:00:00 2001 From: bobcatchris <83428450+bobcatchris@users.noreply.github.com> Date: Mon, 30 Nov 2026 22:17:50 -0600 Subject: [PATCH 1/2] d3d12: rate-limit port descriptors warnings over the whole run missed() chose its warning lines with n < 20 || n.is_power_of_two(), where n came from CHECKED[1]. The per-frame line() swaps that counter to zero, so the first twenty warnings repeat every reporting period: the 48-minute RX 7900 XTX log has 2,280 of them, written synchronously through the launcher's PowerShell Tee-Object. Give the warning a counter of its own that is never reset, so a run says the first twenty and then the powers of two (about 36 lines in total) instead of repeating. Nothing about marking, the fallback or the views changes; the frame line's counts and the writer census are untouched. AI-assisted: yes --- .../leonida-gpu/src/port_descriptors.rs | 27 +++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/d3d12/crates/leonida-gpu/src/port_descriptors.rs b/d3d12/crates/leonida-gpu/src/port_descriptors.rs index 3721c040ca..b67856bbe5 100644 --- a/d3d12/crates/leonida-gpu/src/port_descriptors.rs +++ b/d3d12/crates/leonida-gpu/src/port_descriptors.rs @@ -400,7 +400,8 @@ pub(crate) fn missed(index: u32, handle: u64, view: bool, tabled: bool) { CHECKED[3].fetch_add(1, Relaxed); return; } - let n = CHECKED[1].fetch_add(1, Relaxed); + CHECKED[1].fetch_add(1, Relaxed); + let n = WARNED.fetch_add(1, Relaxed); MISSED_ALL.fetch_add(1, Relaxed); let rip = a.writers.get(((handle - a.start) >> 16) as usize).map_or(0, |w| w.load(Relaxed)); let (base, size) = (IMAGE[0].load(Relaxed), IMAGE[1].load(Relaxed)); @@ -409,7 +410,7 @@ pub(crate) fn missed(index: u32, handle: u64, view: bool, tabled: bool) { let mut by = WRITERS.lock().unwrap_or_else(|e| e.into_inner()); *by.entry(writer.clone()).or_default() += 1; } - if n < 20 || n.is_power_of_two() { + if warn_worthy(n) { tracing::warn!( slot = index, handle = format_args!("{handle:#x}"), @@ -496,6 +497,16 @@ static TAKEN: [AtomicU64; 3] = [const { AtomicU64::new(0) }; 3]; pub(crate) static CHECKED: [AtomicU64; 5] = [const { AtomicU64::new(0) }; 5]; /// Since the start: view records the fallback found that no mark told of. static MISSED_ALL: AtomicU64 = AtomicU64::new(0); +/// Warnings said so far. `CHECKED[1]` is swapped to zero by the frame line, so +/// keying the rate limit on it says the first twenty again every period. This +/// one is never reset: the early records and the powers of two are enough to +/// tell whether the fallback is finding unmarked views, without writing a +/// line for each of the tens of thousands a long run finds. +static WARNED: AtomicU64 = AtomicU64::new(0); + +fn warn_worthy(n: u64) -> bool { + n < 20 || n.is_power_of_two() +} /// Since the start: the missed records by the place that last faulted on their block. static WRITERS: std::sync::Mutex> = std::sync::Mutex::new(std::collections::BTreeMap::new()); /// Since the start: slots taken, of them marked by our calls; pages checked. @@ -554,6 +565,18 @@ pub(crate) fn line(frames: f64) { mod tests { use super::*; + /// The warning budget is for the whole run, not for each frame line: a + /// long run still says something at the start and as the count grows, but + /// does not write a line for every missed record. + #[test] + fn the_warning_stays_bounded_over_a_long_run() { + let said = (0..100_000u64).filter(|&n| warn_worthy(n)).count(); + assert!(said <= 40, "said {said} warnings in 100,000 misses"); + assert!(warn_worthy(0)); + assert!(!warn_worthy(21)); + assert!(warn_worthy(1 << 20)); + } + #[test] fn marks_layout_is_what_the_stores_read() { assert_eq!(size_of::(), 32); From 950f95688db5a856e2262ad7cdeffda7ba6ea605 Mon Sep 17 00:00:00 2001 From: MoonEyes <14891700+MoonEyes@users.noreply.github.com> Date: Tue, 1 Dec 2026 15:26:08 +0100 Subject: [PATCH 2/2] leonida-gpu: the warning's count is tested over several periods Co-Authored-By: Claude Opus 5.5 --- .../leonida-gpu/src/port_descriptors.rs | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/d3d12/crates/leonida-gpu/src/port_descriptors.rs b/d3d12/crates/leonida-gpu/src/port_descriptors.rs index b67856bbe5..11f26ed431 100644 --- a/d3d12/crates/leonida-gpu/src/port_descriptors.rs +++ b/d3d12/crates/leonida-gpu/src/port_descriptors.rs @@ -401,7 +401,7 @@ pub(crate) fn missed(index: u32, handle: u64, view: bool, tabled: bool) { return; } CHECKED[1].fetch_add(1, Relaxed); - let n = WARNED.fetch_add(1, Relaxed); + let warn = next_warning(); MISSED_ALL.fetch_add(1, Relaxed); let rip = a.writers.get(((handle - a.start) >> 16) as usize).map_or(0, |w| w.load(Relaxed)); let (base, size) = (IMAGE[0].load(Relaxed), IMAGE[1].load(Relaxed)); @@ -410,7 +410,7 @@ pub(crate) fn missed(index: u32, handle: u64, view: bool, tabled: bool) { let mut by = WRITERS.lock().unwrap_or_else(|e| e.into_inner()); *by.entry(writer.clone()).or_default() += 1; } - if warn_worthy(n) { + if warn { tracing::warn!( slot = index, handle = format_args!("{handle:#x}"), @@ -507,6 +507,11 @@ static WARNED: AtomicU64 = AtomicU64::new(0); fn warn_worthy(n: u64) -> bool { n < 20 || n.is_power_of_two() } + +/// Counts a missed record; whether it is one to say. +fn next_warning() -> bool { + warn_worthy(WARNED.fetch_add(1, Relaxed)) +} /// Since the start: the missed records by the place that last faulted on their block. static WRITERS: std::sync::Mutex> = std::sync::Mutex::new(std::collections::BTreeMap::new()); /// Since the start: slots taken, of them marked by our calls; pages checked. @@ -577,6 +582,18 @@ mod tests { assert!(warn_worthy(1 << 20)); } + /// The frame line swaps `CHECKED[1]` to zero every period: that does not + /// say the first twenty again. + #[test] + fn a_new_period_does_not_start_the_warnings_again() { + let mut said = 0; + for _ in 0..100 { + CHECKED[1].store(0, Relaxed); + said += (0..100).filter(|_| next_warning()).count(); + } + assert!(said <= 40, "said {said} warnings in 10,000 misses over 100 periods"); + } + #[test] fn marks_layout_is_what_the_stores_read() { assert_eq!(size_of::(), 32);