Jump to content
  • Advertisement
Sign in to follow this  
Roof Top Pew Wee

Better to call Grapics.Write() with an array rather than one vertex at a time?

This topic is 4831 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

So right now, I'm drawing some quads by adjusting my individual vertex, then writing it to the GraphicsStream, then readjusting the individual, and so on. Of course, I'm taking advantage of batching when I call DrawPrimitives, but I'm wondering if there's any sort of performance hit for writing individual vertices through a GraphicsStream rather than passing an array of vertices. . . . or maybe I'm just worrying about something that won't even make much of a difference. Any thoughts? --Vic--

Share this post


Link to post
Share on other sites
Advertisement
Obviously you should only really worry about it if it becomes a bottleneck, but in general, given the choice of using one function call to do something vs. multiple function calls, you should use the one function call version. (But don't do it at the cost of readability unless, again, it's an actual bottleneck.)

Share this post


Link to post
Share on other sites
In general, D3D calls lend themselves toward the concept of batching - sending as much data as possible in the fewest amount of calls. This is due to the nature of D3D and its interaction with the video drivers and GPU hardware. A few examples:

IDirect3DDevice9::DrawIndexedPrimitive()
IDirect3DDevice9::DrawPrimitiveUp()
ID3DXSprite
ID3DXEffect::SetValue()
Buffer::Lock()

So yes, it is probably much better to update all of the vertices at once.

Share this post


Link to post
Share on other sites
Thought I'd mention this as I've found it out during profiling: Calling the Write method with just one vertex passes a value, causing memory to be copied on the stack and in cases like mine, causes the garbage collector to go crazy when drawing a lot of objects. Storing the vertices in arrays, even if they are arrays of 1 element, passes the vertices by reference and reduces memory allocation and GC. Turns out that that's where the true speed benefit comes in.

--Vic--

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!