Search Unity

SRP batcher unity 2020

Discussion in 'Shaders' started by FGoset, Nov 6, 2021.

  1. FGoset

    FGoset

    Joined:
    Sep 26, 2018
    Posts:
    4
    I'm on Unity 2020.2.2f1 and I'm following this Catlike Coding Tutorial: https://catlikecoding.com/unity/tutorials/custom-srp/draw-calls/
    When I get to the point of making the shader compatible with the SRP batcher and enable it in the code, the number of draw calls don't change.
    Is it a known bug ?
    Is there something new in 2020 to do so that the batcher work ?
     
  2. Sluggy

    Sluggy

    Joined:
    Nov 27, 2012
    Posts:
    984
    I had the exact same issue about a year ago when I picked up where I'd left off with that series. On 2019, the display showed the batches saved and in 2020 it did not.

    Fear not though! If you use the Frame Debugger you can indeed see that your batches are working properly (assuming that your shaders are written correctly). Honestly, I'd recommend using the Frame Debugger even if the 'saved draws' display worked anyway as it gives much more useful information about what is happening and why.
     
  3. FGoset

    FGoset

    Joined:
    Sep 26, 2018
    Posts:
    4
    Well. i don't know if it works properly or if i'm only confused with the frame debugger values.
    I have 64 objects with the same material.
    The frame debugger displays only one SRP Batch but when I select it, it says there are 64 draw calls.
     
  4. Sluggy

    Sluggy

    Joined:
    Nov 27, 2012
    Posts:
    984
    It sounds like it is working properly. SRP batching doesn't actually reduce draw calls but instead, reduces the number of state changes and the amount of data being fed to the GPU before drawing. Draw calls themselves haven't been a large source of overhead since the original DX9 days (at least on PC. I can't say for other platforms) which was well over a decade ago now. However, state changes like setting textures and various shader properties DO still have a good bit of overhead so the SRP batcher attempts to alleviate this by batching many different material properties together into a list and then accessing them by offsets during the rendering phase.

    The SRP batcher requires that you use the same shader for everything that is to be batched. For this reason, when you are planning to use the SRP batcher you want to use as few shaders or shader variants as possible (ideally none) and instead use a few 'uber shaders' with lots of configurable properties that are determined at render-time (NOTE: this means you can't use multi-compile properties as these create shader variants which are essentially just different shaders with hard-coded values). Even if many objects have many different configurations on many different materials, as long as they are all using the same shader the SRP can collectively upload all of the different values and index into them as needed - thus, allowing it to perform very fast draw calls with minimal overhead.

    Here is a link from the Unity docs with some helpful diagrams if you want a visual overview of what is happening. https://docs.unity3d.com/Manual/SRPBatcher.html
     
  5. FGoset

    FGoset

    Joined:
    Sep 26, 2018
    Posts:
    4
    Thanks for the infos.I never found this doc before.
    Obviously I'm following this tutorial on PC, but I'm working on smalller devices where the draw calls can have an overhead.
    Anyways draw calls are not really a botleneck in my current project. I was mainly following this tutorial to write my own render pipeline as I suspect that is the part where I can get the most performance.
    But it's always useful to get knowledge of every part of the graphical environment. And your informations will probably be useful to me in the future.
     
  6. Sluggy

    Sluggy

    Joined:
    Nov 27, 2012
    Posts:
    984
    Yeah, when it comes to mobile I can't say I know so much. But according to that page I linked it does not appear that Android is on the list of platforms that support SRP batching so keep that in mind. But if all you're doing is trying to make a pipeline that removes all of the stuff you don't need it's probably going to be faster even without the batching.

    And I've actually been using the same tutorial series for writing my own super light-weight pipeline. It's a super helpful series. That site in general has been a lifesaver many times over the years!