diff --git a/gfx/common/vulkan_common.c b/gfx/common/vulkan_common.c index 0e369bd870..fa216c3e4f 100644 --- a/gfx/common/vulkan_common.c +++ b/gfx/common/vulkan_common.c @@ -1892,6 +1892,10 @@ static bool vulkan_create_display_surface(gfx_ctx_vulkan_data_t *vk, VkDisplayPlaneAlphaFlagBitsKHR alpha_mode = VK_DISPLAY_PLANE_ALPHA_OPAQUE_BIT_KHR; VkDisplaySurfaceCreateInfoKHR create_info = { VK_STRUCTURE_TYPE_DISPLAY_SURFACE_CREATE_INFO_KHR }; VkDisplayModeKHR best_mode = VK_NULL_HANDLE; + /* Monitor index starts on 1, 0 is auto. */ + unsigned monitor_index = info->monitor_index; + unsigned saved_width = *width; + unsigned saved_height = *height; /* We need to decide on GPU here to be able to query support. */ if (!vulkan_context_init_gpu(vk)) @@ -1933,8 +1937,18 @@ static bool vulkan_create_display_surface(gfx_ctx_vulkan_data_t *vk, if (vkGetPhysicalDeviceDisplayPlanePropertiesKHR(vk->context.gpu, &plane_count, planes) != VK_SUCCESS) GOTO_FAIL(); + if (monitor_index > display_count) + { + RARCH_WARN("Monitor index is out of range, using automatic display.\n"); + monitor_index = 0; + } + +retry: for (dpy = 0; dpy < display_count; dpy++) { + if (monitor_index != 0 && (monitor_index - 1) != dpy) + continue; + VkDisplayKHR display = displays[dpy].display; best_mode = VK_NULL_HANDLE; best_plane = UINT32_MAX; @@ -2016,6 +2030,18 @@ static bool vulkan_create_display_surface(gfx_ctx_vulkan_data_t *vk, } out: + if (best_plane == UINT32_MAX && monitor_index != 0) + { + RARCH_WARN("Could not find suitable surface for monitor index: %u.\n", + monitor_index); + RARCH_WARN("Retrying first suitable monitor.\n"); + monitor_index = 0; + best_mode = VK_NULL_HANDLE; + *width = saved_width; + *height = saved_height; + goto retry; + } + if (best_mode == VK_NULL_HANDLE) GOTO_FAIL(); if (best_plane == UINT32_MAX) diff --git a/gfx/common/vulkan_common.h b/gfx/common/vulkan_common.h index 4f70e7981a..7757e3f1d3 100644 --- a/gfx/common/vulkan_common.h +++ b/gfx/common/vulkan_common.h @@ -139,6 +139,7 @@ struct vulkan_display_surface_info { unsigned width; unsigned height; + unsigned monitor_index; }; struct vk_color diff --git a/gfx/drivers_context/khr_display_ctx.c b/gfx/drivers_context/khr_display_ctx.c index 0d671bbe4a..747d16e7f0 100644 --- a/gfx/drivers_context/khr_display_ctx.c +++ b/gfx/drivers_context/khr_display_ctx.c @@ -126,8 +126,9 @@ static bool gfx_ctx_khr_display_set_video_mode(void *data, height = 0; } - info.width = width; - info.height = height; + info.width = width; + info.height = height; + info.monitor_index = video_info->monitor_index; if (!vulkan_surface_create(&khr->vk, VULKAN_WSI_DISPLAY, &info, NULL, 0, 0, khr->swap_interval))