Compare commits
No commits in common. "969a1c411c689bc8495a3dbb81962cdee15f450e" and "c948dd50ab3589057385730c26ceddbccec35abf" have entirely different histories.
969a1c411c
...
c948dd50ab
|
|
@ -113,9 +113,9 @@ impl Buffer {
|
|||
}
|
||||
|
||||
Ok(Self {
|
||||
buffer: DeviceObject::new_debug_named(device.clone(), buffer, desc.name.clone()),
|
||||
buffer: DeviceObject::new(buffer, device.clone(), desc.name.clone()),
|
||||
desc,
|
||||
alloc: Allocation::Owned(DeviceObject::new(device, alloc)),
|
||||
alloc: Allocation::Owned(DeviceObject::new_without_name(alloc, device)),
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -534,7 +534,7 @@ pub mod traits {
|
|||
unsafe {
|
||||
self.device().dev().cmd_push_constants(
|
||||
self.handle(),
|
||||
layout.raw(),
|
||||
layout.handle(),
|
||||
stage,
|
||||
offset,
|
||||
bytes,
|
||||
|
|
@ -575,11 +575,12 @@ pub mod traits {
|
|||
descriptor_sets: &[vk::DescriptorSet],
|
||||
) {
|
||||
// assert_eq!(self.state(), CommandBufferState::Recording);
|
||||
use crate::device::DeviceOwned;
|
||||
unsafe {
|
||||
self.device().dev().cmd_bind_descriptor_sets(
|
||||
self.handle(),
|
||||
bind_point,
|
||||
layout.raw(),
|
||||
layout.handle(),
|
||||
0,
|
||||
descriptor_sets,
|
||||
&[],
|
||||
|
|
|
|||
|
|
@ -16,7 +16,6 @@ use raw_window_handle::RawDisplayHandle;
|
|||
|
||||
use crate::{
|
||||
Instance, PhysicalDeviceFeatures, PhysicalDeviceInfo, Result,
|
||||
device::asdf::traits::ExternallyManagedObject,
|
||||
pipeline::pipeline_cache::PipelineCache,
|
||||
queue::{DeviceQueueInfos, DeviceQueues, Queue},
|
||||
sync::{self, BinarySemaphore, TimelineSemaphore},
|
||||
|
|
@ -55,6 +54,14 @@ pub(crate) struct DeviceExtensions {
|
|||
|
||||
type GpuAllocation = gpu_allocator::vulkan::Allocation;
|
||||
|
||||
impl DeviceHandle for GpuAllocation {
|
||||
unsafe fn destroy(&mut self, device: &Device) {
|
||||
let mut swapped = GpuAllocation::default();
|
||||
std::mem::swap(self, &mut swapped);
|
||||
_ = device.alloc2.lock().free(swapped);
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash)]
|
||||
pub enum AllocationStrategy {
|
||||
#[default]
|
||||
|
|
@ -86,7 +93,7 @@ impl Allocation {
|
|||
pub(crate) fn allocation_mut(&mut self) -> Option<&mut GpuAllocation> {
|
||||
match self {
|
||||
Allocation::Owned(obj) => Some(obj),
|
||||
Allocation::Shared(arc) => Arc::get_mut(arc).map(DerefMut::deref_mut),
|
||||
Allocation::Shared(arc) => Arc::get_mut(arc).map(|alloc| &mut alloc.inner),
|
||||
Allocation::Unmanaged => None,
|
||||
}
|
||||
}
|
||||
|
|
@ -693,7 +700,76 @@ impl<T> DeviceOwnedDebugObject<T> {
|
|||
}
|
||||
}
|
||||
|
||||
pub use asdf::{DeviceObject, InnerDeviceObject};
|
||||
#[derive(Debug)]
|
||||
pub struct DeviceObject<T: DeviceHandle> {
|
||||
inner: T,
|
||||
device: Device,
|
||||
#[cfg(debug_assertions)]
|
||||
name: Option<Cow<'static, str>>,
|
||||
}
|
||||
|
||||
impl<T: DeviceHandle> Deref for DeviceObject<T> {
|
||||
type Target = T;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.inner
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: DeviceHandle> DerefMut for DeviceObject<T> {
|
||||
fn deref_mut(&mut self) -> &mut Self::Target {
|
||||
&mut self.inner
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: DeviceHandle> DeviceObject<T> {
|
||||
pub fn new(inner: T, device: Device, name: Option<Cow<'static, str>>) -> Self
|
||||
where
|
||||
T: vk::Handle + Clone,
|
||||
{
|
||||
unsafe {
|
||||
if let Some(name) = name.as_ref() {
|
||||
device.debug_name_object(inner.clone(), name);
|
||||
}
|
||||
}
|
||||
|
||||
Self {
|
||||
inner,
|
||||
device,
|
||||
#[cfg(debug_assertions)]
|
||||
name,
|
||||
}
|
||||
}
|
||||
pub fn new_without_name(inner: T, device: Device) -> Self {
|
||||
Self {
|
||||
inner,
|
||||
device,
|
||||
#[cfg(debug_assertions)]
|
||||
name: None,
|
||||
}
|
||||
}
|
||||
pub fn device(&self) -> &Device {
|
||||
&self.device
|
||||
}
|
||||
pub fn name(&self) -> Option<&str> {
|
||||
#[cfg(debug_assertions)]
|
||||
{
|
||||
self.name.as_deref()
|
||||
}
|
||||
#[cfg(not(debug_assertions))]
|
||||
{
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: DeviceHandle> Drop for DeviceObject<T> {
|
||||
fn drop(&mut self) {
|
||||
unsafe {
|
||||
self.inner.destroy(&self.device);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub trait DeviceHandle {
|
||||
/// # Safety
|
||||
|
|
@ -701,26 +777,35 @@ pub trait DeviceHandle {
|
|||
unsafe fn destroy(&mut self, device: &Device);
|
||||
}
|
||||
|
||||
impl<O, T: ExternallyManagedObject<O>> ExternallyManagedObject<O> for Mutex<T> {
|
||||
unsafe fn destroy(self, owner: &O) {
|
||||
// Safety guarantee is upheld by the caller.
|
||||
unsafe { self.into_inner().destroy(owner) };
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: AsRef<DeviceInner>> ExternallyManagedObject<T> for vk::Buffer {
|
||||
unsafe fn destroy(self, device: &T) {
|
||||
impl DeviceHandle for vk::Semaphore {
|
||||
unsafe fn destroy(&mut self, device: &Device) {
|
||||
unsafe {
|
||||
device.as_ref().raw.destroy_buffer(self, None);
|
||||
device.dev().destroy_semaphore(*self, None);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: AsRef<DeviceInner>> ExternallyManagedObject<T> for vk::SwapchainKHR {
|
||||
unsafe fn destroy(self, device: &T) {
|
||||
impl DeviceHandle for vk::Fence {
|
||||
unsafe fn destroy(&mut self, device: &Device) {
|
||||
unsafe {
|
||||
if let Some(swapchain) = device.as_ref().device_extensions.swapchain.as_ref() {
|
||||
swapchain.destroy_swapchain(self, None)
|
||||
device.dev().destroy_fence(*self, None);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl DeviceHandle for vk::Buffer {
|
||||
unsafe fn destroy(&mut self, device: &Device) {
|
||||
unsafe {
|
||||
device.dev().destroy_buffer(*self, None);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl DeviceHandle for vk::SwapchainKHR {
|
||||
unsafe fn destroy(&mut self, device: &Device) {
|
||||
unsafe {
|
||||
if let Some(swapchain) = device.device_extensions.swapchain.as_ref() {
|
||||
swapchain.destroy_swapchain(*self, None)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -957,13 +1042,11 @@ pub(crate) mod asdf {
|
|||
}
|
||||
}
|
||||
|
||||
pub type InnerDeviceObject<T> = DeviceObject<T, Arc<DeviceInner>>;
|
||||
|
||||
/// A wrapper for vulkan types which are owned by the device, taking care of destruction.
|
||||
#[derive(Debug)]
|
||||
pub struct DeviceObject<
|
||||
T: traits::ExternallyManagedObject<O>,
|
||||
O: AsRef<super::DeviceInner> = super::Device,
|
||||
O: AsRef<super::DeviceInner> = Arc<super::DeviceInner>,
|
||||
> {
|
||||
inner: ExternallyManagedObject<T, O>,
|
||||
#[allow(dead_code)]
|
||||
|
|
@ -993,54 +1076,9 @@ pub(crate) mod asdf {
|
|||
|
||||
Self { inner, name: None }
|
||||
}
|
||||
|
||||
pub fn new_debug_named_with<D>(
|
||||
owner: O,
|
||||
inner: T,
|
||||
name: Option<impl Into<DebugName>>,
|
||||
debug_namable: impl FnOnce(&T) -> D,
|
||||
) -> Self
|
||||
where
|
||||
D: traits::DebugNameable,
|
||||
{
|
||||
let name = name.map(Into::into);
|
||||
if let Some(ref name) = name {
|
||||
traits::DebugNameable::debug_name(&debug_namable(&inner), owner.as_ref(), name);
|
||||
}
|
||||
|
||||
let obj = ExternallyManagedObject::new(inner, owner);
|
||||
|
||||
Self { inner: obj, name }
|
||||
}
|
||||
|
||||
pub fn device(&self) -> &O {
|
||||
self.inner.owner()
|
||||
}
|
||||
|
||||
pub fn name(&self) -> Option<&str> {
|
||||
self.name.as_ref().map(|n| &**n)
|
||||
}
|
||||
|
||||
pub fn map_inner<U>(self, f: impl FnOnce(T) -> U) -> DeviceObject<U, O>
|
||||
where
|
||||
U: traits::ExternallyManagedObject<O>,
|
||||
{
|
||||
DeviceObject {
|
||||
inner: self.inner.map_inner(f),
|
||||
name: self.name,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn map_owner<U>(self, f: impl FnOnce(O) -> U) -> DeviceObject<T, U>
|
||||
where
|
||||
T: traits::ExternallyManagedObject<U>,
|
||||
U: AsRef<super::DeviceInner>,
|
||||
{
|
||||
DeviceObject {
|
||||
inner: self.inner.map_owner(f),
|
||||
name: self.name,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T, O> Deref for DeviceObject<T, O>
|
||||
|
|
@ -1051,17 +1089,7 @@ pub(crate) mod asdf {
|
|||
type Target = T;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&*self.inner
|
||||
}
|
||||
}
|
||||
|
||||
impl<T, O> DerefMut for DeviceObject<T, O>
|
||||
where
|
||||
T: traits::ExternallyManagedObject<O>,
|
||||
O: AsRef<super::DeviceInner>,
|
||||
{
|
||||
fn deref_mut(&mut self) -> &mut Self::Target {
|
||||
&mut *self.inner
|
||||
&self.inner
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1070,7 +1098,7 @@ pub(crate) mod asdf {
|
|||
|
||||
use super::*;
|
||||
|
||||
impl<T: AsRef<DeviceInner>> traits::ExternallyManagedObject<T> for vk::Semaphore {
|
||||
impl<T: AsRef<DeviceInner>> traits::ExternallyManagedObject<T> for ash::vk::Semaphore {
|
||||
unsafe fn destroy(self, device: &T) {
|
||||
unsafe {
|
||||
device.as_ref().raw.destroy_semaphore(self, None);
|
||||
|
|
|
|||
|
|
@ -1,10 +1,7 @@
|
|||
use std::{borrow::Cow, mem::ManuallyDrop, sync::Arc};
|
||||
|
||||
use crate::{
|
||||
device::{
|
||||
Allocation, AllocationStrategy, DeviceInner, DeviceObject, QueueFlags,
|
||||
asdf::traits::ExternallyManagedObject,
|
||||
},
|
||||
device::{Allocation, AllocationStrategy, DeviceHandle, DeviceObject, QueueFlags},
|
||||
swapchain::Swapchain,
|
||||
util::weak_vec::WeakVec,
|
||||
};
|
||||
|
|
@ -117,10 +114,10 @@ enum ImageInner {
|
|||
Allocated(DeviceObject<vk::Image>, Allocation),
|
||||
}
|
||||
|
||||
impl<T: AsRef<DeviceInner>> ExternallyManagedObject<T> for vk::Image {
|
||||
unsafe fn destroy(self, device: &T) {
|
||||
impl DeviceHandle for vk::Image {
|
||||
unsafe fn destroy(&mut self, device: &Device) {
|
||||
unsafe {
|
||||
device.as_ref().raw.destroy_image(self, None);
|
||||
device.dev().destroy_image(*self, None);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -178,7 +175,7 @@ impl Image {
|
|||
Self::new_with_allocation_unchecked(
|
||||
device.clone(),
|
||||
image,
|
||||
Allocation::Owned(DeviceObject::new(device, alloc)),
|
||||
Allocation::Owned(DeviceObject::new_without_name(alloc, device)),
|
||||
desc,
|
||||
)
|
||||
}
|
||||
|
|
@ -200,7 +197,7 @@ impl Image {
|
|||
|
||||
Ok(Self {
|
||||
image: ImageInner::Allocated(
|
||||
DeviceObject::new_debug_named(device, image, desc.name.clone()),
|
||||
DeviceObject::new(image, device, desc.name.clone()),
|
||||
allocation,
|
||||
),
|
||||
desc,
|
||||
|
|
@ -478,7 +475,7 @@ impl Image {
|
|||
let view = unsafe { device.raw.create_image_view(&create_info, None)? };
|
||||
|
||||
Ok(ManuallyDrop::new(ImageView {
|
||||
view: DeviceObject::new_debug_named(device.clone(), view, desc.name.clone()),
|
||||
view: DeviceObject::new(view, device.clone(), desc.name.clone()),
|
||||
desc,
|
||||
image: self.clone(),
|
||||
}))
|
||||
|
|
@ -685,10 +682,10 @@ impl ImageView {
|
|||
}
|
||||
}
|
||||
|
||||
impl<T: AsRef<DeviceInner>> ExternallyManagedObject<T> for vk::ImageView {
|
||||
unsafe fn destroy(self, device: &T) {
|
||||
impl DeviceHandle for vk::ImageView {
|
||||
unsafe fn destroy(&mut self, device: &Device) {
|
||||
unsafe {
|
||||
device.as_ref().raw.destroy_image_view(self, None);
|
||||
device.dev().destroy_image_view(*self, None);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,13 +1,10 @@
|
|||
use std::{borrow::Cow, path::Path, sync::Arc};
|
||||
|
||||
use ash::{ext, prelude::*, vk};
|
||||
use parking_lot::Mutex;
|
||||
|
||||
use crate::{
|
||||
define_device_owned_handle,
|
||||
device::{
|
||||
Device, DeviceHandle, DeviceInner, DeviceObject, asdf::traits::ExternallyManagedObject,
|
||||
},
|
||||
device::{Device, DeviceHandle, DeviceObject},
|
||||
make_extension,
|
||||
};
|
||||
|
||||
|
|
@ -220,28 +217,15 @@ pub struct DescriptorSetAllocDesc<'a> {
|
|||
pub layout: &'a DescriptorSetLayout,
|
||||
}
|
||||
|
||||
impl DeviceHandle for vk::DescriptorPool {
|
||||
unsafe fn destroy(&mut self, device: &Device) {
|
||||
unsafe { device.dev().destroy_descriptor_pool(*self, None) };
|
||||
}
|
||||
}
|
||||
impl<T: AsRef<DeviceInner>> ExternallyManagedObject<T> for vk::DescriptorPool {
|
||||
unsafe fn destroy(self, device: &T) {
|
||||
// SAFETY: We have exclusive ownership of the descriptor pool, so it's safe to destroy it.
|
||||
unsafe {
|
||||
device.as_ref().raw.destroy_descriptor_pool(self, None);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
define_device_owned_handle! {
|
||||
#[derive(Debug)]
|
||||
pub struct DescriptorPool {
|
||||
pool: DeviceObject<vk::DescriptorPool>,
|
||||
lock: Mutex<()>,
|
||||
pub DescriptorPool(vk::DescriptorPool) {} => |this| unsafe {
|
||||
this.device().dev().destroy_descriptor_pool(this.handle(), None);
|
||||
}
|
||||
}
|
||||
|
||||
impl DescriptorPool {
|
||||
pub fn new(device: Device, desc: DescriptorPoolDesc) -> crate::Result<Self> {
|
||||
pub fn new(device: Device, desc: DescriptorPoolDesc) -> VkResult<Self> {
|
||||
let info = &vk::DescriptorPoolCreateInfo::default()
|
||||
.flags(desc.flags)
|
||||
.max_sets(desc.max_sets)
|
||||
|
|
@ -249,30 +233,23 @@ impl DescriptorPool {
|
|||
|
||||
let handle = unsafe { device.dev().create_descriptor_pool(info, None)? };
|
||||
|
||||
Ok(Self {
|
||||
pool: DeviceObject::new_debug_named(device, handle, desc.name),
|
||||
lock: Mutex::new(()),
|
||||
})
|
||||
Self::construct(device, handle, desc.name)
|
||||
}
|
||||
|
||||
pub fn allocate(&self, descs: &[DescriptorSetAllocDesc]) -> VkResult<Vec<vk::DescriptorSet>> {
|
||||
let layouts = descs
|
||||
.iter()
|
||||
.map(|desc| desc.layout.raw())
|
||||
.map(|desc| desc.layout.handle())
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
let info = &vk::DescriptorSetAllocateInfo::default()
|
||||
.descriptor_pool(*self.pool)
|
||||
.descriptor_pool(self.handle())
|
||||
.set_layouts(&layouts);
|
||||
|
||||
let sets = unsafe {
|
||||
let _lock = self.lock.lock();
|
||||
self.pool.device().raw.allocate_descriptor_sets(info)?
|
||||
};
|
||||
let sets = unsafe { self.device().dev().allocate_descriptor_sets(info)? };
|
||||
|
||||
for (&set, desc) in sets.iter().zip(descs) {
|
||||
if let Some(name) = desc.name.as_ref() {
|
||||
unsafe { self.pool.device().debug_name_object(set, name) };
|
||||
unsafe { self.device().debug_name_object(set, name) };
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -281,34 +258,23 @@ impl DescriptorPool {
|
|||
|
||||
#[allow(dead_code)]
|
||||
pub fn reset(&self) -> VkResult<()> {
|
||||
let _lock = self.lock.lock();
|
||||
unsafe {
|
||||
self.pool
|
||||
.device()
|
||||
.raw
|
||||
.reset_descriptor_pool(*self.pool, vk::DescriptorPoolResetFlags::empty())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: AsRef<DeviceInner>> ExternallyManagedObject<T> for vk::DescriptorSetLayout {
|
||||
unsafe fn destroy(self, device: &T) {
|
||||
unsafe {
|
||||
device
|
||||
.as_ref()
|
||||
.raw
|
||||
.destroy_descriptor_set_layout(self, None);
|
||||
self.device()
|
||||
.dev()
|
||||
.reset_descriptor_pool(self.handle(), vk::DescriptorPoolResetFlags::empty())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
define_device_owned_handle! {
|
||||
#[derive(Debug)]
|
||||
pub struct DescriptorSetLayout {
|
||||
layout: DeviceObject<vk::DescriptorSetLayout>,
|
||||
pub DescriptorSetLayout(vk::DescriptorSetLayout) {} => |this| unsafe {
|
||||
this.device().dev().destroy_descriptor_set_layout(this.handle(), None);
|
||||
}
|
||||
}
|
||||
|
||||
impl DescriptorSetLayout {
|
||||
pub fn new(device: Device, desc: DescriptorSetLayoutDesc) -> crate::Result<Self> {
|
||||
pub fn new(device: Device, desc: DescriptorSetLayoutDesc) -> VkResult<Self> {
|
||||
let (flags, bindings): (Vec<_>, Vec<_>) = desc
|
||||
.bindings
|
||||
.iter()
|
||||
|
|
@ -339,52 +305,34 @@ impl DescriptorSetLayout {
|
|||
info = info.push_next(flags);
|
||||
}
|
||||
|
||||
let layout = unsafe { device.raw.create_descriptor_set_layout(&info, None)? };
|
||||
let layout = unsafe { device.dev().create_descriptor_set_layout(&info, None)? };
|
||||
|
||||
Ok(Self {
|
||||
layout: DeviceObject::new_debug_named(device, layout, desc.name),
|
||||
})
|
||||
}
|
||||
|
||||
pub fn raw(&self) -> vk::DescriptorSetLayout {
|
||||
*self.layout
|
||||
Self::construct(device, layout, desc.name)
|
||||
}
|
||||
}
|
||||
|
||||
use crate::device::DeviceOwned;
|
||||
|
||||
impl<T: AsRef<DeviceInner>> ExternallyManagedObject<T> for vk::PipelineLayout {
|
||||
unsafe fn destroy(self, device: &T) {
|
||||
unsafe {
|
||||
device.as_ref().raw.destroy_pipeline_layout(self, None);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
define_device_owned_handle! {
|
||||
#[derive(Debug)]
|
||||
pub struct PipelineLayout {
|
||||
layout: DeviceObject<vk::PipelineLayout>,
|
||||
pub PipelineLayout(vk::PipelineLayout) {} => |this| unsafe {
|
||||
this.device().dev().destroy_pipeline_layout(this.handle(), None);
|
||||
}
|
||||
}
|
||||
|
||||
impl PipelineLayout {
|
||||
pub fn new(device: Device, desc: PipelineLayoutDesc) -> crate::Result<Self> {
|
||||
pub fn new(device: Device, desc: PipelineLayoutDesc) -> VkResult<Self> {
|
||||
let set_layouts = desc
|
||||
.descriptor_set_layouts
|
||||
.iter()
|
||||
.map(|desc| desc.raw())
|
||||
.map(|desc| desc.handle())
|
||||
.collect::<Vec<_>>();
|
||||
let info = &vk::PipelineLayoutCreateInfo::default()
|
||||
.set_layouts(&set_layouts)
|
||||
.push_constant_ranges(desc.push_constant_ranges);
|
||||
let layout = unsafe { device.raw.create_pipeline_layout(info, None)? };
|
||||
let layout = unsafe { device.dev().create_pipeline_layout(info, None)? };
|
||||
|
||||
Ok(Self {
|
||||
layout: DeviceObject::new_debug_named(device, layout, desc.name),
|
||||
})
|
||||
}
|
||||
|
||||
pub fn raw(&self) -> vk::PipelineLayout {
|
||||
*self.layout
|
||||
Self::construct(device, layout, desc.name)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -483,23 +431,14 @@ impl Sampler {
|
|||
}
|
||||
}
|
||||
|
||||
impl<T: AsRef<DeviceInner>> ExternallyManagedObject<T> for vk::ShaderModule {
|
||||
unsafe fn destroy(self, device: &T) {
|
||||
unsafe {
|
||||
device.as_ref().raw.destroy_shader_module(self, None);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
define_device_owned_handle! {
|
||||
#[derive(Debug)]
|
||||
pub struct ShaderModule {
|
||||
module: DeviceObject<vk::ShaderModule>,
|
||||
pub ShaderModule(vk::ShaderModule) {} => |this| unsafe {
|
||||
this.device().dev().destroy_shader_module(this.handle(), None);
|
||||
}
|
||||
}
|
||||
|
||||
impl ShaderModule {
|
||||
pub fn raw(&self) -> vk::ShaderModule {
|
||||
*self.module
|
||||
}
|
||||
pub fn new_from_path<P: AsRef<Path>>(device: Device, path: P) -> crate::Result<Self> {
|
||||
use std::io::{BufReader, Read, Seek};
|
||||
|
||||
|
|
@ -514,17 +453,15 @@ impl ShaderModule {
|
|||
let size = reader.read(bytemuck::cast_slice_mut(buffer.as_mut_slice()))?;
|
||||
buffer.resize(size / 4, 0);
|
||||
|
||||
Self::new_from_memory(device, &buffer)
|
||||
Ok(Self::new_from_memory(device, &buffer)?)
|
||||
}
|
||||
|
||||
pub fn new_from_memory(device: Device, buffer: &[u32]) -> crate::Result<Self> {
|
||||
pub fn new_from_memory(device: Device, buffer: &[u32]) -> VkResult<Self> {
|
||||
let info = &vk::ShaderModuleCreateInfo::default().code(buffer);
|
||||
|
||||
let module = unsafe { device.dev().create_shader_module(info, None)? };
|
||||
|
||||
Ok(Self {
|
||||
module: DeviceObject::new(device, module),
|
||||
})
|
||||
Self::construct(device, module, None)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -534,18 +471,16 @@ pub struct Pipeline {
|
|||
bind_point: vk::PipelineBindPoint,
|
||||
}
|
||||
|
||||
impl<T: AsRef<DeviceInner>> ExternallyManagedObject<T> for vk::Pipeline {
|
||||
unsafe fn destroy(self, device: &T) {
|
||||
unsafe {
|
||||
device.as_ref().raw.destroy_pipeline(self, None);
|
||||
}
|
||||
impl DeviceHandle for vk::Pipeline {
|
||||
unsafe fn destroy(&mut self, device: &Device) {
|
||||
unsafe { device.raw.destroy_pipeline(*self, None) };
|
||||
}
|
||||
}
|
||||
|
||||
impl ShaderStageDesc<'_> {
|
||||
fn as_create_info(&'_ self) -> vk::PipelineShaderStageCreateInfo<'_> {
|
||||
vk::PipelineShaderStageCreateInfo::default()
|
||||
.module(self.module.raw())
|
||||
.module(self.module.handle())
|
||||
.flags(self.flags)
|
||||
.stage(self.stage)
|
||||
.name(&self.entry)
|
||||
|
|
@ -556,7 +491,7 @@ impl Pipeline {
|
|||
pub fn new_compute(device: Device, desc: ComputePipelineDesc) -> crate::Result<Self> {
|
||||
let info = &vk::ComputePipelineCreateInfo::default()
|
||||
.flags(desc.flags)
|
||||
.layout(desc.layout.raw())
|
||||
.layout(desc.layout.handle())
|
||||
.base_pipeline_handle(
|
||||
desc.base_pipeline
|
||||
.map(|p| p.raw())
|
||||
|
|
@ -579,7 +514,7 @@ impl Pipeline {
|
|||
};
|
||||
|
||||
Ok(Self {
|
||||
pipeline: DeviceObject::new_debug_named(device, pipeline, desc.name),
|
||||
pipeline: DeviceObject::new(pipeline, device, desc.name),
|
||||
bind_point: vk::PipelineBindPoint::COMPUTE,
|
||||
})
|
||||
}
|
||||
|
|
@ -718,7 +653,7 @@ impl Pipeline {
|
|||
p_depth_stencil_state: option_to_ptr(&depth_stencil),
|
||||
p_color_blend_state: option_to_ptr(&color_blend),
|
||||
p_dynamic_state: option_to_ptr(&dynamic),
|
||||
layout: desc.layout.raw(),
|
||||
layout: desc.layout.handle(),
|
||||
render_pass: desc.render_pass.unwrap_or(vk::RenderPass::null()),
|
||||
subpass: desc.subpass.unwrap_or(0),
|
||||
base_pipeline_handle: desc
|
||||
|
|
@ -747,7 +682,7 @@ impl Pipeline {
|
|||
};
|
||||
|
||||
Ok(Self {
|
||||
pipeline: DeviceObject::new_debug_named(device, pipeline, desc.name),
|
||||
pipeline: DeviceObject::new(pipeline, device, desc.name),
|
||||
bind_point: vk::PipelineBindPoint::GRAPHICS,
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -488,10 +488,10 @@ impl Swapchain {
|
|||
.swapchain
|
||||
.clone()
|
||||
.expect("swapchain extension not loaded"),
|
||||
swapchain: DeviceObject::new_debug_named(
|
||||
device,
|
||||
swapchain: DeviceObject::new(
|
||||
swapchain,
|
||||
Some(format!("swapchain-{:x}", swapchain.as_raw())),
|
||||
device,
|
||||
Some(format!("swapchain-{:x}", swapchain.as_raw()).into()),
|
||||
),
|
||||
images,
|
||||
config,
|
||||
|
|
|
|||
|
|
@ -7,10 +7,7 @@ use std::{
|
|||
|
||||
use crate::device::{
|
||||
DevicePools, Pool, PoolObject, Pooled,
|
||||
asdf::{
|
||||
DeviceObject, InnerDeviceObject,
|
||||
traits::ExternallyManagedObject as ExternallyManagedObjectTrait,
|
||||
},
|
||||
asdf::{DeviceObject, traits::ExternallyManagedObject as ExternallyManagedObjectTrait},
|
||||
};
|
||||
use crate::{Result, device::DeviceInner};
|
||||
|
||||
|
|
@ -160,7 +157,7 @@ impl SyncThreadpool {
|
|||
|
||||
pub enum Fence {
|
||||
Dedicated {
|
||||
fence: InnerDeviceObject<vk::Fence>,
|
||||
fence: DeviceObject<vk::Fence>,
|
||||
},
|
||||
Pooled {
|
||||
fence: PoolObject<vk::Fence, Arc<Pool<vk::Fence>>>,
|
||||
|
|
@ -185,10 +182,10 @@ impl ExternallyManagedObjectTrait<Arc<Pool<vk::Fence>>> for vk::Fence {
|
|||
}
|
||||
}
|
||||
|
||||
impl<T: AsRef<DeviceInner>> ExternallyManagedObjectTrait<T> for vk::Fence {
|
||||
unsafe fn destroy(self, device: &T) {
|
||||
impl ExternallyManagedObjectTrait<Arc<DeviceInner>> for vk::Fence {
|
||||
unsafe fn destroy(self, device: &Arc<DeviceInner>) {
|
||||
unsafe {
|
||||
device.as_ref().raw.destroy_fence(self, None);
|
||||
device.raw.destroy_fence(self, None);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -336,7 +333,7 @@ impl From<TimelineSemaphore> for SemaphoreInner {
|
|||
|
||||
pub enum Semaphore {
|
||||
Dedicated {
|
||||
semaphore: InnerDeviceObject<SemaphoreInner>,
|
||||
semaphore: DeviceObject<SemaphoreInner>,
|
||||
},
|
||||
Pooled {
|
||||
#[allow(private_interfaces)]
|
||||
|
|
|
|||
Loading…
Reference in a new issue