From b712c5458b9bb2275ea0c956cc417a07918c27b8 Mon Sep 17 00:00:00 2001 From: Carterpersall Date: Tue, 13 Sep 2022 10:52:22 -0500 Subject: [PATCH 1/3] Turn info_gpu into pure speed - Instead of using Get-CimInstance to get GPU information, which can be very slow, gets the registry entry at HKLM:\SOFTWARE\Microsoft\DirectX\ which contains a list of installed video adapters - 1690 ms -> 40.16 ms - 42x faster (nice) --- winfetch.ps1 | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/winfetch.ps1 b/winfetch.ps1 index 7a88581..7b39c32 100644 --- a/winfetch.ps1 +++ b/winfetch.ps1 @@ -702,12 +702,15 @@ function info_cpu { function info_gpu { [System.Collections.ArrayList]$lines = @() - #loop through Win32_VideoController - foreach ($gpu in Get-CimInstance -ClassName Win32_VideoController -Property Name -CimSession $cimSession) { - [void]$lines.Add(@{ - title = "GPU" - content = $gpu.Name - }) + # Get list of GPUs from the Registry + $LastSeen = (Get-ItemProperty -path HKLM:\SOFTWARE\Microsoft\DirectX\).LastSeen + Get-ChildItem -path HKLM:\SOFTWARE\Microsoft\DirectX\ | Get-ItemProperty | ForEach-Object { + if(($_.Description -ne "Microsoft Basic Render Driver") -and ($_.LastSeen -eq $LastSeen) -and ($lines.content -notcontains $_.Description)){ + [void]$lines.Add(@{ + title = "GPU" + content = $_.Description + }) + } } return $lines } From 4e90d8b0e6fa8a9d72d34329772616706479df20 Mon Sep 17 00:00:00 2001 From: Carterpersall Date: Wed, 14 Sep 2022 10:36:01 -0500 Subject: [PATCH 2/3] Create backup methods - Whenever someone doesn't have the LastSeen key, falls back on a method which is incompatible with users with multiple of the same GPU - If for some reason the entire registry entry doesn't exist, fall back to the previous slow implementation. --- winfetch.ps1 | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/winfetch.ps1 b/winfetch.ps1 index 7b39c32..37ec452 100644 --- a/winfetch.ps1 +++ b/winfetch.ps1 @@ -703,12 +703,32 @@ function info_cpu { function info_gpu { [System.Collections.ArrayList]$lines = @() # Get list of GPUs from the Registry - $LastSeen = (Get-ItemProperty -path HKLM:\SOFTWARE\Microsoft\DirectX\).LastSeen - Get-ChildItem -path HKLM:\SOFTWARE\Microsoft\DirectX\ | Get-ItemProperty | ForEach-Object { - if(($_.Description -ne "Microsoft Basic Render Driver") -and ($_.LastSeen -eq $LastSeen) -and ($lines.content -notcontains $_.Description)){ + $RegDir = Get-ItemProperty -path HKLM:\SOFTWARE\Microsoft\DirectX\ + $LastSeen = $RegDir.LastSeen + if($LastSeen){ + Get-ChildItem -path HKLM:\SOFTWARE\Microsoft\DirectX\ | Get-ItemProperty | ForEach-Object { + if(($_.Description -ne "Microsoft Basic Render Driver") -and ($_.LastSeen -eq $LastSeen)){ + [void]$lines.Add(@{ + title = "GPU" + content = $_.Description + }) + } + } + }elseif($RegDir){ # Alternative Method 1: Won't work properly if user has multiple of the same GPU + Get-ChildItem -path HKLM:\SOFTWARE\Microsoft\DirectX\ | Get-ItemProperty | ForEach-Object { + if(($_.Description -ne "Microsoft Basic Render Driver") -and ($lines.content -notcontains $_.Description)){ + [void]$lines.Add(@{ + title = "GPU" + content = $_.Description + }) + } + } + }else{ # Alternative Method 2: Fallback onto previous implementation + # Loop through Win32_VideoController + foreach ($gpu in Get-CimInstance -ClassName Win32_VideoController -Property Name -CimSession $cimSession) { [void]$lines.Add(@{ title = "GPU" - content = $_.Description + content = $gpu.Name }) } } From 711306b441c7d7e824e3f6b0e5ec541e449df784 Mon Sep 17 00:00:00 2001 From: Carterpersall Date: Thu, 15 Sep 2022 15:02:40 -0500 Subject: [PATCH 3/3] New Backup Method 1 - Gets the subkeys of HKLM:\SYSTEM\CurrentControlSet\Enum\PCI\ and pulls the value of DeviceDesc of those subkey's subkeys, then pulls the device name from the value, then it takes those values and compares those values to a list of GPU titles. --- winfetch.ps1 | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/winfetch.ps1 b/winfetch.ps1 index 37ec452..ad045a2 100644 --- a/winfetch.ps1 +++ b/winfetch.ps1 @@ -703,9 +703,7 @@ function info_cpu { function info_gpu { [System.Collections.ArrayList]$lines = @() # Get list of GPUs from the Registry - $RegDir = Get-ItemProperty -path HKLM:\SOFTWARE\Microsoft\DirectX\ - $LastSeen = $RegDir.LastSeen - if($LastSeen){ + if($LastSeen = (Get-ItemProperty -path HKLM:\SOFTWARE\Microsoft\DirectX\ -ErrorAction SilentlyContinue).LastSeen) { Get-ChildItem -path HKLM:\SOFTWARE\Microsoft\DirectX\ | Get-ItemProperty | ForEach-Object { if(($_.Description -ne "Microsoft Basic Render Driver") -and ($_.LastSeen -eq $LastSeen)){ [void]$lines.Add(@{ @@ -714,12 +712,17 @@ function info_gpu { }) } } - }elseif($RegDir){ # Alternative Method 1: Won't work properly if user has multiple of the same GPU - Get-ChildItem -path HKLM:\SOFTWARE\Microsoft\DirectX\ | Get-ItemProperty | ForEach-Object { - if(($_.Description -ne "Microsoft Basic Render Driver") -and ($lines.content -notcontains $_.Description)){ + }elseif($Devices = Get-ChildItem -path HKLM:\SYSTEM\CurrentControlSet\Enum\PCI\ -Depth 1 -ErrorAction SilentlyContinue) { # Alternative Method 1: Get GPUs from Device Manager's Registry Keys, slightly slower + ($Devices | Get-ItemProperty).DeviceDesc | ForEach-Object { + $Device = $_.Substring($_.IndexOf(';') + 1) + if( + $Device -match "NVIDIA GeForce" -or $Device -match "NVIDIA Quadro" -or $Device -match "NVIDIA Tesla" -or $Device -match "NVIDIA GRID" -or` + $Device -match "Radeon" -or` + $Device -match "Intel(R) UHD" -or $Device -match "Intel(R) HD" -or $Device -match "Intel(R) Iris" -or $Device -match "Intel(R) Arc" + ){ [void]$lines.Add(@{ title = "GPU" - content = $_.Description + content = $Device }) } }