godot_update_embree.py 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. import glob, os, shutil, subprocess, re
  2. include_dirs = [
  3. "common/tasking",
  4. "kernels/bvh",
  5. "kernels/builders",
  6. "common/sys",
  7. "kernels",
  8. "kernels/common",
  9. "common/math",
  10. "common/algorithms",
  11. "common/lexers",
  12. "common/simd",
  13. "include/embree3",
  14. "kernels/subdiv",
  15. "kernels/geometry",
  16. ]
  17. cpp_files = [
  18. "common/sys/sysinfo.cpp",
  19. "common/sys/alloc.cpp",
  20. "common/sys/filename.cpp",
  21. "common/sys/library.cpp",
  22. "common/sys/thread.cpp",
  23. "common/sys/string.cpp",
  24. "common/sys/regression.cpp",
  25. "common/sys/mutex.cpp",
  26. "common/sys/condition.cpp",
  27. "common/sys/barrier.cpp",
  28. "common/math/constants.cpp",
  29. "common/simd/sse.cpp",
  30. "common/lexers/stringstream.cpp",
  31. "common/lexers/tokenstream.cpp",
  32. "common/tasking/taskschedulerinternal.cpp",
  33. "common/algorithms/parallel_for.cpp",
  34. "common/algorithms/parallel_reduce.cpp",
  35. "common/algorithms/parallel_prefix_sum.cpp",
  36. "common/algorithms/parallel_for_for.cpp",
  37. "common/algorithms/parallel_for_for_prefix_sum.cpp",
  38. "common/algorithms/parallel_partition.cpp",
  39. "common/algorithms/parallel_sort.cpp",
  40. "common/algorithms/parallel_set.cpp",
  41. "common/algorithms/parallel_map.cpp",
  42. "common/algorithms/parallel_filter.cpp",
  43. "kernels/common/device.cpp",
  44. "kernels/common/stat.cpp",
  45. "kernels/common/acceln.cpp",
  46. "kernels/common/accelset.cpp",
  47. "kernels/common/state.cpp",
  48. "kernels/common/rtcore.cpp",
  49. "kernels/common/rtcore_builder.cpp",
  50. "kernels/common/scene.cpp",
  51. "kernels/common/alloc.cpp",
  52. "kernels/common/geometry.cpp",
  53. "kernels/common/scene_triangle_mesh.cpp",
  54. "kernels/geometry/primitive4.cpp",
  55. "kernels/builders/primrefgen.cpp",
  56. "kernels/bvh/bvh.cpp",
  57. "kernels/bvh/bvh_statistics.cpp",
  58. "kernels/bvh/bvh4_factory.cpp",
  59. "kernels/bvh/bvh8_factory.cpp",
  60. "kernels/bvh/bvh_collider.cpp",
  61. "kernels/bvh/bvh_rotate.cpp",
  62. "kernels/bvh/bvh_refit.cpp",
  63. "kernels/bvh/bvh_builder.cpp",
  64. "kernels/bvh/bvh_builder_morton.cpp",
  65. "kernels/bvh/bvh_builder_sah.cpp",
  66. "kernels/bvh/bvh_builder_sah_spatial.cpp",
  67. "kernels/bvh/bvh_builder_sah_mb.cpp",
  68. "kernels/bvh/bvh_builder_twolevel.cpp",
  69. "kernels/bvh/bvh_intersector1.cpp",
  70. "kernels/bvh/bvh_intersector1_bvh4.cpp",
  71. ]
  72. os.chdir("../../thirdparty")
  73. dir_name = "embree"
  74. if os.path.exists(dir_name):
  75. shutil.rmtree(dir_name)
  76. subprocess.run(["git", "clone", "https://github.com/lighttransport/embree-aarch64.git", "embree-tmp"])
  77. os.chdir("embree-tmp")
  78. commit_hash = str(subprocess.check_output(["git", "rev-parse", "HEAD"], universal_newlines=True)).strip()
  79. all_files = set(cpp_files)
  80. dest_dir = os.path.join("..", dir_name)
  81. for include_dir in include_dirs:
  82. headers = glob.iglob(os.path.join(include_dir, "*.h"))
  83. all_files.update(headers)
  84. for f in all_files:
  85. d = os.path.join(dest_dir, os.path.dirname(f))
  86. if not os.path.exists(d):
  87. os.makedirs(d)
  88. shutil.copy2(f, d)
  89. with open(os.path.join(dest_dir, "kernels/hash.h"), "w") as hash_file:
  90. hash_file.write(
  91. f"""
  92. // Copyright 2009-2020 Intel Corporation
  93. // SPDX-License-Identifier: Apache-2.0
  94. #define RTC_HASH "{commit_hash}"
  95. """
  96. )
  97. with open(os.path.join(dest_dir, "kernels/config.h"), "w") as config_file:
  98. config_file.write(
  99. """
  100. // Copyright 2009-2020 Intel Corporation
  101. // SPDX-License-Identifier: Apache-2.0
  102. /* #undef EMBREE_RAY_MASK */
  103. /* #undef EMBREE_STAT_COUNTERS */
  104. /* #undef EMBREE_BACKFACE_CULLING */
  105. /* #undef EMBREE_BACKFACE_CULLING_CURVES */
  106. #define EMBREE_FILTER_FUNCTION
  107. /* #undef EMBREE_IGNORE_INVALID_RAYS */
  108. #define EMBREE_GEOMETRY_TRIANGLE
  109. /* #undef EMBREE_GEOMETRY_QUAD */
  110. /* #undef EMBREE_GEOMETRY_CURVE */
  111. /* #undef EMBREE_GEOMETRY_SUBDIVISION */
  112. /* #undef EMBREE_GEOMETRY_USER */
  113. /* #undef EMBREE_GEOMETRY_INSTANCE */
  114. /* #undef EMBREE_GEOMETRY_GRID */
  115. /* #undef EMBREE_GEOMETRY_POINT */
  116. /* #undef EMBREE_RAY_PACKETS */
  117. /* #undef EMBREE_COMPACT_POLYS */
  118. #define EMBREE_CURVE_SELF_INTERSECTION_AVOIDANCE_FACTOR 2.0
  119. #if defined(EMBREE_GEOMETRY_TRIANGLE)
  120. #define IF_ENABLED_TRIS(x) x
  121. #else
  122. #define IF_ENABLED_TRIS(x)
  123. #endif
  124. #if defined(EMBREE_GEOMETRY_QUAD)
  125. #define IF_ENABLED_QUADS(x) x
  126. #else
  127. #define IF_ENABLED_QUADS(x)
  128. #endif
  129. #if defined(EMBREE_GEOMETRY_CURVE) || defined(EMBREE_GEOMETRY_POINT)
  130. #define IF_ENABLED_CURVES_OR_POINTS(x) x
  131. #else
  132. #define IF_ENABLED_CURVES_OR_POINTS(x)
  133. #endif
  134. #if defined(EMBREE_GEOMETRY_CURVE)
  135. #define IF_ENABLED_CURVES(x) x
  136. #else
  137. #define IF_ENABLED_CURVES(x)
  138. #endif
  139. #if defined(EMBREE_GEOMETRY_POINT)
  140. #define IF_ENABLED_POINTS(x) x
  141. #else
  142. #define IF_ENABLED_POINTS(x)
  143. #endif
  144. #if defined(EMBREE_GEOMETRY_SUBDIVISION)
  145. #define IF_ENABLED_SUBDIV(x) x
  146. #else
  147. #define IF_ENABLED_SUBDIV(x)
  148. #endif
  149. #if defined(EMBREE_GEOMETRY_USER)
  150. #define IF_ENABLED_USER(x) x
  151. #else
  152. #define IF_ENABLED_USER(x)
  153. #endif
  154. #if defined(EMBREE_GEOMETRY_INSTANCE)
  155. #define IF_ENABLED_INSTANCE(x) x
  156. #else
  157. #define IF_ENABLED_INSTANCE(x)
  158. #endif
  159. #if defined(EMBREE_GEOMETRY_GRID)
  160. #define IF_ENABLED_GRIDS(x) x
  161. #else
  162. #define IF_ENABLED_GRIDS(x)
  163. #endif
  164. """
  165. )
  166. with open("CMakeLists.txt", "r") as cmake_file:
  167. cmake_content = cmake_file.read()
  168. major_version = int(re.compile(r"EMBREE_VERSION_MAJOR\s(\d+)").findall(cmake_content)[0])
  169. minor_version = int(re.compile(r"EMBREE_VERSION_MINOR\s(\d+)").findall(cmake_content)[0])
  170. patch_version = int(re.compile(r"EMBREE_VERSION_PATCH\s(\d+)").findall(cmake_content)[0])
  171. with open(os.path.join(dest_dir, "include/embree3/rtcore_config.h"), "w") as config_file:
  172. config_file.write(
  173. f"""
  174. // Copyright 2009-2020 Intel Corporation
  175. // SPDX-License-Identifier: Apache-2.0
  176. #pragma once
  177. #define RTC_VERSION_MAJOR {major_version}
  178. #define RTC_VERSION_MINOR {minor_version}
  179. #define RTC_VERSION_PATCH {patch_version}
  180. #define RTC_VERSION {major_version}{minor_version:02d}{patch_version:02d}
  181. #define RTC_VERSION_STRING "{major_version}.{minor_version}.{patch_version}"
  182. #define RTC_MAX_INSTANCE_LEVEL_COUNT 1
  183. #define EMBREE_MIN_WIDTH 0
  184. #define RTC_MIN_WIDTH EMBREE_MIN_WIDTH
  185. #define EMBREE_STATIC_LIB
  186. /* #undef EMBREE_API_NAMESPACE */
  187. #if defined(EMBREE_API_NAMESPACE)
  188. # define RTC_NAMESPACE
  189. # define RTC_NAMESPACE_BEGIN namespace {{
  190. # define RTC_NAMESPACE_END }}
  191. # define RTC_NAMESPACE_USE using namespace ;
  192. # define RTC_API_EXTERN_C
  193. # undef EMBREE_API_NAMESPACE
  194. #else
  195. # define RTC_NAMESPACE_BEGIN
  196. # define RTC_NAMESPACE_END
  197. # define RTC_NAMESPACE_USE
  198. # if defined(__cplusplus)
  199. # define RTC_API_EXTERN_C extern "C"
  200. # else
  201. # define RTC_API_EXTERN_C
  202. # endif
  203. #endif
  204. #if defined(ISPC)
  205. # define RTC_API_IMPORT extern "C" unmasked
  206. # define RTC_API_EXPORT extern "C" unmasked
  207. #elif defined(EMBREE_STATIC_LIB)
  208. # define RTC_API_IMPORT RTC_API_EXTERN_C
  209. # define RTC_API_EXPORT RTC_API_EXTERN_C
  210. #elif defined(_WIN32)
  211. # define RTC_API_IMPORT RTC_API_EXTERN_C __declspec(dllimport)
  212. # define RTC_API_EXPORT RTC_API_EXTERN_C __declspec(dllexport)
  213. #else
  214. # define RTC_API_IMPORT RTC_API_EXTERN_C
  215. # define RTC_API_EXPORT RTC_API_EXTERN_C __attribute__ ((visibility ("default")))
  216. #endif
  217. #if defined(RTC_EXPORT_API)
  218. # define RTC_API RTC_API_EXPORT
  219. #else
  220. # define RTC_API RTC_API_IMPORT
  221. #endif
  222. """
  223. )
  224. os.chdir("..")
  225. shutil.rmtree("embree-tmp")