Sign in to follow this  

DX11 DX11 - Converting an UAV to SRV or Reading an UAV

Recommended Posts

Migi0027    4630

Well, some few days a go I asked a question about re-writable textures, a UAV, which basically acts as a render target, though it took me a while to figure that out. tongue.png


Case #1:

But one problem is that if you use multiple render targets, there aren't so many slots for any UAVs, so I was suggested to sample a UAV to a Srv on a full screen quad, which is actually the way to go!


But, yeah it had to come, what about 3D Textures?


Do I render each single depth slice on and on, wouldn't that be terrible slow? (Sampling each single pixel on a full screen...)


My 3D Texture has the dimension 128x128x128, so using that approach above, I would need to sample 2097152 times, just for one 3D Texture!


What approaches could be taken to this?


Case #2

When reading my UAV, I get several warnings/errors in the runtime:

D3D11: ERROR: ID3D11DeviceContext::DrawIndexed: The Unordered Access View (UAV) in slot 1 of the Pixel Shader unit has the Format (R8G8B8A8_UNORM). This format does not support being read from a shader as as UAV. This mismatch is invalid if the shader actually uses the view (e.g. it is not skipped due to shader code branching). It was unfortunately not possible to have all hardware implementations support reading this format as a UAV, despite that the format can written to as a UAV. If the shader only needs to perform reads but not writes to this resource, consider using a Shader Resource View instead of a UAV.  [ EXECUTION ERROR #2097382: DEVICE_UNORDEREDACCESSVIEW_FORMAT_LD_UNSUPPORTED ]

I get the error, and the reason for it to appear, but just not which format which I should use instead.


How can, if possible, I fix this error, what format is needed?


Thanks, as usual!


Share this post

Link to post
Share on other sites
MJP    19791

I don't understand the problem you're describing for case #1. Could you elaborate on what you're trying to accomplish?

For #2, the only texture format that can be read from a UAV is R32_FLOAT/R32_UINT/R32_SINT. 

Share this post

Link to post
Share on other sites
Migi0027    4630

In case #1, imagine that I had a RW2DTexture, which needed to be converted to a Texture2D.


I'd read over all the data in the pixel shader from the RW (On a full screen quad), the position is the texcoord, then output it to a shader resource view via a render target.


But what I have is a 3d texture, not a 2d, and I actually have 6 of them (Cube Map)


EDIT: Sorry if I made a mess in case #1, I hope this version is better.

Edited by Migi0027

Share this post

Link to post
Share on other sites
Styves    1792

Heh I think you misunderstood from the other topic. :)


You don't need to convert UAV data to a SRV. When you create your UAV resource, you can create a matching SRV resource that points to the same data. You just bind this as a shader resource and in the shader use "Texture2D" as the type. Same goes for Texture3D, etc.


There's no conversions involved, no extra passes. You just create a new SRV. ;)


Hint: so long as the creation flags permit, you can have RTVs, UAVs and SRVs all pointing to the same source. You just need to watch the formats and description setup as it's somewhat specific.


As for the format, what MJP says is basically it. You need to pack the data that you would store to RGBA8_UNORM and pack it to R32_UINT (bitshifts).

Share this post

Link to post
Share on other sites
Styves    1792

No problem. It can be a little difficult to get it all working (creating UAV and SRV with proper types, setting up the CS, etc) so I don't expect anyone to get it all working without a single question if they've never used it before. :)


A good idea though would be to run over to the DX documentation and read up on the UAVs and SRVs a bit more, I'm pretty sure they go over this stuff and also have the notes for proper types, etc. It's a great reference for this stuff. ;)

Share this post

Link to post
Share on other sites
unbird    8338
There's a handy HLSL include coming with the SDK (Include folder, D3DX_DXGIFormatConvert.inl) to help with format conversions. Hmmm, nice, reading the comments there is also enlightening (it mentions the UAV limitations).

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

Sign in to follow this  

  • Partner Spotlight

  • Similar Content

    • By RubenRS
      How do i open an image to use it as Texture2D information without D3DX11CreateShaderResourceViewFromFile? And how it works for different formats like (JPG, PNG, BMP, DDS,  etc.)?
      I have an (512 x 512) image with font letters, also i have the position and texcoord of every letter. The main idea is that i want to obtain the image pixel info, use the position and texcoords to create a new texture with one letter and render it. Or am I wrong in something?
    • By thmfrnk
      I found a very interesting blog post here:
      However, I didn't really got how to use his "TestConeVsSphere" test in 3D (last piece of code on his post). I have the frustumCorners of a 2D Tile cell in ViewSpace and my 3D Cone Origin and Direction, so where to place the "testSphere"? I thought about to also move the Cone into viewspace and put the sphere to the Center of the Cell with the radius of half-cellsize, however what about depth? A sphere does not have inf depth?
      I am missing anything? Any Ideas?
      Thx, Thomas
    • By Modymek
      hi all
      I want to enable and disable shader in MPCH Media player Classic
      the MPCH have shader option using HLSL shaders
      I want the shader to read each file extension before it plays the file
      so if the video file name is video.GR.Mp4 it will play it in Grayscale shader 
      if it is not and standard file name Video.Mp4 without GR. unique extension so it plays standard without shader or end the shader
      here is the shader I have for grayscale
      // $MinimumShaderProfile: ps_2_0
      sampler s0 : register(s0);
      float4 main(float2 tex : TEXCOORD0) : COLOR {
          float c0 = dot(tex2D(s0, tex), float4(0.299, 0.587, 0.114, 0));
          return c0;
      I want to add if or block stantement or bloean to detect file name before it call the shader in order to go to the procedure or disable it or goto end direct without it
      any thoughts or help
    • By noodleBowl
      I've gotten to part in my DirectX 11 project where I need to pass the MVP matrices to my vertex shader. And I'm a little lost when it comes to the use of the constant buffer with the vertex shader
      I understand I need to set up the constant buffer just like any other buffer:
      1. Create a buffer description with the D3D11_BIND_CONSTANT_BUFFER flag 2. Map my matrix data into the constant buffer 3. Use VSSetConstantBuffers to actually use the buffer But I get lost at the VertexShader part, how does my vertex shader know to use this constant buffer when we get to the shader side of things
      In the example I'm following I see they have this as their vertex shader, but I don't understand how the shader knows to use the MatrixBuffer cbuffer. They just use the members directly. What if there was multiple cbuffer declarations like the Microsoft documentation says you could have?
      //Inside vertex shader cbuffer MatrixBuffer { matrix worldMatrix; matrix viewMatrix; matrix projectionMatrix; }; struct VertexInputType { float4 position : POSITION; float4 color : COLOR; }; struct PixelInputType { float4 position : SV_POSITION; float4 color : COLOR; }; PixelInputType ColorVertexShader(VertexInputType input) { PixelInputType output; // Change the position vector to be 4 units for proper matrix calculations. input.position.w = 1.0f; // Calculate the position of the vertex against the world, view, and projection matrices. output.position = mul(input.position, worldMatrix); output.position = mul(output.position, viewMatrix); output.position = mul(output.position, projectionMatrix); // Store the input color for the pixel shader to use. output.color = input.color; return output; }  
    • By gomidas
      I am trying to add normal map to my project I have an example of a cube: 
      I have normal in my shader I think. Then I set shader resource view for texture (NOT BUMP)
                  device.ImmediateContext.PixelShader.SetShaderResource(0, textureView);             device.ImmediateContext.Draw(VerticesCount,0); What should I do to set my normal map or how it is done in dx11 generally example c++?
  • Popular Now