Skip to content

Commit

Permalink
Fix physical device selection (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
shg8 authored Apr 12, 2024
1 parent b34541f commit 268b7ba
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions apps/viewer/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint8_t> physicalDeviceIdFlag{
args::ValueFlag<uint32_t> physicalDeviceIdFlag{
parser, "physical-device", "Select physical device by index", {'d', "device"}
};
args::Flag immediateSwapchainFlag{
Expand Down Expand Up @@ -73,7 +73,7 @@ int main(int argc, char** argv) {
}

if (physicalDeviceIdFlag) {
config.physicalDeviceId = std::make_optional<uint8_t>(args::get(physicalDeviceIdFlag));
config.physicalDeviceId = std::make_optional<uint8_t>(static_cast<uint8_t>(args::get(physicalDeviceIdFlag)));
}

if (immediateSwapchainFlag) {
Expand Down
8 changes: 4 additions & 4 deletions src/vulkan/VulkanContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,10 @@ void VulkanContext::selectPhysicalDevice(std::optional<uint8_t> 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");
Expand All @@ -154,10 +158,6 @@ void VulkanContext::selectPhysicalDevice(std::optional<uint8_t> id, std::optiona
return;
}

if (surface.has_value()) {
deviceExtensions.push_back(VK_KHR_SWAPCHAIN_EXTENSION_NAME);
}

auto suitableDevices = std::vector<vk::PhysicalDevice>{};
for (auto& device: devices) {
if (isDeviceSuitable(device, surface)) {
Expand Down

0 comments on commit 268b7ba

Please sign in to comment.