Search Unity

Question I have a performance issue, please validate my understanding!

Discussion in 'High Definition Render Pipeline' started by brainwipe, Feb 20, 2020.

  1. brainwipe

    brainwipe

    Joined:
    Aug 21, 2017
    Posts:
    78
    I have a performance problem and I think it is because I have a lot of dynamic objects (pipes), each made up of 5 materials and 2 shaders (although each object shares these). I think the dynamic batcher isn't able to batch them and the solution is to get all the pipes using the same material and a single shader. Am I right?

    Under normal load my stats are (copied from the image below but representative):
    • CPU: main 33.4ms, render 14.4ms
    • Batches: 3557, saved by batching: -3546
    • Tris: 118, Verts 236
    • SetPass: 766
    • No shadow casters, skinned mesh, animations or audio.
    The bit I am not sure about is the "saved by batching" being negative. I can't find information on that.



    Other info:
    There are 12 dynamic lights but moving to mixed or baked lights with baked textures made the problem proportionally worse. I'm on a modern PC (with GTX 1660Ti), targeting PC.

    Unity 2019.3.0f6.
    I can't get at the HDRP version right now but I assume that it's not associated with my problem.
    Example gameplay here:


    If I'm right
    I'll be refactoring quite a lot of code and models, so I would like validation before I start.

    Thanks in advance Unity chums!
     

    Attached Files:

  2. unit_dev123

    unit_dev123

    Joined:
    Feb 10, 2020
    Posts:
    989
  3. brainwipe

    brainwipe

    Joined:
    Aug 21, 2017
    Posts:
    78
    Thank you! I had read that; not entirely sure I understood all of it.

    I'm learning how to use the Frame Profiler during my lunch break and I've discovered that some of the pipes are being batched together and others are not. I think the _baseColor differs between some of the game objects and that is causing the batches to break up a little.

    I've also found https://forum.unity.com/threads/incorrect-statistics-using-urp.804615/ which says that the "Saved by Batching" is broken in SRP and as I can't find a way to turn of SRP Batching; I'll ignore that for now.

    My scene also has an "external view", which is rendered to a texture. That might well be causing issues, so I'm going to try turning that off.
     
  4. arnaud-carre

    arnaud-carre

    Unity Technologies

    Joined:
    Jun 23, 2016
    Posts:
    97
    Hi! are you using builtin legacy rendering, or any SRP? ( ie URP or HDRP? )
    If you're using SRP, then it's fine to have several materials in your scene. SRP Batcher will still issue several drawcall, but using a fast code path.
    Could you give more information about the hardware used for your screenshot? Maybe the rendering isn't the main cause of these 34ms?
    also if you're using SRP could you please use that script ( https://github.com/Unity-Technologi...b/master/Assets/Scripts/SRPBatcherProfiler.cs ) and take another screenshot in a high consuming scene?
     
  5. brainwipe

    brainwipe

    Joined:
    Aug 21, 2017
    Posts:
    78
    Thank you, Arnaud! I'll start with answering your questions:

    • I am using HDRP.
    • PC is Intel i7-3770K (3.5GHz), 16GB, Win10 x64, nVidia GTA 1660Ti (a 20xx architecture without the RTX)

    Here is the SRPBatcherProfiler screenie as requested:


    Since my last post, I've been hitting your docs/Unite talks hard! I made a video about what I found since I posted here:



    I used the Profiler and the Profiler analyzer before I started improvements, here's the baseline:
    https://github.com/brainwipe/clomp/...200218-before-grabber-perf-baseline-125.pdata

    The pipes themselves are definitely a large part of the cost. I've already started squashing them down:
    https://github.com/brainwipe/clomp/blob/dev/Test/Profiler/20200226-after-squash-pipe-materials.pdata

    I suspect there are some more code places where I'm doing something silly so I'm not done yet! Is there anything else I am missing?

    For anyone else stumbling on this thread; the SRPBatcherProfiler Arnaud mentioned is explained in this excellent blog post: https://blogs.unity3d.com/2019/02/28/srp-batcher-speed-up-your-rendering/

    Thanks for coming to my aid, it's very much appreciated.