From 18450f4643c6cb5534f6cdfd44492138ed8294f3 Mon Sep 17 00:00:00 2001 From: Philip Rebohle Date: Wed, 15 Jan 2020 23:41:09 +0100 Subject: [PATCH] [d3d11] Lock immediate context when submitting presentation commands Otherwise, a race condition occurs if a game submits rendering commands at the same time as presenting the swap chain image. Only works if multithreaded protection is enabled, but according to MSDN, it is illegal to use DXGI commands and the immediate context in parallel. Fixes stability issues in Tales of Vesperia. --- src/d3d11/d3d11_context.h | 8 ++++---- src/d3d11/d3d11_swapchain.cpp | 2 ++ 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/d3d11/d3d11_context.h b/src/d3d11/d3d11_context.h index c8620a9e..3776ae61 100644 --- a/src/d3d11/d3d11_context.h +++ b/src/d3d11/d3d11_context.h @@ -700,6 +700,10 @@ namespace dxvk { VkImageLayout OldLayout, VkImageLayout NewLayout); + D3D10DeviceLock LockContext() { + return m_multithread.AcquireLock(); + } + protected: D3D11Device* const m_parent; @@ -917,10 +921,6 @@ namespace dxvk { return pShader != nullptr ? pShader->GetCommonShader() : nullptr; } - D3D10DeviceLock LockContext() { - return m_multithread.AcquireLock(); - } - template void EmitCs(Cmd&& command) { m_cmdData = nullptr; diff --git a/src/d3d11/d3d11_swapchain.cpp b/src/d3d11/d3d11_swapchain.cpp index eaedcf37..7cc89725 100644 --- a/src/d3d11/d3d11_swapchain.cpp +++ b/src/d3d11/d3d11_swapchain.cpp @@ -368,6 +368,8 @@ namespace dxvk { D3D11ImmediateContext* pContext, const vk::PresenterSync& Sync, uint32_t FrameId) { + auto lock = pContext->LockContext(); + // Present from CS thread so that we don't // have to synchronize with it first. m_presentStatus.result = VK_NOT_READY;