[Go] Draw call is not batched? Tell you how to find the reason in Unity 5.6 [Copy link]

Source: Internet
Author: User
Tags unity 5

Unity did not provide a straightforward way to find out why draw call was not batched in the previous version of 5.6, but Unity 5.6 added a feature in frame debugger to help developers find relevant information. Today's article will share how you can see why draw call is not being batched in unity 5.6.

As you all know, Unity's built-in dynamic and static batching helps reduce the number of draw call in the game. In the stats window, when the value of "Saved by batching" is greater than 0 o'clock, the batch is already in effect. Unfortunately, it is difficult to know why the batch does not take effect, although the Unity manual provides some possible reasons, but this information requires the user to understand the relevant basics.

<ignore_js_op>


The good news is that a new feature has been added to the Unity 5.6 frame debugger to tell us why unity initiated the new batch process.

Frame debugger is a new feature launched by Unity 5.x, click menu item window > frame debugger to open the frame debugger. This window shows all the batches in the game, along with all the details of the batches, including shaders, textures, and lots of setup information used by the batch.

Before you go into detail about when Unity initiates a new batch process, learn about the concept of batching and its role.

<ignore_js_op>


The Frame debugger in Unity 5.6 now explains why Unity initiated the new batch process.

What is batching (batch)

Unity in order to draw the game object on the screen, it needs to launch a "draw" command to the graphics API. This process is actually a "Draw call". But before the command is launched, Unity also needs to set the desired GPU state for the drawn objects: grids, shaders, textures, blending settings, and some other shader properties. The state Change command, together with one or more drawing commands, is called a batch.

Batch processing process (batching)

The reason for the slow batch process is the command to change the GPU state, while the draw command actually consumes very little resources. So unity always tries to render multiple objects simultaneously using the same GPU state. This process is known as batch processing.

Unity offers three types of batch processing: Static batch processing, dynamic batching, and GPU instancing.

    • Static batching merges multiple static mesh objects into one or more large mesh objects at build time, and then renders multiple objects in a large grid at run time with a batch.
    • Dynamic batching gets multiple small mesh objects in each frame, vertex-transforms them in the CPU, groups similar vertices together, and draws them once.
    • GPU instancing (introduced in Unity 5.4) can draw multiple identical objects with different position, rotation, and other shader properties with a few draw call.


Causes of batch Failure

It is sometimes clear in the editor that some objects that should have been batched are not batched for some reason. First, check to see if the batch processing feature is enabled in player settings. This step seems redundant, but we have too many failure cases because we forgot to turn on the feature.

We have provided a sample project for this purpose to demonstrate the circumstances under which unity must initiate a new batch request. First download the project and import the Unity project. Note that you need to use unity 5.6 to see a description of the batch status in frame debugger.

The following are the reasons why batch processing is not possible in the example project (Unity 5.6). Each reason corresponds to a separate batch.

  • The Additional Vertex streams-object uses Meshrenderer.additionalvertexstreams to set up additional vertex streams.
  • Deferred Objects on Different Lighting layers-The object is in a different light layer.
  • Deferred Objects Split by Shadow distance-Two objects have one within the shadow distance range and the other is not.
  • Different Combined meshes-The object belongs to another merged static mesh.
  • Different Custom properties-The object sets a different materialproperyblock.
  • Different lights-The object is affected by different forward illumination (Forward light).
  • Different materials-The object uses a different material.
  • Different Reflection probes-The object is affected by different reflection probes (Reflection Probe).
  • Different Shadow Caster hash-The object uses other shadow-casting shaders, or sets different shader parameters/keywords that affect the output of the shadow-cast pass.
  • Different Shadow Receiving settings-The object sets a different "Receive Shadows" parameter, or some objects are within the shadow distance, while others are outside the distance.
  • The Different static batching flags-The object uses different static batch settings.
  • Dynamic batching Disabled to Avoid z-fighting-player settings, or is temporarily shut down in the current environment to avoid deep conflicts.
  • Instancing Different geometries-uses GPU instancing to render different meshes or sub-grids.
  • Lightmapped objects-objects use different light maps, or have different light map UV transitions in the same light map.
  • Lightprobe affected objects-objects are affected by other illumination probes (light Probe).
  • Mixed sided Mode Shadow casters-object's "Cast Shadows" setting is different.
  • The Multipass-object uses a shader with more than one pass.
  • Multiple Forward lights-The object is affected by multiple forward light rendering.
  • The Non-instanceable property set-is set to non-instanced properties for instanced shaders.
  • Odd Negative scaling-There is an odd number of negative values for the scaling of the object, for example (1,-1,1).
  • The Shader disables batching-shader explicitly turns off batching using the "disablebatching" tab.
  • Too many Indices in dynamic batch-too many active batch indexes (over 32k).
  • Too many Indices in static batch-there are too many composite mesh indexes in the stationary batch. For OpenGL ES, the 48K,OSX is 32k, and the other platforms are 64k.
  • Too many Vertex Attributes for dynamic batching-has more than 900 vertex properties for the sub-grid to be dynamically batched.
  • Too many Vertices for dynamic batching-the number of sub-mesh vertices to be dynamically batched is more than 300.


Conclusion
Now you can start using frame debugger to check the project and help you find what you can do with batching. As the engine continues to update, you may add more reasons for the batch failure in the future, so please follow our project on GitHub.

[Go] Draw call is not batched? Tell you how to find the reason in Unity 5.6 [Copy link]

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.