Search Unity

  1. Engage, network and learn at Unite Austin 2017, Oct 3 - 5. Get your ticket today!
    Dismiss Notice
  2. Introducing the Unity Essentials Packs! Find out more.
    Dismiss Notice
  3. Check out all the fixes for 5.6 on the patch releases page.
    Dismiss Notice
  4. Unity 2017.1 is now released.
    Dismiss Notice
  5. Unity 2017.2 beta is now available for download.
    Dismiss Notice

Gfx.WaitForPresent

Discussion in 'Editor & General Support' started by jordi_boni, Nov 15, 2013.

  1. Rodolfo-Rubens

    Rodolfo-Rubens

    Joined:
    Nov 17, 2012
    Posts:
    1,016
    Have you tried to activate the GPU Usage to see if there is any extra info? Sometimes you can see the reason for the Gfx.WaitForPresent there..
     
  2. Nition

    Nition

    Joined:
    Jul 4, 2012
    Posts:
    704
    This has been said many times in this thread now but Gfx.WaitForPresent just means that the CPU is waiting for the GPU.

    Unless you have a very special case like Andy-Korth, you will be able to see it: In the profiler window click Add Profiler at the top left and add GPU. Check the GPU data and you should see where your time is going.
     
    Last edited: Feb 6, 2017
    Dave-Carlile likes this.
  3. Dave-Carlile

    Dave-Carlile

    Joined:
    Sep 16, 2012
    Posts:
    935
    One of the best explanations I've seen describing the relationship between the CPU and GPU is this series of blog posts by Shawn Hargreaves who was one of the Microsoft developers behind XNA: https://blogs.msdn.microsoft.com/shawnhar/2008/03/31/an-elf-in-a-box/

    It's worth a read and explains pretty well what's discussed in this thread. WaitForPresent is simply the CPU waiting for the GPU to complete processing before continuing on to the next frame.
     
  4. Nition

    Nition

    Joined:
    Jul 4, 2012
    Posts:
    704
    Great blog post! That covers it exactly.
     
  5. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    4,130
    The name is pretty self explanatory. The GPU is waiting for a present. Maybe some flowers, maybe clothes, a book? It differs a bit from brand to brand.
     
  6. Nition

    Nition

    Joined:
    Jul 4, 2012
    Posts:
    704
    This is true. There's actually a Magnetic Fields song about it.

    The graphics wait is long and boring
    The frame was very long ago
    It's full of opcodes, and strange mnemonics
    And things that only Intel knows

    But I
    I love it when you give me things
    And you
    You oughta give me a "Present" string
     
    Invertex, AcidArrow and Dave-Carlile like this.
  7. Rodolfo-Rubens

    Rodolfo-Rubens

    Joined:
    Nov 17, 2012
    Posts:
    1,016
    Lol, at first I thought you were talking about flowers as terrain details, clothes as clothing physics and book as a simple mesh renderer!
     
  8. GMT

    GMT

    Joined:
    Sep 18, 2014
    Posts:
    47
    It means the CPU has finished its work but the GPU hasn't and so the CPU is waiting for the GPU to finish before it continues. If you look at your GPU load you'll see it has a higher ms than the CPU.

    You can prove it to yourself if you use your GPU's control app that also has overclock/underclock settings; lower the GPU's clocks so it is less powerful, the waitforpresent gap in your CPU Usage profiler window will get bigger. Increase your GPU's clocks (overclock), the waitforpresent gap will get smaller (if the overclock is good).

    It's also very similar with VR headsets and the VR.WaitForGPU / OculusWaitForGPU.
     
  9. Devilzzz

    Devilzzz

    Joined:
    Feb 29, 2016
    Posts:
    3
    Gfx.WaitForPresent means you are not cpu bound. Its a good thing to see. It does not take any processing time on its own so it doesn't create performance spikes. If you see this then that means your scripts are fast enough, the rendering is taking that much; you should try to optimize the graphics.

    Its not always a problem if its there. I ran an almost empty build which can run on highest fps possible on my android device. On mobile devices running on fps greater than 60 is anyway useless so Gfx.WaitForPresent will take up the extra time and balance the fps around 60. In such a case you simply cannot remove it. It is very similar to WaitForTargetFPS sometimes. It is supposed to stay there to prevent you from melting down your hardware just coz of a buggy piece of code!
     
    _M_S_D_, r618 and Rodolfo-Rubens like this.
  10. awesomedata

    awesomedata

    Joined:
    Oct 8, 2014
    Posts:
    235
    Out of curiosity, what is the difference between the two exactly?

    I may just be dense, but the way you describe it sounds (to me) like it does pretty much exactly the same thing, so why doesn't WaitForTargetFPS take up the clock cycle on a pretty much empty scene instead? Is it just the way Unity handles a pretty much empty scene with barely any graphics? If so, why even have WaitForTargetFPS at all? After all, the latter would indicate you are not CPU-bound as well (and would also prevent you from melting your hardware too, right?) Or is the latter part there the difference (that is, one prevents hardware damage by giving the GPU or CPU something to do, while the other doesn't?)
     
  11. Vetlo

    Vetlo

    Joined:
    Feb 6, 2017
    Posts:
    2
    Unity 5.5.2 empty scene:
    Magic_of_Unity_2.jpg
    2d physics in 3D scene ? Gfx.WaitForPresent no lag in pc build, lag in mobile device
     
  12. Vetlo

    Vetlo

    Joined:
    Feb 6, 2017
    Posts:
    2
    I've found a solution to the problem, I switched Unity to run in compatibility mode with Windows XP and it completely eliminated the GFX.WaitForPreset call without any negative impacts on the project.
     
  13. Rodolfo-Rubens

    Rodolfo-Rubens

    Joined:
    Nov 17, 2012
    Posts:
    1,016
    Even though the mistery was already solved there are still some odd things happening...
     
    Last edited: Mar 1, 2017
  14. HonoraryBob

    HonoraryBob

    Joined:
    May 26, 2011
    Posts:
    818
    I started noticing this problem today, along with the similar "WaitForTargetFPS", which I hadn't seen before (which is odd, because I haven't added anything drastic to my project recently). I think it might be part of the set of problems which began after Windows installed an update while I was asleep and unable to stop it, after which many basic functions became abysmally slow - e.g. Gimp is now almost unusable because the mere act of laying in a small brushstroke can take several seconds; and using Windows Explorer to look at folder contents takes an absurd length of time even when the folder only has one or two files; and it likewise now takes awhile to switch between tabs in my browser.
     
  15. HonoraryBob

    HonoraryBob

    Joined:
    May 26, 2011
    Posts:
    818
    Doesn't anyone know what to do about these problems? And more generally, how do we deal with the seemingly random fluctuations in performance? I'm having a dickens of a time figuring out why my current project is so slow, because nothing makes any sense. At one point I stripped out at least half the geometry, only to find that this only increased the framerate by about 10 - 15 fps, which would mean that the single remaining hallway was supposedly reducing the framerate by over 50 fps despite having very little in it? Worse, I couldn't replicate this result because oduring the next test I was now getting a slow framerate even while standing at the edge of the geometry look out into nothing, which makes even less sense.
     
  16. Skolstvo

    Skolstvo

    Joined:
    Dec 21, 2015
    Posts:
    107
    You can lead a horse to water.
     
    GMT likes this.
  17. HonoraryBob

    HonoraryBob

    Joined:
    May 26, 2011
    Posts:
    818
    Meaning what?
     
  18. SpiriTx

    SpiriTx

    Graphics QA Unity Technologies

    Joined:
    Apr 12, 2012
    Posts:
    251
    Gfx.WaitForPresent simply means that your CPU is waiting while your GPU finishes rendering current frame, so it can continue.
    Add GPU profiler (top left corner) to check on what is your GPU itself is doing. Often it will be either too much geometry being rendered or transparent objects. Also V-Sync enabled will force your CPU to wait to have smooth 30 or 60 fps.
     
  19. sholom1

    sholom1

    Joined:
    Oct 7, 2015
    Posts:
    1
    @SpiriTx how can i fix this though?
     
  20. SpiriTx

    SpiriTx

    Graphics QA Unity Technologies

    Joined:
    Apr 12, 2012
    Posts:
    251
    Turn on GPU profiler and check what is actually taking the most of GPU time, when based on that you can optimize.

    If you post a screenshot of the profiler here, we will be able to give you some more precise ideas.
    Usually biggest offenders are realtime lights, transparency or too much geometry.
     
  21. Rob21894

    Rob21894

    Joined:
    Nov 21, 2013
    Posts:
    278
    https://gyazo.com/69feb2a8da52425babd7a21771787d5f

    Would you be able to tell me why this unaccounted time between: WaitForTargetFPS and GPUprofiler.Endqueries is happening?

    Also why I get a 25-30 fps loss when using the unity profiler?
     
  22. SpiriTx

    SpiriTx

    Graphics QA Unity Technologies

    Joined:
    Apr 12, 2012
    Posts:
    251
    Unaccounted time means that there are no profile markers set in that code, so it doesn't show up in profiler. It's an unintended behaviour and if you have repro for it - please bug it, so we can take a look at it and fix it.

    As for the fps loss it's because the profiler itself is also using up your resources.
     
  23. Mafutta

    Mafutta

    Joined:
    Sep 30, 2014
    Posts:
    24
    I changed my default Color Space to Linear, edited the Quality Settings to Good. Then Edited Good Mode's Shadow Quality to Low (Mixed Hard and Soft Shadows),Changed 'Every V Blank' to Don't Sync, then also removed DX9 support for Windows Builds, Only profiled externally and result is at least twice my previous speed and very smooth . see https://docs.unity3d.com/Manual/class-QualitySettings.html You can also try 'every 2nd Vsync' count.
     
    Last edited: Mar 23, 2017
  24. Zoidy

    Zoidy

    Joined:
    Jul 18, 2014
    Posts:
    4
    I found a solution. Asus Sonic Studio was the culprit, as described -Here-
     
  25. ShadowK

    ShadowK

    Joined:
    Sep 5, 2013
    Posts:
    4,438
    @SpiriTx

    I've not found a resolution to this, getting 13+ms spikes in an empty scene with no V-sync (nothing but a main camera).. There is zero a chance a GTX 1080 is waiting for the previous frame to render with an empty scene, it jolts every time it happens (with profiler up or closed down)..

    Fortunatley if I build the solution (for win X64) and do a remote profile, it works absolutely fine..

    It's definatley the editor, but that's been jumpy and laggy ever since I've used Unity (that was about four(ish) years ago) I reported it as a bug in 4.2 and it got lost into the ether.
     
  26. SunnyChow

    SunnyChow

    Joined:
    Jun 6, 2013
    Posts:
    270
    gfx_wait.jpg

    i get a problem like this. I have tried reducing drawcall ,by removing objects and packing ui texture. But it doesn't help much. Do you have any idea for me?
     
  27. Nition

    Nition

    Joined:
    Jul 4, 2012
    Posts:
    704
    Click Add Profiler at the top left there and add the GPU profiler. Then you should be able to see a better idea of what's causing the spikes.
     
  28. mangax

    mangax

    Joined:
    Jul 17, 2013
    Posts:
    196
    check my post on the sync issue :
    https://forum.unity3d.com/threads/gfx-waitforpresent.211166/page-5#post-2607122

    you need to turn of g-sync from also from monitor (if it has any sync tech) + also from your graphic card settings..
    even if you disable it in unity.. it has no effect on some hardware..
     
  29. SunnyChow

    SunnyChow

    Joined:
    Jun 6, 2013
    Posts:
    270
    no it happens in iPad, it doesn't return the GPU data
     
  30. Nition

    Nition

    Joined:
    Jul 4, 2012
    Posts:
    704
    Ah sorry, I haven't tried to profile with iOS before. I see the manual says to "use XCode’s GPU Frame Debugger UI" instead.
     
  31. ShadowK

    ShadowK

    Joined:
    Sep 5, 2013
    Posts:
    4,438
    Yep, tried it and it doesn't make a difference.. As said it seems editor only to me anyway, so I wouldn't of expected that's the issue in the first place.
     
  32. RafaelF82

    RafaelF82

    Joined:
    Oct 28, 2013
    Posts:
    43
    Kinda necroing the thread but I'm having a hard time with it.

    I have an Android Samsung S3 mini, trying to debug performance on it, make the build, attach debugger, and I have Gfx.WaitForPresent getting 50% of CPU time, the game is running at 10 fps, the GPU profiler says "GPU profiling is not supported by the graphics card driver. Please update to a newer version if available.".

    I accept any suggestions that can help me find the issue.



    Edit : On PC Profiler.FinalizeAndSendFrame eats 75% of cpu time, not clear what it is either...
     
  33. Invertex

    Invertex

    Joined:
    Nov 7, 2013
    Posts:
    525
    I would suggest ignoring stuff related to Profiler and Gfx.Wait, and look for other stuff that is highest in processing time and focus your optimizations there. Profiling has its own performance incursions.
     
  34. RafaelF82

    RafaelF82

    Joined:
    Oct 28, 2013
    Posts:
    43
    Yeah this is what I usually do, what is making me curious and makes me question this stuff though is that if gfx.wait is 50% of the cpu time when profiling, why does running the final game without profiling or debugging doesn't make the game run 50% faster.

    Also, it's hard to profile and find bottlenecks when the profiler gives you something useless at 50% and everything else at 1% or .5%.

    And as I said, now on unity 2017 on desktop all I get is Profiler.FinalizeAndSendFrame at 75% cpu time, no indication what it is or how to turn off either... Vsync off, no targetframerate, and this is all I see...

    The game runs flawlessly on the S7 device, I'm just trying to find what I have to turn off to make it run on S3, it's nearly impossible with the current profiler.
     
  35. Simunek

    Simunek

    Joined:
    Jul 15, 2016
    Posts:
    3
    Hi,
    I had this problem for so... soooo long (months) and I was not able to find a solution. In the end I found out that I had so many trees on my terrain. Fix is simple: replace more distant trees with bilboards.

    I hope it will help somebody, have a nice day.
     
  36. Er_ellison

    Er_ellison

    Joined:
    Jul 8, 2017
    Posts:
    2
    same issue annoying me from keep going on
     
  37. rsodre

    rsodre

    Joined:
    May 9, 2012
    Posts:
    110
    I was also in denial, but found the truth like many others here.
    Hear the wise words, GPU is taking too long to process.
    In my case, building for Android, my game was unplayable in a S3.
    I had the Post-processing stack v1 with "only" vignette.
    Removing it solved everything.
     
  38. Er_ellison

    Er_ellison

    Joined:
    Jul 8, 2017
    Posts:
    2
    in my case , even disabling Post processing effects does not affects on that !
     
  39. PseudoDev

    PseudoDev

    Joined:
    Dec 25, 2012
    Posts:
    3
    Edit: It looks like Nvidia driver 384.94 gets rid of the spikes and low fps. I selected this driver because it is the minimum Battlefield 1 requires. Who knows what changed?

    I have constant regular Profiler spikes from Gfx.WaitForPresent ever since I updated my GTX 1060 to the latest driver. I did not have this problem before on an older driver. I also have the same warning message of, "GPU profiling is not support by the graphics driver. Please update to a newer version if available." when GPU Usage is added to the Profiler. Though, I should mention that regardless of the error the Profiler still shows purple data within GPU Usage while in Play Mode and despite the yellow warning symbol.

    Unity 2017.1.0f3
    Vsync disabled in both Unity's Quality settings and Nvidia's Control Panel.
    378.78 = OK.
    384.94 = OK.
    385.41 = Gfx.WaitForPresent problem.
    385.69 = "

    Spiky (385.41, 385.69):
    [​IMG]

    Normal (384.94):
    [​IMG]
     
    Last edited: Sep 22, 2017 at 9:40 PM