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