Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
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
46 const Texture* colorTexture,
47 const Texture* resolveTexture,
48 const Texture* depthStencilTexture,
49 SkRect viewport,
50 const DrawPassList&) 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 void addDrawPass(const DrawPass*);
70
71 void 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
static bool left(const SkPoint &p0, const SkPoint &p1)
bool onClearBuffer(const Buffer *, size_t offset, size_t size) override
bool onAddRenderPass(const RenderPassDesc &, const Texture *colorTexture, const Texture *resolveTexture, const Texture *depthStencilTexture, SkRect viewport, const DrawPassList &) override
bool onCopyBufferToTexture(const Buffer *, const Texture *, const BufferTextureCopyData *copyData, int count) override
bool onCopyBufferToBuffer(const Buffer *srcBuffer, size_t srcOffset, const Buffer *dstBuffer, size_t dstOffset, size_t size) override
bool onSynchronizeBufferToCpu(const Buffer *, bool *outDidResultInWork) override
static std::unique_ptr< DawnCommandBuffer > Make(const DawnSharedContext *, DawnResourceProvider *)
bool onCopyTextureToTexture(const Texture *src, SkIRect srcRect, const Texture *dst, SkIPoint dstPoint, int mipLevel) override
bool onAddComputePass(DispatchGroupSpan) override
bool onCopyTextureToBuffer(const Texture *, SkIRect srcRect, const Buffer *, size_t bufferOffset, size_t bufferRowBytes) override
int32_t height
int32_t width
Point offset