Struct vulkano::memory::ResourceMemory
source · 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
impl ResourceMemory
sourcepub fn new_dedicated(device_memory: DeviceMemory) -> Self
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.
sourcepub unsafe fn from_allocation(
allocator: Arc<dyn MemoryAllocator>,
allocation: MemoryAlloc
) -> Self
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 ofallocator
.allocation
must never be deallocated.
sourcepub fn device_memory(&self) -> &Arc<DeviceMemory>
pub fn device_memory(&self) -> &Arc<DeviceMemory>
Returns the underlying block of DeviceMemory
.
sourcepub fn offset(&self) -> DeviceSize
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
.
sourcepub fn size(&self) -> DeviceSize
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.
sourcepub fn allocation_type(&self) -> AllocationType
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
.
sourcepub fn mapped_slice(
&self,
range: impl RangeBounds<DeviceSize>
) -> Option<Result<NonNull<[u8]>, HostAccessError>>
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.
sourcepub unsafe fn invalidate_range(
&self,
memory_range: MappedMemoryRange
) -> Result<(), Validated<VulkanError>>
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
.
sourcepub unsafe fn flush_range(
&self,
memory_range: MappedMemoryRange
) -> Result<(), Validated<VulkanError>>
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
.