pub struct DeviceLayout { /* private fields */ }Expand description
Vulkan analog of std’s Layout, represented using DeviceSizes.
Unlike Layouts, DeviceLayouts are required to have non-zero size.
Implementations§
Source§impl DeviceLayout
impl DeviceLayout
Sourcepub const MAX_SIZE: u64 = 9_223_372_036_854_775_807u64
pub const MAX_SIZE: u64 = 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<DeviceLayout, TryFromLayoutError>
pub const fn from_layout( layout: Layout, ) -> Result<DeviceLayout, 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: u64,
alignment: u64,
) -> Option<DeviceLayout>
pub const fn from_size_alignment( size: u64, alignment: u64, ) -> Option<DeviceLayout>
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: NonZero<u64>,
alignment: DeviceAlignment,
) -> Option<DeviceLayout>
pub const fn new( size: NonZero<u64>, alignment: DeviceAlignment, ) -> Option<DeviceLayout>
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) -> u64
pub const fn size(&self) -> u64
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<DeviceLayout>
pub const fn align_to(&self, alignment: DeviceAlignment) -> Option<DeviceLayout>
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) -> u64
pub const fn padding_needed_for(&self, alignment: DeviceAlignment) -> u64
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) -> DeviceLayout
pub const fn pad_to_alignment(&self) -> DeviceLayout
Creates a new DeviceLayout by rounding up self.size() to the nearest multiple of
self.alignment().
Sourcepub const fn repeat(&self, n: NonZero<u64>) -> Option<(DeviceLayout, u64)>
pub const fn repeat(&self, n: NonZero<u64>) -> Option<(DeviceLayout, u64)>
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: DeviceLayout) -> Option<(DeviceLayout, u64)>
pub const fn extend(&self, next: DeviceLayout) -> Option<(DeviceLayout, u64)>
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<(DeviceLayout, u64)>
pub const fn extend_with_layout( &self, next: Layout, ) -> Option<(DeviceLayout, u64)>
Sourcepub const fn extend_from_layout(
self,
previous: &Layout,
) -> Option<(DeviceLayout, u64)>
pub const fn extend_from_layout( self, previous: &Layout, ) -> Option<(DeviceLayout, u64)>
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 more