From 6b9717c7f7f3375774d04f85d8a645d6cc9bbc93 Mon Sep 17 00:00:00 2001 From: Triang3l Date: Fri, 10 Aug 2018 18:44:38 +0300 Subject: [PATCH] [D3D12] Fix retarded render target allocation bugs --- src/xenia/gpu/d3d12/render_target_cache.cc | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/xenia/gpu/d3d12/render_target_cache.cc b/src/xenia/gpu/d3d12/render_target_cache.cc index 8b3cb52af..42a750957 100644 --- a/src/xenia/gpu/d3d12/render_target_cache.cc +++ b/src/xenia/gpu/d3d12/render_target_cache.cc @@ -424,6 +424,7 @@ bool RenderTargetCache::UpdateRenderTargets() { if (binding.render_target == nullptr) { continue; } + heap_usage[heap_page_first >> 3] += heap_page_count; // Inform Direct3D that we're reusing the heap for this render target. D3D12_RESOURCE_BARRIER& barrier = barriers[barrier_count++]; @@ -594,7 +595,15 @@ bool RenderTargetCache::GetResourceDesc(RenderTargetKey key, RenderTargetCache::RenderTarget* RenderTargetCache::FindOrCreateRenderTarget( RenderTargetKey key, uint32_t heap_page_first) { assert_true(heap_page_first <= 8 * 5); - // TODO(Triang3l): Find an existing render target. + + // Try to find an existing render target. + auto found_range = render_targets_.equal_range(key.value); + for (auto iter = found_range.first; iter != found_range.second; ++iter) { + RenderTarget* found_render_target = iter->second; + if (found_render_target->heap_page_first == heap_page_first) { + return found_render_target; + } + } D3D12_RESOURCE_DESC resource_desc; if (!GetResourceDesc(key, resource_desc)) {