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 #ifdef SK_ENABLE_STENCIL_CULLING_OHOS 95 void onClearStencil(const GrScissorState& scissor, uint32_t stencilVal) override; 96 #endif 97 void onClearStencilClip(const GrScissorState& scissor, bool insideStencilMask) override; 98 99 void onDrawBlurImage(const GrSurfaceProxyView& proxyView, const SkBlurArg& blurArg) override; 100 101 #ifdef SUPPORT_OPAQUE_OPTIMIZATION 102 void onSetOpaqueRegion(uint32_t opaqueRegionCount, const SkIRect* region) override; 103 #endif 104 105 using LoadFromResolve = GrVkRenderPass::LoadFromResolve; 106 107 bool beginRenderPass(const VkClearValue& clearColor, LoadFromResolve loadFromResolve); 108 109 void addAdditionalRenderPass(bool mustUseSecondaryCommandBuffer); 110 111 void setAttachmentLayouts(LoadFromResolve loadFromResolve); 112 113 void loadResolveIntoMSAA(const SkIRect& nativeBounds); 114 115 using SelfDependencyFlags = GrVkRenderPass::SelfDependencyFlags; 116 117 sk_sp<GrVkFramebuffer> fFramebuffer; 118 std::unique_ptr<GrVkSecondaryCommandBuffer> fCurrentSecondaryCommandBuffer; 119 const GrVkRenderPass* fCurrentRenderPass; 120 SkIRect fCurrentPipelineBounds; 121 GrVkPipelineState* fCurrentPipelineState = nullptr; 122 bool fCurrentCBIsEmpty = true; 123 SkIRect fBounds; 124 SelfDependencyFlags fSelfDependencyFlags = SelfDependencyFlags::kNone; 125 LoadFromResolve fLoadFromResolve = LoadFromResolve::kNo; 126 bool fOverridePipelinesForResolveLoad = false; 127 128 GrVkGpu* fGpu; 129 130 #ifdef SK_DEBUG 131 // When we are actively recording into the GrVkOpsRenderPass we set this flag to true. This 132 // then allows us to assert that we never submit a primary command buffer to the queue while in 133 // a recording state. This is needed since when we submit to the queue we change command pools 134 // and may trigger the old one to be reset, but a recording GrVkOpsRenderPass may still have 135 // a outstanding secondary command buffer allocated from that pool that we'll try to access 136 // after the pool as been reset. 137 bool fIsActive = false; 138 #endif 139 140 using INHERITED = GrOpsRenderPass; 141 }; 142 143 #endif 144