Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CounterSampleBuffer::resolve_counter_range #336

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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