Move impl_id_counter to the macros module (#2158)

This commit is contained in:
marc0246 2023-03-24 14:04:02 +01:00 committed by GitHub
parent 28a98f7a5f
commit 779ed1023f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
28 changed files with 101 additions and 92 deletions

View File

@ -16,6 +16,7 @@
use super::{Buffer, BufferCreateFlags, BufferError, BufferMemory, BufferUsage};
use crate::{
device::{Device, DeviceOwned},
macros::impl_id_counter,
memory::{
allocator::{AllocationType, DeviceLayout, MemoryAlloc},
is_aligned, DedicatedTo, ExternalMemoryHandleTypes, MemoryAllocateFlags,
@ -628,7 +629,7 @@ unsafe impl DeviceOwned for RawBuffer {
}
}
crate::impl_id_counter!(RawBuffer);
impl_id_counter!(RawBuffer);
/// Parameters to create a new [`Buffer`].
#[derive(Clone, Debug)]

View File

@ -49,6 +49,7 @@ use super::{BufferUsage, Subbuffer};
use crate::{
device::{Device, DeviceOwned},
format::{Format, FormatFeatures},
macros::impl_id_counter,
memory::{is_aligned, DeviceAlignment},
DeviceSize, OomError, RequirementNotMet, RequiresOneOf, Version, VulkanError, VulkanObject,
};
@ -301,7 +302,7 @@ unsafe impl DeviceOwned for BufferView {
}
}
crate::impl_id_counter!(BufferView);
impl_id_counter!(BufferView);
/// Parameters to create a new `BufferView`.
#[derive(Clone, Debug)]

View File

@ -18,6 +18,7 @@
use crate::{
command_buffer::CommandBufferLevel,
device::{Device, DeviceOwned},
macros::impl_id_counter,
OomError, RequiresOneOf, Version, VulkanError, VulkanObject,
};
use smallvec::SmallVec;
@ -347,7 +348,7 @@ unsafe impl DeviceOwned for CommandPool {
}
}
crate::impl_id_counter!(CommandPool);
impl_id_counter!(CommandPool);
/// Error that can happen when creating a `CommandPool`.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
@ -493,7 +494,7 @@ unsafe impl DeviceOwned for CommandPoolAlloc {
}
}
crate::impl_id_counter!(CommandPoolAlloc);
impl_id_counter!(CommandPoolAlloc);
/// Error that can happen when trimming command pools.
#[derive(Copy, Clone, Debug, PartialEq, Eq)]

View File

@ -13,7 +13,7 @@
use crate::{
device::{Device, DeviceOwned},
macros::vulkan_enum,
macros::{impl_id_counter, vulkan_enum},
sampler::Sampler,
shader::{DescriptorBindingRequirements, ShaderStages},
OomError, RequirementNotMet, RequiresOneOf, Version, VulkanError, VulkanObject,
@ -457,7 +457,7 @@ unsafe impl DeviceOwned for DescriptorSetLayout {
}
}
crate::impl_id_counter!(DescriptorSetLayout);
impl_id_counter!(DescriptorSetLayout);
/// Error related to descriptor set layout.
#[derive(Debug, Clone, PartialEq, Eq)]

View File

@ -13,6 +13,7 @@ use crate::{
sys::UnsafeDescriptorSet,
},
device::{Device, DeviceOwned},
macros::impl_id_counter,
OomError, Version, VulkanError, VulkanObject,
};
use ahash::HashMap;
@ -346,7 +347,7 @@ unsafe impl DeviceOwned for DescriptorPool {
}
}
crate::impl_id_counter!(DescriptorPool);
impl_id_counter!(DescriptorPool);
/// Parameters to create a new `UnsafeDescriptorPool`.
#[derive(Clone, Debug)]

View File

