From 429f3aaacfaf6b7b8a81d6d4710f16658df66aca Mon Sep 17 00:00:00 2001 From: unexploredtest Date: Mon, 12 Apr 2021 10:25:48 +0430 Subject: [PATCH] Raises an error if 1: There is no Vulkan device 2: physicalDeviceIndex exceeds the device limit --- src/Manager.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/Manager.cpp b/src/Manager.cpp index a78cc7a34..d5e9ce9fc 100644 --- a/src/Manager.cpp +++ b/src/Manager.cpp @@ -287,6 +287,25 @@ Manager::createDevice(const std::vector& familyQueueIndices, } this->mFreeDevice = true; + + // Getting an integer that says how many vuklan devices we have + uint32_t deviceCount = 0; + vkEnumeratePhysicalDevices(*(this->mInstance), &deviceCount, nullptr); + + // This means there are no devices at all + if (deviceCount == 0) { + throw std::runtime_error("Failed to find GPUs with Vulkan support! " + "Maybe you haven't installed vulkan drivers?"); + } + + // This means that we're exceeding our device limit, for + // example if we have 2 devices, just physicalDeviceIndex + // 0 and 1 are acceptable. Hence, physicalDeviceIndex should + // always be less than deviceCount, else we raise an error + if ( !(deviceCount > physicalDeviceIndex) ) { + throw std::runtime_error("There is no such physical index or device, " + "please use your existing device"); + } std::vector physicalDevices = this->mInstance->enumeratePhysicalDevices();