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
// 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);
}
} 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);
}
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:
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));
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();
// 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);
}
} 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);
}
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
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)
{
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++) {