ValveSoftware / openvr

OpenVR SDK
http://steamvr.com
BSD 3-Clause "New" or "Revised" License
6.08k stars 1.28k forks source link

How to disable vsync #1015

Open KrisITB opened 5 years ago

KrisITB commented 5 years ago

Hi,

I'm building an experiment using unity where one of the parameters being modulated is refresh rate of the application... but I'm unable to modulate it when HMD is connected as the vsync seems to be kicking in regardless of the settings in the engine or on the GPU itself. Is there any way I can disable vsync when using vive headset? Alternatively, is there any way to control refresh rate of the display itself?

Best wishes, Kris

aleiby commented 5 years ago

You can disable DirectMode in SteamVR's desktop settings (under Developer). This will make the Vive display show up as a regular monitor at which point you can control various aspects like vsync as you would any other monitor. Disabling vsync will cause tearing, however, and is not something you want to do in a headset for various reasons.

KrisITB commented 5 years ago

Thanks for your reply aleiby. I tried that briefly but the HMD was only displaying the color red for whatever reason, I'll try it again tomorrow if you think this will do and see if I'll manage to make it work with openvr unity build. [edit] no joy in the monitor mode either, vsync still on with no option to disable it be it through GPU settings or in unity application settings. Just to be sure I tested my build without HMD connected (to see if windows is not toying with me) and FPS modulates as expected so it has to be the VR headset forcing the vsync on the application [/edit]

I understand this is not a popular use case scenario as most people usually aim for more FPS, I'm investigating the impact of this parameter on presence and participants physiology hence the weird requirement of reducing frame rate. In case if anyone else needs something similar, one semi-solution that I have developed so far is to throw a thread.sleep() on the main thread pushing vsync to every second and every third frame, not what I was aiming for (linear modulation between 30 and 90) but better than nothing ;)

[edit] Would it be possible to at least allow developers to set the vsync level to every second or every third frame (45 and 30fps) so if anyone needs to play with this settings they do not have to choke down the entire main thread? [/edit]

Many thanks in advance, and congrats to the whole team working on the openvr, it really works like a charm (unless you want to do something bonkers with it ;) )!

aleiby commented 5 years ago

The compositor displays red when in extended mode and knocked out of fullscreen exclusive (which is required to avoid the latency introduced by the Windows desktop compositor). There is no interface for forcing the SteamVR compositor to not present with vsync. You would instead need to run without launching the compositor and do your own rendering to the headset display. You should be able to do this by launching vrserver.exe manually (use -keepalive to keep it from automatically exiting after two seconds without a connection from an application). Then you just need to avoid triggering the launch of the compositor (e.g. by requesting the IVRCompositor or related interface - overlay, screenshots, dashboard, notifications, tracked camera).

Would it be possible to at least allow developers to set the vsync level to every second or every third frame (45 and 30fps) so if anyone needs to play with this settings they do not have to choke down the entire main thread?

The compositor's use of vsync should not affect the application's main thread. Maybe there is some misunderstand / miscommunication about what the actual problem you are trying to solve is.

KrisITB commented 5 years ago

Sorry that was a bit of an overkill for my purpose (a.k.a. too much to learn ;)) , but I might try it in the future if I'll have more time, thank you. Seems that I managed to get it disabled in the end. I'm not exactly sure how tho %) thread sleep does the trick and pushes frame-rate outside of vsync values when it's disabled on gpu settings, but the application.targetframerate unity method is still ignored.

The compositor's use of vsync should not affect the application's main thread. Maybe there is some misunderstand / miscommunication about what the actual problem you are trying to solve is.

I'm not sure if it's executed on the openvr side or unity. The issue is such that once the VR headset is connected I'm unable to control the frame rate of my application through application.targetframerate method which works without the headset connected.

lynrayy commented 1 week ago

however, and is not something you want to do in a headset for various reasons.

87FPS and teared image VS 45FPS and whole image. Disabling VSYNC is what i WANT to do

Any way to disable VSYNC in 2024?

TheDeveloperGuy commented 1 week ago

There is a very clear explanation given by aleiby earlier in this thread. The whole rendering pipeline is oriented around VSYNC timing, so as they said, you'd have to implement your own compositor. If you WANT to disable VSYNC, even though it makes no sense and has no value, then you know what to do.