Skip to content

Commit

Permalink
[d3d9] Use most recently used swapchain for GetFrontBufferData
Browse files Browse the repository at this point in the history
  • Loading branch information
K0bin committed Feb 6, 2024
1 parent a579463 commit 057961a
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/d3d9/d3d9_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1083,7 +1083,10 @@ namespace dxvk {
if (unlikely(iSwapChain != 0))
return D3DERR_INVALIDCALL;

return m_implicitSwapchain->GetFrontBufferData(pDestSurface);
// In windowed mode, GetFrontBufferData takes a screenshot of the entire screen.
// We use the last used swapchain as a workaround.
// Total War: Medieval 2 relies on this.
return m_mostRecentlyUsedSwapchain->GetFrontBufferData(pDestSurface);
}


Expand Down Expand Up @@ -7813,6 +7816,7 @@ namespace dxvk {
}
else
m_implicitSwapchain = new D3D9SwapChainEx(this, pPresentationParameters, pFullscreenDisplayMode);
m_mostRecentlyUsedSwapchain = m_implicitSwapchain.ptr();

if (pPresentationParameters->EnableAutoDepthStencil) {
D3D9_COMMON_TEXTURE_DESC desc;
Expand Down
14 changes: 14 additions & 0 deletions src/d3d9/d3d9_device.h
Original file line number Diff line number Diff line change
Expand Up @@ -1241,6 +1241,18 @@ namespace dxvk {

uint64_t GetCurrentSequenceNumber();

D3D9SwapChainEx* GetLastUsedSwapchain() {
return m_mostRecentlyUsedSwapchain;
}

void SetLastUsedSwapchain(D3D9SwapChainEx* swapchain) {
m_mostRecentlyUsedSwapchain = swapchain;
}

void ResetLastUsedSwapchain() {
m_mostRecentlyUsedSwapchain = m_implicitSwapchain.ptr();
}

Com<D3D9InterfaceEx> m_parent;
D3DDEVTYPE m_deviceType;
HWND m_window;
Expand Down Expand Up @@ -1403,6 +1415,8 @@ namespace dxvk {
HWND m_fullscreenWindow = NULL;
std::atomic<uint32_t> m_losableResourceCounter = { 0 };

D3D9SwapChainEx* m_mostRecentlyUsedSwapchain = nullptr;

#ifdef D3D9_ALLOW_UNMAPPING
lru_list<D3D9CommonTexture*> m_mappedTextures;
#endif
Expand Down
10 changes: 10 additions & 0 deletions src/d3d9/d3d9_swapchain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,14 @@ namespace dxvk {
if (this_thread::isInModuleDetachment())
return;

{
D3D9DeviceLock lock = m_parent->LockDevice();

if (m_parent->GetLastUsedSwapchain() == this) {
m_parent->ResetLastUsedSwapchain();
}
}

DestroyBackBuffers();

ResetWindowProc(m_window);
Expand Down Expand Up @@ -112,6 +120,8 @@ namespace dxvk {
DWORD dwFlags) {
D3D9DeviceLock lock = m_parent->LockDevice();

m_parent->SetLastUsedSwapchain(this);

if (unlikely(m_parent->IsDeviceLost()))
return D3DERR_DEVICELOST;

Expand Down

0 comments on commit 057961a

Please sign in to comment.