blob: f1c6c0a3b3d703a533b8e9c67d9f310c60ef0857 [file] [log] [blame]
David Pinedoc21fdb92016-01-04 16:31:57 -07001#
2# Copyright (C) 2016 Valve Corporation
3#
4# Permission is hereby granted, free of charge, to any person obtaining a
5# copy of this software and associated documentation files (the "Software"),
6# to deal in the Software without restriction, including without limitation
7# the rights to use, copy, modify, merge, publish, distribute, sublicense,
8# and/or sell copies of the Software, and to permit persons to whom the
9# Software is furnished to do so, subject to the following conditions:
10#
11# The above copyright notice and this permission notice shall be included
12# in all copies or substantial portions of the Software.
13#
14# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20# DEALINGS IN THE SOFTWARE.
21#
22# Author: David Pinedo <david@LunarG.com>
23#
24
25# This Powershell script is used by the Vulkan Run Time Installer/Uninstaller to:
26# - Copy the most recent vulkan-<majorabi>-*.dll in C:\Windows\System32
27# to vulkan-<majorabi>.dll
28# - Copy the most recent version of vulkaninfo-<abimajor>-*.exe in
29# C:\Windows\System32 to vulkaninfo.exe
Mark Young4b8b5482016-01-15 15:09:39 -070030# - The same thing is done for those files in C:\Windows\SysWOW64 on a 64-bit
31# target.
David Pinedoc21fdb92016-01-04 16:31:57 -070032# - Set the layer registry entries to point to the layer json files
33# in the Vulkan SDK associated with the most recent vulkan*dll.
34#
Mark Youngaf87f222016-01-20 16:33:18 -070035# This script takes the following parameters:
Mark Young4b8b5482016-01-15 15:09:39 -070036# $majorabi : a single string number specifying the major abi version.
Mark Youngaf87f222016-01-20 16:33:18 -070037# $ossize : an integer indicating if the target is a 64 (64) or 32 (32) bit OS.
David Pinedoc21fdb92016-01-04 16:31:57 -070038#
39
Mark Young4b8b5482016-01-15 15:09:39 -070040Param(
41 [string]$majorabi,
42 [int]$ossize
43)
David Pinedoc21fdb92016-01-04 16:31:57 -070044
45$vulkandll = "vulkan-"+$majorabi+".dll"
46
47# The name of the versioned vulkan dll file is one of the following:
48#
David Pinedo3bdbe5d2016-01-12 16:14:53 -070049# vulkan-<majorabi>-<major>-<minor>-<patch>-<buildno>-<prerelease>-<prebuildno>
50# vulkan-<majorabi>-<major>-<minor>-<patch>-<buildno>-<prerelease>
51# vulkan-<majorabi>-<major>-<minor>-<patch>-<buildno>-<prebuildno>
David Pinedoc21fdb92016-01-04 16:31:57 -070052# vulkan-<majorabi>-<major>-<minor>-<patch>-<buildno>.dll
David Pinedoc21fdb92016-01-04 16:31:57 -070053#
David Pinedo3bdbe5d2016-01-12 16:14:53 -070054# <major>, <minor>, <patch>, <buildno> and <prebuildno> are 1 to 10 numeric digits.
55# <prerelease> is any combination of alpha and numeric characters.
56# If <prerelease> and/or <prebuildno> are present, this identifies a prerelease,
57# and the vulkan dll file will be considered less recent than one with the same
58# <major>, <minor>, <patch>, <buildno> numbers without the <prerelease> and/or
59# <prebuildno>.
David Pinedoc21fdb92016-01-04 16:31:57 -070060
61
62# We first create an array, with one array element for each vulkan-*dll in
Mark Young4b8b5482016-01-15 15:09:39 -070063# C:\Windows\System32 (and C:\Windows\SysWOW64 on 64-bit systems), with each element
64# containing:
David Pinedo3bdbe5d2016-01-12 16:14:53 -070065# <major>=<minor>=<patch>=<buildno>=<prerelease>=<prebuildno>=
David Pinedoc21fdb92016-01-04 16:31:57 -070066# filename
David Pinedo3bdbe5d2016-01-12 16:14:53 -070067# @<major>@<minor>@<patch>@<buildno>@<prerelease>@<prebuildno>@
David Pinedoc21fdb92016-01-04 16:31:57 -070068# [Note that the above three lines are one element in the array.]
69# The build identifiers separated by "=" are suitable for sorting, i.e.
David Pinedo3bdbe5d2016-01-12 16:14:53 -070070# expanded to 10 digits with leading 0s. If <prerelease> or <prebuildno> are
71# not specified, "zzzzzzzzzz" is substituted for them, so that they sort
David Pinedoc21fdb92016-01-04 16:31:57 -070072# to a position after those that do specify them.
73# The build identifiers separated by "@" are the original values extracted
74# from the file name. They are used later to find the path to the SDK
75# install directory for the given filename.
76
Mark Youngd6897a32016-01-20 14:48:21 -070077function UpdateVulkanSysFolder([string]$dir, [int]$writeSdkName)
Mark Younga81e6082016-01-15 12:35:39 -070078{
79 # Push the current path on the stack and go to $dir
80 Push-Location -Path $dir
81
82 # Create a list for all the DLLs in the folder
83 $VulkanDllList=@()
84
85 # Find all DLL objects in this directory
86 dir -name vulkan-$majorabi-*.dll |
David Pinedoc21fdb92016-01-04 16:31:57 -070087 ForEach-Object {
88 $major=$_.Split('-')[2]
89 $majorOrig=$major
90 $minor=$_.Split('-')[3]
91 $minorOrig=$minor
92 $patch=$_.Split('-')[4]
David Pinedo3bdbe5d2016-01-12 16:14:53 -070093 $patchOrig=$patch
94 $buildno=$_.Split('-')[5]
David Pinedoc21fdb92016-01-04 16:31:57 -070095
David Pinedo3bdbe5d2016-01-12 16:14:53 -070096 if ($buildno -match ".dll") {
97 # <prerelease> and <prebuildno> are not in the name
98 $buildno=$buildno -replace ".dll",""
99 $buildnoOrig=$buildno
David Pinedoc21fdb92016-01-04 16:31:57 -0700100 $prerelease="z"*10
101 $prereleaseOrig=""
David Pinedo3bdbe5d2016-01-12 16:14:53 -0700102 $prebuildno="z"*10
103 $prebuildnoOrig=""
David Pinedoc21fdb92016-01-04 16:31:57 -0700104 } else {
105
106 # We assume we don't have more than 5 dashes
107
108 $f=$_ -replace ".dll",""
David Pinedo3bdbe5d2016-01-12 16:14:53 -0700109 $buildno=$f.Split('-')[5]
David Pinedo5da20dd2016-01-13 16:22:19 -0700110 $buildnoOrig=$buildno
David Pinedo3bdbe5d2016-01-12 16:14:53 -0700111 $prerelease=$f.Split('-')[6]
112 $prebuildno=$f.Split('-')[7]
113 if ($prebuildno.Length -eq 0) {
David Pinedoc21fdb92016-01-04 16:31:57 -0700114 if ($prerelease -match "^[0-9]") {
David Pinedo3bdbe5d2016-01-12 16:14:53 -0700115 # prerelease starts with a digit, it must be the prebuildno
116 $prebuildno=$prerelease
David Pinedoc21fdb92016-01-04 16:31:57 -0700117 $prerelease=""
118 }
119 }
David Pinedoc21fdb92016-01-04 16:31:57 -0700120 $prereleaseOrig=$prerelease
David Pinedo3bdbe5d2016-01-12 16:14:53 -0700121 $prebuildnoOrig=$prebuildno
David Pinedoc21fdb92016-01-04 16:31:57 -0700122
123 if ($prerelease.Length -eq 0) {
124 $prerelease="z"*10
125 }
David Pinedo3bdbe5d2016-01-12 16:14:53 -0700126 if ($prebuildno.Length -eq 0) {
127 $prebuildno="z"*10
David Pinedoc21fdb92016-01-04 16:31:57 -0700128 }
129 }
130
131 $major = $major.padleft(10,'0')
132 $minor = $minor.padleft(10,'0')
133 $patch = $patch.padleft(10,'0')
David Pinedoc21fdb92016-01-04 16:31:57 -0700134 $buildno = $buildno.padleft(10,'0')
David Pinedo3bdbe5d2016-01-12 16:14:53 -0700135 $prerelease = $prerelease.padleft(10,'0')
136 $prebuildno = $prebuildno.padleft(10,'0')
David Pinedoc21fdb92016-01-04 16:31:57 -0700137
138 # Add a new element to the $VulkanDllList array
David Pinedo5da20dd2016-01-13 16:22:19 -0700139 $VulkanDllList+="$major=$minor=$patch=$buildno=$prerelease=$prebuildno= $_ @$majorOrig@$minorOrig@$patchOrig@$buildnoOrig@$prereleaseOrig@$prebuildnoOrig@"
David Pinedoc21fdb92016-01-04 16:31:57 -0700140 }
141
Mark Younga81e6082016-01-15 12:35:39 -0700142 # If $VulkanDllList contains at least one element, there's at least one vulkan*.dll file.
143 # Copy the most recent vulkan*.dll (named in the last element of $VulkanDllList) to vulkan-$majorabi.dll.
144 # TODO: In the future, also copy the corresponding vulkaninfo-*.exe to vulkaninfo.exe.
David Pinedoc21fdb92016-01-04 16:31:57 -0700145
Mark Younga81e6082016-01-15 12:35:39 -0700146 if ($VulkanDllList.Length -gt 0) {
David Pinedoc21fdb92016-01-04 16:31:57 -0700147
Mark Younga81e6082016-01-15 12:35:39 -0700148 # Sort the list. The most recent vulkan-*.dll will be in the last element of the list.
149 [array]::sort($VulkanDllList)
David Pinedoc21fdb92016-01-04 16:31:57 -0700150
Mark Younga81e6082016-01-15 12:35:39 -0700151 # Put the name of the most recent vulkan-*.dll in $mrVulkanDLL.
152 # The most recent vulkanDLL is the second word in the last element of the
153 # sorted $VulkanDllList. Copy it to $vulkandll.
154 $mrVulkanDll=$VulkanDllList[-1].Split(' ')[1]
155 copy $mrVulkanDll $vulkandll
David Pinedoc21fdb92016-01-04 16:31:57 -0700156
Mark Younga81e6082016-01-15 12:35:39 -0700157 # Copy the most recent version of vulkaninfo-<abimajor>-*.exe to vulkaninfo.exe.
158 # We create the source file name for the copy from $mrVulkanDll.
159 $mrVulkaninfo=$mrVulkanDll -replace ".dll",".exe"
160 $mrVulkaninfo=$mrVulkaninfo -replace "vulkan","vulkaninfo"
161 copy $mrVulkaninfo vulkaninfo.exe
162
163 # Create the name used in the registry for the SDK associated with $mrVulkanDll.
164 $major=$VulkanDLLList[-1].Split('@')[1]
165 $minor=$VulkanDLLList[-1].Split('@')[2]
166 $patch=$VulkanDLLList[-1].Split('@')[3]
167 $buildno=$VulkanDLLList[-1].Split('@')[4]
168 $prerelease=$VulkanDLLList[-1].Split('@')[5]
169 $prebuildno=$VulkanDLLList[-1].Split('@')[6]
Mark Youngd6897a32016-01-20 14:48:21 -0700170
171 $sdktempname="VulkanSDK"+$major + "." + $minor + "." + $patch + "." + $buildno
Mark Younga81e6082016-01-15 12:35:39 -0700172 if ($prerelease -ne "") {
Mark Youngd6897a32016-01-20 14:48:21 -0700173 $sdktempname=$sdktempname + "." + $prerelease
Mark Younga81e6082016-01-15 12:35:39 -0700174 }
175 if ($prebuildno -ne "") {
Mark Youngd6897a32016-01-20 14:48:21 -0700176 $sdktempname=$sdktempname + "." + $prebuildno
Mark Younga81e6082016-01-15 12:35:39 -0700177 }
David Pinedoc21fdb92016-01-04 16:31:57 -0700178 }
Mark Younga81e6082016-01-15 12:35:39 -0700179
Mark Youngd6897a32016-01-20 14:48:21 -0700180 # Return to our previous folder
181 Pop-Location
182
183 # Only update the overall script-scope SDK name if we're told to
184 if ($writeSdkName -ne 0) {
185 $script:sdkname = $sdktempname
186 }
187
188 return
David Pinedoc21fdb92016-01-04 16:31:57 -0700189}
190
Mark Young4b8b5482016-01-15 15:09:39 -0700191# We only care about SYSWOW64 if we're targeting a 64-bit OS
Mark Youngb628d162016-01-19 15:29:34 -0700192if ($ossize -eq 64) {
Mark Young4b8b5482016-01-15 15:09:39 -0700193 # Update the SYSWOW64 Vulkan DLLS/EXEs
Mark Youngd6897a32016-01-20 14:48:21 -0700194 UpdateVulkanSysFolder c:\WINDOWS\SYSWOW64 0
Mark Young4b8b5482016-01-15 15:09:39 -0700195}
196
197# Update the SYSTEM32 Vulkan DLLS/EXEs
Mark Youngd6897a32016-01-20 14:48:21 -0700198UpdateVulkanSysFolder c:\WINDOWS\SYSTEM32 1
David Pinedoc21fdb92016-01-04 16:31:57 -0700199
200# Create an array of vulkan sdk install dirs
201
202$mrVulkanDllInstallDir=""
203$VulkanSdkDirs=@()
204Get-ChildItem -Path Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall |
205 ForEach-Object {
206 $regkey=$_ -replace ".*\\",""
207 if ($_ -match "\\VulkanSDK") {
208 # Get the install path from UninstallString
209 $tmp=Get-ItemProperty -Path Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$regkey -Name UninstallString
210 $tmp=$tmp -replace "\\Uninstall.exe.*",""
211 $tmp=$tmp -replace ".*=.",""
212 $VulkanSdkDirs+=$tmp
Mark Youngd6897a32016-01-20 14:48:21 -0700213 if ($regkey -eq $script:sdkname) {
David Pinedoc21fdb92016-01-04 16:31:57 -0700214 # Save away the sdk install dir for the the most recent vulkandll
215 $mrVulkanDllInstallDir=$tmp
216 }
217 }
218 }
219
220# Add C:\Vulkan\SDK\0.9.3 to list of SDK install dirs.
221# We do this because there is in a bug in SDK 0.9.3 in which layer
222# reg entries were not removed on uninstall. So we'll try to clean up
223# and remove them now.
224# This works only if 0.9.3 was installed to the default location.
225# If it was not installed to the default location, those entries will
226# need to be cleaned up manually.
227
228$VulkanSdkDirs+="C:\VulkanSDK\0.9.3"
229
David Pinedoc21fdb92016-01-04 16:31:57 -0700230# Remove layer registry entries associated with all installed Vulkan SDKs.
231# Note that we remove only those entries created by Vulkan SDKs. If other
232# layers were installed that are not from an SDK, we don't mess with them.
233
234Get-Item -Path Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Khronos\Vulkan\ExplicitLayers | Select-Object -ExpandProperty Property |
235 ForEach-Object {
236 $regval=$_
237 ForEach ($sdkdir in $VulkanSdkDirs) {
238 if ($regval -like "$sdkdir\*.json") {
David Pinedo9bb478f2016-01-19 21:19:11 -0700239 Remove-ItemProperty -ErrorAction SilentlyContinue -Path HKLM:\SOFTWARE\Khronos\Vulkan\ExplicitLayers -name $regval
David Pinedoc21fdb92016-01-04 16:31:57 -0700240 }
241 }
242 }
Mark Youngb628d162016-01-19 15:29:34 -0700243# Remove 32-bit layer registry entries if we're targeting a 64-bit OS
244if ($ossize -eq 64) {
245 Get-Item -Path Registry::HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Khronos\Vulkan\ExplicitLayers | Select-Object -ExpandProperty Property |
246 ForEach-Object {
247 $regval=$_
248 ForEach ($sdkdir in $VulkanSdkDirs) {
249 if ($regval -like "$sdkdir\*.json") {
Mark Youngd6897a32016-01-20 14:48:21 -0700250 Remove-ItemProperty -ErrorAction SilentlyContinue -Path HKLM:\SOFTWARE\WOW6432Node\Khronos\Vulkan\ExplicitLayers -name $regval
Mark Youngb628d162016-01-19 15:29:34 -0700251 }
252 }
253 }
254}
David Pinedoc21fdb92016-01-04 16:31:57 -0700255
256
257# Create layer registry entries associated with Vulkan SDK from which $mrVulkanDll is from
258
259if ($mrVulkanDllInstallDir -ne "") {
David Pinedo9bb478f2016-01-19 21:19:11 -0700260 New-Item -Force -ErrorAction SilentlyContinue -Path HKLM:\SOFTWARE\Khronos\Vulkan\ExplicitLayers | out-null
David Pinedoc21fdb92016-01-04 16:31:57 -0700261 Get-ChildItem $mrVulkanDllInstallDir\Bin -Filter *json |
262 ForEach-Object {
263 New-ItemProperty -Path HKLM:\SOFTWARE\Khronos\Vulkan\ExplicitLayers -Name $mrVulkanDllInstallDir\Bin\$_ -PropertyType DWord -Value 0 | out-null
264 }
Mark Youngb628d162016-01-19 15:29:34 -0700265
266 # Create registry entires for the WOW6432Node registry only if we're targeting a 64-bit OS
267 if ($ossize -eq 64) {
268 New-Item -Force -ErrorAction Ignore -Path HKLM:\SOFTWARE\WOW6432Node\Khronos\Vulkan\ExplicitLayers | out-null
269 Get-ChildItem $mrVulkanDllInstallDir\Bin32 -Filter *json |
270 ForEach-Object {
Mark Youngd6897a32016-01-20 14:48:21 -0700271 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 -0700272 }
273 }
David Pinedoc21fdb92016-01-04 16:31:57 -0700274}