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 | #ifndef LIBANGLE_RENDERER_VULKAN_COMMAND_GRAPH_H_ |
| 11 | #define LIBANGLE_RENDERER_VULKAN_COMMAND_GRAPH_H_ |
| 12 | |
| 13 | #include "libANGLE/renderer/vulkan/vk_cache_utils.h" |
| 14 | |
| 15 | namespace rx |
| 16 | { |
| 17 | |
| 18 | namespace vk |
| 19 | { |
Jamie Madill | 3d61ac2 | 2018-08-28 16:58:55 -0400 | [diff] [blame] | 20 | enum class VisitedState |
| 21 | { |
| 22 | Unvisited, |
| 23 | Ready, |
| 24 | Visited, |
| 25 | }; |
| 26 | |
Jamie Madill | 0da73fe | 2018-10-02 09:31:39 -0400 | [diff] [blame] | 27 | enum class CommandGraphResourceType |
| 28 | { |
| 29 | Buffer, |
| 30 | Framebuffer, |
| 31 | Image, |
Shahbaz Youssefi | 563fbaa | 2018-10-02 11:22:01 -0400 | [diff] [blame] | 32 | Query, |
| 33 | }; |
| 34 | |
| 35 | // Certain functionality cannot be put in secondary command buffers, so they are special-cased in |
| 36 | // the node. |
| 37 | enum class CommandGraphNodeFunction |
| 38 | { |
| 39 | Generic, |
| 40 | BeginQuery, |
| 41 | EndQuery, |
Shahbaz Youssefi | c2b576d | 2018-10-12 14:45:34 -0400 | [diff] [blame] | 42 | WriteTimestamp, |
Jamie Madill | 0da73fe | 2018-10-02 09:31:39 -0400 | [diff] [blame] | 43 | }; |
| 44 | |
Jamie Madill | 3d61ac2 | 2018-08-28 16:58:55 -0400 | [diff] [blame] | 45 | // Only used internally in the command graph. Kept in the header for better inlining performance. |
| 46 | class CommandGraphNode final : angle::NonCopyable |
| 47 | { |
| 48 | public: |
Shahbaz Youssefi | 563fbaa | 2018-10-02 11:22:01 -0400 | [diff] [blame] | 49 | CommandGraphNode(CommandGraphNodeFunction function); |
Jamie Madill | 3d61ac2 | 2018-08-28 16:58:55 -0400 | [diff] [blame] | 50 | ~CommandGraphNode(); |
| 51 | |
| 52 | // Immutable queries for when we're walking the commands tree. |
| 53 | CommandBuffer *getOutsideRenderPassCommands(); |
| 54 | |
| 55 | CommandBuffer *getInsideRenderPassCommands() |
| 56 | { |
| 57 | ASSERT(!mHasChildren); |
| 58 | return &mInsideRenderPassCommands; |
| 59 | } |
| 60 | |
| 61 | // For outside the render pass (copies, transitions, etc). |
| 62 | angle::Result beginOutsideRenderPassRecording(Context *context, |
| 63 | const CommandPool &commandPool, |
| 64 | CommandBuffer **commandsOut); |
| 65 | |
| 66 | // For rendering commands (draws). |
| 67 | angle::Result beginInsideRenderPassRecording(Context *context, CommandBuffer **commandsOut); |
| 68 | |
| 69 | // storeRenderPassInfo and append*RenderTarget store info relevant to the RenderPass. |
| 70 | void storeRenderPassInfo(const Framebuffer &framebuffer, |
| 71 | const gl::Rectangle renderArea, |
| 72 | const vk::RenderPassDesc &renderPassDesc, |
| 73 | const std::vector<VkClearValue> &clearValues); |
| 74 | |
| 75 | // Dependency commands order node execution in the command graph. |
| 76 | // Once a node has commands that must happen after it, recording is stopped and the node is |
| 77 | // frozen forever. |
| 78 | static void SetHappensBeforeDependency(CommandGraphNode *beforeNode, |
| 79 | CommandGraphNode *afterNode); |
Shahbaz Youssefi | 563fbaa | 2018-10-02 11:22:01 -0400 | [diff] [blame] | 80 | static void SetHappensBeforeDependencies(CommandGraphNode **beforeNodes, |
| 81 | size_t beforeNodesCount, |
Jamie Madill | 3d61ac2 | 2018-08-28 16:58:55 -0400 | [diff] [blame] | 82 | CommandGraphNode *afterNode); |
Shahbaz Youssefi | 563fbaa | 2018-10-02 11:22:01 -0400 | [diff] [blame] | 83 | static void SetHappensBeforeDependencies(CommandGraphNode *beforeNode, |
| 84 | CommandGraphNode **afterNodes, |
| 85 | size_t afterNodesCount); |
Jamie Madill | 3d61ac2 | 2018-08-28 16:58:55 -0400 | [diff] [blame] | 86 | bool hasParents() const; |
| 87 | bool hasChildren() const { return mHasChildren; } |
| 88 | |
| 89 | // Commands for traversing the node on a flush operation. |
| 90 | VisitedState visitedState() const; |
| 91 | void visitParents(std::vector<CommandGraphNode *> *stack); |
| 92 | angle::Result visitAndExecute(Context *context, |
| 93 | Serial serial, |
| 94 | RenderPassCache *renderPassCache, |
| 95 | CommandBuffer *primaryCommandBuffer); |
| 96 | |
Jamie Madill | 0da73fe | 2018-10-02 09:31:39 -0400 | [diff] [blame] | 97 | // Only used in the command graph diagnostics. |
| 98 | const std::vector<CommandGraphNode *> &getParentsForDiagnostics() const; |
| 99 | void setDiagnosticInfo(CommandGraphResourceType resourceType, uintptr_t resourceID); |
| 100 | |
| 101 | CommandGraphResourceType getResourceTypeForDiagnostics() const { return mResourceType; } |
| 102 | uintptr_t getResourceIDForDiagnostics() const { return mResourceID; } |
| 103 | |
Jamie Madill | 3d61ac2 | 2018-08-28 16:58:55 -0400 | [diff] [blame] | 104 | const gl::Rectangle &getRenderPassRenderArea() const; |
| 105 | |
Shahbaz Youssefi | 563fbaa | 2018-10-02 11:22:01 -0400 | [diff] [blame] | 106 | CommandGraphNodeFunction getFunction() const { return mFunction; } |
| 107 | |
| 108 | void setQueryPool(const QueryPool *queryPool, uint32_t queryIndex); |
| 109 | |
Jamie Madill | 03d1a5e | 2018-11-12 11:34:24 -0500 | [diff] [blame] | 110 | void addGlobalMemoryBarrier(VkFlags srcAccess, VkFlags dstAccess); |
| 111 | |
Jamie Madill | 3d61ac2 | 2018-08-28 16:58:55 -0400 | [diff] [blame] | 112 | private: |
| 113 | void setHasChildren(); |
| 114 | |
| 115 | // Used for testing only. |
| 116 | bool isChildOf(CommandGraphNode *parent); |
| 117 | |
| 118 | // Only used if we need a RenderPass for these commands. |
| 119 | RenderPassDesc mRenderPassDesc; |
| 120 | Framebuffer mRenderPassFramebuffer; |
| 121 | gl::Rectangle mRenderPassRenderArea; |
| 122 | gl::AttachmentArray<VkClearValue> mRenderPassClearValues; |
| 123 | |
Shahbaz Youssefi | 563fbaa | 2018-10-02 11:22:01 -0400 | [diff] [blame] | 124 | CommandGraphNodeFunction mFunction; |
| 125 | |
| 126 | // Keep separate buffers for commands inside and outside a RenderPass. |
Jamie Madill | 3d61ac2 | 2018-08-28 16:58:55 -0400 | [diff] [blame] | 127 | // TODO(jmadill): We might not need inside and outside RenderPass commands separate. |
| 128 | CommandBuffer mOutsideRenderPassCommands; |
| 129 | CommandBuffer mInsideRenderPassCommands; |
| 130 | |
Shahbaz Youssefi | 563fbaa | 2018-10-02 11:22:01 -0400 | [diff] [blame] | 131 | // Special-function additional data: |
| 132 | VkQueryPool mQueryPool; |
| 133 | uint32_t mQueryIndex; |
| 134 | |
Jamie Madill | 3d61ac2 | 2018-08-28 16:58:55 -0400 | [diff] [blame] | 135 | // Parents are commands that must be submitted before 'this' CommandNode can be submitted. |
| 136 | std::vector<CommandGraphNode *> mParents; |
| 137 | |
| 138 | // If this is true, other commands exist that must be submitted after 'this' command. |
| 139 | bool mHasChildren; |
| 140 | |
| 141 | // Used when traversing the dependency graph. |
| 142 | VisitedState mVisitedState; |
Jamie Madill | 0da73fe | 2018-10-02 09:31:39 -0400 | [diff] [blame] | 143 | |
| 144 | // Additional diagnostic information. |
| 145 | CommandGraphResourceType mResourceType; |
| 146 | uintptr_t mResourceID; |
Jamie Madill | 03d1a5e | 2018-11-12 11:34:24 -0500 | [diff] [blame] | 147 | |
| 148 | // For global memory barriers. |
| 149 | VkFlags mGlobalMemoryBarrierSrcAccess; |
| 150 | VkFlags mGlobalMemoryBarrierDstAccess; |
Jamie Madill | 3d61ac2 | 2018-08-28 16:58:55 -0400 | [diff] [blame] | 151 | }; |
Jamie Madill | 1f46bc1 | 2018-02-20 16:09:43 -0500 | [diff] [blame] | 152 | |
Jamie Madill | 6c7ab7f | 2018-03-31 14:19:15 -0400 | [diff] [blame] | 153 | // This is a helper class for back-end objects used in Vk command buffers. It records a serial |
| 154 | // at command recording times indicating an order in the queue. We use Fences to detect when |
| 155 | // commands finish, and then release any unreferenced and deleted resources based on the stored |
| 156 | // queue serial in a special 'garbage' queue. Resources also track current read and write |
| 157 | // dependencies. Only one command buffer node can be writing to the Resource at a time, but many |
| 158 | // can be reading from it. Together the dependencies will form a command graph at submission time. |
Jamie Madill | 0da73fe | 2018-10-02 09:31:39 -0400 | [diff] [blame] | 159 | class CommandGraphResource : angle::NonCopyable |
Jamie Madill | 6c7ab7f | 2018-03-31 14:19:15 -0400 | [diff] [blame] | 160 | { |
| 161 | public: |
Jamie Madill | 6c7ab7f | 2018-03-31 14:19:15 -0400 | [diff] [blame] | 162 | virtual ~CommandGraphResource(); |
| 163 | |
Jamie Madill | c57ee25 | 2018-05-30 19:53:48 -0400 | [diff] [blame] | 164 | // Returns true if the resource is in use by the renderer. |
| 165 | bool isResourceInUse(RendererVk *renderer) const; |
Jamie Madill | 6c7ab7f | 2018-03-31 14:19:15 -0400 | [diff] [blame] | 166 | |
Shahbaz Youssefi | 563fbaa | 2018-10-02 11:22:01 -0400 | [diff] [blame] | 167 | // Returns true if the resource has unsubmitted work pending. |
| 168 | bool hasPendingWork(RendererVk *renderer) const; |
| 169 | |
Jamie Madill | 193a284 | 2018-10-30 17:28:41 -0400 | [diff] [blame] | 170 | // Get the current queue serial for this resource. Used to release resources, and for |
| 171 | // queries, to know if the queue they are submitted on has finished execution. |
| 172 | Serial getStoredQueueSerial() const; |
| 173 | |
| 174 | protected: |
| 175 | explicit CommandGraphResource(CommandGraphResourceType resourceType); |
| 176 | |
| 177 | Serial mStoredQueueSerial; |
| 178 | |
| 179 | // Additional diagnostic information. |
| 180 | CommandGraphResourceType mResourceType; |
| 181 | |
| 182 | // Current command graph writing node. |
| 183 | CommandGraphNode *mCurrentWritingNode; |
| 184 | }; |
| 185 | |
| 186 | // Subclass of graph resources that can record command buffers. Images/Buffers/Framebuffers. |
| 187 | // Does not include Query graph resources. |
| 188 | class RecordableGraphResource : public CommandGraphResource |
| 189 | { |
| 190 | public: |
| 191 | ~RecordableGraphResource() override; |
| 192 | |
Jamie Madill | d014c9e | 2018-05-18 15:15:59 -0400 | [diff] [blame] | 193 | // Sets up dependency relations. 'this' resource is the resource being written to. |
Jamie Madill | 193a284 | 2018-10-30 17:28:41 -0400 | [diff] [blame] | 194 | void addWriteDependency(RecordableGraphResource *writingResource); |
Jamie Madill | d014c9e | 2018-05-18 15:15:59 -0400 | [diff] [blame] | 195 | |
| 196 | // Sets up dependency relations. 'this' resource is the resource being read. |
Jamie Madill | 193a284 | 2018-10-30 17:28:41 -0400 | [diff] [blame] | 197 | void addReadDependency(RecordableGraphResource *readingResource); |
Jamie Madill | d014c9e | 2018-05-18 15:15:59 -0400 | [diff] [blame] | 198 | |
Shahbaz Youssefi | 254b32c | 2018-11-26 11:58:03 -0500 | [diff] [blame] | 199 | // Updates the in-use serial tracked for this resource. Will clear dependencies if the resource |
| 200 | // was not used in this set of command nodes. |
| 201 | void updateQueueSerial(Serial queueSerial); |
| 202 | |
Jamie Madill | 6c7ab7f | 2018-03-31 14:19:15 -0400 | [diff] [blame] | 203 | // Allocates a write node via getNewWriteNode and returns a started command buffer. |
| 204 | // The started command buffer will render outside of a RenderPass. |
Jamie Madill | e2d2270 | 2018-09-19 08:11:48 -0400 | [diff] [blame] | 205 | // Will append to an existing command buffer/graph node if possible. |
| 206 | angle::Result recordCommands(Context *context, CommandBuffer **commandBufferOut); |
Jamie Madill | 316c606 | 2018-05-29 10:49:45 -0400 | [diff] [blame] | 207 | |
| 208 | // Begins a command buffer on the current graph node for in-RenderPass rendering. |
Shahbaz Youssefi | e321940 | 2018-12-08 16:54:14 +0100 | [diff] [blame] | 209 | // Currently only called from FramebufferVk::startNewRenderPass. |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 210 | angle::Result beginRenderPass(Context *context, |
| 211 | const Framebuffer &framebuffer, |
| 212 | const gl::Rectangle &renderArea, |
| 213 | const RenderPassDesc &renderPassDesc, |
| 214 | const std::vector<VkClearValue> &clearValues, |
Shahbaz Youssefi | 563fbaa | 2018-10-02 11:22:01 -0400 | [diff] [blame] | 215 | CommandBuffer **commandBufferOut); |
| 216 | |
Jamie Madill | 5dca651 | 2018-05-30 10:53:51 -0400 | [diff] [blame] | 217 | // Checks if we're in a RenderPass, returning true if so. Updates serial internally. |
| 218 | // Returns the started command buffer in commandBufferOut. |
| 219 | bool appendToStartedRenderPass(RendererVk *renderer, CommandBuffer **commandBufferOut); |
Jamie Madill | 316c606 | 2018-05-29 10:49:45 -0400 | [diff] [blame] | 220 | |
| 221 | // Accessor for RenderPass RenderArea. |
| 222 | const gl::Rectangle &getRenderPassRenderArea() const; |
| 223 | |
| 224 | // Called when 'this' object changes, but we'd like to start a new command buffer later. |
Jamie Madill | e2d2270 | 2018-09-19 08:11:48 -0400 | [diff] [blame] | 225 | void finishCurrentCommands(RendererVk *renderer); |
Jamie Madill | 316c606 | 2018-05-29 10:49:45 -0400 | [diff] [blame] | 226 | |
Jamie Madill | 03d1a5e | 2018-11-12 11:34:24 -0500 | [diff] [blame] | 227 | // Store a deferred memory barrier. Will be recorded into a primary command buffer at submit. |
| 228 | void addGlobalMemoryBarrier(VkFlags srcAccess, VkFlags dstAccess) |
| 229 | { |
| 230 | ASSERT(mCurrentWritingNode); |
| 231 | mCurrentWritingNode->addGlobalMemoryBarrier(srcAccess, dstAccess); |
| 232 | } |
| 233 | |
Jamie Madill | 2d03ff4 | 2018-09-27 15:04:26 -0400 | [diff] [blame] | 234 | protected: |
Jamie Madill | 193a284 | 2018-10-30 17:28:41 -0400 | [diff] [blame] | 235 | explicit RecordableGraphResource(CommandGraphResourceType resourceType); |
Jamie Madill | 0da73fe | 2018-10-02 09:31:39 -0400 | [diff] [blame] | 236 | |
Jamie Madill | 6c7ab7f | 2018-03-31 14:19:15 -0400 | [diff] [blame] | 237 | private: |
Jamie Madill | 316c606 | 2018-05-29 10:49:45 -0400 | [diff] [blame] | 238 | // Returns true if this node has a current writing node with no children. |
Jamie Madill | 3d61ac2 | 2018-08-28 16:58:55 -0400 | [diff] [blame] | 239 | bool hasChildlessWritingNode() const |
| 240 | { |
Shahbaz Youssefi | 563fbaa | 2018-10-02 11:22:01 -0400 | [diff] [blame] | 241 | // Note: currently, we don't have a resource that can issue both generic and special |
| 242 | // commands. We don't create read/write dependencies between mixed generic/special |
| 243 | // resources either. As such, we expect the function to always be generic here. If such a |
| 244 | // resource is added in the future, this can add a check for function == generic and fail if |
| 245 | // false. |
| 246 | ASSERT(mCurrentWritingNode == nullptr || |
| 247 | mCurrentWritingNode->getFunction() == CommandGraphNodeFunction::Generic); |
Jamie Madill | 3d61ac2 | 2018-08-28 16:58:55 -0400 | [diff] [blame] | 248 | return (mCurrentWritingNode != nullptr && !mCurrentWritingNode->hasChildren()); |
| 249 | } |
Jamie Madill | 316c606 | 2018-05-29 10:49:45 -0400 | [diff] [blame] | 250 | |
Jamie Madill | 5dca651 | 2018-05-30 10:53:51 -0400 | [diff] [blame] | 251 | // Checks if we're in a RenderPass without children. |
Jamie Madill | 3d61ac2 | 2018-08-28 16:58:55 -0400 | [diff] [blame] | 252 | bool hasStartedRenderPass() const |
| 253 | { |
| 254 | return hasChildlessWritingNode() && |
| 255 | mCurrentWritingNode->getInsideRenderPassCommands()->valid(); |
| 256 | } |
Jamie Madill | 5dca651 | 2018-05-30 10:53:51 -0400 | [diff] [blame] | 257 | |
Jamie Madill | 193a284 | 2018-10-30 17:28:41 -0400 | [diff] [blame] | 258 | void startNewCommands(RendererVk *renderer); |
Jamie Madill | 0da73fe | 2018-10-02 09:31:39 -0400 | [diff] [blame] | 259 | |
Jamie Madill | 193a284 | 2018-10-30 17:28:41 -0400 | [diff] [blame] | 260 | void onWriteImpl(CommandGraphNode *writingNode, Serial currentSerial); |
| 261 | |
| 262 | std::vector<CommandGraphNode *> mCurrentReadingNodes; |
| 263 | }; |
| 264 | |
| 265 | // Specialized command graph node for queries. Not for use with any exposed command buffers. |
| 266 | class QueryGraphResource : public CommandGraphResource |
| 267 | { |
| 268 | public: |
| 269 | ~QueryGraphResource() override; |
| 270 | |
| 271 | void beginQuery(Context *context, const QueryPool *queryPool, uint32_t queryIndex); |
| 272 | void endQuery(Context *context, const QueryPool *queryPool, uint32_t queryIndex); |
| 273 | void writeTimestamp(Context *context, const QueryPool *queryPool, uint32_t queryIndex); |
| 274 | |
| 275 | protected: |
| 276 | QueryGraphResource(); |
| 277 | |
| 278 | private: |
| 279 | void startNewCommands(RendererVk *renderer, CommandGraphNodeFunction function); |
Jamie Madill | 6c7ab7f | 2018-03-31 14:19:15 -0400 | [diff] [blame] | 280 | }; |
| 281 | |
Jamie Madill | 1f46bc1 | 2018-02-20 16:09:43 -0500 | [diff] [blame] | 282 | // Translating OpenGL commands into Vulkan and submitting them immediately loses out on some |
| 283 | // of the powerful flexiblity Vulkan offers in RenderPasses. Load/Store ops can automatically |
| 284 | // clear RenderPass attachments, or preserve the contents. RenderPass automatic layout transitions |
| 285 | // can improve certain performance cases. Also, we can remove redundant RenderPass Begin and Ends |
| 286 | // when processing interleaved draw operations on independent Framebuffers. |
| 287 | // |
| 288 | // ANGLE's CommandGraph (and CommandGraphNode) attempt to solve these problems using deferred |
| 289 | // command submission. We also sometimes call this command re-ordering. A brief summary: |
| 290 | // |
| 291 | // During GL command processing, we record Vulkan commands into secondary command buffers, which |
| 292 | // are stored in CommandGraphNodes, and these nodes are chained together via dependencies to |
| 293 | // for a directed acyclic CommandGraph. When we need to submit the CommandGraph, say during a |
| 294 | // SwapBuffers or ReadPixels call, we begin a primary Vulkan CommandBuffer, and walk the |
| 295 | // CommandGraph, starting at the most senior nodes, recording secondary CommandBuffers inside |
Jamie Madill | 6c7ab7f | 2018-03-31 14:19:15 -0400 | [diff] [blame] | 296 | // and outside RenderPasses as necessary, filled with the right load/store operations. Once |
Jamie Madill | 1f46bc1 | 2018-02-20 16:09:43 -0500 | [diff] [blame] | 297 | // the primary CommandBuffer has recorded all of the secondary CommandBuffers from all the open |
| 298 | // CommandGraphNodes, we submit the primary CommandBuffer to the VkQueue on the device. |
Jamie Madill | a5e0607 | 2018-05-18 14:36:05 -0400 | [diff] [blame] | 299 | // |
Jamie Madill | 1f46bc1 | 2018-02-20 16:09:43 -0500 | [diff] [blame] | 300 | // The Command Graph consists of an array of open Command Graph Nodes. It supports allocating new |
| 301 | // nodes for the graph, which are linked via dependency relation calls in CommandGraphNode, and |
| 302 | // also submitting the whole command graph via submitCommands. |
| 303 | class CommandGraph final : angle::NonCopyable |
| 304 | { |
| 305 | public: |
Jamie Madill | 0da73fe | 2018-10-02 09:31:39 -0400 | [diff] [blame] | 306 | explicit CommandGraph(bool enableGraphDiagnostics); |
Jamie Madill | 1f46bc1 | 2018-02-20 16:09:43 -0500 | [diff] [blame] | 307 | ~CommandGraph(); |
| 308 | |
| 309 | // Allocates a new CommandGraphNode and adds it to the list of current open nodes. No ordering |
| 310 | // relations exist in the node by default. Call CommandGraphNode::SetHappensBeforeDependency |
Shahbaz Youssefi | 563fbaa | 2018-10-02 11:22:01 -0400 | [diff] [blame] | 311 | // to set up dependency relations. If the node is a barrier, it will automatically add |
| 312 | // dependencies between the previous barrier, the new barrier and all nodes in between. |
Jamie Madill | 193a284 | 2018-10-30 17:28:41 -0400 | [diff] [blame] | 313 | CommandGraphNode *allocateNode(CommandGraphNodeFunction function); |
Jamie Madill | 1f46bc1 | 2018-02-20 16:09:43 -0500 | [diff] [blame] | 314 | |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 315 | angle::Result submitCommands(Context *context, |
| 316 | Serial serial, |
| 317 | RenderPassCache *renderPassCache, |
| 318 | CommandPool *commandPool, |
| 319 | CommandBuffer *primaryCommandBufferOut); |
Jamie Madill | 1f46bc1 | 2018-02-20 16:09:43 -0500 | [diff] [blame] | 320 | bool empty() const; |
Yuly Novikov | b56ddbb | 2018-11-02 16:53:18 -0400 | [diff] [blame] | 321 | void clear(); |
Jamie Madill | 1f46bc1 | 2018-02-20 16:09:43 -0500 | [diff] [blame] | 322 | |
Shahbaz Youssefi | 563fbaa | 2018-10-02 11:22:01 -0400 | [diff] [blame] | 323 | CommandGraphNode *getLastBarrierNode(size_t *indexOut); |
| 324 | |
Jamie Madill | 193a284 | 2018-10-30 17:28:41 -0400 | [diff] [blame] | 325 | void setNewBarrier(CommandGraphNode *newBarrier); |
| 326 | |
Jamie Madill | 1f46bc1 | 2018-02-20 16:09:43 -0500 | [diff] [blame] | 327 | private: |
Jamie Madill | 0da73fe | 2018-10-02 09:31:39 -0400 | [diff] [blame] | 328 | void dumpGraphDotFile(std::ostream &out) const; |
Jamie Madill | 1f46bc1 | 2018-02-20 16:09:43 -0500 | [diff] [blame] | 329 | |
Shahbaz Youssefi | 563fbaa | 2018-10-02 11:22:01 -0400 | [diff] [blame] | 330 | void addDependenciesToNextBarrier(size_t begin, size_t end, CommandGraphNode *nextBarrier); |
| 331 | |
Jamie Madill | 0da73fe | 2018-10-02 09:31:39 -0400 | [diff] [blame] | 332 | std::vector<CommandGraphNode *> mNodes; |
| 333 | bool mEnableGraphDiagnostics; |
Shahbaz Youssefi | 563fbaa | 2018-10-02 11:22:01 -0400 | [diff] [blame] | 334 | |
| 335 | // A set of nodes (eventually) exist that act as barriers to guarantee submission order. For |
| 336 | // example, a glMemoryBarrier() calls would lead to such a barrier or beginning and ending a |
| 337 | // query. This is because the graph can reorder operations if it sees fit. Let's call a barrier |
| 338 | // node Bi, and the other nodes Ni. The edges between Ni don't interest us. Before a barrier is |
| 339 | // inserted, we have: |
| 340 | // |
| 341 | // N0 N1 ... Na |
| 342 | // \___\__/_/ (dependency egdes, which we don't care about so I'll stop drawing them. |
| 343 | // \/ |
| 344 | // |
| 345 | // When the first barrier is inserted, we will have: |
| 346 | // |
| 347 | // ______ |
| 348 | // / ____\ |
| 349 | // / / \ |
| 350 | // / / /\ |
| 351 | // N0 N1 ... Na B0 |
| 352 | // |
| 353 | // This makes sure all N0..Na are called before B0. From then on, B0 will be the current |
| 354 | // "barrier point" which extends an edge to every next node: |
| 355 | // |
| 356 | // ______ |
| 357 | // / ____\ |
| 358 | // / / \ |
| 359 | // / / /\ |
| 360 | // N0 N1 ... Na B0 Na+1 ... Nb |
| 361 | // \/ / |
| 362 | // \______/ |
| 363 | // |
| 364 | // |
| 365 | // When the next barrier B1 is met, all nodes between B0 and B1 will add a depenency on B1 as |
| 366 | // well, and the "barrier point" is updated. |
| 367 | // |
| 368 | // ______ |
| 369 | // / ____\ ______ ______ |
| 370 | // / / \ / \ / \ |
| 371 | // / / /\ / /\ / /\ |
| 372 | // N0 N1 ... Na B0 Na+1 ... Nb B1 Nb+1 ... Nc B2 ... |
| 373 | // \/ / / \/ / / |
| 374 | // \______/ / \______/ / |
| 375 | // \_______/ \_______/ |
| 376 | // |
| 377 | // |
| 378 | // When barrier Bi is introduced, all nodes added since Bi-1 need to add a dependency to Bi |
| 379 | // (including Bi-1). We therefore keep track of the node index of the last barrier that was |
| 380 | // issued. |
| 381 | static constexpr size_t kInvalidNodeIndex = std::numeric_limits<std::size_t>::max(); |
| 382 | size_t mLastBarrierIndex; |
Jamie Madill | 0da73fe | 2018-10-02 09:31:39 -0400 | [diff] [blame] | 383 | }; |
Jamie Madill | 1f46bc1 | 2018-02-20 16:09:43 -0500 | [diff] [blame] | 384 | } // namespace vk |
| 385 | } // namespace rx |
| 386 | |
| 387 | #endif // LIBANGLE_RENDERER_VULKAN_COMMAND_GRAPH_H_ |