Sign in to follow this  
schupf

DX10 Buffer

Recommended Posts

Hello, I have 4 little questions about buffers in DX10: 1. Can I use a buffer created with usage = D3D10_USAGE_DEFAULT as destination in method CopyResource(ID3D10Resource *pDstResource, ID3D10Resource *pSrcResource)? 2. Which of these lock methods will perform better/faster: Method A:
Vec3* verts;
vbuffer->Map( D3D10_MAP_WRITE, 0, (void**)&verts);
for(int i=0; i < 100; i++) {
   //... Around 30 vector subtractions and about 10 cross products
   verts[i] = resultVector;
}
vbuffer->Unmap();
Method B:
Vec3* result = new Vec3[100];
for(int i=0; i < 100; i++) {
   // Around 30 vector subtractions and about 10 cross products and then
   result[i] = resultVector;
}
Vec3* result 
vbuffer->Map( D3D10_MAP_WRITE, 0, (void**)&verts);
for(int i=0; i < 100; i++) 
   verts[i] = result;  // Just copy the result to the buffer
vbuffer->Unmap();
So method A calculates everything while the buffer is locked and B calculates everything before the lock and just copies the data to the buffer. Will one of the methods generally be faster? 3. Is it ok to update only some vertices of a vertexbuffer or should I always refill the whole vector? So is this ok: Vec3* verts; vbuffer->Map( D3D10_MAP_WRITE, 0, (void**)&verts); verts[20] = ... verts[82] = ... vbuffer->Unmap() 4. Last one: I have a vertexbuffer with terrain vertices that change from time to time (somtimes every frame and then sometimes only every 5 minutes). Should I create a dynamic vertex buffer and copy the new data directly the buffer per Map() or should I create 2 vertexbuffer's: one vertexbuffer with usage=D3D10_USAGE_DEFAULT and one with usage=D3D10_USAGE_STAGING and then copy the new data to the staging buffer and then copy the staging buffer to the default buffer with Copyresource? (I am asking because the docu says dynamic resources are a good choice for a resources that will be updated by the CPU at least once (!) per frame - which is not the case in my application)

Share this post


Link to post
Share on other sites
1) Yes. That's what CopyResource was designed for: copying stuff around using the GPU.
2) Generally it's a good idea to map a resource for the shortest time you can. In this case, I doubt it's going to make much of a difference. Also, you should use D3D10_MAP_WRITE_DISCARD if you're replacing the entire buffer. 30 subtractions and 10 cross products isn't a lot.
3) Yes, if you use D3D10_MAP_WRITE then it's fine to only update parts of the buffer. If the buffer is not currently bound into the Input Assembler stage, it's better to use D3D10_MAP_WRITE_NO_OVERWRITE.
4) I'd say just use a dynamic buffer, but I'm not so sure about this one. If it turns out to be too slow after profiling, you can always change it.

Share this post


Link to post
Share on other sites
Regarding (4), UpdateSubresource should perform better. See remarks on the doc page for this function for an explanation of how the update happens.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this