From 48296c2ba6eaf91d9f20da647c86119d9531b4cb Mon Sep 17 00:00:00 2001 From: Alex Saveau Date: Fri, 12 Feb 2021 03:39:35 -0800 Subject: [PATCH] Fixup for multi-thread shader compilation (loading stage) (#9762) * Multi-thread shader compilation This offers a huge improvement in startup performance. With around 13,000 shaders we go from ~1:30 to under 10 seconds. It looks like this was the original intention of the author given the outer scope recompile variable. Signed-off-by: Alex Saveau --- rpcs3/Emu/RSX/Common/ProgramStateCache.h | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/rpcs3/Emu/RSX/Common/ProgramStateCache.h b/rpcs3/Emu/RSX/Common/ProgramStateCache.h index 0c83bdccb9..46b940e599 100644 --- a/rpcs3/Emu/RSX/Common/ProgramStateCache.h +++ b/rpcs3/Emu/RSX/Common/ProgramStateCache.h @@ -195,7 +195,9 @@ protected: std::tuple search_fragment_program(const RSXFragmentProgram& rsx_fp, bool force_load = true) { bool recompile = false; + typename binary_to_fragment_program::iterator it; fragment_program_type* new_shader; + { reader_lock lock(m_fragment_mutex); @@ -213,15 +215,14 @@ protected: rsx_log.notice("FP not found in buffer!"); lock.upgrade(); - auto [it, inserted] = m_fragment_shader_cache.try_emplace(rsx_fp); + std::tie(it, recompile) = m_fragment_shader_cache.try_emplace(rsx_fp); new_shader = &(it->second); - recompile = inserted; + } - if (inserted) - { - it->first.clone_data(); - backend_traits::recompile_fragment_program(rsx_fp, *new_shader, m_next_id++); - } + if (recompile) + { + it->first.clone_data(); + backend_traits::recompile_fragment_program(rsx_fp, *new_shader, m_next_id++); } return std::forward_as_tuple(*new_shader, false);