[DX11] Compute Shader / UAV Questions

Started by
2 comments, last by Jason Z 12 years, 4 months ago
I'm getting into Compute Shaders and have a few questions for anyone with experience in this area.

-1-
If a CS needs read-only access to a texture or resource, is there any advantage to making the resource a UAV? Or is am SRV perfectly fine in this situation?


-2-
Is there a way to create a UAV for the back buffer? When I try calling CreateUnorderedAccessView( pBackBuf, NULL, &pBackBufUAV ), I get this error message from D3D:

D3D11: ERROR: ID3D11Device::CreateUnorderedAccessView: The format (0x1d, R8G8B8A8_UNORM_SRGB) cannot be used with a Typed Unordered Access View. [ STATE_CREATION ERROR #2097344: CREATEUNORDEREDACCESSVIEW_INVALIDFORMAT ]
First-chance exception at 0x76f9b9bc in SpecView_td.exe: Microsoft C++ exception: _com_error at memory location 0x098ee568..
D3D11: ERROR: ID3D11Device::CreateUnorderedAccessView: Returning E_INVALIDARG, meaning invalid parameters were passed. [ STATE_CREATION ERROR #2097352: CREATEUNORDEREDACCESSVIEW_INVALIDARG_RETURN ]

So, I tried passing in a D3D11_UNORDERED_ACCESS_VIEW_DESC with its Format set to DXGI_FORMAT_UNKNOWN, but get the same error message. Same thing when I explicitely set Format to the same format as my back buffer (DXGI_FORMAT_R8G8B8A8_UNORM_SRGB). Finally, I tried creating an untyped back buffer by passing DXGI_FORMAT_R8G8B8A8_TYPELESS to CreateSwapChain(), but that causes CreateSwapChain() to fail.

As I typed this, I had a thought that perhaps it's the _SRGB suffix on the back buffer format that's preventing the UAV from being created. I tried passing DXGI_FORMAT_R8G8B8A8_UNORM instead to the swap chain, and now I'm able to create a UAV for the back buffer.

So... let me revise my 2nd question and ask why the _SRGB suffix would prevent a UAV from being created.

Thanks!



[font="Consolas"][size="1"][color="#c0c0c0"][font="Consolas"][size="1"][color="#c0c0c0"][font="Consolas"][size="1"][color="#c0c0c0"][/font][/font][/font]
Advertisement
The general advice for resources that are read only is to utilize an SRV for it. This allows the driver to make certain assumptions (like you won't write to it :) ) and optimize its memory usage. In practice, you are likely using the same hardware to read the data from memory in both cases, so your mileage may vary.

For point #2, you might be interested in reading this forum post, which discusses the conversion process between different formats for UAVs (it should be directly relevant for your case). It comes complete with some helper shader code, so check it out!
Thanks Jason, that's very helpful info.

BTW, very much enjoying your book.

Thanks Jason, that's very helpful info.

BTW, very much enjoying your book.

I'm glad you like it / are enjoying it. If you have any questions or something isn't clear then shoot me an PM or post something here - I appreciate any feedback (good or bad)!

This topic is closed to new replies.

Advertisement