Handle multiple draws or somehow reduce draw counts

Hi everyone,

I am working on a 2D project and encounter serious FPS drops in occasions where hundreds of texture draws happen in a frame. Most of the sprites draws are static and only change with an interaction.

However a weather system is dynamic and changes each frame (with 500 draw each frame)

I read some articles about RenderTargets and got several thoughts.

1- The weather system isn’t a big issue, just for my interest does someone know of way to calculate each particle and draw all particles at once (my particles got different values: alpha, speed, angle). Or an entirely different solution?

2- if I understood correctly a once drawn RenderTarget must not be calculated each frame and can normally be drawn the following frames in one SpriteBatch cycle?

3- I am thinking about using with a 2nd SpriteBatch instance. Where the RenderTarget is prepared with the 2nd and drawn on the first?

3.5- Does question 3 even make a difference since the graphics device is still in use of the first SpriteBatch?

4- As for the static draws i’m thinking of parting the screen (or rather chunks) into 16 separated RenderTargetsts.
For 3 layer so 48 in total.

Previously search results mentioned that there shouldn’t be more than 16 interruptions with SpriteBatch.begin() and SpriteBatch.end() in one frame. In this case i would divide the creation of a chunk into several frames.

5- People also pointed out that a once drawn RenderTarget should not be partly undated (overriding the texture on x, y position or try to clear a location with alpha), but instead fully be redrawn.
Anyone who experienced otherwise?

6- Maybe there is also an different solution, like merging sprites into one before even drawing on the SpriteBatch as example?

Any useful productive thoughts / comments are welcome. As i need a lot of there to make decisions.
Even if only one question is answered or if they are off the questions, but somehow related to the topics.

Thank in Advance

1 Like

500 draws a frame is not much at all. I can get 10k at a high frame rate.

A couple things you can do
Stop the texture swapping. Everytime spritebatch has to swap a texture the batch gets drawn. Texture swapping is costly when doing a lot of draw calls. Create a texture atlas and try to order your draw calls using the same texture. This is the biggest performance increase you will get.

Use spritesortmode.deferred over setting depth layers for things. This performance increase isn’t as big and you will have to order your draw calls in depth your self. However this means spritebatch won’t have to sort your draws when you call spritebatch.end.

Don’t do too many render target swaps. On dedicated gpus its not as bad (you would normally use a few for post processing) but on an integrated gpu it will tank your frame rate.

2 Likes

If you are trying to improve performance I would make sure to actually profile your run and measure how fast it is and look at what parts are slow.

1 Like

@Zynugi I saw your post you describe well on this topic. I thinks i should work on this as you mention. :slightly_smiling_face: