EileenGran 发表于 2023-3-19 18:46

Unity合批(Batching)的限制与失败原因汇总

      Unity中Batching大致可以分为StaticBatching,DynamicBatching,SRPBatching与GPUInstancing四大类,但在使用时我们经常会遇到合批失败的情况,这里汇总了四大类的合批使用限制与合批失败的关键错误信息,建意收藏。Static Batching的限制

额外的内存开销
64000个顶点限制
影响Culling剔除
Dynamic Batching的限制

合批不超过900个顶点属性,(注意不是900个顶点)
除了渲染阴影对象外,相同材质,不同材质实例也不能合并
具有光照贴图的游戏对象如果有附加渲染器参数时,如果需要动态合批这些对象,他们必须指向相同的光照贴图位置。
有多Shader Pass的游戏对象无法做动态合批
受多个光照影响的游戏对象,满足动态合批条件合批后,只会受一个光源的影响
延迟渲染下不支持动态合批
CPU开销可能会增大,需要测试开启使用
GPU Instancing的限制

图形API版本要求
与SRPBatcher不兼容
不同绘制API的参数与绘制个数不同
渲染顶点数较少的网格时,效率可能会较差。(测试使用)
SRP Batching的限制

图形API版本要求
必须是SRP渲染管线
粒子对象不能合批
使用MaterialPropertyBlocks的游戏对象不能合批
Shader必须是compatible的
Batching 失败信息与原因汇总




Unity FrameDebuger中可以查看合批失败的原因


[*]“An object is affected by multiple forward lights.” 此物体受到多个前向灯光的影
[*]“Objects have different materials.” 此物体有不同的材质
[*]“An object is using a multi-pass shader.” 此物体使用了多pass着色器
[*]“An object has odd negative scaling.” 此物体Trasform的Scale使用了负数
[*]“Either objects have different \”Receive Shadows\“ settings, or some objects are within the shadow distance, while some other objects are not.” 此物体接收阴影的设置不同,或者物体有不同的的阴影距离设置
[*]“Objects are affected by different forward lights.” 此物体受到不同的前向灯光影响
[*]“Objects are on different lighting layers.” 物体在不同的Lighting Layer上
[*]“Objects have different \”Cast Shadows\“ settings.” 此物体有不同的投影体设置
[*]“Objects either have different shadow caster shaders, or have different shader properties / keywords that affect the output of the shadow caster pass.” 此物体有不同的投影着色器设置或者有不同的着色器属性或者关键字影响Shadow Caster Pass的输出
[*]“The shader explicitly disables batching with the \”DisableBatching\“ tag.” 着色器中显式设置了DisableBatching的标记
[*]“Objects have different MaterialPropertyBlock set.” 此物体有不同的MaterialPropertyBlock的属性集
[*]“Non-instanced properties set for instanced shader.” Instanced的着色器有非instanced属性集
[*]“Objects are lightmapped.” 物体使用了不同的LightMap或者虽然使用相同的LightMap但使用的UV不同
[*]“Objects are affected by different light probes.” 此物体受到不同的光照探针影响
[*]“Objects are shadowed by baked occlusions and have different occlusion factors.” 此物体烘焙了遮挡,并且设置了不同的遮挡因子
[*]“Objects are affected by different reflection probes.” 此物体受到不同的反射探针影响
[*]“Rendering different meshes or submeshes with GPU instancing.” 使用GPU实例化渲染不同的网格或子网格
[*]“Objects have different batching-static settings.” 此物体有不同的静态合批设置
[*]“Objects belong to different static batches.” 此物体归属不同的Static Batches
[*]"Dynamic Batching is turned off in the Player Settings or is disabled temporarily in the current context to avoid z-fighting.” 在Player Settings中关闭了动态合批,或者在当前的环境中为了避免深度冲突而临时关闭了合批
[*]“There are too many indices (more than 32k) in a dynamic batch.” 动态合批中有太多的索引(大于32k)
[*]“A mesh renderer has additional vertex streams. Dynamic batching doesn‘t support such mesh renderers.” Mesh Renderer具有其他顶点流。动态批处理不支持此类网格渲染器。
[*]“A submesh we are trying to dynamic-batch has more than 300 vertices.” 动态合批超过300个顶点
[*]“A submesh we are trying to dynamic-batch has more than 900 vertex attributes.” 动态合批超过900个顶点属性
[*]“This is the first draw call of a new shadow cascade.” 新阴影级联的第一次绘制调用
[*]“The material doesn‘t have GPU instancing enabled.” 材质未启用GPU Instancing功能
[*]“Objects are rendered using different rendering functions. This can happen if the type of renderer is different (eg Mesh/Skinned Mesh) or when using different settings within the same renderer, such as Sprite Masking.” 使用不同的渲染。如果渲染器的类型不同(例如网格/蒙皮网格),或者在同一渲染器中使用不同的设置(例如精灵遮罩),则可能会发生这种情况。
[*]“Objects have different batching keys. This is usually caused by using different vertex streams on Particle Systems, or by mixing Lines and Trails, or by mixing lit and unlit geometry.” 此对象具有不同的Batching Keys。 这通常是由于在粒子系统上使用不同的顶点流,或混合线和轨迹,或混合Lit和Unlit的几何体造成的。"
[*]“Mesh uses 32 bit index buffer.” Mesh使用了32位的索引缓冲
[*]“Submesh has non-zero base vertex.” 子网格对象有非0的基础顶点, submesh.BaseVertexLocation != 0
[*]“The previous instanced draw call has reached its maximum instance count.” 先前的InstanceDrawCall已经达到了Instance的最大数量
[*]“Motion Vector rendering doesn‘t support batching.” Motion Vector的渲染不支持Batching
[*]“When using late latching, children of an XR late latched GameObject do not use batching.” 使用late latching时,XR late latched GameObject的子级不能合批
[*]“Objects have different bounds and bounds instancing is disabled.” 对象具有不同的包裹体,那么包裹体实例化被禁用
[*]“SRP: Node have different shaders.” 节点具有不同的着色器
[*]“SRP: Node use multi-pass shader” 节点使用了多Pass着色器
[*]“SRP: Node use different shader keywords” 节点使用了不同的着色器关键字
[*]“SRP: End of the batch flush” Batch Flush结束
[*]“SRP: Node is not compatible with SRP batcher” 节点与SRP Batcher不兼容
[*]“SRP: Node material requires device state change” 节点材质需要改变渲染设备状态
[*]“SRP: First call from ScriptableRenderLoopJob” ScriptableRenderLoopJob第一次调用
[*]“SRP: This material has custom buffer override” 材质有自定义重写的Buffer
页: [1]
查看完整版本: Unity合批(Batching)的限制与失败原因汇总