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