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

source

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.

source

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.

source

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.

source

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.

source

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.

source

pub const fn size(&self) -> DeviceSize

Returns the minimum size in bytes for a memory block of this layout.

source

pub const fn alignment(&self) -> DeviceAlignment

Returns the minimum alignment for a memory block of this layout.

source

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.

source

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.

source

pub const fn pad_to_alignment(&self) -> Self

Creates a new DeviceLayout by rounding up self.size() to the nearest multiple of self.alignment().

source

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.

source

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.

source

pub const fn extend_with_layout( &self, next: Layout ) -> Option<(Self, DeviceSize)>

Same as extend, except it extends with a Layout.

source

pub const fn extend_from_layout( self, previous: &Layout ) -> Option<(Self, DeviceSize)>

Creates a new DeviceLayout describing the record for the previous Layout followed by self. This function is otherwise the same as extend.

Trait Implementations§

source§

impl Clone for DeviceLayout

source§

fn clone(&self) -> DeviceLayout

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for DeviceLayout

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Hash for DeviceLayout

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl PartialEq for DeviceLayout

source§

fn eq(&self, other: &DeviceLayout) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl TryFrom<DeviceLayout> for Layout

§

type Error = TryFromDeviceLayoutError

The type returned in the event of a conversion error.
source§

fn try_from(device_layout: DeviceLayout) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<Layout> for DeviceLayout

§

type Error = TryFromLayoutError

The type returned in the event of a conversion error.
source§

fn try_from(layout: Layout) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl Copy for DeviceLayout

source§

impl Eq for DeviceLayout

source§

impl StructuralEq for DeviceLayout

source§

impl StructuralPartialEq for DeviceLayout

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.