Flutter Engine
The Flutter Engine
DrawPass.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_DrawPass_DEFINED
9#define skgpu_graphite_DrawPass_DEFINED
10
12#include "include/core/SkRect.h"
21
22#include <memory>
23
24struct SkImageInfo;
25
26namespace skgpu::graphite {
27
28class BoundsManager;
29class CommandBuffer;
30class DrawList;
31class GraphicsPipeline;
32class Recorder;
33struct RenderPassDesc;
35class RuntimeEffectDictionary;
36class Sampler;
37class TextureDataBlock;
38class Texture;
39enum class UniformSlot;
40
41/**
42 * DrawPass is analogous to a subpass, storing the drawing operations in the order they are stored
43 * in the eventual command buffer, as well as the surface proxy the operations are intended for.
44 * DrawPasses are grouped into a RenderPassTask for execution within a single render pass if the
45 * subpasses are compatible with each other.
46 *
47 * Unlike DrawList, DrawPasses are immutable and represent as closely as possible what will be
48 * stored in the command buffer while being flexible as to how the pass is incorporated. Depending
49 * on the backend, it may even be able to write accumulated vertex and uniform data directly to
50 * mapped GPU memory, although that is the extent of the CPU->GPU work they perform before they are
51 * executed by a RenderPassTask.
52 */
53class DrawPass {
54public:
56
57 // Create a DrawPass that renders the DrawList into `target` with the given load/store ops and
58 // clear color. If the DrawList has draws that required a dst readback texture copy to sample
59 // from in the shader, it must be provided in `dstCopy` and a copy task must be executed before
60 // the DrawPass is executed.
61 static std::unique_ptr<DrawPass> Make(Recorder*,
62 std::unique_ptr<DrawList>,
64 const SkImageInfo& targetInfo,
65 std::pair<LoadOp, StoreOp>,
66 std::array<float, 4> clearColor,
67 sk_sp<TextureProxy> dstCopy,
68 SkIPoint dstCopyOffset);
69
70 // Defined relative to the top-left corner of the surface the DrawPass renders to, and is
71 // contained within its dimensions.
72 const SkIRect& bounds() const { return fBounds; }
73 TextureProxy* target() const { return fTarget.get(); }
74 std::pair<LoadOp, StoreOp> ops() const { return fOps; }
75 std::array<float, 4> clearColor() const { return fClearColor; }
76
77 bool requiresDstTexture() const { return false; }
78 bool requiresMSAA() const { return fRequiresMSAA; }
79
80 SkEnumBitMask<DepthStencilFlags> depthStencilFlags() const { return fDepthStencilFlags; }
81
82 size_t vertexBufferSize() const { return 0; }
83 size_t uniformBufferSize() const { return 0; }
84
85 // Instantiate and prepare any resources used by the DrawPass that require the Recorder's
86 // ResourceProvider. This includes things likes GraphicsPipelines, sampled Textures, Samplers,
87 // etc.
90 const RenderPassDesc&);
91
93 return fCommandList.commands();
94 }
95
96 const GraphicsPipeline* getPipeline(size_t index) const {
97 return fFullPipelines[index].get();
98 }
99 const Texture* getTexture(size_t index) const;
100 const Sampler* getSampler(size_t index) const;
101
102 skia_private::TArray<sk_sp<TextureProxy>> sampledTextures() const { return fSampledTextures; }
103
104 void addResourceRefs(CommandBuffer*) const;
105
106private:
107 class SortKey;
108
110 std::pair<LoadOp, StoreOp> ops,
111 std::array<float, 4> clearColor);
112
113 DrawPassCommands::List fCommandList;
114
115 sk_sp<TextureProxy> fTarget;
117
118 std::pair<LoadOp, StoreOp> fOps;
119 std::array<float, 4> fClearColor;
120
122 bool fRequiresMSAA = false;
123
124 // The pipelines are referenced by index in BindGraphicsPipeline, but that will index into a
125 // an array of actual GraphicsPipelines.
128
129 // These resources all get instantiated during prepareResources.
133};
134
135} // namespace skgpu::graphite
136
137#endif // skgpu_graphite_DrawPass_DEFINED
const SkRect fBounds
SkTBlockList< Command, 16 >::CIter Iter
Definition: DrawCommands.h:203
size_t vertexBufferSize() const
Definition: DrawPass.h:82
const Texture * getTexture(size_t index) const
Definition: DrawPass.cpp:759
std::array< float, 4 > clearColor() const
Definition: DrawPass.h:75
bool prepareResources(ResourceProvider *, const RuntimeEffectDictionary *, const RenderPassDesc &)
Definition: DrawPass.cpp:699
size_t uniformBufferSize() const
Definition: DrawPass.h:83
const Sampler * getSampler(size_t index) const
Definition: DrawPass.cpp:765
DrawPassCommands::List::Iter commands() const
Definition: DrawPass.h:92
const SkIRect & bounds() const
Definition: DrawPass.h:72
SkEnumBitMask< DepthStencilFlags > depthStencilFlags() const
Definition: DrawPass.h:80
std::pair< LoadOp, StoreOp > ops() const
Definition: DrawPass.h:74
bool requiresDstTexture() const
Definition: DrawPass.h:77
TextureProxy * target() const
Definition: DrawPass.h:73
bool requiresMSAA() const
Definition: DrawPass.h:78
skia_private::TArray< sk_sp< TextureProxy > > sampledTextures() const
Definition: DrawPass.h:102
void addResourceRefs(CommandBuffer *) const
Definition: DrawPass.cpp:747
const GraphicsPipeline * getPipeline(size_t index) const
Definition: DrawPass.h:96
static std::unique_ptr< DrawPass > Make(Recorder *, std::unique_ptr< DrawList >, sk_sp< TextureProxy > target, const SkImageInfo &targetInfo, std::pair< LoadOp, StoreOp >, std::array< float, 4 > clearColor, sk_sp< TextureProxy > dstCopy, SkIPoint dstCopyOffset)
Definition: DrawPass.cpp:458
std::function< ProfileSample(void)> Sampler
Sampler is run during SamplingProfiler::SampleRepeatedly. Each platform should implement its version ...
Definition: SkRect.h:32