ValveSoftware / gamescope

SteamOS session compositing window manager
Other
3.15k stars 213 forks source link

Variable Refresh Rate / Adaptive Sync support #199

Closed ppascher closed 2 years ago

ppascher commented 3 years ago

Variable Refresh Rate / Adaptive Sync / Freesync is currently not supported in gamescope. It is supported in wlroots though (1). As most modern GPUs and Monitors support VRR it would be nice to eventually have VRR support in gamescope as well.

2021-05-19 | 10:28:53  emersion: ppascher: yeah, gamescope uses a fixed refresh rate, always. see the -r flag
2021-05-19 | 10:34:00  ppascher: emersion: Thank you. I was using the -r flag to limit my refresh rate a little below the max of 160hz for my monitor so it does not jump in and out of vrr range. Would VRR be something that could be implemented for gamescope since it uses wlroots? Or was this discussed before and dismissed?
2021-05-19 | 10:35:45  emersion: ppascher: i think it could be implemented, but would need a pretty major refactoring in vblankmanager.cpp

(1) https://github.com/swaywm/wlroots/pull/1987

Plagman commented 3 years ago

Yeah. I have some code in progress that helps on that front. Need to figure out how to detect we're VRR-capable in both nested and embedded to enable the logic where 'vblanks' would be driven by the need to repaint.

aqxa1 commented 3 years ago

Looking forward to this. For the record (until this is fixed), if you have a game that is internally capped below the monitor's refresh rate, you'll also need to cap with gamescope, as the monitor will still try and run the max refresh rate when run with gamescope.

nfp0 commented 2 years ago

Also looking forward for this feature.

jarrard commented 2 years ago

Yeah this is basically the last major feature I need in GS before I start using it. Hope it can happen soon!
Not sure if the steam deck can take advantage of VRR or not, but it helps smooth framerates out in many games. It's also not ALWAYS beneficial to have enabled but normally helps.

jluthi commented 2 years ago

Let's get this working!

jarrard commented 2 years ago

I don't really know whats required to make it so at this point. I thought gamescope already runs in true fullscreen mode with the -F flag but maybe its fake, or the game inside is being forced into borderless within gs....

ppascher commented 2 years ago

I just noticed while checking for status on #163 that VRR appears to be working through gamescope playing Cyberpunk 2077. Can someone confirm? This was using sway/wlroots with enabled VRR on amdgpu.

Plagman commented 2 years ago

VRR will 'work', but we won't present at the right time for it to have the desired effect, at the moment. It should be really easy to plumb an unconditional VRR option with how the current thing is laid out, and we can plumb it to dynamically detecting if VRR is currently on for our window or not later.

jarrard commented 2 years ago

It be nice if it worked for xorg since I'm holding off using wayland until it has display gamma controls and maybe HDR happening.

TheEvilSkeleton commented 2 years ago

Theoretical question, if Gamescope supported VRR and if a Wayland compositor like Mutter doesn't support VRR, could we use Gamescope to have VRR support in the micro-compositor (not the UI, but for anything that is running inside Gamescope)?

Scrumplex commented 2 years ago

Theoretical question, if Gamescope supported VRR and if a Wayland compositor like Mutter doesn't support VRR, could we use Gamescope to have the VRR support?

VRR would probably won't work in nested mode (running Gamescope nested inside another compositor or X11)

You could maybe replace mutter with Gamescope, but that sounds very impractical.

Edit: Looks like wlroots only contains code for the DRM backend and for some reason also for the X11 backend

jarrard commented 2 years ago

Doesn't Mutter do fullscreen unredirect anyway which should allow VRR to work?

misyltoad commented 2 years ago

We want to do DRM leasing for stuff like this when nested

misyltoad commented 2 years ago
Doesn't Mutter do fullscreen unredirect anyway which should allow VRR to work?

Don't think itd play nicely, but we can always find out...

wsippel commented 2 years ago

Mutter supports neither VRR nor DRM leasing. Don't think anybody's working on DRM lease support, either: https://gitlab.gnome.org/GNOME/mutter/-/issues/1743

CorvetteCole commented 2 years ago

mutter supports VRR in https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1154 which should hopefully be merged soon

orowith2os commented 2 years ago

I think the best option for adding VRR support to gamescope would be enabling it as a launch option, same with most (all?) other features it has. If someone launches it with the option when their desktop doesn't support it and it breaks something, there's not much that could be done if implemented that way. I'm not very knowledgeable on how stuff would be implemented, and these are just my thoughts, so take em with an abnormally large grain of salt lol

TheEvilSkeleton commented 2 years ago

Related: https://github.com/Plagman/gamescope/commit/ec6bd30bb61e63d29536fc1e39c0326c11da7b5c

chaitan3 commented 2 years ago

VRR seems to be finally working in embedded (drm) mode.

Verified by running gamescope in VT after applying the following hacky patch on latest master (could not find a way to enable it via an environment variable or flag). Monitor OSD now displays game FPS.

diff --git a/src/drm.cpp b/src/drm.cpp
index 1e9b96a..8ceb950 100644
--- a/src/drm.cpp
+++ b/src/drm.cpp
@@ -2002,7 +2002,7 @@ bool drm_set_color_mtx(struct drm_t *drm, float *mtx, enum drm_screen_type scree

 void drm_set_vrr_enabled(struct drm_t *drm, bool enabled)
 {
-       drm->wants_vrr_enabled = enabled;
+       drm->wants_vrr_enabled = true;
 }

 bool drm_get_vrr_in_use(struct drm_t *drm)
misyltoad commented 2 years ago

I'll add a startup flag for this.