Flutter Engine
The Flutter Engine
VulkanCommandBuffer.h
Go to the documentation of this file.
1/*
2 * Copyright 2022 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_VulkanCommandBuffer_DEFINED
9#define skgpu_graphite_VulkanCommandBuffer_DEFINED
10
12
16
17namespace skgpu::graphite {
18
19class VulkanBuffer;
20class VulkanDescriptorSet;
21class VulkanResourceProvider;
22class VulkanSharedContext;
23class VulkanTexture;
24class Buffer;
25
26class VulkanCommandBuffer final : public CommandBuffer {
27public:
28 static std::unique_ptr<VulkanCommandBuffer> Make(const VulkanSharedContext*,
30 ~VulkanCommandBuffer() override;
31
32 bool setNewCommandBufferResources() override;
33
34 bool submit(VkQueue);
35
36 bool isFinished();
37
38 void waitUntilFinished();
39
41 VkPipelineStageFlags srcStageMask,
42 VkPipelineStageFlags dstStageMask,
43 VkBufferMemoryBarrier* barrier);
45 VkPipelineStageFlags dstStageMask,
46 VkBufferMemoryBarrier* barrier);
48 VkPipelineStageFlags srcStageMask,
49 VkPipelineStageFlags dstStageMask,
50 bool byRegion,
51 VkImageMemoryBarrier* barrier);
52
53private:
54 VulkanCommandBuffer(VkCommandPool pool,
55 VkCommandBuffer primaryCommandBuffer,
56 const VulkanSharedContext* sharedContext,
57 VulkanResourceProvider* resourceProvider);
58
59 void onResetCommandBuffer() override;
60
61 void begin();
62 void end();
63
64 void addWaitSemaphores(size_t numWaitSemaphores,
65 const BackendSemaphore* waitSemaphores) override;
66 void addSignalSemaphores(size_t numWaitSemaphores,
67 const BackendSemaphore* signalSemaphores) override;
68 void prepareSurfaceForStateUpdate(SkSurface* targetSurface,
69 const MutableTextureState* newState) override;
70
71 bool onAddRenderPass(const RenderPassDesc&,
72 const Texture* colorTexture,
73 const Texture* resolveTexture,
74 const Texture* depthStencilTexture,
75 SkRect viewport,
76 const DrawPassList&) override;
77
78 bool beginRenderPass(const RenderPassDesc&,
79 const Texture* colorTexture,
80 const Texture* resolveTexture,
81 const Texture* depthStencilTexture);
82 void endRenderPass();
83
84 void addDrawPass(const DrawPass*);
85
86 // Track descriptor changes for binding prior to draw calls
87 void recordBufferBindingInfo(const BindUniformBufferInfo& info, UniformSlot);
88 void recordTextureAndSamplerDescSet(
89 const DrawPass&, const DrawPassCommands::BindTexturesAndSamplers&);
90
91 void bindTextureSamplers();
92 void bindUniformBuffers();
93 void syncDescriptorSets();
94
95 void bindGraphicsPipeline(const GraphicsPipeline*);
96 void setBlendConstants(float* blendConstants);
97 void bindDrawBuffers(const BindBufferInfo& vertices,
98 const BindBufferInfo& instances,
99 const BindBufferInfo& indices,
100 const BindBufferInfo& indirect);
101 void bindVertexBuffers(const Buffer* vertexBuffer, size_t vertexOffset,
102 const Buffer* instanceBuffer, size_t instanceOffset);
103 void bindInputBuffer(const Buffer* buffer, VkDeviceSize offset, uint32_t binding);
104 void bindIndexBuffer(const Buffer* indexBuffer, size_t offset);
105 void bindIndirectBuffer(const Buffer* indirectBuffer, size_t offset);
106 void setScissor(unsigned int left, unsigned int top,
107 unsigned int width, unsigned int height);
108
109 void draw(PrimitiveType type, unsigned int baseVertex, unsigned int vertexCount);
110 void drawIndexed(PrimitiveType type, unsigned int baseIndex, unsigned int indexCount,
111 unsigned int baseVertex);
112 void drawInstanced(PrimitiveType type,
113 unsigned int baseVertex, unsigned int vertexCount,
114 unsigned int baseInstance, unsigned int instanceCount);
115 void drawIndexedInstanced(PrimitiveType type, unsigned int baseIndex,
116 unsigned int indexCount, unsigned int baseVertex,
117 unsigned int baseInstance, unsigned int instanceCount);
118 void drawIndirect(PrimitiveType type);
119 void drawIndexedIndirect(PrimitiveType type);
120
121 // TODO: The virtuals in this class have not yet been implemented as we still haven't
122 // implemented the objects they use.
123 bool onAddComputePass(DispatchGroupSpan) override;
124
125 bool onCopyBufferToBuffer(const Buffer* srcBuffer,
126 size_t srcOffset,
127 const Buffer* dstBuffer,
128 size_t dstOffset,
129 size_t size) override;
130 bool onCopyTextureToBuffer(const Texture*,
131 SkIRect srcRect,
132 const Buffer*,
133 size_t bufferOffset,
134 size_t bufferRowBytes) override;
135 bool onCopyBufferToTexture(const Buffer*,
136 const Texture*,
137 const BufferTextureCopyData* copyData,
138 int count) override;
139 bool onCopyTextureToTexture(const Texture* src,
140 SkIRect srcRect,
141 const Texture* dst,
142 SkIPoint dstPoint,
143 int mipLevel) override;
144
145 bool onSynchronizeBufferToCpu(const Buffer*, bool* outDidResultInWork) override;
146 bool onClearBuffer(const Buffer*, size_t offset, size_t size) override;
147
148 enum BarrierType {
149 kBufferMemory_BarrierType,
150 kImageMemory_BarrierType
151 };
152 void pipelineBarrier(const Resource* resource,
153 VkPipelineStageFlags srcStageMask,
154 VkPipelineStageFlags dstStageMask,
155 bool byRegion,
156 BarrierType barrierType,
157 void* barrier);
158 void submitPipelineBarriers(bool forSelfDependency = false);
159
160 // Update the intrinsic constant uniform with the latest rtAdjust value as determined by a
161 // given viewport. The resource provider is responsible for finding a suitable buffer and
162 // managing its lifetime.
163 void updateRtAdjustUniform(const SkRect& viewport);
164
165 bool updateLoadMSAAVertexBuffer();
166 bool loadMSAAFromResolve(const RenderPassDesc&,
167 VulkanTexture& resolveTexture,
168 SkISize dstDimensions);
169 bool updateAndBindLoadMSAAInputAttachment(const VulkanTexture& resolveTexture);
170 void updateBuffer(const VulkanBuffer* buffer,
171 const void* data,
172 size_t dataSize,
173 size_t dstOffset = 0);
174 void nextSubpass();
175 void setViewport(const SkRect& viewport);
176
177 VkCommandPool fPool;
178 VkCommandBuffer fPrimaryCommandBuffer;
179 const VulkanSharedContext* fSharedContext;
180 VulkanResourceProvider* fResourceProvider;
181
182 // begin() has been called, but not end()
183 bool fActive = false;
184 // Track whether there is currently an active render pass (beginRenderPass has been called, but
185 // not endRenderPass)
186 bool fActiveRenderPass = false;
187
188 const VulkanGraphicsPipeline* fActiveGraphicsPipeline = nullptr;
189
190 VkFence fSubmitFence = VK_NULL_HANDLE;
191
192 // Current semaphores
195
196 // Tracking of memory barriers so that we can submit them all in a batch together.
199 bool fBarriersByRegion = false;
200 VkPipelineStageFlags fSrcStageMask = 0;
201 VkPipelineStageFlags fDstStageMask = 0;
202
203 // Track whether certain descriptor sets need to be bound
204 bool fBindUniformBuffers = false;
205 bool fBindTextureSamplers = false;
206
207 std::array<BindUniformBufferInfo, VulkanGraphicsPipeline::kNumUniformBuffers>
208 fUniformBuffersToBind;
209 VkDescriptorSet fTextureSamplerDescSetToBind = VK_NULL_HANDLE;
210
211 int fNumTextureSamplers = 0;
212
213 VkBuffer fBoundInputBuffers[VulkanGraphicsPipeline::kNumInputBuffers];
214 size_t fBoundInputBufferOffsets[VulkanGraphicsPipeline::kNumInputBuffers];
215
216 VkBuffer fBoundIndexBuffer = VK_NULL_HANDLE;
217 VkBuffer fBoundIndirectBuffer = VK_NULL_HANDLE;
218 size_t fBoundIndexBufferOffset = 0;
219 size_t fBoundIndirectBufferOffset = 0;
220
221 float fCachedBlendConstant[4];
222};
223
224} // namespace skgpu::graphite
225
226#endif // skgpu_graphite_VulkanCommandBuffer_DEFINED
227
AutoreleasePool pool
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition: DM.cpp:213
int count
Definition: FontMgrTest.cpp:50
static SkString resource(SkPDFResourceType type, int index)
GLenum type
void addBufferMemoryBarrier(const Resource *resource, VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask, VkBufferMemoryBarrier *barrier)
void addImageMemoryBarrier(const Resource *, VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask, bool byRegion, VkImageMemoryBarrier *barrier)
static std::unique_ptr< VulkanCommandBuffer > Make(const VulkanSharedContext *, VulkanResourceProvider *)
static constexpr unsigned int kNumInputBuffers
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
int32_t height
int32_t width
SeparatedVector2 offset
Definition: SkRect.h:32
Definition: SkSize.h:16
std::shared_ptr< const fml::Mapping > data
Definition: texture_gles.cc:63
VkFlags VkPipelineStageFlags
Definition: vulkan_core.h:2470
uint64_t VkDeviceSize
Definition: vulkan_core.h:96
#define VK_NULL_HANDLE
Definition: vulkan_core.h:46