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