gpu_alloc

Struct MemoryBlock

Source
pub struct MemoryBlock<M> { /* private fields */ }
Expand description

Memory block allocated by GpuAllocator.

Implementations§

Source§

impl<M> MemoryBlock<M>

Source

pub fn memory(&self) -> &M

Returns reference to parent memory object.

Source

pub fn offset(&self) -> u64

Returns offset in bytes from start of memory object to start of this block.

Source

pub fn size(&self) -> u64

Returns size of this memory block.

Source

pub fn props(&self) -> MemoryPropertyFlags

Returns memory property flags for parent memory object.

Source

pub fn memory_type(&self) -> u32

Returns index of type of parent memory object.

Source

pub unsafe fn map( &mut self, device: &impl MemoryDevice<M>, offset: u64, size: usize, ) -> Result<NonNull<u8>, MapError>

Returns pointer to mapped memory range of this block. This blocks becomes mapped.

The user of returned pointer must guarantee that any previously submitted command that writes to this range has completed before the host reads from or writes to that range, and that any previously submitted command that reads from that range has completed before the host writes to that region. If the device memory was allocated without the HOST_COHERENT property flag set, these guarantees must be made for an extended range: the user must round down the start of the range to the nearest multiple of non_coherent_atom_size, and round the end of the range up to the nearest multiple of non_coherent_atom_size.

§Panics

This function panics if block is currently mapped.

§Safety

block must have been allocated from specified device.

Source

pub unsafe fn unmap(&mut self, device: &impl MemoryDevice<M>) -> bool

Unmaps memory range of this block that was previously mapped with Block::map. This block becomes unmapped.

§Panics

This function panics if this block is not currently mapped.

§Safety

block must have been allocated from specified device.

Source

pub unsafe fn write_bytes( &mut self, device: &impl MemoryDevice<M>, offset: u64, data: &[u8], ) -> Result<(), MapError>

Transiently maps block memory range and copies specified data to the mapped memory range.

§Panics

This function panics if block is currently mapped.

§Safety

block must have been allocated from specified device. The caller must guarantee that any previously submitted command that reads or writes to this range has completed.

Source

pub unsafe fn read_bytes( &mut self, device: &impl MemoryDevice<M>, offset: u64, data: &mut [u8], ) -> Result<(), MapError>

Transiently maps block memory range and copies specified data from the mapped memory range.

§Panics

This function panics if block is currently mapped.

§Safety

block must have been allocated from specified device. The caller must guarantee that any previously submitted command that reads to this range has completed.

Trait Implementations§

Source§

impl<M: Debug> Debug for MemoryBlock<M>

Source§

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

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

impl<M> Send for MemoryBlock<M>
where M: Send,

Source§

impl<M> Sync for MemoryBlock<M>
where M: Sync,

Auto Trait Implementations§

§

impl<M> Freeze for MemoryBlock<M>
where M: Freeze,

§

impl<M> RefUnwindSafe for MemoryBlock<M>
where M: RefUnwindSafe,

§

impl<M> Unpin for MemoryBlock<M>
where M: Unpin,

§

impl<M> UnwindSafe for MemoryBlock<M>

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> 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, 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.