From 1a137f3c083e15e9d17f2fef4c9af61f73ad58d6 Mon Sep 17 00:00:00 2001 From: Quantum Date: Wed, 3 Jun 2026 00:27:29 -0400 Subject: [PATCH] [idd] helper: detect if system has GPU --- idd/LGIddHelper/CNotifyWindow.cpp | 9 ++ idd/LGIddHelper/Devices.cpp | 106 ++++++++++++++++++++ idd/LGIddHelper/Devices.h | 23 +++++ idd/LGIddHelper/LGIddHelper.vcxproj | 2 + idd/LGIddHelper/LGIddHelper.vcxproj.filters | 22 ++++ 5 files changed, 162 insertions(+) create mode 100644 idd/LGIddHelper/Devices.cpp create mode 100644 idd/LGIddHelper/Devices.h diff --git a/idd/LGIddHelper/CNotifyWindow.cpp b/idd/LGIddHelper/CNotifyWindow.cpp index 118cbf4c..34b90526 100644 --- a/idd/LGIddHelper/CNotifyWindow.cpp +++ b/idd/LGIddHelper/CNotifyWindow.cpp @@ -20,6 +20,7 @@ #include "CNotifyWindow.h" #include "CConfigWindow.h" +#include "Devices.h" #include #include #include @@ -161,6 +162,14 @@ void CNotifyWindow::registerIcon() if (!Shell_NotifyIcon(NIM_SETVERSION, &m_iconData)) DEBUG_ERROR_HR(GetLastError(), "Shell_NotifyIcon(NIM_SETVERSION)"); + + bool hasGPU; + if (!checkGPU(hasGPU)) + DEBUG_ERROR("Failed to check if the system has a GPU"); + else if (hasGPU) + DEBUG_INFO("GPU identified"); + else + DEBUG_INFO("System has no GPU"); } HWND CNotifyWindow::hwndDialog() diff --git a/idd/LGIddHelper/Devices.cpp b/idd/LGIddHelper/Devices.cpp new file mode 100644 index 00000000..f6c9f39d --- /dev/null +++ b/idd/LGIddHelper/Devices.cpp @@ -0,0 +1,106 @@ +/** + * Looking Glass + * Copyright © 2017-2026 The Looking Glass Authors + * https://looking-glass.io + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., 59 + * Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "Devices.h" +#include +#include +#include +#include + +inline static bool wprefix(const wchar_t *pre, const wchar_t *str) +{ + return wcsncmp(pre, str, wcslen(pre)) == 0; +} + +bool checkGPU(bool &found) +{ + found = false; + + HDEVINFO hDevInfo = SetupDiGetClassDevsW(&GUID_DEVCLASS_DISPLAY, NULL, NULL, DIGCF_PRESENT); + if (hDevInfo == INVALID_HANDLE_VALUE) + { + DEBUG_WARN_HR(GetLastError(), L"SetupDiGetClassDevsW"); + return false; + } + + SP_DEVINFO_DATA devInfo = { 0 }; + devInfo.cbSize = sizeof devInfo; + + for (DWORD dwIndex = 0; SetupDiEnumDeviceInfo(hDevInfo, dwIndex, &devInfo); ++dwIndex) + { + DWORD dwSizeRequired; + DWORD dwPropertyType; + SetupDiGetDeviceRegistryPropertyW(hDevInfo, &devInfo, SPDRP_HARDWAREID, &dwPropertyType, NULL, 0, &dwSizeRequired); + + DWORD dwLastError = GetLastError(); + if (dwLastError == ERROR_INVALID_DATA) + continue; + else if (dwLastError != ERROR_INSUFFICIENT_BUFFER) + { + DEBUG_WARN_HR(GetLastError(), L"SetupDiGetDeviceRegistryPropertyW(SPDRP_HARDWAREID) size calculation"); + goto fail; + } + + if (dwPropertyType != REG_MULTI_SZ) + { + DEBUG_WARN(L"SetupDiGetDeviceRegistryPropertyW(SPDRP_HARDWAREID) returned wrong type"); + goto fail; + } + + LPWSTR lpBuffer = (LPWSTR)malloc(dwSizeRequired); + if (!lpBuffer) + { + DEBUG_WARN(L"failed to allocate memory for SetupDiGetDeviceRegistryPropertyW(SPDRP_HARDWAREID)"); + goto fail; + } + + if (!SetupDiGetDeviceRegistryPropertyW(hDevInfo, &devInfo, SPDRP_HARDWAREID, &dwPropertyType, (PBYTE)lpBuffer, dwSizeRequired, NULL)) + { + DEBUG_WARN_HR(GetLastError(), L"SetupDiGetDeviceRegistryPropertyW(SPDRP_HARDWAREID) for real"); + free(lpBuffer); + goto fail; + } + + for (LPWSTR lpHwId = lpBuffer; *lpHwId; lpHwId += wcslen(lpBuffer) + 1) + { + if ( + wprefix(L"PCI\\VEN_10DE&", lpHwId) || // Nvidia + wprefix(L"PCI\\VEN_1002&", lpHwId) || // AMD + wprefix(L"PCI\\VEN_8086&", lpHwId) // Intel + ) + { + found = true; + break; + } + } + + free(lpBuffer); + + if (found) + break; + } + + SetupDiDestroyDeviceInfoList(hDevInfo); + return true; + +fail: + SetupDiDestroyDeviceInfoList(hDevInfo); + return false; +} diff --git a/idd/LGIddHelper/Devices.h b/idd/LGIddHelper/Devices.h new file mode 100644 index 00000000..2951be2e --- /dev/null +++ b/idd/LGIddHelper/Devices.h @@ -0,0 +1,23 @@ +/** + * Looking Glass + * Copyright © 2017-2026 The Looking Glass Authors + * https://looking-glass.io + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., 59 + * Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#pragma once + +bool checkGPU(bool &found); diff --git a/idd/LGIddHelper/LGIddHelper.vcxproj b/idd/LGIddHelper/LGIddHelper.vcxproj index 08c39fce..5bdb657b 100644 --- a/idd/LGIddHelper/LGIddHelper.vcxproj +++ b/idd/LGIddHelper/LGIddHelper.vcxproj @@ -190,6 +190,7 @@ copy /Y "$(ProjectDir)VERSION" "$(SolutionDir)$(Platform)\$(Configuration)\LGIdd + @@ -205,6 +206,7 @@ copy /Y "$(ProjectDir)VERSION" "$(SolutionDir)$(Platform)\$(Configuration)\LGIdd + diff --git a/idd/LGIddHelper/LGIddHelper.vcxproj.filters b/idd/LGIddHelper/LGIddHelper.vcxproj.filters index f9146e12..97b59054 100644 --- a/idd/LGIddHelper/LGIddHelper.vcxproj.filters +++ b/idd/LGIddHelper/LGIddHelper.vcxproj.filters @@ -53,6 +53,16 @@ Source Files + + + Source Files + + + Source Files + + + Source Files + @@ -94,6 +104,18 @@ Header Files + + + + + Header Files + + + Header Files + + + Header Files +