Search Unity

No batching: Non-instanced properties set for instanced shader

Discussion in 'Shaders' started by lazybeargames, Jun 22, 2021.

  1. lazybeargames

    lazybeargames

    Joined:
    Mar 16, 2020
    Posts:
    26
    I'm trying to implement instancing in my shader, but a Frame Debugger shows me a message saying "Non-instanced properties set for instanced shader" and doesn't batch draw calls. Don't see any additional helpful info.

    Can anybody please help with a direction of the research?


    I can't post the whole shader here (it is huge), but what have I done:

    1. Added "UNITY_VERTEX_INPUT_INSTANCE_ID" to both structures (vertex input/surface input).
    2. Added a block:
    Code (CSharp):
    1.         UNITY_INSTANCING_BUFFER_START(Props)
    2.             // put more per-instance properties here
    3.             //UNITY_DEFINE_INSTANCED_PROP(fixed, _ObjectID)
    4.             UNITY_DEFINE_INSTANCED_PROP(float4, _OTextureLeftCrd)
    5.             UNITY_DEFINE_INSTANCED_PROP(float4, _OTextureRightCrd)
    6.         UNITY_INSTANCING_BUFFER_END(Props)
    3. Added "UNITY_SETUP_INSTANCE_ID(v); UNITY_TRANSFER_INSTANCE_ID(v, o);" to the vertex shader.
    4. Added "UNITY_SETUP_INSTANCE_ID(IN);" in the beginning of a surface shader.
    5. Accessing parameters with "UNITY_ACCESS_INSTANCED_PROP(Props, _OTextureLeftCrd);"
    6. Checked "GPU Instancing" in the material

    Below are two screenshots of a frame debugger of 2 draw calls which (as far as I understand) should batch as all parameters are the same (the only parameters that are different are _OTextureLeftCrd/_OTextureRightCrd which disappear here when I tick a "GPU Instancing" checkbox in the material).

    Draw call 198:
    upload_2021-6-22_13-7-51.png

    199:
    upload_2021-6-22_13-10-23.png
     
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,342
    I suspect the "reason" being shown here is being shown due to a bug, because the real reason why those two draw calls aren't batching is much more straight forward.

    Draw 198 is the mesh Cylinder_quarter_H (which it's drawing two instances of)

    Draw 199 is the mesh Cube (which it's drawing 513 instances of)

    You can't render different meshes in the same instance draw, it can only instance one mesh at a time.
     
  3. lazybeargames

    lazybeargames

    Joined:
    Mar 16, 2020
    Posts:
    26
    Ahhh... Thanks, I've been totally focused on the right side of the frame debugger and the reason shown.