2
0

godot_update_embree.py 7.1 KB

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