blob: 13a7b4cdd6b73af0aad4b2468b451efbdaafd145 [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 Young4b8b5482016-01-15 15:09:39 -070035# This script takes two parameters:
36# $majorabi : a single string number specifying the major abi version.
37# $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 Younga81e6082016-01-15 12:35:39 -070077function UpdateVulkanSysFolder($dir)
78{
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]
170 $sdkname="VulkanSDK"+$major + "." + $minor + "." + $patch + "." + $buildno
171 if ($prerelease -ne "") {
172 $sdkname=$sdkname + "." + $prerelease
173 }
174 if ($prebuildno -ne "") {
175 $sdkname=$sdkname + "." + $prebuildno
176 }
David Pinedoc21fdb92016-01-04 16:31:57 -0700177 }
Mark Younga81e6082016-01-15 12:35:39 -0700178
179 # Return to our previous folder
180 Pop-Location
David Pinedoc21fdb92016-01-04 16:31:57 -0700181}
182
Mark Young4b8b5482016-01-15 15:09:39 -0700183# We only care about SYSWOW64 if we're targeting a 64-bit OS
184if ($ossize -eq 64)
185{
186 # Update the SYSWOW64 Vulkan DLLS/EXEs
187 UpdateVulkanSysFolder c:\WINDOWS\SYSWOW64
188}
189
190# Update the SYSTEM32 Vulkan DLLS/EXEs
Mark Younga81e6082016-01-15 12:35:39 -0700191UpdateVulkanSysFolder c:\WINDOWS\SYSTEM32
David Pinedoc21fdb92016-01-04 16:31:57 -0700192
193# Create an array of vulkan sdk install dirs
194
195$mrVulkanDllInstallDir=""
196$VulkanSdkDirs=@()
197Get-ChildItem -Path Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall |
198 ForEach-Object {
199 $regkey=$_ -replace ".*\\",""
200 if ($_ -match "\\VulkanSDK") {
201 # Get the install path from UninstallString
202 $tmp=Get-ItemProperty -Path Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$regkey -Name UninstallString
203 $tmp=$tmp -replace "\\Uninstall.exe.*",""
204 $tmp=$tmp -replace ".*=.",""
205 $VulkanSdkDirs+=$tmp
206 if ($regkey -eq $sdkname) {
207 # Save away the sdk install dir for the the most recent vulkandll
208 $mrVulkanDllInstallDir=$tmp
209 }
210 }
211 }
212
213# Add C:\Vulkan\SDK\0.9.3 to list of SDK install dirs.
214# We do this because there is in a bug in SDK 0.9.3 in which layer
215# reg entries were not removed on uninstall. So we'll try to clean up
216# and remove them now.
217# This works only if 0.9.3 was installed to the default location.
218# If it was not installed to the default location, those entries will
219# need to be cleaned up manually.
220
221$VulkanSdkDirs+="C:\VulkanSDK\0.9.3"
222
David Pinedoc21fdb92016-01-04 16:31:57 -0700223# Remove layer registry entries associated with all installed Vulkan SDKs.
224# Note that we remove only those entries created by Vulkan SDKs. If other
225# layers were installed that are not from an SDK, we don't mess with them.
226
227Get-Item -Path Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Khronos\Vulkan\ExplicitLayers | Select-Object -ExpandProperty Property |
228 ForEach-Object {
229 $regval=$_
230 ForEach ($sdkdir in $VulkanSdkDirs) {
231 if ($regval -like "$sdkdir\*.json") {
David Pinedo9bb478f2016-01-19 21:19:11 -0700232 Remove-ItemProperty -ErrorAction SilentlyContinue -Path HKLM:\SOFTWARE\Khronos\Vulkan\ExplicitLayers -name $regval
David Pinedoc21fdb92016-01-04 16:31:57 -0700233 }
234 }
235 }
236
237
238# Create layer registry entries associated with Vulkan SDK from which $mrVulkanDll is from
239
240if ($mrVulkanDllInstallDir -ne "") {
David Pinedo9bb478f2016-01-19 21:19:11 -0700241 New-Item -Force -ErrorAction SilentlyContinue -Path HKLM:\SOFTWARE\Khronos\Vulkan\ExplicitLayers | out-null
David Pinedoc21fdb92016-01-04 16:31:57 -0700242 Get-ChildItem $mrVulkanDllInstallDir\Bin -Filter *json |
243 ForEach-Object {
244 New-ItemProperty -Path HKLM:\SOFTWARE\Khronos\Vulkan\ExplicitLayers -Name $mrVulkanDllInstallDir\Bin\$_ -PropertyType DWord -Value 0 | out-null
245 }
246}