From 08b96d8faabee1bfba21a7c4ce469f7aab86ff44 Mon Sep 17 00:00:00 2001 From: marc0246 <40955683+marc0246@users.noreply.github.com> Date: Mon, 11 Sep 2023 21:04:37 +0200 Subject: [PATCH] Move the `allocation_type` field to `Suballocation` --- vulkano/src/memory/allocator/mod.rs | 10 ---------- vulkano/src/memory/allocator/suballocator.rs | 7 +++++++ vulkano/src/memory/mod.rs | 6 +++--- 3 files changed, 10 insertions(+), 13 deletions(-) diff --git a/vulkano/src/memory/allocator/mod.rs b/vulkano/src/memory/allocator/mod.rs index f94ac1b31e..65dd872eb8 100644 --- a/vulkano/src/memory/allocator/mod.rs +++ b/vulkano/src/memory/allocator/mod.rs @@ -692,14 +692,6 @@ pub struct MemoryAlloc { /// allocation. pub suballocation: Option, - /// 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, } @@ -1419,7 +1411,6 @@ unsafe impl MemoryAllocator for GenericMemoryA Ok(MemoryAlloc { device_memory, suballocation: None, - allocation_type: AllocationType::Unknown, allocation_handle: AllocationHandle(ptr::null_mut()), }) } @@ -1543,7 +1534,6 @@ impl Block { Ok(MemoryAlloc { device_memory: self.device_memory.clone(), suballocation: Some(suballocation), - allocation_type, allocation_handle: AllocationHandle(self as *const Block as _), }) } diff --git a/vulkano/src/memory/allocator/suballocator.rs b/vulkano/src/memory/allocator/suballocator.rs index 4400a3a50b..87c5a89d6d 100644 --- a/vulkano/src/memory/allocator/suballocator.rs +++ b/vulkano/src/memory/allocator/suballocator.rs @@ -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, } @@ -385,6 +389,7 @@ unsafe impl Suballocator for FreeListAllocator { return Ok(Suballocation { offset, size, + allocation_type, handle: AllocationHandle(id.get() as _), }); } @@ -866,6 +871,7 @@ unsafe impl Suballocator for BuddyAllocator { return Ok(Suballocation { offset, size: layout.size(), + allocation_type, handle: AllocationHandle(min_order as _), }); } @@ -1071,6 +1077,7 @@ unsafe impl Suballocator for BumpAllocator { Ok(Suballocation { offset, size, + allocation_type, handle: AllocationHandle(ptr::null_mut()), }) } diff --git a/vulkano/src/memory/mod.rs b/vulkano/src/memory/mod.rs index c7d624b94a..5ddccf8051 100644 --- a/vulkano/src/memory/mod.rs +++ b/vulkano/src/memory/mod.rs @@ -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), @@ -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), @@ -242,6 +242,7 @@ impl ResourceMemory { self.suballocation_handle.map(|handle| Suballocation { offset: self.offset, size: self.size, + allocation_type: self.allocation_type, handle, }) } @@ -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, };