Hash :
0e65454d
Author :
Date :
2018-02-07T14:50:06
Vulkan: Fix circular dependency with resource updates. The old implementation would try to keep recording draw commands to the same framebuffer write operation even if the vertex array buffer data changed. This would lead to a broken dependency graph. Fix this by forcing any current render operations to create a new node in this case, giving a correct command graph. Old design: - render (creates a CommandBufferNode A) - update buffer (creates a CommandBufferNode B which happens after A) - render (to CommandBuffer A, and gives a circular dependency with B) New design - render (CommandBufferNode A) - update buffer (CommandBufferNode B, happens after A) - render (CommandBufferNode C, happens after B) This also renames some methods to try to clarify them. Bug: angleproject:2350 Change-Id: I6559bed4ed3f58f68771662422c5bef6a505282b Reviewed-on: https://chromium-review.googlesource.com/907416 Reviewed-by: Corentin Wallez <cwallez@chromium.org> Reviewed-by: Frank Henigman <fjhenigman@chromium.org> Commit-Queue: Jamie Madill <jmadill@chromium.org>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
//
// Copyright 2017 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// CommandBufferNode:
// Deferred work constructed by GL calls, that will later be flushed to Vulkan.
//
#ifndef LIBANGLE_RENDERER_VULKAN_COMMAND_BUFFER_NODE_H_
#define LIBANGLE_RENDERER_VULKAN_COMMAND_BUFFER_NODE_H_
#include "libANGLE/renderer/vulkan/vk_cache_utils.h"
namespace rx
{
namespace vk
{
enum class VisitedState
{
Unvisited,
Ready,
Visited,
};
class CommandBufferNode final : angle::NonCopyable
{
public:
CommandBufferNode();
~CommandBufferNode();
// Immutable queries for when we're walking the commands tree.
CommandBuffer *getOutsideRenderPassCommands();
CommandBuffer *getInsideRenderPassCommands();
// For outside the render pass (copies, transitions, etc).
Error startRecording(VkDevice device,
const CommandPool &commandPool,
CommandBuffer **commandsOut);
// For rendering commands (draws).
Error startRenderPassRecording(RendererVk *renderer, CommandBuffer **commandsOut);
bool isFinishedRecording() const;
void finishRecording();
// Commands for storing info relevant to the RenderPass.
// RenderTargets must be added in order, with the depth/stencil being added last.
void storeRenderPassInfo(const Framebuffer &framebuffer,
const gl::Rectangle renderArea,
const std::vector<VkClearValue> &clearValues);
void appendColorRenderTarget(Serial serial, RenderTargetVk *colorRenderTarget);
void appendDepthStencilRenderTarget(Serial serial, RenderTargetVk *depthStencilRenderTarget);
// Commands for linking nodes in the dependency graph.
static void SetHappensBeforeDependency(CommandBufferNode *beforeNode,
CommandBufferNode *afterNode);
static void SetHappensBeforeDependencies(const std::vector<CommandBufferNode *> &beforeNodes,
CommandBufferNode *afterNode);
bool hasHappensBeforeDependencies() const;
bool hasHappensAfterDependencies() const;
// Used for testing only.
bool happensAfter(CommandBufferNode *beforeNode);
// Commands for traversing the node on a flush operation.
VisitedState visitedState() const;
void visitDependencies(std::vector<CommandBufferNode *> *stack);
Error visitAndExecute(RendererVk *renderer, CommandBuffer *primaryCommandBuffer);
private:
void initAttachmentDesc(VkAttachmentDescription *desc);
void setHasHappensAfterDependencies();
// Only used if we need a RenderPass for these commands.
RenderPassDesc mRenderPassDesc;
Framebuffer mRenderPassFramebuffer;
gl::Rectangle mRenderPassRenderArea;
gl::AttachmentArray<VkClearValue> mRenderPassClearValues;
// Keep a separate buffers for commands inside and outside a RenderPass.
// TODO(jmadill): We might not need inside and outside RenderPass commands separate.
CommandBuffer mOutsideRenderPassCommands;
CommandBuffer mInsideRenderPassCommands;
// These commands must be submitted before 'this' command can be submitted correctly.
std::vector<CommandBufferNode *> mHappensBeforeDependencies;
// If this is true, other commands exist that must be submitted after 'this' command.
bool mHasHappensAfterDependencies;
// Used when traversing the dependency graph.
VisitedState mVisitedState;
// Is recording currently enabled?
bool mIsFinishedRecording;
};
} // namespace vk
} // namespace rx
#endif // LIBANGLE_RENDERER_VULKAN_COMMAND_BUFFER_NODE_H_