Skip to content

Commit

Permalink
Merge pull request #81251 from aitorciki/nvidia-profile-multiapp
Browse files Browse the repository at this point in the history
[Windows] Fix not applying NVIDIA profile to new executables
  • Loading branch information
akien-mga committed Sep 24, 2023
2 parents 42fb795 + 6263774 commit b8238ec
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions platform/windows/gl_manager_windows_native.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ typedef int(__cdecl *NvAPI_DRS_CreateApplication_t)(NvDRSSessionHandle, NvDRSPro
typedef int(__cdecl *NvAPI_DRS_SaveSettings_t)(NvDRSSessionHandle);
typedef int(__cdecl *NvAPI_DRS_SetSetting_t)(NvDRSSessionHandle, NvDRSProfileHandle, NVDRS_SETTING *);
typedef int(__cdecl *NvAPI_DRS_FindProfileByName_t)(NvDRSSessionHandle, NvAPI_UnicodeString, NvDRSProfileHandle *);
typedef int(__cdecl *NvAPI_DRS_FindApplicationByName_t)(NvDRSSessionHandle, NvAPI_UnicodeString, NvDRSProfileHandle *, NVDRS_APPLICATION *);
NvAPI_GetErrorMessage_t NvAPI_GetErrorMessage__;

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

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

NvDRSProfileHandle profile_handle = 0;

int status = NvAPI_DRS_FindProfileByName(session_handle, (NvU16 *)(app_profile_name_u16.ptrw()), &profile_handle);
int profile_status = NvAPI_DRS_FindProfileByName(session_handle, (NvU16 *)(app_profile_name_u16.ptrw()), &profile_handle);

if (status != 0) {
if (profile_status != 0) {
print_verbose("NVAPI: Profile not found, creating....");

NVDRS_PROFILE profile_info;
Expand All @@ -187,9 +189,17 @@ void GLManagerNative_Windows::_nvapi_disable_threaded_optimization() {
NvAPI_Unload();
return;
}
}

NvDRSProfileHandle app_profile_handle = 0;
NVDRS_APPLICATION_V4 app;
app.version = NVDRS_APPLICATION_VER_V4;

int app_status = NvAPI_DRS_FindApplicationByName(session_handle, (NvU16 *)(app_executable_name_u16.ptrw()), &app_profile_handle, &app);

if (app_status != 0) {
print_verbose("NVAPI: Application not found, adding to profile...");

NVDRS_APPLICATION_V4 app;
app.version = NVDRS_APPLICATION_VER_V4;
app.isPredefined = 0;
app.isMetro = 1;
app.isCommandLine = 1;
Expand Down

0 comments on commit b8238ec

Please sign in to comment.