2022-04-11 22:38:41 +02:00

133 lines
4.1 KiB
Diff

From 3077827d8145f4689b6f43db9924dd71d9963b5d Mon Sep 17 00:00:00 2001
From: badlogic <badlogicgames@gmail.com>
Date: Mon, 11 Apr 2022 13:33:10 +0200
Subject: [PATCH] Add support for Live++ on Windows
When the LIVEPP_PATH environment variable is set, the build adds a CPPDEFINE called LIVEPP_PATH, which then triggers setup, synchronization, and tear down of Live++.
Improve inclusion of Live++ API header as per PR review.
Still requires a separate wide char version of _MKSTR as that's what lpp::lppLoadAndRegister requires.
Use build option livepp instead of environment variable LIVEPP_PATH
E.g. `scons livepp=c:/tools/LivePP`
---
platform/windows/detect.py | 13 ++++++++++++-
platform/windows/godot_windows.cpp | 20 ++++++++++++++++++++
platform/windows/os_windows.cpp | 8 ++++++++
3 files changed, 40 insertions(+), 1 deletion(-)
diff --git a/platform/windows/detect.py b/platform/windows/detect.py
index 249a0d2e79..fb42edff8b 100644
--- a/platform/windows/detect.py
+++ b/platform/windows/detect.py
@@ -44,7 +44,7 @@ def can_build():
def get_opts():
- from SCons.Variables import BoolVariable, EnumVariable
+ from SCons.Variables import BoolVariable, EnumVariable, PathVariable
mingw32 = ""
mingw64 = ""
@@ -73,6 +73,7 @@ def get_opts():
BoolVariable("use_thinlto", "Use ThinLTO", False),
BoolVariable("use_static_cpp", "Link MinGW/MSVC C++ runtime libraries statically", True),
BoolVariable("use_asan", "Use address sanitizer (ASAN)", False),
+ PathVariable("livepp", "Path to the Live++ installation", "", PathVariable.PathAccept),
]
@@ -309,6 +310,16 @@ def configure_msvc(env, manual_msvc_config):
env.AppendUnique(LINKFLAGS=["/STACK:" + str(STACK_SIZE)])
+ # Check if LIVEPP_PATH is set and add #define. Perform
+ # some sanity checks.
+ if env.get("livepp"):
+ if env["target"] == "release_debug" or env["target"] == "debug":
+ print("Found Live++ at %s" % env.get("livepp"))
+ env.AppendUnique(CPPDEFINES=["LIVEPP_PATH=%s" % env.get("livepp")])
+ env.AppendUnique(CPPPATH=[env.get("livepp")])
+ env.AppendUnique(LINKFLAGS=["/FUNCTIONPADMIN"])
+ else:
+ print("Live++ can only be used with targets 'debug' and 'release_debug'")
def configure_mingw(env):
# Workaround for MinGW. See:
diff --git a/platform/windows/godot_windows.cpp b/platform/windows/godot_windows.cpp
index ad4e3ae77c..0974d3d9ae 100644
--- a/platform/windows/godot_windows.cpp
+++ b/platform/windows/godot_windows.cpp
@@ -34,6 +34,11 @@
#include <locale.h>
#include <stdio.h>
+#ifdef LIVEPP_PATH
+#include "API/LPP_API.h"
+HMODULE livePP;
+#endif
+
// For export templates, add a section; the exporter will patch it to enclose
// the data appended to the executable (bundled PCK)
#ifndef TOOLS_ENABLED
@@ -136,6 +141,16 @@ char *wc_to_utf8(const wchar_t *wc) {
}
int widechar_main(int argc, wchar_t **argv) {
+#ifdef LIVEPP_PATH
+#define _MKSTR_L(x) _STR_L(x)
+#define _STR_L(x) L#x
+ livePP = lpp::lppLoadAndRegister(_MKSTR_L(LIVEPP_PATH), "Godot");
+ lpp::lppEnableAllCallingModulesSync(livePP);
+ lpp::lppInstallExceptionHandler(livePP);
+#undef _MKSTR_L
+#undef _STR_L
+#endif
+
OS_Windows os(nullptr);
setlocale(LC_CTYPE, "");
@@ -173,6 +188,11 @@ int widechar_main(int argc, wchar_t **argv) {
}
delete[] argv_utf8;
+#ifdef LIVEPP_PATH
+ lpp::lppShutdown(livePP);
+ ::FreeLibrary(livePP);
+#endif
+
return os.get_exit_code();
}
diff --git a/platform/windows/os_windows.cpp b/platform/windows/os_windows.cpp
index b4669e452a..42f675598a 100644
--- a/platform/windows/os_windows.cpp
+++ b/platform/windows/os_windows.cpp
@@ -53,6 +53,11 @@
#include <regstr.h>
#include <shlobj.h>
+#ifdef LIVEPP_PATH
+#include "API/LPP_API.h"
+extern HMODULE livePP;
+#endif
+
extern "C" {
__declspec(dllexport) DWORD NvOptimusEnablement = 1;
__declspec(dllexport) int AmdPowerXpressRequestHighPerformance = 1;
@@ -677,6 +682,9 @@ void OS_Windows::run() {
if (Main::iteration()) {
break;
}
+#ifdef LIVEPP_PATH
+ lpp::lppSyncPoint(livePP);
+#endif
}
main_loop->finalize();
--
2.27.0.windows.1