vkcube: Resize on SUBOPTIMAL if necessary
authorTony-LunarG <tony@lunarg.com>
Fri, 4 Jun 2021 21:12:55 +0000 (15:12 -0600)
committerTony Barbour <tony@lunarg.com>
Mon, 7 Jun 2021 15:36:02 +0000 (09:36 -0600)
Change-Id: I6421c661880695ba359969fb5e8752e2140167f5

cube/cube.c
cube/cube.cpp

index 7f6effb..973a57a 100644 (file)
@@ -1170,8 +1170,13 @@ static void demo_draw(struct demo *demo) {
         // must be recreated:
         demo_resize(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.
+        // SUBOPTIMAL could be due to a resize
+        VkSurfaceCapabilitiesKHR surfCapabilities;
+        err = demo->fpGetPhysicalDeviceSurfaceCapabilitiesKHR(demo->gpu, demo->surface, &surfCapabilities);
+        assert(!err);
+        if (surfCapabilities.currentExtent.width != demo->width || surfCapabilities.currentExtent.height != demo->height) {
+            demo_resize(demo);
+        }
     } else if (err == VK_ERROR_SURFACE_LOST_KHR) {
         vkDestroySurfaceKHR(demo->inst, demo->surface, NULL);
         demo_create_surface(demo);
index ed572e3..2e42392 100644 (file)
@@ -807,8 +807,13 @@ void Demo::draw() {
         // must be recreated:
         resize();
     } 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.
+        // SUBOPTIMAL could be due to resize
+        vk::SurfaceCapabilitiesKHR surfCapabilities;
+        auto result = gpu.getSurfaceCapabilitiesKHR(surface, &surfCapabilities);
+        VERIFY(result == vk::Result::eSuccess);
+        if (surfCapabilities.currentExtent.width != width || surfCapabilities.currentExtent.height != height) {
+            resize();
+        }
     } else if (result == vk::Result::eErrorSurfaceLostKHR) {
         inst.destroySurfaceKHR(surface, nullptr);
         create_surface();