• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 GrMtlPipelineState;
20 class GrMtlRenderTarget;
21 
22 class GrMtlOpsRenderPass : public GrOpsRenderPass {
23 public:
24     GrMtlOpsRenderPass(GrMtlGpu* gpu, GrRenderTarget* rt, GrSurfaceOrigin origin,
25                        const GrOpsRenderPass::LoadAndStoreInfo& colorInfo,
26                        const GrOpsRenderPass::StencilLoadAndStoreInfo& stencilInfo);
27 
28     ~GrMtlOpsRenderPass() override;
29 
30     void initRenderState(id<MTLRenderCommandEncoder>);
31 
32     void inlineUpload(GrOpFlushState* state, GrDeferredTextureUploadFn& upload) override;
33     void submit();
34 
35 private:
gpu()36     GrGpu* gpu() override { return fGpu; }
37 
38     bool onBindPipeline(const GrProgramInfo&, const SkRect& drawBounds) override;
39     void onSetScissorRect(const SkIRect&) override;
40     bool onBindTextures(const GrGeometryProcessor&,
41                         const GrSurfaceProxy* const geomProcTextures[],
42                         const GrPipeline&) override;
43     void onBindBuffers(sk_sp<const GrBuffer> indexBuffer, sk_sp<const GrBuffer> instanceBuffer,
44                        sk_sp<const GrBuffer> vertexBuffer, GrPrimitiveRestart) override;
45     void onDraw(int vertexCount, int baseVertex) override;
46     void onDrawIndexed(int indexCount, int baseIndex, uint16_t minIndexValue,
47                        uint16_t maxIndexValue, int baseVertex) override;
48     void onDrawInstanced(int instanceCount, int baseInstance, int vertexCount,
49                          int baseVertex) override;
50     void onDrawIndexedInstanced(int indexCount, int baseIndex, int instanceCount, int baseInstance,
51                                 int baseVertex) override;
52     void onDrawIndirect(const GrBuffer* drawIndirectBuffer, size_t bufferOffset,
53                         int drawCount) override;
54     void onDrawIndexedIndirect(const GrBuffer* drawIndirectBuffer, size_t bufferOffset,
55                                int drawCount) override;
56 
57     void onClear(const GrScissorState& scissor, std::array<float, 4> color) override;
58 
59     void onClearStencilClip(const GrScissorState& scissor, bool insideStencilMask) override;
60 
61     void setupRenderPass(const GrOpsRenderPass::LoadAndStoreInfo& colorInfo,
62                          const GrOpsRenderPass::StencilLoadAndStoreInfo& stencilInfo);
63 
64     void setVertexBuffer(id<MTLRenderCommandEncoder>, const GrBuffer*, size_t offset,
65                          size_t inputBufferIndex);
66     void resetBufferBindings();
67     void precreateCmdEncoder();
68 
69     GrMtlGpu*                   fGpu;
70 
71     id<MTLRenderCommandEncoder> fActiveRenderCmdEncoder;
72     GrMtlPipelineState*         fActivePipelineState = nullptr;
73     MTLPrimitiveType            fActivePrimitiveType;
74     MTLRenderPassDescriptor*    fRenderPassDesc;
75     SkRect                      fBounds;
76     size_t                      fCurrentVertexStride;
77 
78     static constexpr size_t kNumBindings = GrMtlUniformHandler::kLastUniformBinding + 3;
79     struct {
80         id<MTLBuffer> fBuffer;
81         size_t fOffset;
82     } fBufferBindings[kNumBindings];
83 
84     using INHERITED = GrOpsRenderPass;
85 };
86 
87 #endif
88