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