| 544 | } |
| 545 | |
| 546 | void VulkanBaseApp::createDevice() |
| 547 | { |
| 548 | { |
| 549 | uint32_t deviceCount = 0; |
| 550 | vkEnumeratePhysicalDevices(m_instance, &deviceCount, nullptr); |
| 551 | if (deviceCount == 0) { |
| 552 | throw std::runtime_error("Failed to find Vulkan capable GPUs!"); |
| 553 | } |
| 554 | std::vector<VkPhysicalDevice> phyDevs(deviceCount); |
| 555 | vkEnumeratePhysicalDevices(m_instance, &deviceCount, phyDevs.data()); |
| 556 | std::vector<VkPhysicalDevice>::iterator it = std::find_if( |
| 557 | phyDevs.begin(), phyDevs.end(), std::bind(&VulkanBaseApp::isSuitableDevice, this, std::placeholders::_1)); |
| 558 | if (it == phyDevs.end()) { |
| 559 | throw std::runtime_error("No suitable device found!"); |
| 560 | } |
| 561 | m_physicalDevice = *it; |
| 562 | } |
| 563 | |
| 564 | uint32_t graphicsQueueIndex, presentQueueIndex; |
| 565 | findGraphicsQueueIndicies(m_physicalDevice, m_surface, graphicsQueueIndex, presentQueueIndex); |
| 566 | |
| 567 | std::vector<VkDeviceQueueCreateInfo> queueCreateInfos; |
| 568 | std::set<uint32_t> uniqueFamilyIndices = {graphicsQueueIndex, presentQueueIndex}; |
| 569 | |
| 570 | float queuePriority = 1.0f; |
| 571 | |
| 572 | for (uint32_t queueFamily : uniqueFamilyIndices) { |
| 573 | VkDeviceQueueCreateInfo queueCreateInfo = {}; |
| 574 | queueCreateInfo.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO; |
| 575 | queueCreateInfo.queueFamilyIndex = queueFamily; |
| 576 | queueCreateInfo.queueCount = 1; |
| 577 | queueCreateInfo.pQueuePriorities = &queuePriority; |
| 578 | queueCreateInfos.push_back(queueCreateInfo); |
| 579 | } |
| 580 | |
| 581 | VkPhysicalDeviceFeatures deviceFeatures = {}; |
| 582 | deviceFeatures.fillModeNonSolid = true; |
| 583 | |
| 584 | VkDeviceCreateInfo createInfo = {}; |
| 585 | createInfo.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO; |
| 586 | |
| 587 | #ifdef _VK_TIMELINE_SEMAPHORE |
| 588 | VkPhysicalDeviceVulkan12Features vk12features = {}; |
| 589 | vk12features.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_2_FEATURES; |
| 590 | vk12features.timelineSemaphore = true; |
| 591 | createInfo.pNext = &vk12features; |
| 592 | #endif |
| 593 | |
| 594 | createInfo.pQueueCreateInfos = queueCreateInfos.data(); |
| 595 | createInfo.queueCreateInfoCount = static_cast<uint32_t>(queueCreateInfos.size()); |
| 596 | |
| 597 | createInfo.pEnabledFeatures = &deviceFeatures; |
| 598 | |
| 599 | std::vector<const char *> deviceExtensions = getRequiredDeviceExtensions(); |
| 600 | deviceExtensions.push_back(VK_KHR_SWAPCHAIN_EXTENSION_NAME); |
| 601 | |
| 602 | createInfo.enabledExtensionCount = static_cast<uint32_t>(deviceExtensions.size()); |
| 603 | createInfo.ppEnabledExtensionNames = deviceExtensions.data(); |
nothing calls this directly
no test coverage detected