Alexis Hetu | 767b41b | 2018-09-26 11:25:46 -0400 | [diff] [blame] | 1 | // Copyright 2018 The SwiftShader Authors. All Rights Reserved. |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | #include "VkCommandBuffer.hpp" |
Alexis Hetu | c65473d | 2018-12-07 16:26:05 -0500 | [diff] [blame] | 16 | #include "VkBuffer.hpp" |
Alexis Hetu | 3f5a479 | 2019-02-01 17:49:55 -0500 | [diff] [blame] | 17 | #include "VkEvent.hpp" |
Alexis Hetu | e1f51b9 | 2019-04-23 15:34:34 -0400 | [diff] [blame] | 18 | #include "VkFence.hpp" |
Alexis Hetu | 9bc7a81 | 2018-12-07 16:13:34 -0500 | [diff] [blame] | 19 | #include "VkFramebuffer.hpp" |
Alexis Hetu | 09056de | 2018-12-07 12:40:00 -0500 | [diff] [blame] | 20 | #include "VkImage.hpp" |
Chris Forbes | 7c33e88 | 2019-02-21 14:58:28 -0800 | [diff] [blame] | 21 | #include "VkImageView.hpp" |
Alexis Hetu | c65473d | 2018-12-07 16:26:05 -0500 | [diff] [blame] | 22 | #include "VkPipeline.hpp" |
Ben Clayton | f2be26a | 2019-03-08 12:02:05 +0000 | [diff] [blame] | 23 | #include "VkPipelineLayout.hpp" |
Alexis Hetu | f0aa9d5 | 2019-04-01 17:06:47 -0400 | [diff] [blame] | 24 | #include "VkQueryPool.hpp" |
Chris Forbes | 50dd2ce | 2018-12-07 17:54:31 -0800 | [diff] [blame] | 25 | #include "VkRenderPass.hpp" |
Alexis Hetu | c65473d | 2018-12-07 16:26:05 -0500 | [diff] [blame] | 26 | #include "Device/Renderer.hpp" |
Alexis Hetu | 767b41b | 2018-09-26 11:25:46 -0400 | [diff] [blame] | 27 | |
Chris Forbes | f8374cf | 2018-12-06 13:25:59 -0800 | [diff] [blame] | 28 | #include <cstring> |
| 29 | |
Alexis Hetu | 767b41b | 2018-09-26 11:25:46 -0400 | [diff] [blame] | 30 | namespace vk |
| 31 | { |
| 32 | |
Alexis Hetu | 072dc0d | 2018-10-31 11:41:25 -0400 | [diff] [blame] | 33 | class CommandBuffer::Command |
| 34 | { |
| 35 | public: |
| 36 | // FIXME (b/119421344): change the commandBuffer argument to a CommandBuffer state |
Alexis Hetu | 9bc7a81 | 2018-12-07 16:13:34 -0500 | [diff] [blame] | 37 | virtual void play(CommandBuffer::ExecutionState& executionState) = 0; |
Alexis Hetu | 072dc0d | 2018-10-31 11:41:25 -0400 | [diff] [blame] | 38 | virtual ~Command() {} |
| 39 | }; |
| 40 | |
| 41 | class BeginRenderPass : public CommandBuffer::Command |
| 42 | { |
| 43 | public: |
Alexis Hetu | 1cd31ea | 2019-01-17 17:14:57 -0500 | [diff] [blame] | 44 | BeginRenderPass(VkRenderPass renderPass, VkFramebuffer framebuffer, VkRect2D renderArea, |
| 45 | uint32_t clearValueCount, const VkClearValue* pClearValues) : |
| 46 | renderPass(Cast(renderPass)), framebuffer(Cast(framebuffer)), renderArea(renderArea), |
| 47 | clearValueCount(clearValueCount) |
Alexis Hetu | 072dc0d | 2018-10-31 11:41:25 -0400 | [diff] [blame] | 48 | { |
| 49 | // FIXME (b/119409619): use an allocator here so we can control all memory allocations |
| 50 | clearValues = new VkClearValue[clearValueCount]; |
| 51 | memcpy(clearValues, pClearValues, clearValueCount * sizeof(VkClearValue)); |
| 52 | } |
| 53 | |
| 54 | ~BeginRenderPass() override |
| 55 | { |
Chris Forbes | f04b56f | 2018-12-28 16:06:16 -0800 | [diff] [blame] | 56 | delete [] clearValues; |
Alexis Hetu | 072dc0d | 2018-10-31 11:41:25 -0400 | [diff] [blame] | 57 | } |
| 58 | |
| 59 | protected: |
Ben Clayton | 93317ec | 2019-02-20 08:53:50 +0000 | [diff] [blame] | 60 | void play(CommandBuffer::ExecutionState& executionState) override |
Alexis Hetu | 072dc0d | 2018-10-31 11:41:25 -0400 | [diff] [blame] | 61 | { |
Alexis Hetu | 1cd31ea | 2019-01-17 17:14:57 -0500 | [diff] [blame] | 62 | executionState.renderPass = renderPass; |
| 63 | executionState.renderPassFramebuffer = framebuffer; |
| 64 | renderPass->begin(); |
Alexis Hetu | 54ec759 | 2019-03-20 14:37:16 -0400 | [diff] [blame] | 65 | framebuffer->clear(executionState.renderPass, clearValueCount, clearValues, renderArea); |
Alexis Hetu | 072dc0d | 2018-10-31 11:41:25 -0400 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | private: |
Alexis Hetu | 1cd31ea | 2019-01-17 17:14:57 -0500 | [diff] [blame] | 69 | RenderPass* renderPass; |
| 70 | Framebuffer* framebuffer; |
Alexis Hetu | 072dc0d | 2018-10-31 11:41:25 -0400 | [diff] [blame] | 71 | VkRect2D renderArea; |
| 72 | uint32_t clearValueCount; |
| 73 | VkClearValue* clearValues; |
| 74 | }; |
| 75 | |
Alexis Hetu | 1cd31ea | 2019-01-17 17:14:57 -0500 | [diff] [blame] | 76 | class NextSubpass : public CommandBuffer::Command |
| 77 | { |
| 78 | public: |
| 79 | NextSubpass() |
| 80 | { |
| 81 | } |
| 82 | |
| 83 | protected: |
Ben Clayton | 93317ec | 2019-02-20 08:53:50 +0000 | [diff] [blame] | 84 | void play(CommandBuffer::ExecutionState& executionState) override |
Alexis Hetu | 1cd31ea | 2019-01-17 17:14:57 -0500 | [diff] [blame] | 85 | { |
Alexis Hetu | 54ec759 | 2019-03-20 14:37:16 -0400 | [diff] [blame] | 86 | bool hasResolveAttachments = (executionState.renderPass->getCurrentSubpass().pResolveAttachments != nullptr); |
| 87 | if(hasResolveAttachments) |
| 88 | { |
| 89 | // FIXME(sugoi): remove the following lines and resolve in Renderer::finishRendering() |
| 90 | // for a Draw command or after the last command of the current subpass |
| 91 | // which modifies pixels. |
| 92 | executionState.renderer->synchronize(); |
| 93 | executionState.renderPassFramebuffer->resolve(executionState.renderPass); |
| 94 | } |
| 95 | |
Alexis Hetu | 1cd31ea | 2019-01-17 17:14:57 -0500 | [diff] [blame] | 96 | executionState.renderPass->nextSubpass(); |
| 97 | } |
| 98 | |
| 99 | private: |
| 100 | }; |
| 101 | |
Alexis Hetu | 072dc0d | 2018-10-31 11:41:25 -0400 | [diff] [blame] | 102 | class EndRenderPass : public CommandBuffer::Command |
| 103 | { |
| 104 | public: |
| 105 | EndRenderPass() |
| 106 | { |
| 107 | } |
| 108 | |
| 109 | protected: |
Ben Clayton | 93317ec | 2019-02-20 08:53:50 +0000 | [diff] [blame] | 110 | void play(CommandBuffer::ExecutionState& executionState) override |
Alexis Hetu | 072dc0d | 2018-10-31 11:41:25 -0400 | [diff] [blame] | 111 | { |
Chris Forbes | fc06fd1 | 2019-03-21 08:36:11 -0700 | [diff] [blame] | 112 | // Execute (implicit or explicit) VkSubpassDependency to VK_SUBPASS_EXTERNAL |
| 113 | // This is somewhat heavier than the actual ordering required. |
| 114 | executionState.renderer->synchronize(); |
Alexis Hetu | 54ec759 | 2019-03-20 14:37:16 -0400 | [diff] [blame] | 115 | |
| 116 | // FIXME(sugoi): remove the following line and resolve in Renderer::finishRendering() |
| 117 | // for a Draw command or after the last command of the current subpass |
| 118 | // which modifies pixels. |
| 119 | executionState.renderPassFramebuffer->resolve(executionState.renderPass); |
| 120 | |
| 121 | executionState.renderPass->end(); |
| 122 | executionState.renderPass = nullptr; |
| 123 | executionState.renderPassFramebuffer = nullptr; |
Alexis Hetu | 072dc0d | 2018-10-31 11:41:25 -0400 | [diff] [blame] | 124 | } |
| 125 | |
| 126 | private: |
| 127 | }; |
| 128 | |
Alexis Hetu | e7b2a05 | 2019-03-18 16:16:36 -0400 | [diff] [blame] | 129 | class ExecuteCommands : public CommandBuffer::Command |
| 130 | { |
| 131 | public: |
| 132 | ExecuteCommands(const VkCommandBuffer& commandBuffer) : commandBuffer(commandBuffer) |
| 133 | { |
| 134 | } |
| 135 | |
| 136 | protected: |
| 137 | void play(CommandBuffer::ExecutionState& executionState) override |
| 138 | { |
| 139 | Cast(commandBuffer)->submitSecondary(executionState); |
| 140 | } |
| 141 | |
| 142 | private: |
| 143 | const VkCommandBuffer commandBuffer; |
| 144 | }; |
| 145 | |
Alexis Hetu | 072dc0d | 2018-10-31 11:41:25 -0400 | [diff] [blame] | 146 | class PipelineBind : public CommandBuffer::Command |
| 147 | { |
| 148 | public: |
| 149 | PipelineBind(VkPipelineBindPoint pPipelineBindPoint, VkPipeline pPipeline) : |
| 150 | pipelineBindPoint(pPipelineBindPoint), pipeline(pPipeline) |
| 151 | { |
| 152 | } |
| 153 | |
| 154 | protected: |
Ben Clayton | 93317ec | 2019-02-20 08:53:50 +0000 | [diff] [blame] | 155 | void play(CommandBuffer::ExecutionState& executionState) override |
Alexis Hetu | 072dc0d | 2018-10-31 11:41:25 -0400 | [diff] [blame] | 156 | { |
Ben Clayton | 225a130 | 2019-04-02 12:28:22 +0100 | [diff] [blame] | 157 | executionState.pipelineState[pipelineBindPoint].pipeline = Cast(pipeline); |
Alexis Hetu | 072dc0d | 2018-10-31 11:41:25 -0400 | [diff] [blame] | 158 | } |
| 159 | |
| 160 | private: |
| 161 | VkPipelineBindPoint pipelineBindPoint; |
| 162 | VkPipeline pipeline; |
| 163 | }; |
| 164 | |
Ben Clayton | f2be26a | 2019-03-08 12:02:05 +0000 | [diff] [blame] | 165 | class Dispatch : public CommandBuffer::Command |
| 166 | { |
| 167 | public: |
| 168 | Dispatch(uint32_t pGroupCountX, uint32_t pGroupCountY, uint32_t pGroupCountZ) : |
| 169 | groupCountX(pGroupCountX), groupCountY(pGroupCountY), groupCountZ(pGroupCountZ) |
| 170 | { |
| 171 | } |
| 172 | |
| 173 | protected: |
| 174 | void play(CommandBuffer::ExecutionState& executionState) override |
| 175 | { |
Ben Clayton | 225a130 | 2019-04-02 12:28:22 +0100 | [diff] [blame] | 176 | auto const &pipelineState = executionState.pipelineState[VK_PIPELINE_BIND_POINT_COMPUTE]; |
| 177 | |
| 178 | ComputePipeline* pipeline = static_cast<ComputePipeline*>(pipelineState.pipeline); |
Ben Clayton | f2be26a | 2019-03-08 12:02:05 +0000 | [diff] [blame] | 179 | pipeline->run(groupCountX, groupCountY, groupCountZ, |
Ben Clayton | 225a130 | 2019-04-02 12:28:22 +0100 | [diff] [blame] | 180 | pipelineState.descriptorSets, |
| 181 | pipelineState.descriptorDynamicOffsets, |
Chris Forbes | a30de54 | 2019-03-18 18:51:55 -0700 | [diff] [blame] | 182 | executionState.pushConstants); |
Ben Clayton | f2be26a | 2019-03-08 12:02:05 +0000 | [diff] [blame] | 183 | } |
| 184 | |
| 185 | private: |
| 186 | uint32_t groupCountX; |
| 187 | uint32_t groupCountY; |
| 188 | uint32_t groupCountZ; |
| 189 | }; |
| 190 | |
Chris Forbes | fc8a46d | 2019-03-22 14:47:47 -0700 | [diff] [blame] | 191 | class DispatchIndirect : public CommandBuffer::Command |
| 192 | { |
| 193 | public: |
| 194 | DispatchIndirect(VkBuffer buffer, VkDeviceSize offset) : |
| 195 | buffer(buffer), offset(offset) |
| 196 | { |
| 197 | } |
| 198 | |
| 199 | protected: |
| 200 | void play(CommandBuffer::ExecutionState& executionState) override |
| 201 | { |
| 202 | auto cmd = reinterpret_cast<VkDispatchIndirectCommand const *>(Cast(buffer)->getOffsetPointer(offset)); |
| 203 | |
Ben Clayton | 225a130 | 2019-04-02 12:28:22 +0100 | [diff] [blame] | 204 | auto const &pipelineState = executionState.pipelineState[VK_PIPELINE_BIND_POINT_COMPUTE]; |
| 205 | |
| 206 | ComputePipeline* pipeline = static_cast<ComputePipeline*>(pipelineState.pipeline); |
Chris Forbes | fc8a46d | 2019-03-22 14:47:47 -0700 | [diff] [blame] | 207 | pipeline->run(cmd->x, cmd->y, cmd->z, |
Ben Clayton | 225a130 | 2019-04-02 12:28:22 +0100 | [diff] [blame] | 208 | pipelineState.descriptorSets, |
| 209 | pipelineState.descriptorDynamicOffsets, |
| 210 | executionState.pushConstants); |
Chris Forbes | fc8a46d | 2019-03-22 14:47:47 -0700 | [diff] [blame] | 211 | } |
| 212 | |
| 213 | private: |
| 214 | VkBuffer buffer; |
| 215 | VkDeviceSize offset; |
| 216 | }; |
| 217 | |
Alexis Hetu | 072dc0d | 2018-10-31 11:41:25 -0400 | [diff] [blame] | 218 | struct VertexBufferBind : public CommandBuffer::Command |
| 219 | { |
| 220 | VertexBufferBind(uint32_t pBinding, const VkBuffer pBuffer, const VkDeviceSize pOffset) : |
| 221 | binding(pBinding), buffer(pBuffer), offset(pOffset) |
| 222 | { |
| 223 | } |
| 224 | |
Ben Clayton | 93317ec | 2019-02-20 08:53:50 +0000 | [diff] [blame] | 225 | void play(CommandBuffer::ExecutionState& executionState) override |
Alexis Hetu | 072dc0d | 2018-10-31 11:41:25 -0400 | [diff] [blame] | 226 | { |
Alexis Hetu | 9bc7a81 | 2018-12-07 16:13:34 -0500 | [diff] [blame] | 227 | executionState.vertexInputBindings[binding] = { buffer, offset }; |
Alexis Hetu | 072dc0d | 2018-10-31 11:41:25 -0400 | [diff] [blame] | 228 | } |
| 229 | |
| 230 | uint32_t binding; |
| 231 | const VkBuffer buffer; |
| 232 | const VkDeviceSize offset; |
| 233 | }; |
| 234 | |
Chris Forbes | baf7ad3 | 2019-02-25 18:14:42 -0800 | [diff] [blame] | 235 | struct IndexBufferBind : public CommandBuffer::Command |
| 236 | { |
| 237 | IndexBufferBind(const VkBuffer buffer, const VkDeviceSize offset, const VkIndexType indexType) : |
| 238 | buffer(buffer), offset(offset), indexType(indexType) |
| 239 | { |
| 240 | |
| 241 | } |
| 242 | |
| 243 | void play(CommandBuffer::ExecutionState& executionState) override |
| 244 | { |
| 245 | executionState.indexBufferBinding = {buffer, offset}; |
| 246 | executionState.indexType = indexType; |
| 247 | } |
| 248 | |
| 249 | const VkBuffer buffer; |
| 250 | const VkDeviceSize offset; |
| 251 | const VkIndexType indexType; |
| 252 | }; |
| 253 | |
Alexis Hetu | 7383243 | 2019-04-11 16:43:18 -0400 | [diff] [blame] | 254 | struct SetViewport : public CommandBuffer::Command |
| 255 | { |
| 256 | SetViewport(const VkViewport& viewport, uint32_t viewportID) : |
| 257 | viewport(viewport), viewportID(viewportID) |
| 258 | { |
| 259 | } |
| 260 | |
| 261 | void play(CommandBuffer::ExecutionState& executionState) override |
| 262 | { |
| 263 | executionState.dynamicState.viewport = viewport; |
| 264 | } |
| 265 | |
| 266 | const VkViewport viewport; |
| 267 | uint32_t viewportID; |
| 268 | }; |
| 269 | |
| 270 | struct SetScissor : public CommandBuffer::Command |
| 271 | { |
| 272 | SetScissor(const VkRect2D& scissor, uint32_t scissorID) : |
| 273 | scissor(scissor), scissorID(scissorID) |
| 274 | { |
| 275 | } |
| 276 | |
| 277 | void play(CommandBuffer::ExecutionState& executionState) override |
| 278 | { |
| 279 | executionState.dynamicState.scissor = scissor; |
| 280 | } |
| 281 | |
| 282 | const VkRect2D scissor; |
| 283 | uint32_t scissorID; |
| 284 | }; |
| 285 | |
| 286 | struct SetDepthBias : public CommandBuffer::Command |
| 287 | { |
| 288 | SetDepthBias(float depthBiasConstantFactor, float depthBiasClamp, float depthBiasSlopeFactor) : |
| 289 | depthBiasConstantFactor(depthBiasConstantFactor), depthBiasClamp(depthBiasClamp), depthBiasSlopeFactor(depthBiasSlopeFactor) |
| 290 | { |
| 291 | } |
| 292 | |
| 293 | void play(CommandBuffer::ExecutionState& executionState) override |
| 294 | { |
| 295 | executionState.dynamicState.depthBiasConstantFactor = depthBiasConstantFactor; |
| 296 | executionState.dynamicState.depthBiasClamp = depthBiasClamp; |
| 297 | executionState.dynamicState.depthBiasSlopeFactor = depthBiasSlopeFactor; |
| 298 | } |
| 299 | |
| 300 | float depthBiasConstantFactor; |
| 301 | float depthBiasClamp; |
| 302 | float depthBiasSlopeFactor; |
| 303 | }; |
| 304 | |
| 305 | struct SetBlendConstants : public CommandBuffer::Command |
| 306 | { |
| 307 | SetBlendConstants(const float blendConstants[4]) |
| 308 | { |
| 309 | memcpy(this->blendConstants, blendConstants, sizeof(this->blendConstants)); |
| 310 | } |
| 311 | |
| 312 | void play(CommandBuffer::ExecutionState& executionState) override |
| 313 | { |
| 314 | memcpy(&(executionState.dynamicState.blendConstants[0]), blendConstants, sizeof(blendConstants)); |
| 315 | } |
| 316 | |
| 317 | float blendConstants[4]; |
| 318 | }; |
| 319 | |
| 320 | struct SetDepthBounds : public CommandBuffer::Command |
| 321 | { |
| 322 | SetDepthBounds(float minDepthBounds, float maxDepthBounds) : |
| 323 | minDepthBounds(minDepthBounds), maxDepthBounds(maxDepthBounds) |
| 324 | { |
| 325 | } |
| 326 | |
| 327 | void play(CommandBuffer::ExecutionState& executionState) override |
| 328 | { |
| 329 | executionState.dynamicState.minDepthBounds = minDepthBounds; |
| 330 | executionState.dynamicState.maxDepthBounds = maxDepthBounds; |
| 331 | } |
| 332 | |
| 333 | float minDepthBounds; |
| 334 | float maxDepthBounds; |
| 335 | }; |
| 336 | struct SetStencilCompareMask : public CommandBuffer::Command |
| 337 | { |
| 338 | SetStencilCompareMask(VkStencilFaceFlags faceMask, uint32_t compareMask) : |
| 339 | faceMask(faceMask), compareMask(compareMask) |
| 340 | { |
| 341 | } |
| 342 | |
| 343 | void play(CommandBuffer::ExecutionState& executionState) override |
| 344 | { |
| 345 | if(faceMask & VK_STENCIL_FACE_FRONT_BIT) |
| 346 | { |
| 347 | executionState.dynamicState.compareMask[0] = compareMask; |
| 348 | } |
| 349 | if(faceMask & VK_STENCIL_FACE_BACK_BIT) |
| 350 | { |
| 351 | executionState.dynamicState.compareMask[1] = compareMask; |
| 352 | } |
| 353 | } |
| 354 | |
| 355 | VkStencilFaceFlags faceMask; |
| 356 | uint32_t compareMask; |
| 357 | }; |
| 358 | |
| 359 | struct SetStencilWriteMask : public CommandBuffer::Command |
| 360 | { |
| 361 | SetStencilWriteMask(VkStencilFaceFlags faceMask, uint32_t writeMask) : |
| 362 | faceMask(faceMask), writeMask(writeMask) |
| 363 | { |
| 364 | } |
| 365 | |
| 366 | void play(CommandBuffer::ExecutionState& executionState) override |
| 367 | { |
| 368 | if(faceMask & VK_STENCIL_FACE_FRONT_BIT) |
| 369 | { |
| 370 | executionState.dynamicState.writeMask[0] = writeMask; |
| 371 | } |
| 372 | if(faceMask & VK_STENCIL_FACE_BACK_BIT) |
| 373 | { |
| 374 | executionState.dynamicState.writeMask[1] = writeMask; |
| 375 | } |
| 376 | } |
| 377 | |
| 378 | VkStencilFaceFlags faceMask; |
| 379 | uint32_t writeMask; |
| 380 | }; |
| 381 | |
| 382 | struct SetStencilReference : public CommandBuffer::Command |
| 383 | { |
| 384 | SetStencilReference(VkStencilFaceFlags faceMask, uint32_t reference) : |
| 385 | faceMask(faceMask), reference(reference) |
| 386 | { |
| 387 | } |
| 388 | |
| 389 | void play(CommandBuffer::ExecutionState& executionState) override |
| 390 | { |
| 391 | if(faceMask & VK_STENCIL_FACE_FRONT_BIT) |
| 392 | { |
| 393 | executionState.dynamicState.reference[0] = reference; |
| 394 | } |
| 395 | if(faceMask & VK_STENCIL_FACE_BACK_BIT) |
| 396 | { |
| 397 | executionState.dynamicState.reference[1] = reference; |
| 398 | } |
| 399 | } |
| 400 | |
| 401 | VkStencilFaceFlags faceMask; |
| 402 | uint32_t reference; |
| 403 | }; |
| 404 | |
Chris Forbes | e1cf863 | 2019-03-08 18:17:35 -0800 | [diff] [blame] | 405 | void CommandBuffer::ExecutionState::bindVertexInputs(sw::Context& context, int firstVertex, int firstInstance) |
Chris Forbes | 00ba176 | 2019-03-08 17:10:41 -0800 | [diff] [blame] | 406 | { |
| 407 | for(uint32_t i = 0; i < MAX_VERTEX_INPUT_BINDINGS; i++) |
| 408 | { |
| 409 | auto &attrib = context.input[i]; |
| 410 | if (attrib.count) |
| 411 | { |
| 412 | const auto &vertexInput = vertexInputBindings[attrib.binding]; |
| 413 | Buffer *buffer = Cast(vertexInput.buffer); |
| 414 | attrib.buffer = buffer ? buffer->getOffsetPointer( |
Chris Forbes | e1cf863 | 2019-03-08 18:17:35 -0800 | [diff] [blame] | 415 | attrib.offset + vertexInput.offset + attrib.vertexStride * firstVertex + attrib.instanceStride * firstInstance) : nullptr; |
Chris Forbes | 00ba176 | 2019-03-08 17:10:41 -0800 | [diff] [blame] | 416 | } |
| 417 | } |
| 418 | } |
| 419 | |
Chris Forbes | 2995dc2 | 2019-03-02 14:57:20 -0800 | [diff] [blame] | 420 | void CommandBuffer::ExecutionState::bindAttachments() |
| 421 | { |
| 422 | // Binds all the attachments for the current subpass |
| 423 | // Ideally this would be performed by BeginRenderPass and NextSubpass, but |
| 424 | // there is too much stomping of the renderer's state by setContext() in |
| 425 | // draws. |
| 426 | |
| 427 | for (auto i = 0u; i < renderPass->getCurrentSubpass().colorAttachmentCount; i++) |
| 428 | { |
| 429 | auto attachmentReference = renderPass->getCurrentSubpass().pColorAttachments[i]; |
| 430 | if (attachmentReference.attachment != VK_ATTACHMENT_UNUSED) |
| 431 | { |
| 432 | auto attachment = renderPassFramebuffer->getAttachment(attachmentReference.attachment); |
Chris Forbes | 37f2bd8 | 2019-04-19 17:24:36 -0700 | [diff] [blame] | 433 | renderer->setRenderTarget(i, attachment); |
Chris Forbes | 2995dc2 | 2019-03-02 14:57:20 -0800 | [diff] [blame] | 434 | } |
| 435 | } |
| 436 | |
| 437 | auto attachmentReference = renderPass->getCurrentSubpass().pDepthStencilAttachment; |
| 438 | if (attachmentReference && attachmentReference->attachment != VK_ATTACHMENT_UNUSED) |
| 439 | { |
| 440 | auto attachment = renderPassFramebuffer->getAttachment(attachmentReference->attachment); |
| 441 | if (attachment->hasDepthAspect()) |
| 442 | { |
Chris Forbes | 37f2bd8 | 2019-04-19 17:24:36 -0700 | [diff] [blame] | 443 | renderer->setDepthBuffer(attachment); |
Chris Forbes | 2995dc2 | 2019-03-02 14:57:20 -0800 | [diff] [blame] | 444 | } |
| 445 | if (attachment->hasStencilAspect()) |
| 446 | { |
Chris Forbes | 37f2bd8 | 2019-04-19 17:24:36 -0700 | [diff] [blame] | 447 | renderer->setStencilBuffer(attachment); |
Chris Forbes | 2995dc2 | 2019-03-02 14:57:20 -0800 | [diff] [blame] | 448 | } |
| 449 | } |
| 450 | } |
| 451 | |
Chris Forbes | 48b3587 | 2019-03-22 14:12:50 -0700 | [diff] [blame] | 452 | struct DrawBase : public CommandBuffer::Command |
Alexis Hetu | 072dc0d | 2018-10-31 11:41:25 -0400 | [diff] [blame] | 453 | { |
Chris Forbes | 48b3587 | 2019-03-22 14:12:50 -0700 | [diff] [blame] | 454 | int bytesPerIndex(CommandBuffer::ExecutionState const& executionState) |
Alexis Hetu | 072dc0d | 2018-10-31 11:41:25 -0400 | [diff] [blame] | 455 | { |
Chris Forbes | 48b3587 | 2019-03-22 14:12:50 -0700 | [diff] [blame] | 456 | return executionState.indexType == VK_INDEX_TYPE_UINT16 ? 2 : 4; |
Alexis Hetu | 072dc0d | 2018-10-31 11:41:25 -0400 | [diff] [blame] | 457 | } |
| 458 | |
Chris Forbes | 48b3587 | 2019-03-22 14:12:50 -0700 | [diff] [blame] | 459 | void draw(CommandBuffer::ExecutionState& executionState, bool indexed, |
| 460 | uint32_t count, uint32_t instanceCount, uint32_t first, int32_t vertexOffset, uint32_t firstInstance) |
Chris Forbes | baf7ad3 | 2019-02-25 18:14:42 -0800 | [diff] [blame] | 461 | { |
Ben Clayton | 225a130 | 2019-04-02 12:28:22 +0100 | [diff] [blame] | 462 | auto const &pipelineState = executionState.pipelineState[VK_PIPELINE_BIND_POINT_GRAPHICS]; |
| 463 | |
| 464 | GraphicsPipeline* pipeline = static_cast<GraphicsPipeline*>(pipelineState.pipeline); |
Chris Forbes | baf7ad3 | 2019-02-25 18:14:42 -0800 | [diff] [blame] | 465 | |
| 466 | sw::Context context = pipeline->getContext(); |
Chris Forbes | e1cf863 | 2019-03-08 18:17:35 -0800 | [diff] [blame] | 467 | |
| 468 | executionState.bindVertexInputs(context, vertexOffset, firstInstance); |
Chris Forbes | baf7ad3 | 2019-02-25 18:14:42 -0800 | [diff] [blame] | 469 | |
Ben Clayton | 225a130 | 2019-04-02 12:28:22 +0100 | [diff] [blame] | 470 | context.descriptorSets = pipelineState.descriptorSets; |
| 471 | context.descriptorDynamicOffsets = pipelineState.descriptorDynamicOffsets; |
Chris Forbes | a30de54 | 2019-03-18 18:51:55 -0700 | [diff] [blame] | 472 | context.pushConstants = executionState.pushConstants; |
| 473 | |
Alexis Hetu | 7383243 | 2019-04-11 16:43:18 -0400 | [diff] [blame] | 474 | if(indexed) |
Chris Forbes | 48b3587 | 2019-03-22 14:12:50 -0700 | [diff] [blame] | 475 | { |
| 476 | context.indexBuffer = Cast(executionState.indexBufferBinding.buffer)->getOffsetPointer( |
| 477 | executionState.indexBufferBinding.offset + first * bytesPerIndex(executionState)); |
Chris Forbes | 48b3587 | 2019-03-22 14:12:50 -0700 | [diff] [blame] | 478 | } |
Chris Forbes | baf7ad3 | 2019-02-25 18:14:42 -0800 | [diff] [blame] | 479 | |
Alexis Hetu | 7383243 | 2019-04-11 16:43:18 -0400 | [diff] [blame] | 480 | // Apply either pipeline state or dynamic state |
| 481 | executionState.renderer->setScissor(pipeline->hasDynamicState(VK_DYNAMIC_STATE_SCISSOR) ? |
| 482 | executionState.dynamicState.scissor : pipeline->getScissor()); |
| 483 | executionState.renderer->setViewport(pipeline->hasDynamicState(VK_DYNAMIC_STATE_VIEWPORT) ? |
| 484 | executionState.dynamicState.viewport : pipeline->getViewport()); |
| 485 | executionState.renderer->setBlendConstant(pipeline->hasDynamicState(VK_DYNAMIC_STATE_BLEND_CONSTANTS) ? |
| 486 | executionState.dynamicState.blendConstants : pipeline->getBlendConstants()); |
| 487 | if(pipeline->hasDynamicState(VK_DYNAMIC_STATE_DEPTH_BIAS)) |
| 488 | { |
| 489 | // If the depth bias clamping feature is not enabled, depthBiasClamp must be 0.0 |
| 490 | ASSERT(executionState.dynamicState.depthBiasClamp == 0.0f); |
| 491 | |
| 492 | context.depthBias = executionState.dynamicState.depthBiasConstantFactor; |
| 493 | context.slopeDepthBias = executionState.dynamicState.depthBiasSlopeFactor; |
| 494 | } |
| 495 | if(pipeline->hasDynamicState(VK_DYNAMIC_STATE_DEPTH_BOUNDS) && context.depthBoundsTestEnable) |
| 496 | { |
| 497 | // Unless the VK_EXT_depth_range_unrestricted extension is enabled minDepthBounds and maxDepthBounds must be between 0.0 and 1.0, inclusive |
| 498 | ASSERT(executionState.dynamicState.minDepthBounds >= 0.0f && executionState.dynamicState.minDepthBounds <= 1.0f); |
| 499 | ASSERT(executionState.dynamicState.maxDepthBounds >= 0.0f && executionState.dynamicState.maxDepthBounds <= 1.0f); |
| 500 | |
| 501 | UNIMPLEMENTED("depthBoundsTestEnable"); |
| 502 | } |
| 503 | if(pipeline->hasDynamicState(VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK) && context.stencilEnable) |
| 504 | { |
| 505 | context.frontStencil.compareMask = executionState.dynamicState.compareMask[0]; |
| 506 | context.backStencil.compareMask = executionState.dynamicState.compareMask[1]; |
| 507 | } |
| 508 | if(pipeline->hasDynamicState(VK_DYNAMIC_STATE_STENCIL_WRITE_MASK) && context.stencilEnable) |
| 509 | { |
| 510 | context.frontStencil.writeMask = executionState.dynamicState.writeMask[0]; |
| 511 | context.backStencil.writeMask = executionState.dynamicState.writeMask[1]; |
| 512 | } |
| 513 | if(pipeline->hasDynamicState(VK_DYNAMIC_STATE_STENCIL_REFERENCE) && context.stencilEnable) |
| 514 | { |
| 515 | context.frontStencil.reference = executionState.dynamicState.reference[0]; |
| 516 | context.backStencil.reference = executionState.dynamicState.reference[1]; |
| 517 | } |
| 518 | |
Chris Forbes | baf7ad3 | 2019-02-25 18:14:42 -0800 | [diff] [blame] | 519 | executionState.renderer->setContext(context); |
Chris Forbes | baf7ad3 | 2019-02-25 18:14:42 -0800 | [diff] [blame] | 520 | |
Chris Forbes | 2995dc2 | 2019-03-02 14:57:20 -0800 | [diff] [blame] | 521 | executionState.bindAttachments(); |
Chris Forbes | baf7ad3 | 2019-02-25 18:14:42 -0800 | [diff] [blame] | 522 | |
Chris Forbes | 48b3587 | 2019-03-22 14:12:50 -0700 | [diff] [blame] | 523 | const uint32_t primitiveCount = pipeline->computePrimitiveCount(count); |
Chris Forbes | e1cf863 | 2019-03-08 18:17:35 -0800 | [diff] [blame] | 524 | for(uint32_t instance = firstInstance; instance != firstInstance + instanceCount; instance++) |
Chris Forbes | baf7ad3 | 2019-02-25 18:14:42 -0800 | [diff] [blame] | 525 | { |
| 526 | executionState.renderer->setInstanceID(instance); |
Alexis Hetu | e1f51b9 | 2019-04-23 15:34:34 -0400 | [diff] [blame] | 527 | executionState.renderer->draw(context.topology, executionState.indexType, primitiveCount, vertexOffset, |
| 528 | executionState.fence); |
Chris Forbes | e1cf863 | 2019-03-08 18:17:35 -0800 | [diff] [blame] | 529 | executionState.renderer->advanceInstanceAttributes(); |
Chris Forbes | baf7ad3 | 2019-02-25 18:14:42 -0800 | [diff] [blame] | 530 | } |
| 531 | } |
Chris Forbes | 48b3587 | 2019-03-22 14:12:50 -0700 | [diff] [blame] | 532 | }; |
| 533 | |
| 534 | struct Draw : public DrawBase |
| 535 | { |
| 536 | Draw(uint32_t vertexCount, uint32_t instanceCount, uint32_t firstVertex, uint32_t firstInstance) |
| 537 | : vertexCount(vertexCount), instanceCount(instanceCount), firstVertex(firstVertex), firstInstance(firstInstance) |
| 538 | { |
| 539 | } |
| 540 | |
| 541 | void play(CommandBuffer::ExecutionState& executionState) override |
| 542 | { |
| 543 | draw(executionState, false, vertexCount, instanceCount, 0, firstVertex, firstInstance); |
| 544 | } |
| 545 | |
| 546 | uint32_t vertexCount; |
| 547 | uint32_t instanceCount; |
| 548 | uint32_t firstVertex; |
| 549 | uint32_t firstInstance; |
| 550 | }; |
| 551 | |
| 552 | struct DrawIndexed : public DrawBase |
| 553 | { |
| 554 | DrawIndexed(uint32_t indexCount, uint32_t instanceCount, uint32_t firstIndex, int32_t vertexOffset, uint32_t firstInstance) |
| 555 | : indexCount(indexCount), instanceCount(instanceCount), firstIndex(firstIndex), vertexOffset(vertexOffset), firstInstance(firstInstance) |
| 556 | { |
| 557 | } |
| 558 | |
| 559 | void play(CommandBuffer::ExecutionState& executionState) override |
| 560 | { |
| 561 | draw(executionState, true, indexCount, instanceCount, firstIndex, vertexOffset, firstInstance); |
| 562 | } |
Chris Forbes | baf7ad3 | 2019-02-25 18:14:42 -0800 | [diff] [blame] | 563 | |
| 564 | uint32_t indexCount; |
| 565 | uint32_t instanceCount; |
| 566 | uint32_t firstIndex; |
| 567 | int32_t vertexOffset; |
| 568 | uint32_t firstInstance; |
| 569 | }; |
| 570 | |
Chris Forbes | 48b3587 | 2019-03-22 14:12:50 -0700 | [diff] [blame] | 571 | struct DrawIndirect : public DrawBase |
| 572 | { |
| 573 | DrawIndirect(VkBuffer buffer, VkDeviceSize offset, uint32_t drawCount, uint32_t stride) |
| 574 | : buffer(buffer), offset(offset), drawCount(drawCount), stride(stride) |
| 575 | { |
| 576 | } |
| 577 | |
| 578 | void play(CommandBuffer::ExecutionState& executionState) override |
| 579 | { |
| 580 | for (auto drawId = 0u; drawId < drawCount; drawId++) |
| 581 | { |
| 582 | auto cmd = reinterpret_cast<VkDrawIndirectCommand const *>(Cast(buffer)->getOffsetPointer(offset + drawId * stride)); |
| 583 | draw(executionState, false, cmd->vertexCount, cmd->instanceCount, 0, cmd->firstVertex, cmd->firstInstance); |
| 584 | } |
| 585 | } |
| 586 | |
| 587 | VkBuffer buffer; |
| 588 | VkDeviceSize offset; |
| 589 | uint32_t drawCount; |
| 590 | uint32_t stride; |
| 591 | }; |
| 592 | |
| 593 | struct DrawIndexedIndirect : public DrawBase |
| 594 | { |
| 595 | DrawIndexedIndirect(VkBuffer buffer, VkDeviceSize offset, uint32_t drawCount, uint32_t stride) |
| 596 | : buffer(buffer), offset(offset), drawCount(drawCount), stride(stride) |
| 597 | { |
| 598 | } |
| 599 | |
| 600 | void play(CommandBuffer::ExecutionState& executionState) override |
| 601 | { |
| 602 | for (auto drawId = 0u; drawId < drawCount; drawId++) |
| 603 | { |
| 604 | auto cmd = reinterpret_cast<VkDrawIndexedIndirectCommand const *>(Cast(buffer)->getOffsetPointer(offset + drawId * stride)); |
| 605 | draw(executionState, true, cmd->indexCount, cmd->instanceCount, cmd->firstIndex, cmd->vertexOffset, cmd->firstInstance); |
| 606 | } |
| 607 | } |
| 608 | |
| 609 | VkBuffer buffer; |
| 610 | VkDeviceSize offset; |
| 611 | uint32_t drawCount; |
| 612 | uint32_t stride; |
| 613 | }; |
| 614 | |
Alexis Hetu | 09056de | 2018-12-07 12:40:00 -0500 | [diff] [blame] | 615 | struct ImageToImageCopy : public CommandBuffer::Command |
| 616 | { |
| 617 | ImageToImageCopy(VkImage pSrcImage, VkImage pDstImage, const VkImageCopy& pRegion) : |
| 618 | srcImage(pSrcImage), dstImage(pDstImage), region(pRegion) |
| 619 | { |
| 620 | } |
| 621 | |
Ben Clayton | 93317ec | 2019-02-20 08:53:50 +0000 | [diff] [blame] | 622 | void play(CommandBuffer::ExecutionState& executionState) override |
Alexis Hetu | 09056de | 2018-12-07 12:40:00 -0500 | [diff] [blame] | 623 | { |
| 624 | Cast(srcImage)->copyTo(dstImage, region); |
| 625 | } |
| 626 | |
| 627 | private: |
| 628 | VkImage srcImage; |
| 629 | VkImage dstImage; |
| 630 | const VkImageCopy region; |
| 631 | }; |
| 632 | |
Alexis Hetu | bb0a7f0 | 2018-12-14 16:50:43 -0500 | [diff] [blame] | 633 | struct BufferToBufferCopy : public CommandBuffer::Command |
| 634 | { |
| 635 | BufferToBufferCopy(VkBuffer pSrcBuffer, VkBuffer pDstBuffer, const VkBufferCopy& pRegion) : |
| 636 | srcBuffer(pSrcBuffer), dstBuffer(pDstBuffer), region(pRegion) |
| 637 | { |
| 638 | } |
| 639 | |
Ben Clayton | 93317ec | 2019-02-20 08:53:50 +0000 | [diff] [blame] | 640 | void play(CommandBuffer::ExecutionState& executionState) override |
Alexis Hetu | bb0a7f0 | 2018-12-14 16:50:43 -0500 | [diff] [blame] | 641 | { |
| 642 | Cast(srcBuffer)->copyTo(Cast(dstBuffer), region); |
| 643 | } |
| 644 | |
| 645 | private: |
| 646 | VkBuffer srcBuffer; |
| 647 | VkBuffer dstBuffer; |
| 648 | const VkBufferCopy region; |
| 649 | }; |
| 650 | |
Alexis Hetu | 072dc0d | 2018-10-31 11:41:25 -0400 | [diff] [blame] | 651 | struct ImageToBufferCopy : public CommandBuffer::Command |
| 652 | { |
| 653 | ImageToBufferCopy(VkImage pSrcImage, VkBuffer pDstBuffer, const VkBufferImageCopy& pRegion) : |
| 654 | srcImage(pSrcImage), dstBuffer(pDstBuffer), region(pRegion) |
| 655 | { |
| 656 | } |
| 657 | |
Ben Clayton | 93317ec | 2019-02-20 08:53:50 +0000 | [diff] [blame] | 658 | void play(CommandBuffer::ExecutionState& executionState) override |
Alexis Hetu | 072dc0d | 2018-10-31 11:41:25 -0400 | [diff] [blame] | 659 | { |
Alexis Hetu | 09056de | 2018-12-07 12:40:00 -0500 | [diff] [blame] | 660 | Cast(srcImage)->copyTo(dstBuffer, region); |
Alexis Hetu | 072dc0d | 2018-10-31 11:41:25 -0400 | [diff] [blame] | 661 | } |
| 662 | |
| 663 | private: |
| 664 | VkImage srcImage; |
| 665 | VkBuffer dstBuffer; |
| 666 | const VkBufferImageCopy region; |
| 667 | }; |
| 668 | |
Alexis Hetu | 09056de | 2018-12-07 12:40:00 -0500 | [diff] [blame] | 669 | struct BufferToImageCopy : public CommandBuffer::Command |
| 670 | { |
| 671 | BufferToImageCopy(VkBuffer pSrcBuffer, VkImage pDstImage, const VkBufferImageCopy& pRegion) : |
| 672 | srcBuffer(pSrcBuffer), dstImage(pDstImage), region(pRegion) |
| 673 | { |
| 674 | } |
| 675 | |
Ben Clayton | 93317ec | 2019-02-20 08:53:50 +0000 | [diff] [blame] | 676 | void play(CommandBuffer::ExecutionState& executionState) override |
Alexis Hetu | 09056de | 2018-12-07 12:40:00 -0500 | [diff] [blame] | 677 | { |
| 678 | Cast(dstImage)->copyFrom(srcBuffer, region); |
| 679 | } |
| 680 | |
| 681 | private: |
| 682 | VkBuffer srcBuffer; |
| 683 | VkImage dstImage; |
| 684 | const VkBufferImageCopy region; |
| 685 | }; |
| 686 | |
Alexis Hetu | 7fb0b73 | 2019-02-07 13:50:10 -0500 | [diff] [blame] | 687 | struct FillBuffer : public CommandBuffer::Command |
| 688 | { |
| 689 | FillBuffer(VkBuffer dstBuffer, VkDeviceSize dstOffset, VkDeviceSize size, uint32_t data) : |
| 690 | dstBuffer(dstBuffer), dstOffset(dstOffset), size(size), data(data) |
| 691 | { |
| 692 | } |
| 693 | |
Ben Clayton | 93317ec | 2019-02-20 08:53:50 +0000 | [diff] [blame] | 694 | void play(CommandBuffer::ExecutionState& executionState) override |
Alexis Hetu | 7fb0b73 | 2019-02-07 13:50:10 -0500 | [diff] [blame] | 695 | { |
| 696 | Cast(dstBuffer)->fill(dstOffset, size, data); |
| 697 | } |
| 698 | |
| 699 | private: |
| 700 | VkBuffer dstBuffer; |
| 701 | VkDeviceSize dstOffset; |
| 702 | VkDeviceSize size; |
| 703 | uint32_t data; |
| 704 | }; |
| 705 | |
| 706 | struct UpdateBuffer : public CommandBuffer::Command |
| 707 | { |
| 708 | UpdateBuffer(VkBuffer dstBuffer, VkDeviceSize dstOffset, VkDeviceSize dataSize, const void* pData) : |
| 709 | dstBuffer(dstBuffer), dstOffset(dstOffset), dataSize(dataSize), pData(pData) |
| 710 | { |
| 711 | } |
| 712 | |
Ben Clayton | 93317ec | 2019-02-20 08:53:50 +0000 | [diff] [blame] | 713 | void play(CommandBuffer::ExecutionState& executionState) override |
Alexis Hetu | 7fb0b73 | 2019-02-07 13:50:10 -0500 | [diff] [blame] | 714 | { |
| 715 | Cast(dstBuffer)->update(dstOffset, dataSize, pData); |
| 716 | } |
| 717 | |
| 718 | private: |
| 719 | VkBuffer dstBuffer; |
| 720 | VkDeviceSize dstOffset; |
| 721 | VkDeviceSize dataSize; |
| 722 | const void* pData; |
| 723 | }; |
| 724 | |
Alexis Hetu | 7ca9f4a | 2019-01-17 14:51:43 -0500 | [diff] [blame] | 725 | struct ClearColorImage : public CommandBuffer::Command |
Alexis Hetu | f14ed32 | 2019-01-16 15:54:55 -0500 | [diff] [blame] | 726 | { |
Alexis Hetu | 7ca9f4a | 2019-01-17 14:51:43 -0500 | [diff] [blame] | 727 | ClearColorImage(VkImage image, const VkClearColorValue& color, const VkImageSubresourceRange& range) : |
Alexis Hetu | f14ed32 | 2019-01-16 15:54:55 -0500 | [diff] [blame] | 728 | image(image), color(color), range(range) |
| 729 | { |
| 730 | } |
| 731 | |
Ben Clayton | 93317ec | 2019-02-20 08:53:50 +0000 | [diff] [blame] | 732 | void play(CommandBuffer::ExecutionState& executionState) override |
Alexis Hetu | f14ed32 | 2019-01-16 15:54:55 -0500 | [diff] [blame] | 733 | { |
| 734 | Cast(image)->clear(color, range); |
| 735 | } |
| 736 | |
| 737 | private: |
| 738 | VkImage image; |
| 739 | const VkClearColorValue color; |
| 740 | const VkImageSubresourceRange range; |
| 741 | }; |
| 742 | |
Alexis Hetu | 7ca9f4a | 2019-01-17 14:51:43 -0500 | [diff] [blame] | 743 | struct ClearDepthStencilImage : public CommandBuffer::Command |
| 744 | { |
| 745 | ClearDepthStencilImage(VkImage image, const VkClearDepthStencilValue& depthStencil, const VkImageSubresourceRange& range) : |
| 746 | image(image), depthStencil(depthStencil), range(range) |
| 747 | { |
| 748 | } |
| 749 | |
Ben Clayton | 93317ec | 2019-02-20 08:53:50 +0000 | [diff] [blame] | 750 | void play(CommandBuffer::ExecutionState& executionState) override |
Alexis Hetu | 7ca9f4a | 2019-01-17 14:51:43 -0500 | [diff] [blame] | 751 | { |
| 752 | Cast(image)->clear(depthStencil, range); |
| 753 | } |
| 754 | |
| 755 | private: |
| 756 | VkImage image; |
| 757 | const VkClearDepthStencilValue depthStencil; |
| 758 | const VkImageSubresourceRange range; |
| 759 | }; |
| 760 | |
Alexis Hetu | 1cd31ea | 2019-01-17 17:14:57 -0500 | [diff] [blame] | 761 | struct ClearAttachment : public CommandBuffer::Command |
| 762 | { |
| 763 | ClearAttachment(const VkClearAttachment& attachment, const VkClearRect& rect) : |
| 764 | attachment(attachment), rect(rect) |
| 765 | { |
| 766 | } |
| 767 | |
Ben Clayton | 93317ec | 2019-02-20 08:53:50 +0000 | [diff] [blame] | 768 | void play(CommandBuffer::ExecutionState& executionState) override |
Alexis Hetu | 1cd31ea | 2019-01-17 17:14:57 -0500 | [diff] [blame] | 769 | { |
Chris Forbes | ed46cde | 2019-04-22 12:49:21 -0700 | [diff] [blame] | 770 | // attachment clears are drawing operations, and so have rasterization-order guarantees. |
| 771 | // however, we don't do the clear through the rasterizer, so need to ensure prior drawing |
| 772 | // has completed first. |
| 773 | executionState.renderer->synchronize(); |
Alexis Hetu | 54ec759 | 2019-03-20 14:37:16 -0400 | [diff] [blame] | 774 | executionState.renderPassFramebuffer->clear(executionState.renderPass, attachment, rect); |
Alexis Hetu | 1cd31ea | 2019-01-17 17:14:57 -0500 | [diff] [blame] | 775 | } |
| 776 | |
| 777 | private: |
| 778 | const VkClearAttachment attachment; |
| 779 | const VkClearRect rect; |
| 780 | }; |
| 781 | |
Alexis Hetu | 809d011 | 2018-12-17 17:00:28 -0500 | [diff] [blame] | 782 | struct BlitImage : public CommandBuffer::Command |
| 783 | { |
| 784 | BlitImage(VkImage srcImage, VkImage dstImage, const VkImageBlit& region, VkFilter filter) : |
| 785 | srcImage(srcImage), dstImage(dstImage), region(region), filter(filter) |
| 786 | { |
| 787 | } |
| 788 | |
Ben Clayton | 93317ec | 2019-02-20 08:53:50 +0000 | [diff] [blame] | 789 | void play(CommandBuffer::ExecutionState& executionState) override |
Alexis Hetu | 809d011 | 2018-12-17 17:00:28 -0500 | [diff] [blame] | 790 | { |
| 791 | Cast(srcImage)->blit(dstImage, region, filter); |
| 792 | } |
| 793 | |
| 794 | private: |
| 795 | VkImage srcImage; |
| 796 | VkImage dstImage; |
Ben Clayton | 24021a2 | 2019-02-19 11:42:31 +0000 | [diff] [blame] | 797 | VkImageBlit region; |
Alexis Hetu | 809d011 | 2018-12-17 17:00:28 -0500 | [diff] [blame] | 798 | VkFilter filter; |
| 799 | }; |
| 800 | |
Alexis Hetu | e5e33cd | 2019-04-11 10:24:52 -0400 | [diff] [blame] | 801 | struct ResolveImage : public CommandBuffer::Command |
| 802 | { |
| 803 | ResolveImage(VkImage srcImage, VkImage dstImage, const VkImageResolve& region) : |
| 804 | srcImage(srcImage), dstImage(dstImage), region(region) |
| 805 | { |
| 806 | } |
| 807 | |
| 808 | void play(CommandBuffer::ExecutionState& executionState) override |
| 809 | { |
| 810 | Cast(srcImage)->resolve(dstImage, region); |
| 811 | } |
| 812 | |
| 813 | private: |
| 814 | VkImage srcImage; |
| 815 | VkImage dstImage; |
| 816 | VkImageResolve region; |
| 817 | }; |
| 818 | |
Alexis Hetu | 9a6c28b | 2018-11-20 11:47:18 -0500 | [diff] [blame] | 819 | struct PipelineBarrier : public CommandBuffer::Command |
| 820 | { |
| 821 | PipelineBarrier() |
| 822 | { |
| 823 | } |
| 824 | |
Ben Clayton | 93317ec | 2019-02-20 08:53:50 +0000 | [diff] [blame] | 825 | void play(CommandBuffer::ExecutionState& executionState) override |
Alexis Hetu | 9a6c28b | 2018-11-20 11:47:18 -0500 | [diff] [blame] | 826 | { |
Alexis Hetu | ead1a34 | 2019-02-26 17:03:00 -0500 | [diff] [blame] | 827 | // This is a very simple implementation that simply calls sw::Renderer::synchronize(), |
| 828 | // since the driver is free to move the source stage towards the bottom of the pipe |
| 829 | // and the target stage towards the top, so a full pipeline sync is spec compliant. |
| 830 | executionState.renderer->synchronize(); |
Alexis Hetu | 9a6c28b | 2018-11-20 11:47:18 -0500 | [diff] [blame] | 831 | |
| 832 | // Right now all buffers are read-only in drawcalls but a similar mechanism will be required once we support SSBOs. |
| 833 | |
| 834 | // Also note that this would be a good moment to update cube map borders or decompress compressed textures, if necessary. |
| 835 | } |
| 836 | |
| 837 | private: |
| 838 | }; |
| 839 | |
Alexis Hetu | 3f5a479 | 2019-02-01 17:49:55 -0500 | [diff] [blame] | 840 | struct SignalEvent : public CommandBuffer::Command |
| 841 | { |
| 842 | SignalEvent(VkEvent ev, VkPipelineStageFlags stageMask) : ev(ev), stageMask(stageMask) |
| 843 | { |
| 844 | } |
| 845 | |
Ben Clayton | 93317ec | 2019-02-20 08:53:50 +0000 | [diff] [blame] | 846 | void play(CommandBuffer::ExecutionState& executionState) override |
Alexis Hetu | 3f5a479 | 2019-02-01 17:49:55 -0500 | [diff] [blame] | 847 | { |
Alexis Hetu | e1f51b9 | 2019-04-23 15:34:34 -0400 | [diff] [blame] | 848 | executionState.renderer->synchronize(); |
| 849 | Cast(ev)->signal(); |
Alexis Hetu | 3f5a479 | 2019-02-01 17:49:55 -0500 | [diff] [blame] | 850 | } |
| 851 | |
| 852 | private: |
| 853 | VkEvent ev; |
| 854 | VkPipelineStageFlags stageMask; // FIXME(b/117835459) : We currently ignore the flags and signal the event at the last stage |
| 855 | }; |
| 856 | |
| 857 | struct ResetEvent : public CommandBuffer::Command |
| 858 | { |
| 859 | ResetEvent(VkEvent ev, VkPipelineStageFlags stageMask) : ev(ev), stageMask(stageMask) |
| 860 | { |
| 861 | } |
| 862 | |
Ben Clayton | 93317ec | 2019-02-20 08:53:50 +0000 | [diff] [blame] | 863 | void play(CommandBuffer::ExecutionState& executionState) override |
Alexis Hetu | 3f5a479 | 2019-02-01 17:49:55 -0500 | [diff] [blame] | 864 | { |
| 865 | Cast(ev)->reset(); |
| 866 | } |
| 867 | |
| 868 | private: |
| 869 | VkEvent ev; |
| 870 | VkPipelineStageFlags stageMask; // FIXME(b/117835459) : We currently ignore the flags and reset the event at the last stage |
| 871 | }; |
| 872 | |
Alexis Hetu | 9041bb7 | 2019-03-15 14:45:45 -0400 | [diff] [blame] | 873 | struct WaitEvent : public CommandBuffer::Command |
| 874 | { |
| 875 | WaitEvent(VkEvent ev) : ev(ev) |
| 876 | { |
| 877 | } |
| 878 | |
| 879 | void play(CommandBuffer::ExecutionState& executionState) override |
| 880 | { |
Alexis Hetu | e1f51b9 | 2019-04-23 15:34:34 -0400 | [diff] [blame] | 881 | executionState.renderer->synchronize(); |
| 882 | Cast(ev)->wait(); |
Alexis Hetu | 9041bb7 | 2019-03-15 14:45:45 -0400 | [diff] [blame] | 883 | } |
| 884 | |
| 885 | private: |
| 886 | VkEvent ev; |
| 887 | }; |
| 888 | |
Alexis Hetu | 5edafb5 | 2019-02-15 14:56:22 -0500 | [diff] [blame] | 889 | struct BindDescriptorSet : public CommandBuffer::Command |
| 890 | { |
Ben Clayton | 225a130 | 2019-04-02 12:28:22 +0100 | [diff] [blame] | 891 | BindDescriptorSet(VkPipelineBindPoint pipelineBindPoint, uint32_t set, const VkDescriptorSet& descriptorSet, |
| 892 | uint32_t dynamicOffsetCount, uint32_t const *dynamicOffsets) |
| 893 | : pipelineBindPoint(pipelineBindPoint), set(set), descriptorSet(descriptorSet), |
| 894 | dynamicOffsetCount(dynamicOffsetCount) |
Alexis Hetu | 5edafb5 | 2019-02-15 14:56:22 -0500 | [diff] [blame] | 895 | { |
Ben Clayton | 225a130 | 2019-04-02 12:28:22 +0100 | [diff] [blame] | 896 | for (uint32_t i = 0; i < dynamicOffsetCount; i++) |
| 897 | { |
| 898 | this->dynamicOffsets[i] = dynamicOffsets[i]; |
| 899 | } |
Alexis Hetu | 5edafb5 | 2019-02-15 14:56:22 -0500 | [diff] [blame] | 900 | } |
| 901 | |
| 902 | void play(CommandBuffer::ExecutionState& executionState) |
| 903 | { |
Ben Clayton | 225a130 | 2019-04-02 12:28:22 +0100 | [diff] [blame] | 904 | ASSERT_OR_RETURN((pipelineBindPoint < VK_PIPELINE_BIND_POINT_RANGE_SIZE) && (set < MAX_BOUND_DESCRIPTOR_SETS)); |
| 905 | auto &pipelineState = executionState.pipelineState[pipelineBindPoint]; |
| 906 | auto pipelineLayout = pipelineState.pipeline->getLayout(); |
| 907 | auto dynamicOffsetBase = pipelineLayout->getDynamicOffsetBase(set); |
| 908 | ASSERT_OR_RETURN(dynamicOffsetBase + dynamicOffsetCount <= MAX_DESCRIPTOR_SET_COMBINED_BUFFERS_DYNAMIC); |
| 909 | |
| 910 | pipelineState.descriptorSets[set] = vk::Cast(descriptorSet); |
| 911 | for (uint32_t i = 0; i < dynamicOffsetCount; i++) |
| 912 | { |
| 913 | pipelineState.descriptorDynamicOffsets[dynamicOffsetBase + i] = dynamicOffsets[i]; |
| 914 | } |
Alexis Hetu | 5edafb5 | 2019-02-15 14:56:22 -0500 | [diff] [blame] | 915 | } |
| 916 | |
| 917 | private: |
| 918 | VkPipelineBindPoint pipelineBindPoint; |
| 919 | uint32_t set; |
| 920 | const VkDescriptorSet descriptorSet; |
Ben Clayton | 225a130 | 2019-04-02 12:28:22 +0100 | [diff] [blame] | 921 | uint32_t dynamicOffsetCount; |
| 922 | vk::DescriptorSet::DynamicOffsets dynamicOffsets; |
Alexis Hetu | 5edafb5 | 2019-02-15 14:56:22 -0500 | [diff] [blame] | 923 | }; |
| 924 | |
Chris Forbes | a30de54 | 2019-03-18 18:51:55 -0700 | [diff] [blame] | 925 | struct SetPushConstants : public CommandBuffer::Command |
| 926 | { |
| 927 | SetPushConstants(uint32_t offset, uint32_t size, void const *pValues) |
| 928 | : offset(offset), size(size) |
| 929 | { |
| 930 | ASSERT(offset < MAX_PUSH_CONSTANT_SIZE); |
| 931 | ASSERT(offset + size <= MAX_PUSH_CONSTANT_SIZE); |
| 932 | |
| 933 | memcpy(data, pValues, size); |
| 934 | } |
| 935 | |
| 936 | void play(CommandBuffer::ExecutionState& executionState) |
| 937 | { |
| 938 | memcpy(&executionState.pushConstants.data[offset], data, size); |
| 939 | } |
| 940 | |
| 941 | private: |
| 942 | uint32_t offset; |
| 943 | uint32_t size; |
| 944 | unsigned char data[MAX_PUSH_CONSTANT_SIZE]; |
| 945 | }; |
| 946 | |
Alexis Hetu | f0aa9d5 | 2019-04-01 17:06:47 -0400 | [diff] [blame] | 947 | struct BeginQuery : public CommandBuffer::Command |
| 948 | { |
| 949 | BeginQuery(VkQueryPool queryPool, uint32_t query, VkQueryControlFlags flags) |
| 950 | : queryPool(queryPool), query(query), flags(flags) |
| 951 | { |
| 952 | } |
| 953 | |
| 954 | void play(CommandBuffer::ExecutionState& executionState) |
| 955 | { |
| 956 | executionState.renderer->addQuery(Cast(queryPool)->getQuery(query)); |
| 957 | Cast(queryPool)->begin(query, flags); |
| 958 | } |
| 959 | |
| 960 | private: |
| 961 | VkQueryPool queryPool; |
| 962 | uint32_t query; |
| 963 | VkQueryControlFlags flags; |
| 964 | }; |
| 965 | |
| 966 | struct EndQuery : public CommandBuffer::Command |
| 967 | { |
| 968 | EndQuery(VkQueryPool queryPool, uint32_t query) |
| 969 | : queryPool(queryPool), query(query) |
| 970 | { |
| 971 | } |
| 972 | |
| 973 | void play(CommandBuffer::ExecutionState& executionState) |
| 974 | { |
| 975 | executionState.renderer->removeQuery(Cast(queryPool)->getQuery(query)); |
| 976 | Cast(queryPool)->end(query); |
| 977 | } |
| 978 | |
| 979 | private: |
| 980 | VkQueryPool queryPool; |
| 981 | uint32_t query; |
| 982 | }; |
| 983 | |
| 984 | struct ResetQueryPool : public CommandBuffer::Command |
| 985 | { |
| 986 | ResetQueryPool(VkQueryPool queryPool, uint32_t firstQuery, uint32_t queryCount) |
| 987 | : queryPool(queryPool), firstQuery(firstQuery), queryCount(queryCount) |
| 988 | { |
| 989 | } |
| 990 | |
| 991 | void play(CommandBuffer::ExecutionState& executionState) |
| 992 | { |
| 993 | Cast(queryPool)->reset(firstQuery, queryCount); |
| 994 | } |
| 995 | |
| 996 | private: |
| 997 | VkQueryPool queryPool; |
| 998 | uint32_t firstQuery; |
| 999 | uint32_t queryCount; |
| 1000 | }; |
| 1001 | |
| 1002 | struct WriteTimeStamp : public CommandBuffer::Command |
| 1003 | { |
| 1004 | WriteTimeStamp(VkQueryPool queryPool, uint32_t query) |
| 1005 | : queryPool(queryPool), query(query) |
| 1006 | { |
| 1007 | } |
| 1008 | |
| 1009 | void play(CommandBuffer::ExecutionState& executionState) |
| 1010 | { |
| 1011 | Cast(queryPool)->writeTimestamp(query); |
| 1012 | } |
| 1013 | |
| 1014 | private: |
| 1015 | VkQueryPool queryPool; |
| 1016 | uint32_t query; |
| 1017 | }; |
| 1018 | |
| 1019 | struct CopyQueryPoolResults : public CommandBuffer::Command |
| 1020 | { |
| 1021 | CopyQueryPoolResults(VkQueryPool queryPool, uint32_t firstQuery, uint32_t queryCount, |
| 1022 | VkBuffer dstBuffer, VkDeviceSize dstOffset, VkDeviceSize stride, VkQueryResultFlags flags) |
| 1023 | : queryPool(queryPool), firstQuery(firstQuery), queryCount(queryCount), dstBuffer(dstBuffer), |
| 1024 | dstOffset(dstOffset), stride(stride), flags(flags) |
| 1025 | { |
| 1026 | } |
| 1027 | |
| 1028 | void play(CommandBuffer::ExecutionState& executionState) |
| 1029 | { |
| 1030 | vk::Buffer* buffer = Cast(dstBuffer); |
| 1031 | Cast(queryPool)->getResults(firstQuery, queryCount, buffer->getSize() - dstOffset, |
| 1032 | buffer->getOffsetPointer(dstOffset), stride, flags); |
| 1033 | } |
| 1034 | |
| 1035 | private: |
| 1036 | VkQueryPool queryPool; |
| 1037 | uint32_t firstQuery; |
| 1038 | uint32_t queryCount; |
| 1039 | VkBuffer dstBuffer; |
| 1040 | VkDeviceSize dstOffset; |
| 1041 | VkDeviceSize stride; |
| 1042 | VkQueryResultFlags flags; |
| 1043 | }; |
| 1044 | |
Alexis Hetu | 767b41b | 2018-09-26 11:25:46 -0400 | [diff] [blame] | 1045 | CommandBuffer::CommandBuffer(VkCommandBufferLevel pLevel) : level(pLevel) |
| 1046 | { |
Alexis Hetu | 072dc0d | 2018-10-31 11:41:25 -0400 | [diff] [blame] | 1047 | // FIXME (b/119409619): replace this vector by an allocator so we can control all memory allocations |
| 1048 | commands = new std::vector<std::unique_ptr<Command> >(); |
Alexis Hetu | 767b41b | 2018-09-26 11:25:46 -0400 | [diff] [blame] | 1049 | } |
| 1050 | |
Alexis Hetu | a9999ce | 2018-10-17 08:00:43 -0400 | [diff] [blame] | 1051 | void CommandBuffer::destroy(const VkAllocationCallbacks* pAllocator) |
| 1052 | { |
Alexis Hetu | d2791c2 | 2018-12-10 14:41:03 -0500 | [diff] [blame] | 1053 | delete commands; |
Alexis Hetu | 072dc0d | 2018-10-31 11:41:25 -0400 | [diff] [blame] | 1054 | } |
| 1055 | |
Alexis Hetu | d2791c2 | 2018-12-10 14:41:03 -0500 | [diff] [blame] | 1056 | void CommandBuffer::resetState() |
Alexis Hetu | 072dc0d | 2018-10-31 11:41:25 -0400 | [diff] [blame] | 1057 | { |
| 1058 | // FIXME (b/119409619): replace this vector by an allocator so we can control all memory allocations |
Alexis Hetu | d2791c2 | 2018-12-10 14:41:03 -0500 | [diff] [blame] | 1059 | commands->clear(); |
| 1060 | |
| 1061 | state = INITIAL; |
Alexis Hetu | a9999ce | 2018-10-17 08:00:43 -0400 | [diff] [blame] | 1062 | } |
| 1063 | |
| 1064 | VkResult CommandBuffer::begin(VkCommandBufferUsageFlags flags, const VkCommandBufferInheritanceInfo* pInheritanceInfo) |
| 1065 | { |
Alexis Hetu | 072dc0d | 2018-10-31 11:41:25 -0400 | [diff] [blame] | 1066 | ASSERT((state != RECORDING) && (state != PENDING)); |
Alexis Hetu | d2791c2 | 2018-12-10 14:41:03 -0500 | [diff] [blame] | 1067 | |
Chris Forbes | 823ca85 | 2019-03-01 17:40:25 -0800 | [diff] [blame] | 1068 | // Nothing interesting to do based on flags. We don't have any optimizations |
| 1069 | // to apply for ONE_TIME_SUBMIT or (lack of) SIMULTANEOUS_USE. RENDER_PASS_CONTINUE |
| 1070 | // must also provide a non-null pInheritanceInfo, which we don't implement yet, but is caught below. |
| 1071 | (void) flags; |
| 1072 | |
Alexis Hetu | e7b2a05 | 2019-03-18 16:16:36 -0400 | [diff] [blame] | 1073 | // pInheritanceInfo merely contains optimization hints, so we currently ignore it |
Alexis Hetu | d2791c2 | 2018-12-10 14:41:03 -0500 | [diff] [blame] | 1074 | |
| 1075 | if(state != INITIAL) |
| 1076 | { |
| 1077 | // Implicit reset |
| 1078 | resetState(); |
| 1079 | } |
| 1080 | |
Alexis Hetu | a9999ce | 2018-10-17 08:00:43 -0400 | [diff] [blame] | 1081 | state = RECORDING; |
| 1082 | |
Alexis Hetu | a9999ce | 2018-10-17 08:00:43 -0400 | [diff] [blame] | 1083 | return VK_SUCCESS; |
| 1084 | } |
| 1085 | |
| 1086 | VkResult CommandBuffer::end() |
| 1087 | { |
Alexis Hetu | 072dc0d | 2018-10-31 11:41:25 -0400 | [diff] [blame] | 1088 | ASSERT(state == RECORDING); |
Alexis Hetu | a9999ce | 2018-10-17 08:00:43 -0400 | [diff] [blame] | 1089 | |
Alexis Hetu | 072dc0d | 2018-10-31 11:41:25 -0400 | [diff] [blame] | 1090 | state = EXECUTABLE; |
Alexis Hetu | a9999ce | 2018-10-17 08:00:43 -0400 | [diff] [blame] | 1091 | |
| 1092 | return VK_SUCCESS; |
| 1093 | } |
| 1094 | |
| 1095 | VkResult CommandBuffer::reset(VkCommandPoolResetFlags flags) |
| 1096 | { |
| 1097 | ASSERT(state != PENDING); |
| 1098 | |
Alexis Hetu | d2791c2 | 2018-12-10 14:41:03 -0500 | [diff] [blame] | 1099 | resetState(); |
Alexis Hetu | a9999ce | 2018-10-17 08:00:43 -0400 | [diff] [blame] | 1100 | |
| 1101 | return VK_SUCCESS; |
| 1102 | } |
| 1103 | |
Alexis Hetu | f251a6f | 2019-01-07 14:47:32 -0500 | [diff] [blame] | 1104 | template<typename T, typename... Args> |
| 1105 | void CommandBuffer::addCommand(Args&&... args) |
| 1106 | { |
Alexis Hetu | 1a9714a | 2019-04-12 11:48:12 -0400 | [diff] [blame] | 1107 | // FIXME (b/119409619): use an allocator here so we can control all memory allocations |
Alexis Hetu | f251a6f | 2019-01-07 14:47:32 -0500 | [diff] [blame] | 1108 | commands->push_back(std::unique_ptr<T>(new T(std::forward<Args>(args)...))); |
| 1109 | } |
| 1110 | |
Alexis Hetu | a9999ce | 2018-10-17 08:00:43 -0400 | [diff] [blame] | 1111 | void CommandBuffer::beginRenderPass(VkRenderPass renderPass, VkFramebuffer framebuffer, VkRect2D renderArea, |
Alexis Hetu | 072dc0d | 2018-10-31 11:41:25 -0400 | [diff] [blame] | 1112 | uint32_t clearValueCount, const VkClearValue* clearValues, VkSubpassContents contents) |
Alexis Hetu | a9999ce | 2018-10-17 08:00:43 -0400 | [diff] [blame] | 1113 | { |
Alexis Hetu | 072dc0d | 2018-10-31 11:41:25 -0400 | [diff] [blame] | 1114 | ASSERT(state == RECORDING); |
| 1115 | |
Alexis Hetu | f251a6f | 2019-01-07 14:47:32 -0500 | [diff] [blame] | 1116 | addCommand<BeginRenderPass>(renderPass, framebuffer, renderArea, clearValueCount, clearValues); |
Alexis Hetu | a9999ce | 2018-10-17 08:00:43 -0400 | [diff] [blame] | 1117 | } |
| 1118 | |
| 1119 | void CommandBuffer::nextSubpass(VkSubpassContents contents) |
| 1120 | { |
Alexis Hetu | 1cd31ea | 2019-01-17 17:14:57 -0500 | [diff] [blame] | 1121 | ASSERT(state == RECORDING); |
| 1122 | |
| 1123 | addCommand<NextSubpass>(); |
Alexis Hetu | a9999ce | 2018-10-17 08:00:43 -0400 | [diff] [blame] | 1124 | } |
| 1125 | |
| 1126 | void CommandBuffer::endRenderPass() |
| 1127 | { |
Alexis Hetu | f251a6f | 2019-01-07 14:47:32 -0500 | [diff] [blame] | 1128 | addCommand<EndRenderPass>(); |
Alexis Hetu | a9999ce | 2018-10-17 08:00:43 -0400 | [diff] [blame] | 1129 | } |
| 1130 | |
| 1131 | void CommandBuffer::executeCommands(uint32_t commandBufferCount, const VkCommandBuffer* pCommandBuffers) |
| 1132 | { |
Alexis Hetu | e7b2a05 | 2019-03-18 16:16:36 -0400 | [diff] [blame] | 1133 | ASSERT(state == RECORDING); |
| 1134 | |
| 1135 | for(uint32_t i = 0; i < commandBufferCount; ++i) |
| 1136 | { |
| 1137 | addCommand<ExecuteCommands>(pCommandBuffers[i]); |
| 1138 | } |
Alexis Hetu | a9999ce | 2018-10-17 08:00:43 -0400 | [diff] [blame] | 1139 | } |
| 1140 | |
| 1141 | void CommandBuffer::setDeviceMask(uint32_t deviceMask) |
| 1142 | { |
Ben Clayton | 00424c1 | 2019-03-17 17:29:30 +0000 | [diff] [blame] | 1143 | UNIMPLEMENTED("setDeviceMask"); |
Alexis Hetu | a9999ce | 2018-10-17 08:00:43 -0400 | [diff] [blame] | 1144 | } |
| 1145 | |
| 1146 | void CommandBuffer::dispatchBase(uint32_t baseGroupX, uint32_t baseGroupY, uint32_t baseGroupZ, |
| 1147 | uint32_t groupCountX, uint32_t groupCountY, uint32_t groupCountZ) |
| 1148 | { |
Ben Clayton | 00424c1 | 2019-03-17 17:29:30 +0000 | [diff] [blame] | 1149 | UNIMPLEMENTED("dispatchBase"); |
Alexis Hetu | a9999ce | 2018-10-17 08:00:43 -0400 | [diff] [blame] | 1150 | } |
| 1151 | |
| 1152 | void CommandBuffer::pipelineBarrier(VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask, |
| 1153 | VkDependencyFlags dependencyFlags, |
| 1154 | uint32_t memoryBarrierCount, const VkMemoryBarrier* pMemoryBarriers, |
| 1155 | uint32_t bufferMemoryBarrierCount, const VkBufferMemoryBarrier* pBufferMemoryBarriers, |
| 1156 | uint32_t imageMemoryBarrierCount, const VkImageMemoryBarrier* pImageMemoryBarriers) |
| 1157 | { |
Alexis Hetu | f251a6f | 2019-01-07 14:47:32 -0500 | [diff] [blame] | 1158 | addCommand<PipelineBarrier>(); |
Alexis Hetu | a9999ce | 2018-10-17 08:00:43 -0400 | [diff] [blame] | 1159 | } |
| 1160 | |
| 1161 | void CommandBuffer::bindPipeline(VkPipelineBindPoint pipelineBindPoint, VkPipeline pipeline) |
| 1162 | { |
Ben Clayton | f2be26a | 2019-03-08 12:02:05 +0000 | [diff] [blame] | 1163 | switch(pipelineBindPoint) |
Alexis Hetu | 072dc0d | 2018-10-31 11:41:25 -0400 | [diff] [blame] | 1164 | { |
Ben Clayton | f2be26a | 2019-03-08 12:02:05 +0000 | [diff] [blame] | 1165 | case VK_PIPELINE_BIND_POINT_COMPUTE: |
| 1166 | case VK_PIPELINE_BIND_POINT_GRAPHICS: |
| 1167 | addCommand<PipelineBind>(pipelineBindPoint, pipeline); |
| 1168 | break; |
| 1169 | default: |
Ben Clayton | 00424c1 | 2019-03-17 17:29:30 +0000 | [diff] [blame] | 1170 | UNIMPLEMENTED("pipelineBindPoint"); |
Alexis Hetu | 072dc0d | 2018-10-31 11:41:25 -0400 | [diff] [blame] | 1171 | } |
Alexis Hetu | a9999ce | 2018-10-17 08:00:43 -0400 | [diff] [blame] | 1172 | } |
| 1173 | |
| 1174 | void CommandBuffer::bindVertexBuffers(uint32_t firstBinding, uint32_t bindingCount, |
| 1175 | const VkBuffer* pBuffers, const VkDeviceSize* pOffsets) |
| 1176 | { |
Chris Forbes | fe3d497 | 2019-02-22 17:21:23 -0800 | [diff] [blame] | 1177 | for(uint32_t i = 0; i < bindingCount; ++i) |
Alexis Hetu | a9999ce | 2018-10-17 08:00:43 -0400 | [diff] [blame] | 1178 | { |
Chris Forbes | fe3d497 | 2019-02-22 17:21:23 -0800 | [diff] [blame] | 1179 | addCommand<VertexBufferBind>(i + firstBinding, pBuffers[i], pOffsets[i]); |
Alexis Hetu | a9999ce | 2018-10-17 08:00:43 -0400 | [diff] [blame] | 1180 | } |
| 1181 | } |
| 1182 | |
| 1183 | void CommandBuffer::beginQuery(VkQueryPool queryPool, uint32_t query, VkQueryControlFlags flags) |
| 1184 | { |
Alexis Hetu | f0aa9d5 | 2019-04-01 17:06:47 -0400 | [diff] [blame] | 1185 | addCommand<BeginQuery>(queryPool, query, flags); |
Alexis Hetu | a9999ce | 2018-10-17 08:00:43 -0400 | [diff] [blame] | 1186 | } |
| 1187 | |
| 1188 | void CommandBuffer::endQuery(VkQueryPool queryPool, uint32_t query) |
| 1189 | { |
Alexis Hetu | f0aa9d5 | 2019-04-01 17:06:47 -0400 | [diff] [blame] | 1190 | addCommand<EndQuery>(queryPool, query); |
Alexis Hetu | a9999ce | 2018-10-17 08:00:43 -0400 | [diff] [blame] | 1191 | } |
| 1192 | |
| 1193 | void CommandBuffer::resetQueryPool(VkQueryPool queryPool, uint32_t firstQuery, uint32_t queryCount) |
| 1194 | { |
Alexis Hetu | f0aa9d5 | 2019-04-01 17:06:47 -0400 | [diff] [blame] | 1195 | addCommand<ResetQueryPool>(queryPool, firstQuery, queryCount); |
Alexis Hetu | a9999ce | 2018-10-17 08:00:43 -0400 | [diff] [blame] | 1196 | } |
| 1197 | |
| 1198 | void CommandBuffer::writeTimestamp(VkPipelineStageFlagBits pipelineStage, VkQueryPool queryPool, uint32_t query) |
| 1199 | { |
Alexis Hetu | f0aa9d5 | 2019-04-01 17:06:47 -0400 | [diff] [blame] | 1200 | addCommand<WriteTimeStamp>(queryPool, query); |
Alexis Hetu | a9999ce | 2018-10-17 08:00:43 -0400 | [diff] [blame] | 1201 | } |
| 1202 | |
| 1203 | void CommandBuffer::copyQueryPoolResults(VkQueryPool queryPool, uint32_t firstQuery, uint32_t queryCount, |
| 1204 | VkBuffer dstBuffer, VkDeviceSize dstOffset, VkDeviceSize stride, VkQueryResultFlags flags) |
| 1205 | { |
Alexis Hetu | f0aa9d5 | 2019-04-01 17:06:47 -0400 | [diff] [blame] | 1206 | addCommand<CopyQueryPoolResults>(queryPool, firstQuery, queryCount, dstBuffer, dstOffset, stride, flags); |
Alexis Hetu | a9999ce | 2018-10-17 08:00:43 -0400 | [diff] [blame] | 1207 | } |
| 1208 | |
| 1209 | void CommandBuffer::pushConstants(VkPipelineLayout layout, VkShaderStageFlags stageFlags, |
| 1210 | uint32_t offset, uint32_t size, const void* pValues) |
| 1211 | { |
Chris Forbes | a30de54 | 2019-03-18 18:51:55 -0700 | [diff] [blame] | 1212 | addCommand<SetPushConstants>(offset, size, pValues); |
Alexis Hetu | a9999ce | 2018-10-17 08:00:43 -0400 | [diff] [blame] | 1213 | } |
| 1214 | |
| 1215 | void CommandBuffer::setViewport(uint32_t firstViewport, uint32_t viewportCount, const VkViewport* pViewports) |
| 1216 | { |
Alexis Hetu | 7383243 | 2019-04-11 16:43:18 -0400 | [diff] [blame] | 1217 | if(firstViewport != 0 || viewportCount > 1) |
| 1218 | { |
| 1219 | UNIMPLEMENTED("viewport"); |
| 1220 | } |
| 1221 | |
| 1222 | for(uint32_t i = 0; i < viewportCount; i++) |
| 1223 | { |
| 1224 | addCommand<SetViewport>(pViewports[i], i + firstViewport); |
| 1225 | } |
Alexis Hetu | a9999ce | 2018-10-17 08:00:43 -0400 | [diff] [blame] | 1226 | } |
| 1227 | |
| 1228 | void CommandBuffer::setScissor(uint32_t firstScissor, uint32_t scissorCount, const VkRect2D* pScissors) |
| 1229 | { |
Alexis Hetu | 7383243 | 2019-04-11 16:43:18 -0400 | [diff] [blame] | 1230 | if(firstScissor != 0 || scissorCount > 1) |
| 1231 | { |
| 1232 | UNIMPLEMENTED("scissor"); |
| 1233 | } |
| 1234 | |
| 1235 | for(uint32_t i = 0; i < scissorCount; i++) |
| 1236 | { |
| 1237 | addCommand<SetScissor>(pScissors[i], i + firstScissor); |
| 1238 | } |
Alexis Hetu | a9999ce | 2018-10-17 08:00:43 -0400 | [diff] [blame] | 1239 | } |
| 1240 | |
| 1241 | void CommandBuffer::setLineWidth(float lineWidth) |
| 1242 | { |
Alexis Hetu | a9999ce | 2018-10-17 08:00:43 -0400 | [diff] [blame] | 1243 | // If the wide lines feature is not enabled, lineWidth must be 1.0 |
| 1244 | ASSERT(lineWidth == 1.0f); |
Alexis Hetu | a9999ce | 2018-10-17 08:00:43 -0400 | [diff] [blame] | 1245 | } |
| 1246 | |
| 1247 | void CommandBuffer::setDepthBias(float depthBiasConstantFactor, float depthBiasClamp, float depthBiasSlopeFactor) |
| 1248 | { |
Alexis Hetu | 7383243 | 2019-04-11 16:43:18 -0400 | [diff] [blame] | 1249 | addCommand<SetDepthBias>(depthBiasConstantFactor, depthBiasClamp, depthBiasSlopeFactor); |
Alexis Hetu | a9999ce | 2018-10-17 08:00:43 -0400 | [diff] [blame] | 1250 | } |
| 1251 | |
| 1252 | void CommandBuffer::setBlendConstants(const float blendConstants[4]) |
| 1253 | { |
Alexis Hetu | 7383243 | 2019-04-11 16:43:18 -0400 | [diff] [blame] | 1254 | addCommand<SetBlendConstants>(blendConstants); |
Alexis Hetu | a9999ce | 2018-10-17 08:00:43 -0400 | [diff] [blame] | 1255 | } |
| 1256 | |
| 1257 | void CommandBuffer::setDepthBounds(float minDepthBounds, float maxDepthBounds) |
| 1258 | { |
Alexis Hetu | 7383243 | 2019-04-11 16:43:18 -0400 | [diff] [blame] | 1259 | addCommand<SetDepthBounds>(minDepthBounds, maxDepthBounds); |
Alexis Hetu | a9999ce | 2018-10-17 08:00:43 -0400 | [diff] [blame] | 1260 | } |
| 1261 | |
| 1262 | void CommandBuffer::setStencilCompareMask(VkStencilFaceFlags faceMask, uint32_t compareMask) |
| 1263 | { |
Alexis Hetu | a9999ce | 2018-10-17 08:00:43 -0400 | [diff] [blame] | 1264 | // faceMask must not be 0 |
| 1265 | ASSERT(faceMask != 0); |
| 1266 | |
Alexis Hetu | 7383243 | 2019-04-11 16:43:18 -0400 | [diff] [blame] | 1267 | addCommand<SetStencilCompareMask>(faceMask, compareMask); |
Alexis Hetu | a9999ce | 2018-10-17 08:00:43 -0400 | [diff] [blame] | 1268 | } |
| 1269 | |
| 1270 | void CommandBuffer::setStencilWriteMask(VkStencilFaceFlags faceMask, uint32_t writeMask) |
| 1271 | { |
Alexis Hetu | a9999ce | 2018-10-17 08:00:43 -0400 | [diff] [blame] | 1272 | // faceMask must not be 0 |
| 1273 | ASSERT(faceMask != 0); |
| 1274 | |
Alexis Hetu | 7383243 | 2019-04-11 16:43:18 -0400 | [diff] [blame] | 1275 | addCommand<SetStencilWriteMask>(faceMask, writeMask); |
Alexis Hetu | a9999ce | 2018-10-17 08:00:43 -0400 | [diff] [blame] | 1276 | } |
| 1277 | |
| 1278 | void CommandBuffer::setStencilReference(VkStencilFaceFlags faceMask, uint32_t reference) |
| 1279 | { |
Alexis Hetu | a9999ce | 2018-10-17 08:00:43 -0400 | [diff] [blame] | 1280 | // faceMask must not be 0 |
| 1281 | ASSERT(faceMask != 0); |
| 1282 | |
Alexis Hetu | 7383243 | 2019-04-11 16:43:18 -0400 | [diff] [blame] | 1283 | addCommand<SetStencilReference>(faceMask, reference); |
Alexis Hetu | a9999ce | 2018-10-17 08:00:43 -0400 | [diff] [blame] | 1284 | } |
| 1285 | |
Ben Clayton | 225a130 | 2019-04-02 12:28:22 +0100 | [diff] [blame] | 1286 | void CommandBuffer::bindDescriptorSets(VkPipelineBindPoint pipelineBindPoint, VkPipelineLayout vkLayout, |
Alexis Hetu | a9999ce | 2018-10-17 08:00:43 -0400 | [diff] [blame] | 1287 | uint32_t firstSet, uint32_t descriptorSetCount, const VkDescriptorSet* pDescriptorSets, |
| 1288 | uint32_t dynamicOffsetCount, const uint32_t* pDynamicOffsets) |
| 1289 | { |
Alexis Hetu | 5edafb5 | 2019-02-15 14:56:22 -0500 | [diff] [blame] | 1290 | ASSERT(state == RECORDING); |
| 1291 | |
Alexis Hetu | 5edafb5 | 2019-02-15 14:56:22 -0500 | [diff] [blame] | 1292 | for(uint32_t i = 0; i < descriptorSetCount; i++) |
| 1293 | { |
Ben Clayton | 225a130 | 2019-04-02 12:28:22 +0100 | [diff] [blame] | 1294 | auto descriptorSetIndex = firstSet + i; |
| 1295 | auto layout = vk::Cast(vkLayout); |
| 1296 | auto setLayout = layout->getDescriptorSetLayout(descriptorSetIndex); |
| 1297 | |
| 1298 | auto numDynamicDescriptors = setLayout->getDynamicDescriptorCount(); |
| 1299 | ASSERT(numDynamicDescriptors == 0 || pDynamicOffsets != nullptr); |
| 1300 | ASSERT(dynamicOffsetCount >= numDynamicDescriptors); |
| 1301 | |
| 1302 | addCommand<BindDescriptorSet>( |
| 1303 | pipelineBindPoint, descriptorSetIndex, pDescriptorSets[i], |
| 1304 | dynamicOffsetCount, pDynamicOffsets); |
| 1305 | |
| 1306 | pDynamicOffsets += numDynamicDescriptors; |
| 1307 | dynamicOffsetCount -= numDynamicDescriptors; |
Alexis Hetu | 5edafb5 | 2019-02-15 14:56:22 -0500 | [diff] [blame] | 1308 | } |
Alexis Hetu | a9999ce | 2018-10-17 08:00:43 -0400 | [diff] [blame] | 1309 | } |
| 1310 | |
| 1311 | void CommandBuffer::bindIndexBuffer(VkBuffer buffer, VkDeviceSize offset, VkIndexType indexType) |
| 1312 | { |
Chris Forbes | baf7ad3 | 2019-02-25 18:14:42 -0800 | [diff] [blame] | 1313 | addCommand<IndexBufferBind>(buffer, offset, indexType); |
Alexis Hetu | a9999ce | 2018-10-17 08:00:43 -0400 | [diff] [blame] | 1314 | } |
| 1315 | |
| 1316 | void CommandBuffer::dispatch(uint32_t groupCountX, uint32_t groupCountY, uint32_t groupCountZ) |
| 1317 | { |
Ben Clayton | f2be26a | 2019-03-08 12:02:05 +0000 | [diff] [blame] | 1318 | addCommand<Dispatch>(groupCountX, groupCountY, groupCountZ); |
Alexis Hetu | a9999ce | 2018-10-17 08:00:43 -0400 | [diff] [blame] | 1319 | } |
| 1320 | |
| 1321 | void CommandBuffer::dispatchIndirect(VkBuffer buffer, VkDeviceSize offset) |
| 1322 | { |
Chris Forbes | fc8a46d | 2019-03-22 14:47:47 -0700 | [diff] [blame] | 1323 | addCommand<DispatchIndirect>(buffer, offset); |
Alexis Hetu | a9999ce | 2018-10-17 08:00:43 -0400 | [diff] [blame] | 1324 | } |
| 1325 | |
| 1326 | void CommandBuffer::copyBuffer(VkBuffer srcBuffer, VkBuffer dstBuffer, uint32_t regionCount, const VkBufferCopy* pRegions) |
| 1327 | { |
Alexis Hetu | bb0a7f0 | 2018-12-14 16:50:43 -0500 | [diff] [blame] | 1328 | ASSERT(state == RECORDING); |
| 1329 | |
| 1330 | for(uint32_t i = 0; i < regionCount; i++) |
| 1331 | { |
Alexis Hetu | f251a6f | 2019-01-07 14:47:32 -0500 | [diff] [blame] | 1332 | addCommand<BufferToBufferCopy>(srcBuffer, dstBuffer, pRegions[i]); |
Alexis Hetu | bb0a7f0 | 2018-12-14 16:50:43 -0500 | [diff] [blame] | 1333 | } |
Alexis Hetu | a9999ce | 2018-10-17 08:00:43 -0400 | [diff] [blame] | 1334 | } |
| 1335 | |
| 1336 | void CommandBuffer::copyImage(VkImage srcImage, VkImageLayout srcImageLayout, VkImage dstImage, VkImageLayout dstImageLayout, |
| 1337 | uint32_t regionCount, const VkImageCopy* pRegions) |
| 1338 | { |
Alexis Hetu | 09056de | 2018-12-07 12:40:00 -0500 | [diff] [blame] | 1339 | ASSERT(state == RECORDING); |
| 1340 | ASSERT(srcImageLayout == VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL || |
| 1341 | srcImageLayout == VK_IMAGE_LAYOUT_GENERAL); |
| 1342 | ASSERT(dstImageLayout == VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL || |
| 1343 | dstImageLayout == VK_IMAGE_LAYOUT_GENERAL); |
| 1344 | |
| 1345 | for(uint32_t i = 0; i < regionCount; i++) |
| 1346 | { |
Alexis Hetu | f251a6f | 2019-01-07 14:47:32 -0500 | [diff] [blame] | 1347 | addCommand<ImageToImageCopy>(srcImage, dstImage, pRegions[i]); |
Alexis Hetu | 09056de | 2018-12-07 12:40:00 -0500 | [diff] [blame] | 1348 | } |
Alexis Hetu | a9999ce | 2018-10-17 08:00:43 -0400 | [diff] [blame] | 1349 | } |
| 1350 | |
| 1351 | void CommandBuffer::blitImage(VkImage srcImage, VkImageLayout srcImageLayout, VkImage dstImage, VkImageLayout dstImageLayout, |
| 1352 | uint32_t regionCount, const VkImageBlit* pRegions, VkFilter filter) |
| 1353 | { |
Alexis Hetu | 809d011 | 2018-12-17 17:00:28 -0500 | [diff] [blame] | 1354 | ASSERT(state == RECORDING); |
| 1355 | ASSERT(srcImageLayout == VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL || |
| 1356 | srcImageLayout == VK_IMAGE_LAYOUT_GENERAL); |
| 1357 | ASSERT(dstImageLayout == VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL || |
| 1358 | dstImageLayout == VK_IMAGE_LAYOUT_GENERAL); |
| 1359 | |
| 1360 | for(uint32_t i = 0; i < regionCount; i++) |
| 1361 | { |
Alexis Hetu | f251a6f | 2019-01-07 14:47:32 -0500 | [diff] [blame] | 1362 | addCommand<BlitImage>(srcImage, dstImage, pRegions[i], filter); |
Alexis Hetu | 809d011 | 2018-12-17 17:00:28 -0500 | [diff] [blame] | 1363 | } |
Alexis Hetu | a9999ce | 2018-10-17 08:00:43 -0400 | [diff] [blame] | 1364 | } |
| 1365 | |
| 1366 | void CommandBuffer::copyBufferToImage(VkBuffer srcBuffer, VkImage dstImage, VkImageLayout dstImageLayout, |
| 1367 | uint32_t regionCount, const VkBufferImageCopy* pRegions) |
| 1368 | { |
Alexis Hetu | 09056de | 2018-12-07 12:40:00 -0500 | [diff] [blame] | 1369 | ASSERT(state == RECORDING); |
| 1370 | |
| 1371 | for(uint32_t i = 0; i < regionCount; i++) |
| 1372 | { |
Alexis Hetu | f251a6f | 2019-01-07 14:47:32 -0500 | [diff] [blame] | 1373 | addCommand<BufferToImageCopy>(srcBuffer, dstImage, pRegions[i]); |
Alexis Hetu | 09056de | 2018-12-07 12:40:00 -0500 | [diff] [blame] | 1374 | } |
Alexis Hetu | a9999ce | 2018-10-17 08:00:43 -0400 | [diff] [blame] | 1375 | } |
| 1376 | |
| 1377 | void CommandBuffer::copyImageToBuffer(VkImage srcImage, VkImageLayout srcImageLayout, VkBuffer dstBuffer, |
| 1378 | uint32_t regionCount, const VkBufferImageCopy* pRegions) |
| 1379 | { |
Alexis Hetu | 09056de | 2018-12-07 12:40:00 -0500 | [diff] [blame] | 1380 | ASSERT(state == RECORDING); |
Chris Forbes | a2457f7 | 2019-05-04 13:34:32 -0700 | [diff] [blame] | 1381 | ASSERT(srcImageLayout == VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL || srcImageLayout == VK_IMAGE_LAYOUT_GENERAL); |
Alexis Hetu | 072dc0d | 2018-10-31 11:41:25 -0400 | [diff] [blame] | 1382 | |
| 1383 | for(uint32_t i = 0; i < regionCount; i++) |
| 1384 | { |
Alexis Hetu | f251a6f | 2019-01-07 14:47:32 -0500 | [diff] [blame] | 1385 | addCommand<ImageToBufferCopy>(srcImage, dstBuffer, pRegions[i]); |
Alexis Hetu | 072dc0d | 2018-10-31 11:41:25 -0400 | [diff] [blame] | 1386 | } |
Alexis Hetu | a9999ce | 2018-10-17 08:00:43 -0400 | [diff] [blame] | 1387 | } |
| 1388 | |
| 1389 | void CommandBuffer::updateBuffer(VkBuffer dstBuffer, VkDeviceSize dstOffset, VkDeviceSize dataSize, const void* pData) |
| 1390 | { |
Alexis Hetu | 7fb0b73 | 2019-02-07 13:50:10 -0500 | [diff] [blame] | 1391 | ASSERT(state == RECORDING); |
| 1392 | |
| 1393 | addCommand<UpdateBuffer>(dstBuffer, dstOffset, dataSize, pData); |
Alexis Hetu | a9999ce | 2018-10-17 08:00:43 -0400 | [diff] [blame] | 1394 | } |
| 1395 | |
| 1396 | void CommandBuffer::fillBuffer(VkBuffer dstBuffer, VkDeviceSize dstOffset, VkDeviceSize size, uint32_t data) |
| 1397 | { |
Alexis Hetu | 7fb0b73 | 2019-02-07 13:50:10 -0500 | [diff] [blame] | 1398 | ASSERT(state == RECORDING); |
| 1399 | |
| 1400 | addCommand<FillBuffer>(dstBuffer, dstOffset, size, data); |
Alexis Hetu | a9999ce | 2018-10-17 08:00:43 -0400 | [diff] [blame] | 1401 | } |
| 1402 | |
| 1403 | void CommandBuffer::clearColorImage(VkImage image, VkImageLayout imageLayout, const VkClearColorValue* pColor, |
| 1404 | uint32_t rangeCount, const VkImageSubresourceRange* pRanges) |
| 1405 | { |
Alexis Hetu | f14ed32 | 2019-01-16 15:54:55 -0500 | [diff] [blame] | 1406 | ASSERT(state == RECORDING); |
| 1407 | |
| 1408 | for(uint32_t i = 0; i < rangeCount; i++) |
| 1409 | { |
Chris Forbes | fffee5b | 2019-01-18 08:33:15 -0800 | [diff] [blame] | 1410 | addCommand<ClearColorImage>(image, pColor[i], pRanges[i]); |
Alexis Hetu | f14ed32 | 2019-01-16 15:54:55 -0500 | [diff] [blame] | 1411 | } |
Alexis Hetu | a9999ce | 2018-10-17 08:00:43 -0400 | [diff] [blame] | 1412 | } |
| 1413 | |
| 1414 | void CommandBuffer::clearDepthStencilImage(VkImage image, VkImageLayout imageLayout, const VkClearDepthStencilValue* pDepthStencil, |
| 1415 | uint32_t rangeCount, const VkImageSubresourceRange* pRanges) |
| 1416 | { |
Alexis Hetu | 7ca9f4a | 2019-01-17 14:51:43 -0500 | [diff] [blame] | 1417 | ASSERT(state == RECORDING); |
| 1418 | |
| 1419 | for(uint32_t i = 0; i < rangeCount; i++) |
| 1420 | { |
Chris Forbes | fffee5b | 2019-01-18 08:33:15 -0800 | [diff] [blame] | 1421 | addCommand<ClearDepthStencilImage>(image, pDepthStencil[i], pRanges[i]); |
Alexis Hetu | 7ca9f4a | 2019-01-17 14:51:43 -0500 | [diff] [blame] | 1422 | } |
Alexis Hetu | a9999ce | 2018-10-17 08:00:43 -0400 | [diff] [blame] | 1423 | } |
| 1424 | |
| 1425 | void CommandBuffer::clearAttachments(uint32_t attachmentCount, const VkClearAttachment* pAttachments, |
| 1426 | uint32_t rectCount, const VkClearRect* pRects) |
| 1427 | { |
Alexis Hetu | 1cd31ea | 2019-01-17 17:14:57 -0500 | [diff] [blame] | 1428 | ASSERT(state == RECORDING); |
| 1429 | |
| 1430 | for(uint32_t i = 0; i < attachmentCount; i++) |
| 1431 | { |
| 1432 | for(uint32_t j = 0; j < rectCount; j++) |
| 1433 | { |
| 1434 | addCommand<ClearAttachment>(pAttachments[i], pRects[j]); |
| 1435 | } |
| 1436 | } |
Alexis Hetu | a9999ce | 2018-10-17 08:00:43 -0400 | [diff] [blame] | 1437 | } |
| 1438 | |
| 1439 | void CommandBuffer::resolveImage(VkImage srcImage, VkImageLayout srcImageLayout, VkImage dstImage, VkImageLayout dstImageLayout, |
| 1440 | uint32_t regionCount, const VkImageResolve* pRegions) |
| 1441 | { |
Alexis Hetu | e5e33cd | 2019-04-11 10:24:52 -0400 | [diff] [blame] | 1442 | ASSERT(state == RECORDING); |
| 1443 | ASSERT(srcImageLayout == VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL || |
| 1444 | srcImageLayout == VK_IMAGE_LAYOUT_GENERAL); |
| 1445 | ASSERT(dstImageLayout == VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL || |
| 1446 | dstImageLayout == VK_IMAGE_LAYOUT_GENERAL); |
| 1447 | |
| 1448 | for(uint32_t i = 0; i < regionCount; i++) |
| 1449 | { |
| 1450 | addCommand<ResolveImage>(srcImage, dstImage, pRegions[i]); |
| 1451 | } |
Alexis Hetu | a9999ce | 2018-10-17 08:00:43 -0400 | [diff] [blame] | 1452 | } |
| 1453 | |
| 1454 | void CommandBuffer::setEvent(VkEvent event, VkPipelineStageFlags stageMask) |
| 1455 | { |
Alexis Hetu | 3f5a479 | 2019-02-01 17:49:55 -0500 | [diff] [blame] | 1456 | ASSERT(state == RECORDING); |
| 1457 | |
| 1458 | addCommand<SignalEvent>(event, stageMask); |
Alexis Hetu | a9999ce | 2018-10-17 08:00:43 -0400 | [diff] [blame] | 1459 | } |
| 1460 | |
| 1461 | void CommandBuffer::resetEvent(VkEvent event, VkPipelineStageFlags stageMask) |
| 1462 | { |
Alexis Hetu | 3f5a479 | 2019-02-01 17:49:55 -0500 | [diff] [blame] | 1463 | ASSERT(state == RECORDING); |
| 1464 | |
| 1465 | addCommand<ResetEvent>(event, stageMask); |
Alexis Hetu | a9999ce | 2018-10-17 08:00:43 -0400 | [diff] [blame] | 1466 | } |
| 1467 | |
| 1468 | void CommandBuffer::waitEvents(uint32_t eventCount, const VkEvent* pEvents, VkPipelineStageFlags srcStageMask, |
| 1469 | VkPipelineStageFlags dstStageMask, uint32_t memoryBarrierCount, const VkMemoryBarrier* pMemoryBarriers, |
| 1470 | uint32_t bufferMemoryBarrierCount, const VkBufferMemoryBarrier* pBufferMemoryBarriers, |
| 1471 | uint32_t imageMemoryBarrierCount, const VkImageMemoryBarrier* pImageMemoryBarriers) |
| 1472 | { |
Alexis Hetu | 9041bb7 | 2019-03-15 14:45:45 -0400 | [diff] [blame] | 1473 | ASSERT(state == RECORDING); |
| 1474 | |
| 1475 | // TODO(b/117835459): Since we always do a full barrier, all memory barrier related arguments are ignored |
| 1476 | |
| 1477 | // Note: srcStageMask and dstStageMask are currently ignored |
| 1478 | for(uint32_t i = 0; i < eventCount; i++) |
| 1479 | { |
| 1480 | addCommand<WaitEvent>(pEvents[i]); |
| 1481 | } |
Alexis Hetu | a9999ce | 2018-10-17 08:00:43 -0400 | [diff] [blame] | 1482 | } |
| 1483 | |
| 1484 | void CommandBuffer::draw(uint32_t vertexCount, uint32_t instanceCount, uint32_t firstVertex, uint32_t firstInstance) |
| 1485 | { |
Alexis Hetu | d9e364c | 2019-01-24 16:36:53 -0500 | [diff] [blame] | 1486 | addCommand<Draw>(vertexCount, instanceCount, firstVertex, firstInstance); |
Alexis Hetu | a9999ce | 2018-10-17 08:00:43 -0400 | [diff] [blame] | 1487 | } |
| 1488 | |
| 1489 | void CommandBuffer::drawIndexed(uint32_t indexCount, uint32_t instanceCount, uint32_t firstIndex, int32_t vertexOffset, uint32_t firstInstance) |
| 1490 | { |
Chris Forbes | baf7ad3 | 2019-02-25 18:14:42 -0800 | [diff] [blame] | 1491 | addCommand<DrawIndexed>(indexCount, instanceCount, firstIndex, vertexOffset, firstInstance); |
Alexis Hetu | a9999ce | 2018-10-17 08:00:43 -0400 | [diff] [blame] | 1492 | } |
| 1493 | |
| 1494 | void CommandBuffer::drawIndirect(VkBuffer buffer, VkDeviceSize offset, uint32_t drawCount, uint32_t stride) |
| 1495 | { |
Chris Forbes | 48b3587 | 2019-03-22 14:12:50 -0700 | [diff] [blame] | 1496 | addCommand<DrawIndirect>(buffer, offset, drawCount, stride); |
Alexis Hetu | a9999ce | 2018-10-17 08:00:43 -0400 | [diff] [blame] | 1497 | } |
| 1498 | |
| 1499 | void CommandBuffer::drawIndexedIndirect(VkBuffer buffer, VkDeviceSize offset, uint32_t drawCount, uint32_t stride) |
| 1500 | { |
Chris Forbes | 48b3587 | 2019-03-22 14:12:50 -0700 | [diff] [blame] | 1501 | addCommand<DrawIndexedIndirect>(buffer, offset, drawCount, stride); |
Alexis Hetu | a9999ce | 2018-10-17 08:00:43 -0400 | [diff] [blame] | 1502 | } |
| 1503 | |
Alexis Hetu | 9bc7a81 | 2018-12-07 16:13:34 -0500 | [diff] [blame] | 1504 | void CommandBuffer::submit(CommandBuffer::ExecutionState& executionState) |
Alexis Hetu | a9999ce | 2018-10-17 08:00:43 -0400 | [diff] [blame] | 1505 | { |
| 1506 | // Perform recorded work |
| 1507 | state = PENDING; |
| 1508 | |
Alexis Hetu | 072dc0d | 2018-10-31 11:41:25 -0400 | [diff] [blame] | 1509 | for(auto& command : *commands) |
| 1510 | { |
Alexis Hetu | 9bc7a81 | 2018-12-07 16:13:34 -0500 | [diff] [blame] | 1511 | command->play(executionState); |
Alexis Hetu | 072dc0d | 2018-10-31 11:41:25 -0400 | [diff] [blame] | 1512 | } |
Alexis Hetu | a9999ce | 2018-10-17 08:00:43 -0400 | [diff] [blame] | 1513 | |
| 1514 | // After work is completed |
| 1515 | state = EXECUTABLE; |
| 1516 | } |
| 1517 | |
Alexis Hetu | e7b2a05 | 2019-03-18 16:16:36 -0400 | [diff] [blame] | 1518 | void CommandBuffer::submitSecondary(CommandBuffer::ExecutionState& executionState) const |
| 1519 | { |
| 1520 | for(auto& command : *commands) |
| 1521 | { |
| 1522 | command->play(executionState); |
| 1523 | } |
| 1524 | } |
| 1525 | |
Chris Forbes | f8374cf | 2018-12-06 13:25:59 -0800 | [diff] [blame] | 1526 | } // namespace vk |