use core::Device;
use core::allocator_helper::AllocatorHelper;
use std::cmp::Ordering;
use std::hash::{Hash, Hasher};
use std::ptr;
use std::sync::Arc;
use vks;
use {TryDestroyError, TryDestroyErrorKind, VulkanObject};
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct PipelineLayout(Arc<Inner>);
impl VulkanObject for PipelineLayout {
type NativeVulkanObject = vks::VkPipelineLayout;
#[inline]
fn as_native_vulkan_object(&self) -> Self::NativeVulkanObject {
self.handle()
}
fn try_destroy(self) -> Result<(), TryDestroyError<Self>> {
let strong_count = Arc::strong_count(&self.0);
if strong_count == 1 {
Ok(())
}
else {
Err(TryDestroyError::new(self, TryDestroyErrorKind::InUse(Some(strong_count))))
}
}
}
impl PipelineLayout {
pub(crate) fn new(handle: vks::VkPipelineLayout, device: Device, allocator: Option<AllocatorHelper>) -> Self {
PipelineLayout(Arc::new(Inner {
handle: handle,
device: device,
allocator: allocator,
}))
}
#[inline]
pub(crate) fn handle(&self) -> vks::VkPipelineLayout {
self.0.handle
}
}
#[derive(Debug)]
struct Inner {
handle: vks::VkPipelineLayout,
device: Device,
allocator: Option<AllocatorHelper>,
}
impl Drop for Inner {
fn drop(&mut self) {
let allocator = match self.allocator {
Some(ref allocator) => allocator.callbacks(),
None => ptr::null(),
};
unsafe {
(self.device.loader().core.vkDestroyPipelineLayout)(self.device.handle(), self.handle, allocator);
}
}
}
unsafe impl Send for Inner { }
unsafe impl Sync for Inner { }
impl PartialEq for Inner {
#[inline]
fn eq(&self, other: &Self) -> bool {
self.handle == other.handle
}
}
impl Eq for Inner { }
impl PartialOrd for Inner {
#[inline]
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
self.handle.partial_cmp(&other.handle)
}
}
impl Ord for Inner {
#[inline]
fn cmp(&self, other: &Self) -> Ordering {
self.handle.cmp(&other.handle)
}
}
impl Hash for Inner {
#[inline]
fn hash<H: Hasher>(&self, state: &mut H) {
self.handle.hash(state);
}
}