Jump to content
  • Advertisement
Sign in to follow this  

DX11 [DX11] Compute Shader / UAV Questions

This topic is 2502 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm getting into Compute Shaders and have a few questions for anyone with experience in this area.

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?

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.



Share this post

Link to post
Share on other sites
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!

Share this post

Link to post
Share on other sites

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)!

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • 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!