Skip to content

Commit

Permalink
VMManager: Refactor and improve boot process
Browse files Browse the repository at this point in the history
[SAVEVERSION+] VM struct changes.

 - Serial/title is now linked to disc, instead of running ELF.
 - Save states can be created during BIOS boot.
 - Patches now apply based on the executing CRC, and only after the
   entry point starts executing (fixes multi-game discs).
 - Add "Fast Forward Boot" option.
 - Split achievements download and activation, downloads occur on
   initialization, but are not activated until after the ELF loads.
 - Prevent HostFS access while in PS1 mode.
 - Remove multiple sources of truth for ELF/CRC/etc.
 - Move ELF state from global scope to VMManager.
 - Prevent game fixes and hw fixes being active while booting game.
 - Simplify game update.
 - Flush recompilers after ELF loads. No point keeping boot code around
   which gets overwritten.
  • Loading branch information
stenzek committed Jun 17, 2023
1 parent 0cf4cb6 commit 36c2718
Show file tree
Hide file tree
Showing 50 changed files with 1,174 additions and 963 deletions.
4 changes: 2 additions & 2 deletions pcsx2-gsrunner/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -293,8 +293,8 @@ void Host::OnVMResumed()
{
}

void Host::OnGameChanged(const std::string& disc_path, const std::string& elf_override, const std::string& game_serial,
const std::string& game_name, u32 game_crc)
void Host::OnGameChanged(const std::string& title, const std::string& elf_override, const std::string& disc_path,
const std::string& disc_serial, u32 disc_crc, u32 current_crc)
{
}

Expand Down
48 changes: 28 additions & 20 deletions pcsx2-qt/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -746,9 +746,9 @@ void MainWindow::updateWindowTitle()
{
QString suffix(QtHost::GetAppConfigSuffix());
QString main_title(QtHost::GetAppNameAndVersion() + suffix);
QString display_title(m_current_game_name + suffix);
QString display_title(m_current_title + suffix);

if (!s_vm_valid || m_current_game_name.isEmpty())
if (!s_vm_valid || m_current_title.isEmpty())
display_title = main_title;
else if (isRenderingToMain())
main_title = display_title;
Expand Down Expand Up @@ -920,7 +920,7 @@ bool MainWindow::requestShutdown(bool allow_confirm, bool allow_save_to_state, b
return true;

// If we don't have a crc, we can't save state.
allow_save_to_state &= (m_current_game_crc != 0);
allow_save_to_state &= (m_current_disc_crc != 0);
bool save_state = allow_save_to_state && default_save_to_state;

// Only confirm on UI thread because we need to display a msgbox.
Expand Down Expand Up @@ -1213,15 +1213,15 @@ void MainWindow::onChangeDiscMenuAboutToHide()
void MainWindow::onLoadStateMenuAboutToShow()
{
m_ui.menuLoadState->clear();
updateSaveStateMenusEnableState(!m_current_game_serial.isEmpty());
populateLoadStateMenu(m_ui.menuLoadState, m_current_disc_path, m_current_game_serial, m_current_game_crc);
updateSaveStateMenusEnableState(!m_current_disc_serial.isEmpty());
populateLoadStateMenu(m_ui.menuLoadState, m_current_disc_path, m_current_disc_serial, m_current_disc_crc);
}

void MainWindow::onSaveStateMenuAboutToShow()
{
m_ui.menuSaveState->clear();
updateSaveStateMenusEnableState(!m_current_game_serial.isEmpty());
populateSaveStateMenu(m_ui.menuSaveState, m_current_game_serial, m_current_game_crc);
updateSaveStateMenusEnableState(!m_current_disc_serial.isEmpty());
populateSaveStateMenu(m_ui.menuSaveState, m_current_disc_serial, m_current_disc_crc);
}

void MainWindow::onViewToolbarActionToggled(bool checked)
Expand Down Expand Up @@ -1269,23 +1269,29 @@ void MainWindow::onViewGamePropertiesActionTriggered()
return;

// prefer to use a game list entry, if we have one, that way the summary is populated
if (!m_current_disc_path.isEmpty() || !m_current_elf_override.isEmpty())
if (!m_current_disc_path.isEmpty() && m_current_elf_override.isEmpty())
{
auto lock = GameList::GetLock();
const GameList::Entry* entry = m_current_elf_override.isEmpty() ?
GameList::GetEntryForPath(m_current_disc_path.toUtf8().constData()) :
GameList::GetEntryForPath(m_current_elf_override.toUtf8().constData());
const GameList::Entry* entry = GameList::GetEntryForPath(m_current_disc_path.toUtf8().constData());
if (entry)
{
SettingsDialog::openGamePropertiesDialog(
entry, m_current_elf_override.isEmpty() ? std::string_view(entry->serial) : std::string_view(), entry->crc);
SettingsDialog::openGamePropertiesDialog(entry, entry->serial, entry->crc);
return;
}
}

// open properties for the current running file (isn't in the game list)
if (m_current_game_crc != 0)
SettingsDialog::openGamePropertiesDialog(nullptr, m_current_game_serial.toStdString(), m_current_game_crc);
if (m_current_disc_crc == 0)
{
QMessageBox::critical(this, tr("Game Properties"), tr("Game properties is unavailable for the current game."));
return;
}

// can't use serial for ELFs, because they might have a disc set
if (m_current_elf_override.isEmpty())
SettingsDialog::openGamePropertiesDialog(nullptr, m_current_disc_serial.toStdString(), m_current_disc_crc);
else
SettingsDialog::openGamePropertiesDialog(nullptr, std::string_view(), m_current_disc_crc);
}

void MainWindow::onGitHubRepositoryActionTriggered()
Expand Down Expand Up @@ -1602,13 +1608,15 @@ void MainWindow::onVMStopped()
m_game_list_widget->refresh(false);
}

