diff --git a/CHANGELOG_VULKANO.md b/CHANGELOG_VULKANO.md index 1242b16a..9606eee7 100644 --- a/CHANGELOG_VULKANO.md +++ b/CHANGELOG_VULKANO.md @@ -32,6 +32,12 @@ - The following functions have been added to both `SyncCommandBufferBuilder` and `AutoCommandBufferBuilder`: `begin_query` (still unsafe), `end_query` (safe), `write_timestamp` (still unsafe), `copy_query_pool_results` (safe), `reset_command_pool` (still unsafe). - Better documentation of everything in the `query` module. - An example demonstrating occlusion queries. +- **Breaking** Improved the handling of image aspects a little, with the enum `ImageAspect` and the struct `ImageAspects`. `UnsafeCommandBufferBuilderImageAspect` has been removed. +- **Breaking** Removed the separate structs for each image format. Now, only the `Format` enum exists. + - Traits that no longer make sense in this context have been removed: `FormatDesc`, the `Possible*FormatDesc` traits, `StrongStorage`. + - In types that had a type parameter for the format type, it has been removed. + - `AcceptsPixels` has been converted to `Pixel`, which is implemented on the pixel type rather than on the format type. +- Added two methods to `Format`: `planes` to query the number of planes in the format, and `aspects` to query what aspects an image of this type has. - The deprecated `cause` trait function on Vulkano error types is replaced with `source`. - Fixed bug in descriptor array layers check when the image is a cubemap. - Vulkano-shaders: Fixed and refined the generation of the `readonly` descriptor attribute. It should now correctly mark uniforms and sampled images as read-only, but storage buffers and images only if explicitly marked as `readonly` in the shader. diff --git a/vulkano/src/buffer/view.rs b/vulkano/src/buffer/view.rs index 279152a9..72a63266 100644 --- a/vulkano/src/buffer/view.rs +++ b/vulkano/src/buffer/view.rs @@ -22,7 +22,7 @@ //! use vulkano::buffer::immutable::ImmutableBuffer; //! use vulkano::buffer::BufferUsage; //! use vulkano::buffer::BufferView; -//! use vulkano::format; +//! use vulkano::format::Format; //! //! # let device: Arc = return; //! # let queue: Arc = return; @@ -33,53 +33,49 @@ //! //! let (buffer, _future) = ImmutableBuffer::<[u32]>::from_iter((0..128).map(|n| n), usage, //! queue.clone()).unwrap(); -//! let _view = BufferView::new(buffer, format::R32Uint).unwrap(); +//! let _view = BufferView::new(buffer, Format::R32Uint).unwrap(); //! ``` -use std::error; -use std::fmt; -use std::marker::PhantomData; -use std::mem::MaybeUninit; -use std::ptr; -use std::sync::Arc; - use crate::buffer::BufferAccess; use crate::buffer::BufferInner; use crate::buffer::TypedBufferAccess; +use crate::check_errors; use crate::device::Device; use crate::device::DeviceOwned; -use crate::format::FormatDesc; -use crate::format::StrongStorage; - -use crate::check_errors; +use crate::format::Format; +use crate::format::Pixel; use crate::vk; use crate::Error; use crate::OomError; use crate::SafeDeref; use crate::VulkanObject; +use std::error; +use std::fmt; +use std::mem::MaybeUninit; +use std::ptr; +use std::sync::Arc; /// Represents a way for the GPU to interpret buffer data. See the documentation of the /// `view` module. -pub struct BufferView +pub struct BufferView where B: BufferAccess, { view: vk::BufferView, buffer: B, - marker: PhantomData, atomic_accesses: bool, } -impl BufferView +impl BufferView where B: BufferAccess, { /// Builds a new buffer view. #[inline] - pub fn new(buffer: B, format: F) -> Result, BufferViewCreationError> + pub fn new(buffer: B, format: Format) -> Result, BufferViewCreationError> where - B: TypedBufferAccess, - F: StrongStorage + 'static, + B: TypedBufferAccess, + Px: Pixel, { unsafe { BufferView::unchecked(buffer, format) } } @@ -87,18 +83,16 @@ where /// Builds a new buffer view without checking that the format is correct. pub unsafe fn unchecked( org_buffer: B, - format: F, - ) -> Result, BufferViewCreationError> + format: Format, + ) -> Result, BufferViewCreationError> where B: BufferAccess, - F: FormatDesc + 'static, { let (view, format_props) = { let size = org_buffer.size(); let BufferInner { buffer, offset } = org_buffer.inner(); let device = buffer.device(); - let format = format.format(); if (offset % device @@ -173,9 +167,8 @@ where }; Ok(BufferView { - view: view, + view, buffer: org_buffer, - marker: PhantomData, atomic_accesses: (format_props & vk::FORMAT_FEATURE_STORAGE_TEXEL_BUFFER_ATOMIC_BIT) != 0, }) @@ -206,7 +199,7 @@ where } } -unsafe impl VulkanObject for BufferView +unsafe impl VulkanObject for BufferView where B: BufferAccess, { @@ -220,7 +213,7 @@ where } } -unsafe impl DeviceOwned for BufferView +unsafe impl DeviceOwned for BufferView where B: BufferAccess, { @@ -230,7 +223,7 @@ where } } -impl fmt::Debug for BufferView +impl fmt::Debug for BufferView where B: BufferAccess + fmt::Debug, { @@ -242,7 +235,7 @@ where } } -impl Drop for BufferView +impl Drop for BufferView where B: BufferAccess, { @@ -261,34 +254,31 @@ where pub unsafe trait BufferViewRef { type BufferAccess: BufferAccess; - type Format; - fn view(&self) -> &BufferView; + fn view(&self) -> &BufferView; } -unsafe impl BufferViewRef for BufferView +unsafe impl BufferViewRef for BufferView where B: BufferAccess, { type BufferAccess = B; - type Format = F; #[inline] - fn view(&self) -> &BufferView { + fn view(&self) -> &BufferView { self } } -unsafe impl BufferViewRef for T +unsafe impl BufferViewRef for T where - T: SafeDeref>, + T: SafeDeref>, B: BufferAccess, { type BufferAccess = B; - type Format = F; #[inline] - fn view(&self) -> &BufferView { + fn view(&self) -> &BufferView { &**self } } @@ -370,7 +360,7 @@ mod tests { use crate::buffer::view::BufferViewCreationError; use crate::buffer::BufferUsage; use crate::buffer::BufferView; - use crate::format; + use crate::format::Format; #[test] fn create_uniform() { @@ -385,7 +375,7 @@ mod tests { let (buffer, _) = ImmutableBuffer::<[[u8; 4]]>::from_iter((0..128).map(|_| [0; 4]), usage, queue.clone()) .unwrap(); - let view = BufferView::new(buffer, format::R8G8B8A8Unorm).unwrap(); + let view = BufferView::new(buffer, Format::R8G8B8A8Unorm).unwrap(); assert!(view.uniform_texel_buffer()); } @@ -403,7 +393,7 @@ mod tests { let (buffer, _) = ImmutableBuffer::<[[u8; 4]]>::from_iter((0..128).map(|_| [0; 4]), usage, queue.clone()) .unwrap(); - let view = BufferView::new(buffer, format::R8G8B8A8Unorm).unwrap(); + let view = BufferView::new(buffer, Format::R8G8B8A8Unorm).unwrap(); assert!(view.storage_texel_buffer()); } @@ -420,7 +410,7 @@ mod tests { let (buffer, _) = ImmutableBuffer::<[u32]>::from_iter((0..128).map(|_| 0), usage, queue.clone()).unwrap(); - let view = BufferView::new(buffer, format::R32Uint).unwrap(); + let view = BufferView::new(buffer, Format::R32Uint).unwrap(); assert!(view.storage_texel_buffer()); assert!(view.storage_texel_buffer_atomic()); @@ -438,7 +428,7 @@ mod tests { ) .unwrap(); - match BufferView::new(buffer, format::R8G8B8A8Unorm) { + match BufferView::new(buffer, Format::R8G8B8A8Unorm) { Err(BufferViewCreationError::WrongBufferUsage) => (), _ => panic!(), } @@ -462,7 +452,7 @@ mod tests { .unwrap(); // TODO: what if R64G64B64A64Sfloat is supported? - match BufferView::new(buffer, format::R64G64B64A64Sfloat) { + match BufferView::new(buffer, Format::R64G64B64A64Sfloat) { Err(BufferViewCreationError::UnsupportedFormat) => (), _ => panic!(), } diff --git a/vulkano/src/command_buffer/auto.rs b/vulkano/src/command_buffer/auto.rs index e5340df2..8c150a7a 100644 --- a/vulkano/src/command_buffer/auto.rs +++ b/vulkano/src/command_buffer/auto.rs @@ -20,7 +20,6 @@ use crate::command_buffer::sys::Flags; use crate::command_buffer::sys::UnsafeCommandBuffer; use crate::command_buffer::sys::UnsafeCommandBufferBuilderBufferImageCopy; use crate::command_buffer::sys::UnsafeCommandBufferBuilderColorImageClear; -use crate::command_buffer::sys::UnsafeCommandBufferBuilderImageAspect; use crate::command_buffer::sys::UnsafeCommandBufferBuilderImageBlit; use crate::command_buffer::sys::UnsafeCommandBufferBuilderImageCopy; use crate::command_buffer::validity::*; @@ -43,11 +42,12 @@ use crate::descriptor::pipeline_layout::PipelineLayoutAbstract; use crate::device::Device; use crate::device::DeviceOwned; use crate::device::Queue; -use crate::format::AcceptsPixels; use crate::format::ClearValue; -use crate::format::Format; use crate::format::FormatTy; +use crate::format::Pixel; use crate::image::ImageAccess; +use crate::image::ImageAspect; +use crate::image::ImageAspects; use crate::image::ImageLayout; use crate::instance::QueueFamily; use crate::pipeline::input_assembly::Index; @@ -838,12 +838,13 @@ impl AutoCommandBufferBuilder { let copy = UnsafeCommandBufferBuilderImageCopy { // TODO: Allowing choosing a subset of the image aspects, but note that if color // is included, neither depth nor stencil may. - aspect: UnsafeCommandBufferBuilderImageAspect { + aspects: ImageAspects { color: source.has_color(), depth: !source.has_color() && source.has_depth() && destination.has_depth(), stencil: !source.has_color() && source.has_stencil() && destination.has_stencil(), + ..ImageAspects::none() }, source_mip_level, destination_mip_level, @@ -943,11 +944,10 @@ impl AutoCommandBufferBuilder { let blit = UnsafeCommandBufferBuilderImageBlit { // TODO: - aspect: if source.has_color() { - UnsafeCommandBufferBuilderImageAspect { + aspects: if source.has_color() { + ImageAspects { color: true, - depth: false, - stencil: false, + ..ImageAspects::none() } } else { unimplemented!() @@ -1121,7 +1121,7 @@ impl AutoCommandBufferBuilder { where S: TypedBufferAccess + Send + Sync + 'static, D: ImageAccess + Send + Sync + 'static, - Format: AcceptsPixels, + Px: Pixel, { self.ensure_outside_render_pass()?; @@ -1143,7 +1143,7 @@ impl AutoCommandBufferBuilder { where S: TypedBufferAccess + Send + Sync + 'static, D: ImageAccess + Send + Sync + 'static, - Format: AcceptsPixels, + Px: Pixel, { unsafe { self.ensure_outside_render_pass()?; @@ -1165,11 +1165,7 @@ impl AutoCommandBufferBuilder { buffer_row_length: 0, buffer_image_height: 0, image_aspect: if destination.has_color() { - UnsafeCommandBufferBuilderImageAspect { - color: true, - depth: false, - stencil: false, - } + ImageAspect::Color } else { unimplemented!() }, @@ -1201,7 +1197,7 @@ impl AutoCommandBufferBuilder { where S: ImageAccess + Send + Sync + 'static, D: TypedBufferAccess + Send + Sync + 'static, - Format: AcceptsPixels, + Px: Pixel, { self.ensure_outside_render_pass()?; @@ -1223,7 +1219,7 @@ impl AutoCommandBufferBuilder { where S: ImageAccess + Send + Sync + 'static, D: TypedBufferAccess + Send + Sync + 'static, - Format: AcceptsPixels, + Px: Pixel, { unsafe { self.ensure_outside_render_pass()?; @@ -1244,10 +1240,15 @@ impl AutoCommandBufferBuilder { buffer_offset: 0, buffer_row_length: 0, buffer_image_height: 0, - image_aspect: UnsafeCommandBufferBuilderImageAspect { - color: source.has_color(), - depth: source.has_depth(), - stencil: source.has_stencil(), + // TODO: Allow the user to choose aspect + image_aspect: if source.has_color() { + ImageAspect::Color + } else if source.has_depth() { + ImageAspect::Depth + } else if source.has_stencil() { + ImageAspect::Stencil + } else { + unimplemented!() }, image_mip_level: mipmap, image_base_array_layer: first_layer, diff --git a/vulkano/src/command_buffer/sys.rs b/vulkano/src/command_buffer/sys.rs index 8790acf1..564bb50c 100644 --- a/vulkano/src/command_buffer/sys.rs +++ b/vulkano/src/command_buffer/sys.rs @@ -23,8 +23,9 @@ use crate::device::Device; use crate::device::DeviceOwned; use crate::format::ClearValue; use crate::format::FormatTy; -use crate::format::PossibleCompressedFormatDesc; use crate::image::ImageAccess; +use crate::image::ImageAspect; +use crate::image::ImageAspects; use crate::image::ImageLayout; use crate::pipeline::depth_stencil::StencilFaceFlags; use crate::pipeline::input_assembly::IndexType; @@ -474,15 +475,17 @@ impl UnsafeCommandBufferBuilder { // TODO: The correct check here is that the uncompressed element size of the source is // equal to the compressed element size of the destination. debug_assert!( - source.format().is_compressed() - || destination.format().is_compressed() + source.format().ty() == FormatTy::Compressed + || destination.format().ty() == FormatTy::Compressed || source.format().size() == destination.format().size() ); // Depth/Stencil formats are required to match exactly. debug_assert!( - !source.format().ty().is_depth_and_or_stencil() - || source.format() == destination.format() + !matches!( + source.format().ty(), + FormatTy::Depth | FormatTy::Stencil | FormatTy::DepthStencil + ) || source.format() == destination.format() ); debug_assert_eq!(source.samples(), destination.samples()); @@ -519,7 +522,7 @@ impl UnsafeCommandBufferBuilder { Some(vk::ImageCopy { srcSubresource: vk::ImageSubresourceLayers { - aspectMask: copy.aspect.to_vk_bits(), + aspectMask: copy.aspects.into(), mipLevel: copy.source_mip_level, baseArrayLayer: copy.source_base_array_layer + source.first_layer as u32, layerCount: copy.layer_count, @@ -530,7 +533,7 @@ impl UnsafeCommandBufferBuilder { z: copy.source_offset[2], }, dstSubresource: vk::ImageSubresourceLayers { - aspectMask: copy.aspect.to_vk_bits(), + aspectMask: copy.aspects.into(), mipLevel: copy.destination_mip_level, baseArrayLayer: copy.destination_base_array_layer + destination.first_layer as u32, @@ -585,7 +588,13 @@ impl UnsafeCommandBufferBuilder { D: ?Sized + ImageAccess, R: Iterator, { - debug_assert!(filter == Filter::Nearest || !source.format().ty().is_depth_and_or_stencil()); + debug_assert!( + filter == Filter::Nearest + || !matches!( + source.format().ty(), + FormatTy::Depth | FormatTy::Stencil | FormatTy::DepthStencil + ) + ); debug_assert!( (source.format().ty() == FormatTy::Uint) == (destination.format().ty() == FormatTy::Uint) @@ -596,7 +605,10 @@ impl UnsafeCommandBufferBuilder { ); debug_assert!( source.format() == destination.format() - || !source.format().ty().is_depth_and_or_stencil() + || !matches!( + source.format().ty(), + FormatTy::Depth | FormatTy::Stencil | FormatTy::DepthStencil + ) ); debug_assert_eq!(source.samples(), 1); @@ -636,7 +648,7 @@ impl UnsafeCommandBufferBuilder { Some(vk::ImageBlit { srcSubresource: vk::ImageSubresourceLayers { - aspectMask: blit.aspect.to_vk_bits(), + aspectMask: blit.aspects.into(), mipLevel: blit.source_mip_level, baseArrayLayer: blit.source_base_array_layer + source.first_layer as u32, layerCount: blit.layer_count, @@ -654,7 +666,7 @@ impl UnsafeCommandBufferBuilder { }, ], dstSubresource: vk::ImageSubresourceLayers { - aspectMask: blit.aspect.to_vk_bits(), + aspectMask: blit.aspects.into(), mipLevel: blit.destination_mip_level, baseArrayLayer: blit.destination_base_array_layer + destination.first_layer as u32, @@ -870,7 +882,7 @@ impl UnsafeCommandBufferBuilder { bufferRowLength: copy.buffer_row_length, bufferImageHeight: copy.buffer_image_height, imageSubresource: vk::ImageSubresourceLayers { - aspectMask: copy.image_aspect.to_vk_bits(), + aspectMask: copy.image_aspect.into(), mipLevel: copy.image_mip_level + destination.first_mipmap_level as u32, baseArrayLayer: copy.image_base_array_layer + destination.first_layer as u32, @@ -944,7 +956,7 @@ impl UnsafeCommandBufferBuilder { bufferRowLength: copy.buffer_row_length, bufferImageHeight: copy.buffer_image_height, imageSubresource: vk::ImageSubresourceLayers { - aspectMask: copy.image_aspect.to_vk_bits(), + aspectMask: copy.image_aspect.into(), mipLevel: copy.image_mip_level + source.first_mipmap_level as u32, baseArrayLayer: copy.image_base_array_layer + source.first_layer as u32, layerCount: copy.image_layer_count, @@ -1625,30 +1637,6 @@ impl UnsafeCommandBufferBuilderExecuteCommands { } } -// TODO: move somewhere else? -#[derive(Debug, Copy, Clone, PartialEq, Eq)] -pub struct UnsafeCommandBufferBuilderImageAspect { - pub color: bool, - pub depth: bool, - pub stencil: bool, -} - -impl UnsafeCommandBufferBuilderImageAspect { - pub(crate) fn to_vk_bits(&self) -> vk::ImageAspectFlagBits { - let mut out = 0; - if self.color { - out |= vk::IMAGE_ASPECT_COLOR_BIT - }; - if self.depth { - out |= vk::IMAGE_ASPECT_DEPTH_BIT - }; - if self.stencil { - out |= vk::IMAGE_ASPECT_STENCIL_BIT - }; - out - } -} - // TODO: move somewhere else? #[derive(Debug, Copy, Clone, PartialEq, Eq)] pub struct UnsafeCommandBufferBuilderColorImageClear { @@ -1664,7 +1652,7 @@ pub struct UnsafeCommandBufferBuilderBufferImageCopy { pub buffer_offset: usize, pub buffer_row_length: u32, pub buffer_image_height: u32, - pub image_aspect: UnsafeCommandBufferBuilderImageAspect, + pub image_aspect: ImageAspect, pub image_mip_level: u32, pub image_base_array_layer: u32, pub image_layer_count: u32, @@ -1675,7 +1663,7 @@ pub struct UnsafeCommandBufferBuilderBufferImageCopy { // TODO: move somewhere else? #[derive(Debug, Copy, Clone, PartialEq, Eq)] pub struct UnsafeCommandBufferBuilderImageCopy { - pub aspect: UnsafeCommandBufferBuilderImageAspect, + pub aspects: ImageAspects, pub source_mip_level: u32, pub destination_mip_level: u32, pub source_base_array_layer: u32, @@ -1689,7 +1677,7 @@ pub struct UnsafeCommandBufferBuilderImageCopy { // TODO: move somewhere else? #[derive(Debug, Copy, Clone, PartialEq, Eq)] pub struct UnsafeCommandBufferBuilderImageBlit { - pub aspect: UnsafeCommandBufferBuilderImageAspect, + pub aspects: ImageAspects, pub source_mip_level: u32, pub destination_mip_level: u32, pub source_base_array_layer: u32, @@ -1927,18 +1915,12 @@ impl UnsafeCommandBufferBuilderPipelineBarrier { (vk::QUEUE_FAMILY_IGNORED, vk::QUEUE_FAMILY_IGNORED) }; - let aspect_mask = if image.has_color() { - vk::IMAGE_ASPECT_COLOR_BIT - } else if image.has_depth() && image.has_stencil() { - vk::IMAGE_ASPECT_DEPTH_BIT | vk::IMAGE_ASPECT_STENCIL_BIT - } else if image.has_depth() { - vk::IMAGE_ASPECT_DEPTH_BIT - } else if image.has_stencil() { - vk::IMAGE_ASPECT_STENCIL_BIT - } else { - unreachable!() - }; + if image.format().ty() == FormatTy::Ycbcr { + unimplemented!(); + } + // TODO: Let user choose + let aspects = image.format().aspects(); let image = image.inner(); self.image_barriers.push(vk::ImageMemoryBarrier { @@ -1952,7 +1934,7 @@ impl UnsafeCommandBufferBuilderPipelineBarrier { dstQueueFamilyIndex: dest_queue, image: image.image.internal_object(), subresourceRange: vk::ImageSubresourceRange { - aspectMask: aspect_mask, + aspectMask: aspects.into(), baseMipLevel: mipmaps.start + image.first_mipmap_level as u32, levelCount: mipmaps.end - mipmaps.start, baseArrayLayer: layers.start + image.first_layer as u32, diff --git a/vulkano/src/command_buffer/validity/blit_image.rs b/vulkano/src/command_buffer/validity/blit_image.rs index b6cea694..02381f50 100644 --- a/vulkano/src/command_buffer/validity/blit_image.rs +++ b/vulkano/src/command_buffer/validity/blit_image.rs @@ -79,7 +79,10 @@ where let source_format_ty = source.format().ty(); let destination_format_ty = destination.format().ty(); - if source_format_ty.is_depth_and_or_stencil() { + if matches!( + source_format_ty, + FormatTy::Depth | FormatTy::Stencil | FormatTy::DepthStencil + ) { if source.format() != destination.format() { return Err(CheckBlitImageError::DepthStencilFormatMismatch); } diff --git a/vulkano/src/command_buffer/validity/copy_image.rs b/vulkano/src/command_buffer/validity/copy_image.rs index 148b4cda..b55e73d1 100644 --- a/vulkano/src/command_buffer/validity/copy_image.rs +++ b/vulkano/src/command_buffer/validity/copy_image.rs @@ -7,15 +7,13 @@ // notice may not be copied, modified, or distributed except // according to those terms. -use std::error; -use std::fmt; - use crate::device::Device; use crate::format::FormatTy; -use crate::format::PossibleCompressedFormatDesc; use crate::image::ImageAccess; use crate::image::ImageDimensions; use crate::VulkanObject; +use std::error; +use std::fmt; /// Checks whether a copy image command is valid. /// @@ -69,7 +67,10 @@ where let source_format_ty = source.format().ty(); let destination_format_ty = destination.format().ty(); - if source_format_ty.is_depth_and_or_stencil() { + if matches!( + source_format_ty, + FormatTy::Depth | FormatTy::Stencil | FormatTy::DepthStencil + ) { if source.format() != destination.format() { return Err(CheckCopyImageError::DepthStencilFormatMismatch); } @@ -78,8 +79,8 @@ where // TODO: The correct check here is that the uncompressed element size of the source is // equal to the compressed element size of the destination. However, format doesn't // currently expose this information, so to be safe, we simply disallow compressed formats. - if source.format().is_compressed() - || destination.format().is_compressed() + if source.format().ty() == FormatTy::Compressed + || destination.format().ty() == FormatTy::Compressed || (source.format().size() != destination.format().size()) { return Err(CheckCopyImageError::SizeIncompatibleFormatsTypes { diff --git a/vulkano/src/command_buffer/validity/copy_image_buffer.rs b/vulkano/src/command_buffer/validity/copy_image_buffer.rs index b7fa7522..6165c064 100644 --- a/vulkano/src/command_buffer/validity/copy_image_buffer.rs +++ b/vulkano/src/command_buffer/validity/copy_image_buffer.rs @@ -13,9 +13,9 @@ use std::fmt; use crate::buffer::TypedBufferAccess; use crate::device::Device; use crate::device::DeviceOwned; -use crate::format::AcceptsPixels; use crate::format::Format; use crate::format::IncompatiblePixelsType; +use crate::format::Pixel; use crate::image::ImageAccess; use crate::VulkanObject; @@ -33,7 +33,7 @@ pub enum CheckCopyBufferImageTy { /// /// - Panics if the buffer and image were not created with `device`. /// -pub fn check_copy_buffer_image( +pub fn check_copy_buffer_image( device: &Device, buffer: &B, image: &I, @@ -46,8 +46,8 @@ pub fn check_copy_buffer_image( ) -> Result<(), CheckCopyBufferImageError> where I: ?Sized + ImageAccess, - B: ?Sized + TypedBufferAccess, - Format: AcceptsPixels

