Debian Codegraph @

src/gpu/graphite/dawn/DawnCommandBuffer.h

raw ◀ ▶
1 Debian patch touch 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
11 #include "src/gpu/graphite/CommandBuffer.h"
12 #include "src/gpu/graphite/DrawPass.h"
13 #include "src/gpu/graphite/GpuWorkSubmission.h"
14 #include "src/gpu/graphite/Log.h"
15 #include "src/gpu/graphite/compute/DispatchGroup.h"
16 #include "src/gpu/graphite/dawn/DawnGraphicsPipeline.h"
17 #include "src/gpu/graphite/dawn/DawnResourceProvider.h"
18
19 #include "webgpu/webgpu_cpp.h" // NO_G3_REWRITE
20
21 #include <optional>
22
23 namespace skgpu::graphite {
24 class ComputePipeline;
25 class DawnBuffer;
26 class DawnComputePipeline;
27 class DawnQueueManager;
28 class DawnSharedContext;
29 class DawnTexture;
30 class DispatchGroup;
31 struct WorkgroupSize;
32
33 class DawnCommandBuffer final : public CommandBuffer {
34 public:
35 static std::unique_ptr<DawnCommandBuffer> Make(const DawnSharedContext*, DawnResourceProvider*);
36 ~DawnCommandBuffer() override;
37
38 wgpu::CommandBuffer finishEncoding();
39
40 #if defined(SK_DEBUG)
41 bool hasActivePassEncoder() const {
42 return fActiveRenderPassEncoder || fActiveComputePassEncoder;
43 }
44 #endif
45
46 bool startTimerQuery() override;
47 void endTimerQuery() override;
48 std::optional<GpuStats> gpuStats() override;
49
50 private:
51 DawnCommandBuffer(const DawnSharedContext* sharedContext,
52 DawnResourceProvider* resourceProvider);
53
54 ResourceProvider* resourceProvider() const override { return fResourceProvider; }
55
56 const DawnSampler* getSampler(const DrawPassCommands::BindTexturesAndSamplers& command,
57 int32_t index);
58
59 void onResetCommandBuffer() override;
60 bool setNewCommandBufferResources() override;
61
62 bool onAddRenderPass(const RenderPassDesc&,
63 SkIRect renderPassBounds,
64 const Texture* colorTexture,
65 const Texture* resolveTexture,
66 const Texture* depthStencilTexture,
67 SkIPoint resolveOffset,
68 SkIRect viewport,
69 const DrawPassList&) override;
70 bool onAddComputePass(DispatchGroupSpan) override;
71
72 // Methods for populating a Dawn RenderPassEncoder:
73 bool beginRenderPass(const RenderPassDesc&,
74 const SkIPoint& resolveOffset,
75 SkIRect renderPassBounds,
76 const Texture* colorTexture,
77 const Texture* resolveTexture,
78 const Texture* depthStencilTexture);
79 bool emulateLoadMSAAFromResolveAndBeginRenderPassEncoder(
80 const RenderPassDesc& intendedRenderPassDesc,
81 const wgpu::RenderPassDescriptor& intendedDawnRenderPassDesc,
82 const SkIPoint& resolveOffset,
83 const SkIRect& renderPassBounds,
84 const DawnTexture* msaaTexture,
85 const DawnTexture* resolveTexture);
86 bool doBlitWithDraw(const wgpu::RenderPassEncoder& renderEncoder,
87 const RenderPassDesc& frontendRenderPassDescKey,
88 const wgpu::TextureView& srcTextureView,
89 SampleCount srcSampleCount,
90 const SkIPoint& srcOffset,
91 const SkIRect& dstBounds);
92 bool endRenderPass();
93
94 [[nodiscard]] bool addDrawPass(DrawPass*);
95
96 bool bindGraphicsPipeline(const GraphicsPipeline*);
97 void setBlendConstants(std::array<float, 4> blendConstants);
98
99 void bindUniformBuffer(const BindBufferInfo& info, UniformSlot);
100 void bindInputBuffer(const Buffer* buffer, size_t offset, uint32_t bindingIndex);
101 void bindIndexBuffer(const Buffer* indexBuffer, size_t offset);
102 void bindIndirectBuffer(const Buffer* indirectBuffer, size_t offset);
103
104 void bindTextureAndSamplers(const DrawPass& drawPass,
105 const DrawPassCommands::BindTexturesAndSamplers& command);
106
107 void setScissor(const Scissor&);
108 bool updateIntrinsicUniformsAsUBO(UniformDataBlock dataBlock);
109 bool updateIntrinsicUniformsAsPushConstant(UniformDataBlock dataBlock);
110 void setViewport(SkIRect viewport);
111
112 void draw(PrimitiveType type, unsigned int baseVertex, unsigned int vertexCount);
113 void drawIndexed(PrimitiveType type,
114 unsigned int baseIndex,
115 unsigned int indexCount,
116 unsigned int baseVertex);
117 void drawInstanced(PrimitiveType type,
118 unsigned int baseVertex,
119 unsigned int vertexCount,
120 unsigned int baseInstance,
121 unsigned int instanceCount);
122 void drawIndexedInstanced(PrimitiveType type,
123 unsigned int baseIndex,
124 unsigned int indexCount,
125 unsigned int baseVertex,
126 unsigned int baseInstance,
127 unsigned int instanceCount);
128 void drawIndirect(PrimitiveType type);
129 void drawIndexedIndirect(PrimitiveType type);
130
131 // Methods for populating a Dawn ComputePassEncoder:
132 void beginComputePass();
133 void bindComputePipeline(const ComputePipeline*);
134 void bindDispatchResources(const DispatchGroup&, const DispatchGroup::Dispatch&);
135 void dispatchWorkgroups(const WorkgroupSize& globalSize);
136 void dispatchWorkgroupsIndirect(const Buffer* indirectBuffer, size_t indirectBufferOffset);
137 void endComputePass();
138
139 // Methods for doing texture/buffer to texture/buffer copying:
140 bool onCopyBufferToBuffer(const Buffer* srcBuffer,
141 size_t srcOffset,
142 const Buffer* dstBuffer,
143 size_t dstOffset,
144 size_t size) override;
145 bool onCopyTextureToBuffer(const Texture*,
146 SkIRect srcRect,
147 const Buffer*,
148 size_t bufferOffset,
149 size_t bufferRowBytes) override;
150 bool onCopyBufferToTexture(const Buffer*,
151 const Texture*,
152 const BufferTextureCopyData* copyData,
153 int count) override;
154 bool onCopyTextureToTexture(const Texture* src,
155 SkIRect srcRect,
156 const Texture* dst,
157 SkIPoint dstPoint,
158 int mipLevel) override;
159 bool onSynchronizeBufferToCpu(const Buffer*, bool* outDidResultInWork) override;
160 bool onClearBuffer(const Buffer*, size_t offset, size_t size) override;
161
162 // Commiting uniform buffers' changes if any before drawing
163 void syncUniformBuffers();
164
165 bool fBoundUniformBuffersDirty = false;
166
•167 std::array<BindBufferInfo, DawnGraphicsPipeline::kMaxNumUniformBuffers> fBoundUniforms;
168
169 wgpu::CommandEncoder fCommandEncoder;
170 wgpu::RenderPassEncoder fActiveRenderPassEncoder;
171 wgpu::ComputePassEncoder fActiveComputePassEncoder;
172
173 struct ResolveStepEmulationInfo {
174 const DawnTexture* fMSAATexture;
175 const DawnTexture* fResolveTexture;
176 SkIPoint fMSAAAOffset;
177 SkIRect fResolveArea;
178 };
179 std::optional<ResolveStepEmulationInfo> fResolveStepEmulationInfo;
180
181 wgpu::Buffer fCurrentIndirectBuffer;
182 size_t fCurrentIndirectBufferOffset = 0;
183
184 bool fWroteFirstPassTimestamps = false;
185 wgpu::QuerySet fTimestampQuerySet;
186 sk_sp<DawnBuffer> fTimestampQueryBuffer;
187 sk_sp<DawnBuffer> fTimestampQueryXferBuffer;
188
189 const DawnGraphicsPipeline* fActiveGraphicsPipeline = nullptr;
190 const DawnComputePipeline* fActiveComputePipeline = nullptr;
191 const DawnSharedContext* fSharedContext;
192 DawnResourceProvider* fResourceProvider;
193 };
194
195 } // namespace skgpu::graphite
196
197 #endif // skgpu_graphite_DawnCommandBuffer_DEFINED