diff --git a/.rustfmt.toml b/.rustfmt.toml new file mode 100644 index 00000000..3535f354 --- /dev/null +++ b/.rustfmt.toml @@ -0,0 +1,2 @@ +# imports_granularity = "Crate" +# group_imports = "One" diff --git a/vulkano/src/buffer/cpu_access.rs b/vulkano/src/buffer/cpu_access.rs index 7c7bf79c..53c12b03 100644 --- a/vulkano/src/buffer/cpu_access.rs +++ b/vulkano/src/buffer/cpu_access.rs @@ -25,7 +25,7 @@ use crate::{ memory::{ pool::{ AllocFromRequirementsFilter, AllocLayout, MappingRequirement, MemoryPoolAlloc, - PotentialDedicatedAllocation, StdMemoryPoolAlloc, + PotentialDedicatedAllocation, StandardMemoryPoolAlloc, }, DedicatedAllocation, DeviceMemoryAllocationError, MemoryPool, }, @@ -50,7 +50,7 @@ use std::{ /// memory caches GPU data on the CPU side. This can be more performant in cases where /// the cpu needs to read data coming off the GPU. #[derive(Debug)] -pub struct CpuAccessibleBuffer> +pub struct CpuAccessibleBuffer> where T: BufferContents + ?Sized, { @@ -252,7 +252,7 @@ where let mem_reqs = buffer.memory_requirements(); let memory = MemoryPool::alloc_from_requirements( - &Device::standard_pool(&device), + &device.standard_memory_pool(), &mem_reqs, AllocLayout::Linear, MappingRequirement::Map, diff --git a/vulkano/src/buffer/cpu_pool.rs b/vulkano/src/buffer/cpu_pool.rs index 8a0cb98e..b9f492ce 100644 --- a/vulkano/src/buffer/cpu_pool.rs +++ b/vulkano/src/buffer/cpu_pool.rs @@ -17,7 +17,7 @@ use crate::{ memory::{ pool::{ AllocFromRequirementsFilter, AllocLayout, MappingRequirement, MemoryPoolAlloc, - PotentialDedicatedAllocation, StdMemoryPool, + PotentialDedicatedAllocation, StandardMemoryPool, }, DedicatedAllocation, DeviceMemoryAllocationError, MemoryPool, }, @@ -91,7 +91,7 @@ use std::{ /// } /// ``` /// -pub struct CpuBufferPool> +pub struct CpuBufferPool> where [T]: BufferContents, A: MemoryPool, @@ -196,11 +196,11 @@ where #[inline] pub fn new(device: Arc, usage: BufferUsage) -> CpuBufferPool { assert!(size_of::() > 0); - let pool = Device::standard_pool(&device); + let pool = device.standard_memory_pool(); CpuBufferPool { - device: device, - pool: pool, + device, + pool, current_buffer: Mutex::new(None), usage: usage.clone(), marker: PhantomData, diff --git a/vulkano/src/buffer/device_local.rs b/vulkano/src/buffer/device_local.rs index 12089421..d08aaf56 100644 --- a/vulkano/src/buffer/device_local.rs +++ b/vulkano/src/buffer/device_local.rs @@ -28,7 +28,8 @@ use crate::{ memory::{ pool::{ alloc_dedicated_with_exportable_fd, AllocFromRequirementsFilter, AllocLayout, - MappingRequirement, MemoryPoolAlloc, PotentialDedicatedAllocation, StdMemoryPoolAlloc, + MappingRequirement, MemoryPoolAlloc, PotentialDedicatedAllocation, + StandardMemoryPoolAlloc, }, DedicatedAllocation, DeviceMemoryAllocationError, DeviceMemoryExportError, ExternalMemoryHandleType, MemoryPool, MemoryRequirements, @@ -122,7 +123,7 @@ use std::{ /// ``` /// #[derive(Debug)] -pub struct DeviceLocalBuffer> +pub struct DeviceLocalBuffer> where T: BufferContents + ?Sized, { @@ -358,7 +359,7 @@ where let (buffer, mem_reqs) = Self::build_buffer(&device, size, usage, &queue_families)?; let memory = MemoryPool::alloc_from_requirements( - &Device::standard_pool(&device), + &device.standard_memory_pool(), &mem_reqs, AllocLayout::Linear, MappingRequirement::DoNotMap, diff --git a/vulkano/src/buffer/sys.rs b/vulkano/src/buffer/sys.rs index b9f4259b..b73ea636 100644 --- a/vulkano/src/buffer/sys.rs +++ b/vulkano/src/buffer/sys.rs @@ -28,11 +28,11 @@ use super::{ cpu_access::{ReadLockError, WriteLockError}, BufferUsage, }; -use crate::range_map::RangeMap; use crate::{ check_errors, device::{Device, DeviceOwned}, memory::{DeviceMemory, DeviceMemoryAllocationError, MemoryRequirements}, + range_map::RangeMap, sync::{AccessError, CurrentAccess, Sharing}, DeviceSize, Error, OomError, Version, VulkanObject, }; @@ -782,13 +782,10 @@ struct BufferRangeState { #[cfg(test)] mod tests { - use super::BufferCreationError; - use super::BufferUsage; - use super::SparseLevel; - use super::UnsafeBuffer; - use super::UnsafeBufferCreateInfo; - use crate::device::Device; - use crate::device::DeviceOwned; + use super::{ + BufferCreationError, BufferUsage, SparseLevel, UnsafeBuffer, UnsafeBufferCreateInfo, + }; + use crate::device::{Device, DeviceOwned}; #[test] fn create() { diff --git a/vulkano/src/buffer/view.rs b/vulkano/src/buffer/view.rs index dff98e73..aef39763 100644 --- a/vulkano/src/buffer/view.rs +++ b/vulkano/src/buffer/view.rs @@ -462,9 +462,13 @@ impl Hash for dyn BufferViewAbstract { #[cfg(test)] mod tests { - use crate::buffer::view::{BufferView, BufferViewCreateInfo, BufferViewCreationError}; - use crate::buffer::{BufferUsage, DeviceLocalBuffer}; - use crate::format::Format; + use crate::{ + buffer::{ + view::{BufferView, BufferViewCreateInfo, BufferViewCreationError}, + BufferUsage, DeviceLocalBuffer, + }, + format::Format, + }; #[test] fn create_uniform() { diff --git a/vulkano/src/command_buffer/auto.rs b/vulkano/src/command_buffer/auto.rs index fc2315b8..f5501d88 100644 --- a/vulkano/src/command_buffer/auto.rs +++ b/vulkano/src/command_buffer/auto.rs @@ -233,22 +233,25 @@ impl AutoCommandBufferBuilder { } } - let pool_builder_alloc = Device::standard_command_pool(&device, queue_family)? - .allocate(level, 1)? - .next() - .expect("Requested one command buffer from the command pool, but got zero."); - let inner = SyncCommandBufferBuilder::new(pool_builder_alloc.inner(), begin_info)?; + device.with_standard_command_pool(queue_family, |pool| { + let pool_builder_alloc = pool + .allocate(level, 1)? + .next() + .expect("Requested one command buffer from the command pool, but got zero."); - Ok(AutoCommandBufferBuilder { - inner, - pool_builder_alloc, - queue_family_id: queue_family.id(), - render_pass_state, - query_state: HashMap::default(), - inheritance_info, - usage, - _data: PhantomData, - }) + let inner = SyncCommandBufferBuilder::new(pool_builder_alloc.inner(), begin_info)?; + + Ok(AutoCommandBufferBuilder { + inner, + pool_builder_alloc, + queue_family_id: queue_family.id(), + render_pass_state, + query_state: HashMap::default(), + inheritance_info, + usage, + _data: PhantomData, + }) + })? } fn validate_begin( diff --git a/vulkano/src/command_buffer/mod.rs b/vulkano/src/command_buffer/mod.rs index b49b9274..595ff58b 100644 --- a/vulkano/src/command_buffer/mod.rs +++ b/vulkano/src/command_buffer/mod.rs @@ -89,29 +89,6 @@ //! alternative command pool implementations and use them. See the `pool` module for more //! information. -pub use self::commands::{ - debug::DebugUtilsError, - image::{ - BlitImageInfo, ClearColorImageInfo, ClearDepthStencilImageInfo, ImageBlit, ImageResolve, - ResolveImageInfo, - }, - pipeline::{ - CheckDescriptorSetsValidityError, CheckDispatchError, CheckDynamicStateValidityError, - CheckIndexBufferError, CheckIndirectBufferError, CheckPipelineError, - CheckPushConstantsValidityError, CheckVertexBufferError, - }, - query::QueryError, - render_pass::{ - ClearAttachment, ClearRect, RenderPassBeginInfo, RenderPassError, RenderingAttachmentInfo, - RenderingAttachmentResolveInfo, RenderingInfo, - }, - secondary::{ExecuteCommandsError, UnsafeCommandBufferBuilderExecuteCommands}, - transfer::{ - BufferCopy, BufferImageCopy, CopyBufferInfo, CopyBufferInfoTyped, CopyBufferToImageInfo, - CopyImageInfo, CopyImageToBufferInfo, FillBufferInfo, ImageCopy, - }, - CopyError, CopyErrorResource, -}; pub use self::{ auto::{ AutoCommandBufferBuilder, AutoCommandBufferBuilderContextError, BuildError, @@ -119,6 +96,29 @@ pub use self::{ DrawIndexedIndirectError, DrawIndirectError, PrimaryAutoCommandBuffer, SecondaryAutoCommandBuffer, }, + commands::{ + debug::DebugUtilsError, + image::{ + BlitImageInfo, ClearColorImageInfo, ClearDepthStencilImageInfo, ImageBlit, + ImageResolve, ResolveImageInfo, + }, + pipeline::{ + CheckDescriptorSetsValidityError, CheckDispatchError, CheckDynamicStateValidityError, + CheckIndexBufferError, CheckIndirectBufferError, CheckPipelineError, + CheckPushConstantsValidityError, CheckVertexBufferError, + }, + query::QueryError, + render_pass::{ + ClearAttachment, ClearRect, RenderPassBeginInfo, RenderPassError, + RenderingAttachmentInfo, RenderingAttachmentResolveInfo, RenderingInfo, + }, + secondary::{ExecuteCommandsError, UnsafeCommandBufferBuilderExecuteCommands}, + transfer::{ + BufferCopy, BufferImageCopy, CopyBufferInfo, CopyBufferInfoTyped, + CopyBufferToImageInfo, CopyImageInfo, CopyImageToBufferInfo, FillBufferInfo, ImageCopy, + }, + CopyError, CopyErrorResource, + }, traits::{ CommandBufferExecError, CommandBufferExecFuture, PrimaryCommandBuffer, SecondaryCommandBuffer, diff --git a/vulkano/src/command_buffer/pool/standard.rs b/vulkano/src/command_buffer/pool/standard.rs index f660f7ed..4cdcceb1 100644 --- a/vulkano/src/command_buffer/pool/standard.rs +++ b/vulkano/src/command_buffer/pool/standard.rs @@ -228,34 +228,37 @@ impl Drop for StandardCommandPoolAlloc { #[cfg(test)] mod tests { - use std::sync::Arc; - use std::thread; - - use crate::command_buffer::pool::{CommandPool, CommandPoolBuilderAlloc}; - use crate::command_buffer::CommandBufferLevel; - use crate::device::Device; - use crate::VulkanObject; + use crate::{ + command_buffer::{ + pool::{CommandPool, CommandPoolBuilderAlloc}, + CommandBufferLevel, + }, + VulkanObject, + }; + use std::{sync::Arc, thread}; #[test] fn reuse_command_buffers() { let (device, queue) = gfx_dev_and_queue!(); - let pool = Device::standard_command_pool(&device, queue.family()).unwrap(); + device + .with_standard_command_pool(queue.family(), |pool| { + let cb = pool + .allocate(CommandBufferLevel::Primary, 1) + .unwrap() + .next() + .unwrap(); + let raw = cb.inner().internal_object(); + drop(cb); - let cb = pool - .allocate(CommandBufferLevel::Primary, 1) - .unwrap() - .next() + let cb2 = pool + .allocate(CommandBufferLevel::Primary, 1) + .unwrap() + .next() + .unwrap(); + assert_eq!(raw, cb2.inner().internal_object()); + }) .unwrap(); - let raw = cb.inner().internal_object(); - drop(cb); - - let cb2 = pool - .allocate(CommandBufferLevel::Primary, 1) - .unwrap() - .next() - .unwrap(); - assert_eq!(raw, cb2.inner().internal_object()); } #[test] @@ -265,13 +268,15 @@ mod tests { let thread = thread::spawn({ let (device, queue) = (device.clone(), queue.clone()); move || { - let pool = Device::standard_command_pool(&device, queue.family()).unwrap(); - - pool.allocate(CommandBufferLevel::Primary, 1) + device + .with_standard_command_pool(queue.family(), |pool| { + pool.allocate(CommandBufferLevel::Primary, 1) + .unwrap() + .next() + .unwrap() + .inner + }) .unwrap() - .next() - .unwrap() - .inner } }); diff --git a/vulkano/src/command_buffer/submit/bind_sparse.rs b/vulkano/src/command_buffer/submit/bind_sparse.rs index 5e3c4e27..a2e9b50d 100644 --- a/vulkano/src/command_buffer/submit/bind_sparse.rs +++ b/vulkano/src/command_buffer/submit/bind_sparse.rs @@ -7,22 +7,17 @@ // notice may not be copied, modified, or distributed except // according to those terms. -use crate::buffer::sys::UnsafeBuffer; -use crate::check_errors; -use crate::device::Queue; -use crate::image::sys::UnsafeImage; -use crate::memory::DeviceMemory; -use crate::sync::Fence; -use crate::sync::Semaphore; -use crate::DeviceSize; -use crate::Error; -use crate::OomError; -use crate::SynchronizedVulkanObject; -use crate::VulkanObject; +use crate::{ + buffer::sys::UnsafeBuffer, + check_errors, + device::Queue, + image::sys::UnsafeImage, + memory::DeviceMemory, + sync::{Fence, Semaphore}, + DeviceSize, Error, OomError, SynchronizedVulkanObject, VulkanObject, +}; use smallvec::SmallVec; -use std::error; -use std::fmt; -use std::marker::PhantomData; +use std::{error, fmt, marker::PhantomData}; // TODO: correctly implement Debug on all the structs of this module diff --git a/vulkano/src/command_buffer/submit/mod.rs b/vulkano/src/command_buffer/submit/mod.rs index 53c0d4b8..13d86cc0 100644 --- a/vulkano/src/command_buffer/submit/mod.rs +++ b/vulkano/src/command_buffer/submit/mod.rs @@ -13,17 +13,16 @@ //! module. These structs are low-level and unsafe, and are mostly used to implement other parts //! of vulkano, so you are encouraged to not use them directly. -pub use self::bind_sparse::SubmitBindSparseBatchBuilder; -pub use self::bind_sparse::SubmitBindSparseBufferBindBuilder; -pub use self::bind_sparse::SubmitBindSparseBuilder; -pub use self::bind_sparse::SubmitBindSparseError; -pub use self::bind_sparse::SubmitBindSparseImageBindBuilder; -pub use self::bind_sparse::SubmitBindSparseImageOpaqueBindBuilder; -pub use self::queue_present::SubmitPresentBuilder; -pub use self::queue_present::SubmitPresentError; -pub use self::queue_submit::SubmitCommandBufferBuilder; -pub use self::queue_submit::SubmitCommandBufferError; -pub use self::semaphores_wait::SubmitSemaphoresWaitBuilder; +pub use self::{ + bind_sparse::{ + SubmitBindSparseBatchBuilder, SubmitBindSparseBufferBindBuilder, SubmitBindSparseBuilder, + SubmitBindSparseError, SubmitBindSparseImageBindBuilder, + SubmitBindSparseImageOpaqueBindBuilder, + }, + queue_present::{SubmitPresentBuilder, SubmitPresentError}, + queue_submit::{SubmitCommandBufferBuilder, SubmitCommandBufferError}, + semaphores_wait::SubmitSemaphoresWaitBuilder, +}; mod bind_sparse; mod queue_present; diff --git a/vulkano/src/command_buffer/submit/queue_present.rs b/vulkano/src/command_buffer/submit/queue_present.rs index 06c525ee..39a42f76 100644 --- a/vulkano/src/command_buffer/submit/queue_present.rs +++ b/vulkano/src/command_buffer/submit/queue_present.rs @@ -7,23 +7,15 @@ // notice may not be copied, modified, or distributed except // according to those terms. +use crate::{ + check_errors, + device::{DeviceOwned, Queue}, + swapchain::{PresentRegion, Swapchain}, + sync::Semaphore, + Error, OomError, SynchronizedVulkanObject, VulkanObject, +}; use smallvec::SmallVec; -use std::error; -use std::fmt; -use std::marker::PhantomData; -use std::ptr; - -use crate::device::DeviceOwned; -use crate::device::Queue; -use crate::swapchain::PresentRegion; -use crate::swapchain::Swapchain; -use crate::sync::Semaphore; - -use crate::check_errors; -use crate::Error; -use crate::OomError; -use crate::SynchronizedVulkanObject; -use crate::VulkanObject; +use std::{error, fmt, marker::PhantomData, ptr}; /// Prototype for a submission that presents a swapchain on the screen. // TODO: example here diff --git a/vulkano/src/command_buffer/submit/queue_submit.rs b/vulkano/src/command_buffer/submit/queue_submit.rs index ee0f84e6..69e120e1 100644 --- a/vulkano/src/command_buffer/submit/queue_submit.rs +++ b/vulkano/src/command_buffer/submit/queue_submit.rs @@ -7,20 +7,15 @@ // notice may not be copied, modified, or distributed except // according to those terms. -use crate::check_errors; -use crate::command_buffer::sys::UnsafeCommandBuffer; -use crate::device::Queue; -use crate::sync::Fence; -use crate::sync::PipelineStages; -use crate::sync::Semaphore; -use crate::Error; -use crate::OomError; -use crate::SynchronizedVulkanObject; -use crate::VulkanObject; +use crate::{ + check_errors, + command_buffer::sys::UnsafeCommandBuffer, + device::Queue, + sync::{Fence, PipelineStages, Semaphore}, + Error, OomError, SynchronizedVulkanObject, VulkanObject, +}; use smallvec::SmallVec; -use std::error; -use std::fmt; -use std::marker::PhantomData; +use std::{error, fmt, marker::PhantomData}; /// Prototype for a submission that executes command buffers. // TODO: example here diff --git a/vulkano/src/command_buffer/submit/semaphores_wait.rs b/vulkano/src/command_buffer/submit/semaphores_wait.rs index 2ebcfed4..425466c8 100644 --- a/vulkano/src/command_buffer/submit/semaphores_wait.rs +++ b/vulkano/src/command_buffer/submit/semaphores_wait.rs @@ -7,13 +7,12 @@ // notice may not be copied, modified, or distributed except // according to those terms. +use crate::{ + command_buffer::submit::{SubmitCommandBufferBuilder, SubmitPresentBuilder}, + sync::{PipelineStages, Semaphore}, +}; use smallvec::SmallVec; -use crate::command_buffer::submit::SubmitCommandBufferBuilder; -use crate::command_buffer::submit::SubmitPresentBuilder; -use crate::sync::PipelineStages; -use crate::sync::Semaphore; - /// Prototype for a submission that waits on semaphores. /// /// This prototype can't actually be submitted because it doesn't correspond to anything in Vulkan. diff --git a/vulkano/src/command_buffer/synced/builder.rs b/vulkano/src/command_buffer/synced/builder.rs index 7faefe7c..e84b9cc1 100644 --- a/vulkano/src/command_buffer/synced/builder.rs +++ b/vulkano/src/command_buffer/synced/builder.rs @@ -14,7 +14,6 @@ pub use crate::command_buffer::commands::{ }, secondary::SyncCommandBufferBuilderExecuteCommands, }; -use crate::range_map::RangeMap; use crate::{ buffer::{sys::UnsafeBuffer, BufferAccess}, command_buffer::{ @@ -36,6 +35,7 @@ use crate::{ }, ComputePipeline, DynamicState, GraphicsPipeline, PipelineBindPoint, PipelineLayout, }, + range_map::RangeMap, range_set::RangeSet, sync::{ AccessFlags, BufferMemoryBarrier, DependencyInfo, ImageMemoryBarrier, PipelineMemoryAccess, diff --git a/vulkano/src/command_buffer/synced/mod.rs b/vulkano/src/command_buffer/synced/mod.rs index 27ae2ce4..b3490e5c 100644 --- a/vulkano/src/command_buffer/synced/mod.rs +++ b/vulkano/src/command_buffer/synced/mod.rs @@ -74,11 +74,11 @@ use super::{ sys::{UnsafeCommandBuffer, UnsafeCommandBufferBuilder}, CommandBufferExecError, }; -use crate::range_map::RangeMap; use crate::{ buffer::{sys::UnsafeBuffer, BufferAccess}, device::{Device, DeviceOwned, Queue}, image::{sys::UnsafeImage, ImageAccess, ImageLayout, ImageSubresourceRange}, + range_map::RangeMap, sync::{ AccessCheckError, AccessError, AccessFlags, GpuFuture, PipelineMemoryAccess, PipelineStages, }, @@ -546,11 +546,13 @@ mod tests { unsafe { let (device, queue) = gfx_dev_and_queue!(); - let pool = Device::standard_command_pool(&device, queue.family()).unwrap(); - let pool_builder_alloc = pool - .allocate(CommandBufferLevel::Primary, 1) - .unwrap() - .next() + let pool_builder_alloc = device + .with_standard_command_pool(queue.family(), |pool| { + pool.allocate(CommandBufferLevel::Primary, 1) + .unwrap() + .next() + .unwrap() + }) .unwrap(); SyncCommandBufferBuilder::new( @@ -599,11 +601,13 @@ mod tests { }) .collect::>(); - let pool = Device::standard_command_pool(&device, queue.family()).unwrap(); - let allocs = pool - .allocate(CommandBufferLevel::Primary, 2) - .unwrap() - .collect::>(); + let allocs = device + .with_standard_command_pool(queue.family(), |pool| { + pool.allocate(CommandBufferLevel::Primary, 2) + .unwrap() + .collect::>() + }) + .unwrap(); { let mut builder = SyncCommandBufferBuilder::new( @@ -659,11 +663,13 @@ mod tests { unsafe { let (device, queue) = gfx_dev_and_queue!(); - let pool = Device::standard_command_pool(&device, queue.family()).unwrap(); - let pool_builder_alloc = pool - .allocate(CommandBufferLevel::Primary, 1) - .unwrap() - .next() + let pool_builder_alloc = device + .with_standard_command_pool(queue.family(), |pool| { + pool.allocate(CommandBufferLevel::Primary, 1) + .unwrap() + .next() + .unwrap() + }) .unwrap(); let mut sync = SyncCommandBufferBuilder::new( &pool_builder_alloc.inner(), @@ -690,11 +696,13 @@ mod tests { unsafe { let (device, queue) = gfx_dev_and_queue!(); - let pool = Device::standard_command_pool(&device, queue.family()).unwrap(); - let pool_builder_alloc = pool - .allocate(CommandBufferLevel::Primary, 1) - .unwrap() - .next() + let pool_builder_alloc = device + .with_standard_command_pool(queue.family(), |pool| { + pool.allocate(CommandBufferLevel::Primary, 1) + .unwrap() + .next() + .unwrap() + }) .unwrap(); let mut sync = SyncCommandBufferBuilder::new( &pool_builder_alloc.inner(), diff --git a/vulkano/src/descriptor_set/layout.rs b/vulkano/src/descriptor_set/layout.rs index eabb5077..6113ba6e 100644 --- a/vulkano/src/descriptor_set/layout.rs +++ b/vulkano/src/descriptor_set/layout.rs @@ -848,11 +848,13 @@ impl From for ash::vk::DescriptorType { #[cfg(test)] mod tests { - use crate::descriptor_set::layout::DescriptorSetLayout; - use crate::descriptor_set::layout::DescriptorSetLayoutBinding; - use crate::descriptor_set::layout::DescriptorSetLayoutCreateInfo; - use crate::descriptor_set::layout::DescriptorType; - use crate::shader::ShaderStages; + use crate::{ + descriptor_set::layout::{ + DescriptorSetLayout, DescriptorSetLayoutBinding, DescriptorSetLayoutCreateInfo, + DescriptorType, + }, + shader::ShaderStages, + }; use std::collections::HashMap; #[test] diff --git a/vulkano/src/descriptor_set/mod.rs b/vulkano/src/descriptor_set/mod.rs index 0ba574ac..4220a018 100644 --- a/vulkano/src/descriptor_set/mod.rs +++ b/vulkano/src/descriptor_set/mod.rs @@ -65,7 +65,7 @@ //! - The `DescriptorPool` trait can be implemented on types from which you can allocate and free //! descriptor sets. However it is different from Vulkan descriptor pools in the sense that an //! implementation of the `DescriptorPool` trait can manage multiple Vulkan descriptor pools. -//! - The `StdDescriptorPool` type is a default implementation of the `DescriptorPool` trait. +//! - The `StandardDescriptorPool` type is a default implementation of the `DescriptorPool` trait. //! - The `DescriptorSet` trait is implemented on types that wrap around Vulkan descriptor sets in //! a safe way. A Vulkan descriptor set is inherently unsafe, so we need safe wrappers around //! them. @@ -73,27 +73,29 @@ //! - The `DescriptorSetsCollection` trait is implemented on collections of types that implement //! `DescriptorSet`. It is what you pass to the draw functions. -pub use self::collection::DescriptorSetsCollection; -use self::layout::DescriptorSetLayout; -pub use self::persistent::PersistentDescriptorSet; -pub use self::single_layout_pool::SingleLayoutDescSetPool; -use self::sys::UnsafeDescriptorSet; pub(crate) use self::update::{check_descriptor_write, DescriptorWriteInfo}; -pub use self::update::{DescriptorSetUpdateError, WriteDescriptorSet, WriteDescriptorSetElements}; -use crate::buffer::view::BufferViewAbstract; -use crate::buffer::BufferAccess; -use crate::descriptor_set::layout::DescriptorType; -use crate::device::DeviceOwned; -use crate::image::view::ImageViewAbstract; -use crate::sampler::Sampler; -use crate::OomError; -use crate::VulkanObject; +pub use self::{ + collection::DescriptorSetsCollection, + persistent::PersistentDescriptorSet, + single_layout_pool::SingleLayoutDescSetPool, + update::{DescriptorSetUpdateError, WriteDescriptorSet, WriteDescriptorSetElements}, +}; +use self::{layout::DescriptorSetLayout, sys::UnsafeDescriptorSet}; +use crate::{ + buffer::{view::BufferViewAbstract, BufferAccess}, + descriptor_set::layout::DescriptorType, + device::DeviceOwned, + image::view::ImageViewAbstract, + sampler::Sampler, + OomError, VulkanObject, +}; use smallvec::{smallvec, SmallVec}; -use std::collections::HashMap; -use std::hash::Hash; -use std::hash::Hasher; -use std::ptr; -use std::sync::Arc; +use std::{ + collections::HashMap, + hash::{Hash, Hasher}, + ptr, + sync::Arc, +}; mod collection; pub mod layout; diff --git a/vulkano/src/descriptor_set/persistent.rs b/vulkano/src/descriptor_set/persistent.rs index 0b084466..85f66a1e 100644 --- a/vulkano/src/descriptor_set/persistent.rs +++ b/vulkano/src/descriptor_set/persistent.rs @@ -21,20 +21,23 @@ //! # Example //! TODO: -use crate::descriptor_set::pool::standard::StdDescriptorPoolAlloc; -use crate::descriptor_set::pool::{DescriptorPool, DescriptorPoolAlloc}; -use crate::descriptor_set::update::WriteDescriptorSet; -use crate::descriptor_set::{ - DescriptorSet, DescriptorSetCreationError, DescriptorSetInner, DescriptorSetLayout, - DescriptorSetResources, UnsafeDescriptorSet, +use crate::{ + descriptor_set::{ + pool::{standard::StandardDescriptorPoolAlloc, DescriptorPool, DescriptorPoolAlloc}, + update::WriteDescriptorSet, + DescriptorSet, DescriptorSetCreationError, DescriptorSetInner, DescriptorSetLayout, + DescriptorSetResources, UnsafeDescriptorSet, + }, + device::{Device, DeviceOwned}, + VulkanObject, +}; +use std::{ + hash::{Hash, Hasher}, + sync::Arc, }; -use crate::device::{Device, DeviceOwned}; -use crate::VulkanObject; -use std::hash::{Hash, Hasher}; -use std::sync::Arc; /// A simple, immutable descriptor set that is expected to be long-lived. -pub struct PersistentDescriptorSet

