Vulkan: refactor CommandGraphResource
Merged back RecordableGraphResource into CommandGraphResource. Queries
didn't really need to be a resource, as they always inserted separate
single-command nodes in the graph. The CommandGraph class is augmented
with a few functions that generate such nodes.
This is in preparation for debug markers, as they too require such
nodes.
Bug: angleproject:2853
Change-Id: I5251a0e0fdd42ed1126921b4acc13687a14af9cd
Reviewed-on: https://chromium-review.googlesource.com/c/1422549
Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org>
Reviewed-by: Jamie Madill <jmadill@chromium.org>
diff --git a/src/libANGLE/renderer/vulkan/CommandGraph.cpp b/src/libANGLE/renderer/vulkan/CommandGraph.cpp
index 979b1e7..adce3e3 100644
--- a/src/libANGLE/renderer/vulkan/CommandGraph.cpp
+++ b/src/libANGLE/renderer/vulkan/CommandGraph.cpp
@@ -83,7 +83,7 @@
// CommandGraphResource implementation.
CommandGraphResource::CommandGraphResource(CommandGraphResourceType resourceType)
- : mResourceType(resourceType), mCurrentWritingNode(nullptr)
+ : mCurrentWritingNode(nullptr), mResourceType(resourceType)
{}
CommandGraphResource::~CommandGraphResource() = default;
@@ -93,22 +93,8 @@
return renderer->isSerialInUse(mStoredQueueSerial);
}
-bool CommandGraphResource::hasPendingWork(RendererVk *renderer) const
-{
- // If the renderer has a queue serial higher than the stored one, the command buffers recorded
- // by this resource have already been submitted, so there is no pending work.
- return mStoredQueueSerial == renderer->getCurrentQueueSerial();
-}
-
-// RecordableGraphResource implementation.
-RecordableGraphResource::RecordableGraphResource(CommandGraphResourceType resourceType)
- : CommandGraphResource(resourceType)
-{}
-
-RecordableGraphResource::~RecordableGraphResource() = default;
-
-angle::Result RecordableGraphResource::recordCommands(Context *context,
- CommandBuffer **commandBufferOut)
+angle::Result CommandGraphResource::recordCommands(Context *context,
+ CommandBuffer **commandBufferOut)
{
updateQueueSerial(context->getRenderer()->getCurrentQueueSerial());
@@ -133,18 +119,18 @@
return angle::Result::Continue;
}
-const gl::Rectangle &RecordableGraphResource::getRenderPassRenderArea() const
+const gl::Rectangle &CommandGraphResource::getRenderPassRenderArea() const
{
ASSERT(hasStartedRenderPass());
return mCurrentWritingNode->getRenderPassRenderArea();
}
-angle::Result RecordableGraphResource::beginRenderPass(ContextVk *contextVk,
- const Framebuffer &framebuffer,
- const gl::Rectangle &renderArea,
- const RenderPassDesc &renderPassDesc,
- const std::vector<VkClearValue> &clearValues,
- CommandBuffer **commandBufferOut)
+angle::Result CommandGraphResource::beginRenderPass(ContextVk *contextVk,
+ const Framebuffer &framebuffer,
+ const gl::Rectangle &renderArea,
+ const RenderPassDesc &renderPassDesc,
+ const std::vector<VkClearValue> &clearValues,
+ CommandBuffer **commandBufferOut)
{
// If a barrier has been inserted in the meantime, stop the command buffer.
if (!hasChildlessWritingNode())
@@ -161,7 +147,7 @@
return mCurrentWritingNode->beginInsideRenderPassRecording(contextVk, commandBufferOut);
}
-void RecordableGraphResource::addWriteDependency(RecordableGraphResource *writingResource)
+void CommandGraphResource::addWriteDependency(CommandGraphResource *writingResource)
{
CommandGraphNode *writingNode = writingResource->mCurrentWritingNode;
ASSERT(writingNode);
@@ -169,7 +155,7 @@
onWriteImpl(writingNode, writingResource->getStoredQueueSerial());
}
-void RecordableGraphResource::addReadDependency(RecordableGraphResource *readingResource)
+void CommandGraphResource::addReadDependency(CommandGraphResource *readingResource)
{
updateQueueSerial(readingResource->getStoredQueueSerial());
@@ -186,12 +172,12 @@
mCurrentReadingNodes.push_back(readingNode);
}
-void RecordableGraphResource::finishCurrentCommands(RendererVk *renderer)
+void CommandGraphResource::finishCurrentCommands(RendererVk *renderer)
{
startNewCommands(renderer);
}
-void RecordableGraphResource::startNewCommands(RendererVk *renderer)
+void CommandGraphResource::startNewCommands(RendererVk *renderer)
{
CommandGraphNode *newCommands =
renderer->getCommandGraph()->allocateNode(CommandGraphNodeFunction::Generic);
@@ -199,7 +185,7 @@
onWriteImpl(newCommands, renderer->getCurrentQueueSerial());
}
-void RecordableGraphResource::onWriteImpl(CommandGraphNode *writingNode, Serial currentSerial)
+void CommandGraphResource::onWriteImpl(CommandGraphNode *writingNode, Serial currentSerial)
{
updateQueueSerial(currentSerial);
@@ -219,44 +205,6 @@
mCurrentWritingNode = writingNode;
}
-// QueryGraphResource implementation.
-QueryGraphResource::QueryGraphResource() : CommandGraphResource(CommandGraphResourceType::Query) {}
-
-QueryGraphResource::~QueryGraphResource() = default;
-
-void QueryGraphResource::beginQuery(Context *context,
- const QueryPool *queryPool,
- uint32_t queryIndex)
-{
- startNewCommands(context->getRenderer(), CommandGraphNodeFunction::BeginQuery);
- mCurrentWritingNode->setQueryPool(queryPool, queryIndex);
-}
-
-void QueryGraphResource::endQuery(Context *context, const QueryPool *queryPool, uint32_t queryIndex)
-{
- startNewCommands(context->getRenderer(), CommandGraphNodeFunction::EndQuery);
- mCurrentWritingNode->setQueryPool(queryPool, queryIndex);
-}
-
-void QueryGraphResource::writeTimestamp(Context *context,
- const QueryPool *queryPool,
- uint32_t queryIndex)
-{
- startNewCommands(context->getRenderer(), CommandGraphNodeFunction::WriteTimestamp);
- mCurrentWritingNode->setQueryPool(queryPool, queryIndex);
-}
-
-void QueryGraphResource::startNewCommands(RendererVk *renderer, CommandGraphNodeFunction function)
-{
- CommandGraph *commandGraph = renderer->getCommandGraph();
- CommandGraphNode *newNode = commandGraph->allocateNode(function);
- newNode->setDiagnosticInfo(mResourceType, reinterpret_cast<uintptr_t>(this));
- commandGraph->setNewBarrier(newNode);
-
- mStoredQueueSerial = renderer->getCurrentQueueSerial();
- mCurrentWritingNode = newNode;
-}
-
// CommandGraphNode implementation.
CommandGraphNode::CommandGraphNode(CommandGraphNodeFunction function)
: mRenderPassClearValues{},
@@ -556,6 +504,16 @@
return newCommands;
}
+CommandGraphNode *CommandGraph::allocateBarrierNode(CommandGraphResourceType resourceType,
+ CommandGraphNodeFunction function)
+{
+ CommandGraphNode *newNode = allocateNode(function);
+ newNode->setDiagnosticInfo(resourceType, 0);
+ setNewBarrier(newNode);
+
+ return newNode;
+}
+
void CommandGraph::setNewBarrier(CommandGraphNode *newBarrier)
{
size_t previousBarrierIndex = 0;
@@ -681,6 +639,27 @@
mNodes.clear();
}
+void CommandGraph::beginQuery(const QueryPool *queryPool, uint32_t queryIndex)
+{
+ CommandGraphNode *newNode =
+ allocateBarrierNode(CommandGraphResourceType::Query, CommandGraphNodeFunction::BeginQuery);
+ newNode->setQueryPool(queryPool, queryIndex);
+}
+
+void CommandGraph::endQuery(const QueryPool *queryPool, uint32_t queryIndex)
+{
+ CommandGraphNode *newNode =
+ allocateBarrierNode(CommandGraphResourceType::Query, CommandGraphNodeFunction::EndQuery);
+ newNode->setQueryPool(queryPool, queryIndex);
+}
+
+void CommandGraph::writeTimestamp(const QueryPool *queryPool, uint32_t queryIndex)
+{
+ CommandGraphNode *newNode = allocateBarrierNode(CommandGraphResourceType::Query,
+ CommandGraphNodeFunction::WriteTimestamp);
+ newNode->setQueryPool(queryPool, queryIndex);
+}
+
// Dumps the command graph into a dot file that works with graphviz.
void CommandGraph::dumpGraphDotFile(std::ostream &out) const
{