Struct vulkano::memory::allocator::DeviceLayout
source · pub struct DeviceLayout { /* private fields */ }
Expand description
Vulkan analog of std’s Layout
, represented using DeviceSize
s.
Unlike Layout
s, DeviceLayout
s are required to have non-zero size.
Implementations§
source§impl DeviceLayout
impl DeviceLayout
sourcepub const MAX_SIZE: DeviceSize = 9_223_372_036_854_775_807u64
pub const MAX_SIZE: DeviceSize = 9_223_372_036_854_775_807u64
The maximum size of a memory block after its layout’s size has been rounded up to the nearest multiple of its layout’s alignment.
This invariant is enforced to avoid arithmetic overflows when constructing layouts and when allocating memory. Any layout that doesn’t uphold this invariant will therefore lead to undefined behavior.
sourcepub const fn from_layout(layout: Layout) -> Result<Self, TryFromLayoutError>
pub const fn from_layout(layout: Layout) -> Result<Self, TryFromLayoutError>
Creates a new DeviceLayout
from a Layout
, or returns an error if the Layout
has
zero size.
sourcepub const fn into_layout(self) -> Result<Layout, TryFromDeviceLayoutError>
pub const fn into_layout(self) -> Result<Layout, TryFromDeviceLayoutError>
Converts the DeviceLayout
into a Layout
, or returns an error if the DeviceLayout
doesn’t meet the invariants of Layout
.
sourcepub const fn from_size_alignment(
size: DeviceSize,
alignment: DeviceSize
) -> Option<Self>
pub const fn from_size_alignment( size: DeviceSize, alignment: DeviceSize ) -> Option<Self>
Creates a new DeviceLayout
from the given size
and alignment
.
Returns None
if size
is zero, alignment
is not a power of two, or if size
would
exceed DeviceLayout::MAX_SIZE
when rounded up to the nearest multiple of alignment
.
sourcepub const fn new(
size: NonZeroDeviceSize,
alignment: DeviceAlignment
) -> Option<Self>
pub const fn new( size: NonZeroDeviceSize, alignment: DeviceAlignment ) -> Option<Self>
Creates a new DeviceLayout
from the given size
and alignment
.
Returns None
if size
would exceed DeviceLayout::MAX_SIZE
when rounded up to the
nearest multiple of alignment
.
sourcepub const fn size(&self) -> DeviceSize
pub const fn size(&self) -> DeviceSize
Returns the minimum size in bytes for a memory block of this layout.
sourcepub const fn alignment(&self) -> DeviceAlignment
pub const fn alignment(&self) -> DeviceAlignment
Returns the minimum alignment for a memory block of this layout.
sourcepub const fn align_to(&self, alignment: DeviceAlignment) -> Option<Self>
pub const fn align_to(&self, alignment: DeviceAlignment) -> Option<Self>
Creates a new DeviceLayout
from self
that is also aligned to alignment
at minimum.
Returns None
if self.size()
would overflow DeviceLayout::MAX_SIZE
when rounded up
to the nearest multiple of alignment
.
sourcepub const fn padding_needed_for(&self, alignment: DeviceAlignment) -> DeviceSize
pub const fn padding_needed_for(&self, alignment: DeviceAlignment) -> DeviceSize
Returns the amount of padding that needs to be added to self.size()
such that the result
is a multiple of alignment
.
sourcepub const fn pad_to_alignment(&self) -> Self
pub const fn pad_to_alignment(&self) -> Self
Creates a new DeviceLayout
by rounding up self.size()
to the nearest multiple of
self.alignment()
.
sourcepub const fn repeat(&self, n: NonZeroDeviceSize) -> Option<(Self, DeviceSize)>
pub const fn repeat(&self, n: NonZeroDeviceSize) -> Option<(Self, DeviceSize)>
Creates a new DeviceLayout
describing the record for n
instances of self
, possibly
with padding at the end of each to ensure correct alignment of all instances.
Returns a tuple consisting of the new layout and the stride, in bytes, of self
, or
returns None
on arithmetic overflow or when the total size would exceed
DeviceLayout::MAX_SIZE
.
sourcepub const fn extend(&self, next: Self) -> Option<(Self, DeviceSize)>
pub const fn extend(&self, next: Self) -> Option<(Self, DeviceSize)>
Creates a new DeviceLayout
describing the record for self
followed by next
, including
potential padding between them to ensure next
will be properly aligned, but without any
trailing padding. You should use pad_to_alignment
after you are done extending the
layout with all fields to get a valid #[repr(C)]
layout.
The alignments of the two layouts get combined by picking the maximum between them.
Returns a tuple consisting of the resulting layout as well as the offset, in bytes, of
next
.
Returns None
on arithmetic overflow or when the total size rounded up to the nearest
multiple of the combined alignment would exceed DeviceLayout::MAX_SIZE
.
sourcepub const fn extend_with_layout(
&self,
next: Layout
) -> Option<(Self, DeviceSize)>
pub const fn extend_with_layout( &self, next: Layout ) -> Option<(Self, DeviceSize)>
sourcepub const fn extend_from_layout(
self,
previous: &Layout
) -> Option<(Self, DeviceSize)>
pub const fn extend_from_layout( self, previous: &Layout ) -> Option<(Self, DeviceSize)>
Trait Implementations§
source§impl Clone for DeviceLayout
impl Clone for DeviceLayout
source§fn clone(&self) -> DeviceLayout
fn clone(&self) -> DeviceLayout
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for DeviceLayout
impl Debug for DeviceLayout
source§impl Hash for DeviceLayout
impl Hash for DeviceLayout
source§impl PartialEq for DeviceLayout
impl PartialEq for DeviceLayout
source§fn eq(&self, other: &DeviceLayout) -> bool
fn eq(&self, other: &DeviceLayout) -> bool
self
and other
values to be equal, and is used
by ==
.