From 124b5026bc8c583f0c19ecaf8d3985e0dcc84121 Mon Sep 17 00:00:00 2001 From: Anees Iqbal Date: Fri, 27 Nov 2026 05:30:42 -0800 Subject: [PATCH] Runtime tests: port the GPU-time calibration placements the old runtime's deletion took 5d725aeec7 deleted the old runtime with its tests. Of its GPU-time tests (tests/gpu_time.rs), these describe the new runtime's Calibration as they stood, ported with their answers unchanged: - a_pair_places_timestamps_on_the_hosts_clock_either_side_of_it, whole, as a_calibration_places_timestamps_on_the_hosts_clock_either_side_of_it (GpuClock::place, now Calibration::at); - the calibrated case of a_span_is_placed_by_the_pair_or_ends_at_the_completion, as a_span_is_placed_by_the_calibration (Calibration::place); its uncalibrated cases do not port, since the floor requires calibrated timestamps; - the 65 s-ahead case of a_pair_that_places_times_outside_the_life_is_set_aside (the Radeon 780M's after two MODE2 resets), as a_calibration_65_s_ahead_places_times_by_the_completion: the times end at the completion seen. Its drift and deviation allowance and its lower bound at the kernel start do not port: the new runtime bounds GPU times by the completion seen alone. Calibration's two fields become pub(crate) so the tests can build one; nothing else changes. Verified: lavapipe and lint runs follow, reported with their jobs. --- .../metal2vulkan-runtime/src/tests/times.rs | 51 ++++++++++++++++++- crates/metal2vulkan-runtime/src/times.rs | 4 +- 2 files changed, 51 insertions(+), 4 deletions(-) diff --git a/crates/metal2vulkan-runtime/src/tests/times.rs b/crates/metal2vulkan-runtime/src/tests/times.rs index 1881cdb7f..5d7d477b0 100644 --- a/crates/metal2vulkan-runtime/src/tests/times.rs +++ b/crates/metal2vulkan-runtime/src/tests/times.rs @@ -1,7 +1,14 @@ //! A command buffer's times (`times.rs`) without a device: the durations of the GPU's ticks across -//! the wrap of their valid bits, and the host clock they are placed on rising. +//! the wrap of their valid bits; timestamps placed on the host clock by a calibration either side +//! of its reading, and by the completion seen where the calibration would place them after it; +//! and the host clock they are placed on rising. -use crate::times::Ticks; +use crate::times::{Calibration, Ticks}; + +/// A calibration that read the GPU's tick `tick` at host nanosecond `host`. +fn calibration(tick: u64, host: u64) -> Calibration { + Calibration { tick, host } +} #[test] fn durations_count_ticks_of_the_period_across_a_wrap() { @@ -17,6 +24,46 @@ fn durations_count_ticks_of_the_period_across_a_wrap() { assert_eq!(full.span(u64::MAX - 1, 3), 5); } +#[test] +fn a_calibration_places_timestamps_on_the_hosts_clock_either_side_of_it() { + let ticks = Ticks::new(2.0, 64); + let pair = calibration(1_000, 5_000_000); + assert_eq!(pair.at(&ticks, 1_000), 5_000_000); + assert_eq!(pair.at(&ticks, 1_500), 5_001_000); + assert_eq!(pair.at(&ticks, 500), 4_999_000); + // Across the bits' wrap, the nearer direction: 8 bits, 6 ticks after 250 is 0 after the wrap. + let narrow = Ticks::new(1.0, 8); + let pair = calibration(250, 1_000); + assert_eq!(pair.at(&narrow, 0), 1_006); + assert_eq!(pair.at(&narrow, 244), 994); +} + +/// A command buffer's two timestamps that the calibration places before the completion seen are +/// the calibration's placement. +#[test] +fn a_span_is_placed_by_the_calibration() { + let ticks = Ticks::new(1.0, 64); + let mut reading = calibration(100, 10_000); + assert_eq!(reading.place(&ticks, (150, 400), 99_999), (10_050, 10_300)); +} + +/// A calibration 65 s off, as a Radeon 780M's after two MODE2 resets (the device's timestamps run +/// 65.15 s past the domain the calibration read), would place the times far past the completion +/// seen: they are placed by the completion, the end at it and the start their exact span before. +#[test] +fn a_calibration_65_s_ahead_places_times_by_the_completion() { + let ticks = Ticks::new(1.0, 64); + // The work ran 1_000 ns from 2_000_100 to 2_001_100 (ticks equal host nanoseconds by the + // sound calibration), and its completion was seen at 2_002_000. + let (start, end, seen) = (2_000_100, 2_001_100, 2_002_000); + let ahead = 65_152_099_677; + let mut off = calibration(1_000_000, 1_000_000); + assert_eq!( + off.place(&ticks, (start + ahead, end + ahead), seen), + (2_001_000, 2_002_000) + ); +} + #[test] fn the_host_time_rises() { let first = crate::host_time(); diff --git a/crates/metal2vulkan-runtime/src/times.rs b/crates/metal2vulkan-runtime/src/times.rs index 76b03c722..fafa9b5f3 100644 --- a/crates/metal2vulkan-runtime/src/times.rs +++ b/crates/metal2vulkan-runtime/src/times.rs @@ -172,8 +172,8 @@ pub(crate) struct Stamped { /// device's tick and the host nanoseconds of the same moment. #[derive(Clone, Copy)] pub(crate) struct Calibration { - tick: u64, - host: u64, + pub(crate) tick: u64, + pub(crate) host: u64, } impl Calibration {