@ -15,6 +15,7 @@ use crate::{
update::{DescriptorWriteInfo, WriteDescriptorSet},
},
device::DeviceOwned,
macros::impl_id_counter,
VulkanObject,
};
use smallvec::SmallVec;
@ -129,4 +130,4 @@ impl Debug for UnsafeDescriptorSet {
}
}
crate::impl_id_counter!(UnsafeDescriptorSet);
impl_id_counter!(UnsafeDescriptorSet);

View File

@ -114,8 +114,8 @@ pub use crate::{
fns::DeviceFunctions,
};
use crate::{
instance::Instance, memory::ExternalMemoryHandleType, OomError, RequirementNotMet,
RequiresOneOf, Version, VulkanError, VulkanObject,
instance::Instance, macros::impl_id_counter, memory::ExternalMemoryHandleType, OomError,
RequirementNotMet, RequiresOneOf, Version, VulkanError, VulkanObject,
};
use ash::vk::Handle;
use parking_lot::Mutex;
@ -645,7 +645,7 @@ unsafe impl VulkanObject for Device {
}
}
crate::impl_id_counter!(Device);
impl_id_counter!(Device);
/// Error that can be returned when creating a device.
#[derive(Copy, Clone, Debug)]

View File

@ -18,7 +18,7 @@ use crate::{
SparseImageFormatProperties,
},
instance::Instance,
macros::{vulkan_bitflags, vulkan_enum},
macros::{impl_id_counter, vulkan_bitflags, vulkan_enum},
memory::MemoryProperties,
swapchain::{
ColorSpace, FullScreenExclusive, PresentMode, Surface, SurfaceApi, SurfaceCapabilities,
@ -2421,7 +2421,7 @@ unsafe impl VulkanObject for PhysicalDevice {
}
}
crate::impl_id_counter!(PhysicalDevice);
impl_id_counter!(PhysicalDevice);
vulkan_enum! {
#[non_exhaustive]

View File

@ -27,6 +27,7 @@ use crate::{
view::ImageViewCreationError, ImageFormatInfo, ImageFormatProperties, ImageType,
SparseImageFormatProperties,
},
macros::impl_id_counter,
memory::{
allocator::{AllocationCreationError, AllocationType, DeviceLayout, MemoryAlloc},
is_aligned, DedicatedTo, DeviceAlignment, ExternalMemoryHandleType,
@ -1877,7 +1878,7 @@ unsafe impl DeviceOwned for RawImage {
}
}
crate::impl_id_counter!(RawImage);
impl_id_counter!(RawImage);
/// Parameters to create a new `Image`.
#[derive(Clone, Debug)]

View File

@ -20,7 +20,7 @@ use crate::{
device::{Device, DeviceOwned},
format::{ChromaSampling, Format, FormatFeatures},
image::{ImageAspects, ImageCreateFlags, ImageTiling, ImageType, SampleCount},
macros::vulkan_enum,
macros::{impl_id_counter, vulkan_enum},
sampler::{ycbcr::SamplerYcbcrConversion, ComponentMapping},
OomError, RequirementNotMet, RequiresOneOf, Version, VulkanError, VulkanObject,
};
@ -797,7 +797,7 @@ where
}
}
crate::impl_id_counter!(ImageView<I: ImageAccess + ?Sized>);
impl_id_counter!(ImageView<I: ImageAccess + ?Sized>);
/// Parameters to create a new `ImageView`.
#[derive(Debug)]

View File

@ -84,8 +84,8 @@ use self::debug::{
};
pub use self::{extensions::InstanceExtensions, layers::LayerProperties};
use crate::{
device::physical::PhysicalDevice, instance::debug::trampoline, OomError, RequiresOneOf,
VulkanError, VulkanLibrary, VulkanObject,
device::physical::PhysicalDevice, instance::debug::trampoline, macros::impl_id_counter,
OomError, RequiresOneOf, VulkanError, VulkanLibrary, VulkanObject,
};
pub use crate::{
extensions::{ExtensionRestriction, ExtensionRestrictionError},
@ -658,7 +658,7 @@ unsafe impl VulkanObject for Instance {
}
}
crate::impl_id_counter!(Instance);
impl_id_counter!(Instance);
impl Debug for Instance {
fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), FmtError> {

View File

@ -483,50 +483,3 @@ 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)).unwrap_or_else(|| {
println!("an ID counter has overflown ...somehow");
std::process::abort();
})
}
}
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

