Setup logical device and device queue
| 665 | |
| 666 | // Setup logical device and device queue |
| 667 | void setupLogicalDevice() |
| 668 | { |
| 669 | // Select a queue family that supports graphics operations and surface presentation |
| 670 | std::uint32_t objectCount = 0; |
| 671 | |
| 672 | std::vector<VkQueueFamilyProperties> queueFamilyProperties; |
| 673 | |
| 674 | vkGetPhysicalDeviceQueueFamilyProperties(gpu, &objectCount, nullptr); |
| 675 | |
| 676 | queueFamilyProperties.resize(objectCount); |
| 677 | |
| 678 | vkGetPhysicalDeviceQueueFamilyProperties(gpu, &objectCount, queueFamilyProperties.data()); |
| 679 | |
| 680 | for (std::size_t i = 0; i < queueFamilyProperties.size(); ++i) |
| 681 | { |
| 682 | VkBool32 surfaceSupported = VK_FALSE; |
| 683 | |
| 684 | vkGetPhysicalDeviceSurfaceSupportKHR(gpu, static_cast<std::uint32_t>(i), surface, &surfaceSupported); |
| 685 | |
| 686 | if ((queueFamilyProperties[i].queueFlags & VK_QUEUE_GRAPHICS_BIT) && (surfaceSupported == VK_TRUE)) |
| 687 | { |
| 688 | queueFamilyIndex = static_cast<std::uint32_t>(i); |
| 689 | break; |
| 690 | } |
| 691 | } |
| 692 | |
| 693 | if (!queueFamilyIndex.has_value()) |
| 694 | { |
| 695 | vulkanAvailable = false; |
| 696 | return; |
| 697 | } |
| 698 | |
| 699 | const float queuePriority = 1.0f; |
| 700 | |
| 701 | VkDeviceQueueCreateInfo deviceQueueCreateInfo = VkDeviceQueueCreateInfo(); |
| 702 | deviceQueueCreateInfo.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO; |
| 703 | deviceQueueCreateInfo.queueCount = 1; |
| 704 | deviceQueueCreateInfo.queueFamilyIndex = *queueFamilyIndex; |
| 705 | deviceQueueCreateInfo.pQueuePriorities = &queuePriority; |
| 706 | |
| 707 | // Enable the swapchain extension |
| 708 | static constexpr std::array extensions = {VK_KHR_SWAPCHAIN_EXTENSION_NAME}; |
| 709 | |
| 710 | // Enable anisotropic filtering |
| 711 | VkPhysicalDeviceFeatures physicalDeviceFeatures = VkPhysicalDeviceFeatures(); |
| 712 | physicalDeviceFeatures.samplerAnisotropy = VK_TRUE; |
| 713 | |
| 714 | VkDeviceCreateInfo deviceCreateInfo = VkDeviceCreateInfo(); |
| 715 | deviceCreateInfo.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO; |
| 716 | deviceCreateInfo.enabledExtensionCount = static_cast<std::uint32_t>(extensions.size()); |
| 717 | deviceCreateInfo.ppEnabledExtensionNames = extensions.data(); |
| 718 | deviceCreateInfo.queueCreateInfoCount = 1; |
| 719 | deviceCreateInfo.pQueueCreateInfos = &deviceQueueCreateInfo; |
| 720 | deviceCreateInfo.pEnabledFeatures = &physicalDeviceFeatures; |
| 721 | |
| 722 | // Create our logical device |
| 723 | if (vkCreateDevice(gpu, &deviceCreateInfo, nullptr, &device) != VK_SUCCESS) |
| 724 | { |
nothing calls this directly
no test coverage detected