1 /* 2 * Copyright 2018 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 GrMtlOpsRenderPass_DEFINED 9 #define GrMtlOpsRenderPass_DEFINED 10 11 #include "src/gpu/GrOpFlushState.h" 12 #include "src/gpu/GrOpsRenderPass.h" 13 #include "src/gpu/mtl/GrMtlGpu.h" 14 15 #import <Metal/Metal.h> 16 17 typedef uint32_t GrColor; 18 class GrMtlBuffer; 19 class GrMtlFramebuffer; 20 class GrMtlPipelineState; 21 class GrMtlRenderCommandEncoder; 22 class GrMtlRenderTarget; 23 24 class GrMtlOpsRenderPass : public GrOpsRenderPass { 25 public: 26 GrMtlOpsRenderPass(GrMtlGpu* gpu, GrRenderTarget* rt, sk_sp<GrMtlFramebuffer>, 27 GrSurfaceOrigin origin, const GrOpsRenderPass::LoadAndStoreInfo& colorInfo, 28 const GrOpsRenderPass::StencilLoadAndStoreInfo& stencilInfo); 29 30 ~GrMtlOpsRenderPass() override; 31 32 void initRenderState(GrMtlRenderCommandEncoder*); 33 34 void inlineUpload(GrOpFlushState* state, GrDeferredTextureUploadFn& upload) override; 35 void submit(); 36 37 private: gpu()38 GrGpu* gpu() override { return fGpu; } 39 40 bool onBindPipeline(const GrProgramInfo&, const SkRect& drawBounds) override; 41 void onSetScissorRect(const SkIRect&) override; 42 bool onBindTextures(const GrGeometryProcessor&, 43 const GrSurfaceProxy* const geomProcTextures[], 44 const GrPipeline&) override; 45 void onBindBuffers(sk_sp<const GrBuffer> indexBuffer, sk_sp<const GrBuffer> instanceBuffer, 46 sk_sp<const GrBuffer> vertexBuffer, GrPrimitiveRestart) override; 47 void onDraw(int vertexCount, int baseVertex) override; 48 void onDrawIndexed(int indexCount, int baseIndex, uint16_t minIndexValue, 49 uint16_t maxIndexValue, int baseVertex) override; 50 void onDrawInstanced(int instanceCount, int baseInstance, int vertexCount, 51 int baseVertex) override; 52 void onDrawIndexedInstanced(int indexCount, int baseIndex, int instanceCount, int baseInstance, 53 int baseVertex) override; 54 void onDrawIndirect(const GrBuffer* drawIndirectBuffer, size_t bufferOffset, 55 int drawCount) override; 56 void onDrawIndexedIndirect(const GrBuffer* drawIndirectBuffer, size_t bufferOffset, 57 int drawCount) override; 58 59 void onClear(const GrScissorState& scissor, std::array<float, 4> color) override; 60 61 void onClearStencilClip(const GrScissorState& scissor, bool insideStencilMask) override; 62 63 void setupRenderPass(const GrOpsRenderPass::LoadAndStoreInfo& colorInfo, 64 const GrOpsRenderPass::StencilLoadAndStoreInfo& stencilInfo); 65 66 void setVertexBuffer(GrMtlRenderCommandEncoder*, const GrBuffer*, size_t offset, 67 size_t inputBufferIndex); 68 69 GrMtlRenderCommandEncoder* setupResolve(); 70 71 GrMtlGpu* fGpu; 72 73 sk_sp<GrMtlFramebuffer> fFramebuffer; 74 GrMtlRenderCommandEncoder* fActiveRenderCmdEncoder; 75 GrMtlPipelineState* fActivePipelineState = nullptr; 76 MTLPrimitiveType fActivePrimitiveType; 77 MTLRenderPassDescriptor* fRenderPassDesc; 78 SkRect fBounds; 79 size_t fCurrentVertexStride; 80 #ifdef SK_ENABLE_MTL_DEBUG_INFO 81 bool fDebugGroupActive = false; 82 #endif 83 84 using INHERITED = GrOpsRenderPass; 85 }; 86 87 #endif 88