From 2044f2910ca496f67d0de7aebb194e3714877da8 Mon Sep 17 00:00:00 2001 From: Jason Ekstrand Date: Mon, 26 Sep 2022 10:48:08 -0500 Subject: [PATCH] vulkan/wsi: Add a supports_scanout flag This flag indicates whether or not the legacy scanout flag is supported. It defaults to true since that has been the default assumption for the WSI code up until now. On NVIDIA hardware, we can't render to linear so, if we don't have modifiers, we want to automatically fall back to the blit path. In theory, we could do this inside the driver but it's a giant pain and much harder to ensure that the blit only happens as part of vkQueuePresent(). Reviewed-by: Adam Jackson Part-of: --- src/vulkan/wsi/wsi_common.c | 1 + src/vulkan/wsi/wsi_common.h | 5 +++++ src/vulkan/wsi/wsi_common_drm.c | 19 +++++++++++++++---- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/vulkan/wsi/wsi_common.c b/src/vulkan/wsi/wsi_common.c index bdd80d4a9c9..480cefec934 100644 --- a/src/vulkan/wsi/wsi_common.c +++ b/src/vulkan/wsi/wsi_common.c @@ -76,6 +76,7 @@ wsi_device_init(struct wsi_device *wsi, wsi->instance_alloc = *alloc; wsi->pdevice = pdevice; + wsi->supports_scanout = true; wsi->sw = sw_device || (WSI_DEBUG & WSI_DEBUG_SW); wsi->wants_linear = (WSI_DEBUG & WSI_DEBUG_LINEAR) != 0; #define WSI_GET_CB(func) \ diff --git a/src/vulkan/wsi/wsi_common.h b/src/vulkan/wsi/wsi_common.h index a7477cfd07c..c180e7c70af 100644 --- a/src/vulkan/wsi/wsi_common.h +++ b/src/vulkan/wsi/wsi_common.h @@ -106,6 +106,11 @@ struct wsi_device { bool has_import_memory_host; + /** Indicates if wsi_image_create_info::scanout is supported + * + * If false, WSI will always use either modifiers or the prime blit path. + */ + bool supports_scanout; bool supports_modifiers; uint32_t maxImageDimension2D; uint32_t optimalBufferCopyRowPitchAlignment; diff --git a/src/vulkan/wsi/wsi_common_drm.c b/src/vulkan/wsi/wsi_common_drm.c index 31e5b35857c..728e45152c5 100644 --- a/src/vulkan/wsi/wsi_common_drm.c +++ b/src/vulkan/wsi/wsi_common_drm.c @@ -601,6 +601,7 @@ static VkResult wsi_configure_prime_image(UNUSED const struct wsi_swapchain *chain, const VkSwapchainCreateInfoKHR *pCreateInfo, bool use_modifier, + wsi_memory_type_select_cb select_buffer_memory_type, struct wsi_image_info *info) { VkResult result = @@ -613,7 +614,7 @@ wsi_configure_prime_image(UNUSED const struct wsi_swapchain *chain, info->prime_use_linear_modifier = use_modifier; info->create_mem = wsi_create_prime_image_mem; - info->select_buffer_memory_type = prime_select_buffer_memory_type; + info->select_buffer_memory_type = select_buffer_memory_type; info->select_image_memory_type = wsi_select_device_memory_type; return VK_SUCCESS; @@ -623,7 +624,13 @@ bool wsi_drm_image_needs_buffer_blit(const struct wsi_device *wsi, const struct wsi_drm_image_params *params) { - return !params->same_gpu; + if (!params->same_gpu) + return true; + + if (params->num_modifier_lists > 0 || wsi->supports_scanout) + return false; + + return true; } VkResult @@ -634,9 +641,13 @@ wsi_drm_configure_image(const struct wsi_swapchain *chain, { assert(params->base.image_type == WSI_IMAGE_TYPE_DRM); - if (!params->same_gpu) { + if (chain->use_buffer_blit) { bool use_modifier = params->num_modifier_lists > 0; - return wsi_configure_prime_image(chain, pCreateInfo, use_modifier, info); + wsi_memory_type_select_cb select_buffer_memory_type = + params->same_gpu ? wsi_select_device_memory_type : + prime_select_buffer_memory_type; + return wsi_configure_prime_image(chain, pCreateInfo, use_modifier, + select_buffer_memory_type, info); } else { return wsi_configure_native_image(chain, pCreateInfo, params->num_modifier_lists,