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

D3D9: Make windowed GetFrontBufferData more accurate #3843

Merged
merged 2 commits into from
Mar 5, 2024

Conversation

K0bin
Copy link
Collaborator

@K0bin K0bin commented Feb 6, 2024

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.

@K0bin K0bin added the d3d9 label Feb 6, 2024
@K0bin K0bin requested a review from misyltoad February 6, 2024 23:19
m_mostRecentlyUsedSwapchain = swapchain;
}

void ResetLastUsedSwapchain() {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider renaming this to RefreshLastUsedSwapchain()

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But it doesn't refresh it, it resets it to the built-in swapchain.

Copy link

@PatrickvL PatrickvL left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two remarks

src/d3d9/d3d9_device.cpp Show resolved Hide resolved
@misyltoad misyltoad merged commit a0e39e9 into doitsujin:master Mar 5, 2024
3 checks passed
@K0bin K0bin deleted the medieval2-hack branch March 5, 2024 14:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[d3d9] Medieval 2 black loading screen in windowed mode with dxvk
4 participants
  翻译: