Search Unity

Question Performance regression after updating to 1.0exp

Discussion in 'Graphics for ECS' started by TieSKey, Oct 1, 2022.

  1. TieSKey

    TieSKey

    Joined:
    Apr 14, 2011
    Posts:
    225
    After updating from 0.51 to 1.0exp I'm getting a heavy performance regression in my game but I really don't know how to interpret the profiler data (see attached image).
    Is that wait the CPU waiting for the GPU? gpu profiling is not available in Vulkan...

    To give some context, I have around 50k entities, most of them hidden by frustum culling at the moment of taking the profiler ss so probably only a few hundred actually visible. Using only 5 materials with custom shaders. All materials and meshes are stored in the same RenderMeshArray.

    The thing is, I get around 80fps on the same machine in the same scene when using 0.51 on 2021.3.10
    Nothing changed from my side except for the migration from 0.51 to 1.0 and well, HDRP was updated by default since it's tied to the editor version.

    Any idea on where to start looking?
    Thx in advance.

    Unity_2022-09-30_21-17-04.png
     
    Last edited: Oct 1, 2022
  2. DreamingImLatios

    DreamingImLatios

    Joined:
    Jun 3, 2017
    Posts:
    4,266
    It is a lot easier to diagnose these issues if you switch your profiler view to timeline mode. Then you can see what all your threads are doing at once and it becomes a lot easier to identify differences.
     
  3. joelv

    joelv

    Unity Technologies

    Joined:
    Mar 20, 2015
    Posts:
    203
    No this is not the CPU waiting for the GPU. It's an performance regression in the C++ parts of Entities Graphics that we ourselves just found out about yesterday and it only affects very heavy scenes. We will try to fix it as soon as possible and already have a plan. It will require us to land and get released in some future 2022.2 beta though so it can take some time.
     
    eizenhorn, TieSKey, JesOb and 2 others like this.
  4. optimise

    optimise

    Joined:
    Jan 22, 2014
    Posts:
    2,129
    C++ parts of Entities Graphics do u mean BRG?
     
  5. joelv

    joelv

    Unity Technologies

    Joined:
    Mar 20, 2015
    Posts:
    203
    Yes. This is in the BatchRendererGroup draw command injection code, which allows commands to be injected between game objects and sorted correctly.
     
    JesOb and optimise like this.
  6. TieSKey

    TieSKey

    Joined:
    Apr 14, 2011
    Posts:
    225
    Ouch.
    Thx for the quick response, now I can stop pulling my hair.
    Have a great weekend.

    Edit:
    btw, just to add more info and make sure it's the same bug. Entities with transparent materials seems to affect performance orders of magnitude more than opaque ones. Like, on a different machine with a better gpu, we can get 50fps on a scene with a few thousand opaque entities visible (still lower than before), but only 10fps on another with less than a hundred transparent ones.
     
    Last edited: Oct 1, 2022
  7. joelv

    joelv

    Unity Technologies

    Joined:
    Mar 20, 2015
    Posts:
    203
    I think this bug hits transparent entities harder than opaque. Transparent entities needs to get sorted so they will be separate draw commands as they cannot use instancing. The bug causes a slowdown per draw command so it's not impossible that a fix will help this as well.

    Transparent entities will be slower than opaque though, just because it cannot instance and needs to get sorted to get correct results. Right now there is no way getting around that
     
    TieSKey likes this.
  8. TieSKey

    TieSKey

    Joined:
    Apr 14, 2011
    Posts:
    225
    Is there a public issue to follow progress on this? I'm not fond of having to read every beta release notes :p
    Thx.
     
  9. joelv

    joelv

    Unity Technologies

    Joined:
    Mar 20, 2015
    Posts:
    203
    No, not that I am aware of. We'll make sure to post here in this thread and say what unity version the fix lands for (we can see this as soon as the fix lands).
     
  10. DreamingImLatios

    DreamingImLatios

    Joined:
    Jun 3, 2017
    Posts:
    4,266
    Ok. I finally got one of my test projects fully functional in 2022.2.0b10.
    This regression is bad!

    Simulations roughly an order of magnitude smaller compared to what I used to ship with solid 60 FPS performance on 5 year old gaming machines is now struggling to hit 30. Profiler view of the timeline shows worker threads being hit hard with RenderLoop.Prepare instances. I even modified all my alpha-faded shaders to instead use opaque dithered fade and it is still bad.

    2021: https://github.com/Dreaming381/lsss-wip/tree/24a465fc3d1a3ccf2a2c3574e6329e03cf4f7c4b
    2022: https://github.com/Dreaming381/lsss-wip/tree/c0bae69215a4480a35716403d23279ac4b9fe2f4

    In the scenes folder, there is a v2 and a v3, and any of the missions inside of them should be immediately playable. Higher mission numbers feature larger simulations. Missions numbered 3 and 4 are where I see regressions for simulation sizes which aren't usually problematic.

    Feel free to use and abuse this project if it helps you resolve the regression and/or communicate progress.
     
  11. joelv

    joelv

    Unity Technologies

    Joined:
    Mar 20, 2015
    Posts:
    203
    Yeah it is a bad regression, and we are really sorry about letting that slip through.
    The fix is entering testing now and we hope to be able to land it as soon as possible. Hopefully you don't have to wait too long for it to arrive.
     
  12. DreamingImLatios

    DreamingImLatios

    Joined:
    Jun 3, 2017
    Posts:
    4,266
    No worries. That's what beta is for. :D Glad you figured it out. And thanks for being so responsive!
     
    JussiKnuuttila and TieSKey like this.
  13. joelv

    joelv

    Unity Technologies

    Joined:
    Mar 20, 2015
    Posts:
    203
    The fix has landed for 2023.1.0a17, we are still in the process of landing for 2022.2 and will get back to you when we have a known version for that.
     
    bradshep, bb8_1, chemicalcrux and 9 others like this.
  14. JussiKnuuttila

    JussiKnuuttila

    Unity Technologies

    Joined:
    Jun 7, 2019
    Posts:
    351
    The fix for the performance regression has landed in 2022.2.0b15. Hopefully, you should see a significantly better performance with that version!
     
  15. Fribur

    Fribur

    Joined:
    Jan 5, 2019
    Posts:
    136
    Excellent job..can finally reap the full benefits from BRG!!!! In a heavy scene with thousands of tiny meshes framerate jumped from 90FPS to 390FPS (without BRG in Entities 0.51 it was ~290 FPS). You can most certainly be proud of this fundamental overhaul.
     
    joelv and JussiKnuuttila like this.
  16. DreamingImLatios

    DreamingImLatios

    Joined:
    Jun 3, 2017
    Posts:
    4,266
    I just tried beta 15. The selected marker used to take 80 milliseconds in the same scene in beta 10.

    upload_2022-11-17_20-22-36.png

    However, at Mission 5, I see this:
    upload_2022-11-17_20-39-43.png
    I'm not sure what is going on with the ScheduleDraw, but I don't remember this being a thing in 2020.3.

    Also, at this scale, I sometimes get spammed with errors "Assertion failed on expression: IsFinite(distanceAlongView) and similar for IsFinite(distanceForSort). And the game will flash white sometimes when these errors start spamming.

    It seems that something still thinks there are transparent draws despite switching to dithered fades, so I will investigate that.

    Edit: Fixed the transparency issue. Apparently changing the settings in Shader Graph don't propagate to the already-created materials. However, opaque has the same performance and I still get the errors from the few objects that are still using transparent shaders.
     
    Last edited: Nov 18, 2022
  17. JussiKnuuttila

    JussiKnuuttila

    Unity Technologies

    Joined:
    Jun 7, 2019
    Posts:
    351
    This suggests that something related to BatchDrawCommand.sortingPosition could be going wrong. For example, invalid positions resulting in NaN distances getting computed, which could explain both the assertions and the performance hit, as invalid sorting distances could lead to very bad sorting orders.
     
  18. DreamingImLatios

    DreamingImLatios

    Joined:
    Jun 3, 2017
    Posts:
    4,266
    You were right! I had NaN position values that were specific to the very large scenes. So the old beta 10 BRG regression numbers were still valid, but I now have new numbers for this extreme scale.

    Those numbers are weird.

    In full transparency mode, the fix brought ExecuteRenderGraph times from 5.5 ms to 4.5 ms.

    But in Opaque dithered mode, the fix brought ExecuteRenderGraph times from 5.5 ms to 0.75 ms.

    I don't really understand why opaques benefitted from the fix since they have nothing to sort, but performance is excellent now and I am error free. Amazing job! :D