Add additional checks when creating vulkan context

Makes sure we get the phsyical devices and queues we expect

Bug: skia:
Change-Id: I13031caa8aa85d680a8e921bee3237d6b53cebf0
Reviewed-on: https://skia-review.googlesource.com/14523
Reviewed-by: Jim Van Verth <jvanverth@google.com>
Commit-Queue: Greg Daniel <egdaniel@google.com>
diff --git a/src/gpu/vk/GrVkBackendContext.cpp b/src/gpu/vk/GrVkBackendContext.cpp
index 479d680..e473178 100644
--- a/src/gpu/vk/GrVkBackendContext.cpp
+++ b/src/gpu/vk/GrVkBackendContext.cpp
@@ -147,7 +147,11 @@
         grVkDestroyInstance(inst, nullptr);
         return nullptr;
     }
-    SkASSERT(gpuCount > 0);
+    if (!gpuCount) {
+        SkDebugf("vkEnumeratePhysicalDevices returned no supported devices.\n");
+        grVkDestroyInstance(inst, nullptr);
+        return nullptr;
+    }
     // Just returning the first physical device instead of getting the whole array.
     // TODO: find best match for our needs
     gpuCount = 1;
@@ -161,7 +165,11 @@
     // query to get the initial queue props size
     uint32_t queueCount;
     grVkGetPhysicalDeviceQueueFamilyProperties(physDev, &queueCount, nullptr);
-    SkASSERT(queueCount >= 1);
+    if (!queueCount) {
+        SkDebugf("vkGetPhysicalDeviceQueueFamilyProperties returned no queues.\n");
+        grVkDestroyInstance(inst, nullptr);
+        return nullptr;
+    }
 
     SkAutoMalloc queuePropsAlloc(queueCount * sizeof(VkQueueFamilyProperties));
     // now get the actual queue props
@@ -177,10 +185,14 @@
             break;
         }
     }
-    SkASSERT(graphicsQueueIndex < queueCount);
+    if (graphicsQueueIndex == queueCount) {
+        SkDebugf("Could not find any supported graphics queues.\n");
+        grVkDestroyInstance(inst, nullptr);
+        return nullptr;
+    }
 
     // iterate to find the present queue, if needed
-    uint32_t presentQueueIndex = graphicsQueueIndex;
+    uint32_t presentQueueIndex = queueCount;
     if (presentQueueIndexPtr && canPresent) {
         for (uint32_t i = 0; i < queueCount; i++) {
             if (canPresent(inst, physDev, i)) {
@@ -188,8 +200,16 @@
                 break;
             }
         }
-        SkASSERT(presentQueueIndex < queueCount);
+        if (presentQueueIndex == queueCount) {
+            SkDebugf("Could not find any supported present queues.\n");
+            grVkDestroyInstance(inst, nullptr);
+            return nullptr;
+        }
         *presentQueueIndexPtr = presentQueueIndex;
+    } else {
+        // Just setting this so we end up make a single queue for graphics since there was no
+        // request for a present queue.
+        presentQueueIndex = graphicsQueueIndex;
     }
 
     extensions.initDevice(kGrVkMinimumVersion, inst, physDev);