Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Texture change (and other state-change) costs on modern GPUs

I'm writing a scene-graph based graphics engine for modeling purposes. I'm using XNA 4. On many places I have been reading, that texture changes (and other state changes) should be minimized during rendering (so I have to order my primitives by materials, etc.).

I created a small test application in XNA 4, which was rendering hundreds of stanford bunny models with a single texture, then doing the same toggling 2 different textures. There was no difference in rendering time (however I used small ~100x100 textures).

So my questions are:

  • Should I really care about sorting my primitives by texture/color/other material parameters? Or is it less important on modern GPUs?
  • What is the expectable percentage of performance loss, if I don't?
  • Are there any other state changes, which can effect the performance?
  • Where can I find some up to date literature/best practice guide about this?

Thank you for any help or links!

like image 738
klapancius Avatar asked Feb 24 '23 12:02

klapancius


1 Answers

State changes haven't really been expensive for a long time. Batches are expensive. (And a state change necessitates a new batch). A batch is basically a call to a Draw*Primitives function.

This PDF from nVidia explains it in detail. It also gives ideas for reducing your batch count.

Batches are a CPU-based limit (not GPU). That PDF lists "< 130 tris/batch" as the point where submitting batches dominates performance and the GPU sits idle waiting for more batches (details). It also says you get about 400 batches per frame, at 60 FPS, per 1GHz of CPU power dedicated to submitting batches. (Although the PDF is a bit old, so those figures are a bit out of date.)

My answer on the gamedev site to a similar question should provide some more details. This one too.

like image 120
Andrew Russell Avatar answered Feb 27 '23 08:02

Andrew Russell