I have added a depth buffer but I is not rendering to it.
D3D12_DESCRIPTOR_HEAP_DESC dsvHeapDesc = {};
dsvHeapDesc.NumDescriptors = 1 + FrameCount * 1;
dsvHeapDesc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_DSV;
dsvHeapDesc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_NONE;
result = m_device->CreateDescriptorHeap( &dsvHeapDesc, IID_PPV_ARGS( &m_dsvHeap ) );
assert( result == S_OK && "ERROR CREATING THE DSV HEAP" );
{//Creating the depth texture
CD3DX12_RESOURCE_DESC depth_texture( D3D12_RESOURCE_DIMENSION_TEXTURE2D, 0,
static_cast< UINT >( m_viewport.Width ), static_cast< UINT >( m_viewport.Height ), 1, 1,
DXGI_FORMAT_D32_FLOAT, 1, 0, D3D12_TEXTURE_LAYOUT_UNKNOWN,
D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL | D3D12_RESOURCE_FLAG_DENY_SHADER_RESOURCE );
D3D12_CLEAR_VALUE clear_value;
clear_value.Format = DXGI_FORMAT_D32_FLOAT;
clear_value.DepthStencil.Depth = 1.0f;
clear_value.DepthStencil.Stencil = 0;
result = m_device->CreateCommittedResource( &CD3DX12_HEAP_PROPERTIES( D3D12_HEAP_TYPE_DEFAULT ),
D3D12_HEAP_FLAG_NONE, &depth_texture, D3D12_RESOURCE_STATE_DEPTH_WRITE, &clear_value,
IID_PPV_ARGS( &m_depthStencil ) );
assert( result == S_OK && "CREATING THE DEPTH STENCIL FAILED" );
m_device->CreateDepthStencilView( m_depthStencil.Get(), nullptr, m_dsvHeap->GetCPUDescriptorHandleForHeapStart() );
}
m_commandList->ClearDepthStencilView( m_dsvHeap->GetCPUDescriptorHandleForHeapStart(),
D3D12_CLEAR_FLAG_DEPTH, 1.0f, 0, 0, nullptr);
The only thing that i think its missing is that the resource is not bound, but i dont know how to bind it.