Flutter Engine
The Flutter Engine
Public Member Functions | Static Public Member Functions | List of all members
GrMtlCommandBuffer Class Reference

#include <GrMtlCommandBuffer.h>

Inheritance diagram for GrMtlCommandBuffer:
SkRefCnt SkRefCntBase

Public Member Functions

 ~GrMtlCommandBuffer () override
 
void releaseResources ()
 
bool commit (bool waitUntilCompleted)
 
bool hasWork ()
 
void addFinishedCallback (sk_sp< skgpu::RefCntedCallback > callback)
 
id< MTLBlitCommandEncoder > getBlitCommandEncoder ()
 
GrMtlRenderCommandEncodergetRenderCommandEncoder (MTLRenderPassDescriptor *, const GrMtlPipelineState *, GrMtlOpsRenderPass *opsRenderPass)
 
GrMtlRenderCommandEncodergetRenderCommandEncoder (MTLRenderPassDescriptor *, GrMtlOpsRenderPass *)
 
void addCompletedHandler (MTLCommandBufferHandler block)
 
void addResource (const sk_sp< const GrManagedResource > &resource)
 
void addGrBuffer (sk_sp< const GrBuffer > buffer)
 
void addGrSurface (sk_sp< const GrSurface > surface)
 
void encodeSignalEvent (sk_sp< GrMtlEvent >, uint64_t value)
 
void encodeWaitForEvent (sk_sp< GrMtlEvent >, uint64_t value)
 
void waitUntilCompleted ()
 
bool isCompleted ()
 
void callFinishedCallbacks ()
 
void pushDebugGroup (NSString *string)
 
void popDebugGroup ()
 
- Public Member Functions inherited from SkRefCntBase
 SkRefCntBase ()
 
virtual ~SkRefCntBase ()
 
bool unique () const
 
void ref () const
 
void unref () const
 

Static Public Member Functions

static sk_sp< GrMtlCommandBufferMake (id< MTLCommandQueue > queue)
 

Detailed Description

Definition at line 30 of file GrMtlCommandBuffer.h.

Constructor & Destructor Documentation

◆ ~GrMtlCommandBuffer()

GrMtlCommandBuffer::~GrMtlCommandBuffer ( )
override

Definition at line 48 of file GrMtlCommandBuffer.mm.

48 {
49 this->endAllEncoding();
50 this->releaseResources();
52
53 fCmdBuffer = nil;
54}

Member Function Documentation

◆ addCompletedHandler()

void GrMtlCommandBuffer::addCompletedHandler ( MTLCommandBufferHandler  block)
inline

Definition at line 53 of file GrMtlCommandBuffer.h.

53 {
54 [fCmdBuffer addCompletedHandler:block];
55 }
void addCompletedHandler(MTLCommandBufferHandler block)

◆ addFinishedCallback()

void GrMtlCommandBuffer::addFinishedCallback ( sk_sp< skgpu::RefCntedCallback callback)
inline

Definition at line 40 of file GrMtlCommandBuffer.h.

40 {
41 fFinishedCallbacks.push_back(std::move(callback));
42 }
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback

◆ addGrBuffer()

void GrMtlCommandBuffer::addGrBuffer ( sk_sp< const GrBuffer buffer)
inline

Definition at line 63 of file GrMtlCommandBuffer.h.

63 {
64 fTrackedGrBuffers.push_back(std::move(buffer));
65 }
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified vm service A custom Dart VM Service port The default is to pick a randomly available open port disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode disable vm service Disable mDNS Dart VM Service publication Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set endless trace buffer
Definition: switches.h:126

◆ addGrSurface()

void GrMtlCommandBuffer::addGrSurface ( sk_sp< const GrSurface surface)
inline

Definition at line 67 of file GrMtlCommandBuffer.h.

67 {
68 fTrackedGrSurfaces.push_back(std::move(surface));
69 }
VkSurfaceKHR surface
Definition: main.cc:49

◆ addResource()

void GrMtlCommandBuffer::addResource ( const sk_sp< const GrManagedResource > &  resource)
inline

Definition at line 57 of file GrMtlCommandBuffer.h.

57 {
58// Disable generic resource tracking for now
59// SkASSERT(resource);
60// fTrackedResources.push_back(std::move(resource));
61 }

◆ callFinishedCallbacks()

void GrMtlCommandBuffer::callFinishedCallbacks ( )
inline

Definition at line 81 of file GrMtlCommandBuffer.h.

81{ fFinishedCallbacks.clear(); }

◆ commit()

bool GrMtlCommandBuffer::commit ( bool  waitUntilCompleted)

Definition at line 181 of file GrMtlCommandBuffer.mm.

