ID3D10Device.CreateBuffer oddities

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

Recommended Posts

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 on other sites
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 on other sites
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 on other sites
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 on other sites
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!