Path: blob/master/misc/scripts/install_d3d12_sdk_windows.py
20801 views
#!/usr/bin/env python312if __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# Sync with `drivers/d3d12/SCsub` when updating Mesa.34# Check for latest version: https://github.com/godotengine/godot-nir-static/releases/latest35mesa_version = "25.3.1-1"36# WinPixEventRuntime37# Check for latest version: https://www.nuget.org/api/v2/package/WinPixEventRuntime (check downloaded filename)38pix_version = "1.0.240308001"39pix_archive = os.path.join(deps_folder, f"WinPixEventRuntime_{pix_version}.nupkg")40pix_folder = os.path.join(deps_folder, "pix")41# DirectX 12 Agility SDK42# 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.618.5`, it should be `618`).45agility_sdk_version = "1.618.5"46agility_sdk_archive = os.path.join(deps_folder, f"Agility_SDK_{agility_sdk_version}.nupkg")47agility_sdk_folder = os.path.join(deps_folder, "agility_sdk")4849# Create dependencies folder50if not os.path.exists(deps_folder):51os.makedirs(deps_folder)5253# Mesa NIR54color_print(f"{Ansi.BOLD}[1/3] Mesa NIR")55for 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]:65mesa_filename = "godot-nir-static-" + arch + "-release.zip"66mesa_archive = os.path.join(deps_folder, mesa_filename)67mesa_folder = os.path.join(deps_folder, "mesa-" + arch)6869if os.path.isfile(mesa_archive):70os.remove(mesa_archive)71print(f"Downloading Mesa NIR {mesa_filename} ...")72urllib.request.urlretrieve(73f"https://github.com/godotengine/godot-nir-static/releases/download/{mesa_version}/{mesa_filename}",74mesa_archive,75)76if os.path.exists(mesa_folder):77print(f"Removing existing local Mesa NIR installation in {mesa_folder} ...")78shutil.rmtree(mesa_folder)79print(f"Extracting Mesa NIR {mesa_filename} to {mesa_folder} ...")80shutil.unpack_archive(mesa_archive, mesa_folder)81os.remove(mesa_archive)82print("Mesa NIR installed successfully.\n")8384# WinPixEventRuntime8586# 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.89pathstr = os.environ.get("PATH", "")90if args.mingw_prefix:91pathstr = os.path.join(args.mingw_prefix, "bin") + os.pathsep + pathstr92gendef = shutil.which("x86_64-w64-mingw32-gendef", path=pathstr) or shutil.which("gendef", path=pathstr) or ""93dlltool = shutil.which("x86_64-w64-mingw32-dlltool", path=pathstr) or shutil.which("dlltool", path=pathstr) or ""94has_mingw = gendef != "" and dlltool != ""9596color_print(f"{Ansi.BOLD}[2/3] WinPixEventRuntime")97if os.path.isfile(pix_archive):98os.remove(pix_archive)99print(f"Downloading WinPixEventRuntime {pix_version} ...")100urllib.request.urlretrieve(f"https://www.nuget.org/api/v2/package/WinPixEventRuntime/{pix_version}", pix_archive)101if os.path.exists(pix_folder):102print(f"Removing existing local WinPixEventRuntime installation in {pix_folder} ...")103shutil.rmtree(pix_folder)104print(f"Extracting WinPixEventRuntime {pix_version} to {pix_folder} ...")105shutil.unpack_archive(pix_archive, pix_folder, "zip")106os.remove(pix_archive)107if has_mingw:108print("Adapting WinPixEventRuntime to also support MinGW alongside MSVC.")109cwd = os.getcwd()110os.chdir(pix_folder)111subprocess.run([gendef, "./bin/x64/WinPixEventRuntime.dll"])112subprocess.run(113[dlltool]114+ "--machine i386:x86-64 --no-leading-underscore -d WinPixEventRuntime.def -D WinPixEventRuntime.dll -l ./bin/x64/libWinPixEventRuntime.a".split()115)116subprocess.run([gendef, "./bin/ARM64/WinPixEventRuntime.dll"])117subprocess.run(118[dlltool]119+ "--machine arm64 --no-leading-underscore -d WinPixEventRuntime.def -D WinPixEventRuntime.dll -l ./bin/ARM64/libWinPixEventRuntime.a".split()120)121os.chdir(cwd)122else:123print(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)126print(f"WinPixEventRuntime {pix_version} installed successfully.\n")127128# DirectX 12 Agility SDK129color_print(f"{Ansi.BOLD}[3/3] DirectX 12 Agility SDK")130if os.path.isfile(agility_sdk_archive):131os.remove(agility_sdk_archive)132print(f"Downloading DirectX 12 Agility SDK {agility_sdk_version} ...")133urllib.request.urlretrieve(134f"https://www.nuget.org/api/v2/package/Microsoft.Direct3D.D3D12/{agility_sdk_version}", agility_sdk_archive135)136if os.path.exists(agility_sdk_folder):137print(f"Removing existing local DirectX 12 Agility SDK installation in {agility_sdk_folder} ...")138shutil.rmtree(agility_sdk_folder)139print(f"Extracting DirectX 12 Agility SDK {agility_sdk_version} to {agility_sdk_folder} ...")140shutil.unpack_archive(agility_sdk_archive, agility_sdk_folder, "zip")141os.remove(agility_sdk_archive)142print(f"DirectX 12 Agility SDK {agility_sdk_version} installed successfully.\n")143144# Complete message145color_print(f'{Ansi.GREEN}All Direct3D 12 SDK components were installed to "{deps_folder}" successfully!')146color_print(f'{Ansi.GREEN}You can now build Godot with Direct3D 12 support enabled by running "scons d3d12=yes".')147148149