2022-06-19 05:43:55 +00:00
|
|
|
/* PCSX2 - PS2 Emulator for PCs
|
|
|
|
* Copyright (C) 2002-2022 PCSX2 Dev Team
|
|
|
|
*
|
|
|
|
* PCSX2 is free software: you can redistribute it and/or modify it under the terms
|
|
|
|
* of the GNU Lesser General Public License as published by the Free Software Found-
|
|
|
|
* ation, either version 3 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* PCSX2 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
|
|
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE. See the GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along with PCSX2.
|
|
|
|
* If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <chrono>
|
|
|
|
#include <csignal>
|
2022-12-25 08:32:05 +00:00
|
|
|
#include <cstdlib>
|
2022-06-19 05:43:55 +00:00
|
|
|
#include <condition_variable>
|
|
|
|
#include <mutex>
|
|
|
|
#include <thread>
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
#include "common/RedtapeWindows.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "fmt/core.h"
|
|
|
|
|
|
|
|
#include "common/Assertions.h"
|
|
|
|
#include "common/Console.h"
|
|
|
|
#include "common/Exceptions.h"
|
|
|
|
#include "common/FileSystem.h"
|
|
|
|
#include "common/MemorySettingsInterface.h"
|
|
|
|
#include "common/Path.h"
|
|
|
|
#include "common/SettingsWrapper.h"
|
|
|
|
#include "common/StringUtil.h"
|
|
|
|
|
|
|
|
#include "pcsx2/PrecompiledHeader.h"
|
|
|
|
|
|
|
|
#include "pcsx2/CDVD/CDVD.h"
|
|
|
|
#include "pcsx2/Frontend/CommonHost.h"
|
|
|
|
#include "pcsx2/Frontend/InputManager.h"
|
|
|
|
#include "pcsx2/Frontend/ImGuiManager.h"
|
|
|
|
#include "pcsx2/Frontend/LogSink.h"
|
|
|
|
#include "pcsx2/GS.h"
|
|
|
|
#include "pcsx2/GS/GS.h"
|
|
|
|
#include "pcsx2/GSDumpReplayer.h"
|
|
|
|
#include "pcsx2/HostDisplay.h"
|
|
|
|
#include "pcsx2/HostSettings.h"
|
|
|
|
#include "pcsx2/INISettingsInterface.h"
|
|
|
|
#include "pcsx2/PerformanceMetrics.h"
|
|
|
|
#include "pcsx2/VMManager.h"
|
|
|
|
|
|
|
|
#ifdef ENABLE_ACHIEVEMENTS
|
|
|
|
#include "pcsx2/Frontend/Achievements.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "svnrev.h"
|
|
|
|
|
|
|
|
namespace GSRunner
|
|
|
|
{
|
|
|
|
static bool InitializeConfig();
|
|
|
|
|
|
|
|
static bool CreatePlatformWindow();
|
|
|
|
static void DestroyPlatformWindow();
|
|
|
|
static std::optional<WindowInfo> GetPlatformWindowInfo();
|
|
|
|
static void PumpPlatformMessages();
|
|
|
|
} // namespace GSRunner
|
|
|
|
|
|
|
|
static constexpr u32 WINDOW_WIDTH = 640;
|
|
|
|
static constexpr u32 WINDOW_HEIGHT = 480;
|
|
|
|
|
|
|
|
static MemorySettingsInterface s_settings_interface;
|
|
|
|
alignas(16) static SysMtgsThread s_mtgs_thread;
|
|
|
|
|
|
|
|
static std::string s_output_prefix;
|
|
|
|
static s32 s_loop_count = 1;
|
2022-10-22 11:17:33 +00:00
|
|
|
static std::optional<bool> s_use_window;
|
2022-06-19 05:43:55 +00:00
|
|
|
|
2022-12-12 12:17:26 +00:00
|
|
|
// Owned by the GS thread.
|
|
|
|
static u32 s_dump_frame_number = 0;
|
2023-02-07 20:12:13 +00:00
|
|
|
static u32 s_loop_number = s_loop_count;
|
2022-12-12 12:17:26 +00:00
|
|
|
|
2022-06-19 05:43:55 +00:00
|
|
|
bool GSRunner::InitializeConfig()
|
|
|
|
{
|
|
|
|
if (!CommonHost::InitializeCriticalFolders())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// don't provide an ini path, or bother loading. we'll store everything in memory.
|
|
|
|
MemorySettingsInterface& si = s_settings_interface;
|
|
|
|
Host::Internal::SetBaseSettingsLayer(&si);
|
|
|
|
|
|
|
|
CommonHost::SetDefaultSettings(si, true, true, true, true, true);
|
|
|
|
|
|
|
|
// complete as quickly as possible
|
|
|
|
si.SetBoolValue("EmuCore/GS", "FrameLimitEnable", false);
|
|
|
|
si.SetIntValue("EmuCore/GS", "VsyncEnable", static_cast<int>(VsyncMode::Off));
|
|
|
|
|
|
|
|
// ensure all input sources are disabled, we're not using them
|
|
|
|
si.SetBoolValue("InputSources", "SDL", false);
|
|
|
|
si.SetBoolValue("InputSources", "XInput", false);
|
|
|
|
|
|
|
|
// we don't need any sound output
|
|
|
|
si.SetStringValue("SPU2/Output", "OutputModule", "nullout");
|
|
|
|
|
|
|
|
// force logging
|
|
|
|
si.SetBoolValue("Logging", "EnableSystemConsole", true);
|
|
|
|
si.SetBoolValue("Logging", "EnableTimestamps", true);
|
|
|
|
si.SetBoolValue("Logging", "EnableVerbose", true);
|
|
|
|
|
|
|
|
// and show some stats :)
|
|
|
|
si.SetBoolValue("EmuCore/GS", "OsdShowFPS", true);
|
|
|
|
si.SetBoolValue("EmuCore/GS", "OsdShowResolution", true);
|
|
|
|
si.SetBoolValue("EmuCore/GS", "OsdShowGSStats", true);
|
|
|
|
|
2022-10-22 11:34:03 +00:00
|
|
|
// remove memory cards, so we don't have sharing violations
|
|
|
|
for (u32 i = 0; i < 2; i++)
|
|
|
|
{
|
|
|
|
si.SetBoolValue("MemoryCards", fmt::format("Slot{}_Enable", i + 1).c_str(), false);
|
|
|
|
si.SetStringValue("MemoryCards", fmt::format("Slot{}_Filename", i + 1).c_str(), "");
|
|
|
|
}
|
|
|
|
|
2022-06-19 05:43:55 +00:00
|
|
|
CommonHost::LoadStartupSettings();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Host::CommitBaseSettingChanges()
|
|
|
|
{
|
|
|
|
// nothing to save, we're all in memory
|
|
|
|
}
|
|
|
|
|
|
|
|
void Host::LoadSettings(SettingsInterface& si, std::unique_lock<std::mutex>& lock)
|
|
|
|
{
|
|
|
|
CommonHost::LoadSettings(si, lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Host::CheckForSettingsChanges(const Pcsx2Config& old_config)
|
|
|
|
{
|
|
|
|
CommonHost::CheckForSettingsChanges(old_config);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Host::RequestResetSettings(bool folders, bool core, bool controllers, bool hotkeys, bool ui)
|
|
|
|
{
|
|
|
|
// not running any UI, so no settings requests will come in
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Host::SetDefaultUISettings(SettingsInterface& si)
|
|
|
|
{
|
|
|
|
// nothing
|
|
|
|
}
|
|
|
|
|
|
|
|
std::optional<std::vector<u8>> Host::ReadResourceFile(const char* filename)
|
|
|
|
{
|
|
|
|
const std::string path(Path::Combine(EmuFolders::Resources, filename));
|
|
|
|
std::optional<std::vector<u8>> ret(FileSystem::ReadBinaryFile(path.c_str()));
|
|
|
|
if (!ret.has_value())
|
|
|
|
Console.Error("Failed to read resource file '%s'", filename);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::optional<std::string> Host::ReadResourceFileToString(const char* filename)
|
|
|
|
{
|
|
|
|
const std::string path(Path::Combine(EmuFolders::Resources, filename));
|
|
|
|
std::optional<std::string> ret(FileSystem::ReadFileToString(path.c_str()));
|
|
|
|
if (!ret.has_value())
|
|
|
|
Console.Error("Failed to read resource file to string '%s'", filename);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::optional<std::time_t> Host::GetResourceFileTimestamp(const char* filename)
|
|
|
|
{
|
|
|
|
const std::string path(Path::Combine(EmuFolders::Resources, filename));
|
|
|
|
FILESYSTEM_STAT_DATA sd;
|
|
|
|
if (!FileSystem::StatFile(filename, &sd))
|
|
|
|
return std::nullopt;
|
|
|
|
|
|
|
|
return sd.ModificationTime;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Host::ReportErrorAsync(const std::string_view& title, const std::string_view& message)
|
|
|
|
{
|
|
|
|
if (!title.empty() && !message.empty())
|
|
|
|
{
|
|
|
|
Console.Error(
|
|
|
|
"ReportErrorAsync: %.*s: %.*s", static_cast<int>(title.size()), title.data(), static_cast<int>(message.size()), message.data());
|
|
|
|
}
|
|
|
|
else if (!message.empty())
|
|
|
|
{
|
|
|
|
Console.Error("ReportErrorAsync: %.*s", static_cast<int>(message.size()), message.data());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Host::ConfirmMessage(const std::string_view& title, const std::string_view& message)
|
|
|
|
{
|
|
|
|
if (!title.empty() && !message.empty())
|
|
|
|
{
|
|
|
|
Console.Error(
|
|
|
|
"ConfirmMessage: %.*s: %.*s", static_cast<int>(title.size()), title.data(), static_cast<int>(message.size()), message.data());
|
|
|
|
}
|
|
|
|
else if (!message.empty())
|
|
|
|
{
|
|
|
|
Console.Error("ConfirmMessage: %.*s", static_cast<int>(message.size()), message.data());
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Host::OpenURL(const std::string_view& url)
|
|
|
|
{
|
|
|
|
// noop
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Host::CopyTextToClipboard(const std::string_view& text)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Host::BeginTextInput()
|
|
|
|
{
|
|
|
|
// noop
|
|
|
|
}
|
|
|
|
|
|
|
|
void Host::EndTextInput()
|
|
|
|
{
|
|
|
|
// noop
|
|
|
|
}
|
|
|
|
|
|
|
|
std::optional<WindowInfo> Host::GetTopLevelWindowInfo()
|
|
|
|
{
|
|
|
|
return GSRunner::GetPlatformWindowInfo();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Host::OnInputDeviceConnected(const std::string_view& identifier, const std::string_view& device_name)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void Host::OnInputDeviceDisconnected(const std::string_view& identifier)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-12-04 15:00:06 +00:00
|
|
|
void Host::SetRelativeMouseMode(bool enabled)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-12-02 14:38:08 +00:00
|
|
|
bool Host::AcquireHostDisplay(RenderAPI api, bool clear_state_on_fail)
|
2022-06-19 05:43:55 +00:00
|
|
|
{
|
|
|
|
const std::optional<WindowInfo> wi(GSRunner::GetPlatformWindowInfo());
|
|
|
|
if (!wi.has_value())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
g_host_display = HostDisplay::CreateForAPI(api);
|
|
|
|
if (!g_host_display)
|
|
|
|
return false;
|
|
|
|
|
2022-12-04 05:09:22 +00:00
|
|
|
if (!g_host_display->CreateDevice(wi.value(), Host::GetEffectiveVSyncMode()) ||
|
|
|
|
!g_host_display->MakeCurrent() || !g_host_display->SetupDevice() || !ImGuiManager::Initialize())
|
2022-06-19 05:43:55 +00:00
|
|
|
{
|
2022-12-02 14:38:08 +00:00
|
|
|
ReleaseHostDisplay(clear_state_on_fail);
|
2022-06-19 05:43:55 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
Console.WriteLn(Color_StrongGreen, "%s Graphics Driver Info:", HostDisplay::RenderAPIToString(g_host_display->GetRenderAPI()));
|
|
|
|
Console.Indent().WriteLn(g_host_display->GetDriverInfo());
|
|
|
|
|
|
|
|
return g_host_display.get();
|
|
|
|
}
|
|
|
|
|
2022-12-02 14:38:08 +00:00
|
|
|
void Host::ReleaseHostDisplay(bool clear_state)
|
2022-06-19 05:43:55 +00:00
|
|
|
{
|
2022-12-02 14:38:08 +00:00
|
|
|
ImGuiManager::Shutdown(clear_state);
|
2022-06-19 05:43:55 +00:00
|
|
|
g_host_display.reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Host::BeginPresentFrame(bool frame_skip)
|
|
|
|
{
|
2023-02-07 20:12:13 +00:00
|
|
|
if (s_loop_number == 0)
|
|
|
|
{
|
|
|
|
// when we wrap around, don't race other files
|
|
|
|
GSJoinSnapshotThreads();
|
2022-12-12 12:17:26 +00:00
|
|
|
|
2023-02-07 20:12:13 +00:00
|
|
|
// queue dumping of this frame
|
|
|
|
std::string dump_path(fmt::format("{}_frame{}.png", s_output_prefix, s_dump_frame_number));
|
|
|
|
GSQueueSnapshot(dump_path);
|
|
|
|
}
|
2022-11-30 15:48:53 +00:00
|
|
|
if (g_host_display->BeginPresent(frame_skip))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
// don't render imgui
|
|
|
|
ImGuiManager::NewFrame();
|
|
|
|
return false;
|
2022-06-19 05:43:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Host::EndPresentFrame()
|
|
|
|
{
|
|
|
|
if (GSDumpReplayer::IsReplayingDump())
|
|
|
|
GSDumpReplayer::RenderUI();
|
|
|
|
|
|
|
|
ImGuiManager::RenderOSD();
|
|
|
|
g_host_display->EndPresent();
|
|
|
|
ImGuiManager::NewFrame();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Host::ResizeHostDisplay(u32 new_window_width, u32 new_window_height, float new_window_scale)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void Host::UpdateHostDisplay()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void Host::RequestResizeHostDisplay(s32 width, s32 height)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void Host::OnVMStarting()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void Host::OnVMStarted()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void Host::OnVMDestroyed()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void Host::OnVMPaused()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void Host::OnVMResumed()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-12-13 20:57:55 +00:00
|
|
|
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)
|
2022-06-19 05:43:55 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void Host::OnPerformanceMetricsUpdated()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void Host::OnSaveStateLoading(const std::string_view& filename)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void Host::OnSaveStateLoaded(const std::string_view& filename, bool was_successful)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void Host::OnSaveStateSaved(const std::string_view& filename)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void Host::RunOnCPUThread(std::function<void()> function, bool block /* = false */)
|
|
|
|
{
|
|
|
|
pxFailRel("Not implemented");
|
|
|
|
}
|
|
|
|
|
|
|
|
void Host::RefreshGameListAsync(bool invalidate_cache)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void Host::CancelGameListRefresh()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Host::IsFullscreen()
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Host::SetFullscreen(bool enabled)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2023-01-28 03:33:51 +00:00
|
|
|
void Host::RequestExit(bool allow_confirm)
|
2022-06-19 05:43:55 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void Host::RequestVMShutdown(bool allow_confirm, bool allow_save_state, bool default_save_state)
|
|
|
|
{
|
|
|
|
VMManager::SetState(VMState::Stopping);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef ENABLE_ACHIEVEMENTS
|
|
|
|
void Host::OnAchievementsRefreshed()
|
|
|
|
{
|
|
|
|
// noop
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
std::optional<u32> InputManager::ConvertHostKeyboardStringToCode(const std::string_view& str)
|
|
|
|
{
|
|
|
|
return std::nullopt;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::optional<std::string> InputManager::ConvertHostKeyboardCodeToString(u32 code)
|
|
|
|
{
|
|
|
|
return std::nullopt;
|
|
|
|
}
|
|
|
|
|
|
|
|
SysMtgsThread& GetMTGS()
|
|
|
|
{
|
|
|
|
return s_mtgs_thread;
|
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
// Interface Stuff
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
const IConsoleWriter* PatchesCon = &Console;
|
|
|
|
BEGIN_HOTKEY_LIST(g_host_hotkeys)
|
|
|
|
END_HOTKEY_LIST()
|
|
|
|
|
|
|
|
static void PrintCommandLineVersion()
|
|
|
|
{
|
|
|
|
std::fprintf(stderr, "PCSX2 GS Runner Version %s\n", GIT_REV);
|
|
|
|
std::fprintf(stderr, "https://pcsx2.net/\n");
|
|
|
|
std::fprintf(stderr, "\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void PrintCommandLineHelp(const char* progname)
|
|
|
|
{
|
|
|
|
PrintCommandLineVersion();
|
|
|
|
std::fprintf(stderr, "Usage: %s [parameters] [--] [filename]\n", progname);
|
|
|
|
std::fprintf(stderr, "\n");
|
|
|
|
std::fprintf(stderr, " -help: Displays this information and exits.\n");
|
|
|
|
std::fprintf(stderr, " -version: Displays version information and exits.\n");
|
|
|
|
std::fprintf(stderr, " -dumpdir <dir>: Frame dump directory (will be dumped as filename_frameN.png).\n");
|
|
|
|
std::fprintf(stderr, " -loop <count>: Loops dump playback N times. Defaults to 1. 0 will loop infinitely.\n");
|
|
|
|
std::fprintf(stderr, " -renderer <renderer>: Sets the graphics renderer. Defaults to Auto.\n");
|
2022-10-22 11:17:33 +00:00
|
|
|
std::fprintf(stderr, " -window: Forces a window to be displayed.\n");
|
|
|
|
std::fprintf(stderr, " -surfaceless: Disables showing a window.\n");
|
2022-10-22 11:34:03 +00:00
|
|
|
std::fprintf(stderr, " -logfile <filename>: Writes emu log to filename.\n");
|
|
|
|
std::fprintf(stderr, " -noshadercache: Disables the shader cache (useful for parallel runs).\n");
|
2022-06-19 05:43:55 +00:00
|
|
|
std::fprintf(stderr, " --: Signals that no more arguments will follow and the remaining\n"
|
|
|
|
" parameters make up the filename. Use when the filename contains\n"
|
|
|
|
" spaces or starts with a dash.\n");
|
|
|
|
std::fprintf(stderr, "\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool ParseCommandLineArgs(int argc, char* argv[], VMBootParameters& params)
|
|
|
|
{
|
|
|
|
bool no_more_args = false;
|
|
|
|
for (int i = 1; i < argc; i++)
|
|
|
|
{
|
|
|
|
if (!no_more_args)
|
|
|
|
{
|
|
|
|
#define CHECK_ARG(str) !std::strcmp(argv[i], str)
|
|
|
|
#define CHECK_ARG_PARAM(str) (!std::strcmp(argv[i], str) && ((i + 1) < argc))
|
|
|
|
|
|
|
|
if (CHECK_ARG("-help"))
|
|
|
|
{
|
|
|
|
PrintCommandLineHelp(argv[0]);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else if (CHECK_ARG("-version"))
|
|
|
|
{
|
|
|
|
PrintCommandLineVersion();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else if (CHECK_ARG_PARAM("-dumpdir"))
|
|
|
|
{
|
2022-10-22 10:40:07 +00:00
|
|
|
s_output_prefix = StringUtil::StripWhitespace(argv[++i]);
|
2022-06-19 05:43:55 +00:00
|
|
|
if (s_output_prefix.empty())
|
|
|
|
{
|
|
|
|
Console.Error("Invalid dump directory specified.");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!FileSystem::DirectoryExists(s_output_prefix.c_str()) && !FileSystem::CreateDirectoryPath(s_output_prefix.c_str(), false))
|
|
|
|
{
|
|
|
|
Console.Error("Failed to create output directory");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else if (CHECK_ARG_PARAM("-loop"))
|
|
|
|
{
|
|
|
|
s_loop_count = StringUtil::FromChars<s32>(argv[++i]).value_or(0);
|
|
|
|
Console.WriteLn("Looping dump playback %d times.", s_loop_count);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else if (CHECK_ARG_PARAM("-renderer"))
|
|
|
|
{
|
|
|
|
const char* rname = argv[++i];
|
|
|
|
|
|
|
|
GSRendererType type = GSRendererType::Auto;
|
|
|
|
if (StringUtil::Strcasecmp(rname, "Auto") == 0)
|
|
|
|
type = GSRendererType::Auto;
|
|
|
|
#ifdef _WIN32
|
|
|
|
else if (StringUtil::Strcasecmp(rname, "dx11") == 0)
|
|
|
|
type = GSRendererType::DX11;
|
|
|
|
else if (StringUtil::Strcasecmp(rname, "dx12") == 0)
|
|
|
|
type = GSRendererType::DX12;
|
|
|
|
#endif
|
|
|
|
#ifdef ENABLE_OPENGL
|
|
|
|
else if (StringUtil::Strcasecmp(rname, "gl") == 0)
|
|
|
|
type = GSRendererType::OGL;
|
|
|
|
#endif
|
|
|
|
#ifdef ENABLE_VULKAN
|
|
|
|
else if (StringUtil::Strcasecmp(rname, "vulkan") == 0)
|
|
|
|
type = GSRendererType::VK;
|
|
|
|
#endif
|
|
|
|
#ifdef __APPLE__
|
|
|
|
else if (StringUtil::Strcasecmp(rname, "metal") == 0)
|
|
|
|
type = GSRendererType::Metal;
|
|
|
|
#endif
|
|
|
|
else if (StringUtil::Strcasecmp(rname, "sw") == 0)
|
|
|
|
type = GSRendererType::SW;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Console.Error("Unknown renderer '%s'", rname);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
Console.WriteLn("Using %s renderer.", Pcsx2Config::GSOptions::GetRendererName(type));
|
|
|
|
s_settings_interface.SetIntValue("EmuCore/GS", "Renderer", static_cast<int>(type));
|
|
|
|
continue;
|
|
|
|
}
|
2023-02-07 22:18:43 +00:00
|
|
|
else if (CHECK_ARG_PARAM("-renderhacks"))
|
|
|
|
{
|
|
|
|
std::string str(argv[++i]);
|
|
|
|
|
|
|
|
s_settings_interface.SetBoolValue("EmuCore/GS", "UserHacks", true);
|
|
|
|
|
|
|
|
if(str.find("af") != std::string::npos)
|
|
|
|
s_settings_interface.SetBoolValue("EmuCore/GS", "UserHacks_AutoFlush", true);
|
|
|
|
if (str.find("cpufb") != std::string::npos)
|
|
|
|
s_settings_interface.SetBoolValue("EmuCore/GS", "UserHacks_CPU_FB_Conversion ", true);
|
|
|
|
if (str.find("dds") != std::string::npos)
|
|
|
|
s_settings_interface.SetBoolValue("EmuCore/GS", "UserHacks_DisableDepthSupport ", true);
|
|
|
|
if (str.find("dpi") != std::string::npos)
|
|
|
|
s_settings_interface.SetBoolValue("EmuCore/GS", "UserHacks_DisablePartialInvalidation ", true);
|
|
|
|
if (str.find("dsf") != std::string::npos)
|
|
|
|
s_settings_interface.SetBoolValue("EmuCore/GS", "UserHacks_DisableSafeFeatures ", true);
|
|
|
|
if (str.find("tinrt") != std::string::npos)
|
|
|
|
s_settings_interface.SetBoolValue("EmuCore/GS", "UserHacks_TextureInsideRt ", true);
|
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
2022-10-22 11:34:03 +00:00
|
|
|
else if (CHECK_ARG_PARAM("-logfile"))
|
|
|
|
{
|
|
|
|
const char* logfile = argv[++i];
|
|
|
|
if (std::strlen(logfile) > 0)
|
|
|
|
{
|
|
|
|
// disable timestamps, since we want to be able to diff the logs
|
|
|
|
Console.WriteLn("Logging to %s...", logfile);
|
|
|
|
CommonHost::SetFileLogPath(logfile);
|
|
|
|
s_settings_interface.SetBoolValue("Logging", "EnableFileLogging", true);
|
|
|
|
s_settings_interface.SetBoolValue("Logging", "EnableTimestamps", false);
|
|
|
|
}
|
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else if (CHECK_ARG("-noshadercache"))
|
|
|
|
{
|
|
|
|
Console.WriteLn("Disabling shader cache");
|
|
|
|
s_settings_interface.SetBoolValue("EmuCore/GS", "disable_shader_cache", false);
|
|
|
|
continue;
|
|
|
|
}
|
2022-10-22 11:17:33 +00:00
|
|
|
else if (CHECK_ARG("-window"))
|
|
|
|
{
|
|
|
|
Console.WriteLn("Creating window");
|
|
|
|
s_use_window = true;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else if (CHECK_ARG("-surfaceless"))
|
|
|
|
{
|
|
|
|
Console.WriteLn("Running surfaceless");
|
|
|
|
s_use_window = false;
|
|
|
|
continue;
|
|
|
|
}
|
2022-06-19 05:43:55 +00:00
|
|
|
else if (CHECK_ARG("--"))
|
|
|
|
{
|
|
|
|
no_more_args = true;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else if (argv[i][0] == '-')
|
|
|
|
{
|
|
|
|
Console.Error("Unknown parameter: '%s'", argv[i]);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
#undef CHECK_ARG
|
|
|
|
#undef CHECK_ARG_PARAM
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!params.filename.empty())
|
|
|
|
params.filename += ' ';
|
|
|
|
params.filename += argv[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (params.filename.empty())
|
|
|
|
{
|
|
|
|
Console.Error("No dump filename provided.");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!VMManager::IsGSDumpFileName(params.filename))
|
|
|
|
{
|
|
|
|
Console.Error("Provided filename is not a GS dump.");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// set up the frame dump directory
|
|
|
|
if (!s_output_prefix.empty())
|
|
|
|
{
|
|
|
|
// strip off all extensions
|
|
|
|
std::string_view title(Path::GetFileTitle(params.filename));
|
|
|
|
if (StringUtil::EndsWithNoCase(title, ".gs"))
|
|
|
|
title = Path::GetFileTitle(title);
|
|
|
|
|
2022-10-22 10:40:07 +00:00
|
|
|
s_output_prefix = Path::Combine(s_output_prefix, StringUtil::StripWhitespace(title));
|
2022-06-19 05:43:55 +00:00
|
|
|
Console.WriteLn(fmt::format("Saving dumps as {}_frameN.png", s_output_prefix));
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char* argv[])
|
|
|
|
{
|
|
|
|
CommonHost::InitializeEarlyConsole();
|
|
|
|
|
|
|
|
if (!GSRunner::InitializeConfig())
|
|
|
|
{
|
|
|
|
Console.Error("Failed to initialize config.");
|
2022-12-25 08:32:05 +00:00
|
|
|
return EXIT_FAILURE;
|
2022-06-19 05:43:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
VMBootParameters params;
|
|
|
|
if (!ParseCommandLineArgs(argc, argv, params))
|
2022-12-25 08:32:05 +00:00
|
|
|
return EXIT_FAILURE;
|
2022-06-19 05:43:55 +00:00
|
|
|
|
|
|
|
PerformanceMetrics::SetCPUThread(Threading::ThreadHandle::GetForCallingThread());
|
|
|
|
if (!VMManager::Internal::InitializeGlobals() || !VMManager::Internal::InitializeMemory())
|
|
|
|
{
|
|
|
|
Console.Error("Failed to allocate globals/memory.");
|
2022-12-25 08:32:05 +00:00
|
|
|
return EXIT_FAILURE;
|
2022-06-19 05:43:55 +00:00
|
|
|
}
|
|
|
|
|
2022-10-22 11:17:33 +00:00
|
|
|
if (s_use_window.value_or(false) && !GSRunner::CreatePlatformWindow())
|
2022-06-19 05:43:55 +00:00
|
|
|
{
|
|
|
|
Console.Error("Failed to create window.");
|
2022-12-25 08:32:05 +00:00
|
|
|
return EXIT_FAILURE;
|
2022-06-19 05:43:55 +00:00
|
|
|
}
|
|
|
|
|
2022-10-22 11:34:03 +00:00
|
|
|
// apply new settings (e.g. pick up renderer change)
|
2022-10-22 11:17:33 +00:00
|
|
|
VMManager::ApplySettings();
|
2023-02-07 20:12:13 +00:00
|
|
|
GSDumpReplayer::SetIsDumpRunner(true);
|
2022-10-22 11:17:33 +00:00
|
|
|
|
2022-06-19 05:43:55 +00:00
|
|
|
if (VMManager::Initialize(params))
|
|
|
|
{
|
|
|
|
// run until end
|
|
|
|
GSDumpReplayer::SetLoopCount(s_loop_count);
|
|
|
|
VMManager::SetState(VMState::Running);
|
|
|
|
while (VMManager::GetState() == VMState::Running)
|
|
|
|
VMManager::Execute();
|
|
|
|
VMManager::Shutdown(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
InputManager::CloseSources();
|
|
|
|
VMManager::Internal::ReleaseMemory();
|
2023-01-23 15:20:14 +00:00
|
|
|
VMManager::Internal::ReleaseGlobals();
|
2022-06-19 05:43:55 +00:00
|
|
|
PerformanceMetrics::SetCPUThread(Threading::ThreadHandle());
|
|
|
|
GSRunner::DestroyPlatformWindow();
|
|
|
|
|
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Host::CPUThreadVSync()
|
|
|
|
{
|
2022-12-12 12:17:26 +00:00
|
|
|
// update GS thread copy of frame number
|
|
|
|
GetMTGS().RunOnGSThread([frame_number = GSDumpReplayer::GetFrameNumber()]() { s_dump_frame_number = frame_number; });
|
2023-02-07 20:12:13 +00:00
|
|
|
GetMTGS().RunOnGSThread([loop_number = GSDumpReplayer::GetLoopCount()]() { s_loop_number = loop_number; });
|
2022-06-19 05:43:55 +00:00
|
|
|
|
|
|
|
// process any window messages (but we shouldn't really have any)
|
|
|
|
GSRunner::PumpPlatformMessages();
|
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
// Platform specific code
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
|
|
|
|
static constexpr LPCWSTR WINDOW_CLASS_NAME = L"PCSX2GSRunner";
|
|
|
|
static HWND s_hwnd = NULL;
|
|
|
|
|
|
|
|
static LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
|
|
|
|
|
|
|
|
bool GSRunner::CreatePlatformWindow()
|
|
|
|
{
|
|
|
|
WNDCLASSEXW wc = {};
|
|
|
|
wc.cbSize = sizeof(WNDCLASSEXW);
|
|
|
|
wc.style = 0;
|
|
|
|
wc.lpfnWndProc = WndProc;
|
|
|
|
wc.cbClsExtra = 0;
|
|
|
|
wc.cbWndExtra = 0;
|
|
|
|
wc.hInstance = GetModuleHandle(nullptr);
|
|
|
|
wc.hIcon = NULL;
|
|
|
|
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
|
|
|
|
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
|
|
|
|
wc.lpszMenuName = NULL;
|
|
|
|
wc.lpszClassName = WINDOW_CLASS_NAME;
|
|
|
|
wc.hIconSm = NULL;
|
|
|
|
|
|
|
|
if (!RegisterClassExW(&wc))
|
|
|
|
{
|
|
|
|
Console.Error("Window registration failed.");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
s_hwnd = CreateWindowExW(WS_EX_CLIENTEDGE, WINDOW_CLASS_NAME, L"PCSX2 GS Runner",
|
|
|
|
WS_OVERLAPPEDWINDOW | WS_CAPTION | WS_MINIMIZEBOX | WS_SYSMENU | WS_SIZEBOX, CW_USEDEFAULT, CW_USEDEFAULT, WINDOW_WIDTH,
|
|
|
|
WINDOW_HEIGHT, nullptr, nullptr, GetModuleHandleW(nullptr), nullptr);
|
|
|
|
if (!s_hwnd)
|
|
|
|
{
|
|
|
|
Console.Error("CreateWindowEx failed.");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
ShowWindow(s_hwnd, SW_SHOW);
|
|
|
|
UpdateWindow(s_hwnd);
|
|
|
|
|
|
|
|
// make sure all messages are processed before returning
|
|
|
|
PumpPlatformMessages();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GSRunner::DestroyPlatformWindow()
|
|
|
|
{
|
|
|
|
if (!s_hwnd)
|
|
|
|
return;
|
|
|
|
|
|
|
|
PumpPlatformMessages();
|
|
|
|
DestroyWindow(s_hwnd);
|
|
|
|
s_hwnd = {};
|
|
|
|
}
|
|
|
|
|
|
|
|
std::optional<WindowInfo> GSRunner::GetPlatformWindowInfo()
|
|
|
|
{
|
|
|
|
WindowInfo wi;
|
2022-10-22 11:17:33 +00:00
|
|
|
|
|
|
|
if (s_hwnd)
|
|
|
|
{
|
|
|
|
RECT rc = {};
|
|
|
|
GetWindowRect(s_hwnd, &rc);
|
|
|
|
wi.surface_width = static_cast<u32>(rc.right - rc.left);
|
|
|
|
wi.surface_height = static_cast<u32>(rc.bottom - rc.top);
|
|
|
|
wi.surface_scale = 1.0f;
|
|
|
|
wi.type = WindowInfo::Type::Win32;
|
|
|
|
wi.window_handle = s_hwnd;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
wi.type = WindowInfo::Type::Surfaceless;
|
|
|
|
}
|
|
|
|
|
2022-06-19 05:43:55 +00:00
|
|
|
return wi;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GSRunner::PumpPlatformMessages()
|
|
|
|
{
|
|
|
|
MSG msg;
|
|
|
|
while (PeekMessageW(&msg, NULL, 0, 0, PM_REMOVE))
|
|
|
|
{
|
|
|
|
TranslateMessage(&msg);
|
|
|
|
DispatchMessageW(&msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
|
|
|
|
{
|
|
|
|
return DefWindowProcW(hwnd, msg, wParam, lParam);
|
|
|
|
}
|
|
|
|
|
2022-12-04 15:00:06 +00:00
|
|
|
#endif // _WIN32
|