Search Unity

Batching problems (large object counts) (SRP/HDRP)

Discussion in 'General Graphics' started by buganat, Jul 4, 2021.

  1. buganat

    buganat

    Joined:
    Apr 26, 2020
    Posts:
    6
    Hi all. Trying to make a game with a lot of objects that can be mined (like a survival game), but there seems to be a lot of performance issues, and unity doesn't seem to be batching objects.

    I'm using HDRP for my project, but I tested this out in another URP project with a sphere prefab with one material, and still couldn't get it to work.

    Example: https://i.imgur.com/PTQkaur.jpg

    All of the spheres come from a static Sphere prefab with a basic material (with no shader) applied. But the framerate goes from ~400 to ~70's-80's in URP. The batch count seems pretty close to the actual number of objects. (around 10,000)

    Here are the object's settings: https://i.imgur.com/vnwn6Tn.jpg (Tried turning off shadows and light probes etc. as well)

    Is there anything I'm missing for improving performance?
     
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
    By default the SRPs use the SRP Batcher. The SRP Batcher takes precedence over static batching, and even over instancing. Generally speaking it allows performance near that of instancing or batching without needing to actually instance or batch an object, allowing different dynamic meshes that only use the same shader to see massive performance improvements compared with not batching at all. It offers huge performance benefits over the built in renderer when using a lot of different meshes with unique materials. When the SRP Batcher is enabled you will indeed see each individual object show as a separate "batch".

    But I did say near, it is not always equivalent. The SRP Batcher is not as good as either instancing or static batching in cases where you have a single material on a high number of static mesh renderer components, or a single material and mesh on a high number of mesh renderer components. But the cutoff for what constitutes "a high number" for the SRP Batcher becomes less effective than the older options is somewhat nebulous and depends on the hardware you're running on, and sometimes the makeup of the rest of the scene.

    You can toggle the SRP Batcher on and off while the game is running in the editor. It's in the Render Pipeline Asset at the bottom under Advanced. Run the game and toggle between SRP Batcher on and off and you can see the performance benefits, and compare to static batching (if it's enabled and the objects are set to static) or instancing (if the material that is applied to all the objects has instancing enabled).

    A quick test with 8000 default spheres in an otherwise empty lit scene got me these numbers (eyeballed rounded averages):

    No batching or instancing:
    CPU: 12ms (Render Thread: 11ms) GPU:7ms
    Around 80 fps

    SRP Batcher:
    CPU: 7ms (Render Thread: 6ms) GPU:3ms
    Around 140 fps

    Static Batching:
    CPU: 7ms (Render Thread: 6ms) GPU: 2ms
    Around 145 fps

    GPU Instancing:
    CPU: 6.5ms (Render Thread: 5.5ms) GPU: 2ms
    Around 150 fps

    So you can see static batching and instancing both have benefits over the SRP batcher with this very contrived setup, but not a lot better. And if the scene was built with a mix of meshes and materials the performance improvements seen for static batching and instancing will likely get lower as the SRP Batching has the potential to improve the performance of rendering everything else in the scene.


    So really the problem isn't "the SRP isn't batching". The problem is it's still expensive to render 10,000 of something with a few hundred vertices each. If you want to render that number of objects you'll want to start investigating using LOD or impostors.
    https://assetstore.unity.com/packages/tools/utilities/amplify-impostors-119877
     
    mgeorgedeveloper and Brother_77 like this.
  3. buganat

    buganat

    Joined:
    Apr 26, 2020
    Posts:
    6
    Hey bgolus, thanks for the reply!
    "When the SRP Batcher is enabled you will indeed see each individual object show as a separate "batch"."
    That's good to know, sounds like the batching is working as intended then.

    "You can toggle the SRP Batcher on and off while the game is running in the editor. It's in the Render Pipeline Asset at the bottom under Advanced."
    Unfortunately it doesn't seem to be available in the HDRP (though it is in the URP), as dynamic batching seems to be enabled by default (my understanding from googling, at least).
    In the URP project however, I toggled the batching options and it indeed changed the "batching/saved by batching" numbers, but had minimal impact on fps, which lines up with what you said about the SRP giving less benefit when using many of the same objects with a shared material.

    "using LOD or impostors."
    I'm currently using LOD's and a short culling distance within my main project, but still getting worse FPS with less objects (40-50's).
    (Also forgot to mention, this is all with a 1070ti)
    The point about approaching the 10k object mark being intense either way might be the reality, though. Tried using occlusion culling to make some of them less visible, but it didn't have much of an impact, so the workaround is probably just to lower the number of objects on screen.

    Also wanted to mention, I used Unity's Terrain tool and made the objects trees, which actually gave decent performance (80-100's range), but the trees weren't able to be interacted with by the player. Not sure if there's something the Terrain tool is doing that manually placing the objects in the hierarchy isn't, though.
     
  4. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
    https://docs.unity3d.com/Manual/SRPBatcher.html
    Basically, for the HDRP it appears they don't think it's worth allowing static batching or auto-instancing.
     
  5. koirat

    koirat

    Joined:
    Jul 7, 2012
    Posts:
    2,074
    Is the in editor stats window valid for HDRP it displays about 5000 batches in my case and Frame debugger less than 1000.
     
  6. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
    No idea.