Sign in to follow this  

Compute Shader - Unbind UAV

Recommended Posts

Migi0027    4628

Hi guys wink.png .


I've got my UAV, initialized with the SRV like this:

data.pSysMem = texArray;
data.SysMemPitch = width * type;
//data.SysMemSlicePitch = width * height * type;

// Build the texture header descriptor
descTex.Width = width;
descTex.Height = height;
descTex.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
descTex.Usage = D3D11_USAGE_DEFAULT;
descTex.CPUAccessFlags = 0;
descTex.MipLevels = 1;
descTex.ArraySize = 1;
descTex.SampleDesc.Count = 1;
descTex.SampleDesc.Quality = 0;

// Create the 2d texture from data
ID3D11Texture2D * pTexture_t = NULL;
HV( dev->CreateTexture2D( &descTex, &data, &pTexture_t ));

// Create resource view descriptor
uavDesc.Format = descTex.Format;
uavDesc.ViewDimension = D3D11_UAV_DIMENSION_TEXTURE2D;

uavDesc.Texture2D.MipSlice = 0;

// Create the shader resource view
HV( dev->CreateUnorderedAccessView( pTexture_t, &uavDesc, &pTexture ));

// Create resource view descriptor
srvDesc.Format = descTex.Format;
srvDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;

srvDesc.Texture2D.MostDetailedMip = 0;
srvDesc.Texture2D.MipLevels = D3D11_RESOURCE_MISC_GENERATE_MIPS;

// Create the shader resource view
HV( dev->CreateShaderResourceView( pTexture_t, &srvDesc, &SRV ));

I've chosen to bind this UAV to the compute shader, for now it's simply only writing a white color to it, which works fine ( debugged it ). I set it like this:

devcon->CSSetUnorderedAccessViews(0, 1, &pOUT, 0);

Now I'd imagine that I'd need to unbind it for a simple shader resource to be accessed, like so:

devcon->CSSetUnorderedAccessViews(0, 0, NULL, 0); // This one

But, when trying to access/send the SRV which points to the same data to the GPU, the debug layer gives me the following warning (or threat really):

Resource being set to PS shader resource slot 0 is still bound on output! Forcing to NULL

Suggesting that the UAV might still be bound somehow, I think, so the SRV is never sent.


What could I have done wrong in this? Do you need anything else?


Thank you for your time, as always. 


Edited by Migi0027

Share this post

Link to post
Share on other sites
Alundra    2316

UAV and SRV must never be bind same time, you have to unbind correctly.

You set using :

devcon->CSSetUnorderedAccessViews(0, 1, &pOUT, 0);

you unbind :

ID3D11UnorderedAccessView* UAV_NULL = NULL;
devcon->CSSetUnorderedAccessViews(0, 1, &UAV_NULL, 0);

When you send the SRV on shader, you must do the same kind of code.

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