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" |
Greg Daniel | 487132b | 2018-12-20 14:09:36 -0500 | [diff] [blame] | 17 | #include "vk/GrVkTypes.h" |
egdaniel | 066df7c | 2016-06-08 14:02:27 -0700 | [diff] [blame] | 18 | |
| 19 | class GrVkGpu; |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 20 | class GrVkImage; |
egdaniel | 066df7c | 2016-06-08 14:02:27 -0700 | [diff] [blame] | 21 | class GrVkRenderPass; |
| 22 | class GrVkRenderTarget; |
| 23 | class GrVkSecondaryCommandBuffer; |
| 24 | |
Greg Daniel | 500d58b | 2017-08-24 15:59:33 -0400 | [diff] [blame] | 25 | class GrVkGpuTextureCommandBuffer : public GrGpuTextureCommandBuffer { |
egdaniel | 066df7c | 2016-06-08 14:02:27 -0700 | [diff] [blame] | 26 | public: |
Robert Phillips | 5b5d84c | 2018-08-09 15:12:18 -0400 | [diff] [blame] | 27 | GrVkGpuTextureCommandBuffer(GrVkGpu* gpu) : fGpu(gpu) {} |
egdaniel | 066df7c | 2016-06-08 14:02:27 -0700 | [diff] [blame] | 28 | |
Greg Daniel | 500d58b | 2017-08-24 15:59:33 -0400 | [diff] [blame] | 29 | ~GrVkGpuTextureCommandBuffer() override; |
| 30 | |
Robert Phillips | b0e93a2 | 2017-08-29 08:26:54 -0400 | [diff] [blame] | 31 | void copy(GrSurface* src, GrSurfaceOrigin srcOrigin, const SkIRect& srcRect, |
| 32 | const SkIPoint& dstPoint) override; |
Greg Daniel | 500d58b | 2017-08-24 15:59:33 -0400 | [diff] [blame] | 33 | |
| 34 | void insertEventMarker(const char*) override; |
| 35 | |
Robert Phillips | 5b5d84c | 2018-08-09 15:12:18 -0400 | [diff] [blame] | 36 | void reset() { |
| 37 | fCopies.reset(); |
| 38 | fTexture = nullptr; |
| 39 | } |
Greg Daniel | 500d58b | 2017-08-24 15:59:33 -0400 | [diff] [blame] | 40 | |
Robert Phillips | 5b5d84c | 2018-08-09 15:12:18 -0400 | [diff] [blame] | 41 | void submit(); |
| 42 | |
| 43 | private: |
Greg Daniel | 500d58b | 2017-08-24 15:59:33 -0400 | [diff] [blame] | 44 | struct CopyInfo { |
Robert Phillips | b0e93a2 | 2017-08-29 08:26:54 -0400 | [diff] [blame] | 45 | CopyInfo(GrSurface* src, GrSurfaceOrigin srcOrigin, const SkIRect& srcRect, |
| 46 | const SkIPoint& dstPoint) |
| 47 | : fSrc(src), fSrcOrigin(srcOrigin), fSrcRect(srcRect), fDstPoint(dstPoint) {} |
Greg Daniel | 500d58b | 2017-08-24 15:59:33 -0400 | [diff] [blame] | 48 | |
Robert Phillips | b0e93a2 | 2017-08-29 08:26:54 -0400 | [diff] [blame] | 49 | GrSurface* fSrc; |
| 50 | GrSurfaceOrigin fSrcOrigin; |
| 51 | SkIRect fSrcRect; |
| 52 | SkIPoint fDstPoint; |
Greg Daniel | 500d58b | 2017-08-24 15:59:33 -0400 | [diff] [blame] | 53 | }; |
| 54 | |
| 55 | GrVkGpu* fGpu; |
| 56 | SkTArray<CopyInfo> fCopies; |
| 57 | |
| 58 | typedef GrGpuTextureCommandBuffer INHERITED; |
| 59 | }; |
| 60 | |
| 61 | class GrVkGpuRTCommandBuffer : public GrGpuRTCommandBuffer, private GrMesh::SendToGpuImpl { |
| 62 | public: |
Robert Phillips | 5b5d84c | 2018-08-09 15:12:18 -0400 | [diff] [blame] | 63 | GrVkGpuRTCommandBuffer(GrVkGpu*); |
Greg Daniel | 500d58b | 2017-08-24 15:59:33 -0400 | [diff] [blame] | 64 | |
| 65 | ~GrVkGpuRTCommandBuffer() override; |
egdaniel | 066df7c | 2016-06-08 14:02:27 -0700 | [diff] [blame] | 66 | |
Robert Phillips | 74c627f | 2017-08-09 10:28:00 -0400 | [diff] [blame] | 67 | void begin() override { } |
egdaniel | 066df7c | 2016-06-08 14:02:27 -0700 | [diff] [blame] | 68 | void end() override; |
| 69 | |
Robert Phillips | 19e51dc | 2017-08-09 09:30:51 -0400 | [diff] [blame] | 70 | void discard() override; |
| 71 | void insertEventMarker(const char*) override; |
egdaniel | 066df7c | 2016-06-08 14:02:27 -0700 | [diff] [blame] | 72 | |
Brian Salomon | 943ed79 | 2017-10-30 09:37:55 -0400 | [diff] [blame] | 73 | void inlineUpload(GrOpFlushState* state, GrDeferredTextureUploadFn& upload) override; |
Greg Daniel | 77b53f6 | 2016-10-18 11:48:51 -0400 | [diff] [blame] | 74 | |
Robert Phillips | b0e93a2 | 2017-08-29 08:26:54 -0400 | [diff] [blame] | 75 | void copy(GrSurface* src, GrSurfaceOrigin srcOrigin, const SkIRect& srcRect, |
| 76 | const SkIPoint& dstPoint) override; |
Greg Daniel | 500d58b | 2017-08-24 15:59:33 -0400 | [diff] [blame] | 77 | |
Greg Daniel | 64cc9aa | 2018-10-19 13:54:56 -0400 | [diff] [blame] | 78 | void executeDrawable(std::unique_ptr<SkDrawable::GpuDrawHandler>) override; |
| 79 | |
Robert Phillips | 5b5d84c | 2018-08-09 15:12:18 -0400 | [diff] [blame] | 80 | void set(GrRenderTarget*, GrSurfaceOrigin, |
| 81 | const GrGpuRTCommandBuffer::LoadAndStoreInfo&, |
| 82 | const GrGpuRTCommandBuffer::StencilLoadAndStoreInfo&); |
| 83 | void reset(); |
| 84 | |
| 85 | void submit(); |
Greg Daniel | 500d58b | 2017-08-24 15:59:33 -0400 | [diff] [blame] | 86 | |
egdaniel | 066df7c | 2016-06-08 14:02:27 -0700 | [diff] [blame] | 87 | private: |
Robert Phillips | 19e51dc | 2017-08-09 09:30:51 -0400 | [diff] [blame] | 88 | void init(); |
Brian Salomon | c293a29 | 2016-11-30 13:38:32 -0500 | [diff] [blame] | 89 | |
Greg Daniel | 070cbaf | 2019-01-03 17:35:54 -0500 | [diff] [blame] | 90 | // Called instead of init when we are drawing to a render target that already wraps a secondary |
| 91 | // command buffer. |
| 92 | void initWrapped(); |
| 93 | |
| 94 | bool wrapsSecondaryCommandBuffer() const; |
| 95 | |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 96 | GrGpu* gpu() override; |
| 97 | |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 98 | // Bind vertex and index buffers |
Brian Salomon | dbf7072 | 2019-02-07 11:31:24 -0500 | [diff] [blame] | 99 | void bindGeometry(const GrGpuBuffer* indexBuffer, |
| 100 | const GrGpuBuffer* vertexBuffer, |
| 101 | const GrGpuBuffer* instanceBuffer); |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 102 | |
Brian Salomon | ff168d9 | 2018-06-23 15:17:27 -0400 | [diff] [blame] | 103 | GrVkPipelineState* prepareDrawState(const GrPrimitiveProcessor&, |
| 104 | const GrPipeline&, |
Brian Salomon | 4934890 | 2018-06-26 09:12:38 -0400 | [diff] [blame] | 105 | const GrPipeline::FixedDynamicState*, |
| 106 | const GrPipeline::DynamicStateArrays*, |
| 107 | GrPrimitiveType); |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 108 | |
Brian Salomon | 4934890 | 2018-06-26 09:12:38 -0400 | [diff] [blame] | 109 | void onDraw(const GrPrimitiveProcessor&, |
| 110 | const GrPipeline&, |
| 111 | const GrPipeline::FixedDynamicState*, |
| 112 | const GrPipeline::DynamicStateArrays*, |
| 113 | const GrMesh[], |
Greg Daniel | 36a77ee | 2016-10-18 10:33:25 -0400 | [diff] [blame] | 114 | int meshCount, |
| 115 | const SkRect& bounds) override; |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 116 | |
Chris Dalton | 114a3c0 | 2017-05-26 15:17:19 -0600 | [diff] [blame] | 117 | // GrMesh::SendToGpuImpl methods. These issue the actual Vulkan draw commands. |
| 118 | // Marked final as a hint to the compiler to not use virtual dispatch. |
Brian Salomon | 802cb31 | 2018-06-08 18:05:20 -0400 | [diff] [blame] | 119 | void sendMeshToGpu(GrPrimitiveType primType, const GrBuffer* vertexBuffer, int vertexCount, |
| 120 | int baseVertex) final { |
| 121 | this->sendInstancedMeshToGpu(primType, vertexBuffer, vertexCount, baseVertex, nullptr, 1, |
| 122 | 0); |
Chris Dalton | 1d61635 | 2017-05-31 12:51:23 -0600 | [diff] [blame] | 123 | } |
Chris Dalton | 114a3c0 | 2017-05-26 15:17:19 -0600 | [diff] [blame] | 124 | |
Brian Salomon | 802cb31 | 2018-06-08 18:05:20 -0400 | [diff] [blame] | 125 | void sendIndexedMeshToGpu(GrPrimitiveType primType, const GrBuffer* indexBuffer, int indexCount, |
| 126 | int baseIndex, uint16_t /*minIndexValue*/, uint16_t /*maxIndexValue*/, |
| 127 | const GrBuffer* vertexBuffer, int baseVertex, |
| 128 | GrPrimitiveRestart restart) final { |
| 129 | SkASSERT(restart == GrPrimitiveRestart::kNo); |
| 130 | this->sendIndexedInstancedMeshToGpu(primType, indexBuffer, indexCount, baseIndex, |
| 131 | vertexBuffer, baseVertex, nullptr, 1, 0, |
| 132 | GrPrimitiveRestart::kNo); |
Chris Dalton | 1d61635 | 2017-05-31 12:51:23 -0600 | [diff] [blame] | 133 | } |
| 134 | |
Brian Salomon | 802cb31 | 2018-06-08 18:05:20 -0400 | [diff] [blame] | 135 | void sendInstancedMeshToGpu(GrPrimitiveType, const GrBuffer* vertexBuffer, int vertexCount, |
| 136 | int baseVertex, const GrBuffer* instanceBuffer, int instanceCount, |
Chris Dalton | 1d61635 | 2017-05-31 12:51:23 -0600 | [diff] [blame] | 137 | int baseInstance) final; |
| 138 | |
Brian Salomon | 802cb31 | 2018-06-08 18:05:20 -0400 | [diff] [blame] | 139 | void sendIndexedInstancedMeshToGpu(GrPrimitiveType, const GrBuffer* indexBuffer, int indexCount, |
| 140 | int baseIndex, const GrBuffer* vertexBuffer, int baseVertex, |
Chris Dalton | 1d61635 | 2017-05-31 12:51:23 -0600 | [diff] [blame] | 141 | const GrBuffer* instanceBuffer, int instanceCount, |
Brian Salomon | 802cb31 | 2018-06-08 18:05:20 -0400 | [diff] [blame] | 142 | int baseInstance, GrPrimitiveRestart) final; |
Chris Dalton | 114a3c0 | 2017-05-26 15:17:19 -0600 | [diff] [blame] | 143 | |
Brian Osman | 9a9baae | 2018-11-05 15:06:26 -0500 | [diff] [blame] | 144 | void onClear(const GrFixedClip&, const SkPMColor4f& color) override; |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 145 | |
Robert Phillips | 19e51dc | 2017-08-09 09:30:51 -0400 | [diff] [blame] | 146 | void onClearStencilClip(const GrFixedClip&, bool insideStencilMask) override; |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 147 | |
Greg Daniel | 77b53f6 | 2016-10-18 11:48:51 -0400 | [diff] [blame] | 148 | void addAdditionalCommandBuffer(); |
Greg Daniel | 22bc865 | 2017-03-22 15:45:43 -0400 | [diff] [blame] | 149 | void addAdditionalRenderPass(); |
Greg Daniel | 77b53f6 | 2016-10-18 11:48:51 -0400 | [diff] [blame] | 150 | |
| 151 | struct InlineUploadInfo { |
Brian Salomon | 943ed79 | 2017-10-30 09:37:55 -0400 | [diff] [blame] | 152 | InlineUploadInfo(GrOpFlushState* state, const GrDeferredTextureUploadFn& upload) |
| 153 | : fFlushState(state), fUpload(upload) {} |
Greg Daniel | 77b53f6 | 2016-10-18 11:48:51 -0400 | [diff] [blame] | 154 | |
Brian Salomon | 742e31d | 2016-12-07 17:06:19 -0500 | [diff] [blame] | 155 | GrOpFlushState* fFlushState; |
Brian Salomon | 943ed79 | 2017-10-30 09:37:55 -0400 | [diff] [blame] | 156 | GrDeferredTextureUploadFn fUpload; |
Greg Daniel | 77b53f6 | 2016-10-18 11:48:51 -0400 | [diff] [blame] | 157 | }; |
| 158 | |
Greg Daniel | 500d58b | 2017-08-24 15:59:33 -0400 | [diff] [blame] | 159 | struct CopyInfo { |
Robert Phillips | b0e93a2 | 2017-08-29 08:26:54 -0400 | [diff] [blame] | 160 | CopyInfo(GrSurface* src, GrSurfaceOrigin srcOrigin, const SkIRect& srcRect, |
Greg Daniel | 55fa647 | 2018-03-16 16:13:10 -0400 | [diff] [blame] | 161 | const SkIPoint& dstPoint, bool shouldDiscardDst) |
| 162 | : fSrc(src) |
| 163 | , fSrcOrigin(srcOrigin) |
| 164 | , fSrcRect(srcRect) |
| 165 | , fDstPoint(dstPoint) |
| 166 | , fShouldDiscardDst(shouldDiscardDst) {} |
Greg Daniel | 500d58b | 2017-08-24 15:59:33 -0400 | [diff] [blame] | 167 | |
Robert Phillips | b0e93a2 | 2017-08-29 08:26:54 -0400 | [diff] [blame] | 168 | GrSurface* fSrc; |
| 169 | GrSurfaceOrigin fSrcOrigin; |
| 170 | SkIRect fSrcRect; |
| 171 | SkIPoint fDstPoint; |
Greg Daniel | 55fa647 | 2018-03-16 16:13:10 -0400 | [diff] [blame] | 172 | bool fShouldDiscardDst; |
Greg Daniel | 500d58b | 2017-08-24 15:59:33 -0400 | [diff] [blame] | 173 | }; |
| 174 | |
Greg Daniel | a3c68df | 2018-03-16 13:46:53 -0400 | [diff] [blame] | 175 | enum class LoadStoreState { |
| 176 | kUnknown, |
| 177 | kStartsWithClear, |
| 178 | kStartsWithDiscard, |
| 179 | kLoadAndStore, |
| 180 | }; |
| 181 | |
Greg Daniel | 36a77ee | 2016-10-18 10:33:25 -0400 | [diff] [blame] | 182 | struct CommandBufferInfo { |
Greg Daniel | 22bc865 | 2017-03-22 15:45:43 -0400 | [diff] [blame] | 183 | const GrVkRenderPass* fRenderPass; |
| 184 | SkTArray<GrVkSecondaryCommandBuffer*> fCommandBuffers; |
| 185 | VkClearValue fColorClearValue; |
| 186 | SkRect fBounds; |
Greg Daniel | a3c68df | 2018-03-16 13:46:53 -0400 | [diff] [blame] | 187 | bool fIsEmpty = true; |
| 188 | LoadStoreState fLoadStoreState = LoadStoreState::kUnknown; |
Greg Daniel | 500d58b | 2017-08-24 15:59:33 -0400 | [diff] [blame] | 189 | // The PreDrawUploads and PreCopies are sent to the GPU before submitting the secondary |
| 190 | // command buffer. |
Greg Daniel | 22bc865 | 2017-03-22 15:45:43 -0400 | [diff] [blame] | 191 | SkTArray<InlineUploadInfo> fPreDrawUploads; |
Greg Daniel | 500d58b | 2017-08-24 15:59:33 -0400 | [diff] [blame] | 192 | SkTArray<CopyInfo> fPreCopies; |
Greg Daniel | ea022cd | 2018-03-16 11:10:03 -0400 | [diff] [blame] | 193 | // Array of images that will be sampled and thus need to be transfered to sampled layout |
| 194 | // before submitting the secondary command buffers. This must happen after we do any predraw |
| 195 | // uploads or copies. |
| 196 | SkTArray<GrVkImage*> fSampledImages; |
Greg Daniel | 22bc865 | 2017-03-22 15:45:43 -0400 | [diff] [blame] | 197 | |
| 198 | GrVkSecondaryCommandBuffer* currentCmdBuf() { |
| 199 | return fCommandBuffers.back(); |
| 200 | } |
Greg Daniel | 36a77ee | 2016-10-18 10:33:25 -0400 | [diff] [blame] | 201 | }; |
| 202 | |
| 203 | SkTArray<CommandBufferInfo> fCommandBufferInfos; |
Greg Daniel | 22bc865 | 2017-03-22 15:45:43 -0400 | [diff] [blame] | 204 | int fCurrentCmdInfo; |
Greg Daniel | 36a77ee | 2016-10-18 10:33:25 -0400 | [diff] [blame] | 205 | |
egdaniel | 066df7c | 2016-06-08 14:02:27 -0700 | [diff] [blame] | 206 | GrVkGpu* fGpu; |
Brian Salomon | c293a29 | 2016-11-30 13:38:32 -0500 | [diff] [blame] | 207 | VkAttachmentLoadOp fVkColorLoadOp; |
| 208 | VkAttachmentStoreOp fVkColorStoreOp; |
| 209 | VkAttachmentLoadOp fVkStencilLoadOp; |
| 210 | VkAttachmentStoreOp fVkStencilStoreOp; |
Brian Osman | 9a9baae | 2018-11-05 15:06:26 -0500 | [diff] [blame] | 211 | SkPMColor4f fClearColor; |
Greg Daniel | 22bc865 | 2017-03-22 15:45:43 -0400 | [diff] [blame] | 212 | GrVkPipelineState* fLastPipelineState; |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 213 | |
Greg Daniel | 500d58b | 2017-08-24 15:59:33 -0400 | [diff] [blame] | 214 | typedef GrGpuRTCommandBuffer INHERITED; |
egdaniel | 066df7c | 2016-06-08 14:02:27 -0700 | [diff] [blame] | 215 | }; |
| 216 | |
| 217 | #endif |