| 293 | } |
| 294 | |
| 295 | void |
| 296 | Manager::createDevice(const std::vector<uint32_t>& familyQueueIndices, |
| 297 | uint32_t physicalDeviceIndex, |
| 298 | const std::vector<std::string>& desiredExtensions) |
| 299 | { |
| 300 | |
| 301 | KP_LOG_DEBUG("Kompute Manager creating Device"); |
| 302 | |
| 303 | if (this->mInstance == nullptr) { |
| 304 | throw std::runtime_error("Kompute Manager instance is null"); |
| 305 | } |
| 306 | |
| 307 | this->mFreeDevice = true; |
| 308 | |
| 309 | // Getting an integer that says how many vuklan devices we have |
| 310 | std::vector<vk::PhysicalDevice> physicalDevices = |
| 311 | this->mInstance->enumeratePhysicalDevices(); |
| 312 | uint32_t deviceCount = physicalDevices.size(); |
| 313 | |
| 314 | // This means there are no devices at all |
| 315 | if (deviceCount == 0) { |
| 316 | throw std::runtime_error("Failed to find GPUs with Vulkan support! " |
| 317 | "Maybe you haven't installed vulkan drivers?"); |
| 318 | } |
| 319 | |
| 320 | // This means that we're exceeding our device limit, for |
| 321 | // example if we have 2 devices, just physicalDeviceIndex |
| 322 | // 0 and 1 are acceptable. Hence, physicalDeviceIndex should |
| 323 | // always be less than deviceCount, else we raise an error |
| 324 | if (!(deviceCount > physicalDeviceIndex)) { |
| 325 | throw std::runtime_error("There is no such physical index or device, " |
| 326 | "please use your existing device"); |
| 327 | } |
| 328 | |
| 329 | vk::PhysicalDevice physicalDevice = physicalDevices[physicalDeviceIndex]; |
| 330 | |
| 331 | this->mPhysicalDevice = |
| 332 | std::make_shared<vk::PhysicalDevice>(physicalDevice); |
| 333 | |
| 334 | #if KOMPUTE_OPT_ACTIVE_LOG_LEVEL <= KOMPUTE_LOG_LEVEL_INFO |
| 335 | vk::PhysicalDeviceProperties physicalDeviceProperties = |
| 336 | physicalDevice.getProperties(); |
| 337 | #endif |
| 338 | |
| 339 | KP_LOG_INFO("Using physical device index {} found {}", |
| 340 | physicalDeviceIndex, |
| 341 | physicalDeviceProperties.deviceName.data()); |
| 342 | |
| 343 | if (familyQueueIndices.empty()) { |
| 344 | // Find compute queue |
| 345 | std::vector<vk::QueueFamilyProperties> allQueueFamilyProperties = |
| 346 | physicalDevice.getQueueFamilyProperties(); |
| 347 | |
| 348 | uint32_t computeQueueFamilyIndex = 0; |
| 349 | bool computeQueueSupported = false; |
| 350 | for (uint32_t i = 0; i < allQueueFamilyProperties.size(); i++) { |
| 351 | vk::QueueFamilyProperties queueFamilyProperties = |
| 352 | allQueueFamilyProperties[i]; |