Sign in to follow this  
resle

ID3D10Device.CreateBuffer oddities

Recommended Posts

resle    129
This snippet of code always succeeds
desc.bytewidth      := (insert some integer)
desc.usage          := D3D10_USAGE_DEFAULT;
desc.CPUAccessFlags := 0;
desc.BindFlags      := (insert any kind of buffer)
desc.MiscFlags      := 0;   
device.CreateBuffer(desc, nil, @buffer);


But whenever I modify desc.usage and desc.CPUAccessFlags, it fails. There's only one other combination that succeeds:
desc.usage          := D3D10_USAGE_DYNAMIC;
desc.CPUAccessFlags := D3D10_CPU_ACCESS_WRITE;


I'd actually need to create some buffers so that they're READABLE AND WRITEABLE by the CPU in subsequent map/unmap operations. This, for example, looks reasonable to me (any many tutorials) but always fails with E_INVALIDARG
desc.usage          := D3D10_USAGE_STAGING;
desc.CPUAccessFlags := D3D10_CPU_ACCESS_WRITE OR D3D10_CPU_ACCESS_READ;


Any hint?

Share this post


Link to post
Share on other sites
Assassin    246
PLEASE use the debug flag when creating your device, it will tell you the answer to this kind of thing much quicker than a forum will. Reading the documentation might also help understand the allowed usage scenarios.

You cannot use CPU read access flags with anything but staging resources, and you cannot set bind flags on staging resources.

Share this post


Link to post
Share on other sites
resle    129
Sorry Assassin, I'm a child learning to walk.. I didn't even notice there was a debug flag in the device creation. I am always more than happy to read the documentation but being it in a language that's not my native tongue, sometime it just doesn't help much.

So maybe I should change the perspective of my question, which is more like this: in a scenario where I am totally uninterested in performance, for every object I want to create a couple buffers (one for indices, one for vertices) that must be always available for mapping, reading, writing. Is that possible at all?

Thanks

a.

Share this post


Link to post
Share on other sites
Assassin    246
You cannot just one universal vidmem/sysmem buffer through the D3D10 API, since it's focused on preventing unexpected performance loss.

You can quite easily create a staging version of a vidmem resource by using GetDesc, modifying the bindflags, usage, and cpu access, and feeding that into CreateBuffer. You can then copy to/from it using CopyResource.

Share this post


Link to post
Share on other sites
resle    129
Thanks a lot, this clears things up a bit. So in the end, basically I have to create a generic "untyped" (no specific binding) staging resource, use it as a recipient to copy - say - a vertex buffer's data. Then I modify this staging resource by mapping/accessing/unmapping it, and finally I copy back the modified resource to the initial vertex buffer.

Things got a lot more complex than they used to be in DX9! I find this somewhat odd, adding constraints to avoid people write software that doesn't perform well sounds like ... an architectural hack of some sort!


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