From 268b7ba99385d6295c10d4e3a22304376455f400 Mon Sep 17 00:00:00 2001 From: Steven <38004233+shg8@users.noreply.github.com> Date: Fri, 12 Apr 2024 02:36:46 -0500 Subject: [PATCH] Fix physical device selection (#29) --- apps/viewer/main.cpp | 4 ++-- src/vulkan/VulkanContext.cpp | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/apps/viewer/main.cpp b/apps/viewer/main.cpp index e65a3e6..8393072 100644 --- a/apps/viewer/main.cpp +++ b/apps/viewer/main.cpp @@ -15,7 +15,7 @@ int main(int argc, char** argv) { parser, "validation-layers", "Enable Vulkan validation layers", {"validation"} }; args::Flag verboseFlag{parser, "verbose", "Enable verbose logging", {'v', "verbose"}}; - args::ValueFlag physicalDeviceIdFlag{ + args::ValueFlag physicalDeviceIdFlag{ parser, "physical-device", "Select physical device by index", {'d', "device"} }; args::Flag immediateSwapchainFlag{ @@ -73,7 +73,7 @@ int main(int argc, char** argv) { } if (physicalDeviceIdFlag) { - config.physicalDeviceId = std::make_optional(args::get(physicalDeviceIdFlag)); + config.physicalDeviceId = std::make_optional(static_cast(args::get(physicalDeviceIdFlag))); } if (immediateSwapchainFlag) { diff --git a/src/vulkan/VulkanContext.cpp b/src/vulkan/VulkanContext.cpp index e18259d..2494648 100644 --- a/src/vulkan/VulkanContext.cpp +++ b/src/vulkan/VulkanContext.cpp @@ -145,6 +145,10 @@ void VulkanContext::selectPhysicalDevice(std::optional id, std::optiona spdlog::info("[{}] {}", ind++, device.getProperties().deviceName); } + if (surface.has_value()) { + deviceExtensions.push_back(VK_KHR_SWAPCHAIN_EXTENSION_NAME); + } + if (id.has_value()) { if (devices.size() <= id.value()) { throw std::runtime_error("Invalid physical device id"); @@ -154,10 +158,6 @@ void VulkanContext::selectPhysicalDevice(std::optional id, std::optiona return; } - if (surface.has_value()) { - deviceExtensions.push_back(VK_KHR_SWAPCHAIN_EXTENSION_NAME); - } - auto suitableDevices = std::vector{}; for (auto& device: devices) { if (isDeviceSuitable(device, surface)) {