install_d3d12_sdk_windows.py 5.4 KB

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