From cc8ddabf88cd5f47b8638bc1b58f901904fc9dd6 Mon Sep 17 00:00:00 2001 From: Sour Date: Sun, 24 Feb 2019 23:53:14 -0500 Subject: [PATCH] PGO build configuration --- .gitignore | 3 +- Core/Console.cpp | 3 +- InteropDLL/EmuApiWrapper.cpp | 21 ++ InteropDLL/stdafx.h | 2 +- Mesen-S.sln | 2 - PGOHelper/PGOGames/readme.md | 7 + PGOHelper/PGOHelper.cpp | 49 ++++ PGOHelper/PGOHelper.vcxproj | 420 ++++++++++++++++++++++++++++ PGOHelper/PGOHelper.vcxproj.filters | 14 + UI/UI.csproj | 4 - 10 files changed, 515 insertions(+), 10 deletions(-) create mode 100644 PGOHelper/PGOGames/readme.md create mode 100644 PGOHelper/PGOHelper.cpp create mode 100644 PGOHelper/PGOHelper.vcxproj create mode 100644 PGOHelper/PGOHelper.vcxproj.filters diff --git a/.gitignore b/.gitignore index 9db2f13..9b50ff9 100644 --- a/.gitignore +++ b/.gitignore @@ -160,6 +160,7 @@ $RECYCLE.BIN/ # Mac desktop service store files .DS_Store *.nes +*.sfc *.sav *.svs *.trt @@ -182,11 +183,9 @@ packages/* !Libretro/hakchi/bin Dependencies/* -GUI.NET/* Linux/* Libretro/* Docs/* Lua/* TestHelper/* UpdateHelper/* -PGOHelper/* diff --git a/Core/Console.cpp b/Core/Console.cpp index 090a05d..ce435de 100644 --- a/Core/Console.cpp +++ b/Core/Console.cpp @@ -19,6 +19,7 @@ #include "../Utilities/Timer.h" #include "../Utilities/VirtualFile.h" #include "../Utilities/PlatformUtilities.h" +#include "../Utilities/FolderUtilities.h" void Console::Initialize() { @@ -110,7 +111,7 @@ void Console::LoadRom(VirtualFile romFile, VirtualFile patchFile) MessageManager::ClearLog(); vector spcRomData; - VirtualFile spcBios("spc700.rom"); + VirtualFile spcBios(FolderUtilities::CombinePath(FolderUtilities::GetHomeFolder(), "spc700.rom")); if(spcBios.IsValid()) { spcBios.ReadFile(spcRomData); } else { diff --git a/InteropDLL/EmuApiWrapper.cpp b/InteropDLL/EmuApiWrapper.cpp index ede4619..c867a47 100644 --- a/InteropDLL/EmuApiWrapper.cpp +++ b/InteropDLL/EmuApiWrapper.cpp @@ -184,5 +184,26 @@ namespace InteropEmu { } DllExport void __stdcall WriteLogEntry(char* message) { MessageManager::Log(message); } + + DllExport void __stdcall PgoRunTest(vector testRoms, bool enableDebugger) + { + FolderUtilities::SetHomeFolder("../PGOMesenHome"); + + for(size_t i = 0; i < testRoms.size(); i++) { + std::cout << "Running: " << testRoms[i] << std::endl; + + _console.reset(new Console()); + _console->Initialize(); + _console->LoadRom((VirtualFile)testRoms[i], VirtualFile()); + + thread testThread([=] { + _console->Run(); + }); + std::this_thread::sleep_for(std::chrono::duration(5000)); + _console->Stop(); + testThread.join(); + _console->Release(); + } + } } } \ No newline at end of file diff --git a/InteropDLL/stdafx.h b/InteropDLL/stdafx.h index 43d156d..21207e0 100644 --- a/InteropDLL/stdafx.h +++ b/InteropDLL/stdafx.h @@ -38,7 +38,7 @@ #pragma comment(lib, "Utilities.lib") #pragma comment(lib, "Windows.lib") #pragma comment(lib, "SevenZip.lib") - #pragma comment(lib, "Lua.lib") + //#pragma comment(lib, "Lua.lib") #pragma comment(lib, "../Dependencies/DirectXTK." MESEN_LIBRARY_DEBUG_SUFFIX ".Static." MESEN_LIBRARY_SUFFIX) #define DllExport __declspec(dllexport) #else diff --git a/Mesen-S.sln b/Mesen-S.sln index dd457f1..ebf83fb 100644 --- a/Mesen-S.sln +++ b/Mesen-S.sln @@ -6,7 +6,6 @@ MinimumVisualStudioVersion = 10.0.40219.1 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Core", "Core\Core.vcxproj", "{78FEF1A1-6DF1-4CBB-A373-AE6FA7CE5CE0}" ProjectSection(ProjectDependencies) = postProject {B5330148-E8C7-46BA-B54E-69BE59EA337D} = {B5330148-E8C7-46BA-B54E-69BE59EA337D} - {B609E0A0-5050-4871-91D6-E760633BCDD1} = {B609E0A0-5050-4871-91D6-E760633BCDD1} EndProjectSection EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Utilities", "Utilities\Utilities.vcxproj", "{B5330148-E8C7-46BA-B54E-69BE59EA337D}" @@ -31,7 +30,6 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "InteropDLL", "InteropDLL\In ProjectSection(ProjectDependencies) = postProject {B5330148-E8C7-46BA-B54E-69BE59EA337D} = {B5330148-E8C7-46BA-B54E-69BE59EA337D} {7761E790-B42C-4179-8550-8365FF9EB23E} = {7761E790-B42C-4179-8550-8365FF9EB23E} - {B609E0A0-5050-4871-91D6-E760633BCDD1} = {B609E0A0-5050-4871-91D6-E760633BCDD1} {78FEF1A1-6DF1-4CBB-A373-AE6FA7CE5CE0} = {78FEF1A1-6DF1-4CBB-A373-AE6FA7CE5CE0} EndProjectSection EndProject diff --git a/PGOHelper/PGOGames/readme.md b/PGOHelper/PGOGames/readme.md new file mode 100644 index 0000000..3e93897 --- /dev/null +++ b/PGOHelper/PGOGames/readme.md @@ -0,0 +1,7 @@ +This folder is used when compiling Mesen-S with PGO. +All .nes files put in this folder will be folder will be run in console mode for a few seconds as a way of building of a profile for use with PGO. + +Once you have added a few roms to this folder, run "make pgo" to produce a PGO-optimized binary (it will take several minutes to build) + +Another folder, called "PGOMesenHome" will be created alongside this one when the instrumented executable runs when executing the PGO script. +This folder will be used as a temporary home folder location for Mesen-S to store the files it creates in the process. \ No newline at end of file diff --git a/PGOHelper/PGOHelper.cpp b/PGOHelper/PGOHelper.cpp new file mode 100644 index 0000000..c67173a --- /dev/null +++ b/PGOHelper/PGOHelper.cpp @@ -0,0 +1,49 @@ +#include +#include +#include +#include +#include + +namespace fs = std::experimental::filesystem; +using std::string; +using std::vector; + +extern "C" { + void __stdcall PgoRunTest(vector testRoms, bool enableDebugger); +} + +vector GetFilesInFolder(string rootFolder, std::unordered_set extensions) +{ + vector files; + vector folders = { { rootFolder } }; + + std::error_code errorCode; + if(!fs::is_directory(fs::u8path(rootFolder), errorCode)) { + return files; + } + + for(string folder : folders) { + for(fs::directory_iterator i(fs::u8path(folder.c_str())), end; i != end; i++) { + string extension = i->path().extension().u8string(); + std::transform(extension.begin(), extension.end(), extension.begin(), ::tolower); + if(extensions.find(extension) != extensions.end()) { + files.push_back(i->path().u8string()); + } + } + } + + return files; +} + +int main(int argc, char* argv[]) +{ + string romFolder = "../PGOGames"; + if(argc >= 2) { + romFolder = argv[1]; + } + + vector testRoms = GetFilesInFolder(romFolder, { {".sfc"} }); + PgoRunTest(testRoms, true); + return 0; +} + diff --git a/PGOHelper/PGOHelper.vcxproj b/PGOHelper/PGOHelper.vcxproj new file mode 100644 index 0000000..a5070d7 --- /dev/null +++ b/PGOHelper/PGOHelper.vcxproj @@ -0,0 +1,420 @@ + + + + + Debug + Win32 + + + Debug + x64 + + + Libretro + Win32 + + + Libretro + x64 + + + PGO Optimize + Win32 + + + PGO Optimize + x64 + + + PGO Profile + Win32 + + + PGO Profile + x64 + + + Release + Win32 + + + Release + x64 + + + + {38D74EE1-5276-4D24-AABC-104B912A27D2} + Win32Proj + PGOHelper + 10.0.16299.0 + + + + Application + true + v141 + Unicode + + + Application + true + v141 + Unicode + + + Application + false + v141 + true + Unicode + + + Application + false + v141 + true + Unicode + + + Application + false + v141 + true + Unicode + + + Application + false + v141 + true + Unicode + + + Application + false + v141 + true + Unicode + + + Application + false + v141 + true + Unicode + + + Application + false + v141 + true + Unicode + + + Application + false + v141 + true + Unicode + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + true + $(SolutionDir)\bin\$(PlatformTarget)\$(Configuration)\ + obj\$(Platform)\$(Configuration)\ + + + true + $(SolutionDir)\bin\$(PlatformTarget)\$(Configuration)\ + obj\$(Platform)\$(Configuration)\ + + + false + $(SolutionDir)\bin\$(PlatformTarget)\$(Configuration)\ + obj\$(Platform)\$(Configuration)\ + + + false + $(SolutionDir)\bin\$(PlatformTarget)\$(Configuration)\ + obj\$(Platform)\$(Configuration)\ + + + false + $(SolutionDir)\bin\$(PlatformTarget)\$(Configuration)\ + obj\$(Platform)\$(Configuration)\ + + + false + $(SolutionDir)\bin\$(PlatformTarget)\PGO Profile\ + obj\$(Platform)\PGO Profile\ + + + false + $(SolutionDir)\bin\$(PlatformTarget)\$(Configuration)\ + obj\$(Platform)\$(Configuration)\ + + + false + $(SolutionDir)\bin\$(PlatformTarget)\$(Configuration)\ + obj\$(Platform)\$(Configuration)\ + + + false + $(SolutionDir)\bin\$(PlatformTarget)\$(Configuration)\ + obj\$(Platform)\$(Configuration)\ + + + false + $(SolutionDir)\bin\$(PlatformTarget)\PGO Profile\ + obj\$(Platform)\PGO Profile\ + + + + + + Level3 + Disabled + WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions) + + + true + false + MultiThreadedDebug + + + Console + true + + + + + + + Level3 + Disabled + WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions) + + + true + false + MultiThreadedDebug + + + Console + true + + + + + Level3 + + + MaxSpeed + true + true + WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions) + + + true + MultiThreaded + + + Console + true + true + true + + + + + Level3 + + + MaxSpeed + true + true + WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions) + + + true + MultiThreaded + + + Console + true + true + true + + + + + Level3 + + + MaxSpeed + true + true + WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions) + + + true + + + Console + true + true + true + + + + + Level3 + + + MaxSpeed + true + true + WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions) + + + true + + + Console + true + true + true + + + + + Level3 + + + MaxSpeed + true + true + WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions) + + + true + MultiThreaded + + + Console + true + true + true + + + + + Level3 + + + MaxSpeed + true + true + WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions) + + + true + MultiThreaded + + + Console + true + true + true + + + + + Level3 + + + MaxSpeed + true + true + WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions) + + + true + + + Console + true + true + true + + + + + Level3 + + + MaxSpeed + true + true + WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions) + + + true + + + Console + true + true + true + + + + + + + + {37749bb2-fa78-4ec9-8990-5628fc0bba19} + false + true + false + true + true + + + + + + \ No newline at end of file diff --git a/PGOHelper/PGOHelper.vcxproj.filters b/PGOHelper/PGOHelper.vcxproj.filters new file mode 100644 index 0000000..f52130d --- /dev/null +++ b/PGOHelper/PGOHelper.vcxproj.filters @@ -0,0 +1,14 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + + + Source Files + + + \ No newline at end of file diff --git a/UI/UI.csproj b/UI/UI.csproj index 4cc523b..ec58f61 100644 --- a/UI/UI.csproj +++ b/UI/UI.csproj @@ -635,10 +635,6 @@ mkdir "Dependencies" -if "x86" == "$(PlatformName)" copy "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\pgort140.dll" "pgort140.dll" - -if "x64" == "$(PlatformName)" copy "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\amd64\pgort140.dll" "pgort140.dll" - if "PGO Optimize" == "$(ConfigurationName)" ( copy "$(SolutionDir)bin\x86\PGO Profile\MesenSCore.dll" "Dependencies\MesenSCore.x86.dll"