blob: db63860dd50bf911d97a369c636be764dc117eea [file] [log] [blame]
Timothy Liange70604e2018-07-19 09:49:46 -04001/*
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 GrMtlGpuCommandBuffer_DEFINED
9#define GrMtlGpuCommandBuffer_DEFINED
10
11#include "GrGpuCommandBuffer.h"
Timothy Liang7ac582e2018-08-06 09:47:23 -040012#include "GrMtlGpu.h"
Timothy Liang5422f9a2018-08-10 10:57:55 -040013#include "GrMesh.h"
Timothy Liange70604e2018-07-19 09:49:46 -040014
Timothy Liang7ac582e2018-08-06 09:47:23 -040015#import <metal/metal.h>
16
Timothy Liang5422f9a2018-08-10 10:57:55 -040017typedef uint32_t GrColor;
18class GrMtlPipelineState;
Timothy Liange70604e2018-07-19 09:49:46 -040019class GrMtlRenderTarget;
20
21class GrMtlGpuTextureCommandBuffer : public GrGpuTextureCommandBuffer {
22public:
23 GrMtlGpuTextureCommandBuffer(GrMtlGpu* gpu, GrTexture* texture, GrSurfaceOrigin origin)
24 : INHERITED(texture, origin)
25 , fGpu(gpu) {
Timothy Liange70604e2018-07-19 09:49:46 -040026 }
27
28 ~GrMtlGpuTextureCommandBuffer() override {}
29
30 void copy(GrSurface* src, GrSurfaceOrigin srcOrigin, const SkIRect& srcRect,
Timothy Liange35055f2018-07-20 16:53:00 -040031 const SkIPoint& dstPoint) override {
32 fGpu->copySurface(fTexture, fOrigin, src, srcOrigin, srcRect, dstPoint);
33 }
Timothy Liange70604e2018-07-19 09:49:46 -040034
35 void insertEventMarker(const char* msg) override {}
36
37private:
Timothy Liange70604e2018-07-19 09:49:46 -040038 GrMtlGpu* fGpu;
39
40 typedef GrGpuTextureCommandBuffer INHERITED;
41};
42
Timothy Liang5422f9a2018-08-10 10:57:55 -040043class GrMtlGpuRTCommandBuffer : public GrGpuRTCommandBuffer, private GrMesh::SendToGpuImpl {
Timothy Liange70604e2018-07-19 09:49:46 -040044public:
45 GrMtlGpuRTCommandBuffer(GrMtlGpu* gpu, GrRenderTarget* rt, GrSurfaceOrigin origin,
Ethan Nicholas56d19a52018-10-15 11:26:20 -040046 const SkRect& bounds,
Timothy Liange70604e2018-07-19 09:49:46 -040047 const GrGpuRTCommandBuffer::LoadAndStoreInfo& colorInfo,
Timothy Liang5422f9a2018-08-10 10:57:55 -040048 const GrGpuRTCommandBuffer::StencilLoadAndStoreInfo& stencilInfo);
49
50 ~GrMtlGpuRTCommandBuffer() override;
Timothy Liange70604e2018-07-19 09:49:46 -040051
Timothy Liange70604e2018-07-19 09:49:46 -040052 void begin() override {}
53 void end() override {}
54
55 void discard() override {}
56
57 void insertEventMarker(const char* msg) override {}
58
59 void inlineUpload(GrOpFlushState* state, GrDeferredTextureUploadFn& upload) override {}
60
61 void copy(GrSurface* src, GrSurfaceOrigin srcOrigin, const SkIRect& srcRect,
Timothy Liang5422f9a2018-08-10 10:57:55 -040062 const SkIPoint& dstPoint) override;
63
64 void submit();
Timothy Liange70604e2018-07-19 09:49:46 -040065
Timothy Liange70604e2018-07-19 09:49:46 -040066private:
Timothy Liang5422f9a2018-08-10 10:57:55 -040067 void internalBegin();
68 void internalEnd();
69
Timothy Liange70604e2018-07-19 09:49:46 -040070 GrGpu* gpu() override { return fGpu; }
71
Timothy Liang5422f9a2018-08-10 10:57:55 -040072 GrMtlPipelineState* prepareDrawState(
73 const GrPrimitiveProcessor& primProc,
74 const GrPipeline& pipeline,
75 const GrPipeline::FixedDynamicState* fixedDynamicState,
76 const GrMesh meshes[],
77 int meshCount);
78
Timothy Liange70604e2018-07-19 09:49:46 -040079 void onDraw(const GrPrimitiveProcessor& primProc,
80 const GrPipeline& pipeline,
81 const GrPipeline::FixedDynamicState* fixedDynamicState,
82 const GrPipeline::DynamicStateArrays* dynamicStateArrays,
83 const GrMesh mesh[],
84 int meshCount,
Timothy Liang5422f9a2018-08-10 10:57:55 -040085 const SkRect& bounds) override;
Timothy Liange70604e2018-07-19 09:49:46 -040086
Ethan Nicholas56d19a52018-10-15 11:26:20 -040087 void onClear(const GrFixedClip& clip, GrColor color) override;
Timothy Liange70604e2018-07-19 09:49:46 -040088
Ethan Nicholas01063512018-10-08 16:58:25 -040089 void onClearStencilClip(const GrFixedClip& clip, bool insideStencilMask) override;
Timothy Liange70604e2018-07-19 09:49:46 -040090
Timothy Liang5422f9a2018-08-10 10:57:55 -040091 MTLRenderPassDescriptor* createRenderPassDesc() const;
92
93 void bindGeometry(const GrBuffer* vertexBuffer, const GrBuffer* instanceBuffer);
94
95 // GrMesh::SendToGpuImpl methods. These issue the actual Metal draw commands.
96 // Marked final as a hint to the compiler to not use virtual dispatch.
97 void sendMeshToGpu(GrPrimitiveType primType, const GrBuffer* vertexBuffer, int vertexCount,
98 int baseVertex) final {
99 this->sendInstancedMeshToGpu(primType, vertexBuffer, vertexCount, baseVertex, nullptr, 1,
100 0);
101 }
102
103 void sendIndexedMeshToGpu(GrPrimitiveType primType, const GrBuffer* indexBuffer, int indexCount,
104 int baseIndex, uint16_t /*minIndexValue*/, uint16_t /*maxIndexValue*/,
105 const GrBuffer* vertexBuffer, int baseVertex,
106 GrPrimitiveRestart restart) final {
107 SkASSERT(restart == GrPrimitiveRestart::kNo);
108 this->sendIndexedInstancedMeshToGpu(primType, indexBuffer, indexCount, baseIndex,
109 vertexBuffer, baseVertex, nullptr, 1, 0,
110 GrPrimitiveRestart::kNo);
111 }
112
113 void sendInstancedMeshToGpu(GrPrimitiveType, const GrBuffer* vertexBuffer, int vertexCount,
114 int baseVertex, const GrBuffer* instanceBuffer, int instanceCount,
115 int baseInstance) final;
116
117 void sendIndexedInstancedMeshToGpu(GrPrimitiveType, const GrBuffer* indexBuffer, int indexCount,
118 int baseIndex, const GrBuffer* vertexBuffer, int baseVertex,
119 const GrBuffer* instanceBuffer, int instanceCount,
120 int baseInstance, GrPrimitiveRestart) final;
121
Timothy Liange70604e2018-07-19 09:49:46 -0400122 GrMtlGpu* fGpu;
Ethan Nicholas56d19a52018-10-15 11:26:20 -0400123 // GrRenderTargetProxy bounds
124 SkRect fBounds;
Timothy Liange70604e2018-07-19 09:49:46 -0400125 GrGpuRTCommandBuffer::LoadAndStoreInfo fColorLoadAndStoreInfo;
126 GrGpuRTCommandBuffer::StencilLoadAndStoreInfo fStencilLoadAndStoreInfo;
127
Timothy Liang5422f9a2018-08-10 10:57:55 -0400128 id<MTLRenderCommandEncoder> fActiveRenderCmdEncoder;
129 MTLRenderPassDescriptor* fRenderPassDesc;
130
131 struct CommandBufferInfo {
132 SkRect fBounds;
133 };
134
135 CommandBufferInfo fCommandBufferInfo;
136
Timothy Liange70604e2018-07-19 09:49:46 -0400137 typedef GrGpuRTCommandBuffer INHERITED;
138};
139
140#endif
141