# Why is DrawIndexedPrimitiveUP so much faster?

## Recommended Posts

Hi I'm fairly new to DX and from all I've read, using the UP functions should be a lot slower that using proper buffers, but it's just not the case for me. I'm doing some testing drawing an object with a fair amount of polygons, and that's all I'm drawing. The verts all get updated each frame. If I draw using vertex/index buffers, I get about 40fps. If I switch to using DrawIndexedPrimitiveUP I get well over 90fps. Why would this happen? I want to do it the "right" way, but everything is telling me the right way sucks. ;) I'm using an ATI card, could it be a driver thing? I haven't yet gotten hold of an nVidia card to test with. I'm really just curious as to why this would happen, when all I ever hear is how bad the UP functions are. Rob.

##### Share on other sites
It's possible you aren't setting up your vertex and index buffers using the most optimal settings. I believe the best settings for doing something equivalent to DrawIndexedPrimitiveUP are D3DPOOL_DEFAULT, D3DUSAGE_DYNAMIC, and D3DLOCK_DISCARD, but don't quote me.

##### Share on other sites
DrawIndexedPrimitiveUP also creates a vertex and index buffer internally, locks it, copies the data and renders it every frame. You maybe cant feel it with one object, or a not so hight detailed mesh, but if you draw a lot of object it will hurt. And the reason of that speed difference is maybe because you are doing the ordinary way wrong. Draw***UP is usually good for displaying debug graphics, for example you want to draw the 3 axes, but dont want to add it to the render pipeline.

##### Share on other sites
Quote:
 Original post by JohnBoltonIt's possible you aren't setting up your vertex buffer using the most optimal settings. I believe the best settings for doing something equivalent to DrawIndexedPrimitiveUP are D3DPOOL_DEFAULT, D3DUSAGE_DYNAMIC, and D3DLOCK_DISCARD, but don't quote me.

Add D3DUSAGE_WRITEONLY to that, and it should fly.

##### Share on other sites
Thanks for the replies, but I am already creating my buffers with all those exact flags. (

The drawing seems to be the bottle neck. If I draw like this:
if(FAILED(m_pDevice->SetVertexShader(MYVERT_FVF)))return false;if(FAILED(m_pDevice->SetStreamSource(0, Vertices, sizeof(MYVERT_VERTEX))))return false;if(FAILED(m_pDevice->SetIndices(Indices, 0)))return false;if(FAILED(m_pDevice->DrawIndexedPrimitive(D3DPT_TRIANGLESTRIP, 0, nVertices, 0, nIndices -2)))return false;

it's slow.

If I do it with a call to DrawIndexedPrimitiveUP, it flies!

I know it's wrong, but it feels so right! :) I understand I must be doing something wrong, but what?

Rob.

##### Share on other sites

are you trying to set the Vertex Shader or the Flexible Vertex Format? if you're trying to set the FVF, you need to use:

if(FAILED(m_pDevice->SetFVF(MYVERT_FVF)))

hope that helps...

##### Share on other sites
Well, then there is no problem. If its faster for your needs, keep using it. After it becomes the bottleneck, rewrite the whole system. I heard that one of the open source engines uses Draw***UP. Maybe CrystalSpace.

##### Share on other sites
I'd bet money your problem is in the vertex buffer locking/creation flags... you must get them right or it will crawl. (Make sure you're not creating vertex buffers every frame or anything like that, of course.)

##### Share on other sites
Quote:

I'm betting it's Direct3D8 code [smile]

The code he posted was valid D3D8, which was tightened up in D3D9.

Okay, to try and offer some ideas...

What is your usage scenario - from a high level, describe what you're doing each frame. Are you locking/modifying the buffers? are you creating new buffers each frame? How many vertices/indices are we talking about? 10..100.. million?

Resource modification/usage can be a bit of a touchy situation, and there are plenty of cases where it might defy common logic. Likewise, it's often possible to re-work those things such that you stick to conventional design patterns and get maximum possible performance [smile]

hth
Jack

##### Share on other sites
Sorry! I forgot to say it's DX8.

I'm already creating the buffers as per the flags suggested above. I'm creating the buffer once, then updating it each frame. (lock, modify, unlock). But the updating of the model doesn't seem to be the problem, the drawing seems to be. Changing from the buffers to the UP makes such a huge difference that it's ridiculous.

##### Share on other sites

Using DX8 could be the reason, but I find it strange that UP is twice as fast.

So you're creating the VB in D3DPOOL_DEFAULT, with D3DUSAGE_DYNAMIC|D3DUSAGE_WRITEONLY, and you're locking with D3DLOCK_DISCARD?
And doing the same to the IB? And its still slow?

What does your vertex update loop look like?
If yours is:

for(i=0; i<numVerts; i++)
{
vertex[i].position.x = newvertex[i].position.x;
vertex[i].position.y = newvertex[i].position.y;
...
}

and theirs is:

memcpy(vertex, newvertex, sizeof(Vertex)*numVerts);

Then that might do it.

How many draws do you do per frame? and how big is your model?

JB

##### Share on other sites
If you haven't already, enable the directx debugging messages via the control panel applet and crank up the output level, it might tell you of any potential performance trouble areas.

## Create an account

Register a new account

• ### Forum Statistics

• Total Topics
628366
• Total Posts
2982274

• 10
• 9
• 13
• 24
• 11