diff --git a/vulkano/src/memory/allocator/suballocator/mod.rs b/vulkano/src/memory/allocator/suballocator/mod.rs index f4a8ca6b..727c9062 100644 --- a/vulkano/src/memory/allocator/suballocator/mod.rs +++ b/vulkano/src/memory/allocator/suballocator/mod.rs @@ -12,6 +12,7 @@ use crate::{image::ImageTiling, DeviceSize}; use std::{ error::Error, fmt::{self, Debug, Display}, + ops::Range, }; mod buddy; @@ -287,6 +288,24 @@ pub struct Suballocation { pub handle: AllocationHandle, } +impl Suballocation { + /// Returns the suballocation as a `DeviceSize` range. + /// + /// This is identical to `self.offset..self.offset + self.size`. + #[inline] + pub fn as_range(&self) -> Range { + self.offset..self.offset + self.size + } + + /// Returns the suballocation as a `usize` range. + /// + /// This is identical to `self.offset as usize..(self.offset + self.size) as usize`. + #[inline] + pub fn as_usize_range(&self) -> Range { + self.offset as usize..(self.offset + self.size) as usize + } +} + /// Error that can be returned when creating an [allocation] using a [suballocator]. /// /// [allocation]: Suballocation @@ -331,6 +350,24 @@ pub struct SuballocationNode { pub allocation_type: SuballocationType, } +impl SuballocationNode { + /// Returns the suballocation as a `DeviceSize` range. + /// + /// This is identical to `self.offset..self.offset + self.size`. + #[inline] + pub fn as_range(&self) -> Range { + self.offset..self.offset + self.size + } + + /// Returns the suballocation as a `usize` range. + /// + /// This is identical to `self.offset as usize..(self.offset + self.size) as usize`. + #[inline] + pub fn as_usize_range(&self) -> Range { + self.offset as usize..(self.offset + self.size) as usize + } +} + /// Tells us if an allocation within a [suballocator]'s list/tree of suballocations is free, and if /// not, what type of resources can be bound to it. The suballocator needs to keep track of this in /// order to be able to respect the buffer-image granularity.