Skip to content

Commit

Permalink
Filter integrated devices from selection list
Browse files Browse the repository at this point in the history
  • Loading branch information
thompsonnoahe committed Dec 24, 2024
1 parent fd14c8e commit d648d5d
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 9 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
target_link_libraries(gpu PRIVATE StreamDeckSDK CUDA::nvml adlx d3d12.lib dxgi.lib dxcore.lib)
66 changes: 59 additions & 7 deletions Src/GpuPlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,22 +87,29 @@ namespace nthompson {

void GpuPlugin::FindAvailableGpus() {
IDXGIFactory1* factory = nullptr;
winrt::com_ptr<IDXCoreAdapterFactory> 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<IDXCoreAdapter> 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;
Expand All @@ -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<UINT, Gpu> item;

item.first = desc.DeviceId;
Expand All @@ -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
Expand Down
3 changes: 3 additions & 0 deletions Src/GpuPlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@
#include <mutex>
#include <set>
#include <dxgi.h>
#include <dxcore.h>
#include <dxcore_interface.h>
#include <algorithm>
#include <winrt/base.h>
#include <functional>
#include "Windows/Nvidia/NvidiaGpuUsage.h"
#include "Windows/Amd/AmdGpuUsage.h"
Expand Down
14 changes: 14 additions & 0 deletions Src/com.nthompson.gpu.sdPlugin/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -49,13 +51,25 @@ 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"]) {
const gpuInfo = payload["settings"]["gpuInfo"]
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', () => {
Expand Down
2 changes: 1 addition & 1 deletion Src/com.nthompson.gpu.sdPlugin/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
{
Expand Down

0 comments on commit d648d5d

Please sign in to comment.