2 * Copyright 2016 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
8 #ifndef GrVkOpsRenderPass_DEFINED
9 #define GrVkOpsRenderPass_DEFINED
11 #include "src/gpu/ganesh/GrOpsRenderPass.h"
13 #include "include/gpu/GrTypes.h"
14 #include "include/gpu/vk/GrVkTypes.h"
15 #include "src/gpu/ganesh/GrColor.h"
16 #include "src/gpu/ganesh/vk/GrVkPipelineState.h"
17 #include "src/gpu/ganesh/vk/GrVkRenderPass.h"
19 class GrVkFramebuffer;
22 class GrVkRenderTarget;
23 class GrVkSecondaryCommandBuffer;
25 class GrVkOpsRenderPass : public GrOpsRenderPass {
27 GrVkOpsRenderPass(GrVkGpu*);
29 ~GrVkOpsRenderPass() override;
31 void inlineUpload(GrOpFlushState* state, GrDeferredTextureUploadFn& upload) override;
33 void onExecuteDrawable(std::unique_ptr<SkDrawable::GpuDrawHandler>) override;
35 bool set(GrRenderTarget*,
36 sk_sp<GrVkFramebuffer>,
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);
50 bool isActive() const { return fIsActive; }
54 bool init(const GrOpsRenderPass::LoadAndStoreInfo& colorInfo,
55 const GrOpsRenderPass::LoadAndStoreInfo& resolveInfo,
56 const GrOpsRenderPass::StencilLoadAndStoreInfo&);
58 // Called instead of init when we are drawing to a render target that already wraps a secondary
62 bool wrapsSecondaryCommandBuffer() const;
64 GrGpu* gpu() override;
66 GrVkCommandBuffer* currentCommandBuffer();
68 void onEnd() override;
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;
77 void onDraw(int vertexCount, int baseVertex) override {
78 this->onDrawInstanced(1, 0, vertexCount, 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);
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;
92 void onClear(const GrScissorState& scissor, std::array<float, 4> color) override;
94 void onClearStencilClip(const GrScissorState& scissor, bool insideStencilMask) override;
96 using LoadFromResolve = GrVkRenderPass::LoadFromResolve;
98 bool beginRenderPass(const VkClearValue& clearColor, LoadFromResolve loadFromResolve);
100 void addAdditionalRenderPass(bool mustUseSecondaryCommandBuffer);
102 void setAttachmentLayouts(LoadFromResolve loadFromResolve);
104 void loadResolveIntoMSAA(const SkIRect& nativeBounds);
106 using SelfDependencyFlags = GrVkRenderPass::SelfDependencyFlags;
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;
115 SelfDependencyFlags fSelfDependencyFlags = SelfDependencyFlags::kNone;
116 LoadFromResolve fLoadFromResolve = LoadFromResolve::kNo;
117 bool fOverridePipelinesForResolveLoad = false;
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;
131 using INHERITED = GrOpsRenderPass;