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