#Static Batching vs Mesh.CombineMesh

1 messages · Page 1 of 1 (latest)

thin atlas
#

Static batching combines the meshes into the same vertex and index buffers, and when it submits the draw calls to the GPU, it can do:

SetMaterial(material)
SetVertexBuffer(combinedVertices)
SetIndexBuffer(combinedIndices)
DrawIndexed(mesh1_offset, mesh1_count)
DrawIndexed(mesh2_offset, mesh2_count)
etc...

Instead of if the meshes aren't combined:

SetMaterial(material)
SetVertexBuffer(mesh1_vertices)
SetIndexBuffer(mesh1_indices)
DrawIndexed(0, mesh1_indices.count)
SetVertexBuffer(mesh2_vertices)
SetIndexBuffer(mesh2_indices)
DrawIndexed(0, mesh2_indices.count)
etc...

So it minimizes the render state changes by reducing how often it's switching between meshes, like the documentation says:

Static batching doesn’t reduce the number of draw calls, but instead reduces the number of render state changes between them.

#

Static Batching vs Mesh.CombineMesh

#

But it's effectively the same as combining it into the same draw call, because the draw calls themselves aren't the most expensive part, but preparing the state before them.

#

SRP Batcher works on the same principle. It doesn't reduce draw calls, but makes them cheaper

vital fable
#

I though you could make 1 single draw call by batching every index in one array. Maybe it is only specific to some GPU API.

#

It might be the same at the end too.

lethal parcel
#

Ehh the game is definitely mostly cpu bound just because the stock code is pretty awful. Also fwiw I’m measuring draw calls with renderdoc, so maybe there’s some details there that you don’t see in the unity frame capture

lethal parcel
#

Gpu instancing would definitely be ideal but the original shaders weren’t compiled with it supported

vital fable
lethal parcel
#

It’s KSP not my game :p. Just working on a mod and trying to squeeze performance because I’m also working on a vr mod

#

Also I have a 3080 ti, so it may well be gpu bound for someone with a weaker card

#

In any case I will experiment with manually combining the meshes instead of using the batching utility. I think the potential downside is that it may not pick up all the relevant lights but that seems unlikely because there usually aren’t that many lights in the scene, maybe 10

#

And lack of culling support but again the meshes are pretty simple

thin atlas