Flutter Engine
The Flutter Engine
GrD3DGpu.h
Go to the documentation of this file.
1/*
2 * Copyright 2020 Google LLC
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 GrD3DGpu_DEFINED
9#define GrD3DGpu_DEFINED
10
19
22struct GrD3DOptions;
23class GrPipeline;
24#if defined(GR_TEST_UTILS)
25struct IDXGraphicsAnalysis;
26#endif
27
28class GrD3DGpu : public GrGpu {
29public:
30 static std::unique_ptr<GrGpu> Make(const GrD3DBackendContext& backendContext,
31 const GrContextOptions&,
33
34 ~GrD3DGpu() override;
35
36 const GrD3DCaps& d3dCaps() const { return static_cast<const GrD3DCaps&>(*this->caps()); }
37
38 GrD3DResourceProvider& resourceProvider() { return fResourceProvider; }
39
42
43 ID3D12Device* device() const { return fDevice.get(); }
44 ID3D12CommandQueue* queue() const { return fQueue.get(); }
45
46 GrD3DMemoryAllocator* memoryAllocator() const { return fMemoryAllocator.get(); }
47
48 GrD3DDirectCommandList* currentCommandList() const { return fCurrentDirectCommandList.get(); }
49
50 GrStagingBufferManager* stagingBufferManager() override { return &fStagingBufferManager; }
52
53 GrRingBuffer* uniformsRingBuffer() override { return &fConstantsRingBuffer; }
54
55 bool protectedContext() const { return false; }
56
58
59 void deleteBackendTexture(const GrBackendTexture&) override;
60
61 bool compile(const GrProgramDesc&, const GrProgramInfo&) override;
62
63#if defined(GR_TEST_UTILS)
64 bool isTestingOnlyBackendTexture(const GrBackendTexture&) const override;
65
66 GrBackendRenderTarget createTestingOnlyBackendRenderTarget(SkISize dimensions,
68 int sampleCnt,
69 GrProtected) override;
70 void deleteTestingOnlyBackendRenderTarget(const GrBackendRenderTarget&) override;
71
72 void testingOnly_startCapture() override;
73 void testingOnly_stopCapture() override;
74
75 void resetShaderCacheForTesting() const override {
76 fResourceProvider.resetShaderCacheForTesting();
77 }
78#endif
79
81 SkISize dimensions, int numStencilSamples) override;
82
84 return GrBackendFormat::MakeDxgi(this->d3dCaps().preferredStencilFormat());
85 }
86
89 int numSamples,
90 GrProtected isProtected,
91 GrMemoryless isMemoryless) override {
92 return nullptr;
93 }
94
96 int numBarriers,
97 D3D12_RESOURCE_TRANSITION_BARRIER* barriers) const;
98
100 int numBarriers,
101 D3D12_RESOURCE_TRANSITION_BARRIER* barriers) const;
102
103 [[nodiscard]] std::unique_ptr<GrSemaphore> makeSemaphore(bool isOwned) override;
104 std::unique_ptr<GrSemaphore> wrapBackendSemaphore(const GrBackendSemaphore&,
106 GrWrapOwnership) override;
107 void insertSemaphore(GrSemaphore* semaphore) override;
108 void waitSemaphore(GrSemaphore* semaphore) override;
109 std::unique_ptr<GrSemaphore> prepareTextureForCrossContextUsage(GrTexture*) override {
110 return nullptr;
111 }
112
113 void submit(GrOpsRenderPass* renderPass) override;
115 const SkIRect& bounds);
116
117 void checkFinishProcs() override { this->checkForFinishedCommandLists(); }
118 void finishOutstandingGpuWork() override;
119
120private:
121 enum class SyncQueue {
122 kForce,
123 kSkip
124 };
125
128
129 void destroyResources();
130
131 sk_sp<GrTexture> onCreateTexture(SkISize,
132 const GrBackendFormat&,
134 int renderTargetSampleCnt,
137 int mipLevelCount,
138 uint32_t levelClearMask,
139 std::string_view label) override;
140
141 sk_sp<GrTexture> onCreateCompressedTexture(SkISize dimensions,
142 const GrBackendFormat&,
146 const void* data,
147 size_t dataSize) override;
148
149 sk_sp<GrTexture> onWrapBackendTexture(const GrBackendTexture&,
152 GrIOType) override;
153 sk_sp<GrTexture> onWrapCompressedBackendTexture(const GrBackendTexture&,
155 GrWrapCacheable) override;
156
157 sk_sp<GrTexture> onWrapRenderableBackendTexture(const GrBackendTexture&,
158 int sampleCnt,
160 GrWrapCacheable) override;
161
162 sk_sp<GrRenderTarget> onWrapBackendRenderTarget(const GrBackendRenderTarget&) override;
163
164 sk_sp<GrGpuBuffer> onCreateBuffer(size_t sizeInBytes,
166 GrAccessPattern) override;
167
168 bool onReadPixels(GrSurface*,
169 SkIRect,
170 GrColorType surfaceColorType,
171 GrColorType dstColorType,
172 void*,
173 size_t rowBytes) override;
174
175 bool onWritePixels(GrSurface*,
176 SkIRect,
177 GrColorType surfaceColorType,
178 GrColorType srcColorType,
179 const GrMipLevel[],
180 int mipLevelCount,
181 bool prepForTexSampling) override;
182
183 bool onTransferFromBufferToBuffer(sk_sp<GrGpuBuffer> src,
184 size_t srcOffset,
186 size_t dstOffset,
187 size_t size) override;
188
189 bool onTransferPixelsTo(GrTexture*,
190 SkIRect,
191 GrColorType surfaceColorType,
192 GrColorType bufferColorType,
194 size_t offset,
195 size_t rowBytes) override;
196
197 bool onTransferPixelsFrom(GrSurface*,
198 SkIRect,
199 GrColorType surfaceColorType,
200 GrColorType bufferColorType,
202 size_t offset) override;
203
204 bool onCopySurface(GrSurface* dst, const SkIRect& dstRect,
205 GrSurface* src, const SkIRect& srcRect,
206 GrSamplerState::Filter) override;
207
208 bool onRegenerateMipMapLevels(GrTexture*) override;
209
210 void onResolveRenderTarget(GrRenderTarget* target, const SkIRect&) override;
211
212 void addFinishedProc(GrGpuFinishedProc finishedProc,
213 GrGpuFinishedContext finishedContext) override;
214 void addFinishedCallback(sk_sp<skgpu::RefCntedCallback> finishedCallback);
215
216 GrOpsRenderPass* onGetOpsRenderPass(
218 bool useMSAASurface,
221 const SkIRect&,
225 GrXferBarrierFlags renderPassXferBarriers) override;
226
227 void prepareSurfacesForBackendAccessAndStateUpdates(
230 const skgpu::MutableTextureState* newState) override;
231
232 bool onSubmitToGpu(GrSyncCpu sync) override;
233
234 GrBackendTexture onCreateBackendTexture(SkISize dimensions,
235 const GrBackendFormat&,
239 std::string_view label) override;
240
241 bool onClearBackendTexture(const GrBackendTexture&,
242 sk_sp<skgpu::RefCntedCallback> finishedCallback,
243 std::array<float, 4> color) override;
244
245 GrBackendTexture onCreateCompressedBackendTexture(SkISize dimensions,
246 const GrBackendFormat&,
248 GrProtected) override;
249
250 bool onUpdateCompressedBackendTexture(const GrBackendTexture&,
251 sk_sp<skgpu::RefCntedCallback> finishedCallback,
252 const void* data,
253 size_t size) override;
254
255 bool submitDirectCommandList(SyncQueue sync);
256
257 void checkForFinishedCommandLists();
258 void waitForQueueCompletion();
259
260 void copySurfaceAsCopyTexture(GrSurface* dst, GrSurface* src, GrD3DTextureResource* dstResource,
261 GrD3DTextureResource* srcResource, const SkIRect& srcRect,
262 const SkIPoint& dstPoint);
263
264 void copySurfaceAsResolve(GrSurface* dst, GrSurface* src, const SkIRect& srcRect,
265 const SkIPoint& dstPoint);
266 void resolveTexture(GrSurface* dst, int32_t dstX, int32_t dstY,
267 GrD3DRenderTarget* src, const SkIRect& srcRect);
268
269 sk_sp<GrD3DTexture> createD3DTexture(SkISize,
270 DXGI_FORMAT,
272 int renderTargetSampleCnt,
275 int mipLevelCount,
277 std::string_view label);
278
279 bool uploadToTexture(GrD3DTexture* tex,
282 const GrMipLevel texels[],
283 int mipLevelCount);
284
285 void readOrTransferPixels(GrD3DTextureResource* texResource,
287 sk_sp<GrGpuBuffer> transferBuffer,
288 const D3D12_PLACED_SUBRESOURCE_FOOTPRINT& placedFootprint);
289
290 bool createTextureResourceForBackendSurface(DXGI_FORMAT dxgiFormat,
291 SkISize dimensions,
292 GrTexturable texturable,
293 GrRenderable renderable,
294 skgpu::Mipmapped mipmapped,
295 int sampleCnt,
297 GrProtected isProtected);
298
299 gr_cp<ID3D12Device> fDevice;
301
302 sk_sp<GrD3DMemoryAllocator> fMemoryAllocator;
303
304 GrD3DResourceProvider fResourceProvider;
305 GrStagingBufferManager fStagingBufferManager;
306 GrRingBuffer fConstantsRingBuffer;
307
308 gr_cp<ID3D12Fence> fFence;
309 uint64_t fCurrentFenceValue = 0;
310
311 std::unique_ptr<GrD3DDirectCommandList> fCurrentDirectCommandList;
312 // One-off special-case descriptors created directly for the mipmap compute shader
313 // and hence aren't tracked by the normal path.
315
316 struct OutstandingCommandList {
317 OutstandingCommandList(std::unique_ptr<GrD3DDirectCommandList> commandList,
318 uint64_t fenceValue)
319 : fCommandList(std::move(commandList)), fFenceValue(fenceValue) {
320 }
321 std::unique_ptr<GrD3DDirectCommandList> fCommandList;
322 uint64_t fFenceValue;
323 };
324
325 SkDeque fOutstandingCommandLists;
326
327 std::unique_ptr<GrD3DOpsRenderPass> fCachedOpsRenderPass;
328
329#if defined(GR_TEST_UTILS)
330 IDXGraphicsAnalysis* fGraphicsAnalysis;
331#endif
332
333 using INHERITED = GrGpu;
334};
335
336#endif
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition: DM.cpp:213
GrWrapCacheable
Definition: GrTypesPriv.h:85
GrIOType
Definition: GrTypesPriv.h:402
GrMipmapStatus
Definition: GrTypesPriv.h:523
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
static SkColorType colorType(AImageDecoder *decoder, const AImageDecoderHeaderInfo *headerInfo)
static SkString resource(SkPDFResourceType type, int index)
SkFilterMode
void deleteBackendTexture(const GrBackendTexture &) override
Definition: GrD3DGpu.cpp:1644
void addBufferResourceBarriers(GrD3DBuffer *buffer, int numBarriers, D3D12_RESOURCE_TRANSITION_BARRIER *barriers) const
Definition: GrD3DGpu.cpp:1729
GrD3DDirectCommandList * currentCommandList() const
Definition: GrD3DGpu.h:48
void submit(GrOpsRenderPass *renderPass) override
Definition: GrD3DGpu.cpp:233
void insertSemaphore(GrSemaphore *semaphore) override
Definition: GrD3DGpu.cpp:1786
const GrD3DCaps & d3dCaps() const
Definition: GrD3DGpu.h:36
bool compile(const GrProgramDesc &, const GrProgramInfo &) override
Definition: GrD3DGpu.cpp:1649
static std::unique_ptr< GrGpu > Make(const GrD3DBackendContext &backendContext, const GrContextOptions &, GrDirectContext *)
Definition: GrD3DGpu.cpp:50
~GrD3DGpu() override
Definition: GrD3DGpu.cpp:109
ID3D12CommandQueue * queue() const
Definition: GrD3DGpu.h:44
std::unique_ptr< GrSemaphore > wrapBackendSemaphore(const GrBackendSemaphore &, GrSemaphoreWrapType, GrWrapOwnership) override
Definition: GrD3DGpu.cpp:1775
sk_sp< GrAttachment > makeMSAAAttachment(SkISize dimensions, const GrBackendFormat &format, int numSamples, GrProtected isProtected, GrMemoryless isMemoryless) override
Definition: GrD3DGpu.h:87
GrBackendFormat getPreferredStencilFormat(const GrBackendFormat &) override
Definition: GrD3DGpu.h:83
void checkFinishProcs() override
Definition: GrD3DGpu.h:117
void waitSemaphore(GrSemaphore *semaphore) override
Definition: GrD3DGpu.cpp:1793
GrD3DMemoryAllocator * memoryAllocator() const
Definition: GrD3DGpu.h:46
void addResourceBarriers(sk_sp< GrManagedResource > resource, int numBarriers, D3D12_RESOURCE_TRANSITION_BARRIER *barriers) const
Definition: GrD3DGpu.cpp:1720
void takeOwnershipOfBuffer(sk_sp< GrGpuBuffer >) override
Definition: GrD3DGpu.cpp:1760
void xferBarrier(GrRenderTarget *, GrXferBarrierType) override
Definition: GrD3DGpu.h:57
void endRenderPass(GrRenderTarget *target, GrSurfaceOrigin origin, const SkIRect &bounds)
Definition: GrD3DGpu.cpp:240
GrD3DResourceProvider & resourceProvider()
Definition: GrD3DGpu.h:38
sk_sp< GrThreadSafePipelineBuilder > refPipelineBuilder() override
Definition: GrD3DGpu.cpp:45
GrRingBuffer * uniformsRingBuffer() override
Definition: GrD3DGpu.h:53
std::unique_ptr< GrSemaphore > makeSemaphore(bool isOwned) override
Definition: GrD3DGpu.cpp:1772
GrThreadSafePipelineBuilder * pipelineBuilder() override
Definition: GrD3DGpu.cpp:41
bool protectedContext() const
Definition: GrD3DGpu.h:55
ID3D12Device * device() const
Definition: GrD3DGpu.h:43
void finishOutstandingGpuWork() override
Definition: GrD3DGpu.cpp:1800
std::unique_ptr< GrSemaphore > prepareTextureForCrossContextUsage(GrTexture *) override
Definition: GrD3DGpu.h:109
sk_sp< GrAttachment > makeStencilAttachment(const GrBackendFormat &, SkISize dimensions, int numStencilSamples) override
Definition: GrD3DGpu.cpp:1324
GrStagingBufferManager * stagingBufferManager() override
Definition: GrD3DGpu.h:50
Definition: GrGpu.h:62
const GrCaps * caps() const
Definition: GrGpu.h:73
GrGpu(GrDirectContext *direct)
Definition: GrGpu.cpp:41
T * get() const
Definition: GrD3DTypes.h:108
T * get() const
Definition: SkRefCnt.h:303
DlColor color
uint32_t uint32_t * format
uint32_t * target
Optional< SkRect > bounds
Definition: SkRecords.h:189
sk_sp< SkBlender > blender SkRect rect
Definition: SkRecords.h:350
BackendSurfaceAccess
Definition: SkSurface.h:44
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
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
Definition: ref_ptr.h:256
SeparatedVector2 offset
Definition: SkRect.h:32
Definition: SkSize.h:16
std::shared_ptr< const fml::Mapping > data
Definition: texture_gles.cc:63