Debian Codegraph @

src/gpu/graphite/DrawPass.h

raw
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 #ifndef skgpu_graphite_DrawPass_DEFINED
8 #define skgpu_graphite_DrawPass_DEFINED
9
10 #include "include/core/SkRect.h"
11 #include "include/core/SkRefCnt.h"
12 #include "include/private/base/SkSpan_impl.h"
13 #include "include/private/base/SkTArray.h"
14 #include "src/gpu/graphite/DrawCommands.h"
15 #include "src/gpu/graphite/GraphicsPipelineDesc.h"
16 #include "src/gpu/graphite/GraphicsPipelineHandle.h"
17
18 struct SkImageInfo;
19
20 namespace skgpu::graphite {
21
22 class CommandBuffer;
23 class DrawList;
24 class FloatStorageManager;
25 class GraphicsPipeline;
26 struct RenderPassDesc;
27 class ResourceProvider;
28 class RuntimeEffectDictionary;
29 class TextureProxy;
30
31 enum class DstReadStrategy : uint8_t;
32 enum class LoadOp : uint8_t;
33 enum class StoreOp : uint8_t;
34
35 /**
36 * DrawPass is analogous to a subpass, storing the drawing operations in the order they are stored
37 * in the eventual command buffer, as well as the surface proxy the operations are intended for.
38 * DrawPasses are grouped into a RenderPassTask for execution within a single render pass if the
39 * subpasses are compatible with each other.
40 *
41 * Unlike DrawList, DrawPasses are immutable and represent as closely as possible what will be
42 * stored in the command buffer while being flexible as to how the pass is incorporated. Depending
43 * on the backend, it may even be able to write accumulated vertex and uniform data directly to
44 * mapped GPU memory, although that is the extent of the CPU->GPU work they perform before they are
45 * executed by a RenderPassTask.
46 */
47 class DrawPass {
48 public:
49 ~DrawPass();
50
51 // Defined relative to the top-left corner of the surface the DrawPass renders to, and is
52 // contained within its dimensions.
53 const SkIRect& bounds() const { return fBounds; }
54 TextureProxy* target() const { return fTarget.get(); }
55 FloatStorageManager* floatStorageManager() const { return fFloatStorageManager.get(); }
56 std::pair<LoadOp, StoreOp> ops() const { return fOps; }
57 std::array<float, 4> clearColor() const { return fClearColor; }
58
59 size_t vertexBufferSize() const { return 0; }
60 size_t uniformBufferSize() const { return 0; }
61
62 // Instantiate and prepare any resources used by the DrawPass that require the Recorder's
63 // ResourceProvider. This includes things likes GraphicsPipelines, sampled Textures, Samplers,
64 // etc.
65 // Note that, due to possible threaded compilation, the Pipelines are not guaranteed to be
66 // complete until Context::insertRecording time.
67 bool prepareResources(ResourceProvider*,
68 sk_sp<const RuntimeEffectDictionary>,
69 const RenderPassDesc&);
70
71 DrawPassCommands::List::Iter commands() const {
72 return fCommandList.commands();
73 }
74
75 const GraphicsPipeline* getPipeline(size_t index) const {
76 return fFullPipelines[index].get();
77 }
78
79 // Proxies are always valid but may not be instantiated until after prepareResources() is called
80 SkSpan<const sk_sp<TextureProxy>> sampledTextures() const { return fSampledTextures; }
81 // Not valid until after prepareResources() is called
82 SkSpan<const sk_sp<GraphicsPipeline>> pipelines() const { return fFullPipelines; }
83
84 [[nodiscard]] bool addResourceRefs(ResourceProvider*, CommandBuffer*);
85
86 private:
87 friend class DrawList; // For the constructor
88
89 DrawPass(sk_sp<TextureProxy> target,
90 std::pair<LoadOp, StoreOp> ops,
91 std::array<float, 4> clearColor,
92 sk_sp<FloatStorageManager> floatStorageManager);
93
94 DrawPassCommands::List fCommandList;
95
96 sk_sp<TextureProxy> fTarget;
97 SkIRect fBounds;
98
99 std::pair<LoadOp, StoreOp> fOps;
100 std::array<float, 4> fClearColor;
101
102 // The pipelines are referenced by index in BindGraphicsPipeline, but that will index into
103 // an array of actual GraphicsPipelines (i.e., fFullPipelines).
104 skia_private::TArray<GraphicsPipelineDesc> fPipelineDescs;
105 skia_private::TArray<float> fPipelineDrawAreas;
106
107 // These resources all get instantiated during prepareResources.
108 skia_private::TArray<GraphicsPipelineHandle> fPipelineHandles;
109 skia_private::TArray<sk_sp<TextureProxy>> fSampledTextures;
110
111 // These get resolved (from the GraphicsPipelineHandles) in prepareResources
112 skia_private::TArray<sk_sp<GraphicsPipeline>> fFullPipelines;
113
114 sk_sp<FloatStorageManager> fFloatStorageManager;
115 };
116
117 } // namespace skgpu::graphite
118
119 #endif // skgpu_graphite_DrawPass_DEFINED