UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
FMetalCommandEncoder Class Reference

#include <MetalCommandEncoder.h>

Public Member Functions

 FMetalCommandEncoder (FMetalDevice &Device, FMetalCommandList &CmdList)
 
void Release (void)
 
void Reset (void)
 
void ResetLive (void)
 
void StartCommandBuffer (void)
 
void EndCommandBuffer (FMetalRHICommandContext *Context)
 
FMetalCommandBufferGetCommandBuffer ()
 
uint32 GetCommandBufferIndex () const
 
bool IsParallelRenderCommandEncoderActive (void) const
 
bool IsRenderCommandEncoderActive (void) const
 
bool IsComputeCommandEncoderActive (void) const
 
bool IsBlitCommandEncoderActive (void) const
 
bool IsAnyCommandEncoderActive (void) const
 
bool IsParallelEncoding ()
 
bool IsRenderPassDescriptorValid (void) const
 
const MTL::RenderPassDescriptor * GetRenderPassDescriptor (void) const
 
MTL::RenderCommandEncoder * GetRenderCommandEncoder (void)
 
MTL::ComputeCommandEncoder * GetComputeCommandEncoder (void)
 
MTL::BlitCommandEncoder * GetBlitCommandEncoder (void)
 
TRefCountPtr< FMetalFence > const & GetEncoderFence (void) const
 
uint32 NumEncodedPasses (void) const
 
MTLParallelRenderCommandEncoderPtr BeginParallelRenderCommandEncoding (FMetalCounterSampler *Sampler)
 
void BeginRenderCommandEncoding (FMetalCounterSampler *Sampler)
 
void BeginRenderCommandEncoding (MTL::RenderPassDescriptor *RenderPassDesc, MTLParallelRenderCommandEncoderPtr ParallelEncoder)
 
void BeginComputeCommandEncoding (MTL::DispatchType Type=MTL::DispatchTypeSerial, FMetalCounterSampler *Sampler=nullptr)
 
void BeginBlitCommandEncoding (FMetalCounterSampler *Sampler)
 
TRefCountPtr< FMetalFenceEndEncoding ()
 
void UpdateFence (FMetalFence *Fence)
 
void WaitForFence (FMetalFence *Fence)
 
void SignalEvent (MTLEventPtr Event, uint32_t SignalCount)
 
void WaitForEvent (MTLEventPtr Event, uint32_t SignalCount)
 
void InsertDebugSignpost (NS::String *String)
 
void PushDebugGroup (NS::String *String)
 
void PopDebugGroup (void)
 
void SetRenderPassDescriptor (MTL::RenderPassDescriptor *RenderPass)
 
void SetRenderPassStoreActions (MTL::StoreAction const *const ColorStore, MTL::StoreAction const DepthStore, MTL::StoreAction const StencilStore)
 
void SetRenderPipelineState (FMetalShaderPipeline *const PipelineState)
 
void SetViewport (MTL::Viewport const Viewport[], uint32 NumActive)
 
void SetFrontFacingWinding (MTL::Winding const FrontFacingWinding)
 
void SetCullMode (MTL::CullMode const CullMode)
 
void SetDepthBias (float const DepthBias, float const SlopeScale, float const Clamp)
 
void SetScissorRect (MTL::ScissorRect const Rect[], uint32 NumActive)
 
void SetTriangleFillMode (MTL::TriangleFillMode const FillMode)
 
void SetDepthClipMode (MTL::DepthClipMode DepthClipMode)
 
void SetBlendColor (float const Red, float const Green, float const Blue, float const Alpha)
 
void SetDepthStencilState (MTL::DepthStencilState *DepthStencilState)
 
void SetStencilReferenceValue (uint32 const ReferenceValue)
 
void SetVisibilityResultMode (MTL::VisibilityResultMode const Mode, NS::UInteger const Offset)
 
void SetShaderBuffer (MTL::FunctionType const FunctionType, FMetalBufferPtr Buffer, NS::UInteger const Offset, NS::UInteger const Length, NS::UInteger const Index, MTL::ResourceUsage const Usage, EPixelFormat const Format=PF_Unknown, NS::UInteger const ElementRowPitch=0, TArray< TTuple< MTL::Resource *, MTL::ResourceUsage > > ReferencedResources={})
 
void SetShaderData (MTL::FunctionType const FunctionType, FMetalBufferData *Data, NS::UInteger const Offset, NS::UInteger const Index, EPixelFormat const Format=PF_Unknown, NS::UInteger const ElementRowPitch=0)
 
void SetShaderBytes (MTL::FunctionType const FunctionType, uint8 const *Bytes, NS::UInteger const Length, NS::UInteger const Index)
 
void SetShaderTexture (MTL::FunctionType const FunctionType, MTL::Texture *Texture, NS::UInteger const Index, MTL::ResourceUsage const Usage)
 
