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

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

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.

  1. 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

2 Likes

LOD Crossfade shader:


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

Amazing report, I couldn’t done something as detailed.
However, I’ve witnessed the same behavior!

Can you raise this as a bug so we can look into it?

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

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.

1 Like

Thank you @arnaud-carre ! Looking forward to your reply.

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.

1 Like

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 )

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”)

5 Likes

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

1 Like

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 :slight_smile:

Hi everyone,

The fix just landed in Unity 2019.3.2f1, available here Unity 2019.3.2

3 Likes

Thank you for the fast fix Arnaud!