Sign in to follow this  

DX8: fast, DX9: 2fps?

This topic is 4400 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

Hi everyone, Till yesterday I was still using DX8. But, after having another "*sigh*" event because I tried something that was unsupported by DX8, I made a copy of the project directory, searched and replaced a LOT of *8 names to *9, replaced my shader architecture, and have a happy DX9 project. Unfortunately, this DX9 project immediatly has catched a cold :(. My terrain used to render quite fast - In DX8 -. Right now it is at a magical 2fps, even if I just render like a 1000primitives. My terrain is bruteforced ,but I optimize the terrain, and reduce the vertices a lot as well (Using the DX8 optimization functions). Now, what could possibly create this huge performance drop? I only had to change a few things in the vertexbuffer code, like adding a NULL parameter at the end and a byte** had to be changed to void**:

	if (FAILED(m_d3d_device->CreateVertexBuffer(m_dwVertexCount * sizeof(m_Vertices[0]),D3DUSAGE_WRITEONLY, 0, 
D3DPOOL_MANAGED, &m_pVertexBuffer, NULL))) return false;

	if (FAILED(m_d3d_device->CreateIndexBuffer(m_dwIndexCount * sizeof(m_Indices[0]), D3DUSAGE_WRITEONLY, D3DFMT_INDEX16, 
D3DPOOL_MANAGED, &m_pIndexBuffer, NULL))) return false;


	//Copy:
	VOID* pBufferIndices;
	
	//Vertexbuffer:
	m_pVertexBuffer->Lock(0, m_dwVertexCount * sizeof(m_Vertices[0]), (void **)&pBufferIndices, 0);
		memcpy(pBufferIndices, m_Vertices, m_dwVertexCount * sizeof(m_Vertices[0]));
	m_pVertexBuffer->Unlock();
	
	//Indexbuffer:
	m_pIndexBuffer->Lock(0, m_dwIndexCount * sizeof(m_Indices[0]), (void **)&pBufferIndices, 0);
		memcpy(pBufferIndices, m_Indices, m_dwIndexCount * sizeof(m_Indices[0]));
	m_pIndexBuffer->Unlock();


And some rendering code:
	mp_d3d_device->SetStreamSource(0, m_pVertexBuffer, 0,sizeof(TERRAIN_CUSTOMVERTEX));
	mp_d3d_device->SetIndices(m_pIndexBuffer);

  mp_d3d_device->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, 1000, 0, 7000);


The rendering code hasn't changed either, I just had to add a 0 on a few places the baseindex thing). If I render a model usin Cal3D I get still like 600 fps. But rendering my terrain will make it go instantly to 30fps or lower, depending how close I am. Vertexbuffer layout I use one big vertexbufffer for the entire terrain. This buffer has the data layut as a quadtree (what I'm using), so if multiple quads are rendered, I sort the render list, and 'attach' the minvertex/vertexlength and ditto for the indices. This way I can reduce the drawprimitive calls. 123abc 456def 789ghi jkl123 mno456 pqr789 Above shows the format of the vertex buffer, for four leaves of the quadtree. The actual numbers/characters are just to indicate the layout, they do not have a meaning ;). So.. Anyone an idea what kind of error I'm making? Something that changed completely in DirectX9 in comparison to DirectX8? Should I change my big vertex buffer to a few separate ones? My terrain is 128x128 btw. Many thanks :)

Share this post


Link to post
Share on other sites
Use the debug Direct3D runtime (see the FAQ of this forum for more information) to see if there is any debug output from D3D.

A performance drop to ~2fps would suggest that you're making the D3D API very unhappy somewhere. If D3D is spewing lots of usage errors or warnings, then a drop that big is quite possible, particularly if you're also getting exceptions inside the D3D runtime...

Looking at the snippets of code you've posted, there doesn't seem to be anything immediately obviously wrong with it.

Share this post


Link to post
Share on other sites
Yeah, Right now I got all the debug info turned on, the only thing being reported are SamplerState changes (since they don't go through my state manager yet). But I cannot believe that such a thing can cause such a problem. Besides, it gets worse when I move closer to the terrain - And right now I'm forcing a certain amount of primitives, so the render state changes are always equal.

I'm quite clueless on this one!


(PS: I am away for a two days soon, so I might reply a little bit later...)

Share this post


Link to post
Share on other sites
Hi,

Unfortunatly I'm running windowed ;). And I have always had the d3dpp value on D3DPRESENT_INTERVAL_IMMEDIATE.

I've also changed my code to make the vertexbuffer equal to the amount of vertices which I'm rendering 1000 and indices just a wild guess, 7000. The fps is still at 20 or so when I'm looking at the terrain from above.

I'm searching around the web for a C++ DX9 terrain example, but unable to find one... any one that might know one here? :). I mean, it just can't be a fillrate issue because of changing from DX8 to DX9. And my 3d mesh renders perfect as well!

Edit: My *entire* terrain as a .X mesh in the DX9 meshviewer runs at 250fps... odd :)

Share this post


Link to post
Share on other sites
Well, you will need to time your rendering to find the bottleneck. But first check the device type. Had some perf issue before, turned out that poor guy used the reference rasterizer. gg.

Post the full source so we can play with it.

Share this post


Link to post
Share on other sites
Quote:
Original post by darkelf2k5
Well, you will need to time your rendering to find the bottleneck. But first check the device type. Had some perf issue before, turned out that poor guy used the reference rasterizer. gg.

Post the full source so we can play with it.



Back home again. :) The device is using HAL and hadware vertex processing. Posting the code is quite hard cause we're talking about a half finished game already ;). Maybe the D3DX optimization functions optimize the vertex data in a way that is really not the way DX9 likes it. Kinda strange though.

Tommorow I will spent a full day (again) debugging this issue. The Meshviewer happily runs at 200 fps when rendering the entire terrain. So, it should just work fine in my game as well... :)

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
if i remmebr correctly some of the default values are not the same for the DX9 functions. Once you find those functions with the different defult values I think you are set. Ive heard of this problem before in these forums, a search might help, since it was resolved before.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Have you accidentally disabled mipmapping perhaps? That can really destroy performance if you use a lot of fillrate..

Share this post


Link to post
Share on other sites

This topic is 4400 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this