use crate::core::{
Buffer as CoreBuffer, DescriptorPool as CoreDescriptorPool,
DescriptorSetLayout as CoreDescriptorSetLayout, Device, Image as CoreImage,
};
use ash::vk;
use std::sync::Arc;
pub struct ExBuffer {
device: Arc<Device>,
buffer: CoreBuffer,
}
impl ExBuffer {
pub(crate) fn new(device: Arc<Device>, buffer: CoreBuffer) -> Self {
Self { device, buffer }
}
#[inline]
pub fn handle(&self) -> vk::Buffer {
self.buffer.handle()
}
#[inline]
pub fn size(&self) -> vk::DeviceSize {
self.buffer.size()
}
#[inline]
pub fn usage(&self) -> vk::BufferUsageFlags {
self.buffer.usage()
}
#[inline]
pub fn core_buffer(&self) -> &CoreBuffer {
&self.buffer
}
#[inline]
pub fn into_core(self) -> CoreBuffer {
let buffer = std::mem::ManuallyDrop::new(self);
unsafe { std::ptr::read(&buffer.buffer) }
}
}
impl Drop for ExBuffer {
fn drop(&mut self) {
self.buffer.destroy(&self.device);
}
}
pub struct ExImage {
device: Arc<Device>,
image: CoreImage,
}
impl ExImage {
pub(crate) fn new(device: Arc<Device>, image: CoreImage) -> Self {
Self { device, image }
}
#[inline]
pub fn handle(&self) -> vk::Image {
self.image.handle()
}
#[inline]
pub fn view(&self) -> vk::ImageView {
self.image.view()
}
#[inline]
pub fn extent(&self) -> vk::Extent3D {
self.image.extent()
}
#[inline]
pub fn format(&self) -> vk::Format {
self.image.format()
}
#[inline]
pub fn usage(&self) -> vk::ImageUsageFlags {
self.image.usage()
}
#[inline]
pub fn core_image(&self) -> &CoreImage {
&self.image
}
#[inline]
pub fn into_core(self) -> CoreImage {
let image = std::mem::ManuallyDrop::new(self);
unsafe { std::ptr::read(&image.image) }
}
}
impl Drop for ExImage {
fn drop(&mut self) {
self.image.destroy(&self.device);
}
}
pub struct ExDescriptorSetLayout {
device: Arc<Device>,
layout: CoreDescriptorSetLayout,
}
impl ExDescriptorSetLayout {
#[allow(dead_code)]
pub(crate) fn new(device: Arc<Device>, layout: CoreDescriptorSetLayout) -> Self {
Self { device, layout }
}
#[inline]
pub fn handle(&self) -> vk::DescriptorSetLayout {
self.layout.handle()
}
#[inline]
pub fn core_layout(&self) -> &CoreDescriptorSetLayout {
&self.layout
}
}
impl Drop for ExDescriptorSetLayout {
fn drop(&mut self) {
self.layout.destroy(&self.device);
}
}
pub struct ExDescriptorPool {
device: Arc<Device>,
pool: CoreDescriptorPool,
}
impl ExDescriptorPool {
#[allow(dead_code)]
pub(crate) fn new(device: Arc<Device>, pool: CoreDescriptorPool) -> Self {
Self { device, pool }
}
#[inline]
pub fn handle(&self) -> vk::DescriptorPool {
self.pool.handle()
}
#[inline]
pub fn allocate(
&self,
device: &Arc<Device>,
layouts: &[vk::DescriptorSetLayout],
) -> Result<Vec<crate::core::DescriptorSet>, crate::core::DescriptorPoolError> {
self.pool.allocate(device, layouts)
}
#[inline]
pub fn core_pool(&self) -> &CoreDescriptorPool {
&self.pool
}
}
impl Drop for ExDescriptorPool {
fn drop(&mut self) {
self.pool.destroy(&self.device);
}
}