Runtime: GPU times round a tick count's nanoseconds to the nearest, not down

Ticks::span cast its f64 nanoseconds to u64, which truncates, and so did
Calibration::at, the host time of a tick by the calibration. Ticks of a period
an f32 cannot state exactly come out a nanosecond short: 96 ticks of the Iris
Xe's 19.2 MHz clock, a period of 52.083332 ns as Vulkan states it, are 5000 ns,
and the cast gave 4999. Both now round to the nearest whole nanosecond, one
expression each, no branch; an end before the start still saturates at 0.
Every GPU span and placed time goes through these two: Calibration::place, the
completion thread's placement (complete.rs), the held-start gaps and
Metrics::runtime_command_buffer_gpu_nanos.

Metal states GPUStartTime and GPUEndTime as host seconds (CFTimeInterval, "the
host time in seconds that GPU starts executing this command buffer") with no
precision promise, so the nearest nanosecond the ticks allow is ours to give.

Verified: the ported durations_count_ticks_of_the_period_across_a_wrap
(tests/times.rs, its answer of 5000 as the deleted runtime's test stated it)
was red at the tree before this commit on lavapipe, job m3-max-76896 (left
4999, right 5000; the other four ported tests green). Green after it:
lavapipe run follows.
This commit is contained in:
Anees Iqbal committed 2026-11-27 05:36:14 -08:00
1 parent 124b5026bc
commit 5089a1570a
1 file changed
+6 -4
+6 -4
View File
@@ -138,9 +138,10 @@ impl Ticks {
}
}
/// Whole nanoseconds from timestamp `start` to `end`, 0 where `end` is the earlier.
/// Nanoseconds from timestamp `start` to `end`, to the nearest whole one, 0 where `end` is
/// the earlier.
pub(crate) fn span(&self, start: u64, end: u64) -> u64 {
self.nanos(start, end) as u64
self.nanos(start, end).round() as u64
}
/// Nanoseconds from timestamp `from` to `to`, negative where `to` is the earlier, within the
@@ -229,9 +230,10 @@ impl Calibration {
}
/// The host time of timestamp `tick` by this calibration as it stands, which moves nothing:
/// for the spans of the runtime's own command buffers ([`Spans`]).
/// for the spans of the runtime's own command buffers ([`Spans`]). To the nearest whole
/// nanosecond.
pub(crate) fn at(&self, ticks: &Ticks, tick: u64) -> u64 {
(self.host as f64 + ticks.nanos(self.tick, tick)) as u64
(self.host as f64 + ticks.nanos(self.tick, tick)).round() as u64
}
}