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 失敗信息與原因彙總
 
  1. “An object is affected by multiple forward lights.” 此物體受到多個前向燈光的影
  2. “Objects have different materials.” 此物體有不同的材質
  3. “An object is using a multi-pass shader.” 此物體使用了多pass着色器
  4. “An object has odd negative scaling.” 此物體Trasform的Scale使用了負數
  5. “Either objects have different \”Receive Shadows\“ settings, or some objects are within the shadow distance, while some other objects are not.” 此物體接收陰影的設置不同,或者物體有不同的的陰影距離設置
  6. “Objects are affected by different forward lights.” 此物體受到不同的前向燈光影響
  7. “Objects are on different lighting layers.” 物體在不同的Lighting Layer上
  8. “Objects have different \”Cast Shadows\“ settings.” 此物體有不同的投影體設置
  9. “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的輸出
  10. “The shader explicitly disables batching with the \”DisableBatching\“ tag.” 着色器中顯式設置了DisableBatching的標記
  11. “Objects have different MaterialPropertyBlock set.” 此物體有不同的MaterialPropertyBlock的屬性集
  12. “Non-instanced properties set for instanced shader.” Instanced的着色器有非instanced屬性集
  13. “Objects are lightmapped.” 物體使用了不同的LightMap或者雖然使用相同的LightMap但使用的UV不同
  14. “Objects are affected by different light probes.” 此物體受到不同的光照探針影響
  15. “Objects are shadowed by baked occlusions and have different occlusion factors.” 此物體烘焙了遮擋,並且設置了不同的遮擋因子
  16. “Objects are affected by different reflection probes.” 此物體受到不同的反射探針影響
  17. “Rendering different meshes or submeshes with GPU instancing.” 使用GPU實例化渲染不同的網格或子網格
  18. “Objects have different batching-static settings.” 此物體有不同的靜態合批設置
  19. “Objects belong to different static batches.” 此物體歸屬不同的Static Batches
  20. "Dynamic Batching is turned off in the Player Settings or is disabled temporarily in the current context to avoid z-fighting.” 在Player Settings中關閉了動態合批,或者在當前的環境中爲了避免深度衝突而臨時關閉了合批
  21. “There are too many indices (more than 32k) in a dynamic batch.” 動態合批中有太多的索引(大於32k)
  22. “A mesh renderer has additional vertex streams. Dynamic batching doesn‘t support such mesh renderers.” Mesh Renderer具有其他頂點流。動態批處理不支持此類網格渲染器。
  23. “A submesh we are trying to dynamic-batch has more than 300 vertices.” 動態合批超過300個頂點
  24. “A submesh we are trying to dynamic-batch has more than 900 vertex attributes.” 動態合批超過900個頂點屬性
  25. “This is the first draw call of a new shadow cascade.” 新陰影級聯的第一次繪製調用
  26. “The material doesn‘t have GPU instancing enabled.” 材質未啓用GPU Instancing功能
  27. “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.” 使用不同的渲染。如果渲染器的類型不同(例如網格/蒙皮網格),或者在同一渲染器中使用不同的設置(例如精靈遮罩),則可能會發生這種情況。
  28. “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的幾何體造成的。"
  29. “Mesh uses 32 bit index buffer.” Mesh使用了32位的索引緩衝
  30. “Submesh has non-zero base vertex.” 子網格對象有非0的基礎頂點, submesh.BaseVertexLocation != 0
  31. “The previous instanced draw call has reached its maximum instance count.” 先前的InstanceDrawCall已經達到了Instance的最大數量
  32. “Motion Vector rendering doesn‘t support batching.” Motion Vector的渲染不支持Batching
  33. “When using late latching, children of an XR late latched GameObject do not use batching.” 使用late latching時,XR late latched GameObject的子級不能合批
  34. “Objects have different bounds and bounds instancing is disabled.” 對象具有不同的包裹體,那麼包裹體實例化被禁用
  35. “SRP: Node have different shaders.” 節點具有不同的着色器
  36. “SRP: Node use multi-pass shader” 節點使用了多Pass着色器
  37. “SRP: Node use different shader keywords” 節點使用了不同的着色器關鍵字
  38. “SRP: End of the batch flush” Batch Flush結束
  39. “SRP: Node is not compatible with SRP batcher” 節點與SRP Batcher不兼容
  40. “SRP: Node material requires device state change” 節點材質需要改變渲染設備狀態
  41. “SRP: First call from ScriptableRenderLoopJob” ScriptableRenderLoopJob第一次調用
  42. “SRP: This material has custom buffer override” 材質有自定義重寫的Buffer
 
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章