Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

"SRP Batcher" in 2018.2

Discussion in 'Graphics Experimental Previews' started by PhilSA, Apr 18, 2018.

  1. arnaud-carre

    arnaud-carre

    Unity Technologies

    Joined:
    Jun 23, 2016
    Posts:
    97
    SRP Batcher enabled in edit mode is in 2019.1. Sorry 2018.3 didn't have that feature, and you have to click PLAY as you described.
     
    esc_marcin likes this.
  2. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    4,196
    I'm just getting around to realizing that the SRP batcher exists, and so far simply enabling it has seem framerates jump from around 60fps to around 75fps in my project in the editor. However, in a build, there doesn't seem to be any improvement when enabling this. Is there anything I can do to dig into this further?

    Also, when using SRP batching, should/must I disable the Static and Dynamic batching options in Player settings? What if all three are enabled?
     
  3. Tartiflette

    Tartiflette

    Joined:
    Apr 10, 2015
    Posts:
    84
    If it doesn't change anything in the build it probably means you are only CPU-limited in the editor (which is fine). I think dynamic batching is generally considered to be a bit 'meh' or oven counter productive, but static batching is fine and can be used with SRP batching.
     
    dgoyette likes this.
  4. arnaud-carre

    arnaud-carre

    Unity Technologies

    Joined:
    Jun 23, 2016
    Posts:
    97
    You are probably using graphics jobs in your standalone player, so rendering part is not the CPU bottleneck. Graphics jobs are not running in editor, that's why you probably see a speedup in editor. The speedup is really there in standalone, but does not impact global framerate because rendering is not CPU bottleneck in your scene. ( you may find details in that blog post https://blogs.unity3d.com/2019/02/28/srp-batcher-speed-up-your-rendering/ )

    Dynamic batching is automatically disabled for all object going to SRP Batcher code path. Static batching is still effective. ( you should always keep static batching option, can't make things run slower so keep it)
     
    dgoyette likes this.
  5. Quatum1000

    Quatum1000

    Joined:
    Oct 5, 2014
    Posts:
    889
    Hi arnaud-carre

    1) On SRP Batching does Unity send the same textures in 2 different materials twice in the same frame?
    2) And does unity generally transfer all textures meshes and materials in one frame to the gpu?

    + And also interesting is the project from the first video. SRP Batcher Benchmark. Would it possible to share this small one please? I'm interesting how many objects and what texture size is used in this case. I think other uses found this small project useful as well.
     
    Last edited: Apr 25, 2019
  6. hogwash

    hogwash

    Joined:
    Oct 12, 2012
    Posts:
    117
    Does SRP batcher work with meshes referenced from .asset files (This is how Houdini stores it's baked meshes)? It seems to work fine for me in editor but in builds those objects don't render. If I disable SRP batcher then those objects render in builds correctly.
     
  7. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,618
    This sounds like a bug.

    Please submit a bug-report as described in this document:
    https://unity3d.com/unity/qa/bug-reporting

    It's important that you report these issues together with a reproduction project if you want them to get fixed. If you don't do it, it might be a long time until someone else reports them or until Unity Technologies find them.

    After you submitted the bug-report, you receive a confirmation email with a bug-report Case number. Please post the Case number (number only, not the link) in this forum thread for Unity staff to pick up.
     
  8. Lyx5698

    Lyx5698

    Joined:
    Oct 22, 2014
    Posts:
    1
    Hi arnaud-carre
    SRP Batcher is very awesome, but I have some question about sprite renderer

    1. What is the reason for SpriteRenderer not supporting by SRPBatcher? (is it because SpriteRenderer uses MaterialPropertyBlock?)
    2. Will SRP batcher support SpriteRenderer in the future?
     
    Terean and msorokinmycom like this.
  9. teutonicus

    teutonicus

    Joined:
    Jul 4, 2012
    Posts:
    71
    I've got issues with missing meshes in builds too. Haven't had a chance to figure out what the issue is or file a bug report but IIRC a lot of them are just regular old .fbx instances/variants existing in the scene and not necessarily referenced in another .asset file. Have to disable SRP batcher for now.
     
  10. rz_0lento

    rz_0lento

    Joined:
    Oct 8, 2013
    Posts:
    2,361
    Are those meshes bigger than 65k vertices? I discovered today that 2019.2.0a14 at least doesn't render my high poly mesh on standalone again, at least not on development build. There used to be a bug for this that was fixed and it does work now on editor but wondering if it has somehow creeped back in to standalone player as it does only affect the highpoly mesh on my build (yet again).
     
  11. eizenhorn

    eizenhorn

    Joined:
    Oct 17, 2016
    Posts:
    2,685
    Did you set Index Format to 32bit? (4 billion verticies limit instead of 65535 for 16bit)
     
  12. rz_0lento

    rz_0lento

    Joined:
    Oct 8, 2013
    Posts:
    2,361
    Actually I double checked and it's was on 16bit mode when it failed. This is a large mesh, it gets split into 3 chunks with 16 bit setting. There used to be an issue with 32bit indexing with multiple materials in past for bigger meshes but that was fixed.

    I remembered I had returned the mesh to 32 bit index format so I assumed it was the same old bug returning, but it's indeed now using 16 bit indices and it still doesn't show the mesh in standalone (it still has multiple materials so maybe that's still related to the issue). I will investigate this more next week if it's still relevant then.
     
  13. bitinn

    bitinn

    Joined:
    Aug 20, 2016
    Posts:
    961
    The old method for toggling SRP batcher for 2018.3, aka "GraphicsSettings.useScriptableRenderPipelineBatching", no longer works in 2019.1, only LWRP asset seems to be able to control it.

    Not sure if it's a bug or not.
     
  14. rz_0lento

    rz_0lento

    Joined:
    Oct 8, 2013
    Posts:
    2,361
    I finally did some simple repro for my recent SRP Batcher issue. It happens on some meshes, for example all test meshes I've exported from Modo fail but batcher still keeps working on default Unity cube.

    So to make this more clear: SRP Batcher works in editor but fails on standalone but only for some meshes (haven't found a pattern yet).

    I tried both 2019.2 with HDRP 6.5+ and 2019.1 with HDRP 5.13 combos. 2019.1 + HDRP 5.13 is fine, it works as it should in standalone, only 2019.2 + HDRP 6.5+ fails there. I forgot to try 2019.2 + HDRP 5.13 combo though.

    Case ID 1153573.
     
    Peter77 likes this.
  15. chanon81

    chanon81

    Joined:
    Oct 6, 2015
    Posts:
    168
    Hello, I just learned about SRP Batcher. I see that 2019.2b Beta release notes says that

    My question is ... so does 2019.1 have any support for SRP Batcher for mobile? Or is it only 2019.2b that can support it?

    Also is the LWRP and SRP Batcher beneficial for 2D games?
     
  16. RegdayNull

    RegdayNull

    Joined:
    Sep 28, 2015
    Posts:
    68
    SRP Batcher does not support SpriteRenderer? Shader has marker "SRP batcher compatible", but in sprites in Frame Debugger has "SRP: Node is not compatible with SRP batcher". I've seen the previous question, but there is no answer. Standard batching is disabled in RP and in shader, and enabling it does not change anything btw.
     
  17. arnaud-carre

    arnaud-carre

    Unity Technologies

    Joined:
    Jun 23, 2016
    Posts:
    97
    Hi,
    Textures data are persistent in GPU memory. During the batch, texture binding can happen right before each drawcall if needed. Same for meshes. ( ie mesh data is in GPU memory, and some vertex or index buffer binding could occur right before drawcall command if needed). ( more technical details in this blogpost https://blogs.unity3d.com/2019/02/28/srp-batcher-speed-up-your-rendering/ )

    Regarding benchmark scene, you can get it from here: https://github.com/Unity-Technologies/SRPBatcherBenchmark
     
  18. arnaud-carre

    arnaud-carre

    Unity Technologies

    Joined:
    Jun 23, 2016
    Posts:
    97
    This bug has been fixed recently and backport to 2019.2 and 2019.1 are in flight. Till backport are released, you can use that work around: for meshes that aren't displayed, just check the "Read/Write enable" checkbox in the mesh inspector.
     
    rz_0lento likes this.
  19. arnaud-carre

    arnaud-carre

    Unity Technologies

    Joined:
    Jun 23, 2016
    Posts:
    97
    GraphicsSettings.useScriptableRenderPipelineBatching is still working. But recently LWRP changed a bit and set the GraphicsSettings.useScriptableRenderPipelineBatching flag each frame using its own value located in LWRP asset ( so even if you change GraphicsSettings.useScriptableRenderPipelineBatching, it will be re-forced by LWRP main loop )
    As a workaround you can look in to LWRP source code where GraphicsSettings.useScriptableRenderPipelineBatching is set and comment the line ( so you can modify GraphicsSettings.useScriptableRenderPipelineBatching yourself at any time )
     
  20. arnaud-carre

    arnaud-carre

    Unity Technologies

    Joined:
    Jun 23, 2016
    Posts:
    97
    You're right, shader is compatible but render-node type isn't. ( currrently SRP Batcher only support meshes ). We may investigate to add sprite support in the future.
     
  21. arnaud-carre

    arnaud-carre

    Unity Technologies

    Joined:
    Jun 23, 2016
    Posts:
    97
    SRP Batcher works on mobile using Vulkan and iOS Metal for a while. It also supports OpenGL since 2019.1. So yes you should have benefit of SRP Batcher on mobile ( 2019.1 for OpenGL )

    Regarding 2D games, if you're using "mesh" you should also benefit of SRP Batcher. If you're using Sprites, currently we don't support it. We may investigate to add 2D sprite support in SRP Batcher
     
    chanon81 likes this.
  22. RegdayNull

    RegdayNull

    Joined:
    Sep 28, 2015
    Posts:
    68
    That would be great, thank you. Because for now I'm doing very strange things, like building meshes and materials from sprites. It is working, but like voodoo magic. Storing meshes in scene file for static and in ScriptableObject for dynamic things not a best way.
     
  23. Quatum1000

    Quatum1000

    Joined:
    Oct 5, 2014
    Posts:
    889
    Cool, Thanks for the link!

    An interesting aspect of the SRP batcher would be also to mark materials optional as static generally. (Also for standard default rendering.) Properties of static materials can not changed at runtime/play for sure and displayed disabled in inspector.

    The SRP batcher and standard renderer can benefit from as well, in order to know exactly what material can be definitely persistent in GPU.

    The biggest issue are multi tillable materials in both axis, (eg ground or wall textures spread over larger surfaces) where texture atlases not work. Or slicing mesh into several repeating UV rectangles not work as well.
     
  24. bitinn

    bitinn

    Joined:
    Aug 20, 2016
    Posts:
    961
    A follow-up question on this: is there currently any way to disable SRP batcher per material with shader keyword? I see SRP Batcher always takes precedence over GPU Instancing when using MeshRenderer.

    (We know manually calling DrawMeshInstanced / Indirect method is still the fastest way to render; but SRP batcher taking precedence over GPU instancing suggests it is just as fast?)
     
  25. arnaud-carre

    arnaud-carre

    Unity Technologies

    Joined:
    Jun 23, 2016
    Posts:
    97
    No there is no way of disable SRP batcher per material. If the material use a custom shader, you could make the shader "non SRP batcher" compatible on purpose. ( for instance by declaring a material var outside of UnityPerMaterial CBUFFER. It's a bit tricky but could be done.

    I admit it's a bit confusing. SRP Batcher is faster than our "generic GPU instancing". ( the one that try to GPU instance any mesh in the scene). But SRP Batcher isn't faster than "explicit GPU instancing". ( But this one require a dedicated shader, and you have to explicitly build and provide the GPU instancing data buffer)
     
    ekakiya and bitinn like this.
  26. Grimreaper358

    Grimreaper358

    Joined:
    Apr 8, 2013
    Posts:
    789
    Will the GPU instancing option be removed from the SRP materials or HDRP specifically? Since SRP Batcher is on by default and GPU instancing isn't overriding it, it's doing nothing unless you turn SRP Batcher off by code then the GPU instancing kicks in. This is why I'm wondering if it will be removed in the future or changed some how.
     
  27. jimmikaelkael

    jimmikaelkael

    Joined:
    Apr 27, 2015
    Posts:
    796
    This is not what I call tricky but rather annoying... Declaring var outside per material constant buffer itself is not enough. The property needs to be declared too so that shader can be flagged as non SRP Batcher compatible.
    IMHO, this is a very hacky way...

    Does Unity forgot the purpose of "DisableBatching" tag ?
    Please allow us to disable shader compatibility with SRP Batcher using "DisableBatching" tag!
     
  28. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    The SRP Batcher might be disabled in the SRP, or the specific rendering you're doing isn't supported by the SRP batcher, so it still has some use and requires a documentation entry more than any other action, I think.

    What is the use case for ever disabling SRP batcher per material? Why would you want to be slowing your project down by forcing it to take a less efficient path?

    SRP batcher is always faster than not having it.

    Using DrawMeshInstancedIndirect doesn't use it so it is irrelivant as you supply your own details for that...
     
  29. jimmikaelkael

    jimmikaelkael

    Joined:
    Apr 27, 2015
    Posts:
    796
    Dear @hippocoder, I haven't asked for advice, you don't know about any of my requirements. I'm not concerned by performances but just by this tricky way of disabling material from being SRP batched.
     
  30. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Why disable material from being SRP batched? There is no reason to.
     
  31. jimmikaelkael

    jimmikaelkael

    Joined:
    Apr 27, 2015
    Posts:
    796
    I have 3 different materials using the same shader, they require a procedural generated texture to be updated each frame which is different for each materials.
    This won't work (all materials using same procedural texture) unless I disable SRP Batcher for these materials.

    EDIT: Forget it, it works fine.
    As with the tricky way of declaring a uniform outside per material constant buffer it is required have the corresponding for it to work fine.
     
    Last edited: Aug 15, 2019
  32. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    I see, so is this something likely to become more common? The reason I am asking is because Unity is happy to change things if there is a good common use case for it, ie it's logical to invest work into it.

    So when people are asking for things, the use-cases are really important.
     
  33. jimmikaelkael

    jimmikaelkael

    Joined:
    Apr 27, 2015
    Posts:
    796
    Not sure this is common... I use compute shaders to generate texture arrays for some tiles, those were set correctly but without the corresponding shader property inlined with texture array declaration the SRP Batcher was having strange behavior, it was switching from one tile's array to another.

    That said, getting a DisableBatching shader tag that is useless for SRP Batcher is a bit strange, that was my initial rant. Avoiding tricks to disable something is really important yes.
     
    hippocoder likes this.
  34. segant

    segant

    Joined:
    May 3, 2017
    Posts:
    196
    Will SRP batcher support skinned mesh renderer in future?
     
  35. arnaud-carre

    arnaud-carre

    Unity Technologies

    Joined:
    Jun 23, 2016
    Posts:
    97
    I have a good news for you: skinned mesh will be SRP Batcher compatible in 2019.3
     
    segant, hippocoder and rz_0lento like this.
  36. segant

    segant

    Joined:
    May 3, 2017
    Posts:
    196
    Thanks for answer. I want to ask another question. In below picture on android build. Static objects are dark and dynamic text located in origin position. I think this is related to this https://issuetracker.unity3d.com/is...s-are-set-incorrectly-when-using-srp-batching I can acces the game after clearing data files in android settings if working version is installed before.

    I'm using 6.9.1 LWRP and 2019.2
    Will this be fixed in 2019.2 or should i upgrade to 2019.3?
     

    Attached Files:

    Last edited: Aug 19, 2019
  37. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Please post the bug report number, or it cannot be resolved.
     
  38. unity_EQf-tZ-Yple_Cg

    unity_EQf-tZ-Yple_Cg

    Joined:
    Nov 14, 2018
    Posts:
    7
    What happens to the crossfade (SpeedTree) ?
    LOD.png
    SRP Batcher: OFF
    ezgif.com-video-to-gif.gif

    SRP Batcher: ON
    ezgif.com-video-to-gif (1).gif
     
  39. rz_0lento

    rz_0lento

    Joined:
    Oct 8, 2013
    Posts:
    2,361
    This issue has existed on HDRP for quite a long time already but I thought it got fixed already, apparently not then? Which HDRP version do you use? Also can you test 2019.3 and 7.x?

    Also on the SRP Batcher off gif, you should see crossfading regardless of the batcher.
     
  40. segant

    segant

    Joined:
    May 3, 2017
    Posts:
    196
    I will if it's not fixed after that case.
     
  41. unity_EQf-tZ-Yple_Cg

    unity_EQf-tZ-Yple_Cg

    Joined:
    Nov 14, 2018
    Posts:
    7
    This test was done on Unity 2019.1.14f1 and HDRP 5.16.1.
    In previous versions it was the same ...
     
  42. unity_EQf-tZ-Yple_Cg

    unity_EQf-tZ-Yple_Cg

    Joined:
    Nov 14, 2018
    Posts:
    7
    Tested on Unity 2019.3.0a12 (HDRP 7.0.1).
    There again they changed the interface, I could not find where the SRP Batcher turns off ...
    ------------------------------------------------------------
    the test is not completed, because of this ...
    Is this setting enabled by default?
    If so, then everything works ...
     
    Last edited: Aug 21, 2019
  43. julian-moschuering

    julian-moschuering

    Joined:
    Apr 15, 2014
    Posts:
    529
    Currently textures and buffers not defined in the material properties are incorrectly handled as they don't get applied per material. This should be handled by either allowing this or by marking the material as SRP incompatible. Is this a known issue?

    Unfortunately this currently makes SRP incompatible with shaders using a per material buffer as they can't be defined in the material properties.
     
  44. segant

    segant

    Joined:
    May 3, 2017
    Posts:
    196
    Hi arnaud. Thanks for your hardwork. My problem has solved for long time. Now i have a few questions. I'm building on android. Which way is more performance with lots of spectators. They use same materials but instanced. I couldn't see much performance difference between shared material and instanced material. But sharedmaterials load much quicker.
    Do vertices count still affects performance high amount even srp is on?
    Do setpass calls count important when using srp? I have reduced it to half and render thread now much less than before. I haven't tested on device. I will after i reduce more.(I have tested it. It's a game changer. So much difference. So i'm looking for particle and text mesh pro batching and maybe new ui shader for urp and batching.)
    Any eta on particles shader and textmeshpro shaders and ui shader srp in Universal RP?(I have tried with dynamic batching but it breaks because it's mixed with ui and textmeshpro ui shaders so it breaks too much. I think dynamic batching consuming more cpu power than srp.)
     
    Last edited: Oct 5, 2019
  45. bitinn

    bitinn

    Joined:
    Aug 20, 2016
    Posts:
    961
    Strange question:

    I have another project using built-in pipeline, but I have ported a SRP batcher compatible shader library to it (instead of using built-in shader library), is there a chance to use SRP batcher?
     
  46. hsallander

    hsallander

    Joined:
    Dec 19, 2013
    Posts:
    46
    As far as I can gather from the Unity documentation SRP Batching isn't available in WebGL since WebGL uses OpenGLES3.0 and not 3.1 that's required for SRP Batching right now, please correct me if I'm wrong. @arnaud-carre and @phil_lira, are there any plans to bring SRP batching to WebGL as well in the future? And if so, do you have any time frame or target version of Unity for this that you could share with us?
     
    hippocoder likes this.
  47. sqallpl

    sqallpl

    Joined:
    Oct 22, 2013
    Posts:
    384
    @arnaud-carre

    Hi,

    It looks like the SpeedTree 'Tree' component (afaik it's responsible for doing some wind calculations and sending them to the material) is breaking the SRP Batcher batching.

    Is there any chance that it will be compatible with SRP Batcher? I'm testing it on 2019.1.1 so maybe the question is not revelant anymore.

    BTW. It could be related to same/similar scenario as @julian-moschuering described in this thread but I'm not sure about that. I don't know how the 'Tree' component really works.

    Thanks.
     
    Last edited: Jan 20, 2020
  48. HQF

    HQF

    Joined:
    Aug 28, 2015
    Posts:
    40
    Hi all, i using 2019.3 and URP and VR with singlePass, also i enabled SRP batching and all my materials compatible with SRP (i use UniversalPipeline/Lit). But looks like SRP batching works in editor when Unity not in Play mode, but when i hit play SRP batching dissappears and i dont see SRP batch in frame debugger and SRPBatcherProfiler.cs shows that SRP batcher code doesnt runs and all objects renders with standard code path. Is it bug or what?
     
  49. xVergilx

    xVergilx

    Joined:
    Dec 22, 2014
    Posts:
    3,296
    So, in which cases its better to use SRP batching, and where is it better to use GPU instancing?

    From reading this thread it seems like SRP batching should be faster anyways?

    Is it worth making shaders for GPU instancing, or it can be just dumped?
     
  50. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    SRP batching replaces GPU instancing, if the GPU instancing is material based (tickbox). If you use DrawInstanced, this will be faster but you manage everything yourself.
     
    xVergilx likes this.