Search Unity

Huge peak in Graphics PresentAndSync

Discussion in 'General Graphics' started by ottolb, Apr 22, 2016.

  1. ottolb

    ottolb

    Joined:
    Jul 1, 2009
    Posts:
    42
    Hi guys,

    We’re facing a performance issue, there is considerable flick in certain moments, which is marked as Graphics.PresentAndSync. We already searched for similar issues (V-Sync, etc), but I think I’m missing something.

    It’s a 3D endless runner game, the scenario and obstacles are placed in runtime, we already use pooling to increase performance.

    We’ve tested several configurations with same results:
    • With V-Sync turned off/on.
    • Different Graphics API: OpenGL 2, 3 or Metal.
    • With no shadow and no light.
    • The current test scene is really simple, with around 5K triangles, and one directional light
      • 28 Draw Calls
      • Shader: Mobile/Directional Coloured
      • We’ve tested on iPad Air, iPhone 5C, iPad 2.
      • On Android that flick doesn’t exist

    Notice that on the image that game execution time take less than 10ms (100FPS), which is great. Although these Graphics.PresentAndSync peaks makes gameplay unplayable.

    Do you have an idea what could cause that peak?
     

    Attached Files:

  2. pointcache

    pointcache

    Joined:
    Sep 22, 2012
    Posts:
    579
    Well since as usual documentation on
    PresentAndSync
    is non existent i can just assume its renamed Gfx.WaitForPresent,
    that just shows inverse relation of CPU time to GPU.
    So the more load you have on gpu the longer cpu has to wait, and that wait time is shown as milliseconds of empty work, so despite cpu is not acutally doing anything you still see it as work in profiler.
    In general that should indicate that cpu is waiting for gpu too long to finish render.
    Thats all assuming that
    PresentAndSync
    is just
    Gfx.WaitForPresent


    in that scenario spikes are actually "drops" in gpu load
     
  3. amoraleite

    amoraleite

    Joined:
    Oct 16, 2014
    Posts:
    41
    I'm working with Otto on this game.
    I would like to add.
    We downloaded some games made with unity searching for the same problem.

    The visual result is a breakdown of linearity in the sequence of frames, in other words, the games running at 60 frames per second, and in our case the profile tag 200-100 fps you see a visual jump. It seems like a hard process for the cpu or gpu, but our game is very optimized.

    There is a game made by another team was even featured in Apple Store, the name is "Handbrake Valet". He has the same problem we found in our game. To see, leave the game running alone on the main screen and you will realize this little jump. For our game this jump makes a lot of difference. :(
     
  4. pointcache

    pointcache

    Joined:
    Sep 22, 2012
    Posts:
    579
    Im sorry the graph shows you have rendering spike, and without your project on hands i cant really help you. It maybe shaders, so forgotten flag, ui operations etc, something somewhere you forgot.
     
    ottolb likes this.
  5. Stardog

    Stardog

    Joined:
    Jun 28, 2010
    Posts:
    1,913
  6. ottolb

    ottolb

    Joined:
    Jul 1, 2009
    Posts:
    42
    Thanks for you reply, we figured out the difference between Gfx.WaitForPresent and Graphics.PresentAndSync for iOS.
    Gfx.WaitForPresent appears on Metal build and Graphics.PresentAndSync for OpenGL.
    Anyway I really didn't found I good reason for that spike on the iPad Air yet.
     
  7. ottolb

    ottolb

    Joined:
    Jul 1, 2009
    Posts:
    42
    Hi, thanks for the advice. But did you testing it in beta 17? Another developer said that it was fixed in some unity 5.4 beta version, but I don't know which one.
    http://forum.unity3d.com/threads/io...fine-help-is-needed-guys.390339/#post-2550166

    Which Unity beta are you using now?
     
  8. ottolb

    ottolb

    Joined:
    Jul 1, 2009
    Posts:
    42
    Right now we had the same problem in a simple project, cubes and a moving camera.
    Build with Unity 5.4.b17 iOS and Unity 5.3.4:
    · Game runs fine on the iPad2, but have the same hiccups on the iPad Air.
    · On Android (Moto G) it run perfect.

    Here it's the project, cubes using unlit color shader.


    Profiler images:



    And notice that somehow Gfx.WaitForPresent disappears for a while and returns. But the scene still the same...


    Attached the project in case someone has interest.
     

    Attached Files:

    MrEsquire likes this.
  9. ottolb

    ottolb

    Joined:
    Jul 1, 2009
    Posts:
    42
    We tested on both b24 and b25, and we got same results on iPad Air.
    Recently I bought an iPad Air 2 and we tested on it. Project runs very well without any peak.
     
  10. Lost-in-the-Garden

    Lost-in-the-Garden

    Joined:
    Nov 18, 2015
    Posts:
    176
    Not sure how it translates to mobile development, but we are seeing similar spikes in Gfx.WaitForPresent on PC when we are saturating the GPU bandwidth. In our case we render into a MRT (think Gbuffer or deferred shading for simplicity) which consumes quite some bandwidth.

    On small resolutions, this problem never happens, but once the bandwidth is saturated we see those spikes. If possible try the game with a smaller resolution to see if this solves the problem.

    If this is the case, high overdraw might be a reason for that. Everything else that consumes bandwidth of course can be to blame (excessive image effects, deferred shading, MRTs...)