install_d3d12_sdk_windows.py 5.2 KB

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