Flutter Engine
The Flutter Engine
CommandBuffer.h
Go to the documentation of this file.
1/*
2 * Copyright 2021 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 skgpu_graphite_CommandBuffer_DEFINED
9#define skgpu_graphite_CommandBuffer_DEFINED
10
12#include "include/core/SkRect.h"
15#include "src/gpu/GpuRefCnt.h"
20
21namespace skgpu {
22class RefCntedCallback;
23class MutableTextureState;
24}
25
26namespace skgpu::graphite {
27
28class Buffer;
29class DispatchGroup;
30class DrawPass;
31class SharedContext;
32class GraphicsPipeline;
33struct RenderPassDesc;
34class Sampler;
35class Texture;
36class TextureProxy;
37
39public:
42
43 virtual ~CommandBuffer();
44
45#ifdef SK_DEBUG
46 bool hasWork() { return fHasWork; }
47#endif
48
49 // Takes a Usage ref on the Resource that will be released when the command buffer has finished
50 // execution.
52 // Takes a CommandBuffer ref on the Resource that will be released when the command buffer has
53 // finished execution. This allows a Resource to be returned to ResourceCache for reuse while
54 // the CommandBuffer is still executing on the GPU. This is most commonly used for Textures or
55 // Buffers which are only accessed via commands on a command buffer.
57 // Release all tracked Resources
58 void resetCommandBuffer();
59
60 // If any work is needed to create new resources for a fresh command buffer do that here.
61 virtual bool setNewCommandBufferResources() = 0;
62
64 void callFinishedProcs(bool success);
65
66 virtual void addWaitSemaphores(size_t numWaitSemaphores,
67 const BackendSemaphore* waitSemaphores) {}
68 virtual void addSignalSemaphores(size_t numWaitSemaphores,
69 const BackendSemaphore* signalSemaphores) {}
70 virtual void prepareSurfaceForStateUpdate(SkSurface* targetSurface,
71 const MutableTextureState* newState) {}
72
75
76 bool addRenderPass(const RenderPassDesc&,
77 sk_sp<Texture> colorTexture,
78 sk_sp<Texture> resolveTexture,
79 sk_sp<Texture> depthStencilTexture,
80 SkRect viewport,
81 const DrawPassList& drawPasses);
82
83 bool addComputePass(DispatchGroupSpan dispatchGroups);
84
85 //---------------------------------------------------------------
86 // Can only be used outside renderpasses
87 //---------------------------------------------------------------
88 bool copyBufferToBuffer(const Buffer* srcBuffer,
89 size_t srcOffset,
90 sk_sp<Buffer> dstBuffer,
91 size_t dstOffset,
92 size_t size);
94 SkIRect srcRect,
96 size_t bufferOffset,
97 size_t bufferRowBytes);
98 bool copyBufferToTexture(const Buffer*,
101 int count);
103 SkIRect srcRect,
105 SkIPoint dstPoint,
106 int mipLevel);
108 bool clearBuffer(const Buffer* buffer, size_t offset, size_t size);
109
110 // This sets a translation to be applied to any subsequently added command, assuming these
111 // commands are part of a translated replay of a Graphite recording.
112 void setReplayTranslation(SkIVector translation) { fReplayTranslation = translation; }
114
115protected:
117
120
121private:
122 // Release all tracked Resources
123 void releaseResources();
124
125 virtual void onResetCommandBuffer() = 0;
126
127 virtual bool onAddRenderPass(const RenderPassDesc&,
128 const Texture* colorTexture,
129 const Texture* resolveTexture,
130 const Texture* depthStencilTexture,
131 SkRect viewport,
132 const DrawPassList& drawPasses) = 0;
133
134 virtual bool onAddComputePass(DispatchGroupSpan dispatchGroups) = 0;
135
136 virtual bool onCopyBufferToBuffer(const Buffer* srcBuffer,
137 size_t srcOffset,
138 const Buffer* dstBuffer,
139 size_t dstOffset,
140 size_t size) = 0;
141 virtual bool onCopyTextureToBuffer(const Texture*,
142 SkIRect srcRect,
143 const Buffer*,
144 size_t bufferOffset,
145 size_t bufferRowBytes) = 0;
146 virtual bool onCopyBufferToTexture(const Buffer*,
147 const Texture*,
149 int count) = 0;
150 virtual bool onCopyTextureToTexture(const Texture* src,
151 SkIRect srcRect,
152 const Texture* dst,
153 SkIPoint dstPoint,
154 int mipLevel) = 0;
155 virtual bool onSynchronizeBufferToCpu(const Buffer*, bool* outDidResultInWork) = 0;
156 virtual bool onClearBuffer(const Buffer*, size_t offset, size_t size) = 0;
157
158#ifdef SK_DEBUG
159 bool fHasWork = false;
160#endif
161 inline static constexpr int kInitialTrackedResourcesCount = 32;
162 template <typename T>
164 TrackedResourceArray<sk_sp<Resource>> fTrackedUsageResources;
165 TrackedResourceArray<gr_cb<Resource>> fCommandBufferResources;
167 skia_private::TArray<sk_sp<Buffer>> fBuffersToAsyncMap;
168};
169
170} // namespace skgpu::graphite
171
172#endif // skgpu_graphite_CommandBuffer_DEFINED
int count
Definition: FontMgrTest.cpp:50
static SkString resource(SkPDFResourceType type, int index)
virtual bool onClearBuffer(const Buffer *, size_t offset, size_t size)=0
virtual bool onAddComputePass(DispatchGroupSpan dispatchGroups)=0
skia_private::TArray< std::unique_ptr< DrawPass > > DrawPassList
Definition: CommandBuffer.h:40
virtual bool onSynchronizeBufferToCpu(const Buffer *, bool *outDidResultInWork)=0
bool clearBuffer(const Buffer *buffer, size_t offset, size_t size)
bool addRenderPass(const RenderPassDesc &, sk_sp< Texture > colorTexture, sk_sp< Texture > resolveTexture, sk_sp< Texture > depthStencilTexture, SkRect viewport, const DrawPassList &drawPasses)
virtual bool setNewCommandBufferResources()=0
bool copyBufferToTexture(const Buffer *, sk_sp< Texture >, const BufferTextureCopyData *, int count)
void addBuffersToAsyncMapOnSubmit(SkSpan< const sk_sp< Buffer > >)
bool addComputePass(DispatchGroupSpan dispatchGroups)
virtual bool onCopyTextureToBuffer(const Texture *, SkIRect srcRect, const Buffer *, size_t bufferOffset, size_t bufferRowBytes)=0
SkSpan< const sk_sp< Buffer > > buffersToAsyncMapOnSubmit() const
virtual void addSignalSemaphores(size_t numWaitSemaphores, const BackendSemaphore *signalSemaphores)
Definition: CommandBuffer.h:68
virtual bool onAddRenderPass(const RenderPassDesc &, const Texture *colorTexture, const Texture *resolveTexture, const Texture *depthStencilTexture, SkRect viewport, const DrawPassList &drawPasses)=0
virtual bool onCopyBufferToBuffer(const Buffer *srcBuffer, size_t srcOffset, const Buffer *dstBuffer, size_t dstOffset, size_t size)=0
bool copyTextureToTexture(sk_sp< Texture > src, SkIRect srcRect, sk_sp< Texture > dst, SkIPoint dstPoint, int mipLevel)
virtual void onResetCommandBuffer()=0
bool copyTextureToBuffer(sk_sp< Texture >, SkIRect srcRect, sk_sp< Buffer >, size_t bufferOffset, size_t bufferRowBytes)
void trackResource(sk_sp< Resource > resource)
virtual void prepareSurfaceForStateUpdate(SkSurface *targetSurface, const MutableTextureState *newState)
Definition: CommandBuffer.h:70
virtual bool onCopyTextureToTexture(const Texture *src, SkIRect srcRect, const Texture *dst, SkIPoint dstPoint, int mipLevel)=0
virtual void addWaitSemaphores(size_t numWaitSemaphores, const BackendSemaphore *waitSemaphores)
Definition: CommandBuffer.h:66
void setReplayTranslation(SkIVector translation)
void addFinishedProc(sk_sp< RefCntedCallback > finishedProc)
bool synchronizeBufferToCpu(sk_sp< Buffer >)
virtual bool onCopyBufferToTexture(const Buffer *, const Texture *, const BufferTextureCopyData *, int count)=0
void callFinishedProcs(bool success)
SkSpan< const std::unique_ptr< DispatchGroup > > DispatchGroupSpan
Definition: CommandBuffer.h:41
bool copyBufferToBuffer(const Buffer *srcBuffer, size_t srcOffset, sk_sp< Buffer > dstBuffer, size_t dstOffset, size_t size)
void trackCommandBufferResource(sk_sp< Resource > resource)
std::function< ProfileSample(void)> Sampler
Sampler is run during SamplingProfiler::SampleRepeatedly. Each platform should implement its version ...
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
Definition: GpuTools.h:21
SeparatedVector2 offset
Definition: SkRect.h:32
Definition: SkSize.h:16