Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changes regarding naming and API consistency #1946

Merged
merged 4 commits into from
Aug 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .rustfmt.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# imports_granularity = "Crate"
# group_imports = "One"
6 changes: 3 additions & 3 deletions vulkano/src/buffer/cpu_access.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use crate::{
memory::{
pool::{
AllocFromRequirementsFilter, AllocLayout, MappingRequirement, MemoryPoolAlloc,
PotentialDedicatedAllocation, StdMemoryPoolAlloc,
PotentialDedicatedAllocation, StandardMemoryPoolAlloc,
},
DedicatedAllocation, DeviceMemoryAllocationError, MemoryPool,
},
Expand All @@ -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<T, A = PotentialDedicatedAllocation<StdMemoryPoolAlloc>>
pub struct CpuAccessibleBuffer<T, A = PotentialDedicatedAllocation<StandardMemoryPoolAlloc>>
where
T: BufferContents + ?Sized,
{
Expand Down Expand Up @@ -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,
Expand Down
10 changes: 5 additions & 5 deletions vulkano/src/buffer/cpu_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use crate::{
memory::{
pool::{
AllocFromRequirementsFilter, AllocLayout, MappingRequirement, MemoryPoolAlloc,
PotentialDedicatedAllocation, StdMemoryPool,
PotentialDedicatedAllocation, StandardMemoryPool,
},
DedicatedAllocation, DeviceMemoryAllocationError, MemoryPool,
},
Expand Down Expand Up @@ -91,7 +91,7 @@ use std::{
/// }
/// ```
///
pub struct CpuBufferPool<T, A = Arc<StdMemoryPool>>
pub struct CpuBufferPool<T, A = Arc<StandardMemoryPool>>
where
[T]: BufferContents,
A: MemoryPool,
Expand Down Expand Up @@ -196,11 +196,11 @@ where
#[inline]
pub fn new(device: Arc<Device>, usage: BufferUsage) -> CpuBufferPool<T> {
assert!(size_of::<T>() > 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,
Expand Down
7 changes: 4 additions & 3 deletions vulkano/src/buffer/device_local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -122,7 +123,7 @@ use std::{
/// ```
///
#[derive(Debug)]
pub struct DeviceLocalBuffer<T, A = PotentialDedicatedAllocation<StdMemoryPoolAlloc>>
pub struct DeviceLocalBuffer<T, A = PotentialDedicatedAllocation<StandardMemoryPoolAlloc>>
where
T: BufferContents + ?Sized,
{
Expand Down Expand Up @@ -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,
Expand Down
13 changes: 5 additions & 8 deletions vulkano/src/buffer/sys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down Expand Up @@ -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() {
Expand Down
10 changes: 7 additions & 3 deletions vulkano/src/buffer/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
35 changes: 19 additions & 16 deletions vulkano/src/command_buffer/auto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,22 +233,25 @@ impl<L> AutoCommandBufferBuilder<L, StandardCommandPoolBuilder> {
}
}

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)?;

Ok(AutoCommandBufferBuilder {
inner,
pool_builder_alloc,
queue_family_id: queue_family.id(),
render_pass_state,
query_state: HashMap::default(),
inheritance_info,
usage,
_data: PhantomData,
})
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.");

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(
Expand Down
46 changes: 23 additions & 23 deletions vulkano/src/command_buffer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,36 +89,36 @@
//! 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,
CommandBufferBeginError, DispatchError, DispatchIndirectError, DrawError, DrawIndexedError,
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,
Expand Down
59 changes: 32 additions & 27 deletions vulkano/src/command_buffer/pool/standard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

let cb = pool
.allocate(CommandBufferLevel::Primary, 1)
.unwrap()
.next()
.unwrap();
let raw = cb.inner().internal_object();
drop(cb);
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 cb2 = 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();
assert_eq!(raw, cb2.inner().internal_object());
}

#[test]
Expand All @@ -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)
.unwrap()
.next()
device
.with_standard_command_pool(queue.family(), |pool| {
pool.allocate(CommandBufferLevel::Primary, 1)
.unwrap()
.next()
.unwrap()
.inner
})
.unwrap()
.inner
}
});

Expand Down
25 changes: 10 additions & 15 deletions vulkano/src/command_buffer/submit/bind_sparse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
21 changes: 10 additions & 11 deletions vulkano/src/command_buffer/submit/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading