void DepthBuffer::CreateDerivedViews( ID3D12Device* Device, DXGI_FORMAT Format ) { ID3D12Resource* Resource = m_pResource.Get(); D3D12_DEPTH_STENCIL_VIEW_DESC DSVDesc; DSVDesc.Format = GetDSVFormat( Format ); DSVDesc.ViewDimension = D3D12_DSV_DIMENSION_TEXTURE2D; DSVDesc.Texture2D.MipSlice = 0; if (m_DSVHandle[0].ptr == ~0ull) { m_DSVHandle[0] = Graphics::g_pDSVDescriptorHeap->Append().GetCPUHandle(); m_DSVHandle[1] = Graphics::g_pDSVDescriptorHeap->Append().GetCPUHandle(); } DSVDesc.Flags = D3D12_DSV_FLAG_NONE; Device->CreateDepthStencilView( Resource, &DSVDesc, m_DSVHandle[0] ); DSVDesc.Flags = D3D12_DSV_FLAG_READ_ONLY_DEPTH; Device->CreateDepthStencilView( Resource, &DSVDesc, m_DSVHandle[1] ); DXGI_FORMAT stencilReadFormat = GetStencilFormat( Format ); if (stencilReadFormat != DXGI_FORMAT_UNKNOWN) { if (m_DSVHandle[2].ptr == ~0ull) { m_DSVHandle[2] = Graphics::g_pDSVDescriptorHeap->Append().GetCPUHandle(); m_DSVHandle[3] = Graphics::g_pDSVDescriptorHeap->Append().GetCPUHandle(); } DSVDesc.Flags = D3D12_DSV_FLAG_READ_ONLY_STENCIL; Device->CreateDepthStencilView( Resource, &DSVDesc, m_DSVHandle[2] ); DSVDesc.Flags = D3D12_DSV_FLAG_READ_ONLY_DEPTH | D3D12_DSV_FLAG_READ_ONLY_STENCIL; Device->CreateDepthStencilView( Resource, &DSVDesc, m_DSVHandle[3] ); } else { m_DSVHandle[2] = m_DSVHandle[0]; m_DSVHandle[3] = m_DSVHandle[1]; } if (m_DepthSRVHandle.ptr == ~0ull) m_DepthSRVHandle = Graphics::g_pCSUDescriptorHeap->Append().GetCPUHandle(); D3D12_SHADER_RESOURCE_VIEW_DESC SRVDesc = {}; SRVDesc.Format = GetDepthFormat( Format ); SRVDesc.ViewDimension = D3D12_SRV_DIMENSION_TEXTURE2D; SRVDesc.Shader4ComponentMapping = D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING; SRVDesc.Texture2D.MipLevels = 1; Device->CreateShaderResourceView( Resource, &SRVDesc, m_DepthSRVHandle ); if (stencilReadFormat != DXGI_FORMAT_UNKNOWN) { if (m_StencilSRVHandle.ptr == ~0ull) { m_StencilSRVHandle = Graphics::g_pCSUDescriptorHeap->Append().GetCPUHandle(); } SRVDesc.Format = stencilReadFormat; Device->CreateShaderResourceView( Resource, &SRVDesc, m_StencilSRVHandle ); } }
void DepthBuffer::CreateDerivedViews(ID3D12Device * pDevice, DXGI_FORMAT format) { ID3D12Resource* resource = m_resource.Get(); D3D12_DEPTH_STENCIL_VIEW_DESC dsvDesc = {}; dsvDesc.Format = GetDSVFormat(format); dsvDesc.ViewDimension = D3D12_DSV_DIMENSION_TEXTURE2D; dsvDesc.Texture2D.MipSlice = 0; if (m_hDSV[0].ptr == ~0ull) { m_hDSV[0] = graphics::AllocateDescriptor(D3D12_DESCRIPTOR_HEAP_TYPE_DSV); m_hDSV[1] = graphics::AllocateDescriptor(D3D12_DESCRIPTOR_HEAP_TYPE_DSV); } dsvDesc.Flags = D3D12_DSV_FLAG_NONE; pDevice->CreateDepthStencilView(resource, &dsvDesc, m_hDSV[0]); dsvDesc.Flags = D3D12_DSV_FLAG_READ_ONLY_DEPTH; pDevice->CreateDepthStencilView(resource, &dsvDesc, m_hDSV[1]); DXGI_FORMAT stencilReadFormat = GetStencilFormat(format); if (stencilReadFormat != DXGI_FORMAT_UNKNOWN) { if (m_hDSV[2].ptr == ~0ull) { m_hDSV[2] = graphics::AllocateDescriptor(D3D12_DESCRIPTOR_HEAP_TYPE_DSV); m_hDSV[3] = graphics::AllocateDescriptor(D3D12_DESCRIPTOR_HEAP_TYPE_DSV); } dsvDesc.Flags = D3D12_DSV_FLAG_READ_ONLY_STENCIL; pDevice->CreateDepthStencilView(resource, &dsvDesc, m_hDSV[2]); dsvDesc.Flags = D3D12_DSV_FLAG_READ_ONLY_DEPTH | D3D12_DSV_FLAG_READ_ONLY_STENCIL; pDevice->CreateDepthStencilView(resource, &dsvDesc, m_hDSV[3]); } else { m_hDSV[2] = m_hDSV[0]; m_hDSV[3] = m_hDSV[1]; } if (m_hDepthSRV.ptr == ~0ull) { m_hDepthSRV = graphics::AllocateDescriptor(D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV); } D3D12_SHADER_RESOURCE_VIEW_DESC srvDesc = {}; srvDesc.Format = GetDepthFormat(format); srvDesc.ViewDimension = D3D12_SRV_DIMENSION_TEXTURE2D; srvDesc.Shader4ComponentMapping = D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING; srvDesc.Texture2D.MipLevels = 1; pDevice->CreateShaderResourceView(resource, &srvDesc, m_hDepthSRV); if (stencilReadFormat != DXGI_FORMAT_UNKNOWN) { if (m_hStencilSRV.ptr == ~0ull) { m_hStencilSRV = graphics::AllocateDescriptor(D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV); } srvDesc.Format = stencilReadFormat; pDevice->CreateShaderResourceView(resource, &srvDesc, m_hStencilSRV); } }