Search Unity

GPU Instancing and Static Batching

Discussion in 'General Graphics' started by m506, Aug 25, 2018.

  1. m506

    m506

    Joined:
    Dec 21, 2015
    Posts:
    89
    Hi there,

    I've been using gpu instancing to batch my draw calls with great success so far, and I decided NOT to use static batching because of the following:
    - its unable to batch if the mesh instances use different light probes (which gpu instancing can)
    - it creates memory overhead because meshes get merged during runtime
    - it slowes down startup because of such mesh merging process


    So my 2 questions are:
    What exactly are GPU instancing disadvantages? any draw backs or performance prices you pay for using it in the long run?
    Why does static batching takes priority over gpu instancing when you have both enabled? Since it seems gpu intancing is a much more complete batching solution.

    Thank you for any input here
     
    tigerleapgorge likes this.
  2. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,033
    According to several tests I ran, Unity's "GameObject GPU instancing" often causes more work on the CPU (yes, CPU) than static batching. See this post for an actual performance issue an user ran into.

    I found GPU instancing slower compared to static batching on some platforms. Thus, don't assume GPU instancing is faster than static batching on platform X, just because it's faster on platform Y. Profile this on every platform you want to target.
     
    ROBYER1 and Editali like this.
  3. m506

    m506

    Joined:
    Dec 21, 2015
    Posts:
    89
    That makes sense. thanks for the input. I guess i don't have a choice because of the light probe limitation on static batching. so I was just curious on why unity gives priority on static batching over gpu instancing, since it seemed to be just the perfect batching solution.
     
  4. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    28,018
    It will depend on what you static batch. Static batching is designed for larger unique meshes that will share the same material. It's not designed for a lot of the same mesh.

    Instancing is great for a lot of the same mesh, and particularly awesome for being dynamic.

    As for dynamic batching, this also works with instancing, and the jury is out if it's good to use with or not.

    But, GPU instancing will usually win if you're manually drawing them with https://docs.unity3d.com/ScriptReference/Graphics.DrawMeshInstanced.html because a lot of GPU instancing's overhead comes from the fact they're all independently sorted and culled, as well as the memory access patterns that come with it.

    It's a pretty good partner for Culling Groups API. Don't take word as gospel though, test everything.
     
  5. m506

    m506

    Joined:
    Dec 21, 2015
    Posts:
    89
    Thank you. Culling Groups API is something I never tried so will get deep into it now. Best regards
     
  6. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    28,018
    Sure, and if you wanted to really go a little bit nuts you could pair it with ECS but I think that would be going a bit nuts for sure.
     
    phobos2077 likes this.
unityunity