• Create Account

## Unordered access view woes with non-structured buffers

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

7 replies to this topic

### #1Husbjörn  Members

Posted 11 August 2014 - 04:59 AM

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;

// 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.

### #2Hodgman  Moderators

Posted 11 August 2014 - 05:47 AM

What does the UAV declaration in the shader code look like?

### #3Husbjörn  Members

Posted 11 August 2014 - 08:05 AM

RWBuffer<float3> RWBuf : register(u0);


But it fails at the call to ID3D11Device::CreateUnorderedAccessView so I don't think the shader declaration is of any relevance since they haven't been bound together yet by then.

### #4Migi0027 (肉コーダ)  Members

Posted 11 August 2014 - 09:27 AM

Do you by any means have a render target bound?

If I'm not mistaken the UAVs and Render Target Views use the same "registry" (Perhaps a different word is used). As an example, if you had one render target, the UAV has to have an offset by 1.

struct PSOut
{
float3 Diffuse : SV_Target0;
};

// RWBuffer<float3> RWBuf : register(u0); Wrong, the render target and UAV both use the same register

RWBuffer<float3> RWBuf : register(u1);


And if two render targets were bound, the UAV had to have an offset by 2. Or you can use your own packing method, just as long as they dont overlap.

Documentation on OMSetRenderTargetsAndUnorderedAccessViews: http://msdn.microsoft.com/en-us/library/windows/desktop/ff476465(v=vs.85).aspx

• UAVStartSlot [in]
•                      >> For pixel shaders, UAVStartSlot should be equal to the number of render-target views being bound.

Although if no render targets are bound to register 0, this is irrelevant.

EDIT: "But it fails at the call to ID3D11Device::CreateUnorderedAccessView so I don't think the shader declaration is of any relevance since they haven't been bound together yet by then.", sorry, misread, this is irrelevant.

Edited by Migi0027, 11 August 2014 - 11:01 AM.

FastCall22: "I want to make the distinction that my laptop is a whore-box that connects to different network"

Blog about... stuff (GDNet, WordPress): www.gamedev.net/blog/1882-the-cuboid-zone/cuboidzone.wordpress.com/

### #5Husbjörn  Members

Posted 11 August 2014 - 04:51 PM

If I'm not mistaken the UAVs and Render Target Views use the same "registry" (Perhaps a different word is used).

Ah yes, that limitation has caused quite some issues since my engine initially allowed binding render targets to arbitrary registers so that there could be unused ones (reserved for possible future use) in-between. I suppose that wasn't the best solution anyway, so good riddance in a way.

I've had some progress whereby it seems that the DXGIFORMAT_R32_UINT works, but that kind of takes away the notion that buffers can be of "any primitive type" so there is most likely something wrong here still... I'll try to get to the bottom of it tomorrow.

### #6MJP  Moderators

Posted 11 August 2014 - 08:01 PM

It's been a long time, but I'm pretty sure that I've used UAV's with typed buffers of various formats in older projects. I will have to check when I get home. That said, I'm not sure where the issue is in your code. What format are you trying to use?

Edited by MJP, 11 August 2014 - 08:02 PM.

### #7ReaperSMS  Members

Posted 12 August 2014 - 12:52 PM

Typed UAVs have some restrictions, check the DXGI programming guide under Hardware Support for Direct3D 11 Formats.

Column 22 on mine is Typed UAV, and it does apply to most of the types. Conspicuously absent from it, however, are 96-bit RGB, 64-bit depth/stencil, 32-bit depth (use R32), packed 24/8 depth/stencil, shared exponent and odd RG_BG/GR_GB modes, and all of the block compressed formats.

tl;dr: DXGI_FORMAT_R32G32B32_FLOAT doesn't work for typed UAVs. The rest do.

### #8Husbjörn  Members

Posted 12 August 2014 - 05:04 PM

Ah yes, I eventually reached the conclusion that it will in fact only work for "real" primitive datatypes (and probably no 64-bit ones like doubles either for that matter). I was led astray by a passage in Practical Rendering with DirectX 11 that insinuated that things like float3 were in fact considered primitives in HLSL and then the fact that the DXGI_FORMAT enumeration contain lots of formats that are indeed vectors. However I suppose they should be treated like syntactic sugar and indeed require a structured buffer.