Skip to main content
gamedev.net
🔒 Locked

ID3D10Device.CreateBuffer oddities

Started by resle 3 replies 1.4k views
Original Post
resle
resle
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?
..so we ate rare animals, we spent the night eating rare animals..
Assassin
Assassin
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.
Assassin, aka RedBeard. andyc.org
resle
resle
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.
..so we ate rare animals, we spent the night eating rare animals..
Assassin
Assassin
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.
Assassin, aka RedBeard. andyc.org
resle
resle
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!


..so we ate rare animals, we spent the night eating rare animals..

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.