mirror of
https://github.com/vulkano-rs/vulkano.git
synced 2024-11-29 10:14:29 +00:00
Replace Iterator
parameters with IntoIterator
where possible, replace various iterator types with impl Iterator
(#1719)
This commit is contained in:
parent
131f5b0f0f
commit
17820738d8
@ -216,7 +216,7 @@ pub(super) fn reflect<'a, I>(
|
|||||||
types_registry: &'a mut HashMap<String, RegisteredType>,
|
types_registry: &'a mut HashMap<String, RegisteredType>,
|
||||||
) -> Result<(TokenStream, TokenStream), Error>
|
) -> Result<(TokenStream, TokenStream), Error>
|
||||||
where
|
where
|
||||||
I: Iterator<Item = &'a str>,
|
I: IntoIterator<Item = &'a str>,
|
||||||
{
|
{
|
||||||
let struct_name = Ident::new(&format!("{}Shader", prefix), Span::call_site());
|
let struct_name = Ident::new(&format!("{}Shader", prefix), Span::call_site());
|
||||||
let spirv = Spirv::new(words)?;
|
let spirv = Spirv::new(words)?;
|
||||||
@ -325,7 +325,7 @@ where
|
|||||||
entry_points_inside_impl.push(entry_point);
|
entry_points_inside_impl.push(entry_point);
|
||||||
}
|
}
|
||||||
|
|
||||||
let include_bytes = input_paths.map(|s| {
|
let include_bytes = input_paths.into_iter().map(|s| {
|
||||||
quote! {
|
quote! {
|
||||||
// using include_bytes here ensures that changing the shader will force recompilation.
|
// using include_bytes here ensures that changing the shader will force recompilation.
|
||||||
// The bytes themselves can be optimized out by the compiler as they are unused.
|
// The bytes themselves can be optimized out by the compiler as they are unused.
|
||||||
|
@ -157,9 +157,12 @@ impl<T> CpuAccessibleBuffer<[T]> {
|
|||||||
data: I,
|
data: I,
|
||||||
) -> Result<Arc<CpuAccessibleBuffer<[T]>>, DeviceMemoryAllocError>
|
) -> Result<Arc<CpuAccessibleBuffer<[T]>>, DeviceMemoryAllocError>
|
||||||
where
|
where
|
||||||
I: ExactSizeIterator<Item = T>,
|
I: IntoIterator<Item = T>,
|
||||||
|
I::IntoIter: ExactSizeIterator,
|
||||||
T: Content + 'static,
|
T: Content + 'static,
|
||||||
{
|
{
|
||||||
|
let data = data.into_iter();
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
let uninitialized = CpuAccessibleBuffer::uninitialized_array(
|
let uninitialized = CpuAccessibleBuffer::uninitialized_array(
|
||||||
device,
|
device,
|
||||||
|
@ -420,11 +420,14 @@ where
|
|||||||
fn try_next_impl<I>(
|
fn try_next_impl<I>(
|
||||||
&self,
|
&self,
|
||||||
cur_buf_mutex: &mut MutexGuard<Option<Arc<ActualBuffer<A>>>>,
|
cur_buf_mutex: &mut MutexGuard<Option<Arc<ActualBuffer<A>>>>,
|
||||||
mut data: I,
|
data: I,
|
||||||
) -> Result<CpuBufferPoolChunk<T, A>, I>
|
) -> Result<CpuBufferPoolChunk<T, A>, I::IntoIter>
|
||||||
where
|
where
|
||||||
I: ExactSizeIterator<Item = T>,
|
I: IntoIterator<Item = T>,
|
||||||
|
I::IntoIter: ExactSizeIterator,
|
||||||
{
|
{
|
||||||
|
let mut data = data.into_iter();
|
||||||
|
|
||||||
// Grab the current buffer. Return `Err` if the pool wasn't "initialized" yet.
|
// Grab the current buffer. Return `Err` if the pool wasn't "initialized" yet.
|
||||||
let current_buffer = match cur_buf_mutex.clone() {
|
let current_buffer = match cur_buf_mutex.clone() {
|
||||||
Some(b) => b,
|
Some(b) => b,
|
||||||
|
@ -193,7 +193,8 @@ impl<T> ImmutableBuffer<[T]> {
|
|||||||
queue: Arc<Queue>,
|
queue: Arc<Queue>,
|
||||||
) -> Result<(Arc<ImmutableBuffer<[T]>>, ImmutableBufferFromBufferFuture), DeviceMemoryAllocError>
|
) -> Result<(Arc<ImmutableBuffer<[T]>>, ImmutableBufferFromBufferFuture), DeviceMemoryAllocError>
|
||||||
where
|
where
|
||||||
D: ExactSizeIterator<Item = T>,
|
D: IntoIterator<Item = T>,
|
||||||
|
D::IntoIter: ExactSizeIterator,
|
||||||
T: 'static + Send + Sync + Sized,
|
T: 'static + Send + Sync + Sized,
|
||||||
{
|
{
|
||||||
let source = CpuAccessibleBuffer::from_iter(
|
let source = CpuAccessibleBuffer::from_iter(
|
||||||
|
@ -72,7 +72,7 @@ impl UnsafeBuffer {
|
|||||||
sparse: Option<SparseLevel>,
|
sparse: Option<SparseLevel>,
|
||||||
) -> Result<(UnsafeBuffer, MemoryRequirements), BufferCreationError>
|
) -> Result<(UnsafeBuffer, MemoryRequirements), BufferCreationError>
|
||||||
where
|
where
|
||||||
I: Iterator<Item = u32>,
|
I: IntoIterator<Item = u32>,
|
||||||
{
|
{
|
||||||
let fns = device.fns();
|
let fns = device.fns();
|
||||||
|
|
||||||
@ -126,7 +126,9 @@ impl UnsafeBuffer {
|
|||||||
Sharing::Exclusive => {
|
Sharing::Exclusive => {
|
||||||
(ash::vk::SharingMode::EXCLUSIVE, SmallVec::<[u32; 8]>::new())
|
(ash::vk::SharingMode::EXCLUSIVE, SmallVec::<[u32; 8]>::new())
|
||||||
}
|
}
|
||||||
Sharing::Concurrent(ids) => (ash::vk::SharingMode::CONCURRENT, ids.collect()),
|
Sharing::Concurrent(ids) => {
|
||||||
|
(ash::vk::SharingMode::CONCURRENT, ids.into_iter().collect())
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let infos = ash::vk::BufferCreateInfo {
|
let infos = ash::vk::BufferCreateInfo {
|
||||||
|
@ -16,16 +16,13 @@
|
|||||||
//! trait. By default vulkano will use the `StandardCommandPool` struct, but you can implement
|
//! trait. By default vulkano will use the `StandardCommandPool` struct, but you can implement
|
||||||
//! this trait yourself by wrapping around the `UnsafeCommandPool` type.
|
//! this trait yourself by wrapping around the `UnsafeCommandPool` type.
|
||||||
|
|
||||||
use crate::device::physical::QueueFamily;
|
|
||||||
|
|
||||||
use crate::device::DeviceOwned;
|
|
||||||
use crate::OomError;
|
|
||||||
|
|
||||||
pub use self::standard::StandardCommandPool;
|
pub use self::standard::StandardCommandPool;
|
||||||
pub use self::sys::CommandPoolTrimError;
|
pub use self::sys::CommandPoolTrimError;
|
||||||
pub use self::sys::UnsafeCommandPool;
|
pub use self::sys::UnsafeCommandPool;
|
||||||
pub use self::sys::UnsafeCommandPoolAlloc;
|
pub use self::sys::UnsafeCommandPoolAlloc;
|
||||||
pub use self::sys::UnsafeCommandPoolAllocIter;
|
use crate::device::physical::QueueFamily;
|
||||||
|
use crate::device::DeviceOwned;
|
||||||
|
use crate::OomError;
|
||||||
|
|
||||||
pub mod standard;
|
pub mod standard;
|
||||||
mod sys;
|
mod sys;
|
||||||
|
@ -22,7 +22,6 @@ use std::marker::PhantomData;
|
|||||||
use std::mem::MaybeUninit;
|
use std::mem::MaybeUninit;
|
||||||
use std::ptr;
|
use std::ptr;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::vec::IntoIter as VecIntoIter;
|
|
||||||
|
|
||||||
/// Low-level implementation of a command pool.
|
/// Low-level implementation of a command pool.
|
||||||
///
|
///
|
||||||
@ -182,41 +181,43 @@ impl UnsafeCommandPool {
|
|||||||
&self,
|
&self,
|
||||||
secondary: bool,
|
secondary: bool,
|
||||||
count: u32,
|
count: u32,
|
||||||
) -> Result<UnsafeCommandPoolAllocIter, OomError> {
|
) -> Result<impl ExactSizeIterator<Item = UnsafeCommandPoolAlloc>, OomError> {
|
||||||
if count == 0 {
|
let out = if count == 0 {
|
||||||
return Ok(UnsafeCommandPoolAllocIter {
|
vec![]
|
||||||
device: self.device.clone(),
|
} else {
|
||||||
list: vec![].into_iter(),
|
let infos = ash::vk::CommandBufferAllocateInfo {
|
||||||
});
|
command_pool: self.pool,
|
||||||
}
|
level: if secondary {
|
||||||
|
ash::vk::CommandBufferLevel::SECONDARY
|
||||||
|
} else {
|
||||||
|
ash::vk::CommandBufferLevel::PRIMARY
|
||||||
|
},
|
||||||
|
command_buffer_count: count,
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
|
|
||||||
let infos = ash::vk::CommandBufferAllocateInfo {
|
unsafe {
|
||||||
command_pool: self.pool,
|
let fns = self.device.fns();
|
||||||
level: if secondary {
|
let mut out = Vec::with_capacity(count as usize);
|
||||||
ash::vk::CommandBufferLevel::SECONDARY
|
check_errors(fns.v1_0.allocate_command_buffers(
|
||||||
} else {
|
self.device.internal_object(),
|
||||||
ash::vk::CommandBufferLevel::PRIMARY
|
&infos,
|
||||||
},
|
out.as_mut_ptr(),
|
||||||
command_buffer_count: count,
|
))?;
|
||||||
..Default::default()
|
|
||||||
|
out.set_len(count as usize);
|
||||||
|
out
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
unsafe {
|
let device = self.device.clone();
|
||||||
let fns = self.device.fns();
|
|
||||||
let mut out = Vec::with_capacity(count as usize);
|
|
||||||
check_errors(fns.v1_0.allocate_command_buffers(
|
|
||||||
self.device.internal_object(),
|
|
||||||
&infos,
|
|
||||||
out.as_mut_ptr(),
|
|
||||||
))?;
|
|
||||||
|
|
||||||
out.set_len(count as usize);
|
Ok(out
|
||||||
|
.into_iter()
|
||||||
Ok(UnsafeCommandPoolAllocIter {
|
.map(move |command_buffer| UnsafeCommandPoolAlloc {
|
||||||
device: self.device.clone(),
|
command_buffer,
|
||||||
list: out.into_iter(),
|
device: device.clone(),
|
||||||
})
|
}))
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Frees individual command buffers.
|
/// Frees individual command buffers.
|
||||||
@ -227,10 +228,12 @@ impl UnsafeCommandPool {
|
|||||||
///
|
///
|
||||||
pub unsafe fn free_command_buffers<I>(&self, command_buffers: I)
|
pub unsafe fn free_command_buffers<I>(&self, command_buffers: I)
|
||||||
where
|
where
|
||||||
I: Iterator<Item = UnsafeCommandPoolAlloc>,
|
I: IntoIterator<Item = UnsafeCommandPoolAlloc>,
|
||||||
{
|
{
|
||||||
let command_buffers: SmallVec<[_; 4]> =
|
let command_buffers: SmallVec<[_; 4]> = command_buffers
|
||||||
command_buffers.map(|cb| cb.command_buffer).collect();
|
.into_iter()
|
||||||
|
.map(|cb| cb.command_buffer)
|
||||||
|
.collect();
|
||||||
let fns = self.device.fns();
|
let fns = self.device.fns();
|
||||||
fns.v1_0.free_command_buffers(
|
fns.v1_0.free_command_buffers(
|
||||||
self.device.internal_object(),
|
self.device.internal_object(),
|
||||||
@ -299,34 +302,6 @@ unsafe impl VulkanObject for UnsafeCommandPoolAlloc {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Iterator for newly-allocated command buffers.
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub struct UnsafeCommandPoolAllocIter {
|
|
||||||
device: Arc<Device>,
|
|
||||||
list: VecIntoIter<ash::vk::CommandBuffer>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Iterator for UnsafeCommandPoolAllocIter {
|
|
||||||
type Item = UnsafeCommandPoolAlloc;
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn next(&mut self) -> Option<UnsafeCommandPoolAlloc> {
|
|
||||||
self.list
|
|
||||||
.next()
|
|
||||||
.map(|command_buffer| UnsafeCommandPoolAlloc {
|
|
||||||
command_buffer,
|
|
||||||
device: self.device.clone(),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn size_hint(&self) -> (usize, Option<usize>) {
|
|
||||||
self.list.size_hint()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ExactSizeIterator for UnsafeCommandPoolAllocIter {}
|
|
||||||
|
|
||||||
/// Error that can happen when trimming command pools.
|
/// Error that can happen when trimming command pools.
|
||||||
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
|
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
|
||||||
pub enum CommandPoolTrimError {
|
pub enum CommandPoolTrimError {
|
||||||
|
@ -385,7 +385,9 @@ impl DescriptorSetBuilder {
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
if !image_view.can_be_sampled(&immutable_samplers[descriptor.array_element as usize]) {
|
if !image_view
|
||||||
|
.can_be_sampled(&immutable_samplers[descriptor.array_element as usize])
|
||||||
|
{
|
||||||
return Err(DescriptorSetError::IncompatibleImageViewSampler);
|
return Err(DescriptorSetError::IncompatibleImageViewSampler);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,7 +12,6 @@
|
|||||||
pub use self::standard::StdDescriptorPool;
|
pub use self::standard::StdDescriptorPool;
|
||||||
pub use self::sys::DescriptorPoolAllocError;
|
pub use self::sys::DescriptorPoolAllocError;
|
||||||
pub use self::sys::UnsafeDescriptorPool;
|
pub use self::sys::UnsafeDescriptorPool;
|
||||||
pub use self::sys::UnsafeDescriptorPoolAllocIter;
|
|
||||||
use crate::descriptor_set::layout::DescriptorSetLayout;
|
use crate::descriptor_set::layout::DescriptorSetLayout;
|
||||||
use crate::descriptor_set::layout::DescriptorType;
|
use crate::descriptor_set::layout::DescriptorType;
|
||||||
use crate::descriptor_set::UnsafeDescriptorSet;
|
use crate::descriptor_set::UnsafeDescriptorSet;
|
||||||
|
@ -21,7 +21,6 @@ use std::fmt;
|
|||||||
use std::mem::MaybeUninit;
|
use std::mem::MaybeUninit;
|
||||||
use std::ptr;
|
use std::ptr;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::vec::IntoIter as VecIntoIter;
|
|
||||||
|
|
||||||
/// Pool from which descriptor sets are allocated from.
|
/// Pool from which descriptor sets are allocated from.
|
||||||
///
|
///
|
||||||
@ -153,7 +152,7 @@ impl UnsafeDescriptorPool {
|
|||||||
pub unsafe fn alloc<'l, I>(
|
pub unsafe fn alloc<'l, I>(
|
||||||
&mut self,
|
&mut self,
|
||||||
layouts: I,
|
layouts: I,
|
||||||
) -> Result<UnsafeDescriptorPoolAllocIter, DescriptorPoolAllocError>
|
) -> Result<impl ExactSizeIterator<Item = UnsafeDescriptorSet>, DescriptorPoolAllocError>
|
||||||
where
|
where
|
||||||
I: IntoIterator<Item = &'l DescriptorSetLayout>,
|
I: IntoIterator<Item = &'l DescriptorSetLayout>,
|
||||||
{
|
{
|
||||||
@ -182,70 +181,68 @@ impl UnsafeDescriptorPool {
|
|||||||
&mut self,
|
&mut self,
|
||||||
layouts: &SmallVec<[ash::vk::DescriptorSetLayout; 8]>,
|
layouts: &SmallVec<[ash::vk::DescriptorSetLayout; 8]>,
|
||||||
variable_descriptor_counts: &SmallVec<[u32; 8]>,
|
variable_descriptor_counts: &SmallVec<[u32; 8]>,
|
||||||
) -> Result<UnsafeDescriptorPoolAllocIter, DescriptorPoolAllocError> {
|
) -> Result<impl ExactSizeIterator<Item = UnsafeDescriptorSet>, DescriptorPoolAllocError> {
|
||||||
let num = layouts.len();
|
let num = layouts.len();
|
||||||
|
|
||||||
if num == 0 {
|
let output = if num == 0 {
|
||||||
return Ok(UnsafeDescriptorPoolAllocIter {
|
vec![]
|
||||||
sets: vec![].into_iter(),
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
let variable_desc_count_alloc_info = if variable_descriptor_counts.iter().any(|c| *c != 0) {
|
|
||||||
Some(ash::vk::DescriptorSetVariableDescriptorCountAllocateInfo {
|
|
||||||
descriptor_set_count: layouts.len() as u32,
|
|
||||||
p_descriptor_counts: variable_descriptor_counts.as_ptr(),
|
|
||||||
.. Default::default()
|
|
||||||
})
|
|
||||||
} else {
|
} else {
|
||||||
None
|
let variable_desc_count_alloc_info =
|
||||||
|
if variable_descriptor_counts.iter().any(|c| *c != 0) {
|
||||||
|
Some(ash::vk::DescriptorSetVariableDescriptorCountAllocateInfo {
|
||||||
|
descriptor_set_count: layouts.len() as u32,
|
||||||
|
p_descriptor_counts: variable_descriptor_counts.as_ptr(),
|
||||||
|
..Default::default()
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
};
|
||||||
|
|
||||||
|
let infos = ash::vk::DescriptorSetAllocateInfo {
|
||||||
|
descriptor_pool: self.pool,
|
||||||
|
descriptor_set_count: layouts.len() as u32,
|
||||||
|
p_set_layouts: layouts.as_ptr(),
|
||||||
|
p_next: if let Some(next) = variable_desc_count_alloc_info.as_ref() {
|
||||||
|
next as *const _ as *const _
|
||||||
|
} else {
|
||||||
|
ptr::null()
|
||||||
|
},
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
|
|
||||||
|
let mut output = Vec::with_capacity(num);
|
||||||
|
|
||||||
|
let fns = self.device.fns();
|
||||||
|
let ret = fns.v1_0.allocate_descriptor_sets(
|
||||||
|
self.device.internal_object(),
|
||||||
|
&infos,
|
||||||
|
output.as_mut_ptr(),
|
||||||
|
);
|
||||||
|
|
||||||
|
// According to the specs, because `VK_ERROR_FRAGMENTED_POOL` was added after version
|
||||||
|
// 1.0 of Vulkan, any negative return value except out-of-memory errors must be
|
||||||
|
// considered as a fragmented pool error.
|
||||||
|
match ret {
|
||||||
|
ash::vk::Result::ERROR_OUT_OF_HOST_MEMORY => {
|
||||||
|
return Err(DescriptorPoolAllocError::OutOfHostMemory);
|
||||||
|
}
|
||||||
|
ash::vk::Result::ERROR_OUT_OF_DEVICE_MEMORY => {
|
||||||
|
return Err(DescriptorPoolAllocError::OutOfDeviceMemory);
|
||||||
|
}
|
||||||
|
ash::vk::Result::ERROR_OUT_OF_POOL_MEMORY_KHR => {
|
||||||
|
return Err(DescriptorPoolAllocError::OutOfPoolMemory);
|
||||||
|
}
|
||||||
|
c if c.as_raw() < 0 => {
|
||||||
|
return Err(DescriptorPoolAllocError::FragmentedPool);
|
||||||
|
}
|
||||||
|
_ => (),
|
||||||
|
};
|
||||||
|
|
||||||
|
output.set_len(num);
|
||||||
|
output
|
||||||
};
|
};
|
||||||
|
|
||||||
let infos = ash::vk::DescriptorSetAllocateInfo {
|
Ok(output.into_iter().map(|s| UnsafeDescriptorSet { set: s }))
|
||||||
descriptor_pool: self.pool,
|
|
||||||
descriptor_set_count: layouts.len() as u32,
|
|
||||||
p_set_layouts: layouts.as_ptr(),
|
|
||||||
p_next: if let Some(next) = variable_desc_count_alloc_info.as_ref() {
|
|
||||||
next as *const _ as *const _
|
|
||||||
} else {
|
|
||||||
ptr::null()
|
|
||||||
},
|
|
||||||
..Default::default()
|
|
||||||
};
|
|
||||||
|
|
||||||
let mut output = Vec::with_capacity(num);
|
|
||||||
|
|
||||||
let fns = self.device.fns();
|
|
||||||
let ret = fns.v1_0.allocate_descriptor_sets(
|
|
||||||
self.device.internal_object(),
|
|
||||||
&infos,
|
|
||||||
output.as_mut_ptr(),
|
|
||||||
);
|
|
||||||
|
|
||||||
// According to the specs, because `VK_ERROR_FRAGMENTED_POOL` was added after version
|
|
||||||
// 1.0 of Vulkan, any negative return value except out-of-memory errors must be
|
|
||||||
// considered as a fragmented pool error.
|
|
||||||
match ret {
|
|
||||||
ash::vk::Result::ERROR_OUT_OF_HOST_MEMORY => {
|
|
||||||
return Err(DescriptorPoolAllocError::OutOfHostMemory);
|
|
||||||
}
|
|
||||||
ash::vk::Result::ERROR_OUT_OF_DEVICE_MEMORY => {
|
|
||||||
return Err(DescriptorPoolAllocError::OutOfDeviceMemory);
|
|
||||||
}
|
|
||||||
ash::vk::Result::ERROR_OUT_OF_POOL_MEMORY_KHR => {
|
|
||||||
return Err(DescriptorPoolAllocError::OutOfPoolMemory);
|
|
||||||
}
|
|
||||||
c if c.as_raw() < 0 => {
|
|
||||||
return Err(DescriptorPoolAllocError::FragmentedPool);
|
|
||||||
}
|
|
||||||
_ => (),
|
|
||||||
};
|
|
||||||
|
|
||||||
output.set_len(num);
|
|
||||||
|
|
||||||
Ok(UnsafeDescriptorPoolAllocIter {
|
|
||||||
sets: output.into_iter(),
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Frees some descriptor sets.
|
/// Frees some descriptor sets.
|
||||||
@ -369,28 +366,6 @@ impl fmt::Display for DescriptorPoolAllocError {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Iterator to the descriptor sets allocated from an unsafe descriptor pool.
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub struct UnsafeDescriptorPoolAllocIter {
|
|
||||||
sets: VecIntoIter<ash::vk::DescriptorSet>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Iterator for UnsafeDescriptorPoolAllocIter {
|
|
||||||
type Item = UnsafeDescriptorSet;
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn next(&mut self) -> Option<UnsafeDescriptorSet> {
|
|
||||||
self.sets.next().map(|s| UnsafeDescriptorSet { set: s })
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn size_hint(&self) -> (usize, Option<usize>) {
|
|
||||||
self.sets.size_hint()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ExactSizeIterator for UnsafeDescriptorPoolAllocIter {}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use crate::descriptor_set::layout::DescriptorDesc;
|
use crate::descriptor_set::layout::DescriptorDesc;
|
||||||
|
@ -56,7 +56,7 @@ impl UnsafeDescriptorSet {
|
|||||||
///
|
///
|
||||||
pub unsafe fn write<I>(&mut self, device: &Device, writes: I)
|
pub unsafe fn write<I>(&mut self, device: &Device, writes: I)
|
||||||
where
|
where
|
||||||
I: Iterator<Item = DescriptorWrite>,
|
I: IntoIterator<Item = DescriptorWrite>,
|
||||||
{
|
{
|
||||||
let fns = device.fns();
|
let fns = device.fns();
|
||||||
|
|
||||||
|
@ -191,8 +191,12 @@ impl Device {
|
|||||||
///
|
///
|
||||||
/// - Panics if one of the queue families doesn't belong to the given device.
|
/// - Panics if one of the queue families doesn't belong to the given device.
|
||||||
///
|
///
|
||||||
|
|
||||||
// TODO: return Arc<Queue> and handle synchronization in the Queue
|
// TODO: return Arc<Queue> and handle synchronization in the Queue
|
||||||
// TODO: should take the PhysicalDevice by value
|
|
||||||
|
// TODO: Eliminate QueuesIter in favour of `impl ExactSizeIterator`. This doesn't currently work
|
||||||
|
// due to this Rust bug: https://github.com/rust-lang/rust/issues/42940. The compiler will
|
||||||
|
// erroneously assume that the return iterator borrows from 'a and break.
|
||||||
pub fn new<'a, I>(
|
pub fn new<'a, I>(
|
||||||
physical_device: PhysicalDevice,
|
physical_device: PhysicalDevice,
|
||||||
requested_features: &Features,
|
requested_features: &Features,
|
||||||
@ -447,15 +451,11 @@ impl Device {
|
|||||||
/// > **Note**: Will return `-> impl ExactSizeIterator<Item = QueueFamily>` in the future.
|
/// > **Note**: Will return `-> impl ExactSizeIterator<Item = QueueFamily>` in the future.
|
||||||
// TODO: ^
|
// TODO: ^
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn active_queue_families<'a>(
|
pub fn active_queue_families<'a>(&'a self) -> impl ExactSizeIterator<Item = QueueFamily<'a>> {
|
||||||
&'a self,
|
|
||||||
) -> Box<dyn ExactSizeIterator<Item = QueueFamily<'a>> + 'a> {
|
|
||||||
let physical_device = self.physical_device();
|
let physical_device = self.physical_device();
|
||||||
Box::new(
|
self.active_queue_families
|
||||||
self.active_queue_families
|
.iter()
|
||||||
.iter()
|
.map(move |&id| physical_device.queue_family_by_id(id).unwrap())
|
||||||
.map(move |&id| physical_device.queue_family_by_id(id).unwrap()),
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the features that have been enabled on the device.
|
/// Returns the features that have been enabled on the device.
|
||||||
|
@ -331,7 +331,8 @@ impl ImmutableImage {
|
|||||||
>
|
>
|
||||||
where
|
where
|
||||||
Px: Pixel + Send + Sync + Clone + 'static,
|
Px: Pixel + Send + Sync + Clone + 'static,
|
||||||
I: ExactSizeIterator<Item = Px>,
|
I: IntoIterator<Item = Px>,
|
||||||
|
I::IntoIter: ExactSizeIterator,
|
||||||
{
|
{
|
||||||
let source = CpuAccessibleBuffer::from_iter(
|
let source = CpuAccessibleBuffer::from_iter(
|
||||||
queue.device().clone(),
|
queue.device().clone(),
|
||||||
|
@ -101,11 +101,13 @@ impl UnsafeImage {
|
|||||||
) -> Result<(UnsafeImage, MemoryRequirements), ImageCreationError>
|
) -> Result<(UnsafeImage, MemoryRequirements), ImageCreationError>
|
||||||
where
|
where
|
||||||
Mi: Into<MipmapsCount>,
|
Mi: Into<MipmapsCount>,
|
||||||
I: Iterator<Item = u32>,
|
I: IntoIterator<Item = u32>,
|
||||||
{
|
{
|
||||||
let sharing = match sharing {
|
let sharing = match sharing {
|
||||||
Sharing::Exclusive => (ash::vk::SharingMode::EXCLUSIVE, SmallVec::<[u32; 8]>::new()),
|
Sharing::Exclusive => (ash::vk::SharingMode::EXCLUSIVE, SmallVec::<[u32; 8]>::new()),
|
||||||
Sharing::Concurrent(ids) => (ash::vk::SharingMode::CONCURRENT, ids.collect()),
|
Sharing::Concurrent(ids) => {
|
||||||
|
(ash::vk::SharingMode::CONCURRENT, ids.into_iter().collect())
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
UnsafeImage::new_impl(
|
UnsafeImage::new_impl(
|
||||||
|
@ -7,18 +7,16 @@
|
|||||||
// notice may not be copied, modified, or distributed except
|
// notice may not be copied, modified, or distributed except
|
||||||
// according to those terms.
|
// according to those terms.
|
||||||
|
|
||||||
use std::error;
|
|
||||||
use std::ffi::CStr;
|
|
||||||
use std::fmt;
|
|
||||||
use std::ptr;
|
|
||||||
use std::vec::IntoIter;
|
|
||||||
|
|
||||||
use crate::check_errors;
|
use crate::check_errors;
|
||||||
use crate::instance::loader;
|
use crate::instance::loader;
|
||||||
use crate::instance::loader::LoadingError;
|
use crate::instance::loader::LoadingError;
|
||||||
use crate::Error;
|
use crate::Error;
|
||||||
use crate::OomError;
|
use crate::OomError;
|
||||||
use crate::Version;
|
use crate::Version;
|
||||||
|
use std::error;
|
||||||
|
use std::ffi::CStr;
|
||||||
|
use std::fmt;
|
||||||
|
use std::ptr;
|
||||||
|
|
||||||
/// Queries the list of layers that are available when creating an instance.
|
/// Queries the list of layers that are available when creating an instance.
|
||||||
///
|
///
|
||||||
@ -43,14 +41,14 @@ use crate::Version;
|
|||||||
/// println!("Available layer: {}", layer.name());
|
/// println!("Available layer: {}", layer.name());
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
pub fn layers_list() -> Result<LayersIterator, LayersListError> {
|
pub fn layers_list() -> Result<impl ExactSizeIterator<Item = LayerProperties>, LayersListError> {
|
||||||
layers_list_from_loader(loader::auto_loader()?)
|
layers_list_from_loader(loader::auto_loader()?)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Same as `layers_list()`, but allows specifying a loader.
|
/// Same as `layers_list()`, but allows specifying a loader.
|
||||||
pub fn layers_list_from_loader<L>(
|
pub fn layers_list_from_loader<L>(
|
||||||
ptrs: &loader::FunctionPointers<L>,
|
ptrs: &loader::FunctionPointers<L>,
|
||||||
) -> Result<LayersIterator, LayersListError>
|
) -> Result<impl ExactSizeIterator<Item = LayerProperties>, LayersListError>
|
||||||
where
|
where
|
||||||
L: loader::Loader,
|
L: loader::Loader,
|
||||||
{
|
{
|
||||||
@ -70,9 +68,7 @@ where
|
|||||||
})?;
|
})?;
|
||||||
layers.set_len(num as usize);
|
layers.set_len(num as usize);
|
||||||
|
|
||||||
Ok(LayersIterator {
|
Ok(layers.into_iter().map(|p| LayerProperties { props: p }))
|
||||||
iter: layers.into_iter(),
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -224,28 +220,6 @@ impl From<Error> for LayersListError {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Iterator that produces the list of layers that are available.
|
|
||||||
// TODO: #[derive(Debug, Clone)]
|
|
||||||
pub struct LayersIterator {
|
|
||||||
iter: IntoIter<ash::vk::LayerProperties>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Iterator for LayersIterator {
|
|
||||||
type Item = LayerProperties;
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn next(&mut self) -> Option<LayerProperties> {
|
|
||||||
self.iter.next().map(|p| LayerProperties { props: p })
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn size_hint(&self) -> (usize, Option<usize>) {
|
|
||||||
self.iter.size_hint()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ExactSizeIterator for LayersIterator {}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use crate::instance;
|
use crate::instance;
|
||||||
|
@ -57,7 +57,6 @@ pub use self::instance::Instance;
|
|||||||
pub use self::instance::InstanceCreationError;
|
pub use self::instance::InstanceCreationError;
|
||||||
pub use self::layers::layers_list;
|
pub use self::layers::layers_list;
|
||||||
pub use self::layers::LayerProperties;
|
pub use self::layers::LayerProperties;
|
||||||
pub use self::layers::LayersIterator;
|
|
||||||
pub use self::layers::LayersListError;
|
pub use self::layers::LayersListError;
|
||||||
pub use self::loader::LoadingError;
|
pub use self::loader::LoadingError;
|
||||||
pub use crate::extensions::{
|
pub use crate::extensions::{
|
||||||
|
@ -156,37 +156,15 @@ impl SupportedPresentModes {
|
|||||||
|
|
||||||
/// Returns an iterator to the list of supported present modes.
|
/// Returns an iterator to the list of supported present modes.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn iter(&self) -> SupportedPresentModesIter {
|
pub fn iter(&self) -> impl Iterator<Item = PresentMode> {
|
||||||
SupportedPresentModesIter(self.clone())
|
let moved = *self;
|
||||||
}
|
std::array::IntoIter::new([
|
||||||
}
|
PresentMode::Immediate,
|
||||||
|
PresentMode::Mailbox,
|
||||||
/// Enumeration of the `PresentMode`s that are supported.
|
PresentMode::Fifo,
|
||||||
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
|
PresentMode::Relaxed,
|
||||||
pub struct SupportedPresentModesIter(SupportedPresentModes);
|
])
|
||||||
|
.filter(move |&mode| moved.supports(mode))
|
||||||
impl Iterator for SupportedPresentModesIter {
|
|
||||||
type Item = PresentMode;
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn next(&mut self) -> Option<PresentMode> {
|
|
||||||
if self.0.immediate {
|
|
||||||
self.0.immediate = false;
|
|
||||||
return Some(PresentMode::Immediate);
|
|
||||||
}
|
|
||||||
if self.0.mailbox {
|
|
||||||
self.0.mailbox = false;
|
|
||||||
return Some(PresentMode::Mailbox);
|
|
||||||
}
|
|
||||||
if self.0.fifo {
|
|
||||||
self.0.fifo = false;
|
|
||||||
return Some(PresentMode::Fifo);
|
|
||||||
}
|
|
||||||
if self.0.relaxed {
|
|
||||||
self.0.relaxed = false;
|
|
||||||
return Some(PresentMode::Relaxed);
|
|
||||||
}
|
|
||||||
None
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -308,37 +286,15 @@ impl SupportedCompositeAlpha {
|
|||||||
|
|
||||||
/// Returns an iterator to the list of supported composite alpha.
|
/// Returns an iterator to the list of supported composite alpha.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn iter(&self) -> SupportedCompositeAlphaIter {
|
pub fn iter(&self) -> impl Iterator<Item = CompositeAlpha> {
|
||||||
SupportedCompositeAlphaIter(self.clone())
|
let moved = *self;
|
||||||
}
|
std::array::IntoIter::new([
|
||||||
}
|
CompositeAlpha::Opaque,
|
||||||
|
CompositeAlpha::PreMultiplied,
|
||||||
/// Enumeration of the `CompositeAlpha` that are supported.
|
CompositeAlpha::PostMultiplied,
|
||||||
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
|
CompositeAlpha::Inherit,
|
||||||
pub struct SupportedCompositeAlphaIter(SupportedCompositeAlpha);
|
])
|
||||||
|
.filter(move |&mode| moved.supports(mode))
|
||||||
impl Iterator for SupportedCompositeAlphaIter {
|
|
||||||
type Item = CompositeAlpha;
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn next(&mut self) -> Option<CompositeAlpha> {
|
|
||||||
if self.0.opaque {
|
|
||||||
self.0.opaque = false;
|
|
||||||
return Some(CompositeAlpha::Opaque);
|
|
||||||
}
|
|
||||||
if self.0.pre_multiplied {
|
|
||||||
self.0.pre_multiplied = false;
|
|
||||||
return Some(CompositeAlpha::PreMultiplied);
|
|
||||||
}
|
|
||||||
if self.0.post_multiplied {
|
|
||||||
self.0.post_multiplied = false;
|
|
||||||
return Some(CompositeAlpha::PostMultiplied);
|
|
||||||
}
|
|
||||||
if self.0.inherit {
|
|
||||||
self.0.inherit = false;
|
|
||||||
return Some(CompositeAlpha::Inherit);
|
|
||||||
}
|
|
||||||
None
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -460,57 +416,20 @@ impl SupportedSurfaceTransforms {
|
|||||||
|
|
||||||
/// Returns an iterator to the list of supported composite alpha.
|
/// Returns an iterator to the list of supported composite alpha.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn iter(&self) -> SupportedSurfaceTransformsIter {
|
pub fn iter(&self) -> impl Iterator<Item = SurfaceTransform> {
|
||||||
SupportedSurfaceTransformsIter(self.clone())
|
let moved = *self;
|
||||||
}
|
std::array::IntoIter::new([
|
||||||
}
|
SurfaceTransform::Identity,
|
||||||
|
SurfaceTransform::Rotate90,
|
||||||
/// Enumeration of the `SurfaceTransform` that are supported.
|
SurfaceTransform::Rotate180,
|
||||||
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
|
SurfaceTransform::Rotate270,
|
||||||
pub struct SupportedSurfaceTransformsIter(SupportedSurfaceTransforms);
|
SurfaceTransform::HorizontalMirror,
|
||||||
|
SurfaceTransform::HorizontalMirrorRotate90,
|
||||||
impl Iterator for SupportedSurfaceTransformsIter {
|
SurfaceTransform::HorizontalMirrorRotate180,
|
||||||
type Item = SurfaceTransform;
|
SurfaceTransform::HorizontalMirrorRotate270,
|
||||||
|
SurfaceTransform::Inherit,
|
||||||
#[inline]
|
])
|
||||||
fn next(&mut self) -> Option<SurfaceTransform> {
|
.filter(move |&mode| moved.supports(mode))
|
||||||
if self.0.identity {
|
|
||||||
self.0.identity = false;
|
|
||||||
return Some(SurfaceTransform::Identity);
|
|
||||||
}
|
|
||||||
if self.0.rotate90 {
|
|
||||||
self.0.rotate90 = false;
|
|
||||||
return Some(SurfaceTransform::Rotate90);
|
|
||||||
}
|
|
||||||
if self.0.rotate180 {
|
|
||||||
self.0.rotate180 = false;
|
|
||||||
return Some(SurfaceTransform::Rotate180);
|
|
||||||
}
|
|
||||||
if self.0.rotate270 {
|
|
||||||
self.0.rotate270 = false;
|
|
||||||
return Some(SurfaceTransform::Rotate270);
|
|
||||||
}
|
|
||||||
if self.0.horizontal_mirror {
|
|
||||||
self.0.horizontal_mirror = false;
|
|
||||||
return Some(SurfaceTransform::HorizontalMirror);
|
|
||||||
}
|
|
||||||
if self.0.horizontal_mirror_rotate90 {
|
|
||||||
self.0.horizontal_mirror_rotate90 = false;
|
|
||||||
return Some(SurfaceTransform::HorizontalMirrorRotate90);
|
|
||||||
}
|
|
||||||
if self.0.horizontal_mirror_rotate180 {
|
|
||||||
self.0.horizontal_mirror_rotate180 = false;
|
|
||||||
return Some(SurfaceTransform::HorizontalMirrorRotate180);
|
|
||||||
}
|
|
||||||
if self.0.horizontal_mirror_rotate270 {
|
|
||||||
self.0.horizontal_mirror_rotate270 = false;
|
|
||||||
return Some(SurfaceTransform::HorizontalMirrorRotate270);
|
|
||||||
}
|
|
||||||
if self.0.inherit {
|
|
||||||
self.0.inherit = false;
|
|
||||||
return Some(SurfaceTransform::Inherit);
|
|
||||||
}
|
|
||||||
None
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -296,18 +296,13 @@
|
|||||||
//! ```
|
//! ```
|
||||||
//!
|
//!
|
||||||
|
|
||||||
use std::sync::atomic::AtomicBool;
|
|
||||||
|
|
||||||
pub use self::capabilities::Capabilities;
|
pub use self::capabilities::Capabilities;
|
||||||
pub use self::capabilities::ColorSpace;
|
pub use self::capabilities::ColorSpace;
|
||||||
pub use self::capabilities::CompositeAlpha;
|
pub use self::capabilities::CompositeAlpha;
|
||||||
pub use self::capabilities::PresentMode;
|
pub use self::capabilities::PresentMode;
|
||||||
pub use self::capabilities::SupportedCompositeAlpha;
|
pub use self::capabilities::SupportedCompositeAlpha;
|
||||||
pub use self::capabilities::SupportedCompositeAlphaIter;
|
|
||||||
pub use self::capabilities::SupportedPresentModes;
|
pub use self::capabilities::SupportedPresentModes;
|
||||||
pub use self::capabilities::SupportedPresentModesIter;
|
|
||||||
pub use self::capabilities::SupportedSurfaceTransforms;
|
pub use self::capabilities::SupportedSurfaceTransforms;
|
||||||
pub use self::capabilities::SupportedSurfaceTransformsIter;
|
|
||||||
pub use self::capabilities::SurfaceTransform;
|
pub use self::capabilities::SurfaceTransform;
|
||||||
pub use self::present_region::PresentRegion;
|
pub use self::present_region::PresentRegion;
|
||||||
pub use self::present_region::RectangleLayer;
|
pub use self::present_region::RectangleLayer;
|
||||||
@ -327,6 +322,7 @@ pub use self::swapchain::Swapchain;
|
|||||||
pub use self::swapchain::SwapchainAcquireFuture;
|
pub use self::swapchain::SwapchainAcquireFuture;
|
||||||
pub use self::swapchain::SwapchainBuilder;
|
pub use self::swapchain::SwapchainBuilder;
|
||||||
pub use self::swapchain::SwapchainCreationError;
|
pub use self::swapchain::SwapchainCreationError;
|
||||||
|
use std::sync::atomic::AtomicBool;
|
||||||
|
|
||||||
mod capabilities;
|
mod capabilities;
|
||||||
pub mod display;
|
pub mod display;
|
||||||
|
@ -164,7 +164,7 @@ impl<'a> From<&'a [&'a Arc<Queue>]> for SharingMode {
|
|||||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
pub enum Sharing<I>
|
pub enum Sharing<I>
|
||||||
where
|
where
|
||||||
I: Iterator<Item = u32>,
|
I: IntoIterator<Item = u32>,
|
||||||
{
|
{
|
||||||
/// The resource is used is only one queue family.
|
/// The resource is used is only one queue family.
|
||||||
Exclusive,
|
Exclusive,
|
||||||
|
Loading…
Reference in New Issue
Block a user