Jamie Madill | 1f46bc1 | 2018-02-20 16:09:43 -0500 | [diff] [blame] | 1 | // |
| 2 | // Copyright 2017 The ANGLE Project Authors. All rights reserved. |
| 3 | // Use of this source code is governed by a BSD-style license that can be |
| 4 | // found in the LICENSE file. |
| 5 | // |
| 6 | // CommandGraph: |
| 7 | // Deferred work constructed by GL calls, that will later be flushed to Vulkan. |
| 8 | // |
| 9 | |
| 10 | #include "libANGLE/renderer/vulkan/CommandGraph.h" |
| 11 | |
Jamie Madill | 0da73fe | 2018-10-02 09:31:39 -0400 | [diff] [blame] | 12 | #include <iostream> |
| 13 | |
Jamie Madill | 1f46bc1 | 2018-02-20 16:09:43 -0500 | [diff] [blame] | 14 | #include "libANGLE/renderer/vulkan/RenderTargetVk.h" |
| 15 | #include "libANGLE/renderer/vulkan/RendererVk.h" |
| 16 | #include "libANGLE/renderer/vulkan/vk_format_utils.h" |
Jamie Madill | 26084d0 | 2018-04-09 13:44:04 -0400 | [diff] [blame] | 17 | #include "libANGLE/renderer/vulkan/vk_helpers.h" |
Jamie Madill | 1f46bc1 | 2018-02-20 16:09:43 -0500 | [diff] [blame] | 18 | |
| 19 | namespace rx |
| 20 | { |
Jamie Madill | 1f46bc1 | 2018-02-20 16:09:43 -0500 | [diff] [blame] | 21 | namespace vk |
| 22 | { |
Jamie Madill | 1f46bc1 | 2018-02-20 16:09:43 -0500 | [diff] [blame] | 23 | namespace |
| 24 | { |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 25 | angle::Result InitAndBeginCommandBuffer(vk::Context *context, |
| 26 | const CommandPool &commandPool, |
| 27 | const VkCommandBufferInheritanceInfo &inheritanceInfo, |
| 28 | VkCommandBufferUsageFlags flags, |
| 29 | CommandBuffer *commandBuffer) |
Jamie Madill | 1f46bc1 | 2018-02-20 16:09:43 -0500 | [diff] [blame] | 30 | { |
| 31 | ASSERT(!commandBuffer->valid()); |
| 32 | |
Shahbaz Youssefi | 06270c9 | 2018-10-03 17:00:25 -0400 | [diff] [blame] | 33 | VkCommandBufferAllocateInfo createInfo = {}; |
Jamie Madill | 1f46bc1 | 2018-02-20 16:09:43 -0500 | [diff] [blame] | 34 | createInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
Jamie Madill | 1f46bc1 | 2018-02-20 16:09:43 -0500 | [diff] [blame] | 35 | createInfo.commandPool = commandPool.getHandle(); |
| 36 | createInfo.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY; |
| 37 | createInfo.commandBufferCount = 1; |
| 38 | |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 39 | ANGLE_TRY(commandBuffer->init(context, createInfo)); |
Jamie Madill | 1f46bc1 | 2018-02-20 16:09:43 -0500 | [diff] [blame] | 40 | |
Shahbaz Youssefi | 06270c9 | 2018-10-03 17:00:25 -0400 | [diff] [blame] | 41 | VkCommandBufferBeginInfo beginInfo = {}; |
Jamie Madill | 1f46bc1 | 2018-02-20 16:09:43 -0500 | [diff] [blame] | 42 | beginInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
Jamie Madill | 1f46bc1 | 2018-02-20 16:09:43 -0500 | [diff] [blame] | 43 | beginInfo.flags = flags | VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT; |
| 44 | beginInfo.pInheritanceInfo = &inheritanceInfo; |
| 45 | |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 46 | ANGLE_TRY(commandBuffer->begin(context, beginInfo)); |
| 47 | return angle::Result::Continue(); |
Jamie Madill | 1f46bc1 | 2018-02-20 16:09:43 -0500 | [diff] [blame] | 48 | } |
| 49 | |
Jamie Madill | 0da73fe | 2018-10-02 09:31:39 -0400 | [diff] [blame] | 50 | const char *GetResourceTypeName(CommandGraphResourceType resourceType) |
| 51 | { |
| 52 | switch (resourceType) |
| 53 | { |
| 54 | case CommandGraphResourceType::Buffer: |
| 55 | return "Buffer"; |
| 56 | case CommandGraphResourceType::Framebuffer: |
| 57 | return "Framebuffer"; |
| 58 | case CommandGraphResourceType::Image: |
| 59 | return "Image"; |
Shahbaz Youssefi | 563fbaa | 2018-10-02 11:22:01 -0400 | [diff] [blame^] | 60 | case CommandGraphResourceType::Query: |
| 61 | return "Query"; |
Jamie Madill | 0da73fe | 2018-10-02 09:31:39 -0400 | [diff] [blame] | 62 | default: |
| 63 | UNREACHABLE(); |
| 64 | return ""; |
| 65 | } |
| 66 | } |
Jamie Madill | 1f46bc1 | 2018-02-20 16:09:43 -0500 | [diff] [blame] | 67 | } // anonymous namespace |
| 68 | |
Jamie Madill | 6c7ab7f | 2018-03-31 14:19:15 -0400 | [diff] [blame] | 69 | // CommandGraphResource implementation. |
Jamie Madill | 0da73fe | 2018-10-02 09:31:39 -0400 | [diff] [blame] | 70 | CommandGraphResource::CommandGraphResource(CommandGraphResourceType resourceType) |
| 71 | : mCurrentWritingNode(nullptr), mResourceType(resourceType) |
Jamie Madill | 6c7ab7f | 2018-03-31 14:19:15 -0400 | [diff] [blame] | 72 | { |
| 73 | } |
| 74 | |
Jamie Madill | 316c606 | 2018-05-29 10:49:45 -0400 | [diff] [blame] | 75 | CommandGraphResource::~CommandGraphResource() = default; |
Jamie Madill | 6c7ab7f | 2018-03-31 14:19:15 -0400 | [diff] [blame] | 76 | |
| 77 | void CommandGraphResource::updateQueueSerial(Serial queueSerial) |
| 78 | { |
| 79 | ASSERT(queueSerial >= mStoredQueueSerial); |
| 80 | |
| 81 | if (queueSerial > mStoredQueueSerial) |
| 82 | { |
| 83 | mCurrentWritingNode = nullptr; |
| 84 | mCurrentReadingNodes.clear(); |
| 85 | mStoredQueueSerial = queueSerial; |
| 86 | } |
| 87 | } |
| 88 | |
Jamie Madill | c57ee25 | 2018-05-30 19:53:48 -0400 | [diff] [blame] | 89 | bool CommandGraphResource::isResourceInUse(RendererVk *renderer) const |
| 90 | { |
| 91 | return renderer->isSerialInUse(mStoredQueueSerial); |
| 92 | } |
| 93 | |
Shahbaz Youssefi | 563fbaa | 2018-10-02 11:22:01 -0400 | [diff] [blame^] | 94 | bool CommandGraphResource::hasPendingWork(RendererVk *renderer) const |
| 95 | { |
| 96 | // If the renderer has a queue serial higher than the stored one, the command buffers recorded |
| 97 | // by this resource have already been submitted, so there is no pending work. |
| 98 | return mStoredQueueSerial == renderer->getCurrentQueueSerial(); |
| 99 | } |
| 100 | |
Jamie Madill | c57ee25 | 2018-05-30 19:53:48 -0400 | [diff] [blame] | 101 | Serial CommandGraphResource::getStoredQueueSerial() const |
Jamie Madill | 6c7ab7f | 2018-03-31 14:19:15 -0400 | [diff] [blame] | 102 | { |
| 103 | return mStoredQueueSerial; |
| 104 | } |
| 105 | |
Jamie Madill | e2d2270 | 2018-09-19 08:11:48 -0400 | [diff] [blame] | 106 | angle::Result CommandGraphResource::recordCommands(Context *context, |
| 107 | CommandBuffer **commandBufferOut) |
Jamie Madill | 6c7ab7f | 2018-03-31 14:19:15 -0400 | [diff] [blame] | 108 | { |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 109 | updateQueueSerial(context->getRenderer()->getCurrentQueueSerial()); |
Jamie Madill | 5dca651 | 2018-05-30 10:53:51 -0400 | [diff] [blame] | 110 | |
Jamie Madill | e2d2270 | 2018-09-19 08:11:48 -0400 | [diff] [blame] | 111 | if (!hasChildlessWritingNode() || hasStartedRenderPass()) |
Jamie Madill | 316c606 | 2018-05-29 10:49:45 -0400 | [diff] [blame] | 112 | { |
Shahbaz Youssefi | 563fbaa | 2018-10-02 11:22:01 -0400 | [diff] [blame^] | 113 | startNewCommands(context->getRenderer(), CommandGraphNodeFunction::Generic); |
Jamie Madill | e2d2270 | 2018-09-19 08:11:48 -0400 | [diff] [blame] | 114 | return mCurrentWritingNode->beginOutsideRenderPassRecording( |
| 115 | context, context->getRenderer()->getCommandPool(), commandBufferOut); |
Jamie Madill | 316c606 | 2018-05-29 10:49:45 -0400 | [diff] [blame] | 116 | } |
| 117 | |
| 118 | CommandBuffer *outsideRenderPassCommands = mCurrentWritingNode->getOutsideRenderPassCommands(); |
| 119 | if (!outsideRenderPassCommands->valid()) |
| 120 | { |
| 121 | ANGLE_TRY(mCurrentWritingNode->beginOutsideRenderPassRecording( |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 122 | context, context->getRenderer()->getCommandPool(), commandBufferOut)); |
Jamie Madill | 316c606 | 2018-05-29 10:49:45 -0400 | [diff] [blame] | 123 | } |
| 124 | else |
| 125 | { |
| 126 | *commandBufferOut = outsideRenderPassCommands; |
| 127 | } |
| 128 | |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 129 | return angle::Result::Continue(); |
Jamie Madill | 316c606 | 2018-05-29 10:49:45 -0400 | [diff] [blame] | 130 | } |
| 131 | |
Jamie Madill | 5dca651 | 2018-05-30 10:53:51 -0400 | [diff] [blame] | 132 | bool CommandGraphResource::appendToStartedRenderPass(RendererVk *renderer, |
| 133 | CommandBuffer **commandBufferOut) |
Jamie Madill | 316c606 | 2018-05-29 10:49:45 -0400 | [diff] [blame] | 134 | { |
Jamie Madill | 5dca651 | 2018-05-30 10:53:51 -0400 | [diff] [blame] | 135 | updateQueueSerial(renderer->getCurrentQueueSerial()); |
| 136 | if (hasStartedRenderPass()) |
| 137 | { |
| 138 | *commandBufferOut = mCurrentWritingNode->getInsideRenderPassCommands(); |
| 139 | return true; |
| 140 | } |
| 141 | else |
| 142 | { |
| 143 | return false; |
| 144 | } |
Jamie Madill | 316c606 | 2018-05-29 10:49:45 -0400 | [diff] [blame] | 145 | } |
| 146 | |
Jamie Madill | 316c606 | 2018-05-29 10:49:45 -0400 | [diff] [blame] | 147 | const gl::Rectangle &CommandGraphResource::getRenderPassRenderArea() const |
| 148 | { |
| 149 | ASSERT(hasStartedRenderPass()); |
| 150 | return mCurrentWritingNode->getRenderPassRenderArea(); |
| 151 | } |
| 152 | |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 153 | angle::Result CommandGraphResource::beginRenderPass(Context *context, |
| 154 | const Framebuffer &framebuffer, |
| 155 | const gl::Rectangle &renderArea, |
| 156 | const RenderPassDesc &renderPassDesc, |
| 157 | const std::vector<VkClearValue> &clearValues, |
Shahbaz Youssefi | 563fbaa | 2018-10-02 11:22:01 -0400 | [diff] [blame^] | 158 | CommandBuffer **commandBufferOut) |
Jamie Madill | 316c606 | 2018-05-29 10:49:45 -0400 | [diff] [blame] | 159 | { |
Shahbaz Youssefi | 563fbaa | 2018-10-02 11:22:01 -0400 | [diff] [blame^] | 160 | // If a barrier has been inserted in the meantime, stop the command buffer. |
| 161 | if (!hasChildlessWritingNode()) |
| 162 | { |
| 163 | startNewCommands(context->getRenderer(), CommandGraphNodeFunction::Generic); |
| 164 | } |
| 165 | |
Jamie Madill | 316c606 | 2018-05-29 10:49:45 -0400 | [diff] [blame] | 166 | // Hard-code RenderPass to clear the first render target to the current clear value. |
| 167 | // TODO(jmadill): Proper clear value implementation. http://anglebug.com/2361 |
| 168 | mCurrentWritingNode->storeRenderPassInfo(framebuffer, renderArea, renderPassDesc, clearValues); |
| 169 | |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 170 | return mCurrentWritingNode->beginInsideRenderPassRecording(context, commandBufferOut); |
Jamie Madill | 316c606 | 2018-05-29 10:49:45 -0400 | [diff] [blame] | 171 | } |
| 172 | |
Shahbaz Youssefi | 563fbaa | 2018-10-02 11:22:01 -0400 | [diff] [blame^] | 173 | void CommandGraphResource::beginQuery(Context *context, |
| 174 | const QueryPool *queryPool, |
| 175 | uint32_t queryIndex) |
| 176 | { |
| 177 | startNewCommands(context->getRenderer(), CommandGraphNodeFunction::BeginQuery); |
| 178 | mCurrentWritingNode->setQueryPool(queryPool, queryIndex); |
| 179 | } |
| 180 | |
| 181 | void CommandGraphResource::endQuery(Context *context, |
| 182 | const QueryPool *queryPool, |
| 183 | uint32_t queryIndex) |
| 184 | { |
| 185 | startNewCommands(context->getRenderer(), CommandGraphNodeFunction::EndQuery); |
| 186 | mCurrentWritingNode->setQueryPool(queryPool, queryIndex); |
| 187 | } |
| 188 | |
Jamie Madill | e2d2270 | 2018-09-19 08:11:48 -0400 | [diff] [blame] | 189 | void CommandGraphResource::finishCurrentCommands(RendererVk *renderer) |
Jamie Madill | 316c606 | 2018-05-29 10:49:45 -0400 | [diff] [blame] | 190 | { |
Shahbaz Youssefi | 563fbaa | 2018-10-02 11:22:01 -0400 | [diff] [blame^] | 191 | startNewCommands(renderer, CommandGraphNodeFunction::Generic); |
| 192 | } |
| 193 | |
| 194 | void CommandGraphResource::startNewCommands(RendererVk *renderer, CommandGraphNodeFunction function) |
| 195 | { |
| 196 | bool isBarrier = function != CommandGraphNodeFunction::Generic; |
| 197 | CommandGraphNode *newCommands = renderer->getCommandGraph()->allocateNode(isBarrier, function); |
Jamie Madill | 0da73fe | 2018-10-02 09:31:39 -0400 | [diff] [blame] | 198 | newCommands->setDiagnosticInfo(mResourceType, reinterpret_cast<uintptr_t>(this)); |
Jamie Madill | 86ce210 | 2018-05-22 11:54:42 -0400 | [diff] [blame] | 199 | onWriteImpl(newCommands, renderer->getCurrentQueueSerial()); |
Jamie Madill | 316c606 | 2018-05-29 10:49:45 -0400 | [diff] [blame] | 200 | } |
| 201 | |
| 202 | void CommandGraphResource::addWriteDependency(CommandGraphResource *writingResource) |
| 203 | { |
| 204 | CommandGraphNode *writingNode = writingResource->mCurrentWritingNode; |
| 205 | ASSERT(writingNode); |
| 206 | |
Jamie Madill | c57ee25 | 2018-05-30 19:53:48 -0400 | [diff] [blame] | 207 | onWriteImpl(writingNode, writingResource->getStoredQueueSerial()); |
Jamie Madill | 316c606 | 2018-05-29 10:49:45 -0400 | [diff] [blame] | 208 | } |
| 209 | |
| 210 | void CommandGraphResource::onWriteImpl(CommandGraphNode *writingNode, Serial currentSerial) |
| 211 | { |
| 212 | updateQueueSerial(currentSerial); |
Jamie Madill | 6c7ab7f | 2018-03-31 14:19:15 -0400 | [diff] [blame] | 213 | |
Jamie Madill | 9cceac4 | 2018-03-31 14:19:16 -0400 | [diff] [blame] | 214 | // Make sure any open reads and writes finish before we execute 'writingNode'. |
Jamie Madill | 6c7ab7f | 2018-03-31 14:19:15 -0400 | [diff] [blame] | 215 | if (!mCurrentReadingNodes.empty()) |
| 216 | { |
Shahbaz Youssefi | 563fbaa | 2018-10-02 11:22:01 -0400 | [diff] [blame^] | 217 | CommandGraphNode::SetHappensBeforeDependencies(mCurrentReadingNodes.data(), |
| 218 | mCurrentReadingNodes.size(), writingNode); |
Jamie Madill | 6c7ab7f | 2018-03-31 14:19:15 -0400 | [diff] [blame] | 219 | mCurrentReadingNodes.clear(); |
| 220 | } |
| 221 | |
| 222 | if (mCurrentWritingNode && mCurrentWritingNode != writingNode) |
| 223 | { |
| 224 | CommandGraphNode::SetHappensBeforeDependency(mCurrentWritingNode, writingNode); |
| 225 | } |
| 226 | |
| 227 | mCurrentWritingNode = writingNode; |
| 228 | } |
| 229 | |
Jamie Madill | 316c606 | 2018-05-29 10:49:45 -0400 | [diff] [blame] | 230 | void CommandGraphResource::addReadDependency(CommandGraphResource *readingResource) |
Jamie Madill | 6c7ab7f | 2018-03-31 14:19:15 -0400 | [diff] [blame] | 231 | { |
Jamie Madill | c57ee25 | 2018-05-30 19:53:48 -0400 | [diff] [blame] | 232 | updateQueueSerial(readingResource->getStoredQueueSerial()); |
Jamie Madill | 316c606 | 2018-05-29 10:49:45 -0400 | [diff] [blame] | 233 | |
| 234 | CommandGraphNode *readingNode = readingResource->mCurrentWritingNode; |
| 235 | ASSERT(readingNode); |
Jamie Madill | 9cceac4 | 2018-03-31 14:19:16 -0400 | [diff] [blame] | 236 | |
| 237 | if (hasChildlessWritingNode()) |
Jamie Madill | 6c7ab7f | 2018-03-31 14:19:15 -0400 | [diff] [blame] | 238 | { |
Jamie Madill | 9cceac4 | 2018-03-31 14:19:16 -0400 | [diff] [blame] | 239 | // Ensure 'readingNode' happens after the current writing node. |
| 240 | CommandGraphNode::SetHappensBeforeDependency(mCurrentWritingNode, readingNode); |
| 241 | } |
| 242 | |
| 243 | // Add the read node to the list of nodes currently reading this resource. |
| 244 | mCurrentReadingNodes.push_back(readingNode); |
| 245 | } |
| 246 | |
Jamie Madill | 1f46bc1 | 2018-02-20 16:09:43 -0500 | [diff] [blame] | 247 | // CommandGraphNode implementation. |
Shahbaz Youssefi | 563fbaa | 2018-10-02 11:22:01 -0400 | [diff] [blame^] | 248 | CommandGraphNode::CommandGraphNode(CommandGraphNodeFunction function) |
| 249 | : mRenderPassClearValues{}, |
| 250 | mFunction(function), |
| 251 | mQueryPool(VK_NULL_HANDLE), |
| 252 | mQueryIndex(0), |
| 253 | mHasChildren(false), |
| 254 | mVisitedState(VisitedState::Unvisited) |
Jamie Madill | 1f46bc1 | 2018-02-20 16:09:43 -0500 | [diff] [blame] | 255 | { |
| 256 | } |
| 257 | |
| 258 | CommandGraphNode::~CommandGraphNode() |
| 259 | { |
| 260 | mRenderPassFramebuffer.setHandle(VK_NULL_HANDLE); |
| 261 | |
| 262 | // Command buffers are managed by the command pool, so don't need to be freed. |
| 263 | mOutsideRenderPassCommands.releaseHandle(); |
| 264 | mInsideRenderPassCommands.releaseHandle(); |
| 265 | } |
| 266 | |
| 267 | CommandBuffer *CommandGraphNode::getOutsideRenderPassCommands() |
| 268 | { |
| 269 | ASSERT(!mHasChildren); |
| 270 | return &mOutsideRenderPassCommands; |
| 271 | } |
| 272 | |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 273 | angle::Result CommandGraphNode::beginOutsideRenderPassRecording(Context *context, |
| 274 | const CommandPool &commandPool, |
| 275 | CommandBuffer **commandsOut) |
Jamie Madill | 1f46bc1 | 2018-02-20 16:09:43 -0500 | [diff] [blame] | 276 | { |
| 277 | ASSERT(!mHasChildren); |
| 278 | |
Shahbaz Youssefi | 06270c9 | 2018-10-03 17:00:25 -0400 | [diff] [blame] | 279 | VkCommandBufferInheritanceInfo inheritanceInfo = {}; |
Jamie Madill | 1f46bc1 | 2018-02-20 16:09:43 -0500 | [diff] [blame] | 280 | inheritanceInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO; |
Jamie Madill | 1f46bc1 | 2018-02-20 16:09:43 -0500 | [diff] [blame] | 281 | inheritanceInfo.renderPass = VK_NULL_HANDLE; |
| 282 | inheritanceInfo.subpass = 0; |
| 283 | inheritanceInfo.framebuffer = VK_NULL_HANDLE; |
Shahbaz Youssefi | 563fbaa | 2018-10-02 11:22:01 -0400 | [diff] [blame^] | 284 | inheritanceInfo.occlusionQueryEnable = |
| 285 | context->getRenderer()->getPhysicalDeviceFeatures().inheritedQueries; |
Jamie Madill | 1f46bc1 | 2018-02-20 16:09:43 -0500 | [diff] [blame] | 286 | inheritanceInfo.queryFlags = 0; |
| 287 | inheritanceInfo.pipelineStatistics = 0; |
| 288 | |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 289 | ANGLE_TRY(InitAndBeginCommandBuffer(context, commandPool, inheritanceInfo, 0, |
Jamie Madill | 1f46bc1 | 2018-02-20 16:09:43 -0500 | [diff] [blame] | 290 | &mOutsideRenderPassCommands)); |
| 291 | |
| 292 | *commandsOut = &mOutsideRenderPassCommands; |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 293 | return angle::Result::Continue(); |
Jamie Madill | 1f46bc1 | 2018-02-20 16:09:43 -0500 | [diff] [blame] | 294 | } |
| 295 | |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 296 | angle::Result CommandGraphNode::beginInsideRenderPassRecording(Context *context, |
| 297 | CommandBuffer **commandsOut) |
Jamie Madill | 1f46bc1 | 2018-02-20 16:09:43 -0500 | [diff] [blame] | 298 | { |
| 299 | ASSERT(!mHasChildren); |
| 300 | |
| 301 | // Get a compatible RenderPass from the cache so we can initialize the inheritance info. |
Shahbaz Youssefi | 563fbaa | 2018-10-02 11:22:01 -0400 | [diff] [blame^] | 302 | // TODO(jmadill): Support query for compatible/conformant render pass. http://anglebug.com/2361 |
Jamie Madill | 1f46bc1 | 2018-02-20 16:09:43 -0500 | [diff] [blame] | 303 | RenderPass *compatibleRenderPass; |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 304 | ANGLE_TRY(context->getRenderer()->getCompatibleRenderPass(context, mRenderPassDesc, |
| 305 | &compatibleRenderPass)); |
Jamie Madill | 1f46bc1 | 2018-02-20 16:09:43 -0500 | [diff] [blame] | 306 | |
Shahbaz Youssefi | 06270c9 | 2018-10-03 17:00:25 -0400 | [diff] [blame] | 307 | VkCommandBufferInheritanceInfo inheritanceInfo = {}; |
Jamie Madill | 1f46bc1 | 2018-02-20 16:09:43 -0500 | [diff] [blame] | 308 | inheritanceInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO; |
Jamie Madill | 1f46bc1 | 2018-02-20 16:09:43 -0500 | [diff] [blame] | 309 | inheritanceInfo.renderPass = compatibleRenderPass->getHandle(); |
| 310 | inheritanceInfo.subpass = 0; |
| 311 | inheritanceInfo.framebuffer = mRenderPassFramebuffer.getHandle(); |
Shahbaz Youssefi | 563fbaa | 2018-10-02 11:22:01 -0400 | [diff] [blame^] | 312 | inheritanceInfo.occlusionQueryEnable = |
| 313 | context->getRenderer()->getPhysicalDeviceFeatures().inheritedQueries; |
Jamie Madill | 1f46bc1 | 2018-02-20 16:09:43 -0500 | [diff] [blame] | 314 | inheritanceInfo.queryFlags = 0; |
| 315 | inheritanceInfo.pipelineStatistics = 0; |
| 316 | |
| 317 | ANGLE_TRY(InitAndBeginCommandBuffer( |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 318 | context, context->getRenderer()->getCommandPool(), inheritanceInfo, |
Jamie Madill | 1f46bc1 | 2018-02-20 16:09:43 -0500 | [diff] [blame] | 319 | VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT, &mInsideRenderPassCommands)); |
| 320 | |
| 321 | *commandsOut = &mInsideRenderPassCommands; |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 322 | return angle::Result::Continue(); |
Jamie Madill | 1f46bc1 | 2018-02-20 16:09:43 -0500 | [diff] [blame] | 323 | } |
| 324 | |
| 325 | void CommandGraphNode::storeRenderPassInfo(const Framebuffer &framebuffer, |
| 326 | const gl::Rectangle renderArea, |
Jamie Madill | bcf467f | 2018-05-23 09:46:00 -0400 | [diff] [blame] | 327 | const vk::RenderPassDesc &renderPassDesc, |
Jamie Madill | 1f46bc1 | 2018-02-20 16:09:43 -0500 | [diff] [blame] | 328 | const std::vector<VkClearValue> &clearValues) |
| 329 | { |
Jamie Madill | bcf467f | 2018-05-23 09:46:00 -0400 | [diff] [blame] | 330 | mRenderPassDesc = renderPassDesc; |
Jamie Madill | 1f46bc1 | 2018-02-20 16:09:43 -0500 | [diff] [blame] | 331 | mRenderPassFramebuffer.setHandle(framebuffer.getHandle()); |
| 332 | mRenderPassRenderArea = renderArea; |
| 333 | std::copy(clearValues.begin(), clearValues.end(), mRenderPassClearValues.begin()); |
| 334 | } |
| 335 | |
Jamie Madill | 1f46bc1 | 2018-02-20 16:09:43 -0500 | [diff] [blame] | 336 | // static |
| 337 | void CommandGraphNode::SetHappensBeforeDependency(CommandGraphNode *beforeNode, |
| 338 | CommandGraphNode *afterNode) |
| 339 | { |
Jamie Madill | 9cceac4 | 2018-03-31 14:19:16 -0400 | [diff] [blame] | 340 | ASSERT(beforeNode != afterNode && !beforeNode->isChildOf(afterNode)); |
Jamie Madill | 1f46bc1 | 2018-02-20 16:09:43 -0500 | [diff] [blame] | 341 | afterNode->mParents.emplace_back(beforeNode); |
| 342 | beforeNode->setHasChildren(); |
Jamie Madill | 1f46bc1 | 2018-02-20 16:09:43 -0500 | [diff] [blame] | 343 | } |
| 344 | |
| 345 | // static |
Shahbaz Youssefi | 563fbaa | 2018-10-02 11:22:01 -0400 | [diff] [blame^] | 346 | void CommandGraphNode::SetHappensBeforeDependencies(CommandGraphNode **beforeNodes, |
| 347 | size_t beforeNodesCount, |
| 348 | CommandGraphNode *afterNode) |
Jamie Madill | 1f46bc1 | 2018-02-20 16:09:43 -0500 | [diff] [blame] | 349 | { |
Shahbaz Youssefi | 563fbaa | 2018-10-02 11:22:01 -0400 | [diff] [blame^] | 350 | afterNode->mParents.insert(afterNode->mParents.end(), beforeNodes, |
| 351 | beforeNodes + beforeNodesCount); |
Jamie Madill | 1f46bc1 | 2018-02-20 16:09:43 -0500 | [diff] [blame] | 352 | |
| 353 | // TODO(jmadill): is there a faster way to do this? |
Shahbaz Youssefi | 563fbaa | 2018-10-02 11:22:01 -0400 | [diff] [blame^] | 354 | for (size_t i = 0; i < beforeNodesCount; ++i) |
Jamie Madill | 1f46bc1 | 2018-02-20 16:09:43 -0500 | [diff] [blame] | 355 | { |
Shahbaz Youssefi | 563fbaa | 2018-10-02 11:22:01 -0400 | [diff] [blame^] | 356 | beforeNodes[i]->setHasChildren(); |
Jamie Madill | 1f46bc1 | 2018-02-20 16:09:43 -0500 | [diff] [blame] | 357 | |
Shahbaz Youssefi | 563fbaa | 2018-10-02 11:22:01 -0400 | [diff] [blame^] | 358 | ASSERT(beforeNodes[i] != afterNode && !beforeNodes[i]->isChildOf(afterNode)); |
| 359 | } |
| 360 | } |
| 361 | |
| 362 | void CommandGraphNode::SetHappensBeforeDependencies(CommandGraphNode *beforeNode, |
| 363 | CommandGraphNode **afterNodes, |
| 364 | size_t afterNodesCount) |
| 365 | { |
| 366 | for (size_t i = 0; i < afterNodesCount; ++i) |
| 367 | { |
| 368 | SetHappensBeforeDependency(beforeNode, afterNodes[i]); |
Jamie Madill | 1f46bc1 | 2018-02-20 16:09:43 -0500 | [diff] [blame] | 369 | } |
| 370 | } |
| 371 | |
| 372 | bool CommandGraphNode::hasParents() const |
| 373 | { |
| 374 | return !mParents.empty(); |
| 375 | } |
| 376 | |
Shahbaz Youssefi | 563fbaa | 2018-10-02 11:22:01 -0400 | [diff] [blame^] | 377 | void CommandGraphNode::setQueryPool(const QueryPool *queryPool, uint32_t queryIndex) |
| 378 | { |
| 379 | ASSERT(mFunction == CommandGraphNodeFunction::BeginQuery || |
| 380 | mFunction == CommandGraphNodeFunction::EndQuery); |
| 381 | mQueryPool = queryPool->getHandle(); |
| 382 | mQueryIndex = queryIndex; |
| 383 | } |
| 384 | |
Jamie Madill | 1f46bc1 | 2018-02-20 16:09:43 -0500 | [diff] [blame] | 385 | void CommandGraphNode::setHasChildren() |
| 386 | { |
| 387 | mHasChildren = true; |
| 388 | } |
| 389 | |
Jamie Madill | 1f46bc1 | 2018-02-20 16:09:43 -0500 | [diff] [blame] | 390 | // Do not call this in anything but testing code, since it's slow. |
| 391 | bool CommandGraphNode::isChildOf(CommandGraphNode *parent) |
| 392 | { |
| 393 | std::set<CommandGraphNode *> visitedList; |
| 394 | std::vector<CommandGraphNode *> openList; |
| 395 | openList.insert(openList.begin(), mParents.begin(), mParents.end()); |
| 396 | while (!openList.empty()) |
| 397 | { |
| 398 | CommandGraphNode *current = openList.back(); |
| 399 | openList.pop_back(); |
| 400 | if (visitedList.count(current) == 0) |
| 401 | { |
| 402 | if (current == parent) |
| 403 | { |
| 404 | return true; |
| 405 | } |
| 406 | visitedList.insert(current); |
| 407 | openList.insert(openList.end(), current->mParents.begin(), current->mParents.end()); |
| 408 | } |
| 409 | } |
| 410 | |
| 411 | return false; |
| 412 | } |
| 413 | |
| 414 | VisitedState CommandGraphNode::visitedState() const |
| 415 | { |
| 416 | return mVisitedState; |
| 417 | } |
| 418 | |
| 419 | void CommandGraphNode::visitParents(std::vector<CommandGraphNode *> *stack) |
| 420 | { |
| 421 | ASSERT(mVisitedState == VisitedState::Unvisited); |
| 422 | stack->insert(stack->end(), mParents.begin(), mParents.end()); |
| 423 | mVisitedState = VisitedState::Ready; |
| 424 | } |
| 425 | |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 426 | angle::Result CommandGraphNode::visitAndExecute(vk::Context *context, |
| 427 | Serial serial, |
| 428 | RenderPassCache *renderPassCache, |
| 429 | CommandBuffer *primaryCommandBuffer) |
Jamie Madill | 1f46bc1 | 2018-02-20 16:09:43 -0500 | [diff] [blame] | 430 | { |
Shahbaz Youssefi | 563fbaa | 2018-10-02 11:22:01 -0400 | [diff] [blame^] | 431 | switch (mFunction) |
Jamie Madill | 1f46bc1 | 2018-02-20 16:09:43 -0500 | [diff] [blame] | 432 | { |
Shahbaz Youssefi | 563fbaa | 2018-10-02 11:22:01 -0400 | [diff] [blame^] | 433 | case CommandGraphNodeFunction::Generic: |
| 434 | ASSERT(mQueryPool == VK_NULL_HANDLE); |
Jamie Madill | 1f46bc1 | 2018-02-20 16:09:43 -0500 | [diff] [blame] | 435 | |
Shahbaz Youssefi | 563fbaa | 2018-10-02 11:22:01 -0400 | [diff] [blame^] | 436 | if (mOutsideRenderPassCommands.valid()) |
| 437 | { |
| 438 | ANGLE_TRY(mOutsideRenderPassCommands.end(context)); |
| 439 | primaryCommandBuffer->executeCommands(1, &mOutsideRenderPassCommands); |
| 440 | } |
Jamie Madill | 1f46bc1 | 2018-02-20 16:09:43 -0500 | [diff] [blame] | 441 | |
Shahbaz Youssefi | 563fbaa | 2018-10-02 11:22:01 -0400 | [diff] [blame^] | 442 | if (mInsideRenderPassCommands.valid()) |
| 443 | { |
| 444 | // Pull a compatible RenderPass from the cache. |
| 445 | // TODO(jmadill): Insert real ops and layout transitions. |
| 446 | RenderPass *renderPass = nullptr; |
| 447 | ANGLE_TRY(renderPassCache->getCompatibleRenderPass(context, serial, mRenderPassDesc, |
| 448 | &renderPass)); |
Jamie Madill | 1f46bc1 | 2018-02-20 16:09:43 -0500 | [diff] [blame] | 449 | |
Shahbaz Youssefi | 563fbaa | 2018-10-02 11:22:01 -0400 | [diff] [blame^] | 450 | ANGLE_TRY(mInsideRenderPassCommands.end(context)); |
Jamie Madill | 1f46bc1 | 2018-02-20 16:09:43 -0500 | [diff] [blame] | 451 | |
Shahbaz Youssefi | 563fbaa | 2018-10-02 11:22:01 -0400 | [diff] [blame^] | 452 | VkRenderPassBeginInfo beginInfo = {}; |
| 453 | beginInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO; |
| 454 | beginInfo.renderPass = renderPass->getHandle(); |
| 455 | beginInfo.framebuffer = mRenderPassFramebuffer.getHandle(); |
| 456 | beginInfo.renderArea.offset.x = static_cast<uint32_t>(mRenderPassRenderArea.x); |
| 457 | beginInfo.renderArea.offset.y = static_cast<uint32_t>(mRenderPassRenderArea.y); |
| 458 | beginInfo.renderArea.extent.width = |
| 459 | static_cast<uint32_t>(mRenderPassRenderArea.width); |
| 460 | beginInfo.renderArea.extent.height = |
| 461 | static_cast<uint32_t>(mRenderPassRenderArea.height); |
| 462 | beginInfo.clearValueCount = mRenderPassDesc.attachmentCount(); |
| 463 | beginInfo.pClearValues = mRenderPassClearValues.data(); |
| 464 | |
| 465 | primaryCommandBuffer->beginRenderPass( |
| 466 | beginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS); |
| 467 | primaryCommandBuffer->executeCommands(1, &mInsideRenderPassCommands); |
| 468 | primaryCommandBuffer->endRenderPass(); |
| 469 | } |
| 470 | break; |
| 471 | |
| 472 | case CommandGraphNodeFunction::BeginQuery: |
| 473 | ASSERT(!mOutsideRenderPassCommands.valid() && !mInsideRenderPassCommands.valid()); |
| 474 | ASSERT(mQueryPool != VK_NULL_HANDLE); |
| 475 | |
| 476 | primaryCommandBuffer->resetQueryPool(mQueryPool, mQueryIndex, 1); |
| 477 | primaryCommandBuffer->beginQuery(mQueryPool, mQueryIndex, 0); |
| 478 | |
| 479 | break; |
| 480 | |
| 481 | case CommandGraphNodeFunction::EndQuery: |
| 482 | ASSERT(!mOutsideRenderPassCommands.valid() && !mInsideRenderPassCommands.valid()); |
| 483 | ASSERT(mQueryPool != VK_NULL_HANDLE); |
| 484 | |
| 485 | primaryCommandBuffer->endQuery(mQueryPool, mQueryIndex); |
| 486 | |
| 487 | break; |
| 488 | |
| 489 | default: |
| 490 | UNREACHABLE(); |
Jamie Madill | 1f46bc1 | 2018-02-20 16:09:43 -0500 | [diff] [blame] | 491 | } |
| 492 | |
| 493 | mVisitedState = VisitedState::Visited; |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 494 | return angle::Result::Continue(); |
Jamie Madill | 1f46bc1 | 2018-02-20 16:09:43 -0500 | [diff] [blame] | 495 | } |
| 496 | |
Jamie Madill | 0da73fe | 2018-10-02 09:31:39 -0400 | [diff] [blame] | 497 | const std::vector<CommandGraphNode *> &CommandGraphNode::getParentsForDiagnostics() const |
| 498 | { |
| 499 | return mParents; |
| 500 | } |
| 501 | |
| 502 | void CommandGraphNode::setDiagnosticInfo(CommandGraphResourceType resourceType, |
| 503 | uintptr_t resourceID) |
| 504 | { |
| 505 | mResourceType = resourceType; |
| 506 | mResourceID = resourceID; |
| 507 | } |
| 508 | |
Luc Ferron | 14f4817 | 2018-04-11 08:43:28 -0400 | [diff] [blame] | 509 | const gl::Rectangle &CommandGraphNode::getRenderPassRenderArea() const |
| 510 | { |
| 511 | return mRenderPassRenderArea; |
| 512 | } |
| 513 | |
Jamie Madill | 1f46bc1 | 2018-02-20 16:09:43 -0500 | [diff] [blame] | 514 | // CommandGraph implementation. |
Jamie Madill | 0da73fe | 2018-10-02 09:31:39 -0400 | [diff] [blame] | 515 | CommandGraph::CommandGraph(bool enableGraphDiagnostics) |
Shahbaz Youssefi | 563fbaa | 2018-10-02 11:22:01 -0400 | [diff] [blame^] | 516 | : mEnableGraphDiagnostics(enableGraphDiagnostics), mLastBarrierIndex(kInvalidNodeIndex) |
Jamie Madill | 0da73fe | 2018-10-02 09:31:39 -0400 | [diff] [blame] | 517 | { |
| 518 | } |
Jamie Madill | 1f46bc1 | 2018-02-20 16:09:43 -0500 | [diff] [blame] | 519 | |
| 520 | CommandGraph::~CommandGraph() |
| 521 | { |
| 522 | ASSERT(empty()); |
| 523 | } |
| 524 | |
Shahbaz Youssefi | 563fbaa | 2018-10-02 11:22:01 -0400 | [diff] [blame^] | 525 | CommandGraphNode *CommandGraph::allocateNode(bool isBarrier, CommandGraphNodeFunction function) |
Jamie Madill | 1f46bc1 | 2018-02-20 16:09:43 -0500 | [diff] [blame] | 526 | { |
| 527 | // TODO(jmadill): Use a pool allocator for the CPU node allocations. |
Shahbaz Youssefi | 563fbaa | 2018-10-02 11:22:01 -0400 | [diff] [blame^] | 528 | CommandGraphNode *newCommands = new CommandGraphNode(function); |
Jamie Madill | 1f46bc1 | 2018-02-20 16:09:43 -0500 | [diff] [blame] | 529 | mNodes.emplace_back(newCommands); |
Shahbaz Youssefi | 563fbaa | 2018-10-02 11:22:01 -0400 | [diff] [blame^] | 530 | |
| 531 | if (isBarrier) |
| 532 | { |
| 533 | setNewBarrier(newCommands); |
| 534 | } |
| 535 | |
Jamie Madill | 1f46bc1 | 2018-02-20 16:09:43 -0500 | [diff] [blame] | 536 | return newCommands; |
| 537 | } |
| 538 | |
Shahbaz Youssefi | 563fbaa | 2018-10-02 11:22:01 -0400 | [diff] [blame^] | 539 | void CommandGraph::setNewBarrier(CommandGraphNode *newBarrier) |
| 540 | { |
| 541 | size_t previousBarrierIndex = 0; |
| 542 | CommandGraphNode *previousBarrier = getLastBarrierNode(&previousBarrierIndex); |
| 543 | |
| 544 | // Add a dependency from previousBarrier to all nodes in (previousBarrier, newBarrier]. |
| 545 | if (previousBarrier && previousBarrierIndex + 1 < mNodes.size()) |
| 546 | { |
| 547 | size_t afterNodesCount = mNodes.size() - (previousBarrierIndex + 1); |
| 548 | CommandGraphNode::SetHappensBeforeDependencies( |
| 549 | previousBarrier, &mNodes[previousBarrierIndex + 1], afterNodesCount); |
| 550 | } |
| 551 | |
| 552 | // Add a dependency from all nodes in (previousBarrier, newBarrier) to newBarrier. |
| 553 | addDependenciesToNextBarrier(previousBarrierIndex + 1, mNodes.size() - 1, newBarrier); |
| 554 | |
| 555 | mLastBarrierIndex = mNodes.size() - 1; |
| 556 | } |
| 557 | |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 558 | angle::Result CommandGraph::submitCommands(Context *context, |
| 559 | Serial serial, |
| 560 | RenderPassCache *renderPassCache, |
| 561 | CommandPool *commandPool, |
| 562 | CommandBuffer *primaryCommandBufferOut) |
Jamie Madill | 1f46bc1 | 2018-02-20 16:09:43 -0500 | [diff] [blame] | 563 | { |
Shahbaz Youssefi | 563fbaa | 2018-10-02 11:22:01 -0400 | [diff] [blame^] | 564 | size_t previousBarrierIndex = 0; |
| 565 | CommandGraphNode *previousBarrier = getLastBarrierNode(&previousBarrierIndex); |
| 566 | |
| 567 | // Add a dependency from previousBarrier to all nodes in (previousBarrier, end]. |
| 568 | if (previousBarrier && previousBarrierIndex + 1 < mNodes.size()) |
| 569 | { |
| 570 | size_t afterNodesCount = mNodes.size() - (previousBarrierIndex + 1); |
| 571 | CommandGraphNode::SetHappensBeforeDependencies( |
| 572 | previousBarrier, &mNodes[previousBarrierIndex + 1], afterNodesCount); |
| 573 | } |
| 574 | |
Shahbaz Youssefi | 06270c9 | 2018-10-03 17:00:25 -0400 | [diff] [blame] | 575 | VkCommandBufferAllocateInfo primaryInfo = {}; |
Jamie Madill | 1f46bc1 | 2018-02-20 16:09:43 -0500 | [diff] [blame] | 576 | primaryInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
Jamie Madill | 1f46bc1 | 2018-02-20 16:09:43 -0500 | [diff] [blame] | 577 | primaryInfo.commandPool = commandPool->getHandle(); |
| 578 | primaryInfo.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 579 | primaryInfo.commandBufferCount = 1; |
| 580 | |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 581 | ANGLE_TRY(primaryCommandBufferOut->init(context, primaryInfo)); |
Jamie Madill | 1f46bc1 | 2018-02-20 16:09:43 -0500 | [diff] [blame] | 582 | |
| 583 | if (mNodes.empty()) |
| 584 | { |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 585 | return angle::Result::Continue(); |
Jamie Madill | 1f46bc1 | 2018-02-20 16:09:43 -0500 | [diff] [blame] | 586 | } |
| 587 | |
Jamie Madill | 0da73fe | 2018-10-02 09:31:39 -0400 | [diff] [blame] | 588 | if (mEnableGraphDiagnostics) |
| 589 | { |
| 590 | dumpGraphDotFile(std::cout); |
| 591 | } |
| 592 | |
Jamie Madill | 1f46bc1 | 2018-02-20 16:09:43 -0500 | [diff] [blame] | 593 | std::vector<CommandGraphNode *> nodeStack; |
| 594 | |
Shahbaz Youssefi | 06270c9 | 2018-10-03 17:00:25 -0400 | [diff] [blame] | 595 | VkCommandBufferBeginInfo beginInfo = {}; |
Jamie Madill | 1f46bc1 | 2018-02-20 16:09:43 -0500 | [diff] [blame] | 596 | beginInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
Jamie Madill | 1f46bc1 | 2018-02-20 16:09:43 -0500 | [diff] [blame] | 597 | beginInfo.flags = 0; |
| 598 | beginInfo.pInheritanceInfo = nullptr; |
| 599 | |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 600 | ANGLE_TRY(primaryCommandBufferOut->begin(context, beginInfo)); |
Jamie Madill | 1f46bc1 | 2018-02-20 16:09:43 -0500 | [diff] [blame] | 601 | |
| 602 | for (CommandGraphNode *topLevelNode : mNodes) |
| 603 | { |
| 604 | // Only process commands that don't have child commands. The others will be pulled in |
| 605 | // automatically. Also skip commands that have already been visited. |
| 606 | if (topLevelNode->hasChildren() || topLevelNode->visitedState() != VisitedState::Unvisited) |
| 607 | continue; |
| 608 | |
| 609 | nodeStack.push_back(topLevelNode); |
| 610 | |
| 611 | while (!nodeStack.empty()) |
| 612 | { |
| 613 | CommandGraphNode *node = nodeStack.back(); |
| 614 | |
| 615 | switch (node->visitedState()) |
| 616 | { |
| 617 | case VisitedState::Unvisited: |
| 618 | node->visitParents(&nodeStack); |
| 619 | break; |
| 620 | case VisitedState::Ready: |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 621 | ANGLE_TRY(node->visitAndExecute(context, serial, renderPassCache, |
Jamie Madill | 1f46bc1 | 2018-02-20 16:09:43 -0500 | [diff] [blame] | 622 | primaryCommandBufferOut)); |
| 623 | nodeStack.pop_back(); |
| 624 | break; |
| 625 | case VisitedState::Visited: |
| 626 | nodeStack.pop_back(); |
| 627 | break; |
| 628 | default: |
| 629 | UNREACHABLE(); |
| 630 | break; |
| 631 | } |
| 632 | } |
| 633 | } |
| 634 | |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 635 | ANGLE_TRY(primaryCommandBufferOut->end(context)); |
Jamie Madill | 1f46bc1 | 2018-02-20 16:09:43 -0500 | [diff] [blame] | 636 | |
| 637 | // TODO(jmadill): Use pool allocation so we don't need to deallocate command graph. |
Jamie Madill | 6c7ab7f | 2018-03-31 14:19:15 -0400 | [diff] [blame] | 638 | for (CommandGraphNode *node : mNodes) |
Jamie Madill | 1f46bc1 | 2018-02-20 16:09:43 -0500 | [diff] [blame] | 639 | { |
| 640 | delete node; |
| 641 | } |
| 642 | mNodes.clear(); |
Shahbaz Youssefi | 563fbaa | 2018-10-02 11:22:01 -0400 | [diff] [blame^] | 643 | mLastBarrierIndex = kInvalidNodeIndex; |
Jamie Madill | 1f46bc1 | 2018-02-20 16:09:43 -0500 | [diff] [blame] | 644 | |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 645 | return angle::Result::Continue(); |
Jamie Madill | 1f46bc1 | 2018-02-20 16:09:43 -0500 | [diff] [blame] | 646 | } |
| 647 | |
| 648 | bool CommandGraph::empty() const |
| 649 | { |
| 650 | return mNodes.empty(); |
| 651 | } |
| 652 | |
Jamie Madill | 0da73fe | 2018-10-02 09:31:39 -0400 | [diff] [blame] | 653 | // Dumps the command graph into a dot file that works with graphviz. |
| 654 | void CommandGraph::dumpGraphDotFile(std::ostream &out) const |
| 655 | { |
| 656 | // This ID maps a node pointer to a monatonic ID. It allows us to look up parent node IDs. |
| 657 | std::map<const CommandGraphNode *, int> nodeIDMap; |
| 658 | std::map<uintptr_t, int> objectIDMap; |
| 659 | |
| 660 | // Map nodes to ids. |
| 661 | for (size_t nodeIndex = 0; nodeIndex < mNodes.size(); ++nodeIndex) |
| 662 | { |
| 663 | const CommandGraphNode *node = mNodes[nodeIndex]; |
| 664 | nodeIDMap[node] = static_cast<int>(nodeIndex) + 1; |
| 665 | } |
| 666 | |
| 667 | int bufferIDCounter = 1; |
| 668 | int framebufferIDCounter = 1; |
| 669 | int imageIDCounter = 1; |
Shahbaz Youssefi | 563fbaa | 2018-10-02 11:22:01 -0400 | [diff] [blame^] | 670 | int queryIDCounter = 1; |
Jamie Madill | 0da73fe | 2018-10-02 09:31:39 -0400 | [diff] [blame] | 671 | |
| 672 | out << "digraph {" << std::endl; |
| 673 | |
| 674 | for (const CommandGraphNode *node : mNodes) |
| 675 | { |
| 676 | int nodeID = nodeIDMap[node]; |
| 677 | |
| 678 | std::stringstream strstr; |
| 679 | strstr << GetResourceTypeName(node->getResourceTypeForDiagnostics()); |
| 680 | strstr << " "; |
| 681 | |
| 682 | auto it = objectIDMap.find(node->getResourceIDForDiagnostics()); |
| 683 | if (it != objectIDMap.end()) |
| 684 | { |
| 685 | strstr << it->second; |
| 686 | } |
| 687 | else |
| 688 | { |
| 689 | int id = 0; |
| 690 | |
| 691 | switch (node->getResourceTypeForDiagnostics()) |
| 692 | { |
| 693 | case CommandGraphResourceType::Buffer: |
| 694 | id = bufferIDCounter++; |
| 695 | break; |
| 696 | case CommandGraphResourceType::Framebuffer: |
| 697 | id = framebufferIDCounter++; |
| 698 | break; |
| 699 | case CommandGraphResourceType::Image: |
| 700 | id = imageIDCounter++; |
| 701 | break; |
Shahbaz Youssefi | 563fbaa | 2018-10-02 11:22:01 -0400 | [diff] [blame^] | 702 | case CommandGraphResourceType::Query: |
| 703 | id = queryIDCounter++; |
| 704 | break; |
Jamie Madill | 0da73fe | 2018-10-02 09:31:39 -0400 | [diff] [blame] | 705 | default: |
| 706 | UNREACHABLE(); |
| 707 | break; |
| 708 | } |
| 709 | |
| 710 | objectIDMap[node->getResourceIDForDiagnostics()] = id; |
| 711 | strstr << id; |
| 712 | } |
| 713 | |
| 714 | const std::string &label = strstr.str(); |
| 715 | out << " " << nodeID << "[label =<" << label << "<BR/> <FONT POINT-SIZE=\"10\">Node ID " |
| 716 | << nodeID << "</FONT>>];" << std::endl; |
| 717 | } |
| 718 | |
| 719 | for (const CommandGraphNode *node : mNodes) |
| 720 | { |
| 721 | int nodeID = nodeIDMap[node]; |
| 722 | |
| 723 | for (const CommandGraphNode *parent : node->getParentsForDiagnostics()) |
| 724 | { |
| 725 | int parentID = nodeIDMap[parent]; |
| 726 | out << " " << parentID << " -> " << nodeID << ";" << std::endl; |
| 727 | } |
| 728 | } |
| 729 | |
| 730 | out << "}" << std::endl; |
| 731 | } |
Shahbaz Youssefi | 563fbaa | 2018-10-02 11:22:01 -0400 | [diff] [blame^] | 732 | |
| 733 | CommandGraphNode *CommandGraph::getLastBarrierNode(size_t *indexOut) |
| 734 | { |
| 735 | *indexOut = mLastBarrierIndex == kInvalidNodeIndex ? 0 : mLastBarrierIndex; |
| 736 | return mLastBarrierIndex == kInvalidNodeIndex ? nullptr : mNodes[mLastBarrierIndex]; |
| 737 | } |
| 738 | |
| 739 | void CommandGraph::addDependenciesToNextBarrier(size_t begin, |
| 740 | size_t end, |
| 741 | CommandGraphNode *nextBarrier) |
| 742 | { |
| 743 | for (size_t i = begin; i < end; ++i) |
| 744 | { |
| 745 | // As a small optimization, only add edges to childless nodes. The others have an |
| 746 | // indirect dependency. |
| 747 | if (!mNodes[i]->hasChildren()) |
| 748 | { |
| 749 | CommandGraphNode::SetHappensBeforeDependency(mNodes[i], nextBarrier); |
| 750 | } |
| 751 | } |
| 752 | } |
| 753 | |
Jamie Madill | 1f46bc1 | 2018-02-20 16:09:43 -0500 | [diff] [blame] | 754 | } // namespace vk |
| 755 | } // namespace rx |