I've been trying to get this to work all morning, as far as I can tell I'm not doing anything obviously wrong. I cannot find any information about it but all examples I can find on using unordered access views are using structured buffers; may it be that they simply won't work with "normal" (primitive datatype) buffers?
Here's what I have:
// Buffer description
D3D11_BUFFER_DESC desc;
ZeroMemory(&desc, sizeof(D3D11_BUFFER_DESC));
desc.Usage = D3D11_USAGE_DEFAULT;
desc.ByteWidth = (UINT)cbByteSize;
desc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_UNORDERED_ACCESS;
// The above works for successfully creating a buffer without any warnings or errors,
// some initial data is provided and a normal shader resource view can be created,
// bound to and used by shaders without issues.
// However when I try to create another (unordered access) view for the same buffer
// like so...
D3D11_UNORDERED_ACCESS_VIEW_DESC udesc;
ZeroMemory(&udesc, sizeof(D3D11_UNORDERED_ACCESS_VIEW_DESC));
udesc.Format = srvDesc.Format; // This seems to be what causes trouble
udesc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
udesc.Buffer.FirstElement = srvDesc.Buffer.FirstElement;
udesc.Buffer.NumElements = srvDesc.Buffer.NumElements;
The debug layer tells me that "the format cannot be used with a typed unordered access view". It doesn't matter if I specify the same format as that which works with the shader resource view, the corresponding TYPELESS format or DXGI_FORMAT_UNKNOWN; I get the same error at all times.
What puzzles me is that it says "typed unordered access view". What does this mean? It sounds like it might be suggesting it is indeed expecting a structured buffer?
I'm posting this here in the hope that someone with more experience will be able to shed some more light on this.