Optimize Drawcalls for Compat mode

Godot Version

4.2

Question

Hi everyone!

So I’m developing a fairly low-poly, orthographic camera game, which is intended to be open beta on the web (itch) and eventually we will port to other platforms. We are using compatibility mode with GDscript to be able to export to the web.

I’ve been fairly consistent with trying to optimize my game as I developed, and have been doing the following:

  • Using multimesh instances for repeated simple meshes throughout the elvel
  • Keeping as many items using the same shader as possible (still more work to do here… so I know I can optimize a bit)
  • baking textures on meshes and joining multiple parts into a single model with a single set of textures

Despite my efforts, I’m getting a huge number of draw calls showing in the editor stats.

In this scene alone I have 265 draw calls. Seems insane. Total triangles are 80k, so the tri count is not the issue.

I’m noticing that each mesh instance 3D produces 3 draw calls (no idea why, like I said, I’ve baked textures and they are composed of a sinlge mesh), and each rigid or static body is also a drawcall.

After a long time profiling to try to see the issue, I’m seeing physics process spike to 18-20ms every now and then. Everything else seems to be reasonably under control.

Anything else I can be doing to optimize?

2 Likes

Debugging drawcalls is tricky in Godot in my opinion. Here’s what I know:

  • Make sure to disable Gizmos, Grid and Origin display, they will affect drawcall counts.
  • Deselect everything, the selection gizmo adds 10 drawcalls to the stats.
  • One MeshInstance3D will produce between 1 and 5 drawcalls, depending on whether shadows are enabled and which cascades are visible. Add even more if you’re using additional lights with shadows
  • Even if separate MeshInstance3D nodes share the same material (shader) they will still produce at least as many drawcalls as there are MeshInstance3D nodes.
  • If you join a mesh, and it has two materials, it will produce at least 2 drawcalls (you addressed that already with texture baking but it’s easy to still end up with multiple drawcalls)

As for physics, I have no idea sorry.

Not much help sorry, but maybe some one else has more insight.

Side note: This kinda sounds like premature optimization to me :slight_smile:

2 Likes

Thanks for the response, this is helpful, so I appreciate the input

Remember that DirectionalLight3D shadows will multiply draw call count by up to 5 for nodes that are within the shadow range with the default directional shadow mode (PSSM 4 Splits). Switch to the Orthogonal mode and reduce Shadow Max Distance to reduce draw call count significantly.

2 Likes

That chopped off about 100* draw calls, so that’s a pretty big improvement. Thank you!
Edit: Wow tuning down the max distance really helped.