use crate::{api, arc, define_mtl, define_obj_type, mtl, ns, objc};
define_obj_type!(
#[doc(alias = "MTLResidencySetDescriptor")]
pub ResidencySetDesc(ns::Id),
MTL_RESIDENCY_SET_DESCRIPTOR,
#[api::available(macos = 15.0, ios = 18.0, maccatalyst = 18.0, tvos = 18.0, visionos = 2.0)]
);
#[link(name = "mtl", kind = "static")]
unsafe extern "C" {
static MTL_RESIDENCY_SET_DESCRIPTOR: &'static objc::Class<ResidencySetDesc>;
}
impl ResidencySetDesc {
define_mtl!(set_label);
#[objc::msg_send(label)]
pub fn label(&self) -> Option<arc::R<ns::String>>;
#[objc::msg_send(initialCapacity)]
pub fn initial_capacity(&self) -> usize;
#[objc::msg_send(setInitialCapacity:)]
pub fn set_initial_capacity(&mut self, val: usize);
}
define_obj_type!(
#[doc(alias = "MTLResidencySet")]
pub ResidencySet(ns::Id)
);
impl ResidencySet {
#[objc::msg_send(device)]
pub fn device(&self) -> arc::R<mtl::Device>;
#[objc::msg_send(label)]
pub fn label(&self) -> Option<arc::R<ns::String>>;
#[objc::msg_send(allocatedSize)]
pub fn allocated_size(&self) -> usize;
#[objc::msg_send(requestResidency)]
pub fn request_residency(&self);
#[objc::msg_send(endResidency)]
pub fn end_residency(&self);
#[objc::msg_send(addAllocation:)]
pub fn add_allocation(&mut self, val: &mtl::Allocation);
#[objc::msg_send(addAllocations:count:)]
pub unsafe fn add_allocations_count(&mut self, ptr: *const &mtl::Allocation, count: usize);
#[inline]
pub fn add_allocations(&mut self, allocations: &[&mtl::Allocation]) {
unsafe { self.add_allocations_count(allocations.as_ptr(), allocations.len()) };
}
#[objc::msg_send(removeAllocation:)]
pub fn remove_allocation(&mut self, val: &mtl::Allocation);
#[objc::msg_send(removeAllocations:count:)]
pub unsafe fn remove_allocations_count(&mut self, ptr: *const &mtl::Allocation, count: usize);
#[inline]
pub fn remove_allocations(&mut self, allocations: &[&mtl::Allocation]) {
unsafe { self.remove_allocations_count(allocations.as_ptr(), allocations.len()) };
}
#[objc::msg_send(removeAllAllocations)]
pub fn remove_all_allocations(&mut self);
#[objc::msg_send(containsAllocation:)]
pub fn contains_allocation(&self, val: &mtl::Allocation) -> bool;
#[objc::msg_send(allAllocations)]
pub fn all_allocations(&self) -> arc::R<ns::Array<mtl::Allocation>>;
#[objc::msg_send(allocationCount)]
pub fn allocation_count(&self) -> usize;
#[objc::msg_send(commit)]
pub fn commit(&mut self);
}
#[cfg(test)]
mod tests {
#[cfg(not(feature = "macos_15_0"))]
use crate::api;
use crate::mtl;
#[cfg(not(feature = "macos_15_0"))]
#[test]
fn basics() {
if api::version!(macos = 15.0) {
let mut desc = mtl::ResidencySetDesc::new().unwrap();
assert_eq!(0, desc.initial_capacity());
desc.set_initial_capacity(10);
assert_eq!(10, desc.initial_capacity());
let device = mtl::Device::sys_default().unwrap();
let set = unsafe { device.new_residency_set(&desc).unwrap() };
assert_eq!(0, set.allocation_count());
}
}
#[cfg(feature = "macos_15_0")]
#[test]
fn basics() {
let mut desc = mtl::ResidencySetDesc::new();
assert_eq!(0, desc.initial_capacity());
desc.set_initial_capacity(10);
assert_eq!(10, desc.initial_capacity());
let device = mtl::Device::sys_default().unwrap();
let set = device.new_residency_set(&desc).unwrap();
assert_eq!(0, set.allocation_count());
}
}