From 96723c6f7083f81eb203ee9b436625e270f1ce3d Mon Sep 17 00:00:00 2001 From: Hans-Kristian Arntzen Date: Tue, 17 Dec 2019 18:56:42 +0100 Subject: [PATCH] Vulkan/Android: Workaround weird WSI return codes in landscape mode. Android WSI wants you to use preTransform, and if it is not used correctly, Android 10 will return VK_SUBOPTIMAL_KHR, and we would create a new swapchain every frame. This workaround just ignores this error, since it's not really an error. A more "proper" fix is to use prerotate and modify the MVP matrices, which might help certain devices with crummy display processors. --- gfx/common/vulkan_common.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/gfx/common/vulkan_common.c b/gfx/common/vulkan_common.c index aa398cdd28..2097289673 100644 --- a/gfx/common/vulkan_common.c +++ b/gfx/common/vulkan_common.c @@ -229,6 +229,11 @@ static void vulkan_emulated_mailbox_loop(void *userdata) mailbox->result = vkAcquireNextImageKHR(mailbox->device, mailbox->swapchain, UINT64_MAX, VK_NULL_HANDLE, fence, &mailbox->index); + /* VK_SUBOPTIMAL_KHR can be returned on Android 10 when prerotate is not dealt with. + * This is not an error we need to care about, and we'll treat it as SUCCESS. */ + if (mailbox->result == VK_SUBOPTIMAL_KHR) + mailbox->result = VK_SUCCESS; + if (mailbox->result == VK_SUCCESS) vkWaitForFences(mailbox->device, 1, &fence, true, UINT64_MAX); vkResetFences(mailbox->device, 1, &fence); @@ -2621,6 +2626,13 @@ void vulkan_present(gfx_ctx_vulkan_data_t *vk, unsigned index) #endif err = vkQueuePresentKHR(vk->context.queue, &present); + /* VK_SUBOPTIMAL_KHR can be returned on Android 10 when prerotate is not dealt with. + * This is not an error we need to care about, and we'll treat it as SUCCESS. */ + if (result == VK_SUBOPTIMAL_KHR) + result = VK_SUCCESS; + if (err == VK_SUBOPTIMAL_KHR) + err = VK_SUCCESS; + #ifdef WSI_HARDENING_TEST trigger_spurious_error_vkresult(&err); #endif @@ -2796,6 +2808,11 @@ retry: err = vkAcquireNextImageKHR(vk->context.device, vk->swapchain, UINT64_MAX, VK_NULL_HANDLE, fence, &vk->context.current_swapchain_index); + + /* VK_SUBOPTIMAL_KHR can be returned on Android 10 when prerotate is not dealt with. + * This is not an error we need to care about, and we'll treat it as SUCCESS. */ + if (err == VK_SUBOPTIMAL_KHR) + err = VK_SUCCESS; } if (err == VK_SUCCESS)