Flutter Engine
The Flutter Engine
Public Member Functions | Static Public Member Functions | List of all members
skgpu::graphite::MtlCommandBuffer Class Referencefinal

#include <MtlCommandBuffer.h>

Inheritance diagram for skgpu::graphite::MtlCommandBuffer:
skgpu::graphite::CommandBuffer

Public Member Functions

 ~MtlCommandBuffer () override
 
bool setNewCommandBufferResources () override
 
void addWaitSemaphores (size_t numWaitSemaphores, const BackendSemaphore *waitSemaphores) override
 
void addSignalSemaphores (size_t numSignalSemaphores, const BackendSemaphore *signalSemaphores) override
 
bool isFinished ()
 
void waitUntilFinished ()
 
bool commit ()
 
- Public Member Functions inherited from skgpu::graphite::CommandBuffer
virtual ~CommandBuffer ()
 
void trackResource (sk_sp< Resource > resource)
 
void trackCommandBufferResource (sk_sp< Resource > resource)
 
void resetCommandBuffer ()
 
virtual bool setNewCommandBufferResources ()=0
 
void addFinishedProc (sk_sp< RefCntedCallback > finishedProc)
 
void callFinishedProcs (bool success)
 
virtual void addWaitSemaphores (size_t numWaitSemaphores, const BackendSemaphore *waitSemaphores)
 
virtual void addSignalSemaphores (size_t numWaitSemaphores, const BackendSemaphore *signalSemaphores)
 
virtual void prepareSurfaceForStateUpdate (SkSurface *targetSurface, const MutableTextureState *newState)
 
void addBuffersToAsyncMapOnSubmit (SkSpan< const sk_sp< Buffer > >)
 
SkSpan< const sk_sp< Buffer > > buffersToAsyncMapOnSubmit () const
 
bool addRenderPass (const RenderPassDesc &, sk_sp< Texture > colorTexture, sk_sp< Texture > resolveTexture, sk_sp< Texture > depthStencilTexture, SkRect viewport, const DrawPassList &drawPasses)
 
bool addComputePass (DispatchGroupSpan dispatchGroups)
 
bool copyBufferToBuffer (const Buffer *srcBuffer, size_t srcOffset, sk_sp< Buffer > dstBuffer, size_t dstOffset, size_t size)
 
bool copyTextureToBuffer (sk_sp< Texture >, SkIRect srcRect, sk_sp< Buffer >, size_t bufferOffset, size_t bufferRowBytes)
 
bool copyBufferToTexture (const Buffer *, sk_sp< Texture >, const BufferTextureCopyData *, int count)
 
bool copyTextureToTexture (sk_sp< Texture > src, SkIRect srcRect, sk_sp< Texture > dst, SkIPoint dstPoint, int mipLevel)
 
bool synchronizeBufferToCpu (sk_sp< Buffer >)
 
bool clearBuffer (const Buffer *buffer, size_t offset, size_t size)
 
void setReplayTranslation (SkIVector translation)
 
void clearReplayTranslation ()
 

Static Public Member Functions

static std::unique_ptr< MtlCommandBufferMake (id< MTLCommandQueue >, const MtlSharedContext *, MtlResourceProvider *)
 

Additional Inherited Members

- Public Types inherited from skgpu::graphite::CommandBuffer
using DrawPassList = skia_private::TArray< std::unique_ptr< DrawPass > >
 
using DispatchGroupSpan = SkSpan< const std::unique_ptr< DispatchGroup > >
 
- Protected Member Functions inherited from skgpu::graphite::CommandBuffer
 CommandBuffer ()
 
- Protected Attributes inherited from skgpu::graphite::CommandBuffer
SkISize fRenderPassSize
 
SkIVector fReplayTranslation
 

Detailed Description

Definition at line 31 of file MtlCommandBuffer.h.

Constructor & Destructor Documentation

◆ ~MtlCommandBuffer()

skgpu::graphite::MtlCommandBuffer::~MtlCommandBuffer ( )
override

Definition at line 51 of file MtlCommandBuffer.mm.

51 {
52 SkASSERT(!fActiveRenderCommandEncoder);
53 SkASSERT(!fActiveComputeCommandEncoder);
54 SkASSERT(!fActiveBlitCommandEncoder);
55}
#define SkASSERT(cond)
Definition: SkAssert.h:116

Member Function Documentation

◆ addSignalSemaphores()

void skgpu::graphite::MtlCommandBuffer::addSignalSemaphores ( size_t  numSignalSemaphores,
const BackendSemaphore signalSemaphores 
)
overridevirtual

Reimplemented from skgpu::graphite::CommandBuffer.

Definition at line 130 of file MtlCommandBuffer.mm.

