Skip to content

Commit 8f27576

Browse files
ryanKkaiiiKkaiwz
authored andcommitted
fix(wayland): get surface extent from window instead of surface properties
On Wayland, VkSurfaceCapabilitiesKHR::currentExtent typically returns {0xFFFFFFFF, 0xFFFFFFFF}, indicating that the application determines the surface size rather than the compositor. This patch fixes the issue by getting the actual surface extent from the platform window on Wayland, ensuring the swapchain is properly recreated with the correct dimensions. Signed-off-by: Ryan Zhang <ryan.zhang@nxp.com>
1 parent fa2cf45 commit 8f27576

1 file changed

Lines changed: 14 additions & 4 deletions

File tree

framework/rendering/render_context.h

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -604,23 +604,33 @@ inline bool RenderContext<bindingType>::handle_surface_changes(bool force_update
604604
}
605605

606606
vk::SurfaceCapabilitiesKHR surface_properties = device.get_gpu().get_handle().getSurfaceCapabilitiesKHR(swapchain->get_surface());
607+
vk::Extent2D cur_extent;
607608

608-
if (surface_properties.currentExtent.width == 0xFFFFFFFF)
609+
#if defined(VK_USE_PLATFORM_WAYLAND_KHR)
610+
// On Wayland, currentExtent is typically {0xFFFFFFFF, 0xFFFFFFFF}, meaning
611+
// the application determines the surface size. We need to get the size from
612+
// the window instead.
613+
cur_extent = vk::Extent2D{window.get_extent().width, window.get_extent().height};
614+
#else
615+
cur_extent = surface_properties.currentExtent;
616+
#endif
617+
618+
if (cur_extent.width == 0xFFFFFFFF || cur_extent.height == 0xFFFFFFFF)
609619
{
610620
return false;
611621
}
612622

613623
// Only recreate the swapchain if the dimensions have changed;
614624
// handle_surface_changes() is called on VK_SUBOPTIMAL_KHR,
615625
// which might not be due to a surface resize
616-
if (surface_properties.currentExtent.width != surface_extent.width || surface_properties.currentExtent.height != surface_extent.height || force_update)
626+
if (cur_extent.width != surface_extent.width || cur_extent.height != surface_extent.height || force_update)
617627
{
618628
// Recreate swapchain
619629
device.get_handle().waitIdle();
620630

621-
update_swapchain_impl(surface_properties.currentExtent, pre_transform);
631+
update_swapchain_impl(cur_extent, pre_transform);
622632

623-
surface_extent = surface_properties.currentExtent;
633+
surface_extent = cur_extent;
624634

625635
return true;
626636
}

0 commit comments

Comments
 (0)