SRP Batcher of URP Shader in Unity


Preface

In the previous article, we learned that SRP Betcher can be allowed only by using the constant register CBUFFER.

In this article, we take a look at what SRP Batcher is.


1. What is SRP Batcher?

  • The SRP Batcher is a render loop that speeds up CPU rendering in a scene with many materials using the same shader variant.

  • Unity help documentation


2. Conditions of use of SRP Batcher

1. Programmable rendering pipeline

  • URP
  • HDRP
  • Custom SRP

2. Let’s use URP as an example

  • Ensure the project uses URP
    Insert image description here

3. Use SRP Batcher is turned on in URP settings.

  • Turn on the Debug mode of the Inspect panel
    Insert image description here
  • Make sure Use SRP Batcher is turned on
    Insert image description here

4. Enable the SRP Batcher code path to render objects

  • Rendered objects must be meshes or skinned meshes. The object cannot be a particle.
  • Shaders must be compatible with SRP Batcher. All lit and unlit shaders in HDRP and URP comply with this requirement (except for the "particle" versions of these shaders).
  • Rendering objects must not use MaterialPropertyBlocks.

5. Make shaders compatible with SRP Batcher:

  • All built-in engine properties must be declared in a CBUFFER named "UnityPerDraw". For example: unity_ObjectToWorld or unity_SHAr.
  • All material properties must be declared in a CBUFFER named UnityPerMaterial. That is, the constant buffer of the previous article

CBUFFER_START(UnityPerMaterial)
half4 _Color;
CBUFFER_END

Insert image description here


3. Differences between different batches

BuildIn Render Pipeline下:

  1. Static Batching (static batching)
  1. Dynamic Batching
  1. GPU Instancing (GPU instantiation)

Universal Render Pipeline下:

SRP Batcher (SRP batch)
Need to meet: the conditions for the use of SRP Batcher mentioned above


4. Compare the differences between each batch of renderings between BRP and SRP

1. Under BRP

Insert image description here

2. Under SRP (the CPU part is the core of SRP)

Insert image description here

5. In Unity, test the effect of turning on and not turning on SRP Batcher.

  • In Unity, prepare a scene like this for testing. Four objects use different shaders of the same Shader.
    Insert image description here

1. Do not turn on SRP Batcher (HDR needs to be turned off)

Insert image description here

Insert image description here
4个对象用了4个批次

2. Enable SRP Batcher

Insert image description here
只用了一个批次

Guess you like

Origin blog.csdn.net/qq_51603875/article/details/135021128