From 9cd5325962d3272a00956b880584d9502abf251b Mon Sep 17 00:00:00 2001 From: kd-11 Date: Mon, 19 Aug 2019 20:20:19 +0300 Subject: [PATCH] rsx: Free memory 'held hostage' by storage sections in the surface cache - Once the memory has been captured by another surface, release the allocation --- rpcs3/Emu/RSX/Common/surface_store.h | 21 +++++++++++++++++++++ rpcs3/Emu/RSX/Common/surface_utils.h | 2 +- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/rpcs3/Emu/RSX/Common/surface_store.h b/rpcs3/Emu/RSX/Common/surface_store.h index 29402a7cce..a1dc06c1de 100644 --- a/rpcs3/Emu/RSX/Common/surface_store.h +++ b/rpcs3/Emu/RSX/Common/surface_store.h @@ -347,6 +347,27 @@ namespace rsx region.target = new_surface; new_surface->set_old_contents_region(region, true); + + if (surface->memory_usage_flags == surface_usage_flags::storage && + region.width == parent_w && + region.height == parent_h && + surface != prev_surface && + surface == e.second) + { + // This has been 'swallowed' by the new surface and can be safely freed + auto &storage = surface->is_depth_surface() ? m_depth_stencil_storage : m_render_targets_storage; + auto &object = storage[e.first]; + + verify(HERE), !src_offset.x, !src_offset.y, object; + if (UNLIKELY(!surface->old_contents.empty())) + { + surface->read_barrier(cmd); + } + + Traits::notify_surface_invalidated(object); + invalidated_resources.push_back(std::move(object)); + storage.erase(e.first); + } } } diff --git a/rpcs3/Emu/RSX/Common/surface_utils.h b/rpcs3/Emu/RSX/Common/surface_utils.h index 8bc96c217c..7b3bbf5d7e 100644 --- a/rpcs3/Emu/RSX/Common/surface_utils.h +++ b/rpcs3/Emu/RSX/Common/surface_utils.h @@ -130,7 +130,7 @@ namespace rsx struct render_target_descriptor { u64 last_use_tag = 0; // tag indicating when this block was last confirmed to have been written to - u64 base_addr = 0; + u32 base_addr = 0; #if (ENABLE_SURFACE_CACHE_DEBUG) u64 memory_hash = 0;