What is more efficient?

Started by
7 comments, last by 21st Century Moose 10 years, 2 months ago

Hi Guys,

I am making massive progress with a game engine I am writing, but am now wondering what would be more efficient. Rendering sprites using the DX9 sprite interface or just using textured quads?

I am calling sprite Begin, End, and Flush only once - even if I am rendering 1000 sprites, so I think I am going as efficient as I can in that regard. But, am wondering if I could squeeze out more potential if I used quads instead.

What do you guys recommend?

Thanks in advance :)

Advertisement

Best to encapsulate your sprite interface and use either a DX9 Spirte or quad implementation. This way you can test out different approaches without the necessarity to rewrite most of your code.

PS:

There might be although some trapdoors when using quads, e.g. filtering, I believe, that sprites are more memory copy operations, while quads will be more like rendering. When rendering you have some advantages (use shaders for some pretty effects) and disadvantages (filtering which could result in bluring your sprites when not really careful).

Thanks Ashaman73, I was hoping there was an easy answer. But you are right, the only way to really tell is to try it out and see.

My code is pretty clean as the sprite calls are allready neatly wrapped up. So, I just need to make some quads and test things out.

All the D3DX stuff are just helpful wrappers around common D3D tasks.

If you implement the exact same D3D operations yourself, it would have exactly the same performance as the D3DX version. Unfortunately I don't think the code for the D3DX sprite interface is available so that you can see what it's doing...

Generally the D3DX code can be improved upon, which is why it's just there as a helper library, rather than an actual part of D3D itself. It's likely just a wrapper around a dynamic vertex/index buffer, which it copies your rects into, and then constructs indexed-draw calls based on the textures used.

You can very likely build a better version yourself based around the specific needs of your game. There's some good info on buffer management here if you want to try:

https://developer.nvidia.com/sites/default/files/akamai/gamedev/files/gdc12/Efficient_Buffer_Management_McDonald.pdf

Cool, thanks for the advice and the link - just downloaded now and I'll have a read.

Actually, I was just reading an XNA book that was talking about the guts of SpriteBatch. It turns out that Spritebatch uses textured quads because the GPU hardware is so specialized it turns out to be faster. I suspect if you roll your own textured quad drawing implementation, it might be marginally faster than SpriteBatch. But the ONLY true test of which one is faster is to code them and profile them both.

A couple of related links:

http://www.gamedev.net/topic/536693-xna-textured-quad-vs-sprite-batch/

http://gamedev.stackexchange.com/questions/21220/how-exactly-does-xnas-spritebatch-work

EckTech Games - Games and Unity Assets I'm working on
Still Flying - My GameDev journal
The Shilwulf Dynasty - Campaign notes for my Rogue Trader RPG

Nice one. I am about to have a read of your links.

There might be although some trapdoors when using quads, e.g. filtering, I believe, that sprites are more memory copy operations, while quads will be more like rendering. When rendering you have some advantages (use shaders for some pretty effects) and disadvantages (filtering which could result in bluring your sprites when not really careful).

D3DX sprites are rendered using textured quads, so it's the same thing.

In my opinion the D3DX helper interfaces for sprites and fonts (and meshes etc.) are excellent when you are starting and actually may be perfectly fine for you for a long time. But sooner or later you'll want to implement it yourself. Especially ID3DXFont is very slow. The problem is that they are quite generalised and you can make a more efficient code by making it directly as you want and need.

Generally the D3DX code can be improved upon, which is why it's just there as a helper library, rather than an actual part of D3D itself. It's likely just a wrapper around a dynamic vertex/index buffer, which it copies your rects into, and then constructs indexed-draw calls based on the textures used.

This is exactly how it's implemented, yes. You can use PIX to view the actual D3D calls that the sprite interface makes and determine that it's nothing more than a wrapper.

Direct3D has need of instancing, but we do not. We have plenty of glVertexAttrib calls.

This topic is closed to new replies.

Advertisement