Unity's Scriptable Render Pipeline (URP/HDRP) has a powerful batching mechanism called "SRP Batcher" that dramatically reduces the overhead of drawing instructions on the CPU side. However, as soon as you use Shader Graph to implement "vertex animation (transformation of Vertex Position)" such as the expression of plants swaying in the wind or the movement of waves, the SRP Batcher, which was functioning normally until then, becomes invalidated, and the number of draw calls (Draw Calls) increases explosively to hundreds to thousands, causing a problem that can severely reduce the performance of the entire game.
In this article, we will explain why Shader Graph's vertex deformation processing inhibits SRP Batcher, explain the mechanism, and introduce a specific solution approach to avoid draw call explosion and maintain high-speed drawing.
For beginners: How would you describe this problem in real life?
Let's compare the relationship between SRP Batcher's batch processing and failure caused by vertex animation to an "attraction ride at a theme park."
A guide (SRP Batcher) is standing at the entrance to the attraction. When a large number of tour passengers wearing clothes with the same design (objects with the same material) arrive, the guide quickly performs boarding procedures all at once, saying, ``You're all in the same group. Everyone get on this large bus (one draw call) together!'' This is ultra-high speed through batching.
However, if you randomly create vertex deformations using Shader Graph, the tour guests will ``sway in the wind, so they each walk in a strange dance at different times.'' Even though the design (material) of the clothes is the same, each dancer dances at completely different times and with different movements (they have individual vertex deformation parameters), so the usher has no choice but to instruct, ``Due to the danger, we cannot guide everyone all at once. Please take a separate taxi (individual draw call) for each person.'' As a result, transportation that used to require just one tour bus turned into a huge queue of taxis (an explosion of draw calls), and attractions became heavily congested. In order to solve this problem, it is necessary to redesign the cue for everyone to dance the same dance (enable GPU instancing) and the line-up arrangement that is easier for tour conductors to manage.
Problem symptoms and specific phenomena
When this bug occurs, the following symptoms are observed.
- When placing a large number of wind-swaying plant assets in a scene,
Batches(orDraw Calls) in the Profiler or Statistics panel (Stats) increases dramatically in proportion to the number of objects. - When checking with Frame Debugger, the error reason
SRP Batcher [Disabled]orNot Compatibleis displayed in the drawing path, and the batch is fragmented into small pieces. - Removing the vertex deformation node (connection to Position) dramatically reduces draw calls and restarts batching.
Possible cause: Why does SRP Batcher not work?
The basic principle for SRP Batcher to work is that they share the same shader code, and that the size and structure of the global property constant buffer (UnityPerMaterial CBUFFER) in the shader are completely matched.
When performing vertex animation (connecting Vertex Position) with Shader Graph, you may define unique deformation parameters for each material (swaying speed, random seed value depending on the individual position of the object, etc.). If these properties are defined outside of the UnityPerMaterial constant buffer, or if the way object-specific local coordinate transformations are calculated deviates from SRP Batcher compatibility, Unity will determine that this object has non-constant material properties and exclude it from SRP Batcher's fast route. As a result, even if the material is the same, rebinding from the CPU to the GPU occurs every time, resulting in a dramatic increase in draw calls. The same is true if the settings for use with GPU instancing do not match.
Specific solutions and approaches
To avoid this draw call explosion, consider the following two approaches.
Approach A: Explicit combination of GPU Instancing
When arranging a large number of identical assets such as plants and rocks, it is most efficient to prioritize GPU Instancing instead of SRP Batcher.
In the Shader Graph material settings, explicitly turn on the Enable GPU Instancing checkbox at the bottom.
[Material Inspector Settings]
☑ Enable GPU Instancing <-- これを有効化する
(これにより、同一メッシュ&同一マテリアルの大量描画が1つのインスタンスコールに集約されます)Also, make sure Support GPU Instancing is enabled in the Shader Graph Settings. This allows batch drawing (instancing) to be performed on the GPU side even when deformation is occurring due to vertex animation, dramatically reducing draw calls.
Approach B: Shader design to maintain SRP Batcher compatibility
If you want the SRP Batcher to work, you must design all custom properties entered into the Shader Graph's vertex inputs to be contained in the UnityPerMaterial constant buffer. Specifically, you should default Override Property Declaration to Global or Hybrid Per-Instance in the property node inspector settings to avoid special settings that would destroy buffers.
Confirmation checklist useful in practice
This is a checklist to prevent draw call explosion before building.
| Confirmation items | Confirmation/remedy procedure |
|---|---|
| Why Frame Debugger | Select the drawing item in Frame Debugger and decipher the string that causes the batch to be Not Compatible. |
| Enable GPU Instancing | Is Enable GPU Instancing checked for the corresponding material of the Prefab that will be placed in large quantities? |
| Constant buffer alignment | In the C# code and HLSL generated by Shader Graph, do the properties fit neatly within CBUFFER_START(UnityPerMaterial)? |
Summary
Vertex animation in Shader Graph enables rich effects, but if you are not aware of the drawing pipeline mechanism, it will lead to an explosion of draw calls. For mass-produced plants and effects, actively use GPU Instancing and adjust material and graph settings to comply with SRP Batcher's compatibility rules to achieve both beauty and smooth frame rates at a high level.