Search Unity

Gfx.WaitForPresent

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

  1. ghostnova

    ghostnova

    Joined:
    Nov 27, 2013
    Posts:
    5
    I'm on Windows 7 Pro and I have the WaitForPresent issue. The spikes are visible on the device too though. I'm going to try Cryztalfox advice. I hope it affects the builds as well.
     
  2. Connorconno2

    Connorconno2

    Joined:
    Jan 23, 2013
    Posts:
    8
    Has anybody found an answer yet?!
     
  3. Deleted User

    Deleted User

    Guest

    Cryztalfox's solution did NOT entirely get rid of the viewport stuttering. Even if it did, I need some DX features for my project so switching to OpenGL is not an option for me.

    This is really a nasty bug that needs to be fixed urgently!
     
  4. Vunpac

    Vunpac

    Joined:
    Mar 13, 2012
    Posts:
    34
    As LaneFox pointed out, it is not an innocent value. It is using 89% of my CPU and my fps is down to 33fps, I only have 3000 objects, basic shaders (all are being batch drawn) I have shadows disabled. There is no reason to be hitting that low of an fps just loading and moving a few thousand cubes.

    I really don't like having to use a work around. Feels like I will run into issues on other systems. I hope they fix this soon.

    Edit: I was just testing something. Seems I only get it when the camera is in Orthographic. The second I switch to perspective, my fps flys up to normal. I am curious as to how many other people are using ortho, or if they are getting this with persp cameras as well?
     
    Last edited: Mar 18, 2014
  5. kilik128

    kilik128

    Joined:
    Jul 15, 2013
    Posts:
    909
    $7Gdkc.png

    IN OpenGL i look win 50ms only ! but gfx stay here
     
  6. Xander779

    Xander779

    Joined:
    Feb 19, 2014
    Posts:
    1
    I've found a solution to the problem that doesn't require any sacrifices to your project.
    The problem appears to be centered around Unity 4.3 compatibility with Windows 8.

    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.
     
  7. kilik128

    kilik128

    Joined:
    Jul 15, 2013
    Posts:
    909
    thank's i just try and i stay here with overhead !
     
  8. d1favero

    d1favero

    Joined:
    Oct 14, 2011
    Posts:
    15
    Just make a quick test here. With shadows enabled, Gfx.WaitForPreset goes to 60%, 70%.
    With no shadows , 0%.
     
  9. JayG81

    JayG81

    Joined:
    Sep 4, 2012
    Posts:
    72
    That worked for me!
     
  10. gsus725

    gsus725

    Joined:
    Aug 23, 2010
    Posts:
    250
    I am also experiencing this problem after updating my Unity to the latest version.

    There were no changes made to my project between updating Unity, yet when I run my game it is unplayable due to the same reasons these dozens of people have pointed out.
     
    Last edited: Apr 19, 2014
  11. zelmund

    zelmund

    Joined:
    Mar 2, 2012
    Posts:
    437
    confirm. if i start unity3d in winXp mode, the problem is gone forever!
     
  12. tswalk

    tswalk

    Joined:
    Jul 27, 2013
    Posts:
    1,109
    I'm not totally convinced this is a bug as I too am (or was) having this problem on a 8.1 / ARM device (mobile) and yet could not figure out why I would get between 30-15fps for basically nothing in my unity project (running remote debug with an actual device).

    but what I CAN say for sure, is that 8.1 seems to be v-sync locked on this particular device, so setting vsync does absolutely nothing in the game.. you just can't change it on the device (at all).

    the other deal is just poorly optimized shaders for DirectX 11 and/or super crappy drivers for ARM and w8... to much stuff happening in the fragment portion of it... seems like anything above 21 ALU "kills" the GPU on these win 8/8.1 mobile devices. so you really have to be conservative with the shaders... combine as much as possible into single textures, single meshes.. no post effects, no or at MOST one light source, no shadows (or extremely limited one hard shadow), limit your physics, limit your particles. post effects absolutely destroys frame rate.


    now with all that said, since we can actually debug remote graphics now for ARM/Win 8.1.... and capture vert/frag operations, as well as mega details for reach draw call and a timeline... :

    (the following is a timeline capture of the drawcall(s) sequence for one frame, 8 draw calls, ~60fps)


    Code (csharp):
    1.  

    as you can see... quite a few cycles just "waiting" for vblank... nothing we can do about it apparently.


    there is really not a lot of difference in that drawcall timeline between a scene optimized for 60fps and one that runs at 30 or 15fps with poorly optimized shaders, are just too much crap going on.
     
  13. kilik128

    kilik128

    Joined:
    Jul 15, 2013
    Posts:
    909
    so if i understand you it's comming from shader maybie
     
  14. tswalk

    tswalk

    Joined:
    Jul 27, 2013
    Posts:
    1,109
    more than likely yes... doesn't mean it was poorly written, it could just be trying to do too much or use operations that are notoriously slow for mobile GPUs.
     
  15. kilik128

    kilik128

    Joined:
    Jul 15, 2013
    Posts:
    909
    yes i use skyshop rendering and get gfxaitForPresent only after install Windows 8
     
  16. gsus725

    gsus725

    Joined:
    Aug 23, 2010
    Posts:
    250
    I have this bug on windows 7. Vsync is off on the project. It happens both in-editor and in-standalone
     
  17. XeviaN360

    XeviaN360

    Joined:
    Jun 3, 2010
    Posts:
    181
    After trying the "Windows XP compatibility mode", i was about to type "yess, it works!". But no. It doesn't.
    The profiler is fine, no gfx.waitforpresent peaks, but the framerate is dropped. So, the xp compatibility mode, only hide the gfx.waitforpresent messages on profiler (really don't know why).

    Closing and reopening Unity does not solve.

    Rebooting windows do solve.

    My project is running at 7/800 fps but when the gfx.waitforpresent thing comes on (randomly) i got 130 fps.
     
    Last edited: Apr 21, 2014
  18. gsus725

    gsus725

    Joined:
    Aug 23, 2010
    Posts:
    250
    Can a Unity developer please tell us what Gfx.WaitForPresent is and why it is hogging so much resources now compared to 4.2?
     
  19. tswalk

    tswalk

    Joined:
    Jul 27, 2013
    Posts:
    1,109
    it most likely reflects a GPU bound problem... as the CPU is literally "waiting" for something.. either vsync, or the GPU to process something. It could be many different things... each of those things I listed in the third paragraph of my earlier post could be the issue, or a combination there-of.
     
    PutridEx likes this.
  20. schetty

    schetty

    Joined:
    Jul 23, 2012
    Posts:
    424
    Hi,

    Here i have attached the image. In this image my scripting and other stuff taking the small amount of memory but this Gfx.WaitforPresent taking the 85% of the space because of this only my frame rate getting low.

    I have checked the scripting,Rendering, Garbage collector, vsync everything coming fine. But this gfx only giving the problem.
    $profiler.JPG

    Have any idea about this?..
     
  21. LightYarn

    LightYarn

    Joined:
    Nov 18, 2012
    Posts:
    77
    Last edited: May 29, 2014
  22. schetty

    schetty

    Joined:
    Jul 23, 2012
    Posts:
    424
    Even i have disable the vsync and i changed my camera to vertexlit from forward rendering. even though i am getting this problem.
     
  23. LightYarn

    LightYarn

    Joined:
    Nov 18, 2012
    Posts:
    77
    Are you developing for mobile?

    Did you try to disable script debugging in the build settings?
     
  24. schetty

    schetty

    Joined:
    Jul 23, 2012
    Posts:
    424
    yes, i am developing for a android mobile platform.

    I have unchecked the script debugging, even-though it is coming.

    Have you got any idea about why it is coming?
     
  25. LightYarn

    LightYarn

    Joined:
    Nov 18, 2012
    Posts:
    77
    Please try to complie a complete empty scene....with only:

    - One Camera (Clear Flags: Solid Color)
    - Disabled Gui-Layer
    - Disabled Flare-Layer

    - NO Scripts in the Scene
    - NO other Objects in the scene

    Try and run this on your android device and then lets see what the profiler is teeling you. Moreover try to disable these in the Build Settings:

    - Multithreaded Rendering
    - Enable Internal Profiler
    - Use 24-bit Depth Buffer

    EDIT: If you now get some acceptable FPS then you need to:
    -> load your game scene, disable every gameObject except your camera
    -> Test the FPS
    -> If everything is okay....enable one gameObject
    -> Test again
    -> If evrything is still okay....enable another gameObject
    -> And so on..

    If you enable one GO and immediately get FPS drops while testing then you know this object is causing the FPS-Drop.
    This is the way I try to find the "bad guys"...its rather time-consuming but it works most of the time.
     
    Last edited: May 30, 2014
  26. schetty

    schetty

    Joined:
    Jul 23, 2012
    Posts:
    424
    thanks for your idea. let me try this
     
  27. schetty

    schetty

    Joined:
    Jul 23, 2012
    Posts:
    424
    i have tried to compile the empty scene with camera and fps count script. i compile it to my unity editor, i played the scene and i saw the profiler the gfx.waitforpresent took the 5.6ms. It was the empty scene eventhough it is taking the more than 90%.

    I uncheck the camera flare and in build setting i uncheck the optimizemesh data, static batching, dynamic batching, enable internal profiler.

    tell me why its taking the so much timing for this?
     
  28. mangax

    mangax

    Joined:
    Jul 17, 2013
    Posts:
    336
    i don't know why none of unity developers found this a real issue..

    testing a sample project on my old Galaxy Nexus, GFX.WaitForPresent took 50+% of resources...
    made the game from being 50-55 fps to around 15fps !! turned the game to unplayable literally!

    i dunno what GFX.WaitForPresent role is, but whatever it is, am sure its Not more important than making the game playable!?..
     
  29. schetty

    schetty

    Joined:
    Jul 23, 2012
    Posts:
    424
    then what the reason for getting down the performance in the scene?
     
  30. mangax

    mangax

    Joined:
    Jul 17, 2013
    Posts:
    336
    sorry i didn't get your question.. what i was saying that gfx.etc was consuming resources thus dropping fps around 15 fps...
     
  31. schetty

    schetty

    Joined:
    Jul 23, 2012
    Posts:
    424
    i have a scene when i run it on the editor it showing the above 50 fps count. But when i exported as a apk and run it on my device the fps rate is getting damage it showing only upto 10fps and lot of lag.

    What is the reason for getting fps down in the device?
     
  32. mangax

    mangax

    Joined:
    Jul 17, 2013
    Posts:
    336
    try connecting your phone to pc then connecting profiler to see what's happening in your device while running the game... no one can answer you without showing an image of profiling your game in mobile..
     
  33. Dex7er

    Dex7er

    Joined:
    Jun 5, 2014
    Posts:
    7
    Having this issue too, even though I just updated to Unity 4.5. I am using Windows 7 and not developing for Mobile.
    Running this on an Intel Xeon E5-2609 Quadcore CPU with 12GB RAM and a 760 GTX installed.

    To start with, opening the Profiler window to try and optimize Performance drops the FPS I am getting in the Editor considerably and checking to see what might be the cause I also get the dreaded "Gfx.WaitForPresent" in the Overview:


    Tried turning off VSync and that didn't help. Even Running it at "Fastest" Quality Setting with Shadows disabled and Low Resolution with AA/AF disabled and Half Res Textures seems to still produce this to a lesser extent.
     
  34. ev3d

    ev3d

    Joined:
    Apr 19, 2013
    Posts:
    327
    I also am having this issue... Nothing seems to fix it..
     
  35. laurelhach

    laurelhach

    Joined:
    Dec 1, 2013
    Posts:
    229
    Anyone got any info on that?
     
  36. deram_scholzara

    deram_scholzara

    Joined:
    Aug 26, 2005
    Posts:
    1,043
    I encountered this issue on Mac OSX 10.9.3, though its behavior seems to depend on which monitor the game is running on.
    Screen Shot 2014-07-03 at 2.29.45 PM.png

    In this image, the left half is running on an Acer AL2216W, and the right half is running on an AOC 2269W. Both are connected via DVI to the same 780ti and both are running at 60 Hz. I don't have to restart the game for this to happen - simply running it in windowed mode and dragging from one monitor to the other will change the behavior.

    Not only does this seem to be limiting the frame rate of the game, but it also makes it really difficult to profile the other items as their sections of the graph get shrunk down so much.
     
  37. Ben-Massey

    Ben-Massey

    Joined:
    Jun 13, 2011
    Posts:
    581
    Interesting find, this issue has prevented us from upgrading for the time being.

    To my knowledge, you can uncheck the coloured box next to the usage group to stop it displaying in the profiler.
     
  38. deram_scholzara

    deram_scholzara

    Joined:
    Aug 26, 2005
    Posts:
    1,043
    Wow... not sure how I never bothered to try that before. Thanks =-)
     
  39. iamsteele

    iamsteele

    Joined:
    Mar 25, 2014
    Posts:
    29
    Not sure if this is at all related, but every time I have a Gfx.WaitForPresent event in my profiler, my Memory graph shows my mesh count jumping from 50 to 130 (nothing going on in the scene), and my active rigidbodies in Physics going from 2 to 0 (they go to sleep)...

    These events happen at exact regular intervals, in my case spread out approximately 20 something frames.

    These events look very precisely controlled in the graphs for Physics and Memory, but the number of ms that Gfx.WaitForPresent takes in my CPU varies greatly. Sometimes it's an unnoticable spike (4%), sometimes its 98%.

    I never noticed this before upgrading to the Pro Trial, but I am currently using unity 4.3 on Windows 7... and this is all coming from running the profiler in the editor with the game running in the editor.
     
  40. Noisecrime

    Noisecrime

    Joined:
    Apr 7, 2010
    Posts:
    2,054
    It would be nice to get some input from Unity.

    However I've noticed in many of the profiler screenshots shown on this page that the GPU usage is pretty high. For example 'schetty' has 21 ms on the GPU alone, that is at best that is 47 frames per second, add on the 5ms or so I can see in the cpu (ignoring waitForPresent) and that takes it down to 38 fps. Now if vsync is active or if the device is snc'd to the fresh rate the gfx.waitForpresent is most likely to be showing the time that frame had to wait for the next sync.

    Many people have mentioned Android, as far as i'm aware those devices are locked to 60 fps, meaning enabling/disabling v-sync will have no effect, thus if you project can't reliably hit 60 fps or more on those devices then you will get waits for the next v-blank.

    Its difficult to be sure since many people posting here have very different projects and may be encountering a number of different issues, but for my money this is definitely something to do with the cpu simply waiting for the gpu to become free or for the v-blank.

    No, not related. In the editor you'll get these regular jumps every time the editor updates. I can't remember off-hand if its something specific, like having the stats window open, or even if its something in the profiler itself. Should be easy to confirm just profile from a standalone build.
     
  41. XeviaN360

    XeviaN360

    Joined:
    Jun 3, 2010
    Posts:
    181
    Just updated to 4.5.2f1. Same problem. Randomly happens. I cannot optimize a !$£/%%£!=)( anything because i got 43 fps once, and 470 after a few Unity restart. F**K.
     
  42. iamsteele

    iamsteele

    Joined:
    Mar 25, 2014
    Posts:
    29
    I haven't tested this yet as I have never profiled a standalone build and will look into that, but just to throw this out there, I diminished its impact by 99% by tunneling all of my OnGUI calls into one main OnGUI, which decreased the amount of garbage collecting my GUI calls were making, which ultimately means less strain on both the CPU and GPU... so you're probably onto something, but I have to say that these spikes occured when my machine was capable of running 140FPS, with a WaitForFPS script locking it to 60... so it's not definitive of "your graphics card can't handle it" and may still infact be a bug... because my graphics card was far from maxed out, with the closest spike not relating to gfx.waitforpresent(which was spiking to 98ms) coming in at a whopping 6ms total. (on the GPU)
     
  43. Oswaldo-Filho

    Oswaldo-Filho

    Joined:
    Jul 18, 2014
    Posts:
    1
    Hello guys,

    same problem here, in my case it's happened in random situations (particles, GUI panels, etc...) but I think I found a solution.

    I used the old technique of erasing everything on the project except the Assets folder. Analyzing the problem more closely (kicks) I fixed the project without having to remove the following files:

    ProjectSettings / EditorBuildSettings.asset
    ProjectSettings / EditorSettings.asset
    ProjectSettings / TagManager.asset <--- I really need this in my project.

    The Unity asked me if I wanted to upgrade the project ... yes.

    It worked for me.

    I BELIEVE the problem is in ProjectSettings / ProjectSettings.asset file, not sure.

    *MAKE A BACKUP BEFORE TRY THIS!
     
    Last edited: Jul 18, 2014
  44. Noisecrime

    Noisecrime

    Joined:
    Apr 7, 2010
    Posts:
    2,054
    Its not a question of your graphics card being maxed out, though that is a good way to get this issue, its about the gpu being busy and the cpu having to wait before it can continue to the next frame.

    For example a project I currently have open the profiler tells me that the cpu is taking 1.39ms, but the GPU is taking 1.59 ms. Clearly the cpu is finishing before the gpu can be ready for the next frame and thus gfx.waitForPresent appears. At least that's my understanding of it and makes sense in terms of the profiler term being used 'waitForPresent'.

    Of course I could be completely wrong, just like everyone else in this thread. Such a shame that we can't get a Unity dev in here to give us a definitive answer.

    I'm also sceptical of many of the 'solutions' posted here, because none provide any reasoning or information as to 'why' their fix works. That leads me to believe that they are simply fixing an unrelated issue that itself impacted on the cpu/gpu timing. Other solutions suggest that there may be some specific hardware issues, but generally I think people are misinterpreting the data they are seeing. Its not that gfx,waitForPresent is adding time, its just the time it has to wait before it can start sending data to the gpu again, which can happen for a variety of reasons, v-sync, maxed out gpu, gpu taking more time than cpu per frame etc.
     
  45. iamsteele

    iamsteele

    Joined:
    Mar 25, 2014
    Posts:
    29
    Ah, that all sounds very reasonable... doesn't explain why my GPU time was 6ms and waitforpresent was 98ms though.. and the disparity seems apparent in other cases in this thread as well where the math doesn't add up
     
  46. Noisecrime

    Noisecrime

    Joined:
    Apr 7, 2010
    Posts:
    2,054
    Hmm, not seen something that extreme, especially if the gpu isn't taking much time itself. Guess there must be more to gfx.waitforpresent than I figured. I've brought this thread to the attention of Brett (bibbinator) hopefully he will be able to get some official posts on the matter in her soon.
     
  47. ElvisAlistar

    ElvisAlistar

    Unity Technologies

    Joined:
    Oct 2, 2013
    Posts:
    226
    I don't know why you are seeing the performance spikes and I am not a graphics programmer, but here is an explanation about what Gfx.WaitForPresent is, as offered by one of our developers a while ago:

    "A better name would be something like "waiting for renderer to catch up."

    It means that the main thread is waiting for the last frame to finish rendering, either on the render thread and GPU. Typically the GPU is the bottleneck, either because of Vsync or drawing too much stuff. It could also be submitting the frame to D3D/OpenGL that's taking long.

    The actual dependency is that the main thread waits for the render thread's last frame, which waits for the GPU's last frame. It could be either of those blocking the main thread. You have to find out what the cause is experimentally by disabling Vsync, rendering to a low resolution using simple shaders etc."

    Maybe this helps some of you.
     
    PutridEx, bitinn and laurelhach like this.
  48. pointcache

    pointcache

    Joined:
    Sep 22, 2012
    Posts:
    579
    Hi im having exactly the same issue on 4.5.4 f1 and Vsync is off ofc.
    Im on win 7 on win 8.1 everything is fine.
    Its been couple of months any news on fixes?

    This destroys my work.. is this a joke? Why its not fixed yet?
     
  49. Biggsism

    Biggsism

    Joined:
    Jul 8, 2013
    Posts:
    5
    I've had this happen off and on but I still can't figure out exactly what triggers it. Tonight I had it crop up again, spent a good chunk of time trying to find the culprit, and literally closing an editor window made it go away. It never ever seems to be the same thing that fixes it but I'll still assume user error until I can't get out of the problem using testing and backups.

    Make sure all your windows (especially scene or any custom stuff like playmaker ect) are closed before profiling the issue. If no dice, try to start Unity in a fresh project and check your scene(s) in pieces.

    If this doesn't help, a fresh project with selective importing to nail down the issue then figure out the route from there. Best of luck.
     
    pointcache likes this.
  50. pointcache

    pointcache

    Joined:
    Sep 22, 2012
    Posts:
    579
    exactly. Its just random bug i guess. Buying new pc solved it.
    Just kidding i restarted and it fixed itself, it's just that you get so sure you can debug stuff that when you actually cant
    you start panicking.