Skip to content

Commit

Permalink
rsx: Add texture readback statistics to the texture cache and debug o…
Browse files Browse the repository at this point in the history
…verlay
  • Loading branch information
kd-11 committed Feb 16, 2018
1 parent 1bd77c2 commit 661b8b0
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 0 deletions.
26 changes: 26 additions & 0 deletions rpcs3/Emu/RSX/Common/texture_cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,10 @@ namespace rsx
std::atomic<s32> m_unreleased_texture_objects = { 0 }; //Number of invalidated objects not yet freed from memory
std::atomic<u32> m_texture_memory_in_use = { 0 };

//Other statistics
std::atomic<u32> m_num_flush_requests = { 0 };
std::atomic<u32> m_num_cache_misses = { 0 };

/* Helpers */
virtual void free_texture_section(section_storage_type&) = 0;
virtual image_view_type create_temporary_subresource_view(commandbuffer_type&, image_resource_type* src, u32 gcm_format, u16 x, u16 y, u16 w, u16 h) = 0;
Expand Down Expand Up @@ -594,6 +598,8 @@ namespace rsx
//TODO: Lower severity when successful to keep the cache from overworking
record_cache_miss(*tex);
}

m_num_flush_requests++;
}
}

Expand Down Expand Up @@ -1073,6 +1079,7 @@ namespace rsx
for (auto &tex : data.sections_to_flush)
{
tex->flush(std::forward<Args>(extras)...);
m_num_flush_requests++;
}

//Restore protection on the sections to reprotect
Expand All @@ -1098,6 +1105,8 @@ namespace rsx

void record_cache_miss(section_storage_type &tex)
{
m_num_cache_misses++;

const u32 memory_address = tex.get_section_base();
const u32 memory_size = tex.get_section_size();
const auto fmt = tex.get_format();
Expand Down Expand Up @@ -2028,6 +2037,12 @@ namespace rsx
}
}

void reset_frame_statistics()
{
m_num_flush_requests.store(0u);
m_num_cache_misses.store(0u);
}

virtual const u32 get_unreleased_textures_count() const
{
return m_unreleased_texture_objects;
Expand All @@ -2038,6 +2053,17 @@ namespace rsx
return m_texture_memory_in_use;
}

virtual u32 get_num_flush_requests() const
{
return m_num_flush_requests;
}

virtual f32 get_cache_miss_ratio() const
{
const auto num_flushes = m_num_flush_requests.load();
return (num_flushes == 0u) ? 0.f : (f32)m_num_cache_misses.load() / num_flushes;
}

/**
* The read only texture invalidate flag is set if a read only texture is trampled by framebuffer memory
* If set, all cached read only textures are considered invalid and should be re-fetched from the texture cache
Expand Down
3 changes: 3 additions & 0 deletions rpcs3/Emu/RSX/GL/GLGSRender.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1373,8 +1373,11 @@ void GLGSRender::flip(int buffer)

auto num_dirty_textures = m_gl_texture_cache.get_unreleased_textures_count();
auto texture_memory_size = m_gl_texture_cache.get_texture_memory_in_use() / (1024 * 1024);
auto num_flushes = m_gl_texture_cache.get_num_flush_requests();
auto cache_miss_ratio = (u32)ceil(m_gl_texture_cache.get_cache_miss_ratio() * 100);
m_text_printer.print_text(0, 108, m_frame->client_width(), m_frame->client_height(), "Unreleased textures: " + std::to_string(num_dirty_textures));
m_text_printer.print_text(0, 126, m_frame->client_width(), m_frame->client_height(), "Texture memory: " + std::to_string(texture_memory_size) + "M");
m_text_printer.print_text(0, 144, m_frame->client_width(), m_frame->client_height(), "Flush requests: " + std::to_string(num_flushes) + " (" + std::to_string(cache_miss_ratio) + "% hard faults)");
}

m_frame->flip(m_context);
Expand Down
1 change: 1 addition & 0 deletions rpcs3/Emu/RSX/GL/GLTextureCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -988,6 +988,7 @@ namespace gl

clear_temporary_subresources();
m_temporary_subresource_cache.clear();
reset_frame_statistics();
}

bool blit(rsx::blit_src_info& src, rsx::blit_dst_info& dst, bool linear_interpolate, gl_render_targets& m_rtts)
Expand Down
3 changes: 3 additions & 0 deletions rpcs3/Emu/RSX/VK/VKGSRender.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3144,9 +3144,12 @@ void VKGSRender::flip(int buffer)
auto num_dirty_textures = m_texture_cache.get_unreleased_textures_count();
auto texture_memory_size = m_texture_cache.get_texture_memory_in_use() / (1024 * 1024);
auto tmp_texture_memory_size = m_texture_cache.get_temporary_memory_in_use() / (1024 * 1024);
auto num_flushes = m_texture_cache.get_num_flush_requests();
auto cache_miss_ratio = (u32)ceil(m_texture_cache.get_cache_miss_ratio() * 100);
m_text_writer->print_text(*m_current_command_buffer, *direct_fbo, 0, 126, direct_fbo->width(), direct_fbo->height(), "Unreleased textures: " + std::to_string(num_dirty_textures));
m_text_writer->print_text(*m_current_command_buffer, *direct_fbo, 0, 144, direct_fbo->width(), direct_fbo->height(), "Texture cache memory: " + std::to_string(texture_memory_size) + "M");
m_text_writer->print_text(*m_current_command_buffer, *direct_fbo, 0, 162, direct_fbo->width(), direct_fbo->height(), "Temporary texture memory: " + std::to_string(tmp_texture_memory_size) + "M");
m_text_writer->print_text(*m_current_command_buffer, *direct_fbo, 0, 180, direct_fbo->width(), direct_fbo->height(), "Flush requests: " + std::to_string(num_flushes) + " (" + std::to_string(cache_miss_ratio) + "% hard faults)");
}

vk::change_image_layout(*m_current_command_buffer, target_image, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, VK_IMAGE_LAYOUT_PRESENT_SRC_KHR, subres);
Expand Down
1 change: 1 addition & 0 deletions rpcs3/Emu/RSX/VK/VKTextureCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -987,6 +987,7 @@ namespace vk
});

m_temporary_subresource_cache.clear();
reset_frame_statistics();
}

template<typename RsxTextureType>
Expand Down

0 comments on commit 661b8b0

Please sign in to comment.