Jump to content
  • Advertisement
Tape_Worm

DX11 D3D11_CPU_ACCESS_READ and default usage

Recommended Posts

So last night I was messing about with some old code on a Direct 3D 11.4 interface and trying out some compute stuff.

I had set this thing up to send data in, run the compute shader, and then output the result data into a structured buffer.  To read this data back in to the CPU, I had copied the structured buffer into a staging buffer and retrieved the data from there.

This all worked well enough. But I was curious to see if I could remove the intermediate copy to stage and read from the structured buffer directly using Map.  To do this, I created the buffer using D3D11_CPU_ACCESS_READ and a usage of default, and to my shock and amazement... it worked (and no warning messages from the D3D Debug log).

However, this seems to run counter to what I've read in the documentation for D3D11_CPU_ACCESS_FLAG:

Quote

D3D11_CPU_ACCESS_READ
The resource is to be mappable so that the CPU can read its contents. Resources created with this flag cannot be set as either inputs or outputs to the pipeline and must be created with staging usage.

The bolded part is what threw me off.  Here, I had a structured buffer created with default usage, and a UAV (definitely bindable to the pipeline), but I was able to map and read the data.

Does this seem wrong?  I'm aware that some hardware manufacturers may implement things differently, but if MS says that this flag can't be used outside of a staging resource, then shouldn't the manufacturer (NVidia) adhere to that?

I can find nothing else in the documentation that says this is allowed or not allowed (beyond the description for D3D11_CPU_ACCESS_READ).  And the debug output for D3D doesn't complain in the slightest. So what gives?  Is it actually safe to do a map & read from a default usage resource with CPU read flags?

Edited by Tape_Worm
Gud grammur

Share this post


Link to post
Share on other sites
Advertisement

Looks like you're accidentally using the MapOnDefaultBuffers feature:

https://msdn.microsoft.com/en-us/library/windows/desktop/dn280377(v=vs.85).aspx

MapOnDefaultBuffers

Type: BOOL

Specifies support for creating ID3D11Buffer resources that can be passed to the ID3D11DeviceContext::Map and ID3D11DeviceContext::Unmap methods. This means that the CPUAccessFlags member of the D3D11_BUFFER_DESC structure may be set with the desired D3D11_CPU_ACCESS_FLAG elements when the Usage member of D3D11_BUFFER_DESC is set to D3D11_USAGE_DEFAULT. The runtime sets this member to TRUE if the hardware is capable of at least D3D_FEATURE_LEVEL_11_0 and the graphics device driver supports mappable default buffers.

Share this post


Link to post
Share on other sites

Well damn.  I remember reading about that ages back, but totally forgot about it.  Makes a lot of sense now.

That said, the docs for D3D11_CPU_ACCESS_FLAGS should be updated to include a link to that info eh?  I've sent feedback regarding that.

Thanks for the clarification.

I'd give you an upvote or whatever they're using nowadays for that, but I have no idea how that system works anymore.  Clearly I'm old and can't handle change.

Edited by Tape_Worm

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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!