void SetShaderSamplerState (MTL::FunctionType const FunctionType, MTL::SamplerState *Sampler, NS::UInteger const Index)
 
void SetShaderSideTable (MTL::FunctionType const FunctionType, NS::UInteger const Index)
 
void UseIndirectArgumentResource (MTL::Texture *Texture, MTL::ResourceUsage const Usage)
 
void UseIndirectArgumentResource (FMetalBufferPtr Buffer, MTL::ResourceUsage const Usage)
 
void TransitionResources (MTL::Resource *Resource)
 
void SetComputePipelineState (FMetalShaderPipelinePtr State)
 
FMetalSubBufferRingGetRingBuffer (void)
 
void UseResource (MTL::Resource *Resource, MTL::ResourceUsage const Usage)
 
void UseResources (TArray< MTL::Resource * > const &Resources, MTL::ResourceUsage const Usage, MTL::RenderStages RenderStages=0)
 
void UseHeaps (TArray< MTL::Heap * > const &Heaps, const MTL::FunctionType Function)
 

Detailed Description

FMetalCommandEncoder: Wraps the details of switching between different command encoders on the command-buffer, allowing for restoration of the render encoder if needed. UnrealEngine expects the API to serialise commands in-order, but Metal expects applications to work with command-buffers directly so we need to implement the RHI semantics by switching between encoder types. This class hides the ugly details. Eventually it might be possible to move some of the operations into pre- & post- command-buffers so that we avoid encoder switches but that will take changes to the RHI and high-level code too, so it won't happen soon.

Constructor & Destructor Documentation

◆ FMetalCommandEncoder()

FMetalCommandEncoder::FMetalCommandEncoder ( FMetalDevice Device,
FMetalCommandList CmdList 
)

Default constructor

Member Function Documentation

◆ BeginBlitCommandEncoding()

void FMetalCommandEncoder::BeginBlitCommandEncoding ( FMetalCounterSampler Sampler)

Begins encoding blit commands into the current command buffer. No other encoder may be active.

◆ BeginComputeCommandEncoding()

void FMetalCommandEncoder::BeginComputeCommandEncoding ( MTL::DispatchType  Type = MTL::DispatchTypeSerial,
FMetalCounterSampler Sampler = nullptr 
)

Begins encoding compute commands into the current command buffer. No other encoder may be active.

◆ BeginParallelRenderCommandEncoding()

MTLParallelRenderCommandEncoderPtr FMetalCommandEncoder::BeginParallelRenderCommandEncoding ( FMetalCounterSampler Sampler)

Begins encoding for parallel rendering commands into the current command buffer. No other encoder may be active

◆ BeginRenderCommandEncoding() [1/2]

void FMetalCommandEncoder::BeginRenderCommandEncoding ( FMetalCounterSampler Sampler)

Begins encoding rendering commands into the current command buffer. No other encoder may be active

◆ BeginRenderCommandEncoding() [2/2]

void FMetalCommandEncoder::BeginRenderCommandEncoding ( MTL::RenderPassDescriptor *  RenderPassDesc,
MTLParallelRenderCommandEncoderPtr  ParallelEncoder 
)

Begins encoding rendering commands into the parallel render encoder (no command buffer required)

◆ EndCommandBuffer()

void FMetalCommandEncoder::EndCommandBuffer ( FMetalRHICommandContext Context)

Will deprecate in 5.6, splits the command buffer into chunks, required for profiling until we switch to encoder counter buffers

◆ EndEncoding()

TRefCountPtr< FMetalFence > FMetalCommandEncoder::EndEncoding ( )

Declare that all command generation from this encoder is complete, and detach from the MTLCommandBuffer if there is an encoder active or does nothing if there isn't.

◆ GetBlitCommandEncoder()

MTL::BlitCommandEncoder * FMetalCommandEncoder::GetBlitCommandEncoder ( void  )
Returns
The active blit command encoder or nullptr if there isn't one.

◆ GetCommandBuffer()

FMetalCommandBuffer * FMetalCommandEncoder::GetCommandBuffer ( )
inline
Returns
the current command buffer

◆ GetCommandBufferIndex()

uint32 FMetalCommandEncoder::GetCommandBufferIndex ( ) const
inline
Returns
the monotonically incremented command buffer index

◆ GetComputeCommandEncoder()

MTL::ComputeCommandEncoder * FMetalCommandEncoder::GetComputeCommandEncoder ( void  )
Returns
The active compute command encoder or nullptr if there isn't one.

◆ GetEncoderFence()

TRefCountPtr< FMetalFence > const & FMetalCommandEncoder::GetEncoderFence ( void  ) const
Returns
The MTLFence for the current encoder or nullptr if there isn't one.

◆ GetRenderCommandEncoder()

