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