void MainWindow::onGameChanged(const QString& path, const QString& elf_override, const QString& serial, const QString& name, quint32 crc)
void MainWindow::onGameChanged(const QString& title, const QString& elf_override, const QString& disc_path,
const QString& serial, quint32 disc_crc, quint32 crc)
{
m_current_disc_path = path;
m_current_title = title;
m_current_elf_override = elf_override;
m_current_game_serial = serial;
m_current_game_name = name;
m_current_game_crc = crc;
m_current_disc_path = disc_path;
m_current_disc_serial = serial;
m_current_disc_crc = disc_crc;
m_current_running_crc = crc;
updateWindowTitle();
updateSaveStateMenusEnableState(!serial.isEmpty());
}
Expand Down
12 changes: 7 additions & 5 deletions pcsx2-qt/MainWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,8 @@ private Q_SLOTS:
void onVMResumed();
void onVMStopped();

void onGameChanged(const QString& path, const QString& elf_override, const QString& serial, const QString& name, quint32 crc);
void onGameChanged(const QString& title, const QString& elf_override, const QString& disc_path,
const QString& serial, quint32 disc_crc, quint32 crc);

protected:
void showEvent(QShowEvent* event) override;
Expand Down Expand Up @@ -279,11 +280,12 @@ private Q_SLOTS:

QMenu* m_settings_toolbar_menu = nullptr;

QString m_current_disc_path;
QString m_current_title;
QString m_current_elf_override;
QString m_current_game_serial;
QString m_current_game_name;
quint32 m_current_game_crc;
QString m_current_disc_path;
QString m_current_disc_serial;
quint32 m_current_disc_crc;
quint32 m_current_running_crc;

bool m_display_created = false;
bool m_relative_mouse_mode = false;
Expand Down
19 changes: 6 additions & 13 deletions pcsx2-qt/QtHost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -667,14 +667,7 @@ void EmuThread::reloadPatches()
return;
}

if (!VMManager::HasValidVM())
return;

Patch::ReloadPatches(true, false, true, true);

// Might change widescreen mode.
if (Patch::ReloadPatchAffectingOptions())
applySettings();
VMManager::ReloadPatches(true, false, true, true);
}

void EmuThread::reloadInputSources()
Expand Down Expand Up @@ -968,11 +961,11 @@ void Host::OnVMResumed()
emit g_emu_thread->onVMResumed();
}

void Host::OnGameChanged(const std::string& disc_path, const std::string& elf_override, const std::string& game_serial,
const std::string& game_name, u32 game_crc)
void Host::OnGameChanged(const std::string& title, const std::string& elf_override, const std::string& disc_path,
const std::string& disc_serial, u32 disc_crc, u32 current_crc)
{
emit g_emu_thread->onGameChanged(QString::fromStdString(disc_path), QString::fromStdString(elf_override),
QString::fromStdString(game_serial), QString::fromStdString(game_name), game_crc);
emit g_emu_thread->onGameChanged(QString::fromStdString(title), QString::fromStdString(elf_override),
QString::fromStdString(disc_path), QString::fromStdString(disc_serial), disc_crc, current_crc);
}

