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

Memory allocations are portions of memory that are reserved for a specific resource or purpose.

There’s a few ways you can obtain a MemoryAlloc in Vulkano. Most commonly you will probably want to use a memory allocator. If you already have a DeviceMemory block on hand that you would like to turn into an allocation, you can use the constructor. Lastly, you can use a suballocator if you want to create multiple smaller allocations out of a bigger one.

Implementations

Creates a new MemoryAlloc.

The memory is mapped automatically if it’s host-visible.

Returns the offset of the allocation within the DeviceMemory block.

Returns the size of the allocation.

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

Returns the mapped pointer to the start of the allocation if the memory is host-visible, otherwise returns None.

Returns a mapped slice to the data within the allocation if the memory is host-visible, otherwise returns None.

Safety
  • While the returned slice exists, there must be no operations pending or executing in a GPU queue that write to the same memory.

Returns a mapped mutable slice to the data within the allocation if the memory is host-visible, otherwise returns None.

Safety
  • While the returned slice exists, there must be no operations pending or executing in a GPU queue that access the same memory.

Invalidates the host (CPU) cache for a range of the allocation.

You must call this method before the memory is read by the host, if the device previously wrote to the memory. It has no effect if the memory is not mapped or if the memory is host-coherent.

range is specified in bytes relative to the start of the allocation. The start and end of range must be a multiple of the non_coherent_atom_size device property, but range.end can also equal to self.size().

Safety
  • If there are memory writes by the GPU that have not been propagated into the CPU cache, then there must not be any references in Rust code to the specified range of the memory.
Panics
  • Panics if range is empty.
  • Panics if range.end exceeds self.size.
  • Panics if range.start or range.end are not a multiple of the non_coherent_atom_size.

Flushes the host (CPU) cache for a range of the allocation.

You must call this method after writing to the memory from the host, if the device is going to read the memory. It has no effect if the memory is not mapped or if the memory is host-coherent.

range is specified in bytes relative to the start of the allocation. The start and end of range must be a multiple of the non_coherent_atom_size device property, but range.end can also equal to self.size().

Safety
  • There must be no operations pending or executing in a GPU queue that access the specified range of the memory.
Panics
  • Panics if range is empty.
  • Panics if range.end exceeds self.size.
  • Panics if range.start or range.end are not a multiple of the non_coherent_atom_size.

Returns the underlying block of DeviceMemory.

Returns the parent allocation if this allocation is a suballocation, otherwise returns None.

Returns true if this allocation is the root of the memory hierarchy.

Returns true if this allocation is a dedicated allocation.

Returns the underlying block of DeviceMemory if this allocation is the root allocation and is not aliased, otherwise returns the allocation back wrapped in Err.

Duplicates the allocation, creating aliased memory. Returns None if the allocation is a dedicated allocation.

You might consider using this method if you want to optimize memory usage by aliasing render targets for example, in which case you will have to double and triple check that the memory is not used concurrently unless it only involves reading. You are highly discouraged from doing this unless you have a reason to.

Safety
  • You must ensure memory accesses are synchronized yourself.

Increases the offset of the allocation by the specified amount and shrinks its size by the same amount.

Panics
  • Panics if the amount exceeds the size of the allocation.

Shrinks the size of the allocation to the specified new_size.

Panics
  • Panics if the new_size exceeds the current size of the allocation.

Sets the offset of the allocation without checking for memory aliasing.

See also shift, which moves the offset safely.

Safety
  • You must ensure that the allocation doesn’t alias any other allocations within the DeviceMemory block, and if it does, then you must ensure memory accesses are synchronized yourself.
  • You must ensure the allocation still fits inside the DeviceMemory block.

Sets the size of the allocation without checking for memory aliasing.

See also shrink, which sets the size safely.

Safety
  • You must ensure that the allocation doesn’t alias any other allocations within the DeviceMemory block, and if it does, then you must ensure memory accesses are synchronized yourself.
  • You must ensure the allocation still fits inside the DeviceMemory block.

Sets the allocation type.

This might cause memory aliasing due to buffer-image granularity conflicts if the allocation type is Linear or NonLinear and is changed to a different one.

Safety
  • You must ensure that the allocation doesn’t alias any other allocations within the DeviceMemory block, and if it does, then you must ensure memory accesses are synchronized yourself.

Trait Implementations

Formats the value using the given formatter. Read more
Returns the device that owns Self.
Executes the destructor for this type. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.