I'm trying to use stencil buffer in directx 12. I have problem that probably is really easy to solve. So, it's look like dx12 ignore it, ClearDepthStencilView() affect only depth, writing to stencil doesn't work.
D3D12_DEPTH_STENCIL_DESC for PSO:
static D3D12_DEPTH_STENCIL_DESC const defaultDepthStencil =
{
/*DepthEnable*/ TRUE
/*DepthWriteMask*/ ,D3D12_DEPTH_WRITE_MASK_ALL
/*DepthFunc*/ ,D3D12_COMPARISON_FUNC_LESS
/*StencilEnable*/ ,TRUE
/*StencilReadMask*/ ,D3D12_DEFAULT_STENCIL_READ_MASK
/*StencilWriteMask*/ ,D3D12_DEFAULT_STENCIL_WRITE_MASK
/*FrontFace.StencilFailOp*/ ,{ D3D12_STENCIL_OP_REPLACE
/*FrontFace.StencilDepthFailOp*/ ,D3D12_STENCIL_OP_REPLACE
/*FrontFace.StencilPassOp*/ ,D3D12_STENCIL_OP_REPLACE
/*FrontFace.StencilFunc*/ ,D3D12_COMPARISON_FUNC_ALWAYS }
/*BackFace.StencilFailOp*/ ,{ D3D12_STENCIL_OP_REPLACE
/*BackFace.StencilDepthFailOp*/ ,D3D12_STENCIL_OP_REPLACE
/*BackFace.StencilPassOp*/ ,D3D12_STENCIL_OP_REPLACE
/*BackFace.StencilFunc*/ ,D3D12_COMPARISON_FUNC_ALWAYS }
};
DSV heap desc:
D3D12_DESCRIPTOR_HEAP_DESC dsvHeapDesc = {};
dsvHeapDesc.NumDescriptors = 1;
dsvHeapDesc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_DSV;
dsvHeapDesc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_NONE;
DSV desc:
D3D12_DEPTH_STENCIL_VIEW_DESC depthStencilDesc = {};
depthStencilDesc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
depthStencilDesc.ViewDimension = D3D12_DSV_DIMENSION_TEXTURE2D;
depthStencilDesc.Flags = D3D12_DSV_FLAG_NONE;
Resource desc:
m_gBuffer[GB_Depth].Dimension( D3D12_RESOURCE_DIMENSION_TEXTURE2D );
m_gBuffer[GB_Depth].Width( m_width );
m_gBuffer[GB_Depth].Height( m_height );
m_gBuffer[GB_Depth].DepthOrArraySize( 1 );
m_gBuffer[GB_Depth].MipLevels( 1 );
m_gBuffer[GB_Depth].Format( DXGI_FORMAT_R24G8_TYPELESS );
m_gBuffer[GB_Depth].SampleCount( 1 );
m_gBuffer[GB_Depth].Layout( D3D12_TEXTURE_LAYOUT_UNKNOWN );
m_gBuffer[GB_Depth].Flags( D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL );
Then OMSetRenderTargets() and ClearDepthStencilView() with flags D3D12_CLEAR_FLAG_DEPTH, D3D12_CLEAR_FLAG_STENCIL.
Any idea what's missing?