Add homegrown IDs for Vulkan objects (#2054)

This commit is contained in:
marc0246 2022-10-29 19:32:43 +02:00 committed by GitHub
parent c6e01446ac
commit 118b5b289b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
31 changed files with 283 additions and 654 deletions

View File

@ -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,
@ -48,6 +49,7 @@ use std::{
pub struct RawBuffer {
handle: ash::vk::Buffer,
device: Arc<Device>,
id: NonZeroU64,
flags: BufferCreateFlags,
size: DeviceSize,
@ -324,13 +326,12 @@ impl RawBuffer {
RawBuffer {
handle,
device,
id: Self::next_id(),
flags,
size,
usage,
sharing,
external_memory_handle_types,
memory_requirements,
}
}
@ -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)]

View File

@ -59,6 +59,7 @@ use std::{
fmt::{Display, Error as FmtError, Formatter},
hash::{Hash, Hasher},
mem::MaybeUninit,
num::NonZeroU64,
ops::Range,
ptr,
sync::Arc,
@ -73,6 +74,7 @@ where
{
handle: ash::vk::BufferView,
buffer: Arc<B>,
id: NonZeroU64,
format: Option<Format>,
format_features: FormatFeatures,
@ -233,7 +235,7 @@ where
Ok(Arc::new(BufferView {
handle,
buffer,
id: Self::next_id(),
format: Some(format),
format_features,
range: 0..size,
@ -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)]

View File

@ -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,
};
@ -35,6 +35,7 @@ use std::{
pub struct CommandPool {
handle: ash::vk::CommandPool,
device: Arc<Device>,
id: NonZeroU64,
queue_family_index: u32,
_transient: bool,
@ -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,
@ -91,6 +93,7 @@ impl CommandPool {
CommandPool {
handle,
device,
id: Self::next_id(),
queue_family_index,
_transient: transient,
_reset_command_buffer: reset_command_buffer,
@ -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,
}))
}
@ -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)]
@ -468,6 +457,7 @@ impl Default for CommandBufferAllocateInfo {
pub struct CommandPoolAlloc {
handle: ash::vk::CommandBuffer,
device: Arc<Device>,
id: NonZeroU64,
level: CommandBufferLevel,
}
@ -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)]

View File

@ -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,
};
@ -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,
@ -60,10 +61,9 @@ impl DescriptorSetLayout {
Ok(Arc::new(DescriptorSetLayout {
handle,
device,
id: Self::next_id(),
bindings,
push_descriptor,
descriptor_counts,
}))
}
@ -98,10 +98,9 @@ impl DescriptorSetLayout {
Arc::new(DescriptorSetLayout {
handle,
device,
id: Self::next_id(),
bindings,
push_descriptor,
descriptor_counts,
})
}
@ -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)]

View File

@ -141,7 +141,7 @@ 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()
}
}
@ -149,8 +149,7 @@ 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);
}
}

View File

@ -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()
}
}
@ -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);
}
}

View File