@ -888,6 +888,51 @@ macro_rules! vulkan_bitflags_enum {
}
}
macro_rules! impl_id_counter {
($type:ident $(< $($param:ident $(: $bound:ident $(+ $bounds:ident)* )?),+ >)?) => {
$crate::macros::impl_id_counter!(
@inner $type $(< $($param),+ >)?, $( $($param $(: $bound $(+ $bounds)* )?),+)?
);
};
($type:ident $(< $($param:ident $(: $bound:ident $(+ $bounds:ident)* )? + ?Sized),+ >)?) => {
$crate::macros::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)).unwrap_or_else(|| {
println!("an ID counter has overflown ...somehow");
std::process::abort();
})
}
}
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);
}
}
};
}
// TODO: Replace with the `?` operator once its constness is stabilized.
macro_rules! try_opt {
($e:expr) => {
@ -899,4 +944,4 @@ macro_rules! try_opt {
};
}
pub(crate) use {try_opt, vulkan_bitflags, vulkan_bitflags_enum, vulkan_enum};
pub(crate) use {impl_id_counter, try_opt, vulkan_bitflags, vulkan_bitflags_enum, vulkan_enum};

View File

@ -10,7 +10,7 @@
use super::{DedicatedAllocation, DedicatedTo, DeviceAlignment};
use crate::{
device::{Device, DeviceOwned},
macros::{vulkan_bitflags, vulkan_bitflags_enum},
macros::{impl_id_counter, vulkan_bitflags, vulkan_bitflags_enum},
memory::{is_aligned, MemoryPropertyFlags},
DeviceSize, OomError, RequirementNotMet, RequiresOneOf, Version, VulkanError, VulkanObject,
};
@ -748,7 +748,7 @@ unsafe impl DeviceOwned for DeviceMemory {
}
}
crate::impl_id_counter!(DeviceMemory);
impl_id_counter!(DeviceMemory);
/// Parameters to allocate a new `DeviceMemory`.
#[derive(Clone, Debug)]

View File

@ -28,6 +28,7 @@ use crate::{
DescriptorSetLayout, DescriptorSetLayoutCreateInfo, DescriptorSetLayoutCreationError,
},
device::{Device, DeviceOwned},
macros::impl_id_counter,
pipeline::{
cache::PipelineCache,
layout::{PipelineLayout, PipelineLayoutCreationError, PipelineLayoutSupersetError},
@ -279,7 +280,7 @@ impl Debug for ComputePipeline {
}
}
crate::impl_id_counter!(ComputePipeline);
impl_id_counter!(ComputePipeline);
unsafe impl VulkanObject for ComputePipeline {
type Handle = ash::vk::Pipeline;

View File

@ -67,6 +67,7 @@ use self::{
use super::{DynamicState, Pipeline, PipelineBindPoint, PipelineLayout};
use crate::{
device::{Device, DeviceOwned},
macros::impl_id_counter,
shader::{DescriptorBindingRequirements, FragmentTestsStages, ShaderStage},
VulkanObject,
};
@ -298,4 +299,4 @@ impl Drop for GraphicsPipeline {
}
}
crate::impl_id_counter!(GraphicsPipeline);
impl_id_counter!(GraphicsPipeline);

View File

@ -66,6 +66,7 @@
use crate::{
descriptor_set::layout::{DescriptorRequirementsNotMet, DescriptorSetLayout, DescriptorType},
device::{Device, DeviceOwned},
macros::impl_id_counter,
shader::{DescriptorBindingRequirements, ShaderStages},
OomError, RequirementNotMet, RequiresOneOf, VulkanError, VulkanObject,
};
@ -694,7 +695,7 @@ unsafe impl DeviceOwned for PipelineLayout {
}
}
crate::impl_id_counter!(PipelineLayout);
impl_id_counter!(PipelineLayout);
/// Error that can happen when creating a pipeline layout.
#[derive(Clone, Debug, PartialEq, Eq)]

