1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-15 13:47:24 +08:00

Add extended logging to NVAPI operations

To help diagnose https://github.com/ppy/osu/issues/30546.
This commit is contained in:
Bartłomiej Dach 2024-11-08 10:00:21 +01:00
parent ce9c74af85
commit d8fc7b1803
No known key found for this signature in database

View File

@ -141,12 +141,12 @@ namespace osu.Desktop
// Make sure that this is a laptop. // Make sure that this is a laptop.
IntPtr[] gpus = new IntPtr[64]; IntPtr[] gpus = new IntPtr[64];
if (checkError(EnumPhysicalGPUs(gpus, out int gpuCount))) if (checkError(EnumPhysicalGPUs(gpus, out int gpuCount), nameof(EnumPhysicalGPUs)))
return false; return false;
for (int i = 0; i < gpuCount; i++) for (int i = 0; i < gpuCount; i++)
{ {
if (checkError(GetSystemType(gpus[i], out var type))) if (checkError(GetSystemType(gpus[i], out var type), nameof(GetSystemType)))
return false; return false;
if (type == NvSystemType.LAPTOP) if (type == NvSystemType.LAPTOP)
@ -182,7 +182,7 @@ namespace osu.Desktop
bool success = setSetting(NvSettingID.OGL_THREAD_CONTROL_ID, (uint)value); bool success = setSetting(NvSettingID.OGL_THREAD_CONTROL_ID, (uint)value);
Logger.Log(success ? $"Threaded optimizations set to \"{value}\"!" : "Threaded optimizations set failed!"); Logger.Log(success ? $"[NVAPI] Threaded optimizations set to \"{value}\"!" : "[NVAPI] Threaded optimizations set failed!");
} }
} }
@ -205,7 +205,7 @@ namespace osu.Desktop
uint numApps = profile.NumOfApps; uint numApps = profile.NumOfApps;
if (checkError(EnumApplications(sessionHandle, profileHandle, 0, ref numApps, applications))) if (checkError(EnumApplications(sessionHandle, profileHandle, 0, ref numApps, applications), nameof(EnumApplications)))
return false; return false;
for (uint i = 0; i < numApps; i++) for (uint i = 0; i < numApps; i++)
@ -236,10 +236,10 @@ namespace osu.Desktop
isApplicationSpecific = true; isApplicationSpecific = true;
if (checkError(FindApplicationByName(sessionHandle, osu_filename, out profileHandle, ref application))) if (checkError(FindApplicationByName(sessionHandle, osu_filename, out profileHandle, ref application), nameof(FindApplicationByName)))
{ {
isApplicationSpecific = false; isApplicationSpecific = false;
if (checkError(GetCurrentGlobalProfile(sessionHandle, out profileHandle))) if (checkError(GetCurrentGlobalProfile(sessionHandle, out profileHandle), nameof(GetCurrentGlobalProfile)))
return false; return false;
} }
@ -263,7 +263,7 @@ namespace osu.Desktop
newProfile.GPUSupport[0] = 1; newProfile.GPUSupport[0] = 1;
if (checkError(CreateProfile(sessionHandle, ref newProfile, out profileHandle))) if (checkError(CreateProfile(sessionHandle, ref newProfile, out profileHandle), nameof(CreateProfile)))
return false; return false;
return true; return true;
@ -284,7 +284,7 @@ namespace osu.Desktop
SettingID = settingId SettingID = settingId
}; };
if (checkError(GetSetting(sessionHandle, profileHandle, settingId, ref setting))) if (checkError(GetSetting(sessionHandle, profileHandle, settingId, ref setting), nameof(GetSetting)))
return false; return false;
return true; return true;
@ -313,7 +313,7 @@ namespace osu.Desktop
}; };
// Set the thread state // Set the thread state
if (checkError(SetSetting(sessionHandle, profileHandle, ref newSetting))) if (checkError(SetSetting(sessionHandle, profileHandle, ref newSetting), nameof(SetSetting)))
return false; return false;
// Get the profile (needed to check app count) // Get the profile (needed to check app count)
@ -321,7 +321,7 @@ namespace osu.Desktop
{ {
Version = NvProfile.Stride Version = NvProfile.Stride
}; };
if (checkError(GetProfileInfo(sessionHandle, profileHandle, ref profile))) if (checkError(GetProfileInfo(sessionHandle, profileHandle, ref profile), nameof(GetProfileInfo)))
return false; return false;
if (!containsApplication(profileHandle, profile, out application)) if (!containsApplication(profileHandle, profile, out application))
@ -332,12 +332,12 @@ namespace osu.Desktop
application.AppName = osu_filename; application.AppName = osu_filename;
application.UserFriendlyName = APPLICATION_NAME; application.UserFriendlyName = APPLICATION_NAME;
if (checkError(CreateApplication(sessionHandle, profileHandle, ref application))) if (checkError(CreateApplication(sessionHandle, profileHandle, ref application), nameof(CreateApplication)))
return false; return false;
} }
// Save! // Save!
return !checkError(SaveSettings(sessionHandle)); return !checkError(SaveSettings(sessionHandle), nameof(SaveSettings));
} }
/// <summary> /// <summary>
@ -346,20 +346,25 @@ namespace osu.Desktop
/// <returns>If the operation succeeded.</returns> /// <returns>If the operation succeeded.</returns>
private static bool createSession() private static bool createSession()
{ {
if (checkError(CreateSession(out sessionHandle))) if (checkError(CreateSession(out sessionHandle), nameof(CreateSession)))
return false; return false;
// Load settings into session // Load settings into session
if (checkError(LoadSettings(sessionHandle))) if (checkError(LoadSettings(sessionHandle), nameof(LoadSettings)))
return false; return false;
return true; return true;
} }
private static bool checkError(NvStatus status) private static bool checkError(NvStatus status, string caller)
{ {
Status = status; Status = status;
return status != NvStatus.OK;
bool hasError = status != NvStatus.OK;
if (hasError)
Logger.Log($"[NVAPI] {caller} call failed with status code {status}");
return hasError;
} }
static NVAPI() static NVAPI()