Closed Bug 1628137 Opened 5 years ago Closed 5 years ago

Switch to using WaitForVBlank for vsync on Windows

Categories

(Core :: Graphics, enhancement, P3)

Desktop
Windows
enhancement

Tracking

()

RESOLVED FIXED
mozilla77
Tracking Status
firefox76 --- fixed
firefox77 --- fixed

People

(Reporter: jrmuizel, Assigned: bpeers)

References

(Blocks 1 open bug)

Details

Attachments

(3 files, 1 obsolete file)

It seems like using DWMFlush causes us to wait for the DWM to finish it's work before starting any of ours.

Chrome has started using WaitForVBlank and there's a thread here with piles of info:
https://bugs.chromium.org/p/chromium/issues/detail?id=953970

https://cs.chromium.org/chromium/src/ui/gl/vsync_thread_win.cc?q=WaitForVBlank&sq=package:chromium&dr=C&l=115

See also the complaints here: https://www.vsynctester.com/firefoxisbroken.html

Switching to WaitForVBlank can buy us 1ms+ of frame budget which can be really important on lower end machines.

Blocks: 1576637

We originally ran into problems with WaitForVBlank acquiring a process wide lock but it seems like those problems were limited to Win7.

From https://bugs.chromium.org/p/chromium/issues/detail?id=953970:
"1. Use WaitForVBlank in Win8+ only, there is a process wide lock in Win7 there prevents other DX from running in the process if you call WaitForVBlank."

Priority: -- → P3
Blocks: vsync
Assignee: nobody → bpeers
Depends on: 1614083
Blocks: 1614083
No longer depends on: 1614083

This seems to work without issues on my dual monitor setup, and substantially reduces the instability in the frame-to-frame delay as measured via QueryPerformanceCounter: from a full millisecond above or below the 16.66 we want, to less than 0.2ms of wobble. Both the peaks and the general variation seems improved.

I haven't tested yet what happens during sleep, monitor time-out, laptop close, etc. I've attached the patch will all the timing scaffolding as part of it. I could take it all out and make a proper review if we think this is enough?

There's also a bit in there where I simply assign vsync = now when using VBlank, and that seems to drop the blue/purple lines on vsynctester.com by about 2ms; not entirely sure what that means but it sounds like a good thing? :)

It would probably be good to make this controllable via a pref. That way we can get it in early and have people easily change it if they run into problems.

Pushed by bpeers@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/d05d35839c2a Switch to using WaitForVBlank for vsync on Windows r=jrmuizel
Status: NEW → RESOLVED
Closed: 5 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla77

I had a look at a new gpuview trace with this change it looks like it has the benefit that we're looking for. We start doing work ~1ms earlier.

Comment on attachment 9139642 [details]
Bug 1628137 - Switch to using WaitForVBlank for vsync on Windows

Beta/Release Uplift Approval Request

  • User impact if declined: This relatively simple change has shown a substantial performance improvement in a number of situations that we've tested. We'd like to get it out as soon as possible.

This change doesn't actually enable the new vsync method (it's behind a pref) but will enable wider testing.

  • Is this code covered by automated tests?: No
  • Has the fix been verified in Nightly?: No
  • Needs manual test from QE?: No
  • If yes, steps to reproduce:
  • List of other uplifts needed: None
  • Risk to taking this patch: Low
  • Why is the change risky/not risky? (and alternatives if risky): There should be no behaviour change because the code is behind a pref.
  • String changes made/needed:
Attachment #9139642 - Flags: approval-mozilla-beta?
OS: Unspecified → Windows
Hardware: Unspecified → Desktop

Enable by default on Windows 10, unless force disabled by pref.

Blocks: 1630389
Attachment #9140862 - Attachment is obsolete: true

Comment on attachment 9139642 [details]
Bug 1628137 - Switch to using WaitForVBlank for vsync on Windows

Lands this new functionality between an off-by-default pref for wider opt-in testing. Approved for 76.0b5.

Attachment #9139642 - Flags: approval-mozilla-beta? → approval-mozilla-beta+
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: