Skip to content

Commit

Permalink
Add CounterSampleBuffer::resolve_counter_range
Browse files Browse the repository at this point in the history
  • Loading branch information
kvark committed Sep 25, 2024
1 parent 9bbe74b commit 7da8c53
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/counters.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::MTLStorageMode;
use crate::{MTLStorageMode, NSUInteger};
use std::mem;

/// See <https://developer.apple.com/documentation/metal/mtlcountersamplebufferdescriptor>
pub enum MTLCounterSampleBufferDescriptor {}
Expand Down Expand Up @@ -63,6 +64,22 @@ foreign_obj_type! {
pub struct CounterSampleBuffer;
}

impl CounterSampleBufferRef {
pub fn sample_count(&self) -> u64 {
unsafe { msg_send![self, sampleCount] }
}

pub fn resolve_counter_range(&self, range: crate::NSRange) -> Vec<NSUInteger> {
let mut data = vec![0 as NSUInteger; range.length as usize];
let total_bytes = range.length * mem::size_of::<NSUInteger>() as u64;
unsafe {
let ns_data: *mut crate::Object = msg_send![self, resolveCounterRange: range];
let () = msg_send![ns_data, getBytes: data.as_mut_ptr() length: total_bytes];
}
data
}
}

/// See <https://developer.apple.com/documentation/metal/mtlcounter>
pub enum MTLCounter {}

Expand Down

0 comments on commit 7da8c53

Please sign in to comment.