vk: Fix use-after-free hazard by checking if we're faulting from within the texture cache

- If we're using the texture cache, DO NOT delete resources.
This commit is contained in:
kd-11 2021-07-23 20:15:07 +03:00 committed by kd-11
parent 69bdbe97a8
commit 6a9d1edee1
2 changed files with 20 additions and 2 deletions

View File

@ -1455,8 +1455,16 @@ namespace rsx
bool evict_unused(const std::set<u32>& exclusion_list)
{
// Manage synchronization externally. It is very likely for RSX to call this after failing to create a new texture while already owning the mutex
// Some sanity checks. Do not evict if the cache is currently in use.
ensure(rsx::get_current_renderer()->is_current_thread());
std::unique_lock lock(m_cache_mutex, std::defer_lock);
if (!lock.try_lock())
{
rsx_log.warning("Unable to evict the texture cache because we're faulting from within in the texture cache!");
return false;
}
rsx_log.warning("[PERFORMANCE WARNING] Texture cache is running eviction routine. This will affect performance.");
thrashed_set evicted_set;
@ -1523,7 +1531,9 @@ namespace rsx
}
}
std::lock_guard lock(m_cache_mutex);
image_view_type result = 0;
switch (desc.op)
{
case deferred_request_command::cubemap_gather:

View File

@ -1094,8 +1094,9 @@ namespace vk
bool texture_cache::handle_memory_pressure(rsx::problem_severity severity)
{
bool any_released = baseclass::handle_memory_pressure(severity);
auto any_released = baseclass::handle_memory_pressure(severity);
// TODO: This can cause invalidation of in-flight resources
if (severity <= rsx::problem_severity::low || !m_temporary_memory_size)
{
// Nothing left to do
@ -1109,6 +1110,13 @@ namespace vk
return any_released;
}
std::unique_lock lock(m_cache_mutex, std::defer_lock);
if (!lock.try_lock())
{
rsx_log.warning("Unable to remove temporary resources because we're already in the texture cache!");
return any_released;
}
// Nuke temporary resources. They will still be visible to the GPU.
auto gc = vk::get_resource_manager();
u64 actual_released_memory = 0;