FifoPlayer: Move instance to System.

This commit is contained in:
Admiral H. Curtiss 2024-01-05 09:31:59 +01:00
parent 2f7f7afe6d
commit fc2ec826d4
No known key found for this signature in database
GPG Key ID: F051B4C4044F33FB
13 changed files with 76 additions and 56 deletions

View File

@ -652,7 +652,7 @@ bool CBoot::BootUp(Core::System& system, const Core::CPUThreadGuard& guard,
bool operator()(const BootParameters::DFF& dff) const
{
NOTICE_LOG_FMT(BOOT, "Booting DFF: {}", dff.dff_path);
return FifoPlayer::GetInstance().Open(dff.dff_path);
return system.GetFifoPlayer().Open(dff.dff_path);
}
private:

View File

@ -466,7 +466,7 @@ static void FifoPlayerThread(Core::System& system, const std::optional<std::stri
Common::SetCurrentThreadName("FIFO-GPU thread");
// Enter CPU run loop. When we leave it - we are done.
if (auto cpu_core = FifoPlayer::GetInstance().GetCPUCore())
if (auto cpu_core = system.GetFifoPlayer().GetCPUCore())
{
system.GetPowerPC().InjectExternalCPUCore(cpu_core.get());
s_is_started = true;
@ -476,13 +476,13 @@ static void FifoPlayerThread(Core::System& system, const std::optional<std::stri
s_is_started = false;
system.GetPowerPC().InjectExternalCPUCore(nullptr);
FifoPlayer::GetInstance().Close();
system.GetFifoPlayer().Close();
}
else
{
// FIFO log does not contain any frames, cannot continue.
PanicAlertFmt("FIFO file is invalid, cannot playback.");
FifoPlayer::GetInstance().Close();
system.GetFifoPlayer().Close();
return;
}
}

View File

@ -172,7 +172,7 @@ void FifoPlaybackAnalyzer::OnCommand(const u8* data, u32 size)
bool IsPlayingBackFifologWithBrokenEFBCopies = false;
FifoPlayer::FifoPlayer()
FifoPlayer::FifoPlayer(Core::System& system) : m_system(system)
{
m_config_changed_callback_id = Config::AddConfigChangedCallback([this] { RefreshConfig(); });
RefreshConfig();
@ -401,12 +401,6 @@ void FifoPlayer::SetFrameRangeEnd(u32 end)
}
}
FifoPlayer& FifoPlayer::GetInstance()
{
static FifoPlayer instance;
return instance;
}
void FifoPlayer::WriteFrame(const FifoFrameInfo& frame, const AnalyzedFrameInfo& info)
{
// Core timing information
@ -821,14 +815,14 @@ bool FifoPlayer::ShouldLoadXF(u8 reg)
(address >= XFMEM_UNKNOWN_GROUP_3_START && address <= XFMEM_UNKNOWN_GROUP_3_END));
}
bool FifoPlayer::IsIdleSet()
bool FifoPlayer::IsIdleSet() const
{
CommandProcessor::UCPStatusReg status =
Core::System::GetInstance().GetMMU().Read_U16(0xCC000000 | CommandProcessor::STATUS_REGISTER);
return status.CommandIdle;
}
bool FifoPlayer::IsHighWatermarkSet()
bool FifoPlayer::IsHighWatermarkSet() const
{
CommandProcessor::UCPStatusReg status =
Core::System::GetInstance().GetMMU().Read_U16(0xCC000000 | CommandProcessor::STATUS_REGISTER);

View File

@ -19,6 +19,10 @@
class FifoDataFile;
struct MemoryUpdate;
namespace Core
{
class System;
}
namespace CPU
{
enum class State;
@ -91,6 +95,11 @@ class FifoPlayer
public:
using CallbackFunc = std::function<void()>;
explicit FifoPlayer(Core::System& system);
FifoPlayer(const FifoPlayer&) = delete;
FifoPlayer(FifoPlayer&&) = delete;
FifoPlayer& operator=(const FifoPlayer&) = delete;
FifoPlayer& operator=(FifoPlayer&&) = delete;
~FifoPlayer();
bool Open(const std::string& filename);
@ -127,13 +136,11 @@ public:
// Callbacks
void SetFileLoadedCallback(CallbackFunc callback);
void SetFrameWrittenCallback(CallbackFunc callback) { m_FrameWrittenCb = std::move(callback); }
static FifoPlayer& GetInstance();
bool IsRunningWithFakeVideoInterfaceUpdates() const;
private:
class CPUCore;
FifoPlayer();
CPU::State AdvanceFrame();
@ -168,11 +175,13 @@ private:
bool ShouldLoadBP(u8 address);
bool ShouldLoadXF(u8 address);
static bool IsIdleSet();
static bool IsHighWatermarkSet();
bool IsIdleSet() const;
bool IsHighWatermarkSet() const;
void RefreshConfig();
Core::System& m_system;
bool m_Loop = true;
// If enabled then all memory updates happen at once before the first frame
bool m_EarlyMemoryUpdates = false;

View File

@ -545,7 +545,7 @@ float VideoInterfaceManager::GetAspectRatio() const
// 5. Calculate the final ratio and scale to 4:3
float ratio = horizontal_active_ratio / vertical_active_ratio;
bool running_fifo_log = FifoPlayer::GetInstance().IsRunningWithFakeVideoInterfaceUpdates();
const bool running_fifo_log = m_system.GetFifoPlayer().IsRunningWithFakeVideoInterfaceUpdates();
if (std::isnormal(ratio) && // Check we have a sane ratio without any infs/nans/zeros
!running_fifo_log) // we don't know the correct ratio for fifos
return ratio * (4.0f / 3.0f); // Scale to 4:3

View File

@ -8,6 +8,7 @@
#include "AudioCommon/SoundStream.h"
#include "Core/Config/MainSettings.h"
#include "Core/CoreTiming.h"
#include "Core/FifoPlayer/FifoPlayer.h"
#include "Core/HW/AudioInterface.h"
#include "Core/HW/CPU.h"
#include "Core/HW/DSP.h"
@ -48,7 +49,8 @@ struct System::Impl
m_memory(system), m_pixel_engine{system}, m_power_pc(system),
m_mmu(system, m_memory, m_power_pc), m_processor_interface(system),
m_serial_interface(system), m_system_timers(system), m_video_interface(system),
m_interpreter(system, m_power_pc.GetPPCState(), m_mmu), m_jit_interface(system)
m_interpreter(system, m_power_pc.GetPPCState(), m_mmu), m_jit_interface(system),
m_fifo_player(system)
{
}
@ -86,6 +88,7 @@ struct System::Impl
Interpreter m_interpreter;
JitInterface m_jit_interface;
VideoCommon::CustomAssetLoader m_custom_asset_loader;
FifoPlayer m_fifo_player;
};
System::System() : m_impl{std::make_unique<Impl>(*this)}
@ -176,6 +179,11 @@ Fifo::FifoManager& System::GetFifo() const
return m_impl->m_fifo;
}
FifoPlayer& System::GetFifoPlayer() const
{
return m_impl->m_fifo_player;
}
GeometryShaderManager& System::GetGeometryShaderManager() const
{
return m_impl->m_geometry_shader_manager;

View File

@ -47,6 +47,7 @@ namespace Fifo
{
class FifoManager;
}
class FifoPlayer;
namespace GPFifo
{
class GPFifoManager;
@ -142,6 +143,7 @@ public:
DVD::DVDThread& GetDVDThread() const;
ExpansionInterface::ExpansionInterfaceManager& GetExpansionInterface() const;
Fifo::FifoManager& GetFifo() const;
FifoPlayer& GetFifoPlayer() const;
GeometryShaderManager& GetGeometryShaderManager() const;
GPFifo::GPFifoManager& GetGPFifo() const;
HSP::HSPManager& GetHSP() const;

View File

@ -37,7 +37,7 @@ constexpr int PART_START_ROLE = Qt::UserRole + 1;
// Values range from 1 to number of parts
constexpr int PART_END_ROLE = Qt::UserRole + 2;
FIFOAnalyzer::FIFOAnalyzer()
FIFOAnalyzer::FIFOAnalyzer(FifoPlayer& fifo_player) : m_fifo_player(fifo_player)
{
CreateWidgets();
ConnectWidgets();
@ -138,7 +138,7 @@ void FIFOAnalyzer::UpdateTree()
{
m_tree_widget->clear();
if (!FifoPlayer::GetInstance().IsPlaying())
if (!m_fifo_player.IsPlaying())
{
m_tree_widget->addTopLevelItem(new QTreeWidgetItem({tr("No recording loaded.")}));
return;
@ -148,7 +148,7 @@ void FIFOAnalyzer::UpdateTree()
m_tree_widget->addTopLevelItem(recording_item);
auto* file = FifoPlayer::GetInstance().GetFile();
auto* file = m_fifo_player.GetFile();
const u32 frame_count = file->GetFrameCount();
@ -158,7 +158,7 @@ void FIFOAnalyzer::UpdateTree()
recording_item->addChild(frame_item);
const AnalyzedFrameInfo& frame_info = FifoPlayer::GetInstance().GetAnalyzedFrameInfo(frame);
const AnalyzedFrameInfo& frame_info = m_fifo_player.GetAnalyzedFrameInfo(frame);
ASSERT(frame_info.parts.size() != 0);
Common::EnumMap<u32, FramePartType::EFBCopy> part_counts;
@ -339,7 +339,7 @@ void FIFOAnalyzer::UpdateDetails()
m_search_previous->setEnabled(false);
m_search_label->clear();
if (!FifoPlayer::GetInstance().IsPlaying())
if (!m_fifo_player.IsPlaying())
return;
const auto items = m_tree_widget->selectedItems();
@ -351,8 +351,8 @@ void FIFOAnalyzer::UpdateDetails()
const u32 start_part_nr = items[0]->data(0, PART_START_ROLE).toUInt();
const u32 end_part_nr = items[0]->data(0, PART_END_ROLE).toUInt();
const AnalyzedFrameInfo& frame_info = FifoPlayer::GetInstance().GetAnalyzedFrameInfo(frame_nr);
const auto& fifo_frame = FifoPlayer::GetInstance().GetFile()->GetFrame(frame_nr);
const AnalyzedFrameInfo& frame_info = m_fifo_player.GetAnalyzedFrameInfo(frame_nr);
const auto& fifo_frame = m_fifo_player.GetFile()->GetFrame(frame_nr);
const u32 object_start = frame_info.parts[start_part_nr].m_start;
const u32 object_end = frame_info.parts[end_part_nr].m_end;
@ -386,7 +386,7 @@ void FIFOAnalyzer::BeginSearch()
{
const QString search_str = m_search_edit->text();
if (!FifoPlayer::GetInstance().IsPlaying())
if (!m_fifo_player.IsPlaying())
return;
const auto items = m_tree_widget->selectedItems();
@ -434,8 +434,8 @@ void FIFOAnalyzer::BeginSearch()
const u32 start_part_nr = items[0]->data(0, PART_START_ROLE).toUInt();
const u32 end_part_nr = items[0]->data(0, PART_END_ROLE).toUInt();
const AnalyzedFrameInfo& frame_info = FifoPlayer::GetInstance().GetAnalyzedFrameInfo(frame_nr);
const FifoFrameInfo& fifo_frame = FifoPlayer::GetInstance().GetFile()->GetFrame(frame_nr);
const AnalyzedFrameInfo& frame_info = m_fifo_player.GetAnalyzedFrameInfo(frame_nr);
const FifoFrameInfo& fifo_frame = m_fifo_player.GetFile()->GetFrame(frame_nr);
const u32 object_start = frame_info.parts[start_part_nr].m_start;
const u32 object_end = frame_info.parts[end_part_nr].m_end;
@ -750,7 +750,7 @@ void FIFOAnalyzer::UpdateDescription()
{
m_entry_detail_browser->clear();
if (!FifoPlayer::GetInstance().IsPlaying())
if (!m_fifo_player.IsPlaying())
return;
const auto items = m_tree_widget->selectedItems();
@ -766,8 +766,8 @@ void FIFOAnalyzer::UpdateDescription()
const u32 end_part_nr = items[0]->data(0, PART_END_ROLE).toUInt();
const u32 entry_nr = m_detail_list->currentRow();
const AnalyzedFrameInfo& frame_info = FifoPlayer::GetInstance().GetAnalyzedFrameInfo(frame_nr);
const FifoFrameInfo& fifo_frame = FifoPlayer::GetInstance().GetFile()->GetFrame(frame_nr);
const AnalyzedFrameInfo& frame_info = m_fifo_player.GetAnalyzedFrameInfo(frame_nr);
const FifoFrameInfo& fifo_frame = m_fifo_player.GetFile()->GetFrame(frame_nr);
const u32 object_start = frame_info.parts[start_part_nr].m_start;
const u32 object_end = frame_info.parts[end_part_nr].m_end;

View File

@ -9,6 +9,7 @@
#include "Common/CommonTypes.h"
class FifoPlayer;
class QGroupBox;
class QLabel;
class QLineEdit;
@ -23,7 +24,7 @@ class FIFOAnalyzer final : public QWidget
Q_OBJECT
public:
explicit FIFOAnalyzer();
explicit FIFOAnalyzer(FifoPlayer& fifo_player);
~FIFOAnalyzer();
void Update();
@ -42,6 +43,8 @@ private:
void UpdateDetails();
void UpdateDescription();
FifoPlayer& m_fifo_player;
QTreeWidget* m_tree_widget;
QListWidget* m_detail_list;
QTextBrowser* m_entry_detail_browser;

View File

@ -32,7 +32,8 @@
#include "DolphinQt/Resources.h"
#include "DolphinQt/Settings.h"
FIFOPlayerWindow::FIFOPlayerWindow(QWidget* parent) : QWidget(parent)
FIFOPlayerWindow::FIFOPlayerWindow(FifoPlayer& fifo_player, QWidget* parent)
: QWidget(parent), m_fifo_player(fifo_player)
{
setWindowTitle(tr("FIFO Player"));
setWindowIcon(Resources::GetAppIcon());
@ -46,9 +47,9 @@ FIFOPlayerWindow::FIFOPlayerWindow(QWidget* parent) : QWidget(parent)
UpdateControls();
FifoPlayer::GetInstance().SetFileLoadedCallback(
m_fifo_player.SetFileLoadedCallback(
[this] { QueueOnObject(this, &FIFOPlayerWindow::OnFIFOLoaded); });
FifoPlayer::GetInstance().SetFrameWrittenCallback([this] {
m_fifo_player.SetFrameWrittenCallback([this] {
QueueOnObject(this, [this] {
UpdateInfo();
UpdateControls();
@ -68,8 +69,8 @@ FIFOPlayerWindow::FIFOPlayerWindow(QWidget* parent) : QWidget(parent)
FIFOPlayerWindow::~FIFOPlayerWindow()
{
FifoPlayer::GetInstance().SetFileLoadedCallback({});
FifoPlayer::GetInstance().SetFrameWrittenCallback({});
m_fifo_player.SetFileLoadedCallback({});
m_fifo_player.SetFrameWrittenCallback({});
}
void FIFOPlayerWindow::CreateWidgets()
@ -160,7 +161,7 @@ void FIFOPlayerWindow::CreateWidgets()
m_tab_widget = new QTabWidget(this);
m_analyzer = new FIFOAnalyzer;
m_analyzer = new FIFOAnalyzer(m_fifo_player);
m_tab_widget->addTab(m_main_widget, tr("Play / Record"));
m_tab_widget->addTab(m_analyzer, tr("Analyze"));
@ -262,7 +263,7 @@ void FIFOPlayerWindow::OnEmulationStarted()
{
UpdateControls();
if (FifoPlayer::GetInstance().GetFile())
if (m_fifo_player.GetFile())
OnFIFOLoaded();
}
@ -286,14 +287,13 @@ void FIFOPlayerWindow::OnRecordingDone()
void FIFOPlayerWindow::UpdateInfo()
{
if (FifoPlayer::GetInstance().IsPlaying())
if (m_fifo_player.IsPlaying())
{
FifoDataFile* file = FifoPlayer::GetInstance().GetFile();
m_info_label->setText(
tr("%1 frame(s)\n%2 object(s)\nCurrent Frame: %3")
.arg(QString::number(file->GetFrameCount()),
QString::number(FifoPlayer::GetInstance().GetCurrentFrameObjectCount()),
QString::number(FifoPlayer::GetInstance().GetCurrentFrameNum())));
FifoDataFile* file = m_fifo_player.GetFile();
m_info_label->setText(tr("%1 frame(s)\n%2 object(s)\nCurrent Frame: %3")
.arg(QString::number(file->GetFrameCount()),
QString::number(m_fifo_player.GetCurrentFrameObjectCount()),
QString::number(m_fifo_player.GetCurrentFrameNum())));
return;
}
@ -327,9 +327,9 @@ void FIFOPlayerWindow::UpdateInfo()
void FIFOPlayerWindow::OnFIFOLoaded()
{
FifoDataFile* file = FifoPlayer::GetInstance().GetFile();
FifoDataFile* file = m_fifo_player.GetFile();
auto object_count = FifoPlayer::GetInstance().GetMaxObjectCount();
auto object_count = m_fifo_player.GetMaxObjectCount();
auto frame_count = file->GetFrameCount();
m_frame_range_to->setMaximum(frame_count - 1);
@ -356,7 +356,7 @@ void FIFOPlayerWindow::OnConfigChanged()
void FIFOPlayerWindow::OnLimitsChanged()
{
FifoPlayer& player = FifoPlayer::GetInstance();
FifoPlayer& player = m_fifo_player;
player.SetFrameRangeStart(m_frame_range_from->value());
player.SetFrameRangeEnd(m_frame_range_to->value());
@ -377,7 +377,7 @@ void FIFOPlayerWindow::UpdateControls()
{
bool running = Core::IsRunning();
bool is_recording = FifoRecorder::GetInstance().IsRecording();
bool is_playing = FifoPlayer::GetInstance().IsPlaying();
bool is_playing = m_fifo_player.IsPlaying();
m_frame_range_from->setEnabled(is_playing);
m_frame_range_from_label->setEnabled(is_playing);

View File

@ -13,13 +13,14 @@ class QPushButton;
class QSpinBox;
class QTabWidget;
class ToolTipCheckBox;
class FifoPlayer;
class FIFOAnalyzer;
class FIFOPlayerWindow : public QWidget
{
Q_OBJECT
public:
explicit FIFOPlayerWindow(QWidget* parent = nullptr);
explicit FIFOPlayerWindow(FifoPlayer& fifo_player, QWidget* parent = nullptr);
~FIFOPlayerWindow();
signals:
@ -49,6 +50,8 @@ private:
bool eventFilter(QObject* object, QEvent* event) final override;
FifoPlayer& m_fifo_player;
QLabel* m_info_label;
QPushButton* m_load;
QPushButton* m_save;

View File

@ -1363,7 +1363,7 @@ void MainWindow::ShowFIFOPlayer()
{
if (!m_fifo_window)
{
m_fifo_window = new FIFOPlayerWindow;
m_fifo_window = new FIFOPlayerWindow(Core::System::GetInstance().GetFifoPlayer());
connect(m_fifo_window, &FIFOPlayerWindow::LoadFIFORequested, this,
[this](const QString& path) { StartGame(path, ScanForSecondDisc::No); });
}

View File

@ -355,17 +355,18 @@ static void BPWritten(PixelShaderManager& pixel_shader_manager, XFStateManager&
// Might also clean up some issues with games doing XFB copies they don't intend to
// display.
auto& system = Core::System::GetInstance();
if (g_ActiveConfig.bImmediateXFB)
{
// below div two to convert from bytes to pixels - it expects width, not stride
u64 ticks = Core::System::GetInstance().GetCoreTiming().GetTicks();
u64 ticks = system.GetCoreTiming().GetTicks();
g_presenter->ImmediateSwap(destAddr, destStride / 2, destStride, height, ticks);
}
else
{
if (FifoPlayer::GetInstance().IsRunningWithFakeVideoInterfaceUpdates())
if (system.GetFifoPlayer().IsRunningWithFakeVideoInterfaceUpdates())
{
auto& vi = Core::System::GetInstance().GetVideoInterface();
auto& vi = system.GetVideoInterface();
vi.FakeVIUpdate(destAddr, srcRect.GetWidth(), destStride, height);
}
}