Add Sleep on windows GrVkGpu dtor to avoid fence bug

BUG=skia:5458
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2099813002

Review-Url: https://codereview.chromium.org/2099813002
diff --git a/src/gpu/vk/GrVkGpu.cpp b/src/gpu/vk/GrVkGpu.cpp
index 0bb99c0..ee5d324 100644
--- a/src/gpu/vk/GrVkGpu.cpp
+++ b/src/gpu/vk/GrVkGpu.cpp
@@ -154,6 +154,20 @@
     // wait for all commands to finish
     fResourceProvider.checkCommandBuffers();
     SkDEBUGCODE(VkResult res = ) VK_CALL(QueueWaitIdle(fQueue));
+
+    // On windows, sometimes calls to QueueWaitIdle return before actually signalling the fences
+    // on the command buffers even though they have completed. This causes an assert to fire when
+    // destroying the command buffers. Currently this ony seems to happen on windows, so we add a
+    // sleep to make sure the fence singals.
+#ifdef SK_DEBUG
+#if defined(SK_BUILD_FOR_WIN)
+    Sleep(10); // In milliseconds
+#else
+    // Uncomment if above bug happens on non windows build.
+    // sleep(1);        // In seconds
+#endif
+#endif
+
     // VK_ERROR_DEVICE_LOST is acceptable when tearing down (see 4.2.4 in spec)
     SkASSERT(VK_SUCCESS == res || VK_ERROR_DEVICE_LOST == res);