David Pinedo | c21fdb9 | 2016-01-04 16:31:57 -0700 | [diff] [blame] | 1 | #
|
| 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 |
|
| 36 | Param([string]$majorabi)
|
| 37 |
|
| 38 | $vulkandll = "vulkan-"+$majorabi+".dll"
|
| 39 |
|
| 40 | # The name of the versioned vulkan dll file is one of the following:
|
| 41 | #
|
| 42 | # vulkan-<majorabi>-<major>-<minor>-<patch>-<prerelease>-<buildno>.dll
|
| 43 | # vulkan-<majorabi>-<major>-<minor>-<patch>-<prerelease>.dll
|
| 44 | # vulkan-<majorabi>-<major>-<minor>-<patch>-<buildno>.dll
|
| 45 | # vulkan-<majorabi>-<major>-<minor>-<patch>.dll
|
| 46 | #
|
| 47 | # <majorabi>, <major>, <minor>, <patch>, and <buildno> are 1 to 10 digits.
|
| 48 | # <prerelease> is [A-Za-z0-9]*
|
| 49 | # If <buildno> is present, it identifies a prerelease, and will be
|
| 50 | # considered less recent than one with the same <major>, <minor>, and
|
| 51 | # <patch> numbers without the <buildno>.
|
| 52 |
|
| 53 |
|
| 54 | # We first create an array, with one array element for each vulkan-*dll in
|
| 55 | # C:\Windows\System32, with each element containing:
|
| 56 | # <major>=<minor>=<patch>=<prerelease>=<buildno>=
|
| 57 | # filename
|
| 58 | # @<major>@<minor>@<patch>@<prerelease>@<buildno>@
|
| 59 | # [Note that the above three lines are one element in the array.]
|
| 60 | # The build identifiers separated by "=" are suitable for sorting, i.e.
|
| 61 | # expanded to 10 digits with leading 0s. If <prerelease> or <buildno> are
|
| 62 | # not specified, 10 z characters are substituted for them, so that they sort
|
| 63 | # to a position after those that do specify them.
|
| 64 | # The build identifiers separated by "@" are the original values extracted
|
| 65 | # from the file name. They are used later to find the path to the SDK
|
| 66 | # install directory for the given filename.
|
| 67 |
|
| 68 | $VulkanDllList=@()
|
| 69 | cd c:\WINDOWS\SYSTEM32
|
| 70 | dir -name vulkan-$majorabi-*.dll |
|
| 71 | ForEach-Object {
|
| 72 | $major=$_.Split('-')[2]
|
| 73 | $majorOrig=$major
|
| 74 | $minor=$_.Split('-')[3]
|
| 75 | $minorOrig=$minor
|
| 76 | $patch=$_.Split('-')[4]
|
| 77 |
|
| 78 | if ($patch -match ".dll") {
|
| 79 | # <prerelease> and <buildno> are not in the name
|
| 80 | $patch=$patch -replace ".dll",""
|
| 81 | $patchOrig=$patch
|
| 82 | $prerelease="z"*10
|
| 83 | $prereleaseOrig=""
|
| 84 | $buildno="z"*10
|
| 85 | $buildnoOrig=""
|
| 86 | } else {
|
| 87 |
|
| 88 | # We assume we don't have more than 5 dashes
|
| 89 |
|
| 90 | $f=$_ -replace ".dll",""
|
| 91 | $patch=$f.Split('-')[4]
|
| 92 | $prerelease=$f.Split('-')[5]
|
| 93 | $buildno=$f.Split('-')[6]
|
| 94 | if ($buildno.Length -eq 0) {
|
| 95 | if ($prerelease -match "^[0-9]") {
|
| 96 | # prerelease starts with a digit, it must be the buildno
|
| 97 | $buildno=$prerelease
|
| 98 | $prerelease=""
|
| 99 | }
|
| 100 | }
|
| 101 | $patchOrig=$patch
|
| 102 | $prereleaseOrig=$prerelease
|
| 103 | $buildnoOrig=$buildno
|
| 104 |
|
| 105 | if ($prerelease.Length -eq 0) {
|
| 106 | $prerelease="z"*10
|
| 107 | }
|
| 108 | if ($buildno.Length -eq 0) {
|
| 109 | $buildno="z"*10
|
| 110 | }
|
| 111 | }
|
| 112 |
|
| 113 | $major = $major.padleft(10,'0')
|
| 114 | $minor = $minor.padleft(10,'0')
|
| 115 | $patch = $patch.padleft(10,'0')
|
| 116 | $prerelease = $prerelease.padleft(10,'0')
|
| 117 | $buildno = $buildno.padleft(10,'0')
|
| 118 |
|
| 119 | # Add a new element to the $VulkanDllList array
|
| 120 | $VulkanDllList+="$major=$minor=$patch=$prerelease=$buildno= $_ @$majorOrig@$minorOrig@$patchOrig@$prereleaseOrig@$buildnoOrig@"
|
| 121 | }
|
| 122 |
|
| 123 |
|
| 124 | # If $VulkanDllList contains at least one element, there's at least one vulkan*.dll file.
|
| 125 | # Copy the most recent vulkan*.dll (named in the last element of $VulkanDllList) to vulkan-0.dll.
|
| 126 | # Also copy the corresponding vulkaninfo-*.exe to vulkaninfo.exe.
|
| 127 |
|
| 128 | if ($VulkanDllList.Length -gt 0) {
|
| 129 |
|
| 130 | # Sort the list. The most recent vulkan-*.dll will be in the last element of the list.
|
| 131 | [array]::sort($VulkanDllList)
|
| 132 |
|
| 133 | # Put the name of the most recent vulkan-*.dll in $mrVulkanDLL.
|
| 134 | # The most recent vulkanDLL is the second word in the last element of the
|
| 135 | # sorted $VulkanDllList. Copy it to $vulkandll.
|
| 136 | $mrVulkanDll=$VulkanDLLList[-1].Split(' ')[1]
|
| 137 | copy $mrVulkanDll $vulkandll
|
| 138 |
|
| 139 | # Copy the most recent version of vulkaninfo-<abimajor>-*.exe to vulkaninfo.exe.
|
| 140 | # We create the source file name for the copy from $mrVulkanDll.
|
| 141 | $mrVulkaninfo=$mrVulkanDll -replace ".dll",".exe"
|
| 142 | $mrVulkaninfo=$mrVulkaninfo -replace "vulkan","vulkaninfo"
|
| 143 | copy $mrVulkaninfo vulkaninfo.exe
|
| 144 |
|
| 145 | # Create the name used in the registry for the SDK associated with $mrVulkanDll.
|
| 146 | $major=$VulkanDLLList[-1].Split('@')[1]
|
| 147 | $minor=$VulkanDLLList[-1].Split('@')[2]
|
| 148 | $patch=$VulkanDLLList[-1].Split('@')[3]
|
| 149 | $prerelease=$VulkanDLLList[-1].Split('@')[4]
|
| 150 | $buildno=$VulkanDLLList[-1].Split('@')[5]
|
| 151 | $sdkname="VulkanSDK"+$major + "." + $minor + "." + $patch
|
| 152 | if ($prerelease -ne "") {
|
| 153 | $sdkname=$sdkname + "." + $prerelease
|
| 154 | }
|
| 155 | if ($buildno -ne "") {
|
| 156 | $sdkname=$sdkname + "." + $buildno
|
| 157 | }
|
| 158 | }
|
| 159 |
|
| 160 |
|
| 161 | # Create an array of vulkan sdk install dirs
|
| 162 |
|
| 163 | $mrVulkanDllInstallDir=""
|
| 164 | $VulkanSdkDirs=@()
|
| 165 | Get-ChildItem -Path Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall |
|
| 166 | ForEach-Object {
|
| 167 | $regkey=$_ -replace ".*\\",""
|
| 168 | if ($_ -match "\\VulkanSDK") {
|
| 169 | # Get the install path from UninstallString
|
| 170 | $tmp=Get-ItemProperty -Path Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$regkey -Name UninstallString
|
| 171 | $tmp=$tmp -replace "\\Uninstall.exe.*",""
|
| 172 | $tmp=$tmp -replace ".*=.",""
|
| 173 | $VulkanSdkDirs+=$tmp
|
| 174 | if ($regkey -eq $sdkname) {
|
| 175 | # Save away the sdk install dir for the the most recent vulkandll
|
| 176 | $mrVulkanDllInstallDir=$tmp
|
| 177 | }
|
| 178 | }
|
| 179 | }
|
| 180 |
|
| 181 | # Add C:\Vulkan\SDK\0.9.3 to list of SDK install dirs.
|
| 182 | # We do this because there is in a bug in SDK 0.9.3 in which layer
|
| 183 | # reg entries were not removed on uninstall. So we'll try to clean up
|
| 184 | # and remove them now.
|
| 185 | # This works only if 0.9.3 was installed to the default location.
|
| 186 | # If it was not installed to the default location, those entries will
|
| 187 | # need to be cleaned up manually.
|
| 188 |
|
| 189 | $VulkanSdkDirs+="C:\VulkanSDK\0.9.3"
|
| 190 |
|
| 191 |
|
| 192 | # Remove layer registry entries associated with all installed Vulkan SDKs.
|
| 193 | # Note that we remove only those entries created by Vulkan SDKs. If other
|
| 194 | # layers were installed that are not from an SDK, we don't mess with them.
|
| 195 |
|
| 196 | Get-Item -Path Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Khronos\Vulkan\ExplicitLayers | Select-Object -ExpandProperty Property |
|
| 197 | ForEach-Object {
|
| 198 | $regval=$_
|
| 199 | ForEach ($sdkdir in $VulkanSdkDirs) {
|
| 200 | if ($regval -like "$sdkdir\*.json") {
|
| 201 | Remove-ItemProperty -ErrorAction Ignore -Path HKLM:\SOFTWARE\Khronos\Vulkan\ExplicitLayers -name $regval
|
| 202 | }
|
| 203 | }
|
| 204 | }
|
| 205 |
|
| 206 |
|
| 207 | # Create layer registry entries associated with Vulkan SDK from which $mrVulkanDll is from
|
| 208 |
|
| 209 | if ($mrVulkanDllInstallDir -ne "") {
|
| 210 | New-Item -ErrorAction Ignore -Path HKLM:\SOFTWARE\Khronos\Vulkan\ExplicitLayers | out-null
|
| 211 | Get-ChildItem $mrVulkanDllInstallDir\Bin -Filter *json |
|
| 212 | ForEach-Object {
|
| 213 | New-ItemProperty -Path HKLM:\SOFTWARE\Khronos\Vulkan\ExplicitLayers -Name $mrVulkanDllInstallDir\Bin\$_ -PropertyType DWord -Value 0 | out-null
|
| 214 | }
|
| 215 | }
|