diff --git a/crates/metal2vulkan-runtime/src/tests/mod.rs b/crates/metal2vulkan-runtime/src/tests/mod.rs index 3e9f7cad3..a43902d5d 100644 --- a/crates/metal2vulkan-runtime/src/tests/mod.rs +++ b/crates/metal2vulkan-runtime/src/tests/mod.rs @@ -152,6 +152,7 @@ mod take_split; mod texture; mod texture_accesses; mod texture_buffers; +mod times; mod translate; mod translator_fields; mod unattached_colors; diff --git a/crates/metal2vulkan-runtime/src/tests/times.rs b/crates/metal2vulkan-runtime/src/tests/times.rs new file mode 100644 index 000000000..1881cdb7f --- /dev/null +++ b/crates/metal2vulkan-runtime/src/tests/times.rs @@ -0,0 +1,25 @@ +//! 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. + +use crate::times::Ticks; + +#[test] +fn durations_count_ticks_of_the_period_across_a_wrap() { + let ticks = Ticks::new(52.083_332, 36); + assert_eq!(ticks.span(1_000, 1_000), 0); + assert_eq!(ticks.span(1_000, 1_096), 5_000); + // From 10 ticks before the 36 bits wrap to 5 after: 15 ticks. + let before = (1u64 << 36) - 10; + assert_eq!(ticks.span(before, 5), 781); + // An end before the start is no duration. + assert_eq!(ticks.span(1_096, 1_000), 0); + let full = Ticks::new(1.0, 64); + assert_eq!(full.span(u64::MAX - 1, 3), 5); +} + +#[test] +fn the_host_time_rises() { + let first = crate::host_time(); + let second = crate::host_time(); + assert!(first > 0 && second >= first, "{first} then {second}"); +}