• Create Account

### #Actualmhagain

Posted 11 December 2012 - 07:38 AM

Using the managed pool, you've got 2 copies of each vertex buffer and index buffer (and a D3DX mesh is really just vertex buffers and index buffers behind the scenes) - one stored in system memory and the other stored in video memory. When you first load a mesh (or any other managed pool resource) the system memory copy is what is loaded, so when you first use one for drawing with, the video memory copy needs to be brought up to date before the draw can occur. Hence the stall.

The solution is to get access to the vertex and index buffers behind the mesh and call IDirect3DResource9::Preload on them, which - per the documentation - "indicates that the application will need this managed resource shortly" - i.e. load it directly into the video RAM copy and avoid the stall on first draw.

Sample code to do this might look something like this (warning: written off the top of my head and untested so please don't just copy/paste it):

void PreloadMesh (ID3DXMesh *mesh)
{
IDirect3DVertexBuffer9 *meshVB = NULL;
IDirect3DIndexBuffer9 *meshIB = NULL;

if (SUCCEEDED (mesh->GetVertexBuffer (&meshVB)))
{
meshVB->Release ();
}

if (SUCCEEDED (mesh->GetIndexBuffer (&meshIB)))
{
meshIB->Release ();
}
}

(Additional note/disclaimer: it's not stated in the documentation but I'm assuming here that GetVertexBuffer and GetIndexBuffer will AddRef the buffers and therefore also require a Release - I don't use the ID3DXMesh interface myself so I don't have confirmation of this).

### #2mhagain

Posted 11 December 2012 - 07:35 AM

Using the managed pool, you've got 2 copies of each vertex buffer and index buffer (and a D3DX mesh is really just vertex buffers and index buffers behind the scenes) - one stored in system memory and the other stored in video memory. When you first load a mesh (or any other managed pool resource) the system memory copy is what is loaded, so when you first use one for drawing with, the video memory copy needs to be brought up to date before the draw can occur. Hence the stall.

The solution is to get access to the vertex and index buffers behind the mesh and call IDirect3DResource9::Preload on them, which - per the documentation - "indicates that the application will need this managed resource shortly" - i.e. load it directly into the video RAM copy and avoid the stall on first draw.

Sample code to do this might look something like this (warning: written off the top of my head and untested so please don't just copy/paste it):

void PreloadMesh (ID3DXMesh *mesh)
{
IDirect3DVertexBuffer9 *meshVB = NULL;
IDirect3DIndexBuffer9 *meshIB = NULL;

if (SUCCEEDED (mesh->GetVertexBuffer (&amp;meshVB)))
{
meshVB->Release ();
}

if (SUCCEEDED (mesh->GetIndexBuffer (&amp;meshIB)))
{
meshIB->Release ();
}
}

(Additional note/disclaimer: it's not stated in the documentation but I'm assuming here that GetVertexBuffer and GetIndexBuffer will AddRef the buffers and therefore also require a Release - I don't use the ID3DXMesh interface myself so I don't have confirmation of this).

### #1mhagain

Posted 11 December 2012 - 07:35 AM

Using the managed pool, you've got 2 copies of each vertex buffer and index buffer (and a D3DX mesh is greally just vertex buffers and index buffers behind the scenes) - one stored in system memory and the other stored in video memory. When you first load a mesh (or any other managed pool resource) the system memory copy is what is loaded, so when you first use one for drawing with, the video memory copy needs to be brought up to date before the draw can occur. Hence the stall.

The solution is to get access to the vertex and index buffers behind the mesh and call IDirect3DResource9::Preload on them, which - per the documentation - "indicates that the application will need this managed resource shortly" - i.e. load it directly into the video RAM copy and avoid the stall on first draw.

Sample code to do this might look something like this (warning: written off the top of my head and untested so please don't just copy/paste it):

void PreloadMesh (ID3DXMesh *mesh)
{
IDirect3DVertexBuffer9 *meshVB = NULL;
IDirect3DIndexBuffer9 *meshIB = NULL;

if (SUCCEEDED (mesh->GetVertexBuffer (&meshVB)))
{
meshVB->Release ();
}

if (SUCCEEDED (mesh->GetIndexBuffer (&meshIB)))
{