From 459a7ba5a26bfd60462f96e0683dfd4299cf98f3 Mon Sep 17 00:00:00 2001 From: kd-11 Date: Tue, 27 Jun 2017 20:46:36 +0300 Subject: [PATCH] rsx: Avoid using push_back/emplace_back on empty STL containers - Reckless management of STL containers causes significant slowdown - Also reorders vertex compare steps to fail quickly on simpler checks --- rpcs3/Emu/RSX/Common/ProgramStateCache.cpp | 7 ++++++- rpcs3/Emu/RSX/RSXThread.cpp | 5 +++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/rpcs3/Emu/RSX/Common/ProgramStateCache.cpp b/rpcs3/Emu/RSX/Common/ProgramStateCache.cpp index 2b3a0f8308..3963336099 100644 --- a/rpcs3/Emu/RSX/Common/ProgramStateCache.cpp +++ b/rpcs3/Emu/RSX/Common/ProgramStateCache.cpp @@ -26,9 +26,11 @@ bool vertex_program_compare::operator()(const RSXVertexProgram &binary1, const R { if (binary1.output_mask != binary2.output_mask) return false; + if (binary1.data.size() != binary2.data.size()) + return false; if (binary1.rsx_vertex_inputs != binary2.rsx_vertex_inputs) return false; - if (binary1.data.size() != binary2.data.size()) return false; + const qword *instBuffer1 = (const qword*)binary1.data.data(); const qword *instBuffer2 = (const qword*)binary2.data.data(); size_t instIndex = 0; @@ -40,6 +42,7 @@ bool vertex_program_compare::operator()(const RSXVertexProgram &binary1, const R return false; instIndex++; } + return true; } @@ -109,6 +112,7 @@ bool fragment_program_compare::operator()(const RSXFragmentProgram& binary1, con binary1.front_back_color_enabled != binary2.front_back_color_enabled || binary1.alpha_func != binary2.alpha_func || binary1.shadow_textures != binary2.shadow_textures || binary1.redirected_textures != binary2.redirected_textures) return false; + const qword *instBuffer1 = (const qword*)binary1.addr; const qword *instBuffer2 = (const qword*)binary2.addr; size_t instIndex = 0; @@ -119,6 +123,7 @@ bool fragment_program_compare::operator()(const RSXFragmentProgram& binary1, con if (inst1.dword[0] != inst2.dword[0] || inst1.dword[1] != inst2.dword[1]) return false; + instIndex++; // Skip constants if (fragment_program_utils::is_constant(inst1.word[1]) || diff --git a/rpcs3/Emu/RSX/RSXThread.cpp b/rpcs3/Emu/RSX/RSXThread.cpp index 4dff4e7e7f..07f83e8123 100644 --- a/rpcs3/Emu/RSX/RSXThread.cpp +++ b/rpcs3/Emu/RSX/RSXThread.cpp @@ -273,7 +273,7 @@ namespace rsx void thread::begin() { - rsx::method_registers.current_draw_clause.inline_vertex_array.clear(); + rsx::method_registers.current_draw_clause.inline_vertex_array.resize(0); in_begin_end = true; } @@ -865,6 +865,7 @@ namespace rsx RSXVertexProgram result = {}; const u32 transform_program_start = rsx::method_registers.transform_program_start(); result.data.reserve((512 - transform_program_start) * 4); + result.rsx_vertex_inputs.reserve(rsx::limits::vertex_count); for (int i = transform_program_start; i < 512; ++i) { @@ -881,7 +882,7 @@ namespace rsx const u32 input_mask = rsx::method_registers.vertex_attrib_input_mask(); const u32 modulo_mask = rsx::method_registers.frequency_divider_operation_mask(); - result.rsx_vertex_inputs.clear(); + for (u8 index = 0; index < rsx::limits::vertex_count; ++index) { bool enabled = !!(input_mask & (1 << index));