blob: 4666f3346c3470306748f94c0408bcebb469eb48 [file] [log] [blame]
David Pinedo1e368f72016-02-04 17:04:44 -07001# Copyright (c) 2015-2016 The Khronos Group Inc.
2# Copyright (c) 2015-2016 Valve Corporation
3# Copyright (c) 2015-2016 LunarG, Inc.
David Pinedoc21fdb92016-01-04 16:31:57 -07004#
David Pinedo1e368f72016-02-04 17:04:44 -07005# Permission is hereby granted, free of charge, to any person obtaining a copy
6# of this software and/or associated documentation files (the "Materials"), to
7# deal in the Materials without restriction, including without limitation the
8# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
9# sell copies of the Materials, and to permit persons to whom the Materials are
10# furnished to do so, subject to the following conditions:
David Pinedoc21fdb92016-01-04 16:31:57 -070011#
David Pinedo1e368f72016-02-04 17:04:44 -070012# The above copyright notice(s) and this permission notice shall be included in
13# all copies or substantial portions of the Materials.
David Pinedoc21fdb92016-01-04 16:31:57 -070014#
David Pinedo1e368f72016-02-04 17:04:44 -070015# THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
David Pinedoc21fdb92016-01-04 16:31:57 -070016# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
David Pinedo1e368f72016-02-04 17:04:44 -070017# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18#
19# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
20# DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
21# OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE MATERIALS OR THE
22# USE OR OTHER DEALINGS IN THE MATERIALS.
David Pinedoc21fdb92016-01-04 16:31:57 -070023#
24# Author: David Pinedo <david@LunarG.com>
David Pinedo1e368f72016-02-04 17:04:44 -070025# Author: Mark Young <mark@LunarG.com>
David Pinedoc21fdb92016-01-04 16:31:57 -070026#
27
David Pinedo1e368f72016-02-04 17:04:44 -070028
David Pinedoc21fdb92016-01-04 16:31:57 -070029# This Powershell script is used by the Vulkan Run Time Installer/Uninstaller to:
30# - Copy the most recent vulkan-<majorabi>-*.dll in C:\Windows\System32
31# to vulkan-<majorabi>.dll
32# - Copy the most recent version of vulkaninfo-<abimajor>-*.exe in
33# C:\Windows\System32 to vulkaninfo.exe
Mark Young4b8b5482016-01-15 15:09:39 -070034# - The same thing is done for those files in C:\Windows\SysWOW64 on a 64-bit
35# target.
David Pinedoc21fdb92016-01-04 16:31:57 -070036# - Set the layer registry entries to point to the layer json files
37# in the Vulkan SDK associated with the most recent vulkan*dll.
38#
Mark Youngaf87f222016-01-20 16:33:18 -070039# This script takes the following parameters:
Mark Young4b8b5482016-01-15 15:09:39 -070040# $majorabi : a single string number specifying the major abi version.
Mark Youngaf87f222016-01-20 16:33:18 -070041# $ossize : an integer indicating if the target is a 64 (64) or 32 (32) bit OS.
David Pinedoc21fdb92016-01-04 16:31:57 -070042#
43
Mark Young4b8b5482016-01-15 15:09:39 -070044Param(
45 [string]$majorabi,
46 [int]$ossize
47)
David Pinedoc21fdb92016-01-04 16:31:57 -070048
49$vulkandll = "vulkan-"+$majorabi+".dll"
Mark Young71e2a402016-02-12 12:07:45 -070050$windrive = $env:SYSTEMDRIVE
51$winfolder = $env:SYSTEMROOT
David Pinedoc21fdb92016-01-04 16:31:57 -070052
David Pinedoc27e0442016-03-15 11:07:19 -060053function notNumeric ($x) {
54 try {
55 0 + $x | Out-Null
56 return $false
57 } catch {
58 return $true
59 }
60}
61
David Pinedoc21fdb92016-01-04 16:31:57 -070062# The name of the versioned vulkan dll file is one of the following:
63#
David Pinedo3bdbe5d2016-01-12 16:14:53 -070064# vulkan-<majorabi>-<major>-<minor>-<patch>-<buildno>-<prerelease>-<prebuildno>
65# vulkan-<majorabi>-<major>-<minor>-<patch>-<buildno>-<prerelease>
66# vulkan-<majorabi>-<major>-<minor>-<patch>-<buildno>-<prebuildno>
David Pinedoc21fdb92016-01-04 16:31:57 -070067# vulkan-<majorabi>-<major>-<minor>-<patch>-<buildno>.dll
David Pinedoc21fdb92016-01-04 16:31:57 -070068#
David Pinedo3bdbe5d2016-01-12 16:14:53 -070069# <major>, <minor>, <patch>, <buildno> and <prebuildno> are 1 to 10 numeric digits.
70# <prerelease> is any combination of alpha and numeric characters.
71# If <prerelease> and/or <prebuildno> are present, this identifies a prerelease,
72# and the vulkan dll file will be considered less recent than one with the same
73# <major>, <minor>, <patch>, <buildno> numbers without the <prerelease> and/or
74# <prebuildno>.
David Pinedoc21fdb92016-01-04 16:31:57 -070075
76
77# We first create an array, with one array element for each vulkan-*dll in
Mark Young4b8b5482016-01-15 15:09:39 -070078# C:\Windows\System32 (and C:\Windows\SysWOW64 on 64-bit systems), with each element
79# containing:
David Pinedo3bdbe5d2016-01-12 16:14:53 -070080# <major>=<minor>=<patch>=<buildno>=<prerelease>=<prebuildno>=
David Pinedoc21fdb92016-01-04 16:31:57 -070081# filename
David Pinedo3bdbe5d2016-01-12 16:14:53 -070082# @<major>@<minor>@<patch>@<buildno>@<prerelease>@<prebuildno>@
David Pinedoc21fdb92016-01-04 16:31:57 -070083# [Note that the above three lines are one element in the array.]
84# The build identifiers separated by "=" are suitable for sorting, i.e.
David Pinedo3bdbe5d2016-01-12 16:14:53 -070085# expanded to 10 digits with leading 0s. If <prerelease> or <prebuildno> are
86# not specified, "zzzzzzzzzz" is substituted for them, so that they sort
David Pinedoc21fdb92016-01-04 16:31:57 -070087# to a position after those that do specify them.
88# The build identifiers separated by "@" are the original values extracted
89# from the file name. They are used later to find the path to the SDK
90# install directory for the given filename.
91
David Pinedoc27e0442016-03-15 11:07:19 -060092
Mark Youngd6897a32016-01-20 14:48:21 -070093function UpdateVulkanSysFolder([string]$dir, [int]$writeSdkName)
Mark Younga81e6082016-01-15 12:35:39 -070094{
95 # Push the current path on the stack and go to $dir
96 Push-Location -Path $dir
David Pinedo1e368f72016-02-04 17:04:44 -070097
Mark Younga81e6082016-01-15 12:35:39 -070098 # Create a list for all the DLLs in the folder
99 $VulkanDllList=@()
David Pinedo1e368f72016-02-04 17:04:44 -0700100
Mark Younga81e6082016-01-15 12:35:39 -0700101 # Find all DLL objects in this directory
102 dir -name vulkan-$majorabi-*.dll |
David Pinedoc21fdb92016-01-04 16:31:57 -0700103 ForEach-Object {
David Pinedoc27e0442016-03-15 11:07:19 -0600104 if ($_ -match "=" -or
105 $_ -match "@" -or
106 $_ -match " " -or
107 ($_.Split('-').count -lt 6) -or
108 ($_.Split('-').count -gt 8))
109 {
110 # If a file name contains "=", "@", or " ", or it contains less then 5 dashes or more than
111 # 7 dashes, it wasn't installed by the Vulkan Run Time.
112 # Note that we need to use return inside of ForEach-Object is to continue with iteration.
113 return
114 }
David Pinedoc21fdb92016-01-04 16:31:57 -0700115 $major=$_.Split('-')[2]
116 $majorOrig=$major
117 $minor=$_.Split('-')[3]
118 $minorOrig=$minor
119 $patch=$_.Split('-')[4]
David Pinedo3bdbe5d2016-01-12 16:14:53 -0700120 $patchOrig=$patch
121 $buildno=$_.Split('-')[5]
David Pinedoc21fdb92016-01-04 16:31:57 -0700122
David Pinedo3bdbe5d2016-01-12 16:14:53 -0700123 if ($buildno -match ".dll") {
David Pinedoc27e0442016-03-15 11:07:19 -0600124 # prerelease and prebuildno are not in the name
125 # Extract buildno, and set prerelease and prebuildno to "z"s
126 $buildno=$buildno -replace ".dll",""
127 $buildnoOrig=$buildno
128 $prerelease="z"*10
129 $prereleaseOrig=""
130 $prebuildno="z"*10
131 $prebuildnoOrig=""
David Pinedoc21fdb92016-01-04 16:31:57 -0700132 } else {
David Pinedoc27e0442016-03-15 11:07:19 -0600133 # Extract buildno, prerelease, and prebuildno
David Pinedoc21fdb92016-01-04 16:31:57 -0700134 $f=$_ -replace ".dll",""
David Pinedo3bdbe5d2016-01-12 16:14:53 -0700135 $buildno=$f.Split('-')[5]
David Pinedo5da20dd2016-01-13 16:22:19 -0700136 $buildnoOrig=$buildno
David Pinedo3bdbe5d2016-01-12 16:14:53 -0700137 $prerelease=$f.Split('-')[6]
138 $prebuildno=$f.Split('-')[7]
139 if ($prebuildno.Length -eq 0) {
David Pinedoc21fdb92016-01-04 16:31:57 -0700140 if ($prerelease -match "^[0-9]") {
David Pinedo3bdbe5d2016-01-12 16:14:53 -0700141 # prerelease starts with a digit, it must be the prebuildno
142 $prebuildno=$prerelease
David Pinedoc21fdb92016-01-04 16:31:57 -0700143 $prerelease=""
144 }
145 }
David Pinedoc21fdb92016-01-04 16:31:57 -0700146 $prereleaseOrig=$prerelease
David Pinedo3bdbe5d2016-01-12 16:14:53 -0700147 $prebuildnoOrig=$prebuildno
David Pinedoc21fdb92016-01-04 16:31:57 -0700148
149 if ($prerelease.Length -eq 0) {
150 $prerelease="z"*10
151 }
David Pinedo3bdbe5d2016-01-12 16:14:53 -0700152 if ($prebuildno.Length -eq 0) {
153 $prebuildno="z"*10
David Pinedoc21fdb92016-01-04 16:31:57 -0700154 }
155 }
156
David Pinedoc27e0442016-03-15 11:07:19 -0600157 # Make sure fields that are supposed to be numbers are numbers
158 if (notNumeric($major)) {return}
159 if (notNumeric($minor)) {return}
160 if (notNumeric($patch)) {return}
161 if (notNumeric($buildno)) {return}
162 if (notNumeric($prebuildno)) {
163 if ($prebuildno -ne "z"*10) {return}
164 }
165
David Pinedoc21fdb92016-01-04 16:31:57 -0700166 $major = $major.padleft(10,'0')
167 $minor = $minor.padleft(10,'0')
168 $patch = $patch.padleft(10,'0')
David Pinedoc21fdb92016-01-04 16:31:57 -0700169 $buildno = $buildno.padleft(10,'0')
David Pinedo3bdbe5d2016-01-12 16:14:53 -0700170 $prerelease = $prerelease.padleft(10,'0')
171 $prebuildno = $prebuildno.padleft(10,'0')
David Pinedoc21fdb92016-01-04 16:31:57 -0700172
173 # Add a new element to the $VulkanDllList array
David Pinedo5da20dd2016-01-13 16:22:19 -0700174 $VulkanDllList+="$major=$minor=$patch=$buildno=$prerelease=$prebuildno= $_ @$majorOrig@$minorOrig@$patchOrig@$buildnoOrig@$prereleaseOrig@$prebuildnoOrig@"
David Pinedoc21fdb92016-01-04 16:31:57 -0700175 }
176
Mark Younga81e6082016-01-15 12:35:39 -0700177 # If $VulkanDllList contains at least one element, there's at least one vulkan*.dll file.
178 # Copy the most recent vulkan*.dll (named in the last element of $VulkanDllList) to vulkan-$majorabi.dll.
David Pinedoc21fdb92016-01-04 16:31:57 -0700179
Mark Younga81e6082016-01-15 12:35:39 -0700180 if ($VulkanDllList.Length -gt 0) {
David Pinedoc21fdb92016-01-04 16:31:57 -0700181
Mark Younga81e6082016-01-15 12:35:39 -0700182 # Sort the list. The most recent vulkan-*.dll will be in the last element of the list.
183 [array]::sort($VulkanDllList)
David Pinedoc21fdb92016-01-04 16:31:57 -0700184
Mark Younga81e6082016-01-15 12:35:39 -0700185 # Put the name of the most recent vulkan-*.dll in $mrVulkanDLL.
186 # The most recent vulkanDLL is the second word in the last element of the
187 # sorted $VulkanDllList. Copy it to $vulkandll.
188 $mrVulkanDll=$VulkanDllList[-1].Split(' ')[1]
189 copy $mrVulkanDll $vulkandll
David Pinedoc21fdb92016-01-04 16:31:57 -0700190
Mark Younga81e6082016-01-15 12:35:39 -0700191 # Copy the most recent version of vulkaninfo-<abimajor>-*.exe to vulkaninfo.exe.
192 # We create the source file name for the copy from $mrVulkanDll.
193 $mrVulkaninfo=$mrVulkanDll -replace ".dll",".exe"
194 $mrVulkaninfo=$mrVulkaninfo -replace "vulkan","vulkaninfo"
195 copy $mrVulkaninfo vulkaninfo.exe
David Pinedo1e368f72016-02-04 17:04:44 -0700196
Mark Younga81e6082016-01-15 12:35:39 -0700197 # Create the name used in the registry for the SDK associated with $mrVulkanDll.
198 $major=$VulkanDLLList[-1].Split('@')[1]
199 $minor=$VulkanDLLList[-1].Split('@')[2]
200 $patch=$VulkanDLLList[-1].Split('@')[3]
201 $buildno=$VulkanDLLList[-1].Split('@')[4]
202 $prerelease=$VulkanDLLList[-1].Split('@')[5]
203 $prebuildno=$VulkanDLLList[-1].Split('@')[6]
David Pinedo1e368f72016-02-04 17:04:44 -0700204
Mark Youngd6897a32016-01-20 14:48:21 -0700205 $sdktempname="VulkanSDK"+$major + "." + $minor + "." + $patch + "." + $buildno
Mark Younga81e6082016-01-15 12:35:39 -0700206 if ($prerelease -ne "") {
Mark Youngd6897a32016-01-20 14:48:21 -0700207 $sdktempname=$sdktempname + "." + $prerelease
Mark Younga81e6082016-01-15 12:35:39 -0700208 }
209 if ($prebuildno -ne "") {
Mark Youngd6897a32016-01-20 14:48:21 -0700210 $sdktempname=$sdktempname + "." + $prebuildno
Mark Younga81e6082016-01-15 12:35:39 -0700211 }
David Pinedoc21fdb92016-01-04 16:31:57 -0700212 }
David Pinedo1e368f72016-02-04 17:04:44 -0700213
Mark Youngd6897a32016-01-20 14:48:21 -0700214 # Return to our previous folder
215 Pop-Location
216
217 # Only update the overall script-scope SDK name if we're told to
218 if ($writeSdkName -ne 0) {
219 $script:sdkname = $sdktempname
220 }
221
222 return
David Pinedoc21fdb92016-01-04 16:31:57 -0700223}
224
Mark Young4b8b5482016-01-15 15:09:39 -0700225# We only care about SYSWOW64 if we're targeting a 64-bit OS
Mark Youngb628d162016-01-19 15:29:34 -0700226if ($ossize -eq 64) {
Mark Young4b8b5482016-01-15 15:09:39 -0700227 # Update the SYSWOW64 Vulkan DLLS/EXEs
Mark Young71e2a402016-02-12 12:07:45 -0700228 UpdateVulkanSysFolder $winfolder\SYSWOW64 0
Mark Young4b8b5482016-01-15 15:09:39 -0700229}
230
231# Update the SYSTEM32 Vulkan DLLS/EXEs
Mark Young71e2a402016-02-12 12:07:45 -0700232UpdateVulkanSysFolder $winfolder\SYSTEM32 1
David Pinedoc21fdb92016-01-04 16:31:57 -0700233
234# Create an array of vulkan sdk install dirs
235
236$mrVulkanDllInstallDir=""
237$VulkanSdkDirs=@()
David Pinedo1e368f72016-02-04 17:04:44 -0700238Get-ChildItem -Path Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall |
David Pinedoc21fdb92016-01-04 16:31:57 -0700239 ForEach-Object {
240 $regkey=$_ -replace ".*\\",""
241 if ($_ -match "\\VulkanSDK") {
242 # Get the install path from UninstallString
243 $tmp=Get-ItemProperty -Path Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$regkey -Name UninstallString
244 $tmp=$tmp -replace "\\Uninstall.exe.*",""
245 $tmp=$tmp -replace ".*=.",""
246 $VulkanSdkDirs+=$tmp
Mark Youngd6897a32016-01-20 14:48:21 -0700247 if ($regkey -eq $script:sdkname) {
David Pinedoc21fdb92016-01-04 16:31:57 -0700248 # Save away the sdk install dir for the the most recent vulkandll
249 $mrVulkanDllInstallDir=$tmp
250 }
251 }
252 }
253
254# Add C:\Vulkan\SDK\0.9.3 to list of SDK install dirs.
255# We do this because there is in a bug in SDK 0.9.3 in which layer
256# reg entries were not removed on uninstall. So we'll try to clean up
257# and remove them now.
258# This works only if 0.9.3 was installed to the default location.
259# If it was not installed to the default location, those entries will
260# need to be cleaned up manually.
261
262$VulkanSdkDirs+="C:\VulkanSDK\0.9.3"
Mark Young71e2a402016-02-12 12:07:45 -0700263$VulkanSdkDirs+="$windrive\VulkanSDK\0.9.3"
David Pinedoc21fdb92016-01-04 16:31:57 -0700264
David Pinedoc21fdb92016-01-04 16:31:57 -0700265# Remove layer registry entries associated with all installed Vulkan SDKs.
266# Note that we remove only those entries created by Vulkan SDKs. If other
267# layers were installed that are not from an SDK, we don't mess with them.
268
269Get-Item -Path Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Khronos\Vulkan\ExplicitLayers | Select-Object -ExpandProperty Property |
270 ForEach-Object {
271 $regval=$_
272 ForEach ($sdkdir in $VulkanSdkDirs) {
273 if ($regval -like "$sdkdir\*.json") {
David Pinedo9bb478f2016-01-19 21:19:11 -0700274 Remove-ItemProperty -ErrorAction SilentlyContinue -Path HKLM:\SOFTWARE\Khronos\Vulkan\ExplicitLayers -name $regval
David Pinedoc21fdb92016-01-04 16:31:57 -0700275 }
276 }
277 }
Mark Youngb628d162016-01-19 15:29:34 -0700278# Remove 32-bit layer registry entries if we're targeting a 64-bit OS
279if ($ossize -eq 64) {
280 Get-Item -Path Registry::HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Khronos\Vulkan\ExplicitLayers | Select-Object -ExpandProperty Property |
281 ForEach-Object {
282 $regval=$_
283 ForEach ($sdkdir in $VulkanSdkDirs) {
284 if ($regval -like "$sdkdir\*.json") {
Mark Youngd6897a32016-01-20 14:48:21 -0700285 Remove-ItemProperty -ErrorAction SilentlyContinue -Path HKLM:\SOFTWARE\WOW6432Node\Khronos\Vulkan\ExplicitLayers -name $regval
Mark Youngb628d162016-01-19 15:29:34 -0700286 }
287 }
288 }
289}
David Pinedoc21fdb92016-01-04 16:31:57 -0700290
291
292# Create layer registry entries associated with Vulkan SDK from which $mrVulkanDll is from
293
294if ($mrVulkanDllInstallDir -ne "") {
Mark Youngb628d162016-01-19 15:29:34 -0700295 if ($ossize -eq 64) {
Mark Young51d35072016-02-09 15:30:34 -0700296
297 # Create registry entires in normal registry location for 64-bit items on a 64-bit OS
298 New-Item -Force -ErrorAction SilentlyContinue -Path HKLM:\SOFTWARE\Khronos\Vulkan\ExplicitLayers | out-null
299 Get-ChildItem $mrVulkanDllInstallDir\Bin -Filter VkLayer*json |
300 ForEach-Object {
301 New-ItemProperty -Path HKLM:\SOFTWARE\Khronos\Vulkan\ExplicitLayers -Name $mrVulkanDllInstallDir\Bin\$_ -PropertyType DWord -Value 0 | out-null
302 }
303
304 # Create registry entires for the WOW6432Node registry location for 32-bit items on a 64-bit OS
305 New-Item -Force -ErrorAction SilentlyContinue -Path HKLM:\SOFTWARE\WOW6432Node\Khronos\Vulkan\ExplicitLayers | out-null
David Pinedo431b82a2016-02-05 09:48:26 -0700306 Get-ChildItem $mrVulkanDllInstallDir\Bin32 -Filter VkLayer*json |
Mark Youngb628d162016-01-19 15:29:34 -0700307 ForEach-Object {
Mark Youngd6897a32016-01-20 14:48:21 -0700308 New-ItemProperty -Path HKLM:\SOFTWARE\WOW6432Node\Khronos\Vulkan\ExplicitLayers -Name $mrVulkanDllInstallDir\Bin32\$_ -PropertyType DWord -Value 0 | out-null
Mark Youngb628d162016-01-19 15:29:34 -0700309 }
Mark Young51d35072016-02-09 15:30:34 -0700310
311 } else {
312
313 # Create registry entires in normal registry location for 32-bit items on a 32-bit OS
314 New-Item -Force -ErrorAction SilentlyContinue -Path HKLM:\SOFTWARE\Khronos\Vulkan\ExplicitLayers | out-null
315 Get-ChildItem $mrVulkanDllInstallDir\Bin32 -Filter VkLayer*json |
316 ForEach-Object {
317 New-ItemProperty -Path HKLM:\SOFTWARE\Khronos\Vulkan\ExplicitLayers -Name $mrVulkanDllInstallDir\Bin32\$_ -PropertyType DWord -Value 0 | out-null
318 }
319
Mark Youngb628d162016-01-19 15:29:34 -0700320 }
David Pinedoc21fdb92016-01-04 16:31:57 -0700321}