Welcome to the Oculus Developer Forums!

Your participation on the forum is subject to the Oculus Code of Conduct.

In general, please be respectful and kind. If you violate the Oculus Code of Conduct, your access to the developer forums may be revoked at the discretion of Oculus staff.

DX11 related lag

CurtisCurtis Posts: 92
Hiro Protagonist
edited September 2014 in Unity Development
Lately I have run into a really big problem. Stomach churning, throw the rift off my head, reach for a bucket, awful lag and it has nothing to do with the frame rate.

There is no choppyness associated with this lag, if anything head tracking goes "extra smooth". For instance, if you roll or nod your head, the camera lags behind, to the point where you can almost get the camera to stay stationary why your are rolling/nodding (and if you do it to much.. reaching for a bucket).



The two times I have noticed it was 1) I had loads of particles on screen, forward rendering. The weird part is, I had equal amounts of particles in all direction, but the horrible lag only occurred when I looked in one direction. If anything, there where less particles where the lag happens...


2) Point light, deferred lighting. Lots of calculations here, lots of shadows being thrown around, but zero drop in frame rate, just this horrible smooth lag.


Is it just me?

Any help fixing this, or at least ways to avoid it would be greatly appreciated!

Thanks

edited to make the subject line more relevant to the topic

Comments

  • cyberealitycybereality Posts: 26,156 Oculus Staff
    Do you experience the same "lag" if you use other input (mouse/keyboard/gamepad) or is it only effecting head-tracking?
    AMD Ryzen 7 1800X | MSI X370 Titanium | G.Skill 16GB DDR4 3200 | EVGA SuperNOVA 1000 | Corsair Hydro H110i
    Gigabyte RX Vega 64 x2 | Samsung 960 Evo M.2 500GB | Seagate FireCuda SSHD 2TB | Phanteks ENTHOO EVOLV
  • CurtisCurtis Posts: 92
    Hiro Protagonist
    It appears to only effect head tracking. I am also using hydras, and I can move those around in front of me with almost no lag in the trouble spots, as long as I hold my head still.

    So this time, I intentionally got the frame rate to dip from 60 fps to 50 fps, and a tiny bit of lag on hand movements, but it is like you would expect. The bad news is that it made the head tracking lag MUCH worse, it is unbearable

    I should also say that 95% of the time everything works fine, and when there is framerate dips the rift reacts like you would expect with <60 fps. Normal choppyness. But this problem seems to be pretty different
  • cyberealitycybereality Posts: 26,156 Oculus Staff
    Are you using DirectX11? I remember some people experiencing lag with DX11 and Unity.
    AMD Ryzen 7 1800X | MSI X370 Titanium | G.Skill 16GB DDR4 3200 | EVGA SuperNOVA 1000 | Corsair Hydro H110i
    Gigabyte RX Vega 64 x2 | Samsung 960 Evo M.2 500GB | Seagate FireCuda SSHD 2TB | Phanteks ENTHOO EVOLV
  • CurtisCurtis Posts: 92
    Hiro Protagonist
    Yep, using direct X11.

    Later on, I'll back everything up, and try it without 11.

    In the long run, that is a bad solution for me though, because I am using tc particles (which requires dx11)

    But still, Ill try it out just to see if that is the problem
  • ccsccs Posts: 219
    Hiro Protagonist
    I have same issue with DX11. The only solution I have found and read about is to turn vsync off. You must turn it off in both quality settings and edit OVRCameraController.cs to turn it off. Code snippet below:
    //QualitySettings.vSyncCount = 			1;
    

    I really hope there is a fix to this soon (I'm not sure if it is a Unity DX11 issue or a Rift SDK issue). I also depend on DX11 and I have to choose between unacceptable latency that will make people ill or reduced visual quality due to tearing. Not a good choice.

    I have the latency tester and I found it registers 60ms with vsync on and 20ms with it off. The difference is huge in terms of head response (I can see why VR failed in the past). FPS is pegged at 60FPS with vsync on and ~110FPS with vsync off.

    DX9 with vsync on doesn't have the same issue.

    I have tried many things to eliminate latency with DX11 with vsync on and none seem to matter. Driver settings don't seem to make a difference (except the one that forces vsync off).

    Here is another thread that talks about this:
    viewtopic.php?f=37&t=5594

    ccs
  • ccsccs Posts: 219
    Hiro Protagonist
    I figured out the issue!

    It appears to be a Unity bug with DX11. Essentially QualitySettings.maxQueuedFrames is not working with DX11. It doesn't matter what you set it to, the latency result is always the same. I filed a bug on Unity to see if they can fix it.

    Fortunately there is a workaround (at least for Nvidia cards). I have an Nvidia GTX 760 and in the driver there is a setting that overrides application max queued frames setting.

    I ran some tests with my latency tester just to verify what my eyes and brain were telling me, and it is pretty clear this setting fixes the issue and shows that QualitySettings.maxQueuedFrames is not functional in DX11 (seems to work fine in DX9).
    Application     Nvidia driver max frames        QualitySettings.   latency  latency  latency avg
                                                     maxQueuedFrames   low      high     10 runs
    vsync off       Use the 3D application setting          0            9        44       21.3
    vsync off       Use the 3D application setting          5           10        49       24.9
    vsync off       1                                       0           11        34       19.8
    vsync on        Use the 3D application setting          0           18        79       53.6
    vsync on        Use the 3D application setting          5           16        71       41.1
    vsync on        1                                       0            9        32       16.2
    

    Attached is a picture showing where the override setting is in the Nvidia driver.



    ccs
  • CurtisCurtis Posts: 92
    Hiro Protagonist
    Awesome, thanks for this info!

    I just tried my project out with Direct X11 disabled, and sure enough, that fixed the problem.

    Turned dx11 back on, disabled V sync like you suggested and... WOW! What a HUGE difference in latency, not only with the trouble spots, but just in general.

    One thing, I am now getting around 100 - 120 fps so I through in a
    Application.targetFrameRate = 60;
    

    just to keep things consistent.


    Thanks again, this is some excellent info!
  • cyberealitycybereality Posts: 26,156 Oculus Staff
    Interesting. This sounds like it's not a bug w/ the SDK itself, but I will have someone take a look to see if there is any way to mitigate the issue.
    AMD Ryzen 7 1800X | MSI X370 Titanium | G.Skill 16GB DDR4 3200 | EVGA SuperNOVA 1000 | Corsair Hydro H110i
    Gigabyte RX Vega 64 x2 | Samsung 960 Evo M.2 500GB | Seagate FireCuda SSHD 2TB | Phanteks ENTHOO EVOLV
  • HeadTripHeadTrip Posts: 164
    Hiro Protagonist
    Nice! that worked for me, i switched it to 1. Thanks! it's so nice to have the correct tracking.
  • vajra3dvajra3d Posts: 134
    Curtis wrote:
    Turned dx11 back on, disabled V sync like you suggested and... WOW! What a HUGE difference in latency, not only with the trouble spots, but just in general.

    Just a word of caution to others, you might want to be careful with turning vsync off since it can cause issues with some physics-based objects that are framerate dependent (i.e., certain actions will run at faster speeds than intended).
  • ccsccs Posts: 219
    Hiro Protagonist
    If your game changes physics behavior based on frame rate, you are doing something wrong in your code. That means your game will play differently if the user's computer can't keep a constant 60fps.

    You should be using 'void FixedUpdate()' to do any physics-based API calls like applying forces to rigidbodies. FixedUpdate runs at a near-fixed time interval and correctly applies forces across frames. You can set FixedUpdate to run at whatever interval you think is appropriate. I find for super-accurate physics, it is best to run at 200 FixedUpdate FPS (you can set this in TimeManager settings with the Fixed Timestamp parameter), but you can also set this lower so it runs below screen refresh (say 30FPS).

    Also you should generally multiply time-dependent calculations/forces by Time.deltaTime (for stuff in Update) and Time.fixedDeltaTime (for stuff in FixedUpdate) to make your code framerate independent. This also prevents glitches due to some frames taking longer than others (no game runs perfect 60fps even with vsync on).

    ccs
  • ccsccs Posts: 219
    Hiro Protagonist
    This has probably changed with 0.4.0 SDK and the new direct rendering mode, but I wanted to point out and confirm that Unity fixed (most of) the DX11 latency issues starting with build 4.5.2p2 here:

    http://forum.unity3d.com/threads/unity-patch-releases.246198/#post-1711628

    (none) : Windows Player: Performance improvements including lower latency in DirectX 11 mode.

    I confirmed the earlier workaround I posted (forcing max queued frames to 1 in driver) is no longer needed. DX11 still seems to have slightly higher latency than DX9, but it is now usable with vsync on as long as prediction is set around 40-50ms.

    Just got my DK2 in, so I'll be moving on to 0.4.0 and see how DX11 is working with the new setup.

    ccs
  • vajra3dvajra3d Posts: 134
    ccs wrote:
    If your game changes physics behavior based on frame rate, you are doing something wrong in your code.

    Yes, indeed I was... and I have since updated my code (about a month ago) but I appreciate your helpful advice on this!
  • CurtisCurtis Posts: 92
    Hiro Protagonist
    ccs wrote:
    This has probably changed with 0.4.0 SDK and the new direct rendering mode, but I wanted to point out and confirm that Unity fixed (most of) the DX11 latency issues starting with build 4.5.2p2 here:

    http://forum.unity3d.com/threads/unity-patch-releases.246198/#post-1711628

    (none) : Windows Player: Performance improvements including lower latency in DirectX 11 mode.

    I confirmed the earlier workaround I posted (forcing max queued frames to 1 in driver) is no longer needed. DX11 still seems to have slightly higher latency than DX9, but it is now usable with vsync on as long as prediction is set around 40-50ms.

    Just got my DK2 in, so I'll be moving on to 0.4.0 and see how DX11 is working with the new setup.

    ccs

    That's great news! The bad news is that the new SDK isn't compatible with DX11. Hopefully that will be fixed in the next SDK update
  • ccsccs Posts: 219
    Hiro Protagonist
    I have been able to get DX11 to work with 0.4.0, and I'm happy to report lag is completely gone! Tracking is perfect now with my DX11 Unity project.

    Here is the formula I have found that works:

    1. IMPORTANT! turn vsync off in Unity quality settings - direct rift mode will take of this for you - if you have it on it will cap you at 60fps, not 75fps and give you terrible results (edit: for me the project actually crashes on start if vsync was on in quality settings)
    2. on the OVRCameraController, uncheck the Time Warp button - i found it sometimes causes juddering and the tracking seems way better with if off!
    3. set Rift display mode to direct HMD access in the Oculus configuration tool
    4. build & run your project (immediately exit your project when it starts)
    5. make sure the oculus configuration tool is closed (camera light should be off)
    6. go to your project folder and run the DirectToRift.exe for your project
    7. if it crashes - just run it again - it should start on 2nd try
    8. if you notice screen tearing or juddering, make sure to exit Unity before running your project
    9. if you still notice screen tearing, in the oculus configuration tool, select Tools->Advanced->Restart Service...
    10. if you still notice screen tearing, reboot your computer - don't open unity or configuration tool - just try running your project right away)

    Obviously Oculus still needs to work out some kinks because you don't get tear-free experience every time, but when it does work, it is really quite amazing.
  • CurtisCurtis Posts: 92
    Hiro Protagonist
    ccs wrote:
    I have been able to get DX11 to work with 0.4.0, and I'm happy to report lag is completely gone! Tracking is perfect now with my DX11 Unity project.

    Here is the formula I have found that works:

    1. IMPORTANT! turn vsync off in Unity quality settings - direct rift mode will take of this for you - if you have it on it will cap you at 60fps, not 75fps and give you terrible results (edit: for me the project actually crashes on start if vsync was on in quality settings)
    2. on the OVRCameraController, uncheck the Time Warp button - i found it sometimes causes juddering and the tracking seems way better with if off!
    3. set Rift display mode to direct HMD access in the Oculus configuration tool
    4. build & run your project (immediately exit your project when it starts)
    5. make sure the oculus configuration tool is closed (camera light should be off)
    6. go to your project folder and run the DirectToRift.exe for your project
    7. if it crashes - just run it again - it should start on 2nd try
    8. if you notice screen tearing or juddering, make sure to exit Unity before running your project
    9. if you still notice screen tearing, in the oculus configuration tool, select Tools->Advanced->Restart Service...
    10. if you still notice screen tearing, reboot your computer - don't open unity or configuration tool - just try running your project right away)

    Obviously Oculus still needs to work out some kinks because you don't get tear-free experience every time, but when it does work, it is really quite amazing.


    Ah, ok I got it working now, thanks for the tips! Head tracking is still pretty weird in the editor, but seems to work just fine when I build. I haven't tested it with any heavy duty scenes yet, but it seems pretty good!
  • spyrospyro Posts: 344
    Art3mis
    Seems they didn't make too much progress. Unity demos have generally more lag then UE4 demos, it's really perceivable. Just compare - say - Oculus Tuscany (add 'force-d3d11' to avoid tearing) with UE4 Coaster or Valerie Controls / Mobile Temple. Must be more than 50 ms difference or so.

    spyro
  • CubicleNinjasCubicleNinjas Posts: 202
    Art3mis
    ccs wrote:
    I have been able to get DX11 to work with 0.4.0, and I'm happy to report lag is completely gone! Tracking is perfect now with my DX11 Unity project.

    Here is the formula I have found that works:

    1. IMPORTANT! turn vsync off in Unity quality settings - direct rift mode will take of this for you - if you have it on it will cap you at 60fps, not 75fps and give you terrible results (edit: for me the project actually crashes on start if vsync was on in quality settings)
    2. on the OVRCameraController, uncheck the Time Warp button - i found it sometimes causes juddering and the tracking seems way better with if off!
    3. set Rift display mode to direct HMD access in the Oculus configuration tool
    4. build & run your project (immediately exit your project when it starts)
    5. make sure the oculus configuration tool is closed (camera light should be off)
    6. go to your project folder and run the DirectToRift.exe for your project
    7. if it crashes - just run it again - it should start on 2nd try
    8. if you notice screen tearing or juddering, make sure to exit Unity before running your project
    9. if you still notice screen tearing, in the oculus configuration tool, select Tools->Advanced->Restart Service...
    10. if you still notice screen tearing, reboot your computer - don't open unity or configuration tool - just try running your project right away)

    Obviously Oculus still needs to work out some kinks because you don't get tear-free experience every time, but when it does work, it is really quite amazing.

    Wish I'd seen this a week ago! Came to the exact same conclusion independently after a bunch of testing. No VSync. No Time Warp. I kill prediction too.
Sign In or Register to comment.