Primitives render optimization

Recently performance became a bottleneck for me, therefore I’m investigating ways of improving the situation. In particular my attention is drawn to SpriteBatch.GraphicsDevice.DrawPrimitives function as I render a lot of primitives. I’ve coded a class with several draw shape methods (rectangle, circle, triangle, roundedrectangle). Now the workflow in these functions is as follows:

clear pooled list of vertices push desired vertices to the list render vertices on the gpu

As I’m not batching draw calls and each shape is drawn in a separate draw call it’s quite reasonable that performance is pretty low.

So in particular I’m looking for a way how to efficiently batch a series of draw commands with a range (that’s the problem) of options.

  • Each shape can be drawn either as outline or filled (created two RasterizerState instances and passed the correct one to the gpu when rendering vertices.
  • Different PrimitiveType types were used but this can be reworked reasonably (ex. for a line I’ve used a PrimitiveType.LineStrip)

Simply said I’d like to batch together this scenario for example:

draw circle outlined draw circle filled

First command used LineStrip as a primitive type, second rasterizer state FillMode.Solid and TriangleStrip

Assuming there is no other way around I’d have to use FillMode.Solid and TriangleStrip for each draw command which would result in sending more vertices that necessary to the gpu (not sure if I could somehow improve this with indicies, commands above are sort of an API my users are expected to use).

Is this a good way to go are there better approaches to take?
Thanks in advance.

You could split the batched calls in two, one list for outlines and one for fills. If draw order matters you can use depth and enable depth clipping.