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

Memory that can be bound to resources.

Most commonly you will want to obtain this by first using a memory allocator and then [constructing this object from its allocation]. Alternatively, if you want to bind a whole block of DeviceMemory to a resource, or can’t go through an allocator, you can use the dedicated constructor.

Implementations§

source§

impl ResourceMemory

source

pub fn new_dedicated(device_memory: DeviceMemory) -> Self

Creates a new ResourceMemory that has a whole device memory block dedicated to it. You may use this when you obtain the memory in a way other than through the use of a memory allocator, for instance by importing memory.

This is safe because we take ownership of the device memory, so that there can be no aliasing resources. On the other hand, the device memory can never be reused: it will be freed once the returned object is dropped.

source

pub unsafe fn from_allocation( allocator: Arc<dyn MemoryAllocator>, allocation: MemoryAlloc ) -> Self

Creates a new ResourceMemory from an allocation of a memory allocator.

Ownership of allocation is semantically transferred to this object, and it is deallocated when the returned object is dropped.

Safety
  • allocation must refer to a currently allocated allocation of allocator.
  • allocation must never be deallocated.
source

pub fn device_memory(&self) -> &Arc<DeviceMemory>

Returns the underlying block of DeviceMemory.

source

pub fn offset(&self) -> DeviceSize

Returns the offset (in bytes) within the DeviceMemory block where this ResourceMemory beings.

If this ResourceMemory is not a suballocation, then this will be 0.

source

pub fn size(&self) -> DeviceSize

Returns the size (in bytes) of the ResourceMemory.

If this ResourceMemory is not a suballocation, then this will be equal to the [allocation size] of the DeviceMemory block.

source

pub fn allocation_type(&self) -> AllocationType

Returns the type of resources that can be bound to this ResourceMemory.

If this ResourceMemory is not a suballocation, then this will be AllocationType::Unknown.

source

pub fn mapped_slice( &self, range: impl RangeBounds<DeviceSize> ) -> Option<Result<NonNull<[u8]>, HostAccessError>>

Returns the mapped pointer to a range of the ResourceMemory, or returns None if ouf of bounds.

range is specified in bytes relative to the beginning of self and must fall within the range of the memory mapping given to DeviceMemory::map.

See MappingState::slice for the safety invariants of the returned pointer.

source

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

Invalidates the host cache for a range of the ResourceMemory.

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 the ResourceMemory.

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 any portion of the specified memory_range.

Trait Implementations§

source§

impl Debug for ResourceMemory

source§

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

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

impl DeviceOwned for ResourceMemory

source§

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

Returns the device that owns self.
source§

impl Drop for ResourceMemory

source§

fn drop(&mut self)

Executes the destructor for this type. Read more

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