comp: Add setting to force a vulkan gpu index

This commit is contained in:
Christoph Haag 2019-10-25 21:05:06 +02:00
parent 186f3ff7e0
commit 7d9ef2f371
5 changed files with 27 additions and 13 deletions

View file

@ -825,7 +825,7 @@ vk_get_device_functions(struct vk_bundle *vk)
*/
static VkResult
vk_select_physical_device(struct vk_bundle *vk)
vk_select_physical_device(struct vk_bundle *vk, int forced_index)
{
VkPhysicalDevice physical_devices[16];
uint32_t gpu_count = ARRAY_SIZE(physical_devices);
@ -848,14 +848,23 @@ vk_select_physical_device(struct vk_bundle *vk)
VK_DEBUG(vk, "Can not deal well with multiple devices.");
}
// as a first-step to 'intelligent' selection, prefer a 'discrete' gpu
// if it is present
VK_DEBUG(vk, "Choosing Vulkan device index");
uint32_t gpu_index = 0;
for (uint32_t i = 0; i < gpu_count; i++) {
VkPhysicalDeviceProperties pdp;
vk->vkGetPhysicalDeviceProperties(physical_devices[i], &pdp);
if (pdp.deviceType == VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU) {
gpu_index = i;
if (forced_index > -1) {
gpu_index = forced_index;
VK_DEBUG(vk, "Forced use of Vulkan device index %d.",
gpu_index);
} else {
// as a first-step to 'intelligent' selection, prefer a
// 'discrete' gpu if it is present
for (uint32_t i = 0; i < gpu_count; i++) {
VkPhysicalDeviceProperties pdp;
vk->vkGetPhysicalDeviceProperties(physical_devices[i],
&pdp);
if (pdp.deviceType ==
VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU) {
gpu_index = i;
}
}
}
@ -929,11 +938,11 @@ err_free:
}
VkResult
vk_create_device(struct vk_bundle *vk)
vk_create_device(struct vk_bundle *vk, int forced_index)
{
VkResult ret;
ret = vk_select_physical_device(vk);
ret = vk_select_physical_device(vk, forced_index);
if (ret != VK_SUCCESS) {
return ret;
}

View file

@ -253,7 +253,7 @@ vk_init_cmd_pool(struct vk_bundle *vk);
* @ingroup comp_common
*/
VkResult
vk_create_device(struct vk_bundle *vk);
vk_create_device(struct vk_bundle *vk, int forced_index);
/*!
* Initialize a bundle with objects given to us by client code,

View file

@ -442,7 +442,7 @@ compositor_init_vulkan(struct comp_compositor *c)
return false;
}
ret = vk_create_device(&c->vk);
ret = vk_create_device(&c->vk, c->settings.gpu_index);
if (ret != VK_SUCCESS) {
return false;
}
@ -531,7 +531,7 @@ compositor_check_vulkan_caps(struct comp_compositor *c)
}
// follow same device selection logic as subsequent calls
ret = vk_create_device(&temp_vk);
ret = vk_create_device(&temp_vk, c->settings.gpu_index);
if (ret != VK_SUCCESS) {
COMP_ERROR(c, "Failed to create VkDevice: %s",
vk_result_string(ret));

View file

@ -18,6 +18,7 @@ DEBUG_GET_ONCE_BOOL_OPTION(force_nvidia, "XRT_COMPOSITOR_FORCE_NVIDIA", false)
DEBUG_GET_ONCE_BOOL_OPTION(force_xcb, "XRT_COMPOSITOR_FORCE_XCB", false)
DEBUG_GET_ONCE_BOOL_OPTION(force_wayland, "XRT_COMPOSITOR_FORCE_WAYLAND", false)
DEBUG_GET_ONCE_BOOL_OPTION(validate_vulkan, "XRT_COMPOSITOR_VULKAN_VALIDATION", false)
DEBUG_GET_ONCE_NUM_OPTION(force_gpu_index, "XRT_COMPOSITOR_FORCE_GPU_INDEX", -1)
// clang-format on
void
@ -43,6 +44,7 @@ comp_settings_init(struct comp_settings *s, struct xrt_device *xdev)
s->print_spew = debug_get_bool_option_print_spew();
s->print_debug = debug_get_bool_option_print_debug();
s->validate_vulkan = debug_get_bool_option_validate_vulkan();
s->gpu_index = debug_get_num_option_force_gpu_index();
if (debug_get_bool_option_force_nvidia()) {
s->window_type = WINDOW_DIRECT_NVIDIA;

View file

@ -84,6 +84,9 @@ struct comp_settings
//! Enable vulkan validation for compositor
bool validate_vulkan;
//! Run the compositor on this Vulkan physical device
int gpu_index;
};
/*!