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