Vulkan:Integrate SecondaryCommandBuffers
Integrate the custom SecondaryCommandBuffer type into the CommandGraph
nodes by adding new ANGLE_USE_CUSTOM_VULKAN_CMD_BUFFERS define that can
be set in the BUILD gn args with angle_enable_custom_vulkan_cmd_buffers
set to "true."
Initially the custom cmd buffers are disabled by default.
This adds some support functions to SecondaryCommandBuffer to make the
integration easier by matching the wrapped cmd buffer interface:
initialize(), end(), valid().
Bug: angleproject:3136
Change-Id: Ib910554583192550757bb8ce89914e3ea8737988
Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/1526556
Commit-Queue: Tobin Ehlis <tobine@google.com>
Reviewed-by: Jamie Madill <jmadill@chromium.org>
diff --git a/src/libANGLE/renderer/vulkan/CommandGraph.h b/src/libANGLE/renderer/vulkan/CommandGraph.h
index 2bb90ff..4548789 100644
--- a/src/libANGLE/renderer/vulkan/CommandGraph.h
+++ b/src/libANGLE/renderer/vulkan/CommandGraph.h
@@ -10,8 +10,15 @@
#ifndef LIBANGLE_RENDERER_VULKAN_COMMAND_GRAPH_H_
#define LIBANGLE_RENDERER_VULKAN_COMMAND_GRAPH_H_
+#include "libANGLE/renderer/vulkan/SecondaryCommandBuffer.h"
#include "libANGLE/renderer/vulkan/vk_cache_utils.h"
+#if ANGLE_USE_CUSTOM_VULKAN_CMD_BUFFERS
+using CommandBufferT = rx::vk::SecondaryCommandBuffer;
+#else
+using CommandBufferT = rx::vk::CommandBuffer;
+#endif
+
namespace rx
{
@@ -61,20 +68,24 @@
ANGLE_INLINE void onCommandBufferFinished() { mCommandBuffer = nullptr; }
protected:
- vk::CommandBuffer *mCommandBuffer = nullptr;
+ CommandBufferT *mCommandBuffer = nullptr;
};
// Only used internally in the command graph. Kept in the header for better inlining performance.
class CommandGraphNode final : angle::NonCopyable
{
public:
- CommandGraphNode(CommandGraphNodeFunction function);
+ CommandGraphNode(CommandGraphNodeFunction function, angle::PoolAllocator *poolAllocator);
~CommandGraphNode();
// Immutable queries for when we're walking the commands tree.
- CommandBuffer *getOutsideRenderPassCommands();
+ CommandBufferT *getOutsideRenderPassCommands()
+ {
+ ASSERT(!mHasChildren);
+ return &mOutsideRenderPassCommands;
+ }
- CommandBuffer *getInsideRenderPassCommands()
+ CommandBufferT *getInsideRenderPassCommands()
{
ASSERT(!mHasChildren);
return &mInsideRenderPassCommands;
@@ -83,10 +94,10 @@
// For outside the render pass (copies, transitions, etc).
angle::Result beginOutsideRenderPassRecording(Context *context,
const CommandPool &commandPool,
- CommandBuffer **commandsOut);
+ CommandBufferT **commandsOut);
// For rendering commands (draws).
- angle::Result beginInsideRenderPassRecording(Context *context, CommandBuffer **commandsOut);
+ angle::Result beginInsideRenderPassRecording(Context *context, CommandBufferT **commandsOut);
// storeRenderPassInfo and append*RenderTarget store info relevant to the RenderPass.
void storeRenderPassInfo(const Framebuffer &framebuffer,
@@ -173,11 +184,11 @@
gl::AttachmentArray<VkClearValue> mRenderPassClearValues;
CommandGraphNodeFunction mFunction;
-
+ angle::PoolAllocator *mPoolAllocator;
// Keep 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;
+ CommandBufferT mOutsideRenderPassCommands;
+ CommandBufferT mInsideRenderPassCommands;
// Special-function additional data:
// Queries:
@@ -251,7 +262,7 @@
// Allocates a write node via getNewWriteNode and returns a started command buffer.
// The started command buffer will render outside of a RenderPass.
// Will append to an existing command buffer/graph node if possible.
- angle::Result recordCommands(Context *context, CommandBuffer **commandBufferOut);
+ angle::Result recordCommands(Context *context, CommandBufferT **commandBufferOut);
// Begins a command buffer on the current graph node for in-RenderPass rendering.
// Called from FramebufferVk::startNewRenderPass and UtilsVk functions.
@@ -260,12 +271,12 @@
const gl::Rectangle &renderArea,
const RenderPassDesc &renderPassDesc,
const std::vector<VkClearValue> &clearValues,
- CommandBuffer **commandBufferOut);
+ CommandBufferT **commandBufferOut);
// Checks if we're in a RenderPass, returning true if so. Updates serial internally.
// Returns the started command buffer in commandBufferOut.
ANGLE_INLINE bool appendToStartedRenderPass(Serial currentQueueSerial,
- CommandBuffer **commandBufferOut)
+ CommandBufferT **commandBufferOut)
{
updateQueueSerial(currentQueueSerial);
if (hasStartedRenderPass())
@@ -340,13 +351,13 @@
// ANGLE's CommandGraph (and CommandGraphNode) attempt to solve these problems using deferred
// command submission. We also sometimes call this command re-ordering. A brief summary:
//
-// During GL command processing, we record Vulkan commands into secondary command buffers, which
+// During GL command processing, we record Vulkan commands into SecondaryCommandBuffers, which
// are stored in CommandGraphNodes, and these nodes are chained together via dependencies to
-// for a directed acyclic CommandGraph. When we need to submit the CommandGraph, say during a
+// form a directed acyclic CommandGraph. When we need to submit the CommandGraph, say during a
// SwapBuffers or ReadPixels call, we begin a primary Vulkan CommandBuffer, and walk the
-// CommandGraph, starting at the most senior nodes, recording secondary CommandBuffers inside
+// CommandGraph, starting at the most senior nodes, recording SecondaryCommandBuffers inside
// and outside RenderPasses as necessary, filled with the right load/store operations. Once
-// the primary CommandBuffer has recorded all of the secondary CommandBuffers from all the open
+// the primary CommandBuffer has recorded all of the SecondaryCommandBuffers from all the open
// CommandGraphNodes, we submit the primary CommandBuffer to the VkQueue on the device.
//
// The Command Graph consists of an array of open Command Graph Nodes. It supports allocating new
@@ -355,7 +366,7 @@
class CommandGraph final : angle::NonCopyable
{
public:
- explicit CommandGraph(bool enableGraphDiagnostics);
+ explicit CommandGraph(bool enableGraphDiagnostics, angle::PoolAllocator *poolAllocator);
~CommandGraph();
// Allocates a new CommandGraphNode and adds it to the list of current open nodes. No ordering
@@ -397,6 +408,7 @@
std::vector<CommandGraphNode *> mNodes;
bool mEnableGraphDiagnostics;
+ angle::PoolAllocator *mPoolAllocator;
// A set of nodes (eventually) exist that act as barriers to guarantee submission order. For
// example, a glMemoryBarrier() calls would lead to such a barrier or beginning and ending a