Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question Batching does not work

Discussion in 'General Graphics' started by neuen12345, Jul 2, 2023.

  1. neuen12345

    neuen12345

    Joined:
    Jul 2, 2023
    Posts:
    4
    Batching in Unity is not working.

    I have a minimally configured Scene and placed 10 Cubes or Quads that can be created from right click.
    My guess is that these should work with Dynamic Batching, but when I look at the Game View, the number of batches is shown as 10.

    However, when I place a particle, the Batch Count increases by one, so it seems that Dynamic Batching is enabled as a project setting.

    I tried copying and pasting the Material of the Particle where Batching is enabled for the Cube and Quad I placed, but it doesn't seem to make sense.

    The Frame Debugger has a
    "Why this draw call cant be batched with the previous one".
    "SRP: First call from ScriptableRenderLoopJob"
    but I don't know what it means.

    Please let me know the cause.
    If there is a way to confirm that Dynamic Batching is working with Unity's default assets, which can be added by right-clicking, please let me know that too.

     
  2. kdgalla

    kdgalla

    Joined:
    Mar 15, 2013
    Posts:
    4,326
  3. neuen12345

    neuen12345

    Joined:
    Jul 2, 2023
    Posts:
    4
    hi kdgalla.

    I could understand that particle and mesh object are different.

    I read the linked topic.
    So you are saying that the dynamic batch processing is not running on this image because it is skipped because the number is small and dynamic batch processing is more demanding?

    I have increased the number by about 1000 and still no dynamic batch processing is being executed.
    Of course, it may not be that simple of a mechanism, but as a first step in solving the problem, I want to make sure that the mesh object dynamic batch is working by creating a minimum scene first.
    Can I use Unity's default assets to check?

    thank you.
     
  4. kdgalla

    kdgalla

    Joined:
    Mar 15, 2013
    Posts:
    4,326
    I didn't say that and I didn't see anywhere in the manual that says that, so I'm not sure what you are talking about here. There are other factors listed that could prevent batching, though, so make sure that they don't apply in your case.
     
  5. DevDunk

    DevDunk

    Joined:
    Feb 13, 2020
    Posts:
    4,362
    You use a scriptable render pipeline, which uses SRP batching first and has dynamic batching as a fallback.
    The setpass calls are the actual draw calls being issued to the GPU. This is just 4 in the screenshot, which seems good. Check the frame debugger to see the draw calls in depth.

    If you want to use dynamic batching instead, you have to disable SRP batching or break SRP batching in the specific shader so it falls to dynamic.
     
  6. Sluggy

    Sluggy

    Joined:
    Nov 27, 2012
    Posts:
    839
    Just as a heads up though, SRP batching is far far far superior to dynamic batching in every way. So really, just try to use shaders that support it and prefer to reuse shaders more than anything.
     
  7. DevDunk

    DevDunk

    Joined:
    Feb 13, 2020
    Posts:
    4,362
    Isn't dynamic batching slightly faster if implemented ideally?
    (but 99/100 times not worth manually managing)
     
  8. neuen12345

    neuen12345

    Joined:
    Jul 2, 2023
    Posts:
    4
    I found out that SRPBatcher and Batching are exclusive and that I need to try SRPBacher first.

    I have an additional question: to confirm that SRPBatcher is working, do I just check the `SetPass calls` in the SceneView Stats window?
    Whether Batches is 1000 or 5000, if `SetPass calls` is a low number, it may mean that Batches is not working, but SRPBatcher is reducing the load?

    I had titled this topic `Batching does not work`, but what I essentially want to do is reduce the load.
     
  9. DevDunk

    DevDunk

    Joined:
    Feb 13, 2020
    Posts:
    4,362
    Setpass calls is draw calls yes.
    To see it more accurately check the frame debugger
     
  10. Sluggy

    Sluggy

    Joined:
    Nov 27, 2012
    Posts:
    839
    If by 'ideally' you mean 'once at startup' then sure? Maybe? Under the right circumstances. But then this really is more like 'runtime static batching'. To be fair, I guess I wasn't very clear when I wrote it but when I said 'superior' it wasn't just in terms of performance but also flexibility too. While it can be a bit of a pain writing shaders from scratch that work well with the SRP batcher the flexibility you get with what you can throw at the renderer is totally worth it!


    You can use the Frame Debugger to see what was combined into SRP batches. If something can't be combined then it will say so and explain why. As for how to judge how well it works - at a glance I find SetPass counts to be pretty reliable.

    To give some perspective on how big of a difference the SRP batcher makes - I have a very dynamic scenario for my current game project that requires loads of characters on the screen, all of them can be dressed with separate outfits and they can all be colored individually. Each and every one of them has their own mesh and material. But they all share the same shader for everything. I was doing a stress test with several hundred of these characters onscreen at once and I think I topped out around 20k-25k draw calls but my SetPass calls were only around 100 so I managed to stay under 20ms per frame. And honestly the only reason it was even that slow was because of the number of skinned mesh renderers and animators choking up the CPU.
     
    DevDunk likes this.
  11. neuen12345

    neuen12345

    Joined:
    Jul 2, 2023
    Posts:
    4
    Hi Sluggy, DevDunk.

    Thank you, your story was very informative and convincing.
     
  12. richardkettlewell

    richardkettlewell

    Unity Technologies

    Joined:
    Sep 9, 2015
    Posts:
    2,235
    Dynamic batching was written to get better performance out of very old graphics hardware. Eg OpenGL ES 2, where draw calls were very expensive, and manually merging small meshes on the CPU actually gave better performance.

    It is pretty much useless on modern hardware.

    The SRP Batcher, on the other hand, is a modern batcher that is designed to be effective on modern hardware.

    In summary, forget about Dynamic Batching - we should (and will) remove it from Unity at some point.

    I think it’s disabled by default in new HDRP/URP projects, in favour of the SRP Batcher.

    Hope this helps!
     
    Sluggy and DevDunk like this.