dxvk
dxvk copied to clipboard
D3D9: Make windowed GetFrontBufferData more accurate
Fixes #3724
Total War Medieval 2 uses GetFrontBufferData to take a screenshot and then copies that screenshot to a texture which is used to render the background of the loading screen.
In windowed mode, GetFrontbufferData will in fact take a screenshot of the entire screen. We don't implement it that way in DXVK, we always blit the most recent front buffer.
There's two problems with our implementations in Medieval 2:
- The image is positioned incorrectly. The game retrieves the window client rect and copies those parts of the GetFrontBufferData destination surface. DXVK always puts the screenshot at 0,0.
- The game uses additional swapchains (on the same window no less) and presents using one of those. DXVK always blits the implicit swapchain.
So to solve this without having to implement GetFrontBufferData properly (taking a screenshot of the entire screen), I propose that we:
- Query the position of the window and blit the screenshot to that location. (easy)
- Track the swapchain that was the most recently used for presenting and forward GetFrontBufferData calls to that swapchain instead of the implicit one. That's obviously a hack but it works for Medieval 2 and should be fine for most other games, as very few games use additional swapchains and even fewer of those use them together with GetFrontBufferData.