Search Unity

Performance problems with Vive and VR. Regular VR.WaitForGPU spikes

Discussion in 'AR/VR (XR) Discussion' started by 8bitgoose, Mar 14, 2018.

  1. 8bitgoose

    8bitgoose

    Joined:
    Dec 28, 2014
    Posts:
    448
    Hi everyone,

    Are you having constant spikes in the Editor when you try and play a scene? Does your performance sometimes get good, and then get terrible again. Does the profiler return spikes ever second whenever you play. Does it slow to a crawl?

    It has nothing to do with your Vive or VR. That is a result of overuse CPU by the stupid Windows Anti-Malware system. It thinks Unity is malware!

    You must either disable realtime anti-malware protection or add Unity.exe to the list of exclusions in your Windows Defender settings.

    To add it to the list (since windows will turn on the real time protection even if you turn it off, thanks windows), you have to go to Windows Defender Settings > Opening Windows Defender Security Center > Virus and Threat Protection > Virus & threat protection settings > scroll to the bottom > Add or Remove Exclusions > + Add an Exclusion > Process > Unity.exe. Yes it tiakes 3 lines to get to this setting.

    The reason the spikes are so bad is because windows defender will hog the CPU. Because the CPU is being hogged, the CPU will miss sending info to the GPU and have to wait till the next scene to send the info again. But now the physics is freaking out because it didn't render, so now it does the physics twice. OH NO, the physics took longer and now the CPU missed the scene again. This cascades to terrible frame rates till the anti malware looks at Unity sees it isn't even running and stops caring.

    This destroyed my productivity for weeks and I had no idea why. I hope this helps you out.
     
  2. GoesTo11

    GoesTo11

    Joined:
    Jul 22, 2014
    Posts:
    604
    Thanks, this appears to help at first glance. You should probably put this in the VR forum.
     
    8bitgoose likes this.
  3. SnowInChina

    SnowInChina

    Joined:
    Oct 9, 2012
    Posts:
    204
    hm, will test this tomorrow
    i get some spikes in the profiler, but i always thought that they are from the profiler itself
    my scene is running stable on 90fps though
     
  4. dogsta

    dogsta

    Joined:
    May 15, 2016
    Posts:
    11
    I was having high VR.WaitForGPU too. After looking into it, I discovered that MSI Afterburner is the culprit.

    Although, it wasn't spikes, just a consistent drop in FPS (<60) and consistently the VR.Wait was, erm, waiting. Kill MSI, things are now smooth as silk for me.

    EDIT: I'm using the Oculus.
     
    8bitgoose likes this.
  5. 8bitgoose

    8bitgoose

    Joined:
    Dec 28, 2014
    Posts:
    448
    Good point! Posting the same in the VR forum. I assume this happens on normal games, but the wait for GFX only affects it if you have Vsync on.
     
  6. ScottF

    ScottF

    Vice President, Platforms

    Joined:
    Jul 31, 2013
    Posts:
    96
    Thanks for reporting this! I will reach out to Microsoft about Unity.exe being processed at Malware to see if we can have a built in exception made.

    Cheers,
    Scott
     
  7. rob_vld

    rob_vld

    Joined:
    Jul 9, 2013
    Posts:
    191
    I was aware of the suggested work around but despite that I dont know what changed, but i am having so much issues with framedrops it isnt funny anymore...

    I am working on a network game and positions and the speed of objects are no longer reliable...
     
  8. FiveFingerStudios

    FiveFingerStudios

    Joined:
    Apr 22, 2016
    Posts:
    510
    I've been having this issue for the past 2 years.

    I've always had to disable Windows Defender real-time protection every time I reboot and I was good However within the last few weeks, thats no longer effective. Windows Defender now turns real-time protection back on automatically!
     
  9. 8bitgoose

    8bitgoose

    Joined:
    Dec 28, 2014
    Posts:
    448
    @rob_vld Have you added an exception for Unity.exe?

    @sbmhome I feel your pain. Windows is becoming more and more controlling of how you do things with the computer that you own. It is super frustrating. I suggest you add an exception, did that and I am not longer getting any issues.
     
    Chiefmastoras1 likes this.
  10. FiveFingerStudios

    FiveFingerStudios

    Joined:
    Apr 22, 2016
    Posts:
    510
    @8bitgoose
    Yes, I added the exception...I didn’t know about that feature...thanks for sharing!
     
  11. 8bitgoose

    8bitgoose

    Joined:
    Dec 28, 2014
    Posts:
    448
    I don't think it is a "feature" of Windows more like helping windows not suck :p. Its too bad this was so hard to find on the internet. I have had the same problem forever @sbmhome
     
  12. FiveFingerStudios

    FiveFingerStudios

    Joined:
    Apr 22, 2016
    Posts:
    510
    Last edited: Mar 19, 2018
  13. 8bitgoose

    8bitgoose

    Joined:
    Dec 28, 2014
    Posts:
    448
    We do meet again. Small community! My project is way behind what I expected. I decided to make the most realistic rope system ever. Turns out that takes an inordinate amount of time...
     
  14. McDev02

    McDev02

    Joined:
    Nov 22, 2010
    Posts:
    664
    This doesn't seem to help for me. My issue is that I made an app and it used to work fine. Now Suddenly two weeks later it seems to lag quite significantly. I tried the Maleware settings for both Unity.exe and the build but no changes.

    I start to think if any Windows Update caused this, for isntance one specific Windows update causes Photoshop to stop working with a pen. I may reinstall Mixed Reality and SteamVR but I see no other option. In Unity I get rather constant 100 FPS and only like every 5th spike I notice in the VR device is actually shown in the profiler. Instead what I think are spikes is shown as a rise from 100 to 200 FPS. Weird. Also in the build it doesn't get much better.

    BTW I am using 2017.3.0f3 and I will try a new Unityversion as well.

    profiler.jpg
    So this actually looks great but it is nearly unplayable. I actually think that tracking is the issue as only head movement is laggy.
     
    Last edited: Jun 25, 2018
  15. 8bitgoose

    8bitgoose

    Joined:
    Dec 28, 2014
    Posts:
    448
    That doesn't look like the lag I've been seeing from this. Those purple spikes are caused by code that creates a lot of garbage. Which means something in your code is creating a lot of stuff in memory that has to be cleaned up.
     
  16. McDev02

    McDev02

    Joined:
    Nov 22, 2010
    Posts:
    664
    Maybe this thread isn't right, it's just that this happened suddenly and meanwhile I know it only occurs with the MixedReality Device, not with the Oculus. I can't track down where the Garbadge comes from but my app, except third party APIs is pretty small. I will profile it with the Oculus and see if there is any difference.
     
  17. orrbain

    orrbain

    Joined:
    Aug 12, 2015
    Posts:
    20
    Thanks for posting this. We've been dealing with a very weird issue where the game would run fine for anywhere from 5-45 minutes, and then all of a sudden we would be dealing with massive judder.

    The Unity Profiler revealed massive amounts of time being spent in XRBeginFrame and XRUpdate. It didn't matter that we were standing in literally the same spot in the game and not doing anything but looking around.

    Finally we found this thread and turned off Windows Defender. In real time I watched the SteamVR frame timings drop from 16+ms on the CPU to 5ms. Unity Profiler showed a similar massive decrease in time in those two functions and now all is fine.

    We recently upgraded from 5.6 to 2018.2. We did not see this issue in 5.6. Is there anything that can be done about this? It's fine for testing but I can't exactly tell everyone who is going to play the game "Hey just trust us we're not a virus." We've seen the problem replicated on about 80% of our tester's computers on both Vive and Oculus headsets, so this is not an isolated issue.
     
  18. 8bitgoose

    8bitgoose

    Joined:
    Dec 28, 2014
    Posts:
    448
    This was happening on builds? I only found this issue with the Unity editor. If this is happening in builds, that is a huge deal. Unity 2018.2 must be doing something different with threading and Windows Defender thinks it is a threat. @ScottF did you ever reach out to Microsoft about this?
     
    Chiefmastoras1 likes this.