Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question Custom render passes, GPU instancing, draw calls

Discussion in 'Universal Render Pipeline' started by MMeyers23, Nov 19, 2022.

  1. MMeyers23

    MMeyers23

    Joined:
    Dec 29, 2019
    Posts:
    101
    I would like to know whether GPU instancing and the performance benefits it incurs still apply when using multiple render passes. For example, I want to use material property blocks to draw objects differently in a custom render pass, RATHER than using a material override. Then I will store the custom render pass color target to a temporary render texture. Does this require the scene to be rendered twice, or does using a single material (albeit with different property block values applied) in each render pass allow instancing to occur across multiple render passes?

    Please let me know if I can better clarify.

    Thanks
     
  2. MMeyers23

    MMeyers23

    Joined:
    Dec 29, 2019
    Posts:
    101
  3. YiboInsane

    YiboInsane

    Joined:
    Jul 22, 2019
    Posts:
    16
    I was indeed writing a simple Lit shader for testing GPU instancing in URP. By using an name different from "UnityPerMaterial" I made it SRP batcher imcompatible which means GPU instancing compatible in URP.

    Code (CSharp):
    1.  
    2. #ifdef FORCE_GPU_INSTANCING
    3. #define PROP NOT_UnityPerMaterial
    4. #else
    5. #define PROP UnityPerMaterial
    6. #endif
    7.  
    8. UNITY_INSTANCING_BUFFER_START(PROP)
    9. UNITY_DEFINE_INSTANCED_PROP(float4, _TintColor)
    10. UNITY_DEFINE_INSTANCED_PROP(float4, _BaseMap_ST)
    11. UNITY_INSTANCING_BUFFER_END(PROP)
    12.  
    Then I tested multi pass shaders i wrote for some fake shadows (1 pass for mesh, 1 pass for shadow)

    It turns out that, if this shadow is SRP compatible, you are all good to have multi pass shader batched by SRP.
    And GPU instancing does not allow multi pass shader. If multi pass is used, GPU instancing gives up and each single renderer use a single batch. so I had to use 2 materials of different shaders (1 for mesh, 1 for fake shadow) on the MeshRenderer. GPU instancing is faster (20% more fps, 140fps on 3060, 4000 verts mesh) rendering vertex animated 10000 GameObjects with 2 materials than SRP rendering same number of GameObjects with 1 shader with 2 passes.

    Not saying that GPU instancing is better, it is just more suitable for my case anyway. A little bit off topic, but I dont' suggest you write multi pass for GPU instancing shaders. Rendering twice isn't going to cost too much if the scene is not so heavily loaded.
     
  4. MMeyers23

    MMeyers23

    Joined:
    Dec 29, 2019
    Posts:
    101
    Thanks for the reply, nice to finally get a response. Correct me if Im wrong though - you are talking about multiple shader passes, as opposed to multiple render passes? I was inquiring about multiple render passes of the camera view using custom scriptable rendered features
     
  5. YiboInsane

    YiboInsane

    Joined:
    Jul 22, 2019
    Posts:
    16
    You are right. I must be mistakenly reading. XD.