egdaniel | 066df7c | 2016-06-08 14:02:27 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
| 8 | #include "GrVkGpuCommandBuffer.h" |
| 9 | |
csmartdalton | 29df760 | 2016-08-31 11:55:52 -0700 | [diff] [blame] | 10 | #include "GrFixedClip.h" |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 11 | #include "GrMesh.h" |
Brian Salomon | 742e31d | 2016-12-07 17:06:19 -0500 | [diff] [blame] | 12 | #include "GrOpFlushState.h" |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 13 | #include "GrPipeline.h" |
| 14 | #include "GrRenderTargetPriv.h" |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 15 | #include "GrTexturePriv.h" |
egdaniel | 066df7c | 2016-06-08 14:02:27 -0700 | [diff] [blame] | 16 | #include "GrVkCommandBuffer.h" |
| 17 | #include "GrVkGpu.h" |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 18 | #include "GrVkPipeline.h" |
egdaniel | 066df7c | 2016-06-08 14:02:27 -0700 | [diff] [blame] | 19 | #include "GrVkRenderPass.h" |
| 20 | #include "GrVkRenderTarget.h" |
| 21 | #include "GrVkResourceProvider.h" |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 22 | #include "GrVkTexture.h" |
Greg Daniel | 36a77ee | 2016-10-18 10:33:25 -0400 | [diff] [blame] | 23 | #include "SkRect.h" |
egdaniel | 066df7c | 2016-06-08 14:02:27 -0700 | [diff] [blame] | 24 | |
Robert Phillips | b0e93a2 | 2017-08-29 08:26:54 -0400 | [diff] [blame] | 25 | void GrVkGpuTextureCommandBuffer::copy(GrSurface* src, GrSurfaceOrigin srcOrigin, |
| 26 | const SkIRect& srcRect, const SkIPoint& dstPoint) { |
| 27 | fCopies.emplace_back(src, srcOrigin, srcRect, dstPoint); |
Greg Daniel | 500d58b | 2017-08-24 15:59:33 -0400 | [diff] [blame] | 28 | } |
| 29 | |
| 30 | void GrVkGpuTextureCommandBuffer::insertEventMarker(const char* msg) { |
| 31 | // TODO: does Vulkan have a correlate? |
| 32 | } |
| 33 | |
| 34 | void GrVkGpuTextureCommandBuffer::submit() { |
| 35 | for (int i = 0; i < fCopies.count(); ++i) { |
| 36 | CopyInfo& copyInfo = fCopies[i]; |
Robert Phillips | b0e93a2 | 2017-08-29 08:26:54 -0400 | [diff] [blame] | 37 | fGpu->copySurface(fTexture, fOrigin, copyInfo.fSrc, copyInfo.fSrcOrigin, copyInfo.fSrcRect, |
| 38 | copyInfo.fDstPoint); |
Greg Daniel | 500d58b | 2017-08-24 15:59:33 -0400 | [diff] [blame] | 39 | } |
| 40 | } |
| 41 | |
| 42 | GrVkGpuTextureCommandBuffer::~GrVkGpuTextureCommandBuffer() {} |
| 43 | |
| 44 | //////////////////////////////////////////////////////////////////////////////// |
| 45 | |
Robert Phillips | 6b47c7d | 2017-08-29 07:24:09 -0400 | [diff] [blame] | 46 | void get_vk_load_store_ops(GrLoadOp loadOpIn, GrStoreOp storeOpIn, |
egdaniel | 066df7c | 2016-06-08 14:02:27 -0700 | [diff] [blame] | 47 | VkAttachmentLoadOp* loadOp, VkAttachmentStoreOp* storeOp) { |
Robert Phillips | 9521447 | 2017-08-08 18:00:03 -0400 | [diff] [blame] | 48 | switch (loadOpIn) { |
Robert Phillips | 6b47c7d | 2017-08-29 07:24:09 -0400 | [diff] [blame] | 49 | case GrLoadOp::kLoad: |
egdaniel | 066df7c | 2016-06-08 14:02:27 -0700 | [diff] [blame] | 50 | *loadOp = VK_ATTACHMENT_LOAD_OP_LOAD; |
egdaniel | 066df7c | 2016-06-08 14:02:27 -0700 | [diff] [blame] | 51 | break; |
Robert Phillips | 6b47c7d | 2017-08-29 07:24:09 -0400 | [diff] [blame] | 52 | case GrLoadOp::kClear: |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 53 | *loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR; |
| 54 | break; |
Robert Phillips | 6b47c7d | 2017-08-29 07:24:09 -0400 | [diff] [blame] | 55 | case GrLoadOp::kDiscard: |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 56 | *loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE; |
| 57 | break; |
| 58 | default: |
| 59 | SK_ABORT("Invalid LoadOp"); |
egdaniel | 066df7c | 2016-06-08 14:02:27 -0700 | [diff] [blame] | 60 | *loadOp = VK_ATTACHMENT_LOAD_OP_LOAD; |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 61 | } |
| 62 | |
Robert Phillips | 9521447 | 2017-08-08 18:00:03 -0400 | [diff] [blame] | 63 | switch (storeOpIn) { |
Robert Phillips | 6b47c7d | 2017-08-29 07:24:09 -0400 | [diff] [blame] | 64 | case GrStoreOp::kStore: |
egdaniel | 066df7c | 2016-06-08 14:02:27 -0700 | [diff] [blame] | 65 | *storeOp = VK_ATTACHMENT_STORE_OP_STORE; |
| 66 | break; |
Robert Phillips | 6b47c7d | 2017-08-29 07:24:09 -0400 | [diff] [blame] | 67 | case GrStoreOp::kDiscard: |
egdaniel | 066df7c | 2016-06-08 14:02:27 -0700 | [diff] [blame] | 68 | *storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE; |
| 69 | break; |
brianosman | 0bbc371 | 2016-06-14 04:53:09 -0700 | [diff] [blame] | 70 | default: |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 71 | SK_ABORT("Invalid StoreOp"); |
brianosman | 0bbc371 | 2016-06-14 04:53:09 -0700 | [diff] [blame] | 72 | *storeOp = VK_ATTACHMENT_STORE_OP_STORE; |
egdaniel | 066df7c | 2016-06-08 14:02:27 -0700 | [diff] [blame] | 73 | } |
| 74 | } |
| 75 | |
Greg Daniel | 500d58b | 2017-08-24 15:59:33 -0400 | [diff] [blame] | 76 | GrVkGpuRTCommandBuffer::GrVkGpuRTCommandBuffer(GrVkGpu* gpu, |
| 77 | GrRenderTarget* rt, GrSurfaceOrigin origin, |
| 78 | const LoadAndStoreInfo& colorInfo, |
| 79 | const StencilLoadAndStoreInfo& stencilInfo) |
Robert Phillips | 19e51dc | 2017-08-09 09:30:51 -0400 | [diff] [blame] | 80 | : INHERITED(rt, origin) |
| 81 | , fGpu(gpu) |
| 82 | , fClearColor(GrColor4f::FromGrColor(colorInfo.fClearColor)) |
| 83 | , fLastPipelineState(nullptr) { |
Robert Phillips | 9521447 | 2017-08-08 18:00:03 -0400 | [diff] [blame] | 84 | get_vk_load_store_ops(colorInfo.fLoadOp, colorInfo.fStoreOp, |
| 85 | &fVkColorLoadOp, &fVkColorStoreOp); |
egdaniel | 066df7c | 2016-06-08 14:02:27 -0700 | [diff] [blame] | 86 | |
Robert Phillips | 9521447 | 2017-08-08 18:00:03 -0400 | [diff] [blame] | 87 | get_vk_load_store_ops(stencilInfo.fLoadOp, stencilInfo.fStoreOp, |
| 88 | &fVkStencilLoadOp, &fVkStencilStoreOp); |
Greg Daniel | 22bc865 | 2017-03-22 15:45:43 -0400 | [diff] [blame] | 89 | fCurrentCmdInfo = -1; |
Robert Phillips | 9521447 | 2017-08-08 18:00:03 -0400 | [diff] [blame] | 90 | |
Robert Phillips | 19e51dc | 2017-08-09 09:30:51 -0400 | [diff] [blame] | 91 | this->init(); |
Brian Salomon | c293a29 | 2016-11-30 13:38:32 -0500 | [diff] [blame] | 92 | } |
| 93 | |
Greg Daniel | 500d58b | 2017-08-24 15:59:33 -0400 | [diff] [blame] | 94 | void GrVkGpuRTCommandBuffer::init() { |
Brian Salomon | c293a29 | 2016-11-30 13:38:32 -0500 | [diff] [blame] | 95 | GrVkRenderPass::LoadStoreOps vkColorOps(fVkColorLoadOp, fVkColorStoreOp); |
| 96 | GrVkRenderPass::LoadStoreOps vkStencilOps(fVkStencilLoadOp, fVkStencilStoreOp); |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 97 | |
Greg Daniel | 36a77ee | 2016-10-18 10:33:25 -0400 | [diff] [blame] | 98 | CommandBufferInfo& cbInfo = fCommandBufferInfos.push_back(); |
Brian Salomon | c293a29 | 2016-11-30 13:38:32 -0500 | [diff] [blame] | 99 | SkASSERT(fCommandBufferInfos.count() == 1); |
Greg Daniel | 22bc865 | 2017-03-22 15:45:43 -0400 | [diff] [blame] | 100 | fCurrentCmdInfo = 0; |
Greg Daniel | 36a77ee | 2016-10-18 10:33:25 -0400 | [diff] [blame] | 101 | |
Robert Phillips | 19e51dc | 2017-08-09 09:30:51 -0400 | [diff] [blame] | 102 | GrVkRenderTarget* vkRT = static_cast<GrVkRenderTarget*>(fRenderTarget); |
| 103 | const GrVkResourceProvider::CompatibleRPHandle& rpHandle = vkRT->compatibleRenderPassHandle(); |
egdaniel | 066df7c | 2016-06-08 14:02:27 -0700 | [diff] [blame] | 104 | if (rpHandle.isValid()) { |
Greg Daniel | 36a77ee | 2016-10-18 10:33:25 -0400 | [diff] [blame] | 105 | cbInfo.fRenderPass = fGpu->resourceProvider().findRenderPass(rpHandle, |
| 106 | vkColorOps, |
| 107 | vkStencilOps); |
egdaniel | 066df7c | 2016-06-08 14:02:27 -0700 | [diff] [blame] | 108 | } else { |
Robert Phillips | 19e51dc | 2017-08-09 09:30:51 -0400 | [diff] [blame] | 109 | cbInfo.fRenderPass = fGpu->resourceProvider().findRenderPass(*vkRT, |
Greg Daniel | 36a77ee | 2016-10-18 10:33:25 -0400 | [diff] [blame] | 110 | vkColorOps, |
| 111 | vkStencilOps); |
egdaniel | 066df7c | 2016-06-08 14:02:27 -0700 | [diff] [blame] | 112 | } |
| 113 | |
Brian Salomon | c293a29 | 2016-11-30 13:38:32 -0500 | [diff] [blame] | 114 | cbInfo.fColorClearValue.color.float32[0] = fClearColor.fRGBA[0]; |
| 115 | cbInfo.fColorClearValue.color.float32[1] = fClearColor.fRGBA[1]; |
| 116 | cbInfo.fColorClearValue.color.float32[2] = fClearColor.fRGBA[2]; |
| 117 | cbInfo.fColorClearValue.color.float32[3] = fClearColor.fRGBA[3]; |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 118 | |
Robert Phillips | 380b90c | 2017-08-30 07:41:07 -0400 | [diff] [blame] | 119 | if (VK_ATTACHMENT_LOAD_OP_CLEAR == fVkColorLoadOp) { |
| 120 | cbInfo.fBounds = SkRect::MakeWH(vkRT->width(), vkRT->height()); |
| 121 | } else { |
| 122 | cbInfo.fBounds.setEmpty(); |
| 123 | } |
Greg Daniel | a3c68df | 2018-03-16 13:46:53 -0400 | [diff] [blame] | 124 | |
| 125 | if (VK_ATTACHMENT_LOAD_OP_CLEAR == fVkColorLoadOp) { |
| 126 | cbInfo.fLoadStoreState = LoadStoreState::kStartsWithClear; |
| 127 | } else if (VK_ATTACHMENT_LOAD_OP_LOAD == fVkColorLoadOp && |
| 128 | VK_ATTACHMENT_STORE_OP_STORE == fVkColorStoreOp) { |
| 129 | cbInfo.fLoadStoreState = LoadStoreState::kLoadAndStore; |
| 130 | } else if (VK_ATTACHMENT_LOAD_OP_DONT_CARE == fVkColorLoadOp) { |
| 131 | cbInfo.fLoadStoreState = LoadStoreState::kStartsWithDiscard; |
| 132 | } |
Greg Daniel | 36a77ee | 2016-10-18 10:33:25 -0400 | [diff] [blame] | 133 | |
Greg Daniel | 22bc865 | 2017-03-22 15:45:43 -0400 | [diff] [blame] | 134 | cbInfo.fCommandBuffers.push_back(fGpu->resourceProvider().findOrCreateSecondaryCommandBuffer()); |
Robert Phillips | 19e51dc | 2017-08-09 09:30:51 -0400 | [diff] [blame] | 135 | cbInfo.currentCmdBuf()->begin(fGpu, vkRT->framebuffer(), cbInfo.fRenderPass); |
egdaniel | 066df7c | 2016-06-08 14:02:27 -0700 | [diff] [blame] | 136 | } |
| 137 | |
Brian Salomon | c293a29 | 2016-11-30 13:38:32 -0500 | [diff] [blame] | 138 | |
Greg Daniel | 500d58b | 2017-08-24 15:59:33 -0400 | [diff] [blame] | 139 | GrVkGpuRTCommandBuffer::~GrVkGpuRTCommandBuffer() { |
Greg Daniel | 36a77ee | 2016-10-18 10:33:25 -0400 | [diff] [blame] | 140 | for (int i = 0; i < fCommandBufferInfos.count(); ++i) { |
| 141 | CommandBufferInfo& cbInfo = fCommandBufferInfos[i]; |
Greg Daniel | 22bc865 | 2017-03-22 15:45:43 -0400 | [diff] [blame] | 142 | for (int j = 0; j < cbInfo.fCommandBuffers.count(); ++j) { |
| 143 | cbInfo.fCommandBuffers[j]->unref(fGpu); |
| 144 | } |
Greg Daniel | 36a77ee | 2016-10-18 10:33:25 -0400 | [diff] [blame] | 145 | cbInfo.fRenderPass->unref(fGpu); |
| 146 | } |
egdaniel | 066df7c | 2016-06-08 14:02:27 -0700 | [diff] [blame] | 147 | } |
| 148 | |
Greg Daniel | 500d58b | 2017-08-24 15:59:33 -0400 | [diff] [blame] | 149 | GrGpu* GrVkGpuRTCommandBuffer::gpu() { return fGpu; } |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 150 | |
Greg Daniel | 500d58b | 2017-08-24 15:59:33 -0400 | [diff] [blame] | 151 | void GrVkGpuRTCommandBuffer::end() { |
Greg Daniel | 22bc865 | 2017-03-22 15:45:43 -0400 | [diff] [blame] | 152 | if (fCurrentCmdInfo >= 0) { |
| 153 | fCommandBufferInfos[fCurrentCmdInfo].currentCmdBuf()->end(fGpu); |
Brian Salomon | c293a29 | 2016-11-30 13:38:32 -0500 | [diff] [blame] | 154 | } |
egdaniel | 066df7c | 2016-06-08 14:02:27 -0700 | [diff] [blame] | 155 | } |
| 156 | |
Greg Daniel | 500d58b | 2017-08-24 15:59:33 -0400 | [diff] [blame] | 157 | void GrVkGpuRTCommandBuffer::submit() { |
Brian Salomon | c293a29 | 2016-11-30 13:38:32 -0500 | [diff] [blame] | 158 | if (!fRenderTarget) { |
| 159 | return; |
| 160 | } |
Robert Phillips | 19e51dc | 2017-08-09 09:30:51 -0400 | [diff] [blame] | 161 | |
| 162 | GrVkRenderTarget* vkRT = static_cast<GrVkRenderTarget*>(fRenderTarget); |
Robert Phillips | 19e51dc | 2017-08-09 09:30:51 -0400 | [diff] [blame] | 163 | GrVkImage* targetImage = vkRT->msaaImage() ? vkRT->msaaImage() : vkRT; |
Greg Daniel | 45a44de | 2018-02-27 10:07:29 -0500 | [diff] [blame] | 164 | GrStencilAttachment* stencil = fRenderTarget->renderTargetPriv().getStencilAttachment(); |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 165 | |
Greg Daniel | 36a77ee | 2016-10-18 10:33:25 -0400 | [diff] [blame] | 166 | for (int i = 0; i < fCommandBufferInfos.count(); ++i) { |
| 167 | CommandBufferInfo& cbInfo = fCommandBufferInfos[i]; |
| 168 | |
Greg Daniel | 77b53f6 | 2016-10-18 11:48:51 -0400 | [diff] [blame] | 169 | for (int j = 0; j < cbInfo.fPreDrawUploads.count(); ++j) { |
| 170 | InlineUploadInfo& iuInfo = cbInfo.fPreDrawUploads[j]; |
| 171 | iuInfo.fFlushState->doUpload(iuInfo.fUpload); |
| 172 | } |
| 173 | |
Greg Daniel | 500d58b | 2017-08-24 15:59:33 -0400 | [diff] [blame] | 174 | for (int j = 0; j < cbInfo.fPreCopies.count(); ++j) { |
| 175 | CopyInfo& copyInfo = cbInfo.fPreCopies[j]; |
Robert Phillips | b0e93a2 | 2017-08-29 08:26:54 -0400 | [diff] [blame] | 176 | fGpu->copySurface(fRenderTarget, fOrigin, copyInfo.fSrc, copyInfo.fSrcOrigin, |
Greg Daniel | 55fa647 | 2018-03-16 16:13:10 -0400 | [diff] [blame] | 177 | copyInfo.fSrcRect, copyInfo.fDstPoint, copyInfo.fShouldDiscardDst); |
Greg Daniel | 500d58b | 2017-08-24 15:59:33 -0400 | [diff] [blame] | 178 | } |
| 179 | |
Greg Daniel | 45a44de | 2018-02-27 10:07:29 -0500 | [diff] [blame] | 180 | |
Greg Daniel | 38c3d93 | 2018-03-16 14:22:30 -0400 | [diff] [blame] | 181 | // TODO: Many things create a scratch texture which adds the discard immediately, but then |
| 182 | // don't draw to it right away. This causes the discard to be ignored and we get yelled at |
| 183 | // for loading uninitialized data. However, once MDB lands with reordering, the discard will |
| 184 | // get reordered with the rest of the draw commands and we can remove the discard check. |
| 185 | if (cbInfo.fIsEmpty && |
| 186 | cbInfo.fLoadStoreState != LoadStoreState::kStartsWithClear && |
| 187 | cbInfo.fLoadStoreState != LoadStoreState::kStartsWithDiscard) { |
Greg Daniel | 77b53f6 | 2016-10-18 11:48:51 -0400 | [diff] [blame] | 188 | // We have sumbitted no actual draw commands to the command buffer and we are not using |
| 189 | // the render pass to do a clear so there is no need to submit anything. |
| 190 | continue; |
| 191 | } |
Greg Daniel | 38c3d93 | 2018-03-16 14:22:30 -0400 | [diff] [blame] | 192 | |
Greg Daniel | dbdba60 | 2018-04-20 11:52:43 -0400 | [diff] [blame] | 193 | // Make sure if we only have a discard load that we execute the discard on the whole image. |
| 194 | // TODO: Once we improve our tracking of discards so that we never end up flushing a discard |
| 195 | // call with no actually ops, remove this. |
| 196 | if (cbInfo.fIsEmpty && cbInfo.fLoadStoreState == LoadStoreState::kStartsWithDiscard) { |
| 197 | cbInfo.fBounds = SkRect::MakeWH(vkRT->width(), vkRT->height()); |
| 198 | } |
| 199 | |
Greg Daniel | 36a77ee | 2016-10-18 10:33:25 -0400 | [diff] [blame] | 200 | if (cbInfo.fBounds.intersect(0, 0, |
| 201 | SkIntToScalar(fRenderTarget->width()), |
| 202 | SkIntToScalar(fRenderTarget->height()))) { |
Greg Daniel | 38c3d93 | 2018-03-16 14:22:30 -0400 | [diff] [blame] | 203 | // Make sure we do the following layout changes after all copies, uploads, or any other |
| 204 | // pre-work is done since we may change the layouts in the pre-work. Also since the |
| 205 | // draws will be submitted in different render passes, we need to guard againts write |
| 206 | // and write issues. |
| 207 | |
| 208 | // Change layout of our render target so it can be used as the color attachment. |
| 209 | targetImage->setImageLayout(fGpu, |
| 210 | VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, |
| 211 | VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, |
| 212 | VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, |
| 213 | false); |
| 214 | |
| 215 | // If we are using a stencil attachment we also need to update its layout |
| 216 | if (stencil) { |
| 217 | GrVkStencilAttachment* vkStencil = (GrVkStencilAttachment*)stencil; |
| 218 | vkStencil->setImageLayout(fGpu, |
| 219 | VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, |
| 220 | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT | |
| 221 | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT, |
| 222 | VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, |
| 223 | false); |
| 224 | } |
| 225 | |
| 226 | // If we have any sampled images set their layout now. |
| 227 | for (int j = 0; j < cbInfo.fSampledImages.count(); ++j) { |
| 228 | cbInfo.fSampledImages[j]->setImageLayout(fGpu, |
| 229 | VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, |
| 230 | VK_ACCESS_SHADER_READ_BIT, |
| 231 | VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, |
| 232 | false); |
| 233 | } |
| 234 | |
Greg Daniel | 36a77ee | 2016-10-18 10:33:25 -0400 | [diff] [blame] | 235 | SkIRect iBounds; |
| 236 | cbInfo.fBounds.roundOut(&iBounds); |
| 237 | |
Greg Daniel | 22bc865 | 2017-03-22 15:45:43 -0400 | [diff] [blame] | 238 | fGpu->submitSecondaryCommandBuffer(cbInfo.fCommandBuffers, cbInfo.fRenderPass, |
Robert Phillips | b0e93a2 | 2017-08-29 08:26:54 -0400 | [diff] [blame] | 239 | &cbInfo.fColorClearValue, vkRT, fOrigin, iBounds); |
Greg Daniel | 36a77ee | 2016-10-18 10:33:25 -0400 | [diff] [blame] | 240 | } |
| 241 | } |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 242 | } |
| 243 | |
Greg Daniel | 500d58b | 2017-08-24 15:59:33 -0400 | [diff] [blame] | 244 | void GrVkGpuRTCommandBuffer::discard() { |
Robert Phillips | 19e51dc | 2017-08-09 09:30:51 -0400 | [diff] [blame] | 245 | GrVkRenderTarget* vkRT = static_cast<GrVkRenderTarget*>(fRenderTarget); |
Brian Salomon | c293a29 | 2016-11-30 13:38:32 -0500 | [diff] [blame] | 246 | |
Greg Daniel | 22bc865 | 2017-03-22 15:45:43 -0400 | [diff] [blame] | 247 | CommandBufferInfo& cbInfo = fCommandBufferInfos[fCurrentCmdInfo]; |
Greg Daniel | 77b53f6 | 2016-10-18 11:48:51 -0400 | [diff] [blame] | 248 | if (cbInfo.fIsEmpty) { |
Robert Phillips | 74c627f | 2017-08-09 10:28:00 -0400 | [diff] [blame] | 249 | // Change the render pass to do a don't-care load for both color & stencil |
egdaniel | 37535c9 | 2016-06-30 08:23:30 -0700 | [diff] [blame] | 250 | GrVkRenderPass::LoadStoreOps vkColorOps(VK_ATTACHMENT_LOAD_OP_DONT_CARE, |
| 251 | VK_ATTACHMENT_STORE_OP_STORE); |
| 252 | GrVkRenderPass::LoadStoreOps vkStencilOps(VK_ATTACHMENT_LOAD_OP_DONT_CARE, |
| 253 | VK_ATTACHMENT_STORE_OP_STORE); |
egdaniel | 37535c9 | 2016-06-30 08:23:30 -0700 | [diff] [blame] | 254 | |
Greg Daniel | 36a77ee | 2016-10-18 10:33:25 -0400 | [diff] [blame] | 255 | const GrVkRenderPass* oldRP = cbInfo.fRenderPass; |
egdaniel | 37535c9 | 2016-06-30 08:23:30 -0700 | [diff] [blame] | 256 | |
egdaniel | 37535c9 | 2016-06-30 08:23:30 -0700 | [diff] [blame] | 257 | const GrVkResourceProvider::CompatibleRPHandle& rpHandle = |
Robert Phillips | 19e51dc | 2017-08-09 09:30:51 -0400 | [diff] [blame] | 258 | vkRT->compatibleRenderPassHandle(); |
egdaniel | 37535c9 | 2016-06-30 08:23:30 -0700 | [diff] [blame] | 259 | if (rpHandle.isValid()) { |
Greg Daniel | 36a77ee | 2016-10-18 10:33:25 -0400 | [diff] [blame] | 260 | cbInfo.fRenderPass = fGpu->resourceProvider().findRenderPass(rpHandle, |
| 261 | vkColorOps, |
| 262 | vkStencilOps); |
egdaniel | 37535c9 | 2016-06-30 08:23:30 -0700 | [diff] [blame] | 263 | } else { |
Robert Phillips | 19e51dc | 2017-08-09 09:30:51 -0400 | [diff] [blame] | 264 | cbInfo.fRenderPass = fGpu->resourceProvider().findRenderPass(*vkRT, |
Greg Daniel | 36a77ee | 2016-10-18 10:33:25 -0400 | [diff] [blame] | 265 | vkColorOps, |
| 266 | vkStencilOps); |
egdaniel | 37535c9 | 2016-06-30 08:23:30 -0700 | [diff] [blame] | 267 | } |
| 268 | |
Greg Daniel | 36a77ee | 2016-10-18 10:33:25 -0400 | [diff] [blame] | 269 | SkASSERT(cbInfo.fRenderPass->isCompatible(*oldRP)); |
egdaniel | 37535c9 | 2016-06-30 08:23:30 -0700 | [diff] [blame] | 270 | oldRP->unref(fGpu); |
Greg Daniel | 5011f85 | 2016-10-28 15:07:16 -0400 | [diff] [blame] | 271 | cbInfo.fBounds.join(fRenderTarget->getBoundsRect()); |
Greg Daniel | a3c68df | 2018-03-16 13:46:53 -0400 | [diff] [blame] | 272 | cbInfo.fLoadStoreState = LoadStoreState::kStartsWithDiscard; |
| 273 | // If we are going to discard the whole render target then the results of any copies we did |
| 274 | // immediately before to the target won't matter, so just drop them. |
| 275 | cbInfo.fPreCopies.reset(); |
egdaniel | 37535c9 | 2016-06-30 08:23:30 -0700 | [diff] [blame] | 276 | } |
| 277 | } |
| 278 | |
Greg Daniel | 500d58b | 2017-08-24 15:59:33 -0400 | [diff] [blame] | 279 | void GrVkGpuRTCommandBuffer::insertEventMarker(const char* msg) { |
Robert Phillips | 65a88fa | 2017-08-08 08:36:22 -0400 | [diff] [blame] | 280 | // TODO: does Vulkan have a correlate? |
| 281 | } |
| 282 | |
Greg Daniel | 500d58b | 2017-08-24 15:59:33 -0400 | [diff] [blame] | 283 | void GrVkGpuRTCommandBuffer::onClearStencilClip(const GrFixedClip& clip, bool insideStencilMask) { |
Chris Dalton | 94c0468 | 2017-11-01 17:15:06 -0600 | [diff] [blame] | 284 | SkASSERT(!clip.hasWindowRectangles()); |
| 285 | |
Jim Van Verth | 6a40abc | 2017-11-02 16:56:09 +0000 | [diff] [blame] | 286 | CommandBufferInfo& cbInfo = fCommandBufferInfos[fCurrentCmdInfo]; |
| 287 | |
Greg Daniel | 65a0927 | 2016-10-12 09:47:22 -0400 | [diff] [blame] | 288 | GrStencilAttachment* sb = fRenderTarget->renderTargetPriv().getStencilAttachment(); |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 289 | // this should only be called internally when we know we have a |
| 290 | // stencil buffer. |
| 291 | SkASSERT(sb); |
| 292 | int stencilBitCount = sb->bits(); |
| 293 | |
| 294 | // The contract with the callers does not guarantee that we preserve all bits in the stencil |
| 295 | // during this clear. Thus we will clear the entire stencil to the desired value. |
| 296 | |
| 297 | VkClearDepthStencilValue vkStencilColor; |
| 298 | memset(&vkStencilColor, 0, sizeof(VkClearDepthStencilValue)); |
csmartdalton | 29df760 | 2016-08-31 11:55:52 -0700 | [diff] [blame] | 299 | if (insideStencilMask) { |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 300 | vkStencilColor.stencil = (1 << (stencilBitCount - 1)); |
| 301 | } else { |
| 302 | vkStencilColor.stencil = 0; |
| 303 | } |
| 304 | |
| 305 | VkClearRect clearRect; |
| 306 | // Flip rect if necessary |
csmartdalton | 29df760 | 2016-08-31 11:55:52 -0700 | [diff] [blame] | 307 | SkIRect vkRect; |
Brian Salomon | d818ebf | 2018-07-02 14:08:49 +0000 | [diff] [blame] | 308 | if (!clip.scissorEnabled()) { |
Greg Daniel | 65a0927 | 2016-10-12 09:47:22 -0400 | [diff] [blame] | 309 | vkRect.setXYWH(0, 0, fRenderTarget->width(), fRenderTarget->height()); |
Robert Phillips | 4f101a7 | 2017-07-28 08:42:04 -0400 | [diff] [blame] | 310 | } else if (kBottomLeft_GrSurfaceOrigin != fOrigin) { |
csmartdalton | 29df760 | 2016-08-31 11:55:52 -0700 | [diff] [blame] | 311 | vkRect = clip.scissorRect(); |
| 312 | } else { |
| 313 | const SkIRect& scissor = clip.scissorRect(); |
Greg Daniel | 65a0927 | 2016-10-12 09:47:22 -0400 | [diff] [blame] | 314 | vkRect.setLTRB(scissor.fLeft, fRenderTarget->height() - scissor.fBottom, |
| 315 | scissor.fRight, fRenderTarget->height() - scissor.fTop); |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 316 | } |
| 317 | |
| 318 | clearRect.rect.offset = { vkRect.fLeft, vkRect.fTop }; |
| 319 | clearRect.rect.extent = { (uint32_t)vkRect.width(), (uint32_t)vkRect.height() }; |
| 320 | |
| 321 | clearRect.baseArrayLayer = 0; |
| 322 | clearRect.layerCount = 1; |
| 323 | |
| 324 | uint32_t stencilIndex; |
Greg Daniel | 36a77ee | 2016-10-18 10:33:25 -0400 | [diff] [blame] | 325 | SkAssertResult(cbInfo.fRenderPass->stencilAttachmentIndex(&stencilIndex)); |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 326 | |
| 327 | VkClearAttachment attachment; |
| 328 | attachment.aspectMask = VK_IMAGE_ASPECT_STENCIL_BIT; |
| 329 | attachment.colorAttachment = 0; // this value shouldn't matter |
| 330 | attachment.clearValue.depthStencil = vkStencilColor; |
| 331 | |
Greg Daniel | 22bc865 | 2017-03-22 15:45:43 -0400 | [diff] [blame] | 332 | cbInfo.currentCmdBuf()->clearAttachments(fGpu, 1, &attachment, 1, &clearRect); |
Greg Daniel | 77b53f6 | 2016-10-18 11:48:51 -0400 | [diff] [blame] | 333 | cbInfo.fIsEmpty = false; |
Greg Daniel | 36a77ee | 2016-10-18 10:33:25 -0400 | [diff] [blame] | 334 | |
| 335 | // Update command buffer bounds |
Brian Salomon | d818ebf | 2018-07-02 14:08:49 +0000 | [diff] [blame] | 336 | if (!clip.scissorEnabled()) { |
Greg Daniel | 36a77ee | 2016-10-18 10:33:25 -0400 | [diff] [blame] | 337 | cbInfo.fBounds.join(fRenderTarget->getBoundsRect()); |
| 338 | } else { |
| 339 | cbInfo.fBounds.join(SkRect::Make(clip.scissorRect())); |
| 340 | } |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 341 | } |
| 342 | |
Greg Daniel | 500d58b | 2017-08-24 15:59:33 -0400 | [diff] [blame] | 343 | void GrVkGpuRTCommandBuffer::onClear(const GrFixedClip& clip, GrColor color) { |
Robert Phillips | 19e51dc | 2017-08-09 09:30:51 -0400 | [diff] [blame] | 344 | GrVkRenderTarget* vkRT = static_cast<GrVkRenderTarget*>(fRenderTarget); |
| 345 | |
Jim Van Verth | 6a40abc | 2017-11-02 16:56:09 +0000 | [diff] [blame] | 346 | // parent class should never let us get here with no RT |
csmartdalton | bf4a8f9 | 2016-09-06 10:01:06 -0700 | [diff] [blame] | 347 | SkASSERT(!clip.hasWindowRectangles()); |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 348 | |
Greg Daniel | 22bc865 | 2017-03-22 15:45:43 -0400 | [diff] [blame] | 349 | CommandBufferInfo& cbInfo = fCommandBufferInfos[fCurrentCmdInfo]; |
Greg Daniel | 36a77ee | 2016-10-18 10:33:25 -0400 | [diff] [blame] | 350 | |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 351 | VkClearColorValue vkColor; |
| 352 | GrColorToRGBAFloat(color, vkColor.float32); |
| 353 | |
Brian Salomon | d818ebf | 2018-07-02 14:08:49 +0000 | [diff] [blame] | 354 | if (cbInfo.fIsEmpty && !clip.scissorEnabled()) { |
Robert Phillips | 74c627f | 2017-08-09 10:28:00 -0400 | [diff] [blame] | 355 | // Change the render pass to do a clear load |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 356 | GrVkRenderPass::LoadStoreOps vkColorOps(VK_ATTACHMENT_LOAD_OP_CLEAR, |
| 357 | VK_ATTACHMENT_STORE_OP_STORE); |
Robert Phillips | 74c627f | 2017-08-09 10:28:00 -0400 | [diff] [blame] | 358 | // Preserve the stencil buffer's load & store settings |
| 359 | GrVkRenderPass::LoadStoreOps vkStencilOps(fVkStencilLoadOp, fVkStencilStoreOp); |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 360 | |
Greg Daniel | 36a77ee | 2016-10-18 10:33:25 -0400 | [diff] [blame] | 361 | const GrVkRenderPass* oldRP = cbInfo.fRenderPass; |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 362 | |
| 363 | const GrVkResourceProvider::CompatibleRPHandle& rpHandle = |
Robert Phillips | 19e51dc | 2017-08-09 09:30:51 -0400 | [diff] [blame] | 364 | vkRT->compatibleRenderPassHandle(); |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 365 | if (rpHandle.isValid()) { |
Greg Daniel | 36a77ee | 2016-10-18 10:33:25 -0400 | [diff] [blame] | 366 | cbInfo.fRenderPass = fGpu->resourceProvider().findRenderPass(rpHandle, |
| 367 | vkColorOps, |
| 368 | vkStencilOps); |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 369 | } else { |
Robert Phillips | 19e51dc | 2017-08-09 09:30:51 -0400 | [diff] [blame] | 370 | cbInfo.fRenderPass = fGpu->resourceProvider().findRenderPass(*vkRT, |
Greg Daniel | 36a77ee | 2016-10-18 10:33:25 -0400 | [diff] [blame] | 371 | vkColorOps, |
| 372 | vkStencilOps); |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 373 | } |
| 374 | |
Greg Daniel | 36a77ee | 2016-10-18 10:33:25 -0400 | [diff] [blame] | 375 | SkASSERT(cbInfo.fRenderPass->isCompatible(*oldRP)); |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 376 | oldRP->unref(fGpu); |
| 377 | |
Greg Daniel | 36a77ee | 2016-10-18 10:33:25 -0400 | [diff] [blame] | 378 | GrColorToRGBAFloat(color, cbInfo.fColorClearValue.color.float32); |
Greg Daniel | a3c68df | 2018-03-16 13:46:53 -0400 | [diff] [blame] | 379 | cbInfo.fLoadStoreState = LoadStoreState::kStartsWithClear; |
| 380 | // If we are going to clear the whole render target then the results of any copies we did |
| 381 | // immediately before to the target won't matter, so just drop them. |
| 382 | cbInfo.fPreCopies.reset(); |
Greg Daniel | 36a77ee | 2016-10-18 10:33:25 -0400 | [diff] [blame] | 383 | |
| 384 | // Update command buffer bounds |
| 385 | cbInfo.fBounds.join(fRenderTarget->getBoundsRect()); |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 386 | return; |
| 387 | } |
| 388 | |
| 389 | // We always do a sub rect clear with clearAttachments since we are inside a render pass |
| 390 | VkClearRect clearRect; |
| 391 | // Flip rect if necessary |
csmartdalton | 29df760 | 2016-08-31 11:55:52 -0700 | [diff] [blame] | 392 | SkIRect vkRect; |
Brian Salomon | d818ebf | 2018-07-02 14:08:49 +0000 | [diff] [blame] | 393 | if (!clip.scissorEnabled()) { |
Greg Daniel | 65a0927 | 2016-10-12 09:47:22 -0400 | [diff] [blame] | 394 | vkRect.setXYWH(0, 0, fRenderTarget->width(), fRenderTarget->height()); |
Robert Phillips | 4f101a7 | 2017-07-28 08:42:04 -0400 | [diff] [blame] | 395 | } else if (kBottomLeft_GrSurfaceOrigin != fOrigin) { |
csmartdalton | 29df760 | 2016-08-31 11:55:52 -0700 | [diff] [blame] | 396 | vkRect = clip.scissorRect(); |
| 397 | } else { |
| 398 | const SkIRect& scissor = clip.scissorRect(); |
Greg Daniel | 65a0927 | 2016-10-12 09:47:22 -0400 | [diff] [blame] | 399 | vkRect.setLTRB(scissor.fLeft, fRenderTarget->height() - scissor.fBottom, |
| 400 | scissor.fRight, fRenderTarget->height() - scissor.fTop); |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 401 | } |
| 402 | clearRect.rect.offset = { vkRect.fLeft, vkRect.fTop }; |
| 403 | clearRect.rect.extent = { (uint32_t)vkRect.width(), (uint32_t)vkRect.height() }; |
| 404 | clearRect.baseArrayLayer = 0; |
| 405 | clearRect.layerCount = 1; |
| 406 | |
| 407 | uint32_t colorIndex; |
Greg Daniel | 36a77ee | 2016-10-18 10:33:25 -0400 | [diff] [blame] | 408 | SkAssertResult(cbInfo.fRenderPass->colorAttachmentIndex(&colorIndex)); |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 409 | |
| 410 | VkClearAttachment attachment; |
| 411 | attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 412 | attachment.colorAttachment = colorIndex; |
| 413 | attachment.clearValue.color = vkColor; |
| 414 | |
Greg Daniel | 22bc865 | 2017-03-22 15:45:43 -0400 | [diff] [blame] | 415 | cbInfo.currentCmdBuf()->clearAttachments(fGpu, 1, &attachment, 1, &clearRect); |
Greg Daniel | 77b53f6 | 2016-10-18 11:48:51 -0400 | [diff] [blame] | 416 | cbInfo.fIsEmpty = false; |
Greg Daniel | 36a77ee | 2016-10-18 10:33:25 -0400 | [diff] [blame] | 417 | |
| 418 | // Update command buffer bounds |
Brian Salomon | d818ebf | 2018-07-02 14:08:49 +0000 | [diff] [blame] | 419 | if (!clip.scissorEnabled()) { |
Greg Daniel | 36a77ee | 2016-10-18 10:33:25 -0400 | [diff] [blame] | 420 | cbInfo.fBounds.join(fRenderTarget->getBoundsRect()); |
| 421 | } else { |
| 422 | cbInfo.fBounds.join(SkRect::Make(clip.scissorRect())); |
| 423 | } |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 424 | return; |
| 425 | } |
| 426 | |
Greg Daniel | 500d58b | 2017-08-24 15:59:33 -0400 | [diff] [blame] | 427 | //////////////////////////////////////////////////////////////////////////////// |
| 428 | |
| 429 | void GrVkGpuRTCommandBuffer::addAdditionalCommandBuffer() { |
Robert Phillips | 19e51dc | 2017-08-09 09:30:51 -0400 | [diff] [blame] | 430 | GrVkRenderTarget* vkRT = static_cast<GrVkRenderTarget*>(fRenderTarget); |
| 431 | |
Greg Daniel | 22bc865 | 2017-03-22 15:45:43 -0400 | [diff] [blame] | 432 | CommandBufferInfo& cbInfo = fCommandBufferInfos[fCurrentCmdInfo]; |
| 433 | cbInfo.currentCmdBuf()->end(fGpu); |
| 434 | cbInfo.fCommandBuffers.push_back(fGpu->resourceProvider().findOrCreateSecondaryCommandBuffer()); |
Robert Phillips | 19e51dc | 2017-08-09 09:30:51 -0400 | [diff] [blame] | 435 | cbInfo.currentCmdBuf()->begin(fGpu, vkRT->framebuffer(), cbInfo.fRenderPass); |
Greg Daniel | 22bc865 | 2017-03-22 15:45:43 -0400 | [diff] [blame] | 436 | } |
| 437 | |
Greg Daniel | 500d58b | 2017-08-24 15:59:33 -0400 | [diff] [blame] | 438 | void GrVkGpuRTCommandBuffer::addAdditionalRenderPass() { |
Robert Phillips | 19e51dc | 2017-08-09 09:30:51 -0400 | [diff] [blame] | 439 | GrVkRenderTarget* vkRT = static_cast<GrVkRenderTarget*>(fRenderTarget); |
| 440 | |
Greg Daniel | 22bc865 | 2017-03-22 15:45:43 -0400 | [diff] [blame] | 441 | fCommandBufferInfos[fCurrentCmdInfo].currentCmdBuf()->end(fGpu); |
Greg Daniel | 77b53f6 | 2016-10-18 11:48:51 -0400 | [diff] [blame] | 442 | |
| 443 | CommandBufferInfo& cbInfo = fCommandBufferInfos.push_back(); |
Greg Daniel | 22bc865 | 2017-03-22 15:45:43 -0400 | [diff] [blame] | 444 | fCurrentCmdInfo++; |
Greg Daniel | 77b53f6 | 2016-10-18 11:48:51 -0400 | [diff] [blame] | 445 | |
| 446 | GrVkRenderPass::LoadStoreOps vkColorOps(VK_ATTACHMENT_LOAD_OP_LOAD, |
| 447 | VK_ATTACHMENT_STORE_OP_STORE); |
| 448 | GrVkRenderPass::LoadStoreOps vkStencilOps(VK_ATTACHMENT_LOAD_OP_LOAD, |
| 449 | VK_ATTACHMENT_STORE_OP_STORE); |
| 450 | |
| 451 | const GrVkResourceProvider::CompatibleRPHandle& rpHandle = |
Robert Phillips | 19e51dc | 2017-08-09 09:30:51 -0400 | [diff] [blame] | 452 | vkRT->compatibleRenderPassHandle(); |
Greg Daniel | 77b53f6 | 2016-10-18 11:48:51 -0400 | [diff] [blame] | 453 | if (rpHandle.isValid()) { |
| 454 | cbInfo.fRenderPass = fGpu->resourceProvider().findRenderPass(rpHandle, |
| 455 | vkColorOps, |
| 456 | vkStencilOps); |
| 457 | } else { |
Robert Phillips | 19e51dc | 2017-08-09 09:30:51 -0400 | [diff] [blame] | 458 | cbInfo.fRenderPass = fGpu->resourceProvider().findRenderPass(*vkRT, |
Greg Daniel | 77b53f6 | 2016-10-18 11:48:51 -0400 | [diff] [blame] | 459 | vkColorOps, |
| 460 | vkStencilOps); |
| 461 | } |
Greg Daniel | a3c68df | 2018-03-16 13:46:53 -0400 | [diff] [blame] | 462 | cbInfo.fLoadStoreState = LoadStoreState::kLoadAndStore; |
Greg Daniel | 77b53f6 | 2016-10-18 11:48:51 -0400 | [diff] [blame] | 463 | |
Greg Daniel | 22bc865 | 2017-03-22 15:45:43 -0400 | [diff] [blame] | 464 | cbInfo.fCommandBuffers.push_back(fGpu->resourceProvider().findOrCreateSecondaryCommandBuffer()); |
Greg Daniel | 77b53f6 | 2016-10-18 11:48:51 -0400 | [diff] [blame] | 465 | // It shouldn't matter what we set the clear color to here since we will assume loading of the |
| 466 | // attachment. |
| 467 | memset(&cbInfo.fColorClearValue, 0, sizeof(VkClearValue)); |
| 468 | cbInfo.fBounds.setEmpty(); |
Greg Daniel | 77b53f6 | 2016-10-18 11:48:51 -0400 | [diff] [blame] | 469 | |
Robert Phillips | 19e51dc | 2017-08-09 09:30:51 -0400 | [diff] [blame] | 470 | cbInfo.currentCmdBuf()->begin(fGpu, vkRT->framebuffer(), cbInfo.fRenderPass); |
Greg Daniel | 77b53f6 | 2016-10-18 11:48:51 -0400 | [diff] [blame] | 471 | } |
| 472 | |
Brian Salomon | 943ed79 | 2017-10-30 09:37:55 -0400 | [diff] [blame] | 473 | void GrVkGpuRTCommandBuffer::inlineUpload(GrOpFlushState* state, |
| 474 | GrDeferredTextureUploadFn& upload) { |
Greg Daniel | 22bc865 | 2017-03-22 15:45:43 -0400 | [diff] [blame] | 475 | if (!fCommandBufferInfos[fCurrentCmdInfo].fIsEmpty) { |
| 476 | this->addAdditionalRenderPass(); |
Greg Daniel | 77b53f6 | 2016-10-18 11:48:51 -0400 | [diff] [blame] | 477 | } |
Greg Daniel | 22bc865 | 2017-03-22 15:45:43 -0400 | [diff] [blame] | 478 | fCommandBufferInfos[fCurrentCmdInfo].fPreDrawUploads.emplace_back(state, upload); |
Greg Daniel | 77b53f6 | 2016-10-18 11:48:51 -0400 | [diff] [blame] | 479 | } |
| 480 | |
Robert Phillips | b0e93a2 | 2017-08-29 08:26:54 -0400 | [diff] [blame] | 481 | void GrVkGpuRTCommandBuffer::copy(GrSurface* src, GrSurfaceOrigin srcOrigin, const SkIRect& srcRect, |
Greg Daniel | 500d58b | 2017-08-24 15:59:33 -0400 | [diff] [blame] | 482 | const SkIPoint& dstPoint) { |
Greg Daniel | a3c68df | 2018-03-16 13:46:53 -0400 | [diff] [blame] | 483 | CommandBufferInfo& cbInfo = fCommandBufferInfos[fCurrentCmdInfo]; |
| 484 | if (!cbInfo.fIsEmpty || LoadStoreState::kStartsWithClear == cbInfo.fLoadStoreState) { |
Greg Daniel | 500d58b | 2017-08-24 15:59:33 -0400 | [diff] [blame] | 485 | this->addAdditionalRenderPass(); |
| 486 | } |
Greg Daniel | a3c68df | 2018-03-16 13:46:53 -0400 | [diff] [blame] | 487 | |
Greg Daniel | 55fa647 | 2018-03-16 16:13:10 -0400 | [diff] [blame] | 488 | fCommandBufferInfos[fCurrentCmdInfo].fPreCopies.emplace_back( |
| 489 | src, srcOrigin, srcRect, dstPoint, |
| 490 | LoadStoreState::kStartsWithDiscard == cbInfo.fLoadStoreState); |
| 491 | |
Greg Daniel | a3c68df | 2018-03-16 13:46:53 -0400 | [diff] [blame] | 492 | if (LoadStoreState::kLoadAndStore != cbInfo.fLoadStoreState) { |
| 493 | // Change the render pass to do a load and store so we don't lose the results of our copy |
| 494 | GrVkRenderPass::LoadStoreOps vkColorOps(VK_ATTACHMENT_LOAD_OP_LOAD, |
| 495 | VK_ATTACHMENT_STORE_OP_STORE); |
| 496 | GrVkRenderPass::LoadStoreOps vkStencilOps(VK_ATTACHMENT_LOAD_OP_LOAD, |
| 497 | VK_ATTACHMENT_STORE_OP_STORE); |
| 498 | |
| 499 | const GrVkRenderPass* oldRP = cbInfo.fRenderPass; |
| 500 | |
| 501 | GrVkRenderTarget* vkRT = static_cast<GrVkRenderTarget*>(fRenderTarget); |
| 502 | const GrVkResourceProvider::CompatibleRPHandle& rpHandle = |
| 503 | vkRT->compatibleRenderPassHandle(); |
| 504 | if (rpHandle.isValid()) { |
| 505 | cbInfo.fRenderPass = fGpu->resourceProvider().findRenderPass(rpHandle, |
| 506 | vkColorOps, |
| 507 | vkStencilOps); |
| 508 | } else { |
| 509 | cbInfo.fRenderPass = fGpu->resourceProvider().findRenderPass(*vkRT, |
| 510 | vkColorOps, |
| 511 | vkStencilOps); |
| 512 | } |
| 513 | SkASSERT(cbInfo.fRenderPass->isCompatible(*oldRP)); |
| 514 | oldRP->unref(fGpu); |
| 515 | |
| 516 | cbInfo.fLoadStoreState = LoadStoreState::kLoadAndStore; |
| 517 | |
| 518 | } |
Greg Daniel | 500d58b | 2017-08-24 15:59:33 -0400 | [diff] [blame] | 519 | } |
| 520 | |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 521 | //////////////////////////////////////////////////////////////////////////////// |
| 522 | |
Brian Salomon | 802cb31 | 2018-06-08 18:05:20 -0400 | [diff] [blame] | 523 | void GrVkGpuRTCommandBuffer::bindGeometry(const GrBuffer* indexBuffer, |
Greg Daniel | 500d58b | 2017-08-24 15:59:33 -0400 | [diff] [blame] | 524 | const GrBuffer* vertexBuffer, |
| 525 | const GrBuffer* instanceBuffer) { |
Chris Dalton | ff92650 | 2017-05-03 14:36:54 -0400 | [diff] [blame] | 526 | GrVkSecondaryCommandBuffer* currCmdBuf = fCommandBufferInfos[fCurrentCmdInfo].currentCmdBuf(); |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 527 | // There is no need to put any memory barriers to make sure host writes have finished here. |
| 528 | // When a command buffer is submitted to a queue, there is an implicit memory barrier that |
| 529 | // occurs for all host writes. Additionally, BufferMemoryBarriers are not allowed inside of |
| 530 | // an active RenderPass. |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 531 | |
Chris Dalton | 1d61635 | 2017-05-31 12:51:23 -0600 | [diff] [blame] | 532 | // Here our vertex and instance inputs need to match the same 0-based bindings they were |
| 533 | // assigned in GrVkPipeline. That is, vertex first (if any) followed by instance. |
| 534 | uint32_t binding = 0; |
| 535 | |
Brian Salomon | 802cb31 | 2018-06-08 18:05:20 -0400 | [diff] [blame] | 536 | if (vertexBuffer) { |
Chris Dalton | 1d61635 | 2017-05-31 12:51:23 -0600 | [diff] [blame] | 537 | SkASSERT(vertexBuffer); |
| 538 | SkASSERT(!vertexBuffer->isCPUBacked()); |
| 539 | SkASSERT(!vertexBuffer->isMapped()); |
| 540 | |
| 541 | currCmdBuf->bindInputBuffer(fGpu, binding++, |
| 542 | static_cast<const GrVkVertexBuffer*>(vertexBuffer)); |
| 543 | } |
| 544 | |
Brian Salomon | 802cb31 | 2018-06-08 18:05:20 -0400 | [diff] [blame] | 545 | if (instanceBuffer) { |
Chris Dalton | 1d61635 | 2017-05-31 12:51:23 -0600 | [diff] [blame] | 546 | SkASSERT(instanceBuffer); |
| 547 | SkASSERT(!instanceBuffer->isCPUBacked()); |
| 548 | SkASSERT(!instanceBuffer->isMapped()); |
| 549 | |
| 550 | currCmdBuf->bindInputBuffer(fGpu, binding++, |
| 551 | static_cast<const GrVkVertexBuffer*>(instanceBuffer)); |
| 552 | } |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 553 | |
Chris Dalton | ff92650 | 2017-05-03 14:36:54 -0400 | [diff] [blame] | 554 | if (indexBuffer) { |
| 555 | SkASSERT(indexBuffer); |
| 556 | SkASSERT(!indexBuffer->isMapped()); |
| 557 | SkASSERT(!indexBuffer->isCPUBacked()); |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 558 | |
Chris Dalton | ff92650 | 2017-05-03 14:36:54 -0400 | [diff] [blame] | 559 | currCmdBuf->bindIndexBuffer(fGpu, static_cast<const GrVkIndexBuffer*>(indexBuffer)); |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 560 | } |
| 561 | } |
| 562 | |
Brian Salomon | 4934890 | 2018-06-26 09:12:38 -0400 | [diff] [blame] | 563 | GrVkPipelineState* GrVkGpuRTCommandBuffer::prepareDrawState( |
| 564 | const GrPrimitiveProcessor& primProc, |
| 565 | const GrPipeline& pipeline, |
| 566 | const GrPipeline::FixedDynamicState* fixedDynamicState, |
| 567 | const GrPipeline::DynamicStateArrays* dynamicStateArrays, |
| 568 | GrPrimitiveType primitiveType) { |
Greg Daniel | 22bc865 | 2017-03-22 15:45:43 -0400 | [diff] [blame] | 569 | CommandBufferInfo& cbInfo = fCommandBufferInfos[fCurrentCmdInfo]; |
| 570 | SkASSERT(cbInfo.fRenderPass); |
Greg Daniel | 36a77ee | 2016-10-18 10:33:25 -0400 | [diff] [blame] | 571 | |
Greg Daniel | 09eeefb | 2017-10-16 15:15:02 -0400 | [diff] [blame] | 572 | GrVkPipelineState* pipelineState = |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 573 | fGpu->resourceProvider().findOrCreateCompatiblePipelineState(pipeline, |
| 574 | primProc, |
| 575 | primitiveType, |
Greg Daniel | 36a77ee | 2016-10-18 10:33:25 -0400 | [diff] [blame] | 576 | *cbInfo.fRenderPass); |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 577 | if (!pipelineState) { |
| 578 | return pipelineState; |
| 579 | } |
| 580 | |
Greg Daniel | 22bc865 | 2017-03-22 15:45:43 -0400 | [diff] [blame] | 581 | if (!cbInfo.fIsEmpty && |
Greg Daniel | 09eeefb | 2017-10-16 15:15:02 -0400 | [diff] [blame] | 582 | fLastPipelineState && fLastPipelineState != pipelineState && |
Greg Daniel | e3cd691 | 2017-05-17 11:15:55 -0400 | [diff] [blame] | 583 | fGpu->vkCaps().newCBOnPipelineChange()) { |
Greg Daniel | 22bc865 | 2017-03-22 15:45:43 -0400 | [diff] [blame] | 584 | this->addAdditionalCommandBuffer(); |
| 585 | } |
Greg Daniel | 09eeefb | 2017-10-16 15:15:02 -0400 | [diff] [blame] | 586 | fLastPipelineState = pipelineState; |
Greg Daniel | 22bc865 | 2017-03-22 15:45:43 -0400 | [diff] [blame] | 587 | |
Brian Salomon | af87483 | 2018-08-03 11:53:40 -0400 | [diff] [blame] | 588 | const GrTextureProxy* const* primProcProxies = nullptr; |
| 589 | if (fixedDynamicState) { |
| 590 | primProcProxies = fixedDynamicState->fPrimitiveProcessorTextures; |
| 591 | } |
| 592 | pipelineState->setData(fGpu, primProc, pipeline, primProcProxies); |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 593 | |
Greg Daniel | 22bc865 | 2017-03-22 15:45:43 -0400 | [diff] [blame] | 594 | pipelineState->bind(fGpu, cbInfo.currentCmdBuf()); |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 595 | |
Robert Phillips | 2890fbf | 2017-07-26 15:48:41 -0400 | [diff] [blame] | 596 | GrRenderTarget* rt = pipeline.renderTarget(); |
Chris Dalton | 46983b7 | 2017-06-06 12:27:16 -0600 | [diff] [blame] | 597 | |
Brian Salomon | d818ebf | 2018-07-02 14:08:49 +0000 | [diff] [blame] | 598 | if (!pipeline.isScissorEnabled()) { |
Robert Phillips | b0e93a2 | 2017-08-29 08:26:54 -0400 | [diff] [blame] | 599 | GrVkPipeline::SetDynamicScissorRectState(fGpu, cbInfo.currentCmdBuf(), |
| 600 | rt, pipeline.proxy()->origin(), |
Chris Dalton | 46983b7 | 2017-06-06 12:27:16 -0600 | [diff] [blame] | 601 | SkIRect::MakeWH(rt->width(), rt->height())); |
Brian Salomon | 4934890 | 2018-06-26 09:12:38 -0400 | [diff] [blame] | 602 | } else if (!dynamicStateArrays || !dynamicStateArrays->fScissorRects) { |
| 603 | SkASSERT(fixedDynamicState); |
| 604 | GrVkPipeline::SetDynamicScissorRectState(fGpu, cbInfo.currentCmdBuf(), rt, |
| 605 | pipeline.proxy()->origin(), |
| 606 | fixedDynamicState->fScissorRect); |
Chris Dalton | 46983b7 | 2017-06-06 12:27:16 -0600 | [diff] [blame] | 607 | } |
Jim Van Verth | 6a40abc | 2017-11-02 16:56:09 +0000 | [diff] [blame] | 608 | GrVkPipeline::SetDynamicViewportState(fGpu, cbInfo.currentCmdBuf(), rt); |
Chris Dalton | 46983b7 | 2017-06-06 12:27:16 -0600 | [diff] [blame] | 609 | GrVkPipeline::SetDynamicBlendConstantState(fGpu, cbInfo.currentCmdBuf(), rt->config(), |
| 610 | pipeline.getXferProcessor()); |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 611 | |
| 612 | return pipelineState; |
| 613 | } |
| 614 | |
Brian Salomon | ff168d9 | 2018-06-23 15:17:27 -0400 | [diff] [blame] | 615 | void GrVkGpuRTCommandBuffer::onDraw(const GrPrimitiveProcessor& primProc, |
| 616 | const GrPipeline& pipeline, |
Brian Salomon | 4934890 | 2018-06-26 09:12:38 -0400 | [diff] [blame] | 617 | const GrPipeline::FixedDynamicState* fixedDynamicState, |
| 618 | const GrPipeline::DynamicStateArrays* dynamicStateArrays, |
Greg Daniel | 500d58b | 2017-08-24 15:59:33 -0400 | [diff] [blame] | 619 | const GrMesh meshes[], |
Greg Daniel | 500d58b | 2017-08-24 15:59:33 -0400 | [diff] [blame] | 620 | int meshCount, |
| 621 | const SkRect& bounds) { |
Robert Phillips | 19e51dc | 2017-08-09 09:30:51 -0400 | [diff] [blame] | 622 | SkASSERT(pipeline.renderTarget() == fRenderTarget); |
Brian Salomon | c293a29 | 2016-11-30 13:38:32 -0500 | [diff] [blame] | 623 | |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 624 | if (!meshCount) { |
| 625 | return; |
| 626 | } |
Greg Daniel | ea022cd | 2018-03-16 11:10:03 -0400 | [diff] [blame] | 627 | |
| 628 | CommandBufferInfo& cbInfo = fCommandBufferInfos[fCurrentCmdInfo]; |
| 629 | |
Brian Salomon | e782f84 | 2018-07-31 13:53:11 -0400 | [diff] [blame] | 630 | auto prepareSampledImage = [&](GrTexture* texture, GrSamplerState::Filter filter) { |
| 631 | GrVkTexture* vkTexture = static_cast<GrVkTexture*>(texture); |
| 632 | // We may need to resolve the texture first if it is also a render target |
| 633 | GrVkRenderTarget* texRT = static_cast<GrVkRenderTarget*>(vkTexture->asRenderTarget()); |
| 634 | if (texRT) { |
| 635 | fGpu->onResolveRenderTarget(texRT); |
| 636 | } |
| 637 | |
| 638 | // Check if we need to regenerate any mip maps |
| 639 | if (GrSamplerState::Filter::kMipMap == filter && |
| 640 | (vkTexture->width() != 1 || vkTexture->height() != 1)) { |
| 641 | SkASSERT(vkTexture->texturePriv().mipMapped() == GrMipMapped::kYes); |
| 642 | if (vkTexture->texturePriv().mipMapsAreDirty()) { |
| 643 | fGpu->regenerateMipMapLevels(vkTexture); |
| 644 | } |
| 645 | } |
| 646 | cbInfo.fSampledImages.push_back(vkTexture); |
| 647 | }; |
| 648 | |
| 649 | for (int i = 0; i < primProc.numTextureSamplers(); ++i) { |
Brian Salomon | af87483 | 2018-08-03 11:53:40 -0400 | [diff] [blame] | 650 | auto texture = fixedDynamicState->fPrimitiveProcessorTextures[i]->peekTexture(); |
| 651 | prepareSampledImage(texture, primProc.textureSampler(i).samplerState().filter()); |
Brian Salomon | e782f84 | 2018-07-31 13:53:11 -0400 | [diff] [blame] | 652 | } |
bsalomon | b58a2b4 | 2016-09-26 06:55:02 -0700 | [diff] [blame] | 653 | GrFragmentProcessor::Iter iter(pipeline); |
| 654 | while (const GrFragmentProcessor* fp = iter.next()) { |
Brian Salomon | e782f84 | 2018-07-31 13:53:11 -0400 | [diff] [blame] | 655 | for (int i = 0; i < fp->numTextureSamplers(); ++i) { |
| 656 | const GrFragmentProcessor::TextureSampler& sampler = fp->textureSampler(i); |
| 657 | prepareSampledImage(sampler.peekTexture(), sampler.samplerState().filter()); |
| 658 | } |
egdaniel | 2f5792a | 2016-07-06 08:51:23 -0700 | [diff] [blame] | 659 | } |
Robert Phillips | bb581ce | 2017-05-29 15:05:15 -0400 | [diff] [blame] | 660 | if (GrTexture* dstTexture = pipeline.peekDstTexture()) { |
Greg Daniel | ea022cd | 2018-03-16 11:10:03 -0400 | [diff] [blame] | 661 | cbInfo.fSampledImages.push_back(static_cast<GrVkTexture*>(dstTexture)); |
Brian Salomon | 18dfa98 | 2017-04-03 16:57:43 -0400 | [diff] [blame] | 662 | } |
egdaniel | 2f5792a | 2016-07-06 08:51:23 -0700 | [diff] [blame] | 663 | |
Chris Dalton | bca46e2 | 2017-05-15 11:03:26 -0600 | [diff] [blame] | 664 | GrPrimitiveType primitiveType = meshes[0].primitiveType(); |
Brian Salomon | 4934890 | 2018-06-26 09:12:38 -0400 | [diff] [blame] | 665 | GrVkPipelineState* pipelineState = this->prepareDrawState(primProc, pipeline, fixedDynamicState, |
| 666 | dynamicStateArrays, primitiveType); |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 667 | if (!pipelineState) { |
| 668 | return; |
| 669 | } |
| 670 | |
Brian Salomon | d818ebf | 2018-07-02 14:08:49 +0000 | [diff] [blame] | 671 | bool dynamicScissor = |
| 672 | pipeline.isScissorEnabled() && dynamicStateArrays && dynamicStateArrays->fScissorRects; |
Brian Salomon | 4934890 | 2018-06-26 09:12:38 -0400 | [diff] [blame] | 673 | |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 674 | for (int i = 0; i < meshCount; ++i) { |
| 675 | const GrMesh& mesh = meshes[i]; |
Chris Dalton | bca46e2 | 2017-05-15 11:03:26 -0600 | [diff] [blame] | 676 | if (mesh.primitiveType() != primitiveType) { |
Chris Dalton | 6f24180 | 2017-05-08 13:58:38 -0400 | [diff] [blame] | 677 | // Technically we don't have to call this here (since there is a safety check in |
| 678 | // pipelineState:setData but this will allow for quicker freeing of resources if the |
| 679 | // pipelineState sits in a cache for a while. |
| 680 | pipelineState->freeTempResources(fGpu); |
| 681 | SkDEBUGCODE(pipelineState = nullptr); |
Chris Dalton | bca46e2 | 2017-05-15 11:03:26 -0600 | [diff] [blame] | 682 | primitiveType = mesh.primitiveType(); |
Brian Salomon | 4934890 | 2018-06-26 09:12:38 -0400 | [diff] [blame] | 683 | pipelineState = this->prepareDrawState(primProc, pipeline, fixedDynamicState, |
| 684 | dynamicStateArrays, primitiveType); |
Chris Dalton | 6f24180 | 2017-05-08 13:58:38 -0400 | [diff] [blame] | 685 | if (!pipelineState) { |
| 686 | return; |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 687 | } |
Chris Dalton | 6f24180 | 2017-05-08 13:58:38 -0400 | [diff] [blame] | 688 | } |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 689 | |
Brian Salomon | 4934890 | 2018-06-26 09:12:38 -0400 | [diff] [blame] | 690 | if (dynamicScissor) { |
| 691 | GrVkPipeline::SetDynamicScissorRectState(fGpu, cbInfo.currentCmdBuf(), fRenderTarget, |
| 692 | pipeline.proxy()->origin(), |
| 693 | dynamicStateArrays->fScissorRects[i]); |
Chris Dalton | 46983b7 | 2017-06-06 12:27:16 -0600 | [diff] [blame] | 694 | } |
| 695 | |
Chris Dalton | bca46e2 | 2017-05-15 11:03:26 -0600 | [diff] [blame] | 696 | SkASSERT(pipelineState); |
Brian Salomon | 802cb31 | 2018-06-08 18:05:20 -0400 | [diff] [blame] | 697 | mesh.sendToGpu(this); |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 698 | } |
| 699 | |
Greg Daniel | 36a77ee | 2016-10-18 10:33:25 -0400 | [diff] [blame] | 700 | cbInfo.fBounds.join(bounds); |
Chris Dalton | 114a3c0 | 2017-05-26 15:17:19 -0600 | [diff] [blame] | 701 | cbInfo.fIsEmpty = false; |
Greg Daniel | 36a77ee | 2016-10-18 10:33:25 -0400 | [diff] [blame] | 702 | |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 703 | // Technically we don't have to call this here (since there is a safety check in |
| 704 | // pipelineState:setData but this will allow for quicker freeing of resources if the |
| 705 | // pipelineState sits in a cache for a while. |
| 706 | pipelineState->freeTempResources(fGpu); |
egdaniel | 066df7c | 2016-06-08 14:02:27 -0700 | [diff] [blame] | 707 | } |
| 708 | |
Brian Salomon | 802cb31 | 2018-06-08 18:05:20 -0400 | [diff] [blame] | 709 | void GrVkGpuRTCommandBuffer::sendInstancedMeshToGpu(GrPrimitiveType, |
Greg Daniel | 500d58b | 2017-08-24 15:59:33 -0400 | [diff] [blame] | 710 | const GrBuffer* vertexBuffer, |
| 711 | int vertexCount, |
| 712 | int baseVertex, |
| 713 | const GrBuffer* instanceBuffer, |
| 714 | int instanceCount, |
| 715 | int baseInstance) { |
Chris Dalton | 114a3c0 | 2017-05-26 15:17:19 -0600 | [diff] [blame] | 716 | CommandBufferInfo& cbInfo = fCommandBufferInfos[fCurrentCmdInfo]; |
Brian Salomon | 802cb31 | 2018-06-08 18:05:20 -0400 | [diff] [blame] | 717 | this->bindGeometry(nullptr, vertexBuffer, instanceBuffer); |
Chris Dalton | 1d61635 | 2017-05-31 12:51:23 -0600 | [diff] [blame] | 718 | cbInfo.currentCmdBuf()->draw(fGpu, vertexCount, instanceCount, baseVertex, baseInstance); |
Chris Dalton | 114a3c0 | 2017-05-26 15:17:19 -0600 | [diff] [blame] | 719 | fGpu->stats()->incNumDraws(); |
| 720 | } |
| 721 | |
Brian Salomon | 802cb31 | 2018-06-08 18:05:20 -0400 | [diff] [blame] | 722 | void GrVkGpuRTCommandBuffer::sendIndexedInstancedMeshToGpu(GrPrimitiveType, |
Greg Daniel | 500d58b | 2017-08-24 15:59:33 -0400 | [diff] [blame] | 723 | const GrBuffer* indexBuffer, |
| 724 | int indexCount, |
| 725 | int baseIndex, |
| 726 | const GrBuffer* vertexBuffer, |
| 727 | int baseVertex, |
| 728 | const GrBuffer* instanceBuffer, |
| 729 | int instanceCount, |
Brian Salomon | 802cb31 | 2018-06-08 18:05:20 -0400 | [diff] [blame] | 730 | int baseInstance, |
| 731 | GrPrimitiveRestart restart) { |
| 732 | SkASSERT(restart == GrPrimitiveRestart::kNo); |
Chris Dalton | 114a3c0 | 2017-05-26 15:17:19 -0600 | [diff] [blame] | 733 | CommandBufferInfo& cbInfo = fCommandBufferInfos[fCurrentCmdInfo]; |
Brian Salomon | 802cb31 | 2018-06-08 18:05:20 -0400 | [diff] [blame] | 734 | this->bindGeometry(indexBuffer, vertexBuffer, instanceBuffer); |
Chris Dalton | 1d61635 | 2017-05-31 12:51:23 -0600 | [diff] [blame] | 735 | cbInfo.currentCmdBuf()->drawIndexed(fGpu, indexCount, instanceCount, |
| 736 | baseIndex, baseVertex, baseInstance); |
Chris Dalton | 114a3c0 | 2017-05-26 15:17:19 -0600 | [diff] [blame] | 737 | fGpu->stats()->incNumDraws(); |
| 738 | } |