mirror of
https://github.com/Lime3DS/Lime3DS.git
synced 2026-06-07 00:15:07 -06:00
android: Handle surface lost during swapchain creation
This commit is contained in:
parent
7220bd2edd
commit
7e58ac5bcf
@ -38,7 +38,14 @@ void Swapchain::Create(u32 width_, u32 height_, vk::SurfaceKHR surface_, bool lo
|
|||||||
Destroy();
|
Destroy();
|
||||||
|
|
||||||
SetPresentMode();
|
SetPresentMode();
|
||||||
|
if (needs_recreation) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
SetSurfaceProperties();
|
SetSurfaceProperties();
|
||||||
|
if (needs_recreation) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const std::array queue_family_indices = {
|
const std::array queue_family_indices = {
|
||||||
instance.GetGraphicsQueueFamilyIndex(),
|
instance.GetGraphicsQueueFamilyIndex(),
|
||||||
@ -70,9 +77,13 @@ void Swapchain::Create(u32 width_, u32 height_, vk::SurfaceKHR surface_, bool lo
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
swapchain = instance.GetDevice().createSwapchainKHR(swapchain_info);
|
swapchain = instance.GetDevice().createSwapchainKHR(swapchain_info);
|
||||||
|
} catch (vk::SurfaceLostKHRError&) {
|
||||||
|
LOG_ERROR(Render_Vulkan, "Surface lost during swapchain creation");
|
||||||
|
needs_recreation = true;
|
||||||
|
return;
|
||||||
} catch (vk::SystemError& err) {
|
} catch (vk::SystemError& err) {
|
||||||
LOG_CRITICAL(Render_Vulkan, "{}", err.what());
|
LOG_CRITICAL(Render_Vulkan, "{}", err.what());
|
||||||
UNREACHABLE();
|
throw;
|
||||||
}
|
}
|
||||||
|
|
||||||
SetupImages();
|
SetupImages();
|
||||||
@ -160,7 +171,15 @@ void Swapchain::FindPresentFormat() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Swapchain::SetPresentMode() {
|
void Swapchain::SetPresentMode() {
|
||||||
const auto modes = instance.GetPhysicalDevice().getSurfacePresentModesKHR(surface);
|
std::vector<vk::PresentModeKHR> modes;
|
||||||
|
try {
|
||||||
|
modes = instance.GetPhysicalDevice().getSurfacePresentModesKHR(surface);
|
||||||
|
} catch (vk::SurfaceLostKHRError&) {
|
||||||
|
LOG_ERROR(Render_Vulkan, "Surface lost during swapchain creation");
|
||||||
|
needs_recreation = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const bool use_vsync = Settings::values.use_vsync.GetValue();
|
const bool use_vsync = Settings::values.use_vsync.GetValue();
|
||||||
const auto find_mode = [&modes](vk::PresentModeKHR requested) {
|
const auto find_mode = [&modes](vk::PresentModeKHR requested) {
|
||||||
const auto it =
|
const auto it =
|
||||||
@ -203,8 +222,14 @@ void Swapchain::SetPresentMode() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Swapchain::SetSurfaceProperties() {
|
void Swapchain::SetSurfaceProperties() {
|
||||||
const vk::SurfaceCapabilitiesKHR capabilities =
|
vk::SurfaceCapabilitiesKHR capabilities;
|
||||||
instance.GetPhysicalDevice().getSurfaceCapabilitiesKHR(surface);
|
try {
|
||||||
|
capabilities = instance.GetPhysicalDevice().getSurfaceCapabilitiesKHR(surface);
|
||||||
|
} catch (vk::SurfaceLostKHRError&) {
|
||||||
|
LOG_ERROR(Render_Vulkan, "Surface lost during swapchain creation");
|
||||||
|
needs_recreation = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
extent = capabilities.currentExtent;
|
extent = capabilities.currentExtent;
|
||||||
if (capabilities.currentExtent.width == std::numeric_limits<u32>::max()) {
|
if (capabilities.currentExtent.width == std::numeric_limits<u32>::max()) {
|
||||||
@ -237,6 +262,7 @@ void Swapchain::Destroy() {
|
|||||||
vk::Device device = instance.GetDevice();
|
vk::Device device = instance.GetDevice();
|
||||||
if (swapchain) {
|
if (swapchain) {
|
||||||
device.destroySwapchainKHR(swapchain);
|
device.destroySwapchainKHR(swapchain);
|
||||||
|
swapchain = VK_NULL_HANDLE;
|
||||||
}
|
}
|
||||||
for (u32 i = 0; i < image_count; i++) {
|
for (u32 i = 0; i < image_count; i++) {
|
||||||
device.destroySemaphore(image_acquired[i]);
|
device.destroySemaphore(image_acquired[i]);
|
||||||
|
|||||||
@ -90,7 +90,7 @@ private:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
const Instance& instance;
|
const Instance& instance;
|
||||||
vk::SwapchainKHR swapchain{};
|
vk::SwapchainKHR swapchain{VK_NULL_HANDLE};
|
||||||
vk::SurfaceKHR surface{};
|
vk::SurfaceKHR surface{};
|
||||||
vk::SurfaceFormatKHR surface_format;
|
vk::SurfaceFormatKHR surface_format;
|
||||||
vk::PresentModeKHR present_mode;
|
vk::PresentModeKHR present_mode;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user