Vulkan: Update resource dependency semantics.

This removes passing the Serial around to several methods, so that
dependency management is a bit more automatic.

This makes life a bit easier when dealing with state updates when
resources are in use by Vulkan.

The FramebuffeVk no longer stores an extra serial of the last draw,
instead it will trigger creation of a new writing node on a state
change update.

Bug: angleproject:2318
Change-Id: Ie58ec66e6e8644ba4d402c509255c3795d363dd3
Reviewed-on: https://chromium-review.googlesource.com/985201
Commit-Queue: Jamie Madill <jmadill@chromium.org>
Reviewed-by: Frank Henigman <fjhenigman@chromium.org>
diff --git a/src/libANGLE/renderer/vulkan/CommandGraph.cpp b/src/libANGLE/renderer/vulkan/CommandGraph.cpp
index e8ed327..fe0b95f 100644
--- a/src/libANGLE/renderer/vulkan/CommandGraph.cpp
+++ b/src/libANGLE/renderer/vulkan/CommandGraph.cpp
@@ -77,15 +77,13 @@
     return mStoredQueueSerial;
 }
 
-bool CommandGraphResource::hasCurrentWritingNode(Serial currentSerial) const
+bool CommandGraphResource::hasChildlessWritingNode() const
 {
-    return (mStoredQueueSerial == currentSerial && mCurrentWritingNode != nullptr &&
-            !mCurrentWritingNode->hasChildren());
+    return (mCurrentWritingNode != nullptr && !mCurrentWritingNode->hasChildren());
 }
 
-CommandGraphNode *CommandGraphResource::getCurrentWritingNode(Serial currentSerial)
+CommandGraphNode *CommandGraphResource::getCurrentWritingNode()
 {
-    ASSERT(currentSerial == mStoredQueueSerial);
     return mCurrentWritingNode;
 }
 
@@ -111,7 +109,7 @@
 {
     updateQueueSerial(serial);
 
-    // Make sure any open reads and writes finish before we execute 'newCommands'.
+    // Make sure any open reads and writes finish before we execute 'writingNode'.
     if (!mCurrentReadingNodes.empty())
     {
         CommandGraphNode::SetHappensBeforeDependencies(mCurrentReadingNodes, writingNode);
@@ -128,19 +126,32 @@
 
 void CommandGraphResource::onReadResource(CommandGraphNode *readingNode, Serial serial)
 {
-    if (hasCurrentWritingNode(serial))
+    updateQueueSerial(serial);
+
+    if (hasChildlessWritingNode())
     {
-        // Ensure 'readOperation' happens after the current write commands.
-        CommandGraphNode::SetHappensBeforeDependency(getCurrentWritingNode(serial), readingNode);
         ASSERT(mStoredQueueSerial == serial);
+
+        // Ensure 'readingNode' happens after the current writing node.
+        CommandGraphNode::SetHappensBeforeDependency(mCurrentWritingNode, readingNode);
+    }
+
+    // Add the read node to the list of nodes currently reading this resource.
+    mCurrentReadingNodes.push_back(readingNode);
+}
+
+bool CommandGraphResource::checkResourceInUseAndRefreshDeps(RendererVk *renderer)
+{
+    if (!renderer->isResourceInUse(*this))
+    {
+        mCurrentReadingNodes.clear();
+        mCurrentWritingNode = nullptr;
+        return false;
     }
     else
     {
-        updateQueueSerial(serial);
+        return true;
     }
-
-    // Add the read operation to the list of nodes currently reading this resource.
-    mCurrentReadingNodes.push_back(readingNode);
 }
 
 // CommandGraphNode implementation.
@@ -247,9 +258,9 @@
 void CommandGraphNode::SetHappensBeforeDependency(CommandGraphNode *beforeNode,
                                                   CommandGraphNode *afterNode)
 {
+    ASSERT(beforeNode != afterNode && !beforeNode->isChildOf(afterNode));
     afterNode->mParents.emplace_back(beforeNode);
     beforeNode->setHasChildren();
-    ASSERT(beforeNode != afterNode && !beforeNode->isChildOf(afterNode));
 }
 
 // static