From 940e726754ef3474de3f43510b791203a4cfebb8 Mon Sep 17 00:00:00 2001 From: kd-11 Date: Thu, 8 Sep 2022 18:02:27 +0300 Subject: [PATCH] rsx: Minor FIFO cleanup --- rpcs3/Emu/RSX/RSXFIFO.cpp | 43 ++++++++++++++++++++++++--------------- rpcs3/Emu/RSX/RSXFIFO.h | 2 ++ 2 files changed, 29 insertions(+), 16 deletions(-) diff --git a/rpcs3/Emu/RSX/RSXFIFO.cpp b/rpcs3/Emu/RSX/RSXFIFO.cpp index 279f6e3b7c..7534f6745c 100644 --- a/rpcs3/Emu/RSX/RSXFIFO.cpp +++ b/rpcs3/Emu/RSX/RSXFIFO.cpp @@ -21,6 +21,7 @@ namespace rsx { FIFO_control::FIFO_control(::rsx::thread* pctrl) { + m_thread = pctrl; m_ctrl = pctrl->ctrl; m_iotable = &pctrl->iomap_table; } @@ -53,7 +54,7 @@ namespace rsx while (read_put() == m_internal_get && !Emu.IsStopped()) { - get_current_renderer()->cpu_wait({}); + m_thread->cpu_wait({}); } } } @@ -124,6 +125,8 @@ namespace rsx // Find the next set bit after every iteration u64 start_time = 0; + u32 bytes_read = 0; + for (int i = 0;; i = (std::countr_zero(utils::rol8(to_fetch, 0 - i - 1)) + i + 1) % 8) { // If a reservation is being updated, try to load another @@ -144,32 +147,41 @@ namespace rsx break; } + bytes_read += 128; continue; } } if (!start_time) { + if ((bytes_read << 1) >= m_cache_size) + { + // Cut our losses, we have enough to work with. + m_cache_size = bytes_read; + break; + } + start_time = rsx::uclock(); } - if (rsx::uclock() - start_time >= 50u) + auto now = rsx::uclock(); + if (now - start_time >= 50u) { - const auto rsx = get_current_renderer(); - - if (rsx->is_stopped()) + if (m_thread->is_stopped()) { return {}; } - rsx->cpu_wait({}); + m_thread->cpu_wait({}); - // Add idle time in reverse: after exchnage start_time becomes uclock(), use substruction because of the reversed order of parameters - const u64 _start = std::exchange(start_time, rsx::uclock()); - rsx->performance_counters.idle_time -= _start - start_time; + const auto then = std::exchange(now, rsx::uclock()); + start_time = now; + m_thread->performance_counters.idle_time += now - then; + } + else + { + busy_wait(200); } - - busy_wait(200); if (g_cfg.core.rsx_fifo_accuracy >= rsx_fifo_mode::atomic_ordered) { @@ -178,8 +190,7 @@ namespace rsx } } - be_t ret; - std::memcpy(&ret, reinterpret_cast(&m_cache) + (addr - m_cache_addr), sizeof(u32)); + const auto ret = utils::bless>(&m_cache)[(addr - m_cache_addr) >> 2]; return {true, ret}; } @@ -221,7 +232,7 @@ namespace rsx bool ok{}; u32 arg = 0; - if (g_cfg.core.rsx_fifo_accuracy) + if (g_cfg.core.rsx_fifo_accuracy) [[ unlikely ]] { std::tie(ok, arg) = fetch_u32(m_internal_get + 4); @@ -229,7 +240,7 @@ namespace rsx { if (arg == FIFO_ERROR) { - get_current_renderer()->recover_fifo(); + m_thread->recover_fifo(); } return false; @@ -311,7 +322,7 @@ namespace rsx m_memwatch_cmp = 0; } - if (!g_cfg.core.rsx_fifo_accuracy) + if (!g_cfg.core.rsx_fifo_accuracy) [[ likely ]] { const u32 put = read_put(); diff --git a/rpcs3/Emu/RSX/RSXFIFO.h b/rpcs3/Emu/RSX/RSXFIFO.h index 65a9d66e16..6961e71d34 100644 --- a/rpcs3/Emu/RSX/RSXFIFO.h +++ b/rpcs3/Emu/RSX/RSXFIFO.h @@ -113,6 +113,7 @@ namespace rsx class FIFO_control { private: + mutable rsx::thread* m_thread; RsxDmaControl* m_ctrl = nullptr; const rsx::rsx_iomap_table* m_iotable; u32 m_internal_get = 0; @@ -129,6 +130,7 @@ namespace rsx u32 m_cache_addr = 0; u32 m_cache_size = 0; alignas(64) std::byte m_cache[8][128]; + public: FIFO_control(rsx::thread* pctrl); ~FIFO_control() = default;