Multiple Command Buffers single command vs Single command buffer multiple commands

Hello everyone,
writing a script that attaches a command buffer in the main camera to draw some instanced elements.

Doing something like:

CommandBuffer commandBuffer1 = new CommandBuffer();
commandBuffer1.DrawMeshInstanced( params1 );
camera.AddCommandBuffer(CameraEvent.BeforeForwardOpaque, commandBuffer1);

CommandBuffer commandBuffer2 = new CommandBuffer();
commandBuffer2.DrawMeshInstanced( params2 );
camera.AddCommandBuffer(CameraEvent.BeforeForwardOpaque, commandBuffer2);

Just wondering if change to a single command buffer:

CommandBuffer commandBuffer = new CommandBuffer;
commandBuffer.DrawMeshInstanced( params1 );
commandBuffer.DrawMeshInstanced( params2 );
camera.AddCommandBuffer(CameraEvent.BeforeForwardOpaque, commandBuffer);

There will be any performance improvement? What if (param1 == param2)?
(the second seems more optimized due to the single command buffer but still two batches)

Try both? I suspect a single command buffer will be faster too, but it might depend on what you’re doing. I know there’s a lot of code in the background for handing going in and out of command buffers, to ensure things like the current render target is set back to the camera, etc., so I definitely wouldn’t expect multiple buffers to be better.

1 Like

Maybe you know any way to chain command buffers together?
For example, I have tons of objects to render. For each of them I cached a separate CommandBuffer that will render specific object to render target.
I’m using separate command buffers and not a single one, because want to use some “fancy” culling, and exclude from rendering process objects that outside camera view.

It’s just an example and pretty much repeats the original question.
But maybe you know a better way of doing something like that.
Thanks