install_d3d12_sdk_windows.py 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. #!/usr/bin/env python
  2. import os
  3. import shutil
  4. import subprocess
  5. import sys
  6. import urllib.request
  7. # Enable ANSI escape code support on Windows 10 and later (for colored console output).
  8. # <https://github.com/python/cpython/issues/73245>
  9. if sys.platform == "win32":
  10. from ctypes import byref, c_int, windll
  11. stdout_handle = windll.kernel32.GetStdHandle(c_int(-11))
  12. mode = c_int(0)
  13. windll.kernel32.GetConsoleMode(c_int(stdout_handle), byref(mode))
  14. mode = c_int(mode.value | 4)
  15. windll.kernel32.SetConsoleMode(c_int(stdout_handle), mode)
  16. # Base Godot dependencies path
  17. # If cross-compiling (no LOCALAPPDATA), we install in `bin`
  18. deps_folder = os.getenv("LOCALAPPDATA")
  19. if deps_folder:
  20. deps_folder = os.path.join(deps_folder, "Godot", "build_deps")
  21. else:
  22. deps_folder = os.path.join("bin", "build_deps")
  23. # DirectX Shader Compiler
  24. # Check for latest version: https://github.com/microsoft/DirectXShaderCompiler/releases/latest
  25. dxc_version = "v1.8.2403.2"
  26. dxc_filename = "dxc_2024_03_29.zip"
  27. dxc_archive = os.path.join(deps_folder, dxc_filename)
  28. dxc_folder = os.path.join(deps_folder, "dxc")
  29. # Mesa NIR
  30. # Check for latest version: https://github.com/godotengine/godot-nir-static/releases/latest
  31. mesa_version = "23.1.9"
  32. mesa_filename = "godot-nir-23.1.9.zip"
  33. mesa_archive = os.path.join(deps_folder, mesa_filename)
  34. mesa_folder = os.path.join(deps_folder, "mesa")
  35. # WinPixEventRuntime
  36. # Check for latest version: https://www.nuget.org/api/v2/package/WinPixEventRuntime (check downloaded filename)
  37. pix_version = "1.0.240308001"
  38. pix_archive = os.path.join(deps_folder, f"WinPixEventRuntime_{pix_version}.nupkg")
  39. pix_folder = os.path.join(deps_folder, "pix")
  40. # DirectX 12 Agility SDK
  41. # 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`).
  44. agility_sdk_version = "1.613.3"
  45. agility_sdk_archive = os.path.join(deps_folder, f"Agility_SDK_{agility_sdk_version}.nupkg")
  46. agility_sdk_folder = os.path.join(deps_folder, "agility_sdk")
  47. # Create dependencies folder
  48. if not os.path.exists(deps_folder):
  49. os.makedirs(deps_folder)
  50. # DirectX Shader Compiler
  51. print("\x1b[1m[1/4] DirectX Shader Compiler\x1b[0m")
  52. if os.path.isfile(dxc_archive):
  53. os.remove(dxc_archive)
  54. print(f"Downloading DirectX Shader Compiler {dxc_filename} ...")
  55. urllib.request.urlretrieve(
  56. f"https://github.com/microsoft/DirectXShaderCompiler/releases/download/{dxc_version}/{dxc_filename}",
  57. dxc_archive,
  58. )
  59. if os.path.exists(dxc_folder):
  60. print(f"Removing existing local DirectX Shader Compiler installation in {dxc_folder} ...")
  61. shutil.rmtree(dxc_folder)
  62. print(f"Extracting DirectX Shader Compiler {dxc_filename} to {dxc_folder} ...")
  63. shutil.unpack_archive(dxc_archive, dxc_folder)
  64. os.remove(dxc_archive)
  65. print(f"DirectX Shader Compiler {dxc_filename} installed successfully.\n")
  66. # Mesa NIR
  67. print("\x1b[1m[2/4] Mesa NIR\x1b[0m")
  68. if os.path.isfile(mesa_archive):
  69. os.remove(mesa_archive)
  70. print(f"Downloading Mesa NIR {mesa_filename} ...")
  71. urllib.request.urlretrieve(
  72. f"https://github.com/godotengine/godot-nir-static/releases/download/{mesa_version}/{mesa_filename}",
  73. mesa_archive,
  74. )
  75. if os.path.exists(mesa_folder):
  76. print(f"Removing existing local Mesa NIR installation in {mesa_folder} ...")
  77. shutil.rmtree(mesa_folder)
  78. print(f"Extracting Mesa NIR {mesa_filename} to {mesa_folder} ...")
  79. shutil.unpack_archive(mesa_archive, mesa_folder)
  80. os.remove(mesa_archive)
  81. print(f"Mesa NIR {mesa_filename} installed successfully.\n")
  82. # WinPixEventRuntime
  83. # MinGW needs DLLs converted with dlltool.
  84. # We rely on finding gendef/dlltool to detect if we have MinGW.
  85. # Check existence of needed tools for generating mingw library.
  86. gendef = shutil.which("gendef") or ""
  87. dlltool = shutil.which("dlltool") or ""
  88. if dlltool == "":
  89. dlltool = shutil.which("x86_64-w64-mingw32-dlltool") or ""
  90. has_mingw = gendef != "" and dlltool != ""
  91. print("\x1b[1m[3/4] WinPixEventRuntime\x1b[0m")
  92. if os.path.isfile(pix_archive):
  93. os.remove(pix_archive)
  94. print(f"Downloading WinPixEventRuntime {pix_version} ...")
  95. urllib.request.urlretrieve(f"https://www.nuget.org/api/v2/package/WinPixEventRuntime/{pix_version}", pix_archive)
  96. if os.path.exists(pix_folder):
  97. print(f"Removing existing local WinPixEventRuntime installation in {pix_folder} ...")
  98. shutil.rmtree(pix_folder)
  99. print(f"Extracting WinPixEventRuntime {pix_version} to {pix_folder} ...")
  100. shutil.unpack_archive(pix_archive, pix_folder, "zip")
  101. os.remove(pix_archive)
  102. if has_mingw:
  103. print("Adapting WinPixEventRuntime to also support MinGW alongside MSVC.")
  104. cwd = os.getcwd()
  105. os.chdir(pix_folder)
  106. subprocess.run([gendef, "./bin/x64/WinPixEventRuntime.dll"])
  107. subprocess.run(
  108. [dlltool]
  109. + "--machine i386:x86-64 --no-leading-underscore -d WinPixEventRuntime.def -D WinPixEventRuntime.dll -l ./bin/x64/libWinPixEventRuntime.a".split()
  110. )
  111. subprocess.run([gendef, "./bin/ARM64/WinPixEventRuntime.dll"])
  112. subprocess.run(
  113. [dlltool]
  114. + "--machine arm64 --no-leading-underscore -d WinPixEventRuntime.def -D WinPixEventRuntime.dll -l ./bin/ARM64/libWinPixEventRuntime.a".split()
  115. )
  116. os.chdir(cwd)
  117. else:
  118. print("MinGW wasn't found, so only MSVC support is provided for WinPixEventRuntime.")
  119. print(f"WinPixEventRuntime {pix_version} installed successfully.\n")
  120. # DirectX 12 Agility SDK
  121. print("\x1b[1m[4/4] DirectX 12 Agility SDK\x1b[0m")
  122. if os.path.isfile(agility_sdk_archive):
  123. os.remove(agility_sdk_archive)
  124. print(f"Downloading DirectX 12 Agility SDK {agility_sdk_version} ...")
  125. urllib.request.urlretrieve(
  126. f"https://www.nuget.org/api/v2/package/Microsoft.Direct3D.D3D12/{agility_sdk_version}", agility_sdk_archive
  127. )
  128. if os.path.exists(agility_sdk_folder):
  129. print(f"Removing existing local DirectX 12 Agility SDK installation in {agility_sdk_folder} ...")
  130. shutil.rmtree(agility_sdk_folder)
  131. print(f"Extracting DirectX 12 Agility SDK {agility_sdk_version} to {agility_sdk_folder} ...")
  132. shutil.unpack_archive(agility_sdk_archive, agility_sdk_folder, "zip")
  133. os.remove(agility_sdk_archive)
  134. print(f"DirectX 12 Agility SDK {agility_sdk_version} installed successfully.\n")
  135. # Complete message
  136. print(f'\x1b[92mAll Direct3D 12 SDK components were installed to "{deps_folder}" successfully!\x1b[0m')
  137. print('\x1b[92mYou can now build Godot with Direct3D 12 support enabled by running "scons d3d12=yes".\x1b[0m')