Search Unity

Question Can SRP Batcher be enabled on some of shader variants of a shader?

Discussion in 'Shaders' started by zhutianlun810, Dec 15, 2021.

  1. zhutianlun810

    zhutianlun810

    Joined:
    Sep 17, 2017
    Posts:
    172
    Hello,

    It seems like I can enable srp batcher on a shader if and only if all shader variants of the shader are Srp batcher compatible.
    If I have code like:
    Code (CSharp):
    1. #ifdef _ENABLE_CB
    2. CBUFFER_START(UnityPerMaterial)
    3. #endif
    It will always say "Material property is found in another cbuffer than UnityPerMaterial", no matter the keyword is enabled or not. It does not make any sense to me.
     
  2. aleksandrk

    aleksandrk

    Unity Technologies

    Joined:
    Jul 3, 2017
    Posts:
    3,026
    That's correct.
     
  3. zhutianlun810

    zhutianlun810

    Joined:
    Sep 17, 2017
    Posts:
    172
    I am using 2019.4.17f1. I am encounter a performance issue.
    I have two version of shader. One is a normal shader(A), the other one(B) have UnityPerMaterial and UnityPerDraw declared. In the scenaro of srp batcher disabled. The renderthread of using A is faster of using B.

    From the renderdoc, I can see that A is updating unity_objectToWorld by glUniform4fv. However, B is updating unity_objectToWorld by glBufferSubData. I feel refresh the all buffer to just update one unity_objectToWorld is the reason why B is slower than A.

    I don't know is there any good way to deal with this problem. CB generation is totally determined by shader. That is, if I declare a CBUFFER_START in the shader, I must use the CB ways to update the value. There is no way for me to use glUniform4fv.

    The problem is some of target devices can support srp batcher but some of can not. I am trying to determine enable/disable srp batcher at runtime(Easy), and, for the part of devices disable srp, the performance is same as using shader which CBUFFER declarations are removed(Seems not possible now).
     
    Last edited: Dec 17, 2021
  4. aleksandrk

    aleksandrk

    Unity Technologies

    Joined:
    Jul 3, 2017
    Posts:
    3,026
    Devices that don't support SRP batcher will work fine and won't use CBUFFERs, even with shaders that declare them.