• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
11 #include "include/core/SkColor.h"
12 #include "include/core/SkRect.h"
13 #include "include/core/SkRefCnt.h"
14 #include "include/private/base/SkTArray.h"
15 #include "src/core/SkEnumBitMask.h"
16 #include "src/gpu/graphite/AttachmentTypes.h"
17 #include "src/gpu/graphite/DrawCommands.h"
18 #include "src/gpu/graphite/DrawTypes.h"
19 #include "src/gpu/graphite/GraphicsPipelineDesc.h"
20 #include "src/gpu/graphite/ResourceTypes.h"
21 
22 #include <memory>
23 
24 struct SkImageInfo;
25 
26 namespace skgpu::graphite {
27 
28 class BoundsManager;
29 class CommandBuffer;
30 class DrawList;
31 class GraphicsPipeline;
32 class Recorder;
33 struct RenderPassDesc;
34 class ResourceProvider;
35 class RuntimeEffectDictionary;
36 class Sampler;
37 class TextureDataBlock;
38 class TextureProxy;
39 class Texture;
40 enum class UniformSlot;
41 
42 /**
43  * DrawPass is analogous to a subpass, storing the drawing operations in the order they are stored
44  * in the eventual command buffer, as well as the surface proxy the operations are intended for.
45  * DrawPasses are grouped into a RenderPassTask for execution within a single render pass if the
46  * subpasses are compatible with each other.
47  *
48  * Unlike DrawList, DrawPasses are immutable and represent as closely as possible what will be
49  * stored in the command buffer while being flexible as to how the pass is incorporated. Depending
50  * on the backend, it may even be able to write accumulated vertex and uniform data directly to
51  * mapped GPU memory, although that is the extent of the CPU->GPU work they perform before they are
52  * executed by a RenderPassTask.
53  */
54 class DrawPass {
55 public:
56     ~DrawPass();
57 
58     static std::unique_ptr<DrawPass> Make(Recorder*,
59                                           std::unique_ptr<DrawList>,
60                                           sk_sp<TextureProxy> target,
61                                           const SkImageInfo& targetInfo,
62                                           std::pair<LoadOp, StoreOp>,
63                                           std::array<float, 4> clearColor);
64 
65     // Defined relative to the top-left corner of the surface the DrawPass renders to, and is
66     // contained within its dimensions.
bounds()67     const SkIRect&      bounds() const { return fBounds;       }
target()68     TextureProxy* target() const { return fTarget.get(); }
ops()69     std::pair<LoadOp, StoreOp> ops() const { return fOps; }
clearColor()70     std::array<float, 4> clearColor() const { return fClearColor; }
71 
requiresDstTexture()72     bool requiresDstTexture() const { return false;            }
requiresMSAA()73     bool requiresMSAA()       const { return fRequiresMSAA;    }
74 
depthStencilFlags()75     SkEnumBitMask<DepthStencilFlags> depthStencilFlags() const { return fDepthStencilFlags; }
76 
vertexBufferSize()77     size_t vertexBufferSize()  const { return 0; }
uniformBufferSize()78     size_t uniformBufferSize() const { return 0; }
79 
80     // Instantiate and prepare any resources used by the DrawPass that require the Recorder's
81     // ResourceProvider. This includes things likes GraphicsPipelines, sampled Textures, Samplers,
82     // etc.
83     bool prepareResources(ResourceProvider*,
84                           const RuntimeEffectDictionary*,
85                           const RenderPassDesc&);
86 
commands()87     DrawPassCommands::List::Iter commands() const {
88         return fCommandList.commands();
89     }
90 
getPipeline(size_t index)91     const GraphicsPipeline* getPipeline(size_t index) const {
92         return fFullPipelines[index].get();
93     }
94     const Texture* getTexture(size_t index) const;
95     const Sampler* getSampler(size_t index) const;
96 
97     void addResourceRefs(CommandBuffer*) const;
98 
99 private:
100     class SortKey;
101 
102     DrawPass(sk_sp<TextureProxy> target,
103              std::pair<LoadOp, StoreOp> ops,
104              std::array<float, 4> clearColor);
105 
106     DrawPassCommands::List fCommandList;
107 
108     sk_sp<TextureProxy> fTarget;
109     SkIRect fBounds;
110 
111     std::pair<LoadOp, StoreOp> fOps;
112     std::array<float, 4> fClearColor;
113 
114     SkEnumBitMask<DepthStencilFlags> fDepthStencilFlags = DepthStencilFlags::kNone;
115     bool fRequiresMSAA = false;
116 
117     // The pipelines are referenced by index in BindGraphicsPipeline, but that will index into a
118     // an array of actual GraphicsPipelines.
119     SkTArray<GraphicsPipelineDesc> fPipelineDescs;
120     SkTArray<SamplerDesc> fSamplerDescs;
121 
122     // These resources all get instantiated during prepareResources.
123     SkTArray<sk_sp<GraphicsPipeline>> fFullPipelines;
124     SkTArray<sk_sp<TextureProxy>> fSampledTextures;
125     SkTArray<sk_sp<Sampler>> fSamplers;
126 };
127 
128 } // namespace skgpu::graphite
129 
130 #endif // skgpu_graphite_DrawPass_DEFINED
131