blob: 322a2e858abb13267d09325f48e43ae2aec80aa4 [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,
Jim Van Verth1223e7f2019-02-28 17:38:35 -050076 GrPrimitiveType primType);
Timothy Liang5422f9a2018-08-10 10:57:55 -040077
Timothy Liange70604e2018-07-19 09:49:46 -040078 void onDraw(const GrPrimitiveProcessor& primProc,
79 const GrPipeline& pipeline,
80 const GrPipeline::FixedDynamicState* fixedDynamicState,
81 const GrPipeline::DynamicStateArrays* dynamicStateArrays,
82 const GrMesh mesh[],
83 int meshCount,
Timothy Liang5422f9a2018-08-10 10:57:55 -040084 const SkRect& bounds) override;
Timothy Liange70604e2018-07-19 09:49:46 -040085
Brian Osman9a9baae2018-11-05 15:06:26 -050086 void onClear(const GrFixedClip& clip, const SkPMColor4f& color) override;
Timothy Liange70604e2018-07-19 09:49:46 -040087
Ethan Nicholas01063512018-10-08 16:58:25 -040088 void onClearStencilClip(const GrFixedClip& clip, bool insideStencilMask) override;
Timothy Liange70604e2018-07-19 09:49:46 -040089
Timothy Liang5422f9a2018-08-10 10:57:55 -040090 MTLRenderPassDescriptor* createRenderPassDesc() const;
91
92 void bindGeometry(const GrBuffer* vertexBuffer, const GrBuffer* instanceBuffer);
93
94 // GrMesh::SendToGpuImpl methods. These issue the actual Metal draw commands.
95 // Marked final as a hint to the compiler to not use virtual dispatch.
96 void sendMeshToGpu(GrPrimitiveType primType, const GrBuffer* vertexBuffer, int vertexCount,
97 int baseVertex) final {
98 this->sendInstancedMeshToGpu(primType, vertexBuffer, vertexCount, baseVertex, nullptr, 1,
99 0);
100 }
101
102 void sendIndexedMeshToGpu(GrPrimitiveType primType, const GrBuffer* indexBuffer, int indexCount,
103 int baseIndex, uint16_t /*minIndexValue*/, uint16_t /*maxIndexValue*/,
104 const GrBuffer* vertexBuffer, int baseVertex,
105 GrPrimitiveRestart restart) final {
106 SkASSERT(restart == GrPrimitiveRestart::kNo);
107 this->sendIndexedInstancedMeshToGpu(primType, indexBuffer, indexCount, baseIndex,
108 vertexBuffer, baseVertex, nullptr, 1, 0,
109 GrPrimitiveRestart::kNo);
110 }
111
112 void sendInstancedMeshToGpu(GrPrimitiveType, const GrBuffer* vertexBuffer, int vertexCount,
113 int baseVertex, const GrBuffer* instanceBuffer, int instanceCount,
114 int baseInstance) final;
115
116 void sendIndexedInstancedMeshToGpu(GrPrimitiveType, const GrBuffer* indexBuffer, int indexCount,
117 int baseIndex, const GrBuffer* vertexBuffer, int baseVertex,
118 const GrBuffer* instanceBuffer, int instanceCount,
119 int baseInstance, GrPrimitiveRestart) final;
120
Timothy Liange70604e2018-07-19 09:49:46 -0400121 GrMtlGpu* fGpu;
Ethan Nicholas56d19a52018-10-15 11:26:20 -0400122 // GrRenderTargetProxy bounds
Ethan Nicholas391d3442018-10-15 13:00:59 -0400123#ifdef SK_DEBUG
Ethan Nicholas56d19a52018-10-15 11:26:20 -0400124 SkRect fBounds;
Ethan Nicholas391d3442018-10-15 13:00:59 -0400125#endif
Timothy Liange70604e2018-07-19 09:49:46 -0400126 GrGpuRTCommandBuffer::LoadAndStoreInfo fColorLoadAndStoreInfo;
127 GrGpuRTCommandBuffer::StencilLoadAndStoreInfo fStencilLoadAndStoreInfo;
128
Timothy Liang5422f9a2018-08-10 10:57:55 -0400129 id<MTLRenderCommandEncoder> fActiveRenderCmdEncoder;
130 MTLRenderPassDescriptor* fRenderPassDesc;
131
132 struct CommandBufferInfo {
133 SkRect fBounds;
134 };
135
136 CommandBufferInfo fCommandBufferInfo;
137
Timothy Liange70604e2018-07-19 09:49:46 -0400138 typedef GrGpuRTCommandBuffer INHERITED;
139};
140
141#endif
142