From 4417701ea774dbea4ba2c93132cbf60f8651396f Mon Sep 17 00:00:00 2001 From: kd-11 Date: Sun, 2 Oct 2022 17:36:01 +0300 Subject: [PATCH] rsx: Track orphaned surfaces' parent addresses --- rpcs3/Emu/RSX/Common/surface_store.h | 4 +- rpcs3/Emu/RSX/GL/GLRenderTargets.cpp | 82 ++++++++++++++-------------- rpcs3/Emu/RSX/VK/VKGSRender.cpp | 74 ++++++++++++------------- 3 files changed, 80 insertions(+), 80 deletions(-) diff --git a/rpcs3/Emu/RSX/Common/surface_store.h b/rpcs3/Emu/RSX/Common/surface_store.h index e921c84e74..0126c17022 100644 --- a/rpcs3/Emu/RSX/Common/surface_store.h +++ b/rpcs3/Emu/RSX/Common/surface_store.h @@ -68,7 +68,7 @@ namespace rsx std::pair m_bound_depth_stencil = {}; // List of sections derived from a section that has been split and invalidated - std::vector orphaned_surfaces; + std::vector> orphaned_surfaces; // List of sections that have been wholly inherited and invalidated std::vector superseded_surfaces; @@ -156,7 +156,7 @@ namespace rsx } ensure(region.target == Traits::get(sink)); - orphaned_surfaces.push_back(region.target); + orphaned_surfaces.push_back({ address, region.target }); data.emplace(region.target->get_memory_range(), std::move(sink)); }; diff --git a/rpcs3/Emu/RSX/GL/GLRenderTargets.cpp b/rpcs3/Emu/RSX/GL/GLRenderTargets.cpp index ccfa7f15bf..14133a542d 100644 --- a/rpcs3/Emu/RSX/GL/GLRenderTargets.cpp +++ b/rpcs3/Emu/RSX/GL/GLRenderTargets.cpp @@ -310,6 +310,47 @@ void GLGSRender::init_buffers(rsx::framebuffer_creation_context context, bool /* m_rtts.superseded_surfaces.clear(); } + if (!m_rtts.orphaned_surfaces.empty()) + { + gl::texture::format format; + gl::texture::type type; + bool swap_bytes; + + for (auto& [base_addr, 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 (!lock) [[likely]] + { + m_gl_texture_cache.commit_framebuffer_memory_region(cmd, surface->get_memory_range()); + continue; + } + + if (surface->is_depth_surface()) + { + 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; + swap_bytes = (type != gl::texture::type::uint_24_8); + } + else + { + 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; + swap_bytes = color_format_gl.swap_bytes; + } + + m_gl_texture_cache.lock_memory_region( + cmd, surface, surface->get_memory_range(), false, + surface->get_surface_width(), surface->get_surface_height(), surface->get_rsx_pitch(), + format, type, swap_bytes); + } + + m_rtts.orphaned_surfaces.clear(); + } + const auto color_format = rsx::internals::surface_color_format_to_gl(m_framebuffer_layout.color_format); for (u8 i = 0; i < rsx::limits::color_buffers_count; ++i) { @@ -347,47 +388,6 @@ void GLGSRender::init_buffers(rsx::framebuffer_creation_context context, bool /* } } - if (!m_rtts.orphaned_surfaces.empty()) - { - gl::texture::format format; - gl::texture::type type; - 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 (!lock) [[likely]] - { - m_gl_texture_cache.commit_framebuffer_memory_region(cmd, surface->get_memory_range()); - continue; - } - - if (surface->is_depth_surface()) - { - 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; - swap_bytes = (type != gl::texture::type::uint_24_8); - } - else - { - 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; - swap_bytes = color_format_gl.swap_bytes; - } - - m_gl_texture_cache.lock_memory_region( - cmd, surface, surface->get_memory_range(), false, - surface->get_surface_width(), surface->get_surface_height(), surface->get_rsx_pitch(), - format, type, swap_bytes); - } - - m_rtts.orphaned_surfaces.clear(); - } - if (m_gl_texture_cache.get_ro_tex_invalidate_intr()) { // Invalidate cached sampler state diff --git a/rpcs3/Emu/RSX/VK/VKGSRender.cpp b/rpcs3/Emu/RSX/VK/VKGSRender.cpp index c2f7c5cf8b..1994c672db 100644 --- a/rpcs3/Emu/RSX/VK/VKGSRender.cpp +++ b/rpcs3/Emu/RSX/VK/VKGSRender.cpp @@ -2416,6 +2416,43 @@ void VKGSRender::prepare_rtts(rsx::framebuffer_creation_context context) m_rtts.superseded_surfaces.clear(); } + if (!m_rtts.orphaned_surfaces.empty()) + { + u32 gcm_format; + bool swap_bytes; + + for (auto& [base_addr, 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 (!lock) [[likely]] + { + m_texture_cache.commit_framebuffer_memory_region(*m_current_command_buffer, surface->get_memory_range()); + continue; + } + + if (surface->is_depth_surface()) + { + 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 + { + auto info = get_compatible_gcm_format(surface->get_surface_color_format()); + gcm_format = info.first; + swap_bytes = info.second; + } + + m_texture_cache.lock_memory_region( + *m_current_command_buffer, surface, surface->get_memory_range(), false, + surface->get_surface_width(), surface->get_surface_height(), surface->get_rsx_pitch(), + gcm_format, swap_bytes); + } + + m_rtts.orphaned_surfaces.clear(); + } + const auto color_fmt_info = get_compatible_gcm_format(m_framebuffer_layout.color_format); for (u8 index : m_draw_buffers) { @@ -2451,43 +2488,6 @@ void VKGSRender::prepare_rtts(rsx::framebuffer_creation_context context) } } - if (!m_rtts.orphaned_surfaces.empty()) - { - 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 (!lock) [[likely]] - { - m_texture_cache.commit_framebuffer_memory_region(*m_current_command_buffer, surface->get_memory_range()); - continue; - } - - if (surface->is_depth_surface()) - { - 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 - { - auto info = get_compatible_gcm_format(surface->get_surface_color_format()); - gcm_format = info.first; - swap_bytes = info.second; - } - - m_texture_cache.lock_memory_region( - *m_current_command_buffer, surface, surface->get_memory_range(), false, - surface->get_surface_width(), surface->get_surface_height(), surface->get_rsx_pitch(), - gcm_format, swap_bytes); - } - - m_rtts.orphaned_surfaces.clear(); - } - m_current_renderpass_key = vk::get_renderpass_key(m_fbo_images); m_cached_renderpass = vk::get_renderpass(*m_device, m_current_renderpass_key);