Search Unity

  1. We've closed the job boards. If you're looking for work, or looking to hire check out Unity Connect. You can see more information here.
    Dismiss Notice
  2. We're running great holiday deals on subscriptions, swag and Asset Store packages! Take a peek at this blog for more information!
    Dismiss Notice
  3. Check out our Unite Austin 2017 YouTube playlist to catch up on what you missed. More videos coming soon.
    Dismiss Notice
  4. Unity 2017.2 is now released.
    Dismiss Notice
  5. The Unity Gear Store is here to help you look great at your next meetup, user group or conference. With all new Unity apparel, stickers and more!
    Dismiss Notice
  6. Introducing the Unity Essentials Packs! Find out more.
    Dismiss Notice
  7. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice
  8. Unity 2017.3 beta is now available for download.
    Dismiss Notice

Gfx.WaitForPresent

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

  1. Nition

    Nition

    Joined:
    Jul 4, 2012
    Posts:
    706
    After years of wading through people with GPU problems masquerading as CPU problems, it really does look like you've got the holy grail; a true case where something legitimately weird is happening. I'm afraid I don't have a good guess as to what's going on there though Andy.Korth. You are the chosen one.

    One idea: According to the profiler you don't have anything opaque being rendered. Is there be anything opaque in your scene? If so, it certainly looks like Opaque is on, but maybe try clicking the little green button next to Opaque under GPU Usage and clicking it a second time to turn it off and on again, just in case.
     
    Last edited: Jan 22, 2016
  2. Andy-Korth

    Andy-Korth

    Joined:
    Jun 7, 2013
    Posts:
    131
    I always knew I was special! It's wonderful to feel validated :D

    There is almost nothing opaque in the scene. That's correct, and it shows that way in the frame debugger as well. It's mostly a 2D game and all the sprites are transparent (with soft alpha edges, not cutout).

    Today in the editor I profiled it again after poking around more and seeing if I can adjust my scenes for better batching by being mindful of what's in the frame debugger. Today I profiled and got something distinctly different:

    [​IMG]

    There are pretty sizable (38.6ms in the selection) GPU spikes that are marked as "Other". They definitely weren't in yesterday's graphs. However, they aren't inducing a CPU wait- CPU frames are completing in something like 2ms. So I think there's something different about the reporting. It also seems to maintain a good framerate in the editor.

    Note that the "stats" block (lower left) reports 274 fps at 3.6 ms a frame in the "graphics" section. That's probably based on CPU time for the frame since the GPU section says 25 ms per frame.

    Yesterday's desktop build performs the same way it did yesterday. So it's not like a solar flare caused yesterday's issue.

    However, when attached to a standalone build of the above scene, the profiler reports this:
    [​IMG]

    As a side note, the camera is no longer moving and that change that occurred halfway through is inexplicable. I'd write the whole profiler result off as total nonsense except the framerate does stutter without the profiler attached, like you'd expect from the CPU graph. Maybe it's just reporting different things. The 13 draw calls and 425 verts is not correct for the scene. But the numbers a bit to the left:

    [​IMG]

    do all look correct. 10k verts, <100 draw calls is correct. The scene isn't that complex.

    Vsync count is set to don't sync. Thanks for reading!
     
  3. Andy-Korth

    Andy-Korth

    Joined:
    Jun 7, 2013
    Posts:
    131
    Unity 5.3.3f1 came out today and it included a line item:
    • Graphics: Reduced framerate spikes where culling system could sometimes stall for several ms while waiting for jobs.

    I thought: Surely this must be the issue I'm having! Yay! So I made new builds and tried it out. The problem did not get better. We've got the same apparent issue, but the profiler reports it differently.

    [​IMG]

    There's still a high 50 ms "Gfx.WaitForPresent" that occurs. it's much longer than a vsync would take. But now there's a comparably long BatchRenderer.Flush. There's 44 calls but a single call accounts for the vast majority of the time.

    When it's not on one of the spikes, the whole camera.render time is about 1.57 ms.

    So I traced it with GLProfiler. Some frames are fine: (note times are in microseconds not miliseconds)
    [​IMG]
    But other times are much worse. Here's a 60 ms glFinishFence + CGLFlushDrawable:
    [​IMG]
    The GLProfiler's stats view isn't too useful because it averages the call costs between the horrific frames and the normal ones.
     
    leni8ec likes this.
  4. Wolfgame

    Wolfgame

    Joined:
    Feb 7, 2014
    Posts:
    10
    Gfx.WaitForPresent is eating 55-60% of our CPU cycles in our project. We have a very small scene with a small number of draw calls and assets. Our scene is more or less late PS2-era quality art. We should be getting a few hundred if not 1000+ FPS. We're getting a mere 30~

     
  5. Nition

    Nition

    Joined:
    Jul 4, 2012
    Posts:
    706
    Could you post a screenshot of your profiler with both the CPU and GPU stats showing (might need to Add Profiler -> GPU)?
     
  6. kuchaku

    kuchaku

    Joined:
    Oct 14, 2014
    Posts:
    37
    This was happening in my project when I updated to windows 10. I was getting 1000 + fps in 8.1 and 200 fps in 10.

    I looked into my (Nvidia) video card, and it was set to 'power saving mode.' Once I set it to 'prefer performance' the problem disappeared.

    So my project (and a few other games) were not getting the full power of the video card. It's probably one of many reasons why this might occur. Basically the power saving mode was 'throttling' the video card, GFX.waitforpresent was the CPU waiting during the power saving throttle.
     
  7. superpig

    superpig

    Insert bacon, receive bugfix Unity Technologies

    Joined:
    Jan 16, 2011
    Posts:
    3,808
    Yes, there is a known issue at the moment with Nvidia Optimus-enabled systems. Nvidia will be fixing the issue in an upcoming driver update, and the very latest Unity patch release also contains a workaround for the problem.
     
  8. Andy-Korth

    Andy-Korth

    Joined:
    Jun 7, 2013
    Posts:
    131
    I spoke with a few Unity people here at GDC about my issue, and they said there's an extremely similar issue with the automatic graphics switching on many different MacBook Pros, and that is what is causing my issue. There's a big delay when switching from integrated graphics to the discrete graphics. The bug is that this occurs even if your computer is set to not switch between cards (System Preferences > Energy Saver > Graphics). It also occurs even if your app has properly set NSSupportsAutomaticGraphicsSwitching: (see https://developer.apple.com/library/mac/qa/qa1734/_index.html )

    They indicated that Unity has a radar bug filed with Apple for this issue. Maybe @superpig knows more about the macbook pro issue specifically?
     
  9. superpig

    superpig

    Insert bacon, receive bugfix Unity Technologies

    Joined:
    Jan 16, 2011
    Posts:
    3,808
    Sorry, I don't - I could ask people but it sounds like you already spoke to the people I would ask :)
     
  10. KRGraphics

    KRGraphics

    Joined:
    Jan 5, 2010
    Posts:
    3,682
    I'm getting this same issue with Gfx.Waitforpresent in my game and the scene is very small (a dojo) with two characters and I'm getting this silly issue. I should take a look at my power settings to see if that changes anything
     
  11. TTTTTa

    TTTTTa

    Joined:
    Mar 3, 2015
    Posts:
    1,347
    I am also having this issue. Here is my take on this:
    If you have pratically nothing in your scene but a few things, wouldnt't you expect the hold up would be GFX.Waitforpresent?
    The CPU has nothing to do, so the GFX.WaitForpresent takes up the most usage in the profiler.

    IF you have a large scene, the GFX.waitforpresent has less activity in the profiler because you have many other things going on CPU wise which take up a larger percentange of the CPU.

    TO prove this do the following:
    1. Create a scene which you get this GFX.WaitForpresent
    2. Now create a cube and attach a MonoBehaviour with just an Update function to rotate the cube
    3. Duplicate the cube a few hundred times

    Voila, the GFX.waitforpresent no longer shows up in the profieler as the highest used process because now you actually have something for the CPU to do (rotating the cubes)


    cubes.jpg
     
  12. CaseyLee

    CaseyLee

    Joined:
    Jan 17, 2013
    Posts:
    32
    It doesn't actually sound like you have the same issue. We are looking at the 'time.ms' to gauge how it is lagging the FPS, not simply the percentage of frame time it spent on the 'gfx.waitforpresent'
     
  13. QFSW

    QFSW

    Joined:
    Mar 24, 2015
    Posts:
    1,713
    In my case its taking 500ms when my game is supposed to be paused, but on ever other situation and every other computer its just fine
    im so confused
     
  14. QFSW

    QFSW

    Joined:
    Mar 24, 2015
    Posts:
    1,713
  15. ThePilgrim

    ThePilgrim

    Joined:
    Apr 25, 2013
    Posts:
    2
    This fixed my issue. To clarify, I went to NVIDIA Control panel -> Manage 3D Settings -> Power management mode. I changed it from "Adaptive" to "Prefer maximum performance". Once I restarted Unity, the problem was gone.

    I'm running Unity 5.3.3f1 On Windows 10 with a GeForce GTX 680.
     
  16. Andy-Korth

    Andy-Korth

    Joined:
    Jun 7, 2013
    Posts:
    131
  17. Andy-Korth

    Andy-Korth

    Joined:
    Jun 7, 2013
    Posts:
    131
    This is a pretty interesting one! Your GFXWaitForPresents look to be well in excess of a 16ms vsync. (Posting more of the trace might have been helpful).

    What renderer are you using? Does the issue persist if you select other renderers? (Particularly swapping between DirectX and OpenGL if you're on windows, like this:)
    [​IMG]

    Are you on Mac or Windows? Does the issue occur on other computers? Does the issue occur if you create a standalone build of that scene and connect the profiler remotely? If the issue does occur, does the profiler report it differently? (It does for me) The final thing would be to run a trace outside of Unity, but the other information would be useful first.
     
  18. QFSW

    QFSW

    Joined:
    Mar 24, 2015
    Posts:
    1,713
    It occurs on my macbook but doesnt occur on my Windows 10 PC
    I'll have to do some more digging to get back on you whether or not a blank scene does it, the thing is it only does it whilst im on the pause menu, during actual gameplay its fine
     
  19. mangax

    mangax

    Joined:
    Jul 17, 2013
    Posts:
    212
    Fixed My Issue!!!

    before 2 days i bought a new screen with the new nvidia g-sync tech + new graphic card (gtx 980)..
    first few days no problems ... i realized later that g-sync wasn't turned on in graphic card settings!
    so i did the natural thing.. i turned it on :) ..

    then the Issue Appeared!! causing frame hiccups and huge fps drop!!!
    i immediately turned g-sync off! and the issue GONE!

    bear in mind i have v-sync disabled all time in unity quality settings..
    it looks that it have NO effect on the graphic card settings or monitor when g-sync is turned on. it was forced by hardware!

    Guys.. it's so clear for me that maybe one issue is related to graphic card and v-sync tech!
    make sure your graphic card don't run v-sync..(in case you don't want v-sync)

    in nvidia control panel you can disable it here:
    disableVsync.jpg

    also Unity devs.. pls take note.. am using latest nvidia driver on a new modern new graphic card. and your latest unity patch (in this post date) have this issue while g-sync on...
     
    Last edited: Jul 4, 2017
    Anlasa likes this.
  20. Rodolfo-Rubens

    Rodolfo-Rubens

    Joined:
    Nov 17, 2012
    Posts:
    1,027
    Last edited: May 8, 2016
  21. Rodolfo-Rubens

    Rodolfo-Rubens

    Joined:
    Nov 17, 2012
    Posts:
    1,027
    Guys, just one quick note, before assuming that the Gfx.WaitForPresent is taking your CPU time, add the GPU Usage profiler too, some of the time on the Gfx.WaitForPresent in the CPU usage profiler actually belongs on the GPU overview items, but since the same is disabled - if the CPU stall waiting for GPU to finish doing its part - all the time of the GPU will appear on the Gfx.WFP... At least that's what it seems like...
     
  22. DenisM

    DenisM

    Joined:
    Dec 6, 2013
    Posts:
    62
    Got the same issue in last unity update. Any news about this?
     
  23. Skolstvo

    Skolstvo

    Joined:
    Dec 21, 2015
    Posts:
    107
    I figured out what the problem is at my end. My laptop power was out so the computer used the internal Intel "GPU". Once the power is plugged in it starts using the real GPU and all is well. Maybe some people are experiencing this bug because of internal Intel graphics butting in.
     
  24. jhughes2112

    jhughes2112

    Joined:
    Nov 20, 2014
    Posts:
    3
    For what it's worth, if you are running DX11 and having terrible 60+ms frames, you can try -force-d3d9 on the command line when launching Unity and it may fix your issue by downgrading the graphics layer. In my case, at least, it worked. I have a brand new MSi laptop with NVidia GTX960M and standalone builds work fine, but in the editor it's unusably slow. Hope that helps someone.
     
  25. S37H

    S37H

    Joined:
    Apr 1, 2012
    Posts:
    22
    The DX9 setting (found under PlayerSettings > Other Settings > Rendering (uncheck Autographics)) worked for me, but of course, causes some of my shaders to break.

    I did get DX11 to work smoothly by disabling my second monitor. They both are set to 60hz, one is 1920x1080, other is 2560x1440. If either monitor is the only one active, editor runs super smooth.. but I really want my second monitor :(

    I also noticed if I opened unity quickly at startup, it would run smooth for maybe 15 seconds before I get the stutter lag.. made me think it was some software loading but I haven't been able to track it down.

    Edit: Eh - guess disabling monitor isn't consistent. It does help, especially if I go to the 1920x1080. I'm running an MSI 980gt, i7 skylake 4ghz, 32gb ram... not much in the scene. Really shouldn't have this lag at all :( I did manage to get it butter smooth on DX11 with one of my monitor disables, but once I closed and reopened unity it was laggy again.
     
    Last edited: Jun 17, 2016
    Skolstvo likes this.
  26. Zinov

    Zinov

    Joined:
    Jul 20, 2015
    Posts:
    38
    Launching my Unity Editor with dedicated graphics card resolved the issue. Like Unity Employee said, I have nVidia Optimus technology. Interesting tho, that Intel graphics card behaves so strangely.
     
  27. S37H

    S37H

    Joined:
    Apr 1, 2012
    Posts:
    22
    AHhhhhh this finally worked! Edit the shortcut target to look roughly like this

    "C:\Program Files\Unity\Editor\Unity.exe" -force-d3d11-no-singlethreaded

    BUTTERY SMOOTH DX11 :D

    EDIT: This was incorrect - what REALLY did it was closing Nahimic - audio software that came with my MSI M7 motherboard.
     
    Last edited: Jun 30, 2016
  28. KBurchfiel

    KBurchfiel

    Joined:
    May 16, 2016
    Posts:
    7
    This came up for me too, and I think I know why: my 4K monitor only renders at 30hz, and "wait for sync" was probably coming up since the monitor couldn't render as fast as the game could play. I don't have this problem when I put the game on my laptop monitor.
    My 4K monitor doesn't use my dedicated graphics card in Unity, but it does when I'm playing the actual game (and the in-game performance improves as a result).
    May be some other things going on too--who knows?
     
  29. TTTTTa

    TTTTTa

    Joined:
    Mar 3, 2015
    Posts:
    1,347
    I am having the same issue. I notice if I click on "Deep profile" in the profiler, the GFX.waitForPresent no longer appears in the profiler. Now the time that was spent on GFX.waitForPresent is now part of Camera.Render. If I unselect the Deep profile, then the GFX.waitForPresent returns in the profiler.

    deepprofile2.png



    This is 100% consistent every-time I run this scenario.
    Clearly something is wrong with GFX.waitforPresent and/or the profiler.
    If this doesn't help prove there's some problem here, I don't know what would.
    j
     
    Last edited: Jul 2, 2016
  30. qoobit

    qoobit

    Joined:
    Aug 19, 2014
    Posts:
    21
    I'm not sure if this helps anyone, but I've had the same issues for the longest times on one of my PCs running i7 6700k with a GTX980ti and 16GB of DDR4 ram. I followed something along these lines for windows 10 and ended up removing the DX11 option and readding it and prioritizing it as #1 and it fixed itself.

    I've been having this problem since unity 5.0. Opening the scene on my macbook pro retina 15 with lower specs run better in editor than my powered VR PC. Having said that, turning vsync off only allows for uncapped FPS rates especially visible on an empty scene. When this is bugged, on an empty scene I only can do around 6-14fps. If I use maximize on play, everything is fine. It just can't seem to deal with both the scene window and game window being visible simultaneously.

    Upon installing 5.4rc1 it seemed to have fix itself for a few days and the problem returned until now when I reloaded the display drivers in this way and it seemed to have corrected itself.

    Not sure how long this will last but I hope it won't happen again.
     
  31. Invertex

    Invertex

    Joined:
    Nov 7, 2013
    Posts:
    566
    So, I had this issue today, and the final thing that fixed it was changing a shader I made from #pragma targer 4.0 to 3.0 and then excluding d3d9 (since it uses too many textures, so I let it fall-back on GLCore instead). Went from getting 40fps to 500+. But the strangest thing is, I've now switched the shader back, and the FPS is still good... Could it be some sort of weird shader cache bug?
     
    Last edited: Jul 31, 2016
  32. KRGraphics

    KRGraphics

    Joined:
    Jan 5, 2010
    Posts:
    3,682
    Bumping this topic... I am doing some updated build for my game and i am getting this same issue again. the scene takes place in a dojo with two characters and lightmaps. At this point, I may just stop developing for now.
     
  33. S37H

    S37H

    Joined:
    Apr 1, 2012
    Posts:
    22
    Do you happen to have Nahimic audio software running? That's what caused it for me. Just had to close it or update to the newest version. If you don't have that maybe try shutting down every non-critical task/program and see if it helps..narrow down what's causing it if it does.
     
  34. KRGraphics

    KRGraphics

    Joined:
    Jan 5, 2010
    Posts:
    3,682
    I have to try something because all of this is a pain. I may even enable GPU skinning just to see the comparison in performance. A small level enclosed level with two characters shouldn't cause this at all...
     
  35. awesomedata

    awesomedata

    Joined:
    Oct 8, 2014
    Posts:
    289
    Are you guys using windows 8.1 editor while having this issue?

    I'm having the same problem and it seems to be the only thing I can think of that I might have in common with most people here, as Unity version doesn't seem to matter considering how long this has been an issue (since what, 2014?). I've turned off vsync and down other settings and it makes only a very slight difference. There are still regular spikes at predictable intervals on the CPU with Gfx.WaitForPresent using up to 97ms for a single call still, no matter what graphics or quality settings I use.

    It's amazing that Unity devs have looked at this (popular) thread since 2014, yet still nobody knows what's happening.


    My (admittedly weak) specs, in case it helps:

    • Intel HD Graphics 4000 (1792 MB Available Graphics Memory, 32 MB Dedicated Video Memory)
    • Toshiba Satellite C55-A5310
    • 6GB RAM
    • Intel Core i3 -3120M CPU @ 2.50GHz 2.50 GHz
    • 64-bit OS, Windows 8.1
    • Unity 5.4.1f1

    Anyone else wanting to get this fixed (eventually) might want to share their specs here too, just in case, so the devs might have something better to work with. If I remember correctly, a bug report was filed (and closed) with this issue previously, but it hasn't been fixed for everyone apparently.
     
  36. TTTTTa

    TTTTTa

    Joined:
    Mar 3, 2015
    Posts:
    1,347
    Hasn't anyone here tried to enable deep profile? The GFX.waitForPresent is replaced with other information in the profiler when in deep profile for me. Which has been pointed out before that others suspected the GFX.waitForPresent is not just related to vsync.
     
  37. KRGraphics

    KRGraphics

    Joined:
    Jan 5, 2010
    Posts:
    3,682
    I enabled Deep Profile and I saw all kinds of crap... my level runs smooth at a solid 60FPS until some mysterious force of CG evil causes my frames to drop... if I can run hitman absolution on this laptop, then I should have NO problem on this. I also play other Unity made fighting games on my machine with no problem... so something is wrong with my development... maybe the shaders I am using are too heavy :(
     
  38. awesomedata

    awesomedata

    Joined:
    Oct 8, 2014
    Posts:
    289
    I enabled Deep Profile and suddenly my Gfx.WaitForPresent shrinks to around 10ms instead of the 90ms it was before. Still slight regular spikes, but they reappear and become huge when Deep Profile is off.

    Nothing changes for my Gfx.WaitForPresent info display though. What are you guys seeing?
     
  39. TTTTTa

    TTTTTa

    Joined:
    Mar 3, 2015
    Posts:
    1,347
    Look at the screenshot I posted above, it's the same exact thing I was having.
    With deep profile disabled, the estimated FPS is 60. With deep profile enabled, the estimated FPS is 200.
    It really does not make any sense what is going on.
     
  40. awesomedata

    awesomedata

    Joined:
    Oct 8, 2014
    Posts:
    289
    I see what you mean now. My FPS doesn't get that high even with it enabled, but I don't have great hardware either.

    What kind of specs (and what version of Unity) are you running?

    Additionally, my profiler doesn't put Camera.Render on the top of the stack except for the frames between the spike intervals. When those intervals happen, Gfx.WaitForPresent shoots up to the top by just a little for a few frames then returns below Camera.Render.

    Apparently it doesn't matter what sort of image effects are running -- you'll find that even with Deep Profile ON, you'll still have spikes at regular intervals (though they'll be less visible, and alternate with Camera.Render which is at the top of the list in-between the interval spikes).

    The spikes are still present, just a lot smaller with Deep Profiler on.

    No clue what's really causing this.
     
  41. awesomedata

    awesomedata

    Joined:
    Oct 8, 2014
    Posts:
    289
    @TTTTTa
    Also, do you, by any chance, have a lot of memory spike/plateus in "Mesh Memory" at regular intervals in your profiler? How about a lot of batches (say ~18) and/or a lot (say, ~2000) saved by batching? This is my current situation if that helps.
     
  42. superpig

    superpig

    Insert bacon, receive bugfix Unity Technologies

    Joined:
    Jan 16, 2011
    Posts:
    3,808
    If you're seeing continuous increases in mesh memory, my guess is that you are running this profiling against play mode in the Editor. Am I right?

    If so, try running the profiler against an actual build instead and see what difference it makes.
     
  43. KRGraphics

    KRGraphics

    Joined:
    Jan 5, 2010
    Posts:
    3,682
    I get spikes when I'm in a build... the scene is small, with only two characters and one light for the sun. It runs smooth until I get spikes... and on low res I get spikes
     
  44. superpig

    superpig

    Insert bacon, receive bugfix Unity Technologies

    Joined:
    Jan 16, 2011
    Posts:
    3,808
    Have you submitted a bug report?
     
  45. KRGraphics

    KRGraphics

    Joined:
    Jan 5, 2010
    Posts:
    3,682
    I should... but my project is HUGE :(

    Here are my laptop Specs

    Windows 10
    GTX 670m @3gb VRAM
    12Gb RAM
    Core i7 3630qm @2.4GHz

    I think the laptop is the issue but I can play games like Hitman Absolution cleanly.
     
  46. DXX28

    DXX28

    Joined:
    Dec 28, 2016
    Posts:
    1
    I can confirm turning off G-SYNC fixed the issue for me. If you have G-SYNC monitor this is likely the culprit.
     
  47. KRGraphics

    KRGraphics

    Joined:
    Jan 5, 2010
    Posts:
    3,682
    Damn, i am trying to send a bug report, but the reporter is not launching at all...
     
  48. awesomedata

    awesomedata

    Joined:
    Oct 8, 2014
    Posts:
    289
    No G-SYNC here.

    @superpig
    I'll do a test on a build once I get a chance, though I've read in this thread that others (besides @KRGraphics) still have the issue on test builds too. I also remember reading that a previously opened bug-report on this issue was closed shortly after, though the bug was still not squashed for most.
     
  49. KRGraphics

    KRGraphics

    Joined:
    Jan 5, 2010
    Posts:
    3,682
    It's strange... and it is literally a small scene I am testing... even scenes with nothing in it, get spikes after a while...
     
  50. Kolyasisan

    Kolyasisan

    Joined:
    Feb 2, 2015
    Posts:
    149
    Oh come on, what is this thing? It's really annoying as it drops framerate dramaticly. Look at how much it ets out of performance! I figured out that every single shader and post-effect cause it, but what is it exactly? I have my V-sync off. upload_2017-2-6_20-44-56.png upload_2017-2-6_20-45-10.png