From b95630d84a928d1c0df304f8b3cbfb59ba283487 Mon Sep 17 00:00:00 2001 From: kd-11 Date: Tue, 31 Oct 2017 21:49:30 +0300 Subject: [PATCH] rsx: Minor fixups - Optimize framebuffer memory invalidate conditions - Fix texture sampling of AA textures (wider by 2x surfaces) --- rpcs3/Emu/RSX/Common/texture_cache.h | 14 ++++++++------ rpcs3/Emu/RSX/GL/GLGSRender.cpp | 22 ++++++++++++---------- rpcs3/Emu/RSX/VK/VKGSRender.cpp | 21 +++++++++++---------- 3 files changed, 31 insertions(+), 26 deletions(-) diff --git a/rpcs3/Emu/RSX/Common/texture_cache.h b/rpcs3/Emu/RSX/Common/texture_cache.h index 1569baeee9..dfebf620ac 100644 --- a/rpcs3/Emu/RSX/Common/texture_cache.h +++ b/rpcs3/Emu/RSX/Common/texture_cache.h @@ -894,9 +894,10 @@ namespace rsx if (extended_dimension != rsx::texture_dimension_extended::texture_dimension_2d) LOG_ERROR(RSX, "Texture resides in render target memory, but requested type is not 2D (%d)", (u32)extended_dimension); - f32 internal_scale = (f32)texptr->get_native_pitch() / tex.pitch(); - bool requires_processing = texptr->get_surface_width() != tex_width || texptr->get_surface_height() != tex_height; + const f32 internal_scale = (f32)texptr->get_native_pitch() / tex.pitch(); + const u32 internal_width = tex_width * texptr->get_native_pitch() / tex.pitch(); + bool requires_processing = texptr->get_surface_width() != internal_width || texptr->get_surface_height() != tex_height; if (!requires_processing) { for (const auto& tex : m_rtts.m_bound_render_targets) @@ -921,7 +922,7 @@ namespace rsx if (requires_processing) { - const auto w = rsx::apply_resolution_scale(tex_width, true); + const auto w = rsx::apply_resolution_scale(internal_width, true); const auto h = rsx::apply_resolution_scale(tex_height, true); return{ create_temporary_subresource_view(cmd, texptr, format, 0, 0, w, h), texture_upload_context::framebuffer_storage, false, internal_scale }; } @@ -942,9 +943,10 @@ namespace rsx if (extended_dimension != rsx::texture_dimension_extended::texture_dimension_2d) LOG_ERROR(RSX, "Texture resides in depth buffer memory, but requested type is not 2D (%d)", (u32)extended_dimension); - f32 internal_scale = (f32)texptr->get_native_pitch() / tex.pitch(); - bool requires_processing = texptr->get_surface_width() != tex_width || texptr->get_surface_height() != tex_height; + const f32 internal_scale = (f32)texptr->get_native_pitch() / tex.pitch(); + const u32 internal_width = tex_width * texptr->get_native_pitch() / tex.pitch(); + bool requires_processing = texptr->get_surface_width() != internal_width || texptr->get_surface_height() != tex_height; if (!requires_processing && texaddr == std::get<0>(m_rtts.m_bound_depth_stencil)) { if (g_cfg.video.strict_rendering_mode) @@ -961,7 +963,7 @@ namespace rsx if (requires_processing) { - const auto w = rsx::apply_resolution_scale(tex_width, true); + const auto w = rsx::apply_resolution_scale(internal_width, true); const auto h = rsx::apply_resolution_scale(tex_height, true); return{ create_temporary_subresource_view(cmd, texptr, format, 0, 0, w, h), texture_upload_context::framebuffer_storage, true, internal_scale }; } diff --git a/rpcs3/Emu/RSX/GL/GLGSRender.cpp b/rpcs3/Emu/RSX/GL/GLGSRender.cpp index a595a41906..348b51fc28 100644 --- a/rpcs3/Emu/RSX/GL/GLGSRender.cpp +++ b/rpcs3/Emu/RSX/GL/GLGSRender.cpp @@ -357,20 +357,22 @@ void GLGSRender::end() std::lock_guard lock(m_sampler_mutex); void* unused = nullptr; + bool update_framebuffer_sourced = false; if (surface_store_tag != m_rtts.cache_tag) { - m_samplers_dirty.store(true); + update_framebuffer_sourced = true; surface_store_tag = m_rtts.cache_tag; } for (int i = 0; i < rsx::limits::fragment_textures_count; ++i) { - if (m_samplers_dirty || m_textures_dirty[i]) - { - if (!fs_sampler_state[i]) - fs_sampler_state[i] = std::make_unique(); + if (!fs_sampler_state[i]) + fs_sampler_state[i] = std::make_unique(); + if (m_samplers_dirty || m_textures_dirty[i] || + (update_framebuffer_sourced && fs_sampler_state[i]->upload_context == rsx::texture_upload_context::framebuffer_storage)) + { auto sampler_state = static_cast(fs_sampler_state[i].get()); if (rsx::method_registers.fragment_textures[i].enabled()) @@ -394,17 +396,17 @@ void GLGSRender::end() for (int i = 0; i < rsx::limits::vertex_textures_count; ++i) { - int texture_index = i + rsx::limits::fragment_textures_count; + if (!vs_sampler_state[i]) + vs_sampler_state[i] = std::make_unique(); - if (m_samplers_dirty || m_vertex_textures_dirty[i]) + if (m_samplers_dirty || m_vertex_textures_dirty[i] || + (update_framebuffer_sourced && vs_sampler_state[i]->upload_context == rsx::texture_upload_context::framebuffer_storage)) { - if (!vs_sampler_state[i]) - vs_sampler_state[i] = std::make_unique(); - auto sampler_state = static_cast(vs_sampler_state[i].get()); if (rsx::method_registers.vertex_textures[i].enabled()) { + const int texture_index = i + rsx::limits::fragment_textures_count; glActiveTexture(GL_TEXTURE0 + texture_index); *sampler_state = m_gl_texture_cache.upload_texture(unused, rsx::method_registers.vertex_textures[i], m_rtts); diff --git a/rpcs3/Emu/RSX/VK/VKGSRender.cpp b/rpcs3/Emu/RSX/VK/VKGSRender.cpp index 354efe8af3..c2712a0181 100644 --- a/rpcs3/Emu/RSX/VK/VKGSRender.cpp +++ b/rpcs3/Emu/RSX/VK/VKGSRender.cpp @@ -1050,20 +1050,22 @@ void VKGSRender::end() //Load textures { std::lock_guard lock(m_sampler_mutex); + bool update_framebuffer_sourced = false; if (surface_store_tag != m_rtts.cache_tag) { - m_samplers_dirty.store(true); + update_framebuffer_sourced = true; surface_store_tag = m_rtts.cache_tag; } for (int i = 0; i < rsx::limits::fragment_textures_count; ++i) { - if (m_samplers_dirty || m_textures_dirty[i]) - { - if (!fs_sampler_state[i]) - fs_sampler_state[i] = std::make_unique(); + if (!fs_sampler_state[i]) + fs_sampler_state[i] = std::make_unique(); + if (m_samplers_dirty || m_textures_dirty[i] || + (update_framebuffer_sourced && fs_sampler_state[i]->upload_context == rsx::texture_upload_context::framebuffer_storage)) + { auto sampler_state = static_cast(fs_sampler_state[i].get()); if (rsx::method_registers.fragment_textures[i].enabled()) @@ -1127,13 +1129,12 @@ void VKGSRender::end() for (int i = 0; i < rsx::limits::vertex_textures_count; ++i) { - int texture_index = i + rsx::limits::fragment_textures_count; + if (!vs_sampler_state[i]) + vs_sampler_state[i] = std::make_unique(); - if (m_samplers_dirty || m_vertex_textures_dirty[i]) + if (m_samplers_dirty || m_vertex_textures_dirty[i] || + (update_framebuffer_sourced && vs_sampler_state[i]->upload_context == rsx::texture_upload_context::framebuffer_storage)) { - if (!vs_sampler_state[i]) - vs_sampler_state[i] = std::make_unique(); - auto sampler_state = static_cast(vs_sampler_state[i].get()); if (rsx::method_registers.vertex_textures[i].enabled())