Move the vk Serial class to renderer_utils.

This can be useful for other back-ends, for various types of state
management. Also redesign the class to use an opaque factory instead
of an increment operator. The class maintains the property of being
ordered. Also assume we don't overflow with 64-bit serials. We could
maybe redesign this to use 32-bit serials for memory constrained
situations, and handle overflow more gracefully.

I plan to use the serials to track state revisions for the vertex
array class, to avoid doing redundant work.

BUG=angleproject:1156

Change-Id: I02c78b228bc6e2fb3ee786fe67a4e607baaca18e
Reviewed-on: https://chromium-review.googlesource.com/529704
Reviewed-by: Geoff Lang <geofflang@chromium.org>
Commit-Queue: Jamie Madill <jmadill@chromium.org>
diff --git a/src/libANGLE/renderer/vulkan/RendererVk.cpp b/src/libANGLE/renderer/vulkan/RendererVk.cpp
index 1f51cd6..0a0f3b8 100644
--- a/src/libANGLE/renderer/vulkan/RendererVk.cpp
+++ b/src/libANGLE/renderer/vulkan/RendererVk.cpp
@@ -95,11 +95,10 @@
       mDevice(VK_NULL_HANDLE),
       mHostVisibleMemoryIndex(std::numeric_limits<uint32_t>::max()),
       mGlslangWrapper(nullptr),
-      mCurrentQueueSerial(),
-      mLastCompletedQueueSerial(),
+      mLastCompletedQueueSerial(mQueueSerialFactory.generate()),
+      mCurrentQueueSerial(mQueueSerialFactory.generate()),
       mInFlightCommands()
 {
-    ++mCurrentQueueSerial;
 }
 
 RendererVk::~RendererVk()
@@ -732,7 +731,8 @@
     ASSERT(mInFlightCommands.size() < 1000u);
 
     // Increment the queue serial. If this fails, we should restart ANGLE.
-    ANGLE_VK_CHECK(++mCurrentQueueSerial, VK_ERROR_OUT_OF_HOST_MEMORY);
+    // TODO(jmadill): Overflow check.
+    mCurrentQueueSerial = mQueueSerialFactory.generate();
 
     return vk::NoError();
 }
@@ -757,7 +757,8 @@
     ASSERT(mInFlightCommands.size() < 1000u);
 
     // Increment the queue serial. If this fails, we should restart ANGLE.
-    ANGLE_VK_CHECK(++mCurrentQueueSerial, VK_ERROR_OUT_OF_HOST_MEMORY);
+    // TODO(jmadill): Overflow check.
+    mCurrentQueueSerial = mQueueSerialFactory.generate();
 
     ANGLE_TRY(checkInFlightCommands());