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/GrTRecorder.h" 17 #include "src/gpu/vk/GrVkPipelineState.h" 18 19 class GrVkGpu; 20 class GrVkImage; 21 class GrVkRenderPass; 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*, GrSurfaceOrigin, const SkIRect& bounds, 36 const GrOpsRenderPass::LoadAndStoreInfo&, 37 const GrOpsRenderPass::StencilLoadAndStoreInfo&, 38 const SkTArray<GrSurfaceProxy*, true>& sampledProxies); 39 void reset(); 40 41 void submit(); 42 43 #ifdef SK_DEBUG isActive()44 bool isActive() const { return fIsActive; } 45 #endif 46 47 private: 48 bool init(const GrOpsRenderPass::LoadAndStoreInfo&, 49 const GrOpsRenderPass::StencilLoadAndStoreInfo&, 50 const SkPMColor4f& clearColor); 51 52 // Called instead of init when we are drawing to a render target that already wraps a secondary 53 // command buffer. 54 bool initWrapped(); 55 56 bool wrapsSecondaryCommandBuffer() const; 57 58 GrGpu* gpu() override; 59 60 GrVkCommandBuffer* currentCommandBuffer(); 61 62 void onEnd() override; 63 64 bool onBindPipeline(const GrProgramInfo&, const SkRect& drawBounds) override; 65 void onSetScissorRect(const SkIRect&) override; 66 bool onBindTextures(const GrPrimitiveProcessor&, const GrSurfaceProxy* const primProcTextures[], 67 const GrPipeline&) override; 68 void onBindBuffers(const GrBuffer* indexBuffer, const GrBuffer* instanceBuffer, 69 const GrBuffer* vertexBuffer, GrPrimitiveRestart) override; onDraw(int vertexCount,int baseVertex)70 void onDraw(int vertexCount, int baseVertex) override { 71 this->onDrawInstanced(1, 0, vertexCount, baseVertex); 72 } onDrawIndexed(int indexCount,int baseIndex,uint16_t minIndexValue,uint16_t maxIndexValue,int baseVertex)73 void onDrawIndexed(int indexCount, int baseIndex, uint16_t minIndexValue, 74 uint16_t maxIndexValue, int baseVertex) override { 75 this->onDrawIndexedInstanced(indexCount, baseIndex, 1, 0, baseVertex); 76 } 77 void onDrawInstanced(int instanceCount, int baseInstance, int vertexCount, 78 int baseVertex) override; 79 void onDrawIndexedInstanced(int indexCount, int baseIndex, int instanceCount, int baseInstance, 80 int baseVertex) override; 81 82 void onClear(const GrFixedClip&, const SkPMColor4f& color) override; 83 84 void onClearStencilClip(const GrFixedClip&, bool insideStencilMask) override; 85 86 void addAdditionalRenderPass(bool mustUseSecondaryCommandBuffer); 87 88 std::unique_ptr<GrVkSecondaryCommandBuffer> fCurrentSecondaryCommandBuffer; 89 const GrVkRenderPass* fCurrentRenderPass; 90 SkIRect fCurrentPipelineBounds; 91 GrVkPipelineState* fCurrentPipelineState = nullptr; 92 bool fCurrentCBIsEmpty = true; 93 SkIRect fBounds; 94 GrVkGpu* fGpu; 95 96 #ifdef SK_DEBUG 97 // When we are actively recording into the GrVkOpsRenderPass we set this flag to true. This 98 // then allows us to assert that we never submit a primary command buffer to the queue while in 99 // a recording state. This is needed since when we submit to the queue we change command pools 100 // and may trigger the old one to be reset, but a recording GrVkOpsRenderPass may still have 101 // a outstanding secondary command buffer allocated from that pool that we'll try to access 102 // after the pool as been reset. 103 bool fIsActive = false; 104 #endif 105 106 typedef GrOpsRenderPass INHERITED; 107 }; 108 109 #endif 110