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

[HDRP] Optimizing high prefab count

Discussion in 'High Definition Render Pipeline' started by Laex410, May 27, 2019.

  1. Laex410

    Laex410

    Joined:
    Mar 18, 2015
    Posts:
    51
    Hello everyone,

    We are currently working on a RTS game, with lots of objects in the scene. Here is a screenshot for reference:

    Screenshot.JPG

    Due to the high amount of objects we are heavily CPU bottlenecked. The planets are generated at runtime and the buildings are spawned prefabs.
    We are using the HDRP with DirectX 11 (since it preforms best). The following optimizations are already implemented:

    - LOD system for the objects with the lowest level being billboards (4 levels total). During generation, we merged each LOD level meshes by material (usually 2-6 meshes per building)
    - The planet tiles are being merged by materials during generation. The planet in the screenshot is just one material, therefore just one mesh.
    - GPU instancing is active for the building materials. The used shader is HDRP/Lit
    - The pipeline is set up to use the SRP Batcher introduced some months ago

    The batch size is still extremely high (~2000, I think the GPU instancing might not be working properly yet). I attached another screenshot from the profiler which shows the current bottleneck quite good. The GPU is running at about 30% performance.

    Capture.JPG

    Are there additional steps I can take to further optimize the CPU performance? Thanks for your help!

    - Alex
     
  2. holyfot

    holyfot

    Joined:
    Dec 16, 2016
    Posts:
    42
    You could use a render instanced script or you can combine the meshes. There is code and assets that do these things.
     
  3. warthos3399

    warthos3399

    Joined:
    May 11, 2019
    Posts:
    1,728
    A mesh combiner will help alot, as your CPU bottlenecked. Ive had a few probs with GPU instancing before, but you have ALOT of objects, and using 2-6 meshes per building, might be hurting you.
     
  4. JJRivers

    JJRivers

    Joined:
    Oct 16, 2018
    Posts:
    137
    This is old news but i'm posting anyways so some late comer isn't mystified by the numbers shown, if you have SRP Batching enabled it will override GPU instancing if the shader is SRP Compatible. The stats window will not show you correct batch numbers, that is due to be fixed in 2021 if i'm not wrong. And it is an entirely different technique, if you go with SRP Batching you Must make sure you are avoiding excessive numbers of shader variants like the bubonic plague (For example, two objects otherwise entirely identical but one has some texture map that the other doesnt, it will be drawn with a different shader variant if your shader is HDRP/Lit).

    Apologies for the necro, but this confusion is seen all over the forums and this returns pretty high up in google.
     
  5. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    SRP batching is also slower by far than using proper GPU instanced indirect, and you can find a few assets that perform this role like https://assetstore.unity.com/packages/tools/utilities/gpu-instancer-117566

    This is miles faster than relying on SRP batcher, because SRP batcher is still going through the CPU first, while GPU instancer or similar uses a compute shader to bypass the CPU, thereby eliminating said bottleneck.

    However without DOTS you'll still need to be moving all these things without transforms since the transform overhead is too high, but I think the above asset would help. I am not affiliated or anything but it does seem like a good solution.
     
    warthos3399 likes this.