From c12c4959a5eb6bbc0dc5a61ece7cbf49f1661406 Mon Sep 17 00:00:00 2001 From: illuminatedfellow <361192299+illuminatedfellow@users.noreply.github.com> Date: Fri, 27 Nov 2026 17:01:19 +0200 Subject: [PATCH] Tidy-ups: replay event, timeline after end, VICTORY_WATCH, validator status - Replay: a Worker closes its fence event when dropped (one leaked per 256 MiB upload batch in diagnostics builds). - Timeline: put_of and stack write nothing once recording has ended, so events that straddle end() no longer land in the next recording. - VICTORY_WATCH: rva + 4 is checked, as VICTORY_CRASH_SAVE's ranges are (a huge RVA in the list wrapped instead of being dropped). - Validator: a failed GetStatus is an error, not a pass, and an error blob with a null pointer reads as empty instead of building a slice from null. Port of avatarmanz/VIctory-7900XTX#319 (its issue #227). (cherry picked from commit 8db88ce6fe40cdd03bc9f9b66fb5d31c92bd246d) --- apps/victory/src/run.rs | 2 +- crates/victory-gpu/src/replay/gpu.rs | 9 +++++++++ crates/victory-gpu/src/timeline/record.rs | 7 +++++++ crates/victory-shader/src/emit/validator.rs | 13 +++++++++++-- 4 files changed, 28 insertions(+), 3 deletions(-) diff --git a/apps/victory/src/run.rs b/apps/victory/src/run.rs index a2b4b1b..b27a695 100644 --- a/apps/victory/src/run.rs +++ b/apps/victory/src/run.rs @@ -421,7 +421,7 @@ fn watch(base: usize, size: usize) { let rvas: Vec = list .split(',') .filter_map(|r| usize::from_str_radix(r.trim().trim_start_matches("0x"), 16).ok()) - .filter(|&rva| rva + 4 <= size) + .filter(|&rva| rva.checked_add(4).is_some_and(|end| end <= size)) .collect(); std::thread::spawn(move || { let mut seen = vec![None; rvas.len()]; diff --git a/crates/victory-gpu/src/replay/gpu.rs b/crates/victory-gpu/src/replay/gpu.rs index 97ff62e..d7377de 100644 --- a/crates/victory-gpu/src/replay/gpu.rs +++ b/crates/victory-gpu/src/replay/gpu.rs @@ -23,6 +23,15 @@ pub(super) struct Worker { // at a time (`&mut self`). unsafe impl Send for Worker {} +impl Drop for Worker { + fn drop(&mut self) { + // SAFETY: our event. + unsafe { + let _ = windows::Win32::Foundation::CloseHandle(self.event); + } + } +} + impl Worker { pub(super) fn new(device: &ID3D12Device, queue: &ID3D12CommandQueue) -> Result { // SAFETY: plain object creation. diff --git a/crates/victory-gpu/src/timeline/record.rs b/crates/victory-gpu/src/timeline/record.rs index 89f256e..e57ac62 100644 --- a/crates/victory-gpu/src/timeline/record.rs +++ b/crates/victory-gpu/src/timeline/record.rs @@ -117,6 +117,10 @@ pub(super) fn put(kind: Kind, name: &'static str, t: (u64, u64), a: u64, b: u64, /// Records an event of `thread`. fn put_of(thread: u32, kind: Kind, name: &'static str, (t0, t1): (u64, u64), a: u64, b: u64, stack: u32) { + // After `end`, a place would be one of the next recording's. + if !on() { + return; + } let slots = SLOTS.load(Ordering::Acquire); if slots.is_null() { return; @@ -138,6 +142,9 @@ fn put_of(thread: u32, kind: Kind, name: &'static str, (t0, t1): (u64, u64), a: /// The caller's stack: its place, plus one. fn stack() -> u32 { + if !on() { + return 0; + } let stacks = STACK.load(Ordering::Acquire); if stacks.is_null() { return 0; diff --git a/crates/victory-shader/src/emit/validator.rs b/crates/victory-shader/src/emit/validator.rs index 32171c7..711b036 100644 --- a/crates/victory-shader/src/emit/validator.rs +++ b/crates/victory-shader/src/emit/validator.rs @@ -187,7 +187,11 @@ impl Validator { let mut status = 0; let get_status: unsafe extern "system" fn(Object, *mut Hresult) -> Hresult = method(result, 3); - get_status(result, &mut status); + let got = get_status(result, &mut status); + if got < 0 { + release(result); + return Err(format!("GetStatus failed: {got:#x}")); + } let mut text = String::new(); if status < 0 { let mut errors: Object = std::ptr::null_mut(); @@ -196,7 +200,12 @@ impl Validator { if get_errors(result, &mut errors) >= 0 && !errors.is_null() { let ptr: unsafe extern "system" fn(Object) -> *const u8 = method(errors, 3); let len: unsafe extern "system" fn(Object) -> usize = method(errors, 4); - let bytes = std::slice::from_raw_parts(ptr(errors), len(errors)); + let (at, n) = (ptr(errors), len(errors)); + let bytes: &[u8] = if at.is_null() { + &[] + } else { + std::slice::from_raw_parts(at, n) + }; text = String::from_utf8_lossy(bytes) .trim_end_matches('\0') .trim()