Blender V4.3
blender::gpu::MTLSafeFreeList Class Reference

#include <mtl_memory.hh>

Public Member Functions

void flag_in_queue ()
 
 MEM_CXX_CLASS_ALLOC_FUNCS ("MTLSafeFreeList")
 
Memory Management - MTLBufferPool and MTLSafeFreeList implementations
 MTLSafeFreeList ()
 
void insert_buffer (gpu::MTLBuffer *buffer)
 
bool should_flush ()
 
void increment_reference ()
 
void decrement_reference ()
 

Friends

class MTLBufferPool
 

Detailed Description

An MTLSafeFreeList is a temporary list of #gpu::MTLBuffers which have been freed by the high level backend, but are pending GPU work execution before the #gpu::MTLBuffers can be returned to the Memory manager pools. This list is implemented as a chunked linked-list.

Only a single MTLSafeFreeList is active at one time and is associated with current command buffer submissions. If an #MTLBuffer is freed during the lifetime of a command buffer, it could still possibly be in-use and as such, the MTLSafeFreeList will increment its reference count for each command buffer submitted while the current pool is active.

  • Reference count is incremented upon #MTLCommandBuffer commit.
  • Reference count is decremented in the #MTLCommandBuffer completion callback handler.

A new MTLSafeFreeList will begin each render step (frame). This pooling of buffers, rather than individual buffer resource tracking reduces performance overhead.

  • The reference count starts at 1 to ensure that the reference count cannot prematurely reach zero until any command buffers have been submitted. This additional decrement happens when the next MTLSafeFreeList is created, to allow the existing pool to be released once the reference count hits zero after submitted command buffers complete.

NOTE: the Metal API independently tracks resources used by command buffers for the purpose of keeping resources alive while in-use by the driver and CPU, however, this differs from the MTLSafeFreeList mechanism in the Metal backend, which exists for the purpose of allowing previously allocated #MTLBuffer resources to be re-used. This allows us to save on the expensive cost of memory allocation.

Definition at line 296 of file mtl_memory.hh.

Constructor & Destructor Documentation

◆ MTLSafeFreeList()

blender::gpu::MTLSafeFreeList::MTLSafeFreeList ( )

Definition at line 561 of file mtl_memory.mm.

Referenced by insert_buffer().

Member Function Documentation

◆ decrement_reference()

◆ flag_in_queue()

void blender::gpu::MTLSafeFreeList::flag_in_queue ( )
inline

◆ increment_reference()

void blender::gpu::MTLSafeFreeList::increment_reference ( )

Definition at line 605 of file mtl_memory.mm.

References BLI_assert.

Referenced by blender::gpu::present(), and blender::gpu::MTLCommandBufferManager::submit().

◆ insert_buffer()

void blender::gpu::MTLSafeFreeList::insert_buffer ( gpu::MTLBuffer * buffer)

◆ MEM_CXX_CLASS_ALLOC_FUNCS()

blender::gpu::MTLSafeFreeList::MEM_CXX_CLASS_ALLOC_FUNCS ( "MTLSafeFreeList" )

◆ should_flush()

bool blender::gpu::MTLSafeFreeList::should_flush ( )

Definition at line 628 of file mtl_memory.mm.

Referenced by blender::gpu::MTLBackend::render_step().

Friends And Related Symbol Documentation

◆ MTLBufferPool

friend class MTLBufferPool
friend

Definition at line 297 of file mtl_memory.hh.


The documentation for this class was generated from the following files: