Skip to content

Commit

Permalink
Prefer discrete GPU over integrated one
Browse files Browse the repository at this point in the history
This unblocks launching on Linux laptops that default to the integrated
GPU which can not handle Vulkan in many instances.
Ideally a manual device selection, or an option for the optimal selection
strategy should be provided via CLI or config, but for the time being
this will unblock the Linux devs.

Partially addresses godotengine#42348 and godotengine#43714
  • Loading branch information
bfloch authored and akien-mga committed Jun 11, 2021
1 parent a59286f commit 36130e5
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion drivers/vulkan/vulkan_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -379,8 +379,25 @@ Error VulkanContext::_create_physical_device() {
free(physical_devices);
ERR_FAIL_V(ERR_CANT_CREATE);
}
/* for now, just grab the first physical device */

// TODO: At least on Linux Laptops integrated GPUs fail with Vulkan in many instances.
// The device should really be a preference, but for now choosing a discrete GPU over the
// integrated one is better than the default.

// Default to first device
uint32_t device_index = 0;

for (uint32_t i = 0; i < gpu_count; ++i) {
VkPhysicalDeviceProperties props;
vkGetPhysicalDeviceProperties(physical_devices[i], &props);

if (props.deviceType == VkPhysicalDeviceType::VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU) {
// Prefer discrete GPU.
device_index = i;
break;
}
}

gpu = physical_devices[device_index];
free(physical_devices);

Expand Down

0 comments on commit 36130e5

Please sign in to comment.