Remove format structs and some related traits (#1550)

* Remove format structs, StrongStorage trait

* Remove a bunch of superfluous traits and functions

* Remove FormatDesc trait

* Make formats macro a bit easier to read

* Rename AcceptsPixels trait to Pixel, reverse implementation direction

* Changelog

* Documentation

* Improved image aspects, add aspects to Format
This commit is contained in:
Rua 2021-04-17 15:05:09 +02:00 committed by GitHub
parent fb187e8884
commit f1dad10cd4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
20 changed files with 770 additions and 1261 deletions

View File

@ -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.

View File

@ -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<vulkano::device::Device> = return;
//! # let queue: Arc<vulkano::device::Queue> = 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<F, B>
pub struct BufferView<B>
where
B: BufferAccess,
{
view: vk::BufferView,
buffer: B,
marker: PhantomData<F>,
atomic_accesses: bool,
}
impl<F, B> BufferView<F, B>
impl<B> BufferView<B>
where
B: BufferAccess,
{
/// Builds a new buffer view.
#[inline]
pub fn new(buffer: B, format: F) -> Result<BufferView<F, B>, BufferViewCreationError>
pub fn new<Px>(buffer: B, format: Format) -> Result<BufferView<B>, BufferViewCreationError>
where
B: TypedBufferAccess<Content = [F::Pixel]>,
F: StrongStorage + 'static,
B: TypedBufferAccess<Content = [Px]>,
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<BufferView<F, B>, BufferViewCreationError>
format: Format,
) -> Result<BufferView<B>, 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<F, B> VulkanObject for BufferView<F, B>
unsafe impl<B> VulkanObject for BufferView<B>
where
B: BufferAccess,
{
@ -220,7 +213,7 @@ where
}
}
unsafe impl<F, B> DeviceOwned for BufferView<F, B>
unsafe impl<B> DeviceOwned for BufferView<B>
where
B: BufferAccess,
{
@ -230,7 +223,7 @@ where
}
}
impl<F, B> fmt::Debug for BufferView<F, B>
impl<B> fmt::Debug for BufferView<B>
where
B: BufferAccess + fmt::Debug,
{
@ -242,7 +235,7 @@ where
}
}
impl<F, B> Drop for BufferView<F, B>
impl<B> Drop for BufferView<B>
where
B: BufferAccess,
{
@ -261,34 +254,31 @@ where
pub unsafe trait BufferViewRef {
type BufferAccess: BufferAccess;
type Format;
fn view(&self) -> &BufferView<Self::Format, Self::BufferAccess>;
fn view(&self) -> &BufferView<Self::BufferAccess>;
}
unsafe impl<F, B> BufferViewRef for BufferView<F, B>
unsafe impl<B> BufferViewRef for BufferView<B>
where
B: BufferAccess,
{
type BufferAccess = B;
type Format = F;
#[inline]
fn view(&self) -> &BufferView<F, B> {
fn view(&self) -> &BufferView<B> {
self
}
}
unsafe impl<T, F, B> BufferViewRef for T
unsafe impl<T, B> BufferViewRef for T
where
T: SafeDeref<Target = BufferView<F, B>>,
T: SafeDeref<Target = BufferView<B>>,
B: BufferAccess,
{
type BufferAccess = B;
type Format = F;
#[inline]
fn view(&self) -> &BufferView<F, B> {
fn view(&self) -> &BufferView<B> {
&**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!(),
}

View File

@ -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<L, P> AutoCommandBufferBuilder<L, P> {
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<L, P> AutoCommandBufferBuilder<L, P> {
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<L, P> AutoCommandBufferBuilder<L, P> {
where
S: TypedBufferAccess<Content = [Px]> + Send + Sync + 'static,
D: ImageAccess + Send + Sync + 'static,
Format: AcceptsPixels<Px>,
Px: Pixel,
{
self.ensure_outside_render_pass()?;
@ -1143,7 +1143,7 @@ impl<L, P> AutoCommandBufferBuilder<L, P> {
where
S: TypedBufferAccess<Content = [Px]> + Send + Sync + 'static,
D: ImageAccess + Send + Sync + 'static,
Format: AcceptsPixels<Px>,
Px: Pixel,
{
unsafe {
self.ensure_outside_render_pass()?;
@ -1165,11 +1165,7 @@ impl<L, P> AutoCommandBufferBuilder<L, P> {
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<L, P> AutoCommandBufferBuilder<L, P> {
where
S: ImageAccess + Send + Sync + 'static,
D: TypedBufferAccess<Content = [Px]> + Send + Sync + 'static,
Format: AcceptsPixels<Px>,
Px: Pixel,
{
self.ensure_outside_render_pass()?;
@ -1223,7 +1219,7 @@ impl<L, P> AutoCommandBufferBuilder<L, P> {
where
S: ImageAccess + Send + Sync + 'static,
D: TypedBufferAccess<Content = [Px]> + Send + Sync + 'static,
Format: AcceptsPixels<Px>,
Px: Pixel,
{
unsafe {
self.ensure_outside_render_pass()?;
@ -1244,10 +1240,15 @@ impl<L, P> AutoCommandBufferBuilder<L, P> {
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,

View File

@ -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<Item = UnsafeCommandBufferBuilderImageBlit>,
{
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,

View File

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

View File

@ -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 {

View File

@ -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<B, I, P>(
pub fn check_copy_buffer_image<B, I, Px>(
device: &Device,
buffer: &B,
image: &I,
@ -46,8 +46,8 @@ pub fn check_copy_buffer_image<B, I, P>(
) -> Result<(), CheckCopyBufferImageError>
where
I: ?Sized + ImageAccess,
B: ?Sized + TypedBufferAccess<Content = [P]>,
Format: AcceptsPixels<P>, // TODO: use a trait on the image itself instead
B: ?Sized + TypedBufferAccess<Content = [Px]>,
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::<Px>(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<P>(format: Format, image_size: [u32; 3], image_num_layers: u32) -> usize
fn required_len_for_format<Px>(format: Format, image_size: [u32; 3], image_num_layers: u32) -> usize
where
Format: AcceptsPixels<P>,
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;
}

View File

@ -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<F, B>,
view: &BufferView<B>,
) -> 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<F, B>,
view: &BufferView<B>,
) -> DescriptorWrite
where
B: BufferAccess,

File diff suppressed because it is too large Load Diff

View File

@ -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<ImageAspect> 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<ImageAspects> 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<vk::ImageAspectFlags> 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,
}
}
}

View File

@ -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<F = Format, A = PotentialDedicatedAllocation<StdMemoryPoolAlloc>> {
pub struct AttachmentImage<A = PotentialDedicatedAllocation<StdMemoryPoolAlloc>> {
// Inner implementation.
image: UnsafeImage,
@ -81,7 +79,7 @@ pub struct AttachmentImage<F = Format, A = PotentialDedicatedAllocation<StdMemor
memory: A,
// Format.
format: F,
format: Format,
// Layout to use when the image is used as a framebuffer attachment.
// Must be either "depth-stencil optimal" or "color optimal".
@ -95,7 +93,7 @@ pub struct AttachmentImage<F = Format, A = PotentialDedicatedAllocation<StdMemor
gpu_lock: AtomicUsize,
}
impl<F> AttachmentImage<F> {
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<F> AttachmentImage<F> {
pub fn new(
device: Arc<Device>,
dimensions: [u32; 2],
format: F,
) -> Result<Arc<AttachmentImage<F>>, ImageCreationError>
where
F: FormatDesc,
{
format: Format,
) -> Result<Arc<AttachmentImage>, ImageCreationError> {
AttachmentImage::new_impl(device, dimensions, format, ImageUsage::none(), 1)
}
@ -119,11 +114,8 @@ impl<F> AttachmentImage<F> {
pub fn input_attachment(
device: Arc<Device>,
dimensions: [u32; 2],
format: F,
) -> Result<Arc<AttachmentImage<F>>, ImageCreationError>
where
F: FormatDesc,
{
format: Format,
) -> Result<Arc<AttachmentImage>, ImageCreationError> {
let base_usage = ImageUsage {
input_attachment: true,
..ImageUsage::none()
@ -141,11 +133,8 @@ impl<F> AttachmentImage<F> {
device: Arc<Device>,
dimensions: [u32; 2],
samples: u32,
format: F,
) -> Result<Arc<AttachmentImage<F>>, ImageCreationError>
where
F: FormatDesc,
{
format: Format,
) -> Result<Arc<AttachmentImage>, ImageCreationError> {
AttachmentImage::new_impl(device, dimensions, format, ImageUsage::none(), samples)
}
@ -157,11 +146,8 @@ impl<F> AttachmentImage<F> {
device: Arc<Device>,
dimensions: [u32; 2],
samples: u32,
format: F,
) -> Result<Arc<AttachmentImage<F>>, ImageCreationError>
where
F: FormatDesc,
{
format: Format,
) -> Result<Arc<AttachmentImage>, ImageCreationError> {
let base_usage = ImageUsage {
input_attachment: true,
..ImageUsage::none()
@ -179,12 +165,9 @@ impl<F> AttachmentImage<F> {
pub fn with_usage(
device: Arc<Device>,
dimensions: [u32; 2],
format: F,
format: Format,
usage: ImageUsage,
) -> Result<Arc<AttachmentImage<F>>, ImageCreationError>
where
F: FormatDesc,
{
) -> Result<Arc<AttachmentImage>, ImageCreationError> {
AttachmentImage::new_impl(device, dimensions, format, usage, 1)
}
@ -199,12 +182,9 @@ impl<F> AttachmentImage<F> {
device: Arc<Device>,
dimensions: [u32; 2],
samples: u32,
format: F,
format: Format,
usage: ImageUsage,
) -> Result<Arc<AttachmentImage<F>>, ImageCreationError>
where
F: FormatDesc,
{
) -> Result<Arc<AttachmentImage>, ImageCreationError> {
AttachmentImage::new_impl(device, dimensions, format, usage, samples)
}
@ -215,11 +195,8 @@ impl<F> AttachmentImage<F> {
pub fn sampled(
device: Arc<Device>,
dimensions: [u32; 2],
format: F,
) -> Result<Arc<AttachmentImage<F>>, ImageCreationError>
where
F: FormatDesc,
{
format: Format,
) -> Result<Arc<AttachmentImage>, ImageCreationError> {
let base_usage = ImageUsage {
sampled: true,
..ImageUsage::none()
@ -235,11 +212,8 @@ impl<F> AttachmentImage<F> {
pub fn sampled_input_attachment(
device: Arc<Device>,
dimensions: [u32; 2],
format: F,
) -> Result<Arc<AttachmentImage<F>>, ImageCreationError>
where
F: FormatDesc,
{
format: Format,
) -> Result<Arc<AttachmentImage>, ImageCreationError> {
let base_usage = ImageUsage {
sampled: true,
input_attachment: true,
@ -260,11 +234,8 @@ impl<F> AttachmentImage<F> {
device: Arc<Device>,
dimensions: [u32; 2],
samples: u32,
format: F,
) -> Result<Arc<AttachmentImage<F>>, ImageCreationError>
where
F: FormatDesc,
{
format: Format,
) -> Result<Arc<AttachmentImage>, ImageCreationError> {
let base_usage = ImageUsage {
sampled: true,
..ImageUsage::none()
@ -282,11 +253,8 @@ impl<F> AttachmentImage<F> {
device: Arc<Device>,
dimensions: [u32; 2],
samples: u32,
format: F,
) -> Result<Arc<AttachmentImage<F>>, ImageCreationError>
where
F: FormatDesc,
{
format: Format,
) -> Result<Arc<AttachmentImage>, ImageCreationError> {
let base_usage = ImageUsage {
sampled: true,
input_attachment: true,
@ -306,11 +274,8 @@ impl<F> AttachmentImage<F> {
pub fn transient(
device: Arc<Device>,
dimensions: [u32; 2],
format: F,
) -> Result<Arc<AttachmentImage<F>>, ImageCreationError>
where
F: FormatDesc,
{
format: Format,
) -> Result<Arc<AttachmentImage>, ImageCreationError> {
let base_usage = ImageUsage {
transient_attachment: true,
..ImageUsage::none()
@ -326,11 +291,8 @@ impl<F> AttachmentImage<F> {
pub fn transient_input_attachment(
device: Arc<Device>,
dimensions: [u32; 2],
format: F,
) -> Result<Arc<AttachmentImage<F>>, ImageCreationError>
where
F: FormatDesc,
{
format: Format,
) -> Result<Arc<AttachmentImage>, ImageCreationError> {
let base_usage = ImageUsage {
transient_attachment: true,
input_attachment: true,
@ -351,11 +313,8 @@ impl<F> AttachmentImage<F> {
device: Arc<Device>,
dimensions: [u32; 2],
samples: u32,
format: F,
) -> Result<Arc<AttachmentImage<F>>, ImageCreationError>
where
F: FormatDesc,
{
format: Format,
) -> Result<Arc<AttachmentImage>, ImageCreationError> {
let base_usage = ImageUsage {
transient_attachment: true,
..ImageUsage::none()
@ -373,11 +332,8 @@ impl<F> AttachmentImage<F> {
device: Arc<Device>,
dimensions: [u32; 2],
samples: u32,
format: F,
) -> Result<Arc<AttachmentImage<F>>, ImageCreationError>
where
F: FormatDesc,
{
format: Format,
) -> Result<Arc<AttachmentImage>, ImageCreationError> {
let base_usage = ImageUsage {
transient_attachment: true,
input_attachment: true,
@ -391,16 +347,13 @@ impl<F> AttachmentImage<F> {
fn new_impl(
device: Arc<Device>,
dimensions: [u32; 2],
format: F,
format: Format,
base_usage: ImageUsage,
samples: u32,
) -> Result<Arc<AttachmentImage<F>>, ImageCreationError>
where
F: FormatDesc,
{
) -> Result<Arc<AttachmentImage>, 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<F> AttachmentImage<F> {
UnsafeImage::new(
device.clone(),
usage,
format.format(),
format,
ImageCreateFlags::none(),
dims,
samples,
@ -469,7 +422,7 @@ impl<F> AttachmentImage<F> {
}
}
impl<F, A> AttachmentImage<F, A> {
impl<A> AttachmentImage<A> {
/// Returns the dimensions of the image.
#[inline]
pub fn dimensions(&self) -> [u32; 2] {
@ -478,10 +431,7 @@ impl<F, A> AttachmentImage<F, A> {
}
}
unsafe impl<F, A> ImageAccess for AttachmentImage<F, A>
where
F: 'static + Send + Sync,
{
unsafe impl<A> ImageAccess for AttachmentImage<A> {
#[inline]
fn inner(&self) -> ImageInner {
ImageInner {
@ -602,42 +552,30 @@ where
}
}
unsafe impl<F, A> ImageClearValue<F::ClearValue> for Arc<AttachmentImage<F, A>>
where
F: FormatDesc + 'static + Send + Sync,
{
unsafe impl<A> ImageClearValue<ClearValue> for Arc<AttachmentImage<A>> {
#[inline]
fn decode(&self, value: F::ClearValue) -> Option<ClearValue> {
fn decode(&self, value: ClearValue) -> Option<ClearValue> {
Some(self.format.decode_clear_value(value))
}
}
unsafe impl<P, F, A> ImageContent<P> for Arc<AttachmentImage<F, A>>
where
F: 'static + Send + Sync,
{
unsafe impl<P, A> ImageContent<P> for Arc<AttachmentImage<A>> {
#[inline]
fn matches_format(&self) -> bool {
true // FIXME:
}
}
impl<F, A> PartialEq for AttachmentImage<F, A>
where
F: 'static + Send + Sync,
{
impl<A> PartialEq for AttachmentImage<A> {
#[inline]
fn eq(&self, other: &Self) -> bool {
ImageAccess::inner(self) == ImageAccess::inner(other)
}
}
impl<F, A> Eq for AttachmentImage<F, A> where F: 'static + Send + Sync {}
impl<A> Eq for AttachmentImage<A> {}
impl<F, A> Hash for AttachmentImage<F, A>
where
F: 'static + Send + Sync,
{
impl<A> Hash for AttachmentImage<A> {
#[inline]
fn hash<H: Hasher>(&self, state: &mut H) {
ImageAccess::inner(self).hash(state);

View File

@ -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<F, A = PotentialDedicatedAllocation<StdMemoryPoolAlloc>> {
pub struct ImmutableImage<A = PotentialDedicatedAllocation<StdMemoryPoolAlloc>> {
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<F, A = PotentialDedicatedAllocation<StdMemoryPoolAlloc>> {
image: Arc<ImmutableImage<F, A>>,
pub struct ImmutableImageInitialization<A = PotentialDedicatedAllocation<StdMemoryPoolAlloc>> {
image: Arc<ImmutableImage<A>>,
used: AtomicBool,
mip_levels_access: std::ops::Range<u32>,
layer_levels_access: std::ops::Range<u32>,
@ -174,17 +173,16 @@ fn generate_mipmaps<L, Img>(
}
}
impl<F> ImmutableImage<F> {
impl ImmutableImage {
#[deprecated(note = "use ImmutableImage::uninitialized instead")]
#[inline]
pub fn new<'a, I>(
device: Arc<Device>,
dimensions: ImageDimensions,
format: F,
format: Format,
queue_families: I,
) -> Result<Arc<ImmutableImage<F>>, ImageCreationError>
) -> Result<Arc<ImmutableImage>, ImageCreationError>
where
F: FormatDesc,
I: IntoIterator<Item = QueueFamily<'a>>,
{
#[allow(deprecated)]
@ -202,12 +200,11 @@ impl<F> ImmutableImage<F> {
pub fn with_mipmaps<'a, I, M>(
device: Arc<Device>,
dimensions: ImageDimensions,
format: F,
format: Format,
mipmaps: M,
queue_families: I,
) -> Result<Arc<ImmutableImage<F>>, ImageCreationError>
) -> Result<Arc<ImmutableImage>, ImageCreationError>
where
F: FormatDesc,
I: IntoIterator<Item = QueueFamily<'a>>,
M: Into<MipmapsCount>,
{
@ -240,15 +237,14 @@ impl<F> ImmutableImage<F> {
pub fn uninitialized<'a, I, M>(
device: Arc<Device>,
dimensions: ImageDimensions,
format: F,
format: Format,
mipmaps: M,
usage: ImageUsage,
flags: ImageCreateFlags,
layout: ImageLayout,
queue_families: I,
) -> Result<(Arc<ImmutableImage<F>>, ImmutableImageInitialization<F>), ImageCreationError>
) -> Result<(Arc<ImmutableImage>, ImmutableImageInitialization), ImageCreationError>
where
F: FormatDesc,
I: IntoIterator<Item = QueueFamily<'a>>,
M: Into<MipmapsCount>,
{
@ -267,7 +263,7 @@ impl<F> ImmutableImage<F> {
UnsafeImage::new(
device.clone(),
usage,
format.format(),
format,
flags,
dimensions,
1,
@ -318,11 +314,11 @@ impl<F> ImmutableImage<F> {
/// Construct an ImmutableImage from the contents of `iter`.
#[inline]
pub fn from_iter<P, I>(
pub fn from_iter<Px, I>(
iter: I,
dimensions: ImageDimensions,
mipmaps: MipmapsCount,
format: F,
format: Format,
queue: Arc<Queue>,
) -> Result<
(
@ -332,10 +328,8 @@ impl<F> ImmutableImage<F> {
ImageCreationError,
>
where
P: Send + Sync + Clone + 'static,
F: FormatDesc + AcceptsPixels<P> + 'static + Send + Sync,
I: ExactSizeIterator<Item = P>,
Format: AcceptsPixels<P>,
Px: Pixel + Send + Sync + Clone + 'static,
I: ExactSizeIterator<Item = Px>,
{
let source = CpuAccessibleBuffer::from_iter(
queue.device().clone(),
@ -347,11 +341,11 @@ impl<F> ImmutableImage<F> {
}
/// Construct an ImmutableImage containing a copy of the data in `source`.
pub fn from_buffer<B, P>(
pub fn from_buffer<B, Px>(
source: B,
dimensions: ImageDimensions,
mipmaps: MipmapsCount,
format: F,
format: Format,
queue: Arc<Queue>,
) -> Result<
(
@ -361,10 +355,8 @@ impl<F> ImmutableImage<F> {
ImageCreationError,
>
where
B: BufferAccess + TypedBufferAccess<Content = [P]> + 'static + Clone + Send + Sync,
P: Send + Sync + Clone + 'static,
F: FormatDesc + AcceptsPixels<P> + 'static + Send + Sync,
Format: AcceptsPixels<P>,
B: BufferAccess + TypedBufferAccess<Content = [Px]> + '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<F> ImmutableImage<F> {
}
}
impl<F, A> ImmutableImage<F, A> {
impl<A> ImmutableImage<A> {
/// Returns the dimensions of the image.
#[inline]
pub fn dimensions(&self) -> ImageDimensions {
@ -444,10 +436,7 @@ impl<F, A> ImmutableImage<F, A> {
}
}
unsafe impl<F, A> ImageAccess for ImmutableImage<F, A>
where
F: 'static + Send + Sync,
{
unsafe impl<A> ImageAccess for ImmutableImage<A> {
#[inline]
fn inner(&self) -> ImageInner {
ImageInner {
@ -537,10 +526,7 @@ where
}
}
unsafe impl<P, F, A> ImageContent<P> for ImmutableImage<F, A>
where
F: 'static + Send + Sync,
{
unsafe impl<P, A> ImageContent<P> for ImmutableImage<A> {
#[inline]
fn matches_format(&self) -> bool {
true // FIXME:
@ -620,32 +606,23 @@ unsafe impl ImageAccess for SubImage {
}
}
impl<F, A> PartialEq for ImmutableImage<F, A>
where
F: 'static + Send + Sync,
{
impl<A> PartialEq for ImmutableImage<A> {
#[inline]
fn eq(&self, other: &Self) -> bool {
ImageAccess::inner(self) == ImageAccess::inner(other)
}
}
impl<F, A> Eq for ImmutableImage<F, A> where F: 'static + Send + Sync {}
impl<A> Eq for ImmutableImage<A> {}
impl<F, A> Hash for ImmutableImage<F, A>
where
F: 'static + Send + Sync,
{
impl<A> Hash for ImmutableImage<A> {
#[inline]
fn hash<H: Hasher>(&self, state: &mut H) {
ImageAccess::inner(self).hash(state);
}
}
unsafe impl<F, A> ImageAccess for ImmutableImageInitialization<F, A>
where
F: 'static + Send + Sync,
{
unsafe impl<A> ImageAccess for ImmutableImageInitialization<A> {
#[inline]
fn inner(&self) -> ImageInner {
ImageAccess::inner(&self.image)
@ -728,22 +705,16 @@ where
}
}
impl<F, A> PartialEq for ImmutableImageInitialization<F, A>
where
F: 'static + Send + Sync,
{
impl<A> PartialEq for ImmutableImageInitialization<A> {
#[inline]
fn eq(&self, other: &Self) -> bool {
ImageAccess::inner(self) == ImageAccess::inner(other)
}
}
impl<F, A> Eq for ImmutableImageInitialization<F, A> where F: 'static + Send + Sync {}
impl<A> Eq for ImmutableImageInitialization<A> {}
impl<F, A> Hash for ImmutableImageInitialization<F, A>
where
F: 'static + Send + Sync,
{
impl<A> Hash for ImmutableImageInitialization<A> {
#[inline]
fn hash<H: Hasher>(&self, state: &mut H) {
ImageAccess::inner(self).hash(state);

View File

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

View File

@ -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<F, A = Arc<StdMemoryPool>>
pub struct StorageImage<A = Arc<StdMemoryPool>>
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<F> StorageImage<F> {
impl StorageImage {
/// Creates a new image with the given dimensions and format.
#[inline]
pub fn new<'a, I>(
device: Arc<Device>,
dimensions: ImageDimensions,
format: F,
format: Format,
queue_families: I,
) -> Result<Arc<StorageImage<F>>, ImageCreationError>
) -> Result<Arc<StorageImage>, ImageCreationError>
where
F: FormatDesc,
I: IntoIterator<Item = QueueFamily<'a>>,
{
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<F> StorageImage<F> {
pub fn with_usage<'a, I>(
device: Arc<Device>,
dimensions: ImageDimensions,
format: F,
format: Format,
usage: ImageUsage,
flags: ImageCreateFlags,
queue_families: I,
) -> Result<Arc<StorageImage<F>>, ImageCreationError>
) -> Result<Arc<StorageImage>, ImageCreationError>
where
F: FormatDesc,
I: IntoIterator<Item = QueueFamily<'a>>,
{
let queue_families = queue_families
@ -132,7 +129,7 @@ impl<F> StorageImage<F> {
UnsafeImage::new(
device.clone(),
usage,
format.format(),
format,
flags,
dimensions,
1,
@ -173,7 +170,7 @@ impl<F> StorageImage<F> {
}
}
impl<F, A> StorageImage<F, A>
impl<A> StorageImage<A>
where
A: MemoryPool,
{
@ -184,9 +181,8 @@ where
}
}
unsafe impl<F, A> ImageAccess for StorageImage<F, A>
unsafe impl<A> ImageAccess for StorageImage<A>
where
F: 'static + Send + Sync,
A: MemoryPool,
{
#[inline]
@ -279,20 +275,18 @@ where
}
}
unsafe impl<F, A> ImageClearValue<F::ClearValue> for StorageImage<F, A>
unsafe impl<A> ImageClearValue<ClearValue> for StorageImage<A>
where
F: FormatDesc + 'static + Send + Sync,
A: MemoryPool,
{
#[inline]
fn decode(&self, value: F::ClearValue) -> Option<ClearValue> {
fn decode(&self, value: ClearValue) -> Option<ClearValue> {
Some(self.format.decode_clear_value(value))
}
}
unsafe impl<P, F, A> ImageContent<P> for StorageImage<F, A>
unsafe impl<P, A> ImageContent<P> for StorageImage<A>
where
F: 'static + Send + Sync,
A: MemoryPool,
{
#[inline]
@ -301,9 +295,8 @@ where
}
}
impl<F, A> PartialEq for StorageImage<F, A>
impl<A> PartialEq for StorageImage<A>
where
F: 'static + Send + Sync,
A: MemoryPool,
{
#[inline]
@ -312,16 +305,10 @@ where
}
}
impl<F, A> Eq for StorageImage<F, A>
where
F: 'static + Send + Sync,
A: MemoryPool,
{
}
impl<A> Eq for StorageImage<A> where A: MemoryPool {}
impl<F, A> Hash for StorageImage<F, A>
impl<A> Hash for StorageImage<A>
where
F: 'static + Send + Sync,
A: MemoryPool,
{
#[inline]

View File

@ -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<W> ImageAccess for SwapchainImage<W> {
}
}
unsafe impl<W> ImageClearValue<<Format as FormatDesc>::ClearValue> for SwapchainImage<W> {
unsafe impl<W> ImageClearValue<ClearValue> for SwapchainImage<W> {
#[inline]
fn decode(&self, value: <Format as FormatDesc>::ClearValue) -> Option<ClearValue> {
fn decode(&self, value: ClearValue) -> Option<ClearValue> {
Some(self.swapchain.format().decode_clear_value(value))
}
}

View File

@ -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,
};

View File

@ -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.

View File

@ -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,

View File

@ -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<W> Surface<W> {
) -> Surface<W> {
Surface {
window: win,
instance: instance,
surface: surface,
instance,
surface,
has_swapchain: AtomicBool::new(false),
}
}
@ -126,7 +125,7 @@ impl<W> Surface<W> {
Ok(Arc::new(Surface {
window: (),
instance: instance.clone(),
surface: surface,
surface,
has_swapchain: AtomicBool::new(false),
}))
}
@ -176,7 +175,7 @@ impl<W> Surface<W> {
Ok(Arc::new(Surface {
window: win,
instance: instance.clone(),
surface: surface,
surface,
has_swapchain: AtomicBool::new(false),
}))
}
@ -209,7 +208,7 @@ impl<W> Surface<W> {
pNext: ptr::null(),
flags: 0, // reserved
connection: connection as *mut _,
window: window,
window,
};
let mut output = MaybeUninit::uninit();
@ -225,7 +224,7 @@ impl<W> Surface<W> {
Ok(Arc::new(Surface {
window: win,
instance: instance.clone(),
surface: surface,
surface,
has_swapchain: AtomicBool::new(false),
}))
}
@ -258,7 +257,7 @@ impl<W> Surface<W> {
pNext: ptr::null(),
flags: 0, // reserved
dpy: display as *mut _,
window: window,
window,
};
let mut output = MaybeUninit::uninit();
@ -274,7 +273,7 @@ impl<W> Surface<W> {
Ok(Arc::new(Surface {
window: win,
instance: instance.clone(),
surface: surface,
surface,
has_swapchain: AtomicBool::new(false),
}))
}
@ -323,7 +322,7 @@ impl<W> Surface<W> {
Ok(Arc::new(Surface {
window: win,
instance: instance.clone(),
surface: surface,
surface,
has_swapchain: AtomicBool::new(false),
}))
}
@ -368,7 +367,7 @@ impl<W> Surface<W> {
Ok(Arc::new(Surface {
window: win,
instance: instance.clone(),
surface: surface,
surface,
has_swapchain: AtomicBool::new(false),
}))
}
@ -414,7 +413,7 @@ impl<W> Surface<W> {
Ok(Arc::new(Surface {
window: win,
instance: instance.clone(),
surface: surface,
surface,
has_swapchain: AtomicBool::new(false),
}))
}
@ -460,7 +459,7 @@ impl<W> Surface<W> {
Ok(Arc::new(Surface {
window: win,
instance: instance.clone(),
surface: surface,
surface,
has_swapchain: AtomicBool::new(false),
}))
}
@ -505,7 +504,7 @@ impl<W> Surface<W> {
Ok(Arc::new(Surface {
window: win,
instance: instance.clone(),
surface: surface,
surface,
has_swapchain: AtomicBool::new(false),
}))
}
@ -640,7 +639,7 @@ impl<W> Surface<W> {
.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))
})
})

View File

@ -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<W> Swapchain<W> {
///
// TODO: isn't it unsafe to take the surface through an Arc when it comes to vulkano-win?
#[inline]
pub fn new<F, S>(
pub fn new<S>(
device: Arc<Device>,
surface: Arc<Surface<W>>,
num_images: u32,
format: F,
format: Format,
dimensions: [u32; 2],
layers: u32,
usage: ImageUsage,
@ -301,14 +299,13 @@ impl<W> Swapchain<W> {
color_space: ColorSpace,
) -> Result<(Arc<Swapchain<W>>, Vec<Arc<SwapchainImage<W>>>), SwapchainCreationError>
where
F: FormatDesc,
S: Into<SharingMode>,
{
Swapchain::new_inner(
device,
surface,
num_images,
format.format(),
format,
color_space,
Some(dimensions),
layers,
@ -325,11 +322,11 @@ impl<W> Swapchain<W> {
/// Same as Swapchain::new but requires an old swapchain for the creation
#[inline]
pub fn with_old_swapchain<F, S>(
pub fn with_old_swapchain<S>(
device: Arc<Device>,
surface: Arc<Surface<W>>,
num_images: u32,
format: F,
format: Format,
dimensions: [u32; 2],
layers: u32,
usage: ImageUsage,
@ -343,14 +340,13 @@ impl<W> Swapchain<W> {
old_swapchain: Arc<Swapchain<W>>,
) -> Result<(Arc<Swapchain<W>>, Vec<Arc<SwapchainImage<W>>>), SwapchainCreationError>
where
F: FormatDesc,
S: Into<SharingMode>,
{
Swapchain::new_inner(
device,
surface,
num_images,
format.format(),
format,
ColorSpace::SrgbNonLinear,
Some(dimensions),
layers,