[D3D12] Cleanup object destruction in Shutdown functions

This commit is contained in:
Triang3l 2018-08-26 00:24:25 +03:00
parent ff014d47d4
commit 791c275fab
5 changed files with 21 additions and 79 deletions

View File

@ -666,10 +666,7 @@ void D3D12CommandProcessor::ShutdownContext() {
auto context = GetD3D12Context(); auto context = GetD3D12Context();
context->AwaitAllFramesCompletion(); context->AwaitAllFramesCompletion();
if (scratch_buffer_ != nullptr) { ui::d3d12::util::ReleaseAndNull(scratch_buffer_);
scratch_buffer_->Release();
scratch_buffer_ = nullptr;
}
scratch_buffer_size_ = 0; scratch_buffer_size_ = 0;
for (auto& buffer_for_deletion : buffers_for_deletion_) { for (auto& buffer_for_deletion : buffers_for_deletion_) {
@ -688,14 +685,8 @@ void D3D12CommandProcessor::ShutdownContext() {
swap_texture_srv_descriptor_heap_->Release(); swap_texture_srv_descriptor_heap_->Release();
swap_texture_srv_descriptor_heap_ = nullptr; swap_texture_srv_descriptor_heap_ = nullptr;
} }
if (swap_texture_rtv_descriptor_heap_ != nullptr) { ui::d3d12::util::ReleaseAndNull(swap_texture_rtv_descriptor_heap_);
swap_texture_rtv_descriptor_heap_->Release(); ui::d3d12::util::ReleaseAndNull(swap_texture_);
swap_texture_rtv_descriptor_heap_ = nullptr;
}
if (swap_texture_ != nullptr) {
swap_texture_->Release();
swap_texture_ = nullptr;
}
sampler_heap_pool_.reset(); sampler_heap_pool_.reset();
view_heap_pool_.reset(); view_heap_pool_.reset();
@ -801,10 +792,7 @@ void D3D12CommandProcessor::PerformSwap(uint32_t frontbuffer_ptr,
cache_clear_requested_ = false; cache_clear_requested_ = false;
GetD3D12Context()->AwaitAllFramesCompletion(); GetD3D12Context()->AwaitAllFramesCompletion();
if (scratch_buffer_ != nullptr) { ui::d3d12::util::ReleaseAndNull(scratch_buffer_);
scratch_buffer_->Release();
scratch_buffer_ = nullptr;
}
scratch_buffer_size_ = 0; scratch_buffer_size_ = 0;
sampler_heap_pool_->ClearCache(); sampler_heap_pool_->ClearCache();

View File

@ -116,14 +116,8 @@ X_STATUS D3D12GraphicsSystem::Setup(cpu::Processor* processor,
} }
void D3D12GraphicsSystem::Shutdown() { void D3D12GraphicsSystem::Shutdown() {
if (stretch_pipeline_ != nullptr) { ui::d3d12::util::ReleaseAndNull(stretch_pipeline_);
stretch_pipeline_->Release(); ui::d3d12::util::ReleaseAndNull(stretch_root_signature_);
stretch_pipeline_ = nullptr;
}
if (stretch_root_signature_ != nullptr) {
stretch_root_signature_->Release();
stretch_root_signature_ = nullptr;
}
GraphicsSystem::Shutdown(); GraphicsSystem::Shutdown();
} }

View File

@ -283,46 +283,17 @@ void RenderTargetCache::Shutdown() {
resolve_pipeline.pipeline->Release(); resolve_pipeline.pipeline->Release();
} }
resolve_pipelines_.clear(); resolve_pipelines_.clear();
if (resolve_root_signature_ != nullptr) { ui::d3d12::util::ReleaseAndNull(resolve_root_signature_);
resolve_root_signature_->Release(); ui::d3d12::util::ReleaseAndNull(edram_tile_sample_32bpp_pipeline_);
resolve_root_signature_ = nullptr; ui::d3d12::util::ReleaseAndNull(edram_clear_depth_float_pipeline_);
} ui::d3d12::util::ReleaseAndNull(edram_clear_32bpp_pipeline_);
if (edram_tile_sample_32bpp_pipeline_ != nullptr) {
edram_tile_sample_32bpp_pipeline_->Release();
edram_tile_sample_32bpp_pipeline_ = nullptr;
}
if (edram_clear_depth_float_pipeline_ != nullptr) {
edram_clear_depth_float_pipeline_->Release();
edram_clear_depth_float_pipeline_ = nullptr;
}
if (edram_clear_32bpp_pipeline_ != nullptr) {
edram_clear_32bpp_pipeline_->Release();
edram_clear_32bpp_pipeline_ = nullptr;
}
for (uint32_t i = 0; i < uint32_t(EDRAMLoadStoreMode::kCount); ++i) { for (uint32_t i = 0; i < uint32_t(EDRAMLoadStoreMode::kCount); ++i) {
if (edram_load_pipelines_[i] != nullptr) { ui::d3d12::util::ReleaseAndNull(edram_store_pipelines_[i]);
edram_load_pipelines_[i]->Release(); ui::d3d12::util::ReleaseAndNull(edram_load_pipelines_[i]);
edram_load_pipelines_[i] = nullptr;
}
if (edram_store_pipelines_[i] != nullptr) {
edram_store_pipelines_[i]->Release();
edram_store_pipelines_[i] = nullptr;
}
}
if (edram_clear_root_signature_ != nullptr) {
edram_clear_root_signature_->Release();
edram_clear_root_signature_ = nullptr;
}
if (edram_load_store_root_signature_ != nullptr) {
edram_load_store_root_signature_->Release();
edram_load_store_root_signature_ = nullptr;
}
if (edram_buffer_ != nullptr) {
edram_buffer_->Release();
edram_buffer_ = nullptr;
} }
ui::d3d12::util::ReleaseAndNull(edram_clear_root_signature_);
ui::d3d12::util::ReleaseAndNull(edram_load_store_root_signature_);
ui::d3d12::util::ReleaseAndNull(edram_buffer_);
} }
void RenderTargetCache::ClearCache() { void RenderTargetCache::ClearCache() {

View File

@ -291,25 +291,13 @@ void TextureCache::Shutdown() {
ClearCache(); ClearCache();
for (uint32_t i = 0; i < uint32_t(TileMode::kCount); ++i) { for (uint32_t i = 0; i < uint32_t(TileMode::kCount); ++i) {
if (tile_pipelines_[i] != nullptr) { ui::d3d12::util::ReleaseAndNull(tile_pipelines_[i]);
tile_pipelines_[i]->Release();
tile_pipelines_[i] = nullptr;
}
}
if (tile_root_signature_ != nullptr) {
tile_root_signature_->Release();
tile_root_signature_ = nullptr;
} }
ui::d3d12::util::ReleaseAndNull(tile_root_signature_);
for (uint32_t i = 0; i < uint32_t(LoadMode::kCount); ++i) { for (uint32_t i = 0; i < uint32_t(LoadMode::kCount); ++i) {
if (load_pipelines_[i] != nullptr) { ui::d3d12::util::ReleaseAndNull(load_pipelines_[i]);
load_pipelines_[i]->Release();
load_pipelines_[i] = nullptr;
}
}
if (load_root_signature_ != nullptr) {
load_root_signature_->Release();
load_root_signature_ = nullptr;
} }
ui::d3d12::util::ReleaseAndNull(load_root_signature_);
} }
void TextureCache::ClearCache() { void TextureCache::ClearCache() {

View File

@ -17,7 +17,8 @@ namespace ui {
namespace d3d12 { namespace d3d12 {
namespace util { namespace util {
inline bool ReleaseAndNull(IUnknown*& object) { template <typename T>
inline bool ReleaseAndNull(T& object) {
if (object != nullptr) { if (object != nullptr) {
object->Release(); object->Release();
object = nullptr; object = nullptr;