Struct DeviceMemory

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

A region of device memory.

§Destruction

Dropping this DeviceMemory will cause Device::free_memory to be called, automatically releasing any resources associated with it.

Implementations§

Source§

impl DeviceMemory

Source

pub fn builder<'b>() -> DeviceMemoryBuilder<'b>

Returns a new DeviceMemoryBuilder.

Source

pub fn new( device: Device, allocation_size: u64, memory_type_index: u32, ) -> VdResult<DeviceMemory>

Returns a new DeviceMemory.

Source

pub unsafe fn map_to_ptr<T>( &self, offset_bytes: u64, size_bytes: u64, flags: MemoryMapFlags, ) -> VdResult<*mut T>

Maps a region of this memory object to a pointer.

Use ::unmap_ptr to unmap this memory.

The flags argument is reserved for future use and is ignored.

Source

pub unsafe fn unmap_ptr(&self)

Unmaps memory.

Do not use this unless memory was mapped using ::map_to_ptr.

Use ::unmap to unmap memory mapped by ::map.

Source

pub unsafe fn map<'m, T>( &'m self, offset_bytes: u64, size_bytes: u64, flags: MemoryMapFlags, ) -> VdResult<MemoryMapping<'m, T>>

Maps a region of memory and returns a mutable reference to it.

Use ::unmap to unmap.

Use ::copy_from_slice on the returned slice to easily copy data into the mapped memory.

§Example
let mut mem = self.uniform_buffer_memory.map(0, ubo_bytes, 0)?;
mem.copy_from_slice(&[ubo]);
self.uniform_buffer_memory.unmap(mem);

Note/Reminder: The above example uses a dedicated buffer and memory allocation for demonstration purposes. It is best practice to allocate all memory from one large buffer and use offsets to specify particular parts.

The flags argument is reserved for future use and is ignored.

§Safety

The caller must ensure that care is taken when mapping a buffer multiple times simultaneously. Use an appropriate synchronization mechanism such as a std::sync::atomic::AtomicBool (in the simplest case) to help coordinate this.

The caller must also ensure that:

  • offset_bytes plus size_bytes is less than the size of this region of memory.
  • This memory region has been created with the MemoryPropertyFlags::HOST_VISIBLE flag.
Source

pub fn unmap<'m, T>(&self, mapping: MemoryMapping<'m, T>)

Unmaps memory.

Source

pub fn handle(&self) -> DeviceMemoryHandle

Returns this object’s handle.

Source

pub fn device(&self) -> &Device

Returns a reference to the associated device.

Trait Implementations§

Source§

impl Clone for DeviceMemory

Source§

fn clone(&self) -> DeviceMemory

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 DeviceMemory

Source§

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

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

impl<'h> Handle for &'h DeviceMemory

Auto Trait Implementations§

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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 T
where 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 T
where T: Clone,

Source§

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 T
where U: Into<T>,

Source§

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 T
where U: TryFrom<T>,

Source§

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.