Why is DrawIndexedPrimitiveUP so much faster?

Started by
10 comments, last by Bezben 18 years, 4 months ago
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.
Advertisement
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.
John BoltonLocomotive Games (THQ)Current Project: Destroy All Humans (Wii). IN STORES NOW!
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.
Every time you implement a singleton, God kills a kitten. Please, think of the kittens!
Quote:Original post by JohnBolton
It'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.
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.
I'm also new to DX, but I'm curious about this line:

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

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...
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.
Every time you implement a singleton, God kills a kitten. Please, think of the kittens!
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.)
Quote:Original post by Christopher Harris
I'm also new to DX, but I'm curious about this line:

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

are you trying to set the Vertex Shader or the Flexible Vertex Format?

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

<hr align="left" width="25%" />
Jack Hoxley <small>[</small><small> Forum FAQ | Revised FAQ | MVP Profile | Developer Journal ]</small>

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.

This topic is closed to new replies.

Advertisement