godot_update_embree.py 7.3 KB

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