Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

SRP Batching - Performance characteristics (case 1209865)

Discussion in 'Universal Render Pipeline' started by Ng0ns, Jan 7, 2020.

  1. Ng0ns

    Ng0ns

    Joined:
    Jun 21, 2016
    Posts:
    75
    Hi people:)

    So, on an off I test the waters to see if it would be worth to switch to the, now "universal" render pipeline, on my android project in terms of performance.

    At the moment I rely on large texture atlases (single material) to keep drawcalls low, so I was hoping the SRP batcher would allow more materials without penalties.

    • Test scene contains 1024 houses (32x32 grid), static with baked lightmaps.
    • Each mesh/house is a single mesh and sums 697 verts, 917tris.

    Testing was done on my HTC10, which supports ES3.2 and according to systeminfo.graphicsDeviceVersion was running that. All materials use "Simple lit" shader.

    Test 1
    Single material, reused on all meshes. 2048 diffuse texture assigned (see image 01 for ref.).

    60+ fps

    Test 2

    Each house use a single material but vary between 16 different ones, each assigned a 512 diffuse texture (see image 02 for ref.).

    In this scene I reached 60+ fps with or without SRP batcher enabled. I know this is capped but other tests done shown no benefit having SRP batcher on or off. Looking at the frame debugger, its clearly doing its job, but theres no performance difference.

    Test 3
    Each house use 4 different materials (submesh) with 4 different variants within scene (so again 16 different materials in all), each material use a 512 diffuse texture like before (see image 03 for ref.).

    This is where things get interesting.

    SRP batching OFF
    60+ fps

    SRP batching ON
    36 fps!

    It seems assigning multiple materials to the same mesh (different parts of cause) has a huge impact on performance when SRP batching is enabled.

    I know 16 different materials within a scene isn't a lot, but I'm surprised to see almost nothing gained when toggling SRP batching on an off. I'm also really sad it see it tank when using submesh materials, especially having thought it the other way around.

    Am I just doing it wrong?

    Cheers :)
     

    Attached Files:

    Last edited: Jan 7, 2020
  2. arnaud-carre

    arnaud-carre

    Unity Technologies

    Joined:
    Jun 23, 2016
    Posts:
    61
    Hi!

    We're interested to study this un-common case. Dividing FPS by two when enabling batcher is not expected at all, so we may have a corner case.
    First, global FPS is not a good metrics for SPR batcher codepath. ( I mean, there is an issue when the framerate drop by two, but the cause may be another part of the engine we should look at). To be sure of SRP Batcher ON/OFF impact, you should use https://github.com/Unity-Technologi...b/master/Assets/Scripts/SRPBatcherProfiler.cs

    Could you post two screenshots of your test 3, with SRPBatcherProfiler.cs enable? ( when enable you can toggle batcher ON/OFF with F9 key)

    Btw if it's not an issue for you you could also post your test3 repro project so we could have a look.
     
  3. Ng0ns

    Ng0ns

    Joined:
    Jun 21, 2016
    Posts:
    75
    Hey Arnaud, thanks for the reply :)

    Applied the profiler script, screenshots attached. Couldn't toggle with f9 (just refreshed display), so I just did so in the URP asset.

    Numbers differ between editor mode and building to the phone tho. In "All object" I'm getting 55 applyshader calls in editor, but only 16 on phone with SRPB off, and 4 versus 2 with SRPB on.

    I've put the project on github https://github.com/Scumworks/SRPBatcherTest

    -Cheers
     

    Attached Files:

    • Log.jpg
      Log.jpg
      File size:
      89.3 KB
      Views:
      171
  4. arnaud-carre

    arnaud-carre

    Unity Technologies

    Joined:
    Jun 23, 2016
    Posts:
    61
    ok so this is a use case we know batcher could be slightly slower ( 10% of CPU rendering time, not 10% of global frame time). This is exactly the case of test3: all objects are "static batched". ( so you go from 1.49ms to 1.62ms (about 10%))
    We may improve the SRP Batcher for this use case in future (where almost all the scene is made of static batched geometry)
    ( as a test, if you disable static batching, you will see huge benefit of SRP Batcher )

    Anyway I still don't get where you go from 60 to 36fps. Is it a different scene?
     
  5. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    26,726
    If it's possible to send this scene as a bug report and drop the case number in this thread it's easier for staff to take a look at.
     
  6. Ng0ns

    Ng0ns

    Joined:
    Jun 21, 2016
    Posts:
    75
    The 60 to 36 is on the phone (android project on my HTC10), screenshots are editor. I ran test3 on the phone with the SRPBatcherProfiler.cs script, and it show the same.

    Edit - Sorry, I realize its easy to overlook in the garble of text that I'm talking about a mobile project.
     
    Last edited: Jan 7, 2020
  7. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    26,726
    Unity needs a case number and your test project to further advise really.
     
    Peter77 likes this.
  8. Ng0ns

    Ng0ns

    Joined:
    Jun 21, 2016
    Posts:
    75
    Sure, np. I'll make a bug report.
     
    Peter77 and hippocoder like this.
  9. Ng0ns

    Ng0ns

    Joined:
    Jun 21, 2016
    Posts:
    75
    So I did a little more testing. When disabling static batching on the meshes, toggling SRP batcher off yield roughly a 4 fps increase to around 40, which seems to co aside with the 10% overhead which was mentioned (on test3).

    I also converted back to the build-in renderer to see what kind of performance it has. Much like URP the first two test doesn't differ much, it does however show the same issues when dealing with "test 3" and having multiple materials assigned to the same mesh (also halves fps).

    So I guess the question is why fps increases when disabling SRP batcher to the extend that it does.
     
  10. BattleAngelAlita

    BattleAngelAlita

    Joined:
    Nov 20, 2016
    Posts:
    224
    What exactly cause slowdown? Multi materials?
     
  11. arnaud-carre

    arnaud-carre

    Unity Technologies

    Joined:
    Jun 23, 2016
    Posts:
    61
    using FPS is often tricky to really measure what happen. Better look at the absolute time in ms. So the large fps drop only occurs on mobile right? Do you have screenshot of SRPBatcherProfiler.cs running on mobile? ( so I can get better idea of the slowdown regarding the rendering code path).
     
  12. Ng0ns

    Ng0ns

    Joined:
    Jun 21, 2016
    Posts:
    75
    Yes, multiple materials assigned to the same mesh (e.g. like different sides of a cube etc.).

    Seems like its mobile only, though I haven't done any tests.

    Here's some screenshots taking on the phone. I've build both as a standard and development, no difference.
     

    Attached Files:

    Last edited: Jan 8, 2020
  13. arnaud-carre

    arnaud-carre

    Unity Technologies

    Joined:
    Jun 23, 2016
    Posts:
    61
    ok I know what happen. It's not directly related to having multiple material per mesh. It's more like SRP Batcher corner case with plenty of static geometry has 10% slowdown right now. This slowdown comes from binding and uploading some "builtin" buffers, that could be avoided in static geometry context.
    The main issue is that un-necessary binding codepath seems to be extremely slow on mobile ( compared to 10% corner case on desktop)
    Please fill a bug. Put something with "SRP Batcher static batching huge slow down on mobile" in the title. I will work on a fix. Even for corner case, such slow down on mobile should be fixed.
     
    Ruslank100, ekakiya, Ng0ns and 2 others like this.
  14. Ng0ns

    Ng0ns

    Joined:
    Jun 21, 2016
    Posts:
    75
    I filed a report yesterday under the name "SRP Batcher - Performance issue with multiple subobject materials on android". According to fogbugz it should have case number 1209865. Thanks a lot for looking into this :)

    - Cheers.
     
    Peter77 and hippocoder like this.
  15. DavidSWu

    DavidSWu

    Joined:
    Jun 20, 2016
    Posts:
    183
    So is it recommended not to use static batching with the SRP batcher for current production builds?
    We have disabled static batching anyway on mobile because it can use up a lot of memory and the srp batcher seemed to solve the problem "about as well" in terms of performance.
     
  16. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    26,726
    Well, static batching can be heavy and a bit sucky, it's very much one of those features that's always been sort of try it and see rather than guaranteed improvement. Personally I have zero use for it and never have since it's always been slower for me. Probably because I use generally good practises + instancing etc... it just becomes pure overhead in a modern pipeline IMO.

    If it looks like the frame time is way too long it could well be a bug though.
     
  17. GunLengend

    GunLengend

    Joined:
    Sep 24, 2014
    Posts:
    50
    Facing the same issue on Android with my project. Huge performance decrease.
     
  18. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    26,726
    Yeah if you're using static batching wrong (like for lots of small things you want to combine that are the same) - it will be really quite a bit slower. Don't use static batching to lazy-combine. It's not for that... use instancing for those instead.

    Also don't forget, each separate element in a static batch is also checked uniquely for culling so those overheads will always exist unless things are properly merged beforehand.

    Can you see where your time goes with profiler?
     
  19. buFFalo94

    buFFalo94

    Joined:
    Sep 14, 2015
    Posts:
    235
  20. GunLengend

    GunLengend

    Joined:
    Sep 24, 2014
    Posts:
    50
    Can you add more clarify here, we didn't use static batching but the issue still exists, FPS now up to 40 but built-in render make it 60. Also, enable SRP batcher cause negative "saved by batching" on Editor. See the attached picture, I'm using URP 7.2.1 and Unity 2019.3.0f6
     

    Attached Files:

  21. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    26,726
    The stats window is unreliable still, and Unity will take a pass over that when things have settled so rely on profiler and of course the frame debugger.

    Typically though it'll be shaders or post effects ruining your mobile perf first. In this case though I see alarmingly high CPU usage.

    The screenshot you posted isn't helping you, please master the profiler, and profile the android device, not the editor.
     
  22. GunLengend

    GunLengend

    Joined:
    Sep 24, 2014
    Posts:
    50
    First, thank for your time and consideration of the topic. Second, let me takes more deep test and give some screenshots for an easy understanding of the issue.
     
    hippocoder likes this.
  23. GXMark

    GXMark

    Joined:
    Oct 13, 2012
    Posts:
    427
    Just so i'm clear on thi SRP Batcher with materials. Does SRP ignore the material instancing option ? I'm guessing if the material can be batched through SRP it ignores the material instancing but can someone confirm this please.
     
  24. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    26,726
    Material instancing is replaced by the SRP batcher when it's active and material instancing has no effect. It's just dormant UI.

    SRP batcher batches by shader, not material anyway.
     
  25. roberto_sc

    roberto_sc

    Joined:
    Dec 13, 2010
    Posts:
    143
    Can someone please explain this further? :) I don't understand how having lots of static geometry, few materials and 1 shader variant can be a corner case. Which case would the SRP Batches be well suited then?

    Can you provide the bug link?
     
  26. roberto_sc

    roberto_sc

    Joined:
    Dec 13, 2010
    Posts:
    143
    I gave the Github project a run in an iPad mini 2 and it went from 39fps (17.91ms CPU Rendering time) with SPR Batcher on to 42fps (19.36ms CPU Rendering time) with SPR Batcher off.
    Using Unity 2019.3.13.
     
  27. forestrf

    forestrf

    Joined:
    Aug 28, 2010
    Posts:
    99
    Maybe the srp batcher should just ignore static geometry given that it's better handled without it? If it's somehow possible of course
     
unityunity