JavaCoolDude

Can't access stencil in a pixel shader on a Radeon 5870

Discussion created by JavaCoolDude on May 9, 2010
Latest reply on May 10, 2010 by JavaCoolDude

Greetings

 

I am trying to access the stencil values within a pixel shader but I haven’t had much luck so far.

I am running a Windows 7 64bits machine with a Radeon 5870, here’s what I am doing:

 

C code:

// create texture

      D3D11_TEXTURE2D_DESC desc;

      desc.Width                          = width;

      desc.Height                         = height;

      desc.MipLevels                      = 1;

      desc.ArraySize                      = 1;

      desc.Format                         = DXGI_FORMAT_R24G8_TYPELESS;

      desc.SampleDesc.Count               = 1;

      desc.SampleDesc.Quality             = 0;

      desc.Usage                          = D3D11_USAGE_DEFAULT;

      desc.BindFlags                      = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_DEPTH_STENCIL;

      desc.CPUAccessFlags                 = 0;

      desc.MiscFlags                      = 0;

 

      HRESULT hr = d3d->CreateTexture2D( &desc, NULL, &m_DsTexture.m_Texture);

     

      D3D11_DEPTH_STENCIL_VIEW_DESC dsvd;

      dsvd.Format             = DXGI_FORMAT_D24_UNORM_S8_UINT;

      dsvd.ViewDimension      = D3D11_DSV_DIMENSION_TEXTURE2D;

      dsvd.Flags              = 0;

      dsvd.Texture2D.MipSlice = 0;

 

      VERIFY_HR( d3d->CreateDepthStencilView( m_DsTexture.m_Texture,// pResource

                                              &dsvd,                // pDesc

                                              &m_DsWriteView ));    // ppRTView

                                             

  

      // Create the shader resource view

      D3D11_SHADER_RESOURCE_VIEW_DESC descSRV;

      descSRV.FormatDXGI_FORMAT_X24_TYPELESS_G8_UINT;  

      descSRV.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;

      descSRV.Texture2D.MipLevels = 1;

      descSRV.Texture2D.MostDetailedMip = 0;

      VERIFY_HR( d3d->CreateShaderResourceView( m_DsTexture.m_Texture,

                                                &descSRV,

                                                &m_DsTexture.m_View ) );

 

Shader code:

Texture2D<uint> g_StencilTexture : MAKE_TEXTURE_REG( TEX_UNIT_BASE );

 

float4 PS_Stencil_Test(in PS_Tex0 input ) : SV_TARGET

 

Outcomes