diff options
| author | Tony-LunarG <tony@lunarg.com> | 2019-09-11 14:32:23 -0600 |
|---|---|---|
| committer | Tony Barbour <tony@lunarg.com> | 2019-09-13 09:31:35 -0600 |
| commit | 6cebf14cc64c91f6278ad8d1e331bb9e4a6831f6 (patch) | |
| tree | ab2676420761b244e9215133660b4d5074db403e /cube | |
| parent | c60f79013bd8abf65c9b680dfb3958fa27c8c1f6 (diff) | |
| download | usermoji-6cebf14cc64c91f6278ad8d1e331bb9e4a6831f6.tar.xz | |
cube: Handle SURFACE_LOST return code
Change-Id: I6989c7da3e36ec8531ff390ca9ee2f9710776f11
Diffstat (limited to 'cube')
| -rw-r--r-- | cube/cube.c | 19 | ||||
| -rw-r--r-- | cube/cube.cpp | 17 |
2 files changed, 32 insertions, 4 deletions
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)); diff --git a/cube/cube.cpp b/cube/cube.cpp index a6f600c0..48c1f728 100644 --- a/cube/cube.cpp +++ b/cube/cube.cpp @@ -242,6 +242,7 @@ struct Demo { void prepare_textures(); void resize(); + void create_surface(); void set_image_layout(vk::Image, vk::ImageAspectFlags, vk::ImageLayout, vk::ImageLayout, vk::AccessFlags, vk::PipelineStageFlags, vk::PipelineStageFlags); void update_data_buffer(); @@ -731,6 +732,10 @@ void Demo::draw() { // swapchain is not as optimal as it could be, but the platform's // presentation engine will still present the image correctly. break; + } else if (result == vk::Result::eErrorSurfaceLostKHR) { + inst.destroySurfaceKHR(surface, nullptr); + create_surface(); + resize(); } else { VERIFY(result == vk::Result::eSuccess); } @@ -793,6 +798,10 @@ void Demo::draw() { } else if (result == vk::Result::eSuboptimalKHR) { // swapchain is not as optimal as it could be, but the platform's // presentation engine will still present the image correctly. + } else if (result == vk::Result::eErrorSurfaceLostKHR) { + inst.destroySurfaceKHR(surface, nullptr); + create_surface(); + resize(); } else { VERIFY(result == vk::Result::eSuccess); } @@ -899,7 +908,7 @@ void Demo::init(int argc, char **argv) { presentMode = vk::PresentModeKHR::eFifo; frameCount = UINT32_MAX; use_xlib = false; - + #if defined(VK_USE_PLATFORM_MACOS_MVK) // MoltenVK may not allow host coherent mapping to linear tiled images // Force the use of a staging buffer to be safe @@ -1267,7 +1276,7 @@ void Demo::init_vk() { gpu.getFeatures(&physDevFeatures); } -void Demo::init_vk_swapchain() { +void Demo::create_surface() { // Create a WSI surface for the window: #if defined(VK_USE_PLATFORM_WIN32_KHR) { @@ -1317,6 +1326,10 @@ void Demo::init_vk_swapchain() { VERIFY(result == vk::Result::eSuccess); } #endif +} + +void Demo::init_vk_swapchain() { + create_surface(); // Iterate over each queue to learn whether it supports presenting: std::unique_ptr<vk::Bool32[]> supportsPresent(new vk::Bool32[queue_family_count]); for (uint32_t i = 0; i < queue_family_count; i++) { |
