Skip to content

Commit fb61d8b

Browse files
aitorcikimandryskowski
authored andcommitted
[Windows] Fix not applying NVIDIA profile to new executables
An NVIDIA profile is applied to the current executable to disable threaded OpenGL optimizations on Windows (see godotengine#71472). But because the application is only added to the profile upon the profile creation, newer executables won't be added to the profile (e.g. if the profile is created on first launch of Godot_v4.1-stable_win64.exe, when users update the editor and launch Godot_v4.2-stable_win64.exe, the profile will never be applied to this new executable). This patch fixes that scenario by splitting creating the profile (if it doesn't exist) and adding the application (if it doesn't have a profile applied) into two separate steps. Applications that have been manually added to a different profile aren't overriden to avoid confusing users who know what they're doing.
1 parent 48608e4 commit fb61d8b

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

platform/windows/gl_manager_windows_native.cpp

+14-4
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ typedef int(__cdecl *NvAPI_DRS_CreateApplication_t)(NvDRSSessionHandle, NvDRSPro
8888
typedef int(__cdecl *NvAPI_DRS_SaveSettings_t)(NvDRSSessionHandle);
8989
typedef int(__cdecl *NvAPI_DRS_SetSetting_t)(NvDRSSessionHandle, NvDRSProfileHandle, NVDRS_SETTING *);
9090
typedef int(__cdecl *NvAPI_DRS_FindProfileByName_t)(NvDRSSessionHandle, NvAPI_UnicodeString, NvDRSProfileHandle *);
91+
typedef int(__cdecl *NvAPI_DRS_FindApplicationByName_t)(NvDRSSessionHandle, NvAPI_UnicodeString, NvDRSProfileHandle *, NVDRS_APPLICATION *);
9192
NvAPI_GetErrorMessage_t NvAPI_GetErrorMessage__;
9293

9394
static bool nvapi_err_check(const char *msg, int status) {
@@ -138,6 +139,7 @@ void GLManagerNative_Windows::_nvapi_disable_threaded_optimization() {
138139
NvAPI_DRS_SaveSettings_t NvAPI_DRS_SaveSettings = (NvAPI_DRS_SaveSettings_t)NvAPI_QueryInterface(0xFCBC7E14);
139140
NvAPI_DRS_SetSetting_t NvAPI_DRS_SetSetting = (NvAPI_DRS_SetSetting_t)NvAPI_QueryInterface(0x577DD202);
140141
NvAPI_DRS_FindProfileByName_t NvAPI_DRS_FindProfileByName = (NvAPI_DRS_FindProfileByName_t)NvAPI_QueryInterface(0x7E4A9A0B);
142+
NvAPI_DRS_FindApplicationByName_t NvAPI_DRS_FindApplicationByName = (NvAPI_DRS_FindApplicationByName_t)NvAPI_QueryInterface(0xEEE566B2);
141143

142144
if (!nvapi_err_check("NVAPI: Init failed", NvAPI_Initialize())) {
143145
return;
@@ -172,9 +174,9 @@ void GLManagerNative_Windows::_nvapi_disable_threaded_optimization() {
172174

173175
NvDRSProfileHandle profile_handle = 0;
174176

175-
int status = NvAPI_DRS_FindProfileByName(session_handle, (NvU16 *)(app_profile_name_u16.ptrw()), &profile_handle);
177+
int profile_status = NvAPI_DRS_FindProfileByName(session_handle, (NvU16 *)(app_profile_name_u16.ptrw()), &profile_handle);
176178

177-
if (status != 0) {
179+
if (profile_status != 0) {
178180
print_verbose("NVAPI: Profile not found, creating....");
179181

180182
NVDRS_PROFILE profile_info;
@@ -187,9 +189,17 @@ void GLManagerNative_Windows::_nvapi_disable_threaded_optimization() {
187189
NvAPI_Unload();
188190
return;
189191
}
192+
}
193+
194+
NvDRSProfileHandle app_profile_handle = 0;
195+
NVDRS_APPLICATION_V4 app;
196+
app.version = NVDRS_APPLICATION_VER_V4;
197+
198+
int app_status = NvAPI_DRS_FindApplicationByName(session_handle, (NvU16 *)(app_executable_name_u16.ptrw()), &app_profile_handle, &app);
199+
200+
if (app_status != 0) {
201+
print_verbose("NVAPI: Application not found, adding to profile...");
190202

191-
NVDRS_APPLICATION_V4 app;
192-
app.version = NVDRS_APPLICATION_VER_V4;
193203
app.isPredefined = 0;
194204
app.isMetro = 1;
195205
app.isCommandLine = 1;

0 commit comments

Comments
 (0)