pub struct DeviceMemory { /* private fields */ }
Expand description

Represents memory that has been allocated from the device.

The destructor of DeviceMemory automatically frees the memory.

Examples

use vulkano::memory::{DeviceMemory, MemoryAllocateInfo};

let memory_type_index = 0;

// Allocates 1KB of memory.
let memory = DeviceMemory::allocate(
    device.clone(),
    MemoryAllocateInfo {
        allocation_size: 1024,
        memory_type_index,
        ..Default::default()
    },
)
.unwrap();

Implementations§

source§

impl DeviceMemory

source

pub fn allocate( device: Arc<Device>, allocate_info: MemoryAllocateInfo<'_> ) -> Result<Self, Validated<VulkanError>>

Allocates a block of memory from the device.

Some platforms may have a limit on the maximum size of a single allocation. For example, certain systems may fail to create allocations with a size greater than or equal to 4GB.

Panics
  • Panics if allocate_info.dedicated_allocation is Some and the contained buffer or image does not belong to device.
source

pub unsafe fn import( device: Arc<Device>, allocate_info: MemoryAllocateInfo<'_>, import_info: MemoryImportInfo ) -> Result<Self, Validated<VulkanError>>

Imports a block of memory from an external source.

Safety
Panics
  • Panics if allocate_info.dedicated_allocation is Some and the contained buffer or image does not belong to device.
source

pub unsafe fn from_handle( device: Arc<Device>, handle: DeviceMemory, allocate_info: MemoryAllocateInfo<'_> ) -> Self

Creates a new DeviceMemory from a raw object handle.

Safety
  • handle must be a valid Vulkan object handle created from device.
  • allocate_info must match the info used to create the object.
source

pub fn memory_type_index(&self) -> u32

Returns the index of the memory type that this memory was allocated from.

source

pub fn allocation_size(&self) -> DeviceSize

Returns the size in bytes of the memory allocation.

source

pub fn is_dedicated(&self) -> bool

Returns true if the memory is a dedicated to a resource.

source

pub fn export_handle_types(&self) -> ExternalMemoryHandleTypes

Returns the handle types that can be exported from the memory allocation.

source

pub fn imported_handle_type(&self) -> Option<ExternalMemoryHandleType>

Returns the handle type that the memory allocation was imported from, if any.

source

pub fn flags(&self) -> MemoryAllocateFlags

Returns the flags the memory was allocated with.

source

pub fn mapping_state(&self) -> Option<&MappingState>

Returns the current mapping state, or None if the memory is not currently host-mapped.

source

pub fn map( &mut self, map_info: MemoryMapInfo ) -> Result<(), Validated<VulkanError>>

Maps a range of memory to be accessed by the host.

self must not be host-mapped already and must be allocated from host-visible memory.

source

pub fn unmap( &mut self, unmap_info: MemoryUnmapInfo ) -> Result<(), Validated<VulkanError>>

Unmaps the memory. It will no longer be accessible from the host.

self must be currently host-mapped.

source

pub unsafe fn invalidate_range( &self, memory_range: MappedMemoryRange ) -> Result<(), Validated<VulkanError>>

Invalidates the host cache for a range of mapped memory.

If the device memory is not host-coherent, you must call this function before the memory is read by the host, if the device previously wrote to the memory. It has no effect if the memory is host-coherent.

Safety
  • If there are memory writes by the device that have not been propagated into the host cache, then there must not be any references in Rust code to any portion of the specified memory_range.
source

pub unsafe fn flush_range( &self, memory_range: MappedMemoryRange ) -> Result<(), Validated<VulkanError>>

Flushes the host cache for a range of mapped memory.

If the device memory is not host-coherent, you must call this function after writing to the memory, if the device is going to read the memory. It has no effect if the memory is host-coherent.

Safety
  • There must be no operations pending or executing in a device queue, that access the specified memory_range.
source

pub fn commitment(&self) -> Result<DeviceSize, Box<ValidationError>>

Retrieves the amount of lazily-allocated memory that is currently commited to this memory object.

The device may change this value at any time, and the returned value may be already out-of-date.

self must have been allocated from a memory type that has the LAZILY_ALLOCATED flag set.

source

pub fn export_fd( &self, handle_type: ExternalMemoryHandleType ) -> Result<File, Validated<VulkanError>>

Exports the device memory into a Unix file descriptor. The caller owns the returned File.

Panics
  • Panics if the user requests an invalid handle type for this device memory object.

Trait Implementations§

source§

impl AsMut<DeviceMemory> for MappedDeviceMemory

source§

fn as_mut(&mut self) -> &mut DeviceMemory

Converts this type into a mutable reference of the (usually inferred) input type.
source§

impl AsRef<DeviceMemory> for MappedDeviceMemory

source§

fn as_ref(&self) -> &DeviceMemory

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl Debug for DeviceMemory

source§

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

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

impl DeviceOwned for DeviceMemory

source§

fn device(&self) -> &Arc<Device>

Returns the device that owns self.
source§

impl Drop for DeviceMemory

source§

fn drop(&mut self)

Executes the destructor for this type. Read more
source§

impl Hash for DeviceMemory

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 DeviceMemory

source§

fn eq(&self, other: &Self) -> 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 VulkanObject for DeviceMemory

§

type Handle = DeviceMemory

The type of the object.
source§

fn handle(&self) -> Self::Handle

Returns the raw Vulkan handle of the object.
source§

impl Eq for DeviceMemory

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> DeviceOwnedVulkanObject for Twhere T: DeviceOwned + VulkanObject,

source§

fn set_debug_utils_object_name( &self, object_name: Option<&str> ) -> Result<(), VulkanError>

Assigns a human-readable name to the object for debugging purposes. 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, 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.