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] Fix issues with presentation #3392

Merged
merged 3 commits into from
May 6, 2023
Merged

Conversation

K0bin
Copy link
Collaborator

@K0bin K0bin commented May 3, 2023

  • Do GDI blit for SWAPEFFECT_COPY_VSYNC too (which is missing from the mingw headers on my system)
  • Dont swap buffers when using SWAPEFFECT_COPY

- Blit the backbuffer contents into the frontbuffer, so GetFrontBufferData returns the expected data
- Replace noExplicitFrontBuffer with that frontbuffer blit (this needs testing)

  • Dont create an additional front buffer for SWAPEFFECT_COPY and windowed SWAPEFFECT_DISCARD with 1 backbuffer. The latter behaves identical to SWAPEFFECT_COPY in my testing, it even supports partial presentation.
  • In those cases, GetFrontBufferData will just return the contents of the backbuffer. That's technically wrong ofc but I don't think adding in another blit in windowed mode is worth it. It's only wrong for SWAPEFFECT_COPY and DISCARD in windowed mode. Fullscreen SWAPEFFECT_COPY is probably very rare because that kind of defeats the purpose as partial presentation doesn't work in fullscreen. GetFrontBufferData was broken in windowed mode anyway because Windows takes a screenshot of the entire screen when you call it and we just used to return the contents of the front buffer.

Fixes #2732
Fixes #2240
Fixes #2568
Fixes #3238
Fixes #1476
Fixes #1481
Fixes #2456
Fixes #2542
Fixes #3005
Fixes #3208
Fixes #3238
Fixes #3206
Fixes #3141
Fixes #3250
Fixes #1554
Fixes #2756
Fixes #2915

Closes #2749

@pchome
Copy link
Contributor

pchome commented May 4, 2023

imho using const swapEffectCopy everywhere would be cleaner a bit

const bool swapEffectCopy = m_presentParams.SwapEffect == D3DSWAPEFFECT_COPY || m_presentParams.SwapEffect == D3DSWAPEFFECT_COPY_VSYNC;

@K0bin
Copy link
Collaborator Author

K0bin commented May 4, 2023

I wrote a test application to figure out how this is supposed to behave:

WINDOWED:
FLIP + 5 buffers => has additional front buffer
FLIP + 1 buffers => has additional front buffer
DISCARD + 5 buffers => has additional front buffer, contents of the backbuffers stay valid
DISCARD + 1 buffers => does not have additional front buffer, contents of the backbuffers stay valid
FLIPEX + 5 buffers => has additional front buffer
FLIPEX + 1 buffers => has additional front buffer
COPY + 1 buffers => does not have additional front buffer

DISCARD always preserves the contents of the back buffer.

Partial Present works for COPY and DISCARD + 1 buffer.
GetFrontBufferData takes a screenshot of the entire monitor in windowed mode.

FULLSCREEN
FLIP + 5 buffers => has additional front buffer
FLIP + 1 buffers => has additional front buffer
DISCARD + 5 buffers => has additional front buffer, contents of the backbuffers stay valid
DISCARD + 1 buffers => has additional front buffer, contents of the backbuffers stay valid
FLIPEX + 5 buffers => has additional front buffer
FLIPEX + 1 buffers => has additional front buffer
COPY + 1 buffers => does not have additional front buffer

DISCARD always preserves the contents of the back buffer.

Partial Present does not work in fullscreen mode.
GetFrontBufferData works as expected.

@K0bin K0bin force-pushed the present-stuff branch 2 times, most recently from 3251f21 to 4e6f76f Compare May 4, 2023 15:30
@w-flo
Copy link
Contributor

w-flo commented May 5, 2023

Replace noExplicitFrontBuffer with that frontbuffer blit (this needs testing)

FWIW, I tested Zusi 3 with your latest patches applied on top of master, and it seems to work without issues. 🐸 Zusi 3 needed the noExplicitFrontBuffer config because it uses DISCARD swapeffect & 1 backbuffer. Thanks for working to get rid of that noExplicitFrontBuffer hack!

Edit: Still works on latest patches without the frontbuffer blit (b5f03a8)

@arodland
Copy link

arodland commented May 5, 2023

Tested FlexRadio SmartSDR, which is a WPF app that has absolutely horrible performance with regular wine and broken (mostly black) display with dxvk 2.1 and master.

This build makes it run just like it does on wined3d — visually correct, but near-unusably slow. I guess it was too much to hope for a magic fix :)

@Blisto91
Copy link
Contributor

Blisto91 commented May 5, 2023

Yes this implementation is expected to be slow

@K0bin K0bin force-pushed the present-stuff branch 4 times, most recently from 2ce9ee8 to b5f03a8 Compare May 5, 2023 13:21
@K0bin K0bin marked this pull request as ready for review May 5, 2023 13:22
@K0bin K0bin added the d3d9 label May 5, 2023
@Blisto91
Copy link
Contributor

Blisto91 commented May 5, 2023

First round of testing based on most of the maybe Partial Present tracked issues

#2732 Fixed
#2240 Fixed
#2568 (Part of issue) Fixed
#2278 Not fixed
#1476 Fixed
#2334 Untested (couldn't get it running)
#1481 Fixed
#2456 Fixed
#2542 Seems fixed or at least improved. dotnet install and (x)Wayland can cause issues
#2860 Untested
#3005 Fixed based on apitrace
#3116 Not fixed
#3208 Fixed

@Blisto91
Copy link
Contributor

Blisto91 commented May 5, 2023

Testing of front buffer issues and related
#3238 Fixed
#3206 Fixed based on apitrace
#3141 Fixed
#3250 Fixed. Thanks @CME42
#1554 Fixed based on apitrace

Honorable mentions
#2756 Fixed
#2915 Fixed

Edit: added a extra honorable mention

@misyltoad
Copy link
Collaborator

@K0bin Do you want to add all of these issues to your commit with a Closes: so we can have a super statisfying clean sweep? :-)

Copy link
Collaborator

@misyltoad misyltoad left a comment

Choose a reason for hiding this comment

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

Minor nits.

src/d3d9/d3d9_swapchain.cpp Outdated Show resolved Hide resolved
src/d3d9/d3d9_swapchain.h Outdated Show resolved Hide resolved
@w-flo
Copy link
Contributor

w-flo commented May 5, 2023

The very first bug report about the front buffer stuff might have been #1368, which this PR fixes properly instead of special-casing the workaround, so if you want to add it to the super long Closes: line 🥇 …

src/d3d9/d3d9_swapchain.h Outdated Show resolved Hide resolved
src/d3d9/d3d9_swapchain.h Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment