From e0ef60ac217fc81fb87f6892aa8d319974856687 Mon Sep 17 00:00:00 2001 From: Nguyen Duy Date: Tue, 30 Apr 2024 14:09:06 +0700 Subject: [PATCH] Add parent GPU option --- app/App.xaml.cs | 8 ++++++ app/Components/CustomPage.xaml | 8 ++++++ app/Components/CustomPage.xaml.cs | 17 +++++++++-- app/ParsecVDD.cs | 48 +++++++++++++++++++++++++++++++ app/Properties/AssemblyInfo.cs | 4 +-- 5 files changed, 81 insertions(+), 4 deletions(-) diff --git a/app/App.xaml.cs b/app/App.xaml.cs index 488971c..70a360c 100644 --- a/app/App.xaml.cs +++ b/app/App.xaml.cs @@ -29,6 +29,14 @@ namespace ParsecVDisplay var modes = Display.ParseModes(e.Args[1]); ParsecVDD.SetCustomDisplayModes(modes); + if (e.Args.Length >= 3) + { + if (Enum.TryParse(e.Args[2], true, out var kind)) + { + ParsecVDD.SetParentGPU(kind); + } + } + Shutdown(); return; } diff --git a/app/Components/CustomPage.xaml b/app/Components/CustomPage.xaml index 72df497..8652c59 100644 --- a/app/Components/CustomPage.xaml +++ b/app/Components/CustomPage.xaml @@ -77,6 +77,14 @@ + + + + + + + + diff --git a/app/Components/CustomPage.xaml.cs b/app/Components/CustomPage.xaml.cs index 699ab31..4bab266 100644 --- a/app/Components/CustomPage.xaml.cs +++ b/app/Components/CustomPage.xaml.cs @@ -14,6 +14,12 @@ namespace ParsecVDisplay.Components public CustomPage() { InitializeComponent(); + + xParentGPU.Items.Clear(); + foreach (var item in Enum.GetValues(typeof(ParsecVDD.ParentGPU))) + { + xParentGPU.Items.Add(item.ToString()); + } } private void ApplyChanges(object sender, EventArgs e) @@ -44,15 +50,19 @@ namespace ParsecVDisplay.Components } } - if (modes.Count > 0) + ParsecVDD.ParentGPU parentGPU; + bool validParentGPU = Enum.TryParse(xParentGPU.SelectedValue.ToString(), true, out parentGPU); + + if (modes.Count > 0 && validParentGPU) { if (Helper.IsAdmin()) { ParsecVDD.SetCustomDisplayModes(modes); + ParsecVDD.SetParentGPU(parentGPU); } else { - var args = $"-custom \"{Display.DumpModes(modes)}\""; + var args = $"-custom \"{Display.DumpModes(modes)}\" \"{parentGPU}\""; if (Helper.RunAdminTask(args) == false) { MessageBox.Show("Could not set custom resolutions, access denied!", @@ -77,6 +87,9 @@ namespace ParsecVDisplay.Components TextBoxes[i + 1].Text = $"{modes[j].Height}"; TextBoxes[i + 2].Text = $"{modes[j].Hz}"; } + + var parentGPU = ParsecVDD.GetParentGPU(); + xParentGPU.SelectedValue = parentGPU.ToString(); } private void Page_Unloaded(object sender, RoutedEventArgs e) diff --git a/app/ParsecVDD.cs b/app/ParsecVDD.cs index 8197d4b..0ba49d7 100644 --- a/app/ParsecVDD.cs +++ b/app/ParsecVDD.cs @@ -269,6 +269,54 @@ namespace ParsecVDisplay } } + public enum ParentGPU + { + Auto = 0, + NVIDIA = 0x10DE, + AMD = 0x1002, + } + + public static ParentGPU GetParentGPU() + { + using (var parameters = Registry.LocalMachine.OpenSubKey( + "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\WUDF\\Services\\ParsecVDA\\Parameters", + RegistryKeyPermissionCheck.ReadSubTree)) + { + if (parameters != null) + { + object value = parameters.GetValue("PreferredRenderAdapterVendorId"); + if (value != null) + { + return (ParentGPU)Convert.ToInt32(value); + } + } + } + + return ParentGPU.Auto; + } + + // Requires admin perm + public static void SetParentGPU(ParentGPU kind) + { + using (var parameters = Registry.LocalMachine.OpenSubKey( + "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\WUDF\\Services\\ParsecVDA\\Parameters", + RegistryKeyPermissionCheck.ReadWriteSubTree)) + { + if (parameters != null) + { + if (kind == ParentGPU.Auto) + { + parameters.DeleteValue("PreferredRenderAdapterVendorId", false); + } + else + { + parameters.SetValue("PreferredRenderAdapterVendorId", + (uint)kind, RegistryValueKind.DWord); + } + } + } + } + static unsafe class Native { [DllImport("kernel32.dll")] diff --git a/app/Properties/AssemblyInfo.cs b/app/Properties/AssemblyInfo.cs index 153efa5..4a53b62 100644 --- a/app/Properties/AssemblyInfo.cs +++ b/app/Properties/AssemblyInfo.cs @@ -7,11 +7,11 @@ using System.Windows; // General Information about an assembly is controlled through the following // set of attributes. Change these attribute values to modify the information // associated with an assembly. -[assembly: AssemblyTitle("ParsecVDisplay")] +[assembly: AssemblyTitle(ParsecVDisplay.App.NAME)] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("ParsecVDisplay")] +[assembly: AssemblyProduct(ParsecVDisplay.App.NAME)] [assembly: AssemblyCopyright("Copyright © 2024")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")]