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