egdaniel | 066df7c | 2016-06-08 14:02:27 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016 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 GrVkGpuCommandBuffer_DEFINED |
| 9 | #define GrVkGpuCommandBuffer_DEFINED |
| 10 | |
| 11 | #include "GrGpuCommandBuffer.h" |
| 12 | |
| 13 | #include "GrColor.h" |
Chris Dalton | 114a3c0 | 2017-05-26 15:17:19 -0600 | [diff] [blame] | 14 | #include "GrMesh.h" |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 15 | #include "GrTypes.h" |
| 16 | #include "GrVkPipelineState.h" |
egdaniel | 066df7c | 2016-06-08 14:02:27 -0700 | [diff] [blame] | 17 | |
| 18 | class GrVkGpu; |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 19 | class GrVkImage; |
egdaniel | 066df7c | 2016-06-08 14:02:27 -0700 | [diff] [blame] | 20 | class GrVkRenderPass; |
| 21 | class GrVkRenderTarget; |
| 22 | class GrVkSecondaryCommandBuffer; |
| 23 | |
Greg Daniel | 500d58b | 2017-08-24 15:59:33 -0400 | [diff] [blame] | 24 | class GrVkGpuTextureCommandBuffer : public GrGpuTextureCommandBuffer { |
egdaniel | 066df7c | 2016-06-08 14:02:27 -0700 | [diff] [blame] | 25 | public: |
Greg Daniel | 500d58b | 2017-08-24 15:59:33 -0400 | [diff] [blame] | 26 | GrVkGpuTextureCommandBuffer(GrVkGpu* gpu, GrTexture* texture, GrSurfaceOrigin origin) |
| 27 | : INHERITED(texture, origin) |
| 28 | , fGpu(gpu) { |
| 29 | } |
egdaniel | 066df7c | 2016-06-08 14:02:27 -0700 | [diff] [blame] | 30 | |
Greg Daniel | 500d58b | 2017-08-24 15:59:33 -0400 | [diff] [blame] | 31 | ~GrVkGpuTextureCommandBuffer() override; |
| 32 | |
Robert Phillips | b0e93a2 | 2017-08-29 08:26:54 -0400 | [diff] [blame] | 33 | void copy(GrSurface* src, GrSurfaceOrigin srcOrigin, const SkIRect& srcRect, |
| 34 | const SkIPoint& dstPoint) override; |
Greg Daniel | 500d58b | 2017-08-24 15:59:33 -0400 | [diff] [blame] | 35 | |
| 36 | void insertEventMarker(const char*) override; |
| 37 | |
| 38 | private: |
| 39 | void submit() override; |
| 40 | |
| 41 | struct CopyInfo { |
Robert Phillips | b0e93a2 | 2017-08-29 08:26:54 -0400 | [diff] [blame] | 42 | CopyInfo(GrSurface* src, GrSurfaceOrigin srcOrigin, const SkIRect& srcRect, |
| 43 | const SkIPoint& dstPoint) |
| 44 | : fSrc(src), fSrcOrigin(srcOrigin), fSrcRect(srcRect), fDstPoint(dstPoint) {} |
Greg Daniel | 500d58b | 2017-08-24 15:59:33 -0400 | [diff] [blame] | 45 | |
Robert Phillips | b0e93a2 | 2017-08-29 08:26:54 -0400 | [diff] [blame] | 46 | GrSurface* fSrc; |
| 47 | GrSurfaceOrigin fSrcOrigin; |
| 48 | SkIRect fSrcRect; |
| 49 | SkIPoint fDstPoint; |
Greg Daniel | 500d58b | 2017-08-24 15:59:33 -0400 | [diff] [blame] | 50 | }; |
| 51 | |
| 52 | GrVkGpu* fGpu; |
| 53 | SkTArray<CopyInfo> fCopies; |
| 54 | |
| 55 | typedef GrGpuTextureCommandBuffer INHERITED; |
| 56 | }; |
| 57 | |
| 58 | class GrVkGpuRTCommandBuffer : public GrGpuRTCommandBuffer, private GrMesh::SendToGpuImpl { |
| 59 | public: |
| 60 | GrVkGpuRTCommandBuffer(GrVkGpu*, GrRenderTarget*, GrSurfaceOrigin, |
| 61 | const LoadAndStoreInfo&, |
| 62 | const StencilLoadAndStoreInfo&); |
| 63 | |
| 64 | ~GrVkGpuRTCommandBuffer() override; |
egdaniel | 066df7c | 2016-06-08 14:02:27 -0700 | [diff] [blame] | 65 | |
Robert Phillips | 74c627f | 2017-08-09 10:28:00 -0400 | [diff] [blame] | 66 | void begin() override { } |
egdaniel | 066df7c | 2016-06-08 14:02:27 -0700 | [diff] [blame] | 67 | void end() override; |
| 68 | |
Robert Phillips | 19e51dc | 2017-08-09 09:30:51 -0400 | [diff] [blame] | 69 | void discard() override; |
| 70 | void insertEventMarker(const char*) override; |
egdaniel | 066df7c | 2016-06-08 14:02:27 -0700 | [diff] [blame] | 71 | |
Brian Salomon | 943ed79 | 2017-10-30 09:37:55 -0400 | [diff] [blame] | 72 | void inlineUpload(GrOpFlushState* state, GrDeferredTextureUploadFn& upload) override; |
Greg Daniel | 77b53f6 | 2016-10-18 11:48:51 -0400 | [diff] [blame] | 73 | |
Robert Phillips | b0e93a2 | 2017-08-29 08:26:54 -0400 | [diff] [blame] | 74 | void copy(GrSurface* src, GrSurfaceOrigin srcOrigin, const SkIRect& srcRect, |
| 75 | const SkIPoint& dstPoint) override; |
Greg Daniel | 500d58b | 2017-08-24 15:59:33 -0400 | [diff] [blame] | 76 | |
| 77 | void submit() override; |
| 78 | |
egdaniel | 066df7c | 2016-06-08 14:02:27 -0700 | [diff] [blame] | 79 | private: |
Robert Phillips | 19e51dc | 2017-08-09 09:30:51 -0400 | [diff] [blame] | 80 | void init(); |
Brian Salomon | c293a29 | 2016-11-30 13:38:32 -0500 | [diff] [blame] | 81 | |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 82 | GrGpu* gpu() override; |
| 83 | |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 84 | // Bind vertex and index buffers |
Chris Dalton | ff92650 | 2017-05-03 14:36:54 -0400 | [diff] [blame] | 85 | void bindGeometry(const GrPrimitiveProcessor&, |
| 86 | const GrBuffer* indexBuffer, |
Chris Dalton | 1d61635 | 2017-05-31 12:51:23 -0600 | [diff] [blame] | 87 | const GrBuffer* vertexBuffer, |
| 88 | const GrBuffer* instanceBuffer); |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 89 | |
Greg Daniel | 09eeefb | 2017-10-16 15:15:02 -0400 | [diff] [blame] | 90 | GrVkPipelineState* prepareDrawState(const GrPipeline&, |
| 91 | const GrPrimitiveProcessor&, |
| 92 | GrPrimitiveType, |
| 93 | bool hasDynamicState); |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 94 | |
| 95 | void onDraw(const GrPipeline& pipeline, |
| 96 | const GrPrimitiveProcessor& primProc, |
Chris Dalton | 46983b7 | 2017-06-06 12:27:16 -0600 | [diff] [blame] | 97 | const GrMesh mesh[], |
| 98 | const GrPipeline::DynamicState[], |
Greg Daniel | 36a77ee | 2016-10-18 10:33:25 -0400 | [diff] [blame] | 99 | int meshCount, |
| 100 | const SkRect& bounds) override; |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 101 | |
Chris Dalton | 114a3c0 | 2017-05-26 15:17:19 -0600 | [diff] [blame] | 102 | // GrMesh::SendToGpuImpl methods. These issue the actual Vulkan draw commands. |
| 103 | // Marked final as a hint to the compiler to not use virtual dispatch. |
Chris Dalton | 1d61635 | 2017-05-31 12:51:23 -0600 | [diff] [blame] | 104 | void sendMeshToGpu(const GrPrimitiveProcessor& primProc, GrPrimitiveType primType, |
| 105 | const GrBuffer* vertexBuffer, int vertexCount, int baseVertex) final { |
| 106 | this->sendInstancedMeshToGpu(primProc, primType, vertexBuffer, vertexCount, baseVertex, |
| 107 | nullptr, 1, 0); |
| 108 | } |
Chris Dalton | 114a3c0 | 2017-05-26 15:17:19 -0600 | [diff] [blame] | 109 | |
Chris Dalton | 1d61635 | 2017-05-31 12:51:23 -0600 | [diff] [blame] | 110 | void sendIndexedMeshToGpu(const GrPrimitiveProcessor& primProc, GrPrimitiveType primType, |
Chris Dalton | 114a3c0 | 2017-05-26 15:17:19 -0600 | [diff] [blame] | 111 | const GrBuffer* indexBuffer, int indexCount, int baseIndex, |
Chris Dalton | 1d61635 | 2017-05-31 12:51:23 -0600 | [diff] [blame] | 112 | uint16_t /*minIndexValue*/, uint16_t /*maxIndexValue*/, |
| 113 | const GrBuffer* vertexBuffer, int baseVertex) final { |
| 114 | this->sendIndexedInstancedMeshToGpu(primProc, primType, indexBuffer, indexCount, baseIndex, |
| 115 | vertexBuffer, baseVertex, nullptr, 1, 0); |
| 116 | } |
| 117 | |
| 118 | void sendInstancedMeshToGpu(const GrPrimitiveProcessor&, GrPrimitiveType, |
| 119 | const GrBuffer* vertexBuffer, int vertexCount, int baseVertex, |
| 120 | const GrBuffer* instanceBuffer, int instanceCount, |
| 121 | int baseInstance) final; |
| 122 | |
| 123 | void sendIndexedInstancedMeshToGpu(const GrPrimitiveProcessor&, GrPrimitiveType, |
| 124 | const GrBuffer* indexBuffer, int indexCount, int baseIndex, |
| 125 | const GrBuffer* vertexBuffer, int baseVertex, |
| 126 | const GrBuffer* instanceBuffer, int instanceCount, |
| 127 | int baseInstance) final; |
Chris Dalton | 114a3c0 | 2017-05-26 15:17:19 -0600 | [diff] [blame] | 128 | |
Robert Phillips | 19e51dc | 2017-08-09 09:30:51 -0400 | [diff] [blame] | 129 | void onClear(const GrFixedClip&, GrColor color) override; |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 130 | |
Robert Phillips | 19e51dc | 2017-08-09 09:30:51 -0400 | [diff] [blame] | 131 | void onClearStencilClip(const GrFixedClip&, bool insideStencilMask) override; |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 132 | |
Greg Daniel | 77b53f6 | 2016-10-18 11:48:51 -0400 | [diff] [blame] | 133 | void addAdditionalCommandBuffer(); |
Greg Daniel | 22bc865 | 2017-03-22 15:45:43 -0400 | [diff] [blame] | 134 | void addAdditionalRenderPass(); |
Greg Daniel | 77b53f6 | 2016-10-18 11:48:51 -0400 | [diff] [blame] | 135 | |
| 136 | struct InlineUploadInfo { |
Brian Salomon | 943ed79 | 2017-10-30 09:37:55 -0400 | [diff] [blame] | 137 | InlineUploadInfo(GrOpFlushState* state, const GrDeferredTextureUploadFn& upload) |
| 138 | : fFlushState(state), fUpload(upload) {} |
Greg Daniel | 77b53f6 | 2016-10-18 11:48:51 -0400 | [diff] [blame] | 139 | |
Brian Salomon | 742e31d | 2016-12-07 17:06:19 -0500 | [diff] [blame] | 140 | GrOpFlushState* fFlushState; |
Brian Salomon | 943ed79 | 2017-10-30 09:37:55 -0400 | [diff] [blame] | 141 | GrDeferredTextureUploadFn fUpload; |
Greg Daniel | 77b53f6 | 2016-10-18 11:48:51 -0400 | [diff] [blame] | 142 | }; |
| 143 | |
Greg Daniel | 500d58b | 2017-08-24 15:59:33 -0400 | [diff] [blame] | 144 | struct CopyInfo { |
Robert Phillips | b0e93a2 | 2017-08-29 08:26:54 -0400 | [diff] [blame] | 145 | CopyInfo(GrSurface* src, GrSurfaceOrigin srcOrigin, const SkIRect& srcRect, |
| 146 | const SkIPoint& dstPoint) |
| 147 | : fSrc(src), fSrcOrigin(srcOrigin), fSrcRect(srcRect), fDstPoint(dstPoint) {} |
Greg Daniel | 500d58b | 2017-08-24 15:59:33 -0400 | [diff] [blame] | 148 | |
Robert Phillips | b0e93a2 | 2017-08-29 08:26:54 -0400 | [diff] [blame] | 149 | GrSurface* fSrc; |
| 150 | GrSurfaceOrigin fSrcOrigin; |
| 151 | SkIRect fSrcRect; |
| 152 | SkIPoint fDstPoint; |
Greg Daniel | 500d58b | 2017-08-24 15:59:33 -0400 | [diff] [blame] | 153 | }; |
| 154 | |
Greg Daniel | 36a77ee | 2016-10-18 10:33:25 -0400 | [diff] [blame] | 155 | struct CommandBufferInfo { |
Greg Daniel | 22bc865 | 2017-03-22 15:45:43 -0400 | [diff] [blame] | 156 | const GrVkRenderPass* fRenderPass; |
| 157 | SkTArray<GrVkSecondaryCommandBuffer*> fCommandBuffers; |
| 158 | VkClearValue fColorClearValue; |
| 159 | SkRect fBounds; |
| 160 | bool fIsEmpty; |
| 161 | bool fStartsWithClear; |
Greg Daniel | 500d58b | 2017-08-24 15:59:33 -0400 | [diff] [blame] | 162 | // The PreDrawUploads and PreCopies are sent to the GPU before submitting the secondary |
| 163 | // command buffer. |
Greg Daniel | 22bc865 | 2017-03-22 15:45:43 -0400 | [diff] [blame] | 164 | SkTArray<InlineUploadInfo> fPreDrawUploads; |
Greg Daniel | 500d58b | 2017-08-24 15:59:33 -0400 | [diff] [blame] | 165 | SkTArray<CopyInfo> fPreCopies; |
Greg Daniel | 22bc865 | 2017-03-22 15:45:43 -0400 | [diff] [blame] | 166 | |
| 167 | GrVkSecondaryCommandBuffer* currentCmdBuf() { |
| 168 | return fCommandBuffers.back(); |
| 169 | } |
Greg Daniel | 36a77ee | 2016-10-18 10:33:25 -0400 | [diff] [blame] | 170 | }; |
| 171 | |
| 172 | SkTArray<CommandBufferInfo> fCommandBufferInfos; |
Greg Daniel | 22bc865 | 2017-03-22 15:45:43 -0400 | [diff] [blame] | 173 | int fCurrentCmdInfo; |
Greg Daniel | 36a77ee | 2016-10-18 10:33:25 -0400 | [diff] [blame] | 174 | |
egdaniel | 066df7c | 2016-06-08 14:02:27 -0700 | [diff] [blame] | 175 | GrVkGpu* fGpu; |
Brian Salomon | c293a29 | 2016-11-30 13:38:32 -0500 | [diff] [blame] | 176 | VkAttachmentLoadOp fVkColorLoadOp; |
| 177 | VkAttachmentStoreOp fVkColorStoreOp; |
| 178 | VkAttachmentLoadOp fVkStencilLoadOp; |
| 179 | VkAttachmentStoreOp fVkStencilStoreOp; |
| 180 | GrColor4f fClearColor; |
Greg Daniel | 22bc865 | 2017-03-22 15:45:43 -0400 | [diff] [blame] | 181 | GrVkPipelineState* fLastPipelineState; |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 182 | |
Greg Daniel | 500d58b | 2017-08-24 15:59:33 -0400 | [diff] [blame] | 183 | typedef GrGpuRTCommandBuffer INHERITED; |
egdaniel | 066df7c | 2016-06-08 14:02:27 -0700 | [diff] [blame] | 184 | }; |
| 185 | |
| 186 | #endif |