Skip to content

Commit

Permalink
Make window resize work with Vulkan. I do still get the occasional lo…
Browse files Browse the repository at this point in the history
…st device so there's some sync bug remaining.
  • Loading branch information
hrydgard committed Oct 7, 2018
1 parent f1dbef0 commit 3a87e34
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
15 changes: 14 additions & 1 deletion Common/Vulkan/VulkanContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,6 @@ void VulkanContext::ReinitSurface(int width, int height) {
surface_ = VK_NULL_HANDLE;
}

ILOG("Creating Vulkan surface (%d, %d)", width, height);
switch (winsys_) {
#ifdef _WIN32
case WINDOWSYSTEM_WIN32:
Expand Down Expand Up @@ -726,8 +725,22 @@ void VulkanContext::ReinitSurface(int width, int height) {
_assert_msg_(G3D, false, "Vulkan support for chosen window system not implemented");
break;
}

width_ = width;
height_ = height;

// In case we didn't get a width and height, try to recover it from the surface.
// Useful with SDL.
if (width_ < 0) {
VkSurfaceCapabilitiesKHR caps;
if (VK_SUCCESS == vkGetPhysicalDeviceSurfaceCapabilitiesKHR(physical_devices_[physical_device_], surface_, &caps)) {
if (caps.currentExtent.width != 0xFFFFFFFF && caps.currentExtent.height != 0xFFFFFFFF) {
width_ = caps.currentExtent.width;
height_ = caps.currentExtent.height;
}
}
}
ILOG("Created Vulkan surface (%d x %d)", width_, height_);
}

bool VulkanContext::InitQueue() {
Expand Down
8 changes: 3 additions & 5 deletions SDL/SDLVulkanGraphicsContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,14 @@ class SDLVulkanGraphicsContext : public GraphicsContext {
}

void Resize() override {
/*
draw_->HandleEvent(Draw::Event::LOST_BACKBUFFER, vulkan_->GetBackbufferWidth(), vulkan_->GetBackbufferHeight());
vulkan_->DestroyObjects();
// TODO: Take from real window dimensions
int width = 1024;
int height = 768;
// We now get the size from the Vk surface, can safely pass in nonsense.
int width = -1;
int height = -1;
vulkan_->ReinitSurface(width, height);
vulkan_->InitObjects();
draw_->HandleEvent(Draw::Event::GOT_BACKBUFFER, vulkan_->GetBackbufferWidth(), vulkan_->GetBackbufferHeight());
*/
}

void SwapInterval(int interval) override {
Expand Down
2 changes: 2 additions & 0 deletions ext/native/thin3d/VulkanRenderManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -857,7 +857,9 @@ void VulkanRenderManager::BeginSubmitFrame(int frame) {
VkResult res = vkAcquireNextImageKHR(vulkan_->GetDevice(), vulkan_->GetSwapchain(), UINT64_MAX, acquireSemaphore_, (VkFence)VK_NULL_HANDLE, &frameData.curSwapchainImage);
if (res == VK_SUBOPTIMAL_KHR) {
// Hopefully the resize will happen shortly. Ignore - one frame might look bad or something.
WLOG("VK_SUBOPTIMAL_KHR returned - ignoring");
} else if (res == VK_ERROR_OUT_OF_DATE_KHR) {
WLOG("VK_ERROR_OUT_OF_DATE_KHR returned - not presenting");
frameData.skipSwap = true;
} else {
_assert_msg_(G3D, res == VK_SUCCESS, "vkAcquireNextImageKHR failed! result=%s", VulkanResultToString(res));
Expand Down

0 comments on commit 3a87e34

Please sign in to comment.