-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathdiagnose-vulkan.ps1
333 lines (319 loc) · 11 KB
/
diagnose-vulkan.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
#!/usr/bin/pwsh
param(
[switch]$norestart,
[switch]$autofix,
[switch]$cleanExplicitReg,
[switch]$disableBadLayers
)
# use manual checks so you can get in a good state instead of simply failing when run through Explorer context menu
$isAdmin = ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]"Administrator")
$argList = "-ExecutionPolicy RemoteSigned -File $PSCommandPath -norestart"
if ($autofix)
{
$argList = "$argList -autofix"
}
if ($cleanExplicitReg)
{
$argList = "$argList -cleanExplicitReg"
}
if ($disableBadLayers)
{
$argList = "$argList -disableBadLayers"
}
function Request-ContextElevation
{
if (-not $isAdmin)
{
Write-Host "Restarting with elevated permissions..."
Start-Process pwsh -Verb runAs -ArgumentList $argList
exit
}
}
if ($PSVersionTable.PSVersion.Major -lt 6)
{
Write-Host "This script requires newer PowerShell version"
Write-Host "You can get the latest version at https://github.com/PowerShell/PowerShell#get-powershell"
if (-not $norestart)
{
Write-Host "Trying to restart..."
Start-Process pwsh -Verb open -ArgumentList $argList
break
}
}
$is64bit = [Environment]::Is64BitOperatingSystem
if (-not $is64bit)
{
Write-Error "This script is only intended for use with 64-bit OS"
break
}
$hasBrokenEntries = $false
$hasExplicitDriverEntries = $false
$properDriverEntries = $false
$hasIncompatibleLayers = $false
Clear-Host
$osInfo = Get-CimInstance -Class CIM_OperatingSystem | Select-Object Caption, Version
Write-Host "OS: $($osInfo.Caption)"
Write-Host "Version: $($osInfo.Version)"
Write-Host
Write-Host "Enumerating GPUs..."
# Computer\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Video\{....}\Video
# DeviceDesc = @oem33.inf,%nvidia_dev.1b06%;NVIDIA GeForce GTX 1080 Ti
# @oem60.inf,%nvidia_dev.2206%;NVIDIA GeForce RTX 3080
# @oem26.inf,%amd67df.51%;Radeon (TM) RX 480 Graphics
# Service = nvlddmkm
# amdkmdag
# It seems like active GPUs should have both Video AND 0000 subkeys
$registeredGpus = @(Get-ChildItem Registry::HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Video)
$gpus = @()
foreach ($entry in $registeredGpus)
{
$gpuGuid = Split-Path $entry.Name -Leaf
$gpuEntryPath = "Registry::HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Video\$gpuGuid"
if (Test-Path "$gpuEntryPath\Video")
{
if (Test-Path "$gpuEntryPath\0000")
{
$gpus += $gpuGuid
}
else
{
$item = Get-ItemProperty -LiteralPath "$gpuEntryPath\Video"
if (@('BasicDisplay', 'WUDFRd') -inotcontains $item.Service)
{
$name = @($item.DeviceDesc -split ';')[-1]
Write-Host "Found inactive GPU entry: $name"
}
}
}
}
if ($gpus.Length -eq 0)
{
Write-Error "Failed to enumerate any GPUs"
break
}
$suffix = ''
if ($gpus.Length -gt 1)
{
$suffix = 's'
}
Write-Host "Found $($gpus.Length) active GPU$($suffix):"
# Computer\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Video\{47F997B3-03D7-11EB-A625-5CF370691F26}\0000
# VulkanDriverName = C:\WINDOWS\System32\DriverStore\FileRepository\nv_dispi.inf_amd64_feed726c6560f7a7\nv-vk64.json
# VulkanDriverNameWoW = C:\WINDOWS\System32\DriverStore\FileRepository\nv_dispi.inf_amd64_feed726c6560f7a7\nv-vk32.json
# VulkanImplicitLayers = C:\WINDOWS\System32\DriverStore\FileRepository\nv_dispi.inf_amd64_feed726c6560f7a7\nv-vk64.json
# VulkanImplicitLayersWow = C:\WINDOWS\System32\DriverStore\FileRepository\nv_dispi.inf_amd64_feed726c6560f7a7\nv-vk32.json
foreach ($gpuGuid in $gpus)
{
$gpuEntryPath = "Registry::HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Video\$gpuGuid"
$gpu = Get-ItemProperty -LiteralPath "$gpuEntryPath\Video"
$output = Get-ItemProperty -LiteralPath "$gpuEntryPath\0000"
$name = @($gpu.DeviceDesc -split ';')[-1]
$driverVersion = $output.DriverVersion
Write-Host "`t$name ($driverVersion)"
$keys = @(Get-ChildItem $gpuEntryPath)
foreach ($subkey in $keys)
{
$output = Split-Path $subkey.Name -Leaf
if ($output -notmatch '\d{4}')
{
continue
}
Write-Host "`t`tOutput $output"
$registeredVulkanDevice = $false
foreach ($prop in @('VulkanDriverName', 'VulkanDriverNameWoW', 'VulkanImplicitLayers', 'VulkanImplicitLayersWow'))
{
if ((Get-Item -LiteralPath "$gpuEntryPath\$output").Property -contains $prop)
{
$propValue = Get-ItemPropertyValue -LiteralPath "$gpuEntryPath\$output" -Name $prop
if (Test-Path -LiteralPath $propValue)
{
if ($prop.StartsWith('VulkanDriver'))
{
$registeredVulkanDevice = $true
}
}
else
{
Write-Host "`t`t`tInvalid value for property $($prop): $propValue"
}
}
}
if ($registeredVulkanDevice)
{
$properDriverEntries = $true
Write-Host "`t`t`tValid Vulkan registration"
}
else
{
Write-Host "`t`t`tNot a Vulkan device"
}
}
}
if (-not $properDriverEntries)
{
$cleanExplicitReg = $false
}
# Computer\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\nvlddmkm
# amdkmdag
# ImagePath = \SystemRoot\System32\DriverStore\FileRepository\nv_dispi.inf_amd64_feed726c6560f7a7\nvlddmkm.sys
# \SystemRoot\System32\DriverStore\FileRepository\u0355166.inf_amd64_b850e0f0c3bce936\B355483\amdkmdag.sys
Write-Host
Write-Host "Checking Vulkan entries..."
# Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Khronos\Vulkan\Drivers
# Computer\HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Khronos\Vulkan\Drivers
# should be empty
$knownProblematicLayers = @('obs-vulkan64.json', 'MirillisActionVulkanLayer.json')
foreach ($node in @('', '\WOW6432Node'))
{
if ($node -eq '')
{
Write-Host "64-bit entries..."
}
else
{
Write-Host "`32-bit entries..."
}
$keyPath = "Registry::HKEY_LOCAL_MACHINE\SOFTWARE$node\Khronos\Vulkan\Drivers"
if (Test-Path -LiteralPath $keyPath)
{
$key = Get-Item -LiteralPath $keyPath
if ($key.ValueCount -gt 0)
{
Write-Host "`tChecking explicit Vulkan driver entries..."
foreach ($prop in $key.Property)
{
if ($cleanExplicitReg)
{
Request-ContextElevation
Remove-ItemProperty -LiteralPath $keyPath -Name $prop
Write-Host "`t`t$prop`: removed"
}
elseif (Test-Path -LiteralPath $prop)
{
$hasExplicitDriverEntries = $true
$state = "enabled"
if ((Get-ItemPropertyValue $keyPath -Name $prop) -eq 1)
{
$state = "disabled"
}
Write-Host "`t`t$prop`: $state"
}
else
{
if ($autofix)
{
Request-ContextElevation
Remove-ItemProperty -LiteralPath $keyPath -Name $prop
Write-Host "`t`t$prop`: removed"
}
else
{
$hasBrokenEntries = $true
Write-Host "`t`t$prop`: BROKEN"
}
}
}
}
}
$keyPath = "Registry::HKEY_LOCAL_MACHINE\SOFTWARE$node\Khronos\Vulkan\ImplicitLayers"
if (Test-Path -LiteralPath $keyPath)
{
$key = Get-Item -LiteralPath $keyPath
if ($key.ValueCount -gt 0)
{
Write-Host "`tChecking implicit Vulkan layers..."
foreach ($prop in $key.Property)
{
$name = Split-Path $prop -Leaf
$value = Get-ItemPropertyValue -LiteralPath $keyPath -Name $prop
if ((Test-Path $prop) -and ($name.ToLower().EndsWith('.json')))
{
if (($value -eq 0) -and ($knownProblematicLayers -contains $name))
{
if ($disableBadLayers)
{
Request-ContextElevation
Set-ItemProperty -LiteralPath $keyPath -Name $prop -Value 1
Write-Host "`t`t$name`: potentially incompatible, disabled"
}
else
{
$hasIncompatibleLayers = $true
Write-Host "`t`t$name`: potentially incompatible"
}
}
else
{
if ($value -eq 0)
{
Write-Host "`t`t$($name): ok, enabled"
}
else
{
Write-Host "`t`t$($name): ok, disabled"
}
}
}
else
{
if ($autofix)
{
Request-ContextElevation
Remove-ItemProperty -LiteralPath $keyPath -Name $prop
Write-Host "`t`t$($name): removed"
}
else
{
$hasBrokenEntries = $true
Write-Host "`t`t$($name): BROKEN"
}
}
}
}
}
}
if (-not $properDriverEntries)
{
# if drivers are too old and used explicit vulkan driver registration, allow it
$hasExplicitDriverEntries = $false
}
if ($hasExplicitDriverEntries -or $hasBrokenEntries -or $hasIncompatibleLayers)
{
$prompt = "`nWhat would you like to do?`n"
$options = 0
if ($hasExplicitDriverEntries)
{
$prompt = "$prompt[c] Clean explicit driver registration`n"
$options++
}
if ($hasIncompatibleLayers)
{
$prompt = "$prompt[d] Disable potentially incompatible layers`n"
$options++
}
if ($hasBrokenEntries)
{
$prompt = "$prompt[r] Remove broken entries`n"
$options++
}
if ($options -gt 1)
{
$prompt = "$prompt[a] All of the above`n"
}
$prompt = "$prompt[n] Do nothing (default)`n"
$choice = Read-Host -Prompt $prompt
$tryToFix = $true
switch ($choice)
{
'a' { $argList = "$argList -autofix -cleanExplicitReg -disableBadLayers" }
'r' { $argList = "$argList -autofix" }
'c' { $argList = "$argList -cleanExplicitReg" }
'd' { $argList = "$argList -disableBadLayers" }
Default { $tryToFix = $false }
}
if ($tryToFix)
{
Request-ContextElevation
}
}
Pause