SaschaWillems / Vulkan

C++ examples for the Vulkan graphics API
MIT License
10.37k stars 2.04k forks source link

VkResult is VK_SUBOPTIMAL_KHR in Android causing SwapChain to be recreated every frame #1150

Open HakimHauston opened 1 month ago

HakimHauston commented 1 month ago

swapChain.queuePresent in VulkanExampleBase::submitFrame returns VK_SUBOPTIMAL_KHR in Android.

This causes windowResize() to be called every frame, re-creating the entire swapChain.

What is the cause of this error? And is there a way to prevent this?

Any input is highly appreciated...

SaschaWillems commented 1 month ago

What device does this happen on? I can't replicate this on my Pixel 4a, but I could test with other devices.

And does this happen all the time, or only under certain conditions?

HakimHauston commented 1 month ago

Hi @SaschaWillems

Thanks for the fast reply and willingness to take a look... I am facing the errors on all the devices I've tested with:

Upon hearing your positive result on Pixel 4a, I grabbed a device and run it but get the same error, this is the screenshot

The error happened all the time, starting from the first frame, I have just sync-ed to the latest commit 1615f95d but this issue also exist in my previous base as early as July (8b4ee590)

w-pearson commented 1 month ago

I noticed this a while ago but never got around to reporting it. It depends on whether the device is held portrait or landscape (I believe the issue happens with landscape, but I'm not 100% sure of this).

VK_SUBOPTIMAL_KHR is generated by Android at https://android.googlesource.com/platform/frameworks/native/+/7a8d900e3d534177284184660cb4c587632bb658/vulkan/libvulkan/swapchain.cpp#2533. https://github.com/KhronosGroup/Vulkan-Samples/tree/main/samples/performance/surface_rotation documents how you can use preTransform to avoid the issue.

SaschaWillems commented 1 month ago

That explains why I don't see this. I usually test in portrait mode. Thanks for the links, will take a look and hopefully fix this :)