Skip to content

Commit

Permalink
Add homegrown IDs for Vulkan objects (#2054)
Browse files Browse the repository at this point in the history
  • Loading branch information
marc0246 authored Oct 29, 2022
1 parent c6e0144 commit 118b5b2
Show file tree
Hide file tree
Showing 31 changed files with 280 additions and 651 deletions.
21 changes: 4 additions & 17 deletions vulkano/src/buffer/sys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ use std::{
fmt::{Display, Error as FmtError, Formatter},
hash::{Hash, Hasher},
mem::{size_of_val, MaybeUninit},
num::NonZeroU64,
ops::{Deref, DerefMut, Range},
ptr,
sync::Arc,
Expand All @@ -48,6 +49,7 @@ use std::{
pub struct RawBuffer {
handle: ash::vk::Buffer,
device: Arc<Device>,
id: NonZeroU64,

flags: BufferCreateFlags,
size: DeviceSize,
Expand Down Expand Up @@ -324,13 +326,12 @@ impl RawBuffer {
RawBuffer {
handle,
device,

id: Self::next_id(),
flags,
size,
usage,
sharing,
external_memory_handle_types,

memory_requirements,
}
}
Expand Down Expand Up @@ -629,21 +630,7 @@ unsafe impl DeviceOwned for RawBuffer {
}
}

impl PartialEq for RawBuffer {
#[inline]
fn eq(&self, other: &Self) -> bool {
self.handle == other.handle && self.device == other.device
}
}

impl Eq for RawBuffer {}

impl Hash for RawBuffer {
fn hash<H: Hasher>(&self, state: &mut H) {
self.handle.hash(state);
self.device.hash(state);
}
}
crate::impl_id_counter!(RawBuffer);

/// Parameters to create a new `Buffer`.
#[derive(Clone, Debug)]
Expand Down
25 changes: 4 additions & 21 deletions vulkano/src/buffer/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ use std::{
fmt::{Display, Error as FmtError, Formatter},
hash::{Hash, Hasher},
mem::MaybeUninit,
num::NonZeroU64,
ops::Range,
ptr,
sync::Arc,
Expand All @@ -73,6 +74,7 @@ where
{
handle: ash::vk::BufferView,
buffer: Arc<B>,
id: NonZeroU64,

format: Option<Format>,
format_features: FormatFeatures,
Expand Down Expand Up @@ -233,7 +235,7 @@ where
Ok(Arc::new(BufferView {
handle,
buffer,

id: Self::next_id(),
format: Some(format),
format_features,
range: 0..size,
Expand Down Expand Up @@ -282,26 +284,7 @@ where
}
}

impl<B> PartialEq for BufferView<B>
where
B: BufferAccess + ?Sized,
{
fn eq(&self, other: &Self) -> bool {
self.handle == other.handle && self.device() == other.device()
}
}

impl<B> Eq for BufferView<B> where B: BufferAccess + ?Sized {}

impl<B> Hash for BufferView<B>
where
B: BufferAccess + ?Sized,
{
fn hash<H: Hasher>(&self, state: &mut H) {
self.handle.hash(state);
self.device().hash(state);
}
}
crate::impl_id_counter!(BufferView<B: BufferAccess + ?Sized>);

/// Parameters to create a new `BufferView`.
#[derive(Clone, Debug)]
Expand Down
40 changes: 8 additions & 32 deletions vulkano/src/command_buffer/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ use std::{
cell::Cell,
error::Error,
fmt::{Display, Error as FmtError, Formatter},
hash::{Hash, Hasher},
marker::PhantomData,
mem::MaybeUninit,
num::NonZeroU64,
ptr,
sync::Arc,
};
Expand All @@ -35,6 +35,7 @@ use std::{
pub struct CommandPool {
handle: ash::vk::CommandPool,
device: Arc<Device>,
id: NonZeroU64,

queue_family_index: u32,
_transient: bool,
Expand Down Expand Up @@ -62,6 +63,7 @@ impl CommandPool {
Ok(CommandPool {
handle,
device,
id: Self::next_id(),
queue_family_index,
_transient: transient,
_reset_command_buffer: reset_command_buffer,
Expand Down Expand Up @@ -91,6 +93,7 @@ impl CommandPool {
CommandPool {
handle,
device,
id: Self::next_id(),
queue_family_index,
_transient: transient,
_reset_command_buffer: reset_command_buffer,
Expand Down Expand Up @@ -231,7 +234,7 @@ impl CommandPool {
Ok(out.into_iter().map(move |command_buffer| CommandPoolAlloc {
handle: command_buffer,
device: device.clone(),

id: CommandPoolAlloc::next_id(),
level,
}))
}
Expand Down Expand Up @@ -336,21 +339,7 @@ unsafe impl DeviceOwned for CommandPool {
}
}

impl PartialEq for CommandPool {
#[inline]
fn eq(&self, other: &Self) -> bool {
self.handle == other.handle && self.device() == other.device()
}
}

impl Eq for CommandPool {}

impl Hash for CommandPool {
fn hash<H: Hasher>(&self, state: &mut H) {
self.handle.hash(state);
self.device().hash(state);
}
}
crate::impl_id_counter!(CommandPool);

/// Error that can happen when creating a `CommandPool`.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
Expand Down Expand Up @@ -468,6 +457,7 @@ impl Default for CommandBufferAllocateInfo {
pub struct CommandPoolAlloc {
handle: ash::vk::CommandBuffer,
device: Arc<Device>,
id: NonZeroU64,
level: CommandBufferLevel,
}

Expand Down Expand Up @@ -495,21 +485,7 @@ unsafe impl DeviceOwned for CommandPoolAlloc {
}
}

impl PartialEq for CommandPoolAlloc {
#[inline]
fn eq(&self, other: &Self) -> bool {
self.handle == other.handle && self.device() == other.device()
}
}

impl Eq for CommandPoolAlloc {}

impl Hash for CommandPoolAlloc {
fn hash<H: Hasher>(&self, state: &mut H) {
self.handle.hash(state);
self.device().hash(state);
}
}
crate::impl_id_counter!(CommandPoolAlloc);

/// Error that can happen when trimming command pools.
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
Expand Down
25 changes: 5 additions & 20 deletions vulkano/src/descriptor_set/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ use std::{
collections::BTreeMap,
error::Error,
fmt::{Display, Error as FmtError, Formatter},
hash::{Hash, Hasher},
mem::MaybeUninit,
num::NonZeroU64,
ptr,
sync::Arc,
};
Expand All @@ -34,6 +34,7 @@ use std::{
pub struct DescriptorSetLayout {
handle: ash::vk::DescriptorSetLayout,
device: Arc<Device>,
id: NonZeroU64,

bindings: BTreeMap<u32, DescriptorSetLayoutBinding>,
push_descriptor: bool,
Expand All @@ -60,10 +61,9 @@ impl DescriptorSetLayout {
Ok(Arc::new(DescriptorSetLayout {
handle,
device,

id: Self::next_id(),
bindings,
push_descriptor,

descriptor_counts,
}))
}
Expand Down Expand Up @@ -98,10 +98,9 @@ impl DescriptorSetLayout {
Arc::new(DescriptorSetLayout {
handle,
device,

id: Self::next_id(),
bindings,
push_descriptor,

descriptor_counts,
})
}
Expand Down Expand Up @@ -453,21 +452,7 @@ unsafe impl DeviceOwned for DescriptorSetLayout {
}
}

impl PartialEq for DescriptorSetLayout {
#[inline]
fn eq(&self, other: &Self) -> bool {
self.handle == other.handle && self.device() == other.device()
}
}

impl Eq for DescriptorSetLayout {}

impl Hash for DescriptorSetLayout {
fn hash<H: Hasher>(&self, state: &mut H) {
self.handle.hash(state);
self.device().hash(state);
}
}
crate::impl_id_counter!(DescriptorSetLayout);

/// Error related to descriptor set layout.
#[derive(Debug, Clone, PartialEq, Eq)]
Expand Down
5 changes: 2 additions & 3 deletions vulkano/src/descriptor_set/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,16 +141,15 @@ pub unsafe trait DescriptorSet: DeviceOwned + Send + Sync {
impl PartialEq for dyn DescriptorSet {
#[inline]
fn eq(&self, other: &Self) -> bool {
self.inner().handle() == other.inner().handle() && self.device() == other.device()
self.inner() == other.inner()
}
}

impl Eq for dyn DescriptorSet {}

impl Hash for dyn DescriptorSet {
fn hash<H: Hasher>(&self, state: &mut H) {
self.inner().handle().hash(state);
self.device().hash(state);
self.inner().hash(state);
}
}

Expand Down
5 changes: 2 additions & 3 deletions vulkano/src/descriptor_set/persistent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ where
P: DescriptorSetAlloc,
{
fn eq(&self, other: &Self) -> bool {
self.inner().handle() == other.inner().handle() && self.device() == other.device()
self.inner() == other.inner()
}
}

Expand All @@ -144,7 +144,6 @@ where
P: DescriptorSetAlloc,
{
fn hash<H: Hasher>(&self, state: &mut H) {
self.inner().handle().hash(state);
self.device().hash(state);
self.inner().hash(state);
}
}
21 changes: 5 additions & 16 deletions vulkano/src/descriptor_set/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ use std::{
cell::Cell,
error::Error,
fmt::{Display, Error as FmtError, Formatter},
hash::{Hash, Hasher},
marker::PhantomData,
mem::MaybeUninit,
num::NonZeroU64,
ptr,
sync::Arc,
};
Expand All @@ -36,6 +36,7 @@ use std::{
pub struct DescriptorPool {
handle: ash::vk::DescriptorPool,
device: Arc<Device>,
id: NonZeroU64,

max_sets: u32,
pool_sizes: HashMap<DescriptorType, u32>,
Expand Down Expand Up @@ -115,6 +116,7 @@ impl DescriptorPool {
Ok(DescriptorPool {
handle,
device,
id: Self::next_id(),
max_sets,
pool_sizes,
can_free_descriptor_sets,
Expand Down Expand Up @@ -144,6 +146,7 @@ impl DescriptorPool {
DescriptorPool {
handle,
device,
id: Self::next_id(),
max_sets,
pool_sizes,
can_free_descriptor_sets,
Expand Down Expand Up @@ -343,21 +346,7 @@ unsafe impl DeviceOwned for DescriptorPool {
}
}

impl PartialEq for DescriptorPool {
#[inline]
fn eq(&self, other: &Self) -> bool {
self.handle == other.handle && self.device() == other.device()
}
}

impl Eq for DescriptorPool {}

impl Hash for DescriptorPool {
fn hash<H: Hasher>(&self, state: &mut H) {
self.handle.hash(state);
self.device().hash(state);
}
}
crate::impl_id_counter!(DescriptorPool);

/// Parameters to create a new `UnsafeDescriptorPool`.
#[derive(Clone, Debug)]
Expand Down
Loading

0 comments on commit 118b5b2

Please sign in to comment.