Flutter Engine
The Flutter Engine
GrMtlGpu.h
Go to the documentation of this file.
1/*
2 * Copyright 2017 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#ifndef GrMtlGpu_DEFINED
9#define GrMtlGpu_DEFINED
10
14
21
27
28#import <Metal/Metal.h>
29
31class GrMtlTexture;
32class GrSemaphore;
34
35class GrMtlGpu : public GrGpu {
36public:
37 static std::unique_ptr<GrGpu> Make(const GrMtlBackendContext&,
38 const GrContextOptions&,
40 ~GrMtlGpu() override;
41
42 void disconnect(DisconnectType) override;
43
46
47 const GrMtlCaps& mtlCaps() const { return *fMtlCaps; }
48
49 id<MTLDevice> device() const { return fDevice; }
50
51 GrMtlResourceProvider& resourceProvider() { return fResourceProvider; }
52
53 GrStagingBufferManager* stagingBufferManager() override { return &fStagingBufferManager; }
54
56
57 enum SyncQueue {
60 };
61
62 void deleteBackendTexture(const GrBackendTexture&) override;
63
64 bool compile(const GrProgramDesc&, const GrProgramInfo&) override;
65
66 bool precompileShader(const SkData& key, const SkData& data) override;
67
68#if defined(GR_TEST_UTILS)
69 bool isTestingOnlyBackendTexture(const GrBackendTexture&) const override;
70
71 GrBackendRenderTarget createTestingOnlyBackendRenderTarget(SkISize dimensions,
73 int sampleCnt,
74 GrProtected) override;
75 void deleteTestingOnlyBackendRenderTarget(const GrBackendRenderTarget&) override;
76
77 void resetShaderCacheForTesting() const override {
78 fResourceProvider.resetShaderCacheForTesting();
79 }
80#endif
81
83
85 GrMtlAttachment* dstAttachment, GrMtlAttachment* srcAttachment,
86 const SkIRect& srcRect, const SkIPoint& dstPoint);
87
88 bool onCopySurface(GrSurface* dst, const SkIRect& dstRect,
89 GrSurface* src, const SkIRect& srcRect,
90 GrSamplerState::Filter) override;
91
92 void submit(GrOpsRenderPass* renderPass) override;
93
94 [[nodiscard]] std::unique_ptr<GrSemaphore> makeSemaphore(bool isOwned) override;
95 std::unique_ptr<GrSemaphore> wrapBackendSemaphore(const GrBackendSemaphore&,
97 GrWrapOwnership) override;
98 void insertSemaphore(GrSemaphore* semaphore) override;
99 void waitSemaphore(GrSemaphore* semaphore) override;
100 void checkFinishProcs() override { this->checkForFinishedCommandBuffers(); }
101 void finishOutstandingGpuWork() override;
102 std::unique_ptr<GrSemaphore> prepareTextureForCrossContextUsage(GrTexture*) override;
103
106 const SkIRect& srcRect,
107 MTLRenderPassStencilAttachmentDescriptor*);
108
109 // When the Metal backend actually uses indirect command buffers, this function will actually do
110 // what it says. For now, every command is encoded directly into the primary command buffer, so
111 // this function is pretty useless, except for indicating that a render target has been drawn
112 // to.
114 const SkIRect* bounds) {
115 this->didWriteToSurface(surface, origin, bounds);
116 }
117
118 GrRingBuffer* uniformsRingBuffer() override { return &fUniformsRingBuffer; }
119
120private:
121 GrMtlGpu(GrDirectContext*, const GrContextOptions&, id<MTLDevice>, id<MTLCommandQueue>);
122
123 void destroyResources();
124
125 void xferBarrier(GrRenderTarget*, GrXferBarrierType) override {}
126
127 void takeOwnershipOfBuffer(sk_sp<GrGpuBuffer>) override;
128
129 GrBackendTexture onCreateBackendTexture(SkISize dimensions,
130 const GrBackendFormat&,
134 std::string_view label) override;
135
136 bool onClearBackendTexture(const GrBackendTexture&,
137 sk_sp<skgpu::RefCntedCallback> finishedCallback,
138 std::array<float, 4> color) override;
139
140 GrBackendTexture onCreateCompressedBackendTexture(SkISize dimensions,
141 const GrBackendFormat&,
143 GrProtected) override;
144
145 bool onUpdateCompressedBackendTexture(const GrBackendTexture&,
146 sk_sp<skgpu::RefCntedCallback> finishedCallback,
147 const void* data,
148 size_t size) override;
149
150 sk_sp<GrTexture> onCreateTexture(SkISize,
151 const GrBackendFormat&,
153 int renderTargetSampleCnt,
156 int mipLevelCount,
157 uint32_t levelClearMask,
158 std::string_view label) override;
159 sk_sp<GrTexture> onCreateCompressedTexture(SkISize dimensions,
160 const GrBackendFormat&,
164 const void* data,
165 size_t dataSize) override;
166
167 sk_sp<GrTexture> onWrapBackendTexture(const GrBackendTexture&,
170 GrIOType) override;
171
172 sk_sp<GrTexture> onWrapCompressedBackendTexture(const GrBackendTexture&,
174 GrWrapCacheable) override;
175
176 sk_sp<GrTexture> onWrapRenderableBackendTexture(const GrBackendTexture&,
177 int sampleCnt,
179 GrWrapCacheable) override;
180
181 sk_sp<GrRenderTarget> onWrapBackendRenderTarget(const GrBackendRenderTarget&) override;
182
183 sk_sp<GrGpuBuffer> onCreateBuffer(size_t, GrGpuBufferType, GrAccessPattern) override;
184
185 bool onReadPixels(GrSurface* surface,
186 SkIRect,
187 GrColorType surfaceColorType,
188 GrColorType bufferColorType,
189 void*,
190 size_t rowBytes) override;
191
192 bool onTransferFromBufferToBuffer(sk_sp<GrGpuBuffer> src,
193 size_t srcOffset,
195 size_t dstOffset,
196 size_t size) override;
197
198 bool onWritePixels(GrSurface*,
199 SkIRect,
200 GrColorType surfaceColorType,
201 GrColorType bufferColorType,
202 const GrMipLevel[],
203 int mipLevelCount,
204 bool prepForTexSampling) override;
205
206 bool onTransferPixelsTo(GrTexture*,
207 SkIRect,
208 GrColorType textureColorType,
209 GrColorType bufferColorType,
211 size_t offset,
212 size_t rowBytes) override;
213
214 bool onTransferPixelsFrom(GrSurface*,
215 SkIRect,
216 GrColorType surfaceColorType,
217 GrColorType bufferColorType,
219 size_t offset) override;
220
221 bool onRegenerateMipMapLevels(GrTexture*) override;
222
223 void onResolveRenderTarget(GrRenderTarget* target, const SkIRect& resolveRect) override;
224
225 void resolve(GrMtlAttachment* resolveAttachment, GrMtlAttachment* msaaAttachment);
226
227 void addFinishedProc(GrGpuFinishedProc finishedProc,
228 GrGpuFinishedContext finishedContext) override;
229 void addFinishedCallback(sk_sp<skgpu::RefCntedCallback> finishedCallback);
230
231 GrOpsRenderPass* onGetOpsRenderPass(
233 bool useMSAASurface,
236 const SkIRect&,
240 GrXferBarrierFlags renderPassXferBarriers) override;
241
242 bool onSubmitToGpu(GrSyncCpu sync) override;
243
244 // Commits the current command buffer to the queue and then creates a new command buffer. If
245 // sync is set to kForce_SyncQueue, the function will wait for all work in the committed
246 // command buffer to finish before returning.
247 bool submitCommandBuffer(SyncQueue sync);
248
249 void checkForFinishedCommandBuffers();
250
251 // Function that uploads data onto textures with private storage mode (GPU access only).
252 bool uploadToTexture(GrMtlTexture* tex,
254 GrColorType dataColorType,
255 const GrMipLevel texels[],
256 int mipLevels);
257
258 // Function that fills texture levels with transparent black based on levelMask.
259 bool clearTexture(GrMtlTexture*, size_t bbp, uint32_t levelMask);
260
261 bool readOrTransferPixels(GrSurface* surface,
263 GrColorType dstColorType,
264 id<MTLBuffer> transferBuffer,
265 size_t offset,
266 size_t imageBytes,
267 size_t rowBytes);
268
269 sk_sp<GrAttachment> makeStencilAttachment(const GrBackendFormat& /*colorFormat*/,
270 SkISize dimensions, int numStencilSamples) override;
271
272 GrBackendFormat getPreferredStencilFormat(const GrBackendFormat&) override {
273 return GrBackendFormats::MakeMtl(this->mtlCaps().preferredStencilFormat());
274 }
275
276 sk_sp<GrAttachment> makeMSAAAttachment(SkISize dimensions,
277 const GrBackendFormat& format,
278 int numSamples,
279 GrProtected isProtected,
280 GrMemoryless isMemoryless) override;
281
282 bool createMtlTextureForBackendSurface(MTLPixelFormat,
283 SkISize dimensions,
284 int sampleCnt,
288 GrMtlTextureInfo*);
289
290#if defined(GR_TEST_UTILS)
291 void testingOnly_startCapture() override;
292 void testingOnly_stopCapture() override;
293#endif
294
295#ifdef SK_ENABLE_DUMP_GPU
296 void onDumpJSON(SkJSONWriter*) const override;
297#endif
298
299 sk_sp<GrMtlCaps> fMtlCaps;
300
301 id<MTLDevice> fDevice;
302 id<MTLCommandQueue> fQueue;
303
304 sk_sp<GrMtlCommandBuffer> fCurrentCmdBuffer;
305
306 using OutstandingCommandBuffer = sk_sp<GrMtlCommandBuffer>;
307 SkDeque fOutstandingCommandBuffers;
308
309 GrMtlResourceProvider fResourceProvider;
310 GrStagingBufferManager fStagingBufferManager;
311 GrRingBuffer fUniformsRingBuffer;
312
313 bool fDisconnected;
314
315 using INHERITED = GrGpu;
316};
317
318#endif
GrWrapCacheable
Definition: GrTypesPriv.h:85
GrIOType
Definition: GrTypesPriv.h:402
GrWrapOwnership
Definition: GrTypesPriv.h:77
GrGpuBufferType
Definition: GrTypesPriv.h:411
GrMemoryless
Definition: GrTypesPriv.h:123
GrTexturable
Definition: GrTypesPriv.h:64
GrSemaphoreWrapType
Definition: GrTypesPriv.h:146
GrColorType
Definition: GrTypesPriv.h:540
GrAccessPattern
Definition: GrTypesPriv.h:424
GrSurfaceOrigin
Definition: GrTypes.h:147
void * GrGpuFinishedContext
Definition: GrTypes.h:178
void(* GrGpuFinishedProc)(GrGpuFinishedContext finishedContext)
Definition: GrTypes.h:179
GrSyncCpu
Definition: GrTypes.h:239
GrXferBarrierType
GrXferBarrierFlags
SkFilterMode
Definition: GrGpu.h:62
void didWriteToSurface(GrSurface *surface, GrSurfaceOrigin origin, const SkIRect *bounds, uint32_t mipLevels=1) const
Definition: GrGpu.cpp:665
GrGpu(GrDirectContext *direct)
Definition: GrGpu.cpp:41
DisconnectType
Definition: GrGpu.h:80
bool onCopySurface(GrSurface *dst, const SkIRect &dstRect, GrSurface *src, const SkIRect &srcRect, GrSamplerState::Filter) override
Definition: GrMtlGpu.mm:1265
sk_sp< GrThreadSafePipelineBuilder > refPipelineBuilder() override
Definition: GrMtlGpu.mm:126
std::unique_ptr< GrSemaphore > wrapBackendSemaphore(const GrBackendSemaphore &, GrSemaphoreWrapType, GrWrapOwnership) override
Definition: GrMtlGpu.mm:1603
GrRingBuffer * uniformsRingBuffer() override
Definition: GrMtlGpu.h:118
bool precompileShader(const SkData &key, const SkData &data) override
Definition: GrMtlGpu.mm:1147
~GrMtlGpu() override
Definition: GrMtlGpu.mm:107
GrMtlRenderCommandEncoder * loadMSAAFromResolve(GrAttachment *dst, GrMtlAttachment *src, const SkIRect &srcRect, MTLRenderPassStencilAttachmentDescriptor *)
Definition: GrMtlGpu.mm:1660
void insertSemaphore(GrSemaphore *semaphore) override
Definition: GrMtlGpu.mm:1611
static std::unique_ptr< GrGpu > Make(const GrMtlBackendContext &, const GrContextOptions &, GrDirectContext *)
Definition: GrMtlGpu.mm:56
void copySurfaceAsBlit(GrSurface *dst, GrSurface *src, GrMtlAttachment *dstAttachment, GrMtlAttachment *srcAttachment, const SkIRect &srcRect, const SkIPoint &dstPoint)
Definition: GrMtlGpu.mm:1230
GrMtlCommandBuffer * commandBuffer()
Definition: GrMtlGpu.mm:187
bool compile(const GrProgramDesc &, const GrProgramInfo &) override
Definition: GrMtlGpu.mm:1134
void disconnect(DisconnectType) override
Definition: GrMtlGpu.mm:113
const GrMtlCaps & mtlCaps() const
Definition: GrMtlGpu.h:47
void checkFinishProcs() override
Definition: GrMtlGpu.h:100
void copySurfaceAsResolve(GrSurface *dst, GrSurface *src)
Definition: GrMtlGpu.mm:1214
void deleteBackendTexture(const GrBackendTexture &) override
Definition: GrMtlGpu.mm:1129
std::unique_ptr< GrSemaphore > prepareTextureForCrossContextUsage(GrTexture *) override
Definition: GrMtlGpu.mm:300
@ kForce_SyncQueue
Definition: GrMtlGpu.h:58
@ kSkip_SyncQueue
Definition: GrMtlGpu.h:59
void waitSemaphore(GrSemaphore *semaphore) override
Definition: GrMtlGpu.mm:1620
id< MTLDevice > device() const
Definition: GrMtlGpu.h:49
GrStagingBufferManager * stagingBufferManager() override
Definition: GrMtlGpu.h:53
void finishOutstandingGpuWork() override
Definition: GrMtlGpu.mm:262
GrMtlResourceProvider & resourceProvider()
Definition: GrMtlGpu.h:51
GrThreadSafePipelineBuilder * pipelineBuilder() override
Definition: GrMtlGpu.mm:122
void submit(GrOpsRenderPass *renderPass) override
Definition: GrMtlGpu.mm:205
void submitIndirectCommandBuffer(GrSurface *surface, GrSurfaceOrigin origin, const SkIRect *bounds)
Definition: GrMtlGpu.h:113
std::unique_ptr< GrSemaphore > makeSemaphore(bool isOwned) override
Definition: GrMtlGpu.mm:1598
Definition: SkData.h:25
DlColor color
VkSurfaceKHR surface
Definition: main.cc:49
uint32_t uint32_t * format
uint32_t * target
SK_API GrBackendFormat MakeMtl(GrMTLPixelFormat format)
Optional< SkRect > bounds
Definition: SkRecords.h:189
sk_sp< SkBlender > blender SkRect rect
Definition: SkRecords.h:350
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Definition: switches.h:259
dst
Definition: cp.py:12
Budgeted
Definition: GpuTypes.h:35
Renderable
Definition: GpuTypes.h:69
Mipmapped
Definition: GpuTypes.h:53
Protected
Definition: GpuTypes.h:61
SeparatedVector2 offset
Definition: SkRect.h:32
Definition: SkSize.h:16
std::shared_ptr< const fml::Mapping > data
Definition: texture_gles.cc:63