rsx: Fix reference leaks in texture_cache<->surface_cache communication

- Properly commit orphaned blocks not invalidating existing cache structures
- Do not ignore overwritten objects when commiting as unprotected fbo. Avoids stale references to invalidated surface objects.
This commit is contained in:
kd-11 2019-08-20 23:22:21 +03:00 committed by kd-11
parent ca8b0da141
commit 5d1b7eb945
3 changed files with 57 additions and 53 deletions

View File

@ -853,7 +853,7 @@ namespace rsx
(invalidation_ignore_unsynchronized && tex.is_flushable() && (cause.skip_flush() || !tex.is_synchronized()) && !overlaps_fault_range) ||
// HACK: When being superseded by an fbo, we preserve other overlapped fbos unless the start addresses match
// If region is committed as fbo, all non-fbo data is removed but all fbos in the region must be preserved if possible
(overlaps_fault_range && tex.get_context() == texture_upload_context::framebuffer_storage && cause.skip_fbos() && (tex.get_section_base() != fault_range_in.start || cause == invalidation_cause::committed_as_fbo))
(overlaps_fault_range && tex.get_context() == texture_upload_context::framebuffer_storage && cause.skip_fbos() && tex.get_section_base() != fault_range_in.start)
)
{
// False positive

View File

@ -364,8 +364,6 @@ void GLGSRender::init_buffers(rsx::framebuffer_creation_context context, bool sk
}
if (!m_rtts.orphaned_surfaces.empty())
{
if (g_cfg.video.write_color_buffers || g_cfg.video.write_depth_buffer)
{
gl::texture::format format;
gl::texture::type type;
@ -373,10 +371,17 @@ void GLGSRender::init_buffers(rsx::framebuffer_creation_context context, bool sk
for (auto& surface : m_rtts.orphaned_surfaces)
{
const bool lock = surface->is_depth_surface() ? !!g_cfg.video.write_depth_buffer :
!!g_cfg.video.write_color_buffers;
if (LIKELY(!lock))
{
m_gl_texture_cache.commit_framebuffer_memory_region(cmd, surface->get_memory_range());
continue;
}
if (surface->is_depth_surface())
{
if (!g_cfg.video.write_depth_buffer) continue;
const auto depth_format_gl = rsx::internals::surface_depth_format_to_gl(surface->get_surface_depth_format());
format = depth_format_gl.format;
type = depth_format_gl.type;
@ -384,8 +389,6 @@ void GLGSRender::init_buffers(rsx::framebuffer_creation_context context, bool sk
}
else
{
if (!g_cfg.video.write_color_buffers) continue;
const auto color_format_gl = rsx::internals::surface_color_format_to_gl(surface->get_surface_color_format());
format = color_format_gl.format;
type = color_format_gl.type;
@ -397,7 +400,6 @@ void GLGSRender::init_buffers(rsx::framebuffer_creation_context context, bool sk
surface->get_surface_width(rsx::surface_metrics::pixels), surface->get_surface_height(rsx::surface_metrics::pixels), surface->get_rsx_pitch(),
format, type, swap_bytes);
}
}
m_rtts.orphaned_surfaces.clear();
}

View File

@ -2926,25 +2926,28 @@ void VKGSRender::prepare_rtts(rsx::framebuffer_creation_context context)
}
if (!m_rtts.orphaned_surfaces.empty())
{
if (g_cfg.video.write_color_buffers || g_cfg.video.write_depth_buffer)
{
u32 gcm_format;
bool swap_bytes;
for (auto& surface : m_rtts.orphaned_surfaces)
{
const bool lock = surface->is_depth_surface() ? !!g_cfg.video.write_depth_buffer :
!!g_cfg.video.write_color_buffers;
if (LIKELY(!lock))
{
m_texture_cache.commit_framebuffer_memory_region(*m_current_command_buffer, surface->get_memory_range());
continue;
}
if (surface->is_depth_surface())
{
if (!g_cfg.video.write_depth_buffer) continue;
gcm_format = (surface->get_surface_depth_format() != rsx::surface_depth_format::z16) ? CELL_GCM_TEXTURE_DEPTH16 : CELL_GCM_TEXTURE_DEPTH24_D8;
swap_bytes = true;
}
else
{
if (!g_cfg.video.write_color_buffers) continue;
auto info = get_compatible_gcm_format(surface->get_surface_color_format());
gcm_format = info.first;
swap_bytes = info.second;
@ -2955,7 +2958,6 @@ void VKGSRender::prepare_rtts(rsx::framebuffer_creation_context context)
surface->get_surface_width(rsx::surface_metrics::pixels), surface->get_surface_height(rsx::surface_metrics::pixels), surface->get_rsx_pitch(),
gcm_format, swap_bytes);
}
}
m_rtts.orphaned_surfaces.clear();
}