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" |
Nicolas Capens | 002b7c1 | 2020-04-24 01:05:57 -0400 | [diff] [blame] | 16 | |
Alexis Hetu | c65473d | 2018-12-07 16:26:05 -0500 | [diff] [blame] | 17 | #include "VkBuffer.hpp" |
Antonio Maiorano | 42fd159 | 2020-04-27 11:30:40 -0400 | [diff] [blame] | 18 | #include "VkConfig.hpp" |
Antonio Maiorano | 6636f14 | 2020-03-30 21:29:07 -0400 | [diff] [blame] | 19 | #include "VkDevice.hpp" |
Alexis Hetu | 3f5a479 | 2019-02-01 17:49:55 -0500 | [diff] [blame] | 20 | #include "VkEvent.hpp" |
Alexis Hetu | e1f51b9 | 2019-04-23 15:34:34 -0400 | [diff] [blame] | 21 | #include "VkFence.hpp" |
Alexis Hetu | 9bc7a81 | 2018-12-07 16:13:34 -0500 | [diff] [blame] | 22 | #include "VkFramebuffer.hpp" |
Alexis Hetu | 09056de | 2018-12-07 12:40:00 -0500 | [diff] [blame] | 23 | #include "VkImage.hpp" |
Chris Forbes | 7c33e88 | 2019-02-21 14:58:28 -0800 | [diff] [blame] | 24 | #include "VkImageView.hpp" |
Alexis Hetu | c65473d | 2018-12-07 16:26:05 -0500 | [diff] [blame] | 25 | #include "VkPipeline.hpp" |
Ben Clayton | f2be26a | 2019-03-08 12:02:05 +0000 | [diff] [blame] | 26 | #include "VkPipelineLayout.hpp" |
Alexis Hetu | f0aa9d5 | 2019-04-01 17:06:47 -0400 | [diff] [blame] | 27 | #include "VkQueryPool.hpp" |
Chris Forbes | 50dd2ce | 2018-12-07 17:54:31 -0800 | [diff] [blame] | 28 | #include "VkRenderPass.hpp" |
Alexis Hetu | c65473d | 2018-12-07 16:26:05 -0500 | [diff] [blame] | 29 | #include "Device/Renderer.hpp" |
Alexis Hetu | 767b41b | 2018-09-26 11:25:46 -0400 | [diff] [blame] | 30 | |
Ben Clayton | a4e06ca | 2019-12-03 12:38:14 +0000 | [diff] [blame] | 31 | #include "./Debug/Context.hpp" |
| 32 | #include "./Debug/File.hpp" |
| 33 | #include "./Debug/Thread.hpp" |
| 34 | |
| 35 | #include "marl/defer.h" |
| 36 | |
Chris Forbes | f8374cf | 2018-12-06 13:25:59 -0800 | [diff] [blame] | 37 | #include <cstring> |
| 38 | |
Ben Clayton | 1e610ee | 2019-12-03 11:48:25 +0000 | [diff] [blame] | 39 | class vk::CommandBuffer::Command |
Alexis Hetu | 072dc0d | 2018-10-31 11:41:25 -0400 | [diff] [blame] | 40 | { |
| 41 | public: |
| 42 | // FIXME (b/119421344): change the commandBuffer argument to a CommandBuffer state |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 43 | virtual void play(vk::CommandBuffer::ExecutionState &executionState) = 0; |
Ben Clayton | 72c398f | 2019-12-03 11:53:09 +0000 | [diff] [blame] | 44 | virtual std::string description() = 0; |
Alexis Hetu | 072dc0d | 2018-10-31 11:41:25 -0400 | [diff] [blame] | 45 | virtual ~Command() {} |
| 46 | }; |
| 47 | |
Ben Clayton | 1e610ee | 2019-12-03 11:48:25 +0000 | [diff] [blame] | 48 | namespace { |
| 49 | |
| 50 | class CmdBeginRenderPass : public vk::CommandBuffer::Command |
Alexis Hetu | 072dc0d | 2018-10-31 11:41:25 -0400 | [diff] [blame] | 51 | { |
| 52 | public: |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 53 | CmdBeginRenderPass(vk::RenderPass *renderPass, vk::Framebuffer *framebuffer, VkRect2D renderArea, |
| 54 | uint32_t clearValueCount, const VkClearValue *pClearValues) |
| 55 | : renderPass(renderPass) |
| 56 | , framebuffer(framebuffer) |
| 57 | , renderArea(renderArea) |
| 58 | , clearValueCount(clearValueCount) |
Alexis Hetu | 072dc0d | 2018-10-31 11:41:25 -0400 | [diff] [blame] | 59 | { |
| 60 | // FIXME (b/119409619): use an allocator here so we can control all memory allocations |
| 61 | clearValues = new VkClearValue[clearValueCount]; |
| 62 | memcpy(clearValues, pClearValues, clearValueCount * sizeof(VkClearValue)); |
| 63 | } |
| 64 | |
Ben Clayton | 1e610ee | 2019-12-03 11:48:25 +0000 | [diff] [blame] | 65 | ~CmdBeginRenderPass() override |
Alexis Hetu | 072dc0d | 2018-10-31 11:41:25 -0400 | [diff] [blame] | 66 | { |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 67 | delete[] clearValues; |
Alexis Hetu | 072dc0d | 2018-10-31 11:41:25 -0400 | [diff] [blame] | 68 | } |
| 69 | |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 70 | void play(vk::CommandBuffer::ExecutionState &executionState) override |
Alexis Hetu | 072dc0d | 2018-10-31 11:41:25 -0400 | [diff] [blame] | 71 | { |
Alexis Hetu | 1cd31ea | 2019-01-17 17:14:57 -0500 | [diff] [blame] | 72 | executionState.renderPass = renderPass; |
| 73 | executionState.renderPassFramebuffer = framebuffer; |
Chris Forbes | d6dc4b7 | 2019-08-23 08:23:27 -0700 | [diff] [blame] | 74 | executionState.subpassIndex = 0; |
Alexis Hetu | 54ec759 | 2019-03-20 14:37:16 -0400 | [diff] [blame] | 75 | framebuffer->clear(executionState.renderPass, clearValueCount, clearValues, renderArea); |
Alexis Hetu | 072dc0d | 2018-10-31 11:41:25 -0400 | [diff] [blame] | 76 | } |
| 77 | |
Ben Clayton | 72c398f | 2019-12-03 11:53:09 +0000 | [diff] [blame] | 78 | std::string description() override { return "vkCmdBeginRenderPass()"; } |
| 79 | |
Alexis Hetu | 072dc0d | 2018-10-31 11:41:25 -0400 | [diff] [blame] | 80 | private: |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 81 | vk::RenderPass *renderPass; |
| 82 | vk::Framebuffer *framebuffer; |
Alexis Hetu | 072dc0d | 2018-10-31 11:41:25 -0400 | [diff] [blame] | 83 | VkRect2D renderArea; |
| 84 | uint32_t clearValueCount; |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 85 | VkClearValue *clearValues; |
Alexis Hetu | 072dc0d | 2018-10-31 11:41:25 -0400 | [diff] [blame] | 86 | }; |
| 87 | |
Ben Clayton | 1e610ee | 2019-12-03 11:48:25 +0000 | [diff] [blame] | 88 | class CmdNextSubpass : public vk::CommandBuffer::Command |
Alexis Hetu | 1cd31ea | 2019-01-17 17:14:57 -0500 | [diff] [blame] | 89 | { |
| 90 | public: |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 91 | void play(vk::CommandBuffer::ExecutionState &executionState) override |
Alexis Hetu | 1cd31ea | 2019-01-17 17:14:57 -0500 | [diff] [blame] | 92 | { |
Chris Forbes | d6dc4b7 | 2019-08-23 08:23:27 -0700 | [diff] [blame] | 93 | bool hasResolveAttachments = (executionState.renderPass->getSubpass(executionState.subpassIndex).pResolveAttachments != nullptr); |
Alexis Hetu | 54ec759 | 2019-03-20 14:37:16 -0400 | [diff] [blame] | 94 | if(hasResolveAttachments) |
| 95 | { |
| 96 | // FIXME(sugoi): remove the following lines and resolve in Renderer::finishRendering() |
| 97 | // for a Draw command or after the last command of the current subpass |
| 98 | // which modifies pixels. |
| 99 | executionState.renderer->synchronize(); |
Chris Forbes | d6dc4b7 | 2019-08-23 08:23:27 -0700 | [diff] [blame] | 100 | executionState.renderPassFramebuffer->resolve(executionState.renderPass, executionState.subpassIndex); |
Alexis Hetu | 54ec759 | 2019-03-20 14:37:16 -0400 | [diff] [blame] | 101 | } |
| 102 | |
Chris Forbes | d6dc4b7 | 2019-08-23 08:23:27 -0700 | [diff] [blame] | 103 | ++executionState.subpassIndex; |
Alexis Hetu | 1cd31ea | 2019-01-17 17:14:57 -0500 | [diff] [blame] | 104 | } |
Ben Clayton | 72c398f | 2019-12-03 11:53:09 +0000 | [diff] [blame] | 105 | |
| 106 | std::string description() override { return "vkCmdNextSubpass()"; } |
Alexis Hetu | 1cd31ea | 2019-01-17 17:14:57 -0500 | [diff] [blame] | 107 | }; |
| 108 | |
Ben Clayton | 1e610ee | 2019-12-03 11:48:25 +0000 | [diff] [blame] | 109 | class CmdEndRenderPass : public vk::CommandBuffer::Command |
Alexis Hetu | 072dc0d | 2018-10-31 11:41:25 -0400 | [diff] [blame] | 110 | { |
| 111 | public: |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 112 | void play(vk::CommandBuffer::ExecutionState &executionState) override |
Alexis Hetu | 072dc0d | 2018-10-31 11:41:25 -0400 | [diff] [blame] | 113 | { |
Chris Forbes | fc06fd1 | 2019-03-21 08:36:11 -0700 | [diff] [blame] | 114 | // Execute (implicit or explicit) VkSubpassDependency to VK_SUBPASS_EXTERNAL |
| 115 | // This is somewhat heavier than the actual ordering required. |
| 116 | executionState.renderer->synchronize(); |
Alexis Hetu | 54ec759 | 2019-03-20 14:37:16 -0400 | [diff] [blame] | 117 | |
| 118 | // FIXME(sugoi): remove the following line and resolve in Renderer::finishRendering() |
| 119 | // for a Draw command or after the last command of the current subpass |
| 120 | // which modifies pixels. |
Chris Forbes | d6dc4b7 | 2019-08-23 08:23:27 -0700 | [diff] [blame] | 121 | executionState.renderPassFramebuffer->resolve(executionState.renderPass, executionState.subpassIndex); |
Alexis Hetu | 54ec759 | 2019-03-20 14:37:16 -0400 | [diff] [blame] | 122 | executionState.renderPass = nullptr; |
| 123 | executionState.renderPassFramebuffer = nullptr; |
Alexis Hetu | 072dc0d | 2018-10-31 11:41:25 -0400 | [diff] [blame] | 124 | } |
Ben Clayton | 72c398f | 2019-12-03 11:53:09 +0000 | [diff] [blame] | 125 | |
| 126 | std::string description() override { return "vkCmdEndRenderPass()"; } |
Alexis Hetu | 072dc0d | 2018-10-31 11:41:25 -0400 | [diff] [blame] | 127 | }; |
| 128 | |
Ben Clayton | 1e610ee | 2019-12-03 11:48:25 +0000 | [diff] [blame] | 129 | class CmdExecuteCommands : public vk::CommandBuffer::Command |
Alexis Hetu | e7b2a05 | 2019-03-18 16:16:36 -0400 | [diff] [blame] | 130 | { |
| 131 | public: |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 132 | CmdExecuteCommands(const vk::CommandBuffer *commandBuffer) |
| 133 | : commandBuffer(commandBuffer) |
Alexis Hetu | e7b2a05 | 2019-03-18 16:16:36 -0400 | [diff] [blame] | 134 | { |
| 135 | } |
| 136 | |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 137 | void play(vk::CommandBuffer::ExecutionState &executionState) override |
Alexis Hetu | e7b2a05 | 2019-03-18 16:16:36 -0400 | [diff] [blame] | 138 | { |
Alexis Hetu | 63ae924 | 2019-06-06 13:52:15 -0400 | [diff] [blame] | 139 | commandBuffer->submitSecondary(executionState); |
Alexis Hetu | e7b2a05 | 2019-03-18 16:16:36 -0400 | [diff] [blame] | 140 | } |
| 141 | |
Ben Clayton | 72c398f | 2019-12-03 11:53:09 +0000 | [diff] [blame] | 142 | std::string description() override { return "vkCmdExecuteCommands()"; } |
| 143 | |
Alexis Hetu | e7b2a05 | 2019-03-18 16:16:36 -0400 | [diff] [blame] | 144 | private: |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 145 | const vk::CommandBuffer *commandBuffer; |
Alexis Hetu | e7b2a05 | 2019-03-18 16:16:36 -0400 | [diff] [blame] | 146 | }; |
| 147 | |
Ben Clayton | 1e610ee | 2019-12-03 11:48:25 +0000 | [diff] [blame] | 148 | class CmdPipelineBind : public vk::CommandBuffer::Command |
Alexis Hetu | 072dc0d | 2018-10-31 11:41:25 -0400 | [diff] [blame] | 149 | { |
| 150 | public: |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 151 | CmdPipelineBind(VkPipelineBindPoint pipelineBindPoint, vk::Pipeline *pipeline) |
| 152 | : pipelineBindPoint(pipelineBindPoint) |
| 153 | , pipeline(pipeline) |
Alexis Hetu | 072dc0d | 2018-10-31 11:41:25 -0400 | [diff] [blame] | 154 | { |
| 155 | } |
| 156 | |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 157 | void play(vk::CommandBuffer::ExecutionState &executionState) override |
Alexis Hetu | 072dc0d | 2018-10-31 11:41:25 -0400 | [diff] [blame] | 158 | { |
Alexis Hetu | 63ae924 | 2019-06-06 13:52:15 -0400 | [diff] [blame] | 159 | executionState.pipelineState[pipelineBindPoint].pipeline = pipeline; |
Alexis Hetu | 072dc0d | 2018-10-31 11:41:25 -0400 | [diff] [blame] | 160 | } |
| 161 | |
Ben Clayton | 72c398f | 2019-12-03 11:53:09 +0000 | [diff] [blame] | 162 | std::string description() override { return "vkCmdPipelineBind()"; } |
| 163 | |
Alexis Hetu | 072dc0d | 2018-10-31 11:41:25 -0400 | [diff] [blame] | 164 | private: |
| 165 | VkPipelineBindPoint pipelineBindPoint; |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 166 | vk::Pipeline *pipeline; |
Alexis Hetu | 072dc0d | 2018-10-31 11:41:25 -0400 | [diff] [blame] | 167 | }; |
| 168 | |
Ben Clayton | 1e610ee | 2019-12-03 11:48:25 +0000 | [diff] [blame] | 169 | class CmdDispatch : public vk::CommandBuffer::Command |
Ben Clayton | f2be26a | 2019-03-08 12:02:05 +0000 | [diff] [blame] | 170 | { |
| 171 | public: |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 172 | CmdDispatch(uint32_t baseGroupX, uint32_t baseGroupY, uint32_t baseGroupZ, uint32_t groupCountX, uint32_t groupCountY, uint32_t groupCountZ) |
| 173 | : baseGroupX(baseGroupX) |
| 174 | , baseGroupY(baseGroupY) |
| 175 | , baseGroupZ(baseGroupZ) |
| 176 | , groupCountX(groupCountX) |
| 177 | , groupCountY(groupCountY) |
| 178 | , groupCountZ(groupCountZ) |
Ben Clayton | f2be26a | 2019-03-08 12:02:05 +0000 | [diff] [blame] | 179 | { |
| 180 | } |
| 181 | |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 182 | void play(vk::CommandBuffer::ExecutionState &executionState) override |
Ben Clayton | f2be26a | 2019-03-08 12:02:05 +0000 | [diff] [blame] | 183 | { |
Ben Clayton | 225a130 | 2019-04-02 12:28:22 +0100 | [diff] [blame] | 184 | auto const &pipelineState = executionState.pipelineState[VK_PIPELINE_BIND_POINT_COMPUTE]; |
| 185 | |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 186 | vk::ComputePipeline *pipeline = static_cast<vk::ComputePipeline *>(pipelineState.pipeline); |
Chris Forbes | 4a4c259 | 2019-05-13 08:53:36 -0700 | [diff] [blame] | 187 | pipeline->run(baseGroupX, baseGroupY, baseGroupZ, |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 188 | groupCountX, groupCountY, groupCountZ, |
Alexis Hetu | 4f438a5 | 2020-06-15 16:13:51 -0400 | [diff] [blame] | 189 | pipelineState.descriptorSetObjects, |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 190 | pipelineState.descriptorSets, |
| 191 | pipelineState.descriptorDynamicOffsets, |
| 192 | executionState.pushConstants); |
Ben Clayton | f2be26a | 2019-03-08 12:02:05 +0000 | [diff] [blame] | 193 | } |
| 194 | |
Ben Clayton | 72c398f | 2019-12-03 11:53:09 +0000 | [diff] [blame] | 195 | std::string description() override { return "vkCmdDispatch()"; } |
| 196 | |
Ben Clayton | f2be26a | 2019-03-08 12:02:05 +0000 | [diff] [blame] | 197 | private: |
Chris Forbes | 4a4c259 | 2019-05-13 08:53:36 -0700 | [diff] [blame] | 198 | uint32_t baseGroupX; |
| 199 | uint32_t baseGroupY; |
| 200 | uint32_t baseGroupZ; |
Ben Clayton | f2be26a | 2019-03-08 12:02:05 +0000 | [diff] [blame] | 201 | uint32_t groupCountX; |
| 202 | uint32_t groupCountY; |
| 203 | uint32_t groupCountZ; |
| 204 | }; |
| 205 | |
Ben Clayton | 1e610ee | 2019-12-03 11:48:25 +0000 | [diff] [blame] | 206 | class CmdDispatchIndirect : public vk::CommandBuffer::Command |
Chris Forbes | fc8a46d | 2019-03-22 14:47:47 -0700 | [diff] [blame] | 207 | { |
| 208 | public: |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 209 | CmdDispatchIndirect(vk::Buffer *buffer, VkDeviceSize offset) |
| 210 | : buffer(buffer) |
| 211 | , offset(offset) |
Chris Forbes | fc8a46d | 2019-03-22 14:47:47 -0700 | [diff] [blame] | 212 | { |
| 213 | } |
| 214 | |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 215 | void play(vk::CommandBuffer::ExecutionState &executionState) override |
Chris Forbes | fc8a46d | 2019-03-22 14:47:47 -0700 | [diff] [blame] | 216 | { |
Alexis Hetu | 63ae924 | 2019-06-06 13:52:15 -0400 | [diff] [blame] | 217 | auto cmd = reinterpret_cast<VkDispatchIndirectCommand const *>(buffer->getOffsetPointer(offset)); |
Chris Forbes | fc8a46d | 2019-03-22 14:47:47 -0700 | [diff] [blame] | 218 | |
Ben Clayton | 225a130 | 2019-04-02 12:28:22 +0100 | [diff] [blame] | 219 | auto const &pipelineState = executionState.pipelineState[VK_PIPELINE_BIND_POINT_COMPUTE]; |
| 220 | |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 221 | auto pipeline = static_cast<vk::ComputePipeline *>(pipelineState.pipeline); |
Chris Forbes | 4a4c259 | 2019-05-13 08:53:36 -0700 | [diff] [blame] | 222 | pipeline->run(0, 0, 0, cmd->x, cmd->y, cmd->z, |
Alexis Hetu | 4f438a5 | 2020-06-15 16:13:51 -0400 | [diff] [blame] | 223 | pipelineState.descriptorSetObjects, |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 224 | pipelineState.descriptorSets, |
| 225 | pipelineState.descriptorDynamicOffsets, |
| 226 | executionState.pushConstants); |
Chris Forbes | fc8a46d | 2019-03-22 14:47:47 -0700 | [diff] [blame] | 227 | } |
| 228 | |
Ben Clayton | 72c398f | 2019-12-03 11:53:09 +0000 | [diff] [blame] | 229 | std::string description() override { return "vkCmdDispatchIndirect()"; } |
| 230 | |
Chris Forbes | fc8a46d | 2019-03-22 14:47:47 -0700 | [diff] [blame] | 231 | private: |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 232 | const vk::Buffer *buffer; |
Chris Forbes | fc8a46d | 2019-03-22 14:47:47 -0700 | [diff] [blame] | 233 | VkDeviceSize offset; |
| 234 | }; |
| 235 | |
Ben Clayton | 1e610ee | 2019-12-03 11:48:25 +0000 | [diff] [blame] | 236 | class CmdVertexBufferBind : public vk::CommandBuffer::Command |
Alexis Hetu | 072dc0d | 2018-10-31 11:41:25 -0400 | [diff] [blame] | 237 | { |
Ben Clayton | 1e610ee | 2019-12-03 11:48:25 +0000 | [diff] [blame] | 238 | public: |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 239 | CmdVertexBufferBind(uint32_t binding, vk::Buffer *buffer, const VkDeviceSize offset) |
| 240 | : binding(binding) |
| 241 | , buffer(buffer) |
| 242 | , offset(offset) |
Alexis Hetu | 072dc0d | 2018-10-31 11:41:25 -0400 | [diff] [blame] | 243 | { |
| 244 | } |
| 245 | |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 246 | void play(vk::CommandBuffer::ExecutionState &executionState) override |
Alexis Hetu | 072dc0d | 2018-10-31 11:41:25 -0400 | [diff] [blame] | 247 | { |
Alexis Hetu | 9bc7a81 | 2018-12-07 16:13:34 -0500 | [diff] [blame] | 248 | executionState.vertexInputBindings[binding] = { buffer, offset }; |
Alexis Hetu | 072dc0d | 2018-10-31 11:41:25 -0400 | [diff] [blame] | 249 | } |
| 250 | |
Ben Clayton | 72c398f | 2019-12-03 11:53:09 +0000 | [diff] [blame] | 251 | std::string description() override { return "vkCmdVertexBufferBind()"; } |
| 252 | |
Alexis Hetu | 63ae924 | 2019-06-06 13:52:15 -0400 | [diff] [blame] | 253 | private: |
Alexis Hetu | 072dc0d | 2018-10-31 11:41:25 -0400 | [diff] [blame] | 254 | uint32_t binding; |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 255 | vk::Buffer *buffer; |
Alexis Hetu | 072dc0d | 2018-10-31 11:41:25 -0400 | [diff] [blame] | 256 | const VkDeviceSize offset; |
| 257 | }; |
| 258 | |
Ben Clayton | 1e610ee | 2019-12-03 11:48:25 +0000 | [diff] [blame] | 259 | class CmdIndexBufferBind : public vk::CommandBuffer::Command |
Chris Forbes | baf7ad3 | 2019-02-25 18:14:42 -0800 | [diff] [blame] | 260 | { |
Ben Clayton | 1e610ee | 2019-12-03 11:48:25 +0000 | [diff] [blame] | 261 | public: |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 262 | CmdIndexBufferBind(vk::Buffer *buffer, const VkDeviceSize offset, const VkIndexType indexType) |
| 263 | : buffer(buffer) |
| 264 | , offset(offset) |
| 265 | , indexType(indexType) |
Chris Forbes | baf7ad3 | 2019-02-25 18:14:42 -0800 | [diff] [blame] | 266 | { |
Chris Forbes | baf7ad3 | 2019-02-25 18:14:42 -0800 | [diff] [blame] | 267 | } |
| 268 | |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 269 | void play(vk::CommandBuffer::ExecutionState &executionState) override |
Chris Forbes | baf7ad3 | 2019-02-25 18:14:42 -0800 | [diff] [blame] | 270 | { |
Alexis Hetu | 63ae924 | 2019-06-06 13:52:15 -0400 | [diff] [blame] | 271 | executionState.indexBufferBinding = { buffer, offset }; |
Chris Forbes | baf7ad3 | 2019-02-25 18:14:42 -0800 | [diff] [blame] | 272 | executionState.indexType = indexType; |
| 273 | } |
| 274 | |
Ben Clayton | 72c398f | 2019-12-03 11:53:09 +0000 | [diff] [blame] | 275 | std::string description() override { return "vkCmdIndexBufferBind()"; } |
| 276 | |
Alexis Hetu | 63ae924 | 2019-06-06 13:52:15 -0400 | [diff] [blame] | 277 | private: |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 278 | vk::Buffer *buffer; |
Chris Forbes | baf7ad3 | 2019-02-25 18:14:42 -0800 | [diff] [blame] | 279 | const VkDeviceSize offset; |
| 280 | const VkIndexType indexType; |
| 281 | }; |
| 282 | |
Ben Clayton | 1e610ee | 2019-12-03 11:48:25 +0000 | [diff] [blame] | 283 | class CmdSetViewport : public vk::CommandBuffer::Command |
Alexis Hetu | 7383243 | 2019-04-11 16:43:18 -0400 | [diff] [blame] | 284 | { |
Ben Clayton | 1e610ee | 2019-12-03 11:48:25 +0000 | [diff] [blame] | 285 | public: |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 286 | CmdSetViewport(const VkViewport &viewport, uint32_t viewportID) |
| 287 | : viewport(viewport) |
| 288 | , viewportID(viewportID) |
Alexis Hetu | 7383243 | 2019-04-11 16:43:18 -0400 | [diff] [blame] | 289 | { |
| 290 | } |
| 291 | |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 292 | void play(vk::CommandBuffer::ExecutionState &executionState) override |
Alexis Hetu | 7383243 | 2019-04-11 16:43:18 -0400 | [diff] [blame] | 293 | { |
| 294 | executionState.dynamicState.viewport = viewport; |
| 295 | } |
| 296 | |
Ben Clayton | 72c398f | 2019-12-03 11:53:09 +0000 | [diff] [blame] | 297 | std::string description() override { return "vkCmdSetViewport()"; } |
| 298 | |
Alexis Hetu | 63ae924 | 2019-06-06 13:52:15 -0400 | [diff] [blame] | 299 | private: |
Alexis Hetu | 7383243 | 2019-04-11 16:43:18 -0400 | [diff] [blame] | 300 | const VkViewport viewport; |
| 301 | uint32_t viewportID; |
| 302 | }; |
| 303 | |
Ben Clayton | 1e610ee | 2019-12-03 11:48:25 +0000 | [diff] [blame] | 304 | class CmdSetScissor : public vk::CommandBuffer::Command |
Alexis Hetu | 7383243 | 2019-04-11 16:43:18 -0400 | [diff] [blame] | 305 | { |
Ben Clayton | 1e610ee | 2019-12-03 11:48:25 +0000 | [diff] [blame] | 306 | public: |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 307 | CmdSetScissor(const VkRect2D &scissor, uint32_t scissorID) |
| 308 | : scissor(scissor) |
| 309 | , scissorID(scissorID) |
Alexis Hetu | 7383243 | 2019-04-11 16:43:18 -0400 | [diff] [blame] | 310 | { |
| 311 | } |
| 312 | |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 313 | void play(vk::CommandBuffer::ExecutionState &executionState) override |
Alexis Hetu | 7383243 | 2019-04-11 16:43:18 -0400 | [diff] [blame] | 314 | { |
| 315 | executionState.dynamicState.scissor = scissor; |
| 316 | } |
| 317 | |
Ben Clayton | 72c398f | 2019-12-03 11:53:09 +0000 | [diff] [blame] | 318 | std::string description() override { return "vkCmdSetScissor()"; } |
| 319 | |
Alexis Hetu | 63ae924 | 2019-06-06 13:52:15 -0400 | [diff] [blame] | 320 | private: |
Alexis Hetu | 7383243 | 2019-04-11 16:43:18 -0400 | [diff] [blame] | 321 | const VkRect2D scissor; |
| 322 | uint32_t scissorID; |
| 323 | }; |
| 324 | |
Ben Clayton | 1e610ee | 2019-12-03 11:48:25 +0000 | [diff] [blame] | 325 | class CmdSetDepthBias : public vk::CommandBuffer::Command |
Alexis Hetu | 7383243 | 2019-04-11 16:43:18 -0400 | [diff] [blame] | 326 | { |
Ben Clayton | 1e610ee | 2019-12-03 11:48:25 +0000 | [diff] [blame] | 327 | public: |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 328 | CmdSetDepthBias(float depthBiasConstantFactor, float depthBiasClamp, float depthBiasSlopeFactor) |
| 329 | : depthBiasConstantFactor(depthBiasConstantFactor) |
| 330 | , depthBiasClamp(depthBiasClamp) |
| 331 | , depthBiasSlopeFactor(depthBiasSlopeFactor) |
Alexis Hetu | 7383243 | 2019-04-11 16:43:18 -0400 | [diff] [blame] | 332 | { |
| 333 | } |
| 334 | |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 335 | void play(vk::CommandBuffer::ExecutionState &executionState) override |
Alexis Hetu | 7383243 | 2019-04-11 16:43:18 -0400 | [diff] [blame] | 336 | { |
| 337 | executionState.dynamicState.depthBiasConstantFactor = depthBiasConstantFactor; |
| 338 | executionState.dynamicState.depthBiasClamp = depthBiasClamp; |
| 339 | executionState.dynamicState.depthBiasSlopeFactor = depthBiasSlopeFactor; |
| 340 | } |
| 341 | |
Ben Clayton | 72c398f | 2019-12-03 11:53:09 +0000 | [diff] [blame] | 342 | std::string description() override { return "vkCmdSetDepthBias()"; } |
| 343 | |
Alexis Hetu | 63ae924 | 2019-06-06 13:52:15 -0400 | [diff] [blame] | 344 | private: |
Alexis Hetu | 7383243 | 2019-04-11 16:43:18 -0400 | [diff] [blame] | 345 | float depthBiasConstantFactor; |
| 346 | float depthBiasClamp; |
| 347 | float depthBiasSlopeFactor; |
| 348 | }; |
| 349 | |
Ben Clayton | 1e610ee | 2019-12-03 11:48:25 +0000 | [diff] [blame] | 350 | class CmdSetBlendConstants : public vk::CommandBuffer::Command |
Alexis Hetu | 7383243 | 2019-04-11 16:43:18 -0400 | [diff] [blame] | 351 | { |
Ben Clayton | 1e610ee | 2019-12-03 11:48:25 +0000 | [diff] [blame] | 352 | public: |
| 353 | CmdSetBlendConstants(const float blendConstants[4]) |
Alexis Hetu | 7383243 | 2019-04-11 16:43:18 -0400 | [diff] [blame] | 354 | { |
| 355 | memcpy(this->blendConstants, blendConstants, sizeof(this->blendConstants)); |
| 356 | } |
| 357 | |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 358 | void play(vk::CommandBuffer::ExecutionState &executionState) override |
Alexis Hetu | 7383243 | 2019-04-11 16:43:18 -0400 | [diff] [blame] | 359 | { |
| 360 | memcpy(&(executionState.dynamicState.blendConstants[0]), blendConstants, sizeof(blendConstants)); |
| 361 | } |
| 362 | |
Ben Clayton | 72c398f | 2019-12-03 11:53:09 +0000 | [diff] [blame] | 363 | std::string description() override { return "vkCmdSetBlendConstants()"; } |
| 364 | |
Alexis Hetu | 63ae924 | 2019-06-06 13:52:15 -0400 | [diff] [blame] | 365 | private: |
Alexis Hetu | 7383243 | 2019-04-11 16:43:18 -0400 | [diff] [blame] | 366 | float blendConstants[4]; |
| 367 | }; |
| 368 | |
Ben Clayton | 1e610ee | 2019-12-03 11:48:25 +0000 | [diff] [blame] | 369 | class CmdSetDepthBounds : public vk::CommandBuffer::Command |
Alexis Hetu | 7383243 | 2019-04-11 16:43:18 -0400 | [diff] [blame] | 370 | { |
Ben Clayton | 1e610ee | 2019-12-03 11:48:25 +0000 | [diff] [blame] | 371 | public: |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 372 | CmdSetDepthBounds(float minDepthBounds, float maxDepthBounds) |
| 373 | : minDepthBounds(minDepthBounds) |
| 374 | , maxDepthBounds(maxDepthBounds) |
Alexis Hetu | 7383243 | 2019-04-11 16:43:18 -0400 | [diff] [blame] | 375 | { |
| 376 | } |
| 377 | |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 378 | void play(vk::CommandBuffer::ExecutionState &executionState) override |
Alexis Hetu | 7383243 | 2019-04-11 16:43:18 -0400 | [diff] [blame] | 379 | { |
| 380 | executionState.dynamicState.minDepthBounds = minDepthBounds; |
| 381 | executionState.dynamicState.maxDepthBounds = maxDepthBounds; |
| 382 | } |
| 383 | |
Ben Clayton | 72c398f | 2019-12-03 11:53:09 +0000 | [diff] [blame] | 384 | std::string description() override { return "vkCmdSetDepthBounds()"; } |
| 385 | |
Alexis Hetu | 63ae924 | 2019-06-06 13:52:15 -0400 | [diff] [blame] | 386 | private: |
Alexis Hetu | 7383243 | 2019-04-11 16:43:18 -0400 | [diff] [blame] | 387 | float minDepthBounds; |
| 388 | float maxDepthBounds; |
| 389 | }; |
Ben Clayton | 1e610ee | 2019-12-03 11:48:25 +0000 | [diff] [blame] | 390 | |
| 391 | class CmdSetStencilCompareMask : public vk::CommandBuffer::Command |
Alexis Hetu | 7383243 | 2019-04-11 16:43:18 -0400 | [diff] [blame] | 392 | { |
Ben Clayton | 1e610ee | 2019-12-03 11:48:25 +0000 | [diff] [blame] | 393 | public: |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 394 | CmdSetStencilCompareMask(VkStencilFaceFlags faceMask, uint32_t compareMask) |
| 395 | : faceMask(faceMask) |
| 396 | , compareMask(compareMask) |
Alexis Hetu | 7383243 | 2019-04-11 16:43:18 -0400 | [diff] [blame] | 397 | { |
| 398 | } |
| 399 | |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 400 | void play(vk::CommandBuffer::ExecutionState &executionState) override |
Alexis Hetu | 7383243 | 2019-04-11 16:43:18 -0400 | [diff] [blame] | 401 | { |
| 402 | if(faceMask & VK_STENCIL_FACE_FRONT_BIT) |
| 403 | { |
| 404 | executionState.dynamicState.compareMask[0] = compareMask; |
| 405 | } |
| 406 | if(faceMask & VK_STENCIL_FACE_BACK_BIT) |
| 407 | { |
| 408 | executionState.dynamicState.compareMask[1] = compareMask; |
| 409 | } |
| 410 | } |
| 411 | |
Ben Clayton | 72c398f | 2019-12-03 11:53:09 +0000 | [diff] [blame] | 412 | std::string description() override { return "vkCmdSetStencilCompareMask()"; } |
| 413 | |
Alexis Hetu | 63ae924 | 2019-06-06 13:52:15 -0400 | [diff] [blame] | 414 | private: |
Alexis Hetu | 7383243 | 2019-04-11 16:43:18 -0400 | [diff] [blame] | 415 | VkStencilFaceFlags faceMask; |
| 416 | uint32_t compareMask; |
| 417 | }; |
| 418 | |
Ben Clayton | 1e610ee | 2019-12-03 11:48:25 +0000 | [diff] [blame] | 419 | class CmdSetStencilWriteMask : public vk::CommandBuffer::Command |
Alexis Hetu | 7383243 | 2019-04-11 16:43:18 -0400 | [diff] [blame] | 420 | { |
Ben Clayton | 1e610ee | 2019-12-03 11:48:25 +0000 | [diff] [blame] | 421 | public: |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 422 | CmdSetStencilWriteMask(VkStencilFaceFlags faceMask, uint32_t writeMask) |
| 423 | : faceMask(faceMask) |
| 424 | , writeMask(writeMask) |
Alexis Hetu | 7383243 | 2019-04-11 16:43:18 -0400 | [diff] [blame] | 425 | { |
| 426 | } |
| 427 | |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 428 | void play(vk::CommandBuffer::ExecutionState &executionState) override |
Alexis Hetu | 7383243 | 2019-04-11 16:43:18 -0400 | [diff] [blame] | 429 | { |
| 430 | if(faceMask & VK_STENCIL_FACE_FRONT_BIT) |
| 431 | { |
| 432 | executionState.dynamicState.writeMask[0] = writeMask; |
| 433 | } |
| 434 | if(faceMask & VK_STENCIL_FACE_BACK_BIT) |
| 435 | { |
| 436 | executionState.dynamicState.writeMask[1] = writeMask; |
| 437 | } |
| 438 | } |
| 439 | |
Ben Clayton | 72c398f | 2019-12-03 11:53:09 +0000 | [diff] [blame] | 440 | std::string description() override { return "vkCmdSetStencilWriteMask()"; } |
| 441 | |
Alexis Hetu | 63ae924 | 2019-06-06 13:52:15 -0400 | [diff] [blame] | 442 | private: |
Alexis Hetu | 7383243 | 2019-04-11 16:43:18 -0400 | [diff] [blame] | 443 | VkStencilFaceFlags faceMask; |
| 444 | uint32_t writeMask; |
| 445 | }; |
| 446 | |
Ben Clayton | 1e610ee | 2019-12-03 11:48:25 +0000 | [diff] [blame] | 447 | class CmdSetStencilReference : public vk::CommandBuffer::Command |
Alexis Hetu | 7383243 | 2019-04-11 16:43:18 -0400 | [diff] [blame] | 448 | { |
Ben Clayton | 1e610ee | 2019-12-03 11:48:25 +0000 | [diff] [blame] | 449 | public: |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 450 | CmdSetStencilReference(VkStencilFaceFlags faceMask, uint32_t reference) |
| 451 | : faceMask(faceMask) |
| 452 | , reference(reference) |
Alexis Hetu | 7383243 | 2019-04-11 16:43:18 -0400 | [diff] [blame] | 453 | { |
| 454 | } |
| 455 | |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 456 | void play(vk::CommandBuffer::ExecutionState &executionState) override |
Alexis Hetu | 7383243 | 2019-04-11 16:43:18 -0400 | [diff] [blame] | 457 | { |
| 458 | if(faceMask & VK_STENCIL_FACE_FRONT_BIT) |
| 459 | { |
| 460 | executionState.dynamicState.reference[0] = reference; |
| 461 | } |
| 462 | if(faceMask & VK_STENCIL_FACE_BACK_BIT) |
| 463 | { |
| 464 | executionState.dynamicState.reference[1] = reference; |
| 465 | } |
| 466 | } |
| 467 | |
Ben Clayton | 72c398f | 2019-12-03 11:53:09 +0000 | [diff] [blame] | 468 | std::string description() override { return "vkCmdSetStencilReference()"; } |
| 469 | |
Alexis Hetu | 63ae924 | 2019-06-06 13:52:15 -0400 | [diff] [blame] | 470 | private: |
Alexis Hetu | 7383243 | 2019-04-11 16:43:18 -0400 | [diff] [blame] | 471 | VkStencilFaceFlags faceMask; |
| 472 | uint32_t reference; |
| 473 | }; |
| 474 | |
Ben Clayton | 1e610ee | 2019-12-03 11:48:25 +0000 | [diff] [blame] | 475 | class CmdDrawBase : public vk::CommandBuffer::Command |
Chris Forbes | 00ba176 | 2019-03-08 17:10:41 -0800 | [diff] [blame] | 476 | { |
Ben Clayton | 1e610ee | 2019-12-03 11:48:25 +0000 | [diff] [blame] | 477 | public: |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 478 | int bytesPerIndex(vk::CommandBuffer::ExecutionState const &executionState) |
Alexis Hetu | 072dc0d | 2018-10-31 11:41:25 -0400 | [diff] [blame] | 479 | { |
Chris Forbes | 48b3587 | 2019-03-22 14:12:50 -0700 | [diff] [blame] | 480 | return executionState.indexType == VK_INDEX_TYPE_UINT16 ? 2 : 4; |
Alexis Hetu | 072dc0d | 2018-10-31 11:41:25 -0400 | [diff] [blame] | 481 | } |
| 482 | |
Alexis Hetu | 7fe5a06 | 2019-05-09 15:35:33 -0400 | [diff] [blame] | 483 | template<typename T> |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 484 | void processPrimitiveRestart(T *indexBuffer, |
Alexis Hetu | 7fe5a06 | 2019-05-09 15:35:33 -0400 | [diff] [blame] | 485 | uint32_t count, |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 486 | vk::GraphicsPipeline *pipeline, |
| 487 | std::vector<std::pair<uint32_t, void *>> &indexBuffers) |
Alexis Hetu | 7fe5a06 | 2019-05-09 15:35:33 -0400 | [diff] [blame] | 488 | { |
| 489 | static const T RestartIndex = static_cast<T>(-1); |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 490 | T *indexBufferStart = indexBuffer; |
Alexis Hetu | 7fe5a06 | 2019-05-09 15:35:33 -0400 | [diff] [blame] | 491 | uint32_t vertexCount = 0; |
| 492 | for(uint32_t i = 0; i < count; i++) |
| 493 | { |
| 494 | if(indexBuffer[i] == RestartIndex) |
| 495 | { |
| 496 | // Record previous segment |
| 497 | if(vertexCount > 0) |
| 498 | { |
| 499 | uint32_t primitiveCount = pipeline->computePrimitiveCount(vertexCount); |
| 500 | if(primitiveCount > 0) |
| 501 | { |
| 502 | indexBuffers.push_back({ primitiveCount, indexBufferStart }); |
| 503 | } |
| 504 | } |
| 505 | vertexCount = 0; |
| 506 | } |
| 507 | else |
| 508 | { |
| 509 | if(vertexCount == 0) |
| 510 | { |
| 511 | indexBufferStart = indexBuffer + i; |
| 512 | } |
| 513 | vertexCount++; |
| 514 | } |
| 515 | } |
| 516 | |
| 517 | // Record last segment |
| 518 | if(vertexCount > 0) |
| 519 | { |
| 520 | uint32_t primitiveCount = pipeline->computePrimitiveCount(vertexCount); |
| 521 | if(primitiveCount > 0) |
| 522 | { |
| 523 | indexBuffers.push_back({ primitiveCount, indexBufferStart }); |
| 524 | } |
| 525 | } |
| 526 | } |
| 527 | |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 528 | void draw(vk::CommandBuffer::ExecutionState &executionState, bool indexed, |
| 529 | 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] | 530 | { |
Ben Clayton | 225a130 | 2019-04-02 12:28:22 +0100 | [diff] [blame] | 531 | auto const &pipelineState = executionState.pipelineState[VK_PIPELINE_BIND_POINT_GRAPHICS]; |
| 532 | |
Ben Clayton | 1e610ee | 2019-12-03 11:48:25 +0000 | [diff] [blame] | 533 | auto *pipeline = static_cast<vk::GraphicsPipeline *>(pipelineState.pipeline); |
Chris Forbes | baf7ad3 | 2019-02-25 18:14:42 -0800 | [diff] [blame] | 534 | |
| 535 | sw::Context context = pipeline->getContext(); |
Chris Forbes | e1cf863 | 2019-03-08 18:17:35 -0800 | [diff] [blame] | 536 | |
Alexis Hetu | 90df527 | 2019-11-12 13:44:12 -0500 | [diff] [blame] | 537 | executionState.bindVertexInputs(context, firstInstance); |
Chris Forbes | baf7ad3 | 2019-02-25 18:14:42 -0800 | [diff] [blame] | 538 | |
Alexis Hetu | 4f438a5 | 2020-06-15 16:13:51 -0400 | [diff] [blame] | 539 | context.descriptorSetObjects = pipelineState.descriptorSetObjects; |
Ben Clayton | 225a130 | 2019-04-02 12:28:22 +0100 | [diff] [blame] | 540 | context.descriptorSets = pipelineState.descriptorSets; |
| 541 | context.descriptorDynamicOffsets = pipelineState.descriptorDynamicOffsets; |
Chris Forbes | a30de54 | 2019-03-18 18:51:55 -0700 | [diff] [blame] | 542 | |
Alexis Hetu | 7383243 | 2019-04-11 16:43:18 -0400 | [diff] [blame] | 543 | // Apply either pipeline state or dynamic state |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 544 | executionState.renderer->setScissor(pipeline->hasDynamicState(VK_DYNAMIC_STATE_SCISSOR) ? executionState.dynamicState.scissor : pipeline->getScissor()); |
| 545 | executionState.renderer->setViewport(pipeline->hasDynamicState(VK_DYNAMIC_STATE_VIEWPORT) ? executionState.dynamicState.viewport : pipeline->getViewport()); |
| 546 | executionState.renderer->setBlendConstant(pipeline->hasDynamicState(VK_DYNAMIC_STATE_BLEND_CONSTANTS) ? executionState.dynamicState.blendConstants : pipeline->getBlendConstants()); |
Alexis Hetu | 3084768 | 2019-09-11 17:18:46 -0400 | [diff] [blame] | 547 | |
Nicolas Capens | 81bc9d9 | 2019-12-16 15:05:57 -0500 | [diff] [blame] | 548 | if(pipeline->hasDynamicState(VK_DYNAMIC_STATE_DEPTH_BIAS)) |
Alexis Hetu | 7383243 | 2019-04-11 16:43:18 -0400 | [diff] [blame] | 549 | { |
| 550 | // If the depth bias clamping feature is not enabled, depthBiasClamp must be 0.0 |
| 551 | ASSERT(executionState.dynamicState.depthBiasClamp == 0.0f); |
| 552 | |
| 553 | context.depthBias = executionState.dynamicState.depthBiasConstantFactor; |
| 554 | context.slopeDepthBias = executionState.dynamicState.depthBiasSlopeFactor; |
| 555 | } |
Nicolas Capens | 44bd43a | 2020-01-22 03:07:14 -0500 | [diff] [blame] | 556 | |
Nicolas Capens | 81bc9d9 | 2019-12-16 15:05:57 -0500 | [diff] [blame] | 557 | if(pipeline->hasDynamicState(VK_DYNAMIC_STATE_DEPTH_BOUNDS) && context.depthBoundsTestEnable) |
Alexis Hetu | 7383243 | 2019-04-11 16:43:18 -0400 | [diff] [blame] | 558 | { |
Nicolas Capens | 44bd43a | 2020-01-22 03:07:14 -0500 | [diff] [blame] | 559 | // Unless the VK_EXT_depth_range_unrestricted extension is enabled, minDepthBounds and maxDepthBounds must be between 0.0 and 1.0, inclusive |
Chris Forbes | 02d4c0d | 2019-08-21 12:04:34 -0700 | [diff] [blame] | 560 | ASSERT(executionState.dynamicState.minDepthBounds >= 0.0f && |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 561 | executionState.dynamicState.minDepthBounds <= 1.0f); |
Chris Forbes | 02d4c0d | 2019-08-21 12:04:34 -0700 | [diff] [blame] | 562 | ASSERT(executionState.dynamicState.maxDepthBounds >= 0.0f && |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 563 | executionState.dynamicState.maxDepthBounds <= 1.0f); |
Alexis Hetu | 7383243 | 2019-04-11 16:43:18 -0400 | [diff] [blame] | 564 | |
Nicolas Capens | 44bd43a | 2020-01-22 03:07:14 -0500 | [diff] [blame] | 565 | UNSUPPORTED("VkPhysicalDeviceFeatures::depthBounds"); |
Alexis Hetu | 7383243 | 2019-04-11 16:43:18 -0400 | [diff] [blame] | 566 | } |
Nicolas Capens | 44bd43a | 2020-01-22 03:07:14 -0500 | [diff] [blame] | 567 | |
Nicolas Capens | 81bc9d9 | 2019-12-16 15:05:57 -0500 | [diff] [blame] | 568 | if(pipeline->hasDynamicState(VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK) && context.stencilEnable) |
Alexis Hetu | 7383243 | 2019-04-11 16:43:18 -0400 | [diff] [blame] | 569 | { |
| 570 | context.frontStencil.compareMask = executionState.dynamicState.compareMask[0]; |
| 571 | context.backStencil.compareMask = executionState.dynamicState.compareMask[1]; |
| 572 | } |
Nicolas Capens | 44bd43a | 2020-01-22 03:07:14 -0500 | [diff] [blame] | 573 | |
Nicolas Capens | 81bc9d9 | 2019-12-16 15:05:57 -0500 | [diff] [blame] | 574 | if(pipeline->hasDynamicState(VK_DYNAMIC_STATE_STENCIL_WRITE_MASK) && context.stencilEnable) |
Alexis Hetu | 7383243 | 2019-04-11 16:43:18 -0400 | [diff] [blame] | 575 | { |
| 576 | context.frontStencil.writeMask = executionState.dynamicState.writeMask[0]; |
| 577 | context.backStencil.writeMask = executionState.dynamicState.writeMask[1]; |
| 578 | } |
Nicolas Capens | 44bd43a | 2020-01-22 03:07:14 -0500 | [diff] [blame] | 579 | |
Nicolas Capens | 81bc9d9 | 2019-12-16 15:05:57 -0500 | [diff] [blame] | 580 | if(pipeline->hasDynamicState(VK_DYNAMIC_STATE_STENCIL_REFERENCE) && context.stencilEnable) |
Alexis Hetu | 7383243 | 2019-04-11 16:43:18 -0400 | [diff] [blame] | 581 | { |
| 582 | context.frontStencil.reference = executionState.dynamicState.reference[0]; |
| 583 | context.backStencil.reference = executionState.dynamicState.reference[1]; |
| 584 | } |
| 585 | |
Alexis Hetu | 2e4f6e8 | 2019-05-08 15:52:21 -0400 | [diff] [blame] | 586 | executionState.bindAttachments(context); |
Chris Forbes | baf7ad3 | 2019-02-25 18:14:42 -0800 | [diff] [blame] | 587 | |
Chris Forbes | 0c1adcc | 2019-08-06 11:10:48 -0700 | [diff] [blame] | 588 | context.occlusionEnabled = executionState.renderer->hasOcclusionQuery(); |
Chris Forbes | baf7ad3 | 2019-02-25 18:14:42 -0800 | [diff] [blame] | 589 | |
Chris Forbes | 02d4c0d | 2019-08-21 12:04:34 -0700 | [diff] [blame] | 590 | std::vector<std::pair<uint32_t, void *>> indexBuffers; |
Nicolas Capens | 81bc9d9 | 2019-12-16 15:05:57 -0500 | [diff] [blame] | 591 | if(indexed) |
Alexis Hetu | 7fe5a06 | 2019-05-09 15:35:33 -0400 | [diff] [blame] | 592 | { |
Chris Forbes | 02d4c0d | 2019-08-21 12:04:34 -0700 | [diff] [blame] | 593 | void *indexBuffer = executionState.indexBufferBinding.buffer->getOffsetPointer( |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 594 | executionState.indexBufferBinding.offset + first * bytesPerIndex(executionState)); |
Nicolas Capens | 81bc9d9 | 2019-12-16 15:05:57 -0500 | [diff] [blame] | 595 | if(pipeline->hasPrimitiveRestartEnable()) |
Alexis Hetu | 7fe5a06 | 2019-05-09 15:35:33 -0400 | [diff] [blame] | 596 | { |
Nicolas Capens | 81bc9d9 | 2019-12-16 15:05:57 -0500 | [diff] [blame] | 597 | switch(executionState.indexType) |
Alexis Hetu | 7fe5a06 | 2019-05-09 15:35:33 -0400 | [diff] [blame] | 598 | { |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 599 | case VK_INDEX_TYPE_UINT16: |
| 600 | processPrimitiveRestart(static_cast<uint16_t *>(indexBuffer), count, pipeline, indexBuffers); |
| 601 | break; |
| 602 | case VK_INDEX_TYPE_UINT32: |
| 603 | processPrimitiveRestart(static_cast<uint32_t *>(indexBuffer), count, pipeline, indexBuffers); |
| 604 | break; |
| 605 | default: |
Nicolas Capens | 44bd43a | 2020-01-22 03:07:14 -0500 | [diff] [blame] | 606 | UNSUPPORTED("VkIndexType %d", int(executionState.indexType)); |
Alexis Hetu | 7fe5a06 | 2019-05-09 15:35:33 -0400 | [diff] [blame] | 607 | } |
| 608 | } |
| 609 | else |
| 610 | { |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 611 | indexBuffers.push_back({ pipeline->computePrimitiveCount(count), indexBuffer }); |
Alexis Hetu | 7fe5a06 | 2019-05-09 15:35:33 -0400 | [diff] [blame] | 612 | } |
| 613 | } |
| 614 | else |
| 615 | { |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 616 | indexBuffers.push_back({ pipeline->computePrimitiveCount(count), nullptr }); |
Alexis Hetu | 7fe5a06 | 2019-05-09 15:35:33 -0400 | [diff] [blame] | 617 | } |
| 618 | |
Nicolas Capens | 81bc9d9 | 2019-12-16 15:05:57 -0500 | [diff] [blame] | 619 | for(uint32_t instance = firstInstance; instance != firstInstance + instanceCount; instance++) |
Chris Forbes | baf7ad3 | 2019-02-25 18:14:42 -0800 | [diff] [blame] | 620 | { |
Chris Forbes | 02d4c0d | 2019-08-21 12:04:34 -0700 | [diff] [blame] | 621 | // FIXME: reconsider instances/views nesting. |
Chris Forbes | d6dc4b7 | 2019-08-23 08:23:27 -0700 | [diff] [blame] | 622 | auto viewMask = executionState.renderPass->getViewMask(executionState.subpassIndex); |
Nicolas Capens | 81bc9d9 | 2019-12-16 15:05:57 -0500 | [diff] [blame] | 623 | while(viewMask) |
Alexis Hetu | 7fe5a06 | 2019-05-09 15:35:33 -0400 | [diff] [blame] | 624 | { |
Chris Forbes | a9da772 | 2019-08-26 12:45:13 -0700 | [diff] [blame] | 625 | int viewID = sw::log2i(viewMask); |
| 626 | viewMask &= ~(1 << viewID); |
Chris Forbes | 02d4c0d | 2019-08-21 12:04:34 -0700 | [diff] [blame] | 627 | |
Nicolas Capens | 81bc9d9 | 2019-12-16 15:05:57 -0500 | [diff] [blame] | 628 | for(auto indexBuffer : indexBuffers) |
Chris Forbes | 02d4c0d | 2019-08-21 12:04:34 -0700 | [diff] [blame] | 629 | { |
Chris Forbes | a9da772 | 2019-08-26 12:45:13 -0700 | [diff] [blame] | 630 | executionState.renderer->draw(&context, executionState.indexType, indexBuffer.first, vertexOffset, |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 631 | executionState.events, instance, viewID, indexBuffer.second, |
| 632 | executionState.renderPassFramebuffer->getExtent(), |
| 633 | executionState.pushConstants); |
Chris Forbes | 02d4c0d | 2019-08-21 12:04:34 -0700 | [diff] [blame] | 634 | } |
Alexis Hetu | 7fe5a06 | 2019-05-09 15:35:33 -0400 | [diff] [blame] | 635 | } |
| 636 | |
Alexis Hetu | 2e4f6e8 | 2019-05-08 15:52:21 -0400 | [diff] [blame] | 637 | executionState.renderer->advanceInstanceAttributes(context.input); |
Chris Forbes | baf7ad3 | 2019-02-25 18:14:42 -0800 | [diff] [blame] | 638 | } |
| 639 | } |
Chris Forbes | 48b3587 | 2019-03-22 14:12:50 -0700 | [diff] [blame] | 640 | }; |
| 641 | |
Ben Clayton | 1e610ee | 2019-12-03 11:48:25 +0000 | [diff] [blame] | 642 | class CmdDraw : public CmdDrawBase |
Chris Forbes | 48b3587 | 2019-03-22 14:12:50 -0700 | [diff] [blame] | 643 | { |
Ben Clayton | 1e610ee | 2019-12-03 11:48:25 +0000 | [diff] [blame] | 644 | public: |
| 645 | CmdDraw(uint32_t vertexCount, uint32_t instanceCount, uint32_t firstVertex, uint32_t firstInstance) |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 646 | : vertexCount(vertexCount) |
| 647 | , instanceCount(instanceCount) |
| 648 | , firstVertex(firstVertex) |
| 649 | , firstInstance(firstInstance) |
Chris Forbes | 48b3587 | 2019-03-22 14:12:50 -0700 | [diff] [blame] | 650 | { |
| 651 | } |
| 652 | |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 653 | void play(vk::CommandBuffer::ExecutionState &executionState) override |
Chris Forbes | 48b3587 | 2019-03-22 14:12:50 -0700 | [diff] [blame] | 654 | { |
| 655 | draw(executionState, false, vertexCount, instanceCount, 0, firstVertex, firstInstance); |
| 656 | } |
| 657 | |
Ben Clayton | 72c398f | 2019-12-03 11:53:09 +0000 | [diff] [blame] | 658 | std::string description() override { return "vkCmdDraw()"; } |
| 659 | |
Alexis Hetu | 63ae924 | 2019-06-06 13:52:15 -0400 | [diff] [blame] | 660 | private: |
Chris Forbes | 48b3587 | 2019-03-22 14:12:50 -0700 | [diff] [blame] | 661 | uint32_t vertexCount; |
| 662 | uint32_t instanceCount; |
| 663 | uint32_t firstVertex; |
| 664 | uint32_t firstInstance; |
| 665 | }; |
| 666 | |
Ben Clayton | 1e610ee | 2019-12-03 11:48:25 +0000 | [diff] [blame] | 667 | class CmdDrawIndexed : public CmdDrawBase |
Chris Forbes | 48b3587 | 2019-03-22 14:12:50 -0700 | [diff] [blame] | 668 | { |
Ben Clayton | 1e610ee | 2019-12-03 11:48:25 +0000 | [diff] [blame] | 669 | public: |
| 670 | CmdDrawIndexed(uint32_t indexCount, uint32_t instanceCount, uint32_t firstIndex, int32_t vertexOffset, uint32_t firstInstance) |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 671 | : indexCount(indexCount) |
| 672 | , instanceCount(instanceCount) |
| 673 | , firstIndex(firstIndex) |
| 674 | , vertexOffset(vertexOffset) |
| 675 | , firstInstance(firstInstance) |
Chris Forbes | 48b3587 | 2019-03-22 14:12:50 -0700 | [diff] [blame] | 676 | { |
| 677 | } |
| 678 | |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 679 | void play(vk::CommandBuffer::ExecutionState &executionState) override |
Chris Forbes | 48b3587 | 2019-03-22 14:12:50 -0700 | [diff] [blame] | 680 | { |
| 681 | draw(executionState, true, indexCount, instanceCount, firstIndex, vertexOffset, firstInstance); |
| 682 | } |
Chris Forbes | baf7ad3 | 2019-02-25 18:14:42 -0800 | [diff] [blame] | 683 | |
Ben Clayton | 72c398f | 2019-12-03 11:53:09 +0000 | [diff] [blame] | 684 | std::string description() override { return "vkCmdDrawIndexed()"; } |
| 685 | |
Alexis Hetu | 63ae924 | 2019-06-06 13:52:15 -0400 | [diff] [blame] | 686 | private: |
Chris Forbes | baf7ad3 | 2019-02-25 18:14:42 -0800 | [diff] [blame] | 687 | uint32_t indexCount; |
| 688 | uint32_t instanceCount; |
| 689 | uint32_t firstIndex; |
| 690 | int32_t vertexOffset; |
| 691 | uint32_t firstInstance; |
| 692 | }; |
| 693 | |
Ben Clayton | 1e610ee | 2019-12-03 11:48:25 +0000 | [diff] [blame] | 694 | class CmdDrawIndirect : public CmdDrawBase |
Chris Forbes | 48b3587 | 2019-03-22 14:12:50 -0700 | [diff] [blame] | 695 | { |
Ben Clayton | 1e610ee | 2019-12-03 11:48:25 +0000 | [diff] [blame] | 696 | public: |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 697 | CmdDrawIndirect(vk::Buffer *buffer, VkDeviceSize offset, uint32_t drawCount, uint32_t stride) |
| 698 | : buffer(buffer) |
| 699 | , offset(offset) |
| 700 | , drawCount(drawCount) |
| 701 | , stride(stride) |
Chris Forbes | 48b3587 | 2019-03-22 14:12:50 -0700 | [diff] [blame] | 702 | { |
| 703 | } |
| 704 | |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 705 | void play(vk::CommandBuffer::ExecutionState &executionState) override |
Chris Forbes | 48b3587 | 2019-03-22 14:12:50 -0700 | [diff] [blame] | 706 | { |
Nicolas Capens | 81bc9d9 | 2019-12-16 15:05:57 -0500 | [diff] [blame] | 707 | for(auto drawId = 0u; drawId < drawCount; drawId++) |
Chris Forbes | 48b3587 | 2019-03-22 14:12:50 -0700 | [diff] [blame] | 708 | { |
Alexis Hetu | 63ae924 | 2019-06-06 13:52:15 -0400 | [diff] [blame] | 709 | auto cmd = reinterpret_cast<VkDrawIndirectCommand const *>(buffer->getOffsetPointer(offset + drawId * stride)); |
Chris Forbes | 48b3587 | 2019-03-22 14:12:50 -0700 | [diff] [blame] | 710 | draw(executionState, false, cmd->vertexCount, cmd->instanceCount, 0, cmd->firstVertex, cmd->firstInstance); |
| 711 | } |
| 712 | } |
| 713 | |
Ben Clayton | 72c398f | 2019-12-03 11:53:09 +0000 | [diff] [blame] | 714 | std::string description() override { return "vkCmdDrawIndirect()"; } |
| 715 | |
Alexis Hetu | 63ae924 | 2019-06-06 13:52:15 -0400 | [diff] [blame] | 716 | private: |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 717 | const vk::Buffer *buffer; |
Chris Forbes | 48b3587 | 2019-03-22 14:12:50 -0700 | [diff] [blame] | 718 | VkDeviceSize offset; |
| 719 | uint32_t drawCount; |
| 720 | uint32_t stride; |
| 721 | }; |
| 722 | |
Ben Clayton | 1e610ee | 2019-12-03 11:48:25 +0000 | [diff] [blame] | 723 | class CmdDrawIndexedIndirect : public CmdDrawBase |
Chris Forbes | 48b3587 | 2019-03-22 14:12:50 -0700 | [diff] [blame] | 724 | { |
Ben Clayton | 1e610ee | 2019-12-03 11:48:25 +0000 | [diff] [blame] | 725 | public: |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 726 | CmdDrawIndexedIndirect(vk::Buffer *buffer, VkDeviceSize offset, uint32_t drawCount, uint32_t stride) |
| 727 | : buffer(buffer) |
| 728 | , offset(offset) |
| 729 | , drawCount(drawCount) |
| 730 | , stride(stride) |
Chris Forbes | 48b3587 | 2019-03-22 14:12:50 -0700 | [diff] [blame] | 731 | { |
| 732 | } |
| 733 | |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 734 | void play(vk::CommandBuffer::ExecutionState &executionState) override |
Chris Forbes | 48b3587 | 2019-03-22 14:12:50 -0700 | [diff] [blame] | 735 | { |
Nicolas Capens | 81bc9d9 | 2019-12-16 15:05:57 -0500 | [diff] [blame] | 736 | for(auto drawId = 0u; drawId < drawCount; drawId++) |
Chris Forbes | 48b3587 | 2019-03-22 14:12:50 -0700 | [diff] [blame] | 737 | { |
Alexis Hetu | 63ae924 | 2019-06-06 13:52:15 -0400 | [diff] [blame] | 738 | auto cmd = reinterpret_cast<VkDrawIndexedIndirectCommand const *>(buffer->getOffsetPointer(offset + drawId * stride)); |
Chris Forbes | 48b3587 | 2019-03-22 14:12:50 -0700 | [diff] [blame] | 739 | draw(executionState, true, cmd->indexCount, cmd->instanceCount, cmd->firstIndex, cmd->vertexOffset, cmd->firstInstance); |
| 740 | } |
| 741 | } |
| 742 | |
Ben Clayton | 72c398f | 2019-12-03 11:53:09 +0000 | [diff] [blame] | 743 | std::string description() override { return "vkCmdDrawIndexedIndirect()"; } |
| 744 | |
Alexis Hetu | 63ae924 | 2019-06-06 13:52:15 -0400 | [diff] [blame] | 745 | private: |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 746 | const vk::Buffer *buffer; |
Chris Forbes | 48b3587 | 2019-03-22 14:12:50 -0700 | [diff] [blame] | 747 | VkDeviceSize offset; |
| 748 | uint32_t drawCount; |
| 749 | uint32_t stride; |
| 750 | }; |
| 751 | |
Nicolas Capens | be1a9ac | 2020-07-09 14:50:52 -0400 | [diff] [blame] | 752 | class CmdCopyImage : public vk::CommandBuffer::Command |
Alexis Hetu | 09056de | 2018-12-07 12:40:00 -0500 | [diff] [blame] | 753 | { |
Ben Clayton | 1e610ee | 2019-12-03 11:48:25 +0000 | [diff] [blame] | 754 | public: |
Nicolas Capens | be1a9ac | 2020-07-09 14:50:52 -0400 | [diff] [blame] | 755 | CmdCopyImage(const vk::Image *srcImage, vk::Image *dstImage, const VkImageCopy ®ion) |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 756 | : srcImage(srcImage) |
| 757 | , dstImage(dstImage) |
| 758 | , region(region) |
Alexis Hetu | 09056de | 2018-12-07 12:40:00 -0500 | [diff] [blame] | 759 | { |
| 760 | } |
| 761 | |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 762 | void play(vk::CommandBuffer::ExecutionState &executionState) override |
Alexis Hetu | 09056de | 2018-12-07 12:40:00 -0500 | [diff] [blame] | 763 | { |
Alexis Hetu | 63ae924 | 2019-06-06 13:52:15 -0400 | [diff] [blame] | 764 | srcImage->copyTo(dstImage, region); |
Alexis Hetu | 09056de | 2018-12-07 12:40:00 -0500 | [diff] [blame] | 765 | } |
| 766 | |
Nicolas Capens | be1a9ac | 2020-07-09 14:50:52 -0400 | [diff] [blame] | 767 | std::string description() override { return "vkCmdCopyImage()"; } |
Ben Clayton | 72c398f | 2019-12-03 11:53:09 +0000 | [diff] [blame] | 768 | |
Alexis Hetu | 09056de | 2018-12-07 12:40:00 -0500 | [diff] [blame] | 769 | private: |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 770 | const vk::Image *srcImage; |
| 771 | vk::Image *dstImage; |
Alexis Hetu | 09056de | 2018-12-07 12:40:00 -0500 | [diff] [blame] | 772 | const VkImageCopy region; |
| 773 | }; |
| 774 | |
Nicolas Capens | be1a9ac | 2020-07-09 14:50:52 -0400 | [diff] [blame] | 775 | class CmdCopyBuffer : public vk::CommandBuffer::Command |
Alexis Hetu | bb0a7f0 | 2018-12-14 16:50:43 -0500 | [diff] [blame] | 776 | { |
Ben Clayton | 1e610ee | 2019-12-03 11:48:25 +0000 | [diff] [blame] | 777 | public: |
Nicolas Capens | be1a9ac | 2020-07-09 14:50:52 -0400 | [diff] [blame] | 778 | CmdCopyBuffer(const vk::Buffer *srcBuffer, vk::Buffer *dstBuffer, const VkBufferCopy ®ion) |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 779 | : srcBuffer(srcBuffer) |
| 780 | , dstBuffer(dstBuffer) |
| 781 | , region(region) |
Alexis Hetu | bb0a7f0 | 2018-12-14 16:50:43 -0500 | [diff] [blame] | 782 | { |
| 783 | } |
| 784 | |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 785 | void play(vk::CommandBuffer::ExecutionState &executionState) override |
Alexis Hetu | bb0a7f0 | 2018-12-14 16:50:43 -0500 | [diff] [blame] | 786 | { |
Alexis Hetu | 63ae924 | 2019-06-06 13:52:15 -0400 | [diff] [blame] | 787 | srcBuffer->copyTo(dstBuffer, region); |
Alexis Hetu | bb0a7f0 | 2018-12-14 16:50:43 -0500 | [diff] [blame] | 788 | } |
| 789 | |
Nicolas Capens | be1a9ac | 2020-07-09 14:50:52 -0400 | [diff] [blame] | 790 | std::string description() override { return "vkCmdCopyBuffer()"; } |
Ben Clayton | 72c398f | 2019-12-03 11:53:09 +0000 | [diff] [blame] | 791 | |
Alexis Hetu | bb0a7f0 | 2018-12-14 16:50:43 -0500 | [diff] [blame] | 792 | private: |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 793 | const vk::Buffer *srcBuffer; |
| 794 | vk::Buffer *dstBuffer; |
Alexis Hetu | bb0a7f0 | 2018-12-14 16:50:43 -0500 | [diff] [blame] | 795 | const VkBufferCopy region; |
| 796 | }; |
| 797 | |
Nicolas Capens | be1a9ac | 2020-07-09 14:50:52 -0400 | [diff] [blame] | 798 | class CmdCopyImageToBuffer : public vk::CommandBuffer::Command |
Alexis Hetu | 072dc0d | 2018-10-31 11:41:25 -0400 | [diff] [blame] | 799 | { |
Ben Clayton | 1e610ee | 2019-12-03 11:48:25 +0000 | [diff] [blame] | 800 | public: |
Nicolas Capens | be1a9ac | 2020-07-09 14:50:52 -0400 | [diff] [blame] | 801 | CmdCopyImageToBuffer(vk::Image *srcImage, vk::Buffer *dstBuffer, const VkBufferImageCopy ®ion) |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 802 | : srcImage(srcImage) |
| 803 | , dstBuffer(dstBuffer) |
| 804 | , region(region) |
Alexis Hetu | 072dc0d | 2018-10-31 11:41:25 -0400 | [diff] [blame] | 805 | { |
| 806 | } |
| 807 | |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 808 | void play(vk::CommandBuffer::ExecutionState &executionState) override |
Alexis Hetu | 072dc0d | 2018-10-31 11:41:25 -0400 | [diff] [blame] | 809 | { |
Alexis Hetu | 63ae924 | 2019-06-06 13:52:15 -0400 | [diff] [blame] | 810 | srcImage->copyTo(dstBuffer, region); |
Alexis Hetu | 072dc0d | 2018-10-31 11:41:25 -0400 | [diff] [blame] | 811 | } |
| 812 | |
Nicolas Capens | be1a9ac | 2020-07-09 14:50:52 -0400 | [diff] [blame] | 813 | std::string description() override { return "vkCmdCopyImageToBuffer()"; } |
Ben Clayton | 72c398f | 2019-12-03 11:53:09 +0000 | [diff] [blame] | 814 | |
Alexis Hetu | 072dc0d | 2018-10-31 11:41:25 -0400 | [diff] [blame] | 815 | private: |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 816 | vk::Image *srcImage; |
| 817 | vk::Buffer *dstBuffer; |
Alexis Hetu | 072dc0d | 2018-10-31 11:41:25 -0400 | [diff] [blame] | 818 | const VkBufferImageCopy region; |
| 819 | }; |
| 820 | |
Nicolas Capens | be1a9ac | 2020-07-09 14:50:52 -0400 | [diff] [blame] | 821 | class CmdCopyBufferToImage : public vk::CommandBuffer::Command |
Alexis Hetu | 09056de | 2018-12-07 12:40:00 -0500 | [diff] [blame] | 822 | { |
Ben Clayton | 1e610ee | 2019-12-03 11:48:25 +0000 | [diff] [blame] | 823 | public: |
Nicolas Capens | be1a9ac | 2020-07-09 14:50:52 -0400 | [diff] [blame] | 824 | CmdCopyBufferToImage(vk::Buffer *srcBuffer, vk::Image *dstImage, const VkBufferImageCopy ®ion) |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 825 | : srcBuffer(srcBuffer) |
| 826 | , dstImage(dstImage) |
| 827 | , region(region) |
Alexis Hetu | 09056de | 2018-12-07 12:40:00 -0500 | [diff] [blame] | 828 | { |
| 829 | } |
| 830 | |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 831 | void play(vk::CommandBuffer::ExecutionState &executionState) override |
Alexis Hetu | 09056de | 2018-12-07 12:40:00 -0500 | [diff] [blame] | 832 | { |
Alexis Hetu | 63ae924 | 2019-06-06 13:52:15 -0400 | [diff] [blame] | 833 | dstImage->copyFrom(srcBuffer, region); |
Alexis Hetu | 09056de | 2018-12-07 12:40:00 -0500 | [diff] [blame] | 834 | } |
| 835 | |
Nicolas Capens | be1a9ac | 2020-07-09 14:50:52 -0400 | [diff] [blame] | 836 | std::string description() override { return "vkCmdCopyBufferToImage()"; } |
Ben Clayton | 72c398f | 2019-12-03 11:53:09 +0000 | [diff] [blame] | 837 | |
Alexis Hetu | 09056de | 2018-12-07 12:40:00 -0500 | [diff] [blame] | 838 | private: |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 839 | vk::Buffer *srcBuffer; |
| 840 | vk::Image *dstImage; |
Alexis Hetu | 09056de | 2018-12-07 12:40:00 -0500 | [diff] [blame] | 841 | const VkBufferImageCopy region; |
| 842 | }; |
| 843 | |
Ben Clayton | 1e610ee | 2019-12-03 11:48:25 +0000 | [diff] [blame] | 844 | class CmdFillBuffer : public vk::CommandBuffer::Command |
Alexis Hetu | 7fb0b73 | 2019-02-07 13:50:10 -0500 | [diff] [blame] | 845 | { |
Ben Clayton | 1e610ee | 2019-12-03 11:48:25 +0000 | [diff] [blame] | 846 | public: |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 847 | CmdFillBuffer(vk::Buffer *dstBuffer, VkDeviceSize dstOffset, VkDeviceSize size, uint32_t data) |
| 848 | : dstBuffer(dstBuffer) |
| 849 | , dstOffset(dstOffset) |
| 850 | , size(size) |
| 851 | , data(data) |
Alexis Hetu | 7fb0b73 | 2019-02-07 13:50:10 -0500 | [diff] [blame] | 852 | { |
| 853 | } |
| 854 | |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 855 | void play(vk::CommandBuffer::ExecutionState &executionState) override |
Alexis Hetu | 7fb0b73 | 2019-02-07 13:50:10 -0500 | [diff] [blame] | 856 | { |
Alexis Hetu | 63ae924 | 2019-06-06 13:52:15 -0400 | [diff] [blame] | 857 | dstBuffer->fill(dstOffset, size, data); |
Alexis Hetu | 7fb0b73 | 2019-02-07 13:50:10 -0500 | [diff] [blame] | 858 | } |
| 859 | |
Ben Clayton | 72c398f | 2019-12-03 11:53:09 +0000 | [diff] [blame] | 860 | std::string description() override { return "vkCmdFillBuffer()"; } |
| 861 | |
Alexis Hetu | 7fb0b73 | 2019-02-07 13:50:10 -0500 | [diff] [blame] | 862 | private: |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 863 | vk::Buffer *dstBuffer; |
Alexis Hetu | 7fb0b73 | 2019-02-07 13:50:10 -0500 | [diff] [blame] | 864 | VkDeviceSize dstOffset; |
| 865 | VkDeviceSize size; |
| 866 | uint32_t data; |
| 867 | }; |
| 868 | |
Ben Clayton | 1e610ee | 2019-12-03 11:48:25 +0000 | [diff] [blame] | 869 | class CmdUpdateBuffer : public vk::CommandBuffer::Command |
Alexis Hetu | 7fb0b73 | 2019-02-07 13:50:10 -0500 | [diff] [blame] | 870 | { |
Ben Clayton | 1e610ee | 2019-12-03 11:48:25 +0000 | [diff] [blame] | 871 | public: |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 872 | CmdUpdateBuffer(vk::Buffer *dstBuffer, VkDeviceSize dstOffset, VkDeviceSize dataSize, const uint8_t *pData) |
| 873 | : dstBuffer(dstBuffer) |
| 874 | , dstOffset(dstOffset) |
| 875 | , data(pData, &pData[dataSize]) |
Alexis Hetu | 7fb0b73 | 2019-02-07 13:50:10 -0500 | [diff] [blame] | 876 | { |
| 877 | } |
| 878 | |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 879 | void play(vk::CommandBuffer::ExecutionState &executionState) override |
Alexis Hetu | 7fb0b73 | 2019-02-07 13:50:10 -0500 | [diff] [blame] | 880 | { |
Alexis Hetu | 63ae924 | 2019-06-06 13:52:15 -0400 | [diff] [blame] | 881 | dstBuffer->update(dstOffset, data.size(), data.data()); |
Alexis Hetu | 7fb0b73 | 2019-02-07 13:50:10 -0500 | [diff] [blame] | 882 | } |
| 883 | |
Ben Clayton | 72c398f | 2019-12-03 11:53:09 +0000 | [diff] [blame] | 884 | std::string description() override { return "vkCmdUpdateBuffer()"; } |
| 885 | |
Alexis Hetu | 7fb0b73 | 2019-02-07 13:50:10 -0500 | [diff] [blame] | 886 | private: |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 887 | vk::Buffer *dstBuffer; |
Alexis Hetu | 7fb0b73 | 2019-02-07 13:50:10 -0500 | [diff] [blame] | 888 | VkDeviceSize dstOffset; |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 889 | std::vector<uint8_t> data; // FIXME (b/119409619): replace this vector by an allocator so we can control all memory allocations |
Alexis Hetu | 7fb0b73 | 2019-02-07 13:50:10 -0500 | [diff] [blame] | 890 | }; |
| 891 | |
Ben Clayton | 1e610ee | 2019-12-03 11:48:25 +0000 | [diff] [blame] | 892 | class CmdClearColorImage : public vk::CommandBuffer::Command |
Alexis Hetu | f14ed32 | 2019-01-16 15:54:55 -0500 | [diff] [blame] | 893 | { |
Ben Clayton | 1e610ee | 2019-12-03 11:48:25 +0000 | [diff] [blame] | 894 | public: |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 895 | CmdClearColorImage(vk::Image *image, const VkClearColorValue &color, const VkImageSubresourceRange &range) |
| 896 | : image(image) |
| 897 | , color(color) |
| 898 | , range(range) |
Alexis Hetu | f14ed32 | 2019-01-16 15:54:55 -0500 | [diff] [blame] | 899 | { |
| 900 | } |
| 901 | |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 902 | void play(vk::CommandBuffer::ExecutionState &executionState) override |
Alexis Hetu | f14ed32 | 2019-01-16 15:54:55 -0500 | [diff] [blame] | 903 | { |
Alexis Hetu | 63ae924 | 2019-06-06 13:52:15 -0400 | [diff] [blame] | 904 | image->clear(color, range); |
Alexis Hetu | f14ed32 | 2019-01-16 15:54:55 -0500 | [diff] [blame] | 905 | } |
| 906 | |
Ben Clayton | 72c398f | 2019-12-03 11:53:09 +0000 | [diff] [blame] | 907 | std::string description() override { return "vkCmdClearColorImage()"; } |
| 908 | |
Alexis Hetu | f14ed32 | 2019-01-16 15:54:55 -0500 | [diff] [blame] | 909 | private: |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 910 | vk::Image *image; |
Alexis Hetu | f14ed32 | 2019-01-16 15:54:55 -0500 | [diff] [blame] | 911 | const VkClearColorValue color; |
| 912 | const VkImageSubresourceRange range; |
| 913 | }; |
| 914 | |
Ben Clayton | 1e610ee | 2019-12-03 11:48:25 +0000 | [diff] [blame] | 915 | class CmdClearDepthStencilImage : public vk::CommandBuffer::Command |
Alexis Hetu | 7ca9f4a | 2019-01-17 14:51:43 -0500 | [diff] [blame] | 916 | { |
Ben Clayton | 1e610ee | 2019-12-03 11:48:25 +0000 | [diff] [blame] | 917 | public: |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 918 | CmdClearDepthStencilImage(vk::Image *image, const VkClearDepthStencilValue &depthStencil, const VkImageSubresourceRange &range) |
| 919 | : image(image) |
| 920 | , depthStencil(depthStencil) |
| 921 | , range(range) |
Alexis Hetu | 7ca9f4a | 2019-01-17 14:51:43 -0500 | [diff] [blame] | 922 | { |
| 923 | } |
| 924 | |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 925 | void play(vk::CommandBuffer::ExecutionState &executionState) override |
Alexis Hetu | 7ca9f4a | 2019-01-17 14:51:43 -0500 | [diff] [blame] | 926 | { |
Alexis Hetu | 63ae924 | 2019-06-06 13:52:15 -0400 | [diff] [blame] | 927 | image->clear(depthStencil, range); |
Alexis Hetu | 7ca9f4a | 2019-01-17 14:51:43 -0500 | [diff] [blame] | 928 | } |
| 929 | |
Ben Clayton | 72c398f | 2019-12-03 11:53:09 +0000 | [diff] [blame] | 930 | std::string description() override { return "vkCmdClearDepthStencilImage()"; } |
| 931 | |
Alexis Hetu | 7ca9f4a | 2019-01-17 14:51:43 -0500 | [diff] [blame] | 932 | private: |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 933 | vk::Image *image; |
Alexis Hetu | 7ca9f4a | 2019-01-17 14:51:43 -0500 | [diff] [blame] | 934 | const VkClearDepthStencilValue depthStencil; |
| 935 | const VkImageSubresourceRange range; |
| 936 | }; |
| 937 | |
Ben Clayton | 1e610ee | 2019-12-03 11:48:25 +0000 | [diff] [blame] | 938 | class CmdClearAttachment : public vk::CommandBuffer::Command |
Alexis Hetu | 1cd31ea | 2019-01-17 17:14:57 -0500 | [diff] [blame] | 939 | { |
Ben Clayton | 1e610ee | 2019-12-03 11:48:25 +0000 | [diff] [blame] | 940 | public: |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 941 | CmdClearAttachment(const VkClearAttachment &attachment, const VkClearRect &rect) |
| 942 | : attachment(attachment) |
| 943 | , rect(rect) |
Alexis Hetu | 1cd31ea | 2019-01-17 17:14:57 -0500 | [diff] [blame] | 944 | { |
| 945 | } |
| 946 | |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 947 | void play(vk::CommandBuffer::ExecutionState &executionState) override |
Alexis Hetu | 1cd31ea | 2019-01-17 17:14:57 -0500 | [diff] [blame] | 948 | { |
Chris Forbes | ed46cde | 2019-04-22 12:49:21 -0700 | [diff] [blame] | 949 | // attachment clears are drawing operations, and so have rasterization-order guarantees. |
| 950 | // however, we don't do the clear through the rasterizer, so need to ensure prior drawing |
| 951 | // has completed first. |
| 952 | executionState.renderer->synchronize(); |
Chris Forbes | d6dc4b7 | 2019-08-23 08:23:27 -0700 | [diff] [blame] | 953 | executionState.renderPassFramebuffer->clearAttachment(executionState.renderPass, executionState.subpassIndex, attachment, rect); |
Alexis Hetu | 1cd31ea | 2019-01-17 17:14:57 -0500 | [diff] [blame] | 954 | } |
| 955 | |
Ben Clayton | 72c398f | 2019-12-03 11:53:09 +0000 | [diff] [blame] | 956 | std::string description() override { return "vkCmdClearAttachment()"; } |
| 957 | |
Alexis Hetu | 1cd31ea | 2019-01-17 17:14:57 -0500 | [diff] [blame] | 958 | private: |
| 959 | const VkClearAttachment attachment; |
| 960 | const VkClearRect rect; |
| 961 | }; |
| 962 | |
Ben Clayton | 1e610ee | 2019-12-03 11:48:25 +0000 | [diff] [blame] | 963 | class CmdBlitImage : public vk::CommandBuffer::Command |
Alexis Hetu | 809d011 | 2018-12-17 17:00:28 -0500 | [diff] [blame] | 964 | { |
Ben Clayton | 1e610ee | 2019-12-03 11:48:25 +0000 | [diff] [blame] | 965 | public: |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 966 | CmdBlitImage(const vk::Image *srcImage, vk::Image *dstImage, const VkImageBlit ®ion, VkFilter filter) |
| 967 | : srcImage(srcImage) |
| 968 | , dstImage(dstImage) |
| 969 | , region(region) |
| 970 | , filter(filter) |
Alexis Hetu | 809d011 | 2018-12-17 17:00:28 -0500 | [diff] [blame] | 971 | { |
| 972 | } |
| 973 | |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 974 | void play(vk::CommandBuffer::ExecutionState &executionState) override |
Alexis Hetu | 809d011 | 2018-12-17 17:00:28 -0500 | [diff] [blame] | 975 | { |
Nicolas Capens | 32f4be1 | 2020-06-10 13:14:07 -0400 | [diff] [blame] | 976 | srcImage->blitTo(dstImage, region, filter); |
Alexis Hetu | 809d011 | 2018-12-17 17:00:28 -0500 | [diff] [blame] | 977 | } |
| 978 | |
Ben Clayton | 72c398f | 2019-12-03 11:53:09 +0000 | [diff] [blame] | 979 | std::string description() override { return "vkCmdBlitImage()"; } |
| 980 | |
Alexis Hetu | 809d011 | 2018-12-17 17:00:28 -0500 | [diff] [blame] | 981 | private: |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 982 | const vk::Image *srcImage; |
| 983 | vk::Image *dstImage; |
Ben Clayton | 24021a2 | 2019-02-19 11:42:31 +0000 | [diff] [blame] | 984 | VkImageBlit region; |
Alexis Hetu | 809d011 | 2018-12-17 17:00:28 -0500 | [diff] [blame] | 985 | VkFilter filter; |
| 986 | }; |
| 987 | |
Ben Clayton | 1e610ee | 2019-12-03 11:48:25 +0000 | [diff] [blame] | 988 | class CmdResolveImage : public vk::CommandBuffer::Command |
Alexis Hetu | e5e33cd | 2019-04-11 10:24:52 -0400 | [diff] [blame] | 989 | { |
Ben Clayton | 1e610ee | 2019-12-03 11:48:25 +0000 | [diff] [blame] | 990 | public: |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 991 | CmdResolveImage(const vk::Image *srcImage, vk::Image *dstImage, const VkImageResolve ®ion) |
| 992 | : srcImage(srcImage) |
| 993 | , dstImage(dstImage) |
| 994 | , region(region) |
Alexis Hetu | e5e33cd | 2019-04-11 10:24:52 -0400 | [diff] [blame] | 995 | { |
| 996 | } |
| 997 | |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 998 | void play(vk::CommandBuffer::ExecutionState &executionState) override |
Alexis Hetu | e5e33cd | 2019-04-11 10:24:52 -0400 | [diff] [blame] | 999 | { |
Nicolas Capens | 32f4be1 | 2020-06-10 13:14:07 -0400 | [diff] [blame] | 1000 | srcImage->resolveTo(dstImage, region); |
Alexis Hetu | e5e33cd | 2019-04-11 10:24:52 -0400 | [diff] [blame] | 1001 | } |
| 1002 | |
Ben Clayton | 72c398f | 2019-12-03 11:53:09 +0000 | [diff] [blame] | 1003 | std::string description() override { return "vkCmdBlitImage()"; } |
| 1004 | |
Alexis Hetu | e5e33cd | 2019-04-11 10:24:52 -0400 | [diff] [blame] | 1005 | private: |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 1006 | const vk::Image *srcImage; |
| 1007 | vk::Image *dstImage; |
Alexis Hetu | e5e33cd | 2019-04-11 10:24:52 -0400 | [diff] [blame] | 1008 | VkImageResolve region; |
| 1009 | }; |
| 1010 | |
Ben Clayton | 1e610ee | 2019-12-03 11:48:25 +0000 | [diff] [blame] | 1011 | class CmdPipelineBarrier : public vk::CommandBuffer::Command |
Alexis Hetu | 9a6c28b | 2018-11-20 11:47:18 -0500 | [diff] [blame] | 1012 | { |
Ben Clayton | 1e610ee | 2019-12-03 11:48:25 +0000 | [diff] [blame] | 1013 | public: |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 1014 | void play(vk::CommandBuffer::ExecutionState &executionState) override |
Alexis Hetu | 9a6c28b | 2018-11-20 11:47:18 -0500 | [diff] [blame] | 1015 | { |
Alexis Hetu | ead1a34 | 2019-02-26 17:03:00 -0500 | [diff] [blame] | 1016 | // This is a very simple implementation that simply calls sw::Renderer::synchronize(), |
| 1017 | // since the driver is free to move the source stage towards the bottom of the pipe |
| 1018 | // and the target stage towards the top, so a full pipeline sync is spec compliant. |
| 1019 | executionState.renderer->synchronize(); |
Alexis Hetu | 9a6c28b | 2018-11-20 11:47:18 -0500 | [diff] [blame] | 1020 | |
| 1021 | // Right now all buffers are read-only in drawcalls but a similar mechanism will be required once we support SSBOs. |
| 1022 | |
| 1023 | // Also note that this would be a good moment to update cube map borders or decompress compressed textures, if necessary. |
| 1024 | } |
Ben Clayton | 72c398f | 2019-12-03 11:53:09 +0000 | [diff] [blame] | 1025 | |
| 1026 | std::string description() override { return "vkCmdPipelineBarrier()"; } |
Alexis Hetu | 9a6c28b | 2018-11-20 11:47:18 -0500 | [diff] [blame] | 1027 | }; |
| 1028 | |
Ben Clayton | 1e610ee | 2019-12-03 11:48:25 +0000 | [diff] [blame] | 1029 | class CmdSignalEvent : public vk::CommandBuffer::Command |
Alexis Hetu | 3f5a479 | 2019-02-01 17:49:55 -0500 | [diff] [blame] | 1030 | { |
Ben Clayton | 1e610ee | 2019-12-03 11:48:25 +0000 | [diff] [blame] | 1031 | public: |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 1032 | CmdSignalEvent(vk::Event *ev, VkPipelineStageFlags stageMask) |
| 1033 | : ev(ev) |
| 1034 | , stageMask(stageMask) |
Alexis Hetu | 3f5a479 | 2019-02-01 17:49:55 -0500 | [diff] [blame] | 1035 | { |
| 1036 | } |
| 1037 | |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 1038 | void play(vk::CommandBuffer::ExecutionState &executionState) override |
Alexis Hetu | 3f5a479 | 2019-02-01 17:49:55 -0500 | [diff] [blame] | 1039 | { |
Alexis Hetu | e1f51b9 | 2019-04-23 15:34:34 -0400 | [diff] [blame] | 1040 | executionState.renderer->synchronize(); |
Alexis Hetu | 63ae924 | 2019-06-06 13:52:15 -0400 | [diff] [blame] | 1041 | ev->signal(); |
Alexis Hetu | 3f5a479 | 2019-02-01 17:49:55 -0500 | [diff] [blame] | 1042 | } |
| 1043 | |
Ben Clayton | 72c398f | 2019-12-03 11:53:09 +0000 | [diff] [blame] | 1044 | std::string description() override { return "vkCmdSignalEvent()"; } |
| 1045 | |
Alexis Hetu | 3f5a479 | 2019-02-01 17:49:55 -0500 | [diff] [blame] | 1046 | private: |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 1047 | vk::Event *ev; |
| 1048 | VkPipelineStageFlags stageMask; // FIXME(b/117835459) : We currently ignore the flags and signal the event at the last stage |
Alexis Hetu | 3f5a479 | 2019-02-01 17:49:55 -0500 | [diff] [blame] | 1049 | }; |
| 1050 | |
Ben Clayton | 1e610ee | 2019-12-03 11:48:25 +0000 | [diff] [blame] | 1051 | class CmdResetEvent : public vk::CommandBuffer::Command |
Alexis Hetu | 3f5a479 | 2019-02-01 17:49:55 -0500 | [diff] [blame] | 1052 | { |
Ben Clayton | 1e610ee | 2019-12-03 11:48:25 +0000 | [diff] [blame] | 1053 | public: |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 1054 | CmdResetEvent(vk::Event *ev, VkPipelineStageFlags stageMask) |
| 1055 | : ev(ev) |
| 1056 | , stageMask(stageMask) |
Alexis Hetu | 3f5a479 | 2019-02-01 17:49:55 -0500 | [diff] [blame] | 1057 | { |
| 1058 | } |
| 1059 | |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 1060 | void play(vk::CommandBuffer::ExecutionState &executionState) override |
Alexis Hetu | 3f5a479 | 2019-02-01 17:49:55 -0500 | [diff] [blame] | 1061 | { |
Alexis Hetu | 63ae924 | 2019-06-06 13:52:15 -0400 | [diff] [blame] | 1062 | ev->reset(); |
Alexis Hetu | 3f5a479 | 2019-02-01 17:49:55 -0500 | [diff] [blame] | 1063 | } |
| 1064 | |
Ben Clayton | 72c398f | 2019-12-03 11:53:09 +0000 | [diff] [blame] | 1065 | std::string description() override { return "vkCmdResetEvent()"; } |
| 1066 | |
Alexis Hetu | 3f5a479 | 2019-02-01 17:49:55 -0500 | [diff] [blame] | 1067 | private: |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 1068 | vk::Event *ev; |
| 1069 | VkPipelineStageFlags stageMask; // FIXME(b/117835459) : We currently ignore the flags and reset the event at the last stage |
Alexis Hetu | 3f5a479 | 2019-02-01 17:49:55 -0500 | [diff] [blame] | 1070 | }; |
| 1071 | |
Ben Clayton | 1e610ee | 2019-12-03 11:48:25 +0000 | [diff] [blame] | 1072 | class CmdWaitEvent : public vk::CommandBuffer::Command |
Alexis Hetu | 9041bb7 | 2019-03-15 14:45:45 -0400 | [diff] [blame] | 1073 | { |
Ben Clayton | 1e610ee | 2019-12-03 11:48:25 +0000 | [diff] [blame] | 1074 | public: |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 1075 | CmdWaitEvent(vk::Event *ev) |
| 1076 | : ev(ev) |
Alexis Hetu | 9041bb7 | 2019-03-15 14:45:45 -0400 | [diff] [blame] | 1077 | { |
| 1078 | } |
| 1079 | |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 1080 | void play(vk::CommandBuffer::ExecutionState &executionState) override |
Alexis Hetu | 9041bb7 | 2019-03-15 14:45:45 -0400 | [diff] [blame] | 1081 | { |
Alexis Hetu | e1f51b9 | 2019-04-23 15:34:34 -0400 | [diff] [blame] | 1082 | executionState.renderer->synchronize(); |
Alexis Hetu | 63ae924 | 2019-06-06 13:52:15 -0400 | [diff] [blame] | 1083 | ev->wait(); |
Alexis Hetu | 9041bb7 | 2019-03-15 14:45:45 -0400 | [diff] [blame] | 1084 | } |
| 1085 | |
Ben Clayton | 72c398f | 2019-12-03 11:53:09 +0000 | [diff] [blame] | 1086 | std::string description() override { return "vkCmdWaitEvent()"; } |
| 1087 | |
Alexis Hetu | 9041bb7 | 2019-03-15 14:45:45 -0400 | [diff] [blame] | 1088 | private: |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 1089 | vk::Event *ev; |
Alexis Hetu | 9041bb7 | 2019-03-15 14:45:45 -0400 | [diff] [blame] | 1090 | }; |
| 1091 | |
Nicolas Capens | 002b7c1 | 2020-04-24 01:05:57 -0400 | [diff] [blame] | 1092 | class CmdBindDescriptorSets : public vk::CommandBuffer::Command |
Alexis Hetu | 5edafb5 | 2019-02-15 14:56:22 -0500 | [diff] [blame] | 1093 | { |
Ben Clayton | 1e610ee | 2019-12-03 11:48:25 +0000 | [diff] [blame] | 1094 | public: |
Nicolas Capens | 002b7c1 | 2020-04-24 01:05:57 -0400 | [diff] [blame] | 1095 | CmdBindDescriptorSets(VkPipelineBindPoint pipelineBindPoint, |
| 1096 | uint32_t firstSet, uint32_t descriptorSetCount, const VkDescriptorSet *pDescriptorSets, |
| 1097 | uint32_t firstDynamicOffset, uint32_t dynamicOffsetCount, const uint32_t *pDynamicOffsets) |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 1098 | : pipelineBindPoint(pipelineBindPoint) |
Nicolas Capens | 002b7c1 | 2020-04-24 01:05:57 -0400 | [diff] [blame] | 1099 | , firstSet(firstSet) |
| 1100 | , descriptorSetCount(descriptorSetCount) |
| 1101 | , firstDynamicOffset(firstDynamicOffset) |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 1102 | , dynamicOffsetCount(dynamicOffsetCount) |
Alexis Hetu | 5edafb5 | 2019-02-15 14:56:22 -0500 | [diff] [blame] | 1103 | { |
Nicolas Capens | 002b7c1 | 2020-04-24 01:05:57 -0400 | [diff] [blame] | 1104 | for(uint32_t i = 0; i < descriptorSetCount; i++) |
| 1105 | { |
Alexis Hetu | 4f438a5 | 2020-06-15 16:13:51 -0400 | [diff] [blame] | 1106 | // We need both a descriptor set object for updates and a descriptor set data pointer for routines |
| 1107 | descriptorSetObjects[firstSet + i] = vk::Cast(pDescriptorSets[i]); |
Nicolas Capens | 002b7c1 | 2020-04-24 01:05:57 -0400 | [diff] [blame] | 1108 | descriptorSets[firstSet + i] = vk::Cast(pDescriptorSets[i])->data; |
| 1109 | } |
| 1110 | |
Nicolas Capens | 81bc9d9 | 2019-12-16 15:05:57 -0500 | [diff] [blame] | 1111 | for(uint32_t i = 0; i < dynamicOffsetCount; i++) |
Ben Clayton | 225a130 | 2019-04-02 12:28:22 +0100 | [diff] [blame] | 1112 | { |
Nicolas Capens | 002b7c1 | 2020-04-24 01:05:57 -0400 | [diff] [blame] | 1113 | dynamicOffsets[firstDynamicOffset + i] = pDynamicOffsets[i]; |
Ben Clayton | 225a130 | 2019-04-02 12:28:22 +0100 | [diff] [blame] | 1114 | } |
Alexis Hetu | 5edafb5 | 2019-02-15 14:56:22 -0500 | [diff] [blame] | 1115 | } |
| 1116 | |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 1117 | void play(vk::CommandBuffer::ExecutionState &executionState) override |
Alexis Hetu | 5edafb5 | 2019-02-15 14:56:22 -0500 | [diff] [blame] | 1118 | { |
Antonio Maiorano | 941293d | 2020-04-27 10:22:49 -0400 | [diff] [blame] | 1119 | ASSERT(pipelineBindPoint < vk::VK_PIPELINE_BIND_POINT_RANGE_SIZE); |
Nicolas Capens | 002b7c1 | 2020-04-24 01:05:57 -0400 | [diff] [blame] | 1120 | ASSERT(firstSet + descriptorSetCount <= vk::MAX_BOUND_DESCRIPTOR_SETS); |
| 1121 | ASSERT(firstDynamicOffset + dynamicOffsetCount <= vk::MAX_DESCRIPTOR_SET_COMBINED_BUFFERS_DYNAMIC); |
Nicolas Capens | 026f7d0 | 2020-04-23 23:44:57 -0400 | [diff] [blame] | 1122 | |
Nicolas Capens | 002b7c1 | 2020-04-24 01:05:57 -0400 | [diff] [blame] | 1123 | auto &pipelineState = executionState.pipelineState[pipelineBindPoint]; |
| 1124 | |
| 1125 | for(uint32_t i = firstSet; i < firstSet + descriptorSetCount; i++) |
Ben Clayton | 225a130 | 2019-04-02 12:28:22 +0100 | [diff] [blame] | 1126 | { |
Alexis Hetu | 4f438a5 | 2020-06-15 16:13:51 -0400 | [diff] [blame] | 1127 | pipelineState.descriptorSetObjects[i] = descriptorSetObjects[i]; |
Nicolas Capens | 002b7c1 | 2020-04-24 01:05:57 -0400 | [diff] [blame] | 1128 | pipelineState.descriptorSets[i] = descriptorSets[i]; |
| 1129 | } |
| 1130 | |
| 1131 | for(uint32_t i = firstDynamicOffset; i < firstDynamicOffset + dynamicOffsetCount; i++) |
| 1132 | { |
| 1133 | pipelineState.descriptorDynamicOffsets[i] = dynamicOffsets[i]; |
Ben Clayton | 225a130 | 2019-04-02 12:28:22 +0100 | [diff] [blame] | 1134 | } |
Alexis Hetu | 5edafb5 | 2019-02-15 14:56:22 -0500 | [diff] [blame] | 1135 | } |
| 1136 | |
Nicolas Capens | 002b7c1 | 2020-04-24 01:05:57 -0400 | [diff] [blame] | 1137 | std::string description() override { return "vkCmdBindDescriptorSets()"; } |
Ben Clayton | 72c398f | 2019-12-03 11:53:09 +0000 | [diff] [blame] | 1138 | |
Alexis Hetu | 5edafb5 | 2019-02-15 14:56:22 -0500 | [diff] [blame] | 1139 | private: |
Nicolas Capens | c7d5ec3 | 2020-04-22 01:11:37 -0400 | [diff] [blame] | 1140 | const VkPipelineBindPoint pipelineBindPoint; |
Nicolas Capens | 002b7c1 | 2020-04-24 01:05:57 -0400 | [diff] [blame] | 1141 | const uint32_t firstSet; |
| 1142 | const uint32_t descriptorSetCount; |
| 1143 | const uint32_t firstDynamicOffset; |
Nicolas Capens | c7d5ec3 | 2020-04-22 01:11:37 -0400 | [diff] [blame] | 1144 | const uint32_t dynamicOffsetCount; |
Nicolas Capens | 002b7c1 | 2020-04-24 01:05:57 -0400 | [diff] [blame] | 1145 | |
Alexis Hetu | 4f438a5 | 2020-06-15 16:13:51 -0400 | [diff] [blame] | 1146 | vk::DescriptorSet::Array descriptorSetObjects; |
Nicolas Capens | 002b7c1 | 2020-04-24 01:05:57 -0400 | [diff] [blame] | 1147 | vk::DescriptorSet::Bindings descriptorSets; |
Ben Clayton | 1e610ee | 2019-12-03 11:48:25 +0000 | [diff] [blame] | 1148 | vk::DescriptorSet::DynamicOffsets dynamicOffsets; |
Alexis Hetu | 5edafb5 | 2019-02-15 14:56:22 -0500 | [diff] [blame] | 1149 | }; |
| 1150 | |
Ben Clayton | 1e610ee | 2019-12-03 11:48:25 +0000 | [diff] [blame] | 1151 | class CmdSetPushConstants : public vk::CommandBuffer::Command |
Chris Forbes | a30de54 | 2019-03-18 18:51:55 -0700 | [diff] [blame] | 1152 | { |
Ben Clayton | 1e610ee | 2019-12-03 11:48:25 +0000 | [diff] [blame] | 1153 | public: |
| 1154 | CmdSetPushConstants(uint32_t offset, uint32_t size, void const *pValues) |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 1155 | : offset(offset) |
| 1156 | , size(size) |
Chris Forbes | a30de54 | 2019-03-18 18:51:55 -0700 | [diff] [blame] | 1157 | { |
Ben Clayton | 1e610ee | 2019-12-03 11:48:25 +0000 | [diff] [blame] | 1158 | ASSERT(offset < vk::MAX_PUSH_CONSTANT_SIZE); |
| 1159 | ASSERT(offset + size <= vk::MAX_PUSH_CONSTANT_SIZE); |
Chris Forbes | a30de54 | 2019-03-18 18:51:55 -0700 | [diff] [blame] | 1160 | |
| 1161 | memcpy(data, pValues, size); |
| 1162 | } |
| 1163 | |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 1164 | void play(vk::CommandBuffer::ExecutionState &executionState) override |
Chris Forbes | a30de54 | 2019-03-18 18:51:55 -0700 | [diff] [blame] | 1165 | { |
| 1166 | memcpy(&executionState.pushConstants.data[offset], data, size); |
| 1167 | } |
| 1168 | |
Ben Clayton | 72c398f | 2019-12-03 11:53:09 +0000 | [diff] [blame] | 1169 | std::string description() override { return "vkCmdSetPushConstants()"; } |
| 1170 | |
Chris Forbes | a30de54 | 2019-03-18 18:51:55 -0700 | [diff] [blame] | 1171 | private: |
| 1172 | uint32_t offset; |
| 1173 | uint32_t size; |
Ben Clayton | 1e610ee | 2019-12-03 11:48:25 +0000 | [diff] [blame] | 1174 | unsigned char data[vk::MAX_PUSH_CONSTANT_SIZE]; |
Chris Forbes | a30de54 | 2019-03-18 18:51:55 -0700 | [diff] [blame] | 1175 | }; |
| 1176 | |
Ben Clayton | 1e610ee | 2019-12-03 11:48:25 +0000 | [diff] [blame] | 1177 | class CmdBeginQuery : public vk::CommandBuffer::Command |
Alexis Hetu | f0aa9d5 | 2019-04-01 17:06:47 -0400 | [diff] [blame] | 1178 | { |
Ben Clayton | 1e610ee | 2019-12-03 11:48:25 +0000 | [diff] [blame] | 1179 | public: |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 1180 | CmdBeginQuery(vk::QueryPool *queryPool, uint32_t query, VkQueryControlFlags flags) |
| 1181 | : queryPool(queryPool) |
| 1182 | , query(query) |
| 1183 | , flags(flags) |
Alexis Hetu | f0aa9d5 | 2019-04-01 17:06:47 -0400 | [diff] [blame] | 1184 | { |
| 1185 | } |
| 1186 | |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 1187 | void play(vk::CommandBuffer::ExecutionState &executionState) override |
Alexis Hetu | f0aa9d5 | 2019-04-01 17:06:47 -0400 | [diff] [blame] | 1188 | { |
Alexis Hetu | 63ae924 | 2019-06-06 13:52:15 -0400 | [diff] [blame] | 1189 | queryPool->begin(query, flags); |
Chris Forbes | 0c1adcc | 2019-08-06 11:10:48 -0700 | [diff] [blame] | 1190 | executionState.renderer->addQuery(queryPool->getQuery(query)); |
Alexis Hetu | f0aa9d5 | 2019-04-01 17:06:47 -0400 | [diff] [blame] | 1191 | } |
| 1192 | |
Ben Clayton | 72c398f | 2019-12-03 11:53:09 +0000 | [diff] [blame] | 1193 | std::string description() override { return "vkCmdBeginQuery()"; } |
| 1194 | |
Alexis Hetu | f0aa9d5 | 2019-04-01 17:06:47 -0400 | [diff] [blame] | 1195 | private: |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 1196 | vk::QueryPool *queryPool; |
Alexis Hetu | f0aa9d5 | 2019-04-01 17:06:47 -0400 | [diff] [blame] | 1197 | uint32_t query; |
| 1198 | VkQueryControlFlags flags; |
| 1199 | }; |
| 1200 | |
Ben Clayton | 1e610ee | 2019-12-03 11:48:25 +0000 | [diff] [blame] | 1201 | class CmdEndQuery : public vk::CommandBuffer::Command |
Alexis Hetu | f0aa9d5 | 2019-04-01 17:06:47 -0400 | [diff] [blame] | 1202 | { |
Ben Clayton | 1e610ee | 2019-12-03 11:48:25 +0000 | [diff] [blame] | 1203 | public: |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 1204 | CmdEndQuery(vk::QueryPool *queryPool, uint32_t query) |
| 1205 | : queryPool(queryPool) |
| 1206 | , query(query) |
Alexis Hetu | f0aa9d5 | 2019-04-01 17:06:47 -0400 | [diff] [blame] | 1207 | { |
| 1208 | } |
| 1209 | |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 1210 | void play(vk::CommandBuffer::ExecutionState &executionState) override |
Alexis Hetu | f0aa9d5 | 2019-04-01 17:06:47 -0400 | [diff] [blame] | 1211 | { |
Alexis Hetu | 63ae924 | 2019-06-06 13:52:15 -0400 | [diff] [blame] | 1212 | executionState.renderer->removeQuery(queryPool->getQuery(query)); |
| 1213 | queryPool->end(query); |
Alexis Hetu | f0aa9d5 | 2019-04-01 17:06:47 -0400 | [diff] [blame] | 1214 | } |
| 1215 | |
Ben Clayton | 72c398f | 2019-12-03 11:53:09 +0000 | [diff] [blame] | 1216 | std::string description() override { return "vkCmdEndQuery()"; } |
| 1217 | |
Alexis Hetu | f0aa9d5 | 2019-04-01 17:06:47 -0400 | [diff] [blame] | 1218 | private: |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 1219 | vk::QueryPool *queryPool; |
Alexis Hetu | f0aa9d5 | 2019-04-01 17:06:47 -0400 | [diff] [blame] | 1220 | uint32_t query; |
| 1221 | }; |
| 1222 | |
Ben Clayton | 1e610ee | 2019-12-03 11:48:25 +0000 | [diff] [blame] | 1223 | class CmdResetQueryPool : public vk::CommandBuffer::Command |
Alexis Hetu | f0aa9d5 | 2019-04-01 17:06:47 -0400 | [diff] [blame] | 1224 | { |
Ben Clayton | 1e610ee | 2019-12-03 11:48:25 +0000 | [diff] [blame] | 1225 | public: |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 1226 | CmdResetQueryPool(vk::QueryPool *queryPool, uint32_t firstQuery, uint32_t queryCount) |
| 1227 | : queryPool(queryPool) |
| 1228 | , firstQuery(firstQuery) |
| 1229 | , queryCount(queryCount) |
Alexis Hetu | f0aa9d5 | 2019-04-01 17:06:47 -0400 | [diff] [blame] | 1230 | { |
| 1231 | } |
| 1232 | |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 1233 | void play(vk::CommandBuffer::ExecutionState &executionState) override |
Alexis Hetu | f0aa9d5 | 2019-04-01 17:06:47 -0400 | [diff] [blame] | 1234 | { |
Alexis Hetu | 63ae924 | 2019-06-06 13:52:15 -0400 | [diff] [blame] | 1235 | queryPool->reset(firstQuery, queryCount); |
Alexis Hetu | f0aa9d5 | 2019-04-01 17:06:47 -0400 | [diff] [blame] | 1236 | } |
| 1237 | |
Ben Clayton | 72c398f | 2019-12-03 11:53:09 +0000 | [diff] [blame] | 1238 | std::string description() override { return "vkCmdResetQueryPool()"; } |
| 1239 | |
Alexis Hetu | f0aa9d5 | 2019-04-01 17:06:47 -0400 | [diff] [blame] | 1240 | private: |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 1241 | vk::QueryPool *queryPool; |
Alexis Hetu | f0aa9d5 | 2019-04-01 17:06:47 -0400 | [diff] [blame] | 1242 | uint32_t firstQuery; |
| 1243 | uint32_t queryCount; |
| 1244 | }; |
| 1245 | |
Ben Clayton | 1e610ee | 2019-12-03 11:48:25 +0000 | [diff] [blame] | 1246 | class CmdWriteTimeStamp : public vk::CommandBuffer::Command |
Alexis Hetu | f0aa9d5 | 2019-04-01 17:06:47 -0400 | [diff] [blame] | 1247 | { |
Ben Clayton | 1e610ee | 2019-12-03 11:48:25 +0000 | [diff] [blame] | 1248 | public: |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 1249 | CmdWriteTimeStamp(vk::QueryPool *queryPool, uint32_t query, VkPipelineStageFlagBits stage) |
| 1250 | : queryPool(queryPool) |
| 1251 | , query(query) |
| 1252 | , stage(stage) |
Alexis Hetu | f0aa9d5 | 2019-04-01 17:06:47 -0400 | [diff] [blame] | 1253 | { |
| 1254 | } |
| 1255 | |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 1256 | void play(vk::CommandBuffer::ExecutionState &executionState) override |
Alexis Hetu | f0aa9d5 | 2019-04-01 17:06:47 -0400 | [diff] [blame] | 1257 | { |
Nicolas Capens | 81bc9d9 | 2019-12-16 15:05:57 -0500 | [diff] [blame] | 1258 | if(stage & ~(VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT | VK_PIPELINE_STAGE_DRAW_INDIRECT_BIT)) |
Chris Forbes | fd72dd0 | 2019-08-14 17:52:36 -0700 | [diff] [blame] | 1259 | { |
| 1260 | // The `top of pipe` and `draw indirect` stages are handled in command buffer processing so a timestamp write |
| 1261 | // done in those stages can just be done here without any additional synchronization. |
| 1262 | // Everything else is deferred to the Renderer; we will treat those stages all as if they were |
| 1263 | // `bottom of pipe`. |
| 1264 | // |
Ben Clayton | e693b62 | 2019-09-05 12:48:37 +0100 | [diff] [blame] | 1265 | // FIXME(chrisforbes): once Marl is integrated, do this in a task so we don't have to stall here. |
Chris Forbes | fd72dd0 | 2019-08-14 17:52:36 -0700 | [diff] [blame] | 1266 | executionState.renderer->synchronize(); |
| 1267 | } |
| 1268 | |
Alexis Hetu | 63ae924 | 2019-06-06 13:52:15 -0400 | [diff] [blame] | 1269 | queryPool->writeTimestamp(query); |
Alexis Hetu | f0aa9d5 | 2019-04-01 17:06:47 -0400 | [diff] [blame] | 1270 | } |
| 1271 | |
Ben Clayton | 72c398f | 2019-12-03 11:53:09 +0000 | [diff] [blame] | 1272 | std::string description() override { return "vkCmdWriteTimeStamp()"; } |
| 1273 | |
Alexis Hetu | f0aa9d5 | 2019-04-01 17:06:47 -0400 | [diff] [blame] | 1274 | private: |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 1275 | vk::QueryPool *queryPool; |
Alexis Hetu | f0aa9d5 | 2019-04-01 17:06:47 -0400 | [diff] [blame] | 1276 | uint32_t query; |
Chris Forbes | fd72dd0 | 2019-08-14 17:52:36 -0700 | [diff] [blame] | 1277 | VkPipelineStageFlagBits stage; |
Alexis Hetu | f0aa9d5 | 2019-04-01 17:06:47 -0400 | [diff] [blame] | 1278 | }; |
| 1279 | |
Ben Clayton | 1e610ee | 2019-12-03 11:48:25 +0000 | [diff] [blame] | 1280 | class CmdCopyQueryPoolResults : public vk::CommandBuffer::Command |
Alexis Hetu | f0aa9d5 | 2019-04-01 17:06:47 -0400 | [diff] [blame] | 1281 | { |
Ben Clayton | 1e610ee | 2019-12-03 11:48:25 +0000 | [diff] [blame] | 1282 | public: |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 1283 | CmdCopyQueryPoolResults(const vk::QueryPool *queryPool, uint32_t firstQuery, uint32_t queryCount, |
| 1284 | vk::Buffer *dstBuffer, VkDeviceSize dstOffset, VkDeviceSize stride, VkQueryResultFlags flags) |
| 1285 | : queryPool(queryPool) |
| 1286 | , firstQuery(firstQuery) |
| 1287 | , queryCount(queryCount) |
| 1288 | , dstBuffer(dstBuffer) |
| 1289 | , dstOffset(dstOffset) |
| 1290 | , stride(stride) |
| 1291 | , flags(flags) |
Alexis Hetu | f0aa9d5 | 2019-04-01 17:06:47 -0400 | [diff] [blame] | 1292 | { |
| 1293 | } |
| 1294 | |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 1295 | void play(vk::CommandBuffer::ExecutionState &executionState) override |
Alexis Hetu | f0aa9d5 | 2019-04-01 17:06:47 -0400 | [diff] [blame] | 1296 | { |
Alexis Hetu | 7d96f51 | 2019-06-13 18:23:56 -0400 | [diff] [blame] | 1297 | queryPool->getResults(firstQuery, queryCount, dstBuffer->getSize() - dstOffset, |
| 1298 | dstBuffer->getOffsetPointer(dstOffset), stride, flags); |
Alexis Hetu | f0aa9d5 | 2019-04-01 17:06:47 -0400 | [diff] [blame] | 1299 | } |
| 1300 | |
Ben Clayton | 72c398f | 2019-12-03 11:53:09 +0000 | [diff] [blame] | 1301 | std::string description() override { return "vkCmdCopyQueryPoolResults()"; } |
| 1302 | |
Alexis Hetu | f0aa9d5 | 2019-04-01 17:06:47 -0400 | [diff] [blame] | 1303 | private: |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 1304 | const vk::QueryPool *queryPool; |
Alexis Hetu | f0aa9d5 | 2019-04-01 17:06:47 -0400 | [diff] [blame] | 1305 | uint32_t firstQuery; |
| 1306 | uint32_t queryCount; |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 1307 | vk::Buffer *dstBuffer; |
Alexis Hetu | f0aa9d5 | 2019-04-01 17:06:47 -0400 | [diff] [blame] | 1308 | VkDeviceSize dstOffset; |
| 1309 | VkDeviceSize stride; |
| 1310 | VkQueryResultFlags flags; |
| 1311 | }; |
| 1312 | |
Ben Clayton | 1e610ee | 2019-12-03 11:48:25 +0000 | [diff] [blame] | 1313 | } // anonymous namespace |
| 1314 | |
| 1315 | namespace vk { |
| 1316 | |
Ben Clayton | a4e06ca | 2019-12-03 12:38:14 +0000 | [diff] [blame] | 1317 | CommandBuffer::CommandBuffer(Device *device, VkCommandBufferLevel pLevel) |
| 1318 | : device(device) |
| 1319 | , level(pLevel) |
Alexis Hetu | 767b41b | 2018-09-26 11:25:46 -0400 | [diff] [blame] | 1320 | { |
Alexis Hetu | 072dc0d | 2018-10-31 11:41:25 -0400 | [diff] [blame] | 1321 | // FIXME (b/119409619): replace this vector by an allocator so we can control all memory allocations |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 1322 | commands = new std::vector<std::unique_ptr<Command>>(); |
Alexis Hetu | 767b41b | 2018-09-26 11:25:46 -0400 | [diff] [blame] | 1323 | } |
| 1324 | |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 1325 | void CommandBuffer::destroy(const VkAllocationCallbacks *pAllocator) |
Alexis Hetu | a9999ce | 2018-10-17 08:00:43 -0400 | [diff] [blame] | 1326 | { |
Alexis Hetu | d2791c2 | 2018-12-10 14:41:03 -0500 | [diff] [blame] | 1327 | delete commands; |
Alexis Hetu | 072dc0d | 2018-10-31 11:41:25 -0400 | [diff] [blame] | 1328 | } |
| 1329 | |
Alexis Hetu | d2791c2 | 2018-12-10 14:41:03 -0500 | [diff] [blame] | 1330 | void CommandBuffer::resetState() |
Alexis Hetu | 072dc0d | 2018-10-31 11:41:25 -0400 | [diff] [blame] | 1331 | { |
| 1332 | // 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] | 1333 | commands->clear(); |
| 1334 | |
| 1335 | state = INITIAL; |
Alexis Hetu | a9999ce | 2018-10-17 08:00:43 -0400 | [diff] [blame] | 1336 | } |
| 1337 | |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 1338 | VkResult CommandBuffer::begin(VkCommandBufferUsageFlags flags, const VkCommandBufferInheritanceInfo *pInheritanceInfo) |
Alexis Hetu | a9999ce | 2018-10-17 08:00:43 -0400 | [diff] [blame] | 1339 | { |
Alexis Hetu | 072dc0d | 2018-10-31 11:41:25 -0400 | [diff] [blame] | 1340 | ASSERT((state != RECORDING) && (state != PENDING)); |
Alexis Hetu | d2791c2 | 2018-12-10 14:41:03 -0500 | [diff] [blame] | 1341 | |
Chris Forbes | 823ca85 | 2019-03-01 17:40:25 -0800 | [diff] [blame] | 1342 | // Nothing interesting to do based on flags. We don't have any optimizations |
| 1343 | // to apply for ONE_TIME_SUBMIT or (lack of) SIMULTANEOUS_USE. RENDER_PASS_CONTINUE |
| 1344 | // must also provide a non-null pInheritanceInfo, which we don't implement yet, but is caught below. |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 1345 | (void)flags; |
Chris Forbes | 823ca85 | 2019-03-01 17:40:25 -0800 | [diff] [blame] | 1346 | |
Alexis Hetu | e7b2a05 | 2019-03-18 16:16:36 -0400 | [diff] [blame] | 1347 | // pInheritanceInfo merely contains optimization hints, so we currently ignore it |
Alexis Hetu | d2791c2 | 2018-12-10 14:41:03 -0500 | [diff] [blame] | 1348 | |
Nicolas Capens | 44bd43a | 2020-01-22 03:07:14 -0500 | [diff] [blame] | 1349 | // "pInheritanceInfo is a pointer to a VkCommandBufferInheritanceInfo structure, used if commandBuffer is a |
| 1350 | // secondary command buffer. If this is a primary command buffer, then this value is ignored." |
| 1351 | if(level == VK_COMMAND_BUFFER_LEVEL_SECONDARY) |
| 1352 | { |
| 1353 | if(pInheritanceInfo->queryFlags != 0) |
| 1354 | { |
| 1355 | // "If the inherited queries feature is not enabled, queryFlags must be 0" |
| 1356 | UNSUPPORTED("VkPhysicalDeviceFeatures::inheritedQueries"); |
| 1357 | } |
| 1358 | } |
| 1359 | |
Alexis Hetu | d2791c2 | 2018-12-10 14:41:03 -0500 | [diff] [blame] | 1360 | if(state != INITIAL) |
| 1361 | { |
| 1362 | // Implicit reset |
| 1363 | resetState(); |
| 1364 | } |
| 1365 | |
Alexis Hetu | a9999ce | 2018-10-17 08:00:43 -0400 | [diff] [blame] | 1366 | state = RECORDING; |
| 1367 | |
Alexis Hetu | a9999ce | 2018-10-17 08:00:43 -0400 | [diff] [blame] | 1368 | return VK_SUCCESS; |
| 1369 | } |
| 1370 | |
| 1371 | VkResult CommandBuffer::end() |
| 1372 | { |
Alexis Hetu | 072dc0d | 2018-10-31 11:41:25 -0400 | [diff] [blame] | 1373 | ASSERT(state == RECORDING); |
Alexis Hetu | a9999ce | 2018-10-17 08:00:43 -0400 | [diff] [blame] | 1374 | |
Alexis Hetu | 072dc0d | 2018-10-31 11:41:25 -0400 | [diff] [blame] | 1375 | state = EXECUTABLE; |
Alexis Hetu | a9999ce | 2018-10-17 08:00:43 -0400 | [diff] [blame] | 1376 | |
Ben Clayton | a4e06ca | 2019-12-03 12:38:14 +0000 | [diff] [blame] | 1377 | #ifdef ENABLE_VK_DEBUGGER |
| 1378 | auto debuggerContext = device->getDebuggerContext(); |
| 1379 | if(debuggerContext) |
| 1380 | { |
| 1381 | std::string source; |
| 1382 | for(auto &command : *commands) |
| 1383 | { |
| 1384 | source += command->description() + "\n"; |
| 1385 | } |
| 1386 | debuggerFile = debuggerContext->lock().createVirtualFile("VkCommandBuffer", source.c_str()); |
| 1387 | } |
| 1388 | #endif // ENABLE_VK_DEBUGGER |
| 1389 | |
Alexis Hetu | a9999ce | 2018-10-17 08:00:43 -0400 | [diff] [blame] | 1390 | return VK_SUCCESS; |
| 1391 | } |
| 1392 | |
| 1393 | VkResult CommandBuffer::reset(VkCommandPoolResetFlags flags) |
| 1394 | { |
| 1395 | ASSERT(state != PENDING); |
| 1396 | |
Alexis Hetu | d2791c2 | 2018-12-10 14:41:03 -0500 | [diff] [blame] | 1397 | resetState(); |
Alexis Hetu | a9999ce | 2018-10-17 08:00:43 -0400 | [diff] [blame] | 1398 | |
| 1399 | return VK_SUCCESS; |
| 1400 | } |
| 1401 | |
Alexis Hetu | f251a6f | 2019-01-07 14:47:32 -0500 | [diff] [blame] | 1402 | template<typename T, typename... Args> |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 1403 | void CommandBuffer::addCommand(Args &&... args) |
Alexis Hetu | f251a6f | 2019-01-07 14:47:32 -0500 | [diff] [blame] | 1404 | { |
Alexis Hetu | 1a9714a | 2019-04-12 11:48:12 -0400 | [diff] [blame] | 1405 | // FIXME (b/119409619): use an allocator here so we can control all memory allocations |
Ben Clayton | 368d39c | 2020-01-08 23:10:47 +0000 | [diff] [blame] | 1406 | commands->push_back(std::make_unique<T>(std::forward<Args>(args)...)); |
Alexis Hetu | f251a6f | 2019-01-07 14:47:32 -0500 | [diff] [blame] | 1407 | } |
| 1408 | |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 1409 | void CommandBuffer::beginRenderPass(RenderPass *renderPass, Framebuffer *framebuffer, VkRect2D renderArea, |
| 1410 | uint32_t clearValueCount, const VkClearValue *clearValues, VkSubpassContents contents) |
Alexis Hetu | a9999ce | 2018-10-17 08:00:43 -0400 | [diff] [blame] | 1411 | { |
Alexis Hetu | 072dc0d | 2018-10-31 11:41:25 -0400 | [diff] [blame] | 1412 | ASSERT(state == RECORDING); |
| 1413 | |
Ben Clayton | 1e610ee | 2019-12-03 11:48:25 +0000 | [diff] [blame] | 1414 | addCommand<::CmdBeginRenderPass>(renderPass, framebuffer, renderArea, clearValueCount, clearValues); |
Alexis Hetu | a9999ce | 2018-10-17 08:00:43 -0400 | [diff] [blame] | 1415 | } |
| 1416 | |
| 1417 | void CommandBuffer::nextSubpass(VkSubpassContents contents) |
| 1418 | { |
Alexis Hetu | 1cd31ea | 2019-01-17 17:14:57 -0500 | [diff] [blame] | 1419 | ASSERT(state == RECORDING); |
| 1420 | |
Ben Clayton | 1e610ee | 2019-12-03 11:48:25 +0000 | [diff] [blame] | 1421 | addCommand<::CmdNextSubpass>(); |
Alexis Hetu | a9999ce | 2018-10-17 08:00:43 -0400 | [diff] [blame] | 1422 | } |
| 1423 | |
| 1424 | void CommandBuffer::endRenderPass() |
| 1425 | { |
Ben Clayton | 1e610ee | 2019-12-03 11:48:25 +0000 | [diff] [blame] | 1426 | addCommand<::CmdEndRenderPass>(); |
Alexis Hetu | a9999ce | 2018-10-17 08:00:43 -0400 | [diff] [blame] | 1427 | } |
| 1428 | |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 1429 | void CommandBuffer::executeCommands(uint32_t commandBufferCount, const VkCommandBuffer *pCommandBuffers) |
Alexis Hetu | a9999ce | 2018-10-17 08:00:43 -0400 | [diff] [blame] | 1430 | { |
Alexis Hetu | e7b2a05 | 2019-03-18 16:16:36 -0400 | [diff] [blame] | 1431 | ASSERT(state == RECORDING); |
| 1432 | |
| 1433 | for(uint32_t i = 0; i < commandBufferCount; ++i) |
| 1434 | { |
Ben Clayton | 1e610ee | 2019-12-03 11:48:25 +0000 | [diff] [blame] | 1435 | addCommand<::CmdExecuteCommands>(vk::Cast(pCommandBuffers[i])); |
Alexis Hetu | e7b2a05 | 2019-03-18 16:16:36 -0400 | [diff] [blame] | 1436 | } |
Alexis Hetu | a9999ce | 2018-10-17 08:00:43 -0400 | [diff] [blame] | 1437 | } |
| 1438 | |
| 1439 | void CommandBuffer::setDeviceMask(uint32_t deviceMask) |
| 1440 | { |
Alexis Hetu | 026ceef | 2019-05-07 17:35:11 -0400 | [diff] [blame] | 1441 | // SwiftShader only has one device, so we ignore the device mask |
Alexis Hetu | a9999ce | 2018-10-17 08:00:43 -0400 | [diff] [blame] | 1442 | } |
| 1443 | |
| 1444 | void CommandBuffer::dispatchBase(uint32_t baseGroupX, uint32_t baseGroupY, uint32_t baseGroupZ, |
| 1445 | uint32_t groupCountX, uint32_t groupCountY, uint32_t groupCountZ) |
| 1446 | { |
Ben Clayton | 1e610ee | 2019-12-03 11:48:25 +0000 | [diff] [blame] | 1447 | addCommand<::CmdDispatch>(baseGroupX, baseGroupY, baseGroupZ, groupCountX, groupCountY, groupCountZ); |
Alexis Hetu | a9999ce | 2018-10-17 08:00:43 -0400 | [diff] [blame] | 1448 | } |
| 1449 | |
| 1450 | void CommandBuffer::pipelineBarrier(VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask, |
| 1451 | VkDependencyFlags dependencyFlags, |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 1452 | uint32_t memoryBarrierCount, const VkMemoryBarrier *pMemoryBarriers, |
| 1453 | uint32_t bufferMemoryBarrierCount, const VkBufferMemoryBarrier *pBufferMemoryBarriers, |
| 1454 | uint32_t imageMemoryBarrierCount, const VkImageMemoryBarrier *pImageMemoryBarriers) |
Alexis Hetu | a9999ce | 2018-10-17 08:00:43 -0400 | [diff] [blame] | 1455 | { |
Ben Clayton | 1e610ee | 2019-12-03 11:48:25 +0000 | [diff] [blame] | 1456 | addCommand<::CmdPipelineBarrier>(); |
Alexis Hetu | a9999ce | 2018-10-17 08:00:43 -0400 | [diff] [blame] | 1457 | } |
| 1458 | |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 1459 | void CommandBuffer::bindPipeline(VkPipelineBindPoint pipelineBindPoint, Pipeline *pipeline) |
Alexis Hetu | a9999ce | 2018-10-17 08:00:43 -0400 | [diff] [blame] | 1460 | { |
Ben Clayton | f2be26a | 2019-03-08 12:02:05 +0000 | [diff] [blame] | 1461 | switch(pipelineBindPoint) |
Alexis Hetu | 072dc0d | 2018-10-31 11:41:25 -0400 | [diff] [blame] | 1462 | { |
Ben Clayton | f2be26a | 2019-03-08 12:02:05 +0000 | [diff] [blame] | 1463 | case VK_PIPELINE_BIND_POINT_COMPUTE: |
| 1464 | case VK_PIPELINE_BIND_POINT_GRAPHICS: |
Ben Clayton | 1e610ee | 2019-12-03 11:48:25 +0000 | [diff] [blame] | 1465 | addCommand<::CmdPipelineBind>(pipelineBindPoint, pipeline); |
Ben Clayton | f2be26a | 2019-03-08 12:02:05 +0000 | [diff] [blame] | 1466 | break; |
| 1467 | default: |
Nicolas Capens | 44bd43a | 2020-01-22 03:07:14 -0500 | [diff] [blame] | 1468 | UNSUPPORTED("VkPipelineBindPoint %d", int(pipelineBindPoint)); |
Alexis Hetu | 072dc0d | 2018-10-31 11:41:25 -0400 | [diff] [blame] | 1469 | } |
Alexis Hetu | a9999ce | 2018-10-17 08:00:43 -0400 | [diff] [blame] | 1470 | } |
| 1471 | |
| 1472 | void CommandBuffer::bindVertexBuffers(uint32_t firstBinding, uint32_t bindingCount, |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 1473 | const VkBuffer *pBuffers, const VkDeviceSize *pOffsets) |
Alexis Hetu | a9999ce | 2018-10-17 08:00:43 -0400 | [diff] [blame] | 1474 | { |
Chris Forbes | fe3d497 | 2019-02-22 17:21:23 -0800 | [diff] [blame] | 1475 | for(uint32_t i = 0; i < bindingCount; ++i) |
Alexis Hetu | a9999ce | 2018-10-17 08:00:43 -0400 | [diff] [blame] | 1476 | { |
Ben Clayton | 1e610ee | 2019-12-03 11:48:25 +0000 | [diff] [blame] | 1477 | addCommand<::CmdVertexBufferBind>(i + firstBinding, vk::Cast(pBuffers[i]), pOffsets[i]); |
Alexis Hetu | a9999ce | 2018-10-17 08:00:43 -0400 | [diff] [blame] | 1478 | } |
| 1479 | } |
| 1480 | |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 1481 | void CommandBuffer::beginQuery(QueryPool *queryPool, uint32_t query, VkQueryControlFlags flags) |
Alexis Hetu | a9999ce | 2018-10-17 08:00:43 -0400 | [diff] [blame] | 1482 | { |
Ben Clayton | 1e610ee | 2019-12-03 11:48:25 +0000 | [diff] [blame] | 1483 | addCommand<::CmdBeginQuery>(queryPool, query, flags); |
Alexis Hetu | a9999ce | 2018-10-17 08:00:43 -0400 | [diff] [blame] | 1484 | } |
| 1485 | |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 1486 | void CommandBuffer::endQuery(QueryPool *queryPool, uint32_t query) |
Alexis Hetu | a9999ce | 2018-10-17 08:00:43 -0400 | [diff] [blame] | 1487 | { |
Ben Clayton | 1e610ee | 2019-12-03 11:48:25 +0000 | [diff] [blame] | 1488 | addCommand<::CmdEndQuery>(queryPool, query); |
Alexis Hetu | a9999ce | 2018-10-17 08:00:43 -0400 | [diff] [blame] | 1489 | } |
| 1490 | |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 1491 | void CommandBuffer::resetQueryPool(QueryPool *queryPool, uint32_t firstQuery, uint32_t queryCount) |
Alexis Hetu | a9999ce | 2018-10-17 08:00:43 -0400 | [diff] [blame] | 1492 | { |
Ben Clayton | 1e610ee | 2019-12-03 11:48:25 +0000 | [diff] [blame] | 1493 | addCommand<::CmdResetQueryPool>(queryPool, firstQuery, queryCount); |
Alexis Hetu | a9999ce | 2018-10-17 08:00:43 -0400 | [diff] [blame] | 1494 | } |
| 1495 | |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 1496 | void CommandBuffer::writeTimestamp(VkPipelineStageFlagBits pipelineStage, QueryPool *queryPool, uint32_t query) |
Alexis Hetu | a9999ce | 2018-10-17 08:00:43 -0400 | [diff] [blame] | 1497 | { |
Ben Clayton | 1e610ee | 2019-12-03 11:48:25 +0000 | [diff] [blame] | 1498 | addCommand<::CmdWriteTimeStamp>(queryPool, query, pipelineStage); |
Alexis Hetu | a9999ce | 2018-10-17 08:00:43 -0400 | [diff] [blame] | 1499 | } |
| 1500 | |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 1501 | void CommandBuffer::copyQueryPoolResults(const QueryPool *queryPool, uint32_t firstQuery, uint32_t queryCount, |
| 1502 | Buffer *dstBuffer, VkDeviceSize dstOffset, VkDeviceSize stride, VkQueryResultFlags flags) |
Alexis Hetu | a9999ce | 2018-10-17 08:00:43 -0400 | [diff] [blame] | 1503 | { |
Ben Clayton | 1e610ee | 2019-12-03 11:48:25 +0000 | [diff] [blame] | 1504 | addCommand<::CmdCopyQueryPoolResults>(queryPool, firstQuery, queryCount, dstBuffer, dstOffset, stride, flags); |
Alexis Hetu | a9999ce | 2018-10-17 08:00:43 -0400 | [diff] [blame] | 1505 | } |
| 1506 | |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 1507 | void CommandBuffer::pushConstants(PipelineLayout *layout, VkShaderStageFlags stageFlags, |
| 1508 | uint32_t offset, uint32_t size, const void *pValues) |
Alexis Hetu | a9999ce | 2018-10-17 08:00:43 -0400 | [diff] [blame] | 1509 | { |
Ben Clayton | 1e610ee | 2019-12-03 11:48:25 +0000 | [diff] [blame] | 1510 | addCommand<::CmdSetPushConstants>(offset, size, pValues); |
Alexis Hetu | a9999ce | 2018-10-17 08:00:43 -0400 | [diff] [blame] | 1511 | } |
| 1512 | |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 1513 | void CommandBuffer::setViewport(uint32_t firstViewport, uint32_t viewportCount, const VkViewport *pViewports) |
Alexis Hetu | a9999ce | 2018-10-17 08:00:43 -0400 | [diff] [blame] | 1514 | { |
Alexis Hetu | 7383243 | 2019-04-11 16:43:18 -0400 | [diff] [blame] | 1515 | if(firstViewport != 0 || viewportCount > 1) |
| 1516 | { |
Nicolas Capens | 44bd43a | 2020-01-22 03:07:14 -0500 | [diff] [blame] | 1517 | UNSUPPORTED("VkPhysicalDeviceFeatures::multiViewport"); |
Alexis Hetu | 7383243 | 2019-04-11 16:43:18 -0400 | [diff] [blame] | 1518 | } |
| 1519 | |
| 1520 | for(uint32_t i = 0; i < viewportCount; i++) |
| 1521 | { |
Ben Clayton | 1e610ee | 2019-12-03 11:48:25 +0000 | [diff] [blame] | 1522 | addCommand<::CmdSetViewport>(pViewports[i], i + firstViewport); |
Alexis Hetu | 7383243 | 2019-04-11 16:43:18 -0400 | [diff] [blame] | 1523 | } |
Alexis Hetu | a9999ce | 2018-10-17 08:00:43 -0400 | [diff] [blame] | 1524 | } |
| 1525 | |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 1526 | void CommandBuffer::setScissor(uint32_t firstScissor, uint32_t scissorCount, const VkRect2D *pScissors) |
Alexis Hetu | a9999ce | 2018-10-17 08:00:43 -0400 | [diff] [blame] | 1527 | { |
Alexis Hetu | 7383243 | 2019-04-11 16:43:18 -0400 | [diff] [blame] | 1528 | if(firstScissor != 0 || scissorCount > 1) |
| 1529 | { |
Nicolas Capens | 44bd43a | 2020-01-22 03:07:14 -0500 | [diff] [blame] | 1530 | UNSUPPORTED("VkPhysicalDeviceFeatures::multiViewport"); |
Alexis Hetu | 7383243 | 2019-04-11 16:43:18 -0400 | [diff] [blame] | 1531 | } |
| 1532 | |
| 1533 | for(uint32_t i = 0; i < scissorCount; i++) |
| 1534 | { |
Ben Clayton | 1e610ee | 2019-12-03 11:48:25 +0000 | [diff] [blame] | 1535 | addCommand<::CmdSetScissor>(pScissors[i], i + firstScissor); |
Alexis Hetu | 7383243 | 2019-04-11 16:43:18 -0400 | [diff] [blame] | 1536 | } |
Alexis Hetu | a9999ce | 2018-10-17 08:00:43 -0400 | [diff] [blame] | 1537 | } |
| 1538 | |
| 1539 | void CommandBuffer::setLineWidth(float lineWidth) |
| 1540 | { |
Alexis Hetu | a9999ce | 2018-10-17 08:00:43 -0400 | [diff] [blame] | 1541 | // If the wide lines feature is not enabled, lineWidth must be 1.0 |
| 1542 | ASSERT(lineWidth == 1.0f); |
Alexis Hetu | a9999ce | 2018-10-17 08:00:43 -0400 | [diff] [blame] | 1543 | } |
| 1544 | |
| 1545 | void CommandBuffer::setDepthBias(float depthBiasConstantFactor, float depthBiasClamp, float depthBiasSlopeFactor) |
| 1546 | { |
Ben Clayton | 1e610ee | 2019-12-03 11:48:25 +0000 | [diff] [blame] | 1547 | addCommand<::CmdSetDepthBias>(depthBiasConstantFactor, depthBiasClamp, depthBiasSlopeFactor); |
Alexis Hetu | a9999ce | 2018-10-17 08:00:43 -0400 | [diff] [blame] | 1548 | } |
| 1549 | |
| 1550 | void CommandBuffer::setBlendConstants(const float blendConstants[4]) |
| 1551 | { |
Ben Clayton | 1e610ee | 2019-12-03 11:48:25 +0000 | [diff] [blame] | 1552 | addCommand<::CmdSetBlendConstants>(blendConstants); |
Alexis Hetu | a9999ce | 2018-10-17 08:00:43 -0400 | [diff] [blame] | 1553 | } |
| 1554 | |
| 1555 | void CommandBuffer::setDepthBounds(float minDepthBounds, float maxDepthBounds) |
| 1556 | { |
Ben Clayton | 1e610ee | 2019-12-03 11:48:25 +0000 | [diff] [blame] | 1557 | addCommand<::CmdSetDepthBounds>(minDepthBounds, maxDepthBounds); |
Alexis Hetu | a9999ce | 2018-10-17 08:00:43 -0400 | [diff] [blame] | 1558 | } |
| 1559 | |
| 1560 | void CommandBuffer::setStencilCompareMask(VkStencilFaceFlags faceMask, uint32_t compareMask) |
| 1561 | { |
Alexis Hetu | a9999ce | 2018-10-17 08:00:43 -0400 | [diff] [blame] | 1562 | // faceMask must not be 0 |
| 1563 | ASSERT(faceMask != 0); |
| 1564 | |
Ben Clayton | 1e610ee | 2019-12-03 11:48:25 +0000 | [diff] [blame] | 1565 | addCommand<::CmdSetStencilCompareMask>(faceMask, compareMask); |
Alexis Hetu | a9999ce | 2018-10-17 08:00:43 -0400 | [diff] [blame] | 1566 | } |
| 1567 | |
| 1568 | void CommandBuffer::setStencilWriteMask(VkStencilFaceFlags faceMask, uint32_t writeMask) |
| 1569 | { |
Alexis Hetu | a9999ce | 2018-10-17 08:00:43 -0400 | [diff] [blame] | 1570 | // faceMask must not be 0 |
| 1571 | ASSERT(faceMask != 0); |
| 1572 | |
Ben Clayton | 1e610ee | 2019-12-03 11:48:25 +0000 | [diff] [blame] | 1573 | addCommand<::CmdSetStencilWriteMask>(faceMask, writeMask); |
Alexis Hetu | a9999ce | 2018-10-17 08:00:43 -0400 | [diff] [blame] | 1574 | } |
| 1575 | |
| 1576 | void CommandBuffer::setStencilReference(VkStencilFaceFlags faceMask, uint32_t reference) |
| 1577 | { |
Alexis Hetu | a9999ce | 2018-10-17 08:00:43 -0400 | [diff] [blame] | 1578 | // faceMask must not be 0 |
| 1579 | ASSERT(faceMask != 0); |
| 1580 | |
Ben Clayton | 1e610ee | 2019-12-03 11:48:25 +0000 | [diff] [blame] | 1581 | addCommand<::CmdSetStencilReference>(faceMask, reference); |
Alexis Hetu | a9999ce | 2018-10-17 08:00:43 -0400 | [diff] [blame] | 1582 | } |
| 1583 | |
Nicolas Capens | 002b7c1 | 2020-04-24 01:05:57 -0400 | [diff] [blame] | 1584 | void CommandBuffer::bindDescriptorSets(VkPipelineBindPoint pipelineBindPoint, const PipelineLayout *pipelineLayout, |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 1585 | uint32_t firstSet, uint32_t descriptorSetCount, const VkDescriptorSet *pDescriptorSets, |
| 1586 | uint32_t dynamicOffsetCount, const uint32_t *pDynamicOffsets) |
Alexis Hetu | a9999ce | 2018-10-17 08:00:43 -0400 | [diff] [blame] | 1587 | { |
Alexis Hetu | 5edafb5 | 2019-02-15 14:56:22 -0500 | [diff] [blame] | 1588 | ASSERT(state == RECORDING); |
| 1589 | |
Nicolas Capens | 002b7c1 | 2020-04-24 01:05:57 -0400 | [diff] [blame] | 1590 | auto firstDynamicOffset = (dynamicOffsetCount != 0) ? pipelineLayout->getDynamicOffsetIndex(firstSet, 0) : 0; |
Ben Clayton | 225a130 | 2019-04-02 12:28:22 +0100 | [diff] [blame] | 1591 | |
Nicolas Capens | 002b7c1 | 2020-04-24 01:05:57 -0400 | [diff] [blame] | 1592 | addCommand<::CmdBindDescriptorSets>( |
| 1593 | pipelineBindPoint, firstSet, descriptorSetCount, pDescriptorSets, |
| 1594 | firstDynamicOffset, dynamicOffsetCount, pDynamicOffsets); |
Alexis Hetu | a9999ce | 2018-10-17 08:00:43 -0400 | [diff] [blame] | 1595 | } |
| 1596 | |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 1597 | void CommandBuffer::bindIndexBuffer(Buffer *buffer, VkDeviceSize offset, VkIndexType indexType) |
Alexis Hetu | a9999ce | 2018-10-17 08:00:43 -0400 | [diff] [blame] | 1598 | { |
Ben Clayton | 1e610ee | 2019-12-03 11:48:25 +0000 | [diff] [blame] | 1599 | addCommand<::CmdIndexBufferBind>(buffer, offset, indexType); |
Alexis Hetu | a9999ce | 2018-10-17 08:00:43 -0400 | [diff] [blame] | 1600 | } |
| 1601 | |
| 1602 | void CommandBuffer::dispatch(uint32_t groupCountX, uint32_t groupCountY, uint32_t groupCountZ) |
| 1603 | { |
Ben Clayton | 1e610ee | 2019-12-03 11:48:25 +0000 | [diff] [blame] | 1604 | addCommand<::CmdDispatch>(0, 0, 0, groupCountX, groupCountY, groupCountZ); |
Alexis Hetu | a9999ce | 2018-10-17 08:00:43 -0400 | [diff] [blame] | 1605 | } |
| 1606 | |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 1607 | void CommandBuffer::dispatchIndirect(Buffer *buffer, VkDeviceSize offset) |
Alexis Hetu | a9999ce | 2018-10-17 08:00:43 -0400 | [diff] [blame] | 1608 | { |
Ben Clayton | 1e610ee | 2019-12-03 11:48:25 +0000 | [diff] [blame] | 1609 | addCommand<::CmdDispatchIndirect>(buffer, offset); |
Alexis Hetu | a9999ce | 2018-10-17 08:00:43 -0400 | [diff] [blame] | 1610 | } |
| 1611 | |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 1612 | void CommandBuffer::copyBuffer(const Buffer *srcBuffer, Buffer *dstBuffer, uint32_t regionCount, const VkBufferCopy *pRegions) |
Alexis Hetu | a9999ce | 2018-10-17 08:00:43 -0400 | [diff] [blame] | 1613 | { |
Alexis Hetu | bb0a7f0 | 2018-12-14 16:50:43 -0500 | [diff] [blame] | 1614 | ASSERT(state == RECORDING); |
| 1615 | |
| 1616 | for(uint32_t i = 0; i < regionCount; i++) |
| 1617 | { |
Nicolas Capens | be1a9ac | 2020-07-09 14:50:52 -0400 | [diff] [blame] | 1618 | addCommand<::CmdCopyBuffer>(srcBuffer, dstBuffer, pRegions[i]); |
Alexis Hetu | bb0a7f0 | 2018-12-14 16:50:43 -0500 | [diff] [blame] | 1619 | } |
Alexis Hetu | a9999ce | 2018-10-17 08:00:43 -0400 | [diff] [blame] | 1620 | } |
| 1621 | |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 1622 | void CommandBuffer::copyImage(const Image *srcImage, VkImageLayout srcImageLayout, Image *dstImage, VkImageLayout dstImageLayout, |
| 1623 | uint32_t regionCount, const VkImageCopy *pRegions) |
Alexis Hetu | a9999ce | 2018-10-17 08:00:43 -0400 | [diff] [blame] | 1624 | { |
Alexis Hetu | 09056de | 2018-12-07 12:40:00 -0500 | [diff] [blame] | 1625 | ASSERT(state == RECORDING); |
| 1626 | ASSERT(srcImageLayout == VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL || |
| 1627 | srcImageLayout == VK_IMAGE_LAYOUT_GENERAL); |
| 1628 | ASSERT(dstImageLayout == VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL || |
| 1629 | dstImageLayout == VK_IMAGE_LAYOUT_GENERAL); |
| 1630 | |
| 1631 | for(uint32_t i = 0; i < regionCount; i++) |
| 1632 | { |
Nicolas Capens | be1a9ac | 2020-07-09 14:50:52 -0400 | [diff] [blame] | 1633 | addCommand<::CmdCopyImage>(srcImage, dstImage, pRegions[i]); |
Alexis Hetu | 09056de | 2018-12-07 12:40:00 -0500 | [diff] [blame] | 1634 | } |
Alexis Hetu | a9999ce | 2018-10-17 08:00:43 -0400 | [diff] [blame] | 1635 | } |
| 1636 | |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 1637 | void CommandBuffer::blitImage(const Image *srcImage, VkImageLayout srcImageLayout, Image *dstImage, VkImageLayout dstImageLayout, |
| 1638 | uint32_t regionCount, const VkImageBlit *pRegions, VkFilter filter) |
Alexis Hetu | a9999ce | 2018-10-17 08:00:43 -0400 | [diff] [blame] | 1639 | { |
Alexis Hetu | 809d011 | 2018-12-17 17:00:28 -0500 | [diff] [blame] | 1640 | ASSERT(state == RECORDING); |
| 1641 | ASSERT(srcImageLayout == VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL || |
| 1642 | srcImageLayout == VK_IMAGE_LAYOUT_GENERAL); |
| 1643 | ASSERT(dstImageLayout == VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL || |
| 1644 | dstImageLayout == VK_IMAGE_LAYOUT_GENERAL); |
| 1645 | |
| 1646 | for(uint32_t i = 0; i < regionCount; i++) |
| 1647 | { |
Ben Clayton | 1e610ee | 2019-12-03 11:48:25 +0000 | [diff] [blame] | 1648 | addCommand<::CmdBlitImage>(srcImage, dstImage, pRegions[i], filter); |
Alexis Hetu | 809d011 | 2018-12-17 17:00:28 -0500 | [diff] [blame] | 1649 | } |
Alexis Hetu | a9999ce | 2018-10-17 08:00:43 -0400 | [diff] [blame] | 1650 | } |
| 1651 | |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 1652 | void CommandBuffer::copyBufferToImage(Buffer *srcBuffer, Image *dstImage, VkImageLayout dstImageLayout, |
| 1653 | uint32_t regionCount, const VkBufferImageCopy *pRegions) |
Alexis Hetu | a9999ce | 2018-10-17 08:00:43 -0400 | [diff] [blame] | 1654 | { |
Alexis Hetu | 09056de | 2018-12-07 12:40:00 -0500 | [diff] [blame] | 1655 | ASSERT(state == RECORDING); |
| 1656 | |
| 1657 | for(uint32_t i = 0; i < regionCount; i++) |
| 1658 | { |
Nicolas Capens | be1a9ac | 2020-07-09 14:50:52 -0400 | [diff] [blame] | 1659 | addCommand<::CmdCopyBufferToImage>(srcBuffer, dstImage, pRegions[i]); |
Alexis Hetu | 09056de | 2018-12-07 12:40:00 -0500 | [diff] [blame] | 1660 | } |
Alexis Hetu | a9999ce | 2018-10-17 08:00:43 -0400 | [diff] [blame] | 1661 | } |
| 1662 | |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 1663 | void CommandBuffer::copyImageToBuffer(Image *srcImage, VkImageLayout srcImageLayout, Buffer *dstBuffer, |
| 1664 | uint32_t regionCount, const VkBufferImageCopy *pRegions) |
Alexis Hetu | a9999ce | 2018-10-17 08:00:43 -0400 | [diff] [blame] | 1665 | { |
Alexis Hetu | 09056de | 2018-12-07 12:40:00 -0500 | [diff] [blame] | 1666 | ASSERT(state == RECORDING); |
Chris Forbes | a2457f7 | 2019-05-04 13:34:32 -0700 | [diff] [blame] | 1667 | 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] | 1668 | |
| 1669 | for(uint32_t i = 0; i < regionCount; i++) |
| 1670 | { |
Nicolas Capens | be1a9ac | 2020-07-09 14:50:52 -0400 | [diff] [blame] | 1671 | addCommand<::CmdCopyImageToBuffer>(srcImage, dstBuffer, pRegions[i]); |
Alexis Hetu | 072dc0d | 2018-10-31 11:41:25 -0400 | [diff] [blame] | 1672 | } |
Alexis Hetu | a9999ce | 2018-10-17 08:00:43 -0400 | [diff] [blame] | 1673 | } |
| 1674 | |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 1675 | void CommandBuffer::updateBuffer(Buffer *dstBuffer, VkDeviceSize dstOffset, VkDeviceSize dataSize, const void *pData) |
Alexis Hetu | a9999ce | 2018-10-17 08:00:43 -0400 | [diff] [blame] | 1676 | { |
Alexis Hetu | 7fb0b73 | 2019-02-07 13:50:10 -0500 | [diff] [blame] | 1677 | ASSERT(state == RECORDING); |
| 1678 | |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 1679 | addCommand<::CmdUpdateBuffer>(dstBuffer, dstOffset, dataSize, reinterpret_cast<const uint8_t *>(pData)); |
Alexis Hetu | a9999ce | 2018-10-17 08:00:43 -0400 | [diff] [blame] | 1680 | } |
| 1681 | |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 1682 | void CommandBuffer::fillBuffer(Buffer *dstBuffer, VkDeviceSize dstOffset, VkDeviceSize size, uint32_t data) |
Alexis Hetu | a9999ce | 2018-10-17 08:00:43 -0400 | [diff] [blame] | 1683 | { |
Alexis Hetu | 7fb0b73 | 2019-02-07 13:50:10 -0500 | [diff] [blame] | 1684 | ASSERT(state == RECORDING); |
| 1685 | |
Ben Clayton | 1e610ee | 2019-12-03 11:48:25 +0000 | [diff] [blame] | 1686 | addCommand<::CmdFillBuffer>(dstBuffer, dstOffset, size, data); |
Alexis Hetu | a9999ce | 2018-10-17 08:00:43 -0400 | [diff] [blame] | 1687 | } |
| 1688 | |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 1689 | void CommandBuffer::clearColorImage(Image *image, VkImageLayout imageLayout, const VkClearColorValue *pColor, |
| 1690 | uint32_t rangeCount, const VkImageSubresourceRange *pRanges) |
Alexis Hetu | a9999ce | 2018-10-17 08:00:43 -0400 | [diff] [blame] | 1691 | { |
Alexis Hetu | f14ed32 | 2019-01-16 15:54:55 -0500 | [diff] [blame] | 1692 | ASSERT(state == RECORDING); |
| 1693 | |
| 1694 | for(uint32_t i = 0; i < rangeCount; i++) |
| 1695 | { |
Ben Clayton | 1e610ee | 2019-12-03 11:48:25 +0000 | [diff] [blame] | 1696 | addCommand<::CmdClearColorImage>(image, *pColor, pRanges[i]); |
Alexis Hetu | f14ed32 | 2019-01-16 15:54:55 -0500 | [diff] [blame] | 1697 | } |
Alexis Hetu | a9999ce | 2018-10-17 08:00:43 -0400 | [diff] [blame] | 1698 | } |
| 1699 | |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 1700 | void CommandBuffer::clearDepthStencilImage(Image *image, VkImageLayout imageLayout, const VkClearDepthStencilValue *pDepthStencil, |
| 1701 | uint32_t rangeCount, const VkImageSubresourceRange *pRanges) |
Alexis Hetu | a9999ce | 2018-10-17 08:00:43 -0400 | [diff] [blame] | 1702 | { |
Alexis Hetu | 7ca9f4a | 2019-01-17 14:51:43 -0500 | [diff] [blame] | 1703 | ASSERT(state == RECORDING); |
| 1704 | |
| 1705 | for(uint32_t i = 0; i < rangeCount; i++) |
| 1706 | { |
Ben Clayton | 1e610ee | 2019-12-03 11:48:25 +0000 | [diff] [blame] | 1707 | addCommand<::CmdClearDepthStencilImage>(image, *pDepthStencil, pRanges[i]); |
Alexis Hetu | 7ca9f4a | 2019-01-17 14:51:43 -0500 | [diff] [blame] | 1708 | } |
Alexis Hetu | a9999ce | 2018-10-17 08:00:43 -0400 | [diff] [blame] | 1709 | } |
| 1710 | |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 1711 | void CommandBuffer::clearAttachments(uint32_t attachmentCount, const VkClearAttachment *pAttachments, |
| 1712 | uint32_t rectCount, const VkClearRect *pRects) |
Alexis Hetu | a9999ce | 2018-10-17 08:00:43 -0400 | [diff] [blame] | 1713 | { |
Alexis Hetu | 1cd31ea | 2019-01-17 17:14:57 -0500 | [diff] [blame] | 1714 | ASSERT(state == RECORDING); |
| 1715 | |
| 1716 | for(uint32_t i = 0; i < attachmentCount; i++) |
| 1717 | { |
| 1718 | for(uint32_t j = 0; j < rectCount; j++) |
| 1719 | { |
Ben Clayton | 1e610ee | 2019-12-03 11:48:25 +0000 | [diff] [blame] | 1720 | addCommand<::CmdClearAttachment>(pAttachments[i], pRects[j]); |
Alexis Hetu | 1cd31ea | 2019-01-17 17:14:57 -0500 | [diff] [blame] | 1721 | } |
| 1722 | } |
Alexis Hetu | a9999ce | 2018-10-17 08:00:43 -0400 | [diff] [blame] | 1723 | } |
| 1724 | |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 1725 | void CommandBuffer::resolveImage(const Image *srcImage, VkImageLayout srcImageLayout, Image *dstImage, VkImageLayout dstImageLayout, |
| 1726 | uint32_t regionCount, const VkImageResolve *pRegions) |
Alexis Hetu | a9999ce | 2018-10-17 08:00:43 -0400 | [diff] [blame] | 1727 | { |
Alexis Hetu | e5e33cd | 2019-04-11 10:24:52 -0400 | [diff] [blame] | 1728 | ASSERT(state == RECORDING); |
| 1729 | ASSERT(srcImageLayout == VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL || |
| 1730 | srcImageLayout == VK_IMAGE_LAYOUT_GENERAL); |
| 1731 | ASSERT(dstImageLayout == VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL || |
| 1732 | dstImageLayout == VK_IMAGE_LAYOUT_GENERAL); |
| 1733 | |
| 1734 | for(uint32_t i = 0; i < regionCount; i++) |
| 1735 | { |
Ben Clayton | 1e610ee | 2019-12-03 11:48:25 +0000 | [diff] [blame] | 1736 | addCommand<::CmdResolveImage>(srcImage, dstImage, pRegions[i]); |
Alexis Hetu | e5e33cd | 2019-04-11 10:24:52 -0400 | [diff] [blame] | 1737 | } |
Alexis Hetu | a9999ce | 2018-10-17 08:00:43 -0400 | [diff] [blame] | 1738 | } |
| 1739 | |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 1740 | void CommandBuffer::setEvent(Event *event, VkPipelineStageFlags stageMask) |
Alexis Hetu | a9999ce | 2018-10-17 08:00:43 -0400 | [diff] [blame] | 1741 | { |
Alexis Hetu | 3f5a479 | 2019-02-01 17:49:55 -0500 | [diff] [blame] | 1742 | ASSERT(state == RECORDING); |
| 1743 | |
Ben Clayton | 1e610ee | 2019-12-03 11:48:25 +0000 | [diff] [blame] | 1744 | addCommand<::CmdSignalEvent>(event, stageMask); |
Alexis Hetu | a9999ce | 2018-10-17 08:00:43 -0400 | [diff] [blame] | 1745 | } |
| 1746 | |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 1747 | void CommandBuffer::resetEvent(Event *event, VkPipelineStageFlags stageMask) |
Alexis Hetu | a9999ce | 2018-10-17 08:00:43 -0400 | [diff] [blame] | 1748 | { |
Alexis Hetu | 3f5a479 | 2019-02-01 17:49:55 -0500 | [diff] [blame] | 1749 | ASSERT(state == RECORDING); |
| 1750 | |
Ben Clayton | 1e610ee | 2019-12-03 11:48:25 +0000 | [diff] [blame] | 1751 | addCommand<::CmdResetEvent>(event, stageMask); |
Alexis Hetu | a9999ce | 2018-10-17 08:00:43 -0400 | [diff] [blame] | 1752 | } |
| 1753 | |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 1754 | void CommandBuffer::waitEvents(uint32_t eventCount, const VkEvent *pEvents, VkPipelineStageFlags srcStageMask, |
| 1755 | VkPipelineStageFlags dstStageMask, uint32_t memoryBarrierCount, const VkMemoryBarrier *pMemoryBarriers, |
| 1756 | uint32_t bufferMemoryBarrierCount, const VkBufferMemoryBarrier *pBufferMemoryBarriers, |
| 1757 | uint32_t imageMemoryBarrierCount, const VkImageMemoryBarrier *pImageMemoryBarriers) |
Alexis Hetu | a9999ce | 2018-10-17 08:00:43 -0400 | [diff] [blame] | 1758 | { |
Alexis Hetu | 9041bb7 | 2019-03-15 14:45:45 -0400 | [diff] [blame] | 1759 | ASSERT(state == RECORDING); |
| 1760 | |
| 1761 | // TODO(b/117835459): Since we always do a full barrier, all memory barrier related arguments are ignored |
| 1762 | |
| 1763 | // Note: srcStageMask and dstStageMask are currently ignored |
| 1764 | for(uint32_t i = 0; i < eventCount; i++) |
| 1765 | { |
Ben Clayton | 1e610ee | 2019-12-03 11:48:25 +0000 | [diff] [blame] | 1766 | addCommand<::CmdWaitEvent>(vk::Cast(pEvents[i])); |
Alexis Hetu | 9041bb7 | 2019-03-15 14:45:45 -0400 | [diff] [blame] | 1767 | } |
Alexis Hetu | a9999ce | 2018-10-17 08:00:43 -0400 | [diff] [blame] | 1768 | } |
| 1769 | |
| 1770 | void CommandBuffer::draw(uint32_t vertexCount, uint32_t instanceCount, uint32_t firstVertex, uint32_t firstInstance) |
| 1771 | { |
Ben Clayton | 1e610ee | 2019-12-03 11:48:25 +0000 | [diff] [blame] | 1772 | addCommand<::CmdDraw>(vertexCount, instanceCount, firstVertex, firstInstance); |
Alexis Hetu | a9999ce | 2018-10-17 08:00:43 -0400 | [diff] [blame] | 1773 | } |
| 1774 | |
| 1775 | void CommandBuffer::drawIndexed(uint32_t indexCount, uint32_t instanceCount, uint32_t firstIndex, int32_t vertexOffset, uint32_t firstInstance) |
| 1776 | { |
Ben Clayton | 1e610ee | 2019-12-03 11:48:25 +0000 | [diff] [blame] | 1777 | addCommand<::CmdDrawIndexed>(indexCount, instanceCount, firstIndex, vertexOffset, firstInstance); |
Alexis Hetu | a9999ce | 2018-10-17 08:00:43 -0400 | [diff] [blame] | 1778 | } |
| 1779 | |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 1780 | void CommandBuffer::drawIndirect(Buffer *buffer, VkDeviceSize offset, uint32_t drawCount, uint32_t stride) |
Alexis Hetu | a9999ce | 2018-10-17 08:00:43 -0400 | [diff] [blame] | 1781 | { |
Ben Clayton | 1e610ee | 2019-12-03 11:48:25 +0000 | [diff] [blame] | 1782 | addCommand<::CmdDrawIndirect>(buffer, offset, drawCount, stride); |
Alexis Hetu | a9999ce | 2018-10-17 08:00:43 -0400 | [diff] [blame] | 1783 | } |
| 1784 | |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 1785 | void CommandBuffer::drawIndexedIndirect(Buffer *buffer, VkDeviceSize offset, uint32_t drawCount, uint32_t stride) |
Alexis Hetu | a9999ce | 2018-10-17 08:00:43 -0400 | [diff] [blame] | 1786 | { |
Ben Clayton | 1e610ee | 2019-12-03 11:48:25 +0000 | [diff] [blame] | 1787 | addCommand<::CmdDrawIndexedIndirect>(buffer, offset, drawCount, stride); |
Alexis Hetu | a9999ce | 2018-10-17 08:00:43 -0400 | [diff] [blame] | 1788 | } |
| 1789 | |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 1790 | void CommandBuffer::submit(CommandBuffer::ExecutionState &executionState) |
Alexis Hetu | a9999ce | 2018-10-17 08:00:43 -0400 | [diff] [blame] | 1791 | { |
| 1792 | // Perform recorded work |
| 1793 | state = PENDING; |
| 1794 | |
Ben Clayton | a4e06ca | 2019-12-03 12:38:14 +0000 | [diff] [blame] | 1795 | #ifdef ENABLE_VK_DEBUGGER |
| 1796 | std::shared_ptr<vk::dbg::Thread> debuggerThread; |
| 1797 | auto debuggerContext = device->getDebuggerContext(); |
| 1798 | if(debuggerContext) |
| 1799 | { |
| 1800 | auto lock = debuggerContext->lock(); |
| 1801 | debuggerThread = lock.currentThread(); |
| 1802 | debuggerThread->setName("vkQueue processor"); |
| 1803 | debuggerThread->enter(lock, debuggerFile, "vkCommandBuffer::submit"); |
| 1804 | lock.unlock(); |
| 1805 | } |
| 1806 | defer(if(debuggerThread) { debuggerThread->exit(); }); |
| 1807 | int line = 1; |
| 1808 | #endif // ENABLE_VK_DEBUGGER |
| 1809 | |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 1810 | for(auto &command : *commands) |
Alexis Hetu | 072dc0d | 2018-10-31 11:41:25 -0400 | [diff] [blame] | 1811 | { |
Ben Clayton | a4e06ca | 2019-12-03 12:38:14 +0000 | [diff] [blame] | 1812 | #ifdef ENABLE_VK_DEBUGGER |
| 1813 | if(debuggerThread) |
| 1814 | { |
Ben Clayton | 694e214 | 2020-04-30 16:46:53 +0100 | [diff] [blame] | 1815 | debuggerThread->update(true, [&](vk::dbg::Frame &frame) { |
Ben Clayton | 3775f6d | 2020-01-08 11:51:34 +0000 | [diff] [blame] | 1816 | frame.location = { debuggerFile, line++, 0 }; |
| 1817 | }); |
Ben Clayton | a4e06ca | 2019-12-03 12:38:14 +0000 | [diff] [blame] | 1818 | } |
| 1819 | #endif // ENABLE_VK_DEBUGGER |
| 1820 | |
Alexis Hetu | 9bc7a81 | 2018-12-07 16:13:34 -0500 | [diff] [blame] | 1821 | command->play(executionState); |
Alexis Hetu | 072dc0d | 2018-10-31 11:41:25 -0400 | [diff] [blame] | 1822 | } |
Alexis Hetu | a9999ce | 2018-10-17 08:00:43 -0400 | [diff] [blame] | 1823 | |
| 1824 | // After work is completed |
| 1825 | state = EXECUTABLE; |
| 1826 | } |
| 1827 | |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 1828 | void CommandBuffer::submitSecondary(CommandBuffer::ExecutionState &executionState) const |
Alexis Hetu | e7b2a05 | 2019-03-18 16:16:36 -0400 | [diff] [blame] | 1829 | { |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 1830 | for(auto &command : *commands) |
Alexis Hetu | e7b2a05 | 2019-03-18 16:16:36 -0400 | [diff] [blame] | 1831 | { |
| 1832 | command->play(executionState); |
| 1833 | } |
| 1834 | } |
| 1835 | |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 1836 | void CommandBuffer::ExecutionState::bindVertexInputs(sw::Context &context, int firstInstance) |
Ben Clayton | 1e610ee | 2019-12-03 11:48:25 +0000 | [diff] [blame] | 1837 | { |
| 1838 | for(uint32_t i = 0; i < MAX_VERTEX_INPUT_BINDINGS; i++) |
| 1839 | { |
| 1840 | auto &attrib = context.input[i]; |
Alexis Hetu | b766e5e | 2020-01-20 11:40:28 -0500 | [diff] [blame] | 1841 | if(attrib.format != VK_FORMAT_UNDEFINED) |
Ben Clayton | 1e610ee | 2019-12-03 11:48:25 +0000 | [diff] [blame] | 1842 | { |
| 1843 | const auto &vertexInput = vertexInputBindings[attrib.binding]; |
| 1844 | VkDeviceSize offset = attrib.offset + vertexInput.offset + |
| 1845 | attrib.instanceStride * firstInstance; |
| 1846 | attrib.buffer = vertexInput.buffer ? vertexInput.buffer->getOffsetPointer(offset) : nullptr; |
| 1847 | |
| 1848 | VkDeviceSize size = vertexInput.buffer ? vertexInput.buffer->getSize() : 0; |
| 1849 | attrib.robustnessSize = (size > offset) ? size - offset : 0; |
| 1850 | } |
| 1851 | } |
| 1852 | } |
| 1853 | |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 1854 | void CommandBuffer::ExecutionState::bindAttachments(sw::Context &context) |
Ben Clayton | 1e610ee | 2019-12-03 11:48:25 +0000 | [diff] [blame] | 1855 | { |
| 1856 | // Binds all the attachments for the current subpass |
| 1857 | // Ideally this would be performed by BeginRenderPass and NextSubpass, but |
| 1858 | // there is too much stomping of the renderer's state by setContext() in |
| 1859 | // draws. |
| 1860 | |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 1861 | auto const &subpass = renderPass->getSubpass(subpassIndex); |
Ben Clayton | 1e610ee | 2019-12-03 11:48:25 +0000 | [diff] [blame] | 1862 | |
Nicolas Capens | 81bc9d9 | 2019-12-16 15:05:57 -0500 | [diff] [blame] | 1863 | for(auto i = 0u; i < subpass.colorAttachmentCount; i++) |
Ben Clayton | 1e610ee | 2019-12-03 11:48:25 +0000 | [diff] [blame] | 1864 | { |
| 1865 | auto attachmentReference = subpass.pColorAttachments[i]; |
Nicolas Capens | 81bc9d9 | 2019-12-16 15:05:57 -0500 | [diff] [blame] | 1866 | if(attachmentReference.attachment != VK_ATTACHMENT_UNUSED) |
Ben Clayton | 1e610ee | 2019-12-03 11:48:25 +0000 | [diff] [blame] | 1867 | { |
| 1868 | context.renderTarget[i] = renderPassFramebuffer->getAttachment(attachmentReference.attachment); |
| 1869 | } |
| 1870 | } |
| 1871 | |
| 1872 | auto attachmentReference = subpass.pDepthStencilAttachment; |
Nicolas Capens | 81bc9d9 | 2019-12-16 15:05:57 -0500 | [diff] [blame] | 1873 | if(attachmentReference && attachmentReference->attachment != VK_ATTACHMENT_UNUSED) |
Ben Clayton | 1e610ee | 2019-12-03 11:48:25 +0000 | [diff] [blame] | 1874 | { |
| 1875 | auto attachment = renderPassFramebuffer->getAttachment(attachmentReference->attachment); |
Nicolas Capens | 81bc9d9 | 2019-12-16 15:05:57 -0500 | [diff] [blame] | 1876 | if(attachment->hasDepthAspect()) |
Ben Clayton | 1e610ee | 2019-12-03 11:48:25 +0000 | [diff] [blame] | 1877 | { |
| 1878 | context.depthBuffer = attachment; |
| 1879 | } |
Nicolas Capens | 81bc9d9 | 2019-12-16 15:05:57 -0500 | [diff] [blame] | 1880 | if(attachment->hasStencilAspect()) |
Ben Clayton | 1e610ee | 2019-12-03 11:48:25 +0000 | [diff] [blame] | 1881 | { |
| 1882 | context.stencilBuffer = attachment; |
| 1883 | } |
| 1884 | } |
| 1885 | } |
| 1886 | |
Nicolas Capens | 157ba26 | 2019-12-10 17:49:14 -0500 | [diff] [blame] | 1887 | } // namespace vk |