181 {
182 this->endAllEncoding();
183 if ([fCmdBuffer status] != MTLCommandBufferStatusNotEnqueued) {
184 NSLog(@"GrMtlCommandBuffer: Tried to commit command buffer while in invalid state.\n");
185 return false;
186 }
187 [fCmdBuffer commit];
188 if (waitUntilCompleted) {
189 this->waitUntilCompleted();
190#if defined(SK_BUILD_FOR_IOS) && defined(SK_METAL_WAIT_UNTIL_SCHEDULED)
191 // If iOS goes into the background we need to make sure all command buffers are scheduled first.
192 // We don't have a way of detecting background transition so this guarantees it.
193 } else {
194 [fCmdBuffer waitUntilScheduled];
195#endif
196 }
197
198 if ([fCmdBuffer status] == MTLCommandBufferStatusError) {
199 SkDebugf("Error submitting command buffer.\n");
200 if (NSError* error = [fCmdBuffer error]) {
201 NSLog(@"%@", error);
202 }
203 }
204
205 return ([fCmdBuffer status] != MTLCommandBufferStatusError);
206}
void SK_SPI SkDebugf(const char format[],...) SK_PRINTF_LIKE(1
bool commit(bool waitUntilCompleted)
const uint8_t uint32_t uint32_t GError ** error

◆ encodeSignalEvent()

void GrMtlCommandBuffer::encodeSignalEvent ( sk_sp< GrMtlEvent event,
uint64_t  value 
)

Definition at line 220 of file GrMtlCommandBuffer.mm.

220 {
221 SkASSERT(fCmdBuffer);
222 this->endAllEncoding(); // ensure we don't have any active command encoders
223 if (@available(macOS 10.14, iOS 12.0, tvOS 12.0, *)) {
224 [fCmdBuffer encodeSignalEvent:event->mtlEvent() value:eventValue];
225 this->addResource(std::move(event));
226 }
227 fHasWork = true;
228}
#define SkASSERT(cond)
Definition: SkAssert.h:116
void addResource(const sk_sp< const GrManagedResource > &resource)
void encodeSignalEvent(sk_sp< GrMtlEvent >, uint64_t value)
FlKeyEvent * event
uint8_t value

◆ encodeWaitForEvent()

void GrMtlCommandBuffer::encodeWaitForEvent ( sk_sp< GrMtlEvent event,
uint64_t  value 
)

Definition at line 230 of file GrMtlCommandBuffer.mm.

230 {
231 SkASSERT(fCmdBuffer);
232 this->endAllEncoding(); // ensure we don't have any active command encoders
233 // TODO: not sure if needed but probably
234 if (@available(macOS 10.14, iOS 12.0, tvOS 12.0, *)) {
235 [fCmdBuffer encodeWaitForEvent:event->mtlEvent() value:eventValue];
236 this->addResource(std::move(event));
237 }
238 fHasWork = true;
239}
void encodeWaitForEvent(sk_sp< GrMtlEvent >, uint64_t value)

◆ getBlitCommandEncoder()

id< MTLBlitCommandEncoder > GrMtlCommandBuffer::getBlitCommandEncoder ( )

Definition at line 64 of file GrMtlCommandBuffer.mm.

64 {
65 if (fActiveBlitCommandEncoder) {
66 return fActiveBlitCommandEncoder;
67 }
68
69 this->endAllEncoding();
70 if (fCmdBuffer.status != MTLCommandBufferStatusNotEnqueued) {
71 NSLog(@"GrMtlCommandBuffer: tried to create MTLBlitCommandEncoder while in invalid state.");
72 return nullptr;
73 }
74 fActiveBlitCommandEncoder = [fCmdBuffer blitCommandEncoder];
75 fHasWork = true;
76
77 return fActiveBlitCommandEncoder;
78}

◆ getRenderCommandEncoder() [1/2]

GrMtlRenderCommandEncoder * GrMtlCommandBuffer::getRenderCommandEncoder ( MTLRenderPassDescriptor *  descriptor,
const GrMtlPipelineState pipelineState,
GrMtlOpsRenderPass opsRenderPass 
)

Definition at line 147 of file GrMtlCommandBuffer.mm.

149 {
150 if (nil != fPreviousRenderPassDescriptor) {
151 if (compatible(fPreviousRenderPassDescriptor.colorAttachments[0],
152 descriptor.colorAttachments[0], pipelineState) &&
153 compatible(fPreviousRenderPassDescriptor.stencilAttachment,
154 descriptor.stencilAttachment, pipelineState)) {
155 return fActiveRenderCommandEncoder.get();
156 }
157 }
158
159 return this->getRenderCommandEncoder(descriptor, opsRenderPass);
160}
static bool compatible(const MTLRenderPassAttachmentDescriptor *first, const MTLRenderPassAttachmentDescriptor *second, const GrMtlPipelineState *pipelineState)
GrMtlRenderCommandEncoder * getRenderCommandEncoder(MTLRenderPassDescriptor *, const GrMtlPipelineState *, GrMtlOpsRenderPass *opsRenderPass)

◆ getRenderCommandEncoder() [2/2]

GrMtlRenderCommandEncoder * GrMtlCommandBuffer::getRenderCommandEncoder ( MTLRenderPassDescriptor *  descriptor,
GrMtlOpsRenderPass opsRenderPass 
)

Definition at line 162 of file GrMtlCommandBuffer.mm.

164 {
165 this->endAllEncoding();
166 if (fCmdBuffer.status != MTLCommandBufferStatusNotEnqueued) {
167 NSLog(@"GrMtlCommandBuffer: tried to create MTLRenderCommandEncoder while in bad state.");
168 return nullptr;
169 }
170 fActiveRenderCommandEncoder = GrMtlRenderCommandEncoder::Make(
171 [fCmdBuffer renderCommandEncoderWithDescriptor:descriptor]);
172 if (opsRenderPass) {
173 opsRenderPass->initRenderState(fActiveRenderCommandEncoder.get());
174 }
175 fPreviousRenderPassDescriptor = descriptor;
176 fHasWork = true;
177
178 return fActiveRenderCommandEncoder.get();
179}
void initRenderState(GrMtlRenderCommandEncoder *)
static std::unique_ptr< GrMtlRenderCommandEncoder > Make(id< MTLRenderCommandEncoder > encoder)

◆ hasWork()

bool GrMtlCommandBuffer::hasWork ( )
inline

Definition at line 38 of file GrMtlCommandBuffer.h.

38{ return fHasWork; }

◆ isCompleted()

bool GrMtlCommandBuffer::isCompleted ( )
inline

Definition at line 77 of file GrMtlCommandBuffer.h.

77 {
78 return fCmdBuffer.status == MTLCommandBufferStatusCompleted ||
79 fCmdBuffer.status == MTLCommandBufferStatusError;
80 }

◆ Make()

GR_NORETAIN_BEGIN sk_sp< GrMtlCommandBuffer > GrMtlCommandBuffer::Make ( id< MTLCommandQueue >  queue)
static

Definition at line 24 of file GrMtlCommandBuffer.mm.

24 {
25 id<MTLCommandBuffer> mtlCommandBuffer;
26#if GR_METAL_SDK_VERSION >= 230
27 if (@available(macOS 11.0, iOS 14.0, tvOS 14.0, *)) {
28 MTLCommandBufferDescriptor* desc = [[MTLCommandBufferDescriptor alloc] init];
29 desc.errorOptions = MTLCommandBufferErrorOptionEncoderExecutionStatus;
30 mtlCommandBuffer = [queue commandBufferWithDescriptor:desc];
31 } else {
32 mtlCommandBuffer = [queue commandBuffer];
33 }
34#else
35 mtlCommandBuffer = [queue commandBuffer];
36#endif
37 if (nil == mtlCommandBuffer) {
38 return nullptr;
39 }
40
41#ifdef SK_ENABLE_MTL_DEBUG_INFO
42 mtlCommandBuffer.label = @"GrMtlCommandBuffer::Make";
43#endif
44
45 return sk_sp<GrMtlCommandBuffer>(new GrMtlCommandBuffer(mtlCommandBuffer));
46}
VkQueue queue
Definition: main.cc:55
static bool init()

◆ popDebugGroup()

void GrMtlCommandBuffer::popDebugGroup ( )
inline

Definition at line 89 of file GrMtlCommandBuffer.h.

89 {
90 if (@available(macOS 10.13, iOS 11.0, tvOS 11.0, *)) {
91 [fCmdBuffer popDebugGroup];
92 }
93 }

◆ pushDebugGroup()

void GrMtlCommandBuffer::pushDebugGroup ( NSString *  string)
inline

Definition at line 83 of file GrMtlCommandBuffer.h.

83 {
84 if (@available(macOS 10.13, iOS 11.0, tvOS 11.0, *)) {
85 [fCmdBuffer pushDebugGroup:string];
86 }
87 }
void pushDebugGroup(NSString *string)

◆ releaseResources()

void GrMtlCommandBuffer::releaseResources ( )

Definition at line 56 of file GrMtlCommandBuffer.mm.

56 {
57 TRACE_EVENT0("skia.gpu", TRACE_FUNC);
58
59 fTrackedResources.clear();
60 fTrackedGrBuffers.clear();
61 fTrackedGrSurfaces.clear();
62}
#define TRACE_FUNC
Definition: SkTraceEvent.h:30
#define TRACE_EVENT0(category_group, name)
Definition: trace_event.h:131

◆ waitUntilCompleted()

void GrMtlCommandBuffer::waitUntilCompleted ( )
inline

Definition at line 74 of file GrMtlCommandBuffer.h.

74 {
75 [fCmdBuffer waitUntilCompleted];
76 }

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