godot_update_embree.py 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  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. ]
  63. os.chdir("../../thirdparty")
  64. dir_name = "embree"
  65. if os.path.exists(dir_name):
  66. shutil.rmtree(dir_name)
  67. subprocess.run(["git", "clone", "https://github.com/embree/embree.git", "embree-tmp"])
  68. os.chdir("embree-tmp")
  69. commit_hash = str(subprocess.check_output(["git", "rev-parse", "HEAD"], universal_newlines=True)).strip()
  70. all_files = set(cpp_files)
  71. dest_dir = os.path.join("..", dir_name)
  72. for include_dir in include_dirs:
  73. headers = glob.iglob(os.path.join(include_dir, "*.h"))
  74. all_files.update(headers)
  75. for f in all_files:
  76. d = os.path.join(dest_dir, os.path.dirname(f))
  77. if not os.path.exists(d):
  78. os.makedirs(d)
  79. shutil.copy2(f, d)
  80. with open(os.path.join(dest_dir, "kernels/hash.h"), "w") as hash_file:
  81. hash_file.write(
  82. f"""
  83. // Copyright 2009-2020 Intel Corporation
  84. // SPDX-License-Identifier: Apache-2.0
  85. #define RTC_HASH "{commit_hash}"
  86. """
  87. )
  88. with open(os.path.join(dest_dir, "kernels/config.h"), "w") as config_file:
  89. config_file.write(
  90. """
  91. // Copyright 2009-2020 Intel Corporation
  92. // SPDX-License-Identifier: Apache-2.0
  93. /* #undef EMBREE_RAY_MASK */
  94. /* #undef EMBREE_STAT_COUNTERS */
  95. /* #undef EMBREE_BACKFACE_CULLING */
  96. /* #undef EMBREE_BACKFACE_CULLING_CURVES */
  97. #define EMBREE_FILTER_FUNCTION
  98. /* #undef EMBREE_IGNORE_INVALID_RAYS */
  99. #define EMBREE_GEOMETRY_TRIANGLE
  100. /* #undef EMBREE_GEOMETRY_QUAD */
  101. /* #undef EMBREE_GEOMETRY_CURVE */
  102. /* #undef EMBREE_GEOMETRY_SUBDIVISION */
  103. /* #undef EMBREE_GEOMETRY_USER */
  104. /* #undef EMBREE_GEOMETRY_INSTANCE */
  105. /* #undef EMBREE_GEOMETRY_GRID */
  106. /* #undef EMBREE_GEOMETRY_POINT */
  107. /* #undef EMBREE_RAY_PACKETS */
  108. /* #undef EMBREE_COMPACT_POLYS */
  109. #define EMBREE_CURVE_SELF_INTERSECTION_AVOIDANCE_FACTOR 2.0
  110. #if defined(EMBREE_GEOMETRY_TRIANGLE)
  111. #define IF_ENABLED_TRIS(x) x
  112. #else
  113. #define IF_ENABLED_TRIS(x)
  114. #endif
  115. #if defined(EMBREE_GEOMETRY_QUAD)
  116. #define IF_ENABLED_QUADS(x) x
  117. #else
  118. #define IF_ENABLED_QUADS(x)
  119. #endif
  120. #if defined(EMBREE_GEOMETRY_CURVE) || defined(EMBREE_GEOMETRY_POINT)
  121. #define IF_ENABLED_CURVES_OR_POINTS(x) x
  122. #else
  123. #define IF_ENABLED_CURVES_OR_POINTS(x)
  124. #endif
  125. #if defined(EMBREE_GEOMETRY_CURVE)
  126. #define IF_ENABLED_CURVES(x) x
  127. #else
  128. #define IF_ENABLED_CURVES(x)
  129. #endif
  130. #if defined(EMBREE_GEOMETRY_POINT)
  131. #define IF_ENABLED_POINTS(x) x
  132. #else
  133. #define IF_ENABLED_POINTS(x)
  134. #endif
  135. #if defined(EMBREE_GEOMETRY_SUBDIVISION)
  136. #define IF_ENABLED_SUBDIV(x) x
  137. #else
  138. #define IF_ENABLED_SUBDIV(x)
  139. #endif
  140. #if defined(EMBREE_GEOMETRY_USER)
  141. #define IF_ENABLED_USER(x) x
  142. #else
  143. #define IF_ENABLED_USER(x)
  144. #endif
  145. #if defined(EMBREE_GEOMETRY_INSTANCE)
  146. #define IF_ENABLED_INSTANCE(x) x
  147. #else
  148. #define IF_ENABLED_INSTANCE(x)
  149. #endif
  150. #if defined(EMBREE_GEOMETRY_GRID)
  151. #define IF_ENABLED_GRIDS(x) x
  152. #else
  153. #define IF_ENABLED_GRIDS(x)
  154. #endif
  155. """
  156. )
  157. with open("CMakeLists.txt", "r") as cmake_file:
  158. cmake_content = cmake_file.read()
  159. major_version = int(re.compile(r"EMBREE_VERSION_MAJOR\s(\d+)").findall(cmake_content)[0])
  160. minor_version = int(re.compile(r"EMBREE_VERSION_MINOR\s(\d+)").findall(cmake_content)[0])
  161. patch_version = int(re.compile(r"EMBREE_VERSION_PATCH\s(\d+)").findall(cmake_content)[0])
  162. with open(os.path.join(dest_dir, "include/embree3/rtcore_config.h"), "w") as config_file:
  163. config_file.write(
  164. f"""
  165. // Copyright 2009-2021 Intel Corporation
  166. // SPDX-License-Identifier: Apache-2.0
  167. #pragma once
  168. #define RTC_VERSION_MAJOR {major_version}
  169. #define RTC_VERSION_MINOR {minor_version}
  170. #define RTC_VERSION_PATCH {patch_version}
  171. #define RTC_VERSION {major_version}{minor_version:02d}{patch_version:02d}
  172. #define RTC_VERSION_STRING "{major_version}.{minor_version}.{patch_version}"
  173. #define RTC_MAX_INSTANCE_LEVEL_COUNT 1
  174. #define EMBREE_MIN_WIDTH 0
  175. #define RTC_MIN_WIDTH EMBREE_MIN_WIDTH
  176. #define EMBREE_STATIC_LIB
  177. /* #undef EMBREE_API_NAMESPACE */
  178. #if defined(EMBREE_API_NAMESPACE)
  179. # define RTC_NAMESPACE
  180. # define RTC_NAMESPACE_BEGIN namespace {{
  181. # define RTC_NAMESPACE_END }}
  182. # define RTC_NAMESPACE_USE using namespace ;
  183. # define RTC_API_EXTERN_C
  184. # undef EMBREE_API_NAMESPACE
  185. #else
  186. # define RTC_NAMESPACE_BEGIN
  187. # define RTC_NAMESPACE_END
  188. # define RTC_NAMESPACE_USE
  189. # if defined(__cplusplus)
  190. # define RTC_API_EXTERN_C extern "C"
  191. # else
  192. # define RTC_API_EXTERN_C
  193. # endif
  194. #endif
  195. #if defined(ISPC)
  196. # define RTC_API_IMPORT extern "C" unmasked
  197. # define RTC_API_EXPORT extern "C" unmasked
  198. #elif defined(EMBREE_STATIC_LIB)
  199. # define RTC_API_IMPORT RTC_API_EXTERN_C
  200. # define RTC_API_EXPORT RTC_API_EXTERN_C
  201. #elif defined(_WIN32)
  202. # define RTC_API_IMPORT RTC_API_EXTERN_C __declspec(dllimport)
  203. # define RTC_API_EXPORT RTC_API_EXTERN_C __declspec(dllexport)
  204. #else
  205. # define RTC_API_IMPORT RTC_API_EXTERN_C
  206. # define RTC_API_EXPORT RTC_API_EXTERN_C __attribute__ ((visibility ("default")))
  207. #endif
  208. #if defined(RTC_EXPORT_API)
  209. # define RTC_API RTC_API_EXPORT
  210. #else
  211. # define RTC_API RTC_API_IMPORT
  212. #endif
  213. """
  214. )
  215. os.chdir("..")
  216. shutil.rmtree("embree-tmp")