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 :)