Flutter Engine
The Flutter Engine
DawnCommandBuffer.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_DawnCommandBuffer_DEFINED
9#define skgpu_graphite_DawnCommandBuffer_DEFINED
10
17
18#include "webgpu/webgpu_cpp.h" // NO_G3_REWRITE
19
20namespace skgpu::graphite {
21class ComputePipeline;
22class DawnBuffer;
23class DawnComputePipeline;
24class DawnQueueManager;
25class DawnResourceProvider;
26class DawnSharedContext;
27class DawnTexture;
28class DispatchGroup;
29struct WorkgroupSize;
30
31class DawnCommandBuffer final : public CommandBuffer {
32public:
33 static std::unique_ptr<DawnCommandBuffer> Make(const DawnSharedContext*, DawnResourceProvider*);
34 ~DawnCommandBuffer() override;
35
36 wgpu::CommandBuffer finishEncoding();
37
38private:
39 DawnCommandBuffer(const DawnSharedContext* sharedContext,
40 DawnResourceProvider* resourceProvider);
41
42 void onResetCommandBuffer() override;
43 bool setNewCommandBufferResources() override;
44
45 bool onAddRenderPass(const RenderPassDesc&,
46 const Texture* colorTexture,
47 const Texture* resolveTexture,
48 const Texture* depthStencilTexture,
49 SkRect viewport,
50 const DrawPassList&) override;
51 bool onAddComputePass(DispatchGroupSpan) override;
52
53 // Methods for populating a Dawn RenderPassEncoder:
54 bool beginRenderPass(const RenderPassDesc&,
55 const Texture* colorTexture,
56 const Texture* resolveTexture,
57 const Texture* depthStencilTexture);
58 bool loadMSAAFromResolveAndBeginRenderPassEncoder(
59 const RenderPassDesc& frontendRenderPassDesc,
60 const wgpu::RenderPassDescriptor& wgpuRenderPassDesc,
61 const DawnTexture* msaaTexture);
62 bool doBlitWithDraw(const wgpu::RenderPassEncoder& renderEncoder,
63 const RenderPassDesc& frontendRenderPassDesc,
64 const wgpu::TextureView& sourceTextureView,
65 int width,
66 int height);
67 void endRenderPass();
68
69 bool addDrawPass(const DrawPass*);
70
71 bool bindGraphicsPipeline(const GraphicsPipeline*);
72 void setBlendConstants(float* blendConstants);
73
74 void bindUniformBuffer(const BindUniformBufferInfo& info, UniformSlot);
75 void bindDrawBuffers(const BindBufferInfo& vertices,
76 const BindBufferInfo& instances,
77 const BindBufferInfo& indices,
78 const BindBufferInfo& indirect);
79
80 void bindTextureAndSamplers(const DrawPass& drawPass,
81 const DrawPassCommands::BindTexturesAndSamplers& command);
82
83 void setScissor(unsigned int left, unsigned int top, unsigned int width, unsigned int height);
84 void preprocessViewport(const SkRect& viewport);
85 void setViewport(const SkRect& viewport);
86
87 void draw(PrimitiveType type, unsigned int baseVertex, unsigned int vertexCount);
88 void drawIndexed(PrimitiveType type,
89 unsigned int baseIndex,
90 unsigned int indexCount,
91 unsigned int baseVertex);
92 void drawInstanced(PrimitiveType type,
93 unsigned int baseVertex,
94 unsigned int vertexCount,
95 unsigned int baseInstance,
96 unsigned int instanceCount);
97 void drawIndexedInstanced(PrimitiveType type,
98 unsigned int baseIndex,
99 unsigned int indexCount,
100 unsigned int baseVertex,
101 unsigned int baseInstance,
102 unsigned int instanceCount);
103 void drawIndirect(PrimitiveType type);
104 void drawIndexedIndirect(PrimitiveType type);
105
106 // Methods for populating a Dawn ComputePassEncoder:
107 void beginComputePass();
108 void bindComputePipeline(const ComputePipeline*);
109 void bindDispatchResources(const DispatchGroup&, const DispatchGroup::Dispatch&);
110 void dispatchWorkgroups(const WorkgroupSize& globalSize);
111 void dispatchWorkgroupsIndirect(const Buffer* indirectBuffer, size_t indirectBufferOffset);
112 void endComputePass();
113
114 // Methods for doing texture/buffer to texture/buffer copying:
115 bool onCopyBufferToBuffer(const Buffer* srcBuffer,
116 size_t srcOffset,
117 const Buffer* dstBuffer,
118 size_t dstOffset,
119 size_t size) override;
120 bool onCopyTextureToBuffer(const Texture*,
121 SkIRect srcRect,
122 const Buffer*,
123 size_t bufferOffset,
124 size_t bufferRowBytes) override;
125 bool onCopyBufferToTexture(const Buffer*,
126 const Texture*,
127 const BufferTextureCopyData* copyData,
128 int count) override;
129 bool onCopyTextureToTexture(const Texture* src,
130 SkIRect srcRect,
131 const Texture* dst,
132 SkIPoint dstPoint,
133 int mipLevel) override;
134 bool onSynchronizeBufferToCpu(const Buffer*, bool* outDidResultInWork) override;
135 bool onClearBuffer(const Buffer*, size_t offset, size_t size) override;
136
137 // Commiting uniform buffers' changes if any before drawing
138 void syncUniformBuffers();
139
140 bool fBoundUniformBuffersDirty = false;
141
142 std::array<const DawnBuffer*, DawnGraphicsPipeline::kNumUniformBuffers> fBoundUniformBuffers;
143 std::array<uint32_t, DawnGraphicsPipeline::kNumUniformBuffers> fBoundUniformBufferOffsets;
144 std::array<uint32_t, DawnGraphicsPipeline::kNumUniformBuffers> fBoundUniformBufferSizes;
145
146 wgpu::CommandEncoder fCommandEncoder;
147 wgpu::RenderPassEncoder fActiveRenderPassEncoder;
148 wgpu::ComputePassEncoder fActiveComputePassEncoder;
149
150 wgpu::Buffer fCurrentIndirectBuffer;
151 size_t fCurrentIndirectBufferOffset = 0;
152
153 sk_sp<DawnBuffer> fIntrinsicConstantBuffer;
154 int fIntrinsicConstantBufferSlotsUsed = 0;
155
156 const DawnGraphicsPipeline* fActiveGraphicsPipeline = nullptr;
157 const DawnComputePipeline* fActiveComputePipeline = nullptr;
158 const DawnSharedContext* fSharedContext;
159 DawnResourceProvider* fResourceProvider;
160};
161
162} // namespace skgpu::graphite
163
164#endif // skgpu_graphite_DawnCommandBuffer_DEFINED
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition: DM.cpp:213
int count
Definition: FontMgrTest.cpp:50
GLenum type
static std::unique_ptr< DawnCommandBuffer > Make(const DawnSharedContext *, DawnResourceProvider *)
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
list command
Definition: valgrind.py:24
int32_t height
int32_t width
SeparatedVector2 offset
Definition: SkRect.h:32