Search Unity

Bug GPU Instancing Decrease Performance

Discussion in 'General Graphics' started by Gokcan, Jun 7, 2021.

  1. Gokcan

    Gokcan

    Joined:
    Aug 15, 2013
    Posts:
    289
    Hi @aleksandrk

    I have a test scene where lots of dynamics objects which share same mesh and material using gpu instancing.
    I am testing it with 3 different mobile phone and on 2 of them when I enable GPU ınstancing performance decrease! On Galaxy s7, performance increase as expected...

    Here are the mobile phones which cause performance decrease:
    General mobile g20 and samsung galaxy A10s which both have PowerVR Rogue GE8320 gpu
     
  2. BattleAngelAlita

    BattleAngelAlita

    Joined:
    Nov 20, 2016
    Posts:
    400
    By GPU Instancing you mean toggle on material?
     
  3. Gokcan

    Gokcan

    Joined:
    Aug 15, 2013
    Posts:
    289
    @BattleAngelAlita
    Yes, when I toggle it on, performance decreases which I was expecting to increase...
     
  4. Gokcan

    Gokcan

    Joined:
    Aug 15, 2013
    Posts:
    289
    Any help?
     
  5. BattleAngelAlita

    BattleAngelAlita

    Joined:
    Nov 20, 2016
    Posts:
    400
    Under the hood this toggle implemented very unoptimal, and in most cases work slower.
    You can do proper instancing by hands with a BatchRendererGroup.
     
  6. Gokcan

    Gokcan

    Joined:
    Aug 15, 2013
    Posts:
    289
    This is developed nearly 7 years ago. I dont think it is unoptimal. In the documentation, there is not any info about which mobile gpus it works or not. But it is a huge problem for us that blocks releasing app...
     
    Stormer2020 likes this.
  7. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,342
    As @BattleAngelAlita already mentioned, Unity's automatic instancing isn't necessarily the most optimal. Instancing also isn't necessarily faster on all hardware. Technically instancing is always slower to render. Why it's useful is it lets the CPU issue a single command to the GPU to render a lot of objects which can reduce the CPU usage and GPU idle time. When you have a CPU issue a draw command for each object individually sometimes the GPU will finish drawing the previous command before the next one is issued, so the overall frame takes longer to render because the GPU is spending time idle when it could be doing work.

    However instancing requires slightly more complex shaders, with data for each instance being accessed from arrays based on the instance ID. For modern GPUs the additional cost is negligible, but on older GPUs the cost of doing this can be significant. If the GPU your device has takes longer to render each object than the CPU takes to issue individual commands, or if access data from an array is especially slow such that the idle time you avoid is less than the cost increase of using instancing, then instancing is a net negative.

    Add to that Unity's automatic instancing can sometimes be more expensive on the CPU than not instancing at all and you see results like what you're seeing. Unfortunately it's not as simple as "these GPUs can't do instancing / are too slow to do instancing" as it'll depend on factors like the complexity of the model / shader being instanced and what else is being rendered to determine if instancing is beneficial for you or not. So it's not as easy as just having a list Unity provides of "bad GPUs".

    To expand on the topic of "Unity's automatic instancing isn't optimal", it's setup to ensure there are no visual changes between having it enabled vs disabled instead of rendering the fastest. For example if you have any real time lights, light probes, reflection probes, or have your instances span from inside to outside of the shadow distance, Unity will split up instances into smaller instanced groups. Instancing is often only really useful when drawing several hundred or thousand, so if you're using the above features Unity may be drawing instanced groups that are in the tens of objects and providing little to no benefit vs drawing them normally. In some versions of Unity the above features can cause instanced meshes to render individually, but still "instanced", meaning you get the worst of both.
     
    Last edited: Jun 9, 2021
  8. Stormer2020

    Stormer2020

    Joined:
    Sep 14, 2020
    Posts:
    92
    I was used GPU instance at WebGL. It's works fine on PC, but lagged on MacOS.
    Now, I deprecated GPU instance. It sucks!
     
    AndyKun and Gokcan like this.