@ -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,
};
@ -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>,
@ -115,6 +116,7 @@ impl DescriptorPool {
Ok(DescriptorPool {
handle,
device,
id: Self::next_id(),
max_sets,
pool_sizes,
can_free_descriptor_sets,
@ -144,6 +146,7 @@ impl DescriptorPool {
DescriptorPool {
handle,
device,
id: Self::next_id(),
max_sets,
pool_sizes,
can_free_descriptor_sets,
@ -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)]

View File

@ -254,7 +254,7 @@ unsafe impl DeviceOwned for SingleLayoutDescSet {
impl PartialEq for SingleLayoutDescSet {
#[inline]
fn eq(&self, other: &Self) -> bool {
self.inner().handle() == other.inner().handle() && self.device() == other.device()
self.inner() == other.inner()
}
}
@ -262,8 +262,7 @@ impl Eq for SingleLayoutDescSet {}
impl Hash for SingleLayoutDescSet {
fn hash<H: Hasher>(&self, state: &mut H) {
self.inner().handle().hash(state);
self.device().hash(state);
self.inner().hash(state);
}
}
@ -500,7 +499,7 @@ unsafe impl DeviceOwned for SingleLayoutVariableDescSet {
impl PartialEq for SingleLayoutVariableDescSet {
#[inline]
fn eq(&self, other: &Self) -> bool {
self.inner().handle() == other.inner().handle() && self.device() == other.device()
self.inner() == other.inner()
}
}
@ -508,7 +507,6 @@ impl Eq for SingleLayoutVariableDescSet {}
impl Hash for SingleLayoutVariableDescSet {
fn hash<H: Hasher>(&self, state: &mut H) {
self.inner().handle().hash(state);
self.device().hash(state);
self.inner().hash(state);
}
}

View File

@ -20,6 +20,7 @@ use crate::{
use smallvec::SmallVec;
use std::{
fmt::{Debug, Error as FmtError, Formatter},
num::NonZeroU64,
ptr,
};
@ -27,14 +28,20 @@ use std::{
///
/// Contrary to most other objects in this library, this one doesn't free itself automatically and
/// doesn't hold the pool or the device it is associated to.
/// Instead it is an object meant to be used with the `UnsafeDescriptorPool`.
/// Instead it is an object meant to be used with the [`DescriptorPool`].
///
/// [`DescriptorPool`]: super::pool::DescriptorPool
pub struct UnsafeDescriptorSet {
handle: ash::vk::DescriptorSet,
id: NonZeroU64,
}
impl UnsafeDescriptorSet {
pub(crate) fn new(handle: ash::vk::DescriptorSet) -> Self {
Self { handle }
Self {
handle,
id: Self::next_id(),
}
}
/// Modifies a descriptor set. Doesn't check that the writes or copies are correct, and
@ -121,3 +128,5 @@ impl Debug for UnsafeDescriptorSet {
write!(f, "<Vulkan descriptor set {:?}>", self.handle)
}
}
crate::impl_id_counter!(UnsafeDescriptorSet);

View File

@ -125,8 +125,8 @@ use std::{
ffi::CString,
fmt::{Display, Error as FmtError, Formatter},
fs::File,
hash::{Hash, Hasher},
mem::MaybeUninit,
num::NonZeroU64,
ops::Deref,
ptr,
sync::{
@ -146,6 +146,7 @@ mod queue;
pub struct Device {
handle: ash::vk::Device,
physical_device: Arc<PhysicalDevice>,
id: NonZeroU64,
// The highest version that is supported for this device.
// This is the minimum of Instance::max_api_version and PhysicalDevice::api_version.
@ -406,6 +407,7 @@ impl Device {
let device = Arc::new(Device {
handle,
physical_device,
id: Self::next_id(),
api_version,
fns,
enabled_extensions,
@ -643,21 +645,7 @@ unsafe impl VulkanObject for Device {
}
}
impl PartialEq for Device {
#[inline]
fn eq(&self, other: &Self) -> bool {
self.handle == other.handle && self.physical_device == other.physical_device
}
}
impl Eq for Device {}
impl Hash for Device {
fn hash<H: Hasher>(&self, state: &mut H) {
self.handle.hash(state);
self.physical_device.hash(state);
}
}
crate::impl_id_counter!(Device);
/// Error that can be returned when creating a device.
#[derive(Copy, Clone, Debug)]

View File

@ -34,8 +34,8 @@ use bytemuck::cast_slice;
use std::{
error::Error,
fmt::{Debug, Display, Error as FmtError, Formatter},
hash::{Hash, Hasher},
mem::MaybeUninit,
num::NonZeroU64,
ptr,
sync::Arc,
};
@ -65,6 +65,7 @@ use std::{
pub struct PhysicalDevice {
handle: ash::vk::PhysicalDevice,
instance: Arc<Instance>,
id: NonZeroU64,
// Data queried at `PhysicalDevice` creation.
api_version: Version,
@ -131,7 +132,7 @@ impl PhysicalDevice {
Ok(Arc::new(PhysicalDevice {
handle,
instance,
id: Self::next_id(),
api_version,
supported_extensions,
supported_features,
@ -139,7 +140,6 @@ impl PhysicalDevice {
extension_properties,
memory_properties,
queue_family_properties,
external_buffer_properties: OnceCache::new(),
external_fence_properties: OnceCache::new(),
external_semaphore_properties: OnceCache::new(),
@ -2415,21 +2415,7 @@ unsafe impl VulkanObject for PhysicalDevice {
}
}
impl PartialEq for PhysicalDevice {
#[inline]
fn eq(&self, other: &Self) -> bool {
self.handle == other.handle && self.instance == other.instance
}
}
impl Eq for PhysicalDevice {}
impl Hash for PhysicalDevice {
fn hash<H: Hasher>(&self, state: &mut H) {
self.handle.hash(state);
self.instance.hash(state);
}
}
crate::impl_id_counter!(PhysicalDevice);
vulkan_enum! {
/// Type of a physical device.

View File

@ -44,6 +44,7 @@ use std::{
hash::{Hash, Hasher},
iter::{FusedIterator, Peekable},
mem::{size_of_val, MaybeUninit},
num::NonZeroU64,
ops::Range,
ptr,
sync::Arc,
@ -58,6 +59,7 @@ use std::{
pub struct RawImage {
handle: ash::vk::Image,
device: Arc<Device>,
id: NonZeroU64,
flags: ImageCreateFlags,
dimensions: ImageDimensions,
@ -1008,9 +1010,9 @@ impl RawImage {
};
RawImage {
device,
handle,
device,
id: Self::next_id(),
flags,
dimensions,
format,
@ -1023,7 +1025,6 @@ impl RawImage {
stencil_usage,
sharing,
external_memory_handle_types,
memory_requirements,
needs_destruction,
subresource_layout: OnceCache::new(),
@ -1846,21 +1847,7 @@ unsafe impl DeviceOwned for RawImage {
}
}
impl PartialEq for RawImage {
#[inline]
fn eq(&self, other: &Self) -> bool {
self.handle == other.handle && self.device() == other.device()
}
}
impl Eq for RawImage {}
impl Hash for RawImage {
fn hash<H: Hasher>(&self, state: &mut H) {
self.handle.hash(state);
self.device().hash(state);
}
}
crate::impl_id_counter!(RawImage);
/// Parameters to create a new `Image`.
#[derive(Clone, Debug)]

View File

@ -29,6 +29,7 @@ use std::{
fmt::{Debug, Display, Error as FmtError, Formatter},
hash::{Hash, Hasher},
mem::MaybeUninit,
num::NonZeroU64,
ptr,
sync::Arc,
};
@ -41,6 +42,7 @@ where
{
handle: ash::vk::ImageView,
image: Arc<I>,
id: NonZeroU64,
component_mapping: ComponentMapping,
format: Option<Format>,
@ -672,7 +674,7 @@ where
Ok(Arc::new(ImageView {
handle,
image,
id: Self::next_id(),
view_type,
format,
format_features,
@ -680,7 +682,6 @@ where
subresource_range,
usage,
sampler_ycbcr_conversion,
filter_cubic,
filter_cubic_minmax,
}))
@ -782,26 +783,7 @@ where
}
}
impl<I> PartialEq for ImageView<I>
where
I: ImageAccess + ?Sized,
{
fn eq(&self, other: &Self) -> bool {
self.handle == other.handle && self.device() == other.device()
}
}
impl<I> Eq for ImageView<I> where I: ImageAccess + ?Sized {}
impl<I> Hash for ImageView<I>
where
I: ImageAccess + ?Sized,
{
fn hash<H: Hasher>(&self, state: &mut H) {
self.handle.hash(state);
self.device().hash(state);
}
}
crate::impl_id_counter!(ImageView<I: ImageAccess + ?Sized>);
/// Parameters to create a new `ImageView`.
#[derive(Debug)]

View File

@ -97,8 +97,8 @@ use std::{
error::Error,
ffi::{c_void, CString},
fmt::{Debug, Display, Error as FmtError, Formatter},
hash::{Hash, Hasher},
mem::MaybeUninit,
num::NonZeroU64,
panic::{RefUnwindSafe, UnwindSafe},
ptr,
sync::Arc,
@ -260,6 +260,7 @@ mod layers;
pub struct Instance {
handle: ash::vk::Instance,
fns: InstanceFunctions,
id: NonZeroU64,
api_version: Version,
enabled_extensions: InstanceExtensions,
@ -531,7 +532,7 @@ impl Instance {
Ok(Arc::new(Instance {
handle,
fns,
id: Self::next_id(),
api_version,
enabled_extensions,
enabled_layers,
@ -656,26 +657,14 @@ unsafe impl VulkanObject for Instance {
}
}
impl PartialEq for Instance {
#[inline]
fn eq(&self, other: &Self) -> bool {
self.handle == other.handle
}
}
impl Eq for Instance {}
impl Hash for Instance {
fn hash<H: Hasher>(&self, state: &mut H) {
self.handle.hash(state);
}
}
crate::impl_id_counter!(Instance);
impl Debug for Instance {
fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), FmtError> {
let Self {
handle,
fns,
id: _,
api_version,
enabled_extensions,
enabled_layers,

View File

@ -381,3 +381,47 @@ pub(crate) struct RequirementNotMet {
/// syntax from being used.
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] // add traits as needed
pub struct NonExhaustive(pub(crate) ());
macro_rules! impl_id_counter {
($type:ident $(< $($param:ident $(: $bound:ident $(+ $bounds:ident)* )?),+ >)?) => {
$crate::impl_id_counter!(
@inner $type $(< $($param),+ >)?, $( $($param $(: $bound $(+ $bounds)* )?),+)?
);
};
($type:ident $(< $($param:ident $(: $bound:ident $(+ $bounds:ident)* )? + ?Sized),+ >)?) => {
$crate::impl_id_counter!(
@inner $type $(< $($param),+ >)?, $( $($param $(: $bound $(+ $bounds)* )? + ?Sized),+)?
);
};
(@inner $type:ident $(< $($param:ident),+ >)?, $($bounds:tt)*) => {
impl< $($bounds)* > $type $(< $($param),+ >)? {
fn next_id() -> std::num::NonZeroU64 {
use std::{
num::NonZeroU64,
sync::atomic::{AtomicU64, Ordering},
};
static COUNTER: AtomicU64 = AtomicU64::new(1);
NonZeroU64::new(COUNTER.fetch_add(1, Ordering::Relaxed)).expect("ID overflow")
}
}
impl< $($bounds)* > PartialEq for $type $(< $($param),+ >)? {
#[inline]
fn eq(&self, other: &Self) -> bool {
self.id == other.id
}
}
impl< $($bounds)* > Eq for $type $(< $($param),+ >)? {}
impl< $($bounds)* > std::hash::Hash for $type $(< $($param),+ >)? {
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
self.id.hash(state);
}
}
};
}
pub(crate) use impl_id_counter;

View File

@ -18,8 +18,8 @@ use std::{
ffi::c_void,
fmt::{Display, Error as FmtError, Formatter},
fs::File,
hash::{Hash, Hasher},
mem::MaybeUninit,
num::NonZeroU64,
ops::Range,
ptr, slice,
sync::{atomic::Ordering, Arc},
@ -52,6 +52,7 @@ use std::{
pub struct DeviceMemory {
handle: ash::vk::DeviceMemory,
device: Arc<Device>,
id: NonZeroU64,
allocation_size: DeviceSize,
memory_type_index: u32,
@ -105,6 +106,7 @@ impl DeviceMemory {
DeviceMemory {
handle,
device,
id: Self::next_id(),
allocation_size,
memory_type_index,
export_handle_types,
@ -532,6 +534,7 @@ impl DeviceMemory {
Ok(DeviceMemory {
handle,
device,
id: Self::next_id(),
allocation_size,
memory_type_index,
export_handle_types,
@ -701,21 +704,7 @@ unsafe impl DeviceOwned for DeviceMemory {
}
}
impl PartialEq for DeviceMemory {
#[inline]
fn eq(&self, other: &Self) -> bool {
self.handle == other.handle && self.device() == other.device()
}
}
impl Eq for DeviceMemory {}
impl Hash for DeviceMemory {
fn hash<H: Hasher>(&self, state: &mut H) {
self.handle.hash(state);
self.device.hash(state);
}
}
crate::impl_id_counter!(DeviceMemory);
/// Parameters to allocate a new `DeviceMemory`.
#[derive(Clone, Debug)]

View File

@ -42,6 +42,7 @@ use std::{
fmt::{Debug, Display, Error as FmtError, Formatter},
mem,
mem::MaybeUninit,
num::NonZeroU64,
ptr,
sync::Arc,
};
@ -57,6 +58,7 @@ use std::{
pub struct ComputePipeline {
handle: ash::vk::Pipeline,
device: Arc<Device>,
id: NonZeroU64,
layout: Arc<PipelineLayout>,
descriptor_requirements: HashMap<(u32, u32), DescriptorRequirements>,
num_used_descriptor_sets: u32,
@ -232,6 +234,7 @@ impl ComputePipeline {
Ok(Arc::new(ComputePipeline {
handle,
device: device.clone(),
id: Self::next_id(),
layout,
descriptor_requirements,
num_used_descriptor_sets,
@ -278,14 +281,7 @@ impl Debug for ComputePipeline {
}
}
impl PartialEq for ComputePipeline {
#[inline]
fn eq(&self, other: &Self) -> bool {
self.handle() == other.handle()
}
}
impl Eq for ComputePipeline {}
crate::impl_id_counter!(ComputePipeline);
unsafe impl VulkanObject for ComputePipeline {
type Handle = ash::vk::Pipeline;

View File

@ -394,12 +394,12 @@ where
Ok(Arc::new(GraphicsPipeline {
handle,
device,
id: GraphicsPipeline::next_id(),
layout: pipeline_layout,
render_pass: render_pass.take().expect("Missing render pass"),
shaders,
descriptor_requirements,
num_used_descriptor_sets,
vertex_input_state, // Can be None if there's a mesh shader, but we don't support that yet
input_assembly_state, // Can be None if there's a mesh shader, but we don't support that yet
tessellation_state: has.tessellation_state.then_some(tessellation_state),

View File

@ -73,7 +73,7 @@ use crate::{
use ahash::HashMap;
use std::{
fmt::{Debug, Error as FmtError, Formatter},
hash::{Hash, Hasher},
num::NonZeroU64,
ptr,
sync::Arc,
};
@ -100,6 +100,7 @@ pub mod viewport;
pub struct GraphicsPipeline {
handle: ash::vk::Pipeline,
device: Arc<Device>,
id: NonZeroU64,
layout: Arc<PipelineLayout>,
render_pass: PipelineRenderPassType,
@ -293,18 +294,4 @@ impl Drop for GraphicsPipeline {
}
}
impl PartialEq for GraphicsPipeline {
#[inline]
fn eq(&self, other: &Self) -> bool {
self.device == other.device && self.handle == other.handle
}
}
impl Eq for GraphicsPipeline {}
impl Hash for GraphicsPipeline {
fn hash<H: Hasher>(&self, state: &mut H) {
self.handle.hash(state);
self.device.hash(state);
}
}
crate::impl_id_counter!(GraphicsPipeline);

View File

@ -73,8 +73,8 @@ use smallvec::SmallVec;
use std::{
error::Error,
fmt::{Display, Error as FmtError, Formatter},
hash::{Hash, Hasher},
mem::MaybeUninit,
num::NonZeroU64,
ptr,
sync::Arc,
};
@ -84,6 +84,7 @@ use std::{
pub struct PipelineLayout {
handle: ash::vk::PipelineLayout,
device: Arc<Device>,
id: NonZeroU64,
set_layouts: Vec<Arc<DescriptorSetLayout>>,
push_constant_ranges: Vec<PushConstantRange>,
@ -129,6 +130,7 @@ impl PipelineLayout {
Ok(Arc::new(PipelineLayout {
handle,
device,
id: Self::next_id(),
set_layouts,
push_constant_ranges,
push_constant_ranges_disjoint,
@ -548,6 +550,7 @@ impl PipelineLayout {
Arc::new(PipelineLayout {
handle,
device,
id: Self::next_id(),
set_layouts,
push_constant_ranges,
push_constant_ranges_disjoint,
@ -690,21 +693,7 @@ unsafe impl DeviceOwned for PipelineLayout {
}
}
impl PartialEq for PipelineLayout {
#[inline]
fn eq(&self, other: &Self) -> bool {
self.handle == other.handle && self.device() == other.device()
}
}
impl Eq for PipelineLayout {}
impl Hash for PipelineLayout {
fn hash<H: Hasher>(&self, state: &mut H) {
self.handle.hash(state);
self.device().hash(state);
}
}
crate::impl_id_counter!(PipelineLayout);
/// Error that can happen when creating a pipeline layout.
#[derive(Clone, Debug, PartialEq, Eq)]

View File

@ -22,8 +22,8 @@ use std::{
error::Error,
ffi::c_void,
fmt::{Display, Error as FmtError, Formatter},
hash::{Hash, Hasher},
mem::{size_of_val, MaybeUninit},
num::NonZeroU64,
ops::Range,
ptr,
sync::Arc,
@ -34,6 +34,7 @@ use std::{
pub struct QueryPool {
handle: ash::vk::QueryPool,
device: Arc<Device>,
id: NonZeroU64,
query_type: QueryType,
query_count: u32,
@ -98,7 +99,7 @@ impl QueryPool {
Ok(Arc::new(QueryPool {
handle,
device,
id: Self::next_id(),
query_type,
query_count,
}))
@ -125,6 +126,7 @@ impl QueryPool {
Arc::new(QueryPool {
handle,
device,
id: Self::next_id(),
query_type,
query_count,
})
@ -195,21 +197,7 @@ unsafe impl DeviceOwned for QueryPool {
}
}
impl PartialEq for QueryPool {
#[inline]
fn eq(&self, other: &Self) -> bool {
self.handle == other.handle && self.device() == other.device()
}
}
impl Eq for QueryPool {}
impl Hash for QueryPool {
fn hash<H: Hasher>(&self, state: &mut H) {
self.handle.hash(state);
self.device().hash(state);
}
}
crate::impl_id_counter!(QueryPool);
/// Parameters to create a new `QueryPool`.
#[derive(Clone, Debug)]

View File

@ -18,8 +18,8 @@ use smallvec::SmallVec;
use std::{
error::Error,
fmt::{Display, Error as FmtError, Formatter},
hash::{Hash, Hasher},
mem::MaybeUninit,
num::NonZeroU64,
ops::Range,
ptr,
sync::Arc,
@ -53,6 +53,7 @@ use std::{
pub struct Framebuffer {
handle: ash::vk::Framebuffer,
render_pass: Arc<RenderPass>,
id: NonZeroU64,
attachments: Vec<Arc<dyn ImageViewAbstract>>,
extent: [u32; 2],
@ -323,7 +324,7 @@ impl Framebuffer {
Ok(Arc::new(Framebuffer {
handle,
render_pass,
id: Self::next_id(),
attachments,
extent,
layers,
@ -352,7 +353,7 @@ impl Framebuffer {
Arc::new(Framebuffer {
handle,
render_pass,
id: Self::next_id(),
attachments,
extent,
layers,
@ -418,21 +419,7 @@ unsafe impl DeviceOwned for Framebuffer {
}
}
impl PartialEq for Framebuffer {
#[inline]
fn eq(&self, other: &Self) -> bool {
self.handle == other.handle && self.device() == other.device()
}
}
impl Eq for Framebuffer {}
impl Hash for Framebuffer {
fn hash<H: Hasher>(&self, state: &mut H) {
self.handle.hash(state);
self.device().hash(state);
}
}
crate::impl_id_counter!(Framebuffer);
/// Parameters to create a new `Framebuffer`.
#[derive(Clone, Debug)]

View File

@ -38,13 +38,7 @@ use crate::{
sync::{AccessFlags, PipelineStages},
Version, VulkanObject,
};
use std::{
cmp::max,
hash::{Hash, Hasher},
mem::MaybeUninit,
ptr,
sync::Arc,
};
use std::{cmp::max, mem::MaybeUninit, num::NonZeroU64, ptr, sync::Arc};
#[macro_use]
mod macros;
@ -108,6 +102,7 @@ mod framebuffer;
pub struct RenderPass {
handle: ash::vk::RenderPass,
device: Arc<Device>,
id: NonZeroU64,
attachments: Vec<AttachmentDescription>,
subpasses: Vec<SubpassDescription>,
@ -154,12 +149,11 @@ impl RenderPass {
Ok(Arc::new(RenderPass {
handle,
device,
id: Self::next_id(),
attachments,
subpasses,
dependencies,
correlated_view_masks,
granularity,
views_used,
}))
@ -223,12 +217,11 @@ impl RenderPass {
Ok(Arc::new(RenderPass {
handle,
device,
id: Self::next_id(),
attachments,
subpasses,
dependencies,
correlated_view_masks,
granularity,
views_used,
}))
@ -294,6 +287,7 @@ impl RenderPass {
let Self {
handle: _,
device: _,
id: _,
attachments: attachments1,
subpasses: subpasses1,
dependencies: dependencies1,
@ -304,6 +298,7 @@ impl RenderPass {
let Self {
handle: _,
device: _,
id: _,
attachments: attachments2,
subpasses: subpasses2,
dependencies: dependencies2,
@ -537,21 +532,7 @@ unsafe impl DeviceOwned for RenderPass {
}
}
impl PartialEq for RenderPass {
#[inline]
fn eq(&self, other: &Self) -> bool {
self.handle == other.handle && self.device() == other.device()
}
}
impl Eq for RenderPass {}
impl Hash for RenderPass {
fn hash<H: Hasher>(&self, state: &mut H) {
self.handle.hash(state);
self.device.hash(state);
}
}
crate::impl_id_counter!(RenderPass);
/// Represents a subpass within a `RenderPass` object.
///

View File

@ -58,8 +58,8 @@ use crate::{
use std::{
error::Error,
fmt::{Display, Error as FmtError, Formatter},
hash::{Hash, Hasher},
mem::MaybeUninit,
num::NonZeroU64,
ops::RangeInclusive,
ptr,
sync::Arc,
@ -98,6 +98,7 @@ use std::{
pub struct Sampler {
handle: ash::vk::Sampler,
device: Arc<Device>,
id: NonZeroU64,
address_mode: [SamplerAddressMode; 3],
anisotropy: Option<f32>,
@ -438,7 +439,7 @@ impl Sampler {
Ok(Arc::new(Sampler {
handle,
device,
id: Self::next_id(),
address_mode,
anisotropy,
border_color: address_mode
@ -488,7 +489,7 @@ impl Sampler {
Arc::new(Sampler {
handle,
device,
id: Self::next_id(),
address_mode,
anisotropy,
border_color: address_mode
@ -758,21 +759,7 @@ unsafe impl DeviceOwned for Sampler {
}
}
impl PartialEq for Sampler {
#[inline]
fn eq(&self, other: &Self) -> bool {
self.handle == other.handle && self.device() == other.device()
}
}
impl Eq for Sampler {}
impl Hash for Sampler {
fn hash<H: Hasher>(&self, state: &mut H) {
self.handle.hash(state);
self.device().hash(state);
}
}
crate::impl_id_counter!(Sampler);
/// Error that can happen when creating an instance.
#[derive(Clone, Debug, PartialEq)]

View File

@ -99,8 +99,8 @@ use crate::{
use std::{
error::Error,
fmt::{Display, Error as FmtError, Formatter},
hash::{Hash, Hasher},
mem::MaybeUninit,
num::NonZeroU64,
ptr,
sync::Arc,
};
@ -110,6 +110,7 @@ use std::{
pub struct SamplerYcbcrConversion {
handle: ash::vk::SamplerYcbcrConversion,
device: Arc<Device>,
id: NonZeroU64,
format: Option<Format>,
ycbcr_model: SamplerYcbcrModelConversion,
@ -350,6 +351,7 @@ impl SamplerYcbcrConversion {
Ok(Arc::new(SamplerYcbcrConversion {
handle,
device,
id: Self::next_id(),
format: Some(format),
ycbcr_model,
ycbcr_range,
@ -387,6 +389,7 @@ impl SamplerYcbcrConversion {
Arc::new(SamplerYcbcrConversion {
handle,
device,
id: Self::next_id(),
format,
ycbcr_model,
ycbcr_range,
@ -446,6 +449,7 @@ impl SamplerYcbcrConversion {
let &Self {
handle: _,
device: _,
id: _,
format,
ycbcr_model,
ycbcr_range,
@ -499,21 +503,7 @@ unsafe impl DeviceOwned for SamplerYcbcrConversion {
}
}
impl PartialEq for SamplerYcbcrConversion {
#[inline]
fn eq(&self, other: &Self) -> bool {
self.handle == other.handle && self.device() == other.device()
}
}
impl Eq for SamplerYcbcrConversion {}
impl Hash for SamplerYcbcrConversion {
fn hash<H: Hasher>(&self, state: &mut H) {
self.handle.hash(state);
self.device().hash(state);
}
}
crate::impl_id_counter!(SamplerYcbcrConversion);
/// Error that can happen when creating a `SamplerYcbcrConversion`.
#[derive(Clone, Debug, PartialEq, Eq)]

View File

@ -19,7 +19,7 @@
use crate::{
descriptor_set::layout::DescriptorType,
device::Device,
device::{Device, DeviceOwned},
format::{Format, NumericType},
image::view::ImageViewType,
macros::{vulkan_bitflags, vulkan_enum},
@ -36,6 +36,7 @@ use std::{
fmt::{Display, Error as FmtError, Formatter},
mem,
mem::MaybeUninit,
num::NonZeroU64,
ptr,
sync::Arc,
};
@ -53,6 +54,7 @@ include!(concat!(env!("OUT_DIR"), "/spirv_reqs.rs"));
pub struct ShaderModule {
handle: ash::vk::ShaderModule,
device: Arc<Device>,
id: NonZeroU64,
entry_points: HashMap<String, HashMap<ExecutionModel, EntryPointInfo>>,
}
@ -189,6 +191,7 @@ impl ShaderModule {
Ok(Arc::new(ShaderModule {
handle,
device,
id: Self::next_id(),
entry_points,
}))
}
@ -257,15 +260,6 @@ impl ShaderModule {
}
}
unsafe impl VulkanObject for ShaderModule {
type Handle = ash::vk::ShaderModule;
#[inline]
fn handle(&self) -> Self::Handle {
self.handle
}
}
impl Drop for ShaderModule {
#[inline]
fn drop(&mut self) {
@ -276,6 +270,24 @@ impl Drop for ShaderModule {
}
}
unsafe impl VulkanObject for ShaderModule {
type Handle = ash::vk::ShaderModule;
#[inline]
fn handle(&self) -> Self::Handle {
self.handle
}
}
unsafe impl DeviceOwned for ShaderModule {
#[inline]
fn device(&self) -> &Arc<Device> {
&self.device
}
}
crate::impl_id_counter!(ShaderModule);
/// Error that can happen when creating a new shader module.
#[derive(Clone, Debug)]
pub enum ShaderCreationError {

View File

@ -28,8 +28,8 @@ use std::{
any::Any,
error::Error,
fmt::{Debug, Display, Error as FmtError, Formatter},
hash::{Hash, Hasher},
mem::MaybeUninit,
num::NonZeroU64,
ptr,
sync::{atomic::AtomicBool, Arc},
};
@ -40,6 +40,7 @@ use std::{
pub struct Surface {
handle: ash::vk::SurfaceKHR,
instance: Arc<Instance>,
id: NonZeroU64,
api: SurfaceApi,
object: Option<Arc<dyn Any + Send + Sync>>,
// If true, a swapchain has been associated to this surface, and that any new swapchain
@ -75,13 +76,12 @@ impl Surface {
Surface {
handle,
instance,
id: Self::next_id(),
api,
object,
has_swapchain: AtomicBool::new(false),
#[cfg(target_os = "ios")]
metal_layer: IOSMetalLayer::new(std::ptr::null_mut(), std::ptr::null_mut()),
surface_formats: OnceCache::new(),
surface_present_modes: OnceCache::new(),
surface_support: OnceCache::new(),
@ -139,20 +139,12 @@ impl Surface {
output.assume_init()
};
Ok(Arc::new(Surface {
handle,
Ok(Arc::new(Self::from_handle(
instance,
api: SurfaceApi::Headless,
handle,
SurfaceApi::Headless,
object,
has_swapchain: AtomicBool::new(false),
#[cfg(target_os = "ios")]
metal_layer: IOSMetalLayer::new(std::ptr::null_mut(), std::ptr::null_mut()),
surface_formats: OnceCache::new(),
surface_present_modes: OnceCache::new(),
surface_support: OnceCache::new(),
}))
)))
}
/// Creates a `Surface` from a `DisplayPlane`.
@ -236,20 +228,12 @@ impl Surface {
output.assume_init()
};
Ok(Arc::new(Surface {
Ok(Arc::new(Self::from_handle(
instance.clone(),
handle,
instance: instance.clone(),
api: SurfaceApi::DisplayPlane,
object: None,
has_swapchain: AtomicBool::new(false),
#[cfg(target_os = "ios")]
metal_layer: IOSMetalLayer::new(std::ptr::null_mut(), std::ptr::null_mut()),
surface_formats: OnceCache::new(),
surface_present_modes: OnceCache::new(),
surface_support: OnceCache::new(),
}))
SurfaceApi::DisplayPlane,
None,
)))
}
/// Creates a `Surface` from an Android window.
@ -315,20 +299,12 @@ impl Surface {
output.assume_init()
};
Ok(Arc::new(Surface {
handle,
Ok(Arc::new(Self::from_handle(
instance,
api: SurfaceApi::Android,
handle,
SurfaceApi::Android,
object,
has_swapchain: AtomicBool::new(false),
#[cfg(target_os = "ios")]
metal_layer: IOSMetalLayer::new(std::ptr::null_mut(), std::ptr::null_mut()),
surface_formats: OnceCache::new(),
surface_present_modes: OnceCache::new(),
surface_support: OnceCache::new(),
}))
)))
}
/// Creates a `Surface` from a DirectFB surface.
@ -404,20 +380,12 @@ impl Surface {
output.assume_init()
};
Ok(Arc::new(Surface {
handle,
Ok(Arc::new(Self::from_handle(
instance,
api: SurfaceApi::DirectFB,
handle,
SurfaceApi::DirectFB,
object,
has_swapchain: AtomicBool::new(false),
#[cfg(target_os = "ios")]
metal_layer: IOSMetalLayer::new(std::ptr::null_mut(), std::ptr::null_mut()),
surface_formats: OnceCache::new(),
surface_present_modes: OnceCache::new(),
surface_support: OnceCache::new(),
}))
)))
}
/// Creates a `Surface` from an Fuchsia ImagePipe.
@ -488,20 +456,12 @@ impl Surface {
output.assume_init()
};
Ok(Arc::new(Surface {
handle,
Ok(Arc::new(Self::from_handle(
instance,
api: SurfaceApi::FuchsiaImagePipe,
handle,
SurfaceApi::FuchsiaImagePipe,
object,
has_swapchain: AtomicBool::new(false),
#[cfg(target_os = "ios")]
metal_layer: IOSMetalLayer::new(std::ptr::null_mut(), std::ptr::null_mut()),
surface_formats: OnceCache::new(),
surface_present_modes: OnceCache::new(),
surface_support: OnceCache::new(),
}))
)))
}
/// Creates a `Surface` from a Google Games Platform stream descriptor.
@ -572,20 +532,12 @@ impl Surface {
output.assume_init()
};
Ok(Arc::new(Surface {
handle,
Ok(Arc::new(Self::from_handle(
instance,
api: SurfaceApi::GgpStreamDescriptor,
handle,
SurfaceApi::GgpStreamDescriptor,
object,
has_swapchain: AtomicBool::new(false),
#[cfg(target_os = "ios")]
metal_layer: IOSMetalLayer::new(std::ptr::null_mut(), std::ptr::null_mut()),
surface_formats: OnceCache::new(),
surface_present_modes: OnceCache::new(),
surface_support: OnceCache::new(),
}))
)))
}
/// Creates a `Surface` from an iOS `UIView`.
@ -658,19 +610,12 @@ impl Surface {
output.assume_init()
};
Ok(Arc::new(Surface {
handle,
Ok(Arc::new(Self::from_handle(
instance,
api: SurfaceApi::Ios,
handle,
SurfaceApi::Ios,
object,
has_swapchain: AtomicBool::new(false),
metal_layer,
surface_formats: OnceCache::new(),
surface_present_modes: OnceCache::new(),
surface_support: OnceCache::new(),
}))
)))
}
/// Creates a `Surface` from a MacOS `NSView`.
@ -743,20 +688,12 @@ impl Surface {
output.assume_init()
};
Ok(Arc::new(Surface {
handle,
Ok(Arc::new(Self::from_handle(
instance,
api: SurfaceApi::MacOs,
handle,
SurfaceApi::MacOs,
object,
has_swapchain: AtomicBool::new(false),
#[cfg(target_os = "ios")]
metal_layer: IOSMetalLayer::new(std::ptr::null_mut(), std::ptr::null_mut()),
surface_formats: OnceCache::new(),
surface_present_modes: OnceCache::new(),
surface_support: OnceCache::new(),
}))
)))
}
/// Creates a `Surface` from a Metal `CAMetalLayer`.
@ -819,20 +756,12 @@ impl Surface {
output.assume_init()
};
Ok(Arc::new(Surface {
handle,
Ok(Arc::new(Self::from_handle(
instance,
api: SurfaceApi::Metal,
handle,
SurfaceApi::Metal,
object,
has_swapchain: AtomicBool::new(false),
#[cfg(target_os = "ios")]
metal_layer: IOSMetalLayer::new(std::ptr::null_mut(), std::ptr::null_mut()),
surface_formats: OnceCache::new(),
surface_present_modes: OnceCache::new(),
surface_support: OnceCache::new(),
}))
)))
}
/// Creates a `Surface` from a QNX Screen window.
@ -908,20 +837,12 @@ impl Surface {
output.assume_init()
};
Ok(Arc::new(Surface {
handle,
Ok(Arc::new(Self::from_handle(
instance,
api: SurfaceApi::Qnx,
handle,
SurfaceApi::Qnx,
object,
has_swapchain: AtomicBool::new(false),
#[cfg(target_os = "ios")]
metal_layer: IOSMetalLayer::new(std::ptr::null_mut(), std::ptr::null_mut()),
surface_formats: OnceCache::new(),
surface_present_modes: OnceCache::new(),
surface_support: OnceCache::new(),
}))
)))
}
/// Creates a `Surface` from a `code:nn::code:vi::code:Layer`.
@ -987,20 +908,12 @@ impl Surface {
output.assume_init()
};
Ok(Arc::new(Surface {
handle,
Ok(Arc::new(Self::from_handle(
instance,
api: SurfaceApi::Vi,
handle,
SurfaceApi::Vi,
object,
has_swapchain: AtomicBool::new(false),
#[cfg(target_os = "ios")]
metal_layer: IOSMetalLayer::new(std::ptr::null_mut(), std::ptr::null_mut()),
surface_formats: OnceCache::new(),
surface_present_modes: OnceCache::new(),
surface_support: OnceCache::new(),
}))
)))
}
/// Creates a `Surface` from a Wayland window.
@ -1078,20 +991,12 @@ impl Surface {
output.assume_init()
};
Ok(Arc::new(Surface {
handle,
Ok(Arc::new(Self::from_handle(
instance,
api: SurfaceApi::Wayland,
handle,
SurfaceApi::Wayland,
object,
has_swapchain: AtomicBool::new(false),
#[cfg(target_os = "ios")]
metal_layer: IOSMetalLayer::new(std::ptr::null_mut(), std::ptr::null_mut()),
surface_formats: OnceCache::new(),
surface_present_modes: OnceCache::new(),
surface_support: OnceCache::new(),
}))
)))
}
/// Creates a `Surface` from a Win32 window.
@ -1169,20 +1074,12 @@ impl Surface {
output.assume_init()
};
Ok(Arc::new(Surface {
handle,
Ok(Arc::new(Self::from_handle(
instance,
api: SurfaceApi::Win32,
handle,
SurfaceApi::Win32,
object,
has_swapchain: AtomicBool::new(false),
#[cfg(target_os = "ios")]
metal_layer: IOSMetalLayer::new(std::ptr::null_mut(), std::ptr::null_mut()),
surface_formats: OnceCache::new(),
surface_present_modes: OnceCache::new(),
surface_support: OnceCache::new(),
}))
)))
}
/// Creates a `Surface` from an XCB window.
@ -1260,20 +1157,12 @@ impl Surface {
output.assume_init()
};
Ok(Arc::new(Surface {
handle,
Ok(Arc::new(Self::from_handle(
instance,
api: SurfaceApi::Xcb,
handle,
SurfaceApi::Xcb,
object,
has_swapchain: AtomicBool::new(false),
#[cfg(target_os = "ios")]
metal_layer: IOSMetalLayer::new(std::ptr::null_mut(), std::ptr::null_mut()),
surface_formats: OnceCache::new(),
surface_present_modes: OnceCache::new(),
surface_support: OnceCache::new(),
}))
)))
}
/// Creates a `Surface` from an Xlib window.
@ -1351,20 +1240,12 @@ impl Surface {
output.assume_init()
};
Ok(Arc::new(Surface {
handle,
Ok(Arc::new(Self::from_handle(
instance,
api: SurfaceApi::Xlib,
handle,
SurfaceApi::Xlib,
object,
has_swapchain: AtomicBool::new(false),
#[cfg(target_os = "ios")]
metal_layer: IOSMetalLayer::new(std::ptr::null_mut(), std::ptr::null_mut()),
surface_formats: OnceCache::new(),
surface_present_modes: OnceCache::new(),
surface_support: OnceCache::new(),
}))
)))
}
/// Returns the instance this surface was created with.
@ -1394,6 +1275,7 @@ impl Surface {
/// its sublayers are not automatically resized, and we must resize
/// it here.
#[cfg(target_os = "ios")]
#[inline]
pub unsafe fn update_ios_sublayer_on_resize(&self) {
use core_graphics_types::geometry::CGRect;
let class = class!(CAMetalLayer);
@ -1405,6 +1287,7 @@ impl Surface {
}
impl Drop for Surface {
#[inline]
fn drop(&mut self) {
unsafe {
let fns = self.instance.fns();
@ -1416,11 +1299,14 @@ impl Drop for Surface {
unsafe impl VulkanObject for Surface {
type Handle = ash::vk::SurfaceKHR;
#[inline]
fn handle(&self) -> Self::Handle {
self.handle
}
}
crate::impl_id_counter!(Surface);
impl Debug for Surface {
fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), FmtError> {
let Self {
@ -1442,22 +1328,8 @@ impl Debug for Surface {
}
}
impl PartialEq for Surface {
fn eq(&self, other: &Self) -> bool {
self.handle == other.handle && self.instance() == other.instance()
}
}
impl Eq for Surface {}
impl Hash for Surface {
fn hash<H: Hasher>(&self, state: &mut H) {
self.handle.hash(state);
self.instance().hash(state);
}
}
unsafe impl SurfaceSwapchainLock for Surface {
#[inline]
fn flag(&self) -> &AtomicBool {
&self.has_swapchain
}

View File

@ -32,7 +32,6 @@ use smallvec::{smallvec, SmallVec};
use std::{
error::Error,
fmt::{Debug, Display, Error as FmtError, Formatter},
hash::{Hash, Hasher},
mem::MaybeUninit,
num::NonZeroU64,
ops::Range,
@ -49,6 +48,7 @@ pub struct Swapchain {
handle: ash::vk::SwapchainKHR,
device: Arc<Device>,
surface: Arc<Surface>,
id: NonZeroU64,
min_image_count: u32,
image_format: Format,
@ -135,7 +135,7 @@ impl Swapchain {
handle,
device,
surface,
id: Self::next_id(),
min_image_count,
image_format: image_format.unwrap(),
image_color_space,
@ -150,7 +150,6 @@ impl Swapchain {
full_screen_exclusive,
win32_monitor,
prev_present_id: Default::default(),
full_screen_exclusive_held: AtomicBool::new(false),
images: image_handles
.iter()
@ -235,7 +234,7 @@ impl Swapchain {
handle,
device: self.device.clone(),
surface: self.surface.clone(),
id: Self::next_id(),
min_image_count,
image_format: image_format.unwrap(),
image_color_space,
@ -250,7 +249,6 @@ impl Swapchain {
full_screen_exclusive,
win32_monitor,
prev_present_id: Default::default(),
full_screen_exclusive_held: AtomicBool::new(full_screen_exclusive_held),
images: image_handles
.iter()
@ -814,6 +812,7 @@ impl Swapchain {
/// and must not already hold full-screen exclusivity. Full-screen exclusivity is held until
/// either the `release_full_screen_exclusive` is called, or if any of the the other `Swapchain`
/// functions return `FullScreenExclusiveLost`.
#[inline]
pub fn acquire_full_screen_exclusive(&self) -> Result<(), FullScreenExclusiveError> {
if self.full_screen_exclusive != FullScreenExclusive::ApplicationControlled {
return Err(FullScreenExclusiveError::NotApplicationControlled);
@ -840,6 +839,7 @@ impl Swapchain {
///
/// The swapchain must have been created with [`FullScreenExclusive::ApplicationControlled`],
/// and must currently hold full-screen exclusivity.
#[inline]
pub fn release_full_screen_exclusive(&self) -> Result<(), FullScreenExclusiveError> {
if self.full_screen_exclusive != FullScreenExclusive::ApplicationControlled {
return Err(FullScreenExclusiveError::NotApplicationControlled);
@ -869,6 +869,7 @@ impl Swapchain {
/// then this function will always return false. If true is returned the swapchain
/// is in `FullScreenExclusive::AppControlled` full-screen exclusivity mode and exclusivity
/// is currently acquired.
#[inline]
pub fn is_full_screen_exclusive(&self) -> bool {
if self.full_screen_exclusive != FullScreenExclusive::ApplicationControlled {
false
@ -901,6 +902,7 @@ impl Swapchain {
}
impl Drop for Swapchain {
#[inline]
fn drop(&mut self) {
unsafe {
let fns = self.device.fns();
@ -917,31 +919,20 @@ impl Drop for Swapchain {
unsafe impl VulkanObject for Swapchain {
type Handle = ash::vk::SwapchainKHR;
#[inline]
fn handle(&self) -> Self::Handle {
self.handle
}
}
unsafe impl DeviceOwned for Swapchain {
#[inline]
fn device(&self) -> &Arc<Device> {
&self.device
}
}
impl PartialEq for Swapchain {
fn eq(&self, other: &Self) -> bool {
self.handle == other.handle && self.device() == other.device()
}
}
impl Eq for Swapchain {}
impl Hash for Swapchain {
fn hash<H: Hasher>(&self, state: &mut H) {
self.handle.hash(state);
self.device().hash(state);
}
}
crate::impl_id_counter!(Swapchain);
impl Debug for Swapchain {
fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), FmtError> {
@ -949,6 +940,7 @@ impl Debug for Swapchain {
handle,
device,
surface,
id: _,
min_image_count,
image_format,
image_color_space,

View File

@ -14,8 +14,8 @@ use crate::{
use std::{
error::Error,
fmt::{Display, Error as FmtError, Formatter},
hash::{Hash, Hasher},
mem::MaybeUninit,
num::NonZeroU64,
ptr,
sync::Arc,
};
@ -30,6 +30,7 @@ use std::{
pub struct Event {
handle: ash::vk::Event,
device: Arc<Device>,
id: NonZeroU64,
must_put_in_pool: bool,
}
@ -74,8 +75,9 @@ impl Event {
};
Ok(Event {
device,
handle,
device,
id: Self::next_id(),
must_put_in_pool: false,
})
}
@ -101,6 +103,7 @@ impl Event {
Event {
handle,
device,
id: Self::next_id(),
must_put_in_pool: true,
}
}
@ -128,8 +131,9 @@ impl Event {
_create_info: EventCreateInfo,
) -> Event {
Event {
device,
handle,
device,
id: Self::next_id(),
must_put_in_pool: false,
}
}
@ -226,21 +230,7 @@ unsafe impl DeviceOwned for Event {
}
}
impl PartialEq for Event {
#[inline]
fn eq(&self, other: &Self) -> bool {
self.handle == other.handle && self.device() == other.device()
}
}
impl Eq for Event {}
impl Hash for Event {
fn hash<H: Hasher>(&self, state: &mut H) {
self.handle.hash(state);
self.device().hash(state);
}
}
crate::impl_id_counter!(Event);
/// Parameters to create a new `Event`.
#[derive(Clone, Debug)]

View File

@ -18,8 +18,8 @@ use std::{
error::Error,
fmt::{Display, Error as FmtError, Formatter},
fs::File,
hash::{Hash, Hasher},
mem::MaybeUninit,
num::NonZeroU64,
ptr,
sync::{Arc, Weak},
time::Duration,
@ -52,6 +52,7 @@ use std::{
pub struct Fence {
handle: ash::vk::Fence,
device: Arc<Device>,
id: NonZeroU64,
must_put_in_pool: bool,
export_handle_types: ExternalFenceHandleTypes,
@ -172,10 +173,9 @@ impl Fence {
Ok(Fence {
handle,
device,
id: Self::next_id(),
must_put_in_pool: false,
export_handle_types,
state: Mutex::new(FenceState {
is_signaled: signaled,
..Default::default()
@ -205,10 +205,9 @@ impl Fence {
Fence {
handle,
device,
id: Self::next_id(),
must_put_in_pool: true,
export_handle_types: ExternalFenceHandleTypes::empty(),
state: Mutex::new(Default::default()),
}
}
@ -244,10 +243,9 @@ impl Fence {
Fence {
handle,
device,
id: Self::next_id(),
must_put_in_pool: false,
export_handle_types,
state: Mutex::new(FenceState {
is_signaled: signaled,
..Default::default()
@ -1089,21 +1087,7 @@ unsafe impl DeviceOwned for Fence {
}
}
impl PartialEq for Fence {
#[inline]
fn eq(&self, other: &Self) -> bool {
self.handle == other.handle && self.device() == other.device()
}
}
impl Eq for Fence {}
impl Hash for Fence {
fn hash<H: Hasher>(&self, state: &mut H) {
self.handle.hash(state);
self.device().hash(state);
}
}
crate::impl_id_counter!(Fence);
#[derive(Debug, Default)]
pub(crate) struct FenceState {

View File

@ -17,8 +17,8 @@ use std::{
error::Error,
fmt::{Display, Error as FmtError, Formatter},
fs::File,
hash::{Hash, Hasher},
mem::MaybeUninit,
num::NonZeroU64,
ptr,
sync::{Arc, Weak},
};
@ -31,6 +31,7 @@ use std::{
pub struct Semaphore {
handle: ash::vk::Semaphore,
device: Arc<Device>,
id: NonZeroU64,
must_put_in_pool: bool,
export_handle_types: ExternalSemaphoreHandleTypes,
@ -146,12 +147,11 @@ impl Semaphore {
};
Ok(Semaphore {
device,
handle,
device,
id: Self::next_id(),
must_put_in_pool: false,
export_handle_types,
state: Mutex::new(Default::default()),
})
}
@ -167,12 +167,11 @@ impl Semaphore {
let handle = device.semaphore_pool().lock().pop();
let semaphore = match handle {
Some(handle) => Semaphore {
device,
handle,
device,
id: Self::next_id(),
must_put_in_pool: true,
export_handle_types: ExternalSemaphoreHandleTypes::empty(),
state: Mutex::new(Default::default()),
},
None => {
@ -204,12 +203,11 @@ impl Semaphore {
} = create_info;
Semaphore {
device,
handle,
device,
id: Self::next_id(),
must_put_in_pool: false,
export_handle_types,
state: Mutex::new(Default::default()),
}
}
@ -1005,21 +1003,7 @@ unsafe impl DeviceOwned for Semaphore {
}
}
impl PartialEq for Semaphore {
#[inline]
fn eq(&self, other: &Self) -> bool {
self.handle == other.handle && self.device() == other.device()
}
}
impl Eq for Semaphore {}
impl Hash for Semaphore {
fn hash<H: Hasher>(&self, state: &mut H) {
self.handle.hash(state);
self.device().hash(state);
}
}
crate::impl_id_counter!(Semaphore);
#[derive(Debug, Default)]
pub(crate) struct SemaphoreState {