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