Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Resolved Gfx.WaitForPresentOnGfxThread takes long time

Discussion in 'Universal Render Pipeline' started by hundredMS, Sep 10, 2020.

  1. hundredMS

    hundredMS

    Joined:
    Dec 28, 2017
    Posts:
    4
    Hello,
    We are using Unity 2019.4.8f1, VSync is set to Every V Blank and we use Multithreaded Rendering. The issue is Gfx.WaitForPresentOnGfxThread takes long time to finish its job. We profiled the project on Android platform and here is the results:

    Ekran Alıntısı.PNG


    We have done some research about this problem and we found out that CPU is waiting for GPU to finish its job but as we can see in the image, GPU (11.71ms) takes less time than CPU (52.84ms). We don't understand what is going on here, we need some help here. Thank you.
     
  2. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    934
    Hi,
    Did you set Application.targetFrameRate = 60? At it's default of -1, it'll choose 30 on most devices. (Though technically targetFrameRate should be ignored if vSyncCount is set)
     
  3. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    934
    Also, how do the timings on your Render Thread look like when looked at through the CPU Usage Profiler Module's Timeline view? It could also be the combination of Render Thread timings + GPU present timings(which include vSync but also parts of those 10-11ms) that push your frames past 16.66ms.
     
  4. hundredMS

    hundredMS

    Joined:
    Dec 28, 2017
    Posts:
    4
    Thanks for quick response. We created a new URP Project with the same configuration as our project and instantiated 900 primitive cubes with same material and shader (URP/Simple Lit). We set Application.targetFrameRate to 60. We still get the same results. You can see the CPU Usage Profiler Module's Timeline view:

    Ekran Alıntısı.PNG
     
  5. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    934
    WaitForPresentOnGfxThread.PNG
    Well that orange box here shows how much time is spend just on the CPU to render that frame, starting from when the last frame was done getting presented. Eyeball measurement says that's ~32ms. Now I wouldn't expect the GPU to finish drawing such a frame in ~1ms so that means the frame has already slipped by two vBlanks (one at 16.66ms. one at 33.3 ms frame time).
    The yellow box marks the Gfx.Present sample and contains vSync time as well as time just generally waiting for the GPU to finish drawing the frame. I wouldn't be too surprised to see that the GPU time for this frame in this scenario would be above 16 ms too, so you'd also be missing the vBlank at the 50 ms mark and that's how you end up with a frame getting flipped (presented) to the screen at the 4th, 66.6ms vBlank.

    So you are both overburdening the CPU and the GPU with that frame. Maybe the Frame Debugger can help you see if you are using batching and if there is anything else to look out for when trying to optimize this :)
     
    hundredMS likes this.
  6. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    934
  7. hundredMS

    hundredMS

    Joined:
    Dec 28, 2017
    Posts:
    4
    We have watched the video you send and read the document, we gained some useful information from those but still we couldn't fix the problem. We created a new project without URP and we used the same configuration as before. We used Mobile/VertexLit(Only Directional Lights) as shader on cubes. Here is the profiler result:

    Ekran Alıntısı.PNG
    As you can see Gfx.WaitForPresentOnGfxThread does not take much time in this project. We were expecting that URP has better performance over normal Unity project. We are wondering if we are using URP as it suppose to be.
     
  8. Sky77

    Sky77

    Joined:
    Jan 30, 2014
    Posts:
    37
    To be fair, the Mobile/VertexLit shader is a lot less complex than the SimpleLit shader in URP, you really can't compare them.
     
    MartinTilo likes this.
  9. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    934
    I'm not firm enough with URP to comment on that but what @Sky77 mentioned seems valid enough. Make sure that the shaders are somewhat more comparable than Vertex Lit vs non Vertex Lit.
     
  10. hundredMS

    hundredMS

    Joined:
    Dec 28, 2017
    Posts:
    4
    We found this post and we decided to build our project with Built-in Render Pipeline. This may help you, thanks for your support.
     
  11. Sky77

    Sky77

    Joined:
    Jan 30, 2014
    Posts:
    37
    It really depends on what you’re doing. We’ve used LWRP extensively and we’re using URP on mobile now (iOS only), and there’s simply no way we can achieve the same performances / visual quality using built-in.
     
    hundredMS likes this.
unityunity