131 {
132 if (!signalSemaphores) {
133 SkASSERT(numSignalSemaphores == 0);
134 return;
135 }
136
137 // Can only insert events with no active encoder
138 SkASSERT(!fActiveRenderCommandEncoder);
139 SkASSERT(!fActiveComputeCommandEncoder);
140 this->endBlitCommandEncoder();
141
142 if (@available(macOS 10.14, iOS 12.0, tvOS 12.0, *)) {
143 for (size_t i = 0; i < numSignalSemaphores; ++i) {
144 auto semaphore = signalSemaphores[i];
145 if (semaphore.isValid() && semaphore.backend() == BackendApi::kMetal) {
146 id<MTLEvent> mtlEvent = (__bridge id<MTLEvent>)semaphore.getMtlEvent();
147 [(*fCommandBuffer) encodeSignalEvent: mtlEvent
148 value: semaphore.getMtlValue()];
149 }
150 }
151 }
152}
uint8_t value

◆ addWaitSemaphores()

void skgpu::graphite::MtlCommandBuffer::addWaitSemaphores ( size_t  numWaitSemaphores,
const BackendSemaphore waitSemaphores 
)
overridevirtual

Reimplemented from skgpu::graphite::CommandBuffer.

Definition at line 107 of file MtlCommandBuffer.mm.

108 {
109 if (!waitSemaphores) {
110 SkASSERT(numWaitSemaphores == 0);
111 return;
112 }
113
114 // Can only insert events with no active encoder
115 SkASSERT(!fActiveRenderCommandEncoder);
116 SkASSERT(!fActiveComputeCommandEncoder);
117 this->endBlitCommandEncoder();
118 if (@available(macOS 10.14, iOS 12.0, tvOS 12.0, *)) {
119 for (size_t i = 0; i < numWaitSemaphores; ++i) {
120 auto semaphore = waitSemaphores[i];
121 if (semaphore.isValid() && semaphore.backend() == BackendApi::kMetal) {
122 id<MTLEvent> mtlEvent = (__bridge id<MTLEvent>)semaphore.getMtlEvent();
123 [(*fCommandBuffer) encodeWaitForEvent: mtlEvent
124 value: semaphore.getMtlValue()];
125 }
126 }
127 }
128}

◆ commit()

bool skgpu::graphite::MtlCommandBuffer::commit ( )

Definition at line 83 of file MtlCommandBuffer.mm.

83 {
84 SkASSERT(!fActiveRenderCommandEncoder);
85 SkASSERT(!fActiveComputeCommandEncoder);
86 this->endBlitCommandEncoder();
87 [(*fCommandBuffer) commit];
88
89 if ((*fCommandBuffer).status == MTLCommandBufferStatusError) {
90 NSString* description = (*fCommandBuffer).error.localizedDescription;
91 const char* errorString = [description UTF8String];
92 SKGPU_LOG_E("Failure submitting command buffer: %s", errorString);
93 }
94
95 return ((*fCommandBuffer).status != MTLCommandBufferStatusError);
96}
#define SKGPU_LOG_E(fmt,...)
Definition: Log.h:38

◆ isFinished()

bool skgpu::graphite::MtlCommandBuffer::isFinished ( )
inline

Definition at line 45 of file MtlCommandBuffer.h.

45 {
46 return (*fCommandBuffer).status == MTLCommandBufferStatusCompleted ||
47 (*fCommandBuffer).status == MTLCommandBufferStatusError;
48
49 }

◆ Make()

std::unique_ptr< MtlCommandBuffer > skgpu::graphite::MtlCommandBuffer::Make ( id< MTLCommandQueue >  queue,
const MtlSharedContext sharedContext,
MtlResourceProvider resourceProvider 
)
static

Definition at line 30 of file MtlCommandBuffer.mm.

32 {
33 auto commandBuffer = std::unique_ptr<MtlCommandBuffer>(
34 new MtlCommandBuffer(queue, sharedContext, resourceProvider));
35 if (!commandBuffer) {
36 return nullptr;
37 }
38 if (!commandBuffer->createNewMTLCommandBuffer()) {
39 return nullptr;
40 }
41 return commandBuffer;
42}
VkQueue queue
Definition: main.cc:55

◆ setNewCommandBufferResources()

bool skgpu::graphite::MtlCommandBuffer::setNewCommandBufferResources ( )
overridevirtual

Implements skgpu::graphite::CommandBuffer.

Definition at line 57 of file MtlCommandBuffer.mm.

57 {
58 return this->createNewMTLCommandBuffer();
59}

◆ waitUntilFinished()

void skgpu::graphite::MtlCommandBuffer::waitUntilFinished ( )
inline

Definition at line 50 of file MtlCommandBuffer.h.

50 {
51 // TODO: it's not clear what do to if status is Enqueued. Commit and then wait?
52 if ((*fCommandBuffer).status == MTLCommandBufferStatusScheduled ||
53 (*fCommandBuffer).status == MTLCommandBufferStatusCommitted) {
54 [(*fCommandBuffer) waitUntilCompleted];
55 }
56 if (!this->isFinished()) {
57 SKGPU_LOG_E("Unfinished command buffer status: %d",
58 (int)(*fCommandBuffer).status);
59 SkASSERT(false);
60 }
61 }

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