Vulkan: Implement GL_EXT_disjoint_timer_query

- QueryVk::queryCounter() and relevant utils are implemented for the
sake of Timestamp queries.
- TimeElapsed queries are implemented using two Timestamp queries.

Bug: angleproject:2885
Change-Id: Id181bd97f5a24e7e96b3ea1b819483227e64daf0
Reviewed-on: https://chromium-review.googlesource.com/c/1276806
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 5b0d951..6cadc02 100644
--- a/src/libANGLE/renderer/vulkan/CommandGraph.cpp
+++ b/src/libANGLE/renderer/vulkan/CommandGraph.cpp
@@ -65,6 +65,8 @@
                     return "BeginQuery";
                 case CommandGraphNodeFunction::EndQuery:
                     return "EndQuery";
+                case CommandGraphNodeFunction::WriteTimestamp:
+                    return "WriteTimestamp";
                 default:
                     UNREACHABLE();
                     return "Query";
@@ -196,6 +198,14 @@
     mCurrentWritingNode->setQueryPool(queryPool, queryIndex);
 }
 
+void CommandGraphResource::writeTimestamp(Context *context,
+                                          const QueryPool *queryPool,
+                                          uint32_t queryIndex)
+{
+    startNewCommands(context->getRenderer(), CommandGraphNodeFunction::WriteTimestamp);
+    mCurrentWritingNode->setQueryPool(queryPool, queryIndex);
+}
+
 void CommandGraphResource::finishCurrentCommands(RendererVk *renderer)
 {
     startNewCommands(renderer, CommandGraphNodeFunction::Generic);
@@ -387,7 +397,8 @@
 void CommandGraphNode::setQueryPool(const QueryPool *queryPool, uint32_t queryIndex)
 {
     ASSERT(mFunction == CommandGraphNodeFunction::BeginQuery ||
-           mFunction == CommandGraphNodeFunction::EndQuery);
+           mFunction == CommandGraphNodeFunction::EndQuery ||
+           mFunction == CommandGraphNodeFunction::WriteTimestamp);
     mQueryPool  = queryPool->getHandle();
     mQueryIndex = queryIndex;
 }
@@ -496,6 +507,16 @@
 
             break;
 
+        case CommandGraphNodeFunction::WriteTimestamp:
+            ASSERT(!mOutsideRenderPassCommands.valid() && !mInsideRenderPassCommands.valid());
+            ASSERT(mQueryPool != VK_NULL_HANDLE);
+
+            primaryCommandBuffer->resetQueryPool(mQueryPool, mQueryIndex, 1);
+            primaryCommandBuffer->writeTimestamp(VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT, mQueryPool,
+                                                 mQueryIndex);
+
+            break;
+
         default:
             UNREACHABLE();
     }