From 8f29452ca928ba52156bfff9f8102ee3dd14ad8a Mon Sep 17 00:00:00 2001 From: Matt Borgerson Date: Thu, 10 Jul 2025 13:38:16 -0700 Subject: [PATCH] ui: Initialize preferred xemu NVIDIA application profile --- config_spec.yml | 3 +++ ui/xemu.c | 52 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) diff --git a/config_spec.yml b/config_spec.yml index 5b2991390c..68db468d9c 100644 --- a/config_spec.yml +++ b/config_spec.yml @@ -212,6 +212,9 @@ display: advanced_tree_state: type: bool default: false + setup_nvidia_profile: + type: bool + default: true audio: vp: diff --git a/ui/xemu.c b/ui/xemu.c index 3d3c2a9587..81a951d35c 100644 --- a/ui/xemu.c +++ b/ui/xemu.c @@ -61,6 +61,7 @@ #include #ifdef _WIN32 +#include "nvapi.h" // Provide hint to prefer high-performance graphics for hybrid systems // https://gpuopen.com/learn/amdpowerxpressrequesthighperformance/ __declspec(dllexport) DWORD AmdPowerXpressRequestHighPerformance = 1; @@ -1265,6 +1266,51 @@ static void sleep_ns(int64_t ns) #endif } +#ifdef _WIN32 +static const wchar_t *get_executable_name(void) +{ + static wchar_t exe_name[MAX_PATH] = { 0 }; + static bool initialized = false; + + if (!initialized) { + wchar_t full_path[MAX_PATH]; + DWORD length = GetModuleFileNameW(NULL, full_path, MAX_PATH); + if (length == 0 || length == MAX_PATH) { + return NULL; + } + + wchar_t *last_slash = wcsrchr(full_path, L'\\'); + if (last_slash) { + wcsncpy_s(exe_name, MAX_PATH, last_slash + 1, _TRUNCATE); + } else { + wcsncpy_s(exe_name, MAX_PATH, full_path, _TRUNCATE); + } + + initialized = true; + } + + return exe_name; +} + +static void setup_nvidia_profile(void) +{ + const wchar_t *exe_name = get_executable_name(); + if (exe_name == NULL) { + fprintf(stderr, "Failed to get current executable name\n"); + return; + } + + if (nvapi_init()) { + nvapi_setup_profile((NvApiProfileOpts){ + .profile_name = L"xemu", + .executable_name = exe_name, + .threaded_optimization = false, + }); + nvapi_finalize(); + } +} +#endif + int main(int argc, char **argv) { QemuThread thread; @@ -1324,6 +1370,12 @@ int main(int argc, char **argv) } atexit(xemu_settings_save); +#ifdef _WIN32 + if (g_config.display.setup_nvidia_profile) { + setup_nvidia_profile(); + } +#endif + sdl2_display_very_early_init(NULL); qemu_sem_init(&display_init_sem, 0);