MTL::RenderCommandEncoder * FMetalCommandEncoder::GetRenderCommandEncoder ( void  )
Returns
The active render command encoder or nullptr if there isn't one.

◆ GetRenderPassDescriptor()

const MTL::RenderPassDescriptor * FMetalCommandEncoder::GetRenderPassDescriptor ( void  ) const
Returns
The current render pass descriptor.

◆ GetRingBuffer()

FMetalSubBufferRing & FMetalCommandEncoder::GetRingBuffer ( void  )

◆ InsertDebugSignpost()

void FMetalCommandEncoder::InsertDebugSignpost ( NS::String *  String)

◆ IsAnyCommandEncoderActive()

bool FMetalCommandEncoder::IsAnyCommandEncoderActive ( void  ) const
inline
Returns
True if any encoder is active, otherwise false.

◆ IsBlitCommandEncoderActive()

bool FMetalCommandEncoder::IsBlitCommandEncoderActive ( void  ) const
inline
Returns
True if and only if there is an active blit command encoder, otherwise false.

◆ IsComputeCommandEncoderActive()

bool FMetalCommandEncoder::IsComputeCommandEncoderActive ( void  ) const
inline
Returns
True if and only if there is an active compute command encoder, otherwise false.

◆ IsParallelEncoding()

bool FMetalCommandEncoder::IsParallelEncoding ( )
inline

◆ IsParallelRenderCommandEncoderActive()

bool FMetalCommandEncoder::IsParallelRenderCommandEncoderActive ( void  ) const
inline
Returns
True if and only if there is an active parallel render command encoder, otherwise false.

◆ IsRenderCommandEncoderActive()

bool FMetalCommandEncoder::IsRenderCommandEncoderActive ( void  ) const
inline
Returns
True if and only if there is an active render command encoder, otherwise false.

◆ IsRenderPassDescriptorValid()

bool FMetalCommandEncoder::IsRenderPassDescriptorValid ( void  ) const
Returns
True if and only if there is valid render pass descriptor set on the encoder, otherwise false.

◆ NumEncodedPasses()

uint32 FMetalCommandEncoder::NumEncodedPasses ( void  ) const
inline
Returns
The number of encoded passes in the command buffer.

◆ PopDebugGroup()

void FMetalCommandEncoder::PopDebugGroup ( void  )

◆ PushDebugGroup()

void FMetalCommandEncoder::PushDebugGroup ( NS::String *  String)

◆ Release()

void FMetalCommandEncoder::Release ( void  )

Release Function

◆ Reset()

void FMetalCommandEncoder::Reset ( void  )

Reset cached state for reuse

◆ ResetLive()

void FMetalCommandEncoder::ResetLive ( void  )

Reset cached state for reuse while in rendering

◆ SetBlendColor()

void FMetalCommandEncoder::SetBlendColor ( float const  Red,
float const  Green,
float const  Blue,
float const  Alpha 
)

◆ SetComputePipelineState()

void FMetalCommandEncoder::SetComputePipelineState ( FMetalShaderPipelinePtr  State)

◆ SetCullMode()

void FMetalCommandEncoder::SetCullMode ( MTL::CullMode const  CullMode)

◆ SetDepthBias()

void FMetalCommandEncoder::SetDepthBias ( float const  DepthBias,
float const  SlopeScale,
float const  Clamp 
)

◆ SetDepthClipMode()

void FMetalCommandEncoder::SetDepthClipMode ( MTL::DepthClipMode  DepthClipMode)

◆ SetDepthStencilState()

void FMetalCommandEncoder::SetDepthStencilState ( MTL::DepthStencilState *  DepthStencilState)

◆ SetFrontFacingWinding()

void FMetalCommandEncoder::SetFrontFacingWinding ( MTL::Winding const  FrontFacingWinding)

◆ SetRenderPassDescriptor()

void FMetalCommandEncoder::SetRenderPassDescriptor ( MTL::RenderPassDescriptor *  RenderPass)

Set the render pass descriptor - no encoder may be active when this function is called.

Parameters
RenderPassThe render pass descriptor to set. May be nullptr.

◆ SetRenderPassStoreActions()

void FMetalCommandEncoder::SetRenderPassStoreActions ( MTL::StoreAction const *const  ColorStore,
MTL::StoreAction const  DepthStore,
MTL::StoreAction const  StencilStore 
)

Set the render pass store actions, call after SetRenderPassDescriptor but before EndEncoding.

Parameters
ColorStoreThe store actions for color targets.
DepthStoreThe store actions for the depth buffer - use MTL::StoreActionUnknown if no depth-buffer bound.
StencilStoreThe store actions for the stencil buffer - use MTL::StoreActionUnknown if no stencil-buffer bound.

◆ SetRenderPipelineState()

