Skip to content

Commit

Permalink
Save selected device, bump version to 1.2.3
Browse files Browse the repository at this point in the history
  • Loading branch information
thompsonnoahe committed Dec 18, 2024
1 parent 133a6f1 commit fd14c8e
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 15 deletions.
3 changes: 2 additions & 1 deletion Src/GpuAbstraction.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ namespace nthompson {
GpuVendor vendor;
std::string name;
uint32_t index;
UINT deviceId;
};

NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(Gpu, vendor, name, index);
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(Gpu, vendor, name, index, deviceId);
}

24 changes: 17 additions & 7 deletions Src/GpuPlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ namespace nthompson {
const nlohmann::json &inPayload, const std::string &inDeviceID) {
std::scoped_lock<std::mutex> lock(mutex_);
contexts_.insert(inContext);

if (inPayload.contains("settings")) {
Gpu gpu = inPayload["settings"]["gpuInfo"];
HandleSelectedGpu(gpu);
}
}

void GpuPlugin::WillDisappearForAction(const std::string &inAction, const std::string &inContext,
Expand All @@ -81,9 +86,9 @@ namespace nthompson {
}

void GpuPlugin::FindAvailableGpus() {
IDXGIFactory* factory = nullptr;
IDXGIFactory1* factory = nullptr;

HRESULT result = CreateDXGIFactory(__uuidof(IDXGIFactory), (void**)&factory);
HRESULT result = CreateDXGIFactory1(__uuidof(IDXGIFactory), (void**)&factory);

if (FAILED(result)) {
ESDLog("Failed to create factory object.");
Expand All @@ -95,6 +100,8 @@ namespace nthompson {
UINT index = 0;
IDXGIAdapter* adapter = nullptr;

uint32_t nvidiaGpuCount = 0, amdGpuCount = 0, unknownCount = 0;

while (factory->EnumAdapters(index, &adapter) != DXGI_ERROR_NOT_FOUND) {
DXGI_ADAPTER_DESC desc;
adapter->GetDesc(&desc);
Expand All @@ -111,20 +118,23 @@ namespace nthompson {
item.first = desc.DeviceId;

if (description.find(nvidia) != std::string::npos) {
item.second = {GpuVendor::Nvidia, gpuName, index};
item.second = {GpuVendor::Nvidia, gpuName, nvidiaGpuCount, item.first};
gpus_.insert(item);
std::string gpuLog = gpuName + " found";
ESDLog(gpuLog);
nvidiaGpuCount++;
}
else if (description.find(amd) != std::string::npos || description.find(advancedMicroDevices) != std::string::npos) {
item.second = {GpuVendor::Amd, gpuName, index};
item.second = {GpuVendor::Amd, gpuName, amdGpuCount, item.first};
gpus_.insert(item);
std::string gpuLog = gpuName + " found";
ESDLog(gpuLog);
amdGpuCount++;
} else {
item.second = {GpuVendor::Unknown, gpuName, index};
item.second = {GpuVendor::Unknown, gpuName, unknownCount, item.first};
gpus_.insert(item);
ESDLog("Found unsupported display adapter");
unknownCount++;
}

++index;
Expand All @@ -136,7 +146,6 @@ namespace nthompson {
const std::string &inDeviceID) {
nlohmann::json payload;
if (inPayload.at("propertyInspectorLoaded").get<bool>()) {
payload["type"] = "availableGpus";
payload["gpus"] = gpus_;
payload["selected"] = selectedGpu_;
mConnectionManager->SendToPropertyInspector(inAction, inContext, payload);
Expand All @@ -146,6 +155,7 @@ namespace nthompson {
Gpu gpu = inPayload["gpuInfo"];
HandleSelectedGpu(gpu);
mConnectionManager->SendToPropertyInspector(inAction, inContext, payload);
mConnectionManager->SetSettings(inPayload, inContext);
}
}

Expand All @@ -161,7 +171,7 @@ namespace nthompson {
usage_ = nullptr;
break;
}
selectedGpu_ = gpu.index;
selectedGpu_ = gpu;
}

void GpuPlugin::KeyDownForAction(const std::string &inAction, const std::string &inContext,
Expand Down
4 changes: 2 additions & 2 deletions Src/GpuPlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,12 @@ namespace nthompson {
const std::string& inDeviceID) override;
private:
void FindAvailableGpus();
std::map<uint32_t, Gpu> gpus_;
std::map<UINT, Gpu> gpus_;
std::unique_ptr<IGpuUsage> usage_ = nullptr;
std::unique_ptr<Timer> timer_;
std::mutex mutex_;
std::set<std::string> contexts_;
int32_t selectedGpu_{0};
Gpu selectedGpu_{};
void HandleSelectedGpu(const Gpu &gpu);
};

Expand Down
16 changes: 12 additions & 4 deletions Src/com.nthompson.gpu.sdPlugin/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,19 @@ window.connectElgatoStreamDeckSocket = (inPort, inPropertyInspectorUUID, inRegis

if (!payload) return;

const gpus = payload['gpus'];
const selected = payload['selected'];
if (payload["gpus"]) {
const gpus = payload['gpus'];
const selection = payload['selected'];

for (let i = 0; i < gpus?.length; i++) {
select.add(new Option(gpus[i][1].name, JSON.stringify(gpus[i][1]), false, selected > 0 ? i === selected : i === 0));
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 (payload["settings"]) {
const gpuInfo = payload["settings"]["gpuInfo"]
const options = [...select.options];
select.selectedIndex = options.findIndex(o => JSON.parse(o.value).deviceId === gpuInfo["deviceId"]);
}
})

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.2",
"Version": "1.2.3",
"URL": "https://github.com/thompsonnoahe/StreamDeckGpu",
"OS": [
{
Expand Down

0 comments on commit fd14c8e

Please sign in to comment.