cancel
Showing results for 
Search instead for 
Did you mean: 

Archives Discussions

Java_Cool_Dude
Journeyman III

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

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

 

Tags (1)
0 Likes
2 Replies
Java_Cool_Dude
Journeyman III

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

What do you know, I just switched from ps 4.0 profile when compiling my shader to 5.0 and everything works as expected.

 

0 Likes
Java_Cool_Dude
Journeyman III

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

It turns out the ps_4_0 profile is just fine what happened though was when I switched to ps_5_0 I also started declaring my texture resource as Texture2uint4> instead of Texture2D<uint> and since the stencil value is stored in the y (green) component of the texture according to the DXGI_FORMAT_X24_TYPELESS_G8_UINT format, I was originally throwing it away in favor of an undefined x value (X24).

Bottom line is, use at least Texture2D<uint2> if you plan on accessing your stencil values.

Sigh!

 

0 Likes