Skip to content
New issue

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

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

Already on GitHub? # to your account

Move the allocation_type field to Suballocation, since AllocationType is unique to suballocations #2327

Merged
merged 1 commit into from
Sep 12, 2023
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
10 changes: 0 additions & 10 deletions vulkano/src/memory/allocator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -692,14 +692,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 @@ -1419,7 +1411,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 @@ -1543,7 +1534,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 @@ -188,6 +188,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 @@ -385,6 +389,7 @@ unsafe impl Suballocator for FreeListAllocator {
return Ok(Suballocation {
offset,
size,
allocation_type,
handle: AllocationHandle(id.get() as _),
});
}
Expand Down Expand Up @@ -866,6 +871,7 @@ unsafe impl Suballocator for BuddyAllocator {
return Ok(Suballocation {
offset,
size: layout.size(),
allocation_type,
handle: AllocationHandle(min_order as _),
});
}
Expand Down Expand Up @@ -1071,6 +1077,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