View File

@ -16,7 +16,7 @@
use crate::{
buffer::BufferContents,
device::{Device, DeviceOwned},
macros::vulkan_bitflags,
macros::{impl_id_counter, vulkan_bitflags},
DeviceSize, OomError, RequirementNotMet, RequiresOneOf, VulkanError, VulkanObject,
};
use std::{
@ -198,7 +198,7 @@ unsafe impl DeviceOwned for QueryPool {
}
}
crate::impl_id_counter!(QueryPool);
impl_id_counter!(QueryPool);
/// Parameters to create a new `QueryPool`.
#[derive(Clone, Debug)]

View File

@ -12,6 +12,7 @@ use crate::{
device::{Device, DeviceOwned},
format::Format,
image::{view::ImageViewType, ImageDimensions, ImageUsage, ImageViewAbstract, SampleCount},
macros::impl_id_counter,
OomError, VulkanError, VulkanObject,
};
use smallvec::SmallVec;
@ -422,7 +423,7 @@ unsafe impl DeviceOwned for Framebuffer {
}
}
crate::impl_id_counter!(Framebuffer);
impl_id_counter!(Framebuffer);
/// Parameters to create a new `Framebuffer`.
#[derive(Clone, Debug)]

View File

@ -33,7 +33,7 @@ use crate::{
device::{Device, DeviceOwned},
format::Format,
image::{ImageAspects, ImageLayout, SampleCount},
macros::{vulkan_bitflags_enum, vulkan_enum},
macros::{impl_id_counter, vulkan_bitflags_enum, vulkan_enum},
shader::ShaderInterface,
sync::{AccessFlags, DependencyFlags, PipelineStages},
Version, VulkanObject,
@ -544,7 +544,7 @@ unsafe impl DeviceOwned for RenderPass {
}
}
crate::impl_id_counter!(RenderPass);
impl_id_counter!(RenderPass);
/// Represents a subpass within a `RenderPass` object.
///

View File

@ -51,7 +51,7 @@ use crate::{
device::{Device, DeviceOwned},
format::FormatFeatures,
image::{view::ImageViewType, ImageAspects, ImageViewAbstract},
macros::vulkan_enum,
macros::{impl_id_counter, vulkan_enum},
pipeline::graphics::depth_stencil::CompareOp,
shader::ShaderScalarType,
OomError, RequirementNotMet, RequiresOneOf, VulkanError, VulkanObject,
@ -779,7 +779,7 @@ unsafe impl DeviceOwned for Sampler {
}
}
crate::impl_id_counter!(Sampler);
impl_id_counter!(Sampler);
/// Error that can happen when creating an instance.
#[derive(Clone, Debug, PartialEq)]

View File

@ -92,7 +92,7 @@
use crate::{
device::{Device, DeviceOwned},
format::{ChromaSampling, Format, FormatFeatures, NumericType},
macros::vulkan_enum,
macros::{impl_id_counter, vulkan_enum},
sampler::{ComponentMapping, ComponentSwizzle, Filter},
OomError, RequirementNotMet, RequiresOneOf, Version, VulkanError, VulkanObject,
};
@ -509,7 +509,7 @@ unsafe impl DeviceOwned for SamplerYcbcrConversion {
}
}
crate::impl_id_counter!(SamplerYcbcrConversion);
impl_id_counter!(SamplerYcbcrConversion);
/// Error that can happen when creating a `SamplerYcbcrConversion`.
#[derive(Clone, Debug, PartialEq, Eq)]

