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 | |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 90 | GrGpu* gpu() override; |
| 91 | |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 92 | // Bind vertex and index buffers |
Brian Salomon | 802cb31 | 2018-06-08 18:05:20 -0400 | [diff] [blame] | 93 | void bindGeometry(const GrBuffer* indexBuffer, |
Chris Dalton | 1d61635 | 2017-05-31 12:51:23 -0600 | [diff] [blame] | 94 | const GrBuffer* vertexBuffer, |
| 95 | const GrBuffer* instanceBuffer); |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 96 | |
Brian Salomon | ff168d9 | 2018-06-23 15:17:27 -0400 | [diff] [blame] | 97 | GrVkPipelineState* prepareDrawState(const GrPrimitiveProcessor&, |
| 98 | const GrPipeline&, |
Brian Salomon | 4934890 | 2018-06-26 09:12:38 -0400 | [diff] [blame] | 99 | const GrPipeline::FixedDynamicState*, |
| 100 | const GrPipeline::DynamicStateArrays*, |
| 101 | GrPrimitiveType); |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 102 | |
Brian Salomon | 4934890 | 2018-06-26 09:12:38 -0400 | [diff] [blame] | 103 | void onDraw(const GrPrimitiveProcessor&, |
| 104 | const GrPipeline&, |
| 105 | const GrPipeline::FixedDynamicState*, |
| 106 | const GrPipeline::DynamicStateArrays*, |
| 107 | const GrMesh[], |
Greg Daniel | 36a77ee | 2016-10-18 10:33:25 -0400 | [diff] [blame] | 108 | int meshCount, |
| 109 | const SkRect& bounds) override; |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 110 | |
Chris Dalton | 114a3c0 | 2017-05-26 15:17:19 -0600 | [diff] [blame] | 111 | // GrMesh::SendToGpuImpl methods. These issue the actual Vulkan draw commands. |
| 112 | // 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] | 113 | void sendMeshToGpu(GrPrimitiveType primType, const GrBuffer* vertexBuffer, int vertexCount, |
| 114 | int baseVertex) final { |
| 115 | this->sendInstancedMeshToGpu(primType, vertexBuffer, vertexCount, baseVertex, nullptr, 1, |
| 116 | 0); |
Chris Dalton | 1d61635 | 2017-05-31 12:51:23 -0600 | [diff] [blame] | 117 | } |
Chris Dalton | 114a3c0 | 2017-05-26 15:17:19 -0600 | [diff] [blame] | 118 | |
Brian Salomon | 802cb31 | 2018-06-08 18:05:20 -0400 | [diff] [blame] | 119 | void sendIndexedMeshToGpu(GrPrimitiveType primType, const GrBuffer* indexBuffer, int indexCount, |
| 120 | int baseIndex, uint16_t /*minIndexValue*/, uint16_t /*maxIndexValue*/, |
| 121 | const GrBuffer* vertexBuffer, int baseVertex, |
| 122 | GrPrimitiveRestart restart) final { |
| 123 | SkASSERT(restart == GrPrimitiveRestart::kNo); |
| 124 | this->sendIndexedInstancedMeshToGpu(primType, indexBuffer, indexCount, baseIndex, |
| 125 | vertexBuffer, baseVertex, nullptr, 1, 0, |
| 126 | GrPrimitiveRestart::kNo); |
Chris Dalton | 1d61635 | 2017-05-31 12:51:23 -0600 | [diff] [blame] | 127 | } |
| 128 | |
Brian Salomon | 802cb31 | 2018-06-08 18:05:20 -0400 | [diff] [blame] | 129 | void sendInstancedMeshToGpu(GrPrimitiveType, const GrBuffer* vertexBuffer, int vertexCount, |
| 130 | int baseVertex, const GrBuffer* instanceBuffer, int instanceCount, |
Chris Dalton | 1d61635 | 2017-05-31 12:51:23 -0600 | [diff] [blame] | 131 | int baseInstance) final; |
| 132 | |
Brian Salomon | 802cb31 | 2018-06-08 18:05:20 -0400 | [diff] [blame] | 133 | void sendIndexedInstancedMeshToGpu(GrPrimitiveType, const GrBuffer* indexBuffer, int indexCount, |
| 134 | int baseIndex, const GrBuffer* vertexBuffer, int baseVertex, |
Chris Dalton | 1d61635 | 2017-05-31 12:51:23 -0600 | [diff] [blame] | 135 | const GrBuffer* instanceBuffer, int instanceCount, |
Brian Salomon | 802cb31 | 2018-06-08 18:05:20 -0400 | [diff] [blame] | 136 | int baseInstance, GrPrimitiveRestart) final; |
Chris Dalton | 114a3c0 | 2017-05-26 15:17:19 -0600 | [diff] [blame] | 137 | |
Brian Osman | 9a9baae | 2018-11-05 15:06:26 -0500 | [diff] [blame] | 138 | void onClear(const GrFixedClip&, const SkPMColor4f& color) override; |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 139 | |
Robert Phillips | 19e51dc | 2017-08-09 09:30:51 -0400 | [diff] [blame] | 140 | void onClearStencilClip(const GrFixedClip&, bool insideStencilMask) override; |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 141 | |
Greg Daniel | 77b53f6 | 2016-10-18 11:48:51 -0400 | [diff] [blame] | 142 | void addAdditionalCommandBuffer(); |
Greg Daniel | 22bc865 | 2017-03-22 15:45:43 -0400 | [diff] [blame] | 143 | void addAdditionalRenderPass(); |
Greg Daniel | 77b53f6 | 2016-10-18 11:48:51 -0400 | [diff] [blame] | 144 | |
| 145 | struct InlineUploadInfo { |
Brian Salomon | 943ed79 | 2017-10-30 09:37:55 -0400 | [diff] [blame] | 146 | InlineUploadInfo(GrOpFlushState* state, const GrDeferredTextureUploadFn& upload) |
| 147 | : fFlushState(state), fUpload(upload) {} |
Greg Daniel | 77b53f6 | 2016-10-18 11:48:51 -0400 | [diff] [blame] | 148 | |
Brian Salomon | 742e31d | 2016-12-07 17:06:19 -0500 | [diff] [blame] | 149 | GrOpFlushState* fFlushState; |
Brian Salomon | 943ed79 | 2017-10-30 09:37:55 -0400 | [diff] [blame] | 150 | GrDeferredTextureUploadFn fUpload; |
Greg Daniel | 77b53f6 | 2016-10-18 11:48:51 -0400 | [diff] [blame] | 151 | }; |
| 152 | |
Greg Daniel | 500d58b | 2017-08-24 15:59:33 -0400 | [diff] [blame] | 153 | struct CopyInfo { |
Robert Phillips | b0e93a2 | 2017-08-29 08:26:54 -0400 | [diff] [blame] | 154 | CopyInfo(GrSurface* src, GrSurfaceOrigin srcOrigin, const SkIRect& srcRect, |
Greg Daniel | 55fa647 | 2018-03-16 16:13:10 -0400 | [diff] [blame] | 155 | const SkIPoint& dstPoint, bool shouldDiscardDst) |
| 156 | : fSrc(src) |
| 157 | , fSrcOrigin(srcOrigin) |
| 158 | , fSrcRect(srcRect) |
| 159 | , fDstPoint(dstPoint) |
| 160 | , fShouldDiscardDst(shouldDiscardDst) {} |
Greg Daniel | 500d58b | 2017-08-24 15:59:33 -0400 | [diff] [blame] | 161 | |
Robert Phillips | b0e93a2 | 2017-08-29 08:26:54 -0400 | [diff] [blame] | 162 | GrSurface* fSrc; |
| 163 | GrSurfaceOrigin fSrcOrigin; |
| 164 | SkIRect fSrcRect; |
| 165 | SkIPoint fDstPoint; |
Greg Daniel | 55fa647 | 2018-03-16 16:13:10 -0400 | [diff] [blame] | 166 | bool fShouldDiscardDst; |
Greg Daniel | 500d58b | 2017-08-24 15:59:33 -0400 | [diff] [blame] | 167 | }; |
| 168 | |
Greg Daniel | a3c68df | 2018-03-16 13:46:53 -0400 | [diff] [blame] | 169 | enum class LoadStoreState { |
| 170 | kUnknown, |
| 171 | kStartsWithClear, |
| 172 | kStartsWithDiscard, |
| 173 | kLoadAndStore, |
| 174 | }; |
| 175 | |
Greg Daniel | 36a77ee | 2016-10-18 10:33:25 -0400 | [diff] [blame] | 176 | struct CommandBufferInfo { |
Greg Daniel | 22bc865 | 2017-03-22 15:45:43 -0400 | [diff] [blame] | 177 | const GrVkRenderPass* fRenderPass; |
| 178 | SkTArray<GrVkSecondaryCommandBuffer*> fCommandBuffers; |
| 179 | VkClearValue fColorClearValue; |
| 180 | SkRect fBounds; |
Greg Daniel | a3c68df | 2018-03-16 13:46:53 -0400 | [diff] [blame] | 181 | bool fIsEmpty = true; |
| 182 | LoadStoreState fLoadStoreState = LoadStoreState::kUnknown; |
Greg Daniel | 500d58b | 2017-08-24 15:59:33 -0400 | [diff] [blame] | 183 | // The PreDrawUploads and PreCopies are sent to the GPU before submitting the secondary |
| 184 | // command buffer. |
Greg Daniel | 22bc865 | 2017-03-22 15:45:43 -0400 | [diff] [blame] | 185 | SkTArray<InlineUploadInfo> fPreDrawUploads; |
Greg Daniel | 500d58b | 2017-08-24 15:59:33 -0400 | [diff] [blame] | 186 | SkTArray<CopyInfo> fPreCopies; |
Greg Daniel | ea022cd | 2018-03-16 11:10:03 -0400 | [diff] [blame] | 187 | // Array of images that will be sampled and thus need to be transfered to sampled layout |
| 188 | // before submitting the secondary command buffers. This must happen after we do any predraw |
| 189 | // uploads or copies. |
| 190 | SkTArray<GrVkImage*> fSampledImages; |
Greg Daniel | 22bc865 | 2017-03-22 15:45:43 -0400 | [diff] [blame] | 191 | |
| 192 | GrVkSecondaryCommandBuffer* currentCmdBuf() { |
| 193 | return fCommandBuffers.back(); |
| 194 | } |
Greg Daniel | 36a77ee | 2016-10-18 10:33:25 -0400 | [diff] [blame] | 195 | }; |
| 196 | |
| 197 | SkTArray<CommandBufferInfo> fCommandBufferInfos; |
Greg Daniel | 22bc865 | 2017-03-22 15:45:43 -0400 | [diff] [blame] | 198 | int fCurrentCmdInfo; |
Greg Daniel | 36a77ee | 2016-10-18 10:33:25 -0400 | [diff] [blame] | 199 | |
egdaniel | 066df7c | 2016-06-08 14:02:27 -0700 | [diff] [blame] | 200 | GrVkGpu* fGpu; |
Brian Salomon | c293a29 | 2016-11-30 13:38:32 -0500 | [diff] [blame] | 201 | VkAttachmentLoadOp fVkColorLoadOp; |
| 202 | VkAttachmentStoreOp fVkColorStoreOp; |
| 203 | VkAttachmentLoadOp fVkStencilLoadOp; |
| 204 | VkAttachmentStoreOp fVkStencilStoreOp; |
Brian Osman | 9a9baae | 2018-11-05 15:06:26 -0500 | [diff] [blame] | 205 | SkPMColor4f fClearColor; |
Greg Daniel | 22bc865 | 2017-03-22 15:45:43 -0400 | [diff] [blame] | 206 | GrVkPipelineState* fLastPipelineState; |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 207 | |
Greg Daniel | 500d58b | 2017-08-24 15:59:33 -0400 | [diff] [blame] | 208 | typedef GrGpuRTCommandBuffer INHERITED; |
egdaniel | 066df7c | 2016-06-08 14:02:27 -0700 | [diff] [blame] | 209 | }; |
| 210 | |
| 211 | #endif |