Search Unity

Question Breaking woes with SRP Batcher and Shadows

Discussion in 'General Graphics' started by Kolyasisan, Jan 20, 2021.

  1. Kolyasisan

    Kolyasisan

    Joined:
    Feb 2, 2015
    Posts:
    397
    Hello.

    We're using a custom SRP in our project and recently we've performed certain optimizations in order to reduce individual SRP Batches and increase Draw Calls amount in them. We've done this by writing a tool that would clean-up unused shader keywords and reducing the amount of various keywords themselves, instead moving as much as possible into branches based on uniform properties.

    So far so good, this optimization gave us a noticeable speedup: now there are less SRP Batches with more draw calls in them. However, the shadows don't appear to work with it quite well...

    When rendering shadows, SRP Batcher tends to break quite a bit of them with a description of "Objects either have different shadow casters, or have different properties/keywords that affect the output of the shadow caster pass".

    However, I am genuenly confused about this and I need help resolving this issue or at least clarifying it. I've pasted 2 screenshots of sequential SRP batches, which use *the same shader and shader keywords*. Granted, there are different textures between those two, but there's no such issue when rendering with DrawRenderers, batches produced by those can do multiple drawcalls with different textures. Batches break only if there's a new shader, a different set of shader keywords or some property modifies the draw state (a different cull/stencil value).

    If it's not a bug, then why was it done this way? What's so different between drawing them via DrawRenderers and drawing them via DrawShadows? How can I resolve such an issue? Currently, draw calls are a bottleneck for one of our target platforms and we would've liked to speed them up by reducing the amount of individual SRP Batches.
     

    Attached Files:

  2. Kolyasisan

    Kolyasisan

    Joined:
    Feb 2, 2015
    Posts:
    397
    Or how about this? Now there's not a single bit different between those two SRP Batches, yet they still break because of that same reason.
     

    Attached Files:

  3. Autarkis

    Autarkis

    Joined:
    Oct 10, 2011
    Posts:
    318
  4. Kolyasisan

    Kolyasisan

    Joined:
    Feb 2, 2015
    Posts:
    397
    Never did, unfortunately. But maybe the issue is due to profiling SRP batcher drawcalls originating from different threads? I'm in the dark on this one.