1
\$\begingroup\$

I have a compute shader which task is to take an input image and then blur it using a Gaussian filter approach. The input and output for the compute shader looks like this:

//Input and output resources
Texture2D<float4> InputMap : register(t0);
RWTexture2D<float4> OutputMap : register(u0);

The necessary steps for the compute shader setup is shown below:

//Load SRV with the image first
DX::ThrowIfFailed(CreateWICTextureFromFileEx(D3DHelper::GetDevice(), L"Images/floor.jpg", 0, D3D11_USAGE_DEFAULT, D3D11_BIND_UNORDERED_ACCESS | D3D11_BIND_SHADER_RESOURCE,
        0, 0, 0, m_resource.GetAddressOf(), m_blurTexture.GetAddressOf()));

//Create UAV
D3D11_UNORDERED_ACCESS_VIEW_DESC descView;
memset(&descView, 0, sizeof(descView));
descView.Format = DXGI_FORMAT_UNKNOWN;
descView.ViewDimension = D3D11_UAV_DIMENSION_TEXTURE2D;
descView.Texture2D.MipSlice = 0;

DX::ThrowIfFailed(D3DHelper::GetDevice()->CreateUnorderedAccessView(m_resource.Get(), &descView, m_UAV.GetAddressOf()));

//Blur image with compute shader
Shader::SetComputeShader("Blur", m_blurTexture, m_UAV, 16, 16, 1);
Shader::UnbindComputeShader();

Now if we imagine that the work of the compute shader is done correctly, the last step would then be to bind the SRV/UAV containing the blurred image to the pixel shader stage for the object which will use the texture. However, this texture seems to end up completely black after the compute shader pass if I do the following binding:

D3DHelper::GetDeviceContext()->PSSetShaderResources(0, 1, m_blurTexture.GetAddressOf());

I believe there are a few more steps missing since I need to get the data from the UAV and not the SRV since the UAV contains the output image. What would be the correct approach?

\$\endgroup\$
2

0

You must log in to answer this question.