From d4239edbc3f63bf07ba00f0f5173ae84aee47f0b Mon Sep 17 00:00:00 2001 From: Andrej Redeky Date: Sun, 29 Oct 2023 11:06:59 +0100 Subject: [PATCH 1/4] Add `sol::lib::jit` to actually enable JIT ( resolves #899 ) --- src/scripting/Scripting.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/scripting/Scripting.cpp b/src/scripting/Scripting.cpp index 1433088d..ddf27d01 100644 --- a/src/scripting/Scripting.cpp +++ b/src/scripting/Scripting.cpp @@ -49,7 +49,7 @@ void Scripting::Initialize() auto lua = m_lua.Lock(); auto& luaVm = lua.Get(); - luaVm.open_libraries(sol::lib::base, sol::lib::string, sol::lib::io, sol::lib::math, sol::lib::package, sol::lib::os, sol::lib::table, sol::lib::bit32); + luaVm.open_libraries(sol::lib::base, sol::lib::string, sol::lib::io, sol::lib::math, sol::lib::package, sol::lib::os, sol::lib::table, sol::lib::bit32, sol::lib::jit); luaVm.require("sqlite3", luaopen_lsqlite3); // make sure to set package path to current directory scope From ea8a09d3cdf8fecd8516e87f4eb0f7832fe20a0a Mon Sep 17 00:00:00 2001 From: Andrej Redeky Date: Sun, 29 Oct 2023 16:03:14 +0100 Subject: [PATCH 2/4] Add option to enable/disable JIT --- src/Options.cpp | 5 +++-- src/Options.h | 1 + src/overlay/widgets/Settings.cpp | 3 +++ 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/Options.cpp b/src/Options.cpp index 17634c92..36674773 100644 --- a/src/Options.cpp +++ b/src/Options.cpp @@ -60,6 +60,7 @@ void DeveloperSettings::Load(const nlohmann::json& aConfig) DumpGameOptions = aConfig.value("dump_game_options", DumpGameOptions); MaxLinesConsoleHistory = aConfig.value("max_lines_console_history", MaxLinesConsoleHistory); PersistentConsole = aConfig.value("persistent_console", PersistentConsole); + EnableJIT = aConfig.value("enable_jit", EnableJIT); // set global "Enable ImGui Assertions" g_ImGuiAssertionsEnabled = EnableImGuiAssertions; @@ -70,8 +71,8 @@ nlohmann::json DeveloperSettings::Save() const // set global "Enable ImGui Assertions" g_ImGuiAssertionsEnabled = EnableImGuiAssertions; - return {{"remove_dead_bindings", RemoveDeadBindings}, {"enable_imgui_assertions", EnableImGuiAssertions}, - {"dump_game_options", DumpGameOptions}, {"max_lines_console_history", MaxLinesConsoleHistory}, {"persistent_console", PersistentConsole}}; + return {{"remove_dead_bindings", RemoveDeadBindings}, {"enable_imgui_assertions", EnableImGuiAssertions}, {"dump_game_options", DumpGameOptions}, + {"max_lines_console_history", MaxLinesConsoleHistory}, {"persistent_console", PersistentConsole}, {"enable_jit", EnableJIT}}; } void DeveloperSettings::ResetToDefaults() diff --git a/src/Options.h b/src/Options.h index 7b01a506..97c870f7 100644 --- a/src/Options.h +++ b/src/Options.h @@ -50,6 +50,7 @@ struct DeveloperSettings bool DumpGameOptions{false}; uint64_t MaxLinesConsoleHistory{1000}; bool PersistentConsole{true}; + bool EnableJIT{true}; }; struct Options diff --git a/src/overlay/widgets/Settings.cpp b/src/overlay/widgets/Settings.cpp index af54fb30..fd49c2f6 100644 --- a/src/overlay/widgets/Settings.cpp +++ b/src/overlay/widgets/Settings.cpp @@ -107,6 +107,9 @@ void Settings::OnUpdate() UpdateAndDrawSetting( "Dump Game Options", "Dumps all game options into main log file (requires restart to take effect).", m_developer.DumpGameOptions, developerSettings.DumpGameOptions); + UpdateAndDrawSetting( + "Enable JIT for Lua", "Enables JIT compiler for Lua VM, which may majorly speed up the mods. Disable it in case you experience issues as a troubleshooting step (requires restart to take effect).", m_developer.EnableJIT, + developerSettings.EnableJIT); ImGui::EndTable(); } From 974ffc454c3f9df5cd724d46c8b378125b93546e Mon Sep 17 00:00:00 2001 From: Andrej Redeky Date: Sun, 29 Oct 2023 16:03:35 +0100 Subject: [PATCH 3/4] Reformat Options.cpp --- src/Options.cpp | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/Options.cpp b/src/Options.cpp index 36674773..fa622720 100644 --- a/src/Options.cpp +++ b/src/Options.cpp @@ -18,14 +18,9 @@ void PatchesSettings::Load(const nlohmann::json& aConfig) nlohmann::json PatchesSettings::Save() const { return { - {"disable_async_compute", AsyncCompute}, - {"disable_antialiasing", Antialiasing}, - {"skip_start_menu", SkipStartMenu}, - {"disable_intro_movies", DisableIntroMovies}, - {"disable_vignette", DisableVignette}, - {"disable_boundary_teleport", DisableBoundaryTeleport}, - {"disable_win7_vsync", DisableWin7Vsync}, - {"minimap_flicker", MinimapFlicker}, + {"disable_async_compute", AsyncCompute}, {"disable_antialiasing", Antialiasing}, {"skip_start_menu", SkipStartMenu}, + {"disable_intro_movies", DisableIntroMovies}, {"disable_vignette", DisableVignette}, {"disable_boundary_teleport", DisableBoundaryTeleport}, + {"disable_win7_vsync", DisableWin7Vsync}, {"minimap_flicker", MinimapFlicker}, }; } From e204a6db14d5f39fe09f9fd69f9803261f337b08 Mon Sep 17 00:00:00 2001 From: Andrej Redeky Date: Sun, 29 Oct 2023 16:09:42 +0100 Subject: [PATCH 4/4] Use the new EnableJIT setting to conditionaly enable JIT --- src/CET.cpp | 2 +- src/scripting/LuaVM.h | 2 +- src/scripting/LuaVM_Hooks.cpp | 4 ++-- src/scripting/Scripting.cpp | 9 +++++++-- src/scripting/Scripting.h | 3 ++- 5 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/CET.cpp b/src/CET.cpp index db2b02a8..9ec5caf6 100644 --- a/src/CET.cpp +++ b/src/CET.cpp @@ -71,7 +71,7 @@ CET::CET() , m_bindings(m_paths, m_options) , m_window(&m_bindings, &m_d3d12) , m_d3d12(m_window, m_paths, m_options) - , m_vm(m_paths, m_bindings, m_d3d12) + , m_vm(m_paths, m_options, m_bindings, m_d3d12) , m_overlay(m_bindings, m_options, m_persistentState, m_vm) { } diff --git a/src/scripting/LuaVM.h b/src/scripting/LuaVM.h index c0881ac6..be8d4291 100644 --- a/src/scripting/LuaVM.h +++ b/src/scripting/LuaVM.h @@ -25,7 +25,7 @@ struct TDBIDLookupEntry struct Image; struct LuaVM { - LuaVM(const Paths& aPaths, VKBindings& aBindings, D3D12& aD3D12); + LuaVM(const Paths& aPaths, const Options& aOptions, VKBindings& aBindings, D3D12& aD3D12); ~LuaVM() = default; [[nodiscard]] const VKBind* GetBind(const VKModBind& acModBind) const; diff --git a/src/scripting/LuaVM_Hooks.cpp b/src/scripting/LuaVM_Hooks.cpp index 088dd305..a7bb3693 100644 --- a/src/scripting/LuaVM_Hooks.cpp +++ b/src/scripting/LuaVM_Hooks.cpp @@ -258,8 +258,8 @@ void LuaVM::HookLogChannel(RED4ext::IScriptable*, RED4ext::CStackFrame* apStack, } } -LuaVM::LuaVM(const Paths& aPaths, VKBindings& aBindings, D3D12& aD3D12) - : m_scripting(aPaths, aBindings, aD3D12) +LuaVM::LuaVM(const Paths& aPaths, const Options& aOptions, VKBindings& aBindings, D3D12& aD3D12) + : m_scripting(aPaths, aOptions, aBindings, aD3D12) , m_d3d12(aD3D12) { Hook(); diff --git a/src/scripting/Scripting.cpp b/src/scripting/Scripting.cpp index ddf27d01..89a92b40 100644 --- a/src/scripting/Scripting.cpp +++ b/src/scripting/Scripting.cpp @@ -32,12 +32,13 @@ static constexpr bool s_cThrowLuaErrors = true; static RTTILocator s_stringType{RED4ext::FNV1a64("String")}; static RTTILocator s_resRefType{RED4ext::FNV1a64("redResourceReferenceScriptToken")}; -Scripting::Scripting(const Paths& aPaths, VKBindings& aBindings, D3D12& aD3D12) +Scripting::Scripting(const Paths& aPaths, const Options& aOptions, VKBindings& aBindings, D3D12& aD3D12) : m_sandbox(this, aBindings) , m_mapper(m_lua.AsRef(), m_sandbox) , m_store(m_sandbox, aPaths, aBindings) , m_override(this) , m_paths(aPaths) + , m_options(aOptions) , m_d3d12(aD3D12) { CreateLogger(aPaths.CETRoot() / "scripting.log", "scripting"); @@ -49,7 +50,11 @@ void Scripting::Initialize() auto lua = m_lua.Lock(); auto& luaVm = lua.Get(); - luaVm.open_libraries(sol::lib::base, sol::lib::string, sol::lib::io, sol::lib::math, sol::lib::package, sol::lib::os, sol::lib::table, sol::lib::bit32, sol::lib::jit); + luaVm.open_libraries(sol::lib::base, sol::lib::string, sol::lib::io, sol::lib::math, sol::lib::package, sol::lib::os, sol::lib::table, sol::lib::bit32); + + if (m_options.Developer.EnableJIT) + luaVm.open_libraries(sol::lib::jit); + luaVm.require("sqlite3", luaopen_lsqlite3); // make sure to set package path to current directory scope diff --git a/src/scripting/Scripting.h b/src/scripting/Scripting.h index 23938306..b6d25600 100644 --- a/src/scripting/Scripting.h +++ b/src/scripting/Scripting.h @@ -11,7 +11,7 @@ struct Scripting { using LockedState = TiltedPhoques::Locked; - Scripting(const Paths& aPaths, VKBindings& aBindings, D3D12& aD3D12); + Scripting(const Paths& aPaths, const Options& aOptions, VKBindings& aBindings, D3D12& aD3D12); ~Scripting() = default; void Initialize(); @@ -61,5 +61,6 @@ struct Scripting ScriptStore m_store; FunctionOverride m_override; const Paths& m_paths; + const Options& m_options; D3D12& m_d3d12; };