install_d3d12_sdk_windows.py 6.1 KB

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