From a41d48b739c144ee7b36290a9642064bc6cdcd05 Mon Sep 17 00:00:00 2001 From: Greg Daniel Date: Thu, 27 Apr 2017 12:57:59 -0400 Subject: [PATCH] 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 Commit-Queue: Greg Daniel --- src/gpu/vk/GrVkBackendContext.cpp | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) 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 @@ const GrVkBackendContext* GrVkBackendContext::Create(uint32_t* presentQueueIndex 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 @@ const GrVkBackendContext* GrVkBackendContext::Create(uint32_t* presentQueueIndex // 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 @@ const GrVkBackendContext* GrVkBackendContext::Create(uint32_t* presentQueueIndex 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 @@ const GrVkBackendContext* GrVkBackendContext::Create(uint32_t* presentQueueIndex 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); -- 2.7.4