xref: /aosp_15_r20/external/skia/src/gpu/ganesh/vk/GrVkOpsRenderPass.h (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
1 /*
2 * Copyright 2016 Google Inc.
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 GrVkOpsRenderPass_DEFINED
9 #define GrVkOpsRenderPass_DEFINED
10 
11 #include "include/core/SkDrawable.h"
12 #include "include/core/SkRect.h"
13 #include "include/core/SkRefCnt.h"
14 #include "include/private/base/SkDebug.h"
15 #include "include/private/base/SkTArray.h"
16 #include "include/private/gpu/vk/SkiaVulkan.h"
17 #include "src/gpu/ganesh/GrDeferredUpload.h"
18 #include "src/gpu/ganesh/GrGeometryProcessor.h"
19 #include "src/gpu/ganesh/GrOpsRenderPass.h"
20 #include "src/gpu/ganesh/vk/GrVkRenderPass.h"
21 
22 #include <array>
23 #include <cstddef>
24 #include <cstdint>
25 #include <memory>
26 
27 class GrBuffer;
28 class GrGpu;
29 class GrOpFlushState;
30 class GrPipeline;
31 class GrProgramInfo;
32 class GrRenderTarget;
33 class GrScissorState;
34 class GrSurfaceProxy;
35 class GrVkCommandBuffer;
36 class GrVkFramebuffer;
37 class GrVkGpu;
38 class GrVkPipelineState;
39 class GrVkSecondaryCommandBuffer;
40 enum GrSurfaceOrigin : int;
41 enum class GrPrimitiveRestart : bool;
42 
43 class GrVkOpsRenderPass : public GrOpsRenderPass {
44 public:
45     GrVkOpsRenderPass(GrVkGpu*);
46 
47     ~GrVkOpsRenderPass() override;
48 
49     void inlineUpload(GrOpFlushState* state, GrDeferredTextureUploadFn& upload) override;
50 
51     void onExecuteDrawable(std::unique_ptr<SkDrawable::GpuDrawHandler>) override;
52 
53     bool set(GrRenderTarget*,
54              sk_sp<GrVkFramebuffer>,
55              GrSurfaceOrigin,
56              const SkIRect& bounds,
57              const GrOpsRenderPass::LoadAndStoreInfo&,
58              const GrOpsRenderPass::StencilLoadAndStoreInfo&,
59              const GrOpsRenderPass::LoadAndStoreInfo& resolveInfo,
60              GrVkRenderPass::SelfDependencyFlags selfDepFlags,
61              GrVkRenderPass::LoadFromResolve loadFromResolve,
62              const skia_private::TArray<GrSurfaceProxy*, true>& sampledProxies);
63     void reset();
64 
65     void submit();
66 
67 #ifdef SK_DEBUG
isActive()68     bool isActive() const { return fIsActive; }
69 #endif
70 
71 private:
72     bool init(const GrOpsRenderPass::LoadAndStoreInfo& colorInfo,
73               const GrOpsRenderPass::LoadAndStoreInfo& resolveInfo,
74               const GrOpsRenderPass::StencilLoadAndStoreInfo&);
75 
76     // Called instead of init when we are drawing to a render target that already wraps a secondary
77     // command buffer.
78     bool initWrapped();
79 
80     bool wrapsSecondaryCommandBuffer() const;
81 
82     GrGpu* gpu() override;
83 
84     GrVkCommandBuffer* currentCommandBuffer();
85 
86     void onEnd() override;
87 
88     bool onBindPipeline(const GrProgramInfo&, const SkRect& drawBounds) override;
89     void onSetScissorRect(const SkIRect&) override;
90     bool onBindTextures(const GrGeometryProcessor&,
91                         const GrSurfaceProxy* const geomProcTextures[],
92                         const GrPipeline&) override;
93     void onBindBuffers(sk_sp<const GrBuffer> indexBuffer, sk_sp<const GrBuffer> instanceBuffer,
94                        sk_sp<const GrBuffer> vertexBuffer, GrPrimitiveRestart) override;
onDraw(int vertexCount,int baseVertex)95     void onDraw(int vertexCount, int baseVertex) override {
96         this->onDrawInstanced(1, 0, vertexCount, baseVertex);
97     }
onDrawIndexed(int indexCount,int baseIndex,uint16_t minIndexValue,uint16_t maxIndexValue,int baseVertex)98     void onDrawIndexed(int indexCount, int baseIndex, uint16_t minIndexValue,
99                        uint16_t maxIndexValue, int baseVertex) override {
100         this->onDrawIndexedInstanced(indexCount, baseIndex, 1, 0, baseVertex);
101     }
102     void onDrawInstanced(int instanceCount, int baseInstance, int vertexCount,
103                          int baseVertex) override;
104     void onDrawIndexedInstanced(int indexCount, int baseIndex, int instanceCount, int baseInstance,
105                                 int baseVertex) override;
106     void onDrawIndirect(const GrBuffer* drawIndirectBuffer, size_t offset, int drawCount) override;
107     void onDrawIndexedIndirect(const GrBuffer* drawIndirectBuffer, size_t offset,
108                                int drawCount) override;
109 
110     void onClear(const GrScissorState& scissor, std::array<float, 4> color) override;
111 
112     void onClearStencilClip(const GrScissorState& scissor, bool insideStencilMask) override;
113 
114     using LoadFromResolve = GrVkRenderPass::LoadFromResolve;
115 
116     bool beginRenderPass(const VkClearValue& clearColor, LoadFromResolve loadFromResolve);
117 
118     void addAdditionalRenderPass(bool mustUseSecondaryCommandBuffer);
119 
120     void setAttachmentLayouts(LoadFromResolve loadFromResolve);
121 
122     void loadResolveIntoMSAA(const SkIRect& nativeBounds);
123 
124     using SelfDependencyFlags = GrVkRenderPass::SelfDependencyFlags;
125 
126     sk_sp<GrVkFramebuffer>                      fFramebuffer;
127     std::unique_ptr<GrVkSecondaryCommandBuffer> fCurrentSecondaryCommandBuffer;
128     const GrVkRenderPass*                       fCurrentRenderPass;
129     SkIRect                                     fCurrentPipelineBounds;
130     GrVkPipelineState*                          fCurrentPipelineState = nullptr;
131     bool                                        fCurrentCBIsEmpty = true;
132     SkIRect                                     fBounds;
133     SelfDependencyFlags                         fSelfDependencyFlags = SelfDependencyFlags::kNone;
134     LoadFromResolve                             fLoadFromResolve = LoadFromResolve::kNo;
135     bool                                        fOverridePipelinesForResolveLoad = false;
136 
137     GrVkGpu*                                    fGpu;
138 
139 #ifdef SK_DEBUG
140     // When we are actively recording into the GrVkOpsRenderPass we set this flag to true. This
141     // then allows us to assert that we never submit a primary command buffer to the queue while in
142     // a recording state. This is needed since when we submit to the queue we change command pools
143     // and may trigger the old one to be reset, but a recording GrVkOpsRenderPass may still have
144     // a outstanding secondary command buffer allocated from that pool that we'll try to access
145     // after the pool as been reset.
146     bool fIsActive = false;
147 #endif
148 
149     using INHERITED = GrOpsRenderPass;
150 };
151 
152 #endif
153