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 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #include "src/gpu/vk/GrVkCommandBuffer.h" |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 9 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 10 | #include "include/core/SkRect.h" |
| 11 | #include "src/gpu/vk/GrVkCommandPool.h" |
| 12 | #include "src/gpu/vk/GrVkFramebuffer.h" |
| 13 | #include "src/gpu/vk/GrVkGpu.h" |
| 14 | #include "src/gpu/vk/GrVkImage.h" |
| 15 | #include "src/gpu/vk/GrVkImageView.h" |
| 16 | #include "src/gpu/vk/GrVkIndexBuffer.h" |
| 17 | #include "src/gpu/vk/GrVkPipeline.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 18 | #include "src/gpu/vk/GrVkPipelineState.h" |
| 19 | #include "src/gpu/vk/GrVkPipelineState.h" |
| 20 | #include "src/gpu/vk/GrVkRenderPass.h" |
| 21 | #include "src/gpu/vk/GrVkRenderTarget.h" |
| 22 | #include "src/gpu/vk/GrVkTransferBuffer.h" |
| 23 | #include "src/gpu/vk/GrVkUtil.h" |
| 24 | #include "src/gpu/vk/GrVkVertexBuffer.h" |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 25 | |
| 26 | void GrVkCommandBuffer::invalidateState() { |
Chris Dalton | 1d61635 | 2017-05-31 12:51:23 -0600 | [diff] [blame] | 27 | for (auto& boundInputBuffer : fBoundInputBuffers) { |
| 28 | boundInputBuffer = VK_NULL_HANDLE; |
| 29 | } |
egdaniel | 470d77a | 2016-03-18 12:50:27 -0700 | [diff] [blame] | 30 | fBoundIndexBuffer = VK_NULL_HANDLE; |
egdaniel | 470d77a | 2016-03-18 12:50:27 -0700 | [diff] [blame] | 31 | |
| 32 | memset(&fCachedViewport, 0, sizeof(VkViewport)); |
| 33 | fCachedViewport.width = - 1.0f; // Viewport must have a width greater than 0 |
| 34 | |
| 35 | memset(&fCachedScissor, 0, sizeof(VkRect2D)); |
| 36 | fCachedScissor.offset.x = -1; // Scissor offset must be greater that 0 to be valid |
| 37 | |
| 38 | for (int i = 0; i < 4; ++i) { |
| 39 | fCachedBlendConstant[i] = -1.0; |
| 40 | } |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 41 | } |
| 42 | |
Greg Daniel | 0addbdf | 2019-11-25 15:03:58 -0500 | [diff] [blame] | 43 | void GrVkCommandBuffer::freeGPUData(GrVkGpu* gpu, VkCommandPool cmdPool) const { |
Brian Salomon | e39526b | 2019-06-24 16:35:53 -0400 | [diff] [blame] | 44 | TRACE_EVENT0("skia.gpu", TRACE_FUNC); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 45 | SkASSERT(!fIsActive); |
Greg Daniel | 0addbdf | 2019-11-25 15:03:58 -0500 | [diff] [blame] | 46 | SkASSERT(!fTrackedResources.count()); |
| 47 | SkASSERT(!fTrackedRecycledResources.count()); |
| 48 | SkASSERT(cmdPool != VK_NULL_HANDLE); |
| 49 | SkASSERT(!this->isWrapped()); |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 50 | |
Greg Daniel | 0addbdf | 2019-11-25 15:03:58 -0500 | [diff] [blame] | 51 | GR_VK_CALL(gpu->vkInterface(), FreeCommandBuffers(gpu->device(), cmdPool, 1, &fCmdBuffer)); |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 52 | |
| 53 | this->onFreeGPUData(gpu); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 54 | } |
| 55 | |
Greg Daniel | cef213c | 2017-04-21 11:52:27 -0400 | [diff] [blame] | 56 | void GrVkCommandBuffer::abandonGPUData() const { |
Ethan Nicholas | 8e265a7 | 2018-12-12 16:22:40 -0500 | [diff] [blame] | 57 | SkDEBUGCODE(fResourcesReleased = true;) |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 58 | for (int i = 0; i < fTrackedResources.count(); ++i) { |
Brian Salomon | 614c1a8 | 2018-12-19 15:42:06 -0500 | [diff] [blame] | 59 | fTrackedResources[i]->notifyRemovedFromCommandBuffer(); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 60 | fTrackedResources[i]->unrefAndAbandon(); |
| 61 | } |
egdaniel | c1be9bc | 2016-07-20 08:33:00 -0700 | [diff] [blame] | 62 | |
| 63 | for (int i = 0; i < fTrackedRecycledResources.count(); ++i) { |
Brian Salomon | 614c1a8 | 2018-12-19 15:42:06 -0500 | [diff] [blame] | 64 | fTrackedRecycledResources[i]->notifyRemovedFromCommandBuffer(); |
egdaniel | c1be9bc | 2016-07-20 08:33:00 -0700 | [diff] [blame] | 65 | // We don't recycle resources when abandoning them. |
| 66 | fTrackedRecycledResources[i]->unrefAndAbandon(); |
| 67 | } |
Greg Daniel | 7d918fd | 2018-06-19 15:22:01 -0400 | [diff] [blame] | 68 | |
Ethan Nicholas | 8e265a7 | 2018-12-12 16:22:40 -0500 | [diff] [blame] | 69 | this->onAbandonGPUData(); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 70 | } |
| 71 | |
Ethan Nicholas | 8e265a7 | 2018-12-12 16:22:40 -0500 | [diff] [blame] | 72 | void GrVkCommandBuffer::releaseResources(GrVkGpu* gpu) { |
Brian Salomon | e39526b | 2019-06-24 16:35:53 -0400 | [diff] [blame] | 73 | TRACE_EVENT0("skia.gpu", TRACE_FUNC); |
Ethan Nicholas | 8e265a7 | 2018-12-12 16:22:40 -0500 | [diff] [blame] | 74 | SkDEBUGCODE(fResourcesReleased = true;) |
jvanverth | 7ec9241 | 2016-07-06 09:24:57 -0700 | [diff] [blame] | 75 | SkASSERT(!fIsActive); |
| 76 | for (int i = 0; i < fTrackedResources.count(); ++i) { |
Brian Salomon | 614c1a8 | 2018-12-19 15:42:06 -0500 | [diff] [blame] | 77 | fTrackedResources[i]->notifyRemovedFromCommandBuffer(); |
jvanverth | 7ec9241 | 2016-07-06 09:24:57 -0700 | [diff] [blame] | 78 | fTrackedResources[i]->unref(gpu); |
| 79 | } |
egdaniel | c1be9bc | 2016-07-20 08:33:00 -0700 | [diff] [blame] | 80 | for (int i = 0; i < fTrackedRecycledResources.count(); ++i) { |
Brian Salomon | 614c1a8 | 2018-12-19 15:42:06 -0500 | [diff] [blame] | 81 | fTrackedRecycledResources[i]->notifyRemovedFromCommandBuffer(); |
egdaniel | c1be9bc | 2016-07-20 08:33:00 -0700 | [diff] [blame] | 82 | fTrackedRecycledResources[i]->recycle(const_cast<GrVkGpu*>(gpu)); |
| 83 | } |
egdaniel | 594739c | 2016-09-20 12:39:25 -0700 | [diff] [blame] | 84 | |
| 85 | if (++fNumResets > kNumRewindResetsBeforeFullReset) { |
| 86 | fTrackedResources.reset(); |
| 87 | fTrackedRecycledResources.reset(); |
| 88 | fTrackedResources.setReserve(kInitialTrackedResourcesCount); |
| 89 | fTrackedRecycledResources.setReserve(kInitialTrackedResourcesCount); |
| 90 | fNumResets = 0; |
| 91 | } else { |
| 92 | fTrackedResources.rewind(); |
| 93 | fTrackedRecycledResources.rewind(); |
| 94 | } |
| 95 | |
jvanverth | 7ec9241 | 2016-07-06 09:24:57 -0700 | [diff] [blame] | 96 | this->invalidateState(); |
| 97 | |
Ethan Nicholas | 8e265a7 | 2018-12-12 16:22:40 -0500 | [diff] [blame] | 98 | this->onReleaseResources(gpu); |
jvanverth | 7ec9241 | 2016-07-06 09:24:57 -0700 | [diff] [blame] | 99 | } |
| 100 | |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 101 | //////////////////////////////////////////////////////////////////////////////// |
| 102 | // CommandBuffer commands |
| 103 | //////////////////////////////////////////////////////////////////////////////// |
| 104 | |
| 105 | void GrVkCommandBuffer::pipelineBarrier(const GrVkGpu* gpu, |
Greg Daniel | 59dc148 | 2019-02-22 10:46:38 -0500 | [diff] [blame] | 106 | const GrVkResource* resource, |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 107 | VkPipelineStageFlags srcStageMask, |
| 108 | VkPipelineStageFlags dstStageMask, |
| 109 | bool byRegion, |
| 110 | BarrierType barrierType, |
Greg Daniel | 59dc148 | 2019-02-22 10:46:38 -0500 | [diff] [blame] | 111 | void* barrier) { |
Greg Daniel | 070cbaf | 2019-01-03 17:35:54 -0500 | [diff] [blame] | 112 | SkASSERT(!this->isWrapped()); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 113 | SkASSERT(fIsActive); |
egdaniel | 58a8d92 | 2016-04-21 08:03:10 -0700 | [diff] [blame] | 114 | // For images we can have barriers inside of render passes but they require us to add more |
| 115 | // support in subpasses which need self dependencies to have barriers inside them. Also, we can |
| 116 | // never have buffer barriers inside of a render pass. For now we will just assert that we are |
| 117 | // not in a render pass. |
| 118 | SkASSERT(!fActiveRenderPass); |
Greg Daniel | f346df3 | 2019-04-03 14:52:13 -0400 | [diff] [blame] | 119 | |
Greg Daniel | ee54f23 | 2019-04-03 14:58:40 -0400 | [diff] [blame] | 120 | if (barrierType == kBufferMemory_BarrierType) { |
| 121 | const VkBufferMemoryBarrier* barrierPtr = reinterpret_cast<VkBufferMemoryBarrier*>(barrier); |
| 122 | fBufferBarriers.push_back(*barrierPtr); |
| 123 | } else { |
| 124 | SkASSERT(barrierType == kImageMemory_BarrierType); |
| 125 | const VkImageMemoryBarrier* barrierPtr = reinterpret_cast<VkImageMemoryBarrier*>(barrier); |
Greg Daniel | 212ff05 | 2019-04-09 10:41:34 -0400 | [diff] [blame] | 126 | // We need to check if we are adding a pipeline barrier that covers part of the same |
| 127 | // subresource range as a barrier that is already in current batch. If it does, then we must |
| 128 | // submit the first batch because the vulkan spec does not define a specific ordering for |
| 129 | // barriers submitted in the same batch. |
| 130 | // TODO: Look if we can gain anything by merging barriers together instead of submitting |
| 131 | // the old ones. |
| 132 | for (int i = 0; i < fImageBarriers.count(); ++i) { |
| 133 | VkImageMemoryBarrier& currentBarrier = fImageBarriers[i]; |
| 134 | if (barrierPtr->image == currentBarrier.image) { |
| 135 | const VkImageSubresourceRange newRange = barrierPtr->subresourceRange; |
| 136 | const VkImageSubresourceRange oldRange = currentBarrier.subresourceRange; |
| 137 | SkASSERT(newRange.aspectMask == oldRange.aspectMask); |
| 138 | SkASSERT(newRange.baseArrayLayer == oldRange.baseArrayLayer); |
| 139 | SkASSERT(newRange.layerCount == oldRange.layerCount); |
| 140 | uint32_t newStart = newRange.baseMipLevel; |
| 141 | uint32_t newEnd = newRange.baseMipLevel + newRange.levelCount - 1; |
| 142 | uint32_t oldStart = oldRange.baseMipLevel; |
| 143 | uint32_t oldEnd = oldRange.baseMipLevel + oldRange.levelCount - 1; |
| 144 | if (SkTMax(newStart, oldStart) <= SkTMin(newEnd, oldEnd)) { |
| 145 | this->submitPipelineBarriers(gpu); |
| 146 | break; |
| 147 | } |
| 148 | } |
| 149 | } |
Greg Daniel | ee54f23 | 2019-04-03 14:58:40 -0400 | [diff] [blame] | 150 | fImageBarriers.push_back(*barrierPtr); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 151 | } |
Greg Daniel | ee54f23 | 2019-04-03 14:58:40 -0400 | [diff] [blame] | 152 | fBarriersByRegion |= byRegion; |
| 153 | |
| 154 | fSrcStageMask = fSrcStageMask | srcStageMask; |
| 155 | fDstStageMask = fDstStageMask | dstStageMask; |
| 156 | |
| 157 | fHasWork = true; |
Greg Daniel | 59dc148 | 2019-02-22 10:46:38 -0500 | [diff] [blame] | 158 | if (resource) { |
| 159 | this->addResource(resource); |
| 160 | } |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 161 | } |
| 162 | |
Greg Daniel | ee54f23 | 2019-04-03 14:58:40 -0400 | [diff] [blame] | 163 | void GrVkCommandBuffer::submitPipelineBarriers(const GrVkGpu* gpu) { |
| 164 | SkASSERT(fIsActive); |
| 165 | |
| 166 | // Currently we never submit a pipeline barrier without at least one memory barrier. |
| 167 | if (fBufferBarriers.count() || fImageBarriers.count()) { |
| 168 | // For images we can have barriers inside of render passes but they require us to add more |
| 169 | // support in subpasses which need self dependencies to have barriers inside them. Also, we |
| 170 | // can never have buffer barriers inside of a render pass. For now we will just assert that |
| 171 | // we are not in a render pass. |
| 172 | SkASSERT(!fActiveRenderPass); |
| 173 | SkASSERT(!this->isWrapped()); |
| 174 | SkASSERT(fSrcStageMask && fDstStageMask); |
| 175 | |
| 176 | VkDependencyFlags dependencyFlags = fBarriersByRegion ? VK_DEPENDENCY_BY_REGION_BIT : 0; |
| 177 | GR_VK_CALL(gpu->vkInterface(), CmdPipelineBarrier( |
| 178 | fCmdBuffer, fSrcStageMask, fDstStageMask, dependencyFlags, 0, nullptr, |
| 179 | fBufferBarriers.count(), fBufferBarriers.begin(), |
| 180 | fImageBarriers.count(), fImageBarriers.begin())); |
| 181 | fBufferBarriers.reset(); |
| 182 | fImageBarriers.reset(); |
| 183 | fBarriersByRegion = false; |
| 184 | fSrcStageMask = 0; |
| 185 | fDstStageMask = 0; |
| 186 | } |
| 187 | SkASSERT(!fBufferBarriers.count()); |
| 188 | SkASSERT(!fImageBarriers.count()); |
| 189 | SkASSERT(!fBarriersByRegion); |
| 190 | SkASSERT(!fSrcStageMask); |
| 191 | SkASSERT(!fDstStageMask); |
| 192 | } |
| 193 | |
| 194 | |
Greg Daniel | 6ecc911 | 2017-06-16 16:17:03 +0000 | [diff] [blame] | 195 | void GrVkCommandBuffer::bindInputBuffer(GrVkGpu* gpu, uint32_t binding, |
| 196 | const GrVkVertexBuffer* vbuffer) { |
| 197 | VkBuffer vkBuffer = vbuffer->buffer(); |
| 198 | SkASSERT(VK_NULL_HANDLE != vkBuffer); |
| 199 | SkASSERT(binding < kMaxInputBuffers); |
| 200 | // TODO: once vbuffer->offset() no longer always returns 0, we will need to track the offset |
| 201 | // to know if we can skip binding or not. |
| 202 | if (vkBuffer != fBoundInputBuffers[binding]) { |
| 203 | VkDeviceSize offset = vbuffer->offset(); |
| 204 | GR_VK_CALL(gpu->vkInterface(), CmdBindVertexBuffers(fCmdBuffer, |
| 205 | binding, |
| 206 | 1, |
| 207 | &vkBuffer, |
| 208 | &offset)); |
| 209 | fBoundInputBuffers[binding] = vkBuffer; |
Greg Daniel | 59dc148 | 2019-02-22 10:46:38 -0500 | [diff] [blame] | 210 | this->addResource(vbuffer->resource()); |
Greg Daniel | 6ecc911 | 2017-06-16 16:17:03 +0000 | [diff] [blame] | 211 | } |
| 212 | } |
| 213 | |
| 214 | void GrVkCommandBuffer::bindIndexBuffer(GrVkGpu* gpu, const GrVkIndexBuffer* ibuffer) { |
| 215 | VkBuffer vkBuffer = ibuffer->buffer(); |
| 216 | SkASSERT(VK_NULL_HANDLE != vkBuffer); |
| 217 | // TODO: once ibuffer->offset() no longer always returns 0, we will need to track the offset |
| 218 | // to know if we can skip binding or not. |
| 219 | if (vkBuffer != fBoundIndexBuffer) { |
| 220 | GR_VK_CALL(gpu->vkInterface(), CmdBindIndexBuffer(fCmdBuffer, |
| 221 | vkBuffer, |
| 222 | ibuffer->offset(), |
| 223 | VK_INDEX_TYPE_UINT16)); |
| 224 | fBoundIndexBuffer = vkBuffer; |
Greg Daniel | 59dc148 | 2019-02-22 10:46:38 -0500 | [diff] [blame] | 225 | this->addResource(ibuffer->resource()); |
Greg Daniel | 6ecc911 | 2017-06-16 16:17:03 +0000 | [diff] [blame] | 226 | } |
| 227 | } |
| 228 | |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 229 | void GrVkCommandBuffer::clearAttachments(const GrVkGpu* gpu, |
| 230 | int numAttachments, |
| 231 | const VkClearAttachment* attachments, |
| 232 | int numRects, |
Greg Daniel | f346df3 | 2019-04-03 14:52:13 -0400 | [diff] [blame] | 233 | const VkClearRect* clearRects) { |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 234 | SkASSERT(fIsActive); |
| 235 | SkASSERT(fActiveRenderPass); |
| 236 | SkASSERT(numAttachments > 0); |
| 237 | SkASSERT(numRects > 0); |
Greg Daniel | f346df3 | 2019-04-03 14:52:13 -0400 | [diff] [blame] | 238 | |
Greg Daniel | ee54f23 | 2019-04-03 14:58:40 -0400 | [diff] [blame] | 239 | this->addingWork(gpu); |
Greg Daniel | f346df3 | 2019-04-03 14:52:13 -0400 | [diff] [blame] | 240 | |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 241 | #ifdef SK_DEBUG |
| 242 | for (int i = 0; i < numAttachments; ++i) { |
| 243 | if (attachments[i].aspectMask == VK_IMAGE_ASPECT_COLOR_BIT) { |
| 244 | uint32_t testIndex; |
| 245 | SkAssertResult(fActiveRenderPass->colorAttachmentIndex(&testIndex)); |
| 246 | SkASSERT(testIndex == attachments[i].colorAttachment); |
| 247 | } |
| 248 | } |
| 249 | #endif |
| 250 | GR_VK_CALL(gpu->vkInterface(), CmdClearAttachments(fCmdBuffer, |
| 251 | numAttachments, |
| 252 | attachments, |
| 253 | numRects, |
| 254 | clearRects)); |
Greg Daniel | a718a61 | 2019-10-07 16:25:41 -0400 | [diff] [blame] | 255 | if (gpu->vkCaps().mustInvalidatePrimaryCmdBufferStateAfterClearAttachments()) { |
| 256 | this->invalidateState(); |
| 257 | } |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 258 | } |
| 259 | |
| 260 | void GrVkCommandBuffer::bindDescriptorSets(const GrVkGpu* gpu, |
egdaniel | 22281c1 | 2016-03-23 13:49:40 -0700 | [diff] [blame] | 261 | GrVkPipelineState* pipelineState, |
Greg Daniel | eecc687 | 2019-07-29 13:21:37 -0400 | [diff] [blame] | 262 | VkPipelineLayout layout, |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 263 | uint32_t firstSet, |
| 264 | uint32_t setCount, |
| 265 | const VkDescriptorSet* descriptorSets, |
| 266 | uint32_t dynamicOffsetCount, |
| 267 | const uint32_t* dynamicOffsets) { |
| 268 | SkASSERT(fIsActive); |
| 269 | GR_VK_CALL(gpu->vkInterface(), CmdBindDescriptorSets(fCmdBuffer, |
| 270 | VK_PIPELINE_BIND_POINT_GRAPHICS, |
Greg Daniel | eecc687 | 2019-07-29 13:21:37 -0400 | [diff] [blame] | 271 | layout, |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 272 | firstSet, |
| 273 | setCount, |
| 274 | descriptorSets, |
| 275 | dynamicOffsetCount, |
| 276 | dynamicOffsets)); |
egdaniel | bc9b296 | 2016-09-27 08:00:53 -0700 | [diff] [blame] | 277 | } |
| 278 | |
egdaniel | 470d77a | 2016-03-18 12:50:27 -0700 | [diff] [blame] | 279 | void GrVkCommandBuffer::bindPipeline(const GrVkGpu* gpu, const GrVkPipeline* pipeline) { |
| 280 | SkASSERT(fIsActive); |
egdaniel | 470d77a | 2016-03-18 12:50:27 -0700 | [diff] [blame] | 281 | GR_VK_CALL(gpu->vkInterface(), CmdBindPipeline(fCmdBuffer, |
| 282 | VK_PIPELINE_BIND_POINT_GRAPHICS, |
| 283 | pipeline->pipeline())); |
egdaniel | ec44099 | 2016-09-13 09:54:11 -0700 | [diff] [blame] | 284 | this->addResource(pipeline); |
egdaniel | 470d77a | 2016-03-18 12:50:27 -0700 | [diff] [blame] | 285 | } |
| 286 | |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 287 | void GrVkCommandBuffer::drawIndexed(const GrVkGpu* gpu, |
| 288 | uint32_t indexCount, |
| 289 | uint32_t instanceCount, |
| 290 | uint32_t firstIndex, |
| 291 | int32_t vertexOffset, |
Greg Daniel | f346df3 | 2019-04-03 14:52:13 -0400 | [diff] [blame] | 292 | uint32_t firstInstance) { |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 293 | SkASSERT(fIsActive); |
| 294 | SkASSERT(fActiveRenderPass); |
Greg Daniel | ee54f23 | 2019-04-03 14:58:40 -0400 | [diff] [blame] | 295 | this->addingWork(gpu); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 296 | GR_VK_CALL(gpu->vkInterface(), CmdDrawIndexed(fCmdBuffer, |
| 297 | indexCount, |
| 298 | instanceCount, |
| 299 | firstIndex, |
| 300 | vertexOffset, |
| 301 | firstInstance)); |
| 302 | } |
| 303 | |
| 304 | void GrVkCommandBuffer::draw(const GrVkGpu* gpu, |
| 305 | uint32_t vertexCount, |
| 306 | uint32_t instanceCount, |
| 307 | uint32_t firstVertex, |
Greg Daniel | f346df3 | 2019-04-03 14:52:13 -0400 | [diff] [blame] | 308 | uint32_t firstInstance) { |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 309 | SkASSERT(fIsActive); |
| 310 | SkASSERT(fActiveRenderPass); |
Greg Daniel | ee54f23 | 2019-04-03 14:58:40 -0400 | [diff] [blame] | 311 | this->addingWork(gpu); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 312 | GR_VK_CALL(gpu->vkInterface(), CmdDraw(fCmdBuffer, |
| 313 | vertexCount, |
| 314 | instanceCount, |
| 315 | firstVertex, |
| 316 | firstInstance)); |
| 317 | } |
egdaniel | 470d77a | 2016-03-18 12:50:27 -0700 | [diff] [blame] | 318 | |
| 319 | void GrVkCommandBuffer::setViewport(const GrVkGpu* gpu, |
| 320 | uint32_t firstViewport, |
| 321 | uint32_t viewportCount, |
| 322 | const VkViewport* viewports) { |
| 323 | SkASSERT(fIsActive); |
| 324 | SkASSERT(1 == viewportCount); |
| 325 | if (memcmp(viewports, &fCachedViewport, sizeof(VkViewport))) { |
| 326 | GR_VK_CALL(gpu->vkInterface(), CmdSetViewport(fCmdBuffer, |
| 327 | firstViewport, |
| 328 | viewportCount, |
| 329 | viewports)); |
| 330 | fCachedViewport = viewports[0]; |
| 331 | } |
| 332 | } |
| 333 | |
| 334 | void GrVkCommandBuffer::setScissor(const GrVkGpu* gpu, |
| 335 | uint32_t firstScissor, |
| 336 | uint32_t scissorCount, |
| 337 | const VkRect2D* scissors) { |
| 338 | SkASSERT(fIsActive); |
| 339 | SkASSERT(1 == scissorCount); |
| 340 | if (memcmp(scissors, &fCachedScissor, sizeof(VkRect2D))) { |
| 341 | GR_VK_CALL(gpu->vkInterface(), CmdSetScissor(fCmdBuffer, |
| 342 | firstScissor, |
| 343 | scissorCount, |
| 344 | scissors)); |
| 345 | fCachedScissor = scissors[0]; |
| 346 | } |
| 347 | } |
| 348 | |
| 349 | void GrVkCommandBuffer::setBlendConstants(const GrVkGpu* gpu, |
| 350 | const float blendConstants[4]) { |
| 351 | SkASSERT(fIsActive); |
| 352 | if (memcmp(blendConstants, fCachedBlendConstant, 4 * sizeof(float))) { |
| 353 | GR_VK_CALL(gpu->vkInterface(), CmdSetBlendConstants(fCmdBuffer, blendConstants)); |
| 354 | memcpy(fCachedBlendConstant, blendConstants, 4 * sizeof(float)); |
| 355 | } |
| 356 | } |
egdaniel | 9a6cf80 | 2016-06-08 08:22:05 -0700 | [diff] [blame] | 357 | |
Greg Daniel | ee54f23 | 2019-04-03 14:58:40 -0400 | [diff] [blame] | 358 | void GrVkCommandBuffer::addingWork(const GrVkGpu* gpu) { |
| 359 | this->submitPipelineBarriers(gpu); |
| 360 | fHasWork = true; |
| 361 | } |
| 362 | |
egdaniel | 9a6cf80 | 2016-06-08 08:22:05 -0700 | [diff] [blame] | 363 | /////////////////////////////////////////////////////////////////////////////// |
| 364 | // PrimaryCommandBuffer |
| 365 | //////////////////////////////////////////////////////////////////////////////// |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 366 | GrVkPrimaryCommandBuffer::~GrVkPrimaryCommandBuffer() { |
| 367 | // Should have ended any render pass we're in the middle of |
| 368 | SkASSERT(!fActiveRenderPass); |
| 369 | } |
| 370 | |
egdaniel | 9a6cf80 | 2016-06-08 08:22:05 -0700 | [diff] [blame] | 371 | GrVkPrimaryCommandBuffer* GrVkPrimaryCommandBuffer::Create(const GrVkGpu* gpu, |
Greg Daniel | 0addbdf | 2019-11-25 15:03:58 -0500 | [diff] [blame] | 372 | VkCommandPool cmdPool) { |
egdaniel | 9a6cf80 | 2016-06-08 08:22:05 -0700 | [diff] [blame] | 373 | const VkCommandBufferAllocateInfo cmdInfo = { |
| 374 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, // sType |
Ben Wagner | a93a14a | 2017-08-28 10:34:05 -0400 | [diff] [blame] | 375 | nullptr, // pNext |
Greg Daniel | 0addbdf | 2019-11-25 15:03:58 -0500 | [diff] [blame] | 376 | cmdPool, // commandPool |
egdaniel | 9a6cf80 | 2016-06-08 08:22:05 -0700 | [diff] [blame] | 377 | VK_COMMAND_BUFFER_LEVEL_PRIMARY, // level |
| 378 | 1 // bufferCount |
| 379 | }; |
| 380 | |
| 381 | VkCommandBuffer cmdBuffer; |
| 382 | VkResult err = GR_VK_CALL(gpu->vkInterface(), AllocateCommandBuffers(gpu->device(), |
| 383 | &cmdInfo, |
| 384 | &cmdBuffer)); |
| 385 | if (err) { |
| 386 | return nullptr; |
| 387 | } |
Greg Daniel | 0addbdf | 2019-11-25 15:03:58 -0500 | [diff] [blame] | 388 | return new GrVkPrimaryCommandBuffer(cmdBuffer); |
egdaniel | 9a6cf80 | 2016-06-08 08:22:05 -0700 | [diff] [blame] | 389 | } |
| 390 | |
Greg Daniel | e643da6 | 2019-11-05 12:36:42 -0500 | [diff] [blame] | 391 | void GrVkPrimaryCommandBuffer::begin(GrVkGpu* gpu) { |
egdaniel | 9a6cf80 | 2016-06-08 08:22:05 -0700 | [diff] [blame] | 392 | SkASSERT(!fIsActive); |
| 393 | VkCommandBufferBeginInfo cmdBufferBeginInfo; |
| 394 | memset(&cmdBufferBeginInfo, 0, sizeof(VkCommandBufferBeginInfo)); |
| 395 | cmdBufferBeginInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 396 | cmdBufferBeginInfo.pNext = nullptr; |
| 397 | cmdBufferBeginInfo.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT; |
| 398 | cmdBufferBeginInfo.pInheritanceInfo = nullptr; |
| 399 | |
Greg Daniel | e643da6 | 2019-11-05 12:36:42 -0500 | [diff] [blame] | 400 | GR_VK_CALL_ERRCHECK(gpu, BeginCommandBuffer(fCmdBuffer, &cmdBufferBeginInfo)); |
egdaniel | 9a6cf80 | 2016-06-08 08:22:05 -0700 | [diff] [blame] | 401 | fIsActive = true; |
| 402 | } |
| 403 | |
Ethan Nicholas | 8e265a7 | 2018-12-12 16:22:40 -0500 | [diff] [blame] | 404 | void GrVkPrimaryCommandBuffer::end(GrVkGpu* gpu) { |
egdaniel | 9a6cf80 | 2016-06-08 08:22:05 -0700 | [diff] [blame] | 405 | SkASSERT(fIsActive); |
| 406 | SkASSERT(!fActiveRenderPass); |
Greg Daniel | ee54f23 | 2019-04-03 14:58:40 -0400 | [diff] [blame] | 407 | |
| 408 | this->submitPipelineBarriers(gpu); |
| 409 | |
Greg Daniel | e643da6 | 2019-11-05 12:36:42 -0500 | [diff] [blame] | 410 | GR_VK_CALL_ERRCHECK(gpu, EndCommandBuffer(fCmdBuffer)); |
egdaniel | 9a6cf80 | 2016-06-08 08:22:05 -0700 | [diff] [blame] | 411 | this->invalidateState(); |
| 412 | fIsActive = false; |
Robert Phillips | 04d2ce2 | 2019-04-03 13:20:43 -0400 | [diff] [blame] | 413 | fHasWork = false; |
egdaniel | 9a6cf80 | 2016-06-08 08:22:05 -0700 | [diff] [blame] | 414 | } |
| 415 | |
Greg Daniel | fa3adf7 | 2019-11-07 09:53:41 -0500 | [diff] [blame] | 416 | bool GrVkPrimaryCommandBuffer::beginRenderPass(GrVkGpu* gpu, |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 417 | const GrVkRenderPass* renderPass, |
Robert Phillips | 9521447 | 2017-08-08 18:00:03 -0400 | [diff] [blame] | 418 | const VkClearValue clearValues[], |
Greg Daniel | fa3adf7 | 2019-11-07 09:53:41 -0500 | [diff] [blame] | 419 | GrVkRenderTarget* target, |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 420 | const SkIRect& bounds, |
| 421 | bool forSecondaryCB) { |
egdaniel | 9a6cf80 | 2016-06-08 08:22:05 -0700 | [diff] [blame] | 422 | SkASSERT(fIsActive); |
| 423 | SkASSERT(!fActiveRenderPass); |
Greg Daniel | fa3adf7 | 2019-11-07 09:53:41 -0500 | [diff] [blame] | 424 | SkASSERT(renderPass->isCompatible(*target)); |
| 425 | |
| 426 | const GrVkFramebuffer* framebuffer = target->getFramebuffer(); |
| 427 | if (!framebuffer) { |
| 428 | return false; |
| 429 | } |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 430 | |
Greg Daniel | ee54f23 | 2019-04-03 14:58:40 -0400 | [diff] [blame] | 431 | this->addingWork(gpu); |
Greg Daniel | f346df3 | 2019-04-03 14:52:13 -0400 | [diff] [blame] | 432 | |
egdaniel | 9a6cf80 | 2016-06-08 08:22:05 -0700 | [diff] [blame] | 433 | VkRenderPassBeginInfo beginInfo; |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 434 | VkRect2D renderArea; |
| 435 | renderArea.offset = { bounds.fLeft , bounds.fTop }; |
| 436 | renderArea.extent = { (uint32_t)bounds.width(), (uint32_t)bounds.height() }; |
| 437 | |
| 438 | memset(&beginInfo, 0, sizeof(VkRenderPassBeginInfo)); |
| 439 | beginInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO; |
| 440 | beginInfo.pNext = nullptr; |
| 441 | beginInfo.renderPass = renderPass->vkRenderPass(); |
Greg Daniel | fa3adf7 | 2019-11-07 09:53:41 -0500 | [diff] [blame] | 442 | beginInfo.framebuffer = framebuffer->framebuffer(); |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 443 | beginInfo.renderArea = renderArea; |
Greg Daniel | b68319a | 2018-02-23 16:08:28 -0500 | [diff] [blame] | 444 | beginInfo.clearValueCount = renderPass->clearValueCount(); |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 445 | beginInfo.pClearValues = clearValues; |
| 446 | |
| 447 | VkSubpassContents contents = forSecondaryCB ? VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS |
| 448 | : VK_SUBPASS_CONTENTS_INLINE; |
| 449 | |
egdaniel | 9a6cf80 | 2016-06-08 08:22:05 -0700 | [diff] [blame] | 450 | GR_VK_CALL(gpu->vkInterface(), CmdBeginRenderPass(fCmdBuffer, &beginInfo, contents)); |
| 451 | fActiveRenderPass = renderPass; |
| 452 | this->addResource(renderPass); |
Greg Daniel | fa3adf7 | 2019-11-07 09:53:41 -0500 | [diff] [blame] | 453 | target->addResources(*this); |
| 454 | return true; |
egdaniel | 9a6cf80 | 2016-06-08 08:22:05 -0700 | [diff] [blame] | 455 | } |
| 456 | |
| 457 | void GrVkPrimaryCommandBuffer::endRenderPass(const GrVkGpu* gpu) { |
| 458 | SkASSERT(fIsActive); |
| 459 | SkASSERT(fActiveRenderPass); |
Greg Daniel | ee54f23 | 2019-04-03 14:58:40 -0400 | [diff] [blame] | 460 | this->addingWork(gpu); |
egdaniel | 9a6cf80 | 2016-06-08 08:22:05 -0700 | [diff] [blame] | 461 | GR_VK_CALL(gpu->vkInterface(), CmdEndRenderPass(fCmdBuffer)); |
| 462 | fActiveRenderPass = nullptr; |
| 463 | } |
| 464 | |
| 465 | void GrVkPrimaryCommandBuffer::executeCommands(const GrVkGpu* gpu, |
Greg Daniel | 8daf3b7 | 2019-07-30 09:57:26 -0400 | [diff] [blame] | 466 | std::unique_ptr<GrVkSecondaryCommandBuffer> buffer) { |
Ethan Nicholas | 8e265a7 | 2018-12-12 16:22:40 -0500 | [diff] [blame] | 467 | // The Vulkan spec allows secondary command buffers to be executed on a primary command buffer |
| 468 | // if the command pools both were created from were created with the same queue family. However, |
| 469 | // we currently always create them from the same pool. |
egdaniel | 9a6cf80 | 2016-06-08 08:22:05 -0700 | [diff] [blame] | 470 | SkASSERT(fIsActive); |
Greg Daniel | 77b53f6 | 2016-10-18 11:48:51 -0400 | [diff] [blame] | 471 | SkASSERT(!buffer->fIsActive); |
egdaniel | 9a6cf80 | 2016-06-08 08:22:05 -0700 | [diff] [blame] | 472 | SkASSERT(fActiveRenderPass); |
| 473 | SkASSERT(fActiveRenderPass->isCompatible(*buffer->fActiveRenderPass)); |
| 474 | |
Greg Daniel | ee54f23 | 2019-04-03 14:58:40 -0400 | [diff] [blame] | 475 | this->addingWork(gpu); |
Greg Daniel | f346df3 | 2019-04-03 14:52:13 -0400 | [diff] [blame] | 476 | |
egdaniel | 9a6cf80 | 2016-06-08 08:22:05 -0700 | [diff] [blame] | 477 | GR_VK_CALL(gpu->vkInterface(), CmdExecuteCommands(fCmdBuffer, 1, &buffer->fCmdBuffer)); |
Greg Daniel | 8daf3b7 | 2019-07-30 09:57:26 -0400 | [diff] [blame] | 478 | fSecondaryCommandBuffers.push_back(std::move(buffer)); |
egdaniel | 066df7c | 2016-06-08 14:02:27 -0700 | [diff] [blame] | 479 | // When executing a secondary command buffer all state (besides render pass state) becomes |
| 480 | // invalidated and must be reset. This includes bound buffers, pipelines, dynamic state, etc. |
| 481 | this->invalidateState(); |
egdaniel | 9a6cf80 | 2016-06-08 08:22:05 -0700 | [diff] [blame] | 482 | } |
| 483 | |
Greg Daniel | e643da6 | 2019-11-05 12:36:42 -0500 | [diff] [blame] | 484 | static void submit_to_queue(GrVkGpu* gpu, |
Greg Daniel | 48661b8 | 2018-01-22 16:11:35 -0500 | [diff] [blame] | 485 | VkQueue queue, |
| 486 | VkFence fence, |
| 487 | uint32_t waitCount, |
| 488 | const VkSemaphore* waitSemaphores, |
| 489 | const VkPipelineStageFlags* waitStages, |
| 490 | uint32_t commandBufferCount, |
| 491 | const VkCommandBuffer* commandBuffers, |
| 492 | uint32_t signalCount, |
Emircan Uysaler | 23ca4e7 | 2019-06-24 10:53:09 -0400 | [diff] [blame] | 493 | const VkSemaphore* signalSemaphores, |
| 494 | GrProtected protectedContext) { |
| 495 | VkProtectedSubmitInfo protectedSubmitInfo; |
| 496 | if (protectedContext == GrProtected::kYes) { |
| 497 | memset(&protectedSubmitInfo, 0, sizeof(VkProtectedSubmitInfo)); |
| 498 | protectedSubmitInfo.sType = VK_STRUCTURE_TYPE_PROTECTED_SUBMIT_INFO; |
| 499 | protectedSubmitInfo.pNext = nullptr; |
| 500 | protectedSubmitInfo.protectedSubmit = VK_TRUE; |
| 501 | } |
| 502 | |
Greg Daniel | 48661b8 | 2018-01-22 16:11:35 -0500 | [diff] [blame] | 503 | VkSubmitInfo submitInfo; |
| 504 | memset(&submitInfo, 0, sizeof(VkSubmitInfo)); |
| 505 | submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
Emircan Uysaler | 23ca4e7 | 2019-06-24 10:53:09 -0400 | [diff] [blame] | 506 | submitInfo.pNext = protectedContext == GrProtected::kYes ? &protectedSubmitInfo : nullptr; |
Greg Daniel | 48661b8 | 2018-01-22 16:11:35 -0500 | [diff] [blame] | 507 | submitInfo.waitSemaphoreCount = waitCount; |
| 508 | submitInfo.pWaitSemaphores = waitSemaphores; |
| 509 | submitInfo.pWaitDstStageMask = waitStages; |
| 510 | submitInfo.commandBufferCount = commandBufferCount; |
| 511 | submitInfo.pCommandBuffers = commandBuffers; |
| 512 | submitInfo.signalSemaphoreCount = signalCount; |
| 513 | submitInfo.pSignalSemaphores = signalSemaphores; |
Greg Daniel | e643da6 | 2019-11-05 12:36:42 -0500 | [diff] [blame] | 514 | GR_VK_CALL_ERRCHECK(gpu, QueueSubmit(queue, 1, &submitInfo, fence)); |
Greg Daniel | 48661b8 | 2018-01-22 16:11:35 -0500 | [diff] [blame] | 515 | } |
| 516 | |
Greg Daniel | 6be3523 | 2017-03-01 17:01:09 -0500 | [diff] [blame] | 517 | void GrVkPrimaryCommandBuffer::submitToQueue( |
Greg Daniel | e643da6 | 2019-11-05 12:36:42 -0500 | [diff] [blame] | 518 | GrVkGpu* gpu, |
Greg Daniel | 6be3523 | 2017-03-01 17:01:09 -0500 | [diff] [blame] | 519 | VkQueue queue, |
| 520 | GrVkGpu::SyncQueue sync, |
Greg Daniel | 48661b8 | 2018-01-22 16:11:35 -0500 | [diff] [blame] | 521 | SkTArray<GrVkSemaphore::Resource*>& signalSemaphores, |
| 522 | SkTArray<GrVkSemaphore::Resource*>& waitSemaphores) { |
egdaniel | 9a6cf80 | 2016-06-08 08:22:05 -0700 | [diff] [blame] | 523 | SkASSERT(!fIsActive); |
| 524 | |
| 525 | VkResult err; |
jvanverth | 7ec9241 | 2016-07-06 09:24:57 -0700 | [diff] [blame] | 526 | if (VK_NULL_HANDLE == fSubmitFence) { |
| 527 | VkFenceCreateInfo fenceInfo; |
| 528 | memset(&fenceInfo, 0, sizeof(VkFenceCreateInfo)); |
| 529 | fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 530 | err = GR_VK_CALL(gpu->vkInterface(), CreateFence(gpu->device(), &fenceInfo, nullptr, |
| 531 | &fSubmitFence)); |
| 532 | SkASSERT(!err); |
| 533 | } else { |
| 534 | GR_VK_CALL(gpu->vkInterface(), ResetFences(gpu->device(), 1, &fSubmitFence)); |
| 535 | } |
egdaniel | 9a6cf80 | 2016-06-08 08:22:05 -0700 | [diff] [blame] | 536 | |
Greg Daniel | a5cb781 | 2017-06-16 09:45:32 -0400 | [diff] [blame] | 537 | int signalCount = signalSemaphores.count(); |
Greg Daniel | 6be3523 | 2017-03-01 17:01:09 -0500 | [diff] [blame] | 538 | int waitCount = waitSemaphores.count(); |
Greg Daniel | 6be3523 | 2017-03-01 17:01:09 -0500 | [diff] [blame] | 539 | |
Greg Daniel | 48661b8 | 2018-01-22 16:11:35 -0500 | [diff] [blame] | 540 | if (0 == signalCount && 0 == waitCount) { |
| 541 | // This command buffer has no dependent semaphores so we can simply just submit it to the |
| 542 | // queue with no worries. |
Greg Daniel | e643da6 | 2019-11-05 12:36:42 -0500 | [diff] [blame] | 543 | submit_to_queue(gpu, queue, fSubmitFence, 0, nullptr, nullptr, 1, &fCmdBuffer, 0, nullptr, |
Emircan Uysaler | 23ca4e7 | 2019-06-24 10:53:09 -0400 | [diff] [blame] | 544 | gpu->protectedContext() ? GrProtected::kYes : GrProtected::kNo); |
Greg Daniel | 48661b8 | 2018-01-22 16:11:35 -0500 | [diff] [blame] | 545 | } else { |
Greg Daniel | 48661b8 | 2018-01-22 16:11:35 -0500 | [diff] [blame] | 546 | SkTArray<VkSemaphore> vkSignalSems(signalCount); |
| 547 | for (int i = 0; i < signalCount; ++i) { |
| 548 | if (signalSemaphores[i]->shouldSignal()) { |
| 549 | this->addResource(signalSemaphores[i]); |
| 550 | vkSignalSems.push_back(signalSemaphores[i]->semaphore()); |
| 551 | } |
| 552 | } |
| 553 | |
| 554 | SkTArray<VkSemaphore> vkWaitSems(waitCount); |
| 555 | SkTArray<VkPipelineStageFlags> vkWaitStages(waitCount); |
| 556 | for (int i = 0; i < waitCount; ++i) { |
| 557 | if (waitSemaphores[i]->shouldWait()) { |
| 558 | this->addResource(waitSemaphores[i]); |
| 559 | vkWaitSems.push_back(waitSemaphores[i]->semaphore()); |
| 560 | vkWaitStages.push_back(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT); |
| 561 | } |
| 562 | } |
Greg Daniel | e643da6 | 2019-11-05 12:36:42 -0500 | [diff] [blame] | 563 | submit_to_queue(gpu, queue, fSubmitFence, vkWaitSems.count(), vkWaitSems.begin(), |
| 564 | vkWaitStages.begin(), 1, &fCmdBuffer, |
Emircan Uysaler | 23ca4e7 | 2019-06-24 10:53:09 -0400 | [diff] [blame] | 565 | vkSignalSems.count(), vkSignalSems.begin(), |
| 566 | gpu->protectedContext() ? GrProtected::kYes : GrProtected::kNo); |
Greg Daniel | 48661b8 | 2018-01-22 16:11:35 -0500 | [diff] [blame] | 567 | for (int i = 0; i < signalCount; ++i) { |
| 568 | signalSemaphores[i]->markAsSignaled(); |
| 569 | } |
| 570 | for (int i = 0; i < waitCount; ++i) { |
| 571 | waitSemaphores[i]->markAsWaited(); |
| 572 | } |
Greg Daniel | 48661b8 | 2018-01-22 16:11:35 -0500 | [diff] [blame] | 573 | } |
egdaniel | 9a6cf80 | 2016-06-08 08:22:05 -0700 | [diff] [blame] | 574 | |
| 575 | if (GrVkGpu::kForce_SyncQueue == sync) { |
| 576 | err = GR_VK_CALL(gpu->vkInterface(), |
| 577 | WaitForFences(gpu->device(), 1, &fSubmitFence, true, UINT64_MAX)); |
Emircan Uysaler | 283ec65 | 2019-10-31 15:33:31 -0400 | [diff] [blame] | 578 | if (VK_SUCCESS != err) { |
| 579 | SkDebugf("Fence failed: %d\n", err); |
Ben Wagner | b4aab9a | 2017-08-16 10:53:04 -0400 | [diff] [blame] | 580 | SK_ABORT("failing"); |
egdaniel | 9a6cf80 | 2016-06-08 08:22:05 -0700 | [diff] [blame] | 581 | } |
egdaniel | 9a6cf80 | 2016-06-08 08:22:05 -0700 | [diff] [blame] | 582 | |
Greg Daniel | a3aa75a | 2019-04-12 14:24:55 -0400 | [diff] [blame] | 583 | fFinishedProcs.reset(); |
| 584 | |
egdaniel | 9a6cf80 | 2016-06-08 08:22:05 -0700 | [diff] [blame] | 585 | // Destroy the fence |
| 586 | GR_VK_CALL(gpu->vkInterface(), DestroyFence(gpu->device(), fSubmitFence, nullptr)); |
| 587 | fSubmitFence = VK_NULL_HANDLE; |
| 588 | } |
| 589 | } |
| 590 | |
Greg Daniel | a3aa75a | 2019-04-12 14:24:55 -0400 | [diff] [blame] | 591 | bool GrVkPrimaryCommandBuffer::finished(const GrVkGpu* gpu) { |
Ethan Nicholas | 8e265a7 | 2018-12-12 16:22:40 -0500 | [diff] [blame] | 592 | SkASSERT(!fIsActive); |
egdaniel | 9a6cf80 | 2016-06-08 08:22:05 -0700 | [diff] [blame] | 593 | if (VK_NULL_HANDLE == fSubmitFence) { |
| 594 | return true; |
| 595 | } |
| 596 | |
| 597 | VkResult err = GR_VK_CALL(gpu->vkInterface(), GetFenceStatus(gpu->device(), fSubmitFence)); |
| 598 | switch (err) { |
| 599 | case VK_SUCCESS: |
| 600 | return true; |
| 601 | |
| 602 | case VK_NOT_READY: |
| 603 | return false; |
| 604 | |
| 605 | default: |
| 606 | SkDebugf("Error getting fence status: %d\n", err); |
Ben Wagner | b4aab9a | 2017-08-16 10:53:04 -0400 | [diff] [blame] | 607 | SK_ABORT("failing"); |
egdaniel | 9a6cf80 | 2016-06-08 08:22:05 -0700 | [diff] [blame] | 608 | break; |
| 609 | } |
| 610 | |
| 611 | return false; |
| 612 | } |
| 613 | |
Greg Daniel | a3aa75a | 2019-04-12 14:24:55 -0400 | [diff] [blame] | 614 | void GrVkPrimaryCommandBuffer::addFinishedProc(sk_sp<GrRefCntedCallback> finishedProc) { |
| 615 | fFinishedProcs.push_back(std::move(finishedProc)); |
| 616 | } |
| 617 | |
Ethan Nicholas | 8e265a7 | 2018-12-12 16:22:40 -0500 | [diff] [blame] | 618 | void GrVkPrimaryCommandBuffer::onReleaseResources(GrVkGpu* gpu) { |
jvanverth | 7ec9241 | 2016-07-06 09:24:57 -0700 | [diff] [blame] | 619 | for (int i = 0; i < fSecondaryCommandBuffers.count(); ++i) { |
Ethan Nicholas | 8e265a7 | 2018-12-12 16:22:40 -0500 | [diff] [blame] | 620 | fSecondaryCommandBuffers[i]->releaseResources(gpu); |
| 621 | } |
Brian Salomon | ab32f65 | 2019-05-10 14:24:50 -0400 | [diff] [blame] | 622 | fFinishedProcs.reset(); |
Ethan Nicholas | 8e265a7 | 2018-12-12 16:22:40 -0500 | [diff] [blame] | 623 | } |
| 624 | |
Greg Daniel | 0addbdf | 2019-11-25 15:03:58 -0500 | [diff] [blame] | 625 | void GrVkPrimaryCommandBuffer::recycleSecondaryCommandBuffers(GrVkCommandPool* cmdPool) { |
Ethan Nicholas | 8e265a7 | 2018-12-12 16:22:40 -0500 | [diff] [blame] | 626 | for (int i = 0; i < fSecondaryCommandBuffers.count(); ++i) { |
Greg Daniel | 0addbdf | 2019-11-25 15:03:58 -0500 | [diff] [blame] | 627 | fSecondaryCommandBuffers[i].release()->recycle(cmdPool); |
jvanverth | 7ec9241 | 2016-07-06 09:24:57 -0700 | [diff] [blame] | 628 | } |
| 629 | fSecondaryCommandBuffers.reset(); |
| 630 | } |
| 631 | |
egdaniel | 9a6cf80 | 2016-06-08 08:22:05 -0700 | [diff] [blame] | 632 | void GrVkPrimaryCommandBuffer::copyImage(const GrVkGpu* gpu, |
| 633 | GrVkImage* srcImage, |
| 634 | VkImageLayout srcLayout, |
| 635 | GrVkImage* dstImage, |
| 636 | VkImageLayout dstLayout, |
| 637 | uint32_t copyRegionCount, |
| 638 | const VkImageCopy* copyRegions) { |
| 639 | SkASSERT(fIsActive); |
| 640 | SkASSERT(!fActiveRenderPass); |
Greg Daniel | ee54f23 | 2019-04-03 14:58:40 -0400 | [diff] [blame] | 641 | this->addingWork(gpu); |
egdaniel | 9a6cf80 | 2016-06-08 08:22:05 -0700 | [diff] [blame] | 642 | this->addResource(srcImage->resource()); |
| 643 | this->addResource(dstImage->resource()); |
| 644 | GR_VK_CALL(gpu->vkInterface(), CmdCopyImage(fCmdBuffer, |
| 645 | srcImage->image(), |
| 646 | srcLayout, |
| 647 | dstImage->image(), |
| 648 | dstLayout, |
| 649 | copyRegionCount, |
| 650 | copyRegions)); |
| 651 | } |
| 652 | |
| 653 | void GrVkPrimaryCommandBuffer::blitImage(const GrVkGpu* gpu, |
| 654 | const GrVkResource* srcResource, |
| 655 | VkImage srcImage, |
| 656 | VkImageLayout srcLayout, |
| 657 | const GrVkResource* dstResource, |
| 658 | VkImage dstImage, |
| 659 | VkImageLayout dstLayout, |
| 660 | uint32_t blitRegionCount, |
| 661 | const VkImageBlit* blitRegions, |
| 662 | VkFilter filter) { |
| 663 | SkASSERT(fIsActive); |
| 664 | SkASSERT(!fActiveRenderPass); |
Greg Daniel | ee54f23 | 2019-04-03 14:58:40 -0400 | [diff] [blame] | 665 | this->addingWork(gpu); |
egdaniel | 9a6cf80 | 2016-06-08 08:22:05 -0700 | [diff] [blame] | 666 | this->addResource(srcResource); |
| 667 | this->addResource(dstResource); |
| 668 | GR_VK_CALL(gpu->vkInterface(), CmdBlitImage(fCmdBuffer, |
| 669 | srcImage, |
| 670 | srcLayout, |
| 671 | dstImage, |
| 672 | dstLayout, |
| 673 | blitRegionCount, |
| 674 | blitRegions, |
| 675 | filter)); |
| 676 | } |
| 677 | |
Greg Daniel | 6ecc911 | 2017-06-16 16:17:03 +0000 | [diff] [blame] | 678 | void GrVkPrimaryCommandBuffer::blitImage(const GrVkGpu* gpu, |
| 679 | const GrVkImage& srcImage, |
| 680 | const GrVkImage& dstImage, |
| 681 | uint32_t blitRegionCount, |
| 682 | const VkImageBlit* blitRegions, |
| 683 | VkFilter filter) { |
| 684 | this->blitImage(gpu, |
| 685 | srcImage.resource(), |
| 686 | srcImage.image(), |
| 687 | srcImage.currentLayout(), |
| 688 | dstImage.resource(), |
| 689 | dstImage.image(), |
| 690 | dstImage.currentLayout(), |
| 691 | blitRegionCount, |
| 692 | blitRegions, |
| 693 | filter); |
| 694 | } |
| 695 | |
| 696 | |
egdaniel | 9a6cf80 | 2016-06-08 08:22:05 -0700 | [diff] [blame] | 697 | void GrVkPrimaryCommandBuffer::copyImageToBuffer(const GrVkGpu* gpu, |
| 698 | GrVkImage* srcImage, |
| 699 | VkImageLayout srcLayout, |
| 700 | GrVkTransferBuffer* dstBuffer, |
| 701 | uint32_t copyRegionCount, |
| 702 | const VkBufferImageCopy* copyRegions) { |
| 703 | SkASSERT(fIsActive); |
| 704 | SkASSERT(!fActiveRenderPass); |
Greg Daniel | ee54f23 | 2019-04-03 14:58:40 -0400 | [diff] [blame] | 705 | this->addingWork(gpu); |
egdaniel | 9a6cf80 | 2016-06-08 08:22:05 -0700 | [diff] [blame] | 706 | this->addResource(srcImage->resource()); |
| 707 | this->addResource(dstBuffer->resource()); |
| 708 | GR_VK_CALL(gpu->vkInterface(), CmdCopyImageToBuffer(fCmdBuffer, |
| 709 | srcImage->image(), |
| 710 | srcLayout, |
| 711 | dstBuffer->buffer(), |
| 712 | copyRegionCount, |
| 713 | copyRegions)); |
| 714 | } |
| 715 | |
| 716 | void GrVkPrimaryCommandBuffer::copyBufferToImage(const GrVkGpu* gpu, |
| 717 | GrVkTransferBuffer* srcBuffer, |
| 718 | GrVkImage* dstImage, |
| 719 | VkImageLayout dstLayout, |
| 720 | uint32_t copyRegionCount, |
| 721 | const VkBufferImageCopy* copyRegions) { |
| 722 | SkASSERT(fIsActive); |
| 723 | SkASSERT(!fActiveRenderPass); |
Greg Daniel | ee54f23 | 2019-04-03 14:58:40 -0400 | [diff] [blame] | 724 | this->addingWork(gpu); |
egdaniel | 9a6cf80 | 2016-06-08 08:22:05 -0700 | [diff] [blame] | 725 | this->addResource(srcBuffer->resource()); |
| 726 | this->addResource(dstImage->resource()); |
| 727 | GR_VK_CALL(gpu->vkInterface(), CmdCopyBufferToImage(fCmdBuffer, |
| 728 | srcBuffer->buffer(), |
| 729 | dstImage->image(), |
| 730 | dstLayout, |
| 731 | copyRegionCount, |
| 732 | copyRegions)); |
| 733 | } |
| 734 | |
Greg Daniel | 6888c0d | 2017-08-25 11:55:50 -0400 | [diff] [blame] | 735 | |
| 736 | void GrVkPrimaryCommandBuffer::copyBuffer(GrVkGpu* gpu, |
| 737 | GrVkBuffer* srcBuffer, |
| 738 | GrVkBuffer* dstBuffer, |
| 739 | uint32_t regionCount, |
| 740 | const VkBufferCopy* regions) { |
| 741 | SkASSERT(fIsActive); |
| 742 | SkASSERT(!fActiveRenderPass); |
Greg Daniel | ee54f23 | 2019-04-03 14:58:40 -0400 | [diff] [blame] | 743 | this->addingWork(gpu); |
Greg Daniel | 6888c0d | 2017-08-25 11:55:50 -0400 | [diff] [blame] | 744 | #ifdef SK_DEBUG |
| 745 | for (uint32_t i = 0; i < regionCount; ++i) { |
| 746 | const VkBufferCopy& region = regions[i]; |
| 747 | SkASSERT(region.size > 0); |
| 748 | SkASSERT(region.srcOffset < srcBuffer->size()); |
| 749 | SkASSERT(region.dstOffset < dstBuffer->size()); |
| 750 | SkASSERT(region.srcOffset + region.size <= srcBuffer->size()); |
| 751 | SkASSERT(region.dstOffset + region.size <= dstBuffer->size()); |
| 752 | } |
| 753 | #endif |
| 754 | this->addResource(srcBuffer->resource()); |
| 755 | this->addResource(dstBuffer->resource()); |
| 756 | GR_VK_CALL(gpu->vkInterface(), CmdCopyBuffer(fCmdBuffer, |
| 757 | srcBuffer->buffer(), |
| 758 | dstBuffer->buffer(), |
| 759 | regionCount, |
| 760 | regions)); |
| 761 | } |
| 762 | |
jvanverth | a584de9 | 2016-06-30 09:10:52 -0700 | [diff] [blame] | 763 | void GrVkPrimaryCommandBuffer::updateBuffer(GrVkGpu* gpu, |
| 764 | GrVkBuffer* dstBuffer, |
| 765 | VkDeviceSize dstOffset, |
| 766 | VkDeviceSize dataSize, |
| 767 | const void* data) { |
| 768 | SkASSERT(fIsActive); |
| 769 | SkASSERT(!fActiveRenderPass); |
| 770 | SkASSERT(0 == (dstOffset & 0x03)); // four byte aligned |
| 771 | // TODO: handle larger transfer sizes |
| 772 | SkASSERT(dataSize <= 65536); |
| 773 | SkASSERT(0 == (dataSize & 0x03)); // four byte aligned |
Greg Daniel | ee54f23 | 2019-04-03 14:58:40 -0400 | [diff] [blame] | 774 | this->addingWork(gpu); |
jvanverth | a584de9 | 2016-06-30 09:10:52 -0700 | [diff] [blame] | 775 | this->addResource(dstBuffer->resource()); |
| 776 | GR_VK_CALL(gpu->vkInterface(), CmdUpdateBuffer(fCmdBuffer, |
| 777 | dstBuffer->buffer(), |
| 778 | dstOffset, |
| 779 | dataSize, |
| 780 | (const uint32_t*) data)); |
| 781 | } |
| 782 | |
egdaniel | 9a6cf80 | 2016-06-08 08:22:05 -0700 | [diff] [blame] | 783 | void GrVkPrimaryCommandBuffer::clearColorImage(const GrVkGpu* gpu, |
| 784 | GrVkImage* image, |
| 785 | const VkClearColorValue* color, |
| 786 | uint32_t subRangeCount, |
| 787 | const VkImageSubresourceRange* subRanges) { |
| 788 | SkASSERT(fIsActive); |
| 789 | SkASSERT(!fActiveRenderPass); |
Greg Daniel | ee54f23 | 2019-04-03 14:58:40 -0400 | [diff] [blame] | 790 | this->addingWork(gpu); |
egdaniel | 9a6cf80 | 2016-06-08 08:22:05 -0700 | [diff] [blame] | 791 | this->addResource(image->resource()); |
| 792 | GR_VK_CALL(gpu->vkInterface(), CmdClearColorImage(fCmdBuffer, |
| 793 | image->image(), |
| 794 | image->currentLayout(), |
| 795 | color, |
| 796 | subRangeCount, |
| 797 | subRanges)); |
| 798 | } |
| 799 | |
| 800 | void GrVkPrimaryCommandBuffer::clearDepthStencilImage(const GrVkGpu* gpu, |
| 801 | GrVkImage* image, |
| 802 | const VkClearDepthStencilValue* color, |
| 803 | uint32_t subRangeCount, |
| 804 | const VkImageSubresourceRange* subRanges) { |
| 805 | SkASSERT(fIsActive); |
| 806 | SkASSERT(!fActiveRenderPass); |
Greg Daniel | ee54f23 | 2019-04-03 14:58:40 -0400 | [diff] [blame] | 807 | this->addingWork(gpu); |
egdaniel | 9a6cf80 | 2016-06-08 08:22:05 -0700 | [diff] [blame] | 808 | this->addResource(image->resource()); |
| 809 | GR_VK_CALL(gpu->vkInterface(), CmdClearDepthStencilImage(fCmdBuffer, |
| 810 | image->image(), |
| 811 | image->currentLayout(), |
| 812 | color, |
| 813 | subRangeCount, |
| 814 | subRanges)); |
| 815 | } |
| 816 | |
egdaniel | 52ad251 | 2016-08-04 12:50:01 -0700 | [diff] [blame] | 817 | void GrVkPrimaryCommandBuffer::resolveImage(GrVkGpu* gpu, |
| 818 | const GrVkImage& srcImage, |
| 819 | const GrVkImage& dstImage, |
| 820 | uint32_t regionCount, |
| 821 | const VkImageResolve* regions) { |
| 822 | SkASSERT(fIsActive); |
| 823 | SkASSERT(!fActiveRenderPass); |
| 824 | |
Greg Daniel | ee54f23 | 2019-04-03 14:58:40 -0400 | [diff] [blame] | 825 | this->addingWork(gpu); |
egdaniel | 52ad251 | 2016-08-04 12:50:01 -0700 | [diff] [blame] | 826 | this->addResource(srcImage.resource()); |
| 827 | this->addResource(dstImage.resource()); |
| 828 | |
| 829 | GR_VK_CALL(gpu->vkInterface(), CmdResolveImage(fCmdBuffer, |
| 830 | srcImage.image(), |
| 831 | srcImage.currentLayout(), |
| 832 | dstImage.image(), |
| 833 | dstImage.currentLayout(), |
| 834 | regionCount, |
| 835 | regions)); |
| 836 | } |
| 837 | |
Ethan Nicholas | 8e265a7 | 2018-12-12 16:22:40 -0500 | [diff] [blame] | 838 | void GrVkPrimaryCommandBuffer::onFreeGPUData(GrVkGpu* gpu) const { |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 839 | SkASSERT(!fActiveRenderPass); |
| 840 | // Destroy the fence, if any |
| 841 | if (VK_NULL_HANDLE != fSubmitFence) { |
| 842 | GR_VK_CALL(gpu->vkInterface(), DestroyFence(gpu->device(), fSubmitFence, nullptr)); |
| 843 | } |
Greg Daniel | 0addbdf | 2019-11-25 15:03:58 -0500 | [diff] [blame] | 844 | SkASSERT(!fSecondaryCommandBuffers.count()); |
Ethan Nicholas | 8e265a7 | 2018-12-12 16:22:40 -0500 | [diff] [blame] | 845 | } |
| 846 | |
| 847 | void GrVkPrimaryCommandBuffer::onAbandonGPUData() const { |
| 848 | SkASSERT(!fActiveRenderPass); |
Greg Daniel | 8daf3b7 | 2019-07-30 09:57:26 -0400 | [diff] [blame] | 849 | for (const auto& buffer : fSecondaryCommandBuffers) { |
| 850 | buffer->abandonGPUData(); |
Ethan Nicholas | 8e265a7 | 2018-12-12 16:22:40 -0500 | [diff] [blame] | 851 | } |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 852 | } |
| 853 | |
egdaniel | 9a6cf80 | 2016-06-08 08:22:05 -0700 | [diff] [blame] | 854 | /////////////////////////////////////////////////////////////////////////////// |
| 855 | // SecondaryCommandBuffer |
| 856 | //////////////////////////////////////////////////////////////////////////////// |
| 857 | |
jvanverth | 7ec9241 | 2016-07-06 09:24:57 -0700 | [diff] [blame] | 858 | GrVkSecondaryCommandBuffer* GrVkSecondaryCommandBuffer::Create(const GrVkGpu* gpu, |
Ethan Nicholas | 8e265a7 | 2018-12-12 16:22:40 -0500 | [diff] [blame] | 859 | GrVkCommandPool* cmdPool) { |
Greg Daniel | 070cbaf | 2019-01-03 17:35:54 -0500 | [diff] [blame] | 860 | SkASSERT(cmdPool); |
egdaniel | 9a6cf80 | 2016-06-08 08:22:05 -0700 | [diff] [blame] | 861 | const VkCommandBufferAllocateInfo cmdInfo = { |
| 862 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, // sType |
Ben Wagner | a93a14a | 2017-08-28 10:34:05 -0400 | [diff] [blame] | 863 | nullptr, // pNext |
Ethan Nicholas | 8e265a7 | 2018-12-12 16:22:40 -0500 | [diff] [blame] | 864 | cmdPool->vkCommandPool(), // commandPool |
egdaniel | 9a6cf80 | 2016-06-08 08:22:05 -0700 | [diff] [blame] | 865 | VK_COMMAND_BUFFER_LEVEL_SECONDARY, // level |
| 866 | 1 // bufferCount |
| 867 | }; |
| 868 | |
| 869 | VkCommandBuffer cmdBuffer; |
| 870 | VkResult err = GR_VK_CALL(gpu->vkInterface(), AllocateCommandBuffers(gpu->device(), |
| 871 | &cmdInfo, |
| 872 | &cmdBuffer)); |
| 873 | if (err) { |
| 874 | return nullptr; |
| 875 | } |
Greg Daniel | 0addbdf | 2019-11-25 15:03:58 -0500 | [diff] [blame] | 876 | return new GrVkSecondaryCommandBuffer(cmdBuffer, false); |
egdaniel | 9a6cf80 | 2016-06-08 08:22:05 -0700 | [diff] [blame] | 877 | } |
| 878 | |
Greg Daniel | 070cbaf | 2019-01-03 17:35:54 -0500 | [diff] [blame] | 879 | GrVkSecondaryCommandBuffer* GrVkSecondaryCommandBuffer::Create(VkCommandBuffer cmdBuffer) { |
Greg Daniel | 0addbdf | 2019-11-25 15:03:58 -0500 | [diff] [blame] | 880 | return new GrVkSecondaryCommandBuffer(cmdBuffer, true); |
Greg Daniel | 070cbaf | 2019-01-03 17:35:54 -0500 | [diff] [blame] | 881 | } |
egdaniel | 9a6cf80 | 2016-06-08 08:22:05 -0700 | [diff] [blame] | 882 | |
Greg Daniel | e643da6 | 2019-11-05 12:36:42 -0500 | [diff] [blame] | 883 | void GrVkSecondaryCommandBuffer::begin(GrVkGpu* gpu, const GrVkFramebuffer* framebuffer, |
jvanverth | 7ec9241 | 2016-07-06 09:24:57 -0700 | [diff] [blame] | 884 | const GrVkRenderPass* compatibleRenderPass) { |
egdaniel | 9a6cf80 | 2016-06-08 08:22:05 -0700 | [diff] [blame] | 885 | SkASSERT(!fIsActive); |
jvanverth | 7ec9241 | 2016-07-06 09:24:57 -0700 | [diff] [blame] | 886 | SkASSERT(compatibleRenderPass); |
| 887 | fActiveRenderPass = compatibleRenderPass; |
egdaniel | 9a6cf80 | 2016-06-08 08:22:05 -0700 | [diff] [blame] | 888 | |
Greg Daniel | 070cbaf | 2019-01-03 17:35:54 -0500 | [diff] [blame] | 889 | if (!this->isWrapped()) { |
| 890 | VkCommandBufferInheritanceInfo inheritanceInfo; |
| 891 | memset(&inheritanceInfo, 0, sizeof(VkCommandBufferInheritanceInfo)); |
| 892 | inheritanceInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO; |
| 893 | inheritanceInfo.pNext = nullptr; |
| 894 | inheritanceInfo.renderPass = fActiveRenderPass->vkRenderPass(); |
| 895 | inheritanceInfo.subpass = 0; // Currently only using 1 subpass for each render pass |
| 896 | inheritanceInfo.framebuffer = framebuffer ? framebuffer->framebuffer() : VK_NULL_HANDLE; |
| 897 | inheritanceInfo.occlusionQueryEnable = false; |
| 898 | inheritanceInfo.queryFlags = 0; |
| 899 | inheritanceInfo.pipelineStatistics = 0; |
egdaniel | 9a6cf80 | 2016-06-08 08:22:05 -0700 | [diff] [blame] | 900 | |
Greg Daniel | 070cbaf | 2019-01-03 17:35:54 -0500 | [diff] [blame] | 901 | VkCommandBufferBeginInfo cmdBufferBeginInfo; |
| 902 | memset(&cmdBufferBeginInfo, 0, sizeof(VkCommandBufferBeginInfo)); |
| 903 | cmdBufferBeginInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 904 | cmdBufferBeginInfo.pNext = nullptr; |
| 905 | cmdBufferBeginInfo.flags = VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT | |
| 906 | VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT; |
| 907 | cmdBufferBeginInfo.pInheritanceInfo = &inheritanceInfo; |
egdaniel | 9a6cf80 | 2016-06-08 08:22:05 -0700 | [diff] [blame] | 908 | |
Greg Daniel | e643da6 | 2019-11-05 12:36:42 -0500 | [diff] [blame] | 909 | GR_VK_CALL_ERRCHECK(gpu, BeginCommandBuffer(fCmdBuffer, &cmdBufferBeginInfo)); |
Greg Daniel | 070cbaf | 2019-01-03 17:35:54 -0500 | [diff] [blame] | 910 | } |
egdaniel | 9a6cf80 | 2016-06-08 08:22:05 -0700 | [diff] [blame] | 911 | fIsActive = true; |
| 912 | } |
| 913 | |
Ethan Nicholas | 8e265a7 | 2018-12-12 16:22:40 -0500 | [diff] [blame] | 914 | void GrVkSecondaryCommandBuffer::end(GrVkGpu* gpu) { |
egdaniel | 9a6cf80 | 2016-06-08 08:22:05 -0700 | [diff] [blame] | 915 | SkASSERT(fIsActive); |
Greg Daniel | 070cbaf | 2019-01-03 17:35:54 -0500 | [diff] [blame] | 916 | if (!this->isWrapped()) { |
Greg Daniel | e643da6 | 2019-11-05 12:36:42 -0500 | [diff] [blame] | 917 | GR_VK_CALL_ERRCHECK(gpu, EndCommandBuffer(fCmdBuffer)); |
Greg Daniel | 070cbaf | 2019-01-03 17:35:54 -0500 | [diff] [blame] | 918 | } |
egdaniel | 9a6cf80 | 2016-06-08 08:22:05 -0700 | [diff] [blame] | 919 | this->invalidateState(); |
| 920 | fIsActive = false; |
Robert Phillips | 04d2ce2 | 2019-04-03 13:20:43 -0400 | [diff] [blame] | 921 | fHasWork = false; |
egdaniel | 9a6cf80 | 2016-06-08 08:22:05 -0700 | [diff] [blame] | 922 | } |
Greg Daniel | 8daf3b7 | 2019-07-30 09:57:26 -0400 | [diff] [blame] | 923 | |
Greg Daniel | 0addbdf | 2019-11-25 15:03:58 -0500 | [diff] [blame] | 924 | void GrVkSecondaryCommandBuffer::recycle(GrVkCommandPool* cmdPool) { |
Greg Daniel | 8daf3b7 | 2019-07-30 09:57:26 -0400 | [diff] [blame] | 925 | if (this->isWrapped()) { |
Greg Daniel | 8daf3b7 | 2019-07-30 09:57:26 -0400 | [diff] [blame] | 926 | delete this; |
| 927 | } else { |
Greg Daniel | 0addbdf | 2019-11-25 15:03:58 -0500 | [diff] [blame] | 928 | cmdPool->recycleSecondaryCommandBuffer(this); |
Greg Daniel | 8daf3b7 | 2019-07-30 09:57:26 -0400 | [diff] [blame] | 929 | } |
| 930 | } |
| 931 | |