Jump to content
  • Advertisement
Sign in to follow this  
HendrixSweden

Bad performance when drawing many objects

This topic is 4862 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'am developing a simple multiplayer game where you play the popular board game called Goin an 3d environment. On each board of Go you can put aproximately 360 stones, I've build a stone from 580 triangles at my best LOD. Since there is only two colours of stones I'm using two vertex buffers for the stones. The problem seemes to be the number of stones I draw using DrawPrimitive. Is there any way to optimize this? How expensive are SetStreamSource(...), ,SetMaterial(...) ,SetTexture(...) What should you avoid doing in each render to speed things up? The stones has its own matrix so I do a SetTransform(D3DTS_WORLD, ...) call per stone to render. Here are some test data on my ati 9800XT which should pump out at most 400M tri/s ---- Drawing 500 stones per frame 550 000 tri are drawn at 20 fps 44 000 tri are drawn at 44fps 10 000 tri are drawn at 44fps ... Strange indeed! :) Drawing 100 stones 100 000 tri are drawn at 95fps 10 000 tri are drawn at 150fps Please help :) Imagine when I've put 20 go-boards in my game whith aprox 7000 stones in it!

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by HendrixSweden
I'am developing a simple multiplayer game where you play the popular board game called Goin an 3d environment. On each board of Go you can put aproximately 360 stones, I've build a stone from 580 triangles at my best LOD.

Since there is only two colours of stones I'm using two vertex buffers for the stones. The problem seemes to be the number of stones I draw using DrawPrimitive.

Is there any way to optimize this?
How expensive are SetStreamSource(...),
,SetMaterial(...)
,SetTexture(...)

What should you avoid doing in each render to speed things up? The stones has its own matrix so I do a SetTransform(D3DTS_WORLD, ...) call per stone to render.


Here are some test data on my ati 9800XT which should pump out at most 400M tri/s

----
Drawing 500 stones per frame

550 000 tri are drawn at 20 fps
44 000 tri are drawn at 44fps
10 000 tri are drawn at 44fps ... Strange indeed! :)


Drawing 100 stones
100 000 tri are drawn at 95fps
10 000 tri are drawn at 150fps


Please help :)
Imagine when I've put 20 go-boards in my game whith aprox 7000 stones in it!


It's few techniques how to increase performance :
1. use index buffer (indexed buffers can be cached internally)
2. if many objects use the same texture or material, draw it in batch (set one material and draw ALL objects with this material (or parts of these objects), then change to other material and draw other ones)
3. minimize vertex buffer switches (you wrote, that you are use only one VB, it's good)
4. minimize state switches (render state, texture state etc.)

Share this post


Link to post
Share on other sites
Good pointers... but the batch thing... I use one VB but I call the DrawPrimitive function once per object I'm rendering, I can get rid of setmaterial and set texture when drawing the same object in different locations, hopefully that will give me some boost, but I'm afraid that the calls to DrawPrimitive are to slow. And what about settings states, shouldn't the API be smart enough to do a fast setState if the state is already set? =)

And what about this code-snippet does it make a change?

LPDIRECT3DVERTEXBUFFER9 test;
unsigned int bla,blo;
pDevice->GetStreamSource(0, &test, &bla, &blo);
if (test != m_graphicData->at(i).m_pVerts)
pDevice->SetStreamSource( 0, m_graphicData->at(i).m_pVerts, 0, sizeof(MATSMESH_VERTEX) );

Share this post


Link to post
Share on other sites
Quote:
Original post by HendrixSweden
Good pointers... but the batch thing... I use one VB but I call the DrawPrimitive function once per object I'm rendering, I can get rid of setmaterial and set texture when drawing the same object in different locations, hopefully that will give me some boost, but I'm afraid that the calls to DrawPrimitive are to slow. And what about settings states, shouldn't the API be smart enough to do a fast setState if the state is already set? =)

And what about this code-snippet does it make a change?

LPDIRECT3DVERTEXBUFFER9 test;
unsigned int bla,blo;
pDevice->GetStreamSource(0, &test, &bla, &blo);
if (test != m_graphicData->at(i).m_pVerts)
pDevice->SetStreamSource( 0, m_graphicData->at(i).m_pVerts, 0, sizeof(MATSMESH_VERTEX) );


Which pooling method you use for VB ? Use managed pooling (D3DPOOL_MANAGED). Use static buffers if it can be.
Try use index buffer for draw primitives, and use triangle strips (not an triangle list).

Share this post


Link to post
Share on other sites
I use D3DPOOL_MANAGED, trying to understand queryperformancecounter and figure out where the bottleneck is :)

I'll continue tomorrow, posting back some results.. thx

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!