Search Unity

LOD Crossfade breaks the (SRP) batcher. Worst than Legacy.

Discussion in 'Universal Render Pipeline' started by NuclearC00kie, Jan 28, 2020.

  1. NuclearC00kie

    NuclearC00kie

    Joined:
    Apr 11, 2019
    Posts:
    32
    Unity version: 2019.3.0f5
    URP version: 7.1.8

    We noticed a huge FPS drop when using non-animated crossfade on LODGroups.
    Here are a few comparision numbers of the same scene and same view, with and without LOD crossfade:

    * No fade mode
    - Shadows on: 29 SRP batches, 31367 batches, 33ms CPU, 6.5ms GPU, 6.5k verts
    - Shadows off: 11 SRP batches, 14599 batches 24.2ms CPU, 6.3ms GPU, 6.5k verts
    * Fade mode: crossfade (no animate), settings 0.2
    - Shadows on: 4323 SRP batches, 33674 batches, 78ms CPU, 36.3ms GPU, 6.6K verts
    - Shadows off: 975 SRP batches, 15119 batches, 30ms CPU, 14ms GPU, 6.5k verts

    SRP batches number comes from the frame debugger, the other values come from the stats window.

    As you can see, enabling crossfade breaks the SRP batcher.
    My best guess is that it's caused by the LOD_FADE_CROSSFADE keyword, being toggled on / off for each object that should crossfade.
    I do however think that the sorter or batcher can do a better job here. Only +- 20% of the rendered objects are affected by the crossfade but the batcher is almost 1000 times less effective. You can also clearly see that the GPU time to render is a lot higher with crossfade on.

    Yellow objects have LOD_FADE_CROSSFADE false, red objects have LOD_FADE_CROSSFADE true

    upload_2020-1-28_10-10-43.png

    Please also note the effect that the SHADOWS have on the batches and performance.
    In this scene, there is only a directional light but the impact of the shadows is HUGE.

    2. How we can reproduce it using the example you attached
    * Load LODScene
    * Investigate state of the Obj prefab. Check if lodgroup fade mode is "None" or "Crossfade".
    * Press play and take note of the performance in the scene (use frame debugger to get SRP Batch numbers)
    * Toggle the value of the lodgroup in the Obj prefab from None to Crossfade or the other way around
    * Press play and take not of the performance in the scene (use frame debugger to get SRP Batch numbers)
    * Notice SRP batch count and detrimental performance when enabling crossfade.

    EXTRA
    * Open the UniversalRP-HighQuality asset and toggle "Cast Shadows" on or off.
    * Notice HUGE differences in performance


    These are the numbers on legacy pipeline, with the same scene:

    * No fade mode
    - Shadows on: 5958 batches, 53ms CPU, 20ms GPU, 4.1M verts
    - Shadows off: 464 batches, 24ms CPU, 4ms GPU, 655K verts
    * Fade mode: crossfade (no animate), settings 0.2
    - Shadows on: 18947 batches, 68ms CPU, 37ms GPU, 4.2M verts
    - Shadows off: 2409 batches, 27ms CPU, 10ms GPU, 667k verts

    Issue tracker numbers: 1214825 and 1214826
     
    StenCG and goncalo-vasconcelos like this.
  2. NuclearC00kie

    NuclearC00kie

    Joined:
    Apr 11, 2019
    Posts:
    32
    LOD Crossfade shader:
    upload_2020-1-28_10-17-47.png
    upload_2020-1-28_10-18-55.png

    LODGroup setup: (Same on each LOD level)
    upload_2020-1-28_10-20-12.png
     
  3. sebsmax

    sebsmax

    Joined:
    Sep 8, 2015
    Posts:
    118
    Amazing report, I couldn't done something as detailed.
    However, I've witnessed the same behavior!
     
  4. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,225
    Can you raise this as a bug so we can look into it?
     
  5. NuclearC00kie

    NuclearC00kie

    Joined:
    Apr 11, 2019
    Posts:
    32
    Hi @Tim-C

    I already did.
    I actually have put the ticket numbers in the initial post...

    > Issue tracker numbers: 1214825 and 1214826

    Note that I've changed the LOD crossfade shader for this forum post, after submitting the bug, to make it more readable (yellow and red, instead of a dither crossfade). All values measured are from the bug report.

    Cheers
     
  6. arnaud-carre

    arnaud-carre

    Unity Technologies

    Joined:
    Jun 23, 2016
    Posts:
    97
    hi @NuclearC00kie

    Thanks for your detailed bug report. There is something strange here. We can repro. We will investigate your test scene case a bit more and let you know if we get more details.
     
    NuclearC00kie likes this.
  7. Fishing_Cactus

    Fishing_Cactus

    Joined:
    Nov 8, 2014
    Posts:
    45
  8. o1o101

    o1o101

    Joined:
    Jan 19, 2014
    Posts:
    639
    Thank you very much for reporting this, I noticed much worse performance with the SRP batcher & this could possibly explain it! Was using LOD crossfade on many objects.
     
    Fishing_Cactus likes this.
  9. arnaud-carre

    arnaud-carre

    Unity Technologies

    Joined:
    Jun 23, 2016
    Posts:
    97
    Hi!

    After investigation the cross-fade shader variant was not part of our sorting criteria. So after the sort, when processing render nodes in the batch, we could break the batch very often if rendernode crossfade differ from the previous one ( introducing a large slow down)
    We will fix that by using cross(fade information in our sorting. You will get benefit whatever SRP batcher is ON or OFF. Here is a screenshot of timing with the fix. Please note that in this specific scene, speedup with the fix is even higher when disabling SRP batcher, because GPU instancing could run at its best in this synthetic scene. ( GPU instancing wasn't efficient in previous version also because of the wrong sorting )
    upload_2020-2-5_17-4-46.png

    We will ensure that this fix will be back ported to 2019.3.
    To be fair, the speedup won't be so big in a real-life game scene ( I mean, this benchmark scene renders tons of objects in a "crossfade state")
     
    zalogic, forestrf, phil_lira and 2 others like this.
  10. Lars-Steenhoff

    Lars-Steenhoff

    Joined:
    Aug 7, 2007
    Posts:
    3,527
    Thanks for the fix, when I have a dense forest there will be many objects in a crossfade state at the same time, seems this will be helpful
     
    hippocoder likes this.
  11. NuclearC00kie

    NuclearC00kie

    Joined:
    Apr 11, 2019
    Posts:
    32
    That's wonderful news @arnaud-carre Thanks a lot!
    This will also make a big impact for our games. the crossfade code was really on the hot path :)
     
  12. arnaud-carre

    arnaud-carre

    Unity Technologies

    Joined:
    Jun 23, 2016
    Posts:
    97
  13. NuclearC00kie

    NuclearC00kie

    Joined:
    Apr 11, 2019
    Posts:
    32
    Thank you for the fast fix Arnaud!