blob: 7d90f62048d1eb7424271d182edb7ad007633c0f [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 Confidential Information as defined by the Khronos
16# Membership Agreement until designated non-confidential by Khronos, at which
17# point this condition clause shall be removed.
David Pinedoc21fdb92016-01-04 16:31:57 -070018#
David Pinedo1e368f72016-02-04 17:04:44 -070019# THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
David Pinedoc21fdb92016-01-04 16:31:57 -070020# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
David Pinedo1e368f72016-02-04 17:04:44 -070021# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
22#
23# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
24# DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
25# OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE MATERIALS OR THE
26# USE OR OTHER DEALINGS IN THE MATERIALS.
David Pinedoc21fdb92016-01-04 16:31:57 -070027#
28# Author: David Pinedo <david@LunarG.com>
David Pinedo1e368f72016-02-04 17:04:44 -070029# Author: Mark Young <mark@LunarG.com>
David Pinedoc21fdb92016-01-04 16:31:57 -070030#
31
David Pinedo1e368f72016-02-04 17:04:44 -070032
David Pinedoc21fdb92016-01-04 16:31:57 -070033# This Powershell script is used by the Vulkan Run Time Installer/Uninstaller to:
34# - Copy the most recent vulkan-<majorabi>-*.dll in C:\Windows\System32
35# to vulkan-<majorabi>.dll
36# - Copy the most recent version of vulkaninfo-<abimajor>-*.exe in
37# C:\Windows\System32 to vulkaninfo.exe
Mark Young4b8b5482016-01-15 15:09:39 -070038# - The same thing is done for those files in C:\Windows\SysWOW64 on a 64-bit
39# target.
David Pinedoc21fdb92016-01-04 16:31:57 -070040# - Set the layer registry entries to point to the layer json files
41# in the Vulkan SDK associated with the most recent vulkan*dll.
42#
Mark Youngaf87f222016-01-20 16:33:18 -070043# This script takes the following parameters:
Mark Young4b8b5482016-01-15 15:09:39 -070044# $majorabi : a single string number specifying the major abi version.
Mark Youngaf87f222016-01-20 16:33:18 -070045# $ossize : an integer indicating if the target is a 64 (64) or 32 (32) bit OS.
David Pinedoc21fdb92016-01-04 16:31:57 -070046#
47
Mark Young4b8b5482016-01-15 15:09:39 -070048Param(
49 [string]$majorabi,
50 [int]$ossize
51)
David Pinedoc21fdb92016-01-04 16:31:57 -070052
53$vulkandll = "vulkan-"+$majorabi+".dll"
54
55# The name of the versioned vulkan dll file is one of the following:
56#
David Pinedo3bdbe5d2016-01-12 16:14:53 -070057# vulkan-<majorabi>-<major>-<minor>-<patch>-<buildno>-<prerelease>-<prebuildno>
58# vulkan-<majorabi>-<major>-<minor>-<patch>-<buildno>-<prerelease>
59# vulkan-<majorabi>-<major>-<minor>-<patch>-<buildno>-<prebuildno>
David Pinedoc21fdb92016-01-04 16:31:57 -070060# vulkan-<majorabi>-<major>-<minor>-<patch>-<buildno>.dll
David Pinedoc21fdb92016-01-04 16:31:57 -070061#
David Pinedo3bdbe5d2016-01-12 16:14:53 -070062# <major>, <minor>, <patch>, <buildno> and <prebuildno> are 1 to 10 numeric digits.
63# <prerelease> is any combination of alpha and numeric characters.
64# If <prerelease> and/or <prebuildno> are present, this identifies a prerelease,
65# and the vulkan dll file will be considered less recent than one with the same
66# <major>, <minor>, <patch>, <buildno> numbers without the <prerelease> and/or
67# <prebuildno>.
David Pinedoc21fdb92016-01-04 16:31:57 -070068
69
70# We first create an array, with one array element for each vulkan-*dll in
Mark Young4b8b5482016-01-15 15:09:39 -070071# C:\Windows\System32 (and C:\Windows\SysWOW64 on 64-bit systems), with each element
72# containing:
David Pinedo3bdbe5d2016-01-12 16:14:53 -070073# <major>=<minor>=<patch>=<buildno>=<prerelease>=<prebuildno>=
David Pinedoc21fdb92016-01-04 16:31:57 -070074# filename
David Pinedo3bdbe5d2016-01-12 16:14:53 -070075# @<major>@<minor>@<patch>@<buildno>@<prerelease>@<prebuildno>@
David Pinedoc21fdb92016-01-04 16:31:57 -070076# [Note that the above three lines are one element in the array.]
77# The build identifiers separated by "=" are suitable for sorting, i.e.
David Pinedo3bdbe5d2016-01-12 16:14:53 -070078# expanded to 10 digits with leading 0s. If <prerelease> or <prebuildno> are
79# not specified, "zzzzzzzzzz" is substituted for them, so that they sort
David Pinedoc21fdb92016-01-04 16:31:57 -070080# to a position after those that do specify them.
81# The build identifiers separated by "@" are the original values extracted
82# from the file name. They are used later to find the path to the SDK
83# install directory for the given filename.
84
Mark Youngd6897a32016-01-20 14:48:21 -070085function UpdateVulkanSysFolder([string]$dir, [int]$writeSdkName)
Mark Younga81e6082016-01-15 12:35:39 -070086{
87 # Push the current path on the stack and go to $dir
88 Push-Location -Path $dir
David Pinedo1e368f72016-02-04 17:04:44 -070089
Mark Younga81e6082016-01-15 12:35:39 -070090 # Create a list for all the DLLs in the folder
91 $VulkanDllList=@()
David Pinedo1e368f72016-02-04 17:04:44 -070092
Mark Younga81e6082016-01-15 12:35:39 -070093 # Find all DLL objects in this directory
94 dir -name vulkan-$majorabi-*.dll |
David Pinedoc21fdb92016-01-04 16:31:57 -070095 ForEach-Object {
96 $major=$_.Split('-')[2]
97 $majorOrig=$major
98 $minor=$_.Split('-')[3]
99 $minorOrig=$minor
100 $patch=$_.Split('-')[4]
David Pinedo3bdbe5d2016-01-12 16:14:53 -0700101 $patchOrig=$patch
102 $buildno=$_.Split('-')[5]
David Pinedoc21fdb92016-01-04 16:31:57 -0700103
David Pinedo3bdbe5d2016-01-12 16:14:53 -0700104 if ($buildno -match ".dll") {
105 # <prerelease> and <prebuildno> are not in the name
106 $buildno=$buildno -replace ".dll",""
107 $buildnoOrig=$buildno
David Pinedoc21fdb92016-01-04 16:31:57 -0700108 $prerelease="z"*10
109 $prereleaseOrig=""
David Pinedo3bdbe5d2016-01-12 16:14:53 -0700110 $prebuildno="z"*10
111 $prebuildnoOrig=""
David Pinedoc21fdb92016-01-04 16:31:57 -0700112 } else {
113
114 # We assume we don't have more than 5 dashes
115
116 $f=$_ -replace ".dll",""
David Pinedo3bdbe5d2016-01-12 16:14:53 -0700117 $buildno=$f.Split('-')[5]
David Pinedo5da20dd2016-01-13 16:22:19 -0700118 $buildnoOrig=$buildno
David Pinedo3bdbe5d2016-01-12 16:14:53 -0700119 $prerelease=$f.Split('-')[6]
120 $prebuildno=$f.Split('-')[7]
121 if ($prebuildno.Length -eq 0) {
David Pinedoc21fdb92016-01-04 16:31:57 -0700122 if ($prerelease -match "^[0-9]") {
David Pinedo3bdbe5d2016-01-12 16:14:53 -0700123 # prerelease starts with a digit, it must be the prebuildno
124 $prebuildno=$prerelease
David Pinedoc21fdb92016-01-04 16:31:57 -0700125 $prerelease=""
126 }
127 }
David Pinedoc21fdb92016-01-04 16:31:57 -0700128 $prereleaseOrig=$prerelease
David Pinedo3bdbe5d2016-01-12 16:14:53 -0700129 $prebuildnoOrig=$prebuildno
David Pinedoc21fdb92016-01-04 16:31:57 -0700130
131 if ($prerelease.Length -eq 0) {
132 $prerelease="z"*10
133 }
David Pinedo3bdbe5d2016-01-12 16:14:53 -0700134 if ($prebuildno.Length -eq 0) {
135 $prebuildno="z"*10
David Pinedoc21fdb92016-01-04 16:31:57 -0700136 }
137 }
138
139 $major = $major.padleft(10,'0')
140 $minor = $minor.padleft(10,'0')
141 $patch = $patch.padleft(10,'0')
David Pinedoc21fdb92016-01-04 16:31:57 -0700142 $buildno = $buildno.padleft(10,'0')
David Pinedo3bdbe5d2016-01-12 16:14:53 -0700143 $prerelease = $prerelease.padleft(10,'0')
144 $prebuildno = $prebuildno.padleft(10,'0')
David Pinedoc21fdb92016-01-04 16:31:57 -0700145
146 # Add a new element to the $VulkanDllList array
David Pinedo5da20dd2016-01-13 16:22:19 -0700147 $VulkanDllList+="$major=$minor=$patch=$buildno=$prerelease=$prebuildno= $_ @$majorOrig@$minorOrig@$patchOrig@$buildnoOrig@$prereleaseOrig@$prebuildnoOrig@"
David Pinedoc21fdb92016-01-04 16:31:57 -0700148 }
149
Mark Younga81e6082016-01-15 12:35:39 -0700150 # If $VulkanDllList contains at least one element, there's at least one vulkan*.dll file.
151 # Copy the most recent vulkan*.dll (named in the last element of $VulkanDllList) to vulkan-$majorabi.dll.
152 # TODO: In the future, also copy the corresponding vulkaninfo-*.exe to vulkaninfo.exe.
David Pinedoc21fdb92016-01-04 16:31:57 -0700153
Mark Younga81e6082016-01-15 12:35:39 -0700154 if ($VulkanDllList.Length -gt 0) {
David Pinedoc21fdb92016-01-04 16:31:57 -0700155
Mark Younga81e6082016-01-15 12:35:39 -0700156 # Sort the list. The most recent vulkan-*.dll will be in the last element of the list.
157 [array]::sort($VulkanDllList)
David Pinedoc21fdb92016-01-04 16:31:57 -0700158
Mark Younga81e6082016-01-15 12:35:39 -0700159 # Put the name of the most recent vulkan-*.dll in $mrVulkanDLL.
160 # The most recent vulkanDLL is the second word in the last element of the
161 # sorted $VulkanDllList. Copy it to $vulkandll.
162 $mrVulkanDll=$VulkanDllList[-1].Split(' ')[1]
163 copy $mrVulkanDll $vulkandll
David Pinedoc21fdb92016-01-04 16:31:57 -0700164
Mark Younga81e6082016-01-15 12:35:39 -0700165 # Copy the most recent version of vulkaninfo-<abimajor>-*.exe to vulkaninfo.exe.
166 # We create the source file name for the copy from $mrVulkanDll.
167 $mrVulkaninfo=$mrVulkanDll -replace ".dll",".exe"
168 $mrVulkaninfo=$mrVulkaninfo -replace "vulkan","vulkaninfo"
169 copy $mrVulkaninfo vulkaninfo.exe
David Pinedo1e368f72016-02-04 17:04:44 -0700170
Mark Younga81e6082016-01-15 12:35:39 -0700171 # Create the name used in the registry for the SDK associated with $mrVulkanDll.
172 $major=$VulkanDLLList[-1].Split('@')[1]
173 $minor=$VulkanDLLList[-1].Split('@')[2]
174 $patch=$VulkanDLLList[-1].Split('@')[3]
175 $buildno=$VulkanDLLList[-1].Split('@')[4]
176 $prerelease=$VulkanDLLList[-1].Split('@')[5]
177 $prebuildno=$VulkanDLLList[-1].Split('@')[6]
David Pinedo1e368f72016-02-04 17:04:44 -0700178
Mark Youngd6897a32016-01-20 14:48:21 -0700179 $sdktempname="VulkanSDK"+$major + "." + $minor + "." + $patch + "." + $buildno
Mark Younga81e6082016-01-15 12:35:39 -0700180 if ($prerelease -ne "") {
Mark Youngd6897a32016-01-20 14:48:21 -0700181 $sdktempname=$sdktempname + "." + $prerelease
Mark Younga81e6082016-01-15 12:35:39 -0700182 }
183 if ($prebuildno -ne "") {
Mark Youngd6897a32016-01-20 14:48:21 -0700184 $sdktempname=$sdktempname + "." + $prebuildno
Mark Younga81e6082016-01-15 12:35:39 -0700185 }
David Pinedoc21fdb92016-01-04 16:31:57 -0700186 }
David Pinedo1e368f72016-02-04 17:04:44 -0700187
Mark Youngd6897a32016-01-20 14:48:21 -0700188 # Return to our previous folder
189 Pop-Location
190
191 # Only update the overall script-scope SDK name if we're told to
192 if ($writeSdkName -ne 0) {
193 $script:sdkname = $sdktempname
194 }
195
196 return
David Pinedoc21fdb92016-01-04 16:31:57 -0700197}
198
Mark Young4b8b5482016-01-15 15:09:39 -0700199# We only care about SYSWOW64 if we're targeting a 64-bit OS
Mark Youngb628d162016-01-19 15:29:34 -0700200if ($ossize -eq 64) {
Mark Young4b8b5482016-01-15 15:09:39 -0700201 # Update the SYSWOW64 Vulkan DLLS/EXEs
Mark Youngd6897a32016-01-20 14:48:21 -0700202 UpdateVulkanSysFolder c:\WINDOWS\SYSWOW64 0
Mark Young4b8b5482016-01-15 15:09:39 -0700203}
204
205# Update the SYSTEM32 Vulkan DLLS/EXEs
Mark Youngd6897a32016-01-20 14:48:21 -0700206UpdateVulkanSysFolder c:\WINDOWS\SYSTEM32 1
David Pinedoc21fdb92016-01-04 16:31:57 -0700207
208# Create an array of vulkan sdk install dirs
209
210$mrVulkanDllInstallDir=""
211$VulkanSdkDirs=@()
David Pinedo1e368f72016-02-04 17:04:44 -0700212Get-ChildItem -Path Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall |
David Pinedoc21fdb92016-01-04 16:31:57 -0700213 ForEach-Object {
214 $regkey=$_ -replace ".*\\",""
215 if ($_ -match "\\VulkanSDK") {
216 # Get the install path from UninstallString
217 $tmp=Get-ItemProperty -Path Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$regkey -Name UninstallString
218 $tmp=$tmp -replace "\\Uninstall.exe.*",""
219 $tmp=$tmp -replace ".*=.",""
220 $VulkanSdkDirs+=$tmp
Mark Youngd6897a32016-01-20 14:48:21 -0700221 if ($regkey -eq $script:sdkname) {
David Pinedoc21fdb92016-01-04 16:31:57 -0700222 # Save away the sdk install dir for the the most recent vulkandll
223 $mrVulkanDllInstallDir=$tmp
224 }
225 }
226 }
227
228# Add C:\Vulkan\SDK\0.9.3 to list of SDK install dirs.
229# We do this because there is in a bug in SDK 0.9.3 in which layer
230# reg entries were not removed on uninstall. So we'll try to clean up
231# and remove them now.
232# This works only if 0.9.3 was installed to the default location.
233# If it was not installed to the default location, those entries will
234# need to be cleaned up manually.
235
236$VulkanSdkDirs+="C:\VulkanSDK\0.9.3"
237
David Pinedoc21fdb92016-01-04 16:31:57 -0700238# Remove layer registry entries associated with all installed Vulkan SDKs.
239# Note that we remove only those entries created by Vulkan SDKs. If other
240# layers were installed that are not from an SDK, we don't mess with them.
241
242Get-Item -Path Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Khronos\Vulkan\ExplicitLayers | Select-Object -ExpandProperty Property |
243 ForEach-Object {
244 $regval=$_
245 ForEach ($sdkdir in $VulkanSdkDirs) {
246 if ($regval -like "$sdkdir\*.json") {
David Pinedo9bb478f2016-01-19 21:19:11 -0700247 Remove-ItemProperty -ErrorAction SilentlyContinue -Path HKLM:\SOFTWARE\Khronos\Vulkan\ExplicitLayers -name $regval
David Pinedoc21fdb92016-01-04 16:31:57 -0700248 }
249 }
250 }
Mark Youngb628d162016-01-19 15:29:34 -0700251# Remove 32-bit layer registry entries if we're targeting a 64-bit OS
252if ($ossize -eq 64) {
253 Get-Item -Path Registry::HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Khronos\Vulkan\ExplicitLayers | Select-Object -ExpandProperty Property |
254 ForEach-Object {
255 $regval=$_
256 ForEach ($sdkdir in $VulkanSdkDirs) {
257 if ($regval -like "$sdkdir\*.json") {
Mark Youngd6897a32016-01-20 14:48:21 -0700258 Remove-ItemProperty -ErrorAction SilentlyContinue -Path HKLM:\SOFTWARE\WOW6432Node\Khronos\Vulkan\ExplicitLayers -name $regval
Mark Youngb628d162016-01-19 15:29:34 -0700259 }
260 }
261 }
262}
David Pinedoc21fdb92016-01-04 16:31:57 -0700263
264
265# Create layer registry entries associated with Vulkan SDK from which $mrVulkanDll is from
266
267if ($mrVulkanDllInstallDir -ne "") {
David Pinedo9bb478f2016-01-19 21:19:11 -0700268 New-Item -Force -ErrorAction SilentlyContinue -Path HKLM:\SOFTWARE\Khronos\Vulkan\ExplicitLayers | out-null
David Pinedo431b82a2016-02-05 09:48:26 -0700269 Get-ChildItem $mrVulkanDllInstallDir\Bin -Filter VkLayer*json |
David Pinedoc21fdb92016-01-04 16:31:57 -0700270 ForEach-Object {
271 New-ItemProperty -Path HKLM:\SOFTWARE\Khronos\Vulkan\ExplicitLayers -Name $mrVulkanDllInstallDir\Bin\$_ -PropertyType DWord -Value 0 | out-null
272 }
Mark Youngb628d162016-01-19 15:29:34 -0700273
274 # Create registry entires for the WOW6432Node registry only if we're targeting a 64-bit OS
275 if ($ossize -eq 64) {
276 New-Item -Force -ErrorAction Ignore -Path HKLM:\SOFTWARE\WOW6432Node\Khronos\Vulkan\ExplicitLayers | out-null
David Pinedo431b82a2016-02-05 09:48:26 -0700277 Get-ChildItem $mrVulkanDllInstallDir\Bin32 -Filter VkLayer*json |
Mark Youngb628d162016-01-19 15:29:34 -0700278 ForEach-Object {
Mark Youngd6897a32016-01-20 14:48:21 -0700279 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 -0700280 }
281 }
David Pinedoc21fdb92016-01-04 16:31:57 -0700282}