title: Unable to read depth buffer from Compute shader
body: <p>I am unable to read depth buffer from compute shader.</p>
  
  <p>I am using this in my hlsl code.</p>
  
  <pre><code>Texture2D&lt;float4&gt; gDepthTextures : register(t3);
  // tried this.
  //Texture2D&lt;float&gt; gDepthTextures : register(t3);
  // and this.
  //Texture2D&lt;uint&gt; gDepthTextures : register(t3);
  // and this.
  //Texture2D&lt;uint4&gt; gDepthTextures : register(t3);
  </code></pre>
  
  <p>And doing this to read the buffer.</p>
  
  <pre><code>outputTexture[dispatchThreadId.xy]=gDepthTextures.Load(int3(dispatchThreadId.xy,0));
  </code></pre>
  
  <p>And I am detaching depth buffer from render target.</p>
  
  <pre><code>ID3D11RenderTargetView *nullView[3]={NULL,NULL,NULL};
          g_pImmediateContext-&gt;OMSetRenderTargets( 3, nullView, NULL );
  </code></pre>
  
  <p>Still I am getting this error in output.</p>
  
  <pre><code>*D3D11 ERROR: ID3D11DeviceContext::Dispatch: The Shader Resource View dimension declared in the shader code (TEXTURE2D) does not match the view type bound to slot 3 of the Compute Shader unit (BUFFER).  This mismatch is invalid if the shader actually uses the view (e.g. it is not skipped due to shader code branching). [ EXECUTION ERROR #354: DEVICE_DRAW_VIEW_DIMENSION_MISMATCH]*
  </code></pre>
  
  <p>This is how I am creating shader resource view.</p>
  
  <pre><code>// Create depth stencil texture
  D3D11_TEXTURE2D_DESC descDepth;
  ZeroMemory( &amp;descDepth, sizeof(descDepth) );
  descDepth.Width = width;
  descDepth.Height = height;
  descDepth.MipLevels = 1;
  descDepth.ArraySize = 1;
  descDepth.Format = DXGI_FORMAT_R32_TYPELESS;
  descDepth.SampleDesc.Count = 1;
  descDepth.SampleDesc.Quality = 0;
  descDepth.Usage = D3D11_USAGE_DEFAULT;
  descDepth.BindFlags = D3D11_BIND_DEPTH_STENCIL | D3D11_BIND_SHADER_RESOURCE;
  descDepth.CPUAccessFlags = 0;
  descDepth.MiscFlags = 0;
  hr = g_pd3dDevice-&gt;CreateTexture2D( &amp;descDepth, NULL, &amp;g_pDepthStencil );
  if( FAILED( hr ) )
      return hr;
  
  // Create the depth stencil view
  D3D11_DEPTH_STENCIL_VIEW_DESC descDSV;
  ZeroMemory( &amp;descDSV, sizeof(descDSV) );
  descDSV.Format = DXGI_FORMAT_D32_FLOAT;
  descDSV.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D;
  descDSV.Texture2D.MipSlice = 0;
  hr = g_pd3dDevice-&gt;CreateDepthStencilView( g_pDepthStencil, &amp;descDSV,     &amp;g_pDepthStencilView );
  if( FAILED( hr ) )
      return hr;
  
  //  Create depth shader resource view.
  D3D11_SHADER_RESOURCE_VIEW_DESC srvDesc;
  ZeroMemory(&amp;srvDesc,sizeof(D3D11_SHADER_RESOURCE_VIEW_DESC));
  srvDesc.Format=DXGI_FORMAT_R32_UINT;
  srvDesc.ViewDimension=D3D11_SRV_DIMENSION_TEXTURE2D;
  srvDesc.Texture2D.MostDetailedMip=0;
  srvDesc.Texture2D.MipLevels=1;
  
  
  hr=g_pd3dDevice-&gt;CreateShaderResourceView(g_pDepthStencil,&amp;srvDesc,&amp;g_pDepthSRV);
  if(FAILED(hr))
      return hr;
  </code></pre>
  
  <p>I have tried all the formats mentioned <a href="https://gamedev.stackexchange.com/questions/26687/what-are-the-valid-depthbuffer-texture-formats-in-directx-11-and-which-are-also">here</a> in combination with the hlsl texture formats float, float4, uint, uint4 with no success. Any idea?</p>