diff --git a/CMakeLists.txt b/CMakeLists.txt index 3cdd81e..8816c33 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -31,4 +31,4 @@ add_library(adlx STATIC ${THIRD_PARTY_AMD_INCLUDE} ${THIRD_PARTY_AMD_SRC} ${THIR set_property(TARGET gpu PROPERTY LINK_FLAGS "/DELAYLOAD:nvml.dll") -target_link_libraries(gpu PRIVATE StreamDeckSDK CUDA::nvml adlx d3d12.lib dxgi.lib) \ No newline at end of file +target_link_libraries(gpu PRIVATE StreamDeckSDK CUDA::nvml adlx d3d12.lib dxgi.lib dxcore.lib) \ No newline at end of file diff --git a/Src/GpuPlugin.cpp b/Src/GpuPlugin.cpp index 9d9f1c2..79db767 100644 --- a/Src/GpuPlugin.cpp +++ b/Src/GpuPlugin.cpp @@ -87,22 +87,29 @@ namespace nthompson { void GpuPlugin::FindAvailableGpus() { IDXGIFactory1* factory = nullptr; + winrt::com_ptr coreFactory; - HRESULT result = CreateDXGIFactory1(__uuidof(IDXGIFactory), (void**)&factory); + HRESULT result = CreateDXGIFactory1(__uuidof(IDXGIFactory1), (void**)&factory); if (FAILED(result)) { ESDLog("Failed to create factory object."); return; } + if (FAILED(DXCoreCreateAdapterFactory(coreFactory.put()))) { + ESDLog("Failed to create core factory object."); + return; + } + std::string amd = "amd", advancedMicroDevices = "advanced micro devices", nvidia = "nvidia"; UINT index = 0; - IDXGIAdapter* adapter = nullptr; + IDXGIAdapter1* adapter = nullptr; + winrt::com_ptr coreAdapter = nullptr; - uint32_t nvidiaGpuCount = 0, amdGpuCount = 0, unknownCount = 0; + uint32_t nvidiaGpuCount = 0, amdGpuCount = 0; - while (factory->EnumAdapters(index, &adapter) != DXGI_ERROR_NOT_FOUND) { + while (factory->EnumAdapters1(index, &adapter) != DXGI_ERROR_NOT_FOUND) { DXGI_ADAPTER_DESC desc; adapter->GetDesc(&desc); std::wstring wDescription = desc.Description; @@ -113,6 +120,51 @@ namespace nthompson { std::transform(description.begin(), description.end(), description.begin(), [](char c) { return std::tolower(c); }); + if (FAILED(coreFactory->GetAdapterByLuid(desc.AdapterLuid, coreAdapter.put()))) { + ESDLog("Failed to get core adapter."); + adapter->Release(); + ++index; + continue; + } + + if (!coreAdapter->IsPropertySupported(DXCoreAdapterProperty::IsIntegrated) || !coreAdapter->IsPropertySupported(DXCoreAdapterProperty::IsHardware)) { + ESDLog("Adapter does not support required properties."); + adapter->Release(); + ++index; + continue; + } + + bool isIntegrated = false; + bool isHardwareAdapter; + + if (FAILED(coreAdapter->GetProperty(DXCoreAdapterProperty::IsIntegrated, &isIntegrated))) { + ESDLog("Failed to get integrated property."); + adapter->Release(); + ++index; + continue; + } + + if (FAILED(coreAdapter->GetProperty(DXCoreAdapterProperty::IsHardware, &isHardwareAdapter))) { + ESDLog("Failed to get hardware property."); + adapter->Release(); + ++index; + continue; + } + + if (!isHardwareAdapter) { + ESDLog("Adapter is not a hardware adapter."); + adapter->Release(); + ++index; + continue; + } + + if (isIntegrated) { + ESDLog("Adapter is iGPU."); + adapter->Release(); + ++index; + continue; + } + std::pair item; item.first = desc.DeviceId; @@ -131,14 +183,14 @@ namespace nthompson { ESDLog(gpuLog); amdGpuCount++; } else { - item.second = {GpuVendor::Unknown, gpuName, unknownCount, item.first}; - gpus_.insert(item); ESDLog("Found unsupported display adapter"); - unknownCount++; } ++index; + + adapter->Release(); } + factory->Release(); } void diff --git a/Src/GpuPlugin.h b/Src/GpuPlugin.h index fa39869..2dba531 100644 --- a/Src/GpuPlugin.h +++ b/Src/GpuPlugin.h @@ -11,7 +11,10 @@ #include #include #include +#include +#include #include +#include #include #include "Windows/Nvidia/NvidiaGpuUsage.h" #include "Windows/Amd/AmdGpuUsage.h" diff --git a/Src/com.nthompson.gpu.sdPlugin/js/index.js b/Src/com.nthompson.gpu.sdPlugin/js/index.js index 3170ef0..225d710 100644 --- a/Src/com.nthompson.gpu.sdPlugin/js/index.js +++ b/Src/com.nthompson.gpu.sdPlugin/js/index.js @@ -38,6 +38,8 @@ window.connectElgatoStreamDeckSocket = (inPort, inPropertyInspectorUUID, inRegis socket.addEventListener('message', (e) => { const info = JSON.parse(e.data); + console.log(info); + const payload = info['payload']; if (!payload) return; @@ -49,6 +51,14 @@ window.connectElgatoStreamDeckSocket = (inPort, inPropertyInspectorUUID, inRegis for (let i = 0; i < gpus?.length; i++) { select.add(new Option(gpus[i][1].name, JSON.stringify(gpus[i][1]), false, gpus[i][1].deviceId === selection['deviceId'])); } + + if (gpus.length === 0) { + select.add(new Option("No GPUs found", null, false, true)); + } + + if (gpus.length === 1) { + sendValueToPlugin(JSON.stringify(gpus[0][1]), 'gpuInfo'); + } } if (payload["settings"]) { @@ -56,6 +66,10 @@ window.connectElgatoStreamDeckSocket = (inPort, inPropertyInspectorUUID, inRegis const options = [...select.options]; select.selectedIndex = options.findIndex(o => JSON.parse(o.value).deviceId === gpuInfo["deviceId"]); } + + if (!payload["gpus"] && !payload["settings"]) { + select.add(new Option("No GPUs found", null, false, true)); + } }) socket.addEventListener('close', () => { diff --git a/Src/com.nthompson.gpu.sdPlugin/manifest.json b/Src/com.nthompson.gpu.sdPlugin/manifest.json index c714d65..92a129d 100644 --- a/Src/com.nthompson.gpu.sdPlugin/manifest.json +++ b/Src/com.nthompson.gpu.sdPlugin/manifest.json @@ -24,7 +24,7 @@ "Description": "Displays the current GPU usage.", "Name": "GPU Utilization", "Icon": "pluginIcon", - "Version": "1.2.3", + "Version": "1.2.4", "URL": "https://github.com/thompsonnoahe/StreamDeckGpu", "OS": [ {