, // TODO: use a trait on the image itself instead + B: ?Sized + TypedBufferAccess, + Px: Pixel, // TODO: use a trait on the image itself instead { let buffer_inner = buffer.inner(); let image_inner = image.inner(); @@ -105,10 +105,11 @@ where return Err(CheckCopyBufferImageError::ImageCoordinatesOutOfRange); } - image.format().ensure_accepts()?; + Px::ensure_accepts(image.format())?; { - let required_len = required_len_for_format(image.format(), image_size, image_num_layers); + let required_len = + required_len_for_format::(image.format(), image_size, image_num_layers); if required_len > buffer.len() { return Err(CheckCopyBufferImageError::BufferTooSmall { required_len, @@ -124,16 +125,16 @@ where /// Computes the minimum required len in elements for buffer with image data in specified /// format of specified size. -fn required_len_for_format

(format: Format, image_size: [u32; 3], image_num_layers: u32) -> usize +fn required_len_for_format(format: Format, image_size: [u32; 3], image_num_layers: u32) -> usize where - Format: AcceptsPixels

, + Px: Pixel, { let (block_width, block_height) = format.block_dimensions(); let num_blocks = (image_size[0] + block_width - 1) / block_width * ((image_size[1] + block_height - 1) / block_height) * image_size[2] * image_num_layers; - let required_len = num_blocks as usize * format.rate() as usize; + let required_len = num_blocks as usize * Px::rate(format) as usize; return required_len; } diff --git a/vulkano/src/descriptor/descriptor_set/sys.rs b/vulkano/src/descriptor/descriptor_set/sys.rs index c915c8bb..76265c56 100644 --- a/vulkano/src/descriptor/descriptor_set/sys.rs +++ b/vulkano/src/descriptor/descriptor_set/sys.rs @@ -899,10 +899,10 @@ impl DescriptorWrite { } #[inline] - pub fn uniform_texel_buffer<'a, F, B>( + pub fn uniform_texel_buffer<'a, B>( binding: u32, array_element: u32, - view: &BufferView, + view: &BufferView, ) -> DescriptorWrite where B: BufferAccess, @@ -919,10 +919,10 @@ impl DescriptorWrite { } #[inline] - pub fn storage_texel_buffer<'a, F, B>( + pub fn storage_texel_buffer<'a, B>( binding: u32, array_element: u32, - view: &BufferView, + view: &BufferView, ) -> DescriptorWrite where B: BufferAccess, diff --git a/vulkano/src/format.rs b/vulkano/src/format.rs index f4def57e..9e07e4c5 100644 --- a/vulkano/src/format.rs +++ b/vulkano/src/format.rs @@ -7,15 +7,7 @@ // notice may not be copied, modified, or distributed except // according to those terms. -//! Declares all the formats of data and images supported by Vulkan. -//! -//! # Content of this module -//! -//! This module contains three things: -//! -//! - The `Format` enumeration, which contains all the available formats. -//! - The `FormatDesc` trait. -//! - One struct for each format. +//! All the formats of images supported by Vulkan. //! //! # Formats //! @@ -54,47 +46,45 @@ //! texturing (ie. blitting source and sampling them linearly). You should choose one of these //! formats if you have an image that you are going to sample from: //! -//! // TODO: use vulkano enums -//! - B4G4R4A4_UNORM_PACK16 -//! - R5G6B5_UNORM_PACK16 -//! - A1R5G5B5_UNORM_PACK16 -//! - R8_UNORM -//! - R8_SNORM -//! - R8G8_UNORM -//! - R8G8_SNORM -//! - R8G8B8A8_UNORM -//! - R8G8B8A8_SNORM -//! - R8G8B8A8_SRGB -//! - B8G8R8A8_UNORM -//! - B8G8R8A8_SRGB -//! - A8B8G8R8_UNORM_PACK32 -//! - A8B8G8R8_SNORM_PACK32 -//! - A8B8G8R8_SRGB_PACK32 -//! - A2B10G10R10_UNORM_PACK32 -//! - R16_SFLOAT -//! - R16G16_SFLOAT -//! - R16G16B16A16_SFLOAT -//! - B10G11R11_UFLOAT_PACK32 -//! - E5B9G9R9_UFLOAT_PACK32 +//! - B4G4R4A4UnormPack16 +//! - R5G6B5UnormPack16 +//! - A1R5G5B5UnormPack16 +//! - R8Unorm +//! - R8Snorm +//! - R8G8Unorm +//! - R8G8Snorm +//! - R8G8B8A8Unorm +//! - R8G8B8A8Snorm +//! - R8G8B8A8Srgb +//! - B8G8R8A8Unorm +//! - B8G8R8A8Srgb +//! - A8B8G8R8UnormPack32 +//! - A8B8G8R8SnormPack32 +//! - A8B8G8R8SrgbPack32 +//! - A2B10G10R10UnormPack32 +//! - R16Sfloat +//! - R16G16Sfloat +//! - R16G16B16A16Sfloat +//! - B10G11R11UfloatPack32 +//! - E5B9G9R9UfloatPack32 //! //! The following formats are guaranteed to be supported for everything that is related to //! intermediate render targets (ie. blitting destination, color attachment and sampling linearly): //! -//! // TODO: use vulkano enums -//! - R5G6B5_UNORM_PACK16 -//! - A1R5G5B5_UNORM_PACK16 -//! - R8_UNORM -//! - R8G8_UNORM -//! - R8G8B8A8_UNORM -//! - R8G8B8A8_SRGB -//! - B8G8R8A8_UNORM -//! - B8G8R8A8_SRGB -//! - A8B8G8R8_UNORM_PACK32 -//! - A8B8G8R8_SRGB_PACK32 -//! - A2B10G10R10_UNORM_PACK32 -//! - R16_SFLOAT -//! - R16G16_SFLOAT -//! - R16G16B16A16_SFLOAT +//! - R5G6B5UnormPack16 +//! - A1R5G5B5UnormPack16 +//! - R8Unorm +//! - R8G8Unorm +//! - R8G8B8A8Unorm +//! - R8G8B8A8Srgb +//! - B8G8R8A8Unorm +//! - B8G8R8A8Srgb +//! - A8B8G8R8UnormPack32 +//! - A8B8G8R8SrgbPack32 +//! - A2B10G10R10UnormPack32 +//! - R16Sfloat +//! - R16G16Sfloat +//! - R16G16B16A16Sfloat //! //! For depth images, only `D16Unorm` is guaranteed to be supported. For depth-stencil images, //! it is guaranteed that either `D24Unorm_S8Uint` or `D32Sfloat_S8Uint` are supported. @@ -102,81 +92,18 @@ //! // TODO: storage formats //! +use crate::image::ImageAspects; +use crate::instance::PhysicalDevice; +use crate::vk; +use crate::VulkanObject; +use half::f16; +use std::convert::TryFrom; use std::mem::MaybeUninit; use std::vec::IntoIter as VecIntoIter; use std::{error, fmt, mem}; -use crate::instance::PhysicalDevice; -use half::f16; - -use crate::vk; -use crate::VulkanObject; - -// TODO: add enumerations for color, depth, stencil and depthstencil formats - -/// Some data whose type must be known by the library. -/// -/// This trait is unsafe to implement because bad things will happen if `ty()` returns a wrong -/// value. -pub unsafe trait Data { - /// Returns the type of the data from an enum. - fn ty() -> Format; - - // TODO "is_supported" functions that redirect to `Self::ty().is_supported()` -} - -// TODO: that's just an example ; implement for all common data types -unsafe impl Data for i8 { - #[inline] - fn ty() -> Format { - Format::R8Sint - } -} -unsafe impl Data for u8 { - #[inline] - fn ty() -> Format { - Format::R8Uint - } -} - -#[derive(Debug, Copy, Clone, PartialEq, Eq)] -pub struct IncompatiblePixelsType; - -impl error::Error for IncompatiblePixelsType {} - -impl fmt::Display for IncompatiblePixelsType { - #[inline] - fn fmt(&self, fmt: &mut fmt::Formatter) -> Result<(), fmt::Error> { - write!( - fmt, - "{}", - "supplied pixels' type is incompatible with this format" - ) - } -} - -pub unsafe trait AcceptsPixels { - /// Returns an error if `T` cannot be used as a source of pixels for `Self`. - fn ensure_accepts(&self) -> Result<(), IncompatiblePixelsType>; - - /// The number of `T`s which make up a single pixel. - /// - /// ``` - /// use vulkano::format::{AcceptsPixels, R8G8B8A8Srgb}; - /// assert_eq!(>::rate(&R8G8B8A8Srgb), 1); - /// assert_eq!(>::rate(&R8G8B8A8Srgb), 4); - /// ``` - /// - /// # Panics - /// - /// May panic if `ensure_accepts` would not return `Ok(())`. - fn rate(&self) -> u32 { - 1 - } -} - macro_rules! formats { - ($($name:ident => $vk:ident [$bdim:expr] [$sz:expr] [$($f_ty:tt)*] {$($d_ty:tt)*},)+) => ( + ($($name:ident => { vk: $vk:ident, bdim: $bdim:expr, size: $sz:expr, ty: $f_ty:ident$(, planes: $planes:expr)?},)+) => ( /// An enumeration of all the possible formats. #[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)] #[repr(u32)] @@ -198,7 +125,7 @@ macro_rules! formats { /// this will be the size of a single block. Returns `None` if the /// size is irrelevant. #[inline] - pub fn size(&self) -> Option { + pub const fn size(&self) -> Option { match *self { $( Format::$name => $sz, @@ -209,7 +136,7 @@ macro_rules! formats { /// Returns (width, height) of the dimensions for block based formats. For /// non block formats will return (1,1) #[inline] - pub fn block_dimensions(&self) -> (u32, u32) { + pub const fn block_dimensions(&self) -> (u32, u32) { match *self { $( Format::$name => $bdim, @@ -217,480 +144,285 @@ macro_rules! formats { } } - /// Returns the `Format` corresponding to a Vulkan constant. - pub(crate) fn from_vulkan_num(val: u32) -> Option { + /// Returns the data type of the format. + #[inline] + pub const fn ty(&self) -> FormatTy { + match *self { + $( + Format::$name => FormatTy::$f_ty, + )+ + } + } + + /// Returns the number of planes that images of this format have. + /// + /// Returns 0 if the format is not multi-planar. + #[inline] + pub const fn planes(&self) -> u8 { + match *self { + $( + $(Format::$name => $planes,)? + )+ + _ => 0, + } + } + } + + impl TryFrom for Format { + type Error = (); + + #[inline] + fn try_from(val: vk::Format) -> Result { match val { $( - vk::$vk => Some(Format::$name), + vk::$vk => Ok(Format::$name), )+ - _ => None, - } - } - - /// Returns the Vulkan constant corresponding to the `Format`. - pub(crate) fn to_vulkan_num(&self) -> u32 { - match *self { - $( - Format::$name => vk::$vk, - )+ - } - } - - #[inline] - pub fn ty(&self) -> FormatTy { - match *self { - $( - Format::$name => formats!(__inner_ty__ $name $($f_ty)*), - )+ - } - } - - /// Retrieves the properties of a format when used by a certain device. - #[inline] - pub fn properties(&self, device: PhysicalDevice) -> FormatProperties { - let vk_properties = unsafe { - let vk_i = device.instance().pointers(); - let mut output = MaybeUninit::uninit(); - vk_i.GetPhysicalDeviceFormatProperties( - device.internal_object(), - self.to_vulkan_num(), - output.as_mut_ptr(), - ); - output.assume_init() - }; - - FormatProperties { - linear_tiling_features: FormatFeatures::from_bits(vk_properties.linearTilingFeatures), - optimal_tiling_features: FormatFeatures::from_bits(vk_properties.optimalTilingFeatures), - buffer_features: FormatFeatures::from_bits(vk_properties.bufferFeatures), + _ => Err(()), } } } - $( - #[derive(Debug, Copy, Clone, Default)] - #[allow(missing_docs)] - #[allow(non_camel_case_types)] - pub struct $name; - - formats!(__inner_impl__ $name $($f_ty)*); - formats!(__inner_strongstorage__ $name $($d_ty)*); - )+ + impl From for vk::Format { + #[inline] + fn from(val: Format) -> Self { + val as vk::Format + } + } ); - - (__inner_impl__ $name:ident float=$num:expr) => { - unsafe impl FormatDesc for $name { - type ClearValue = [f32; $num]; - - #[inline] - fn format(&self) -> Format { - Format::$name - } - - #[inline] - fn decode_clear_value(&self, val: Self::ClearValue) -> ClearValue { - val.into() - } - } - unsafe impl PossibleFloatFormatDesc for $name { - #[inline(always)] - fn is_float(&self) -> bool { true } - } - unsafe impl PossibleFloatOrCompressedFormatDesc for $name { - #[inline(always)] - fn is_float_or_compressed(&self) -> bool { true } - } - }; - - (__inner_impl__ $name:ident uint=$num:expr) => { - unsafe impl FormatDesc for $name { - type ClearValue = [u32; $num]; - - #[inline] - fn format(&self) -> Format { - Format::$name - } - - #[inline] - fn decode_clear_value(&self, val: Self::ClearValue) -> ClearValue { - val.into() - } - } - - unsafe impl PossibleUintFormatDesc for $name { - #[inline(always)] - fn is_uint(&self) -> bool { true } - } - }; - - (__inner_impl__ $name:ident sint=$num:expr) => { - unsafe impl FormatDesc for $name { - type ClearValue = [i32; $num]; - - #[inline] - fn format(&self) -> Format { - Format::$name - } - - #[inline] - fn decode_clear_value(&self, val: Self::ClearValue) -> ClearValue { - val.into() - } - } - - unsafe impl PossibleSintFormatDesc for $name { - #[inline(always)] - fn is_sint(&self) -> bool { true } - } - }; - - (__inner_impl__ $name:ident depth) => { - unsafe impl FormatDesc for $name { - type ClearValue = f32; - - #[inline] - fn format(&self) -> Format { - Format::$name - } - - #[inline] - fn decode_clear_value(&self, val: Self::ClearValue) -> ClearValue { - val.into() - } - } - - unsafe impl PossibleDepthFormatDesc for $name { - #[inline(always)] - fn is_depth(&self) -> bool { true } - } - }; - - (__inner_impl__ $name:ident stencil) => { - unsafe impl FormatDesc for $name { - type ClearValue = u32; // FIXME: shouldn't stencil be i32? - - #[inline] - fn format(&self) -> Format { - Format::$name - } - - #[inline] - fn decode_clear_value(&self, val: Self::ClearValue) -> ClearValue { - val.into() - } - } - - unsafe impl PossibleStencilFormatDesc for $name { - #[inline(always)] - fn is_stencil(&self) -> bool { true } - } - }; - - (__inner_impl__ $name:ident depthstencil) => { - unsafe impl FormatDesc for $name { - type ClearValue = (f32, u32); // FIXME: shouldn't stencil be i32? - - #[inline] - fn format(&self) -> Format { - Format::$name - } - - #[inline] - fn decode_clear_value(&self, val: Self::ClearValue) -> ClearValue { - val.into() - } - } - - unsafe impl PossibleDepthStencilFormatDesc for $name { - #[inline(always)] - fn is_depth_stencil(&self) -> bool { true } - } - }; - - (__inner_impl__ $name:ident compressed = $feature:ident) => { - unsafe impl FormatDesc for $name { - type ClearValue = [f32; 4]; - - #[inline] - fn format(&self) -> Format { - Format::$name - } - - #[inline] - fn decode_clear_value(&self, val: Self::ClearValue) -> ClearValue { - val.into() - } - } - - unsafe impl PossibleCompressedFormatDesc for $name { - #[inline(always)] - fn is_compressed(&self) -> bool { true } - } - unsafe impl PossibleFloatOrCompressedFormatDesc for $name { - #[inline(always)] - fn is_float_or_compressed(&self) -> bool { true } - } - }; - - (__inner_impl__ $name:ident ycbcr) => { - unsafe impl FormatDesc for $name { - type ClearValue = [f32; 4]; - - #[inline] - fn format(&self) -> Format { - Format::$name - } - - #[inline] - fn decode_clear_value(&self, val: Self::ClearValue) -> ClearValue { - ClearValue::None - } - } - - unsafe impl PossibleYcbcrFormatDesc for $name { - #[inline(always)] - fn is_ycbcr(&self) -> bool { true } - } - }; - - (__inner_ty__ $name:ident float=$num:tt) => { FormatTy::Float }; - (__inner_ty__ $name:ident uint=$num:tt) => { FormatTy::Uint }; - (__inner_ty__ $name:ident sint=$num:tt) => { FormatTy::Sint }; - (__inner_ty__ $name:ident depth) => { FormatTy::Depth }; - (__inner_ty__ $name:ident stencil) => { FormatTy::Stencil }; - (__inner_ty__ $name:ident depthstencil) => { FormatTy::DepthStencil }; - (__inner_ty__ $name:ident compressed=$f:tt) => { FormatTy::Compressed }; - (__inner_ty__ $name:ident ycbcr) => { FormatTy::Ycbcr }; - - - (__inner_strongstorage__ $name:ident [$ty:ty; $dim:expr]) => { - formats!(__inner_strongstorage_common__ $name [$ty; $dim]); - unsafe impl AcceptsPixels<$ty> for $name { - fn ensure_accepts(&self) -> Result<(), IncompatiblePixelsType> { Ok(()) } - fn rate(&self) -> u32 { $dim } - } - }; - (__inner_strongstorage__ $name:ident $ty:ty) => { - formats!(__inner_strongstorage_common__ $name $ty); - }; - (__inner_strongstorage__ $name:ident ) => {}; - - (__inner_strongstorage_common__ $name:ident $ty:ty) => { - unsafe impl StrongStorage for $name { - type Pixel = $ty; - } - unsafe impl AcceptsPixels<$ty> for $name { - fn ensure_accepts(&self) -> Result<(), IncompatiblePixelsType> { Ok(()) } - } - }; } formats! { - R4G4UnormPack8 => FORMAT_R4G4_UNORM_PACK8 [(1, 1)] [Some(1)] [float=2] {u8}, - R4G4B4A4UnormPack16 => FORMAT_R4G4B4A4_UNORM_PACK16 [(1, 1)] [Some(2)] [float=4] {u16}, - B4G4R4A4UnormPack16 => FORMAT_B4G4R4A4_UNORM_PACK16 [(1, 1)] [Some(2)] [float=4] {u16}, - R5G6B5UnormPack16 => FORMAT_R5G6B5_UNORM_PACK16 [(1, 1)] [Some(2)] [float=3] {u16}, - B5G6R5UnormPack16 => FORMAT_B5G6R5_UNORM_PACK16 [(1, 1)] [Some(2)] [float=3] {u16}, - R5G5B5A1UnormPack16 => FORMAT_R5G5B5A1_UNORM_PACK16 [(1, 1)] [Some(2)] [float=4] {u16}, - B5G5R5A1UnormPack16 => FORMAT_B5G5R5A1_UNORM_PACK16 [(1, 1)] [Some(2)] [float=4] {u16}, - A1R5G5B5UnormPack16 => FORMAT_A1R5G5B5_UNORM_PACK16 [(1, 1)] [Some(2)] [float=4] {u16}, - R8Unorm => FORMAT_R8_UNORM [(1, 1)] [Some(1)] [float=1] {u8}, - R8Snorm => FORMAT_R8_SNORM [(1, 1)] [Some(1)] [float=1] {i8}, - R8Uscaled => FORMAT_R8_USCALED [(1, 1)] [Some(1)] [float=1] {u8}, - R8Sscaled => FORMAT_R8_SSCALED [(1, 1)] [Some(1)] [float=1] {i8}, - R8Uint => FORMAT_R8_UINT [(1, 1)] [Some(1)] [uint=1] {u8}, - R8Sint => FORMAT_R8_SINT [(1, 1)] [Some(1)] [sint=1] {i8}, - R8Srgb => FORMAT_R8_SRGB [(1, 1)] [Some(1)] [float=1] {u8}, - R8G8Unorm => FORMAT_R8G8_UNORM [(1, 1)] [Some(2)] [float=2] {[u8; 2]}, - R8G8Snorm => FORMAT_R8G8_SNORM [(1, 1)] [Some(2)] [float=2] {[i8; 2]}, - R8G8Uscaled => FORMAT_R8G8_USCALED [(1, 1)] [Some(2)] [float=2] {[u8; 2]}, - R8G8Sscaled => FORMAT_R8G8_SSCALED [(1, 1)] [Some(2)] [float=2] {[i8; 2]}, - R8G8Uint => FORMAT_R8G8_UINT [(1, 1)] [Some(2)] [uint=2] {[u8; 2]}, - R8G8Sint => FORMAT_R8G8_SINT [(1, 1)] [Some(2)] [sint=2] {[i8; 2]}, - R8G8Srgb => FORMAT_R8G8_SRGB [(1, 1)] [Some(2)] [float=2] {[u8; 2]}, - R8G8B8Unorm => FORMAT_R8G8B8_UNORM [(1, 1)] [Some(3)] [float=3] {[u8; 3]}, - R8G8B8Snorm => FORMAT_R8G8B8_SNORM [(1, 1)] [Some(3)] [float=3] {[i8; 3]}, - R8G8B8Uscaled => FORMAT_R8G8B8_USCALED [(1, 1)] [Some(3)] [float=3] {[u8; 3]}, - R8G8B8Sscaled => FORMAT_R8G8B8_SSCALED [(1, 1)] [Some(3)] [float=3] {[i8; 3]}, - R8G8B8Uint => FORMAT_R8G8B8_UINT [(1, 1)] [Some(3)] [uint=3] {[u8; 3]}, - R8G8B8Sint => FORMAT_R8G8B8_SINT [(1, 1)] [Some(3)] [sint=3] {[i8; 3]}, - R8G8B8Srgb => FORMAT_R8G8B8_SRGB [(1, 1)] [Some(3)] [float=3] {[u8; 3]}, - B8G8R8Unorm => FORMAT_B8G8R8_UNORM [(1, 1)] [Some(3)] [float=3] {[u8; 3]}, - B8G8R8Snorm => FORMAT_B8G8R8_SNORM [(1, 1)] [Some(3)] [float=3] {[i8; 3]}, - B8G8R8Uscaled => FORMAT_B8G8R8_USCALED [(1, 1)] [Some(3)] [float=3] {[u8; 3]}, - B8G8R8Sscaled => FORMAT_B8G8R8_SSCALED [(1, 1)] [Some(3)] [float=3] {[i8; 3]}, - B8G8R8Uint => FORMAT_B8G8R8_UINT [(1, 1)] [Some(3)] [uint=3] {[u8; 3]}, - B8G8R8Sint => FORMAT_B8G8R8_SINT [(1, 1)] [Some(3)] [sint=3] {[i8; 3]}, - B8G8R8Srgb => FORMAT_B8G8R8_SRGB [(1, 1)] [Some(3)] [float=3] {[u8; 3]}, - R8G8B8A8Unorm => FORMAT_R8G8B8A8_UNORM [(1, 1)] [Some(4)] [float=4] {[u8; 4]}, - R8G8B8A8Snorm => FORMAT_R8G8B8A8_SNORM [(1, 1)] [Some(4)] [float=4] {[i8; 4]}, - R8G8B8A8Uscaled => FORMAT_R8G8B8A8_USCALED [(1, 1)] [Some(4)] [float=4] {[u8; 4]}, - R8G8B8A8Sscaled => FORMAT_R8G8B8A8_SSCALED [(1, 1)] [Some(4)] [float=4] {[i8; 4]}, - R8G8B8A8Uint => FORMAT_R8G8B8A8_UINT [(1, 1)] [Some(4)] [uint=4] {[u8; 4]}, - R8G8B8A8Sint => FORMAT_R8G8B8A8_SINT [(1, 1)] [Some(4)] [sint=4] {[i8; 4]}, - R8G8B8A8Srgb => FORMAT_R8G8B8A8_SRGB [(1, 1)] [Some(4)] [float=4] {[u8; 4]}, - B8G8R8A8Unorm => FORMAT_B8G8R8A8_UNORM [(1, 1)] [Some(4)] [float=4] {[u8; 4]}, - B8G8R8A8Snorm => FORMAT_B8G8R8A8_SNORM [(1, 1)] [Some(4)] [float=4] {[i8; 4]}, - B8G8R8A8Uscaled => FORMAT_B8G8R8A8_USCALED [(1, 1)] [Some(4)] [float=4] {[u8; 4]}, - B8G8R8A8Sscaled => FORMAT_B8G8R8A8_SSCALED [(1, 1)] [Some(4)] [float=4] {[i8; 4]}, - B8G8R8A8Uint => FORMAT_B8G8R8A8_UINT [(1, 1)] [Some(4)] [uint=4] {[u8; 4]}, - B8G8R8A8Sint => FORMAT_B8G8R8A8_SINT [(1, 1)] [Some(4)] [sint=4] {[i8; 4]}, - B8G8R8A8Srgb => FORMAT_B8G8R8A8_SRGB [(1, 1)] [Some(4)] [float=4] {[u8; 4]}, - A8B8G8R8UnormPack32 => FORMAT_A8B8G8R8_UNORM_PACK32 [(1, 1)] [Some(4)] [float=4] {[u8; 4]}, - A8B8G8R8SnormPack32 => FORMAT_A8B8G8R8_SNORM_PACK32 [(1, 1)] [Some(4)] [float=4] {[i8; 4]}, - A8B8G8R8UscaledPack32 => FORMAT_A8B8G8R8_USCALED_PACK32 [(1, 1)] [Some(4)] [float=4] {[u8; 4]}, - A8B8G8R8SscaledPack32 => FORMAT_A8B8G8R8_SSCALED_PACK32 [(1, 1)] [Some(4)] [float=4] {[i8; 4]}, - A8B8G8R8UintPack32 => FORMAT_A8B8G8R8_UINT_PACK32 [(1, 1)] [Some(4)] [uint=4] {[u8; 4]}, - A8B8G8R8SintPack32 => FORMAT_A8B8G8R8_SINT_PACK32 [(1, 1)] [Some(4)] [sint=4] {[i8; 4]}, - A8B8G8R8SrgbPack32 => FORMAT_A8B8G8R8_SRGB_PACK32 [(1, 1)] [Some(4)] [float=4] {[u8; 4]}, - A2R10G10B10UnormPack32 => FORMAT_A2R10G10B10_UNORM_PACK32 [(1, 1)] [Some(4)] [float=4] {u32}, - A2R10G10B10SnormPack32 => FORMAT_A2R10G10B10_SNORM_PACK32 [(1, 1)] [Some(4)] [float=4] {u32}, - A2R10G10B10UscaledPack32 => FORMAT_A2R10G10B10_USCALED_PACK32 [(1, 1)] [Some(4)] [float=4] {u32}, - A2R10G10B10SscaledPack32 => FORMAT_A2R10G10B10_SSCALED_PACK32 [(1, 1)] [Some(4)] [float=4] {u32}, - A2R10G10B10UintPack32 => FORMAT_A2R10G10B10_UINT_PACK32 [(1, 1)] [Some(4)] [uint=4] {u32}, - A2R10G10B10SintPack32 => FORMAT_A2R10G10B10_SINT_PACK32 [(1, 1)] [Some(4)] [sint=4] {u32}, - A2B10G10R10UnormPack32 => FORMAT_A2B10G10R10_UNORM_PACK32 [(1, 1)] [Some(4)] [float=4] {u32}, - A2B10G10R10SnormPack32 => FORMAT_A2B10G10R10_SNORM_PACK32 [(1, 1)] [Some(4)] [float=4] {u32}, - A2B10G10R10UscaledPack32 => FORMAT_A2B10G10R10_USCALED_PACK32 [(1, 1)] [Some(4)] [float=4] {u32}, - A2B10G10R10SscaledPack32 => FORMAT_A2B10G10R10_SSCALED_PACK32 [(1, 1)] [Some(4)] [float=4] {u32}, - A2B10G10R10UintPack32 => FORMAT_A2B10G10R10_UINT_PACK32 [(1, 1)] [Some(4)] [uint=4] {u32}, - A2B10G10R10SintPack32 => FORMAT_A2B10G10R10_SINT_PACK32 [(1, 1)] [Some(4)] [sint=4] {u32}, - R16Unorm => FORMAT_R16_UNORM [(1, 1)] [Some(2)] [float=1] {u16}, - R16Snorm => FORMAT_R16_SNORM [(1, 1)] [Some(2)] [float=1] {i16}, - R16Uscaled => FORMAT_R16_USCALED [(1, 1)] [Some(2)] [float=1] {u16}, - R16Sscaled => FORMAT_R16_SSCALED [(1, 1)] [Some(2)] [float=1] {i16}, - R16Uint => FORMAT_R16_UINT [(1, 1)] [Some(2)] [uint=1] {u16}, - R16Sint => FORMAT_R16_SINT [(1, 1)] [Some(2)] [sint=1] {i16}, - R16Sfloat => FORMAT_R16_SFLOAT [(1, 1)] [Some(2)] [float=1] {f16}, - R16G16Unorm => FORMAT_R16G16_UNORM [(1, 1)] [Some(4)] [float=2] {[u16; 2]}, - R16G16Snorm => FORMAT_R16G16_SNORM [(1, 1)] [Some(4)] [float=2] {[i16; 2]}, - R16G16Uscaled => FORMAT_R16G16_USCALED [(1, 1)] [Some(4)] [float=2] {[u16; 2]}, - R16G16Sscaled => FORMAT_R16G16_SSCALED [(1, 1)] [Some(4)] [float=2] {[i16; 2]}, - R16G16Uint => FORMAT_R16G16_UINT [(1, 1)] [Some(4)] [uint=2] {[u16; 2]}, - R16G16Sint => FORMAT_R16G16_SINT [(1, 1)] [Some(4)] [sint=2] {[i16; 2]}, - R16G16Sfloat => FORMAT_R16G16_SFLOAT [(1, 1)] [Some(4)] [float=2] {[f16; 2]}, - R16G16B16Unorm => FORMAT_R16G16B16_UNORM [(1, 1)] [Some(6)] [float=3] {[u16; 3]}, - R16G16B16Snorm => FORMAT_R16G16B16_SNORM [(1, 1)] [Some(6)] [float=3] {[i16; 3]}, - R16G16B16Uscaled => FORMAT_R16G16B16_USCALED [(1, 1)] [Some(6)] [float=3] {[u16; 3]}, - R16G16B16Sscaled => FORMAT_R16G16B16_SSCALED [(1, 1)] [Some(6)] [float=3] {[i16; 3]}, - R16G16B16Uint => FORMAT_R16G16B16_UINT [(1, 1)] [Some(6)] [uint=3] {[u16; 3]}, - R16G16B16Sint => FORMAT_R16G16B16_SINT [(1, 1)] [Some(6)] [sint=3] {[i16; 3]}, - R16G16B16Sfloat => FORMAT_R16G16B16_SFLOAT [(1, 1)] [Some(6)] [float=3] {[f16; 3]}, - R16G16B16A16Unorm => FORMAT_R16G16B16A16_UNORM [(1, 1)] [Some(8)] [float=4] {[u16; 4]}, - R16G16B16A16Snorm => FORMAT_R16G16B16A16_SNORM [(1, 1)] [Some(8)] [float=4] {[i16; 4]}, - R16G16B16A16Uscaled => FORMAT_R16G16B16A16_USCALED [(1, 1)] [Some(8)] [float=4] {[u16; 4]}, - R16G16B16A16Sscaled => FORMAT_R16G16B16A16_SSCALED [(1, 1)] [Some(8)] [float=4] {[i16; 4]}, - R16G16B16A16Uint => FORMAT_R16G16B16A16_UINT [(1, 1)] [Some(8)] [uint=4] {[u16; 4]}, - R16G16B16A16Sint => FORMAT_R16G16B16A16_SINT [(1, 1)] [Some(8)] [sint=4] {[i16; 4]}, - R16G16B16A16Sfloat => FORMAT_R16G16B16A16_SFLOAT [(1, 1)] [Some(8)] [float=4] {[f16; 4]}, - R32Uint => FORMAT_R32_UINT [(1, 1)] [Some(4)] [uint=1] {u32}, - R32Sint => FORMAT_R32_SINT [(1, 1)] [Some(4)] [sint=1] {i32}, - R32Sfloat => FORMAT_R32_SFLOAT [(1, 1)] [Some(4)] [float=1] {f32}, - R32G32Uint => FORMAT_R32G32_UINT [(1, 1)] [Some(8)] [uint=2] {[u32; 2]}, - R32G32Sint => FORMAT_R32G32_SINT [(1, 1)] [Some(8)] [sint=2] {[i32; 2]}, - R32G32Sfloat => FORMAT_R32G32_SFLOAT [(1, 1)] [Some(8)] [float=2] {[f32; 2]}, - R32G32B32Uint => FORMAT_R32G32B32_UINT [(1, 1)] [Some(12)] [uint=3] {[u32; 3]}, - R32G32B32Sint => FORMAT_R32G32B32_SINT [(1, 1)] [Some(12)] [sint=3] {[i32; 3]}, - R32G32B32Sfloat => FORMAT_R32G32B32_SFLOAT [(1, 1)] [Some(12)] [float=3] {[f32; 3]}, - R32G32B32A32Uint => FORMAT_R32G32B32A32_UINT [(1, 1)] [Some(16)] [uint=4] {[u32; 4]}, - R32G32B32A32Sint => FORMAT_R32G32B32A32_SINT [(1, 1)] [Some(16)] [sint=4] {[i32; 4]}, - R32G32B32A32Sfloat => FORMAT_R32G32B32A32_SFLOAT [(1, 1)] [Some(16)] [float=4] {[f32; 4]}, - R64Uint => FORMAT_R64_UINT [(1, 1)] [Some(8)] [uint=1] {u64}, - R64Sint => FORMAT_R64_SINT [(1, 1)] [Some(8)] [sint=1] {i64}, - R64Sfloat => FORMAT_R64_SFLOAT [(1, 1)] [Some(8)] [float=1] {f64}, - R64G64Uint => FORMAT_R64G64_UINT [(1, 1)] [Some(16)] [uint=2] {[u64; 2]}, - R64G64Sint => FORMAT_R64G64_SINT [(1, 1)] [Some(16)] [sint=2] {[i64; 2]}, - R64G64Sfloat => FORMAT_R64G64_SFLOAT [(1, 1)] [Some(16)] [float=2] {[f64; 2]}, - R64G64B64Uint => FORMAT_R64G64B64_UINT [(1, 1)] [Some(24)] [uint=3] {[u64; 3]}, - R64G64B64Sint => FORMAT_R64G64B64_SINT [(1, 1)] [Some(24)] [sint=3] {[i64; 3]}, - R64G64B64Sfloat => FORMAT_R64G64B64_SFLOAT [(1, 1)] [Some(24)] [float=3] {[f64; 3]}, - R64G64B64A64Uint => FORMAT_R64G64B64A64_UINT [(1, 1)] [Some(32)] [uint=4] {[u64; 4]}, - R64G64B64A64Sint => FORMAT_R64G64B64A64_SINT [(1, 1)] [Some(32)] [sint=4] {[i64; 4]}, - R64G64B64A64Sfloat => FORMAT_R64G64B64A64_SFLOAT [(1, 1)] [Some(32)] [float=4] {[f64; 4]}, - B10G11R11UfloatPack32 => FORMAT_B10G11R11_UFLOAT_PACK32 [(1, 1)] [Some(4)] [float=3] {u32}, - E5B9G9R9UfloatPack32 => FORMAT_E5B9G9R9_UFLOAT_PACK32 [(1, 1)] [Some(4)] [float=3] {u32}, - D16Unorm => FORMAT_D16_UNORM [(1, 1)] [Some(2)] [depth] {}, - X8_D24UnormPack32 => FORMAT_X8_D24_UNORM_PACK32 [(1, 1)] [Some(4)] [depth] {}, - D32Sfloat => FORMAT_D32_SFLOAT [(1, 1)] [Some(4)] [depth] {}, - S8Uint => FORMAT_S8_UINT [(1, 1)] [Some(1)] [stencil] {}, - D16Unorm_S8Uint => FORMAT_D16_UNORM_S8_UINT [(1, 1)] [None] [depthstencil] {}, - D24Unorm_S8Uint => FORMAT_D24_UNORM_S8_UINT [(1, 1)] [None] [depthstencil] {}, - D32Sfloat_S8Uint => FORMAT_D32_SFLOAT_S8_UINT [(1, 1)] [None] [depthstencil] {}, - BC1_RGBUnormBlock => FORMAT_BC1_RGB_UNORM_BLOCK [(4, 4)] [Some(8)] [compressed=texture_compression_bc] {u8}, - BC1_RGBSrgbBlock => FORMAT_BC1_RGB_SRGB_BLOCK [(4, 4)] [Some(8)] [compressed=texture_compression_bc] {u8}, - BC1_RGBAUnormBlock => FORMAT_BC1_RGBA_UNORM_BLOCK [(4, 4)] [Some(8)] [compressed=texture_compression_bc] {u8}, - BC1_RGBASrgbBlock => FORMAT_BC1_RGBA_SRGB_BLOCK [(4, 4)] [Some(8)] [compressed=texture_compression_bc] {u8}, - BC2UnormBlock => FORMAT_BC2_UNORM_BLOCK [(4, 4)] [Some(16)] [compressed=texture_compression_bc] {u8}, - BC2SrgbBlock => FORMAT_BC2_SRGB_BLOCK [(4, 4)] [Some(16)] [compressed=texture_compression_bc] {u8}, - BC3UnormBlock => FORMAT_BC3_UNORM_BLOCK [(4, 4)] [Some(16)] [compressed=texture_compression_bc] {u8}, - BC3SrgbBlock => FORMAT_BC3_SRGB_BLOCK [(4, 4)] [Some(16)] [compressed=texture_compression_bc] {u8}, - BC4UnormBlock => FORMAT_BC4_UNORM_BLOCK [(4, 4)] [Some(8)] [compressed=texture_compression_bc] {u8}, - BC4SnormBlock => FORMAT_BC4_SNORM_BLOCK [(4, 4)] [Some(8)] [compressed=texture_compression_bc] {u8}, - BC5UnormBlock => FORMAT_BC5_UNORM_BLOCK [(4, 4)] [Some(16)] [compressed=texture_compression_bc] {u8}, - BC5SnormBlock => FORMAT_BC5_SNORM_BLOCK [(4, 4)] [Some(16)] [compressed=texture_compression_bc] {u8}, - BC6HUfloatBlock => FORMAT_BC6H_UFLOAT_BLOCK [(4, 4)] [Some(16)] [compressed=texture_compression_bc] {u8}, - BC6HSfloatBlock => FORMAT_BC6H_SFLOAT_BLOCK [(4, 4)] [Some(16)] [compressed=texture_compression_bc] {u8}, - BC7UnormBlock => FORMAT_BC7_UNORM_BLOCK [(4, 4)] [Some(16)] [compressed=texture_compression_bc] {u8}, - BC7SrgbBlock => FORMAT_BC7_SRGB_BLOCK [(4, 4)] [Some(16)] [compressed=texture_compression_bc] {u8}, - ETC2_R8G8B8UnormBlock => FORMAT_ETC2_R8G8B8_UNORM_BLOCK [(4, 4)] [Some(8)] [compressed=texture_compression_etc2] {u8}, - ETC2_R8G8B8SrgbBlock => FORMAT_ETC2_R8G8B8_SRGB_BLOCK [(4, 4)] [Some(8)] [compressed=texture_compression_etc2] {u8}, - ETC2_R8G8B8A1UnormBlock => FORMAT_ETC2_R8G8B8A1_UNORM_BLOCK [(4, 4)] [Some(8)] [compressed=texture_compression_etc2] {u8}, - ETC2_R8G8B8A1SrgbBlock => FORMAT_ETC2_R8G8B8A1_SRGB_BLOCK [(4, 4)] [Some(8)] [compressed=texture_compression_etc2] {u8}, - ETC2_R8G8B8A8UnormBlock => FORMAT_ETC2_R8G8B8A8_UNORM_BLOCK [(4, 4)] [Some(16)] [compressed=texture_compression_etc2] {u8}, - ETC2_R8G8B8A8SrgbBlock => FORMAT_ETC2_R8G8B8A8_SRGB_BLOCK [(4, 4)] [Some(16)] [compressed=texture_compression_etc2] {u8}, - EAC_R11UnormBlock => FORMAT_EAC_R11_UNORM_BLOCK [(4, 4)] [Some(8)] [compressed=texture_compression_etc2] {u8}, - EAC_R11SnormBlock => FORMAT_EAC_R11_SNORM_BLOCK [(4, 4)] [Some(8)] [compressed=texture_compression_etc2] {u8}, - EAC_R11G11UnormBlock => FORMAT_EAC_R11G11_UNORM_BLOCK [(4, 4)] [Some(16)] [compressed=texture_compression_etc2] {u8}, - EAC_R11G11SnormBlock => FORMAT_EAC_R11G11_SNORM_BLOCK [(4, 4)] [Some(16)] [compressed=texture_compression_etc2] {u8}, - ASTC_4x4UnormBlock => FORMAT_ASTC_4x4_UNORM_BLOCK [(4, 4)] [Some(16)] [compressed=texture_compression_astc_ldr] {u8}, - ASTC_4x4SrgbBlock => FORMAT_ASTC_4x4_SRGB_BLOCK [(4, 4)] [Some(16)] [compressed=texture_compression_astc_ldr] {u8}, - ASTC_5x4UnormBlock => FORMAT_ASTC_5x4_UNORM_BLOCK [(5, 4)] [Some(16)] [compressed=texture_compression_astc_ldr] {u8}, - ASTC_5x4SrgbBlock => FORMAT_ASTC_5x4_SRGB_BLOCK [(5, 4)] [Some(16)] [compressed=texture_compression_astc_ldr] {u8}, - ASTC_5x5UnormBlock => FORMAT_ASTC_5x5_UNORM_BLOCK [(5, 5)] [Some(16)] [compressed=texture_compression_astc_ldr] {u8}, - ASTC_5x5SrgbBlock => FORMAT_ASTC_5x5_SRGB_BLOCK [(5, 5)] [Some(16)] [compressed=texture_compression_astc_ldr] {u8}, - ASTC_6x5UnormBlock => FORMAT_ASTC_6x5_UNORM_BLOCK [(6, 5)] [Some(16)] [compressed=texture_compression_astc_ldr] {u8}, - ASTC_6x5SrgbBlock => FORMAT_ASTC_6x5_SRGB_BLOCK [(6, 5)] [Some(16)] [compressed=texture_compression_astc_ldr] {u8}, - ASTC_6x6UnormBlock => FORMAT_ASTC_6x6_UNORM_BLOCK [(6, 6)] [Some(16)] [compressed=texture_compression_astc_ldr] {u8}, - ASTC_6x6SrgbBlock => FORMAT_ASTC_6x6_SRGB_BLOCK [(6, 6)] [Some(16)] [compressed=texture_compression_astc_ldr] {u8}, - ASTC_8x5UnormBlock => FORMAT_ASTC_8x5_UNORM_BLOCK [(8, 5)] [Some(16)] [compressed=texture_compression_astc_ldr] {u8}, - ASTC_8x5SrgbBlock => FORMAT_ASTC_8x5_SRGB_BLOCK [(8, 5)] [Some(16)] [compressed=texture_compression_astc_ldr] {u8}, - ASTC_8x6UnormBlock => FORMAT_ASTC_8x6_UNORM_BLOCK [(8, 6)] [Some(16)] [compressed=texture_compression_astc_ldr] {u8}, - ASTC_8x6SrgbBlock => FORMAT_ASTC_8x6_SRGB_BLOCK [(8, 6)] [Some(16)] [compressed=texture_compression_astc_ldr] {u8}, - ASTC_8x8UnormBlock => FORMAT_ASTC_8x8_UNORM_BLOCK [(8, 8)] [Some(16)] [compressed=texture_compression_astc_ldr] {u8}, - ASTC_8x8SrgbBlock => FORMAT_ASTC_8x8_SRGB_BLOCK [(8, 8)] [Some(16)] [compressed=texture_compression_astc_ldr] {u8}, - ASTC_10x5UnormBlock => FORMAT_ASTC_10x5_UNORM_BLOCK [(10, 5)] [Some(16)] [compressed=texture_compression_astc_ldr] {u8}, - ASTC_10x5SrgbBlock => FORMAT_ASTC_10x5_SRGB_BLOCK [(10, 5)] [Some(16)] [compressed=texture_compression_astc_ldr] {u8}, - ASTC_10x6UnormBlock => FORMAT_ASTC_10x6_UNORM_BLOCK [(10, 6)] [Some(16)] [compressed=texture_compression_astc_ldr] {u8}, - ASTC_10x6SrgbBlock => FORMAT_ASTC_10x6_SRGB_BLOCK [(10, 6)] [Some(16)] [compressed=texture_compression_astc_ldr] {u8}, - ASTC_10x8UnormBlock => FORMAT_ASTC_10x8_UNORM_BLOCK [(10, 8)] [Some(16)] [compressed=texture_compression_astc_ldr] {u8}, - ASTC_10x8SrgbBlock => FORMAT_ASTC_10x8_SRGB_BLOCK [(10, 8)] [Some(16)] [compressed=texture_compression_astc_ldr] {u8}, - ASTC_10x10UnormBlock => FORMAT_ASTC_10x10_UNORM_BLOCK [(10, 10)] [Some(16)] [compressed=texture_compression_astc_ldr] {u8}, - ASTC_10x10SrgbBlock => FORMAT_ASTC_10x10_SRGB_BLOCK [(10, 10)] [Some(16)] [compressed=texture_compression_astc_ldr] {u8}, - ASTC_12x10UnormBlock => FORMAT_ASTC_12x10_UNORM_BLOCK [(12, 10)] [Some(16)] [compressed=texture_compression_astc_ldr] {u8}, - ASTC_12x10SrgbBlock => FORMAT_ASTC_12x10_SRGB_BLOCK [(12, 10)] [Some(16)] [compressed=texture_compression_astc_ldr] {u8}, - ASTC_12x12UnormBlock => FORMAT_ASTC_12x12_UNORM_BLOCK [(12, 12)] [Some(16)] [compressed=texture_compression_astc_ldr] {u8}, - ASTC_12x12SrgbBlock => FORMAT_ASTC_12x12_SRGB_BLOCK [(12, 12)] [Some(16)] [compressed=texture_compression_astc_ldr] {u8}, - G8B8R8_3PLANE420Unorm => FORMAT_G8_B8_R8_3PLANE_420_UNORM [(1, 1)] [None] [ycbcr] {}, - G8B8R8_2PLANE420Unorm => FORMAT_G8_B8R8_2PLANE_420_UNORM [(1, 1)] [None] [ycbcr] {}, + R4G4UnormPack8 => {vk: FORMAT_R4G4_UNORM_PACK8, bdim: (1, 1), size: Some(1), ty: Float}, + R4G4B4A4UnormPack16 => {vk: FORMAT_R4G4B4A4_UNORM_PACK16, bdim: (1, 1), size: Some(2), ty: Float}, + B4G4R4A4UnormPack16 => {vk: FORMAT_B4G4R4A4_UNORM_PACK16, bdim: (1, 1), size: Some(2), ty: Float}, + R5G6B5UnormPack16 => {vk: FORMAT_R5G6B5_UNORM_PACK16, bdim: (1, 1), size: Some(2), ty: Float}, + B5G6R5UnormPack16 => {vk: FORMAT_B5G6R5_UNORM_PACK16, bdim: (1, 1), size: Some(2), ty: Float}, + R5G5B5A1UnormPack16 => {vk: FORMAT_R5G5B5A1_UNORM_PACK16, bdim: (1, 1), size: Some(2), ty: Float}, + B5G5R5A1UnormPack16 => {vk: FORMAT_B5G5R5A1_UNORM_PACK16, bdim: (1, 1), size: Some(2), ty: Float}, + A1R5G5B5UnormPack16 => {vk: FORMAT_A1R5G5B5_UNORM_PACK16, bdim: (1, 1), size: Some(2), ty: Float}, + R8Unorm => {vk: FORMAT_R8_UNORM, bdim: (1, 1), size: Some(1), ty: Float}, + R8Snorm => {vk: FORMAT_R8_SNORM, bdim: (1, 1), size: Some(1), ty: Float}, + R8Uscaled => {vk: FORMAT_R8_USCALED, bdim: (1, 1), size: Some(1), ty: Float}, + R8Sscaled => {vk: FORMAT_R8_SSCALED, bdim: (1, 1), size: Some(1), ty: Float}, + R8Uint => {vk: FORMAT_R8_UINT, bdim: (1, 1), size: Some(1), ty: Uint}, + R8Sint => {vk: FORMAT_R8_SINT, bdim: (1, 1), size: Some(1), ty: Sint}, + R8Srgb => {vk: FORMAT_R8_SRGB, bdim: (1, 1), size: Some(1), ty: Float}, + R8G8Unorm => {vk: FORMAT_R8G8_UNORM, bdim: (1, 1), size: Some(2), ty: Float}, + R8G8Snorm => {vk: FORMAT_R8G8_SNORM, bdim: (1, 1), size: Some(2), ty: Float}, + R8G8Uscaled => {vk: FORMAT_R8G8_USCALED, bdim: (1, 1), size: Some(2), ty: Float}, + R8G8Sscaled => {vk: FORMAT_R8G8_SSCALED, bdim: (1, 1), size: Some(2), ty: Float}, + R8G8Uint => {vk: FORMAT_R8G8_UINT, bdim: (1, 1), size: Some(2), ty: Uint}, + R8G8Sint => {vk: FORMAT_R8G8_SINT, bdim: (1, 1), size: Some(2), ty: Sint}, + R8G8Srgb => {vk: FORMAT_R8G8_SRGB, bdim: (1, 1), size: Some(2), ty: Float}, + R8G8B8Unorm => {vk: FORMAT_R8G8B8_UNORM, bdim: (1, 1), size: Some(3), ty: Float}, + R8G8B8Snorm => {vk: FORMAT_R8G8B8_SNORM, bdim: (1, 1), size: Some(3), ty: Float}, + R8G8B8Uscaled => {vk: FORMAT_R8G8B8_USCALED, bdim: (1, 1), size: Some(3), ty: Float}, + R8G8B8Sscaled => {vk: FORMAT_R8G8B8_SSCALED, bdim: (1, 1), size: Some(3), ty: Float}, + R8G8B8Uint => {vk: FORMAT_R8G8B8_UINT, bdim: (1, 1), size: Some(3), ty: Uint}, + R8G8B8Sint => {vk: FORMAT_R8G8B8_SINT, bdim: (1, 1), size: Some(3), ty: Sint}, + R8G8B8Srgb => {vk: FORMAT_R8G8B8_SRGB, bdim: (1, 1), size: Some(3), ty: Float}, + B8G8R8Unorm => {vk: FORMAT_B8G8R8_UNORM, bdim: (1, 1), size: Some(3), ty: Float}, + B8G8R8Snorm => {vk: FORMAT_B8G8R8_SNORM, bdim: (1, 1), size: Some(3), ty: Float}, + B8G8R8Uscaled => {vk: FORMAT_B8G8R8_USCALED, bdim: (1, 1), size: Some(3), ty: Float}, + B8G8R8Sscaled => {vk: FORMAT_B8G8R8_SSCALED, bdim: (1, 1), size: Some(3), ty: Float}, + B8G8R8Uint => {vk: FORMAT_B8G8R8_UINT, bdim: (1, 1), size: Some(3), ty: Uint}, + B8G8R8Sint => {vk: FORMAT_B8G8R8_SINT, bdim: (1, 1), size: Some(3), ty: Sint}, + B8G8R8Srgb => {vk: FORMAT_B8G8R8_SRGB, bdim: (1, 1), size: Some(3), ty: Float}, + R8G8B8A8Unorm => {vk: FORMAT_R8G8B8A8_UNORM, bdim: (1, 1), size: Some(4), ty: Float}, + R8G8B8A8Snorm => {vk: FORMAT_R8G8B8A8_SNORM, bdim: (1, 1), size: Some(4), ty: Float}, + R8G8B8A8Uscaled => {vk: FORMAT_R8G8B8A8_USCALED, bdim: (1, 1), size: Some(4), ty: Float}, + R8G8B8A8Sscaled => {vk: FORMAT_R8G8B8A8_SSCALED, bdim: (1, 1), size: Some(4), ty: Float}, + R8G8B8A8Uint => {vk: FORMAT_R8G8B8A8_UINT, bdim: (1, 1), size: Some(4), ty: Uint}, + R8G8B8A8Sint => {vk: FORMAT_R8G8B8A8_SINT, bdim: (1, 1), size: Some(4), ty: Sint}, + R8G8B8A8Srgb => {vk: FORMAT_R8G8B8A8_SRGB, bdim: (1, 1), size: Some(4), ty: Float}, + B8G8R8A8Unorm => {vk: FORMAT_B8G8R8A8_UNORM, bdim: (1, 1), size: Some(4), ty: Float}, + B8G8R8A8Snorm => {vk: FORMAT_B8G8R8A8_SNORM, bdim: (1, 1), size: Some(4), ty: Float}, + B8G8R8A8Uscaled => {vk: FORMAT_B8G8R8A8_USCALED, bdim: (1, 1), size: Some(4), ty: Float}, + B8G8R8A8Sscaled => {vk: FORMAT_B8G8R8A8_SSCALED, bdim: (1, 1), size: Some(4), ty: Float}, + B8G8R8A8Uint => {vk: FORMAT_B8G8R8A8_UINT, bdim: (1, 1), size: Some(4), ty: Uint}, + B8G8R8A8Sint => {vk: FORMAT_B8G8R8A8_SINT, bdim: (1, 1), size: Some(4), ty: Sint}, + B8G8R8A8Srgb => {vk: FORMAT_B8G8R8A8_SRGB, bdim: (1, 1), size: Some(4), ty: Float}, + A8B8G8R8UnormPack32 => {vk: FORMAT_A8B8G8R8_UNORM_PACK32, bdim: (1, 1), size: Some(4), ty: Float}, + A8B8G8R8SnormPack32 => {vk: FORMAT_A8B8G8R8_SNORM_PACK32, bdim: (1, 1), size: Some(4), ty: Float}, + A8B8G8R8UscaledPack32 => {vk: FORMAT_A8B8G8R8_USCALED_PACK32, bdim: (1, 1), size: Some(4), ty: Float}, + A8B8G8R8SscaledPack32 => {vk: FORMAT_A8B8G8R8_SSCALED_PACK32, bdim: (1, 1), size: Some(4), ty: Float}, + A8B8G8R8UintPack32 => {vk: FORMAT_A8B8G8R8_UINT_PACK32, bdim: (1, 1), size: Some(4), ty: Uint}, + A8B8G8R8SintPack32 => {vk: FORMAT_A8B8G8R8_SINT_PACK32, bdim: (1, 1), size: Some(4), ty: Sint}, + A8B8G8R8SrgbPack32 => {vk: FORMAT_A8B8G8R8_SRGB_PACK32, bdim: (1, 1), size: Some(4), ty: Float}, + A2R10G10B10UnormPack32 => {vk: FORMAT_A2R10G10B10_UNORM_PACK32, bdim: (1, 1), size: Some(4), ty: Float}, + A2R10G10B10SnormPack32 => {vk: FORMAT_A2R10G10B10_SNORM_PACK32, bdim: (1, 1), size: Some(4), ty: Float}, + A2R10G10B10UscaledPack32 => {vk: FORMAT_A2R10G10B10_USCALED_PACK32, bdim: (1, 1), size: Some(4), ty: Float}, + A2R10G10B10SscaledPack32 => {vk: FORMAT_A2R10G10B10_SSCALED_PACK32, bdim: (1, 1), size: Some(4), ty: Float}, + A2R10G10B10UintPack32 => {vk: FORMAT_A2R10G10B10_UINT_PACK32, bdim: (1, 1), size: Some(4), ty: Uint}, + A2R10G10B10SintPack32 => {vk: FORMAT_A2R10G10B10_SINT_PACK32, bdim: (1, 1), size: Some(4), ty: Sint}, + A2B10G10R10UnormPack32 => {vk: FORMAT_A2B10G10R10_UNORM_PACK32, bdim: (1, 1), size: Some(4), ty: Float}, + A2B10G10R10SnormPack32 => {vk: FORMAT_A2B10G10R10_SNORM_PACK32, bdim: (1, 1), size: Some(4), ty: Float}, + A2B10G10R10UscaledPack32 => {vk: FORMAT_A2B10G10R10_USCALED_PACK32, bdim: (1, 1), size: Some(4), ty: Float}, + A2B10G10R10SscaledPack32 => {vk: FORMAT_A2B10G10R10_SSCALED_PACK32, bdim: (1, 1), size: Some(4), ty: Float}, + A2B10G10R10UintPack32 => {vk: FORMAT_A2B10G10R10_UINT_PACK32, bdim: (1, 1), size: Some(4), ty: Uint}, + A2B10G10R10SintPack32 => {vk: FORMAT_A2B10G10R10_SINT_PACK32, bdim: (1, 1), size: Some(4), ty: Sint}, + R16Unorm => {vk: FORMAT_R16_UNORM, bdim: (1, 1), size: Some(2), ty: Float}, + R16Snorm => {vk: FORMAT_R16_SNORM, bdim: (1, 1), size: Some(2), ty: Float}, + R16Uscaled => {vk: FORMAT_R16_USCALED, bdim: (1, 1), size: Some(2), ty: Float}, + R16Sscaled => {vk: FORMAT_R16_SSCALED, bdim: (1, 1), size: Some(2), ty: Float}, + R16Uint => {vk: FORMAT_R16_UINT, bdim: (1, 1), size: Some(2), ty: Uint}, + R16Sint => {vk: FORMAT_R16_SINT, bdim: (1, 1), size: Some(2), ty: Sint}, + R16Sfloat => {vk: FORMAT_R16_SFLOAT, bdim: (1, 1), size: Some(2), ty: Float}, + R16G16Unorm => {vk: FORMAT_R16G16_UNORM, bdim: (1, 1), size: Some(4), ty: Float}, + R16G16Snorm => {vk: FORMAT_R16G16_SNORM, bdim: (1, 1), size: Some(4), ty: Float}, + R16G16Uscaled => {vk: FORMAT_R16G16_USCALED, bdim: (1, 1), size: Some(4), ty: Float}, + R16G16Sscaled => {vk: FORMAT_R16G16_SSCALED, bdim: (1, 1), size: Some(4), ty: Float}, + R16G16Uint => {vk: FORMAT_R16G16_UINT, bdim: (1, 1), size: Some(4), ty: Uint}, + R16G16Sint => {vk: FORMAT_R16G16_SINT, bdim: (1, 1), size: Some(4), ty: Sint}, + R16G16Sfloat => {vk: FORMAT_R16G16_SFLOAT, bdim: (1, 1), size: Some(4), ty: Float}, + R16G16B16Unorm => {vk: FORMAT_R16G16B16_UNORM, bdim: (1, 1), size: Some(6), ty: Float}, + R16G16B16Snorm => {vk: FORMAT_R16G16B16_SNORM, bdim: (1, 1), size: Some(6), ty: Float}, + R16G16B16Uscaled => {vk: FORMAT_R16G16B16_USCALED, bdim: (1, 1), size: Some(6), ty: Float}, + R16G16B16Sscaled => {vk: FORMAT_R16G16B16_SSCALED, bdim: (1, 1), size: Some(6), ty: Float}, + R16G16B16Uint => {vk: FORMAT_R16G16B16_UINT, bdim: (1, 1), size: Some(6), ty: Uint}, + R16G16B16Sint => {vk: FORMAT_R16G16B16_SINT, bdim: (1, 1), size: Some(6), ty: Sint}, + R16G16B16Sfloat => {vk: FORMAT_R16G16B16_SFLOAT, bdim: (1, 1), size: Some(6), ty: Float}, + R16G16B16A16Unorm => {vk: FORMAT_R16G16B16A16_UNORM, bdim: (1, 1), size: Some(8), ty: Float}, + R16G16B16A16Snorm => {vk: FORMAT_R16G16B16A16_SNORM, bdim: (1, 1), size: Some(8), ty: Float}, + R16G16B16A16Uscaled => {vk: FORMAT_R16G16B16A16_USCALED, bdim: (1, 1), size: Some(8), ty: Float}, + R16G16B16A16Sscaled => {vk: FORMAT_R16G16B16A16_SSCALED, bdim: (1, 1), size: Some(8), ty: Float}, + R16G16B16A16Uint => {vk: FORMAT_R16G16B16A16_UINT, bdim: (1, 1), size: Some(8), ty: Uint}, + R16G16B16A16Sint => {vk: FORMAT_R16G16B16A16_SINT, bdim: (1, 1), size: Some(8), ty: Sint}, + R16G16B16A16Sfloat => {vk: FORMAT_R16G16B16A16_SFLOAT, bdim: (1, 1), size: Some(8), ty: Float}, + R32Uint => {vk: FORMAT_R32_UINT, bdim: (1, 1), size: Some(4), ty: Uint}, + R32Sint => {vk: FORMAT_R32_SINT, bdim: (1, 1), size: Some(4), ty: Sint}, + R32Sfloat => {vk: FORMAT_R32_SFLOAT, bdim: (1, 1), size: Some(4), ty: Float}, + R32G32Uint => {vk: FORMAT_R32G32_UINT, bdim: (1, 1), size: Some(8), ty: Uint}, + R32G32Sint => {vk: FORMAT_R32G32_SINT, bdim: (1, 1), size: Some(8), ty: Sint}, + R32G32Sfloat => {vk: FORMAT_R32G32_SFLOAT, bdim: (1, 1), size: Some(8), ty: Float}, + R32G32B32Uint => {vk: FORMAT_R32G32B32_UINT, bdim: (1, 1), size: Some(12), ty: Uint}, + R32G32B32Sint => {vk: FORMAT_R32G32B32_SINT, bdim: (1, 1), size: Some(12), ty: Sint}, + R32G32B32Sfloat => {vk: FORMAT_R32G32B32_SFLOAT, bdim: (1, 1), size: Some(12), ty: Float}, + R32G32B32A32Uint => {vk: FORMAT_R32G32B32A32_UINT, bdim: (1, 1), size: Some(16), ty: Uint}, + R32G32B32A32Sint => {vk: FORMAT_R32G32B32A32_SINT, bdim: (1, 1), size: Some(16), ty: Sint}, + R32G32B32A32Sfloat => {vk: FORMAT_R32G32B32A32_SFLOAT, bdim: (1, 1), size: Some(16), ty: Float}, + R64Uint => {vk: FORMAT_R64_UINT, bdim: (1, 1), size: Some(8), ty: Uint}, + R64Sint => {vk: FORMAT_R64_SINT, bdim: (1, 1), size: Some(8), ty: Sint}, + R64Sfloat => {vk: FORMAT_R64_SFLOAT, bdim: (1, 1), size: Some(8), ty: Float}, + R64G64Uint => {vk: FORMAT_R64G64_UINT, bdim: (1, 1), size: Some(16), ty: Uint}, + R64G64Sint => {vk: FORMAT_R64G64_SINT, bdim: (1, 1), size: Some(16), ty: Sint}, + R64G64Sfloat => {vk: FORMAT_R64G64_SFLOAT, bdim: (1, 1), size: Some(16), ty: Float}, + R64G64B64Uint => {vk: FORMAT_R64G64B64_UINT, bdim: (1, 1), size: Some(24), ty: Uint}, + R64G64B64Sint => {vk: FORMAT_R64G64B64_SINT, bdim: (1, 1), size: Some(24), ty: Sint}, + R64G64B64Sfloat => {vk: FORMAT_R64G64B64_SFLOAT, bdim: (1, 1), size: Some(24), ty: Float}, + R64G64B64A64Uint => {vk: FORMAT_R64G64B64A64_UINT, bdim: (1, 1), size: Some(32), ty: Uint}, + R64G64B64A64Sint => {vk: FORMAT_R64G64B64A64_SINT, bdim: (1, 1), size: Some(32), ty: Sint}, + R64G64B64A64Sfloat => {vk: FORMAT_R64G64B64A64_SFLOAT, bdim: (1, 1), size: Some(32), ty: Float}, + B10G11R11UfloatPack32 => {vk: FORMAT_B10G11R11_UFLOAT_PACK32, bdim: (1, 1), size: Some(4), ty: Float}, + E5B9G9R9UfloatPack32 => {vk: FORMAT_E5B9G9R9_UFLOAT_PACK32, bdim: (1, 1), size: Some(4), ty: Float}, + D16Unorm => {vk: FORMAT_D16_UNORM, bdim: (1, 1), size: Some(2), ty: Depth}, + X8_D24UnormPack32 => {vk: FORMAT_X8_D24_UNORM_PACK32, bdim: (1, 1), size: Some(4), ty: Depth}, + D32Sfloat => {vk: FORMAT_D32_SFLOAT, bdim: (1, 1), size: Some(4), ty: Depth}, + S8Uint => {vk: FORMAT_S8_UINT, bdim: (1, 1), size: Some(1), ty: Stencil}, + D16Unorm_S8Uint => {vk: FORMAT_D16_UNORM_S8_UINT, bdim: (1, 1), size: None, ty: DepthStencil}, + D24Unorm_S8Uint => {vk: FORMAT_D24_UNORM_S8_UINT, bdim: (1, 1), size: None, ty: DepthStencil}, + D32Sfloat_S8Uint => {vk: FORMAT_D32_SFLOAT_S8_UINT, bdim: (1, 1), size: None, ty: DepthStencil}, + BC1_RGBUnormBlock => {vk: FORMAT_BC1_RGB_UNORM_BLOCK, bdim: (4, 4), size: Some(8), ty: Compressed}, + BC1_RGBSrgbBlock => {vk: FORMAT_BC1_RGB_SRGB_BLOCK, bdim: (4, 4), size: Some(8), ty: Compressed}, + BC1_RGBAUnormBlock => {vk: FORMAT_BC1_RGBA_UNORM_BLOCK, bdim: (4, 4), size: Some(8), ty: Compressed}, + BC1_RGBASrgbBlock => {vk: FORMAT_BC1_RGBA_SRGB_BLOCK, bdim: (4, 4), size: Some(8), ty: Compressed}, + BC2UnormBlock => {vk: FORMAT_BC2_UNORM_BLOCK, bdim: (4, 4), size: Some(16), ty: Compressed}, + BC2SrgbBlock => {vk: FORMAT_BC2_SRGB_BLOCK, bdim: (4, 4), size: Some(16), ty: Compressed}, + BC3UnormBlock => {vk: FORMAT_BC3_UNORM_BLOCK, bdim: (4, 4), size: Some(16), ty: Compressed}, + BC3SrgbBlock => {vk: FORMAT_BC3_SRGB_BLOCK, bdim: (4, 4), size: Some(16), ty: Compressed}, + BC4UnormBlock => {vk: FORMAT_BC4_UNORM_BLOCK, bdim: (4, 4), size: Some(8), ty: Compressed}, + BC4SnormBlock => {vk: FORMAT_BC4_SNORM_BLOCK, bdim: (4, 4), size: Some(8), ty: Compressed}, + BC5UnormBlock => {vk: FORMAT_BC5_UNORM_BLOCK, bdim: (4, 4), size: Some(16), ty: Compressed}, + BC5SnormBlock => {vk: FORMAT_BC5_SNORM_BLOCK, bdim: (4, 4), size: Some(16), ty: Compressed}, + BC6HUfloatBlock => {vk: FORMAT_BC6H_UFLOAT_BLOCK, bdim: (4, 4), size: Some(16), ty: Compressed}, + BC6HSfloatBlock => {vk: FORMAT_BC6H_SFLOAT_BLOCK, bdim: (4, 4), size: Some(16), ty: Compressed}, + BC7UnormBlock => {vk: FORMAT_BC7_UNORM_BLOCK, bdim: (4, 4), size: Some(16), ty: Compressed}, + BC7SrgbBlock => {vk: FORMAT_BC7_SRGB_BLOCK, bdim: (4, 4), size: Some(16), ty: Compressed}, + ETC2_R8G8B8UnormBlock => {vk: FORMAT_ETC2_R8G8B8_UNORM_BLOCK, bdim: (4, 4), size: Some(8), ty: Compressed}, + ETC2_R8G8B8SrgbBlock => {vk: FORMAT_ETC2_R8G8B8_SRGB_BLOCK, bdim: (4, 4), size: Some(8), ty: Compressed}, + ETC2_R8G8B8A1UnormBlock => {vk: FORMAT_ETC2_R8G8B8A1_UNORM_BLOCK, bdim: (4, 4), size: Some(8), ty: Compressed}, + ETC2_R8G8B8A1SrgbBlock => {vk: FORMAT_ETC2_R8G8B8A1_SRGB_BLOCK, bdim: (4, 4), size: Some(8), ty: Compressed}, + ETC2_R8G8B8A8UnormBlock => {vk: FORMAT_ETC2_R8G8B8A8_UNORM_BLOCK, bdim: (4, 4), size: Some(16), ty: Compressed}, + ETC2_R8G8B8A8SrgbBlock => {vk: FORMAT_ETC2_R8G8B8A8_SRGB_BLOCK, bdim: (4, 4), size: Some(16), ty: Compressed}, + EAC_R11UnormBlock => {vk: FORMAT_EAC_R11_UNORM_BLOCK, bdim: (4, 4), size: Some(8), ty: Compressed}, + EAC_R11SnormBlock => {vk: FORMAT_EAC_R11_SNORM_BLOCK, bdim: (4, 4), size: Some(8), ty: Compressed}, + EAC_R11G11UnormBlock => {vk: FORMAT_EAC_R11G11_UNORM_BLOCK, bdim: (4, 4), size: Some(16), ty: Compressed}, + EAC_R11G11SnormBlock => {vk: FORMAT_EAC_R11G11_SNORM_BLOCK, bdim: (4, 4), size: Some(16), ty: Compressed}, + ASTC_4x4UnormBlock => {vk: FORMAT_ASTC_4x4_UNORM_BLOCK, bdim: (4, 4), size: Some(16), ty: Compressed}, + ASTC_4x4SrgbBlock => {vk: FORMAT_ASTC_4x4_SRGB_BLOCK, bdim: (4, 4), size: Some(16), ty: Compressed}, + ASTC_5x4UnormBlock => {vk: FORMAT_ASTC_5x4_UNORM_BLOCK, bdim: (5, 4), size: Some(16), ty: Compressed}, + ASTC_5x4SrgbBlock => {vk: FORMAT_ASTC_5x4_SRGB_BLOCK, bdim: (5, 4), size: Some(16), ty: Compressed}, + ASTC_5x5UnormBlock => {vk: FORMAT_ASTC_5x5_UNORM_BLOCK, bdim: (5, 5), size: Some(16), ty: Compressed}, + ASTC_5x5SrgbBlock => {vk: FORMAT_ASTC_5x5_SRGB_BLOCK, bdim: (5, 5), size: Some(16), ty: Compressed}, + ASTC_6x5UnormBlock => {vk: FORMAT_ASTC_6x5_UNORM_BLOCK, bdim: (6, 5), size: Some(16), ty: Compressed}, + ASTC_6x5SrgbBlock => {vk: FORMAT_ASTC_6x5_SRGB_BLOCK, bdim: (6, 5), size: Some(16), ty: Compressed}, + ASTC_6x6UnormBlock => {vk: FORMAT_ASTC_6x6_UNORM_BLOCK, bdim: (6, 6), size: Some(16), ty: Compressed}, + ASTC_6x6SrgbBlock => {vk: FORMAT_ASTC_6x6_SRGB_BLOCK, bdim: (6, 6), size: Some(16), ty: Compressed}, + ASTC_8x5UnormBlock => {vk: FORMAT_ASTC_8x5_UNORM_BLOCK, bdim: (8, 5), size: Some(16), ty: Compressed}, + ASTC_8x5SrgbBlock => {vk: FORMAT_ASTC_8x5_SRGB_BLOCK, bdim: (8, 5), size: Some(16), ty: Compressed}, + ASTC_8x6UnormBlock => {vk: FORMAT_ASTC_8x6_UNORM_BLOCK, bdim: (8, 6), size: Some(16), ty: Compressed}, + ASTC_8x6SrgbBlock => {vk: FORMAT_ASTC_8x6_SRGB_BLOCK, bdim: (8, 6), size: Some(16), ty: Compressed}, + ASTC_8x8UnormBlock => {vk: FORMAT_ASTC_8x8_UNORM_BLOCK, bdim: (8, 8), size: Some(16), ty: Compressed}, + ASTC_8x8SrgbBlock => {vk: FORMAT_ASTC_8x8_SRGB_BLOCK, bdim: (8, 8), size: Some(16), ty: Compressed}, + ASTC_10x5UnormBlock => {vk: FORMAT_ASTC_10x5_UNORM_BLOCK, bdim: (10, 5), size: Some(16), ty: Compressed}, + ASTC_10x5SrgbBlock => {vk: FORMAT_ASTC_10x5_SRGB_BLOCK, bdim: (10, 5), size: Some(16), ty: Compressed}, + ASTC_10x6UnormBlock => {vk: FORMAT_ASTC_10x6_UNORM_BLOCK, bdim: (10, 6), size: Some(16), ty: Compressed}, + ASTC_10x6SrgbBlock => {vk: FORMAT_ASTC_10x6_SRGB_BLOCK, bdim: (10, 6), size: Some(16), ty: Compressed}, + ASTC_10x8UnormBlock => {vk: FORMAT_ASTC_10x8_UNORM_BLOCK, bdim: (10, 8), size: Some(16), ty: Compressed}, + ASTC_10x8SrgbBlock => {vk: FORMAT_ASTC_10x8_SRGB_BLOCK, bdim: (10, 8), size: Some(16), ty: Compressed}, + ASTC_10x10UnormBlock => {vk: FORMAT_ASTC_10x10_UNORM_BLOCK, bdim: (10, 10), size: Some(16), ty: Compressed}, + ASTC_10x10SrgbBlock => {vk: FORMAT_ASTC_10x10_SRGB_BLOCK, bdim: (10, 10), size: Some(16), ty: Compressed}, + ASTC_12x10UnormBlock => {vk: FORMAT_ASTC_12x10_UNORM_BLOCK, bdim: (12, 10), size: Some(16), ty: Compressed}, + ASTC_12x10SrgbBlock => {vk: FORMAT_ASTC_12x10_SRGB_BLOCK, bdim: (12, 10), size: Some(16), ty: Compressed}, + ASTC_12x12UnormBlock => {vk: FORMAT_ASTC_12x12_UNORM_BLOCK, bdim: (12, 12), size: Some(16), ty: Compressed}, + ASTC_12x12SrgbBlock => {vk: FORMAT_ASTC_12x12_SRGB_BLOCK, bdim: (12, 12), size: Some(16), ty: Compressed}, + G8B8R8_3PLANE420Unorm => {vk: FORMAT_G8_B8_R8_3PLANE_420_UNORM, bdim: (1, 1), size: None, ty: Ycbcr, planes: 3}, + G8B8R8_2PLANE420Unorm => {vk: FORMAT_G8_B8R8_2PLANE_420_UNORM, bdim: (1, 1), size: None, ty: Ycbcr, planes: 2}, } -pub unsafe trait FormatDesc { - type ClearValue; - - fn format(&self) -> Format; - - fn decode_clear_value(&self, value: Self::ClearValue) -> ClearValue; -} - -unsafe impl FormatDesc for Format { - type ClearValue = ClearValue; - +impl Format { + /// Returns the aspects that images of this format have. #[inline] - fn format(&self) -> Format { - *self + pub const fn aspects(&self) -> ImageAspects { + let ty = self.ty(); + let planes = self.planes(); + ImageAspects { + color: matches!( + ty, + FormatTy::Float | FormatTy::Uint | FormatTy::Sint | FormatTy::Compressed + ), + depth: matches!(ty, FormatTy::Depth | FormatTy::DepthStencil), + stencil: matches!(ty, FormatTy::Stencil | FormatTy::DepthStencil), + plane0: planes >= 1, + plane1: planes >= 2, + plane2: planes >= 3, + ..ImageAspects::none() + } } - fn decode_clear_value(&self, value: Self::ClearValue) -> ClearValue { + /// Retrieves the properties of a format when used by a certain device. + #[inline] + pub fn properties(&self, physical_device: PhysicalDevice) -> FormatProperties { + let vk_properties = unsafe { + let vk_i = physical_device.instance().pointers(); + let mut output = MaybeUninit::uninit(); + vk_i.GetPhysicalDeviceFormatProperties( + physical_device.internal_object(), + (*self).into(), + output.as_mut_ptr(), + ); + output.assume_init() + }; + + FormatProperties { + linear_tiling_features: vk_properties.linearTilingFeatures.into(), + optimal_tiling_features: vk_properties.optimalTilingFeatures.into(), + buffer_features: vk_properties.bufferFeatures.into(), + } + } + + #[inline] + pub fn decode_clear_value(&self, value: ClearValue) -> ClearValue { match (self.ty(), value) { (FormatTy::Float, f @ ClearValue::Float(_)) => f, (FormatTy::Compressed, f @ ClearValue::Float(_)) => f, @@ -704,108 +436,44 @@ unsafe impl FormatDesc for Format { } } -/// Trait for types that can possibly describe a float attachment. -pub unsafe trait PossibleFloatFormatDesc: FormatDesc { - /// Returns true if the format is a float format. - fn is_float(&self) -> bool; +#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +pub enum FormatTy { + Float, + Uint, + Sint, + Depth, + Stencil, + DepthStencil, + Compressed, + Ycbcr, } -unsafe impl PossibleFloatFormatDesc for Format { +/// Trait for Rust types that can represent a pixel in an image. +pub unsafe trait Pixel { + /// Returns an error if `Self` cannot be used as a source of pixels for `format`. + fn ensure_accepts(format: Format) -> Result<(), IncompatiblePixelsType>; + + /// The number of `Self`s which make up a single pixel. + /// + /// # Panics + /// + /// May panic if `ensure_accepts` would not return `Ok(())`. + fn rate(format: Format) -> u32; +} + +#[derive(Debug, Copy, Clone, PartialEq, Eq)] +pub struct IncompatiblePixelsType; + +impl error::Error for IncompatiblePixelsType {} + +impl fmt::Display for IncompatiblePixelsType { #[inline] - fn is_float(&self) -> bool { - self.ty() == FormatTy::Float - } -} - -pub unsafe trait PossibleUintFormatDesc: FormatDesc { - fn is_uint(&self) -> bool; -} - -unsafe impl PossibleUintFormatDesc for Format { - #[inline] - fn is_uint(&self) -> bool { - self.ty() == FormatTy::Uint - } -} - -pub unsafe trait PossibleSintFormatDesc: FormatDesc { - fn is_sint(&self) -> bool; -} - -unsafe impl PossibleSintFormatDesc for Format { - #[inline] - fn is_sint(&self) -> bool { - self.ty() == FormatTy::Sint - } -} - -pub unsafe trait PossibleDepthFormatDesc: FormatDesc { - fn is_depth(&self) -> bool; -} - -unsafe impl PossibleDepthFormatDesc for Format { - #[inline] - fn is_depth(&self) -> bool { - self.ty() == FormatTy::Depth - } -} - -pub unsafe trait PossibleStencilFormatDesc: FormatDesc { - fn is_stencil(&self) -> bool; -} - -unsafe impl PossibleStencilFormatDesc for Format { - #[inline] - fn is_stencil(&self) -> bool { - self.ty() == FormatTy::Stencil - } -} - -pub unsafe trait PossibleDepthStencilFormatDesc: FormatDesc { - fn is_depth_stencil(&self) -> bool; -} - -unsafe impl PossibleDepthStencilFormatDesc for Format { - #[inline] - fn is_depth_stencil(&self) -> bool { - self.ty() == FormatTy::DepthStencil - } -} - -pub unsafe trait PossibleCompressedFormatDesc: FormatDesc { - fn is_compressed(&self) -> bool; -} - -unsafe impl PossibleCompressedFormatDesc for Format { - #[inline] - fn is_compressed(&self) -> bool { - self.ty() == FormatTy::Compressed - } -} - -/// Trait for types that can possibly describe a float or compressed attachment. -pub unsafe trait PossibleFloatOrCompressedFormatDesc: FormatDesc { - /// Returns true if the format is a float or compressed format. - fn is_float_or_compressed(&self) -> bool; -} - -unsafe impl PossibleFloatOrCompressedFormatDesc for Format { - #[inline] - fn is_float_or_compressed(&self) -> bool { - self.ty() == FormatTy::Float || self.ty() == FormatTy::Compressed - } -} - -/// Trait for types that can possibly describe a Ycbcr format. -pub unsafe trait PossibleYcbcrFormatDesc: FormatDesc { - /// Trait for types that can possibly describe a Ycbcr format. - fn is_ycbcr(&self) -> bool; -} - -unsafe impl PossibleYcbcrFormatDesc for Format { - #[inline] - fn is_ycbcr(&self) -> bool { - self.ty() == FormatTy::Ycbcr + fn fmt(&self, fmt: &mut fmt::Formatter) -> Result<(), fmt::Error> { + write!( + fmt, + "{}", + "supplied pixels' type is incompatible with this format" + ) } } @@ -822,17 +490,18 @@ macro_rules! impl_pixel { $(impl_pixel!(inner ($ty, $ty, $ty, $ty));)* }; (inner $ty:ty) => { - unsafe impl AcceptsPixels<$ty> for Format { - fn ensure_accepts(&self) -> Result<(), IncompatiblePixelsType> { + unsafe impl Pixel for $ty { + fn ensure_accepts(format: Format) -> Result<(), IncompatiblePixelsType> { // TODO: Be more strict: accept only if the format has a matching AcceptsPixels impl. - if self.size().map_or(false, |x| x % mem::size_of::<$ty>() == 0) { + if format.size().map_or(false, |x| x % mem::size_of::<$ty>() == 0) { Ok(()) } else { Err(IncompatiblePixelsType) } } - fn rate(&self) -> u32 { - (self.size().expect("this format cannot accept pixels") / mem::size_of::<$ty>()) as u32 + + fn rate(format: Format) -> u32 { + (format.size().expect("this format cannot accept pixels") / mem::size_of::<$ty>()) as u32 } } } @@ -842,33 +511,6 @@ impl_pixel! { u8; i8; u16; i16; u32; i32; u64; i64; f16; f32; f64; } -pub unsafe trait StrongStorage: FormatDesc { - type Pixel: Copy; -} - -#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] -pub enum FormatTy { - Float, - Uint, - Sint, - Depth, - Stencil, - DepthStencil, - Compressed, - Ycbcr, -} - -impl FormatTy { - /// Returns true if `Depth`, `Stencil`, `DepthStencil`. False otherwise. - #[inline] - pub fn is_depth_and_or_stencil(&self) -> bool { - match *self { - FormatTy::Depth | FormatTy::Stencil | FormatTy::DepthStencil => true, - _ => false, - } - } -} - /// Describes a uniform value that will be used to fill an image. // TODO: should have the same layout as `vk::ClearValue` for performance #[derive(Debug, Copy, Clone, PartialEq)] @@ -1081,10 +723,10 @@ pub struct FormatFeatures { pub ext_fragment_density_map: bool, } -impl FormatFeatures { +impl From for FormatFeatures { #[inline] #[rustfmt::skip] - pub(crate) fn from_bits(val: u32) -> FormatFeatures { + fn from(val: vk::FormatFeatureFlags) -> FormatFeatures { FormatFeatures { sampled_image: (val & vk::FORMAT_FEATURE_SAMPLED_IMAGE_BIT) != 0, storage_image: (val & vk::FORMAT_FEATURE_STORAGE_IMAGE_BIT) != 0, diff --git a/vulkano/src/image/aspect.rs b/vulkano/src/image/aspect.rs index 2023d9e6..10731500 100644 --- a/vulkano/src/image/aspect.rs +++ b/vulkano/src/image/aspect.rs @@ -10,13 +10,34 @@ use crate::vk; use std::ops::BitOr; -/// Describes how an aspect of the image that be used to query Vulkan. This is **not** just a suggestion. -/// Check out VkImageAspectFlagBits in the Vulkan spec. +/// An individual data type within an image. /// -/// If you specify an aspect of the image that doesn't exist (for example, depth for a YUV image), a panic -/// will happen. -#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] -pub struct ImageAspect { +/// Most images have only the `Color` aspect, but some may have several. +#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] +#[repr(u32)] +pub enum ImageAspect { + Color = vk::IMAGE_ASPECT_COLOR_BIT, + Depth = vk::IMAGE_ASPECT_DEPTH_BIT, + Stencil = vk::IMAGE_ASPECT_STENCIL_BIT, + Metadata = vk::IMAGE_ASPECT_METADATA_BIT, + Plane0 = vk::IMAGE_ASPECT_PLANE_0_BIT, + Plane1 = vk::IMAGE_ASPECT_PLANE_1_BIT, + Plane2 = vk::IMAGE_ASPECT_PLANE_2_BIT, + MemoryPlane0 = vk::IMAGE_ASPECT_MEMORY_PLANE_0_BIT_EXT, + MemoryPlane1 = vk::IMAGE_ASPECT_MEMORY_PLANE_1_BIT_EXT, + MemoryPlane2 = vk::IMAGE_ASPECT_MEMORY_PLANE_2_BIT_EXT, +} + +impl From for vk::ImageAspectFlags { + #[inline] + fn from(value: ImageAspect) -> vk::ImageAspectFlags { + value as u32 + } +} + +/// A mask specifying one or more `ImageAspect`s. +#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)] +pub struct ImageAspects { pub color: bool, pub depth: bool, pub stencil: bool, @@ -29,23 +50,11 @@ pub struct ImageAspect { pub memory_plane2: bool, } -impl ImageAspect { - /// Builds a `ImageAspect` with all values set to false. Useful as a default value. - /// - /// # Example - /// - /// ```rust - /// use vulkano::image::ImageAspect as ImageAspect; - /// - /// let _aspect = ImageAspect { - /// color: true, - /// depth: true, - /// .. ImageAspect::none() - /// }; - /// ``` +impl ImageAspects { + /// Builds an `ImageAspect` with all values set to false. Useful as a default value. #[inline] - pub fn none() -> ImageAspect { - ImageAspect { + pub const fn none() -> ImageAspects { + ImageAspects { color: false, depth: false, stencil: false, @@ -58,65 +67,14 @@ impl ImageAspect { memory_plane2: false, } } - - #[inline] - pub(crate) fn to_aspect_bits(&self) -> vk::ImageAspectFlagBits { - let mut result = 0; - if self.color { - result |= vk::IMAGE_ASPECT_COLOR_BIT; - } - if self.depth { - result |= vk::IMAGE_ASPECT_DEPTH_BIT; - } - if self.stencil { - result |= vk::IMAGE_ASPECT_STENCIL_BIT; - } - if self.metadata { - result |= vk::IMAGE_ASPECT_METADATA_BIT; - } - if self.plane0 { - result |= vk::IMAGE_ASPECT_PLANE_0_BIT; - } - if self.plane1 { - result |= vk::IMAGE_ASPECT_PLANE_1_BIT; - } - if self.plane2 { - result |= vk::IMAGE_ASPECT_PLANE_2_BIT; - } - if self.memory_plane0 { - result |= vk::IMAGE_ASPECT_MEMORY_PLANE_0_BIT_EXT; - } - if self.memory_plane1 { - result |= vk::IMAGE_ASPECT_MEMORY_PLANE_1_BIT_EXT; - } - if self.memory_plane2 { - result |= vk::IMAGE_ASPECT_MEMORY_PLANE_2_BIT_EXT - } - result - } - - pub(crate) fn from_bits(val: u32) -> ImageAspect { - ImageAspect { - color: (val & vk::IMAGE_ASPECT_COLOR_BIT) != 0, - depth: (val & vk::IMAGE_ASPECT_DEPTH_BIT) != 0, - stencil: (val & vk::IMAGE_ASPECT_STENCIL_BIT) != 0, - metadata: (val & vk::IMAGE_ASPECT_METADATA_BIT) != 0, - plane0: (val & vk::IMAGE_ASPECT_PLANE_0_BIT) != 0, - plane1: (val & vk::IMAGE_ASPECT_PLANE_1_BIT) != 0, - plane2: (val & vk::IMAGE_ASPECT_PLANE_2_BIT) != 0, - memory_plane0: (val & vk::IMAGE_ASPECT_MEMORY_PLANE_0_BIT_EXT) != 0, - memory_plane1: (val & vk::IMAGE_ASPECT_MEMORY_PLANE_1_BIT_EXT) != 0, - memory_plane2: (val & vk::IMAGE_ASPECT_MEMORY_PLANE_2_BIT_EXT) != 0, - } - } } -impl BitOr for ImageAspect { +impl BitOr for ImageAspects { type Output = Self; #[inline] fn bitor(self, rhs: Self) -> Self { - ImageAspect { + ImageAspects { color: self.color || rhs.color, depth: self.depth || rhs.depth, stencil: self.stencil || rhs.stencil, @@ -130,3 +88,59 @@ impl BitOr for ImageAspect { } } } + +impl From for vk::ImageAspectFlags { + #[inline] + fn from(value: ImageAspects) -> vk::ImageAspectFlags { + let mut result = 0; + if value.color { + result |= vk::IMAGE_ASPECT_COLOR_BIT; + } + if value.depth { + result |= vk::IMAGE_ASPECT_DEPTH_BIT; + } + if value.stencil { + result |= vk::IMAGE_ASPECT_STENCIL_BIT; + } + if value.metadata { + result |= vk::IMAGE_ASPECT_METADATA_BIT; + } + if value.plane0 { + result |= vk::IMAGE_ASPECT_PLANE_0_BIT; + } + if value.plane1 { + result |= vk::IMAGE_ASPECT_PLANE_1_BIT; + } + if value.plane2 { + result |= vk::IMAGE_ASPECT_PLANE_2_BIT; + } + if value.memory_plane0 { + result |= vk::IMAGE_ASPECT_MEMORY_PLANE_0_BIT_EXT; + } + if value.memory_plane1 { + result |= vk::IMAGE_ASPECT_MEMORY_PLANE_1_BIT_EXT; + } + if value.memory_plane2 { + result |= vk::IMAGE_ASPECT_MEMORY_PLANE_2_BIT_EXT + } + result + } +} + +impl From for ImageAspects { + #[inline] + fn from(val: vk::ImageAspectFlags) -> ImageAspects { + ImageAspects { + color: (val & vk::IMAGE_ASPECT_COLOR_BIT) != 0, + depth: (val & vk::IMAGE_ASPECT_DEPTH_BIT) != 0, + stencil: (val & vk::IMAGE_ASPECT_STENCIL_BIT) != 0, + metadata: (val & vk::IMAGE_ASPECT_METADATA_BIT) != 0, + plane0: (val & vk::IMAGE_ASPECT_PLANE_0_BIT) != 0, + plane1: (val & vk::IMAGE_ASPECT_PLANE_1_BIT) != 0, + plane2: (val & vk::IMAGE_ASPECT_PLANE_2_BIT) != 0, + memory_plane0: (val & vk::IMAGE_ASPECT_MEMORY_PLANE_0_BIT_EXT) != 0, + memory_plane1: (val & vk::IMAGE_ASPECT_MEMORY_PLANE_1_BIT_EXT) != 0, + memory_plane2: (val & vk::IMAGE_ASPECT_MEMORY_PLANE_2_BIT_EXT) != 0, + } + } +} diff --git a/vulkano/src/image/attachment.rs b/vulkano/src/image/attachment.rs index 735cc519..9c3caca3 100644 --- a/vulkano/src/image/attachment.rs +++ b/vulkano/src/image/attachment.rs @@ -7,19 +7,10 @@ // notice may not be copied, modified, or distributed except // according to those terms. -use std::hash::Hash; -use std::hash::Hasher; -use std::iter::Empty; -use std::sync::atomic::AtomicBool; -use std::sync::atomic::AtomicUsize; -use std::sync::atomic::Ordering; -use std::sync::Arc; - use crate::buffer::BufferAccess; use crate::device::Device; use crate::format::ClearValue; use crate::format::Format; -use crate::format::FormatDesc; use crate::format::FormatTy; use crate::image::sys::ImageCreationError; use crate::image::sys::UnsafeImage; @@ -42,6 +33,13 @@ use crate::memory::pool::StdMemoryPoolAlloc; use crate::memory::DedicatedAlloc; use crate::sync::AccessError; use crate::sync::Sharing; +use std::hash::Hash; +use std::hash::Hasher; +use std::iter::Empty; +use std::sync::atomic::AtomicBool; +use std::sync::atomic::AtomicUsize; +use std::sync::atomic::Ordering; +use std::sync::Arc; /// ImageAccess whose purpose is to be used as a framebuffer attachment. /// @@ -73,7 +71,7 @@ use crate::sync::Sharing; /// // TODO: forbid reading transient images outside render passes? #[derive(Debug)] -pub struct AttachmentImage> { +pub struct AttachmentImage> { // Inner implementation. image: UnsafeImage, @@ -81,7 +79,7 @@ pub struct AttachmentImage AttachmentImage { +impl AttachmentImage { /// Creates a new image with the given dimensions and format. /// /// Returns an error if the dimensions are too large or if the backend doesn't support this @@ -104,11 +102,8 @@ impl AttachmentImage { pub fn new( device: Arc, dimensions: [u32; 2], - format: F, - ) -> Result>, ImageCreationError> - where - F: FormatDesc, - { + format: Format, + ) -> Result, ImageCreationError> { AttachmentImage::new_impl(device, dimensions, format, ImageUsage::none(), 1) } @@ -119,11 +114,8 @@ impl AttachmentImage { pub fn input_attachment( device: Arc, dimensions: [u32; 2], - format: F, - ) -> Result>, ImageCreationError> - where - F: FormatDesc, - { + format: Format, + ) -> Result, ImageCreationError> { let base_usage = ImageUsage { input_attachment: true, ..ImageUsage::none() @@ -141,11 +133,8 @@ impl AttachmentImage { device: Arc, dimensions: [u32; 2], samples: u32, - format: F, - ) -> Result>, ImageCreationError> - where - F: FormatDesc, - { + format: Format, + ) -> Result, ImageCreationError> { AttachmentImage::new_impl(device, dimensions, format, ImageUsage::none(), samples) } @@ -157,11 +146,8 @@ impl AttachmentImage { device: Arc, dimensions: [u32; 2], samples: u32, - format: F, - ) -> Result>, ImageCreationError> - where - F: FormatDesc, - { + format: Format, + ) -> Result, ImageCreationError> { let base_usage = ImageUsage { input_attachment: true, ..ImageUsage::none() @@ -179,12 +165,9 @@ impl AttachmentImage { pub fn with_usage( device: Arc, dimensions: [u32; 2], - format: F, + format: Format, usage: ImageUsage, - ) -> Result>, ImageCreationError> - where - F: FormatDesc, - { + ) -> Result, ImageCreationError> { AttachmentImage::new_impl(device, dimensions, format, usage, 1) } @@ -199,12 +182,9 @@ impl AttachmentImage { device: Arc, dimensions: [u32; 2], samples: u32, - format: F, + format: Format, usage: ImageUsage, - ) -> Result>, ImageCreationError> - where - F: FormatDesc, - { + ) -> Result, ImageCreationError> { AttachmentImage::new_impl(device, dimensions, format, usage, samples) } @@ -215,11 +195,8 @@ impl AttachmentImage { pub fn sampled( device: Arc, dimensions: [u32; 2], - format: F, - ) -> Result>, ImageCreationError> - where - F: FormatDesc, - { + format: Format, + ) -> Result, ImageCreationError> { let base_usage = ImageUsage { sampled: true, ..ImageUsage::none() @@ -235,11 +212,8 @@ impl AttachmentImage { pub fn sampled_input_attachment( device: Arc, dimensions: [u32; 2], - format: F, - ) -> Result>, ImageCreationError> - where - F: FormatDesc, - { + format: Format, + ) -> Result, ImageCreationError> { let base_usage = ImageUsage { sampled: true, input_attachment: true, @@ -260,11 +234,8 @@ impl AttachmentImage { device: Arc, dimensions: [u32; 2], samples: u32, - format: F, - ) -> Result>, ImageCreationError> - where - F: FormatDesc, - { + format: Format, + ) -> Result, ImageCreationError> { let base_usage = ImageUsage { sampled: true, ..ImageUsage::none() @@ -282,11 +253,8 @@ impl AttachmentImage { device: Arc, dimensions: [u32; 2], samples: u32, - format: F, - ) -> Result>, ImageCreationError> - where - F: FormatDesc, - { + format: Format, + ) -> Result, ImageCreationError> { let base_usage = ImageUsage { sampled: true, input_attachment: true, @@ -306,11 +274,8 @@ impl AttachmentImage { pub fn transient( device: Arc, dimensions: [u32; 2], - format: F, - ) -> Result>, ImageCreationError> - where - F: FormatDesc, - { + format: Format, + ) -> Result, ImageCreationError> { let base_usage = ImageUsage { transient_attachment: true, ..ImageUsage::none() @@ -326,11 +291,8 @@ impl AttachmentImage { pub fn transient_input_attachment( device: Arc, dimensions: [u32; 2], - format: F, - ) -> Result>, ImageCreationError> - where - F: FormatDesc, - { + format: Format, + ) -> Result, ImageCreationError> { let base_usage = ImageUsage { transient_attachment: true, input_attachment: true, @@ -351,11 +313,8 @@ impl AttachmentImage { device: Arc, dimensions: [u32; 2], samples: u32, - format: F, - ) -> Result>, ImageCreationError> - where - F: FormatDesc, - { + format: Format, + ) -> Result, ImageCreationError> { let base_usage = ImageUsage { transient_attachment: true, ..ImageUsage::none() @@ -373,11 +332,8 @@ impl AttachmentImage { device: Arc, dimensions: [u32; 2], samples: u32, - format: F, - ) -> Result>, ImageCreationError> - where - F: FormatDesc, - { + format: Format, + ) -> Result, ImageCreationError> { let base_usage = ImageUsage { transient_attachment: true, input_attachment: true, @@ -391,16 +347,13 @@ impl AttachmentImage { fn new_impl( device: Arc, dimensions: [u32; 2], - format: F, + format: Format, base_usage: ImageUsage, samples: u32, - ) -> Result>, ImageCreationError> - where - F: FormatDesc, - { + ) -> Result, ImageCreationError> { // TODO: check dimensions against the max_framebuffer_width/height/layers limits - let is_depth = match format.format().ty() { + let is_depth = match format.ty() { FormatTy::Depth => true, FormatTy::DepthStencil => true, FormatTy::Stencil => true, @@ -424,7 +377,7 @@ impl AttachmentImage { UnsafeImage::new( device.clone(), usage, - format.format(), + format, ImageCreateFlags::none(), dims, samples, @@ -469,7 +422,7 @@ impl AttachmentImage { } } -impl AttachmentImage { +impl AttachmentImage { /// Returns the dimensions of the image. #[inline] pub fn dimensions(&self) -> [u32; 2] { @@ -478,10 +431,7 @@ impl AttachmentImage { } } -unsafe impl ImageAccess for AttachmentImage -where - F: 'static + Send + Sync, -{ +unsafe impl ImageAccess for AttachmentImage { #[inline] fn inner(&self) -> ImageInner { ImageInner { @@ -602,42 +552,30 @@ where } } -unsafe impl ImageClearValue for Arc> -where - F: FormatDesc + 'static + Send + Sync, -{ +unsafe impl ImageClearValue for Arc> { #[inline] - fn decode(&self, value: F::ClearValue) -> Option { + fn decode(&self, value: ClearValue) -> Option { Some(self.format.decode_clear_value(value)) } } -unsafe impl ImageContent

