blob: ce3ab23388eb8ff45a304303036434adab92968b [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
Mark Younga81e6082016-01-15 12:35:39 -070069function UpdateVulkanSysFolder($dir)
70{
71 # Push the current path on the stack and go to $dir
72 Push-Location -Path $dir
73
74 # Create a list for all the DLLs in the folder
75 $VulkanDllList=@()
76
77 # Find all DLL objects in this directory
78 dir -name vulkan-$majorabi-*.dll |
David Pinedoc21fdb92016-01-04 16:31:57 -070079 ForEach-Object {
80 $major=$_.Split('-')[2]
81 $majorOrig=$major
82 $minor=$_.Split('-')[3]
83 $minorOrig=$minor
84 $patch=$_.Split('-')[4]
David Pinedo3bdbe5d2016-01-12 16:14:53 -070085 $patchOrig=$patch
86 $buildno=$_.Split('-')[5]
David Pinedoc21fdb92016-01-04 16:31:57 -070087
David Pinedo3bdbe5d2016-01-12 16:14:53 -070088 if ($buildno -match ".dll") {
89 # <prerelease> and <prebuildno> are not in the name
90 $buildno=$buildno -replace ".dll",""
91 $buildnoOrig=$buildno
David Pinedoc21fdb92016-01-04 16:31:57 -070092 $prerelease="z"*10
93 $prereleaseOrig=""
David Pinedo3bdbe5d2016-01-12 16:14:53 -070094 $prebuildno="z"*10
95 $prebuildnoOrig=""
David Pinedoc21fdb92016-01-04 16:31:57 -070096 } else {
97
98 # We assume we don't have more than 5 dashes
99
100 $f=$_ -replace ".dll",""
David Pinedo3bdbe5d2016-01-12 16:14:53 -0700101 $buildno=$f.Split('-')[5]
David Pinedo5da20dd2016-01-13 16:22:19 -0700102 $buildnoOrig=$buildno
David Pinedo3bdbe5d2016-01-12 16:14:53 -0700103 $prerelease=$f.Split('-')[6]
104 $prebuildno=$f.Split('-')[7]
105 if ($prebuildno.Length -eq 0) {
David Pinedoc21fdb92016-01-04 16:31:57 -0700106 if ($prerelease -match "^[0-9]") {
David Pinedo3bdbe5d2016-01-12 16:14:53 -0700107 # prerelease starts with a digit, it must be the prebuildno
108 $prebuildno=$prerelease
David Pinedoc21fdb92016-01-04 16:31:57 -0700109 $prerelease=""
110 }
111 }
David Pinedoc21fdb92016-01-04 16:31:57 -0700112 $prereleaseOrig=$prerelease
David Pinedo3bdbe5d2016-01-12 16:14:53 -0700113 $prebuildnoOrig=$prebuildno
David Pinedoc21fdb92016-01-04 16:31:57 -0700114
115 if ($prerelease.Length -eq 0) {
116 $prerelease="z"*10
117 }
David Pinedo3bdbe5d2016-01-12 16:14:53 -0700118 if ($prebuildno.Length -eq 0) {
119 $prebuildno="z"*10
David Pinedoc21fdb92016-01-04 16:31:57 -0700120 }
121 }
122
123 $major = $major.padleft(10,'0')
124 $minor = $minor.padleft(10,'0')
125 $patch = $patch.padleft(10,'0')
David Pinedoc21fdb92016-01-04 16:31:57 -0700126 $buildno = $buildno.padleft(10,'0')
David Pinedo3bdbe5d2016-01-12 16:14:53 -0700127 $prerelease = $prerelease.padleft(10,'0')
128 $prebuildno = $prebuildno.padleft(10,'0')
David Pinedoc21fdb92016-01-04 16:31:57 -0700129
130 # Add a new element to the $VulkanDllList array
David Pinedo5da20dd2016-01-13 16:22:19 -0700131 $VulkanDllList+="$major=$minor=$patch=$buildno=$prerelease=$prebuildno= $_ @$majorOrig@$minorOrig@$patchOrig@$buildnoOrig@$prereleaseOrig@$prebuildnoOrig@"
David Pinedoc21fdb92016-01-04 16:31:57 -0700132 }
133
Mark Younga81e6082016-01-15 12:35:39 -0700134 # If $VulkanDllList contains at least one element, there's at least one vulkan*.dll file.
135 # Copy the most recent vulkan*.dll (named in the last element of $VulkanDllList) to vulkan-$majorabi.dll.
136 # TODO: In the future, also copy the corresponding vulkaninfo-*.exe to vulkaninfo.exe.
David Pinedoc21fdb92016-01-04 16:31:57 -0700137
Mark Younga81e6082016-01-15 12:35:39 -0700138 if ($VulkanDllList.Length -gt 0) {
David Pinedoc21fdb92016-01-04 16:31:57 -0700139
Mark Younga81e6082016-01-15 12:35:39 -0700140 # Sort the list. The most recent vulkan-*.dll will be in the last element of the list.
141 [array]::sort($VulkanDllList)
David Pinedoc21fdb92016-01-04 16:31:57 -0700142
Mark Younga81e6082016-01-15 12:35:39 -0700143 # Put the name of the most recent vulkan-*.dll in $mrVulkanDLL.
144 # The most recent vulkanDLL is the second word in the last element of the
145 # sorted $VulkanDllList. Copy it to $vulkandll.
146 $mrVulkanDll=$VulkanDllList[-1].Split(' ')[1]
147 copy $mrVulkanDll $vulkandll
David Pinedoc21fdb92016-01-04 16:31:57 -0700148
Mark Younga81e6082016-01-15 12:35:39 -0700149 # Copy the most recent version of vulkaninfo-<abimajor>-*.exe to vulkaninfo.exe.
150 # We create the source file name for the copy from $mrVulkanDll.
151 $mrVulkaninfo=$mrVulkanDll -replace ".dll",".exe"
152 $mrVulkaninfo=$mrVulkaninfo -replace "vulkan","vulkaninfo"
153 copy $mrVulkaninfo vulkaninfo.exe
154
155 # Create the name used in the registry for the SDK associated with $mrVulkanDll.
156 $major=$VulkanDLLList[-1].Split('@')[1]
157 $minor=$VulkanDLLList[-1].Split('@')[2]
158 $patch=$VulkanDLLList[-1].Split('@')[3]
159 $buildno=$VulkanDLLList[-1].Split('@')[4]
160 $prerelease=$VulkanDLLList[-1].Split('@')[5]
161 $prebuildno=$VulkanDLLList[-1].Split('@')[6]
162 $sdkname="VulkanSDK"+$major + "." + $minor + "." + $patch + "." + $buildno
163 if ($prerelease -ne "") {
164 $sdkname=$sdkname + "." + $prerelease
165 }
166 if ($prebuildno -ne "") {
167 $sdkname=$sdkname + "." + $prebuildno
168 }
David Pinedoc21fdb92016-01-04 16:31:57 -0700169 }
Mark Younga81e6082016-01-15 12:35:39 -0700170
171 # Return to our previous folder
172 Pop-Location
David Pinedoc21fdb92016-01-04 16:31:57 -0700173}
174
Mark Younga81e6082016-01-15 12:35:39 -0700175# Update the SYSWOW64 and SYSTEM32 Vulkan items
176UpdateVulkanSysFolder c:\WINDOWS\SYSWOW64
177UpdateVulkanSysFolder c:\WINDOWS\SYSTEM32
David Pinedoc21fdb92016-01-04 16:31:57 -0700178
179# Create an array of vulkan sdk install dirs
180
181$mrVulkanDllInstallDir=""
182$VulkanSdkDirs=@()
183Get-ChildItem -Path Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall |
184 ForEach-Object {
185 $regkey=$_ -replace ".*\\",""
186 if ($_ -match "\\VulkanSDK") {
187 # Get the install path from UninstallString
188 $tmp=Get-ItemProperty -Path Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$regkey -Name UninstallString
189 $tmp=$tmp -replace "\\Uninstall.exe.*",""
190 $tmp=$tmp -replace ".*=.",""
191 $VulkanSdkDirs+=$tmp
192 if ($regkey -eq $sdkname) {
193 # Save away the sdk install dir for the the most recent vulkandll
194 $mrVulkanDllInstallDir=$tmp
195 }
196 }
197 }
198
199# Add C:\Vulkan\SDK\0.9.3 to list of SDK install dirs.
200# We do this because there is in a bug in SDK 0.9.3 in which layer
201# reg entries were not removed on uninstall. So we'll try to clean up
202# and remove them now.
203# This works only if 0.9.3 was installed to the default location.
204# If it was not installed to the default location, those entries will
205# need to be cleaned up manually.
206
207$VulkanSdkDirs+="C:\VulkanSDK\0.9.3"
208
209
210# Remove layer registry entries associated with all installed Vulkan SDKs.
211# Note that we remove only those entries created by Vulkan SDKs. If other
212# layers were installed that are not from an SDK, we don't mess with them.
213
214Get-Item -Path Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Khronos\Vulkan\ExplicitLayers | Select-Object -ExpandProperty Property |
215 ForEach-Object {
216 $regval=$_
217 ForEach ($sdkdir in $VulkanSdkDirs) {
218 if ($regval -like "$sdkdir\*.json") {
David Pinedo9bb478f2016-01-19 21:19:11 -0700219 Remove-ItemProperty -ErrorAction SilentlyContinue -Path HKLM:\SOFTWARE\Khronos\Vulkan\ExplicitLayers -name $regval
David Pinedoc21fdb92016-01-04 16:31:57 -0700220 }
221 }
222 }
223
224
225# Create layer registry entries associated with Vulkan SDK from which $mrVulkanDll is from
226
227if ($mrVulkanDllInstallDir -ne "") {
David Pinedo9bb478f2016-01-19 21:19:11 -0700228 New-Item -Force -ErrorAction SilentlyContinue -Path HKLM:\SOFTWARE\Khronos\Vulkan\ExplicitLayers | out-null
David Pinedoc21fdb92016-01-04 16:31:57 -0700229 Get-ChildItem $mrVulkanDllInstallDir\Bin -Filter *json |
230 ForEach-Object {
231 New-ItemProperty -Path HKLM:\SOFTWARE\Khronos\Vulkan\ExplicitLayers -Name $mrVulkanDllInstallDir\Bin\$_ -PropertyType DWord -Value 0 | out-null
232 }
233}