View File

@ -136,7 +136,7 @@ use crate::{
device::{Device, DeviceOwned},
format::{Format, NumericType},
image::view::ImageViewType,
macros::vulkan_bitflags_enum,
macros::{impl_id_counter, vulkan_bitflags_enum},
pipeline::{graphics::input_assembly::PrimitiveTopology, layout::PushConstantRange},
shader::spirv::{Capability, Spirv, SpirvError},
sync::PipelineStages,
@ -401,7 +401,7 @@ unsafe impl DeviceOwned for ShaderModule {
}
}
crate::impl_id_counter!(ShaderModule);
impl_id_counter!(ShaderModule);
/// Error that can happen when creating a new shader module.
#[derive(Clone, Debug)]

View File

@ -13,7 +13,7 @@ use crate::{
format::Format,
image::ImageUsage,
instance::Instance,
macros::{vulkan_bitflags_enum, vulkan_enum},
macros::{impl_id_counter, vulkan_bitflags_enum, vulkan_enum},
swapchain::{
display::{DisplayMode, DisplayPlane},
SurfaceSwapchainLock,
@ -1305,7 +1305,7 @@ unsafe impl VulkanObject for Surface {
}
}
crate::impl_id_counter!(Surface);
impl_id_counter!(Surface);
impl Debug for Surface {
fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), FmtError> {

View File

@ -19,7 +19,7 @@ use crate::{
sys::Image, ImageFormatInfo, ImageLayout, ImageTiling, ImageType, ImageUsage,
SwapchainImage,
},
macros::vulkan_enum,
macros::{impl_id_counter, vulkan_enum},
swapchain::{PresentInfo, SurfaceApi, SurfaceInfo, SurfaceSwapchainLock},
sync::{
fence::{Fence, FenceError},
@ -934,7 +934,7 @@ unsafe impl DeviceOwned for Swapchain {
}
}
crate::impl_id_counter!(Swapchain);
impl_id_counter!(Swapchain);
impl Debug for Swapchain {
fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), FmtError> {

View File

@ -26,6 +26,7 @@
use crate::{
device::{Device, DeviceOwned},
macros::impl_id_counter,
OomError, RequiresOneOf, VulkanError, VulkanObject,
};
use std::{
@ -247,7 +248,7 @@ unsafe impl DeviceOwned for Event {
}
}
crate::impl_id_counter!(Event);
impl_id_counter!(Event);
/// Parameters to create a new `Event`.
#[derive(Clone, Debug)]

View File

@ -12,7 +12,7 @@
use crate::{
device::{Device, DeviceOwned, Queue},
macros::{vulkan_bitflags, vulkan_bitflags_enum},
macros::{impl_id_counter, vulkan_bitflags, vulkan_bitflags_enum},
OomError, RequirementNotMet, RequiresOneOf, Version, VulkanError, VulkanObject,
};
use parking_lot::{Mutex, MutexGuard};
@ -1123,7 +1123,7 @@ unsafe impl DeviceOwned for Fence {
}
}
crate::impl_id_counter!(Fence);
impl_id_counter!(Fence);
#[derive(Debug, Default)]
pub(crate) struct FenceState {

View File

@ -12,7 +12,7 @@
use crate::{
device::{Device, DeviceOwned, Queue},
macros::{vulkan_bitflags, vulkan_bitflags_enum},
macros::{impl_id_counter, vulkan_bitflags, vulkan_bitflags_enum},
OomError, RequirementNotMet, RequiresOneOf, Version, VulkanError, VulkanObject,
};
use parking_lot::{Mutex, MutexGuard};
@ -1019,7 +1019,7 @@ unsafe impl DeviceOwned for Semaphore {
}
}
crate::impl_id_counter!(Semaphore);
impl_id_counter!(Semaphore);
#[derive(Debug, Default)]
pub(crate) struct SemaphoreState {