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, |
| 76 | const GrMesh meshes[], |
| 77 | int meshCount); |
| 78 | |
Timothy Liang | e70604e | 2018-07-19 09:49:46 -0400 | [diff] [blame] | 79 | 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 Liang | 5422f9a | 2018-08-10 10:57:55 -0400 | [diff] [blame] | 85 | const SkRect& bounds) override; |
Timothy Liang | e70604e | 2018-07-19 09:49:46 -0400 | [diff] [blame] | 86 | |
Brian Osman | 9a9baae | 2018-11-05 15:06:26 -0500 | [diff] [blame] | 87 | void onClear(const GrFixedClip& clip, const SkPMColor4f& color) override; |
Timothy Liang | e70604e | 2018-07-19 09:49:46 -0400 | [diff] [blame] | 88 | |
Ethan Nicholas | 0106351 | 2018-10-08 16:58:25 -0400 | [diff] [blame] | 89 | void onClearStencilClip(const GrFixedClip& clip, bool insideStencilMask) override; |
Timothy Liang | e70604e | 2018-07-19 09:49:46 -0400 | [diff] [blame] | 90 | |
Timothy Liang | 5422f9a | 2018-08-10 10:57:55 -0400 | [diff] [blame] | 91 | 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 Liang | e70604e | 2018-07-19 09:49:46 -0400 | [diff] [blame] | 122 | GrMtlGpu* fGpu; |
Ethan Nicholas | 56d19a5 | 2018-10-15 11:26:20 -0400 | [diff] [blame] | 123 | // GrRenderTargetProxy bounds |
Ethan Nicholas | 391d344 | 2018-10-15 13:00:59 -0400 | [diff] [blame] | 124 | #ifdef SK_DEBUG |
Ethan Nicholas | 56d19a5 | 2018-10-15 11:26:20 -0400 | [diff] [blame] | 125 | SkRect fBounds; |
Ethan Nicholas | 391d344 | 2018-10-15 13:00:59 -0400 | [diff] [blame] | 126 | #endif |
Timothy Liang | e70604e | 2018-07-19 09:49:46 -0400 | [diff] [blame] | 127 | GrGpuRTCommandBuffer::LoadAndStoreInfo fColorLoadAndStoreInfo; |
| 128 | GrGpuRTCommandBuffer::StencilLoadAndStoreInfo fStencilLoadAndStoreInfo; |
| 129 | |
Timothy Liang | 5422f9a | 2018-08-10 10:57:55 -0400 | [diff] [blame] | 130 | id<MTLRenderCommandEncoder> fActiveRenderCmdEncoder; |
| 131 | MTLRenderPassDescriptor* fRenderPassDesc; |
| 132 | |
| 133 | struct CommandBufferInfo { |
| 134 | SkRect fBounds; |
| 135 | }; |
| 136 | |
| 137 | CommandBufferInfo fCommandBufferInfo; |
| 138 | |
Timothy Liang | e70604e | 2018-07-19 09:49:46 -0400 | [diff] [blame] | 139 | typedef GrGpuRTCommandBuffer INHERITED; |
| 140 | }; |
| 141 | |
| 142 | #endif |
| 143 | |