Struct vulkano::memory::MappedDeviceMemory[][src]

pub struct MappedDeviceMemory { /* fields omitted */ }

Represents memory that has been allocated and mapped in CPU accessible space.

Can be obtained with DeviceMemory::alloc_and_map. The function will panic if the memory type is not host-accessible.

In order to access the content of the allocated memory, you can use the read_write method. This method returns a guard object that derefs to the content.

Example

use vulkano::memory::DeviceMemory;

// The memory type must be mappable.
let mem_ty = device.physical_device().memory_types()
                    .filter(|t| t.is_host_visible())
                    .next().unwrap();    // Vk specs guarantee that this can't fail

// Allocates 1KB of memory.
let memory = DeviceMemory::alloc_and_map(device.clone(), mem_ty, 1024).unwrap();

// Get access to the content. Note that this is very unsafe for two reasons: 1) the content is
// uninitialized, and 2) the access is unsynchronized.
unsafe {
    let mut content = memory.read_write::<[u8]>(0 .. 1024);
    content[12] = 54;       // `content` derefs to a `&[u8]` or a `&mut [u8]`
}

Implementations

impl MappedDeviceMemory[src]

pub fn unmap(self) -> DeviceMemory[src]

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

pub unsafe fn read_write<T: ?Sized>(
    &self,
    range: Range<usize>
) -> CpuAccess<'_, T> where
    T: Content
[src]

Gives access to the content of the memory.

This function takes care of calling vkInvalidateMappedMemoryRanges and vkFlushMappedMemoryRanges on the given range. You are therefore encouraged to use the smallest range as possible, and to not call this function multiple times in a row for several small changes.

Safety

  • Type safety is not checked. You must ensure that T corresponds to the content of the buffer.
  • Accesses are not synchronized. Synchronization must be handled outside of the MappedDeviceMemory.

Trait Implementations

impl AsMut<DeviceMemory> for MappedDeviceMemory[src]

fn as_mut(&mut self) -> &mut DeviceMemory[src]

Performs the conversion.

impl AsRef<DeviceMemory> for MappedDeviceMemory[src]

fn as_ref(&self) -> &DeviceMemory[src]

Performs the conversion.

impl Debug for MappedDeviceMemory[src]

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

Formats the value using the given formatter. Read more

impl DeviceOwned for MappedDeviceMemory[src]

fn device(&self) -> &Arc<Device>[src]

Returns the device that owns Self.

impl Send for MappedDeviceMemory[src]

impl Sync for MappedDeviceMemory[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

pub fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

pub fn borrow_mut(&mut self) -> &mut T[src]

Mutably borrows from an owned value. Read more

impl<T> Content for T[src]

pub fn ref_from_ptr(*mut c_void, usize) -> Option<*mut T>[src]

Builds a pointer to this type from a raw pointer.

pub fn is_size_suitable(usize) -> bool[src]

Returns true if the size is suitable to store a type like this.

pub fn indiv_size() -> usize[src]

Returns the size of an individual element.

impl<T> From<T> for T[src]

pub fn from(t: T) -> T[src]

Performs the conversion.

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

pub fn into(self) -> U[src]

Performs the conversion.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

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

Performs the conversion.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

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

Performs the conversion.