default.h 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. // Copyright 2009-2021 Intel Corporation
  2. // SPDX-License-Identifier: Apache-2.0
  3. #pragma once
  4. #include "../../common/sys/platform.h"
  5. #include "../../common/sys/sysinfo.h"
  6. #include "../../common/sys/thread.h"
  7. #include "../../common/sys/alloc.h"
  8. #include "../../common/sys/ref.h"
  9. #include "../../common/sys/intrinsics.h"
  10. #include "../../common/sys/atomic.h"
  11. #include "../../common/sys/mutex.h"
  12. #include "../../common/sys/vector.h"
  13. #include "../../common/sys/array.h"
  14. #include "../../common/sys/string.h"
  15. #include "../../common/sys/regression.h"
  16. #include "../../common/sys/vector.h"
  17. #include "../../common/math/math.h"
  18. #include "../../common/math/transcendental.h"
  19. #include "../../common/simd/simd.h"
  20. #include "../../common/math/vec2.h"
  21. #include "../../common/math/vec3.h"
  22. #include "../../common/math/vec4.h"
  23. #include "../../common/math/vec2fa.h"
  24. #include "../../common/math/vec3fa.h"
  25. #include "../../common/math/interval.h"
  26. #include "../../common/math/bbox.h"
  27. #include "../../common/math/obbox.h"
  28. #include "../../common/math/lbbox.h"
  29. #include "../../common/math/linearspace2.h"
  30. #include "../../common/math/linearspace3.h"
  31. #include "../../common/math/affinespace.h"
  32. #include "../../common/math/range.h"
  33. #include "../../common/lexers/tokenstream.h"
  34. #include "../../common/tasking/taskscheduler.h"
  35. #define COMMA ,
  36. #include "../config.h"
  37. #include "isa.h"
  38. #include "stat.h"
  39. #include "profile.h"
  40. #include "rtcore.h"
  41. #include "vector.h"
  42. #include "state.h"
  43. #include "instance_stack.h"
  44. #include <vector>
  45. #include <map>
  46. #include <algorithm>
  47. #include <functional>
  48. #include <utility>
  49. #include <sstream>
  50. namespace embree
  51. {
  52. ////////////////////////////////////////////////////////////////////////////////
  53. /// Vec2 shortcuts
  54. ////////////////////////////////////////////////////////////////////////////////
  55. template<int N> using Vec2vf = Vec2<vfloat<N>>;
  56. template<int N> using Vec2vd = Vec2<vdouble<N>>;
  57. template<int N> using Vec2vr = Vec2<vreal<N>>;
  58. template<int N> using Vec2vi = Vec2<vint<N>>;
  59. template<int N> using Vec2vl = Vec2<vllong<N>>;
  60. template<int N> using Vec2vb = Vec2<vbool<N>>;
  61. template<int N> using Vec2vbf = Vec2<vboolf<N>>;
  62. template<int N> using Vec2vbd = Vec2<vboold<N>>;
  63. typedef Vec2<vfloat4> Vec2vf4;
  64. typedef Vec2<vdouble4> Vec2vd4;
  65. typedef Vec2<vreal4> Vec2vr4;
  66. typedef Vec2<vint4> Vec2vi4;
  67. typedef Vec2<vllong4> Vec2vl4;
  68. typedef Vec2<vbool4> Vec2vb4;
  69. typedef Vec2<vboolf4> Vec2vbf4;
  70. typedef Vec2<vboold4> Vec2vbd4;
  71. typedef Vec2<vfloat8> Vec2vf8;
  72. typedef Vec2<vdouble8> Vec2vd8;
  73. typedef Vec2<vreal8> Vec2vr8;
  74. typedef Vec2<vint8> Vec2vi8;
  75. typedef Vec2<vllong8> Vec2vl8;
  76. typedef Vec2<vbool8> Vec2vb8;
  77. typedef Vec2<vboolf8> Vec2vbf8;
  78. typedef Vec2<vboold8> Vec2vbd8;
  79. typedef Vec2<vfloat16> Vec2vf16;
  80. typedef Vec2<vdouble16> Vec2vd16;
  81. typedef Vec2<vreal16> Vec2vr16;
  82. typedef Vec2<vint16> Vec2vi16;
  83. typedef Vec2<vllong16> Vec2vl16;
  84. typedef Vec2<vbool16> Vec2vb16;
  85. typedef Vec2<vboolf16> Vec2vbf16;
  86. typedef Vec2<vboold16> Vec2vbd16;
  87. typedef Vec2<vfloatx> Vec2vfx;
  88. typedef Vec2<vdoublex> Vec2vdx;
  89. typedef Vec2<vrealx> Vec2vrx;
  90. typedef Vec2<vintx> Vec2vix;
  91. typedef Vec2<vllongx> Vec2vlx;
  92. typedef Vec2<vboolx> Vec2vbx;
  93. typedef Vec2<vboolfx> Vec2vbfx;
  94. typedef Vec2<vbooldx> Vec2vbdx;
  95. ////////////////////////////////////////////////////////////////////////////////
  96. /// Vec3 shortcuts
  97. ////////////////////////////////////////////////////////////////////////////////
  98. template<int N> using Vec3vf = Vec3<vfloat<N>>;
  99. template<int N> using Vec3vd = Vec3<vdouble<N>>;
  100. template<int N> using Vec3vr = Vec3<vreal<N>>;
  101. template<int N> using Vec3vi = Vec3<vint<N>>;
  102. template<int N> using Vec3vl = Vec3<vllong<N>>;
  103. template<int N> using Vec3vb = Vec3<vbool<N>>;
  104. template<int N> using Vec3vbf = Vec3<vboolf<N>>;
  105. template<int N> using Vec3vbd = Vec3<vboold<N>>;
  106. typedef Vec3<vfloat4> Vec3vf4;
  107. typedef Vec3<vdouble4> Vec3vd4;
  108. typedef Vec3<vreal4> Vec3vr4;
  109. typedef Vec3<vint4> Vec3vi4;
  110. typedef Vec3<vllong4> Vec3vl4;
  111. typedef Vec3<vbool4> Vec3vb4;
  112. typedef Vec3<vboolf4> Vec3vbf4;
  113. typedef Vec3<vboold4> Vec3vbd4;
  114. typedef Vec3<vfloat8> Vec3vf8;
  115. typedef Vec3<vdouble8> Vec3vd8;
  116. typedef Vec3<vreal8> Vec3vr8;
  117. typedef Vec3<vint8> Vec3vi8;
  118. typedef Vec3<vllong8> Vec3vl8;
  119. typedef Vec3<vbool8> Vec3vb8;
  120. typedef Vec3<vboolf8> Vec3vbf8;
  121. typedef Vec3<vboold8> Vec3vbd8;
  122. typedef Vec3<vfloat16> Vec3vf16;
  123. typedef Vec3<vdouble16> Vec3vd16;
  124. typedef Vec3<vreal16> Vec3vr16;
  125. typedef Vec3<vint16> Vec3vi16;
  126. typedef Vec3<vllong16> Vec3vl16;
  127. typedef Vec3<vbool16> Vec3vb16;
  128. typedef Vec3<vboolf16> Vec3vbf16;
  129. typedef Vec3<vboold16> Vec3vbd16;
  130. typedef Vec3<vfloatx> Vec3vfx;
  131. typedef Vec3<vdoublex> Vec3vdx;
  132. typedef Vec3<vrealx> Vec3vrx;
  133. typedef Vec3<vintx> Vec3vix;
  134. typedef Vec3<vllongx> Vec3vlx;
  135. typedef Vec3<vboolx> Vec3vbx;
  136. typedef Vec3<vboolfx> Vec3vbfx;
  137. typedef Vec3<vbooldx> Vec3vbdx;
  138. ////////////////////////////////////////////////////////////////////////////////
  139. /// Vec4 shortcuts
  140. ////////////////////////////////////////////////////////////////////////////////
  141. template<int N> using Vec4vf = Vec4<vfloat<N>>;
  142. template<int N> using Vec4vd = Vec4<vdouble<N>>;
  143. template<int N> using Vec4vr = Vec4<vreal<N>>;
  144. template<int N> using Vec4vi = Vec4<vint<N>>;
  145. template<int N> using Vec4vl = Vec4<vllong<N>>;
  146. template<int N> using Vec4vb = Vec4<vbool<N>>;
  147. template<int N> using Vec4vbf = Vec4<vboolf<N>>;
  148. template<int N> using Vec4vbd = Vec4<vboold<N>>;
  149. typedef Vec4<vfloat4> Vec4vf4;
  150. typedef Vec4<vdouble4> Vec4vd4;
  151. typedef Vec4<vreal4> Vec4vr4;
  152. typedef Vec4<vint4> Vec4vi4;
  153. typedef Vec4<vllong4> Vec4vl4;
  154. typedef Vec4<vbool4> Vec4vb4;
  155. typedef Vec4<vboolf4> Vec4vbf4;
  156. typedef Vec4<vboold4> Vec4vbd4;
  157. typedef Vec4<vfloat8> Vec4vf8;
  158. typedef Vec4<vdouble8> Vec4vd8;
  159. typedef Vec4<vreal8> Vec4vr8;
  160. typedef Vec4<vint8> Vec4vi8;
  161. typedef Vec4<vllong8> Vec4vl8;
  162. typedef Vec4<vbool8> Vec4vb8;
  163. typedef Vec4<vboolf8> Vec4vbf8;
  164. typedef Vec4<vboold8> Vec4vbd8;
  165. typedef Vec4<vfloat16> Vec4vf16;
  166. typedef Vec4<vdouble16> Vec4vd16;
  167. typedef Vec4<vreal16> Vec4vr16;
  168. typedef Vec4<vint16> Vec4vi16;
  169. typedef Vec4<vllong16> Vec4vl16;
  170. typedef Vec4<vbool16> Vec4vb16;
  171. typedef Vec4<vboolf16> Vec4vbf16;
  172. typedef Vec4<vboold16> Vec4vbd16;
  173. typedef Vec4<vfloatx> Vec4vfx;
  174. typedef Vec4<vdoublex> Vec4vdx;
  175. typedef Vec4<vrealx> Vec4vrx;
  176. typedef Vec4<vintx> Vec4vix;
  177. typedef Vec4<vllongx> Vec4vlx;
  178. typedef Vec4<vboolx> Vec4vbx;
  179. typedef Vec4<vboolfx> Vec4vbfx;
  180. typedef Vec4<vbooldx> Vec4vbdx;
  181. ////////////////////////////////////////////////////////////////////////////////
  182. /// Other shortcuts
  183. ////////////////////////////////////////////////////////////////////////////////
  184. template<int N> using BBox3vf = BBox<Vec3vf<N>>;
  185. typedef BBox<Vec3vf4> BBox3vf4;
  186. typedef BBox<Vec3vf8> BBox3vf8;
  187. typedef BBox<Vec3vf16> BBox3vf16;
  188. /* calculate time segment itime and fractional time ftime */
  189. __forceinline int getTimeSegment(float time, float numTimeSegments, float& ftime)
  190. {
  191. const float timeScaled = time * numTimeSegments;
  192. const float itimef = clamp(floorf(timeScaled), 0.0f, numTimeSegments-1.0f);
  193. ftime = timeScaled - itimef;
  194. return int(itimef);
  195. }
  196. __forceinline int getTimeSegment(float time, float start_time, float end_time, float numTimeSegments, float& ftime)
  197. {
  198. const float timeScaled = (time-start_time)/(end_time-start_time) * numTimeSegments;
  199. const float itimef = clamp(floorf(timeScaled), 0.0f, numTimeSegments-1.0f);
  200. ftime = timeScaled - itimef;
  201. return int(itimef);
  202. }
  203. template<int N>
  204. __forceinline vint<N> getTimeSegment(const vfloat<N>& time, const vfloat<N>& numTimeSegments, vfloat<N>& ftime)
  205. {
  206. const vfloat<N> timeScaled = time * numTimeSegments;
  207. const vfloat<N> itimef = clamp(floor(timeScaled), vfloat<N>(zero), numTimeSegments-1.0f);
  208. ftime = timeScaled - itimef;
  209. return vint<N>(itimef);
  210. }
  211. template<int N>
  212. __forceinline vint<N> getTimeSegment(const vfloat<N>& time, const vfloat<N>& start_time, const vfloat<N>& end_time, const vfloat<N>& numTimeSegments, vfloat<N>& ftime)
  213. {
  214. const vfloat<N> timeScaled = (time-start_time)/(end_time-start_time) * numTimeSegments;
  215. const vfloat<N> itimef = clamp(floor(timeScaled), vfloat<N>(zero), numTimeSegments-1.0f);
  216. ftime = timeScaled - itimef;
  217. return vint<N>(itimef);
  218. }
  219. /* calculate overlapping time segment range */
  220. __forceinline range<int> getTimeSegmentRange(const BBox1f& time_range, float numTimeSegments)
  221. {
  222. const float round_up = 1.0f+2.0f*float(ulp); // corrects inaccuracies to precisely match time step
  223. const float round_down = 1.0f-2.0f*float(ulp);
  224. const int itime_lower = (int)max(floor(round_up *time_range.lower*numTimeSegments), 0.0f);
  225. const int itime_upper = (int)min(ceil (round_down*time_range.upper*numTimeSegments), numTimeSegments);
  226. return make_range(itime_lower, itime_upper);
  227. }
  228. /* calculate overlapping time segment range */
  229. __forceinline range<int> getTimeSegmentRange(const BBox1f& range, BBox1f time_range, float numTimeSegments)
  230. {
  231. const float lower = (range.lower-time_range.lower)/time_range.size();
  232. const float upper = (range.upper-time_range.lower)/time_range.size();
  233. return getTimeSegmentRange(BBox1f(lower,upper),numTimeSegments);
  234. }
  235. }