Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 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 GrVkCommandBuffer_DEFINED |
| 9 | #define GrVkCommandBuffer_DEFINED |
| 10 | |
| 11 | #include "GrVkGpu.h" |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 12 | #include "GrVkResource.h" |
Greg Daniel | 6be3523 | 2017-03-01 17:01:09 -0500 | [diff] [blame] | 13 | #include "GrVkSemaphore.h" |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 14 | #include "GrVkUtil.h" |
Greg Daniel | 487132b | 2018-12-20 14:09:36 -0500 | [diff] [blame] | 15 | #include "vk/GrVkTypes.h" |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 16 | |
Greg Daniel | 6ecc911 | 2017-06-16 16:17:03 +0000 | [diff] [blame] | 17 | class GrVkBuffer; |
egdaniel | 9a6cf80 | 2016-06-08 08:22:05 -0700 | [diff] [blame] | 18 | class GrVkFramebuffer; |
Greg Daniel | 6ecc911 | 2017-06-16 16:17:03 +0000 | [diff] [blame] | 19 | class GrVkIndexBuffer; |
| 20 | class GrVkImage; |
egdaniel | 470d77a | 2016-03-18 12:50:27 -0700 | [diff] [blame] | 21 | class GrVkPipeline; |
Greg Daniel | 6ecc911 | 2017-06-16 16:17:03 +0000 | [diff] [blame] | 22 | class GrVkPipelineState; |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 23 | class GrVkRenderPass; |
| 24 | class GrVkRenderTarget; |
| 25 | class GrVkTransferBuffer; |
Greg Daniel | 6ecc911 | 2017-06-16 16:17:03 +0000 | [diff] [blame] | 26 | class GrVkVertexBuffer; |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 27 | |
| 28 | class GrVkCommandBuffer : public GrVkResource { |
| 29 | public: |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 30 | void invalidateState(); |
| 31 | |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 32 | //////////////////////////////////////////////////////////////////////////// |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 33 | // CommandBuffer commands |
| 34 | //////////////////////////////////////////////////////////////////////////// |
| 35 | enum BarrierType { |
| 36 | kMemory_BarrierType, |
| 37 | kBufferMemory_BarrierType, |
| 38 | kImageMemory_BarrierType |
| 39 | }; |
| 40 | |
| 41 | void pipelineBarrier(const GrVkGpu* gpu, |
Greg Daniel | 59dc148 | 2019-02-22 10:46:38 -0500 | [diff] [blame] | 42 | const GrVkResource* resource, |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 43 | VkPipelineStageFlags srcStageMask, |
| 44 | VkPipelineStageFlags dstStageMask, |
| 45 | bool byRegion, |
| 46 | BarrierType barrierType, |
Greg Daniel | 59dc148 | 2019-02-22 10:46:38 -0500 | [diff] [blame] | 47 | void* barrier); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 48 | |
Greg Daniel | 6ecc911 | 2017-06-16 16:17:03 +0000 | [diff] [blame] | 49 | void bindInputBuffer(GrVkGpu* gpu, uint32_t binding, const GrVkVertexBuffer* vbuffer); |
Chris Dalton | 1d61635 | 2017-05-31 12:51:23 -0600 | [diff] [blame] | 50 | |
Greg Daniel | 6ecc911 | 2017-06-16 16:17:03 +0000 | [diff] [blame] | 51 | void bindIndexBuffer(GrVkGpu* gpu, const GrVkIndexBuffer* ibuffer); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 52 | |
egdaniel | 58a8d92 | 2016-04-21 08:03:10 -0700 | [diff] [blame] | 53 | void bindPipeline(const GrVkGpu* gpu, const GrVkPipeline* pipeline); |
| 54 | |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 55 | void bindDescriptorSets(const GrVkGpu* gpu, |
egdaniel | 22281c1 | 2016-03-23 13:49:40 -0700 | [diff] [blame] | 56 | GrVkPipelineState*, |
Greg Daniel | 7d918fd | 2018-06-19 15:22:01 -0400 | [diff] [blame] | 57 | GrVkPipelineLayout* layout, |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 58 | uint32_t firstSet, |
| 59 | uint32_t setCount, |
| 60 | const VkDescriptorSet* descriptorSets, |
| 61 | uint32_t dynamicOffsetCount, |
| 62 | const uint32_t* dynamicOffsets); |
| 63 | |
egdaniel | bc9b296 | 2016-09-27 08:00:53 -0700 | [diff] [blame] | 64 | void bindDescriptorSets(const GrVkGpu* gpu, |
| 65 | const SkTArray<const GrVkRecycledResource*>&, |
| 66 | const SkTArray<const GrVkResource*>&, |
Greg Daniel | 7d918fd | 2018-06-19 15:22:01 -0400 | [diff] [blame] | 67 | GrVkPipelineLayout* layout, |
egdaniel | bc9b296 | 2016-09-27 08:00:53 -0700 | [diff] [blame] | 68 | uint32_t firstSet, |
| 69 | uint32_t setCount, |
| 70 | const VkDescriptorSet* descriptorSets, |
| 71 | uint32_t dynamicOffsetCount, |
| 72 | const uint32_t* dynamicOffsets); |
| 73 | |
Ethan Nicholas | 8e265a7 | 2018-12-12 16:22:40 -0500 | [diff] [blame] | 74 | GrVkCommandPool* commandPool() { return fCmdPool; } |
| 75 | |
egdaniel | 470d77a | 2016-03-18 12:50:27 -0700 | [diff] [blame] | 76 | void setViewport(const GrVkGpu* gpu, |
| 77 | uint32_t firstViewport, |
| 78 | uint32_t viewportCount, |
| 79 | const VkViewport* viewports); |
| 80 | |
| 81 | void setScissor(const GrVkGpu* gpu, |
| 82 | uint32_t firstScissor, |
| 83 | uint32_t scissorCount, |
| 84 | const VkRect2D* scissors); |
| 85 | |
| 86 | void setBlendConstants(const GrVkGpu* gpu, const float blendConstants[4]); |
| 87 | |
egdaniel | 9a6cf80 | 2016-06-08 08:22:05 -0700 | [diff] [blame] | 88 | // Commands that only work inside of a render pass |
| 89 | void clearAttachments(const GrVkGpu* gpu, |
| 90 | int numAttachments, |
| 91 | const VkClearAttachment* attachments, |
| 92 | int numRects, |
| 93 | const VkClearRect* clearRects) const; |
| 94 | |
| 95 | void drawIndexed(const GrVkGpu* gpu, |
| 96 | uint32_t indexCount, |
| 97 | uint32_t instanceCount, |
| 98 | uint32_t firstIndex, |
| 99 | int32_t vertexOffset, |
| 100 | uint32_t firstInstance) const; |
| 101 | |
| 102 | void draw(const GrVkGpu* gpu, |
| 103 | uint32_t vertexCount, |
| 104 | uint32_t instanceCount, |
| 105 | uint32_t firstVertex, |
| 106 | uint32_t firstInstance) const; |
| 107 | |
Greg Daniel | 7d918fd | 2018-06-19 15:22:01 -0400 | [diff] [blame] | 108 | // Add ref-counted resource that will be tracked and released when this command buffer finishes |
| 109 | // execution |
egdaniel | 9a6cf80 | 2016-06-08 08:22:05 -0700 | [diff] [blame] | 110 | void addResource(const GrVkResource* resource) { |
| 111 | resource->ref(); |
Brian Salomon | 614c1a8 | 2018-12-19 15:42:06 -0500 | [diff] [blame] | 112 | resource->notifyAddedToCommandBuffer(); |
egdaniel | 594739c | 2016-09-20 12:39:25 -0700 | [diff] [blame] | 113 | fTrackedResources.append(1, &resource); |
egdaniel | 9a6cf80 | 2016-06-08 08:22:05 -0700 | [diff] [blame] | 114 | } |
| 115 | |
egdaniel | c1be9bc | 2016-07-20 08:33:00 -0700 | [diff] [blame] | 116 | // Add ref-counted resource that will be tracked and released when this command buffer finishes |
| 117 | // execution. When it is released, it will signal that the resource can be recycled for reuse. |
| 118 | void addRecycledResource(const GrVkRecycledResource* resource) { |
| 119 | resource->ref(); |
Brian Salomon | 614c1a8 | 2018-12-19 15:42:06 -0500 | [diff] [blame] | 120 | resource->notifyAddedToCommandBuffer(); |
egdaniel | 594739c | 2016-09-20 12:39:25 -0700 | [diff] [blame] | 121 | fTrackedRecycledResources.append(1, &resource); |
egdaniel | c1be9bc | 2016-07-20 08:33:00 -0700 | [diff] [blame] | 122 | } |
| 123 | |
Greg Daniel | 7d918fd | 2018-06-19 15:22:01 -0400 | [diff] [blame] | 124 | // Add ref-counted resource that will be tracked and released when this command buffer finishes |
| 125 | // recording. |
| 126 | void addRecordingResource(const GrVkResource* resource) { |
| 127 | resource->ref(); |
Brian Salomon | 614c1a8 | 2018-12-19 15:42:06 -0500 | [diff] [blame] | 128 | resource->notifyAddedToCommandBuffer(); |
Greg Daniel | 7d918fd | 2018-06-19 15:22:01 -0400 | [diff] [blame] | 129 | fTrackedRecordingResources.append(1, &resource); |
| 130 | } |
| 131 | |
Ethan Nicholas | 8e265a7 | 2018-12-12 16:22:40 -0500 | [diff] [blame] | 132 | void releaseResources(GrVkGpu* gpu); |
jvanverth | 7ec9241 | 2016-07-06 09:24:57 -0700 | [diff] [blame] | 133 | |
Robert Phillips | ce0a2bf | 2019-04-02 13:37:34 -0400 | [diff] [blame] | 134 | bool hasWork() const { return fHasWork; } |
| 135 | |
egdaniel | 9a6cf80 | 2016-06-08 08:22:05 -0700 | [diff] [blame] | 136 | protected: |
Ethan Nicholas | 8e265a7 | 2018-12-12 16:22:40 -0500 | [diff] [blame] | 137 | GrVkCommandBuffer(VkCommandBuffer cmdBuffer, GrVkCommandPool* cmdPool, |
Greg Daniel | 070cbaf | 2019-01-03 17:35:54 -0500 | [diff] [blame] | 138 | const GrVkRenderPass* rp = nullptr) |
egdaniel | 594739c | 2016-09-20 12:39:25 -0700 | [diff] [blame] | 139 | : fIsActive(false) |
egdaniel | 9a6cf80 | 2016-06-08 08:22:05 -0700 | [diff] [blame] | 140 | , fActiveRenderPass(rp) |
| 141 | , fCmdBuffer(cmdBuffer) |
Ethan Nicholas | 8e265a7 | 2018-12-12 16:22:40 -0500 | [diff] [blame] | 142 | , fCmdPool(cmdPool) |
egdaniel | 594739c | 2016-09-20 12:39:25 -0700 | [diff] [blame] | 143 | , fNumResets(0) { |
| 144 | fTrackedResources.setReserve(kInitialTrackedResourcesCount); |
| 145 | fTrackedRecycledResources.setReserve(kInitialTrackedResourcesCount); |
Greg Daniel | 7d918fd | 2018-06-19 15:22:01 -0400 | [diff] [blame] | 146 | fTrackedRecordingResources.setReserve(kInitialTrackedResourcesCount); |
egdaniel | 9a6cf80 | 2016-06-08 08:22:05 -0700 | [diff] [blame] | 147 | this->invalidateState(); |
| 148 | } |
egdaniel | 594739c | 2016-09-20 12:39:25 -0700 | [diff] [blame] | 149 | |
Greg Daniel | 070cbaf | 2019-01-03 17:35:54 -0500 | [diff] [blame] | 150 | bool isWrapped() const { |
| 151 | return fCmdPool == nullptr; |
| 152 | } |
| 153 | |
Robert Phillips | ce0a2bf | 2019-04-02 13:37:34 -0400 | [diff] [blame] | 154 | void addedWork() const { fHasWork = true; } |
| 155 | |
egdaniel | 594739c | 2016-09-20 12:39:25 -0700 | [diff] [blame] | 156 | SkTDArray<const GrVkResource*> fTrackedResources; |
| 157 | SkTDArray<const GrVkRecycledResource*> fTrackedRecycledResources; |
Greg Daniel | 7d918fd | 2018-06-19 15:22:01 -0400 | [diff] [blame] | 158 | SkTDArray<const GrVkResource*> fTrackedRecordingResources; |
egdaniel | 9a6cf80 | 2016-06-08 08:22:05 -0700 | [diff] [blame] | 159 | |
| 160 | // Tracks whether we are in the middle of a command buffer begin/end calls and thus can add |
| 161 | // new commands to the buffer; |
Robert Phillips | 04d2ce2 | 2019-04-03 13:20:43 -0400 | [diff] [blame^] | 162 | bool fIsActive; |
| 163 | mutable bool fHasWork = false; |
egdaniel | 9a6cf80 | 2016-06-08 08:22:05 -0700 | [diff] [blame] | 164 | |
| 165 | // Stores a pointer to the current active render pass (i.e. begin has been called but not |
| 166 | // end). A nullptr means there is no active render pass. The GrVKCommandBuffer does not own |
| 167 | // the render pass. |
| 168 | const GrVkRenderPass* fActiveRenderPass; |
| 169 | |
| 170 | VkCommandBuffer fCmdBuffer; |
egdaniel | 9a6cf80 | 2016-06-08 08:22:05 -0700 | [diff] [blame] | 171 | |
Ethan Nicholas | 8e265a7 | 2018-12-12 16:22:40 -0500 | [diff] [blame] | 172 | // Raw pointer, not refcounted. The command pool controls the command buffer's lifespan, so |
| 173 | // it's guaranteed to outlive us. |
| 174 | GrVkCommandPool* fCmdPool; |
| 175 | |
egdaniel | 9a6cf80 | 2016-06-08 08:22:05 -0700 | [diff] [blame] | 176 | private: |
| 177 | static const int kInitialTrackedResourcesCount = 32; |
| 178 | |
Ethan Nicholas | 8e265a7 | 2018-12-12 16:22:40 -0500 | [diff] [blame] | 179 | void freeGPUData(GrVkGpu* gpu) const final override; |
| 180 | virtual void onFreeGPUData(GrVkGpu* gpu) const = 0; |
| 181 | void abandonGPUData() const final override; |
| 182 | virtual void onAbandonGPUData() const = 0; |
egdaniel | 9a6cf80 | 2016-06-08 08:22:05 -0700 | [diff] [blame] | 183 | |
Ethan Nicholas | 8e265a7 | 2018-12-12 16:22:40 -0500 | [diff] [blame] | 184 | virtual void onReleaseResources(GrVkGpu* gpu) {} |
jvanverth | 7ec9241 | 2016-07-06 09:24:57 -0700 | [diff] [blame] | 185 | |
Greg Daniel | 6ecc911 | 2017-06-16 16:17:03 +0000 | [diff] [blame] | 186 | static constexpr uint32_t kMaxInputBuffers = 2; |
| 187 | |
Chris Dalton | 1d61635 | 2017-05-31 12:51:23 -0600 | [diff] [blame] | 188 | VkBuffer fBoundInputBuffers[kMaxInputBuffers]; |
| 189 | VkBuffer fBoundIndexBuffer; |
egdaniel | 9a6cf80 | 2016-06-08 08:22:05 -0700 | [diff] [blame] | 190 | |
egdaniel | 594739c | 2016-09-20 12:39:25 -0700 | [diff] [blame] | 191 | // When resetting the command buffer, we remove the tracked resources from their arrays, and |
| 192 | // we prefer to not free all the memory every time so usually we just rewind. However, to avoid |
| 193 | // all arrays growing to the max size, after so many resets we'll do a full reset of the tracked |
| 194 | // resource arrays. |
| 195 | static const int kNumRewindResetsBeforeFullReset = 8; |
| 196 | int fNumResets; |
| 197 | |
egdaniel | 9a6cf80 | 2016-06-08 08:22:05 -0700 | [diff] [blame] | 198 | // Cached values used for dynamic state updates |
| 199 | VkViewport fCachedViewport; |
| 200 | VkRect2D fCachedScissor; |
| 201 | float fCachedBlendConstant[4]; |
Ethan Nicholas | 8e265a7 | 2018-12-12 16:22:40 -0500 | [diff] [blame] | 202 | |
| 203 | #ifdef SK_DEBUG |
| 204 | mutable bool fResourcesReleased = false; |
| 205 | #endif |
egdaniel | 9a6cf80 | 2016-06-08 08:22:05 -0700 | [diff] [blame] | 206 | }; |
| 207 | |
| 208 | class GrVkSecondaryCommandBuffer; |
| 209 | |
| 210 | class GrVkPrimaryCommandBuffer : public GrVkCommandBuffer { |
| 211 | public: |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 212 | ~GrVkPrimaryCommandBuffer() override; |
| 213 | |
Ethan Nicholas | 8e265a7 | 2018-12-12 16:22:40 -0500 | [diff] [blame] | 214 | static GrVkPrimaryCommandBuffer* Create(const GrVkGpu* gpu, GrVkCommandPool* cmdPool); |
egdaniel | 9a6cf80 | 2016-06-08 08:22:05 -0700 | [diff] [blame] | 215 | |
| 216 | void begin(const GrVkGpu* gpu); |
Ethan Nicholas | 8e265a7 | 2018-12-12 16:22:40 -0500 | [diff] [blame] | 217 | void end(GrVkGpu* gpu); |
egdaniel | 9a6cf80 | 2016-06-08 08:22:05 -0700 | [diff] [blame] | 218 | |
| 219 | // Begins render pass on this command buffer. The framebuffer from GrVkRenderTarget will be used |
| 220 | // in the render pass. |
| 221 | void beginRenderPass(const GrVkGpu* gpu, |
| 222 | const GrVkRenderPass* renderPass, |
Robert Phillips | 9521447 | 2017-08-08 18:00:03 -0400 | [diff] [blame] | 223 | const VkClearValue clearValues[], |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 224 | const GrVkRenderTarget& target, |
| 225 | const SkIRect& bounds, |
| 226 | bool forSecondaryCB); |
egdaniel | 9a6cf80 | 2016-06-08 08:22:05 -0700 | [diff] [blame] | 227 | void endRenderPass(const GrVkGpu* gpu); |
| 228 | |
| 229 | // Submits the SecondaryCommandBuffer into this command buffer. It is required that we are |
| 230 | // currently inside a render pass that is compatible with the one used to create the |
| 231 | // SecondaryCommandBuffer. |
| 232 | void executeCommands(const GrVkGpu* gpu, |
jvanverth | 7ec9241 | 2016-07-06 09:24:57 -0700 | [diff] [blame] | 233 | GrVkSecondaryCommandBuffer* secondaryBuffer); |
egdaniel | 9a6cf80 | 2016-06-08 08:22:05 -0700 | [diff] [blame] | 234 | |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 235 | // Commands that only work outside of a render pass |
| 236 | void clearColorImage(const GrVkGpu* gpu, |
| 237 | GrVkImage* image, |
| 238 | const VkClearColorValue* color, |
| 239 | uint32_t subRangeCount, |
| 240 | const VkImageSubresourceRange* subRanges); |
| 241 | |
egdaniel | 3d5d9ac | 2016-03-01 12:56:15 -0800 | [diff] [blame] | 242 | void clearDepthStencilImage(const GrVkGpu* gpu, |
| 243 | GrVkImage* image, |
| 244 | const VkClearDepthStencilValue* color, |
| 245 | uint32_t subRangeCount, |
| 246 | const VkImageSubresourceRange* subRanges); |
| 247 | |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 248 | void copyImage(const GrVkGpu* gpu, |
| 249 | GrVkImage* srcImage, |
| 250 | VkImageLayout srcLayout, |
| 251 | GrVkImage* dstImage, |
| 252 | VkImageLayout dstLayout, |
| 253 | uint32_t copyRegionCount, |
| 254 | const VkImageCopy* copyRegions); |
| 255 | |
egdaniel | 17b8925 | 2016-04-05 07:23:38 -0700 | [diff] [blame] | 256 | void blitImage(const GrVkGpu* gpu, |
egdaniel | b2df0c2 | 2016-05-13 11:30:37 -0700 | [diff] [blame] | 257 | const GrVkResource* srcResource, |
| 258 | VkImage srcImage, |
egdaniel | 17b8925 | 2016-04-05 07:23:38 -0700 | [diff] [blame] | 259 | VkImageLayout srcLayout, |
egdaniel | b2df0c2 | 2016-05-13 11:30:37 -0700 | [diff] [blame] | 260 | const GrVkResource* dstResource, |
| 261 | VkImage dstImage, |
egdaniel | 17b8925 | 2016-04-05 07:23:38 -0700 | [diff] [blame] | 262 | VkImageLayout dstLayout, |
| 263 | uint32_t blitRegionCount, |
| 264 | const VkImageBlit* blitRegions, |
| 265 | VkFilter filter); |
| 266 | |
egdaniel | b2df0c2 | 2016-05-13 11:30:37 -0700 | [diff] [blame] | 267 | void blitImage(const GrVkGpu* gpu, |
| 268 | const GrVkImage& srcImage, |
| 269 | const GrVkImage& dstImage, |
| 270 | uint32_t blitRegionCount, |
| 271 | const VkImageBlit* blitRegions, |
Greg Daniel | 6ecc911 | 2017-06-16 16:17:03 +0000 | [diff] [blame] | 272 | VkFilter filter); |
egdaniel | b2df0c2 | 2016-05-13 11:30:37 -0700 | [diff] [blame] | 273 | |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 274 | void copyImageToBuffer(const GrVkGpu* gpu, |
| 275 | GrVkImage* srcImage, |
| 276 | VkImageLayout srcLayout, |
| 277 | GrVkTransferBuffer* dstBuffer, |
| 278 | uint32_t copyRegionCount, |
| 279 | const VkBufferImageCopy* copyRegions); |
| 280 | |
| 281 | void copyBufferToImage(const GrVkGpu* gpu, |
| 282 | GrVkTransferBuffer* srcBuffer, |
| 283 | GrVkImage* dstImage, |
| 284 | VkImageLayout dstLayout, |
| 285 | uint32_t copyRegionCount, |
| 286 | const VkBufferImageCopy* copyRegions); |
| 287 | |
Greg Daniel | 6888c0d | 2017-08-25 11:55:50 -0400 | [diff] [blame] | 288 | void copyBuffer(GrVkGpu* gpu, |
| 289 | GrVkBuffer* srcBuffer, |
| 290 | GrVkBuffer* dstBuffer, |
| 291 | uint32_t regionCount, |
| 292 | const VkBufferCopy* regions); |
| 293 | |
jvanverth | a584de9 | 2016-06-30 09:10:52 -0700 | [diff] [blame] | 294 | void updateBuffer(GrVkGpu* gpu, |
| 295 | GrVkBuffer* dstBuffer, |
| 296 | VkDeviceSize dstOffset, |
| 297 | VkDeviceSize dataSize, |
| 298 | const void* data); |
| 299 | |
egdaniel | 52ad251 | 2016-08-04 12:50:01 -0700 | [diff] [blame] | 300 | void resolveImage(GrVkGpu* gpu, |
| 301 | const GrVkImage& srcImage, |
| 302 | const GrVkImage& dstImage, |
| 303 | uint32_t regionCount, |
| 304 | const VkImageResolve* regions); |
| 305 | |
Greg Daniel | 6be3523 | 2017-03-01 17:01:09 -0500 | [diff] [blame] | 306 | void submitToQueue(const GrVkGpu* gpu, VkQueue queue, GrVkGpu::SyncQueue sync, |
Greg Daniel | 48661b8 | 2018-01-22 16:11:35 -0500 | [diff] [blame] | 307 | SkTArray<GrVkSemaphore::Resource*>& signalSemaphores, |
| 308 | SkTArray<GrVkSemaphore::Resource*>& waitSemaphores); |
egdaniel | 9a6cf80 | 2016-06-08 08:22:05 -0700 | [diff] [blame] | 309 | bool finished(const GrVkGpu* gpu) const; |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 310 | |
Ethan Nicholas | 8e265a7 | 2018-12-12 16:22:40 -0500 | [diff] [blame] | 311 | void recycleSecondaryCommandBuffers(); |
| 312 | |
jvanverth | 7ec9241 | 2016-07-06 09:24:57 -0700 | [diff] [blame] | 313 | #ifdef SK_TRACE_VK_RESOURCES |
| 314 | void dumpInfo() const override { |
| 315 | SkDebugf("GrVkPrimaryCommandBuffer: %d (%d refs)\n", fCmdBuffer, this->getRefCnt()); |
| 316 | } |
| 317 | #endif |
| 318 | |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 319 | private: |
Ethan Nicholas | 8e265a7 | 2018-12-12 16:22:40 -0500 | [diff] [blame] | 320 | explicit GrVkPrimaryCommandBuffer(VkCommandBuffer cmdBuffer, GrVkCommandPool* cmdPool) |
| 321 | : INHERITED(cmdBuffer, cmdPool) |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 322 | , fSubmitFence(VK_NULL_HANDLE) {} |
| 323 | |
Ethan Nicholas | 8e265a7 | 2018-12-12 16:22:40 -0500 | [diff] [blame] | 324 | void onFreeGPUData(GrVkGpu* gpu) const override; |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 325 | |
Ethan Nicholas | 8e265a7 | 2018-12-12 16:22:40 -0500 | [diff] [blame] | 326 | void onAbandonGPUData() const override; |
| 327 | |
| 328 | void onReleaseResources(GrVkGpu* gpu) override; |
jvanverth | 7ec9241 | 2016-07-06 09:24:57 -0700 | [diff] [blame] | 329 | |
| 330 | SkTArray<GrVkSecondaryCommandBuffer*, true> fSecondaryCommandBuffers; |
| 331 | VkFence fSubmitFence; |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 332 | |
egdaniel | 9a6cf80 | 2016-06-08 08:22:05 -0700 | [diff] [blame] | 333 | typedef GrVkCommandBuffer INHERITED; |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 334 | }; |
| 335 | |
egdaniel | 9a6cf80 | 2016-06-08 08:22:05 -0700 | [diff] [blame] | 336 | class GrVkSecondaryCommandBuffer : public GrVkCommandBuffer { |
| 337 | public: |
Ethan Nicholas | 8e265a7 | 2018-12-12 16:22:40 -0500 | [diff] [blame] | 338 | static GrVkSecondaryCommandBuffer* Create(const GrVkGpu* gpu, GrVkCommandPool* cmdPool); |
Greg Daniel | 070cbaf | 2019-01-03 17:35:54 -0500 | [diff] [blame] | 339 | // Used for wrapping an external secondary command buffer. |
| 340 | static GrVkSecondaryCommandBuffer* Create(VkCommandBuffer externalSecondaryCB); |
egdaniel | 9a6cf80 | 2016-06-08 08:22:05 -0700 | [diff] [blame] | 341 | |
jvanverth | 7ec9241 | 2016-07-06 09:24:57 -0700 | [diff] [blame] | 342 | void begin(const GrVkGpu* gpu, const GrVkFramebuffer* framebuffer, |
| 343 | const GrVkRenderPass* compatibleRenderPass); |
Ethan Nicholas | 8e265a7 | 2018-12-12 16:22:40 -0500 | [diff] [blame] | 344 | void end(GrVkGpu* gpu); |
egdaniel | 9a6cf80 | 2016-06-08 08:22:05 -0700 | [diff] [blame] | 345 | |
Greg Daniel | 64cc9aa | 2018-10-19 13:54:56 -0400 | [diff] [blame] | 346 | VkCommandBuffer vkCommandBuffer() { return fCmdBuffer; } |
| 347 | |
jvanverth | 7ec9241 | 2016-07-06 09:24:57 -0700 | [diff] [blame] | 348 | #ifdef SK_TRACE_VK_RESOURCES |
| 349 | void dumpInfo() const override { |
| 350 | SkDebugf("GrVkSecondaryCommandBuffer: %d (%d refs)\n", fCmdBuffer, this->getRefCnt()); |
| 351 | } |
| 352 | #endif |
| 353 | |
egdaniel | 9a6cf80 | 2016-06-08 08:22:05 -0700 | [diff] [blame] | 354 | private: |
Ethan Nicholas | 8e265a7 | 2018-12-12 16:22:40 -0500 | [diff] [blame] | 355 | explicit GrVkSecondaryCommandBuffer(VkCommandBuffer cmdBuffer, GrVkCommandPool* cmdPool) |
| 356 | : INHERITED(cmdBuffer, cmdPool) {} |
egdaniel | 9a6cf80 | 2016-06-08 08:22:05 -0700 | [diff] [blame] | 357 | |
Ethan Nicholas | 8e265a7 | 2018-12-12 16:22:40 -0500 | [diff] [blame] | 358 | void onFreeGPUData(GrVkGpu* gpu) const override {} |
| 359 | |
| 360 | void onAbandonGPUData() const override {} |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 361 | |
egdaniel | 9a6cf80 | 2016-06-08 08:22:05 -0700 | [diff] [blame] | 362 | friend class GrVkPrimaryCommandBuffer; |
| 363 | |
| 364 | typedef GrVkCommandBuffer INHERITED; |
| 365 | }; |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 366 | |
| 367 | #endif |