for Arc> -where - F: 'static + Send + Sync, -{ +unsafe impl ImageContent

for Arc> { #[inline] fn matches_format(&self) -> bool { true // FIXME: } } -impl PartialEq for AttachmentImage -where - F: 'static + Send + Sync, -{ +impl PartialEq for AttachmentImage { #[inline] fn eq(&self, other: &Self) -> bool { ImageAccess::inner(self) == ImageAccess::inner(other) } } -impl Eq for AttachmentImage where F: 'static + Send + Sync {} +impl Eq for AttachmentImage {} -impl Hash for AttachmentImage -where - F: 'static + Send + Sync, -{ +impl Hash for AttachmentImage { #[inline] fn hash(&self, state: &mut H) { ImageAccess::inner(self).hash(state); diff --git a/vulkano/src/image/immutable.rs b/vulkano/src/image/immutable.rs index e300b1b7..b8947351 100644 --- a/vulkano/src/image/immutable.rs +++ b/vulkano/src/image/immutable.rs @@ -17,9 +17,8 @@ use crate::command_buffer::PrimaryAutoCommandBuffer; use crate::command_buffer::PrimaryCommandBuffer; use crate::device::Device; use crate::device::Queue; -use crate::format::AcceptsPixels; use crate::format::Format; -use crate::format::FormatDesc; +use crate::format::Pixel; use crate::image::sys::ImageCreationError; use crate::image::sys::UnsafeImage; use crate::image::traits::ImageAccess; @@ -55,11 +54,11 @@ use std::sync::Arc; /// but then you must only ever read from it. // TODO: type (2D, 3D, array, etc.) as template parameter #[derive(Debug)] -pub struct ImmutableImage> { +pub struct ImmutableImage> { image: UnsafeImage, dimensions: ImageDimensions, memory: A, - format: F, + format: Format, initialized: AtomicBool, layout: ImageLayout, } @@ -105,8 +104,8 @@ impl SubImage { } // Must not implement Clone, as that would lead to multiple `used` values. -pub struct ImmutableImageInitialization> { - image: Arc>, +pub struct ImmutableImageInitialization> { + image: Arc>, used: AtomicBool, mip_levels_access: std::ops::Range, layer_levels_access: std::ops::Range, @@ -174,17 +173,16 @@ fn generate_mipmaps( } } -impl ImmutableImage { +impl ImmutableImage { #[deprecated(note = "use ImmutableImage::uninitialized instead")] #[inline] pub fn new<'a, I>( device: Arc, dimensions: ImageDimensions, - format: F, + format: Format, queue_families: I, - ) -> Result>, ImageCreationError> + ) -> Result, ImageCreationError> where - F: FormatDesc, I: IntoIterator>, { #[allow(deprecated)] @@ -202,12 +200,11 @@ impl ImmutableImage { pub fn with_mipmaps<'a, I, M>( device: Arc, dimensions: ImageDimensions, - format: F, + format: Format, mipmaps: M, queue_families: I, - ) -> Result>, ImageCreationError> + ) -> Result, ImageCreationError> where - F: FormatDesc, I: IntoIterator>, M: Into, { @@ -240,15 +237,14 @@ impl ImmutableImage { pub fn uninitialized<'a, I, M>( device: Arc, dimensions: ImageDimensions, - format: F, + format: Format, mipmaps: M, usage: ImageUsage, flags: ImageCreateFlags, layout: ImageLayout, queue_families: I, - ) -> Result<(Arc>, ImmutableImageInitialization), ImageCreationError> + ) -> Result<(Arc, ImmutableImageInitialization), ImageCreationError> where - F: FormatDesc, I: IntoIterator>, M: Into, { @@ -267,7 +263,7 @@ impl ImmutableImage { UnsafeImage::new( device.clone(), usage, - format.format(), + format, flags, dimensions, 1, @@ -318,11 +314,11 @@ impl ImmutableImage { /// Construct an ImmutableImage from the contents of `iter`. #[inline] - pub fn from_iter( + pub fn from_iter( iter: I, dimensions: ImageDimensions, mipmaps: MipmapsCount, - format: F, + format: Format, queue: Arc, ) -> Result< ( @@ -332,10 +328,8 @@ impl ImmutableImage { ImageCreationError, > where - P: Send + Sync + Clone + 'static, - F: FormatDesc + AcceptsPixels

+ 'static + Send + Sync, - I: ExactSizeIterator, - Format: AcceptsPixels

, + Px: Pixel + Send + Sync + Clone + 'static, + I: ExactSizeIterator, { let source = CpuAccessibleBuffer::from_iter( queue.device().clone(), @@ -347,11 +341,11 @@ impl ImmutableImage { } /// Construct an ImmutableImage containing a copy of the data in `source`. - pub fn from_buffer( + pub fn from_buffer( source: B, dimensions: ImageDimensions, mipmaps: MipmapsCount, - format: F, + format: Format, queue: Arc, ) -> Result< ( @@ -361,10 +355,8 @@ impl ImmutableImage { ImageCreationError, > where - B: BufferAccess + TypedBufferAccess + 'static + Clone + Send + Sync, - P: Send + Sync + Clone + 'static, - F: FormatDesc + AcceptsPixels

+ 'static + Send + Sync, - Format: AcceptsPixels

, + B: BufferAccess + TypedBufferAccess + 'static + Clone + Send + Sync, + Px: Pixel + Send + Sync + Clone + 'static, { let need_to_generate_mipmaps = has_mipmaps(mipmaps); let usage = ImageUsage { @@ -430,7 +422,7 @@ impl ImmutableImage { } } -impl ImmutableImage { +impl ImmutableImage { /// Returns the dimensions of the image. #[inline] pub fn dimensions(&self) -> ImageDimensions { @@ -444,10 +436,7 @@ impl ImmutableImage { } } -unsafe impl ImageAccess for ImmutableImage -where - F: 'static + Send + Sync, -{ +unsafe impl ImageAccess for ImmutableImage { #[inline] fn inner(&self) -> ImageInner { ImageInner { @@ -537,10 +526,7 @@ where } } -unsafe impl ImageContent

for ImmutableImage -where - F: 'static + Send + Sync, -{ +unsafe impl ImageContent

for ImmutableImage { #[inline] fn matches_format(&self) -> bool { true // FIXME: @@ -620,32 +606,23 @@ unsafe impl ImageAccess for SubImage { } } -impl PartialEq for ImmutableImage -where - F: 'static + Send + Sync, -{ +impl PartialEq for ImmutableImage { #[inline] fn eq(&self, other: &Self) -> bool { ImageAccess::inner(self) == ImageAccess::inner(other) } } -impl Eq for ImmutableImage where F: 'static + Send + Sync {} +impl Eq for ImmutableImage {} -impl Hash for ImmutableImage -where - F: 'static + Send + Sync, -{ +impl Hash for ImmutableImage { #[inline] fn hash(&self, state: &mut H) { ImageAccess::inner(self).hash(state); } } -unsafe impl ImageAccess for ImmutableImageInitialization -where - F: 'static + Send + Sync, -{ +unsafe impl ImageAccess for ImmutableImageInitialization { #[inline] fn inner(&self) -> ImageInner { ImageAccess::inner(&self.image) @@ -728,22 +705,16 @@ where } } -impl PartialEq for ImmutableImageInitialization -where - F: 'static + Send + Sync, -{ +impl PartialEq for ImmutableImageInitialization { #[inline] fn eq(&self, other: &Self) -> bool { ImageAccess::inner(self) == ImageAccess::inner(other) } } -impl Eq for ImmutableImageInitialization where F: 'static + Send + Sync {} +impl Eq for ImmutableImageInitialization {} -impl Hash for ImmutableImageInitialization -where - F: 'static + Send + Sync, -{ +impl Hash for ImmutableImageInitialization { #[inline] fn hash(&self, state: &mut H) { ImageAccess::inner(self).hash(state); diff --git a/vulkano/src/image/mod.rs b/vulkano/src/image/mod.rs index 7b1103b1..42fb7d3e 100644 --- a/vulkano/src/image/mod.rs +++ b/vulkano/src/image/mod.rs @@ -46,10 +46,8 @@ //! To be written. //! -use std::cmp; -use std::convert::TryFrom; - pub use self::aspect::ImageAspect; +pub use self::aspect::ImageAspects; pub use self::attachment::AttachmentImage; pub use self::immutable::ImmutableImage; pub use self::layout::ImageDescriptorLayouts; @@ -61,6 +59,8 @@ pub use self::traits::ImageAccess; pub use self::traits::ImageInner; pub use self::usage::ImageUsage; pub use self::view::ImageViewAbstract; +use std::cmp; +use std::convert::TryFrom; mod aspect; pub mod attachment; // TODO: make private @@ -439,7 +439,7 @@ impl ImageDimensions { #[cfg(test)] mod tests { - use crate::format; + use crate::format::Format; use crate::image::ImageDimensions; use crate::image::ImmutableImage; use crate::image::MipmapsCount; @@ -562,7 +562,7 @@ mod tests { vec.into_iter(), dimensions, MipmapsCount::One, - format::R8Unorm, + Format::R8Unorm, queue.clone(), ) .unwrap(); @@ -577,7 +577,7 @@ mod tests { vec.into_iter(), dimensions, MipmapsCount::Log2, - format::R8Unorm, + Format::R8Unorm, queue.clone(), ) .unwrap(); diff --git a/vulkano/src/image/storage.rs b/vulkano/src/image/storage.rs index 004fb50c..a210728e 100644 --- a/vulkano/src/image/storage.rs +++ b/vulkano/src/image/storage.rs @@ -7,17 +7,10 @@ // notice may not be copied, modified, or distributed except // according to those terms. -use smallvec::SmallVec; -use std::hash::Hash; -use std::hash::Hasher; -use std::sync::atomic::AtomicUsize; -use std::sync::atomic::Ordering; -use std::sync::Arc; - use crate::buffer::BufferAccess; use crate::device::Device; use crate::format::ClearValue; -use crate::format::FormatDesc; +use crate::format::Format; use crate::format::FormatTy; use crate::image::sys::ImageCreationError; use crate::image::sys::UnsafeImage; @@ -41,11 +34,17 @@ use crate::memory::pool::StdMemoryPool; use crate::memory::DedicatedAlloc; use crate::sync::AccessError; use crate::sync::Sharing; +use smallvec::SmallVec; +use std::hash::Hash; +use std::hash::Hasher; +use std::sync::atomic::AtomicUsize; +use std::sync::atomic::Ordering; +use std::sync::Arc; /// General-purpose image in device memory. Can be used for any usage, but will be slower than a /// specialized image. #[derive(Debug)] -pub struct StorageImage> +pub struct StorageImage> where A: MemoryPool, { @@ -59,7 +58,7 @@ where dimensions: ImageDimensions, // Format. - format: F, + format: Format, // Queue families allowed to access this image. queue_families: SmallVec<[u32; 4]>, @@ -68,20 +67,19 @@ where gpu_lock: AtomicUsize, } -impl StorageImage { +impl StorageImage { /// Creates a new image with the given dimensions and format. #[inline] pub fn new<'a, I>( device: Arc, dimensions: ImageDimensions, - format: F, + format: Format, queue_families: I, - ) -> Result>, ImageCreationError> + ) -> Result, ImageCreationError> where - F: FormatDesc, I: IntoIterator>, { - let is_depth = match format.format().ty() { + let is_depth = match format.ty() { FormatTy::Depth => true, FormatTy::DepthStencil => true, FormatTy::Stencil => true, @@ -108,13 +106,12 @@ impl StorageImage { pub fn with_usage<'a, I>( device: Arc, dimensions: ImageDimensions, - format: F, + format: Format, usage: ImageUsage, flags: ImageCreateFlags, queue_families: I, - ) -> Result>, ImageCreationError> + ) -> Result, ImageCreationError> where - F: FormatDesc, I: IntoIterator>, { let queue_families = queue_families @@ -132,7 +129,7 @@ impl StorageImage { UnsafeImage::new( device.clone(), usage, - format.format(), + format, flags, dimensions, 1, @@ -173,7 +170,7 @@ impl StorageImage { } } -impl StorageImage +impl StorageImage where A: MemoryPool, { @@ -184,9 +181,8 @@ where } } -unsafe impl ImageAccess for StorageImage +unsafe impl ImageAccess for StorageImage where - F: 'static + Send + Sync, A: MemoryPool, { #[inline] @@ -279,20 +275,18 @@ where } } -unsafe impl ImageClearValue for StorageImage +unsafe impl ImageClearValue for StorageImage where - F: FormatDesc + 'static + Send + Sync, A: MemoryPool, { #[inline] - fn decode(&self, value: F::ClearValue) -> Option { + fn decode(&self, value: ClearValue) -> Option { Some(self.format.decode_clear_value(value)) } } -unsafe impl ImageContent

for StorageImage +unsafe impl ImageContent

for StorageImage where - F: 'static + Send + Sync, A: MemoryPool, { #[inline] @@ -301,9 +295,8 @@ where } } -impl PartialEq for StorageImage +impl PartialEq for StorageImage where - F: 'static + Send + Sync, A: MemoryPool, { #[inline] @@ -312,16 +305,10 @@ where } } -impl Eq for StorageImage -where - F: 'static + Send + Sync, - A: MemoryPool, -{ -} +impl Eq for StorageImage where A: MemoryPool {} -impl Hash for StorageImage +impl Hash for StorageImage where - F: 'static + Send + Sync, A: MemoryPool, { #[inline] diff --git a/vulkano/src/image/swapchain.rs b/vulkano/src/image/swapchain.rs index a5e58380..bad2f95f 100644 --- a/vulkano/src/image/swapchain.rs +++ b/vulkano/src/image/swapchain.rs @@ -7,14 +7,8 @@ // notice may not be copied, modified, or distributed except // according to those terms. -use std::hash::Hash; -use std::hash::Hasher; -use std::sync::Arc; - use crate::buffer::BufferAccess; use crate::format::ClearValue; -use crate::format::Format; -use crate::format::FormatDesc; use crate::image::traits::ImageAccess; use crate::image::traits::ImageClearValue; use crate::image::traits::ImageContent; @@ -23,8 +17,10 @@ use crate::image::ImageInner; use crate::image::ImageLayout; use crate::swapchain::Swapchain; use crate::sync::AccessError; - use crate::OomError; +use std::hash::Hash; +use std::hash::Hasher; +use std::sync::Arc; /// An image that is part of a swapchain. /// @@ -173,9 +169,9 @@ unsafe impl ImageAccess for SwapchainImage { } } -unsafe impl ImageClearValue<::ClearValue> for SwapchainImage { +unsafe impl ImageClearValue for SwapchainImage { #[inline] - fn decode(&self, value: ::ClearValue) -> Option { + fn decode(&self, value: ClearValue) -> Option { Some(self.swapchain.format().decode_clear_value(value)) } } diff --git a/vulkano/src/image/sys.rs b/vulkano/src/image/sys.rs index 4e1a07ca..a67de2aa 100644 --- a/vulkano/src/image/sys.rs +++ b/vulkano/src/image/sys.rs @@ -13,6 +13,24 @@ //! other image types of this library, and all custom image types //! that you create must wrap around the types in this module. +use crate::check_errors; +use crate::device::Device; +use crate::format::Format; +use crate::format::FormatFeatures; +use crate::format::FormatTy; +use crate::image::ImageAspect; +use crate::image::ImageCreateFlags; +use crate::image::ImageDimensions; +use crate::image::ImageUsage; +use crate::image::MipmapsCount; +use crate::memory::DeviceMemory; +use crate::memory::DeviceMemoryAllocError; +use crate::memory::MemoryRequirements; +use crate::sync::Sharing; +use crate::vk; +use crate::Error; +use crate::OomError; +use crate::VulkanObject; use smallvec::SmallVec; use std::error; use std::fmt; @@ -24,27 +42,6 @@ use std::ops::Range; use std::ptr; use std::sync::Arc; -use crate::device::Device; -use crate::format::Format; -use crate::format::FormatFeatures; -use crate::format::FormatTy; -use crate::format::PossibleYcbcrFormatDesc; -use crate::image::ImageAspect; -use crate::image::ImageCreateFlags; -use crate::image::ImageDimensions; -use crate::image::ImageUsage; -use crate::image::MipmapsCount; -use crate::memory::DeviceMemory; -use crate::memory::DeviceMemoryAllocError; -use crate::memory::MemoryRequirements; -use crate::sync::Sharing; - -use crate::check_errors; -use crate::vk; -use crate::Error; -use crate::OomError; -use crate::VulkanObject; - /// A storage for pixels or arbitrary data. /// /// # Safety @@ -727,7 +724,7 @@ impl UnsafeImage { /// #[inline] pub unsafe fn color_linear_layout(&self, mip_level: u32) -> LinearLayout { - self.linear_layout_impl(mip_level, vk::IMAGE_ASPECT_COLOR_BIT) + self.linear_layout_impl(mip_level, ImageAspect::Color) } /// Same as `color_linear_layout`, except that it retrieves the depth component of the image. @@ -743,7 +740,7 @@ impl UnsafeImage { /// #[inline] pub unsafe fn depth_linear_layout(&self, mip_level: u32) -> LinearLayout { - self.linear_layout_impl(mip_level, vk::IMAGE_ASPECT_DEPTH_BIT) + self.linear_layout_impl(mip_level, ImageAspect::Depth) } /// Same as `color_linear_layout`, except that it retrieves the stencil component of the image. @@ -759,7 +756,7 @@ impl UnsafeImage { /// #[inline] pub unsafe fn stencil_linear_layout(&self, mip_level: u32) -> LinearLayout { - self.linear_layout_impl(mip_level, vk::IMAGE_ASPECT_STENCIL_BIT) + self.linear_layout_impl(mip_level, ImageAspect::Stencil) } /// Same as `color_linear_layout`, except that it retrieves layout for the requested ycbcr @@ -773,40 +770,34 @@ impl UnsafeImage { #[inline] pub unsafe fn multiplane_color_layout(&self, aspect: ImageAspect) -> LinearLayout { // This function only supports color and planar aspects currently. - let bits = aspect.to_aspect_bits(); - let unsupported = bits - & !(vk::IMAGE_ASPECT_COLOR_BIT - | vk::IMAGE_ASPECT_PLANE_0_BIT - | vk::IMAGE_ASPECT_PLANE_1_BIT - | vk::IMAGE_ASPECT_PLANE_2_BIT); - - assert!(unsupported == 0); + assert!(matches!( + aspect, + ImageAspect::Color | ImageAspect::Plane0 | ImageAspect::Plane1 | ImageAspect::Plane2 + )); assert!(self.mipmaps == 1); - if bits - & (vk::IMAGE_ASPECT_PLANE_0_BIT - | vk::IMAGE_ASPECT_PLANE_1_BIT - | vk::IMAGE_ASPECT_PLANE_2_BIT) - != 0 - { - assert!(self.format.is_ycbcr()); - if bits & vk::IMAGE_ASPECT_PLANE_2_BIT != 0 { + if matches!( + aspect, + ImageAspect::Plane0 | ImageAspect::Plane1 | ImageAspect::Plane2 + ) { + assert_eq!(self.format.ty(), FormatTy::Ycbcr); + if aspect == ImageAspect::Plane2 { // Vulkano only supports NV12 and YV12 currently. If that changes, this will too. assert!(self.format == Format::G8B8R8_3PLANE420Unorm); } } - self.linear_layout_impl(0, bits) + self.linear_layout_impl(0, aspect) } // Implementation of the `*_layout` functions. - unsafe fn linear_layout_impl(&self, mip_level: u32, aspect: u32) -> LinearLayout { + unsafe fn linear_layout_impl(&self, mip_level: u32, aspect: ImageAspect) -> LinearLayout { let vk = self.device.pointers(); assert!(mip_level < self.mipmaps); let subresource = vk::ImageSubresource { - aspectMask: aspect, + aspectMask: vk::ImageAspectFlags::from(aspect), mipLevel: mip_level, arrayLayer: 0, }; diff --git a/vulkano/src/image/traits.rs b/vulkano/src/image/traits.rs index 396a2c61..66e1f196 100644 --- a/vulkano/src/image/traits.rs +++ b/vulkano/src/image/traits.rs @@ -7,26 +7,18 @@ // notice may not be copied, modified, or distributed except // according to those terms. -use std::hash::Hash; -use std::hash::Hasher; - use crate::buffer::BufferAccess; use crate::format::ClearValue; use crate::format::Format; -use crate::format::PossibleCompressedFormatDesc; -use crate::format::PossibleDepthFormatDesc; -use crate::format::PossibleDepthStencilFormatDesc; -use crate::format::PossibleFloatFormatDesc; -use crate::format::PossibleSintFormatDesc; -use crate::format::PossibleStencilFormatDesc; -use crate::format::PossibleUintFormatDesc; +use crate::format::FormatTy; use crate::image::sys::UnsafeImage; use crate::image::ImageDescriptorLayouts; use crate::image::ImageDimensions; use crate::image::ImageLayout; use crate::sync::AccessError; - use crate::SafeDeref; +use std::hash::Hash; +use std::hash::Hasher; /// Trait for types that represent the way a GPU can access an image. pub unsafe trait ImageAccess { @@ -42,24 +34,27 @@ pub unsafe trait ImageAccess { /// Returns true if the image is a color image. #[inline] fn has_color(&self) -> bool { - let format = self.format(); - format.is_float() || format.is_uint() || format.is_sint() || format.is_compressed() + matches!( + self.format().ty(), + FormatTy::Float | FormatTy::Uint | FormatTy::Sint | FormatTy::Compressed + ) } /// Returns true if the image has a depth component. In other words, if it is a depth or a /// depth-stencil format. #[inline] fn has_depth(&self) -> bool { - let format = self.format(); - format.is_depth() || format.is_depth_stencil() + matches!(self.format().ty(), FormatTy::Depth | FormatTy::DepthStencil) } /// Returns true if the image has a stencil component. In other words, if it is a stencil or a /// depth-stencil format. #[inline] fn has_stencil(&self) -> bool { - let format = self.format(); - format.is_stencil() || format.is_depth_stencil() + matches!( + self.format().ty(), + FormatTy::Stencil | FormatTy::DepthStencil + ) } /// Returns the number of mipmap levels of this image. diff --git a/vulkano/src/image/view.rs b/vulkano/src/image/view.rs index 09761c97..affd50c1 100644 --- a/vulkano/src/image/view.rs +++ b/vulkano/src/image/view.rs @@ -314,16 +314,12 @@ impl UnsafeImageView { debug_assert!(array_layers.end > array_layers.start); debug_assert!(array_layers.end <= image.dimensions().array_layers()); - let aspect_mask = match image.format().ty() { - FormatTy::Float | FormatTy::Uint | FormatTy::Sint | FormatTy::Compressed => { - vk::IMAGE_ASPECT_COLOR_BIT - } - FormatTy::Depth => vk::IMAGE_ASPECT_DEPTH_BIT, - FormatTy::Stencil => vk::IMAGE_ASPECT_STENCIL_BIT, - FormatTy::DepthStencil => vk::IMAGE_ASPECT_DEPTH_BIT | vk::IMAGE_ASPECT_STENCIL_BIT, - // Not yet supported --> would require changes to ImmutableImage API :-) - FormatTy::Ycbcr => unimplemented!(), - }; + if image.format().ty() == FormatTy::Ycbcr { + unimplemented!(); + } + + // TODO: Let user choose + let aspects = image.format().aspects(); let view = { let infos = vk::ImageViewCreateInfo { @@ -335,7 +331,7 @@ impl UnsafeImageView { format: image.format() as u32, components: component_mapping.into(), subresourceRange: vk::ImageSubresourceRange { - aspectMask: aspect_mask, + aspectMask: aspects.into(), baseMipLevel: mipmap_levels.start, levelCount: mipmap_levels.end - mipmap_levels.start, baseArrayLayer: array_layers.start, diff --git a/vulkano/src/swapchain/surface.rs b/vulkano/src/swapchain/surface.rs index cd478d36..bcb769d1 100644 --- a/vulkano/src/swapchain/surface.rs +++ b/vulkano/src/swapchain/surface.rs @@ -7,14 +7,7 @@ // notice may not be copied, modified, or distributed except // according to those terms. -use std::error; -use std::fmt; -use std::mem::MaybeUninit; -use std::os::raw::c_ulong; -use std::ptr; -use std::sync::atomic::AtomicBool; -use std::sync::Arc; - +use crate::check_errors; use crate::format::Format; use crate::image::ImageUsage; use crate::instance::Instance; @@ -25,12 +18,18 @@ use crate::swapchain::display::DisplayMode; use crate::swapchain::display::DisplayPlane; use crate::swapchain::Capabilities; use crate::swapchain::SurfaceSwapchainLock; - -use crate::check_errors; use crate::vk; use crate::Error; use crate::OomError; use crate::VulkanObject; +use std::convert::TryFrom; +use std::error; +use std::fmt; +use std::mem::MaybeUninit; +use std::os::raw::c_ulong; +use std::ptr; +use std::sync::atomic::AtomicBool; +use std::sync::Arc; /// Represents a surface on the screen. /// @@ -57,8 +56,8 @@ impl Surface { ) -> Surface { Surface { window: win, - instance: instance, - surface: surface, + instance, + surface, has_swapchain: AtomicBool::new(false), } } @@ -126,7 +125,7 @@ impl Surface { Ok(Arc::new(Surface { window: (), instance: instance.clone(), - surface: surface, + surface, has_swapchain: AtomicBool::new(false), })) } @@ -176,7 +175,7 @@ impl Surface { Ok(Arc::new(Surface { window: win, instance: instance.clone(), - surface: surface, + surface, has_swapchain: AtomicBool::new(false), })) } @@ -209,7 +208,7 @@ impl Surface { pNext: ptr::null(), flags: 0, // reserved connection: connection as *mut _, - window: window, + window, }; let mut output = MaybeUninit::uninit(); @@ -225,7 +224,7 @@ impl Surface { Ok(Arc::new(Surface { window: win, instance: instance.clone(), - surface: surface, + surface, has_swapchain: AtomicBool::new(false), })) } @@ -258,7 +257,7 @@ impl Surface { pNext: ptr::null(), flags: 0, // reserved dpy: display as *mut _, - window: window, + window, }; let mut output = MaybeUninit::uninit(); @@ -274,7 +273,7 @@ impl Surface { Ok(Arc::new(Surface { window: win, instance: instance.clone(), - surface: surface, + surface, has_swapchain: AtomicBool::new(false), })) } @@ -323,7 +322,7 @@ impl Surface { Ok(Arc::new(Surface { window: win, instance: instance.clone(), - surface: surface, + surface, has_swapchain: AtomicBool::new(false), })) } @@ -368,7 +367,7 @@ impl Surface { Ok(Arc::new(Surface { window: win, instance: instance.clone(), - surface: surface, + surface, has_swapchain: AtomicBool::new(false), })) } @@ -414,7 +413,7 @@ impl Surface { Ok(Arc::new(Surface { window: win, instance: instance.clone(), - surface: surface, + surface, has_swapchain: AtomicBool::new(false), })) } @@ -460,7 +459,7 @@ impl Surface { Ok(Arc::new(Surface { window: win, instance: instance.clone(), - surface: surface, + surface, has_swapchain: AtomicBool::new(false), })) } @@ -505,7 +504,7 @@ impl Surface { Ok(Arc::new(Surface { window: win, instance: instance.clone(), - surface: surface, + surface, has_swapchain: AtomicBool::new(false), })) } @@ -640,7 +639,7 @@ impl Surface { .into_iter() .filter_map(|f| { // TODO: Change the way capabilities not supported in vk-sys are handled - Format::from_vulkan_num(f.format).map(|format| { + Format::try_from(f.format).ok().map(|format| { (format, capabilities::color_space_from_num(f.colorSpace)) }) }) diff --git a/vulkano/src/swapchain/swapchain.rs b/vulkano/src/swapchain/swapchain.rs index ac498d10..d69b387c 100644 --- a/vulkano/src/swapchain/swapchain.rs +++ b/vulkano/src/swapchain/swapchain.rs @@ -7,17 +7,6 @@ // notice may not be copied, modified, or distributed except // according to those terms. -use std::error; -use std::fmt; -use std::mem; -use std::mem::MaybeUninit; -use std::ptr; -use std::sync::atomic::AtomicBool; -use std::sync::atomic::Ordering; -use std::sync::Arc; -use std::sync::Mutex; -use std::time::Duration; - use crate::buffer::BufferAccess; use crate::command_buffer::submit::SubmitAnyBuilder; use crate::command_buffer::submit::SubmitPresentBuilder; @@ -27,7 +16,6 @@ use crate::device::Device; use crate::device::DeviceOwned; use crate::device::Queue; use crate::format::Format; -use crate::format::FormatDesc; use crate::image::swapchain::SwapchainImage; use crate::image::sys::UnsafeImage; use crate::image::ImageAccess; @@ -55,6 +43,16 @@ use crate::sync::GpuFuture; use crate::sync::PipelineStages; use crate::sync::Semaphore; use crate::sync::SharingMode; +use std::error; +use std::fmt; +use std::mem; +use std::mem::MaybeUninit; +use std::ptr; +use std::sync::atomic::AtomicBool; +use std::sync::atomic::Ordering; +use std::sync::Arc; +use std::sync::Mutex; +use std::time::Duration; use crate::check_errors; use crate::vk; @@ -284,11 +282,11 @@ impl Swapchain { /// // TODO: isn't it unsafe to take the surface through an Arc when it comes to vulkano-win? #[inline] - pub fn new( + pub fn new( device: Arc, surface: Arc>, num_images: u32, - format: F, + format: Format, dimensions: [u32; 2], layers: u32, usage: ImageUsage, @@ -301,14 +299,13 @@ impl Swapchain { color_space: ColorSpace, ) -> Result<(Arc>, Vec>>), SwapchainCreationError> where - F: FormatDesc, S: Into, { Swapchain::new_inner( device, surface, num_images, - format.format(), + format, color_space, Some(dimensions), layers, @@ -325,11 +322,11 @@ impl Swapchain { /// Same as Swapchain::new but requires an old swapchain for the creation #[inline] - pub fn with_old_swapchain( + pub fn with_old_swapchain( device: Arc, surface: Arc>, num_images: u32, - format: F, + format: Format, dimensions: [u32; 2], layers: u32, usage: ImageUsage, @@ -343,14 +340,13 @@ impl Swapchain { old_swapchain: Arc>, ) -> Result<(Arc>, Vec>>), SwapchainCreationError> where - F: FormatDesc, S: Into, { Swapchain::new_inner( device, surface, num_images, - format.format(), + format, ColorSpace::SrgbNonLinear, Some(dimensions), layers,