ValveSoftware / openvr

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

WaitFrameSync causes performance degradation, GPU frametime rises up to 100ms #1812

Closed sergioberg closed 10 months ago

sergioberg commented 10 months ago

Using WaitFrameSync in Background or Overlay application causes performance degradation of the running game, GPU frametime rises up to 100ms. Because of this I had to stop using WaitFrameSync in my application - fpsVR.

OS Windows 11/10 SteamVR 2.2.3/2.3.1 SDK version 1.23.7/2.0.10

Example code to reproduce the problem:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Valve.VR;

namespace WaitFrameSyncTest
{
    internal class Program
    {
        public static CVRSystem vrSystem;
        static float hz = 90.0f;

        static void Main(string[] args)
        {
            var error = EVRInitError.None;  
            vrSystem = OpenVR.Init(ref error, EVRApplicationType.VRApplication_Background);
            if (error != EVRInitError.None)
            {
                Console.WriteLine("HMD Not Found");
                return;
            }
            var error2 = ETrackedPropertyError.TrackedProp_Success;
            hz = OpenVR.System.GetFloatTrackedDeviceProperty(0, ETrackedDeviceProperty.Prop_DisplayFrequency_Float, ref error2);

            Console.WriteLine(hz.ToString("F3"));
            while (true)
            {
                OpenVR.Overlay.WaitFrameSync((uint)(1000 / hz));
                //....
            }
        }
    }
}

STEPS: Run SteamVR. Run the above code. Run Half Life Alyx (As an example, the problem is reproduced in other games too). Wait a few seconds and the problem will appear. It is better to test on wireless VR headsets (frame time rises to 100ms), on wired headsets the effect is not always visible and the frame time increases slightly. If, while observing this problem, you switch to another window and back, the problem disappears.

sergioberg commented 10 months ago

Update: The problem is also reproduced on SDK 2.0.10

sergioberg commented 10 months ago

Fixed in SteamVR 2.3.2