Archived

This topic is now archived and is closed to further replies.

dynamicman

efficient CopyMemory calls...

Recommended Posts

dynamicman    122
lets say I have a large array of vertices. These vertices are to be copied to a vertex buffer. should I... A) Copy the individual vertex changes (one by one)? or... B) Just copy the whole array into the buffer? I'm guessing that if I have small changes, then single CopyMemory calls are more efficient but if I have done many changes to the array, then copying them as a whole is better. Are there any suggestions on how I could implement a good copying routine? One of my thoughts is to keep track of what changes I've been making to the array and decide on an appropriate copy. Whould the overhead in checking (the array for changes) be worse than not checking and copying it (the whole thing) directly? Edited by - dynamicman on November 8, 2001 3:19:57 PM

Share this post


Link to post
Share on other sites
S1CA    1418
Are you updating vertices sequentially or do you require some sort of random access ?

Do you need to read the vertices before writing them ? (i.e. a Read-Modify-Write operation). If the buffer is AGP or local video memory you want to avoid reads at all costs - if necessary have a system memory copy and read that and write the result to your copy AND the target buffer. That should be faster than doing a read from VRAM.

If the vertex buffer is in AGP memory or worse local video memory, you''ll definately want to try and take advange of burst writes which''ll require sequential access to get the most out of.


There are more questions than there are answers! - the best method depends very much on what your application is doing with the vertices and how it''s doing it (access patterns, sizes, T&L?, shaders?, updated every frame? etc).

--
Simon O''''Connor
Creative Asylum Ltd
www.creative-asylum.com

Share this post


Link to post
Share on other sites
dynamicman    122
well basically, I have an "array" within my program that represents the vertex buffer that I've created with DirectX. Whenever I need to update the vertex buffer, I lock and copy this "array" using CopyMemory. The vertex buffer will be updated each frame (only locked once per frame). All my drawable objects will play around with parts of the "array" and when the proper time comes, I want to copy these changes into the vertex buffer.

I don't read anything from the vertex buffer. Just writes.

I was just wondering what was more efficient, to copy each "change" individually or to just copy the whole array into the vertex buffer.

Edited by - dynamicman on November 8, 2001 3:42:17 PM

Edited by - dynamicman on November 8, 2001 3:45:07 PM

Share this post


Link to post
Share on other sites
invective    118
It really depends on how big the whole buffer is and how many individual changes you have. You might want to break up your vertices for each buffer into logical areas,such as a grid for a deformable terrain, or body parts for a moving character. This way, if only say the legs are being animated, you lock and copy only the leg vertices instead of the contents of the whole buffer. You don''t want to do excessive copying, but on the other hand, you don''t want to burden the update routine with so much logic that it takes just as long to figure out what to copy and making small no sequential writes as it would have to just copy the whole thing over to begin with.

Share this post


Link to post
Share on other sites