Skip to main content
gamedev.net
🔒 Locked

Hardware instancing

Started by Volgut 2 replies 1.8k views
Original Post
Volgut
Volgut
Hello, I implemented hardware instancing in my 3D engine and I am getting some performance issues. My test scene contains 100 objects and each one has 30k triangles, so in total I am rendering around 3M triangles. Without instancing I am getting 9FPS and with instancing only 8FPS. I have the latest drivers and I tested my application on GeForce 9700GS (Windows XP) and GeForce 8600GS (Windows Vista) and it behaves similar. I have 2 static vertex buffers. First one contains geometry of the mesh and the second one holds instance data (transformation matrix). Buffers are created in managed memory pool (I also tested the problem with default memory pool, but it didn't change anything). Before calling DrawIndexedPrimitive from the device I am running following code: pD3DDevice->SetStreamSourceFreq( 0, D3DSTREAMSOURCE_INDEXEDDATA | a_nNumOfInstances ); pD3DDevice->SetStreamSourceFreq( 1, D3DSTREAMSOURCE_INSTANCEDATA | 1ul ); In my vertex shader I am passing instance data trough NORMAL1-NORMAL4 (I tested also TEXCOORDx, but it didn't help). The problem with the performance appears when I try to access my instance data in the shader - if I don't use it then I am getting around 40 FPS. I think that there must be something wrong with the second vertex buffer which holds instance data, because as soon as I access the data from it the performance drops significantly. Does anyone has a clue what might be wrong? Thanks.
remigius
remigius

It's a bit of a guess, but I think your framerate is getting sucked up elsewhere, perhaps by expensive pixel shaders? Instancing is mainly useful for reducing the draw call overhead when rendering many relatively low-poly models. With 30K faces per object, the performance gain from instancing may not be there. In fact, it would seem that repeating the instance data for large objects is actually more costly judging by your framerate.

When you say you don't use instancing and get 40 FPS, do you mean that 40 FPS is for a single instance? If so, you really might want to check out if you have any other performance sinkholes, since generally speaking 40FPS is low even for a 30K poly model. To quickly check if it's indeed some expensive pixel shader that's to blame, replace it by a simple one outputing a solid color.
Volgut
Volgut
Thanks for the reply. Also one of my first ideas about poor performance was to modify the pixel shader, so I changed it to output singe color, but it didn't help. My application runs at around 40FPS, because in my test scene I am using HDR rendering, deferred shading, volumetric clouds, water, volumetric light scattering etc. and these effects are not for free ;)

I created simple sphere containing around 1k triangles and I populated this mesh 1000 times in my scene to get 1000xDrawPrimitiveCalls and... it seems to work :) Without instancing I have only 12FPS and with instancing 28FPS, so almost two times more. So it looks like you were right - to get real boost from the instancing you have to have a lot of low-poly objects and basically it doesn't work for very complex meshes. Thank for help!
MJP
MJP
3m triangles is a lot of triangles for a scene. That's going to be a huge hit on bandwidth, especially if you're rendering with MRT for deferred shading. I'm not surprised at all that you get a large boost in performance by cutting your triangle count by two thirds.

The thing about instancing is it will only help you if you're CPU bound. Too many DrawPrimitive calls are a strain on the CPU, not the GPU. So if you're GPU bound to begin with, instancing won't make things any better (it might even make it worse).

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.