Detect metal counter sampling style

Use MTLDevice::supports_counter_sampling() to select the appropriate counter style.
This commit is contained in:
chad 2022-04-25 02:34:19 -04:00
parent 02cc867950
commit 867b97f41d

View file

@ -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)),