Skip to content

Commit

Permalink
Move the allocation_type field to Suballocation (#2327)
Browse files Browse the repository at this point in the history
  • Loading branch information
marc0246 authored Sep 12, 2023
1 parent c43a9c9 commit 7d63f8e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 13 deletions.
10 changes: 0 additions & 10 deletions vulkano/src/memory/allocator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -716,14 +716,6 @@ pub struct MemoryAlloc {
/// allocation.
pub suballocation: Option<Suballocation>,

/// The type of resources that can be bound to this memory block. This will be exactly equal to
/// the requested allocation type.
///
/// For dedicated allocations it doesn't matter what this is, as there aren't going to be any
/// neighboring suballocations. Therefore the allocator implementation is advised to always set
/// this to [`AllocationType::Unknown`] in that case for maximum flexibility.
pub allocation_type: AllocationType,

/// An opaque handle identifying the allocation inside the allocator.
pub allocation_handle: AllocationHandle,
}
Expand Down Expand Up @@ -1443,7 +1435,6 @@ unsafe impl<S: Suballocator + Send + 'static> MemoryAllocator for GenericMemoryA
Ok(MemoryAlloc {
device_memory,
suballocation: None,
allocation_type: AllocationType::Unknown,
allocation_handle: AllocationHandle(ptr::null_mut()),
})
}
Expand Down Expand Up @@ -1567,7 +1558,6 @@ impl<S: Suballocator> Block<S> {
Ok(MemoryAlloc {
device_memory: self.device_memory.clone(),
suballocation: Some(suballocation),
allocation_type,
allocation_handle: AllocationHandle(self as *const Block<S> as _),
})
}
Expand Down
7 changes: 7 additions & 0 deletions vulkano/src/memory/allocator/suballocator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,10 @@ pub struct Suballocation {
/// The size of the allocation. This will be exactly equal to the requested size.
pub size: DeviceSize,

/// The type of resources that can be bound to this memory block. This will be exactly equal to
/// the requested allocation type.
pub allocation_type: AllocationType,

/// An opaque handle identifying the allocation within the allocator.
pub handle: AllocationHandle,
}
Expand Down Expand Up @@ -404,6 +408,7 @@ unsafe impl Suballocator for FreeListAllocator {
return Ok(Suballocation {
offset,
size,
allocation_type,
handle: AllocationHandle(id.get() as _),
});
}
Expand Down Expand Up @@ -885,6 +890,7 @@ unsafe impl Suballocator for BuddyAllocator {
return Ok(Suballocation {
offset,
size: layout.size(),
allocation_type,
handle: AllocationHandle(min_order as _),
});
}
Expand Down Expand Up @@ -1090,6 +1096,7 @@ unsafe impl Suballocator for BumpAllocator {
Ok(Suballocation {
offset,
size,
allocation_type,
handle: AllocationHandle(ptr::null_mut()),
})
}
Expand Down
6 changes: 3 additions & 3 deletions vulkano/src/memory/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ impl ResourceMemory {
ResourceMemory {
offset: suballocation.offset,
size: suballocation.size,
allocation_type: allocation.allocation_type,
allocation_type: suballocation.allocation_type,
allocation_handle: allocation.allocation_handle,
suballocation_handle: Some(suballocation.handle),
allocator: Some(allocator),
Expand All @@ -190,7 +190,7 @@ impl ResourceMemory {
ResourceMemory {
offset: 0,
size: allocation.device_memory.allocation_size(),
allocation_type: allocation.allocation_type,
allocation_type: AllocationType::Unknown,
allocation_handle: allocation.allocation_handle,
suballocation_handle: None,
allocator: Some(allocator),
Expand Down Expand Up @@ -242,6 +242,7 @@ impl ResourceMemory {
self.suballocation_handle.map(|handle| Suballocation {
offset: self.offset,
size: self.size,
allocation_type: self.allocation_type,
handle,
})
}
Expand Down Expand Up @@ -426,7 +427,6 @@ impl Drop for ResourceMemory {
let allocation = MemoryAlloc {
device_memory,
suballocation: self.suballocation(),
allocation_type: self.allocation_type,
allocation_handle: self.allocation_handle,
};

Expand Down

0 comments on commit 7d63f8e

Please # to comment.