From 867b97f41d3c66124d211c8018889b7af941461f Mon Sep 17 00:00:00 2001 From: chad Date: Mon, 25 Apr 2022 02:34:19 -0400 Subject: [PATCH] Detect metal counter sampling style Use MTLDevice::supports_counter_sampling() to select the appropriate counter style. --- piet-gpu-hal/src/metal.rs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/piet-gpu-hal/src/metal.rs b/piet-gpu-hal/src/metal.rs index b2189e4..307def8 100644 --- a/piet-gpu-hal/src/metal.rs +++ b/piet-gpu-hal/src/metal.rs @@ -55,7 +55,7 @@ pub struct MtlDevice { /// Type of counter sampling. /// /// See https://developer.apple.com/documentation/metal/counter_sampling/sampling_gpu_data_into_counter_sample_buffers -#[derive(Clone, Copy, PartialEq, Eq)] +#[derive(Clone, Copy, PartialEq, Eq, Debug)] enum CounterStyle { None, Stage, @@ -244,12 +244,18 @@ impl MtlDevice { // Timer stuff let timer_set = CounterSet::get_timer_counter_set(&device); let counter_style = if timer_set.is_some() { - // TODO: M1 is stage style, but should do proper runtime detection. - CounterStyle::Stage + if device.supports_counter_sampling(metal::MTLCounterSamplingPoint::AtStageBoundary) { + CounterStyle::Stage + } else if device + .supports_counter_sampling(metal::MTLCounterSamplingPoint::AtDispatchBoundary) + { + CounterStyle::Command + } else { + CounterStyle::None + } } else { CounterStyle::None }; - MtlDevice { device, cmd_queue: Arc::new(Mutex::new(cmd_queue)),