Fixes to vulkan restart logic on Android. Should help #10696

This commit is contained in:
Henrik Rydgård 2018-03-11 17:14:11 +01:00
parent 0ed3deabe6
commit 9f9903c02e
5 changed files with 20 additions and 14 deletions

View File

@ -922,13 +922,16 @@ VkFence VulkanContext::CreateFence(bool presignalled) {
return fence;
}
void VulkanContext::DestroyDevice() {
ILOG("VulkanContext::DestroyDevice (performing deletes)");
// If there happen to be any pending deletes, now is a good time.
void VulkanContext::PerformPendingDeletes() {
for (int i = 0; i < ARRAY_SIZE(frame_); i++) {
frame_[i].deleteList.PerformDeletes(device_);
}
Delete().PerformDeletes(device_);
}
void VulkanContext::DestroyDevice() {
ILOG("VulkanContext::DestroyDevice (performing deletes)");
PerformPendingDeletes();
vkDestroyDevice(device_, nullptr);
device_ = nullptr;

View File

@ -148,9 +148,9 @@ public:
// Also destroys the surface.
void DestroyObjects();
void DestroyDevice();
void PerformPendingDeletes();
void WaitUntilQueueIdle();
// Utility functions for shorter code

View File

@ -169,22 +169,24 @@ bool AndroidVulkanContext::InitFromRenderThread(ANativeWindow *wnd, int desiredB
return success;
}
void AndroidVulkanContext::Shutdown() {
void AndroidVulkanContext::ShutdownFromRenderThread() {
ILOG("AndroidVulkanContext::Shutdown");
draw_->HandleEvent(Draw::Event::LOST_BACKBUFFER, g_Vulkan->GetBackbufferWidth(), g_Vulkan->GetBackbufferHeight());
ILOG("Calling NativeShutdownGraphics");
NativeShutdownGraphics();
delete draw_;
draw_ = nullptr;
g_Vulkan->WaitUntilQueueIdle();
g_Vulkan->DestroyObjects();
g_Vulkan->PerformPendingDeletes();
g_Vulkan->DestroyObjects(); // Also destroys the surface, a bit asymmetric
ILOG("Done with ShutdownFromRenderThread");
}
void AndroidVulkanContext::Shutdown() {
ILOG("Calling NativeShutdownGraphics");
g_Vulkan->DestroyDevice();
g_Vulkan->DestroyDebugMsgCallback();
g_Vulkan->DestroyInstance();
// We keep the g_Vulkan context around to avoid invalidating a ton of pointers around the app.
finalize_glslang();
ILOG("AndroidVulkanContext::Shutdown completed");
}

View File

@ -14,6 +14,8 @@ public:
bool InitAPI();
bool InitFromRenderThread(ANativeWindow *wnd, int desiredBackbufferSizeX, int desiredBackbufferSizeY, int backbufferFormat, int androidVersion) override;
void ShutdownFromRenderThread() override; // Inverses InitFromRenderThread.
void Shutdown() override;
void SwapInterval(int interval) override;
void SwapBuffers() override;

View File

@ -983,10 +983,9 @@ retry:
NativeShutdownGraphics();
renderer_inited = false;
ILOG("Shutting down graphics context.");
graphicsContext->Shutdown();
delete graphicsContext;
graphicsContext = nullptr;
// Shut the graphics context down to the same state it was in when we entered the render thread.
ILOG("Shutting down graphics context from render thread...");
graphicsContext->ShutdownFromRenderThread();
renderLoopRunning = false;
WLOG("Render loop function exited.");
return true;