Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/misc/scripts/install_d3d12_sdk_windows.py
9896 views
1
#!/usr/bin/env python
2
3
if __name__ != "__main__":
4
raise SystemExit(f'Utility script "{__file__}" should not be used as a module!')
5
6
import argparse
7
import os
8
import shutil
9
import subprocess
10
import sys
11
import urllib.request
12
13
sys.path.insert(0, os.path.join(os.path.dirname(os.path.abspath(__file__)), "../../"))
14
15
from misc.utility.color import Ansi, color_print
16
17
parser = argparse.ArgumentParser(description="Install D3D12 dependencies for Windows platforms.")
18
parser.add_argument(
19
"--mingw_prefix",
20
default=os.getenv("MINGW_PREFIX", ""),
21
help="Explicitly specify a path containing the MinGW bin folder.",
22
)
23
args = parser.parse_args()
24
25
# Base Godot dependencies path
26
# If cross-compiling (no LOCALAPPDATA), we install in `bin`
27
deps_folder = os.getenv("LOCALAPPDATA")
28
if deps_folder:
29
deps_folder = os.path.join(deps_folder, "Godot", "build_deps")
30
else:
31
deps_folder = os.path.join("bin", "build_deps")
32
33
# Mesa NIR
34
# Check for latest version: https://github.com/godotengine/godot-nir-static/releases/latest
35
mesa_version = "23.1.9-1"
36
# WinPixEventRuntime
37
# Check for latest version: https://www.nuget.org/api/v2/package/WinPixEventRuntime (check downloaded filename)
38
pix_version = "1.0.240308001"
39
pix_archive = os.path.join(deps_folder, f"WinPixEventRuntime_{pix_version}.nupkg")
40
pix_folder = os.path.join(deps_folder, "pix")
41
# DirectX 12 Agility SDK
42
# Check for latest version: https://www.nuget.org/api/v2/package/Microsoft.Direct3D.D3D12 (check downloaded filename)
43
# After updating this, remember to change the default value of the `rendering/rendering_device/d3d12/agility_sdk_version`
44
# project setting to match the minor version (e.g. for `1.613.3`, it should be `613`).
45
agility_sdk_version = "1.613.3"
46
agility_sdk_archive = os.path.join(deps_folder, f"Agility_SDK_{agility_sdk_version}.nupkg")
47
agility_sdk_folder = os.path.join(deps_folder, "agility_sdk")
48
49
# Create dependencies folder
50
if not os.path.exists(deps_folder):
51
os.makedirs(deps_folder)
52
53
# Mesa NIR
54
color_print(f"{Ansi.BOLD}[1/3] Mesa NIR")
55
for arch in [
56
"arm64-llvm",
57
"arm64-msvc",
58
"x86_32-gcc",
59
"x86_32-llvm",
60
"x86_32-msvc",
61
"x86_64-gcc",
62
"x86_64-llvm",
63
"x86_64-msvc",
64
]:
65
mesa_filename = "godot-nir-static-" + arch + "-release.zip"
66
mesa_archive = os.path.join(deps_folder, mesa_filename)
67
mesa_folder = os.path.join(deps_folder, "mesa-" + arch)
68
69
if os.path.isfile(mesa_archive):
70
os.remove(mesa_archive)
71
print(f"Downloading Mesa NIR {mesa_filename} ...")
72
urllib.request.urlretrieve(
73
f"https://github.com/godotengine/godot-nir-static/releases/download/{mesa_version}/{mesa_filename}",
74
mesa_archive,
75
)
76
if os.path.exists(mesa_folder):
77
print(f"Removing existing local Mesa NIR installation in {mesa_folder} ...")
78
shutil.rmtree(mesa_folder)
79
print(f"Extracting Mesa NIR {mesa_filename} to {mesa_folder} ...")
80
shutil.unpack_archive(mesa_archive, mesa_folder)
81
os.remove(mesa_archive)
82
print("Mesa NIR installed successfully.\n")
83
84
# WinPixEventRuntime
85
86
# MinGW needs DLLs converted with dlltool.
87
# We rely on finding gendef/dlltool to detect if we have MinGW.
88
# Check existence of needed tools for generating mingw library.
89
pathstr = os.environ.get("PATH", "")
90
if args.mingw_prefix:
91
pathstr = os.path.join(args.mingw_prefix, "bin") + os.pathsep + pathstr
92
gendef = shutil.which("x86_64-w64-mingw32-gendef", path=pathstr) or shutil.which("gendef", path=pathstr) or ""
93
dlltool = shutil.which("x86_64-w64-mingw32-dlltool", path=pathstr) or shutil.which("dlltool", path=pathstr) or ""
94
has_mingw = gendef != "" and dlltool != ""
95
96
color_print(f"{Ansi.BOLD}[2/3] WinPixEventRuntime")
97
if os.path.isfile(pix_archive):
98
os.remove(pix_archive)
99
print(f"Downloading WinPixEventRuntime {pix_version} ...")
100
urllib.request.urlretrieve(f"https://www.nuget.org/api/v2/package/WinPixEventRuntime/{pix_version}", pix_archive)
101
if os.path.exists(pix_folder):
102
print(f"Removing existing local WinPixEventRuntime installation in {pix_folder} ...")
103
shutil.rmtree(pix_folder)
104
print(f"Extracting WinPixEventRuntime {pix_version} to {pix_folder} ...")
105
shutil.unpack_archive(pix_archive, pix_folder, "zip")
106
os.remove(pix_archive)
107
if has_mingw:
108
print("Adapting WinPixEventRuntime to also support MinGW alongside MSVC.")
109
cwd = os.getcwd()
110
os.chdir(pix_folder)
111
subprocess.run([gendef, "./bin/x64/WinPixEventRuntime.dll"])
112
subprocess.run(
113
[dlltool]
114
+ "--machine i386:x86-64 --no-leading-underscore -d WinPixEventRuntime.def -D WinPixEventRuntime.dll -l ./bin/x64/libWinPixEventRuntime.a".split()
115
)
116
subprocess.run([gendef, "./bin/ARM64/WinPixEventRuntime.dll"])
117
subprocess.run(
118
[dlltool]
119
+ "--machine arm64 --no-leading-underscore -d WinPixEventRuntime.def -D WinPixEventRuntime.dll -l ./bin/ARM64/libWinPixEventRuntime.a".split()
120
)
121
os.chdir(cwd)
122
else:
123
print(
124
'MinGW support requires "dlltool" and "gendef" dependencies, so only MSVC support is provided for WinPixEventRuntime. Did you forget to provide a `--mingw_prefix`?'
125
)
126
print(f"WinPixEventRuntime {pix_version} installed successfully.\n")
127
128
# DirectX 12 Agility SDK
129
color_print(f"{Ansi.BOLD}[3/3] DirectX 12 Agility SDK")
130
if os.path.isfile(agility_sdk_archive):
131
os.remove(agility_sdk_archive)
132
print(f"Downloading DirectX 12 Agility SDK {agility_sdk_version} ...")
133
urllib.request.urlretrieve(
134
f"https://www.nuget.org/api/v2/package/Microsoft.Direct3D.D3D12/{agility_sdk_version}", agility_sdk_archive
135
)
136
if os.path.exists(agility_sdk_folder):
137
print(f"Removing existing local DirectX 12 Agility SDK installation in {agility_sdk_folder} ...")
138
shutil.rmtree(agility_sdk_folder)
139
print(f"Extracting DirectX 12 Agility SDK {agility_sdk_version} to {agility_sdk_folder} ...")
140
shutil.unpack_archive(agility_sdk_archive, agility_sdk_folder, "zip")
141
os.remove(agility_sdk_archive)
142
print(f"DirectX 12 Agility SDK {agility_sdk_version} installed successfully.\n")
143
144
# Complete message
145
color_print(f'{Ansi.GREEN}All Direct3D 12 SDK components were installed to "{deps_folder}" successfully!')
146
color_print(f'{Ansi.GREEN}You can now build Godot with Direct3D 12 support enabled by running "scons d3d12=yes".')
147
148