blob: 5dbcbec8762ad7b601678555de1b72853a040676 [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
30# - Set the layer registry entries to point to the layer json files
31# in the Vulkan SDK associated with the most recent vulkan*dll.
32#
33# This script takes one parameter - a single number specifying the major abi version.
34#
35
36Param([string]$majorabi)
37
38$vulkandll = "vulkan-"+$majorabi+".dll"
39
40# The name of the versioned vulkan dll file is one of the following:
41#
David Pinedo3bdbe5d2016-01-12 16:14:53 -070042# vulkan-<majorabi>-<major>-<minor>-<patch>-<buildno>-<prerelease>-<prebuildno>
43# vulkan-<majorabi>-<major>-<minor>-<patch>-<buildno>-<prerelease>
44# vulkan-<majorabi>-<major>-<minor>-<patch>-<buildno>-<prebuildno>
David Pinedoc21fdb92016-01-04 16:31:57 -070045# vulkan-<majorabi>-<major>-<minor>-<patch>-<buildno>.dll
David Pinedoc21fdb92016-01-04 16:31:57 -070046#
David Pinedo3bdbe5d2016-01-12 16:14:53 -070047# <major>, <minor>, <patch>, <buildno> and <prebuildno> are 1 to 10 numeric digits.
48# <prerelease> is any combination of alpha and numeric characters.
49# If <prerelease> and/or <prebuildno> are present, this identifies a prerelease,
50# and the vulkan dll file will be considered less recent than one with the same
51# <major>, <minor>, <patch>, <buildno> numbers without the <prerelease> and/or
52# <prebuildno>.
David Pinedoc21fdb92016-01-04 16:31:57 -070053
54
55# We first create an array, with one array element for each vulkan-*dll in
56# C:\Windows\System32, with each element containing:
David Pinedo3bdbe5d2016-01-12 16:14:53 -070057# <major>=<minor>=<patch>=<buildno>=<prerelease>=<prebuildno>=
David Pinedoc21fdb92016-01-04 16:31:57 -070058# filename
David Pinedo3bdbe5d2016-01-12 16:14:53 -070059# @<major>@<minor>@<patch>@<buildno>@<prerelease>@<prebuildno>@
David Pinedoc21fdb92016-01-04 16:31:57 -070060# [Note that the above three lines are one element in the array.]
61# The build identifiers separated by "=" are suitable for sorting, i.e.
David Pinedo3bdbe5d2016-01-12 16:14:53 -070062# expanded to 10 digits with leading 0s. If <prerelease> or <prebuildno> are
63# not specified, "zzzzzzzzzz" is substituted for them, so that they sort
David Pinedoc21fdb92016-01-04 16:31:57 -070064# to a position after those that do specify them.
65# The build identifiers separated by "@" are the original values extracted
66# from the file name. They are used later to find the path to the SDK
67# install directory for the given filename.
68
69$VulkanDllList=@()
70cd c:\WINDOWS\SYSTEM32
71dir -name vulkan-$majorabi-*.dll |
72 ForEach-Object {
73 $major=$_.Split('-')[2]
74 $majorOrig=$major
75 $minor=$_.Split('-')[3]
76 $minorOrig=$minor
77 $patch=$_.Split('-')[4]
David Pinedo3bdbe5d2016-01-12 16:14:53 -070078 $patchOrig=$patch
79 $buildno=$_.Split('-')[5]
David Pinedoc21fdb92016-01-04 16:31:57 -070080
David Pinedo3bdbe5d2016-01-12 16:14:53 -070081 if ($buildno -match ".dll") {
82 # <prerelease> and <prebuildno> are not in the name
83 $buildno=$buildno -replace ".dll",""
84 $buildnoOrig=$buildno
David Pinedoc21fdb92016-01-04 16:31:57 -070085 $prerelease="z"*10
86 $prereleaseOrig=""
David Pinedo3bdbe5d2016-01-12 16:14:53 -070087 $prebuildno="z"*10
88 $prebuildnoOrig=""
David Pinedoc21fdb92016-01-04 16:31:57 -070089 } else {
90
91 # We assume we don't have more than 5 dashes
92
93 $f=$_ -replace ".dll",""
David Pinedo3bdbe5d2016-01-12 16:14:53 -070094 $buildno=$f.Split('-')[5]
95 $prerelease=$f.Split('-')[6]
96 $prebuildno=$f.Split('-')[7]
97 if ($prebuildno.Length -eq 0) {
David Pinedoc21fdb92016-01-04 16:31:57 -070098 if ($prerelease -match "^[0-9]") {
David Pinedo3bdbe5d2016-01-12 16:14:53 -070099 # prerelease starts with a digit, it must be the prebuildno
100 $prebuildno=$prerelease
David Pinedoc21fdb92016-01-04 16:31:57 -0700101 $prerelease=""
102 }
103 }
David Pinedoc21fdb92016-01-04 16:31:57 -0700104 $prereleaseOrig=$prerelease
David Pinedo3bdbe5d2016-01-12 16:14:53 -0700105 $prebuildnoOrig=$prebuildno
David Pinedoc21fdb92016-01-04 16:31:57 -0700106
107 if ($prerelease.Length -eq 0) {
108 $prerelease="z"*10
109 }
David Pinedo3bdbe5d2016-01-12 16:14:53 -0700110 if ($prebuildno.Length -eq 0) {
111 $prebuildno="z"*10
David Pinedoc21fdb92016-01-04 16:31:57 -0700112 }
113 }
114
115 $major = $major.padleft(10,'0')
116 $minor = $minor.padleft(10,'0')
117 $patch = $patch.padleft(10,'0')
David Pinedoc21fdb92016-01-04 16:31:57 -0700118 $buildno = $buildno.padleft(10,'0')
David Pinedo3bdbe5d2016-01-12 16:14:53 -0700119 $prerelease = $prerelease.padleft(10,'0')
120 $prebuildno = $prebuildno.padleft(10,'0')
David Pinedoc21fdb92016-01-04 16:31:57 -0700121
122 # Add a new element to the $VulkanDllList array
David Pinedo3bdbe5d2016-01-12 16:14:53 -0700123 $VulkanDllList+="$major=$minor=$patch=$buildno=$prerelease=$prebuildno= $_ @$majorOrig@$minorOrig@$patch@$buildnoOrig@$prereleaseOrig@$prebuildnoOrig@"
David Pinedoc21fdb92016-01-04 16:31:57 -0700124 }
125
126
127# If $VulkanDllList contains at least one element, there's at least one vulkan*.dll file.
128# Copy the most recent vulkan*.dll (named in the last element of $VulkanDllList) to vulkan-0.dll.
129# Also copy the corresponding vulkaninfo-*.exe to vulkaninfo.exe.
130
131if ($VulkanDllList.Length -gt 0) {
132
133 # Sort the list. The most recent vulkan-*.dll will be in the last element of the list.
134 [array]::sort($VulkanDllList)
135
136 # Put the name of the most recent vulkan-*.dll in $mrVulkanDLL.
137 # The most recent vulkanDLL is the second word in the last element of the
138 # sorted $VulkanDllList. Copy it to $vulkandll.
139 $mrVulkanDll=$VulkanDLLList[-1].Split(' ')[1]
140 copy $mrVulkanDll $vulkandll
141
142 # Copy the most recent version of vulkaninfo-<abimajor>-*.exe to vulkaninfo.exe.
143 # We create the source file name for the copy from $mrVulkanDll.
144 $mrVulkaninfo=$mrVulkanDll -replace ".dll",".exe"
145 $mrVulkaninfo=$mrVulkaninfo -replace "vulkan","vulkaninfo"
146 copy $mrVulkaninfo vulkaninfo.exe
147
148 # Create the name used in the registry for the SDK associated with $mrVulkanDll.
149 $major=$VulkanDLLList[-1].Split('@')[1]
150 $minor=$VulkanDLLList[-1].Split('@')[2]
151 $patch=$VulkanDLLList[-1].Split('@')[3]
David Pinedo3bdbe5d2016-01-12 16:14:53 -0700152 $buildno=$VulkanDLLList[-1].Split('@')[4]
153 $prerelease=$VulkanDLLList[-1].Split('@')[5]
154 $prebuildno=$VulkanDLLList[-1].Split('@')[6]
David Pinedoc21fdb92016-01-04 16:31:57 -0700155 $sdkname="VulkanSDK"+$major + "." + $minor + "." + $patch
156 if ($prerelease -ne "") {
157 $sdkname=$sdkname + "." + $prerelease
158 }
David Pinedo3bdbe5d2016-01-12 16:14:53 -0700159 if ($prebuildno -ne "") {
160 $sdkname=$sdkname + "." + $prebuildno
David Pinedoc21fdb92016-01-04 16:31:57 -0700161 }
162}
163
164
165# Create an array of vulkan sdk install dirs
166
167$mrVulkanDllInstallDir=""
168$VulkanSdkDirs=@()
169Get-ChildItem -Path Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall |
170 ForEach-Object {
171 $regkey=$_ -replace ".*\\",""
172 if ($_ -match "\\VulkanSDK") {
173 # Get the install path from UninstallString
174 $tmp=Get-ItemProperty -Path Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$regkey -Name UninstallString
175 $tmp=$tmp -replace "\\Uninstall.exe.*",""
176 $tmp=$tmp -replace ".*=.",""
177 $VulkanSdkDirs+=$tmp
178 if ($regkey -eq $sdkname) {
179 # Save away the sdk install dir for the the most recent vulkandll
180 $mrVulkanDllInstallDir=$tmp
181 }
182 }
183 }
184
185# Add C:\Vulkan\SDK\0.9.3 to list of SDK install dirs.
186# We do this because there is in a bug in SDK 0.9.3 in which layer
187# reg entries were not removed on uninstall. So we'll try to clean up
188# and remove them now.
189# This works only if 0.9.3 was installed to the default location.
190# If it was not installed to the default location, those entries will
191# need to be cleaned up manually.
192
193$VulkanSdkDirs+="C:\VulkanSDK\0.9.3"
194
195
196# Remove layer registry entries associated with all installed Vulkan SDKs.
197# Note that we remove only those entries created by Vulkan SDKs. If other
198# layers were installed that are not from an SDK, we don't mess with them.
199
200Get-Item -Path Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Khronos\Vulkan\ExplicitLayers | Select-Object -ExpandProperty Property |
201 ForEach-Object {
202 $regval=$_
203 ForEach ($sdkdir in $VulkanSdkDirs) {
204 if ($regval -like "$sdkdir\*.json") {
205 Remove-ItemProperty -ErrorAction Ignore -Path HKLM:\SOFTWARE\Khronos\Vulkan\ExplicitLayers -name $regval
206 }
207 }
208 }
209
210
211# Create layer registry entries associated with Vulkan SDK from which $mrVulkanDll is from
212
213if ($mrVulkanDllInstallDir -ne "") {
214 New-Item -ErrorAction Ignore -Path HKLM:\SOFTWARE\Khronos\Vulkan\ExplicitLayers | out-null
215 Get-ChildItem $mrVulkanDllInstallDir\Bin -Filter *json |
216 ForEach-Object {
217 New-ItemProperty -Path HKLM:\SOFTWARE\Khronos\Vulkan\ExplicitLayers -Name $mrVulkanDllInstallDir\Bin\$_ -PropertyType DWord -Value 0 | out-null
218 }
219}