Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice
  2. Ever participated in one our Game Jams? Want pointers on your project? Our Evangelists will be available on Friday to give feedback. Come share your games with us!
    Dismiss Notice

Profiler GFx.WaitForPresent and EditorLoop too high with Vsync off

Discussion in 'Editor & General Support' started by cmorait, Jan 29, 2019.

  1. cmorait

    cmorait

    Joined:
    Nov 22, 2017
    Posts:
    58
    I have turned off Vsync and I see again those values too high and as a result, I drop under 30 frames.

    Why Editor Loop is so high?



     
    siddharth3322 likes this.
  2. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    627
    Profiling the playmode player running in the editor is not recommended as it will give you skewered data since it's all running in the same tread (i.e. you game's main thread and the editor). We try to reduce the effect as much as possible and as a result, do not collect more detailed data on what is happening in the editor, unless you turn Profile Editor on too.

    As for GFX.WaitForPresent, here is an excerpt of some upcoming change to the documentation around this often confusing topic:
    • WaitForTargetFPS: Time spent waiting for the targeted FPS specified by Application.targetFrameRate. The Editor doesn’t VSync on the GPU and instead also uses WaitForTargetFPS to simulate the delay for VSync.

    • Gfx.ProcessCommands: This sample on the render thread encompasses all processing of the Rendering commands on the render thread. Some of that time might be spend waiting for VSync or new commands from the main thread, which can be seen from it’s child sample Gfx.WaitForPresent.

    • Gfx.WaitForCommands: This sample indicates that the render thread is ready for new commands and might indicate a bottle neck on the main thread.

    • Gfx.PresentFrame: This render thread sample is time spend waiting for the GPU to render and present the frame, which might include waiting for VSync.

    • Gfx.WaitForPresent: When the main thread is ready to start rendering the next frame, but the render thread has not finished waiting on the GPU to Present the frame. This might indicate that your game is GPU bound. Look at the Timeline view to see if the render thread is simultaneously spending time in Gfx.PresentFrame. If the render thread is still spending time in Camera.Render, your game is CPU bound and e.g. spending to much time sending draw calls/textures to the GPU.
    As you can see, seeing that sample does not necessarily mean that this has anything todo with VSync. You might just be trying to draw too much.
     
  3. roberto_sc

    roberto_sc

    Joined:
    Dec 13, 2010
    Posts:
    139
    Was there ever an update to the documentation?
     
  4. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    627
    Hi @roberto_sc, thanks for pushing us on it. The update should have happened already but there where a couple of hold-ups. The focus on it has increased this week though so I hope we'll get this in soon.
     
  5. MaxXR

    MaxXR

    Joined:
    Jun 18, 2017
    Posts:
    67
    Thanks Martin
    Where/how can one learn how to optimise this (sorry if noob question I am learning) because am trying to create a 3d EQ visualiser (see video below) but it's performance sucks so trying to figure out what parts I can fix, perhaps with ECS?

    If you have any tips, pointers, advice, recommendations, or links for what I need to learn it would be much appreciated. Thanks

     
  6. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    627
    Hi @MaxXR

    You should make a build player and attach the profiler to that instead of profiling the Editor. Most of the time seems to be spend drawing the editor

    also, maybe you should check out https://unity.com/visual-effect-graph for that EQ visualizer.
     
  7. lama89625

    lama89625

    Joined:
    Feb 14, 2019
    Posts:
    12
    Hello, Martin! Haven't found anything about this in the docs. I guess it's not out there yet. (update: nevermind, found it)
    I've been trying to learn more about how things work to better analize the performance of my game.

    Is my understanding correct that Unity doesn't actually start doing any of the rendering related CPU work for the next frame (culling, batching, forming draw calls etc.) before the GPU is done drawing the previous frame?
    In the profiler it shows that the main thread gets blocked in Gfx.WaitForPresent after doing physics, behaviour updates and other things but before Camera.Render.

    So am I wrong or does it mean that GPU and CPU's rendering related work are never parallel?
    Does it also means that the time spent inside Gfx.PresentFrame is basically the GPU time for that frame?
     

    Attached Files:

    Last edited: Sep 20, 2019
  8. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    627
    Yes, that change just very recently landed in the docs.


    yes that is correct.

    I'm not too firm on Rendering, Multithreaded Renderin, and GPU flows or upcoming changes with SRPs and DOTS in this regard but yes, the current situation is pretty much that. Unity does not get started on uploading new rendering commands, and doesn't reuse RenderTextures or buffers currently being displayed, before that frame is done displaying.
     
  9. roberto_sc

    roberto_sc

    Joined:
    Dec 13, 2010
    Posts:
    139
  10. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    627
    @roberto_sc that may be because you looked in the Scripting API instead of the Manual? They are sadly not interconnected as well as they maybe could be with their own search queries and such...
    Anyways: here's the manual page that contains common samples like those VSync related Gfx.WaitForPresent and friends: https://docs.unity3d.com/Manual/ProfilerCPU.html
    The section on Common Samples is a bit down the page. The Overview page has also been overhauled.
     
    roberto_sc likes this.
  11. lama89625

    lama89625

    Joined:
    Feb 14, 2019
    Posts:
    12
    I understand it better know, thanks!
     
  12. Digika

    Digika

    Joined:
    Jan 7, 2018
    Posts:
    24
    2019.2.0, standalone
    My frametime is stable 12.5ms, vsync disabled, fullscreen, framerate capped to 80 via Riva. I'm getting weird jitter/stutter which should not be there. Here is the profile snapshot:

    https://imgur.com/a/DVPiIqy

    Is it normal GFX.ProcessCommands and GFX.PresentFrame to be split between frames?
     
  13. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    627
    Yes. the Render thread follows the GPU frame which is somewhat independend from the main CPU frame. I say somewhat because there are sycn points, which is what you're seeing with the WaitForTargetFPS sample underneath the Gfx.WaitForPresentOnGfxThread sample.

    I'm assuming (after quick googling) that Riva refers to an overclocking tool? What do you mean by
    ?

    While I can see that your Rendering time is a little unstable over the frames, I can't tell you why from a screenshot of just one frame. There might be different amounts of workload being passed to the GPU from frame to frame, the GPU might have to deal with work from other applications running on the same machine etc...

    Also, you might want to update to 2019.2.13f1 or newer once they're out because this issue just got fixed https://issuetracker.unity3d.com/is...er-profiler-graph-if-a-sample-is-not-selected
    Which meant that that Semaphore.WaitForSignal time in your screenshot was not attributed to the VSync Category so it'd be missing from the CPU Usage chart (or rather hidden in "Other" which was further hidden by this bug).

    With that fix, the CPU Usage Chart should give you a better impression of overall frame time stability (if you enabled displaying of all categories)
     
  14. Digika

    Digika

    Joined:
    Jan 7, 2018
    Posts:
    24
    Correct. I use RivaTuner to limit framerate instead of built-in `targetFramerate`. The former hooks up via d3d11 renderer and does very accurate job.

    Well, my frametime graph is flat as a floor and GPU load always around 40%. If GPU would be busy elsewhere I'd probably see it in RivaTuner general GPU HW statistics via spikes.
    I doubt you will have time but if you are willing to take a look: www26.zippyshare.com/v/xCopV1IR/file.html (raw profile binary, only lats few frames relevant, big spikes is me alt+tab'ing)
    This issue really boggles my mind because all conditions are basically perfect yet I get this weird jitter that just nauseating.

    The standalone player build is 2019.2.0 Il2cpp and the profiler is from 2019.3.0.b

    What do you mean by "all categories"?
     
    Last edited: Nov 13, 2019
unityunity