void EmuThread::updatePerformanceMetrics(bool force)
Expand Down Expand Up @@ -1124,7 +1117,7 @@ void Host::VSyncOnCPUThread()

void Host::RunOnCPUThread(std::function<void()> function, bool block /* = false */)
{
if (g_emu_thread->isOnEmuThread())
if (block && g_emu_thread->isOnEmuThread())
{
// probably shouldn't ever happen, but just in case..
function();
Expand Down
3 changes: 2 additions & 1 deletion pcsx2-qt/QtHost.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,8 @@ public Q_SLOTS:
void onVMStopped();

/// Provided by the host; called when the running executable changes.
void onGameChanged(const QString& path, const QString& elf_override, const QString& serial, const QString& name, quint32 crc);
void onGameChanged(const QString& title, const QString& elf_override, const QString& disc_path,
const QString& serial, quint32 disc_crc, quint32 crc);

void onInputDevicesEnumerated(const QList<QPair<QString, QString>>& devices);
void onInputDeviceConnected(const QString& identifier, const QString& device_name);
Expand Down
12 changes: 12 additions & 0 deletions pcsx2-qt/Settings/BIOSSettingsWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,29 @@

BIOSSettingsWidget::BIOSSettingsWidget(SettingsDialog* dialog, QWidget* parent)
: QWidget(parent)
, m_dialog(dialog)
{
SettingsInterface* sif = dialog->getSettingsInterface();

m_ui.setupUi(this);

SettingWidgetBinder::BindWidgetToBoolSetting(sif, m_ui.fastBoot, "EmuCore", "EnableFastBoot", true);
SettingWidgetBinder::BindWidgetToBoolSetting(sif, m_ui.fastBootFastForward, "EmuCore", "EnableFastBootFastForward", false);
SettingWidgetBinder::BindWidgetToFolderSetting(sif, m_ui.searchDirectory, m_ui.browseSearchDirectory, m_ui.openSearchDirectory,
m_ui.resetSearchDirectory, "Folders", "Bios", Path::Combine(EmuFolders::DataRoot, "bios"));

dialog->registerWidgetHelp(m_ui.fastBoot, tr("Fast Boot"), tr("Checked"),
tr("Patches the BIOS to skip the console's boot animation."));

dialog->registerWidgetHelp(m_ui.fastBoot, tr("Fast Forward Boot"), tr("Unchecked"),
tr("Removes emulation speed throttle until the game starts to reduce startup time."));

refreshList();

connect(m_ui.searchDirectory, &QLineEdit::textChanged, this, &BIOSSettingsWidget::refreshList);
connect(m_ui.refresh, &QPushButton::clicked, this, &BIOSSettingsWidget::refreshList);
connect(m_ui.fileList, &QTreeWidget::currentItemChanged, this, &BIOSSettingsWidget::listItemChanged);
connect(m_ui.fastBoot, &QCheckBox::stateChanged, this, &BIOSSettingsWidget::fastBootChanged);
}

BIOSSettingsWidget::~BIOSSettingsWidget()
Expand Down Expand Up @@ -139,6 +145,12 @@ void BIOSSettingsWidget::listItemChanged(const QTreeWidgetItem* current, const Q
g_emu_thread->applySettings();
}

void BIOSSettingsWidget::fastBootChanged()
{
const bool enabled = m_dialog->getEffectiveBoolValue("EmuCore", "EnableFastBoot", true);
m_ui.fastBootFastForward->setEnabled(enabled);
}

BIOSSettingsWidget::RefreshThread::RefreshThread(BIOSSettingsWidget* parent, const QString& directory)
: QThread(parent)
, m_parent(parent)
Expand Down
3 changes: 3 additions & 0 deletions pcsx2-qt/Settings/BIOSSettingsWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,11 @@ private Q_SLOTS:
void listItemChanged(const QTreeWidgetItem* current, const QTreeWidgetItem* previous);
void listRefreshed(const QVector<BIOSInfo>& items);

void fastBootChanged();

private:
Ui::BIOSSettingsWidget m_ui;
SettingsDialog* m_dialog;

class RefreshThread final : public QThread
{
Expand Down
21 changes: 16 additions & 5 deletions pcsx2-qt/Settings/BIOSSettingsWidget.ui
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,22 @@
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QCheckBox" name="fastBoot">
<property name="text">
<string>Fast Boot</string>
</property>
</widget>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QCheckBox" name="fastBoot">
<property name="text">
<string>Fast Boot</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="fastBootFastForward">
<property name="text">
<string>Fast Forward Boot</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
Expand Down

0 comments on commit 36c2718

Please sign in to comment.