Skip to content

Commit

Permalink
[dxvk] Fix synchronization around vkDeviceWaitIdle
Browse files Browse the repository at this point in the history
From the spec:
	"Host access to all VkQueue objects created
	from device must be externally synchronized"

We were not doing that, which could cause hangs and
all sorts of issues when recreating the swap chain
on Nvidia GPUs.
  • Loading branch information
doitsujin committed Nov 19, 2019
1 parent 4fff234 commit ceddbaf
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 6 deletions.
2 changes: 2 additions & 0 deletions src/d3d11/d3d11_swapchain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,8 @@ namespace dxvk {
void D3D11SwapChain::RecreateSwapChain(BOOL Vsync) {
// Ensure that we can safely destroy the swap chain
m_device->waitForSubmission(&m_presentStatus);
m_device->waitForIdle();

m_presentStatus.result = VK_SUCCESS;

vk::PresenterDesc presenterDesc;
Expand Down
4 changes: 2 additions & 2 deletions src/dxvk/dxvk_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,10 +237,10 @@ namespace dxvk {


void DxvkDevice::waitForIdle() {
m_submissionQueue.synchronize();

this->lockSubmission();
if (m_vkd->vkDeviceWaitIdle(m_vkd->device()) != VK_SUCCESS)
Logger::err("DxvkDevice: waitForIdle: Operation failed");
this->unlockSubmission();
}


Expand Down
4 changes: 1 addition & 3 deletions src/vulkan/vulkan_presenter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ namespace dxvk::vk {
// Create one set of semaphores per swap image
m_semaphores.resize(m_info.imageCount);

for (uint32_t i = 0; i < m_info.imageCount; i++) {
for (uint32_t i = 0; i < m_semaphores.size(); i++) {
VkFenceCreateInfo fenceInfo;
fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
fenceInfo.pNext = nullptr;
Expand Down Expand Up @@ -399,8 +399,6 @@ namespace dxvk::vk {


void Presenter::destroySwapchain() {
m_vkd->vkDeviceWaitIdle(m_vkd->device());

for (const auto& img : m_images)
m_vkd->vkDestroyImageView(m_vkd->device(), img.view, nullptr);

Expand Down
4 changes: 3 additions & 1 deletion src/vulkan/vulkan_presenter.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,9 @@ namespace dxvk::vk {
/**
* \brief Changes presenter properties
*
* Recreates the swap chain immediately.
* Recreates the swap chain immediately. Note that
* no swap chain resources must be in use by the
* GPU at the time this is called.
* \param [in] desc Swap chain description
*/
VkResult recreateSwapChain(
Expand Down

0 comments on commit ceddbaf

Please sign in to comment.