Debian Codegraph @

misc/scripts/install_d3d12_sdk_windows.py

raw symbols SCIP
1 #!/usr/bin/env python3
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 # Sync with `drivers/d3d12/SCsub` when updating Mesa.
35 # Check for latest version: https://github.com/godotengine/godot-nir-static/releases/latest
36 mesa_version = "25.3.1-1"
37 # WinPixEventRuntime
38 # Check for latest version: https://www.nuget.org/api/v2/package/WinPixEventRuntime (check downloaded filename)
39 pix_version = "1.0.240308001"
40 pix_archive = os.path.join(deps_folder, f"WinPixEventRuntime_{pix_version}.nupkg")
41 pix_folder = os.path.join(deps_folder, "pix")
42 # DirectX 12 Agility SDK
43 # Check for latest version: https://www.nuget.org/api/v2/package/Microsoft.Direct3D.D3D12 (check downloaded filename)
44 # After updating this, remember to change the default value of the `rendering/rendering_device/d3d12/agility_sdk_version`
45 # project setting to match the minor version (e.g. for `1.618.5`, it should be `618`).
46 agility_sdk_version = "1.618.5"
47 agility_sdk_archive = os.path.join(deps_folder, f"Agility_SDK_{agility_sdk_version}.nupkg")
48 agility_sdk_folder = os.path.join(deps_folder, "agility_sdk")
49
50 # Create dependencies folder
51 if not os.path.exists(deps_folder):
52 os.makedirs(deps_folder)
53
54 # Mesa NIR
55 color_print(f"{Ansi.BOLD}[1/3] Mesa NIR")
56 for arch in [
57 "arm64-llvm",
58 "arm64-msvc",
59 "x86_32-gcc",
60 "x86_32-llvm",
61 "x86_32-msvc",
62 "x86_64-gcc",
63 "x86_64-llvm",
64 "x86_64-msvc",
65 ]:
66 mesa_filename = "godot-nir-static-" + arch + "-release.zip"
67 mesa_archive = os.path.join(deps_folder, mesa_filename)
68 mesa_folder = os.path.join(deps_folder, "mesa-" + arch)
69
70 if os.path.isfile(mesa_archive):
71 os.remove(mesa_archive)
72 print(f"Downloading Mesa NIR {mesa_filename} ...")
73 urllib.request.urlretrieve(
74 f"https://github.com/godotengine/godot-nir-static/releases/download/{mesa_version}/{mesa_filename}",
75 mesa_archive,
76 )
77 if os.path.exists(mesa_folder):
78 print(f"Removing existing local Mesa NIR installation in {mesa_folder} ...")
79 shutil.rmtree(mesa_folder)
80 print(f"Extracting Mesa NIR {mesa_filename} to {mesa_folder} ...")
81 shutil.unpack_archive(mesa_archive, mesa_folder)
82 os.remove(mesa_archive)
83 print("Mesa NIR installed successfully.\n")
84
85 # WinPixEventRuntime
86
87 # MinGW needs DLLs converted with dlltool.
88 # We rely on finding gendef/dlltool to detect if we have MinGW.
89 # Check existence of needed tools for generating mingw library.
90 pathstr = os.environ.get("PATH", "")
91 if args.mingw_prefix:
92 pathstr = os.path.join(args.mingw_prefix, "bin") + os.pathsep + pathstr
93 gendef = shutil.which("x86_64-w64-mingw32-gendef", path=pathstr) or shutil.which("gendef", path=pathstr) or ""
94 dlltool = shutil.which("x86_64-w64-mingw32-dlltool", path=pathstr) or shutil.which("dlltool", path=pathstr) or ""
95 has_mingw = gendef != "" and dlltool != ""
96
97 color_print(f"{Ansi.BOLD}[2/3] WinPixEventRuntime")
98 if os.path.isfile(pix_archive):
99 os.remove(pix_archive)
100 print(f"Downloading WinPixEventRuntime {pix_version} ...")
101 urllib.request.urlretrieve(f"https://www.nuget.org/api/v2/package/WinPixEventRuntime/{pix_version}", pix_archive)
102 if os.path.exists(pix_folder):
103 print(f"Removing existing local WinPixEventRuntime installation in {pix_folder} ...")
104 shutil.rmtree(pix_folder)
105 print(f"Extracting WinPixEventRuntime {pix_version} to {pix_folder} ...")
106 shutil.unpack_archive(pix_archive, pix_folder, "zip")
107 os.remove(pix_archive)
108 if has_mingw:
109 print("Adapting WinPixEventRuntime to also support MinGW alongside MSVC.")
110 cwd = os.getcwd()
111 os.chdir(pix_folder)
112 subprocess.run([gendef, "./bin/x64/WinPixEventRuntime.dll"])
113 subprocess.run(
114 [dlltool]
115 + "--machine i386:x86-64 --no-leading-underscore -d WinPixEventRuntime.def -D WinPixEventRuntime.dll -l ./bin/x64/libWinPixEventRuntime.a".split()
116 )
117 subprocess.run([gendef, "./bin/ARM64/WinPixEventRuntime.dll"])
118 subprocess.run(
119 [dlltool]
120 + "--machine arm64 --no-leading-underscore -d WinPixEventRuntime.def -D WinPixEventRuntime.dll -l ./bin/ARM64/libWinPixEventRuntime.a".split()
121 )
122 os.chdir(cwd)
123 else:
124 print(
125 'MinGW support requires "dlltool" and "gendef" dependencies, so only MSVC support is provided for WinPixEventRuntime. Did you forget to provide a `--mingw_prefix`?'
126 )
127 print(f"WinPixEventRuntime {pix_version} installed successfully.\n")
128
129 # DirectX 12 Agility SDK
130 color_print(f"{Ansi.BOLD}[3/3] DirectX 12 Agility SDK")
131 if os.path.isfile(agility_sdk_archive):
132 os.remove(agility_sdk_archive)
133 print(f"Downloading DirectX 12 Agility SDK {agility_sdk_version} ...")
134 urllib.request.urlretrieve(
135 f"https://www.nuget.org/api/v2/package/Microsoft.Direct3D.D3D12/{agility_sdk_version}", agility_sdk_archive
136 )
137 if os.path.exists(agility_sdk_folder):
138 print(f"Removing existing local DirectX 12 Agility SDK installation in {agility_sdk_folder} ...")
139 shutil.rmtree(agility_sdk_folder)
140 print(f"Extracting DirectX 12 Agility SDK {agility_sdk_version} to {agility_sdk_folder} ...")
141 shutil.unpack_archive(agility_sdk_archive, agility_sdk_folder, "zip")
142 os.remove(agility_sdk_archive)
143 print(f"DirectX 12 Agility SDK {agility_sdk_version} installed successfully.\n")
144
145 # Complete message
146 color_print(f'{Ansi.GREEN}All Direct3D 12 SDK components were installed to "{deps_folder}" successfully!')
147 color_print(f'{Ansi.GREEN}You can now build Godot with Direct3D 12 support enabled by running "scons d3d12=yes".')