From f5ad14b109fc90d291d5937e07ee8463d7da1169 Mon Sep 17 00:00:00 2001 From: Quantum Date: Mon, 19 Jul 2021 19:42:20 -0400 Subject: [PATCH] [host] windows: directly link D3DKMTSetProcessSchedulingPriorityClass This function is available since Windows Vista and can therefore be used directly without going through GetProcAddress. Unfortunately, MinGW does not have d3dkmthk.h, but we can declare the prototype ourselves and link against gdi32.dll. --- host/platform/Windows/src/platform.c | 42 +++++++++++----------------- 1 file changed, 17 insertions(+), 25 deletions(-) diff --git a/host/platform/Windows/src/platform.c b/host/platform/Windows/src/platform.c index e7e93842..10b86a9d 100644 --- a/host/platform/Windows/src/platform.c +++ b/host/platform/Windows/src/platform.c @@ -504,33 +504,25 @@ finish: return result; } +typedef enum _D3DKMT_SCHEDULINGPRIORITYCLASS +{ + D3DKMT_SCHEDULINGPRIORITYCLASS_IDLE = 0, + D3DKMT_SCHEDULINGPRIORITYCLASS_BELOW_NORMAL = 1, + D3DKMT_SCHEDULINGPRIORITYCLASS_NORMAL = 2, + D3DKMT_SCHEDULINGPRIORITYCLASS_ABOVE_NORMAL = 3, + D3DKMT_SCHEDULINGPRIORITYCLASS_HIGH = 4, + D3DKMT_SCHEDULINGPRIORITYCLASS_REALTIME = 5, +} +D3DKMT_SCHEDULINGPRIORITYCLASS; + +NTSTATUS APIENTRY D3DKMTSetProcessSchedulingPriorityClass( + _In_ HANDLE, _In_ D3DKMT_SCHEDULINGPRIORITYCLASS +); + void boostPriority(void) { - typedef enum _D3DKMT_SCHEDULINGPRIORITYCLASS - { - D3DKMT_SCHEDULINGPRIORITYCLASS_IDLE, - D3DKMT_SCHEDULINGPRIORITYCLASS_BELOW_NORMAL, - D3DKMT_SCHEDULINGPRIORITYCLASS_NORMAL, - D3DKMT_SCHEDULINGPRIORITYCLASS_ABOVE_NORMAL, - D3DKMT_SCHEDULINGPRIORITYCLASS_HIGH, - D3DKMT_SCHEDULINGPRIORITYCLASS_REALTIME - } - D3DKMT_SCHEDULINGPRIORITYCLASS; - typedef NTSTATUS WINAPI (*PD3DKMTSetProcessSchedulingPriorityClass) - (HANDLE, D3DKMT_SCHEDULINGPRIORITYCLASS); - - HMODULE gdi32 = GetModuleHandleA("GDI32"); - if (!gdi32) - return; - - PD3DKMTSetProcessSchedulingPriorityClass fn = - (PD3DKMTSetProcessSchedulingPriorityClass) - GetProcAddress(gdi32, "D3DKMTSetProcessSchedulingPriorityClass"); - - if (!fn) - return; - - if (FAILED(fn(GetCurrentProcess(), D3DKMT_SCHEDULINGPRIORITYCLASS_REALTIME))) + if (FAILED(D3DKMTSetProcessSchedulingPriorityClass(GetCurrentProcess(), + D3DKMT_SCHEDULINGPRIORITYCLASS_REALTIME))) { DEBUG_WARN("Failed to set realtime GPU priority."); DEBUG_INFO("This is not a failure, please do not report this as an issue.");