render texture pieces vs full texture

My question is fairly simple : is rendering multiple pieces of a single texture separately, but in the same sprite batch (for example each line of a 32*32 tex) significantly slower than rendering the full texture at once ? And is using SpriteSortMode.texture rather than SpriteSortMode.deffered better in that case ?

I don’t know the answer but you should be able to setup a benchmark test by timing the rendering of e.g. 1000 32x32 textures using each method and compare the times.

If they are close then increase from 1000 to 10000 and upwards.

1 Like

I thought about this, but I also thought it would be easier to ask. Guess I’ll do what you said then, thanks anyway :smiley:

Even if people answered I think this is the type of thing that people would be wrong about, jonathanmcc is correct, best test it yourself. I remember getting a 10-40% boost by replacing the default C# sort with an un-optimised but non-generic one and even after posting proof people still didn’t believe me because their intuition is that the default C# functions must be fast.

It will be signficantly slower.

The reason is, even if they are batched spritebatch needs to send every vertice for every quad (2 triangles) to the gpu every frame.

1000 quads = 4000 vertices vs 1 quad = 4 vertices

The actual drawing on the gpu is not much slower.

If you are looking at drawing millions of quads at once every frame with hundreds or thousands of fps then i suggest storing all your static vertices on the gpu and draw using an index buffer (a lot more complicated because your no longer using spritebatch)

1 Like

What is there to be wrong about? Spritebatch does significant amount of work per sprite on CPU side, data are not persistent and will be uploaded to GPU every frame, 4 vertices with, if I remember correctly, 32 byte stride. As boot said, on GPU itself the price difference will be irrelevant for up to tens of thousands of tiles, however CPU and PCIe will be major bottle necks which will make it way slower without any room for argument.

After a quick look into the code to learn how SpriteBatch actually works, I believe that boot and Ravendarke are right and I don’t think I’ll test it anyway as I found a much cleaner solution to my problem. Thanks everyone for your answers !