Table of Contents

Class MetalCommandBufferPool

Namespace
DotCompute.Backends.Metal.Utilities
Assembly
DotCompute.Backends.Metal.dll

Pool for managing Metal command buffers to reduce allocation overhead.

public sealed class MetalCommandBufferPool : IDisposable
Inheritance
MetalCommandBufferPool
Implements
Inherited Members
Extension Methods

Constructors

MetalCommandBufferPool(nint, ILogger<MetalCommandBufferPool>, int)

Initializes a new instance of the MetalCommandBufferPool.

public MetalCommandBufferPool(nint commandQueue, ILogger<MetalCommandBufferPool> logger, int maxPoolSize = 16)

Parameters

commandQueue nint

The Metal command queue to create buffers from.

logger ILogger<MetalCommandBufferPool>

Logger for diagnostics.

maxPoolSize int

Maximum number of buffers to keep in pool.

Properties

Stats

Gets statistics about the command buffer pool. Note: Since command buffers are no longer pooled for reuse, AvailableBuffers and CurrentPoolSize are always 0.

public CommandBufferPoolStats Stats { get; }

Property Value

CommandBufferPoolStats

Methods

Cleanup()

Performs cleanup of stale buffers from the pool. Since command buffers are no longer pooled for reuse, this only cleans up leaked active buffers.

public void Cleanup()

Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

public void Dispose()

GetCommandBuffer()

Gets a command buffer from the pool or creates a new one. NOTE: Metal command buffers are one-shot objects and cannot be reused after commit. This method always creates a fresh command buffer.

public nint GetCommandBuffer()

Returns

nint

A command buffer handle.

GetStats()

Gets statistics about the command buffer pool (API compatibility method).

public CommandBufferPoolStats GetStats()

Returns

CommandBufferPoolStats

ReturnCommandBuffer(nint)

Returns a command buffer to the pool for cleanup. NOTE: Metal command buffers cannot be reused after commit, so they are always disposed. This method exists for API compatibility and proper tracking cleanup.

public void ReturnCommandBuffer(nint buffer)

Parameters

buffer nint

The command buffer to dispose.