Search Unity

Clear takes extremely long on Android

Discussion in 'General Graphics' started by ayellowpaper, May 2, 2019.

  1. ayellowpaper

    ayellowpaper

    Joined:
    Dec 8, 2013
    Posts:
    52
    Hey everybody,

    I'm building a game for android and wanted to profile my game because I noticed low framerate. When profiling I noticed that clearing the buffer takes 10ms, which is 72%. I honestly don't understand how it could take that long. I'm using Unity 2019.1.0f2, building for Android and playing/profiling on a Huawei P20 Lite. I'm using the forward renderer (not the new rendering pipeline) and the lowest quality settings.

    Clear.png

    Any help is highly appreciated. Thanks in advance!
     
  2. aleksandrk

    aleksandrk

    Unity Technologies

    Joined:
    Jul 3, 2017
    Posts:
    3,014
    This phone has a huge screen resolution (1080 x 2280) and an entry-level GPU (Mali-T830 MP2), so the behaviour you see is expected.

    On the other hand, the screenshot shows that you have 16.8ms CPU time and 14.17ms GPU time, so you're not GPU bound :)
     
  3. ayellowpaper

    ayellowpaper

    Joined:
    Dec 8, 2013
    Posts:
    52
    Thank you for the reply aleksandrk.

    The CPU is waiting for VSync on mobile. It's actually only working for 2ms and waiting the rest of the time. I'll include the CPU Usage next time.

    I know the Huawei P20 Lite doesn't have a strong GPU. I'm still trying to actually understand where the time consumption comes from. I want to learn. I've created an empty project, set the camera Clear Flags to "Don't Clear". I've once rendered nothing, then 1 cube, and then 100 cubes. The results:

    - nothing: pretty much 0 ms
    - 1 cube: ~7ms
    - 100 cubes: ~12ms

    I noticed that going from nothing to just one cube incurs a big overhead. Also interesting to note is that once the clear flag was changed, Unity allots the time to Render.Mesh instead, because it actually doesn't get any faster.

    Clear2.png

    I'm rendering a simple cube with an unlit shader which has nothing but a color property, and Unity tells me it takes 7ms. I assume that there is some initialization happening in the background that Unity doesn't tell me about, which takes a lot if time, and Unity simply adds it to the ms of whatever calls it first. First it was Clear, now it's Render.Mesh.
    I'll just accept that profiling the GPU isn't as transparent as it could be and work with what I have.

    Thank you for your time.
     
  4. aleksandrk

    aleksandrk

    Unity Technologies

    Joined:
    Jul 3, 2017
    Posts:
    3,014
    It can be more transparent if you use vendor-specific profilers, one from ARM in your case.

    I'm pretty sure that the data you get in the Unity profiler for the CPU time is accurate. If the CPU is waiting for VSync that much, then it has nearly nothing to do for it. The GPU might've finished the work already as well, but there's no possibility to turn VSync off on mobile. As long as you're hitting your target frame rate, you're good :)
     
    ayellowpaper likes this.
  5. mhmtemnacr

    mhmtemnacr

    Joined:
    Mar 7, 2013
    Posts:
    15
    So, if cpu is waiting for vsync for too long, there is nothing i can do to solve?

    I have the same problem btw. Getting 11 fps on low-middle spec android phone (but it can run other games smoothly). Scene and Models are not complicated. I couldnt find why the game is lagging too much.
     
  6. aleksandrk

    aleksandrk

    Unity Technologies

    Joined:
    Jul 3, 2017
    Posts:
    3,014
    Do you have any postprocessing enabled?
     
  7. mhmtemnacr

    mhmtemnacr

    Joined:
    Mar 7, 2013
    Posts:
    15
    No. Im using builtin render engine btw (no urp).

    Here is profiler screenshot of gpu :

     
  8. aleksandrk

    aleksandrk

    Unity Technologies

    Joined:
    Jul 3, 2017
    Posts:
    3,014
    And what's happening on the CPU side?
     
  9. mhmtemnacr

    mhmtemnacr

    Joined:
    Mar 7, 2013
    Posts:
    15
    Semaphore.WaitForSignal takes the most of cpu time.

    And i think shadows are the problem. When i disable them i can get 60 fps.

    But i need it (directional light & baked)
     
  10. aleksandrk

    aleksandrk

    Unity Technologies

    Joined:
    Jul 3, 2017
    Posts:
    3,014
    This means the GPU is doing too much work.