Search Unity

Device.Present in profiler....what' the deal.

Discussion in 'Editor & General Support' started by iverson, Apr 19, 2011.

  1. iverson

    iverson

    Joined:
    Dec 27, 2008
    Posts:
    81
    Device.Present (Total) 32% (Self) 28%
    what's the problem?
     
  2. Alexey

    Alexey

    Unity Technologies

    Joined:
    May 10, 2010
    Posts:
    1,624
    well, Device.Present may wait for vsync(vblank) - so it is just sitting there doing nothing ;-).
    Two main reasons are:
    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)
     
    Furquijo and Robert9552 like this.
  3. iverson

    iverson

    Joined:
    Dec 27, 2008
    Posts:
    81
    the only one interface for frame rate is "Application.targetFrameRate" in unity,is it the key?
    as you're right,the frame rate is low,because there are 500 character in my scene,but they are invisible.
    i have to optimize 500 character in a scene.
     
  4. Alexey

    Alexey

    Unity Technologies

    Joined:
    May 10, 2010
    Posts:
    1,624
    well, that's sligtly different
    in QualitySettings there is a checkbox: Enable VBL (or something like that) if that is checked your fps will be aligned with monitor refresh rate (that's what VBL stands for). Try to disable VBL and profile once again
     
  5. iverson

    iverson

    Joined:
    Dec 27, 2008
    Posts:
    81
    thanks man, it worked.
     
  6. Antony-Blackett

    Antony-Blackett

    Joined:
    Feb 15, 2011
    Posts:
    1,778
    I've got the same issue on my iPhone4. Only I don't have VBL on and the Device.Present function is consuming 81% of the frame! This pushes my frame rate to 10-15 fps even though the rest of the game is running in under 8ms...

    Any ideas?

    Could it be a shader problem or something on the iPhone?
     
    IgorAherne likes this.
  7. Alexey

    Alexey

    Unity Technologies

    Joined:
    May 10, 2010
    Posts:
    1,624
    you should have posted it in ios section
    on ios you have forced VBL
    and on later ios versions high Device.Present indicates that cpu waits for gpu (this counter will be updated in 3.4) meaning you are gpu bound
     
    Furquijo and IgorAherne like this.
  8. Antony-Blackett

    Antony-Blackett

    Joined:
    Feb 15, 2011
    Posts:
    1,778
    Thanks, this is what I thought.
     
  9. Xroft666

    Xroft666

    Joined:
    Dec 24, 2010
    Posts:
    24
    Hi, guys. From previous posts I understand that Device.Present is a process of waiting. But it slows my iPad from 5 to 15 fps and what am I suposed to do with it?
    Thanks )
     
  10. andymads

    andymads

    Joined:
    Jun 16, 2011
    Posts:
    1,614
    @Antony Blackett and @WhiteDevil, did you guys learn anything new that could be added to this discussion?

    I can't figure out why my main menu screen is running at ~40ms per frame on an iPhone 4 yet on an iPod Touch 3GS I get 30 fps - and this is with having cut the screen right down to just a single button graphic on the iPhone 4.

    According to the Unity profiler the Device.Present is the culprit, but as mentioned above by @Alexey, I am GPU bound? I can't see how.
     
  11. funshark

    funshark

    Joined:
    Mar 24, 2009
    Posts:
    225
    I can't figure out what is the problem with Device.Present.
    I have a sluggish screen update in all my projects, with Vsync or not, and these "lags" are sync with the Device.Present component in the Profiler.
    Even with the simpliest scene : 1 cam and 1 cube with a transform updated per frame.
    It's annoying me since I thought it was something related to Camera and LateUpdate at the beginning..
     
  12. Alexey

    Alexey

    Unity Technologies

    Joined:
    May 10, 2010
    Posts:
    1,624
    device.present will be here because ios can't run faster then 60fps [or actually kFPS set up in AppController.mm] - so it basically shows you that you are waiting gpu to start new frame.
     
  13. andymads

    andymads

    Joined:
    Jun 16, 2011
    Posts:
    1,614
    I did find out something which helped me - I was rendering a couple of big invisible quads via a third-party plugin.
     
  14. SeikoTheWiz

    SeikoTheWiz

    Joined:
    Aug 1, 2011
    Posts:
    69
    We solved our biggest "device.present" issue by simplifying our shaders
     
  15. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    The device.present problems you see here are caused by overdraw - stop filling the whole screen with transparent / ui and you are likely going much faster.

    iPhone4 / iPod Touch 4 / iPad1 have the same gpu as the 3gs generation but 4 / 5.2 times the pixel to render which the gpu is simply barely capable of doing -> alpha is a very bad idea if not used correctly, fullscreen effects are a no go and big particle systems will kill you too
     
  16. Allan-Smith

    Allan-Smith

    Joined:
    Feb 7, 2012
    Posts:
    57
    I've been struggling with this for quite some time... I've read this thread, and many others around the forums... but I just cant understand what is the problem.

    Here is my scenario: We are developing a 2D game, and the menu was running at 16 fps (with targetFrameRate set to 60) on the iPad 1. I profile it and Device.present is the villain. There is a lot of transparency on the menu, and 4 layers of background at different speeds, which adds up to a lot of transparency over the other. Anyway, reading about it, we made some changes, cut images into smaller ones, etc, and got to 24FPS, which is still bad. Then, after reading some more... we decided to do it other way... we modeled planes in the right shape for everything, so there is NOTHING transparent in the scene. The scene itself has 900 triangles with 8 simple objects, 4 different materials (all unlit), no overdraw (according to unity overdraw view), no scripts at all... and on the iPad 1 I still get only 45 FPS, which is good, but its not the possible 60 fps. On the profiler, the villain is still Device.present.

    If it were just for the menu, it would be ok, 45 is good, but I would like to understand why Device.present is still killing 1/4 of my fps for nothing, so I can improve other areas of the game that I am having the same problem.

    Thank you for your attention,
    Best regards,
    Allan
     
  17. superpig

    superpig

    Drink more water! Unity Technologies

    Joined:
    Jan 16, 2011
    Posts:
    4,657
    Have you turned off VSync? (I don't know if that's even possible on an iPad...)

    Assuming that VSync is on and the device is running at a 60Hz refresh rate, an average of 45FPS sounds like you're hitting every one-and-a-half frames (i.e. you just miss the first vsync and so present on the one after it, and then hit the vsync after that, repeat ad infinitum).

    It may also be that Device.Present is flushing buffers or something - a double-buffered GPU has to finish drawing to the backbuffer before it can present it as the front buffer, so if Device.Present is blocking then it may be because it's still drawing.
     
  18. Allan-Smith

    Allan-Smith

    Joined:
    Feb 7, 2012
    Posts:
    57
    Yep, VSync is turned off (at least on the quality settings)

    The real problem is that on the Menu we get 45 fps~, and on the game, we get about 45-48fps, but the enemies move as if they were lagged... its not a natural movement... initially they fall using rigidbodies and gravity until they reach the ground, and the fall is "laggy"... that is why I am concerned about this. This doesnt happen on any other device we`ve tested, the game runs at 60fps on iPhone 3GS... but feels laggy on iPad 1... =/
     
  19. kilik128

    kilik128

    Joined:
    Jul 15, 2013
    Posts:
    909
    same here don't understand


    $7Fr3A.png
    $7Fr3A.png
     
  20. Denis Kniazhev

    Denis Kniazhev

    Joined:
    Apr 4, 2015
    Posts:
    2
    I have created a test 2D project which consists just of a camera and a sprite (200Kb png image). The sprite has a rigidbody and a script which rotates it when a user touches the screen. So the longer user touches the screen, the faster the sprite rotates. I run it on an average Android 4.2.1 device (Lenovo P780). This runs mostly 60 fps but the frame rate drops to 30 every 3-5 seconds for couple of moments. When this happens, Device.Present takes 80% of farme execution time.
    My project quality settins are set to Fastest, meaning that vsync (and a bunch of other stuff) is disabled. But yet the frame rate drops because of Device.Present.
    I have also tried Tower Defence example on the same device, with Fastest quality settings, and it runs on 35-40 fps, dropping to 15-25, again because of Device.Present.
    I have downloaded a couple of non-Unity, pretty intense 2D games from play store and they seem to run solid 60 fps on the same device. On the other hand, all Unity android games which I tried felt a bit luggish: playable, but definitely not 60 fps. I wonder if they all suffer from Device.Present too...

    Is there any solution for this Device.Present issue?
     
  21. hakankaraduman

    hakankaraduman

    Joined:
    Aug 27, 2012
    Posts:
    354
    I also have Device.PresentAndSync showing on profiler that takes much time to process.

    I have 40k verts in my scene and just 3 different material, they all use mobile/diffuse material and 256x256 compressed textures.

    I still have 28-30 fps either on s3 and galaxy tab 2014 edition.
     
  22. Guillaumzed

    Guillaumzed

    Joined:
    Mar 29, 2015
    Posts:
    71
    I also have that device.present taking a maximum of resources (Total 86,3% Self : 85,6% !) on two of my scenes when I build and profile my game on Android. (with Vsync turned off or on, it doesn't change a thing)

    The first scene has only one canvas and 4 ameliorated buttons (meaning they are constituted of 4-5 UI layers). it runs, without animations at 20FPS. Quite ridiculous...
    The second scene uses a canvas too and a Pie from the "graph Maker" addon and run at approximately 30fps with one pie only and no animation. Ridiculous Too!

    The enigma is that I really don't underestand why those two scenes are doing that. My 4 other scenes, which display much more gameobjects run their 60fps.

    I'm working to understand why. I'll post here my eventual discoveries (if there is any)
     
  23. Guillaumzed

    Guillaumzed

    Joined:
    Mar 29, 2015
    Posts:
    71
    First solution :
    On one of my scene, it was an UI Image that was stretched which was doing the big mess.
    I found out that, if it was stretched (in any directions) with a bottom or a top NOT at zero, it was okay. But with all the values at 0 (left-right_top-bottom) : Boum, slow down "device.present" in the profiler.
    The solution in this case was to make a Sprite and a camera to replace my UI image that i wanted to stretch as a background image.

    It looks very much like a bug to me. I'll post that to the Unity dev team.

    For the other scenes, the problm seems different... still working on it.
     
    Last edited: Sep 12, 2015
  24. Peotor

    Peotor

    Joined:
    Jan 26, 2014
    Posts:
    2
    Here is what woked for me: I had more than one camera in scene, but while they all were enabled i had this "Perfomance hits", but when i disabled each of them except one i need at current moment, this problem disappeared.
     
  25. NGC6543

    NGC6543

    Joined:
    Jun 3, 2015
    Posts:
    228
    Hey, I have the same issue here.

    Screenshot.png
    A game runs on iOS iPod 5th generation shows major performance impact caused by Graphics.PresentAndSync.

    As you can see, Camera.Render finished within 6ms so the rendering isn't the issue. Same game runs smooth on iPhone 6, only iPod causes the problem. I turned off VSync, change Graphics API from Metal to OpenGL ES 2.0 but no success(It looks like iPod only supports OpenGL ES 2.0 anyway)

    When I run the game on iPod through XCode, output panel shows these warnings :

    WARNING: Shader Unsupported: 'Standard' - Pass 'FORWARD' has no vertex shader
    WARNING: Shader Unsupported: 'Standard' - Pass 'FORWARD_DELTA' has no vertex shader
    WARNING: Shader Unsupported: 'Standard' - Pass 'SHADOWCASTER' has no vertex shader
    WARNING: Shader Unsupported: 'Standard' - All passes removed
    UnloadTime: 21.868374 ms

    On iPhone using Metal doesn't show these warnings. But I don't use Standard Shaders anyway, so... What can be the problem??
     
    IgorAherne likes this.
  26. Serhii-Horun

    Serhii-Horun

    Joined:
    Apr 12, 2015
    Posts:
    151
    Yeah, I have the same issue! Any solution?
     

    Attached Files:

  27. FastPaolo71

    FastPaolo71

    Joined:
    May 5, 2015
    Posts:
    2
  28. rlaghdejr

    rlaghdejr

    Joined:
    Dec 6, 2013
    Posts:
    1
    To me it was my custom shader (for tutorial screen with rounded-box holes) causing it (around 60ms of it).
     
    Last edited: Jan 10, 2018
  29. laurG

    laurG

    Joined:
    Jun 1, 2017
    Posts:
    9
    Apparently this happens because of CPU related performance issues. In my case, I was using a SphereCast on Android in the FixedUpdate of a single object. I removed that and I got 60 FPS.
     
  30. tdx110

    tdx110

    Joined:
    Apr 25, 2020
    Posts:
    3
    I found the solution!
    In Build Setting furn off: 1.Deep Profiling Support 2. Script Debugging 3.Autoconnect Profiler
    I think Device.present is send data information to Unity. If you disable Developmen Build it will work normally.
    Zrzut ekranu (1).png
     
  31. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    2,455
    I appreciate that this area is nebulous but no it's not. It's about flipping the front buffer (the view frame the GPU was putting the results of it's computations on before they are shown) to the screen.

    Turning off script debugging is ALWAYS recommended when profiling as that impacts script performance. Deep profiling support adds a little bit of overhead, way more is added when you also USE it in the profiler by turning on Deep Profiling. For more accurate but less informative (on demand) profiling info, you might want to turn this off until you need it. Lastly Autoconnect just tries to hook the player up with the editor that build it. There's some issues with that that we're in the process of fixing but I wouldn't jump to those being an issue here beyond you getting a profiler attached and immediately having Deep Profiling on and affecting CPU performance.

    Why did turning all that off remove the Present times for you? Probably because your CPU frame timings where better due to less overhead, maybe no attached profiler or one that needs smaller data packages transmitted, which, due to using USB or wifi chips to transmit the data can thereby affect your power budget and heat which can have knock on effects on your CPU and GPU frequencies, (this is mostly an issue on mobile). Or your GPU frame was just started too late due to the overhead and ended up being GPU bound? Hard to tell without further information / timeline view screenshots showing main and render thread from mai thread start to render thread finish.

    Remember that on mobile, vSync is not an option the OS gives you, so present times include vSync and if you miss your v blank, present can take longer than expected. Always check in CPU timeline view when inspecting Render pipeline issues, check in with the profiler documentation, specifically the common markers page, and maybe read up on this blog post for background info on the rendering pipeline.

    Note on the Profiler documentation pages: ideally make sure you are on the page relating to your specific version, as the documentation adjusts for the changes happening in this space version over version, e.g. marker renames or additions.
     
  32. sparkkhuang

    sparkkhuang

    Joined:
    Apr 9, 2021
    Posts:
    9
    I have a similar question to answer, thank you.
    https://forum.unity.com/threads/why...lly-static-but-the-freeze-is-serious.1145033/
     
  33. Toolsmith

    Toolsmith

    Joined:
    Sep 29, 2016
    Posts:
    9
    I'm using URP in my Android project. I had issues with Device.Present with Multithreaded Rendering turned off and Gfx.WaitForPresentOnGfxThread with Multithreaded Rendering turned on. Both could steal up to 40ms on high end device with a lot of noticable spikes.

    After a while I noticed that I left default quality settings for Android devices completely unchanged - there was no URP asset attached, vSync was on etc.. Until now I was editing default settings for Windows devices.

    After I made things right I got rid of these fps drops. Now I'm getting almost stable 60 fps with profiler on (+/-5 fps with target frame rate set to 60fps). Now around 75% of each frame is taken by WaitForTargetFPS but i think that's a step froward (still I fell kinda silly for making that kind of mistake with quality settings).

    I was searching for solution in many different posts so I thought that I will come back and write it down so it could help anybody.

    Hava a great time!
     
  34. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    2,455
    Glad you found a solution to this.

    I'd say that's a leap forward. Mobile devices can't run faster than at their screen refresh rate and I'm guessing that your device has a 60Hz screen. Your CPU main thread seems to have plenty of time to cool down between frames, avoiding overheating and therefore thermal throttling. You should check in Timeline view how much of that WaitForTargetFPS is overlapping the Render Thread still spending busy with Camera.Render work, and how much of that is Gfx/Device.Present. if most of it is spend on the later your entire CPU is pretty much idle, which is a good thing (unless you are GPU bound on lower spec devices, then you might want to shift work from the GPU to the CPU).
    With that much room to spare you have space for more gameplay logic, can likely run smoothly on lower spec devices, use up less battery, can run in hotter climates...

    All that to say that: Seeing the CPU waiting for the target FPS, or VSync, doesn't have to be a problem.

    Especially on mobile, you shouldn't max out the system resources or your players will get a sub-par experience: hot phones that go stuttery and a battery that is dead after a 20 min play time is not something they'll appreciate. You'll also likely exclude lower spec devices entirely.
     
  35. StayThirsty

    StayThirsty

    Joined:
    Jul 6, 2013
    Posts:
    42
    @MartinTilo
    So I am having the same issue however it doesn't happen consistently. After running the game on my Android and waiting anywhere between 2 minutes to 30 minutes I will eventually have incredible performance drop until the game freezes and crashes. Screenshot 2022-02-18 231809.png 176,000 ms!!! :eek:

    I am using unity 2021.2.11f1 with ECS, unity physics, unity platforms.android and the hybrid renderer. All of which are preview so that could be the reason for this extreme ms
     
    Last edited: Feb 19, 2022
  36. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    2,455
    Do you per chance have the Player Setting "Optimize Frame Pacing" on? And if so, dies the crash go away when you turn it off? There is a super-hard-to-track-down bug in there for which we only have anecdotic reports but no bug report, so if that solves it, please please please report a bug via the Editor menu
    Help > Report A Bug
    with your project attached so that we can get that sorted out.

    If it's not that, you look to be choking out your GPU and might want to use a native Android profiling tool based on which GPU your phone has, e.g. ARM Mobile Studio to analyze this further. Or you might be able to infer some things by checking your Rendering Profiler Module and your Render thread in CPU timeline view and see if anything odd is piling up before the crash.
     
  37. StayThirsty

    StayThirsty

    Joined:
    Jul 6, 2013
    Posts:
    42
    Hello and thanks for your reply!

    Optimize Frame Pacing was enabled but unfortunately disabling it didn't stop the crash :(
    The scene is essentially empty with about 3 UGUI images. I used this basic scene to test if my main scene was causing the issue but it appears not

    I also removed all the packages (ECS, com unity physics, platforms android, hybrid renderer) but still had the crash

    I found this thread where others seemed to have similar issues and you were also helping them there:
    https://forum.unity.com/threads/and...h-playerloop-in-profiler-at-60-000-ms.863143/

    Someone had claimed that the Tilemap was causing his game to crash despite disabling Optimize Frame Pacing. I have (had) Tilemap as well but wasn't using it so I removed it as well. Will see if it crashes

    Edit: Removing Tilemap didnt help. This fps drop happens even on a brand new project. I am running more tests to see if disabling Optimize Frame Pacing fixes it
     
    Last edited: Feb 20, 2022