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
impl DeviceMemory
Sourcepub fn builder<'b>() -> DeviceMemoryBuilder<'b>
pub fn builder<'b>() -> DeviceMemoryBuilder<'b>
Returns a new DeviceMemoryBuilder
.
Sourcepub fn new(
device: Device,
allocation_size: u64,
memory_type_index: u32,
) -> VdResult<DeviceMemory>
pub fn new( device: Device, allocation_size: u64, memory_type_index: u32, ) -> VdResult<DeviceMemory>
Returns a new DeviceMemory
.
Sourcepub unsafe fn map_to_ptr<T>(
&self,
offset_bytes: u64,
size_bytes: u64,
flags: MemoryMapFlags,
) -> VdResult<*mut T>
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.
Sourcepub unsafe fn unmap_ptr(&self)
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
.
Sourcepub unsafe fn map<'m, T>(
&'m self,
offset_bytes: u64,
size_bytes: u64,
flags: MemoryMapFlags,
) -> VdResult<MemoryMapping<'m, T>>
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
plussize_bytes
is less than the size of this region of memory.- This memory region has been created with the
MemoryPropertyFlags::HOST_VISIBLE
flag.
Sourcepub fn handle(&self) -> DeviceMemoryHandle
pub fn handle(&self) -> DeviceMemoryHandle
Returns this object’s handle.
Trait Implementations§
Source§impl Clone for DeviceMemory
impl Clone for DeviceMemory
Source§fn clone(&self) -> DeviceMemory
fn clone(&self) -> DeviceMemory
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more