From 6cebf14cc64c91f6278ad8d1e331bb9e4a6831f6 Mon Sep 17 00:00:00 2001 From: Tony-LunarG Date: Wed, 11 Sep 2019 14:32:23 -0600 Subject: cube: Handle SURFACE_LOST return code Change-Id: I6989c7da3e36ec8531ff390ca9ee2f9710776f11 --- cube/cube.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'cube/cube.c') diff --git a/cube/cube.c b/cube/cube.c index 41d980ce..1b7b3227 100644 --- a/cube/cube.c +++ b/cube/cube.c @@ -588,8 +588,9 @@ bool CanPresentEarlier(uint64_t earliest, uint64_t actual, uint64_t margin, uint return false; } -// Forward declaration: +// Forward declarations: static void demo_resize(struct demo *demo); +static void demo_create_surface(struct demo *demo); static bool memory_type_from_properties(struct demo *demo, uint32_t typeBits, VkFlags requirements_mask, uint32_t *typeIndex) { // Search memtypes to find first index with those properties @@ -1017,6 +1018,10 @@ static void demo_draw(struct demo *demo) { // demo->swapchain is not as optimal as it could be, but the platform's // presentation engine will still present the image correctly. break; + } else if (err == VK_ERROR_SURFACE_LOST_KHR) { + vkDestroySurfaceKHR(demo->inst, demo->surface, NULL); + demo_create_surface(demo); + demo_resize(demo); } else { assert(!err); } @@ -1159,6 +1164,10 @@ static void demo_draw(struct demo *demo) { } else if (err == VK_SUBOPTIMAL_KHR) { // demo->swapchain is not as optimal as it could be, but the platform's // presentation engine will still present the image correctly. + } else if (err == VK_ERROR_SURFACE_LOST_KHR) { + vkDestroySurfaceKHR(demo->inst, demo->surface, NULL); + demo_create_surface(demo); + demo_resize(demo); } else { assert(!err); } @@ -3352,7 +3361,7 @@ static void demo_create_device(struct demo *demo) { assert(!err); } -static void demo_init_vk_swapchain(struct demo *demo) { +static void demo_create_surface(struct demo *demo) { VkResult U_ASSERT_ONLY err; // Create a WSI surface for the window: @@ -3420,6 +3429,12 @@ static void demo_init_vk_swapchain(struct demo *demo) { err = vkCreateMacOSSurfaceMVK(demo->inst, &surface, NULL, &demo->surface); #endif assert(!err); +} + +static void demo_init_vk_swapchain(struct demo *demo) { + VkResult U_ASSERT_ONLY err; + + demo_create_surface(demo); // Iterate over each queue to learn whether it supports presenting: VkBool32 *supportsPresent = (VkBool32 *)malloc(demo->queue_family_count * sizeof(VkBool32)); -- cgit v1.2.3