SCsub 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. #!/usr/bin/env python
  2. from misc.utility.scons_hints import *
  3. import os
  4. from pathlib import Path
  5. import methods
  6. Import("env")
  7. env_d3d12_rdd = env.Clone()
  8. thirdparty_obj = []
  9. # DirectX Headers (must take precedence over Windows SDK's).
  10. env.Prepend(CPPPATH=["#thirdparty/directx_headers/include/directx"])
  11. env_d3d12_rdd.Prepend(CPPPATH=["#thirdparty/directx_headers/include/directx"])
  12. env_d3d12_rdd.Prepend(CPPPATH=["#thirdparty/directx_headers/include/dxguids"])
  13. # Direct3D 12 Memory Allocator.
  14. env.Append(CPPPATH=["#thirdparty/d3d12ma"])
  15. env_d3d12_rdd.Append(CPPPATH=["#thirdparty/d3d12ma"])
  16. # Agility SDK.
  17. if env["agility_sdk_path"] != "" and os.path.exists(env["agility_sdk_path"]):
  18. env_d3d12_rdd.Append(CPPDEFINES=["AGILITY_SDK_ENABLED"])
  19. if env["agility_sdk_multiarch"]:
  20. env_d3d12_rdd.Append(CPPDEFINES=["AGILITY_SDK_MULTIARCH_ENABLED"])
  21. # PIX.
  22. if env["use_pix"]:
  23. env_d3d12_rdd.Append(CPPDEFINES=["PIX_ENABLED"])
  24. env_d3d12_rdd.Append(CPPPATH=[env["pix_path"] + "/Include"])
  25. # Mesa (SPIR-V to DXIL functionality).
  26. mesa_dir = (env["mesa_libs"] + "/godot-mesa").replace("\\", "/")
  27. mesa_gen_dir = (env["mesa_libs"] + "/godot-mesa/generated").replace("\\", "/")
  28. mesa_absdir = Dir(mesa_dir).abspath
  29. mesa_gen_absdir = Dir(mesa_dir + "/generated").abspath
  30. custom_build_steps = [
  31. [
  32. "src/compiler",
  33. "glsl/ir_expression_operation.py enum > %s/ir_expression_operation.h",
  34. "ir_expression_operation.h",
  35. ],
  36. ["src/compiler/nir", "nir_builder_opcodes_h.py > %s/nir_builder_opcodes.h", "nir_builder_opcodes.h"],
  37. ["src/compiler/nir", "nir_constant_expressions.py > %s/nir_constant_expressions.c", "nir_constant_expressions.c"],
  38. ["src/compiler/nir", "nir_intrinsics_h.py --outdir %s", "nir_intrinsics.h"],
  39. ["src/compiler/nir", "nir_intrinsics_c.py --outdir %s", "nir_intrinsics.c"],
  40. ["src/compiler/nir", "nir_intrinsics_indices_h.py --outdir %s", "nir_intrinsics_indices.h"],
  41. ["src/compiler/nir", "nir_opcodes_h.py > %s/nir_opcodes.h", "nir_opcodes.h"],
  42. ["src/compiler/nir", "nir_opcodes_c.py > %s/nir_opcodes.c", "nir_opcodes.c"],
  43. ["src/compiler/nir", "nir_opt_algebraic.py > %s/nir_opt_algebraic.c", "nir_opt_algebraic.c"],
  44. ["src/compiler/spirv", "vtn_generator_ids_h.py spir-v.xml %s/vtn_generator_ids.h", "vtn_generator_ids.h"],
  45. [
  46. "src/microsoft/compiler",
  47. "dxil_nir_algebraic.py -p ../../../src/compiler/nir > %s/dxil_nir_algebraic.c",
  48. "dxil_nir_algebraic.c",
  49. ],
  50. ["src/util", "format_srgb.py > %s/format_srgb.c", "format_srgb.c"],
  51. ["src/util/format", "u_format_table.py u_format.csv --header > %s/u_format_pack.h", "u_format_pack.h"],
  52. ["src/util/format", "u_format_table.py u_format.csv > %s/u_format_table.c", "u_format_table.c"],
  53. ]
  54. mesa_gen_include_paths = [mesa_gen_dir + "/src"]
  55. # See update_mesa.sh for explanation.
  56. for v in custom_build_steps:
  57. subdir = v[0]
  58. cmd = v[1]
  59. gen_filename = v[2]
  60. in_dir = str(Path(mesa_absdir + "/" + subdir))
  61. out_full_path = mesa_dir + "/generated/" + subdir
  62. out_file_full_path = out_full_path + "/" + gen_filename
  63. if gen_filename.endswith(".h"):
  64. mesa_gen_include_paths += [out_full_path.replace("\\", "/")]
  65. mesa_private_inc_paths = [v[0] for v in os.walk(mesa_absdir)]
  66. mesa_private_inc_paths = [v.replace(mesa_absdir, mesa_dir) for v in mesa_private_inc_paths]
  67. mesa_private_inc_paths = [v.replace("\\", "/") for v in mesa_private_inc_paths]
  68. # Avoid build results depending on if generated files already exist.
  69. mesa_private_inc_paths = [v for v in mesa_private_inc_paths if not v.startswith(mesa_gen_dir)]
  70. mesa_private_inc_paths.sort()
  71. # Include the list of the generated ones now, so out-of-the-box sources can include generated headers.
  72. mesa_private_inc_paths += mesa_gen_include_paths
  73. # We have to blacklist some because we are bindly adding every Mesa directory
  74. # to the include path and in some cases that causes the wrong header to be included.
  75. mesa_blacklist_inc_paths = [
  76. "src/c11",
  77. ]
  78. mesa_blacklist_inc_paths = [mesa_dir + "/" + v for v in mesa_blacklist_inc_paths]
  79. mesa_private_inc_paths = [v for v in mesa_private_inc_paths if v not in mesa_blacklist_inc_paths]
  80. # Added by ourselves.
  81. extra_defines = [
  82. "WINDOWS_NO_FUTEX",
  83. ]
  84. mesa_ver = Path(mesa_absdir + "/VERSION.info")
  85. if not mesa_ver.is_file():
  86. mesa_ver = Path(mesa_absdir + "/VERSION")
  87. # These defines are inspired by the Meson build scripts in the original repo.
  88. extra_defines += [
  89. "__STDC_CONSTANT_MACROS",
  90. "__STDC_FORMAT_MACROS",
  91. "__STDC_LIMIT_MACROS",
  92. ("PACKAGE_VERSION", '\\"' + mesa_ver.read_text().strip() + '\\"'),
  93. ("PACKAGE_BUGREPORT", '\\"https://gitlab.freedesktop.org/mesa/mesa/-/issues\\"'),
  94. "PIPE_SUBSYSTEM_WINDOWS_USER",
  95. ("_Static_assert", "static_assert"),
  96. ]
  97. if env.msvc:
  98. extra_defines += [
  99. "_USE_MATH_DEFINES",
  100. "VC_EXTRALEAN",
  101. "_CRT_SECURE_NO_WARNINGS",
  102. "_CRT_SECURE_NO_DEPRECATE",
  103. "_SCL_SECURE_NO_WARNINGS",
  104. "_SCL_SECURE_NO_DEPRECATE",
  105. "_ALLOW_KEYWORD_MACROS",
  106. ("_HAS_EXCEPTIONS", 0),
  107. "NOMINMAX",
  108. "HAVE_STRUCT_TIMESPEC",
  109. ]
  110. else:
  111. extra_defines += [
  112. "HAVE_STRUCT_TIMESPEC",
  113. ]
  114. if methods.using_gcc(env) and methods.get_compiler_version(env)["major"] < 13:
  115. # `region` & `endregion` not recognized as valid pragmas.
  116. env_d3d12_rdd.Append(CCFLAGS=["-Wno-unknown-pragmas"])
  117. env.Append(CCFLAGS=["-Wno-unknown-pragmas"])
  118. # This is needed since rendering_device_d3d12.cpp needs to include some Mesa internals.
  119. env_d3d12_rdd.Prepend(CPPPATH=mesa_private_inc_paths)
  120. # For the same reason as above, the defines must be the same as in the 3rd-party code itself.
  121. env_d3d12_rdd.Append(CPPDEFINES=extra_defines)
  122. # Add all.
  123. env.drivers_sources += thirdparty_obj
  124. # Godot source files.
  125. driver_obj = []
  126. env_d3d12_rdd.add_source_files(driver_obj, "*.cpp")
  127. env.drivers_sources += driver_obj
  128. # Needed to force rebuilding the driver files when the thirdparty code is updated.
  129. env.Depends(driver_obj, thirdparty_obj)