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

InputCommon:QuartzKB&M: Use KVO to watch window position #10979

Merged
merged 3 commits into from Oct 22, 2022

Conversation

TellowKrinkle
Copy link
Contributor

CGWindowListCreateDescriptionFromArray would send a request to WindowServer and block until it got a response. This had two issues:

  1. The call took ~200µs on average. Dolphin's main emulation thread seems to call UpdateInput() about 5 times per frame during Wii emulation, wasting 1ms per frame
  2. Since you're now waiting for WindowServer to get back to you, what if it just happens to be busy when you made your request? About 5% of calls take >1ms, some upwards of 2ms.

Changes QuartzKeyboardAndMouse to use a KVO observer on the window to update a position variable under a mutex.

Also modifies QuartzKeyboardAndMouse to calculate mouse coordinates relative to the main view, rather than the entire window (which includes the window's titlebar).

CGWindowListCreateDescriptionFromArray would block for up to ~1ms, which isn't a great thing to do on the main emulation thread
Copy link
Member

@OatmealDome OatmealDome left a comment

Choose a reason for hiding this comment

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

LGTM.

@dvessel
Copy link
Contributor

dvessel commented Oct 8, 2022

Nice! Please merge.

❯ gfx-render-time \
  --dolphin /Applications/Dolphin/master\ 5.0-17558.app \
  --dtm F-Zero\ Sand\ Ocean\ Intro.dtm -r 3 \
  --config=Graphics.Settings.InternalResolution=1 
1/3 metal...................6.092ms
Run completed. Sampled 11436 frames.
2/3 metal...................6.204ms
Run completed. Sampled 11436 frames.
3/3 metal...................6.112ms
Run completed. Sampled 11436 frames.
11436 frames 6.092ms metal pass 1
11436 frames 6.204ms metal pass 2
11436 frames 6.112ms metal pass 3
34308 frames 6.136ms complete

❯ gfx-render-time \
  --dolphin /Applications/Dolphin/QuartzWindowSpeed\ 5.0-17561.app \
  --dtm F-Zero\ Sand\ Ocean\ Intro.dtm -r 3 \
  --config=Graphics.Settings.InternalResolution=1 
1/3 metal...............4.609ms
Run completed. Sampled 11436 frames.
2/3 metal...............4.610ms
Run completed. Sampled 11436 frames.
3/3 metal...............4.610ms
Run completed. Sampled 11436 frames.
11436 frames 4.609ms metal pass 1
11436 frames 4.610ms metal pass 2
11436 frames 4.610ms metal pass 3
34308 frames 4.610ms complete

@TellowKrinkle
Copy link
Contributor Author

Skyward Sword DC 85 → 105 fps on i9 9980HK + Radeon Pro 5600M

@JMC47 JMC47 merged commit bc4d080 into dolphin-emu:master Oct 22, 2022
11 checks passed
@galad87
Copy link

galad87 commented Oct 22, 2022

I almost wrote that this PR fixed the horrible frame pacing on Intel Macs, then I remember I didn't test Dolphin since updating to Ventura RC and tested the a version before this PR.

Actually It was Ventura that fixed the frame pacing issue, I guess there are some nice improvements to Metal and AMD drivers, now Dolphin it's smooth as butter even on Intel Macs!

Anyway, a big thanks for all the Ubershaders and latest improvements that made this stutter free experience possible on Macs too!

@TellowKrinkle TellowKrinkle deleted the QuartzWindowSpeed branch October 22, 2022 20:24
@TellowKrinkle
Copy link
Contributor Author

TellowKrinkle commented Oct 22, 2022

I almost wrote that this PR fixed the horrible frame pacing on Intel Macs, then I remember I didn't test Dolphin since updating to Ventura RC and tested the a version before this PR.

In that case, I wouldn't be surprised if you test #11028 and run with --config=Graphics.Settings.MTLUsePresentDrawable=1 (or by adding MTLUsePresentDrawable=1 to GFX.ini) (note: will prevent fast-forward), that would probably fix it on pre-Ventura as well (though for Metal only).

Side note: Does fast forward still work on Ventura?

@galad87
Copy link

galad87 commented Oct 25, 2022

Fast forward works on Ventura.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
5 participants