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 Nov 21, 2024
1 parent 8c92db7 commit ae17b07
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 ae17b07

Please sign in to comment.