Skip to content

Commit

Permalink
Add Suballocation[Node]::as[_usize]_range (#2586)
Browse files Browse the repository at this point in the history
  • Loading branch information
marc0246 authored Oct 22, 2024
1 parent 303bdfc commit 8a365cf
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions vulkano/src/memory/allocator/suballocator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use crate::{image::ImageTiling, DeviceSize};
use std::{
error::Error,
fmt::{self, Debug, Display},
ops::Range,
};

mod buddy;
Expand Down Expand Up @@ -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<DeviceSize> {
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<usize> {
self.offset as usize..(self.offset + self.size) as usize
}
}

/// Error that can be returned when creating an [allocation] using a [suballocator].
///
/// [allocation]: Suballocation
Expand Down Expand Up @@ -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<DeviceSize> {
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<usize> {
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.
Expand Down

0 comments on commit 8a365cf

Please sign in to comment.