Search Unity

  1. Improved Prefab workflow (includes Nested Prefabs!), 2D isometric Tilemap and more! Get the 2018.3 Beta now.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. Let us know a bit about your interests, and if you'd like to become more directly involved. Take our survey!
    Dismiss Notice
  4. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice
  5. Want to see the most recent patch releases? Take a peek at the patch release page.
    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,057
    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:
    729
    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:
    959
    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:
    729
    Great blog post! That covers it exactly.
     
  5. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    4,944
    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:
    729
    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
     
  7. Rodolfo-Rubens

    Rodolfo-Rubens

    Joined:
    Nov 17, 2012
    Posts:
    1,057
    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:
    48
    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:
    593
    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,057
    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:
    1,001
    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:
    1,001
    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:
    1,001
    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:
    309
    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. Deleted User

    Deleted User

    Guest

    @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:
    322
    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:
    729
    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:
    235
    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:
    322
    no it happens in iPad, it doesn't return the GPU data
     
  30. Nition

    Nition

    Joined:
    Jul 4, 2012
    Posts:
    729
    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. Deleted User

    Deleted User

    Guest

    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:
    92
    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:
    782
    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:
    92
    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:
    5
    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:
    10
    same issue annoying me from keep going on
     
  37. rsodre

    rsodre

    Joined:
    May 9, 2012
    Posts:
    117
    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:
    10
    in my case , even disabling Post processing effects does not affects on that !
     
  39. Hamburgert

    Hamburgert

    Joined:
    Feb 14, 2015
    Posts:
    3
    Necro justification: I found the source of my gfx.WaitForPresent and it wasn't mentioned (afaik).

    I came here looking for solutions to the same problem; When playing my rather simple game in the editor, I was experiencing weird lag spikes. The profiler showed gfx.WaitForPresent was around 30-65ms in random peaks.
    Reading this thread led me to understand that the GPU is doing something heavy/slow, so I checked my physics settings.

    After fiddling around with the settings, I found a solution that worked for me: Disabled the "Enable Adaptive Force"

    I had enabled it previously while debugging weird physics behaviour, and just left it on.
    Just for the luls, I even tried cranking up the default solver iterations to unreasonably high values, without seeing the lagspikes return.
    Now I can spawn in many of my physics based contraptions, and I'm still seeing a solid 60+ fps!
     
    Dave-Carlile likes this.
  40. awesomedata

    awesomedata

    Joined:
    Oct 8, 2014
    Posts:
    593
    I suspected something in the physics was causing this -- the name is apparently a misnomer if this is the case.

    Thanks for posting that.

    I'm not sure this was my own problem, but I wonder if this fix works for anyone else having editor lag spikes. -- I just had an empty scene with a default cube in it while in the editor when I got this issue. It seemed to go away when I added more visually intense stuff, but that was only an illusion -- when I zoomed way into the profiler it was still there.

    Granted, I was on a laptop at the time, but thinking on it more, it was likely a physics issue since the visuals seemed to have no problem at all. After all -- the default cube also has a collider on it.
     
  41. SilverStorm

    SilverStorm

    Joined:
    Aug 25, 2011
    Posts:
    492
    It's not Physics related I don't think. I reported a bug report. I have two images to help anyone. My one only occurs in maximized play mode and the fps is thousands fast when not in maximized. When the profiler is open Gfx.waitforpresent takes up the fps but when I click Deep profile the GUI is what eats it which is weird take a look see.....

    If you experience the same thing I am then you have the same issue.

    *Update it seems the deep profile only caused that issue in that one instance, which means the gfx.waitforpresent is back....
     

    Attached Files:

  42. Afropenguinn

    Afropenguinn

    Joined:
    May 15, 2013
    Posts:
    245
    A recent culprit I found was the Geforce Experience overlay. I tried toggling it on and off, and got a significant increase in stability when it was off. With it on I would get a pretty steady stutter every second or so.
     
    Eremes likes this.
  43. Peter77

    Peter77

    Joined:
    Jun 12, 2013
    Posts:
    2,633
    According to your second screenshot, WaitForPresent takes 3.3ms and the game runs with 240 fps. Why do you think there is a problem?
     
  44. Daimer

    Daimer

    Joined:
    Mar 9, 2014
    Posts:
    4
    I updated my nvidia graphic drivers. That solved issue.
     
  45. SilverStorm

    SilverStorm

    Joined:
    Aug 25, 2011
    Posts:
    492
    Because it usually runs at thousands of fps.

    This is so weird but after opening an older project and running an API updator the bug entirely disappeared. My infected projects now run perfectly without any issues when I go fullscreen no more fps drop! Perhaps the API updator had some leak or something that caused the issue in the first place in the editor and by exe builds, or who knows. For now the bug has gone so if it returns for me I will try that one weird trick to six pack abs again!
     
  46. citizen_12

    citizen_12

    Joined:
    Jun 21, 2013
    Posts:
    31
    Thanks for this tip! I had this issue and turned off the overlay junk. Now everything is running smoothly.
     
  47. Nition

    Nition

    Joined:
    Jul 4, 2012
    Posts:
    729
    In the top left click Add Profiler and add GPU. If you've read this thread you've probably seen this statement like a billion times already but: Gfx.waitforpresent just means the CPU is waiting on the GPU, so it's the GPU performance you really need to check to find out what's making it slow.
     
  48. SilverStorm

    SilverStorm

    Joined:
    Aug 25, 2011
    Posts:
    492
    Hi there, yes I have seen people describe that this is what it means but the lack of consensus worries me.
    I know it is related to the GPU and I know that it is Unity that causes this problem because it wasn't always this way.

    Finally however I did find a temporarily solution which involves using another 3d app like Zbrush and modeling in it for 5 minutes will most of the time fix this bug.

    So as long as I build my projects when the bug is not active all is then well and now that I have a fix it's easy peasy at least for me anyway.
     
  49. Nition

    Nition

    Joined:
    Jul 4, 2012
    Posts:
    729
    You have turned on the GPU profiler and checked out what's showing up there though? I only ask because you didn't have it showing in your screenshot.
     
  50. SilverStorm

    SilverStorm

    Joined:
    Aug 25, 2011
    Posts:
    492
    Here are screenshots for whats going on in the CPU and GPU side.
    This scene only has some text in it. [It doesn't matter what's in the scene anyway in my tests]
    Having the profiler open doubles my fps count. Without the profiler open remember my fps is 100 on an empty full screen scene. The bug only occurs when the editor window (not game window) is maximized - near x and minimize areas of the top right of standard programs.

    Umaximizing the window (even though it only becomes 1% smaller this way) gives me 2000 fps.
    This time opening up Zbrush and minimizing it fixes the bug instantly.
     

    Attached Files:

    • CPU.png
      CPU.png
      File size:
      90.4 KB
      Views:
      150
    • GPU.png
      GPU.png
      File size:
      71.9 KB
      Views:
      133
    Last edited: Dec 19, 2017