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