Skip to content

Commit

Permalink
Clean up in-crate use statements
Browse files Browse the repository at this point in the history
  • Loading branch information
MarijnS95 committed Feb 12, 2025
1 parent b0d15c6 commit 2ec2298
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 27 deletions.
14 changes: 8 additions & 6 deletions src/d3d12/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@ mod visualizer;
#[cfg(feature = "visualizer")]
pub use visualizer::AllocatorVisualizer;

use super::{allocator, allocator::AllocationType};
use crate::{
allocator::{AllocatorReport, MemoryBlockReport},
allocator::{
AllocationType, AllocatorReport, DedicatedBlockAllocator, FreeListAllocator,
MemoryBlockReport, SubAllocator,
},
AllocationError, AllocationSizes, AllocatorDebugSettings, MemoryLocation, Result,
};

Expand Down Expand Up @@ -257,7 +259,7 @@ impl Allocation {
struct MemoryBlock {
heap: ID3D12Heap,
size: u64,
sub_allocator: Box<dyn allocator::SubAllocator>,
sub_allocator: Box<dyn SubAllocator>,
}
impl MemoryBlock {
fn new(
Expand Down Expand Up @@ -297,10 +299,10 @@ impl MemoryBlock {
}?
};

let sub_allocator: Box<dyn allocator::SubAllocator> = if dedicated {
Box::new(allocator::DedicatedBlockAllocator::new(size))
let sub_allocator: Box<dyn SubAllocator> = if dedicated {
Box::new(DedicatedBlockAllocator::new(size))
} else {
Box::new(allocator::FreeListAllocator::new(size))
Box::new(FreeListAllocator::new(size))
};

Ok(Self {
Expand Down
25 changes: 14 additions & 11 deletions src/metal/mod.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
use std::{backtrace::Backtrace, sync::Arc};

#[cfg(feature = "visualizer")]
mod visualizer;
#[cfg(feature = "visualizer")]
pub use visualizer::AllocatorVisualizer;

use log::debug;
use objc2::{rc::Retained, runtime::ProtocolObject};
use objc2_foundation::NSString;
Expand All @@ -13,8 +8,16 @@ use objc2_metal::{
MTLStorageMode, MTLTextureDescriptor,
};

#[cfg(feature = "visualizer")]
mod visualizer;
#[cfg(feature = "visualizer")]
pub use visualizer::AllocatorVisualizer;

use crate::{
allocator::{self, AllocatorReport, MemoryBlockReport},
allocator::{
AllocationType, AllocatorReport, DedicatedBlockAllocator, FreeListAllocator,
MemoryBlockReport, SubAllocator,
},
AllocationError, AllocationSizes, AllocatorDebugSettings, MemoryLocation, Result,
};

Expand Down Expand Up @@ -175,7 +178,7 @@ pub struct CommittedAllocationStatistics {
struct MemoryBlock {
heap: Retained<ProtocolObject<dyn MTLHeap>>,
size: u64,
sub_allocator: Box<dyn allocator::SubAllocator>,
sub_allocator: Box<dyn SubAllocator>,
}

impl MemoryBlock {
Expand All @@ -196,10 +199,10 @@ impl MemoryBlock {
"MemoryBlock {memory_location:?}"
))));

let sub_allocator: Box<dyn allocator::SubAllocator> = if dedicated {
Box::new(allocator::DedicatedBlockAllocator::new(size))
let sub_allocator: Box<dyn SubAllocator> = if dedicated {
Box::new(DedicatedBlockAllocator::new(size))
} else {
Box::new(allocator::FreeListAllocator::new(size))
Box::new(FreeListAllocator::new(size))
};

Ok(Self {
Expand Down Expand Up @@ -228,7 +231,7 @@ impl MemoryType {
backtrace: Arc<Backtrace>,
allocation_sizes: &AllocationSizes,
) -> Result<Allocation> {
let allocation_type = allocator::AllocationType::Linear;
let allocation_type = AllocationType::Linear;

let is_host = self.heap_properties.storageMode() != MTLStorageMode::Private;
let memblock_size = allocation_sizes.get_memblock_size(is_host, self.active_general_blocks);
Expand Down
23 changes: 13 additions & 10 deletions src/vulkan/mod.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
#[cfg(feature = "visualizer")]
mod visualizer;
use std::{backtrace::Backtrace, fmt, marker::PhantomData, sync::Arc};

use ash::vk;
use log::{debug, Level};

#[cfg(feature = "visualizer")]
mod visualizer;
#[cfg(feature = "visualizer")]
pub use visualizer::AllocatorVisualizer;

use super::allocator;
use crate::{
allocator::{AllocatorReport, MemoryBlockReport},
allocator::{
AllocationType, AllocatorReport, DedicatedBlockAllocator, FreeListAllocator,
MemoryBlockReport, SubAllocator,
},
AllocationError, AllocationSizes, AllocatorDebugSettings, MemoryLocation, Result,
};

Expand Down Expand Up @@ -337,7 +340,7 @@ pub(crate) struct MemoryBlock {
pub(crate) device_memory: vk::DeviceMemory,
pub(crate) size: u64,
pub(crate) mapped_ptr: Option<SendSyncPtr>,
pub(crate) sub_allocator: Box<dyn allocator::SubAllocator>,
pub(crate) sub_allocator: Box<dyn SubAllocator>,
#[cfg(feature = "visualizer")]
pub(crate) dedicated_allocation: bool,
}
Expand Down Expand Up @@ -411,13 +414,13 @@ impl MemoryBlock {
})
.transpose()?;

let sub_allocator: Box<dyn allocator::SubAllocator> = if allocation_scheme
let sub_allocator: Box<dyn SubAllocator> = if allocation_scheme
!= AllocationScheme::GpuAllocatorManaged
|| requires_personal_block
{
Box::new(allocator::DedicatedBlockAllocator::new(size))
Box::new(DedicatedBlockAllocator::new(size))
} else {
Box::new(allocator::FreeListAllocator::new(size))
Box::new(FreeListAllocator::new(size))
};

Ok(Self {
Expand Down Expand Up @@ -460,9 +463,9 @@ impl MemoryType {
allocation_sizes: &AllocationSizes,
) -> Result<Allocation> {
let allocation_type = if desc.linear {
allocator::AllocationType::Linear
AllocationType::Linear
} else {
allocator::AllocationType::NonLinear
AllocationType::NonLinear
};

let is_host = self
Expand Down

0 comments on commit 2ec2298

Please sign in to comment.