Working with the SRP Batcher

Tutorial

·

intermediate

·

+10XP

·

10 mins

·

(14)

Unity Technologies

Working with the SRP Batcher

The Scriptable Render Pipeline (SRP) Batcher is a rendering loop that speeds up CPU rendering in Scenes with Materials that use the same Shader variant. To use the SRP Batcher, your project must be using either the Lightweight Render Pipeline (LWRP), the High Definition Render Pipeline (HDRP), or a custom SRP.

Languages available:

1. How the SRP Batcher works

If you are using Unity 2019.3 or above, click here.


In Unity, you can modify the properties of any Material at any time during a frame, though this can have a few drawbacks. For example, the CPU workload for a draw call that’s using a new Material can be high. In such a case, the more Materials you have in a Scene, Unity has to use more of the CPU to set up the data for the GPU. The SRP Batcher reduces this workload by batching a sequence of GPU commands. This batching process helps improve performance, but the batches must be as large as possible.


You accomplish this performance gain by using as few Shader variants as possible, but you can use as many different Materials using the same Shader as you want.


The SRP Batcher works on many platforms. Below is a list of platforms and the minimum Unity version required (for XR, you can use the SRP Batcher only with the SinglePassInstanced mode):


  • Windows DirectX 11 - 2018.2

  • Playstation 4 - 2018.2

  • Vulkan - 2018.3

  • OSX Metal - 2018.3

  • iOS Metal - 2018.3

  • Nintendo Switch - 2018.3

  • OpenGL 4.2 and higher - 2019.1

  • OpenGL ES 3.1 and higher - 2019.1

  • Xbox One DirectX 12 - 2019.1

  • Windows DirectX 12 - 2019.1

2. Enable the SRP Batcher

To enable the SRP Batcher, you must have an LWRP Asset or HDRP Asset in your project and added to your graphic settings.


For new LWRP and HDRP projects, the Asset files can be found in your Assets/Settings folder. If you don’t have these Assets, you can add them from your Project window. To do this:


  1. Right-click on the Project window.

  1. Select Create > Rendering > Lightweight/High Definition Render Pipeline > Pipeline Asset.

  1. Navigate to Edit > Project Settings > Graphics.

  1. Add the LWRP/HDRP Asset you created to the Scriptable Render Pipeline Settings field (Figure 01).

Figure 01: Adding the SRP Asset to the Graphics settings

Figure 01: Adding the SRP Asset to the Graphics settings


3. Activate the SRP Batcher

To use the SRP Batcher, your project must use a Scriptable Render Pipeline project, which can be LWRP, HDRP, or a custom SRP. To activate the SRP Batcher in either LWRP or HDRP:


  1. In the Hierarchy window, select the LWRP Asset or HDRP Asset.

  1. In the Inspector for the Asset, go to the Advanced section.

  1. Enable the SRP Batcher checkbox. (Figure 02).

Figure 02: Enabling the SRP Batcher in the pipeline Asset

Figure 02: Enabling the SRP Batcher in the pipeline Asset


4. SRP Shader Compatibility

In order for the SRP Batcher to render an object, the object must be in a Mesh that’s not a particle or skinned Mesh. The Shader must also be compatible with the SRP Batcher, which encapsulates all lit and unlit Shaders in HDRP and LWRP except for the particles versions of these Shaders.


You can see the compatibility of a Shader in the Inspector panel (Figure 03).


Figure 03: SRP Batcher compatible Shader

Figure 03: SRP Batcher compatible Shader


5. Find the SRP Batcher data in Frame Debugger

In order to debug or find data while using the SRP Batcher, you will need to use the Frame Debugger window to find the batches. To check the status of the SRP Batcher batch:


  1. Open the Frame Debugger window by going to Window > Analysis > Frame Debugger.

  1. Enable Frame Debug, if needed.

  1. Click an SRP batch you want to inspect (Figure 04).

Figure 04: SRP Batch in the frame debugger.

Figure 04: SRP Batch in the frame debugger.


In order to determine SRP Batcher efficiency, refer to the Frame Debug information.


  • Draw Calls: This tells you how many draw calls have been batched. The higher the number, the more efficient it is. If you have a lower number, such as 2, it could be a sign that you have too many Shader variants.

  • Keywords: These are the keywords that the Shaders are using.

  • SRP: This is the reason why the batch been broken. As illustrated in Figure 04, Node use different shader keyword means that the Shader keywords used for the batch are different than the keywords in the previous batch. This lets you know the Shader variant has changed and has to break the batch.

6. Concusion

SRP batching can make complicated and graphics-intensive Scenes more performant. This has a few benefits, such as making draw calls more efficient and, in some cases, it can speed up the global frame rates of your project.


Complete this tutorial