Vertex Lock Vs DrawPrimitiveUP

Started by
7 comments, last by Milos 21 years, 5 months ago
Would it be faster if I substited per frame vertex buffer locks and rendering with DrawPrimitive with DrawPrimitiveUP call to render from the array itself ??
-Milos
Advertisement
I very much doubt it. As long as you''re not doing something stupid like locking and unlocking the vertex buffer many times per frame with only a few vertices filled in each time (if you are doing this, then you should be collecting the vertices during the frame and then doing a single lock, fill, unlock per vertex buffer, preferably with only one or two vertex buffers).

DrawPrimitiveUP does the same or more work as you''re doing with your own buffer, it locks and fills an internally created vertex buffer and then draws from it. So basically, you should only use DrawPrimitiveUP if you really don''t care about speed (like when you''re just testing something). Otherwise, although it may work well enough, you run the risk of getting bad performance simply because you''re not controlling the pipeline yourself, and therefore haven''t optimised it for your application.

Hope that helps,

John B
The best thing about the internet is the way people with no experience or qualifications can pretend to be completely superior to other people who have no experience or qualifications.
Hey there,

Basically, You NEVER want to use drawPrimitiveUP. It is one of the slowest methods out there (not to mention sloppy). If you properly create and lock your vertex buffers, you will not have that much of an issue with speed.

¬_¬
Thanks. I am using transformed vertices for lens flares, mouse and one more thingy in the engine. And these vertex buffers are locked only when update is needed. I guess that there is no significant drawback then?
-Milos
When i created my 2d game engine i had it so every sprite called a function called place_Sprite().

place_Sprite() created a standard 2d square on the screen using a temp array full of the data passed to the function, set the texture of the sprite, and displayed it using DrawPrimativeUP. This function was called to display all my sprites, which were in a linked list. Basically:

while(enemyList->prev != NULL) {  place_Sprite(enemyList->x, enemyList->y, enemyList->width,enemyList->height, &enemyList->data.tex);		enemyList=enemyList->prev;}  


And:

void place_Sprite(FLOAT x, FLOAT y, FLOAT width, FLOAT height, LPDIRECT3DTEXTURE8* g_pTexture) {	temp[0].x=x;	temp[0].y=y;        ...fill rest of temp with passed data		g_pd3dDevice->SetTexture( 0, *g_pTexture);	g_pd3dDevice->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);	g_pd3dDevice->SetVertexShader(D3DFVF_CUSTOMVERTEX);	g_pd3dDevice->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP , 2  , temp , sizeof ( MASTERSTRUCT ) ) ;}  


So each call of the function would have had to Lock/Unlock the buffer each time, so i used DrawPrimativeUP() and passed it an array full of the data passed to the function.

Speed wise it worked ok on all the machines i tested it on (ranging from a 400mhz -70fps). Not sure if i will use this in my 3d game. I'd be happy to hear from anyone suggesting an alternative to this approach :-)

Hope this helps you in some way :-)
Aaron

[edited by - Weeks on November 6, 2002 9:57:11 PM]
If you properly create a dynamic vertex buffer and properly lock it, your program should run quite a bit faster.

¬_¬
I have never tried to use dynamic vertex buffers. What is the main idea behind it? I think I got a picture that it''s a buffet that I will be appending, is this correct?

-Milos
-Milos
Basically, normal vertex buffers are designed to be written to once, and never locked again. If you lock it again, you will suffer a performance hit. If you are planning on writing to a buffer more than once, you should make it dynamic. When you make a vertex buffer dynamic, you make write to it as many times as you want. Each write still takes some time, but it *considerably* less than a static vertex buffer.

Note that with any buffer, it is best to write a lot of data to it all at once, and have fewer larger buffers than many small buffers.

This is at least how I have learned it. Niyaw has written a very good article on vertex buffers here (note that it is still in "production"):

http://niyaw.cjb.net/articles/d3d_resources.html

Hope this helps!

fuzztrek

¬_¬
Understood Fuzztrek. Thank you.
-Milos

This topic is closed to new replies.

Advertisement