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, |
Ethan Nicholas | 56d19a5 | 2018-10-15 11:26:20 -0400 | [diff] [blame] | 46 | const SkRect& bounds, |
Timothy Liang | e70604e | 2018-07-19 09:49:46 -0400 | [diff] [blame] | 47 | const GrGpuRTCommandBuffer::LoadAndStoreInfo& colorInfo, |
Timothy Liang | 5422f9a | 2018-08-10 10:57:55 -0400 | [diff] [blame] | 48 | const GrGpuRTCommandBuffer::StencilLoadAndStoreInfo& stencilInfo); |
| 49 | |
| 50 | ~GrMtlGpuRTCommandBuffer() override; |
Timothy Liang | e70604e | 2018-07-19 09:49:46 -0400 | [diff] [blame] | 51 | |
Timothy Liang | e70604e | 2018-07-19 09:49:46 -0400 | [diff] [blame] | 52 | 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 Liang | 5422f9a | 2018-08-10 10:57:55 -0400 | [diff] [blame] | 62 | const SkIPoint& dstPoint) override; |
| 63 | |
| 64 | void submit(); |
Timothy Liang | e70604e | 2018-07-19 09:49:46 -0400 | [diff] [blame] | 65 | |
Timothy Liang | e70604e | 2018-07-19 09:49:46 -0400 | [diff] [blame] | 66 | private: |
Timothy Liang | 5422f9a | 2018-08-10 10:57:55 -0400 | [diff] [blame] | 67 | void internalBegin(); |
| 68 | void internalEnd(); |
| 69 | |
Timothy Liang | e70604e | 2018-07-19 09:49:46 -0400 | [diff] [blame] | 70 | GrGpu* gpu() override { return fGpu; } |
| 71 | |
Timothy Liang | 5422f9a | 2018-08-10 10:57:55 -0400 | [diff] [blame] | 72 | GrMtlPipelineState* prepareDrawState( |
| 73 | const GrPrimitiveProcessor& primProc, |
| 74 | const GrPipeline& pipeline, |
| 75 | const GrPipeline::FixedDynamicState* fixedDynamicState, |
Jim Van Verth | 1223e7f | 2019-02-28 17:38:35 -0500 | [diff] [blame^] | 76 | GrPrimitiveType primType); |
Timothy Liang | 5422f9a | 2018-08-10 10:57:55 -0400 | [diff] [blame] | 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 | |
Brian Osman | 9a9baae | 2018-11-05 15:06:26 -0500 | [diff] [blame] | 86 | void onClear(const GrFixedClip& clip, const SkPMColor4f& color) override; |
Timothy Liang | e70604e | 2018-07-19 09:49:46 -0400 | [diff] [blame] | 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; |
Ethan Nicholas | 56d19a5 | 2018-10-15 11:26:20 -0400 | [diff] [blame] | 122 | // GrRenderTargetProxy bounds |
Ethan Nicholas | 391d344 | 2018-10-15 13:00:59 -0400 | [diff] [blame] | 123 | #ifdef SK_DEBUG |
Ethan Nicholas | 56d19a5 | 2018-10-15 11:26:20 -0400 | [diff] [blame] | 124 | SkRect fBounds; |
Ethan Nicholas | 391d344 | 2018-10-15 13:00:59 -0400 | [diff] [blame] | 125 | #endif |
Timothy Liang | e70604e | 2018-07-19 09:49:46 -0400 | [diff] [blame] | 126 | GrGpuRTCommandBuffer::LoadAndStoreInfo fColorLoadAndStoreInfo; |
| 127 | GrGpuRTCommandBuffer::StencilLoadAndStoreInfo fStencilLoadAndStoreInfo; |
| 128 | |
Timothy Liang | 5422f9a | 2018-08-10 10:57:55 -0400 | [diff] [blame] | 129 | id<MTLRenderCommandEncoder> fActiveRenderCmdEncoder; |
| 130 | MTLRenderPassDescriptor* fRenderPassDesc; |
| 131 | |
| 132 | struct CommandBufferInfo { |
| 133 | SkRect fBounds; |
| 134 | }; |
| 135 | |
| 136 | CommandBufferInfo fCommandBufferInfo; |
| 137 | |
Timothy Liang | e70604e | 2018-07-19 09:49:46 -0400 | [diff] [blame] | 138 | typedef GrGpuRTCommandBuffer INHERITED; |
| 139 | }; |
| 140 | |
| 141 | #endif |
| 142 | |