Search Unity

HDRP - Batching does not work

Discussion in 'High Definition Render Pipeline' started by sergiusz308, Jun 23, 2019.

  1. sergiusz308

    sergiusz308

    Joined:
    Aug 23, 2016
    Posts:
    235
    Hello, trying to get batching to work with no results :(

    Have a simple scene with single prefab (mesh + material) being rendered with HDRP Lit material. Material is set to use GPU Instancing. Number of batches: 6

    Each time I duplicate prefab, number of batches goes up, and up, and up - by 6 each time.

    Material has one diffuse map and one emission map.

    No scripts, no custom shader, all standard stuff (apart from mesh and textures).

    Unity v. 2019.1.7f1, HDRP v. 5.16.1

    What am doing wrong?

    Screenshots:

    Two prefabs are there (one duplicated off another), second one is disabled:
    barching_not_working_1.png

    After enabling rendering for second one:
    barching_not_working_2.png

    Prefab setup:
    barching_not_working_3.png
     
  2. sergiusz308

    sergiusz308

    Joined:
    Aug 23, 2016
    Posts:
    235
    Bump - anyone? It seems that GPU instancing is not working here. I red through manual and tutorials on batching topic and everything is set up as it should be but still no result.

    No particular information can be found also in profiler or frame debugger.

    GPU Instancing works however in standard Unity rendering pipeline.

    What's happening?
     
  3. Dinamytes

    Dinamytes

    Joined:
    Nov 3, 2016
    Posts:
    51
    Also happening for me.
     
  4. sergiusz308

    sergiusz308

    Joined:
    Aug 23, 2016
    Posts:
    235
    OK, after more testing (because I have nothing more interesting to do than investigating what's wrong: Unity rendering or Unity documentation....) it seems that docs are not updated.

    Batching works, but:

    - when material is checked to use GPU Instancing and SRP Batcher is enabled there's no "draw instanced" calls in the frame debugger visible and Stats display batched calls with - sign

    - when material is checked to use GPU Instancing and SRP Batch is disabled, you can observe "draw instanced" calls in the frame debugger and Stats displays batched calls properly, as documented in the manual

    Anyone from Unity Dev team please comment on this - is my understanding is correct?
     
    Last edited: Aug 13, 2019
  5. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    11,795
  6. arnaud-carre

    arnaud-carre

    Unity Technologies

    Joined:
    Jun 23, 2016
    Posts:
    97
    Hi!

    Have to admit it's a bit confusing and we're working on improving that. First, the statistics window is not up to date when batcher is ON ( because some numbers have no meaning in batcher context, ie "saved by batcher" ). This is not ideal situation and we're working on refactoring that statistic window to provide good metrics (with certainly new names))

    Anyway if you really want to measure performance with and without batcher, I recommend you to use a small script ( SRPBatcherProfiler.cs ) . More details in that blogpost.

    Regarding automatic GPU instancing, we by pass it when SRP Batcher is ON ( because in real life scene, batcher is slightly faster ). Of course you still can use explicit GPU instancing via Graphics.DrawInstanced for dedicated things.
     
  7. nasos_333

    nasos_333

    Joined:
    Feb 13, 2013
    Posts:
    13,362
    Hi,

    I use the HDRP Lit shader and enabled GPU instancing for objects copied and scaled - rotated around, but the batches are still enormous (like 3000) and "saved by batching' metric reports a minus -2000, is this meaning the batching is working ?
     
  8. shredingskin

    shredingskin

    Joined:
    Nov 7, 2012
    Posts:
    242
    Does the documentation need to be updated ? I don't see an advanced options in the HDRP asset.
     
    EthanFischer likes this.
  9. sergiusz308

    sergiusz308

    Joined:
    Aug 23, 2016
    Posts:
    235
    In March 2020 I have no idea- that whole thing with SRP transitioning is a one huge mess, on unity side.

    Maybe some big customers with dedicated support from unity have any understanding of how to properly and efficiently use new rendering pipeline.

    Little guys like myself are left with nonexistent or outdated documentation, confusing blog posts and sponsor videos, completely unhelpful forum and bug report replies. It's hit and miss game.

    Great that there's raytracing tech you can show off, but not being able to properly investigate performance, without using some loose scripts, posted somewhere on the forums (because I have too much free time I can spend on hacking around instead of developing my game...) its just pathetic. And this is just a tip of the iceberg of missing or broken things in the new pipeline.

    I should have stayed with built in renderer. It's at least two years, if not more, before srp become ready to production use. I wish somebody would mentioned that in multiple blog posts and videos they advertised srp in.
     
    Genebris, Beauque, Ziflin and 3 others like this.
  10. Ultroman

    Ultroman

    Joined:
    Mar 10, 2014
    Posts:
    110
    Also still waiting on figuring out whether my batching works or not. It says 48 batches and -48 saved. Does that mean that I have successfully messed up every single instancing-attempt I have done, or does it mean that it works?

    I'm sorry, but I have to agree. It's impossible to do any real work here, without creating all the building blocks to fit into Unity to make it work. How is there not a single particle-shader for HDRP yet? Yes, I've tried the beta-package they made, but those don't support colors, so you have to write those yourself. That's such a weird choice to me.
     
  11. strongbox3d

    strongbox3d

    Joined:
    May 8, 2012
    Posts:
    860
    I am using Unity 2019.37f1, HDRP.

    I still have this problem about batching, I have a lot of objects with the exact same material and texture on them, the are not marked as static batch since they are moving, and the material is mark to GPU Instance batch. Guess what? I get exactly the same result that you guys: A high number in "Batches" and a negative number as high in "Saved by batching".

    I don't find any place in Settings or HDRP asset to turn on/off SRP batching neither!

    Could someone from Unity shine a real light here? Please

    Regards,
    Carlos
     
  12. customphase

    customphase

    Joined:
    Aug 19, 2012
    Posts:
    246
    +1 to this. In frame debugger it shows that SRP Batcher works and batches things, however, if you try and use RenderDoc, you'll see that in fact absolutely nothing gets batched, even static stuff. Unity 2020.1b8, HDRP 8.1.0

    upload_2020-5-28_2-51-29.png

    upload_2020-5-28_2-51-1.png

    Making the boxes non static and enabling GPU instancing on their material does nothing as well. Theres still one drawcall per box.

    cc @arnaud-carre
     
    florianBrn likes this.
  13. JPDoiron

    JPDoiron

    Joined:
    Jan 11, 2013
    Posts:
    16
    Look in detail on the draw call and the definition of SRP batching you'll see the difference .It indeed does 1 draw call each but reduced the states changes from 5-10 to 1. That's what SRP batcher does, reducing CPU overhead by reducing the state changes that occurs when you change the shader.



    Without SRP


    With SRP



    Still 2 draw calls, but overhead for each is significantly reduced.

    regards

    JP
     
    laurentlavigne likes this.
  14. SilverStorm

    SilverStorm

    Joined:
    Aug 25, 2011
    Posts:
    712
    Can someone please provide me with how to use batching properly in HDRP I have looked at all the documentation and it's either all outdated or very difficult to follow. Static batching no longer works in HDRP and GPU instancing seems to be causing trouble with certain people.

    I have an RTX 3070 and I am getting 500 batches on simple scenes and 20K batches on larger but medium sized scenes I cannot release a game like this if profiling it is broken as the fps count is very low.
    I was told about the SRP batcher but I can't find it in HDRP and the docs don't help or are telling me to use scripts and such and such. I thought HDRP was production ready?
     
  15. nasos_333

    nasos_333

    Joined:
    Feb 13, 2013
    Posts:
    13,362
    After working with both pipelines for long time now, I think SRPs are nowhere even close to near production ready, URP not even has point light shadows and both URP and even more HDRP are generally extremely slow comparing to standard, both pipelines are largely useless imo for any serious project atm, i give it 1-2 years to be fully realized, if ever can be with such complexity and overhead.
     
  16. SilverStorm

    SilverStorm

    Joined:
    Aug 25, 2011
    Posts:
    712
    That's a real shame because I was just getting to like HDRP. I can't go back however because of things like Subsurface Scattering and the beauty of the shaders. A lot of what you say is right and particle effects aren't working in HDRP properly and other stuff but there hasn't been anything serious until the batching issue.

    Though I still didn't get an answer to my question about how to use the batching?
    I will have to bring out mesh combine studio if the batching is really that bad because it uses its own batching system and works on all pipelines.
    If all else fails I'll have to go back to standard but we'll see I've come to far to turn back now.
     
  17. customphase

    customphase

    Joined:
    Aug 19, 2012
    Posts:
    246
    If you want/need to use it - then use it. Sure, its not an ideal solution, but its really good nevertheless. We use it for our project btw:


    They do, you just need to use HDRP compliant particle shaders.

    Static batching still works, i dont know where you got the information that it does not. SRP Batcher is enabled by default in HDRP and can only be disabled through scripting. Anyways, batches is just one of performance metrics, open up GPU profiler and look at what exactly is taking the most time. And if you think something takes more than it should - file a bug report.
     
    radiantboy likes this.
  18. BattleAngelAlita

    BattleAngelAlita

    Joined:
    Nov 20, 2016
    Posts:
    400
    I find only one easy way to force HDRP to use instancing - import hybrid rendering package to project, and throw all static geometry in to the entity world.
     
  19. SilverStorm

    SilverStorm

    Joined:
    Aug 25, 2011
    Posts:
    712
    You are probably right it's probably a bug because if the Batcher it's enabled by default then it means Unity just can't handle so many objects and they need to be combined..

    In regards to the particles it looks like they are listed in the package manager instead of out of the box.

    Congratulations on getting onto the PS5!
     
    Last edited: Nov 30, 2020
  20. SilverStorm

    SilverStorm

    Joined:
    Aug 25, 2011
    Posts:
    712
    Ah I just looked up the Hybrid Renderer and I understand now. Thanks for that at first I didn't understand what you meant by Hybrid Renderer I was thinking is this a new renderer that combines HDRP and URP but nope it's just some troll at Unity who should get a pay cut for naming it something other than DOTS.
     
    Last edited: Nov 30, 2020
  21. arnaud-carre

    arnaud-carre

    Unity Technologies

    Joined:
    Jun 23, 2016
    Posts:
    97
    Hi,
    Here are some details about how SRP batcher is working and may help to understand various scenario in your scenes. First of all SRP Batcher doesn't reduce the low level API drawCall, at all. If you have 1000 cubes, you will get 1000 drawcalls. ( in Renderdoc you can see 1000 DrawInstanced with 1 instance per cube). The DraWInstanced(1) is just for VR ( if you run VR mode then you'll get DrawInstanced(2) in renderdoc).
    Now about Material GPU Instancing. There is two kind of scenarios with instancing:
    1) A real life scene with plenty of different materials, some custom vars, and many different meshes.
    2) A specific scene with a lot of similar meshes, using the exact same material without any custom vars ( like all cubes have exact same size, color, etc)

    In case 1), SRP batcher is faster than our generic GPU instancing code path.
    In case 2), using GPU instancing is still faster than SRP Batcher.

    Right now, when SRP Batcher is ON, Material GPU instancing is bypassed ( so you're always in case 1). What if you really want to enable Material GPU instancing because you are in the very specific case 2? You have severla options:

    a) simply disable SRP batcher. (using the HDRP or URP asset). If you do that, please profile your game, maybe it won't get faster afterall. This is not ideal as nothing else will benefit from SRP Batcher speedup
    b) better: Create a new shader (you can copy/paste URP/Lit or HDRP/Lit if you want), and simply makes it "SRP Batcher not compatible". An easy way to do that is to rename "UnityPerMaterial" cbuffer to another name like "BypassUnityPerMaterial". As this shader won't contain a cbuffer named "UnityPerMaterial", it will be marked as "non ocmpatible" ( you could check in the shader inspector). As it's not SRP batcher compatible anymore, it can go through the old generic material GPU instancing code path.Then, set this new shader to all material that you want to be GPU instanced
    As always, please profile your specific usecase to check it improves CPU rendering performance or not. ( don't forget GPU instancing is a CPU optimization, not a GPU one )

    Just to know we're working in improving performance with SRP Batcher & GPU Instancing in the up-coming new Hybrid renderer. V2. It should be released in 2020.2.
     
    Last edited: Nov 30, 2020
    StenCG, sergiusz308, Beauque and 4 others like this.
  22. SilverStorm

    SilverStorm

    Joined:
    Aug 25, 2011
    Posts:
    712
    Update My results agreed with what @arnaud-carre said
    However I could not disable it in HDRP in the asset it's not there only via the script I did it.

    My results agree with what the above Unity Personnel said.
    So I got the SRP Batcher Profiler script and put it on my camera and found out that GPU instancing is disabled while SRP Batcher is enabled and only one will be enabled at a time. It's important to know that HDRP does not support regular static batching so only SRP batching or GPU instancing are options here.
    So the problem is it gets weird:

    Scene1:
    In my scene with 3000 standard with a new HDRP standard material applied to the cubes the SRP Batcher performs at 120fps while disabling SRP the GUP instancing starts working giving me 130 fps basically saving 1 MS which is good and it shows 2700 saved by batching which is huge.

    Scene2:
    However in another scene with an asset pack i bought with similar props and only color in the material the srp batcher
    performs the best 55fps in the 26000 batches while disabling it and putting GPU instancing on I get only 3000 batches and saving 23000 batches but the performance is even worse now with only 47fps. That doesn't make any sense.
    By having GPU instancing off completely and SRP off completely I get 52 fps.
    I can't figure this out because GPU instancing is meant to support a very high number of objects where here the GPU instancing fails hard over having it disabled....

    Scene3:
    Running this in another scene that is more complex with many buildings and materials shows that the SRP
    batcher really is the better option with it being turned on saving 80% of the set pass calls.
    Again the GPU instancing performs garbage here with a good 20fps worse than the SRP batcher despite saving many 80% of the batches in this 16000 batch scene.

    So Basically having the SRP batcher enabled which is the default behavior most of the time gives the best results but other people have said that the GPU instancer is very finicky and unreliable and after seeing what I saw I do agree.

    However my video card is one of the best out there and other people have reported similar fps that I have when it comes to drawing such dense levels so my only assumption here is that maybe to get more performance I will have to look elsewhere past the materials and likely into the shadows, occlusion culling, backface culling or probably the most effective one-mesh combining.

    I am pretty sure that if I was to combine those 2 thousand cubes into 1 mesh I would get the most performance here at the cost of disabling culling.

    FINAL UPDATE: I combined the meshes of the Scene1 using a free tool on the asset store and yes the performance gain is enormous giving me about 100+fps.
    https://assetstore.unity.com/packages/tools/modeling/mesh-combiner-157192
    Now I feel kind of silly looking at Scene 2 and realizing the modular castle is not combined
    and looking at scene 3 however I need something different because mesh combining will output 1 material so unless the houses will all be atlassed it won't work that is why Mesh Combine studios grid system will work for that.
     
    Last edited: Nov 30, 2020
    sergiusz308 likes this.
  23. BattleAngelAlita

    BattleAngelAlita

    Joined:
    Nov 20, 2016
    Posts:
    400
    You also can manually batch your objects with BatchRendererGroup API
     
  24. arnaud-carre

    arnaud-carre

    Unity Technologies

    Joined:
    Jun 23, 2016
    Posts:
    97
    "However I could not disable it in HDRP in the asset it's not there only via the script I did it."

    oh right, you can disable it using HDRP asset but only when you enable the "debug" inspector ( we should update the doc on that). URP has still the option in the normal inspector.

    "It's important to know that HDRP does not support regular static batching so only SRP batching or GPU instancing are options here."

    HDRP still supports static batching. Stayic batching criterias are the same as legacy unity, it's quite restrictive. ( objects should be static but also near together, should have exact same material, same lightmap, etc. ).

    "However in another scene with an asset pack i bought with similar props and only color in the material the srp batcher
    performs the best 55fps in the 26000 batches while disabling it and putting GPU instancing on I get only 3000 batches and saving 23000 batches but the performance is even worse now with only 47fps. That doesn't make any sense.
    By having GPU instancing off completely and SRP off completely I get 52 fps.
    I can't figure this out because GPU instancing is meant to support a very high number of objects where here the GPU instancing fails hard over having it disabled...."

    As I said our generic GPU instancing code is only efficient if all objects has no custom values per object. Your scene use different color per object right? In this case SRP Batcher is even faster as you said.
    To really get maximum performance for that kind of scene ( a lot of same mesh, using different properties per object, like color ) you should use the new hybrid renderer v2. Should be here for 2020.2.

    "Running this in another scene that is more complex with many buildings and materials shows that the SRP
    batcher really is the better option with it being turned on saving 80% of the set pass calls."

    yes as a rule of thumb, the optimization of SRP Batcher comes from reducing the number of SetPass calls ( and not the number of DrawCall ).

    "However my video card is one of the best out there and other people have reported similar fps that I have"

    so it means your scene is CPU bound
     
    Last edited: Nov 30, 2020
  25. sergiusz308

    sergiusz308

    Joined:
    Aug 23, 2016
    Posts:
    235
    @arnaud-carre OK, so one question about "Stats" window and SRP Batcher. As I can see here - "stats" still does not properly display the batching metric:

    upload_2021-3-31_16-2-1.png

    In the frame debugger I see that for drawing opaque objects I have these 4 SRP batches. Regardles of the performance discussion above I'd like to know how this compares to 357 batches that you can see in the stats window, to the right?

    Because SRP batcher does not actually limits number of draw calls, is this the reason why I am seeing those 357 batches in the "stats" window?

    If it's correct way of understanding, what's the benefit of the SRP Batcher then? Whenever you read or listen about graphics pipeline optimization there's this mantra being repeated all over everywhere - bring down drawcalls. If this is not how SRP Batcher works, as you mentioned above it's also bypassing instancing path - what's the purpose of it?

    Last question - what would be the best approach to render hundreds of objects with the same material (shader) but different parameters (i.e. color) in URP?

    Following up your response to SilverStorm - then using SRP Batcher in URP and hunderds of objects (before moving to ECS/DOTS) should I use renderer copy of the material, not the "sharedmaterial", let's say referenced in the Start, to change individual parameters of that copy of the object (i.e. change it's color)?

    Sorry for the long post but maybe, if answered :) it could bring all those questions / discussions / answers related to the SRP batcher / instancing in one place so peoples can learn from it little bit better way than just going through multiple blog posts and vidoes, all of those touching subject but none of those actually providing a comprehensive look at the subject.

    Thanks!
    S.
     
    Last edited: Mar 31, 2021