From b7da69bccc4ea47f63ada201c40934a74f53ebc3 Mon Sep 17 00:00:00 2001 From: Noah Thompson Date: Sat, 7 Dec 2024 21:43:08 -0800 Subject: [PATCH] V1.2.1 - Launch associated app --- Src/GpuPlugin.cpp | 7 +++++++ Src/GpuPlugin.h | 6 ++++++ Src/Windows/Amd/AmdGpuUsage.cpp | 27 +++++++++++++++++++++++++++ Src/Windows/Amd/AmdGpuUsage.h | 6 ++++-- Src/Windows/IGpuUsage.h | 1 + Src/Windows/Nvidia/NvidiaGpuUsage.cpp | 27 +++++++++++++++++++++++++++ Src/Windows/Nvidia/NvidiaGpuUsage.h | 5 ++++- 7 files changed, 76 insertions(+), 3 deletions(-) diff --git a/Src/GpuPlugin.cpp b/Src/GpuPlugin.cpp index a2c2615..e4bc6f4 100644 --- a/Src/GpuPlugin.cpp +++ b/Src/GpuPlugin.cpp @@ -158,4 +158,11 @@ namespace nthompson { } selectedGpu_ = gpu.index; } + + void GpuPlugin::KeyDownForAction(const std::string &inAction, const std::string &inContext, + const nlohmann::json &inPayload, const std::string &inDeviceID) { + if (!usage_) return; + + usage_->LaunchAssociatedApp(); + } } \ No newline at end of file diff --git a/Src/GpuPlugin.h b/Src/GpuPlugin.h index 9e12fa9..ae231b6 100644 --- a/Src/GpuPlugin.h +++ b/Src/GpuPlugin.h @@ -53,6 +53,12 @@ namespace nthompson { const std::string &inContext, const nlohmann::json &inPayload, const std::string &inDeviceID) override; + + void KeyDownForAction( + const std::string& inAction, + const std::string& inContext, + const nlohmann::json& inPayload, + const std::string& inDeviceID) override; private: void FindAvailableGpus(); std::vector gpus_; diff --git a/Src/Windows/Amd/AmdGpuUsage.cpp b/Src/Windows/Amd/AmdGpuUsage.cpp index 58839e8..466db85 100644 --- a/Src/Windows/Amd/AmdGpuUsage.cpp +++ b/Src/Windows/Amd/AmdGpuUsage.cpp @@ -67,5 +67,32 @@ namespace nthompson { helper_.Terminate(); } + void AmdGpuUsage::LaunchAssociatedApp() { + STARTUPINFO startupInfo; + PROCESS_INFORMATION processInformation; + + ZeroMemory(&startupInfo, sizeof(startupInfo)); + startupInfo.cb = sizeof(startupInfo); + ZeroMemory(&processInformation, sizeof(processInformation)); + + LPCTSTR path = R"(C:\Program Files\AMD\CNext\CNext\RadeonSoftware.exe)"; + + CreateProcess( + path, + nullptr, + nullptr, + nullptr, + FALSE, + 0, + nullptr, + nullptr, + &startupInfo, + &processInformation + ); + + CloseHandle(processInformation.hProcess); + CloseHandle(processInformation.hThread); + } + } diff --git a/Src/Windows/Amd/AmdGpuUsage.h b/Src/Windows/Amd/AmdGpuUsage.h index a432baf..360e635 100644 --- a/Src/Windows/Amd/AmdGpuUsage.h +++ b/Src/Windows/Amd/AmdGpuUsage.h @@ -13,10 +13,12 @@ namespace nthompson { class AmdGpuUsage : public IGpuUsage { public: - AmdGpuUsage(int32_t index = 0); + explicit AmdGpuUsage(int32_t index = 0); ~AmdGpuUsage() override; uint32_t GetGpuUsage() override; - private: + void LaunchAssociatedApp() override; + + private: static inline ADLXHelper helper_; adlx::IADLXGPUPtr gpu_; adlx::IADLXPerformanceMonitoringServicesPtr perfMonitoringServices_; diff --git a/Src/Windows/IGpuUsage.h b/Src/Windows/IGpuUsage.h index dbd44cd..09e4d07 100644 --- a/Src/Windows/IGpuUsage.h +++ b/Src/Windows/IGpuUsage.h @@ -13,5 +13,6 @@ namespace nthompson { IGpuUsage() = default; virtual ~IGpuUsage() = default; virtual uint32_t GetGpuUsage() = 0; + virtual void LaunchAssociatedApp() = 0; }; } diff --git a/Src/Windows/Nvidia/NvidiaGpuUsage.cpp b/Src/Windows/Nvidia/NvidiaGpuUsage.cpp index 7b94654..c028fb4 100644 --- a/Src/Windows/Nvidia/NvidiaGpuUsage.cpp +++ b/Src/Windows/Nvidia/NvidiaGpuUsage.cpp @@ -40,5 +40,32 @@ namespace nthompson { nvmlShutdown(); } + void NvidiaGpuUsage::LaunchAssociatedApp() { + STARTUPINFO startupInfo; + PROCESS_INFORMATION processInformation; + + ZeroMemory(&startupInfo, sizeof(startupInfo)); + startupInfo.cb = sizeof(startupInfo); + ZeroMemory(&processInformation, sizeof(processInformation)); + + LPCTSTR path = R"(C:\Program Files\NVIDIA Corporation\NVIDIA app\CEF\NVIDIA app.exe)"; + + CreateProcess( + path, + nullptr, + nullptr, + nullptr, + FALSE, + 0, + nullptr, + nullptr, + &startupInfo, + &processInformation + ); + + CloseHandle(processInformation.hProcess); + CloseHandle(processInformation.hThread); + } + } // nthompson \ No newline at end of file diff --git a/Src/Windows/Nvidia/NvidiaGpuUsage.h b/Src/Windows/Nvidia/NvidiaGpuUsage.h index 8e5408e..0ab5ec4 100644 --- a/Src/Windows/Nvidia/NvidiaGpuUsage.h +++ b/Src/Windows/Nvidia/NvidiaGpuUsage.h @@ -5,6 +5,7 @@ #pragma once #include +#include #include #include "StreamDeckSDK/ESDLogger.h" #include "../IGpuUsage.h" @@ -16,7 +17,9 @@ namespace nthompson { explicit NvidiaGpuUsage(int32_t index = 0); ~NvidiaGpuUsage() override; uint32_t GetGpuUsage() override; - private: + void LaunchAssociatedApp() override; + + private: nvmlDevice_t device_; nvmlUtilization_t utilization_; };