Godot Engine – Multi-platform 2D and 3D game engine
Make GPU preference symbols configurable at build time
LanzaSchneidera67c1df697d9
diff --git a/platform/windows/detect.py b/platform/windows/detect.pyindex 19b6d98ee5d..a85976999b3 100644--- a/platform/windows/detect.py+++ b/platform/windows/detect.py@@ -215,6 +215,9 @@ def get_opts():"Path to the PIX runtime distribution (optional for D3D12)",os.path.join(d3d12_deps_folder, "pix"),),+ BoolVariable(+ "prefer_high_performance_gpu", "Prefer high-performance GPU on NVIDIA Optimus/AMD PowerXpress systems", True+ ),]@@ -911,6 +914,9 @@ def configure(env: "SConsEnvironment"):# At this point the env has been set up with basic tools/compilers.env.Prepend(CPPPATH=["#platform/windows"])+ if env["prefer_high_performance_gpu"]:+ env.Append(CPPDEFINES=["ENABLE_PREFER_HIGH_PERFORMANCE_GPU"])+env.msvc = "mingw" not in env["TOOLS"]if env.msvc:configure_msvc(env)diff --git a/platform/windows/os_windows.cpp b/platform/windows/os_windows.cppindex e5f2d7703e3..68f9b693d58 100644--- a/platform/windows/os_windows.cpp+++ b/platform/windows/os_windows.cpp@@ -90,8 +90,10 @@#endifextern "C" {+#ifdef ENABLE_PREFER_HIGH_PERFORMANCE_GPU__declspec(dllexport) DWORD NvOptimusEnablement = 1;__declspec(dllexport) int AmdPowerXpressRequestHighPerformance = 1;+#endif // ENABLE_PREFER_HIGH_PERFORMANCE_GPU__declspec(dllexport) void NoHotPatch() {} // Disable Nahimic code injection.}