Timothy Liang | e70604e | 2018-07-19 09:49:46 -0400 | [diff] [blame] | 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 GrMtlGpuCommandBuffer_DEFINED |
| 9 | #define GrMtlGpuCommandBuffer_DEFINED |
| 10 | |
| 11 | #include "GrGpuCommandBuffer.h" |
Timothy Liang | 7ac582e | 2018-08-06 09:47:23 -0400 | [diff] [blame] | 12 | #include "GrMtlGpu.h" |
Timothy Liang | 5422f9a | 2018-08-10 10:57:55 -0400 | [diff] [blame] | 13 | #include "GrMesh.h" |
Timothy Liang | e70604e | 2018-07-19 09:49:46 -0400 | [diff] [blame] | 14 | |
Timothy Liang | 7ac582e | 2018-08-06 09:47:23 -0400 | [diff] [blame] | 15 | #import <metal/metal.h> |
| 16 | |
Timothy Liang | 5422f9a | 2018-08-10 10:57:55 -0400 | [diff] [blame] | 17 | typedef uint32_t GrColor; |
| 18 | class GrMtlPipelineState; |
Timothy Liang | e70604e | 2018-07-19 09:49:46 -0400 | [diff] [blame] | 19 | class GrMtlRenderTarget; |
| 20 | |
| 21 | class GrMtlGpuTextureCommandBuffer : public GrGpuTextureCommandBuffer { |
| 22 | public: |
| 23 | GrMtlGpuTextureCommandBuffer(GrMtlGpu* gpu, GrTexture* texture, GrSurfaceOrigin origin) |
| 24 | : INHERITED(texture, origin) |
| 25 | , fGpu(gpu) { |
Timothy Liang | e70604e | 2018-07-19 09:49:46 -0400 | [diff] [blame] | 26 | } |
| 27 | |
| 28 | ~GrMtlGpuTextureCommandBuffer() override {} |
| 29 | |
| 30 | void copy(GrSurface* src, GrSurfaceOrigin srcOrigin, const SkIRect& srcRect, |
Timothy Liang | e35055f | 2018-07-20 16:53:00 -0400 | [diff] [blame] | 31 | const SkIPoint& dstPoint) override { |
| 32 | fGpu->copySurface(fTexture, fOrigin, src, srcOrigin, srcRect, dstPoint); |
| 33 | } |
Timothy Liang | e70604e | 2018-07-19 09:49:46 -0400 | [diff] [blame] | 34 | |
| 35 | void insertEventMarker(const char* msg) override {} |
| 36 | |
| 37 | private: |
Timothy Liang | e70604e | 2018-07-19 09:49:46 -0400 | [diff] [blame] | 38 | GrMtlGpu* fGpu; |
| 39 | |
| 40 | typedef GrGpuTextureCommandBuffer INHERITED; |
| 41 | }; |
| 42 | |
Timothy Liang | 5422f9a | 2018-08-10 10:57:55 -0400 | [diff] [blame] | 43 | class GrMtlGpuRTCommandBuffer : public GrGpuRTCommandBuffer, private GrMesh::SendToGpuImpl { |
Timothy Liang | e70604e | 2018-07-19 09:49:46 -0400 | [diff] [blame] | 44 | public: |
| 45 | GrMtlGpuRTCommandBuffer(GrMtlGpu* gpu, GrRenderTarget* rt, GrSurfaceOrigin origin, |
| 46 | const GrGpuRTCommandBuffer::LoadAndStoreInfo& colorInfo, |
Timothy Liang | 5422f9a | 2018-08-10 10:57:55 -0400 | [diff] [blame] | 47 | const GrGpuRTCommandBuffer::StencilLoadAndStoreInfo& stencilInfo); |
| 48 | |
| 49 | ~GrMtlGpuRTCommandBuffer() override; |
Timothy Liang | e70604e | 2018-07-19 09:49:46 -0400 | [diff] [blame] | 50 | |
Timothy Liang | e70604e | 2018-07-19 09:49:46 -0400 | [diff] [blame] | 51 | void begin() override {} |
| 52 | void end() override {} |
| 53 | |
| 54 | void discard() override {} |
| 55 | |
| 56 | void insertEventMarker(const char* msg) override {} |
| 57 | |
| 58 | void inlineUpload(GrOpFlushState* state, GrDeferredTextureUploadFn& upload) override {} |
| 59 | |
| 60 | void copy(GrSurface* src, GrSurfaceOrigin srcOrigin, const SkIRect& srcRect, |
Timothy Liang | 5422f9a | 2018-08-10 10:57:55 -0400 | [diff] [blame] | 61 | const SkIPoint& dstPoint) override; |
| 62 | |
| 63 | void submit(); |
Timothy Liang | e70604e | 2018-07-19 09:49:46 -0400 | [diff] [blame] | 64 | |
Timothy Liang | e70604e | 2018-07-19 09:49:46 -0400 | [diff] [blame] | 65 | private: |
Timothy Liang | 5422f9a | 2018-08-10 10:57:55 -0400 | [diff] [blame] | 66 | void internalBegin(); |
| 67 | void internalEnd(); |
| 68 | |
Timothy Liang | e70604e | 2018-07-19 09:49:46 -0400 | [diff] [blame] | 69 | GrGpu* gpu() override { return fGpu; } |
| 70 | |
Timothy Liang | 5422f9a | 2018-08-10 10:57:55 -0400 | [diff] [blame] | 71 | GrMtlPipelineState* prepareDrawState( |
| 72 | const GrPrimitiveProcessor& primProc, |
| 73 | const GrPipeline& pipeline, |
| 74 | const GrPipeline::FixedDynamicState* fixedDynamicState, |
| 75 | const GrMesh meshes[], |
| 76 | int meshCount); |
| 77 | |
Timothy Liang | e70604e | 2018-07-19 09:49:46 -0400 | [diff] [blame] | 78 | 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 Liang | 5422f9a | 2018-08-10 10:57:55 -0400 | [diff] [blame] | 84 | const SkRect& bounds) override; |
Timothy Liang | e70604e | 2018-07-19 09:49:46 -0400 | [diff] [blame] | 85 | |
| 86 | void onClear(const GrFixedClip& clip, GrColor color) override {} |
| 87 | |
Ethan Nicholas | 0106351 | 2018-10-08 16:58:25 -0400 | [diff] [blame^] | 88 | void onClearStencilClip(const GrFixedClip& clip, bool insideStencilMask) override; |
Timothy Liang | e70604e | 2018-07-19 09:49:46 -0400 | [diff] [blame] | 89 | |
Timothy Liang | 5422f9a | 2018-08-10 10:57:55 -0400 | [diff] [blame] | 90 | 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 Liang | e70604e | 2018-07-19 09:49:46 -0400 | [diff] [blame] | 121 | GrMtlGpu* fGpu; |
| 122 | GrGpuRTCommandBuffer::LoadAndStoreInfo fColorLoadAndStoreInfo; |
| 123 | GrGpuRTCommandBuffer::StencilLoadAndStoreInfo fStencilLoadAndStoreInfo; |
| 124 | |
Timothy Liang | 5422f9a | 2018-08-10 10:57:55 -0400 | [diff] [blame] | 125 | id<MTLRenderCommandEncoder> fActiveRenderCmdEncoder; |
| 126 | MTLRenderPassDescriptor* fRenderPassDesc; |
| 127 | |
| 128 | struct CommandBufferInfo { |
| 129 | SkRect fBounds; |
| 130 | }; |
| 131 | |
| 132 | CommandBufferInfo fCommandBufferInfo; |
| 133 | |
Timothy Liang | e70604e | 2018-07-19 09:49:46 -0400 | [diff] [blame] | 134 | typedef GrGpuRTCommandBuffer INHERITED; |
| 135 | }; |
| 136 | |
| 137 | #endif |
| 138 | |