Search Unity

[Unity 5.3] Static batching not batch draw calls

Discussion in 'General Graphics' started by MinhDao, Dec 8, 2015.

  1. MinhDao

    MinhDao

    Joined:
    Oct 28, 2013
    Posts:
    155
    Hi,

    I've just test Unity 5.3 with empty scene and static batching seem not working correct.
    Step :
    • Create new project and new scene
    • Create Cube + Sphere + Plane
    • Disable all light, shadow, quality setting is simple
    Result:
    • Unity 5.1.2 : SetPass Calls : 2 Draw Calls : 2 Total Batches : 4
    • Unity 5.3 : SetPass Calls : 2 Draw Calls : 4 Total Batches : 2
    Test with my game build on android, fps drop from 40fps => 15fps
    Please check this case!
     
  2. superpig

    superpig

    Quis aedificabit ipsos aedificatores? Unity Technologies

    Joined:
    Jan 16, 2011
    Posts:
    4,124
    Did you mark the objects as static?
     
  3. MinhDao

    MinhDao

    Joined:
    Oct 28, 2013
    Posts:
    155
    Yes, all object were marked as static
     
    Last edited: Dec 8, 2015
  4. superpig

    superpig

    Quis aedificabit ipsos aedificatores? Unity Technologies

    Joined:
    Jan 16, 2011
    Posts:
    4,124
    OK. Could you open the empty project you created, go to the Help menu, and choose 'Report a Bug'? It's going to be much more reliable if you can send us the project where you're seeing this behaviour, instead of us trying to create it and maybe missing steps (like marking the objects as static...) Once you're done, let me know the bug number and I'll see if I can look at it.
     
  5. rstorm000

    rstorm000

    Joined:
    Aug 19, 2010
    Posts:
    212
    dynamic batching appears to be on the fritz for me (OSX)
     
  6. MinhDao

    MinhDao

    Joined:
    Oct 28, 2013
    Posts:
    155
    It seems like i missing something.
    Release note of Unity 5.1.4 :

    • (716978) - Profiler: Fixed Rendering detailed stats. Stats for Draw Calls and Total Batches were previously swapped.
    So Draw calls stats is total draw calls before batching! Am I understanding correctly?
     
  7. st-VALVe

    st-VALVe

    Joined:
    Jan 8, 2014
    Posts:
    11
    So any news about it?
     
  8. MinhDao

    MinhDao

    Joined:
    Oct 28, 2013
    Posts:
    155
    I tested with some cubes, here is result (Unity 5.2.2 f1):

    If i use dynamic batching with 3 cube same material, i have :
    • SetPass Calls : 1 | Draw Calls : 2 | Total Batches : 2
    If i use static batching with 3 cube same material, i have :
    • SetPass Calls : 1 | Draw Calls : 4 | Total Batches : 2
    So, static batching not batch draw calls? Can someone explain me about static batching? If it isn't reduce draw calls, what it does?
     
  9. st-VALVe

    st-VALVe

    Joined:
    Jan 8, 2014
    Posts:
    11
  10. ifurkend

    ifurkend

    Joined:
    Sep 4, 2012
    Posts:
    347
    Create 2 default particle system prefabs...

    Unity 5.2: One batched
    Unity 5.3.1p1: None batched

     
    RakshithAnand likes this.
  11. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    3,221
    Particle systems are not batched now as we have a multi-threaded particle backend so its not possible. If you do notice a regression in performance between the 2 methods then do please let us know however it should be better overall.
     
  12. ifurkend

    ifurkend

    Joined:
    Sep 4, 2012
    Posts:
    347
    I am not complaining as I have tested a rather complicated particle effect on a (relatively new) mobile phone and it runs surprisingly at 60 fps. I just want to confirm one thing: Does the multi-threading use more power for processing? This can be quite sensitive on mobile platforms.
     
  13. Sandler

    Sandler

    Joined:
    Nov 6, 2015
    Posts:
    48
    Pushing this.
    Does this mean if i compile without multiple threaded settings, particle systems will be batched?
    Wasn´t there a thread were multithreading lead to crashes?
     
  14. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    3,221
    No batching does not work with particle systems any more. The multi threading is done before rendering, its for calculations of each particle's properties, positions/sizes etc. The rendering happens after this stage so they are 2 seperate things. I am not aware of any crashes related to particle threading. Do you have a link?
     
  15. joshenes

    joshenes

    Joined:
    Apr 18, 2014
    Posts:
    46
    Is there any way we can have an option in the Player settings for "Particle System Batching" that would use the old system when enabled and allow particles to be batched?

    Our game has lots of particle systems for weapon effects, foot impacts, and all kinds of stuff. Each particle system usually has only a small number of particles. A lot of effort has been spent ensuring that all particle systems use an atlas and share the same material so they will be able to batch.

    This change has drastically increased the number of draw calls, especially since we are developing for VR and the draw calls are doubled. It has impacted us to the point where we would probably have to use a third-party solution for particles going forward.

    I'm curious why calculating particles in a thread would exclude them from being batched. Is it calculating *each* particle system in a separate thread? If so, this seems like an overly aggressive optimization that would only be beneficial in certain circumstances with a small number of particle systems that have many particles each.
     
    Rycons likes this.
  16. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    3,221
    Have you actually noticed a regression in fps?

    We are prototyping a version that does both threading and batching. This will be in a future release though, not something we will backport as its a substantial feature change.
     
  17. joshenes

    joshenes

    Joined:
    Apr 18, 2014
    Posts:
    46
    Yes. We are targeting 90Hz on VR and 144Hz for regular screens. In a real-world scenario, I find that as the number of batches increases we essentially get cut off from reaching those higher frame rates.

    An increase in batches in one part of the engine means we need to reduce them somewhere else.
    Particle effects are an especially bad area for this to happen since the number of particle systems on screen can fluctuate wildly once the action starts, as opposed to predictable things like characters and pieces of environment.

    The batching page in the online manual also still says that particles will be batched, so this might be confusing for someone reading.

    I don't suppose there is any chance of getting this new particle batching in 5.4? You'd have a new #1 fan. :)
     
  18. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    3,221
    Hard to make any promises about when the feature will be available at this stage. It was only implemented today so it's going to take some time to test and iron out any issues. We will update the docs though.
     
  19. richardkettlewell

    richardkettlewell

    Unity Technologies

    Joined:
    Sep 9, 2015
    Posts:
    912
    Hey, I wanted to provide another update on this.

    We have been working on reinstating dynamic batching for particle systems, to work with the new multi-threading, and have made good progress. We are currently testing a solution, and assessing the risks with putting the change into various Unity versions.

    We will update you again when we have more to report.
     
  20. joshenes

    joshenes

    Joined:
    Apr 18, 2014
    Posts:
    46
    That sounds wonderful, thank you for your efforts!
     
  21. Jodon

    Jodon

    Joined:
    Sep 12, 2010
    Posts:
    411
    For our Gear VR game this is killing us on performance. Anxiously awaiting updates. It's unlikely we can ship without a fix. I tried going back to legacy particle systems, but they seem to be broken as well :(.
     
  22. RakshithAnand

    RakshithAnand

    Joined:
    Jun 30, 2013
    Posts:
    54
    Hi,

    Any news on this? Need to release my iOS game in few days. Just want to know when this dynamic batching will be back. Please let me know.

    Thanks
     
  23. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    3,221
    Its currently in the queue to go into 5.3. It's unlikely to be in next weeks patch but may be in the week after. Cant say for sure until it actually goes in.
     
  24. RakshithAnand

    RakshithAnand

    Joined:
    Jun 30, 2013
    Posts:
    54
    Thats good to know thank you!
     
  25. richardkettlewell

    richardkettlewell

    Unity Technologies

    Joined:
    Sep 9, 2015
    Posts:
    912
    Hi all,

    Dynamic Batching for particles, lines and trails was submitted today into 5.3.4 Patch 2, which will be released soon!
     
  26. joshenes

    joshenes

    Joined:
    Apr 18, 2014
    Posts:
    46
    Great to hear. Thanks!
    I've since moved on to 5.4 beta for the VR features included. Any idea when it might make it into 5.4?
     
  27. richardkettlewell

    richardkettlewell

    Unity Technologies

    Joined:
    Sep 9, 2015
    Posts:
    912
    I've just had confirmation that this fix has also (just!) made it into 5.4.0 Beta12 :)
     
  28. Sandler

    Sandler

    Joined:
    Nov 6, 2015
    Posts:
    48
    Awesome thanks! :)
     
  29. RakshithAnand

    RakshithAnand

    Joined:
    Jun 30, 2013
    Posts:
    54
    So even line renderers are batched now? If so awesome! :)
     
  30. joshenes

    joshenes

    Joined:
    Apr 18, 2014
    Posts:
    46
    Will lines, trails, and particles cross-pollenate and batch with each other if they meet batching requirements? Just an idea. :)
     
  31. ifurkend

    ifurkend

    Joined:
    Sep 4, 2012
    Posts:
    347
    As far as I concern, the default trail renderer does not batch before 5.3. You can try the free "Melee Weapon Trail" on asset store which is quite old already but still works fine in 5.4.0b10 and batches multiple trails of same material.
     
  32. ifurkend

    ifurkend

    Joined:
    Sep 4, 2012
    Posts:
    347
    Batching is happening, but I would appreciate if there is any indication of "saved by batching" in stats like in 5.2.

    And thanks for making the default trail renderer batches now.

     
    Last edited: Mar 30, 2016
  33. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    3,221
    Hmm does it not do that. Could you file a bug report?
     
  34. ifurkend

    ifurkend

    Joined:
    Sep 4, 2012
    Posts:
    347
    Because 2 or more particle systems with same material only generate 1 call, I assume batching is in effect. I've submitted a report anyway about that "saved by batching" stat.
     
    karl_jones likes this.
  35. joshenes

    joshenes

    Joined:
    Apr 18, 2014
    Posts:
    46
    I wanted to say thanks again for this feature, and let you know that it has resolved the performance issues we were experiencing in our game. It seems to reduce to a few draw calls instead of only one, but I assume this is because it is batching the particles per worker thread? In any case, it is reduced enough to not be a concern. Thanks!
     
    richardkettlewell and karl_jones like this.
  36. richardkettlewell

    richardkettlewell

    Unity Technologies

    Joined:
    Sep 9, 2015
    Posts:
    912
    Great to hear that this has helped your performance :)

    There are a few reasons why you might be seeing slightly more than 1 batch, but if you are using the experimental graphics jobs feature in 5.4, then your guess is likely to be the correct one.

    Regarding the saved by batching stat, our internal qa team had spotted that too, so it's already logged and I'll take a look at it very soon.
     
    karl_jones likes this.
  37. chsadao

    chsadao

    Joined:
    Apr 14, 2016
    Posts:
    2
    draw call is still 2 in 5.4 when i created 2 particle system with the same material, and set their 'texture sheet animation'.之前用5.1的时候这样做的话DrawCall是只有1的。draw call is 1 if i do this in 5.1. can somebody tell me why?
     
  38. ifurkend

    ifurkend

    Joined:
    Sep 4, 2012
    Posts:
    347
    Can you capture a screen shot of a bare scene (no light) with 2 identical default particle system objects?

    你可以像我上面那帖般截张图看看吗?从最简单场景(没有灯光)建两个预设的粒子系统物件。还有你的Unity 5.4是b几?
     
  39. chsadao

    chsadao

    Joined:
    Apr 14, 2016
    Posts:
    2
    this is the state in 5.4.0b12:(它在5.4.0.B12里是这样的)
    upload_2016-4-16_13-59-23.png

    and this is the state when i do the same things in 5.1.1:(同样的做法在5.1.1里drawccall只有1)
     

    Attached Files:

  40. richardkettlewell

    richardkettlewell

    Unity Technologies

    Joined:
    Sep 9, 2015
    Posts:
    912
    The stat reporting was still a little broken in 5.4.0b12, although batching is working. The reporting has been fixed since then, so hopefully the most recent beta (15) will give you better stats for the rows underneath the line you have highlighted.

    You may still find it says 2 for draw calls though, due to how to the new particle batching works. However, the important stat is the "Total Batches", which is 1 in both versions.

    - 5.1 copies all the particle data for each system into one contiguous buffer, on the main thread, in order to batch things into 1 draw call. This is slow and doesn't scale well to multi-core.
    - The new batching in 5.3+ builds the geometry into one buffer on multiple threads, then binds the buffer and all the state, and finally issues multiple draw calls for each valid range of the buffer. This last part is how static batching works, and is very fast.

    On devices that do not have threads, there should be no significant performance difference.
     
    ifurkend and karl_jones like this.
  41. bioticste

    bioticste

    Joined:
    Aug 11, 2014
    Posts:
    12
    I'm using Unity 5.3.5f1 and getting 0 in saved by batching, the framerate is constantly dropping below 60fps. When I was using 5.2 saved by batching was always between 50 and 70 and the game ran at a solid 60+fps. I was wondering if this issue will be fixed or if I should revert to using Unity 5.2. Thanks :) Unity 5_2 Batching OK.jpg Unity 5_3_5 Batching Not OK.jpg

    The images show the batching issue in a simple scene with a directional light source.
     
    Last edited: Jun 9, 2016
  42. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    3,221
    Try using the frame grabber and seeing if they are actually batched. It looks like they are to me. 2 batches is being reported.
     
  43. richardkettlewell

    richardkettlewell

    Unity Technologies

    Joined:
    Sep 9, 2015
    Posts:
    912
    It looks like the same bug in the stats that was discussed higher up this thread. The "Batches" and "SetPass calls" both suggest that the batching is working.
     
  44. xxhaissamxx

    xxhaissamxx

    Joined:
    Jan 12, 2015
    Posts:
    130
    i have 110 cube with default material , i found batching only 3 so i thought there is something with my material when i used my material have same result (3)

    After adding my modeling has 3 batches like 1 cube so after add same number of cubes (110) and with same material give me 15 batches :/


    so why cube after 110 have only 3 and for my modeling it's 15 ?
     
  45. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    5,950
    Each batch has a limit on the amount of vertex data it can hold. Higher poly objects (or more complex shaders) reduces the number of objects that can be combined.
     
    colin299, xxhaissamxx and karl_jones like this.
  46. colin299

    colin299

    Joined:
    Sep 2, 2013
    Posts:
    131
    1.Are there any guideline about the vertex data limit?
    I am on Android and different mesh results different static batch number.

    The only difference of the test below is the meshFilter's mesh.
    The more the vertices, static batching results more batches( about 7k vertices per batch)
    -Camera no distance sort
    -all mesh renderer same material
    -all static

    2.Is there a way to make static batch works on more vertices?
    I tried cut vertex data like tangent,normal,uv, but no difference
    static batching difference.png
     
  47. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    3,221
    Unity has a limit of 65535 vertices per mesh. A batch is just a lot of meshes combined to form 1 mesh so the limit still applies. There is no way around this. We would need to change all meshes to use 32 bit ints instead of 16 bit which would double the memory for all mesh indices.
     
    colin299 and richardkettlewell like this.
  48. xxhaissamxx

    xxhaissamxx

    Joined:
    Jan 12, 2015
    Posts:
    130
    so is there anyway to decrease vertices to make all Objects use save batching ?
     
  49. colin299

    colin299

    Joined:
    Sep 2, 2013
    Posts:
    131
    @karl.jones thanks for replying to the question!
    I understand Unity's mesh has a limitation of 65535 vertices per mesh so everything fits into the unsigned 16-bit binary number range, so memory usage is optimal for most case, which is good!

    But from the test I posted above, and a new test below, Unity's static batching's batch is not containing vertex number close to 65535. Stat from different test:
    1. 10k vertices produce 2 batches (expectation is 1)
    2. 70k vertices produce 7 batches (expectation is 2) = average 10k vertices / batch
    3. 160k vertices produce 21 batches (expectation is 3) = average 7.6k vertices / batch,
    4. 1.0M vertices produce 121 batches(expectation is 16) = average 8.3k vertices / batch

    There is 1 batch from glclear, which is ignored.

    summary:
    Unity Static batching is not reaching its vertex limit(65535) per batch, but rather 7.6k~10k vertices per batch, are there any other limitation other then vertex number?

    unity static batch 8k vertice limit.png
     
  50. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    3,221
    Try using the frame grabber to get better details. How many verts are in each model?