Search Unity

  1. Curious about what's going to be in 2021.1? Have a look at the 2021.1 beta blog post.
    Dismiss Notice

GPU instancing - doesn't seem to improve performance.

Discussion in '5.5 Beta' started by sgower, Oct 23, 2016.

  1. sgower

    sgower

    Joined:
    Mar 9, 2015
    Posts:
    315
    I'm not sure this is the best place for this, but I believe GPU instancing is a beta feature. Mods, feel free to move this if you think there is a better place.

    I can't seem to get any benefits from using GPU instancing. I build a scene with thousands of primitives that use 3 different materials. The screenshot below is when I don't use the instanced shader for my materials. It shows 44 fps, and "Saved by batching 32".






    When I change the 3 materials in the scene (I do this in the Editor while the game is running) to user an instanced shader, I see the "Saved by batching" jump from 32 to 15296. But there is no frame rate increase, and in fact, the frame rate drops from 44, to 42. I'm running this with Unity 5.5b8, an I6700k CPU, and Geforce 980Ti GPU. Does anyone know why I'm not seeing any performance benefits? Thanks!

     
  2. hoesterey

    hoesterey

    Joined:
    Mar 19, 2010
    Posts:
    571
    Your SetPass calls have not gone down. SetPass calls are where the majority of the cost is. GPU instancing should be reducing SetPass calls. If its not its either a bug in unity or something strange that your doing.
     
  3. sgower

    sgower

    Joined:
    Mar 9, 2015
    Posts:
    315
    Hmmm.. ok. Well after switching the 3 materials to use an Instanced shader, the "Saved by batching" went up, so clearly the change has some effect, but (evidently as you mentioned), I'm not getting the benefit that I should be getting. I'm not sure what I could be doing wrong.

    I just upgraded to 5.5b9 and one thing I noticed is that my old instanced shader not longer worked (objects using it appeared pink), and the Editor.log showed this error:

    Shader error in 'Instanced/NewInstancedSurfaceShader': unrecognized identifier 'UNITY_INSTANCE_ID' at line 59 (on d3d11)

    After creating a new Instanced shader, I tested again, but still see no benefits.
     
    Last edited: Oct 26, 2016
    MrEsquire likes this.
  4. Carpe-Denius

    Carpe-Denius

    Joined:
    May 17, 2013
    Posts:
    828
    Just a guess, but does it work if you assign the instanced material before you switch to play mode?
     
  5. richardkettlewell

    richardkettlewell

    Unity Technologies

    Joined:
    Sep 9, 2015
    Posts:
    1,705
    Regarding the compile error, we have renamed that macro to UNITY_VERTEX_INPUT_INSTANCE_ID but for some reason our shader upgraded isnt working. We are investigating why, but for now, manually renaming it will fix your shader error.

    Harder to say why your performance hasn't improved with instancing.. you are probably limited by something else. Wild guess based on your screenshot: you have a slow script running on the main thread that is animating all those meshes. Instancing will most commonly give you a benefit if you are limited by render thread draw call submission. Your profile capture suggests you have 23ms of main thread work but only 8ms of render thread work.
     
    karl_jones likes this.
  6. zeroyao

    zeroyao

    Unity Technologies

    Joined:
    Mar 28, 2013
    Posts:
    169
    As @richardkettlewell said it's hard to tell. A screenshot of the profiler window in both Hierarchy view and Timeline view would help. GPU instancing mostly improves render thread time, slightly improves GPU time (by keeping GPU more busy with drawing) and adds a small amount of overhead to main thread. So it depends on to which factor is your frame rate bound.
     
  7. sgower

    sgower

    Joined:
    Mar 9, 2015
    Posts:
    315
    Thanks guys. My project has some issues I'm working on that are preventing me from running another test right now, but maybe I can post the requested items later.
     
    Last edited: Oct 27, 2016
unityunity