Contents

makeAliasable()

Allows future heap resource allocations to alias against the resource’s memory, reusing it.

Declaration

func makeAliasable()

Discussion

Resource instances marked as aliased have backing memory available for use in new allocations to the heap. One common use case is to make a single large resource aliasable for reuse of memory by smaller and more frequent resource allocations. For situations where you need fine-grained control over your memory management, you might want to use a heap with the allocation type MTLHeapType.placement and manage memory yourself instead.

Aliased resources can’t be un-aliased or moved. If you use an aliased resource instance to read or write data, it results in undefined behavior.

When working with resources possibly backed by aliased memory, you should take great care that the system doesn’t access resources from multiple aliases concurrently. Use an MTLEvent or MTLFence instance to protect access to resources that you’ve either already aliased or intend to alias.

The general process to reuse memory from aliased resources is:

  1. Allocate an MTLHeap instance to hold your task’s resources, using the makeHeap(descriptor:) method. Your heap should be big enough to store the maximum amount of concurrently loaded data you expect.

  2. Allocate your resource(s) using a heap method that returns an MTLResource instance.

  3. Perform your stage on the GPU, and when it completes, mark the resource allocation(s) as aliasable by calling this method.

  4. For each successive stage of your overall pass, repeat steps 2 and 3. Ensure that the prior stage fully completes before making any new resources on an aliasable heap through an event or fence.

See Also

Managing heap resources