Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[vulkan] Recreate the surface on surface loss. #991

Merged
merged 3 commits into from
Apr 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 19 additions & 8 deletions src/vulkan/vulkan_presenter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ namespace dxvk::vk {
const Rc<DeviceFn>& vkd,
PresenterDevice device,
const PresenterDesc& desc)
: m_vki(vki), m_vkd(vkd), m_device(device) {
if (createSurface(window) != VK_SUCCESS)
: m_vki(vki), m_vkd(vkd), m_device(device), m_window(window) {
if (createSurface() != VK_SUCCESS)
throw DxvkError("Failed to create surface");

if (recreateSwapChain(desc) != VK_SUCCESS)
Expand Down Expand Up @@ -105,8 +105,19 @@ namespace dxvk::vk {
VkResult status;

if ((status = m_vki->vkGetPhysicalDeviceSurfaceCapabilitiesKHR(
m_device.adapter, m_surface, &caps)) != VK_SUCCESS)
return status;
m_device.adapter, m_surface, &caps)) != VK_SUCCESS) {
if (status == VK_ERROR_SURFACE_LOST_KHR) {
// Recreate the surface and try again.
if (m_surface)
destroySurface();
if ((status = createSurface()) != VK_SUCCESS)
return status;
status = m_vki->vkGetPhysicalDeviceSurfaceCapabilitiesKHR(
m_device.adapter, m_surface, &caps);
}
if (status != VK_SUCCESS)
return status;
}

if ((status = getSupportedFormats(formats)) != VK_SUCCESS)
return status;
Expand Down Expand Up @@ -355,16 +366,16 @@ namespace dxvk::vk {
}


VkResult Presenter::createSurface(HWND window) {
VkResult Presenter::createSurface() {
HINSTANCE instance = reinterpret_cast<HINSTANCE>(
GetWindowLongPtr(window, GWLP_HINSTANCE));
GetWindowLongPtr(m_window, GWLP_HINSTANCE));

VkWin32SurfaceCreateInfoKHR info;
info.sType = VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR;
info.pNext = nullptr;
info.flags = 0;
info.hinstance = instance;
info.hwnd = window;
info.hwnd = m_window;

VkResult status = m_vki->vkCreateWin32SurfaceKHR(
m_vki->instance(), &info, nullptr, &m_surface);
Expand Down Expand Up @@ -412,4 +423,4 @@ namespace dxvk::vk {
m_vki->vkDestroySurfaceKHR(m_vki->instance(), m_surface, nullptr);
}

}
}
5 changes: 3 additions & 2 deletions src/vulkan/vulkan_presenter.h
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ namespace dxvk::vk {
PresenterDevice m_device;
PresenterInfo m_info;

HWND m_window = nullptr;
VkSurfaceKHR m_surface = VK_NULL_HANDLE;
VkSwapchainKHR m_swapchain = VK_NULL_HANDLE;

Expand Down Expand Up @@ -213,12 +214,12 @@ namespace dxvk::vk {
VkPresentModeKHR presentMode,
uint32_t desired);

VkResult createSurface(HWND window);
VkResult createSurface();

void destroySwapchain();

void destroySurface();

};

}
}