rsx: Minor FIFO cleanup

This commit is contained in:
kd-11 2022-09-08 18:02:27 +03:00 committed by kd-11
commit 940e726754
2 changed files with 29 additions and 16 deletions

View file

@ -21,6 +21,7 @@ namespace rsx
{ {
FIFO_control::FIFO_control(::rsx::thread* pctrl) FIFO_control::FIFO_control(::rsx::thread* pctrl)
{ {
m_thread = pctrl;
m_ctrl = pctrl->ctrl; m_ctrl = pctrl->ctrl;
m_iotable = &pctrl->iomap_table; m_iotable = &pctrl->iomap_table;
} }
@ -53,7 +54,7 @@ namespace rsx
while (read_put() == m_internal_get && !Emu.IsStopped()) 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 // Find the next set bit after every iteration
u64 start_time = 0; u64 start_time = 0;
u32 bytes_read = 0;
for (int i = 0;; i = (std::countr_zero<u32>(utils::rol8(to_fetch, 0 - i - 1)) + i + 1) % 8) for (int i = 0;; i = (std::countr_zero<u32>(utils::rol8(to_fetch, 0 - i - 1)) + i + 1) % 8)
{ {
// If a reservation is being updated, try to load another // If a reservation is being updated, try to load another
@ -144,32 +147,41 @@ namespace rsx
break; break;
} }
bytes_read += 128;
continue; continue;
} }
} }
if (!start_time) 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(); 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 (m_thread->is_stopped())
if (rsx->is_stopped())
{ {
return {}; 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 auto then = std::exchange(now, rsx::uclock());
const u64 _start = std::exchange(start_time, rsx::uclock()); start_time = now;
rsx->performance_counters.idle_time -= _start - start_time; 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) if (g_cfg.core.rsx_fifo_accuracy >= rsx_fifo_mode::atomic_ordered)
{ {
@ -178,8 +190,7 @@ namespace rsx
} }
} }
be_t<u32> ret; const auto ret = utils::bless<const be_t<u32>>(&m_cache)[(addr - m_cache_addr) >> 2];
std::memcpy(&ret, reinterpret_cast<const u8*>(&m_cache) + (addr - m_cache_addr), sizeof(u32));
return {true, ret}; return {true, ret};
} }
@ -221,7 +232,7 @@ namespace rsx
bool ok{}; bool ok{};
u32 arg = 0; 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); std::tie(ok, arg) = fetch_u32(m_internal_get + 4);
@ -229,7 +240,7 @@ namespace rsx
{ {
if (arg == FIFO_ERROR) if (arg == FIFO_ERROR)
{ {
get_current_renderer()->recover_fifo(); m_thread->recover_fifo();
} }
return false; return false;
@ -311,7 +322,7 @@ namespace rsx
m_memwatch_cmp = 0; m_memwatch_cmp = 0;
} }
if (!g_cfg.core.rsx_fifo_accuracy) if (!g_cfg.core.rsx_fifo_accuracy) [[ likely ]]
{ {
const u32 put = read_put(); const u32 put = read_put();

View file

@ -113,6 +113,7 @@ namespace rsx
class FIFO_control class FIFO_control
{ {
private: private:
mutable rsx::thread* m_thread;
RsxDmaControl* m_ctrl = nullptr; RsxDmaControl* m_ctrl = nullptr;
const rsx::rsx_iomap_table* m_iotable; const rsx::rsx_iomap_table* m_iotable;
u32 m_internal_get = 0; u32 m_internal_get = 0;
@ -129,6 +130,7 @@ namespace rsx
u32 m_cache_addr = 0; u32 m_cache_addr = 0;
u32 m_cache_size = 0; u32 m_cache_size = 0;
alignas(64) std::byte m_cache[8][128]; alignas(64) std::byte m_cache[8][128];
public: public:
FIFO_control(rsx::thread* pctrl); FIFO_control(rsx::thread* pctrl);
~FIFO_control() = default; ~FIFO_control() = default;