Search Unity

Hopefully the last Gfx.WaitForPresent

Discussion in 'Editor & General Support' started by gumboots, Nov 17, 2017.

  1. gumboots

    gumboots

    Joined:
    May 24, 2011
    Posts:
    271
    Hi there,

    I know there have been a hundred posts about this issue, but I'm yet to see an explanation or solution that actually applies. I had to format my computer and reinstall Unity, and now this issue is present. I can't create a project to reproduce it reliably on other computers, because it is editor related, not project.

    Prior to the reinstall, the game was running smoothly in the editor. In addition, this issue is also present in blank scenes. As in, I can't maintain 60fps in blank scenes. Builds run perfectly.
    • I tried upgrading from 2017.1 to 2017.2, but the issue still remains.
    • I added my GPU to the profiler, and Camera.Render at its peak is taking 0.047ms. Where Gfx.WaitForPresent is taking 27.44ms. These numbers are taken from a blank scene, but scenes with objects in them have similar values.
    As mentioned, I can't find an explanation or solution for this issue, and it's extremely annoying trying to test my game at ~25fps.

    Any help is greatly appreciated.
     
  2. alexeyzakharov

    alexeyzakharov

    Unity Technologies

    Joined:
    Jul 2, 2014
    Posts:
    347
    Hi!

    Did you check if Editor uses not internal GPU?
    Do you have VSync in settings? What happens if you close Scene View?

    Gfx.WaitForPresent is usually indicator that vsync is on or game is gpu-bound. Assuming that this happens for an empty scene, more likely the reason is that editor uses integrated gpu.
     
  3. gumboots

    gumboots

    Joined:
    May 24, 2011
    Posts:
    271
    Hi there! Thanks for the response. How do I figure out if Unity is using integrated graphics or not? I'm fairly certain my desktop PC doesn't even have integrated graphics, so that seems unlikely. Closing the scene few gave me ~5 extra frames or so. (Going from ~25 up to ~30.) Disabling VSync didn't have any impact.
     
  4. alexeyzakharov

    alexeyzakharov

    Unity Technologies

    Joined:
    Jul 2, 2014
    Posts:
    347
    You can check e.g. Editor.log. It contains lines like:
    GfxDevice: creating device client; threaded=1
    Direct3D:
    Version: Direct3D 11.0 [level 11.0]
    Renderer: NVIDIA GeForce GT 750M (ID=0xfe9)
    Vendor:
    VRAM: 2018 MB
    Driver: 22.21.13.8205
    In this case it is dedicated GPU - GeForce GT 750M.

    If you are on Windows and have NVIDIA GPU, you can enforce dedicated GPU card in "NVIDIA Control Panel->Manage 3D Settings->Program Settings tab->Select Unity.exe->Select to use High Performance Processor. Overwise please post your configuration.
     
  5. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    4,469
    Could you please, please, please rename Gfx.WaitForPresent in the profiler? There keeps popping up threads about this, and a lot of them are filled with arbitrary speculation. You can't really google to figure out what it is, because you just hit forum/reddit threads with people giving different pieces of (not necessarily correct) advice

    If the entry simply said "waiting for GPU" or "Waiting for VSync" depending on what's happening, that'd be a great bit of help for the end users.
     
  6. gumboots

    gumboots

    Joined:
    May 24, 2011
    Posts:
    271
    Hi there,

    I checked my Editor.log and it says it is using:

    Code (CSharp):
    1. GfxDevice: creating device client; threaded=1
    2. Direct3D:
    3.     Version:  Direct3D 11.0 [level 11.1]
    4.     Renderer: NVIDIA GeForce GTX 1080 (ID=0x1b80)
    5.     Vendor:   NVIDIA
    6.     VRAM:     7980 MB
    7.     Driver:   22.21.13.8569
    Which appears to be correct. My full computer's specs are i7 4770, 2 x GTX 1080s and 32gb RAM. I'm running Windows 10.
     
  7. alexeyzakharov

    alexeyzakharov

    Unity Technologies

    Joined:
    Jul 2, 2014
    Posts:
    347
    Noted! Not sure about renaming, but adding description/docs to high level marker is on our roadmap
     
  8. alexeyzakharov

    alexeyzakharov

    Unity Technologies

    Joined:
    Jul 2, 2014
    Posts:
    347
  9. ArachnidAnimal

    ArachnidAnimal

    Joined:
    Mar 3, 2015
    Posts:
    1,651
    Here is the anomaly with the profiler/GFX.WaitForPresent I have experienced with Unity ever since I have used it:

    profile.jpg
    .

    When deep profile is disabled, I am getting ridiculous GFX.WaitForPresent.
    Now when I switch to "deep profile", then GFX.WaitForPresent is no longer displayed in the profile.
    Instead, now Camera.Render will contain additional entries such as "Render transparent geometry".

    (I am running on AMD Radeon R7 260x, which is one of the most common graphics card on the market).

    The conclusion is GFX.WaitForPresent represents an amalgamation of activities. Need to switch to deep profile to find out what those activities are. Baste is right, GFX.WaitForPresent is too vague to know what it is.
    .
     
  10. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    4,469
    Since GFX.WaitForPresent represents waiting for the graphics card, it won't show up as something else if you turn on deep profiling - turning it on won't show GPU frames in the CPU profiler.

    What's probably happening (educated guess) is that on the left, you're waiting for the GPU at frequent intervals. On the right, the overhead of deep profiling is so large that you never need to wait for the GPU - the spikes only put you down to 60FPS when you're waiting, and the deep profiler causes you to always run at 60FPS:

    You should make sure vsync is turned off, and then turn on the GPU profiler just under it. Note that when you turn it on, it will show "your GPU doesn't support GPU profiling" - that's a bug. You just have to let it record frames before it understands the difference between "no frames" and "not supported" :p
     
  11. gumboots

    gumboots

    Joined:
    May 24, 2011
    Posts:
    271
  12. gumboots

    gumboots

    Joined:
    May 24, 2011
    Posts:
    271
    Hi @alexeyzakharov something else that is strange is that it often stops after awhile. Just standing in the scene with the game running will eventually even out and start running better, if not perfect. Going from 6 frames a second to 50.
     
  13. alexeyzakharov

    alexeyzakharov

    Unity Technologies

    Joined:
    Jul 2, 2014
    Posts:
    347
    Hi! This doesn't sound right. Could you please file a bug with the detailed information.
    From what you have told this seems like vsync issue, but the reason is not clear and should be investigated properly.
    Thanks!
     
  14. iivo_k

    iivo_k

    Joined:
    Jan 28, 2013
    Posts:
    312
    How can we help you solve this?
    I have Windows 10 FCU with GTX 1070 and had to rollback to NVidia 388.0 drivers since the never ones cause really bad slowdown with Windowed GSync in games. So there's obviously problems with Windows and NVidia even without Unity, but the periodic slowdowns with Unity may be something different. I'd guess something with (Windowed) G-Sync / Vsync.
     
  15. akuno

    akuno

    Joined:
    Dec 14, 2015
    Posts:
    35
    @alexeyzakharov I am having this issue aswell. When I used Unity in August, everything was alright. But since I came back (20 november) all my projects (including ones in older unity version 5.6) are having this issue. I have tried countless fixes with no luck.

    GTX 970 here, I would guess some geforce driver update messed stuff up.

    Here are some pictures on a simple project:
    gfxnightmare.jpg
    gfxnightmare2.jpg
     
    alexeyzakharov likes this.
  16. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    4,451
    I would imagine the most help you can provide, is to use the Unity Bug Reporter tool, submit an actual bug-report and post the Case number here for Alexey to pick up. The Bug Reporter tool collects various hardware/driver information of your system, which is probably what Unity needs to sort this out.

    Attach a project that UT can use to reproduce the issue and test their fix against. I often attach a screen-recording to show-case the issue as well, to proof that there is problem.

    The easier you make it for QA to confirm the issue, the more likely it is that it gets forwarded to a developer to investigate the issue.

    Here is a page that describes how Unity Technologies wants us to report bugs:
    https://unity3d.com/unity/qa/bug-reporting
     
    alexeyzakharov likes this.
  17. iivo_k

    iivo_k

    Joined:
    Jan 28, 2013
    Posts:
    312
    I was thinking something more in-depth like trying different driver versions / settings to help them narrow it down. A repro project won't help here since the 30 ms frames also happen in a clean project with an empty scene and obviously don't happen for everyone. Judging from Alexey's replies, they may not yet have a good grasp of the issue or the causes.

    Just to reiterate:
    - It's not about GPU power - happens with GTX 1070 in an empty scene.
    - Changing to DX9 does not help.
    - Windows 10 Fall Creators Update and NVidia drivers later than 388.0 have issues, which some reports say are fixed in Windows 17025 Insider Preview ( https://forums.geforce.com/default/...s-drops-since-windows-10-creators-update/151/ ). Could be related, although I'm running 388.0 which fixes slowdowns in Overwatch but not in Unity.
    - Disabling G-Sync mostly fixes the issue, the slow Gfx.WaitForPresent frame times go from >30ms to < 2ms (which still is a "slow" frame in an empty scene though).
     
    alexeyzakharov likes this.
  18. alexeyzakharov

    alexeyzakharov

    Unity Technologies

    Joined:
    Jul 2, 2014
    Posts:
    347
    @iivo_k, @akuno, @Peter77 Thanks for the help!
    Yes, please create a bugreport with a detailed description of what you have already tried and discovered.
    This is not a known bug and looks like a driver issue from what you are describing.
     
  19. gumboots

    gumboots

    Joined:
    May 24, 2011
    Posts:
    271
    @alexeyzakharov I found something interesting today when I did a complete driver wipe and installed July's drivers. The short of it is that NVIDIA's 'In-game Overlay' is a cause of performance woes in the editor. (Doesn't seem to be related to driver version, as returning to the latest didn't make any difference.) I went from 5-15 frames a second in the editor to a steady 30 when disabling the overlay.

    Performance still isn't where it should be (30fps @ 720p in the editor versus 120+fps @ 1440p in a build), but this has had a noticeable improvement and might provide insight into what else might be going on?

    For anyone attempting to utilise this, you need to go into GeForce Experience's settings and disable "IN-GAME OVERLAY". Simply turning off Instant Replay or any of the other features in the overlay has no effect.

    Edit: I didn't realise rendering the scene view had such a high cost. Turning that off took me from 30 to 80fps. It also removes the strange Profiler behaviour. Where it would say the frame was taking a huge amount of time due to Gfx.WaitForPresent, but if you profiled the graphics card the frame was taking no time!

    Edit 2: A build at 720p gets ~270fps. So there's still a fairly large discrepancy. However not rendering the scene view did give a massive increase!
     
    Last edited: Dec 19, 2017
    akuno and alexeyzakharov like this.
  20. akuno

    akuno

    Joined:
    Dec 14, 2015
    Posts:
    35

    Attached Files:

  21. alexeyzakharov

    alexeyzakharov

    Unity Technologies

    Joined:
    Jul 2, 2014
    Posts:
    347
    @gumboots @akuno
    Thank you very much for the investigation and posting the workaround solution!
     
    akuno likes this.
  22. iivo_k

    iivo_k

    Joined:
    Jan 28, 2013
    Posts:
    312
    I don't have Gefore Experience installed myself.
     
  23. Salja

    Salja

    Joined:
    Mar 23, 2017
    Posts:
    326
    Same bug all time Gtx.WaitForPresent on Unity 2017.3.0f1 i test p1 too same bug i get with a GTX980 just 25-45 FPS and the FPS drop over time to 0
     
    WILEz1975 likes this.
  24. gumboots

    gumboots

    Joined:
    May 24, 2011
    Posts:
    271
    @alexeyzakharov I think some confusion about Gfx.WaitForPresent is that it includes rendering the scene view. Would it be possible to break these out and list the scene view as a separate item?
     
  25. alexeyzakharov

    alexeyzakharov

    Unity Technologies

    Joined:
    Jul 2, 2014
    Posts:
    347
    I think so, I put it to our backlog.
    Right now in the Editor we separate editor logic from a player logic by disabling thread profiling for main and render threads in editor logic sections. That's what you can see as "EditorOverhead" samples.
    However render commands are queued sequentially altogether and might be executed on GPU without any fences.
    I guess the desirable option would be to use GPU timer queries on supported platforms to say when exactly editor commands started and finished. Alternatively we could flush playmode commands, but that's would skew results.
     
  26. gumboots

    gumboots

    Joined:
    May 24, 2011
    Posts:
    271
    I made this script to automatically hide the Scene view if you happen to like having it in a different tab group to the Game view:

    https://pastebin.com/3MekpEM0

    Put that in a class called FocusOnPlayDummyWindow.cs, and then go to Window -> Focus on Play Dummy Window. Drag the Dummy window into the same tab group as Scene, and every time you play, the Dummy window will focus. When you stop playing, the Scene window will return focus.

    Might help someone!
     
    alexeyzakharov and Salja like this.
  27. The_BenEvans

    The_BenEvans

    Joined:
    Jul 31, 2012
    Posts:
    137
    I've just been fighting with the Editor (5.6.5f1 and previous versions) as it was experiencing random fps drops, especially when moving and docking editor GUI tabs, then resizing them. Panning around the Scene was also a nightmare, even a empty new one. This is on a 1080 card too.

    After changing "Manage 3D Settings -> Program Settings -> Unity3D.exe -> Monitor Technology" from "G-Sync" to "Fixed Refresh" and restarting the editor, it's as smooth as butter. Hopefully it stays this way. (I've also got the GeForce Experience overlay turned off)
     
    iivo_k likes this.
  28. johntheunsto

    johntheunsto

    Joined:
    Feb 28, 2013
    Posts:
    2
    I am experiencing something similar.... I am building the game for android. Vsync is set to dont sync in all levels of quality. The game runs fine in the editor. But in android it has terrible fps (less than 15 average). The Profiler shows GFX.Waitforpresent causing around 50ms. Using OpenGL 3.0... In order to determine the cause of the problem, I built an empty scene. ( It had objects but they were all set to Inactive) .... A new "Wait for TargetFpS" was taking 30ms. It was under VSync. Though I had disabled it in quality settings. Am I supposed to disable it elsewhere? When I added a camera, GFX.Waitforpresent was back... causing about 20ms in an empty scene... Is it a problem with my phone?
    I used Asus Zenfone 3 (Ze552kl) for this.
     
  29. iivo_k

    iivo_k

    Joined:
    Jan 28, 2013
    Posts:
    312
    AFAIK VSync is always enabled on Android regardless of the setting in Unity. Anyway, this doesn't really seem related to the issues discussed in this thread.
     
  30. GeorgeCH

    GeorgeCH

    Joined:
    Oct 5, 2016
    Posts:
    222
    Fun fact - something similar just happened to me. Turned out, my Nvidia display driver had decided to have a fit, which forced Unity to use my integrated video card with predictable results.

    I do wish I had found this thread before I spent hours trying to figure out why my game's frame rate had suddenly tanked - but, man, think of all the optimization I've done in the process!
     
  31. Freznosis

    Freznosis

    Joined:
    Jul 16, 2014
    Posts:
    226
    I was having this problem and the Profiler as usual wasn't helping at all. I wasn't using Vsync and had no scripts that would cause this as they are all light and optimized. I managed to find out the Screen Space Reflections in the Processing Stack was causing these horrible spikes and consistent lag through my scene. Turning it off took my overall load from 15ms to 3ms. I never had a problem with SSR before but it's something to look out for I guess.
     
  32. indieDoroid

    indieDoroid

    Joined:
    Jan 25, 2016
    Posts:
    244
    This is very helpful! Thanks for sharing your experiences guys.. I'm having the same problem with my profiler and high spikes.
     
  33. jhughes2112

    jhughes2112

    Joined:
    Nov 20, 2014
    Posts:
    98
    For what it's worth, GFX.WaitForPresent means the GPU is busy. Although there are lots of reasons why that may be, in real scenes where there's a lot going on, sometimes it can just mean you're rendering with too complex of a shader, or too many polygons with complicated shaders. Going into Timeline mode in the Profiler helps diagnose this, but the 100% telltale sign it's your shaders is if you progressively reduce your resolution and see the GFX.WaitForPresent also get smaller each time, that's what's happening. Basically, that means you have a GPU that is being overtaxed and lowering the resolution reduces the number of pixels it has to draw. Try culling more, simplifying shaders, or find a different way to do what you're doing.
     
  34. proto_monkey

    proto_monkey

    Joined:
    Jun 7, 2015
    Posts:
    18
    I am using a empty default 2D project in 2018.1.1f1 and I get these constant framerate drops when I play in the editor. I do see the gfx.waitForPresent and EditorOverhead items as the top items when I am profiling. I tried all V-sync options and none solve the issue. I have removed Scene view while playing, that has no effect.

    I have a macbook pro with macOS 10.13.4 and I don't have this issue with 2017.3.1f1

    You mentioned the person should check if Editor uses not internal GPU. How can I check and modify that if needed?

    In the profiler on the hierarchy header it says GPU 0.0ms all the time, so I am assuming that my GPU is doing nothing.

    I see a fix in the issuetracker for 2018.2.0a2 :

    https://issuetracker.unity3d.com/is...-editoroverhead-after-upgrading-to-2017-dot-3

    I am unsure if this is the same issue as mine is not consistent, but rather spikes.
     
    Last edited: May 26, 2018
  35. jhughes2112

    jhughes2112

    Joined:
    Nov 20, 2014
    Posts:
    98
    Can't help you--too many variables and questions. Isolate down to what you know. If it works in 2017.x but not in 2018.x, with the same video drivers and same scene and settings (reinstall the old version and verify), it's either a setting change in Unity 2018.x or a bug. If it doesn't work in 2017.x or 2018.x, it's something on your end. On a PC, you can check which GPU is active by opening up task manager and looking under performance. On Mac, I dunno. Look for a program that will graph GPU usage. As I said, it means the GPU is busy, so look for things that make it busy--including opening multiple Editor windows, background rendering tasks, having the profiler open itself maybe. Reboot your system and run a test, just in case something is zombied in the background.
     
  36. proto_monkey

    proto_monkey

    Joined:
    Jun 7, 2015
    Posts:
    18
    Thanks for the reply, but I was directing my question at the unity dev.

    I think I have it isolated down quite far. My best estimation is that it is indeed a bug or possibly some kind of setting change in 2018.x

    Reboots and eliminating windows/applications etc has been done long ago. Fresh boot, nothing but unity running, and activity monitor to see if anything is sucking performance. It's a empty default 2D project with a single sprite and I even removed the scene view and made sure nothing was selected as some have said the inspector panel might be involved, haha

    There ain't a whole lotta variables anymore. I doubt the issue is external to Unity because 2017.3 runs fine and my CPU and GPU are doing next to nothing. It's an empty project after all. If the GPU is seen as busy, it's because Unity has a bug that's mistaking it for busy :)

    I have no plugins. I've tried removing the external monitor, which someone else suggested. Tried every v-sync option. Setting quality level to lowest and toggling graphics settings to see if anything makes a difference. none of it does.

    Also runs beautifully smooth in a build, so that also points to it being a Unity editor specific issue.

    Ah well, bug is submitted. Just going to continue with 2017.3 and be glad I didn't go pro/plus yet.
     
  37. mkgame

    mkgame

    Joined:
    Feb 24, 2014
    Posts:
    584
    I have exactly the same issue. But, in Unity 5.6.6f2 Pro it is hardly visible (1 ms, 1000 FPS), and in Unity 2017.4.11f1 Personal and 2018.2.8f1 Personal (4 ms, 250 FPS) it looks like yours in the profiler. I converted the same project to 2017 and 2018.
     
  38. Jakub_Machowski

    Jakub_Machowski

    Joined:
    Mar 19, 2013
    Posts:
    371
    I have similart problem on unity 2018.2 it a little bit annoying cause sometimes I change nothing in project click play in editor and have 12 fps turn off click again play and have 60 fps this is very hard cause it happends sometimes only
     
  39. purnamasari

    purnamasari

    Joined:
    Mar 8, 2018
    Posts:
    17
    I'm finally fix this by reinstalling Nvdia Driver and disable In-Game Overlay at Geforce Experience.
     
  40. proto_monkey

    proto_monkey

    Joined:
    Jun 7, 2015
    Posts:
    18
    This is no longer an issue for me, I am not sure if it was a Unity fix or was an issue with macOS that got fixed when I updated to Mojave. I kind of just gave up on Unity 2018 and had been working with a 2017 build. After I installed Mojave I decided to try out latest 2018 version and to my surprise everything was smooth.

    Made me wonder if possibly the issue could have been related to a macOS issue and Mojave was the real fix, but not going to go back to test that theory. :)
     
  41. WILEz1975

    WILEz1975

    Joined:
    Mar 23, 2013
    Posts:
    309
    Same problem, the transition from 2018.2 to 2018.3.0f2 went from 90 fps to 15fps.

    - On nVidia 1060 - 6Gb.
    - DX 11
    - nVidia Game Overlay Disabled.

    Really a very bad thing.
     
    Last edited: Dec 15, 2018
    nevermorint likes this.
  42. FMFishingCactus

    FMFishingCactus

    Joined:
    Oct 23, 2018
    Posts:
    5
    Had the problem, like 90% on Gtx.WaitForPresent in some frames (unity 2018.3) :
    Be sure your display is connected to your graphical card and not to your motherboard (in that case it won't use your graphical card but the integrated graphical drivers)...
    Also since I am working on a workstation type, I turned the NVIDIA settings to dedicated to graphical tasks instead of doing both graphical and calculus tasks.
     
  43. arbazgillani

    arbazgillani

    Joined:
    Dec 23, 2015
    Posts:
    2
    I am facing the same issue in Unity 2018.2.6. Everything works fine in 2017 or lower but here in this editor i have long gfx.waitforpresent peaks. I dun know why unity is not looking into this issue or giving a proper explanation or solution. Has anyone solved this issue in Mac Mojave 10.14 ? Please help me if u can?
     
unityunity