{ +pub struct PersistentDescriptorSet

{ alloc: P, inner: DescriptorSetInner, } diff --git a/vulkano/src/descriptor_set/pool/mod.rs b/vulkano/src/descriptor_set/pool/mod.rs index 26b13c9c..cda4cce8 100644 --- a/vulkano/src/descriptor_set/pool/mod.rs +++ b/vulkano/src/descriptor_set/pool/mod.rs @@ -10,7 +10,7 @@ //! A pool from which descriptor sets can be allocated. pub use self::{ - standard::StdDescriptorPool, + standard::StandardDescriptorPool, sys::{ DescriptorPoolAllocError, DescriptorSetAllocateInfo, UnsafeDescriptorPool, UnsafeDescriptorPoolCreateInfo, diff --git a/vulkano/src/descriptor_set/pool/standard.rs b/vulkano/src/descriptor_set/pool/standard.rs index 594daabc..6c5524b3 100644 --- a/vulkano/src/descriptor_set/pool/standard.rs +++ b/vulkano/src/descriptor_set/pool/standard.rs @@ -20,15 +20,14 @@ use crate::{ device::{Device, DeviceOwned}, OomError, }; -use std::collections::HashMap; -use std::sync::Arc; +use std::{collections::HashMap, sync::Arc}; /// Standard implementation of a descriptor pool. /// /// Interally, this implementation uses one [`SingleLayoutDescSetPool`] / /// [`SingleLayoutVariableDescSetPool`] per descriptor set layout. #[derive(Debug)] -pub struct StdDescriptorPool { +pub struct StandardDescriptorPool { device: Arc, pools: HashMap, Pool>, } @@ -39,24 +38,24 @@ enum Pool { Variable(SingleLayoutVariableDescSetPool), } -impl StdDescriptorPool { - /// Builds a new `StdDescriptorPool`. - pub fn new(device: Arc) -> StdDescriptorPool { - StdDescriptorPool { +impl StandardDescriptorPool { + /// Builds a new `StandardDescriptorPool`. + pub fn new(device: Arc) -> StandardDescriptorPool { + StandardDescriptorPool { device, pools: HashMap::default(), } } } -unsafe impl DescriptorPool for StdDescriptorPool { - type Alloc = StdDescriptorPoolAlloc; +unsafe impl DescriptorPool for StandardDescriptorPool { + type Alloc = StandardDescriptorPoolAlloc; fn allocate( &mut self, layout: &Arc, variable_descriptor_count: u32, - ) -> Result { + ) -> Result { assert!( !layout.push_descriptor(), "the provided descriptor set layout is for push descriptors, and cannot be used to \ @@ -94,20 +93,20 @@ unsafe impl DescriptorPool for StdDescriptorPool { } }; - Ok(StdDescriptorPoolAlloc { inner }) + Ok(StandardDescriptorPoolAlloc { inner }) } } -unsafe impl DeviceOwned for StdDescriptorPool { +unsafe impl DeviceOwned for StandardDescriptorPool { #[inline] fn device(&self) -> &Arc { &self.device } } -/// A descriptor set allocated from a `StdDescriptorPool`. +/// A descriptor set allocated from a `StandardDescriptorPool`. #[derive(Debug)] -pub struct StdDescriptorPoolAlloc { +pub struct StandardDescriptorPoolAlloc { // The actual descriptor alloc. inner: PoolAlloc, } @@ -118,7 +117,7 @@ enum PoolAlloc { Variable(SingleLayoutVariablePoolAlloc), } -impl DescriptorPoolAlloc for StdDescriptorPoolAlloc { +impl DescriptorPoolAlloc for StandardDescriptorPoolAlloc { #[inline] fn inner(&self) -> &UnsafeDescriptorSet { match &self.inner { diff --git a/vulkano/src/descriptor_set/single_layout_pool.rs b/vulkano/src/descriptor_set/single_layout_pool.rs index 335c1754..590dda2e 100644 --- a/vulkano/src/descriptor_set/single_layout_pool.rs +++ b/vulkano/src/descriptor_set/single_layout_pool.rs @@ -37,9 +37,9 @@ const MAX_POOLS: usize = 32; /// `VkDescriptorPool`. Its function is to provide access to pool(s) to allocate descriptor sets /// from and optimizes for a specific layout which must not have a variable descriptor count. If /// you need a variable descriptor count see [`SingleLayoutVariableDescSetPool`]. For a more general -/// purpose pool see [`StdDescriptorPool`]. +/// purpose pool see [`StandardDescriptorPool`]. /// -/// [`StdDescriptorPool`]: super::pool::standard::StdDescriptorPool +/// [`StandardDescriptorPool`]: super::pool::standard::StandardDescriptorPool #[derive(Debug)] pub struct SingleLayoutDescSetPool { // The `SingleLayoutPool` struct contains an actual Vulkan pool. Every time it is full we create @@ -252,9 +252,9 @@ impl Hash for SingleLayoutDescSet { /// Much like [`SingleLayoutDescSetPool`], except that it allows you to allocate descriptor sets /// with a variable descriptor count. As this has more overhead, you should only use this pool if /// you need the functionality and prefer [`SingleLayoutDescSetPool`] otherwise. For a more general -/// purpose pool see [`StdDescriptorPool`]. +/// purpose pool see [`StandardDescriptorPool`]. /// -/// [`StdDescriptorPool`]: super::pool::standard::StdDescriptorPool +/// [`StandardDescriptorPool`]: super::pool::standard::StandardDescriptorPool #[derive(Debug)] pub struct SingleLayoutVariableDescSetPool { // The `SingleLayoutVariablePool` struct contains an actual Vulkan pool. Every time it is full diff --git a/vulkano/src/descriptor_set/sys.rs b/vulkano/src/descriptor_set/sys.rs index 041b25d2..3ccfa7db 100644 --- a/vulkano/src/descriptor_set/sys.rs +++ b/vulkano/src/descriptor_set/sys.rs @@ -9,13 +9,16 @@ //! Low-level descriptor set. -use crate::descriptor_set::layout::DescriptorSetLayout; -use crate::descriptor_set::update::{DescriptorWriteInfo, WriteDescriptorSet}; -use crate::device::DeviceOwned; -use crate::VulkanObject; +use crate::{ + descriptor_set::{ + layout::DescriptorSetLayout, + update::{DescriptorWriteInfo, WriteDescriptorSet}, + }, + device::DeviceOwned, + VulkanObject, +}; use smallvec::SmallVec; -use std::fmt; -use std::ptr; +use std::{fmt, ptr}; /// Low-level descriptor set. /// diff --git a/vulkano/src/device/extensions.rs b/vulkano/src/device/extensions.rs index e4419e2d..9f84ed43 100644 --- a/vulkano/src/device/extensions.rs +++ b/vulkano/src/device/extensions.rs @@ -8,10 +8,11 @@ // according to those terms. pub use crate::extensions::{ExtensionRestriction, ExtensionRestrictionError, OneOfRequirements}; -use crate::instance::InstanceExtensions; -use crate::Version; -use std::ffi::{CStr, CString}; -use std::fmt::Formatter; +use crate::{instance::InstanceExtensions, Version}; +use std::{ + ffi::{CStr, CString}, + fmt::Formatter, +}; // Generated by build.rs include!(concat!(env!("OUT_DIR"), "/device_extensions.rs")); diff --git a/vulkano/src/device/features.rs b/vulkano/src/device/features.rs index 8866a482..e3c34dcc 100644 --- a/vulkano/src/device/features.rs +++ b/vulkano/src/device/features.rs @@ -7,11 +7,8 @@ // notice may not be copied, modified, or distributed except // according to those terms. -use crate::device::DeviceExtensions; -use crate::instance::InstanceExtensions; -use crate::Version; -use std::error; -use std::fmt; +use crate::{device::DeviceExtensions, instance::InstanceExtensions, Version}; +use std::{error, fmt}; // Generated by build.rs include!(concat!(env!("OUT_DIR"), "/features.rs")); diff --git a/vulkano/src/device/mod.rs b/vulkano/src/device/mod.rs index 376e2b05..a96613b2 100644 --- a/vulkano/src/device/mod.rs +++ b/vulkano/src/device/mod.rs @@ -105,9 +105,9 @@ pub use self::{ use crate::{ check_errors, command_buffer::pool::StandardCommandPool, - descriptor_set::pool::StdDescriptorPool, + descriptor_set::pool::StandardDescriptorPool, instance::{debug::DebugUtilsLabel, Instance}, - memory::{pool::StdMemoryPool, ExternalMemoryHandleType}, + memory::{pool::StandardMemoryPool, ExternalMemoryHandleType}, Error, OomError, SynchronizedVulkanObject, Version, VulkanObject, }; pub use crate::{ @@ -148,7 +148,7 @@ pub struct Device { api_version: Version, fns: DeviceFunctions, - standard_pool: Mutex>, + standard_pool: Mutex>, enabled_extensions: DeviceExtensions, enabled_features: Features, active_queue_families: SmallVec<[u32; 2]>, @@ -505,15 +505,15 @@ impl Device { } /// Returns the standard memory pool used by default if you don't provide any other pool. - pub fn standard_pool(me: &Arc) -> Arc { - let mut pool = me.standard_pool.lock().unwrap(); + pub fn standard_memory_pool(self: &Arc) -> Arc { + let mut pool = self.standard_pool.lock().unwrap(); if let Some(p) = pool.upgrade() { return p; } // The weak pointer is empty, so we create the pool. - let new_pool = StdMemoryPool::new(me.clone()); + let new_pool = StandardMemoryPool::new(self.clone()); *pool = Arc::downgrade(&new_pool); new_pool } @@ -529,11 +529,11 @@ impl Device { /// /// - Panics if called again from within the callback. pub fn with_standard_descriptor_pool( - self: &Arc, - f: impl FnOnce(&mut StdDescriptorPool) -> T, + self: &Arc, + f: impl FnOnce(&mut StandardDescriptorPool) -> T, ) -> T { thread_local! { - static TLS: RefCell> = + static TLS: RefCell> = RefCell::new(HashMap::default()); } @@ -541,15 +541,15 @@ impl Device { let mut tls = tls.borrow_mut(); let pool = match tls.entry(self.internal_object()) { Entry::Occupied(entry) => entry.into_mut(), - Entry::Vacant(entry) => entry.insert(StdDescriptorPool::new(self.clone())), + Entry::Vacant(entry) => entry.insert(StandardDescriptorPool::new(self.clone())), }; f(pool) }) } - /// Returns the standard command buffer pool used by default if you don't provide any other - /// pool. + /// Gives you access to the standard command buffer pool used by default if you don't provide + /// any other pool. /// /// Pools are stored in thread-local storage to avoid locks, which means that a pool is only /// dropped once both the thread exits and all command buffers allocated from it are dropped. @@ -559,10 +559,12 @@ impl Device { /// # Panics /// /// - Panics if the device and the queue family don't belong to the same physical device. - pub fn standard_command_pool( - me: &Arc, + /// - Panics if called again from within the callback. + pub fn with_standard_command_pool( + self: &Arc, queue_family: QueueFamily, - ) -> Result, OomError> { + f: impl FnOnce(&Arc) -> T, + ) -> Result { thread_local! { static TLS: RefCell>> = RefCell::new(Default::default()); @@ -570,15 +572,15 @@ impl Device { TLS.with(|tls| { let mut tls = tls.borrow_mut(); - let per_family = match tls.entry((me.internal_object(), queue_family.id())) { + let pool = match tls.entry((self.internal_object(), queue_family.id())) { Entry::Occupied(entry) => entry.into_mut(), Entry::Vacant(entry) => entry.insert(Arc::new(StandardCommandPool::new( - me.clone(), + self.clone(), queue_family, )?)), }; - Ok(per_family.clone()) + Ok(f(pool)) }) } @@ -1222,9 +1224,10 @@ impl fmt::Display for DebugUtilsError { #[cfg(test)] mod tests { - use crate::device::physical::PhysicalDevice; - use crate::device::{Device, DeviceCreateInfo, DeviceCreationError, QueueCreateInfo}; - use crate::device::{FeatureRestriction, FeatureRestrictionError, Features}; + use crate::device::{ + physical::PhysicalDevice, Device, DeviceCreateInfo, DeviceCreationError, + FeatureRestriction, FeatureRestrictionError, Features, QueueCreateInfo, + }; use std::sync::Arc; #[test] diff --git a/vulkano/src/device/properties.rs b/vulkano/src/device/properties.rs index eeddb87d..92baf315 100644 --- a/vulkano/src/device/properties.rs +++ b/vulkano/src/device/properties.rs @@ -1,16 +1,18 @@ -use crate::device::physical::{ - ConformanceVersion, DriverId, PhysicalDeviceType, PointClippingBehavior, ShaderCoreProperties, - ShaderFloatControlsIndependence, SubgroupFeatures, +use crate::{ + device::{ + physical::{ + ConformanceVersion, DriverId, PhysicalDeviceType, PointClippingBehavior, + ShaderCoreProperties, ShaderFloatControlsIndependence, SubgroupFeatures, + }, + DeviceExtensions, + }, + image::{SampleCount, SampleCounts}, + instance::InstanceExtensions, + render_pass::ResolveModes, + shader::ShaderStages, + DeviceSize, Version, }; -use crate::device::DeviceExtensions; -use crate::image::{SampleCount, SampleCounts}; -use crate::instance::InstanceExtensions; -use crate::render_pass::ResolveModes; -use crate::shader::ShaderStages; -use crate::DeviceSize; -use crate::Version; -use std::ffi::CStr; -use std::os::raw::c_char; +use std::{ffi::CStr, os::raw::c_char}; // Generated by build.rs include!(concat!(env!("OUT_DIR"), "/properties.rs")); diff --git a/vulkano/src/extensions.rs b/vulkano/src/extensions.rs index 81e14919..01092396 100644 --- a/vulkano/src/extensions.rs +++ b/vulkano/src/extensions.rs @@ -8,8 +8,10 @@ // according to those terms. use crate::Version; -use std::error; -use std::fmt::{Display, Error as FmtError, Formatter}; +use std::{ + error, + fmt::{Display, Error as FmtError, Formatter}, +}; /// An error that can happen when enabling an extension on an instance or device. #[derive(Clone, Copy, Debug)] diff --git a/vulkano/src/image/attachment.rs b/vulkano/src/image/attachment.rs index 468a0dd6..c7c439d3 100644 --- a/vulkano/src/image/attachment.rs +++ b/vulkano/src/image/attachment.rs @@ -18,7 +18,8 @@ use crate::{ memory::{ pool::{ alloc_dedicated_with_exportable_fd, AllocFromRequirementsFilter, AllocLayout, - MappingRequirement, MemoryPoolAlloc, PotentialDedicatedAllocation, StdMemoryPoolAlloc, + MappingRequirement, MemoryPoolAlloc, PotentialDedicatedAllocation, + StandardMemoryPoolAlloc, }, DedicatedAllocation, DeviceMemoryExportError, ExternalMemoryHandleType, ExternalMemoryHandleTypes, MemoryPool, @@ -64,7 +65,7 @@ use std::{ /// // TODO: forbid reading transient images outside render passes? #[derive(Debug)] -pub struct AttachmentImage> { +pub struct AttachmentImage> { // Inner implementation. image: Arc, @@ -442,7 +443,7 @@ impl AttachmentImage { let mem_reqs = image.memory_requirements(); let memory = MemoryPool::alloc_from_requirements( - &Device::standard_pool(&device), + &device.standard_memory_pool(), &mem_reqs, AllocLayout::Optimal, MappingRequirement::DoNotMap, diff --git a/vulkano/src/image/immutable.rs b/vulkano/src/image/immutable.rs index b79e1d26..5713e583 100644 --- a/vulkano/src/image/immutable.rs +++ b/vulkano/src/image/immutable.rs @@ -25,7 +25,7 @@ use crate::{ memory::{ pool::{ AllocFromRequirementsFilter, AllocLayout, MappingRequirement, MemoryPoolAlloc, - PotentialDedicatedAllocation, StdMemoryPoolAlloc, + PotentialDedicatedAllocation, StandardMemoryPoolAlloc, }, DedicatedAllocation, DeviceMemoryAllocationError, MemoryPool, }, @@ -45,7 +45,7 @@ use std::{ /// but then you must only ever read from it. // TODO: type (2D, 3D, array, etc.) as template parameter #[derive(Debug)] -pub struct ImmutableImage> { +pub struct ImmutableImage> { image: Arc, dimensions: ImageDimensions, memory: A, @@ -204,7 +204,7 @@ impl ImmutableImage { let mem_reqs = image.memory_requirements(); let memory = MemoryPool::alloc_from_requirements( - &Device::standard_pool(&device), + &device.standard_memory_pool(), &mem_reqs, AllocLayout::Optimal, MappingRequirement::DoNotMap, @@ -411,7 +411,7 @@ where } // Must not implement Clone, as that would lead to multiple `used` values. -pub struct ImmutableImageInitialization> { +pub struct ImmutableImageInitialization> { image: Arc>, mip_levels_access: Range, array_layers_access: Range, diff --git a/vulkano/src/image/mod.rs b/vulkano/src/image/mod.rs index aa803231..77969410 100644 --- a/vulkano/src/image/mod.rs +++ b/vulkano/src/image/mod.rs @@ -839,11 +839,10 @@ impl From for ImageFormatProperties { #[cfg(test)] mod tests { - use crate::format::Format; - use crate::image::ImageAccess; - use crate::image::ImageDimensions; - use crate::image::ImmutableImage; - use crate::image::MipmapsCount; + use crate::{ + format::Format, + image::{ImageAccess, ImageDimensions, ImmutableImage, MipmapsCount}, + }; #[test] fn max_mip_levels() { diff --git a/vulkano/src/image/storage.rs b/vulkano/src/image/storage.rs index aeab4431..8ff3b608 100644 --- a/vulkano/src/image/storage.rs +++ b/vulkano/src/image/storage.rs @@ -11,16 +11,14 @@ use super::{ sys::UnsafeImage, traits::ImageContent, ImageAccess, ImageCreateFlags, ImageCreationError, ImageDescriptorLayouts, ImageDimensions, ImageInner, ImageLayout, ImageUsage, }; -use crate::device::Queue; -use crate::image::view::ImageView; use crate::{ - device::{physical::QueueFamily, Device, DeviceOwned}, + device::{physical::QueueFamily, Device, DeviceOwned, Queue}, format::Format, - image::sys::UnsafeImageCreateInfo, + image::{sys::UnsafeImageCreateInfo, view::ImageView}, memory::{ pool::{ alloc_dedicated_with_exportable_fd, AllocFromRequirementsFilter, AllocLayout, - MappingRequirement, MemoryPoolAlloc, PotentialDedicatedAllocation, StdMemoryPool, + MappingRequirement, MemoryPoolAlloc, PotentialDedicatedAllocation, StandardMemoryPool, }, DedicatedAllocation, DeviceMemoryExportError, ExternalMemoryHandleType, ExternalMemoryHandleTypes, MemoryPool, @@ -38,7 +36,7 @@ use std::{ /// General-purpose image in device memory. Can be used for any usage, but will be slower than a /// specialized image. #[derive(Debug)] -pub struct StorageImage> +pub struct StorageImage> where A: MemoryPool, { @@ -130,7 +128,7 @@ impl StorageImage { let mem_reqs = image.memory_requirements(); let memory = MemoryPool::alloc_from_requirements( - &Device::standard_pool(&device), + &device.standard_memory_pool(), &mem_reqs, AllocLayout::Optimal, MappingRequirement::DoNotMap, @@ -352,9 +350,13 @@ where #[cfg(test)] mod tests { use super::StorageImage; - use crate::format::Format; - use crate::image::view::ImageViewCreationError; - use crate::image::{ImageAccess, ImageCreationError, ImageDimensions, ImageUsage}; + use crate::{ + format::Format, + image::{ + view::ImageViewCreationError, ImageAccess, ImageCreationError, ImageDimensions, + ImageUsage, + }, + }; #[test] fn create() { diff --git a/vulkano/src/image/sys.rs b/vulkano/src/image/sys.rs index 5e80dd61..2b5de6bc 100644 --- a/vulkano/src/image/sys.rs +++ b/vulkano/src/image/sys.rs @@ -18,18 +18,17 @@ use super::{ ImageSubresourceLayers, ImageSubresourceRange, ImageTiling, ImageUsage, SampleCount, SampleCounts, }; -use crate::image::view::ImageViewCreationError; -use crate::range_map::RangeMap; use crate::{ buffer::cpu_access::{ReadLockError, WriteLockError}, check_errors, device::{Device, DeviceOwned}, format::{ChromaSampling, Format, FormatFeatures, NumericType}, - image::{ImageFormatInfo, ImageFormatProperties, ImageType}, + image::{view::ImageViewCreationError, ImageFormatInfo, ImageFormatProperties, ImageType}, memory::{ DeviceMemory, DeviceMemoryAllocationError, ExternalMemoryHandleType, ExternalMemoryHandleTypes, MemoryRequirements, }, + range_map::RangeMap, sync::{AccessError, CurrentAccess, Sharing}, DeviceSize, Error, OomError, Version, VulkanObject, }; @@ -2186,18 +2185,15 @@ impl FusedIterator for SubresourceRangeIterator {} #[cfg(test)] mod tests { - use super::ImageCreationError; - use super::ImageUsage; - use super::UnsafeImage; - use super::UnsafeImageCreateInfo; - use crate::format::Format; - use crate::image::sys::SubresourceRangeIterator; - use crate::image::ImageAspect; - use crate::image::ImageAspects; - use crate::image::ImageDimensions; - use crate::image::ImageSubresourceRange; - use crate::image::SampleCount; - use crate::DeviceSize; + use super::{ImageCreationError, ImageUsage, UnsafeImage, UnsafeImageCreateInfo}; + use crate::{ + format::Format, + image::{ + sys::SubresourceRangeIterator, ImageAspect, ImageAspects, ImageDimensions, + ImageSubresourceRange, SampleCount, + }, + DeviceSize, + }; use smallvec::SmallVec; #[test] diff --git a/vulkano/src/memory/device_memory.rs b/vulkano/src/memory/device_memory.rs index c3e983ca..863e117c 100644 --- a/vulkano/src/memory/device_memory.rs +++ b/vulkano/src/memory/device_memory.rs @@ -1476,9 +1476,10 @@ impl From for MemoryMapError { #[cfg(test)] mod tests { use super::MemoryAllocateInfo; - use crate::memory::DeviceMemory; - use crate::memory::DeviceMemoryAllocationError; - use crate::OomError; + use crate::{ + memory::{DeviceMemory, DeviceMemoryAllocationError}, + OomError, + }; #[test] fn create() { diff --git a/vulkano/src/memory/mod.rs b/vulkano/src/memory/mod.rs index 06ec0654..25d97b50 100644 --- a/vulkano/src/memory/mod.rs +++ b/vulkano/src/memory/mod.rs @@ -90,7 +90,7 @@ //! A memory pool is any object that implements the `MemoryPool` trait. You can implement that //! trait on your own structure and then use it when you create buffers and images so that they //! get memory from that pool. By default if you don't specify any pool when creating a buffer or -//! an image, an instance of `StdMemoryPool` that is shared by the `Device` object is used. +//! an image, an instance of `StandardMemoryPool` that is shared by the `Device` object is used. pub use self::{ device_memory::{ diff --git a/vulkano/src/memory/pool/host_visible.rs b/vulkano/src/memory/pool/host_visible.rs index af6766a6..91da3131 100644 --- a/vulkano/src/memory/pool/host_visible.rs +++ b/vulkano/src/memory/pool/host_visible.rs @@ -7,29 +7,31 @@ // notice may not be copied, modified, or distributed except // according to those terms. -use crate::device::physical::MemoryType; -use crate::device::Device; -use crate::instance::Instance; -use crate::memory::device_memory::MemoryAllocateInfo; -use crate::memory::DeviceMemory; -use crate::memory::DeviceMemoryAllocationError; -use crate::memory::MappedDeviceMemory; -use crate::DeviceSize; -use std::cmp; -use std::ops::Range; -use std::sync::Arc; -use std::sync::Mutex; +use crate::{ + device::{physical::MemoryType, Device}, + instance::Instance, + memory::{ + device_memory::MemoryAllocateInfo, DeviceMemory, DeviceMemoryAllocationError, + MappedDeviceMemory, + }, + DeviceSize, +}; +use std::{ + cmp, + ops::Range, + sync::{Arc, Mutex}, +}; /// Memory pool that operates on a given memory type. #[derive(Debug)] -pub struct StdHostVisibleMemoryTypePool { +pub struct StandardHostVisibleMemoryTypePool { device: Arc, memory_type: u32, // TODO: obviously very inefficient occupied: Mutex, Vec>)>>, } -impl StdHostVisibleMemoryTypePool { +impl StandardHostVisibleMemoryTypePool { /// Creates a new pool that will operate on the given memory type. /// /// # Panic @@ -38,7 +40,10 @@ impl StdHostVisibleMemoryTypePool { /// - Panics if the memory type is not host-visible. /// #[inline] - pub fn new(device: Arc, memory_type: MemoryType) -> Arc { + pub fn new( + device: Arc, + memory_type: MemoryType, + ) -> Arc { assert_eq!( &**device.physical_device().instance() as *const Instance, &**memory_type.physical_device().instance() as *const Instance @@ -49,7 +54,7 @@ impl StdHostVisibleMemoryTypePool { ); assert!(memory_type.is_host_visible()); - Arc::new(StdHostVisibleMemoryTypePool { + Arc::new(StandardHostVisibleMemoryTypePool { device: device.clone(), memory_type: memory_type.id(), occupied: Mutex::new(Vec::new()), @@ -67,7 +72,7 @@ impl StdHostVisibleMemoryTypePool { me: &Arc, size: DeviceSize, alignment: DeviceSize, - ) -> Result { + ) -> Result { assert!(size != 0); assert!(alignment != 0); @@ -88,7 +93,7 @@ impl StdHostVisibleMemoryTypePool { let entry2 = entries[i + 1].clone(); if entry1_end + size <= entry2.start { entries.insert(i + 1, entry1_end..entry1_end + size); - return Ok(StdHostVisibleMemoryTypePoolAlloc { + return Ok(StandardHostVisibleMemoryTypePoolAlloc { pool: me.clone(), memory: dev_mem.clone(), offset: entry1_end, @@ -101,7 +106,7 @@ impl StdHostVisibleMemoryTypePool { let last_end = entries.last().map(|e| align(e.end, alignment)).unwrap_or(0); if last_end + size <= (**dev_mem).as_ref().allocation_size() { entries.push(last_end..last_end + size); - return Ok(StdHostVisibleMemoryTypePoolAlloc { + return Ok(StandardHostVisibleMemoryTypePoolAlloc { pool: me.clone(), memory: dev_mem.clone(), offset: last_end, @@ -127,7 +132,7 @@ impl StdHostVisibleMemoryTypePool { }; occupied.push((new_block.clone(), vec![0..size])); - Ok(StdHostVisibleMemoryTypePoolAlloc { + Ok(StandardHostVisibleMemoryTypePoolAlloc { pool: me.clone(), memory: new_block, offset: 0, @@ -152,14 +157,14 @@ impl StdHostVisibleMemoryTypePool { } #[derive(Debug)] -pub struct StdHostVisibleMemoryTypePoolAlloc { - pool: Arc, +pub struct StandardHostVisibleMemoryTypePoolAlloc { + pool: Arc, memory: Arc, offset: DeviceSize, size: DeviceSize, } -impl StdHostVisibleMemoryTypePoolAlloc { +impl StandardHostVisibleMemoryTypePoolAlloc { #[inline] pub fn memory(&self) -> &MappedDeviceMemory { &self.memory @@ -176,7 +181,7 @@ impl StdHostVisibleMemoryTypePoolAlloc { } } -impl Drop for StdHostVisibleMemoryTypePoolAlloc { +impl Drop for StandardHostVisibleMemoryTypePoolAlloc { fn drop(&mut self) { let mut occupied = self.pool.occupied.lock().unwrap(); diff --git a/vulkano/src/memory/pool/mod.rs b/vulkano/src/memory/pool/mod.rs index af0c74e5..11108935 100644 --- a/vulkano/src/memory/pool/mod.rs +++ b/vulkano/src/memory/pool/mod.rs @@ -7,22 +7,22 @@ // notice may not be copied, modified, or distributed except // according to those terms. -pub use self::host_visible::StdHostVisibleMemoryTypePool; -pub use self::host_visible::StdHostVisibleMemoryTypePoolAlloc; -pub use self::non_host_visible::StdNonHostVisibleMemoryTypePool; -pub use self::non_host_visible::StdNonHostVisibleMemoryTypePoolAlloc; -pub use self::pool::StdMemoryPool; -pub use self::pool::StdMemoryPoolAlloc; -use crate::device::physical::MemoryType; -use crate::device::{Device, DeviceOwned}; -use crate::memory::device_memory::MemoryAllocateInfo; -use crate::memory::DedicatedAllocation; -use crate::memory::DeviceMemory; -use crate::memory::DeviceMemoryAllocationError; -use crate::memory::ExternalMemoryHandleTypes; -use crate::memory::MappedDeviceMemory; -use crate::memory::MemoryRequirements; -use crate::DeviceSize; +pub use self::{ + host_visible::{StandardHostVisibleMemoryTypePool, StandardHostVisibleMemoryTypePoolAlloc}, + non_host_visible::{ + StandardNonHostVisibleMemoryTypePool, StandardNonHostVisibleMemoryTypePoolAlloc, + }, + pool::{StandardMemoryPool, StandardMemoryPoolAlloc}, +}; +use crate::{ + device::{physical::MemoryType, Device, DeviceOwned}, + memory::{ + device_memory::MemoryAllocateInfo, DedicatedAllocation, DeviceMemory, + DeviceMemoryAllocationError, ExternalMemoryHandleTypes, MappedDeviceMemory, + MemoryRequirements, + }, + DeviceSize, +}; use std::sync::Arc; mod host_visible; @@ -77,7 +77,7 @@ pub(crate) fn alloc_dedicated_with_exportable_fd( map: MappingRequirement, dedicated_allocation: DedicatedAllocation, filter: F, -) -> Result, DeviceMemoryAllocationError> +) -> Result, DeviceMemoryAllocationError> where F: FnMut(MemoryType) -> AllocFromRequirementsFilter, { diff --git a/vulkano/src/memory/pool/non_host_visible.rs b/vulkano/src/memory/pool/non_host_visible.rs index d4175be1..b3809619 100644 --- a/vulkano/src/memory/pool/non_host_visible.rs +++ b/vulkano/src/memory/pool/non_host_visible.rs @@ -7,28 +7,28 @@ // notice may not be copied, modified, or distributed except // according to those terms. -use crate::device::physical::MemoryType; -use crate::device::Device; -use crate::instance::Instance; -use crate::memory::device_memory::MemoryAllocateInfo; -use crate::memory::DeviceMemory; -use crate::memory::DeviceMemoryAllocationError; -use crate::DeviceSize; -use std::cmp; -use std::ops::Range; -use std::sync::Arc; -use std::sync::Mutex; +use crate::{ + device::{physical::MemoryType, Device}, + instance::Instance, + memory::{device_memory::MemoryAllocateInfo, DeviceMemory, DeviceMemoryAllocationError}, + DeviceSize, +}; +use std::{ + cmp, + ops::Range, + sync::{Arc, Mutex}, +}; /// Memory pool that operates on a given memory type. #[derive(Debug)] -pub struct StdNonHostVisibleMemoryTypePool { +pub struct StandardNonHostVisibleMemoryTypePool { device: Arc, memory_type: u32, // TODO: obviously very inefficient occupied: Mutex, Vec>)>>, } -impl StdNonHostVisibleMemoryTypePool { +impl StandardNonHostVisibleMemoryTypePool { /// Creates a new pool that will operate on the given memory type. /// /// # Panic @@ -39,7 +39,7 @@ impl StdNonHostVisibleMemoryTypePool { pub fn new( device: Arc, memory_type: MemoryType, - ) -> Arc { + ) -> Arc { assert_eq!( &**device.physical_device().instance() as *const Instance, &**memory_type.physical_device().instance() as *const Instance @@ -49,7 +49,7 @@ impl StdNonHostVisibleMemoryTypePool { memory_type.physical_device().index() ); - Arc::new(StdNonHostVisibleMemoryTypePool { + Arc::new(StandardNonHostVisibleMemoryTypePool { device: device.clone(), memory_type: memory_type.id(), occupied: Mutex::new(Vec::new()), @@ -67,7 +67,7 @@ impl StdNonHostVisibleMemoryTypePool { me: &Arc, size: DeviceSize, alignment: DeviceSize, - ) -> Result { + ) -> Result { assert!(size != 0); assert!(alignment != 0); @@ -88,7 +88,7 @@ impl StdNonHostVisibleMemoryTypePool { let entry2 = entries[i + 1].clone(); if entry1_end + size <= entry2.start { entries.insert(i + 1, entry1_end..entry1_end + size); - return Ok(StdNonHostVisibleMemoryTypePoolAlloc { + return Ok(StandardNonHostVisibleMemoryTypePoolAlloc { pool: me.clone(), memory: dev_mem.clone(), offset: entry1_end, @@ -101,7 +101,7 @@ impl StdNonHostVisibleMemoryTypePool { let last_end = entries.last().map(|e| align(e.end, alignment)).unwrap_or(0); if last_end + size <= dev_mem.allocation_size() { entries.push(last_end..last_end + size); - return Ok(StdNonHostVisibleMemoryTypePoolAlloc { + return Ok(StandardNonHostVisibleMemoryTypePoolAlloc { pool: me.clone(), memory: dev_mem.clone(), offset: last_end, @@ -126,7 +126,7 @@ impl StdNonHostVisibleMemoryTypePool { }; occupied.push((new_block.clone(), vec![0..size])); - Ok(StdNonHostVisibleMemoryTypePoolAlloc { + Ok(StandardNonHostVisibleMemoryTypePoolAlloc { pool: me.clone(), memory: new_block, offset: 0, @@ -151,14 +151,14 @@ impl StdNonHostVisibleMemoryTypePool { } #[derive(Debug)] -pub struct StdNonHostVisibleMemoryTypePoolAlloc { - pool: Arc, +pub struct StandardNonHostVisibleMemoryTypePoolAlloc { + pool: Arc, memory: Arc, offset: DeviceSize, size: DeviceSize, } -impl StdNonHostVisibleMemoryTypePoolAlloc { +impl StandardNonHostVisibleMemoryTypePoolAlloc { #[inline] pub fn memory(&self) -> &DeviceMemory { &self.memory @@ -175,7 +175,7 @@ impl StdNonHostVisibleMemoryTypePoolAlloc { } } -impl Drop for StdNonHostVisibleMemoryTypePoolAlloc { +impl Drop for StandardNonHostVisibleMemoryTypePoolAlloc { fn drop(&mut self) { let mut occupied = self.pool.occupied.lock().unwrap(); diff --git a/vulkano/src/memory/pool/pool.rs b/vulkano/src/memory/pool/pool.rs index face9e55..abac878e 100644 --- a/vulkano/src/memory/pool/pool.rs +++ b/vulkano/src/memory/pool/pool.rs @@ -7,41 +7,38 @@ // notice may not be copied, modified, or distributed except // according to those terms. -use crate::device::physical::MemoryType; -use crate::device::Device; -use crate::device::DeviceOwned; -use crate::memory::pool::AllocLayout; -use crate::memory::pool::MappingRequirement; -use crate::memory::pool::MemoryPool; -use crate::memory::pool::MemoryPoolAlloc; -use crate::memory::pool::StdHostVisibleMemoryTypePool; -use crate::memory::pool::StdHostVisibleMemoryTypePoolAlloc; -use crate::memory::pool::StdNonHostVisibleMemoryTypePool; -use crate::memory::pool::StdNonHostVisibleMemoryTypePoolAlloc; -use crate::memory::DeviceMemory; -use crate::memory::DeviceMemoryAllocationError; -use crate::memory::MappedDeviceMemory; -use crate::DeviceSize; -use std::collections::hash_map::Entry; -use std::collections::HashMap; -use std::sync::Arc; -use std::sync::Mutex; +use crate::{ + device::{physical::MemoryType, Device, DeviceOwned}, + memory::{ + pool::{ + AllocLayout, MappingRequirement, MemoryPool, MemoryPoolAlloc, + StandardHostVisibleMemoryTypePool, StandardHostVisibleMemoryTypePoolAlloc, + StandardNonHostVisibleMemoryTypePool, StandardNonHostVisibleMemoryTypePoolAlloc, + }, + DeviceMemory, DeviceMemoryAllocationError, MappedDeviceMemory, + }, + DeviceSize, +}; +use std::{ + collections::{hash_map::Entry, HashMap}, + sync::{Arc, Mutex}, +}; #[derive(Debug)] -pub struct StdMemoryPool { +pub struct StandardMemoryPool { device: Arc, // For each memory type index, stores the associated pool. pools: Mutex>, } -impl StdMemoryPool { +impl StandardMemoryPool { /// Creates a new pool. #[inline] - pub fn new(device: Arc) -> Arc { + pub fn new(device: Arc) -> Arc { let cap = device.physical_device().memory_types().len(); - Arc::new(StdMemoryPool { + Arc::new(StandardMemoryPool { device: device.clone(), pools: Mutex::new(HashMap::with_capacity(cap)), }) @@ -49,13 +46,13 @@ impl StdMemoryPool { } fn generic_allocation( - mem_pool: Arc, + mem_pool: Arc, memory_type: MemoryType, size: DeviceSize, alignment: DeviceSize, layout: AllocLayout, map: MappingRequirement, -) -> Result { +) -> Result { let mut pools = mem_pool.pools.lock().unwrap(); let memory_type_host_visible = memory_type.is_host_visible(); @@ -64,17 +61,17 @@ fn generic_allocation( match pools.entry((memory_type.id(), layout, map)) { Entry::Occupied(entry) => match entry.get() { &Pool::HostVisible(ref pool) => { - let alloc = StdHostVisibleMemoryTypePool::alloc(&pool, size, alignment)?; - let inner = StdMemoryPoolAllocInner::HostVisible(alloc); - Ok(StdMemoryPoolAlloc { + let alloc = StandardHostVisibleMemoryTypePool::alloc(&pool, size, alignment)?; + let inner = StandardMemoryPoolAllocInner::HostVisible(alloc); + Ok(StandardMemoryPoolAlloc { inner, pool: mem_pool.clone(), }) } &Pool::NonHostVisible(ref pool) => { - let alloc = StdNonHostVisibleMemoryTypePool::alloc(&pool, size, alignment)?; - let inner = StdMemoryPoolAllocInner::NonHostVisible(alloc); - Ok(StdMemoryPoolAlloc { + let alloc = StandardNonHostVisibleMemoryTypePool::alloc(&pool, size, alignment)?; + let inner = StandardMemoryPoolAllocInner::NonHostVisible(alloc); + Ok(StandardMemoryPoolAlloc { inner, pool: mem_pool.clone(), }) @@ -83,21 +80,22 @@ fn generic_allocation( Entry::Vacant(entry) => { if memory_type_host_visible { - let pool = StdHostVisibleMemoryTypePool::new(mem_pool.device.clone(), memory_type); + let pool = + StandardHostVisibleMemoryTypePool::new(mem_pool.device.clone(), memory_type); entry.insert(Pool::HostVisible(pool.clone())); - let alloc = StdHostVisibleMemoryTypePool::alloc(&pool, size, alignment)?; - let inner = StdMemoryPoolAllocInner::HostVisible(alloc); - Ok(StdMemoryPoolAlloc { + let alloc = StandardHostVisibleMemoryTypePool::alloc(&pool, size, alignment)?; + let inner = StandardMemoryPoolAllocInner::HostVisible(alloc); + Ok(StandardMemoryPoolAlloc { inner, pool: mem_pool.clone(), }) } else { let pool = - StdNonHostVisibleMemoryTypePool::new(mem_pool.device.clone(), memory_type); + StandardNonHostVisibleMemoryTypePool::new(mem_pool.device.clone(), memory_type); entry.insert(Pool::NonHostVisible(pool.clone())); - let alloc = StdNonHostVisibleMemoryTypePool::alloc(&pool, size, alignment)?; - let inner = StdMemoryPoolAllocInner::NonHostVisible(alloc); - Ok(StdMemoryPoolAlloc { + let alloc = StandardNonHostVisibleMemoryTypePool::alloc(&pool, size, alignment)?; + let inner = StandardMemoryPoolAllocInner::NonHostVisible(alloc); + Ok(StandardMemoryPoolAlloc { inner, pool: mem_pool.clone(), }) @@ -106,8 +104,8 @@ fn generic_allocation( } } -unsafe impl MemoryPool for Arc { - type Alloc = StdMemoryPoolAlloc; +unsafe impl MemoryPool for Arc { + type Alloc = StandardMemoryPoolAlloc; fn alloc_generic( &self, @@ -116,12 +114,12 @@ unsafe impl MemoryPool for Arc { alignment: DeviceSize, layout: AllocLayout, map: MappingRequirement, - ) -> Result { + ) -> Result { generic_allocation(self.clone(), memory_type, size, alignment, layout, map) } } -unsafe impl DeviceOwned for StdMemoryPool { +unsafe impl DeviceOwned for StandardMemoryPool { #[inline] fn device(&self) -> &Arc { &self.device @@ -130,54 +128,54 @@ unsafe impl DeviceOwned for StdMemoryPool { #[derive(Debug)] enum Pool { - HostVisible(Arc), - NonHostVisible(Arc), + HostVisible(Arc), + NonHostVisible(Arc), } #[derive(Debug)] -pub struct StdMemoryPoolAlloc { - inner: StdMemoryPoolAllocInner, - pool: Arc, +pub struct StandardMemoryPoolAlloc { + inner: StandardMemoryPoolAllocInner, + pool: Arc, } -impl StdMemoryPoolAlloc { +impl StandardMemoryPoolAlloc { #[inline] pub fn size(&self) -> DeviceSize { match self.inner { - StdMemoryPoolAllocInner::NonHostVisible(ref mem) => mem.size(), - StdMemoryPoolAllocInner::HostVisible(ref mem) => mem.size(), + StandardMemoryPoolAllocInner::NonHostVisible(ref mem) => mem.size(), + StandardMemoryPoolAllocInner::HostVisible(ref mem) => mem.size(), } } } -unsafe impl MemoryPoolAlloc for StdMemoryPoolAlloc { +unsafe impl MemoryPoolAlloc for StandardMemoryPoolAlloc { #[inline] fn memory(&self) -> &DeviceMemory { match self.inner { - StdMemoryPoolAllocInner::NonHostVisible(ref mem) => mem.memory(), - StdMemoryPoolAllocInner::HostVisible(ref mem) => mem.memory().as_ref(), + StandardMemoryPoolAllocInner::NonHostVisible(ref mem) => mem.memory(), + StandardMemoryPoolAllocInner::HostVisible(ref mem) => mem.memory().as_ref(), } } #[inline] fn mapped_memory(&self) -> Option<&MappedDeviceMemory> { match self.inner { - StdMemoryPoolAllocInner::NonHostVisible(_) => None, - StdMemoryPoolAllocInner::HostVisible(ref mem) => Some(mem.memory()), + StandardMemoryPoolAllocInner::NonHostVisible(_) => None, + StandardMemoryPoolAllocInner::HostVisible(ref mem) => Some(mem.memory()), } } #[inline] fn offset(&self) -> DeviceSize { match self.inner { - StdMemoryPoolAllocInner::NonHostVisible(ref mem) => mem.offset(), - StdMemoryPoolAllocInner::HostVisible(ref mem) => mem.offset(), + StandardMemoryPoolAllocInner::NonHostVisible(ref mem) => mem.offset(), + StandardMemoryPoolAllocInner::HostVisible(ref mem) => mem.offset(), } } } #[derive(Debug)] -enum StdMemoryPoolAllocInner { - NonHostVisible(StdNonHostVisibleMemoryTypePoolAlloc), - HostVisible(StdHostVisibleMemoryTypePoolAlloc), +enum StandardMemoryPoolAllocInner { + NonHostVisible(StandardNonHostVisibleMemoryTypePoolAlloc), + HostVisible(StandardHostVisibleMemoryTypePoolAlloc), } diff --git a/vulkano/src/pipeline/cache.rs b/vulkano/src/pipeline/cache.rs index b732c6b3..7785f3b7 100644 --- a/vulkano/src/pipeline/cache.rs +++ b/vulkano/src/pipeline/cache.rs @@ -21,14 +21,8 @@ //! of [`get_data`](crate::pipeline::cache::PipelineCache::get_data) for example of how to store the data //! on the disk, and [`with_data`](crate::pipeline::cache::PipelineCache::with_data) for how to reload it. -use crate::check_errors; -use crate::device::Device; -use crate::OomError; -use crate::Success; -use crate::VulkanObject; -use std::mem::MaybeUninit; -use std::ptr; -use std::sync::Arc; +use crate::{check_errors, device::Device, OomError, Success, VulkanObject}; +use std::{mem::MaybeUninit, ptr, sync::Arc}; /// Opaque cache that contains pipeline objects. /// @@ -256,9 +250,10 @@ impl Drop for PipelineCache { #[cfg(test)] mod tests { - use crate::pipeline::cache::PipelineCache; - use crate::pipeline::ComputePipeline; - use crate::shader::ShaderModule; + use crate::{ + pipeline::{cache::PipelineCache, ComputePipeline}, + shader::ShaderModule, + }; use std::sync::Arc; #[test] diff --git a/vulkano/src/pipeline/compute.rs b/vulkano/src/pipeline/compute.rs index 4bedd01f..969bcb88 100644 --- a/vulkano/src/pipeline/compute.rs +++ b/vulkano/src/pipeline/compute.rs @@ -23,28 +23,21 @@ //! command on the command buffer. use super::layout::PipelineLayoutCreateInfo; -use crate::check_errors; -use crate::descriptor_set::layout::{ - DescriptorSetLayout, DescriptorSetLayoutCreateInfo, DescriptorSetLayoutCreationError, +use crate::{ + check_errors, + descriptor_set::layout::{ + DescriptorSetLayout, DescriptorSetLayoutCreateInfo, DescriptorSetLayoutCreationError, + }, + device::{Device, DeviceOwned}, + pipeline::{ + cache::PipelineCache, + layout::{PipelineLayout, PipelineLayoutCreationError, PipelineLayoutSupersetError}, + Pipeline, PipelineBindPoint, + }, + shader::{DescriptorRequirements, EntryPoint, SpecializationConstants}, + DeviceSize, Error, OomError, VulkanObject, }; -use crate::device::{Device, DeviceOwned}; -use crate::pipeline::cache::PipelineCache; -use crate::pipeline::layout::{ - PipelineLayout, PipelineLayoutCreationError, PipelineLayoutSupersetError, -}; -use crate::pipeline::{Pipeline, PipelineBindPoint}; -use crate::shader::{DescriptorRequirements, EntryPoint, SpecializationConstants}; -use crate::DeviceSize; -use crate::Error; -use crate::OomError; -use crate::VulkanObject; -use std::collections::HashMap; -use std::error; -use std::fmt; -use std::mem; -use std::mem::MaybeUninit; -use std::ptr; -use std::sync::Arc; +use std::{collections::HashMap, error, fmt, mem, mem::MaybeUninit, ptr, sync::Arc}; /// A pipeline object that describes to the Vulkan implementation how it should perform compute /// operations. @@ -406,20 +399,14 @@ impl From for ComputePipelineCreationError { #[cfg(test)] mod tests { - use crate::buffer::BufferUsage; - use crate::buffer::CpuAccessibleBuffer; - use crate::command_buffer::AutoCommandBufferBuilder; - use crate::command_buffer::CommandBufferUsage; - use crate::descriptor_set::PersistentDescriptorSet; - use crate::descriptor_set::WriteDescriptorSet; - use crate::pipeline::ComputePipeline; - use crate::pipeline::Pipeline; - use crate::pipeline::PipelineBindPoint; - use crate::shader::ShaderModule; - use crate::shader::SpecializationConstants; - use crate::shader::SpecializationMapEntry; - use crate::sync::now; - use crate::sync::GpuFuture; + use crate::{ + buffer::{BufferUsage, CpuAccessibleBuffer}, + command_buffer::{AutoCommandBufferBuilder, CommandBufferUsage}, + descriptor_set::{PersistentDescriptorSet, WriteDescriptorSet}, + pipeline::{ComputePipeline, Pipeline, PipelineBindPoint}, + shader::{ShaderModule, SpecializationConstants, SpecializationMapEntry}, + sync::{now, GpuFuture}, + }; // TODO: test for basic creation // TODO: test for pipeline layout error diff --git a/vulkano/src/pipeline/graphics/vertex_input/buffers.rs b/vulkano/src/pipeline/graphics/vertex_input/buffers.rs index c3d37bfe..be7fcaed 100644 --- a/vulkano/src/pipeline/graphics/vertex_input/buffers.rs +++ b/vulkano/src/pipeline/graphics/vertex_input/buffers.rs @@ -8,15 +8,15 @@ // according to those terms. use super::VertexMemberInfo; -use crate::pipeline::graphics::vertex_input::IncompatibleVertexDefinitionError; -use crate::pipeline::graphics::vertex_input::Vertex; -use crate::pipeline::graphics::vertex_input::VertexDefinition; -use crate::pipeline::graphics::vertex_input::VertexInputAttributeDescription; -use crate::pipeline::graphics::vertex_input::VertexInputBindingDescription; -use crate::pipeline::graphics::vertex_input::VertexInputRate; -use crate::pipeline::graphics::vertex_input::VertexInputState; -use crate::shader::ShaderInterface; -use crate::DeviceSize; +use crate::{ + pipeline::graphics::vertex_input::{ + IncompatibleVertexDefinitionError, Vertex, VertexDefinition, + VertexInputAttributeDescription, VertexInputBindingDescription, VertexInputRate, + VertexInputState, + }, + shader::ShaderInterface, + DeviceSize, +}; use std::mem; /// A vertex definition for any number of vertex and instance buffers. diff --git a/vulkano/src/pipeline/graphics/vertex_input/collection.rs b/vulkano/src/pipeline/graphics/vertex_input/collection.rs index c3694a67..c03d9c0b 100644 --- a/vulkano/src/pipeline/graphics/vertex_input/collection.rs +++ b/vulkano/src/pipeline/graphics/vertex_input/collection.rs @@ -82,12 +82,11 @@ impl_collection!(Z, Y, X, W, V, U, T, S, R, Q, P, O, N, M, L, K, J, I, H, G, F, #[cfg(test)] mod tests { use super::VertexBuffersCollection; - use crate::buffer::BufferAccess; - use crate::buffer::BufferAccessObject; - use crate::buffer::BufferInner; - use crate::device::Device; - use crate::device::DeviceOwned; - use crate::DeviceSize; + use crate::{ + buffer::{BufferAccess, BufferAccessObject, BufferInner}, + device::{Device, DeviceOwned}, + DeviceSize, + }; use std::sync::Arc; struct DummyBufferA {} diff --git a/vulkano/src/pipeline/graphics/vertex_input/definition.rs b/vulkano/src/pipeline/graphics/vertex_input/definition.rs index baeffaa3..1c84a3e6 100644 --- a/vulkano/src/pipeline/graphics/vertex_input/definition.rs +++ b/vulkano/src/pipeline/graphics/vertex_input/definition.rs @@ -50,12 +50,12 @@ //! # } //! ``` -use crate::format::Format; -use crate::pipeline::graphics::vertex_input::VertexInputState; -use crate::pipeline::graphics::vertex_input::VertexMemberTy; -use crate::shader::ShaderInterface; -use std::error; -use std::fmt; +use crate::{ + format::Format, + pipeline::graphics::vertex_input::{VertexInputState, VertexMemberTy}, + shader::ShaderInterface, +}; +use std::{error, fmt}; /// Trait for types that can create a [`VertexInputState`] from a [`ShaderInterface`]. pub unsafe trait VertexDefinition { diff --git a/vulkano/src/pipeline/layout.rs b/vulkano/src/pipeline/layout.rs index aed626d0..e1cc6183 100644 --- a/vulkano/src/pipeline/layout.rs +++ b/vulkano/src/pipeline/layout.rs @@ -1132,13 +1132,12 @@ impl Counter { #[cfg(test)] mod tests { + use super::PipelineLayout; use crate::{ pipeline::layout::{PipelineLayoutCreateInfo, PushConstantRange}, shader::ShaderStages, }; - use super::PipelineLayout; - #[test] fn push_constant_ranges_disjoint() { let test_cases = [ diff --git a/vulkano/src/pipeline/mod.rs b/vulkano/src/pipeline/mod.rs index 437b73cd..eceaf132 100644 --- a/vulkano/src/pipeline/mod.rs +++ b/vulkano/src/pipeline/mod.rs @@ -17,9 +17,7 @@ //! the CPU). Consequently it is a CPU-intensive operation that should be performed at //! initialization or during a loading screen. -pub use self::compute::ComputePipeline; -pub use self::graphics::GraphicsPipeline; -pub use self::layout::PipelineLayout; +pub use self::{compute::ComputePipeline, graphics::GraphicsPipeline, layout::PipelineLayout}; use crate::device::DeviceOwned; use std::sync::Arc; diff --git a/vulkano/src/query.rs b/vulkano/src/query.rs index 8aa87e83..c2d48406 100644 --- a/vulkano/src/query.rs +++ b/vulkano/src/query.rs @@ -759,10 +759,7 @@ impl From for ash::vk::QueryResultFlags { #[cfg(test)] mod tests { use super::QueryPoolCreateInfo; - use crate::query::QueryPipelineStatisticFlags; - use crate::query::QueryPool; - use crate::query::QueryPoolCreationError; - use crate::query::QueryType; + use crate::query::{QueryPipelineStatisticFlags, QueryPool, QueryPoolCreationError, QueryType}; #[test] fn pipeline_statistics_feature() { diff --git a/vulkano/src/range_map.rs b/vulkano/src/range_map.rs index ea225cf0..701bc2da 100644 --- a/vulkano/src/range_map.rs +++ b/vulkano/src/range_map.rs @@ -1,10 +1,11 @@ -use std::cmp; -use std::cmp::Ordering; -use std::collections::{btree_map, BTreeMap}; -use std::fmt::{self, Debug}; -use std::iter::{FromIterator, FusedIterator, Peekable}; -use std::ops::Bound; -use std::ops::{Add, Range, Sub}; +use std::{ + cmp, + cmp::Ordering, + collections::{btree_map, BTreeMap}, + fmt::{self, Debug}, + iter::{FromIterator, FusedIterator, Peekable}, + ops::{Add, Bound, Range, Sub}, +}; /// A map whose keys are stored as (half-open) ranges bounded /// inclusively below and exclusively above `(start..end)`. diff --git a/vulkano/src/render_pass/framebuffer.rs b/vulkano/src/render_pass/framebuffer.rs index 9bfeee3e..784e4e2f 100644 --- a/vulkano/src/render_pass/framebuffer.rs +++ b/vulkano/src/render_pass/framebuffer.rs @@ -724,13 +724,11 @@ impl From for FramebufferCreationError { #[cfg(test)] mod tests { - use crate::format::Format; - use crate::image::attachment::AttachmentImage; - use crate::image::view::ImageView; - use crate::render_pass::Framebuffer; - use crate::render_pass::FramebufferCreateInfo; - use crate::render_pass::FramebufferCreationError; - use crate::render_pass::RenderPass; + use crate::{ + format::Format, + image::{attachment::AttachmentImage, view::ImageView}, + render_pass::{Framebuffer, FramebufferCreateInfo, FramebufferCreationError, RenderPass}, + }; #[test] fn simple_create() { diff --git a/vulkano/src/render_pass/mod.rs b/vulkano/src/render_pass/mod.rs index a1496510..0305be84 100644 --- a/vulkano/src/render_pass/mod.rs +++ b/vulkano/src/render_pass/mod.rs @@ -25,10 +25,10 @@ //! Consequently you can create graphics pipelines from a render pass object alone. //! A `Framebuffer` object is only needed when you actually add draw commands to a command buffer. -pub use self::create::RenderPassCreationError; -pub use self::framebuffer::Framebuffer; -pub use self::framebuffer::FramebufferCreateInfo; -pub use self::framebuffer::FramebufferCreationError; +pub use self::{ + create::RenderPassCreationError, + framebuffer::{Framebuffer, FramebufferCreateInfo, FramebufferCreationError}, +}; use crate::{ device::{Device, DeviceOwned}, format::Format, @@ -37,8 +37,8 @@ use crate::{ sync::{AccessFlags, PipelineStages}, Version, VulkanObject, }; -use std::cmp::max; use std::{ + cmp::max, hash::{Hash, Hasher}, mem::MaybeUninit, ptr, @@ -1228,9 +1228,10 @@ impl From for ResolveModes { #[cfg(test)] mod tests { - use crate::format::Format; - use crate::render_pass::RenderPass; - use crate::render_pass::RenderPassCreationError; + use crate::{ + format::Format, + render_pass::{RenderPass, RenderPassCreationError}, + }; #[test] fn empty() { diff --git a/vulkano/src/shader/mod.rs b/vulkano/src/shader/mod.rs index b78567d1..4f8d1298 100644 --- a/vulkano/src/shader/mod.rs +++ b/vulkano/src/shader/mod.rs @@ -17,32 +17,31 @@ //! code. You are encouraged to use the `vulkano-shaders` crate that will generate Rust code that //! wraps around vulkano's shaders API. -use crate::check_errors; -use crate::descriptor_set::layout::DescriptorType; -use crate::device::Device; -use crate::format::{Format, NumericType}; -use crate::image::view::ImageViewType; -use crate::pipeline::graphics::input_assembly::PrimitiveTopology; -use crate::pipeline::layout::PushConstantRange; -use crate::shader::spirv::{Capability, Spirv, SpirvError}; -use crate::sync::PipelineStages; -use crate::DeviceSize; -use crate::OomError; -use crate::Version; -use crate::VulkanObject; -use std::borrow::Cow; -use std::collections::{HashMap, HashSet}; -use std::error; -use std::error::Error; -use std::ffi::CStr; -use std::ffi::CString; -use std::fmt; -use std::fmt::Display; -use std::mem; -use std::mem::MaybeUninit; -use std::ops::BitOr; -use std::ptr; -use std::sync::Arc; +use crate::{ + check_errors, + descriptor_set::layout::DescriptorType, + device::Device, + format::{Format, NumericType}, + image::view::ImageViewType, + pipeline::{graphics::input_assembly::PrimitiveTopology, layout::PushConstantRange}, + shader::spirv::{Capability, Spirv, SpirvError}, + sync::PipelineStages, + DeviceSize, OomError, Version, VulkanObject, +}; +use std::{ + borrow::Cow, + collections::{HashMap, HashSet}, + error, + error::Error, + ffi::{CStr, CString}, + fmt, + fmt::Display, + mem, + mem::MaybeUninit, + ops::BitOr, + ptr, + sync::Arc, +}; pub mod reflect; pub mod spirv; diff --git a/vulkano/src/shader/reflect.rs b/vulkano/src/shader/reflect.rs index 1765d405..b6b6cc77 100644 --- a/vulkano/src/shader/reflect.rs +++ b/vulkano/src/shader/reflect.rs @@ -9,11 +9,9 @@ //! Extraction of information from SPIR-V modules, that is needed by the rest of Vulkano. -use crate::descriptor_set::layout::DescriptorType; -use crate::image::view::ImageViewType; -use crate::shader::ShaderScalarType; -use crate::DeviceSize; use crate::{ + descriptor_set::layout::DescriptorType, + image::view::ImageViewType, pipeline::layout::PushConstantRange, shader::{ spirv::{ @@ -22,11 +20,15 @@ use crate::{ }, DescriptorIdentifier, DescriptorRequirements, EntryPointInfo, GeometryShaderExecution, GeometryShaderInput, ShaderExecution, ShaderInterface, ShaderInterfaceEntry, - ShaderInterfaceEntryType, ShaderStage, SpecializationConstantRequirements, + ShaderInterfaceEntryType, ShaderScalarType, ShaderStage, + SpecializationConstantRequirements, }, + DeviceSize, +}; +use std::{ + borrow::Cow, + collections::{HashMap, HashSet}, }; -use std::borrow::Cow; -use std::collections::{HashMap, HashSet}; /// Returns an iterator of the capabilities used by `spirv`. pub fn spirv_capabilities<'a>(spirv: &'a Spirv) -> impl Iterator { diff --git a/vulkano/src/swapchain/display.rs b/vulkano/src/swapchain/display.rs index ce1a8fb9..0e60fc53 100644 --- a/vulkano/src/swapchain/display.rs +++ b/vulkano/src/swapchain/display.rs @@ -28,18 +28,11 @@ #![allow(dead_code)] // TODO: this module isn't finished #![allow(unused_variables)] // TODO: this module isn't finished -use crate::check_errors; -use crate::device::physical::PhysicalDevice; -use crate::instance::Instance; -use crate::swapchain::SupportedSurfaceTransforms; -use crate::OomError; -use crate::Success; -use crate::VulkanObject; -use std::ffi::CStr; -use std::fmt::Formatter; -use std::sync::Arc; -use std::vec::IntoIter; -use std::{fmt, ptr}; +use crate::{ + check_errors, device::physical::PhysicalDevice, instance::Instance, + swapchain::SupportedSurfaceTransforms, OomError, Success, VulkanObject, +}; +use std::{ffi::CStr, fmt, fmt::Formatter, ptr, sync::Arc, vec::IntoIter}; // TODO: extract this to a `display` module and solve the visibility problems diff --git a/vulkano/src/swapchain/mod.rs b/vulkano/src/swapchain/mod.rs index 14265feb..dabfb55c 100644 --- a/vulkano/src/swapchain/mod.rs +++ b/vulkano/src/swapchain/mod.rs @@ -317,33 +317,19 @@ //! ``` //! -pub use self::present_region::PresentRegion; -pub use self::present_region::RectangleLayer; -pub use self::surface::ColorSpace; -pub use self::surface::CompositeAlpha; -pub use self::surface::PresentMode; -pub use self::surface::SupportedCompositeAlpha; -pub use self::surface::SupportedSurfaceTransforms; -pub use self::surface::Surface; -pub use self::surface::SurfaceApi; -pub use self::surface::SurfaceCapabilities; -pub use self::surface::SurfaceCreationError; -pub use self::surface::SurfaceInfo; -pub use self::surface::SurfaceTransform; -pub use self::swapchain::acquire_next_image; -pub use self::swapchain::acquire_next_image_raw; -pub use self::swapchain::present; -pub use self::swapchain::present_incremental; -pub use self::swapchain::AcquireError; -pub use self::swapchain::AcquiredImage; -pub use self::swapchain::FullScreenExclusive; -pub use self::swapchain::FullScreenExclusiveError; -pub use self::swapchain::PresentFuture; -pub use self::swapchain::Swapchain; -pub use self::swapchain::SwapchainAcquireFuture; -pub use self::swapchain::SwapchainCreateInfo; -pub use self::swapchain::SwapchainCreationError; -pub use self::swapchain::Win32Monitor; +pub use self::{ + present_region::{PresentRegion, RectangleLayer}, + surface::{ + ColorSpace, CompositeAlpha, PresentMode, SupportedCompositeAlpha, + SupportedSurfaceTransforms, Surface, SurfaceApi, SurfaceCapabilities, SurfaceCreationError, + SurfaceInfo, SurfaceTransform, + }, + swapchain::{ + acquire_next_image, acquire_next_image_raw, present, present_incremental, AcquireError, + AcquiredImage, FullScreenExclusive, FullScreenExclusiveError, PresentFuture, Swapchain, + SwapchainAcquireFuture, SwapchainCreateInfo, SwapchainCreationError, Win32Monitor, + }, +}; use std::sync::atomic::AtomicBool; pub mod display; diff --git a/vulkano/src/swapchain/surface.rs b/vulkano/src/swapchain/surface.rs index 10b93de8..31b67d85 100644 --- a/vulkano/src/swapchain/surface.rs +++ b/vulkano/src/swapchain/surface.rs @@ -7,25 +7,25 @@ // notice may not be copied, modified, or distributed except // according to those terms. -use super::FullScreenExclusive; -use super::Win32Monitor; -use crate::check_errors; -use crate::image::ImageUsage; -use crate::instance::Instance; -use crate::swapchain::display::DisplayMode; -use crate::swapchain::display::DisplayPlane; -use crate::swapchain::SurfaceSwapchainLock; -use crate::Error; -use crate::OomError; -use crate::VulkanObject; -use std::error; -use std::fmt; -use std::hash::{Hash, Hasher}; -use std::mem::MaybeUninit; -use std::os::raw::c_ulong; -use std::ptr; -use std::sync::atomic::AtomicBool; -use std::sync::Arc; +use super::{FullScreenExclusive, Win32Monitor}; +use crate::{ + check_errors, + image::ImageUsage, + instance::Instance, + swapchain::{ + display::{DisplayMode, DisplayPlane}, + SurfaceSwapchainLock, + }, + Error, OomError, VulkanObject, +}; +use std::{ + error, fmt, + hash::{Hash, Hasher}, + mem::MaybeUninit, + os::raw::c_ulong, + ptr, + sync::{atomic::AtomicBool, Arc}, +}; /// Represents a surface on the screen. /// @@ -1272,8 +1272,7 @@ pub struct SurfaceCapabilities { #[cfg(test)] mod tests { - use crate::swapchain::Surface; - use crate::swapchain::SurfaceCreationError; + use crate::swapchain::{Surface, SurfaceCreationError}; use std::ptr; #[test] diff --git a/vulkano/src/sync/event.rs b/vulkano/src/sync/event.rs index 7db81460..e1d05d8f 100644 --- a/vulkano/src/sync/event.rs +++ b/vulkano/src/sync/event.rs @@ -239,8 +239,7 @@ impl Default for EventCreateInfo { #[cfg(test)] mod tests { - use crate::sync::Event; - use crate::VulkanObject; + use crate::{sync::Event, VulkanObject}; #[test] fn event_create() { diff --git a/vulkano/src/sync/fence.rs b/vulkano/src/sync/fence.rs index 9d83d33c..c96a9b52 100644 --- a/vulkano/src/sync/fence.rs +++ b/vulkano/src/sync/fence.rs @@ -447,9 +447,10 @@ impl From for FenceWaitError { #[cfg(test)] mod tests { - use crate::sync::fence::FenceCreateInfo; - use crate::sync::Fence; - use crate::VulkanObject; + use crate::{ + sync::{fence::FenceCreateInfo, Fence}, + VulkanObject, + }; use std::time::Duration; #[test] diff --git a/vulkano/src/sync/mod.rs b/vulkano/src/sync/mod.rs index abad44b7..630d36ef 100644 --- a/vulkano/src/sync/mod.rs +++ b/vulkano/src/sync/mod.rs @@ -103,9 +103,6 @@ //! TODO: talk about fence + semaphore simultaneously //! TODO: talk about using fences to clean up -use crate::device::Queue; -use std::sync::Arc; - pub use self::{ event::{Event, EventCreateInfo}, fence::{Fence, FenceCreateInfo, FenceWaitError}, @@ -122,6 +119,8 @@ pub use self::{ ExternalSemaphoreProperties, Semaphore, SemaphoreCreateInfo, SemaphoreCreationError, }, }; +use crate::device::Queue; +use std::sync::Arc; mod event; mod fence;