void FMetalCommandEncoder::SetRenderPipelineState ( FMetalShaderPipeline *const  PipelineState)

◆ SetScissorRect()

void FMetalCommandEncoder::SetScissorRect ( MTL::ScissorRect const  Rect[],
uint32  NumActive 
)

◆ SetShaderBuffer()

void FMetalCommandEncoder::SetShaderBuffer ( MTL::FunctionType const  FunctionType,
FMetalBufferPtr  Buffer,
NS::UInteger const  Offset,
NS::UInteger const  Length,
NS::UInteger const  Index,
MTL::ResourceUsage const  Usage,
EPixelFormat const  Format = PF_Unknown,
NS::UInteger const  ElementRowPitch = 0,
TArray< TTuple< MTL::Resource *, MTL::ResourceUsage > >  ReferencedResources = {} 
)

◆ SetShaderBytes()

void FMetalCommandEncoder::SetShaderBytes ( MTL::FunctionType const  FunctionType,
uint8 const *  Bytes,
NS::UInteger const  Length,
NS::UInteger const  Index 
)

◆ SetShaderData()

void FMetalCommandEncoder::SetShaderData ( MTL::FunctionType const  FunctionType,
FMetalBufferData Data,
NS::UInteger const  Offset,
NS::UInteger const  Index,
EPixelFormat const  Format = PF_Unknown,
NS::UInteger const  ElementRowPitch = 0 
)

◆ SetShaderSamplerState()

void FMetalCommandEncoder::SetShaderSamplerState ( MTL::FunctionType const  FunctionType,
MTL::SamplerState *  Sampler,
NS::UInteger const  Index 
)

◆ SetShaderSideTable()

void FMetalCommandEncoder::SetShaderSideTable ( MTL::FunctionType const  FunctionType,
NS::UInteger const  Index 
)

◆ SetShaderTexture()

void FMetalCommandEncoder::SetShaderTexture ( MTL::FunctionType const  FunctionType,
MTL::Texture *  Texture,
NS::UInteger const  Index,
MTL::ResourceUsage const  Usage 
)

◆ SetStencilReferenceValue()

void FMetalCommandEncoder::SetStencilReferenceValue ( uint32 const  ReferenceValue)

◆ SetTriangleFillMode()

void FMetalCommandEncoder::SetTriangleFillMode ( MTL::TriangleFillMode const  FillMode)

◆ SetViewport()

void FMetalCommandEncoder::SetViewport ( MTL::Viewport const  Viewport[],
uint32  NumActive 
)

◆ SetVisibilityResultMode()

void FMetalCommandEncoder::SetVisibilityResultMode ( MTL::VisibilityResultMode const  Mode,
NS::UInteger const  Offset 
)

◆ SignalEvent()

void FMetalCommandEncoder::SignalEvent ( MTLEventPtr  Event,
uint32_t  SignalCount 
)

Update the event to capture all GPU work so far enqueued by this encoder.

◆ StartCommandBuffer()

void FMetalCommandEncoder::StartCommandBuffer ( void  )

Start encoding to CommandBuffer. It is an error to call this with any outstanding command encoders or current command buffer. Instead call EndEncoding & CommitCommandBuffer before calling this.

◆ TransitionResources()

void FMetalCommandEncoder::TransitionResources ( MTL::Resource *  Resource)

◆ UpdateFence()

void FMetalCommandEncoder::UpdateFence ( FMetalFence Fence)

Update the event to capture all GPU work so far enqueued by this encoder.

◆ UseHeaps()

void FMetalCommandEncoder::UseHeaps ( TArray< MTL::Heap * > const &  Heaps,
const MTL::FunctionType  Function 
)

◆ UseIndirectArgumentResource() [1/2]

void FMetalCommandEncoder::UseIndirectArgumentResource ( FMetalBufferPtr  Buffer,
MTL::ResourceUsage const  Usage 
)

◆ UseIndirectArgumentResource() [2/2]

void FMetalCommandEncoder::UseIndirectArgumentResource ( MTL::Texture *  Texture,
MTL::ResourceUsage const  Usage 
)

◆ UseResource()

void FMetalCommandEncoder::UseResource ( MTL::Resource *  Resource,
MTL::ResourceUsage const  Usage 
)

◆ UseResources()

void FMetalCommandEncoder::UseResources ( TArray< MTL::Resource * > const &  Resources,
MTL::ResourceUsage const  Usage,
MTL::RenderStages  RenderStages = 0 
)

◆ WaitForEvent()

void FMetalCommandEncoder::WaitForEvent ( MTLEventPtr  Event,
uint32_t  SignalCount 
)

Prevent further GPU work until the event is reached.

◆ WaitForFence()

void FMetalCommandEncoder::WaitForFence ( FMetalFence Fence)

Prevent further GPU work until the event is reached.


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