Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
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.
51 void trackResource(sk_sp<Resource> resource);
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,
104 sk_sp<Texture> dst,
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
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
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)
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)
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)
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
bool copyBufferToBuffer(const Buffer *srcBuffer, size_t srcOffset, sk_sp< Buffer > dstBuffer, size_t dstOffset, size_t size)
void trackCommandBufferResource(sk_sp< Resource > resource)
static const uint8_t buffer[]
std::function< ProfileSample(void)> Sampler
Sampler is run during SamplingProfiler::SampleRepeatedly. Each platform should implement its version ...
Point offset