Skip to content

Conversation

@PancakeTAS
Copy link
Contributor

It appears some compositors (tested on Hyprland) don't invalidate the swapchain after a window resize. This breaks rendering entirely due to mismatched sizes in the demo struct, versus the created framebuffer and isn't caught by anything else.

@ci-tester-lunarg
Copy link

Author PancakeTAS not on autobuild list. Waiting for curator authorization before starting CI build.

1 similar comment
@ci-tester-lunarg
Copy link

Author PancakeTAS not on autobuild list. Waiting for curator authorization before starting CI build.

@CLAassistant
Copy link

CLAassistant commented Sep 15, 2025

CLA assistant check
All committers have signed the CLA.

@PancakeTAS
Copy link
Contributor Author

This closes #1138, I should've put that into the description.

@ci-tester-lunarg
Copy link

CI Vulkan-Tools build queued with queue ID 534513.

@ci-tester-lunarg
Copy link

CI Vulkan-Tools build # 1815 running.

@ci-tester-lunarg
Copy link

CI Vulkan-Tools build # 1815 passed.

@mahkoh
Copy link
Contributor

mahkoh commented Sep 20, 2025

It appears some compositors (tested on Hyprland) don't invalidate the swapchain after a window resize.

On wayland, the swapchain size is always controlled by the client. Therefore there is nothing to invalidate nor is there any mechanism for the compositor to invalidate anything.

This patch is wrong. The client should not do anything until it receives the xdg_surface.configure event as documented:

This configure event asks the client to resize its toplevel surface or to change its state. The configured state should not be applied immediately. See xdg_surface.configure for details.

The client might in fact receive many xdg_toplevel.configure events before receiving a single xdg_surface.configure event. The client should ignore all but the last xdg_toplevel.configure event in this case.

The existing code is not entirely correct because it might try to present before having received the first xdg_surface.configure event. This patch would fix that:

diff --git a/cube/cube.c b/cube/cube.c
index b4db7500..8e37cc15 100644
--- a/cube/cube.c
+++ b/cube/cube.c
@@ -1372,6 +1372,12 @@ static void demo_prepare_swapchain(struct demo *demo) {
     VkResult U_ASSERT_ONLY err;
     VkSwapchainKHR oldSwapchain = demo->swapchain;
 
+#if defined(VK_USE_PLATFORM_WAYLAND_KHR)
+    if (demo->wsi_platform == WSI_PLATFORM_WAYLAND && !demo->xdg_surface_has_been_configured) {
+        return;
+    }
+#endif
+
     // Check the surface capabilities and formats
     VkSurfaceCapabilitiesKHR surfCapabilities;
     err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(demo->gpu, demo->surface, &surfCapabilities);
@@ -3054,10 +3060,8 @@ static void demo_run(struct demo *demo) {
 static void handle_surface_configure(void *data, struct xdg_surface *xdg_surface, uint32_t serial) {
     struct demo *demo = (struct demo *)data;
     xdg_surface_ack_configure(xdg_surface, serial);
-    if (demo->xdg_surface_has_been_configured) {
-        demo_resize(demo);
-    }
     demo->xdg_surface_has_been_configured = 1;
+    demo_resize(demo);
 }
 
 static const struct xdg_surface_listener xdg_surface_listener = {handle_surface_configure};

However, in practice it always gets lucky because the vulkan driver performs a number of roundtrips before creating the swapchain.

@mahkoh
Copy link
Contributor

mahkoh commented Sep 20, 2025

The solution for this error from your logs is to double-buffer the width/height parameters sent in the xdg_toplevel.configure event until they are applied in the xdg_surface.configure event:

vkCmdBeginRenderPass(): pRenderPassBegin->renderArea offset.x (0) + extent.width (1280) is greater than framebuffer width (500).

@ci-tester-lunarg
Copy link

Author PancakeTAS not on autobuild list. Waiting for curator authorization before starting CI build.

1 similar comment
@ci-tester-lunarg
Copy link

Author PancakeTAS not on autobuild list. Waiting for curator authorization before starting CI build.

@ci-tester-lunarg
Copy link

Author PancakeTAS not on autobuild list. Waiting for curator authorization before starting CI build.

1 similar comment
@ci-tester-lunarg
Copy link

Author PancakeTAS not on autobuild list. Waiting for curator authorization before starting CI build.

@PancakeTAS
Copy link
Contributor Author

I implemented the double buffering and moved the surface reconfigure to handle_surface_configure properly. I'm not familiar enough with Wayland specification to judge whether inserting an early return in demo_prepare_swapchain is a good idea or if there is a better.. workaround? The changes seem to work as expected though, please take a look @mahkoh.

@mahkoh
Copy link
Contributor

mahkoh commented Sep 21, 2025

LGTM

@ci-tester-lunarg
Copy link

CI Vulkan-Tools build queued with queue ID 536288.

@ci-tester-lunarg
Copy link

CI Vulkan-Tools build # 1824 running.

Copy link
Contributor

@charles-lunarg charles-lunarg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was able to run this and had no issue with resizing. Wayland code also makes more sense now, which is stellar.

@ci-tester-lunarg
Copy link

CI Vulkan-Tools build # 1824 passed.

@charles-lunarg charles-lunarg merged commit e3ecc39 into KhronosGroup:main Sep 22, 2025
18 checks passed
@PancakeTAS PancakeTAS deleted the fix_wayland_wsi branch September 22, 2025 19:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants