Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Gfx.WaitForPresent

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

  1. jordi_boni

    jordi_boni

    Joined:
    Feb 7, 2013
    Posts:
    18
    What's the meaning of gfx.WaitForPresent? How can I resolve this performance matter?

    Best regards

    $gfxWaitForPresent.jpg
     
  2. Calaek

    Calaek

    Joined:
    Feb 19, 2013
    Posts:
    15
    I was experiencing this too actually, and to be quite honest. I found that having the profiler open every play test was causing me performance issues inside the unity player. Probably due to the constant draw calls to that GUI window. I close it and everything is smooth again. And I just ran a test, I am experiencing a lot of gfx.waitforpresent too. I *think* it maybe a vsync thing. But I could be wrong. Do you experience poor performance with profiler closed?
     
  3. jordi_boni

    jordi_boni

    Joined:
    Feb 7, 2013
    Posts:
    18
    I am profiling from my computer to another computer running my application connected to a TV
     
  4. Calaek

    Calaek

    Joined:
    Feb 19, 2013
    Posts:
    15
    Ah, well even still. I never liked the performance of a tool that's supposed to help performance :D
     
    sanmn19 likes this.
  5. Zergling103

    Zergling103

    Joined:
    Aug 16, 2011
    Posts:
    392
    I'm having a similar issue. In my case, it takes up to 50 ms.
     
    nordaj123 likes this.
  6. DigitalAperture

    DigitalAperture

    Joined:
    Jul 11, 2013
    Posts:
    2
    Similar issue in my case. VSync seems to be causing it because my game is extremely smooth without it on but when it is I get the same WaitForPresent spikes. The strange thing with my game is that after adding a LOT more objects to the scene it runs extremely smooth again.

    $dmU0jR6.png
     
  7. XeviaN360

    XeviaN360

    Joined:
    Jun 3, 2010
    Posts:
    181
    Same here, what is it? VSync is disabled.
     
  8. Zergling103

    Zergling103

    Joined:
    Aug 16, 2011
    Posts:
    392
    I think it has to do with swapping around the active RenderTexture. Normally the lag induced by having the profiler open would show up as RenderTexture.setActive, but I think they tried to detect this and instead display it as Gfx.WaitForPresent.

    Though, the RenderTexture.setActive still seems to show up for DigitalAperture (the purple section).
     
    Carterryan1990 and Agent0023 like this.
  9. Seith

    Seith

    Joined:
    Nov 3, 2012
    Posts:
    755
    Same problem here. So is it only linked to the fact the Profiler is open and running then?

     
  10. Exalia

    Exalia

    Joined:
    Aug 14, 2013
    Posts:
    22
    Bumping this for more attention, My application also suffers from this
     
  11. XeviaN360

    XeviaN360

    Joined:
    Jun 3, 2010
    Posts:
    181
  12. roxIndie

    roxIndie

    Joined:
    Oct 14, 2012
    Posts:
    28
    Same here. Uses 20-65 ms on the CPU when profiling connected to my OUYA.
     
  13. twiesner

    twiesner

    Joined:
    Oct 4, 2011
    Posts:
    309
    Gfx- waitforpresent use to be called device.present.

    According to the old forum post (http://forum.unity3d.com/threads/86312-Device-Present-in-profiler-what-the-deal) two reasons it would show up:
    "you are too fast - refresh rate is 60hz and you are ready after 10ms - 6ms you need to just wait
    you are slightly too slow - same as before - but you are ready after 20 ms - you will wait 13 ms (up to 33ms = 30 fps)"
     
    Last edited: Nov 20, 2013
  14. berney

    berney

    Joined:
    Sep 11, 2012
    Posts:
    10
    Same issue here. This was not present in 4.2.x
     
  15. sebas77

    sebas77

    Joined:
    Nov 4, 2011
    Posts:
    1,639
    waitforpresent, that should be the device.present as suggested, is actually a good thing...it means you are GPU bound and the CPU at a given point (usually 3 fames ahead) must wait for the GPU to finish. (IT also could mean that you need to optimize your rendering :) )
     
  16. sebas77

    sebas77

    Joined:
    Nov 4, 2011
    Posts:
    1,639
    ah btw, today I noticed that profiling inside the editor gives completely wrong results! Try to build your application and profile your application externally instead!
     
    sj631 likes this.
  17. XeviaN360

    XeviaN360

    Joined:
    Jun 3, 2010
    Posts:
    181
    Ok, i opened a bug report (Case 579069).
    I was playing with a simple empty project and some balls bouncing around with diffuse shaders and no fancy post effects -> 1900/2000 fps. Then i started to add a secondary camera, a rendertexture, and some post effects. Unity started to drop fps to 120/130, and showing in the profiler a 99% cpu usage by Gfx.WaitForPresent. I removed everything: cameras, post effects, rendertargets, etc. I have ONE ball bouncing. Still at 130 fps with WaitForPresent at 99%.

    I think there is something broken about rendertargets in 4.3 ...
     
  18. XeviaN360

    XeviaN360

    Joined:
    Jun 3, 2010
    Posts:
    181
  19. Exalia

    Exalia

    Joined:
    Aug 14, 2013
    Posts:
    22
    I'm having a similar problems, and it is very frustrating. Does Unity not have a list of profiler stat names to find out what this is? It's hard to fix an issue if I don't know where to look :(
     
    vsugrob likes this.
  20. strachan.alex

    strachan.alex

    Joined:
    Oct 12, 2013
    Posts:
    1
    Same problem, Just appeared since 4.3. Wish I could share more light on the situation but I got nothing
     
  21. Silly_Rollo

    Silly_Rollo

    Joined:
    Dec 21, 2012
    Posts:
    501
    Another one here for Gfx.WaitForPresent. I agree that there should be definitely be a breakdown in the Unity docs about the profiler stat names.
     
  22. MikeMarcin

    MikeMarcin

    Joined:
    May 15, 2012
    Posts:
    17
    FWIW on android I get this with multithreaded rendering enabled.
    With multithreaded rendering disabled I get some more reasonable looking profiler output.
     
  23. Seith

    Seith

    Joined:
    Nov 3, 2012
    Posts:
    755
    So is this an expected behavior of the profiler or is this a 4.3 bug? And if it is, did anyone open a bug report yet?
     
  24. Djekaster

    Djekaster

    Joined:
    Dec 17, 2012
    Posts:
    7
    Got the same issue. The most interesting - we fixed this in 4.2 by disabling VSync in Project settings. But then we got this trouble back after update to Win 8.1 and Unity 4.3. And even VSync disabling doesn't help. So now I cannot understand, is it Win 8.1 issue (cause all projects, compiled in 4.2 and worked in Win 8, are crashing down), or this is a Unity 4.3?
     
  25. CaptainKirby

    CaptainKirby

    Joined:
    Dec 12, 2011
    Posts:
    36
    So,... it dissapeared from the profiler when i turned the shadow quality down to medium from high... strange
     
  26. Seith

    Seith

    Joined:
    Nov 3, 2012
    Posts:
    755
    @Djekaster: Well I'm on Windows 8 so I would say 8.1 is not the culprit here... :(

    @CaptainKirby: I assume you mean the shadow texture size in the project's Rendering preferences. I tried that but it didn't fix the issue.

    One precision: I use DX11.
     
  27. Matthew Scott

    Matthew Scott

    Joined:
    Jan 16, 2013
    Posts:
    33
    Mine was working fine the other day while I was optimizing a script, just had an empty scene with my script running on a game empty with Vsync disabled, FPS in the 1000's, then for no apparent reason, with no changes made at all, I started getting 250 fps, and GFX.WaitForPresent taking up 96% and causing red spikes all over the place...no explanation for this......sometimes it happens, sometimes it doesn't, sometimes when I hit play it starts of at 250 fps with Wait for Present and then randomly stops and Im back at 2500+ again.

    Completely lost as to why this is happening......I always took it as a vsync thing which is fine, but it shouldn't be doing it if I have vsync off.

    ***Edit - It's working fine again now....after a few play's...I really dont get it...
     
    Last edited: Dec 13, 2013
  28. HraKK

    HraKK

    Joined:
    Oct 13, 2013
    Posts:
    12
    Got a same problem. I use 4.3.1f1 version of Unity3D.

    I want to make a tile background with parallax. So I render via SpriteRenderer Texture2D with WrapMode : repeat, like that:

    var texture = (Texture2D)Resources.Load("background");
    var material = (Material)Resources.Load("tiling");


    SpriteRenderer renderer = gameObject.GetComponent<SpriteRenderer>();
    Sprite sprite = new Sprite();
    sprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), new Vector2(0, 0), 1.0f);

    renderer.material = material;
    renderer.sprite = sprite;


    In material "tiling" I'm use default sprite shader modified in this way:
    OUT.texcoord.x += _TextureOffset;
    I did it for scrolling texture, couz standart SetTextureOffset seems not work properly.

    So, in Update method I added a script for shift a texture, let's simplify it for understanding to:

    renderer.material.SetFloat("_TextureOffset", i * Time.deltaTime);

    Okay, it work well! But, on the surface it look a bit jerky. Profiler says me what it happen when Gfx.WaitForPresent got a spyke. Ok, maybe I assumed what I overloaded GPU, but indeed I don't. It's easy to check - just create an empty project. Unfortunately, the spykes still here :(

    I try to disable VSync but it seems have no effect.

    Please, help me! I'm going to get upset(
     
  29. mangax

    mangax

    Joined:
    Jul 17, 2013
    Posts:
    334
    i confirm this is happens to me every time i play in editor... not sure if it occurs on the other devices
     
  30. HraKK

    HraKK

    Joined:
    Oct 13, 2013
    Posts:
    12
    it does not depend on device. I checked.
     
    Last edited: Dec 19, 2013
  31. Seith

    Seith

    Joined:
    Nov 3, 2012
    Posts:
    755
    Did anyone post a bug report about it? If so, is it already on the issue tracker page?
     
  32. XeviaN360

    XeviaN360

    Joined:
    Jun 3, 2010
    Posts:
    181
    I submitted a bugreport but they told me it's not reproducible. We need to create a simple project that reproduce this bug and send to them
     
  33. Cryztalfox

    Cryztalfox

    Joined:
    Jan 6, 2014
    Posts:
    6
    This problem exists mostly for users who have eithor updated their Windows device to the lastest 8, or are using 8.1. I have done a few tests myself and have noticed this only occured when I eithor updated windows, or ran it on my 8.1 machine (my main one). Not sure how the devs state it's not reproducible since for me if I open the editor (pro and indie) on my 8.1 machine with an empty scene, disable V-Sync, you will see the profiler display gfx.waitforpresent (pro) or half of your usual fps mileage (indie). I'm going to take a guess and say it may be in relation with an NVidia override of Unity's settings but I have no idea. Bumping for attention. Lets hope for an update.
     
  34. XeviaN360

    XeviaN360

    Joined:
    Jun 3, 2010
    Posts:
    181
    This IS a bug.

    If you read ALL the previous posts in this thread you'll find that this bug happens also with no vsync option enabled.

    It could be related to gpu bound situations, like when you're using render targets / render textures. But that BUG, in my case, came out when i updated to Windows 8.1 and Unity 4.3.
     
    Last edited: Jan 7, 2014
    Cubonde likes this.
  35. VenomUnity

    VenomUnity

    Joined:
    Apr 6, 2013
    Posts:
    29
    Probably it's a bug. Look at this in my scene
     

    Attached Files:

    Last edited: Jan 7, 2014
  36. Duney

    Duney

    Joined:
    Aug 19, 2013
    Posts:
    170
    Got the same thing here with 8.1. Completely eats the CPU speed continuously and is causing my game to run like a snail.
     
  37. XeviaN360

    XeviaN360

    Joined:
    Jun 3, 2010
    Posts:
    181
    Could any of you send a bug report with an attached sample? :)
     
  38. Cryztalfox

    Cryztalfox

    Joined:
    Jan 6, 2014
    Posts:
    6
    So I was experimenting in my project which previously had the gfx.waitforpresent, when something most peculiar happened. In the profiler under the GPU profiler, it failed to detect my graphics card (yes it's functioning fine just unity couldn't detect it at the time). When this occurs and it can't "monitor" the gpu, there is NOT ONE CALL to Gfx.waitforpresent. I'm going to see if I can find a way to invoke this detection error as there seems to be a 100% correleation with the profilers Gpu profiler and GFX.Waitforpresent. Hope this helps anybody. Also yes I am using 4.3 and Windows 8.1.
     
  39. Cryztalfox

    Cryztalfox

    Joined:
    Jan 6, 2014
    Posts:
    6
    Hey guys so I recently have found a fix for this through experimenting but it comes at a cost. If you are using Unity pro's realtime shadow's they may not work for you should you choose to do this but it's not permanent. The reason you guys are getting this is due to Direct X with 8.1. The only way I have found to eliminate this gfx.waitforpresent is to go to your Unity Shortcut, under target where it says "C:\Program Files (x86)\Unity\Editor\Unity.exe" (or w.e your path is) append this "-force-opengl". Only Windows uses opengl so if you are getting this on a linux or mac sorry. If you've never added targets before here's an example of how your target should look like quotes included: "C:\Program Files (x86)\Unity\Editor\Unity.exe" -force-opengl
     
  40. Cryztalfox

    Cryztalfox

    Joined:
    Jan 6, 2014
    Posts:
    6
    Sorry, in a rush but fyi you can still use Unity's shadow if you change your lighting method to forward rendering (blonde moment lol). So there's no cons involved so long as you aren't using DirectX only features. Let me know if it worked for you :)
     
    Whiteleaf likes this.
  41. HiVE-interactive

    HiVE-interactive

    Joined:
    Oct 11, 2013
    Posts:
    14
    I would like to confirm that this is indeed a bug. I have been getting alternating FPS and thread caps after quitting unity and reloading the scene. Gfx.WaitForPresent is the culprit
    I am using 4.3.1f and windows 7 (dx11) - so this confirms that the bug affects win7 users also.

    Cryztalfox's fix has indeed brought my thread back down below 1 and FPS is capping at around 1k - thanks for helping out dude.

    I'm still wondering though, will this issue affect builds - forcing builds to also target -force-opengl ?
     
  42. Duney

    Duney

    Joined:
    Aug 19, 2013
    Posts:
    170
    Just tried Cryztalfox's work-around and it seems to stop the Gfx.WaitforPresent showing, just unfortunate that a couple of my shaders requires DirectX, so will hopefully see some kind of fix soon, or at least an acknowledgement that there is an issue here.
     
  43. SmashedAvocado

    SmashedAvocado

    Joined:
    Dec 19, 2013
    Posts:
    45
    I am having the same issue but I'm using a lot of post effects. I found that changing my shadow resolution from Very High resolution to High resolution seemed to have reduced the WaitForPresent time somewhat.

    I also found that I had a very high resolution texture for my Skybox (4096px), and reducing that down to a smaller resolution also seemed to make stuttering go away.
     
  44. LaneFox

    LaneFox

    Joined:
    Jun 29, 2011
    Posts:
    7,454
    Ditto also having this problem.

    It has slowed my compiled build down significantly, juggling anywhere between 60 and 15 fps.
     
  45. BenKurdziel

    BenKurdziel

    Joined:
    Nov 9, 2012
    Posts:
    8
    Hey guys, exact same problem here,

    Edit - Modifying my findings:

    From what I've found looking at this, it has to do with the Quality Settings.

    In my project, the issue appeared between the default "Good" and "Beautiful" levels. So I slowly modified the Beautiful level to match the Good level with the project running and the Profiler open, and upon switching Shadow Quality down from High to Medium, I saw a jump from 25-35 fps to 55-65 fps. Anisotropic Textures also seems to reduce the amount of time for the GFX issue.

    In short, from what I can see, lower your Shadow Resolution to Medium, and set your Anisotropic Textures to "Per Texture".

    I know it's not optimal, but for performance sake, might be the only option right now.
     
    Last edited: Jan 23, 2014
    PutridEx likes this.
  46. mangax

    mangax

    Joined:
    Jul 17, 2013
    Posts:
    334
    i confirm that Cryztalfox temporary fix has eliminated the issue..

    and i'd like to say that am using latest version of windows 7 pro.. so it's not an issue bound to windows 8
    i dunno if nvidia drivers can cause such an issue, but i remember updated nvidia drivers many times.. so maybe gpu drivers involved in this??
     
  47. kilik128

    kilik128

    Joined:
    Jul 15, 2013
    Posts:
    909
    any other idea i have try all i got 120 ms in my scène form gfx.waitforpresent
     
  48. Edy

    Edy

    Joined:
    Jun 3, 2010
    Posts:
    2,495
    Every time this happens to me I put the computer into Sleep mode, wait a few seconds, and wake it up. I don't event close Unity. Everything runs fine then. In my case it seems to be a kind of problem with the graphic adapter that gets fixed when the driver is completely restarted.
     
  49. Binary42

    Binary42

    Joined:
    Aug 15, 2013
    Posts:
    207
    Hey, Gfx.WaitForPresent is probably just similar to WaitForTargetFPS, their graphs seem to be mutually dependent. Meaning, regardless whether V-Sync is enabled or not, its just a waiting thread aka Idle. So if this value is at 99% your CPU isn't going to melt soon, it just got nothing to do.

    The problems / test cases posted here, they all have an impact on CPU load and thus show an effect in Gfx.WaitForPresent. But you might reconsider before blaming this innocent value. ;)
     
  50. LaneFox

    LaneFox

    Joined:
    Jun 29, 2011
    Posts:
    7,454
    If its idle with nothing to do then what explains the performance hit?
     
    NonPlayerCorey likes this.