Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

BUG: VR.WaitForGPU forcibly occupies CPU when running in background

Discussion in 'AR/VR (XR) Discussion' started by John-Chen350, Oct 8, 2016.

  1. John-Chen350

    John-Chen350

    Joined:
    Jan 14, 2015
    Posts:
    53
    I'm working on a enterprise-level Unity3D project on OpenVR recently. Generally speaking it works great, yet when I send it into background (when other VR programs are running) Unity forcibly cooled FPS down to ~10. I've noticed that VR.WaitForGPU used ~100ms even if there are nothing being rendered. No active cameras.

    I know there are no needs for rendering to HMD when you are in background, but what if I need it to be in companion window while I cannot even toggle off VRSettings.enabled? (which definitely caused crash)

    In this situation, I have no way to improve framerate for now. Application.targetFrameRate did nothing. I need only the camera working for Main Display at this time, without removing the VR support altogether (which is needed earlier or later during life cycle)..

    Looking forward to your kind help, Unity Team :)
     
  2. John-Chen350

    John-Chen350

    Joined:
    Jan 14, 2015
    Posts:
    53
    Actually I'm finding a way to dynamically enable and disable VR support (which now caused CRASH)..

    Or please give me a way to set frame rate manually other than 10fps / 100ms..
     
  3. John-Chen350

    John-Chen350

    Joined:
    Jan 14, 2015
    Posts:
    53
    Anyone knows?
     
  4. Dreamwriter

    Dreamwriter

    Joined:
    Jul 22, 2011
    Posts:
    472
    Here's how to enable/disable VR support:

    UnityEngine.VR.VRSettings.enabled = false;
     
  5. thep3000

    thep3000

    Unity Technologies

    Joined:
    Aug 9, 2013
    Posts:
    398
    I think OpenVR may be throttling Unity when it's in the background as a policy. If that is the case I don't think there is much we can do.

    Regarding VRSettings.enabled crash -- do you mind submitting a bug report and sending issue id to me? I just fixed a bug yesterday with a crash on toggling enabled when the scene is using image effects. Planning on backporting to 5.5, 5.4 but I don't have an ETA yet. Would like to know if it fixes your problem.

    If VRSettings.enabled works, will this resolve your issue?
     
    John-Chen350 likes this.
  6. John-Chen350

    John-Chen350

    Joined:
    Jan 14, 2015
    Posts:
    53
    Thank you for your reply first. I've thought that no one may come to this thread yet :)

    If there is no camera rendering to OpenVR, it's not necessary for Unity to be blocked by OpenVR driver and VR.WaitForGPU. And I do believe that this way will be more simple since toggling VRSettings.enabled is basically unstable. Also, I've downloaded 5.5 beta 10 today to see if VRSettings.enabled works or not (along with openvr plugin)
     
  7. John-Chen350

    John-Chen350

    Joined:
    Jan 14, 2015
    Posts:
    53
    Which shall cause a crash under all 5.4 versions after OpenVR initialized first.
     
  8. John-Chen350

    John-Chen350

    Joined:
    Jan 14, 2015
    Posts:
    53
    Yes, under 5.5b10 VRSettings.enabled works. But there are something remained that will cause a crash. I'm trying to reproduce that.
     
  9. John-Chen350

    John-Chen350

    Joined:
    Jan 14, 2015
    Posts:
    53
    It is simple to reproduce. Create a scene with OpenVR(SteamVR) Plugin. Enable VR by default; when the scene is running with SteamVR working, disable it and crashed immediately.
     
  10. John-Chen350

    John-Chen350

    Joined:
    Jan 14, 2015
    Posts:
    53
    Submitted a bug report mentioned this thread.. Case 847878
     
  11. thep3000

    thep3000

    Unity Technologies

    Joined:
    Aug 9, 2013
    Posts:
    398
    I backported the fix to the crash you reported, it is part of 5.4.2p4 and should be included in 5.5 release.

    VRSettings.enabled should be 100% stable, if this is not the case, let's fix those issues.
     
    John-Chen350 and ScottF like this.
  12. John-Chen350

    John-Chen350

    Joined:
    Jan 14, 2015
    Posts:
    53
    So do you mean my crash reported yesterday (with 5.5p10) is caused by SteamVR plugin? Or is that fixed in some versions (like 5.4.2p4)?

    Without SteamVR plugin it is really hard to get information like, controllers. Maybe I should connect to OpenVR Native Plugin directly? I need to get controller info when in background (without actual rendering).
     
  13. John-Chen350

    John-Chen350

    Joined:
    Jan 14, 2015
    Posts:
    53
    How about the question these days?

    I think I should split my program into two parts: one for rendering to screen and one for rendering to headset... Otherwise Steam still crashes with VRSettings.enabled switching from script.