diff --git a/host/platform/Windows/capture/DXGI/src/dxgi.c b/host/platform/Windows/capture/DXGI/src/dxgi.c index c3f00613..f682d5c4 100644 --- a/host/platform/Windows/capture/DXGI/src/dxgi.c +++ b/host/platform/Windows/capture/DXGI/src/dxgi.c @@ -37,18 +37,6 @@ #include "dxgi_extra.h" -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); - #define LOCKED(x) INTERLOCKED_SECTION(this->deviceContextLock, x) enum TextureState @@ -433,39 +421,6 @@ static bool dxgi_init(void) DEBUG_INFO("Capture Size : %u x %u", this->width, this->height); DEBUG_INFO("AcquireLock : %s" , this->useAcquireLock ? "enabled" : "disabled"); - // bump up our priority - { - HMODULE gdi32 = GetModuleHandleA("GDI32"); - if (gdi32) - { - PD3DKMTSetProcessSchedulingPriorityClass fn = - (PD3DKMTSetProcessSchedulingPriorityClass)GetProcAddress(gdi32, "D3DKMTSetProcessSchedulingPriorityClass"); - - if (fn) - { - status = fn(GetCurrentProcess(), D3DKMT_SCHEDULINGPRIORITYCLASS_REALTIME); - if (FAILED(status)) - { - DEBUG_WARN("Failed to set realtime GPU priority."); - DEBUG_INFO("This is not a failure, please do not report this as an issue."); - DEBUG_INFO("To fix this, install and run the Looking Glass host as a service."); - DEBUG_INFO("looking-glass-host.exe InstallService"); - } - } - } - - IDXGIDevice * dxgi; - status = ID3D11Device_QueryInterface(this->device, &IID_IDXGIDevice, (void **)&dxgi); - if (FAILED(status)) - { - DEBUG_WINERROR("failed to query DXGI interface from device", status); - goto fail; - } - - IDXGIDevice_SetGPUThreadPriority(dxgi, 7); - IDXGIDevice_Release(dxgi); - } - // try to reduce the latency { IDXGIDevice1 * dxgi; diff --git a/host/platform/Windows/src/platform.c b/host/platform/Windows/src/platform.c index a3abf88c..9b291f32 100644 --- a/host/platform/Windows/src/platform.c +++ b/host/platform/Windows/src/platform.c @@ -467,6 +467,41 @@ finish: return result; } +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))) + { + DEBUG_WARN("Failed to set realtime GPU priority."); + DEBUG_INFO("This is not a failure, please do not report this as an issue."); + DEBUG_INFO("To fix this, install and run the Looking Glass host as a service."); + DEBUG_INFO("looking-glass-host.exe InstallService"); + } +} + bool app_init(void) { const char * logFile = option_get_string("os", "logFile" ); @@ -490,6 +525,9 @@ bool app_init(void) // get the performance frequency for spinlocks QueryPerformanceFrequency(&app.perfFreq); + // try to boost the scheduler priority + boostPriority(); + return true; }