scene.cpp 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929
  1. // ======================================================================== //
  2. // Copyright 2009-2017 Intel Corporation //
  3. // //
  4. // Licensed under the Apache License, Version 2.0 (the "License"); //
  5. // you may not use this file except in compliance with the License. //
  6. // You may obtain a copy of the License at //
  7. // //
  8. // http://www.apache.org/licenses/LICENSE-2.0 //
  9. // //
  10. // Unless required by applicable law or agreed to in writing, software //
  11. // distributed under the License is distributed on an "AS IS" BASIS, //
  12. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. //
  13. // See the License for the specific language governing permissions and //
  14. // limitations under the License. //
  15. // ======================================================================== //
  16. #include "scene.h"
  17. #include "../bvh/bvh4_factory.h"
  18. #include "../bvh/bvh8_factory.h"
  19. namespace embree
  20. {
  21. /* error raising rtcIntersect and rtcOccluded functions */
  22. void missing_rtcCommit() { throw_RTCError(RTC_INVALID_OPERATION,"scene got not committed"); }
  23. void invalid_rtcIntersect1() { throw_RTCError(RTC_INVALID_OPERATION,"rtcIntersect and rtcOccluded not enabled"); }
  24. void invalid_rtcIntersect4() { throw_RTCError(RTC_INVALID_OPERATION,"rtcIntersect4 and rtcOccluded4 not enabled"); }
  25. void invalid_rtcIntersect8() { throw_RTCError(RTC_INVALID_OPERATION,"rtcIntersect8 and rtcOccluded8 not enabled"); }
  26. void invalid_rtcIntersect16() { throw_RTCError(RTC_INVALID_OPERATION,"rtcIntersect16 and rtcOccluded16 not enabled"); }
  27. void invalid_rtcIntersectN() { throw_RTCError(RTC_INVALID_OPERATION,"rtcIntersectN and rtcOccludedN not enabled"); }
  28. Scene::Scene (Device* device, RTCSceneFlags sflags, RTCAlgorithmFlags aflags)
  29. : Accel(AccelData::TY_UNKNOWN),
  30. device(device),
  31. commitCounterSubdiv(0),
  32. numMappedBuffers(0),
  33. flags(sflags), aflags(aflags),
  34. needTriangleIndices(false), needTriangleVertices(false),
  35. needQuadIndices(false), needQuadVertices(false),
  36. needBezierIndices(false), needBezierVertices(false),
  37. needLineIndices(false), needLineVertices(false),
  38. needSubdivIndices(false), needSubdivVertices(false),
  39. is_build(false), modified(true),
  40. progressInterface(this), progress_monitor_function(nullptr), progress_monitor_ptr(nullptr), progress_monitor_counter(0),
  41. numIntersectionFilters1(0), numIntersectionFilters4(0), numIntersectionFilters8(0), numIntersectionFilters16(0), numIntersectionFiltersN(0)
  42. {
  43. #if defined(TASKING_INTERNAL)
  44. scheduler = nullptr;
  45. #elif defined(TASKING_TBB)
  46. group = new tbb::task_group;
  47. #elif defined(TASKING_PPL)
  48. group = new concurrency::task_group;
  49. #endif
  50. intersectors = Accel::Intersectors(missing_rtcCommit);
  51. if (device->scene_flags != -1)
  52. flags = (RTCSceneFlags) device->scene_flags;
  53. if (aflags & RTC_INTERPOLATE) {
  54. needTriangleIndices = true;
  55. needQuadIndices = true;
  56. needBezierIndices = true;
  57. needLineIndices = true;
  58. //needSubdivIndices = true; // not required for interpolation
  59. needTriangleVertices = true;
  60. needQuadVertices = true;
  61. needBezierVertices = true;
  62. needLineVertices = true;
  63. needSubdivVertices = true;
  64. }
  65. createTriangleAccel();
  66. createTriangleMBAccel();
  67. createQuadAccel();
  68. createQuadMBAccel();
  69. createSubdivAccel();
  70. createSubdivMBAccel();
  71. createHairAccel();
  72. createHairMBAccel();
  73. createLineAccel();
  74. createLineMBAccel();
  75. #if defined(EMBREE_GEOMETRY_TRIANGLES)
  76. accels.add(device->bvh4_factory->BVH4InstancedBVH4Triangle4ObjectSplit(this));
  77. #endif
  78. // has to be the last as the instID field of a hit instance is not invalidated by other hit geometry
  79. createUserGeometryAccel();
  80. createUserGeometryMBAccel();
  81. }
  82. void Scene::createTriangleAccel()
  83. {
  84. #if defined(EMBREE_GEOMETRY_TRIANGLES)
  85. if (device->tri_accel == "default")
  86. {
  87. if (isStatic()) {
  88. int mode = 2*(int)isCompact() + 1*(int)isRobust();
  89. switch (mode) {
  90. case /*0b00*/ 0:
  91. #if defined (__TARGET_AVX__)
  92. if (device->hasISA(AVX))
  93. {
  94. if (isHighQuality())
  95. accels.add(device->bvh8_factory->BVH8Triangle4(this,BVH8Factory::BuildVariant::HIGH_QUALITY,BVH8Factory::IntersectVariant::FAST));
  96. else
  97. accels.add(device->bvh8_factory->BVH8Triangle4(this,BVH8Factory::BuildVariant::STATIC,BVH8Factory::IntersectVariant::FAST));
  98. }
  99. else
  100. #endif
  101. {
  102. if (isHighQuality())
  103. accels.add(device->bvh4_factory->BVH4Triangle4(this,BVH4Factory::BuildVariant::HIGH_QUALITY,BVH4Factory::IntersectVariant::FAST));
  104. else
  105. accels.add(device->bvh4_factory->BVH4Triangle4(this,BVH4Factory::BuildVariant::STATIC,BVH4Factory::IntersectVariant::FAST));
  106. }
  107. break;
  108. case /*0b01*/ 1:
  109. #if defined (__TARGET_AVX__)
  110. if (device->hasISA(AVX))
  111. accels.add(device->bvh8_factory->BVH8Triangle4v(this,BVH8Factory::BuildVariant::STATIC,BVH8Factory::IntersectVariant::ROBUST));
  112. else
  113. #endif
  114. accels.add(device->bvh4_factory->BVH4Triangle4v(this,BVH4Factory::BuildVariant::STATIC,BVH4Factory::IntersectVariant::ROBUST));
  115. break;
  116. case /*0b10*/ 2:
  117. #if defined (__TARGET_AVX__)
  118. if (device->hasISA(AVX))
  119. accels.add(device->bvh8_factory->BVH8Triangle4i(this,BVH8Factory::BuildVariant::STATIC,BVH8Factory::IntersectVariant::FAST ));
  120. else
  121. #endif
  122. accels.add(device->bvh4_factory->BVH4Triangle4i(this,BVH4Factory::BuildVariant::STATIC,BVH4Factory::IntersectVariant::FAST ));
  123. break;
  124. case /*0b11*/ 3:
  125. #if defined (__TARGET_AVX__)
  126. if (device->hasISA(AVX))
  127. accels.add(device->bvh8_factory->BVH8Triangle4i(this,BVH8Factory::BuildVariant::STATIC,BVH8Factory::IntersectVariant::ROBUST));
  128. else
  129. #endif
  130. accels.add(device->bvh4_factory->BVH4Triangle4i(this,BVH4Factory::BuildVariant::STATIC,BVH4Factory::IntersectVariant::ROBUST));
  131. break;
  132. }
  133. }
  134. else /* dynamic */
  135. {
  136. #if defined (__TARGET_AVX__)
  137. if (device->hasISA(AVX))
  138. {
  139. int mode = 2*(int)isCompact() + 1*(int)isRobust();
  140. switch (mode) {
  141. case /*0b00*/ 0: accels.add(device->bvh8_factory->BVH8Triangle4 (this,BVH8Factory::BuildVariant::DYNAMIC,BVH8Factory::IntersectVariant::FAST )); break;
  142. case /*0b01*/ 1: accels.add(device->bvh8_factory->BVH8Triangle4v(this,BVH8Factory::BuildVariant::DYNAMIC,BVH8Factory::IntersectVariant::ROBUST)); break;
  143. case /*0b10*/ 2: accels.add(device->bvh8_factory->BVH8Triangle4i(this,BVH8Factory::BuildVariant::DYNAMIC,BVH8Factory::IntersectVariant::FAST )); break;
  144. case /*0b11*/ 3: accels.add(device->bvh8_factory->BVH8Triangle4i(this,BVH8Factory::BuildVariant::DYNAMIC,BVH8Factory::IntersectVariant::ROBUST)); break;
  145. }
  146. }
  147. else
  148. #endif
  149. {
  150. int mode = 2*(int)isCompact() + 1*(int)isRobust();
  151. switch (mode) {
  152. case /*0b00*/ 0: accels.add(device->bvh4_factory->BVH4Triangle4 (this,BVH4Factory::BuildVariant::DYNAMIC,BVH4Factory::IntersectVariant::FAST )); break;
  153. case /*0b01*/ 1: accels.add(device->bvh4_factory->BVH4Triangle4v(this,BVH4Factory::BuildVariant::DYNAMIC,BVH4Factory::IntersectVariant::ROBUST)); break;
  154. case /*0b10*/ 2: accels.add(device->bvh4_factory->BVH4Triangle4i(this,BVH4Factory::BuildVariant::DYNAMIC,BVH4Factory::IntersectVariant::FAST )); break;
  155. case /*0b11*/ 3: accels.add(device->bvh4_factory->BVH4Triangle4i(this,BVH4Factory::BuildVariant::DYNAMIC,BVH4Factory::IntersectVariant::ROBUST)); break;
  156. }
  157. }
  158. }
  159. }
  160. else if (device->tri_accel == "bvh4.triangle4") accels.add(device->bvh4_factory->BVH4Triangle4 (this));
  161. else if (device->tri_accel == "bvh4.triangle4v") accels.add(device->bvh4_factory->BVH4Triangle4v(this));
  162. else if (device->tri_accel == "bvh4.triangle4i") accels.add(device->bvh4_factory->BVH4Triangle4i(this));
  163. else if (device->tri_accel == "qbvh4.triangle4i") accels.add(device->bvh4_factory->BVH4QuantizedTriangle4i(this));
  164. #if defined (__TARGET_AVX__)
  165. else if (device->tri_accel == "bvh8.triangle4") accels.add(device->bvh8_factory->BVH8Triangle4 (this));
  166. else if (device->tri_accel == "bvh8.triangle4i") accels.add(device->bvh8_factory->BVH8Triangle4i(this));
  167. else if (device->tri_accel == "qbvh8.triangle4i") accels.add(device->bvh8_factory->BVH8QuantizedTriangle4i(this));
  168. #endif
  169. else throw_RTCError(RTC_INVALID_ARGUMENT,"unknown triangle acceleration structure "+device->tri_accel);
  170. #endif
  171. }
  172. void Scene::createTriangleMBAccel()
  173. {
  174. #if defined(EMBREE_GEOMETRY_TRIANGLES)
  175. if (device->tri_accel_mb == "default")
  176. {
  177. int mode = 2*(int)isCompact() + 1*(int)isRobust();
  178. #if defined (__TARGET_AVX__)
  179. if (device->hasISA(AVX2)) // BVH8 reduces performance on AVX only-machines
  180. {
  181. switch (mode) {
  182. case /*0b00*/ 0: accels.add(device->bvh8_factory->BVH8Triangle4iMB(this,BVH8Factory::BuildVariant::STATIC,BVH8Factory::IntersectVariant::FAST )); break;
  183. case /*0b01*/ 1: accels.add(device->bvh8_factory->BVH8Triangle4iMB(this,BVH8Factory::BuildVariant::STATIC,BVH8Factory::IntersectVariant::ROBUST)); break;
  184. case /*0b10*/ 2: accels.add(device->bvh4_factory->BVH4Triangle4iMB(this,BVH4Factory::BuildVariant::STATIC,BVH4Factory::IntersectVariant::FAST )); break;
  185. case /*0b11*/ 3: accels.add(device->bvh4_factory->BVH4Triangle4iMB(this,BVH4Factory::BuildVariant::STATIC,BVH4Factory::IntersectVariant::ROBUST)); break;
  186. }
  187. }
  188. else
  189. #endif
  190. {
  191. switch (mode) {
  192. case /*0b00*/ 0: accels.add(device->bvh4_factory->BVH4Triangle4iMB(this,BVH4Factory::BuildVariant::STATIC,BVH4Factory::IntersectVariant::FAST )); break;
  193. case /*0b01*/ 1: accels.add(device->bvh4_factory->BVH4Triangle4iMB(this,BVH4Factory::BuildVariant::STATIC,BVH4Factory::IntersectVariant::ROBUST)); break;
  194. case /*0b10*/ 2: accels.add(device->bvh4_factory->BVH4Triangle4iMB(this,BVH4Factory::BuildVariant::STATIC,BVH4Factory::IntersectVariant::FAST )); break;
  195. case /*0b11*/ 3: accels.add(device->bvh4_factory->BVH4Triangle4iMB(this,BVH4Factory::BuildVariant::STATIC,BVH4Factory::IntersectVariant::ROBUST)); break;
  196. }
  197. }
  198. }
  199. else if (device->tri_accel_mb == "bvh4.triangle4vmb") accels.add(device->bvh4_factory->BVH4Triangle4vMB(this));
  200. else if (device->tri_accel_mb == "bvh4.triangle4imb") accels.add(device->bvh4_factory->BVH4Triangle4iMB(this));
  201. #if defined (__TARGET_AVX__)
  202. else if (device->tri_accel_mb == "bvh8.triangle4vmb") accels.add(device->bvh8_factory->BVH8Triangle4vMB(this));
  203. else if (device->tri_accel_mb == "bvh8.triangle4imb") accels.add(device->bvh8_factory->BVH8Triangle4iMB(this));
  204. #endif
  205. else throw_RTCError(RTC_INVALID_ARGUMENT,"unknown motion blur triangle acceleration structure "+device->tri_accel_mb);
  206. #endif
  207. }
  208. void Scene::createQuadAccel()
  209. {
  210. #if defined(EMBREE_GEOMETRY_QUADS)
  211. if (device->quad_accel == "default")
  212. {
  213. if (isStatic())
  214. {
  215. /* static */
  216. int mode = 2*(int)isCompact() + 1*(int)isRobust();
  217. switch (mode) {
  218. case /*0b00*/ 0:
  219. #if defined (__TARGET_AVX__)
  220. if (device->hasISA(AVX))
  221. {
  222. if (isHighQuality())
  223. accels.add(device->bvh8_factory->BVH8Quad4v(this,BVH8Factory::BuildVariant::HIGH_QUALITY,BVH8Factory::IntersectVariant::FAST));
  224. else
  225. accels.add(device->bvh8_factory->BVH8Quad4v(this,BVH8Factory::BuildVariant::STATIC,BVH8Factory::IntersectVariant::FAST));
  226. }
  227. else
  228. #endif
  229. {
  230. if (isHighQuality())
  231. accels.add(device->bvh4_factory->BVH4Quad4v(this,BVH4Factory::BuildVariant::HIGH_QUALITY,BVH4Factory::IntersectVariant::FAST));
  232. else
  233. accels.add(device->bvh4_factory->BVH4Quad4v(this,BVH4Factory::BuildVariant::STATIC,BVH4Factory::IntersectVariant::FAST));
  234. }
  235. break;
  236. case /*0b01*/ 1:
  237. #if defined (__TARGET_AVX__)
  238. if (device->hasISA(AVX))
  239. accels.add(device->bvh8_factory->BVH8Quad4v(this,BVH8Factory::BuildVariant::STATIC,BVH8Factory::IntersectVariant::ROBUST));
  240. else
  241. #endif
  242. accels.add(device->bvh4_factory->BVH4Quad4v(this,BVH4Factory::BuildVariant::STATIC,BVH4Factory::IntersectVariant::ROBUST));
  243. break;
  244. case /*0b10*/ 2: accels.add(device->bvh4_factory->BVH4Quad4i(this,BVH4Factory::BuildVariant::STATIC,BVH4Factory::IntersectVariant::FAST)); break;
  245. case /*0b11*/ 3: accels.add(device->bvh4_factory->BVH4Quad4i(this,BVH4Factory::BuildVariant::STATIC,BVH4Factory::IntersectVariant::ROBUST)); break;
  246. }
  247. }
  248. else /* dynamic */
  249. {
  250. #if defined (__TARGET_AVX__)
  251. if (device->hasISA(AVX))
  252. {
  253. int mode = 2*(int)isCompact() + 1*(int)isRobust();
  254. switch (mode) {
  255. case /*0b00*/ 0: accels.add(device->bvh8_factory->BVH8Quad4v(this,BVH8Factory::BuildVariant::DYNAMIC,BVH8Factory::IntersectVariant::FAST)); break;
  256. case /*0b01*/ 1: accels.add(device->bvh8_factory->BVH8Quad4v(this,BVH8Factory::BuildVariant::DYNAMIC,BVH8Factory::IntersectVariant::ROBUST)); break;
  257. case /*0b10*/ 2: accels.add(device->bvh8_factory->BVH8Quad4v(this,BVH8Factory::BuildVariant::DYNAMIC,BVH8Factory::IntersectVariant::FAST)); break;
  258. case /*0b11*/ 3: accels.add(device->bvh8_factory->BVH8Quad4v(this,BVH8Factory::BuildVariant::DYNAMIC,BVH8Factory::IntersectVariant::ROBUST)); break;
  259. }
  260. }
  261. else
  262. #endif
  263. {
  264. int mode = 2*(int)isCompact() + 1*(int)isRobust();
  265. switch (mode) {
  266. case /*0b00*/ 0: accels.add(device->bvh4_factory->BVH4Quad4v(this,BVH4Factory::BuildVariant::DYNAMIC,BVH4Factory::IntersectVariant::FAST)); break;
  267. case /*0b01*/ 1: accels.add(device->bvh4_factory->BVH4Quad4v(this,BVH4Factory::BuildVariant::DYNAMIC,BVH4Factory::IntersectVariant::ROBUST)); break;
  268. case /*0b10*/ 2: accels.add(device->bvh4_factory->BVH4Quad4v(this,BVH4Factory::BuildVariant::DYNAMIC,BVH4Factory::IntersectVariant::FAST)); break;
  269. case /*0b11*/ 3: accels.add(device->bvh4_factory->BVH4Quad4v(this,BVH4Factory::BuildVariant::DYNAMIC,BVH4Factory::IntersectVariant::ROBUST)); break;
  270. }
  271. }
  272. }
  273. }
  274. else if (device->quad_accel == "bvh4.quad4v") accels.add(device->bvh4_factory->BVH4Quad4v(this));
  275. else if (device->quad_accel == "bvh4.quad4i") accels.add(device->bvh4_factory->BVH4Quad4i(this));
  276. else if (device->quad_accel == "qbvh4.quad4i") accels.add(device->bvh4_factory->BVH4QuantizedQuad4i(this));
  277. #if defined (__TARGET_AVX__)
  278. else if (device->quad_accel == "bvh8.quad4v") accels.add(device->bvh8_factory->BVH8Quad4v(this));
  279. else if (device->quad_accel == "bvh8.quad4i") accels.add(device->bvh8_factory->BVH8Quad4i(this));
  280. else if (device->quad_accel == "qbvh8.quad4i") accels.add(device->bvh8_factory->BVH8QuantizedQuad4i(this));
  281. #endif
  282. else throw_RTCError(RTC_INVALID_ARGUMENT,"unknown quad acceleration structure "+device->quad_accel);
  283. #endif
  284. }
  285. void Scene::createQuadMBAccel()
  286. {
  287. #if defined(EMBREE_GEOMETRY_QUADS)
  288. if (device->quad_accel_mb == "default")
  289. {
  290. int mode = 2*(int)isCompact() + 1*(int)isRobust();
  291. switch (mode) {
  292. case /*0b00*/ 0:
  293. #if defined (__TARGET_AVX__)
  294. if (device->hasISA(AVX))
  295. accels.add(device->bvh8_factory->BVH8Quad4iMB(this,BVH8Factory::BuildVariant::STATIC,BVH8Factory::IntersectVariant::FAST));
  296. else
  297. #endif
  298. accels.add(device->bvh4_factory->BVH4Quad4iMB(this,BVH4Factory::BuildVariant::STATIC,BVH4Factory::IntersectVariant::FAST));
  299. break;
  300. case /*0b01*/ 1:
  301. #if defined (__TARGET_AVX__)
  302. if (device->hasISA(AVX))
  303. accels.add(device->bvh8_factory->BVH8Quad4iMB(this,BVH8Factory::BuildVariant::STATIC,BVH8Factory::IntersectVariant::ROBUST));
  304. else
  305. #endif
  306. accels.add(device->bvh4_factory->BVH4Quad4iMB(this,BVH4Factory::BuildVariant::STATIC,BVH4Factory::IntersectVariant::ROBUST));
  307. break;
  308. case /*0b10*/ 2: accels.add(device->bvh4_factory->BVH4Quad4iMB(this,BVH4Factory::BuildVariant::STATIC,BVH4Factory::IntersectVariant::FAST )); break;
  309. case /*0b11*/ 3: accels.add(device->bvh4_factory->BVH4Quad4iMB(this,BVH4Factory::BuildVariant::STATIC,BVH4Factory::IntersectVariant::ROBUST)); break;
  310. }
  311. }
  312. else if (device->quad_accel_mb == "bvh4.quad4imb") accels.add(device->bvh4_factory->BVH4Quad4iMB(this));
  313. #if defined (__TARGET_AVX__)
  314. else if (device->quad_accel_mb == "bvh8.quad4imb") accels.add(device->bvh8_factory->BVH8Quad4iMB(this));
  315. #endif
  316. else throw_RTCError(RTC_INVALID_ARGUMENT,"unknown quad acceleration structure "+device->quad_accel_mb);
  317. #endif
  318. }
  319. void Scene::createHairAccel()
  320. {
  321. #if defined(EMBREE_GEOMETRY_HAIR)
  322. if (device->hair_accel == "default")
  323. {
  324. int mode = 2*(int)isCompact() + 1*(int)isRobust();
  325. if (isStatic())
  326. {
  327. #if defined (__TARGET_AVX__)
  328. if (device->hasISA(AVX2)) // only enable on HSW machines, for SNB this codepath is slower
  329. {
  330. switch (mode) {
  331. case /*0b00*/ 0: accels.add(device->bvh8_factory->BVH8OBBBezier1v(this)); break;
  332. case /*0b01*/ 1: accels.add(device->bvh8_factory->BVH8OBBBezier1v(this)); break;
  333. case /*0b10*/ 2: accels.add(device->bvh8_factory->BVH8OBBBezier1i(this)); break;
  334. case /*0b11*/ 3: accels.add(device->bvh8_factory->BVH8OBBBezier1i(this)); break;
  335. }
  336. }
  337. else
  338. #endif
  339. {
  340. switch (mode) {
  341. case /*0b00*/ 0: accels.add(device->bvh4_factory->BVH4OBBBezier1v(this)); break;
  342. case /*0b01*/ 1: accels.add(device->bvh4_factory->BVH4OBBBezier1v(this)); break;
  343. case /*0b10*/ 2: accels.add(device->bvh4_factory->BVH4OBBBezier1i(this)); break;
  344. case /*0b11*/ 3: accels.add(device->bvh4_factory->BVH4OBBBezier1i(this)); break;
  345. }
  346. }
  347. }
  348. else
  349. {
  350. switch (mode) {
  351. case /*0b00*/ 0: accels.add(device->bvh4_factory->BVH4Bezier1v(this)); break;
  352. case /*0b01*/ 1: accels.add(device->bvh4_factory->BVH4Bezier1v(this)); break;
  353. case /*0b10*/ 2: accels.add(device->bvh4_factory->BVH4Bezier1i(this)); break;
  354. case /*0b11*/ 3: accels.add(device->bvh4_factory->BVH4Bezier1i(this)); break;
  355. }
  356. }
  357. }
  358. else if (device->hair_accel == "bvh4.bezier1v" ) accels.add(device->bvh4_factory->BVH4Bezier1v(this));
  359. else if (device->hair_accel == "bvh4.bezier1i" ) accels.add(device->bvh4_factory->BVH4Bezier1i(this));
  360. else if (device->hair_accel == "bvh4obb.bezier1v" ) accels.add(device->bvh4_factory->BVH4OBBBezier1v(this));
  361. else if (device->hair_accel == "bvh4obb.bezier1i" ) accels.add(device->bvh4_factory->BVH4OBBBezier1i(this));
  362. #if defined (__TARGET_AVX__)
  363. else if (device->hair_accel == "bvh8obb.bezier1v" ) accels.add(device->bvh8_factory->BVH8OBBBezier1v(this));
  364. else if (device->hair_accel == "bvh8obb.bezier1i" ) accels.add(device->bvh8_factory->BVH8OBBBezier1i(this));
  365. #endif
  366. else throw_RTCError(RTC_INVALID_ARGUMENT,"unknown hair acceleration structure "+device->hair_accel);
  367. #endif
  368. }
  369. void Scene::createHairMBAccel()
  370. {
  371. #if defined(EMBREE_GEOMETRY_HAIR)
  372. if (device->hair_accel_mb == "default")
  373. {
  374. #if defined (__TARGET_AVX__)
  375. if (device->hasISA(AVX2)) // only enable on HSW machines, on SNB this codepath is slower
  376. {
  377. accels.add(device->bvh8_factory->BVH8OBBBezier1iMB(this));
  378. }
  379. else
  380. #endif
  381. {
  382. accels.add(device->bvh4_factory->BVH4OBBBezier1iMB(this));
  383. }
  384. }
  385. else if (device->hair_accel_mb == "bvh4obb.bezier1imb") accels.add(device->bvh4_factory->BVH4OBBBezier1iMB(this));
  386. #if defined (__TARGET_AVX__)
  387. else if (device->hair_accel_mb == "bvh8obb.bezier1imb") accels.add(device->bvh8_factory->BVH8OBBBezier1iMB(this));
  388. #endif
  389. else throw_RTCError(RTC_INVALID_ARGUMENT,"unknown motion blur hair acceleration structure "+device->tri_accel_mb);
  390. #endif
  391. }
  392. void Scene::createLineAccel()
  393. {
  394. #if defined(EMBREE_GEOMETRY_LINES)
  395. if (device->line_accel == "default")
  396. {
  397. if (isStatic())
  398. {
  399. #if defined (__TARGET_AVX__)
  400. if (device->hasISA(AVX) && !isCompact())
  401. accels.add(device->bvh8_factory->BVH8Line4i(this));
  402. else
  403. #endif
  404. accels.add(device->bvh4_factory->BVH4Line4i(this,BVH4Factory::BuildVariant::STATIC));
  405. }
  406. else
  407. {
  408. accels.add(device->bvh4_factory->BVH4Line4i(this,BVH4Factory::BuildVariant::DYNAMIC));
  409. }
  410. }
  411. else if (device->line_accel == "bvh4.line4i") accels.add(device->bvh4_factory->BVH4Line4i(this));
  412. #if defined (__TARGET_AVX__)
  413. else if (device->line_accel == "bvh8.line4i") accels.add(device->bvh8_factory->BVH8Line4i(this));
  414. #endif
  415. else throw_RTCError(RTC_INVALID_ARGUMENT,"unknown line segment acceleration structure "+device->line_accel);
  416. #endif
  417. }
  418. void Scene::createLineMBAccel()
  419. {
  420. #if defined(EMBREE_GEOMETRY_LINES)
  421. if (device->line_accel_mb == "default")
  422. {
  423. #if defined (__TARGET_AVX__)
  424. if (device->hasISA(AVX) && !isCompact())
  425. accels.add(device->bvh8_factory->BVH8Line4iMB(this));
  426. else
  427. #endif
  428. accels.add(device->bvh4_factory->BVH4Line4iMB(this));
  429. }
  430. else if (device->line_accel_mb == "bvh4.line4imb") accels.add(device->bvh4_factory->BVH4Line4iMB(this));
  431. #if defined (__TARGET_AVX__)
  432. else if (device->line_accel_mb == "bvh8.line4imb") accels.add(device->bvh8_factory->BVH8Line4iMB(this));
  433. #endif
  434. else throw_RTCError(RTC_INVALID_ARGUMENT,"unknown motion blur line segment acceleration structure "+device->line_accel_mb);
  435. #endif
  436. }
  437. void Scene::createSubdivAccel()
  438. {
  439. #if defined(EMBREE_GEOMETRY_SUBDIV)
  440. if (device->subdiv_accel == "default")
  441. {
  442. if (isIncoherent(flags) && isStatic())
  443. accels.add(device->bvh4_factory->BVH4SubdivPatch1Eager(this));
  444. else
  445. accels.add(device->bvh4_factory->BVH4SubdivPatch1(this,true));
  446. }
  447. else if (device->subdiv_accel == "bvh4.subdivpatch1eager" ) accels.add(device->bvh4_factory->BVH4SubdivPatch1Eager(this));
  448. else if (device->subdiv_accel == "bvh4.subdivpatch1" ) accels.add(device->bvh4_factory->BVH4SubdivPatch1(this,false));
  449. else if (device->subdiv_accel == "bvh4.subdivpatch1cached") accels.add(device->bvh4_factory->BVH4SubdivPatch1(this,true));
  450. else throw_RTCError(RTC_INVALID_ARGUMENT,"unknown subdiv accel "+device->subdiv_accel);
  451. #endif
  452. }
  453. void Scene::createSubdivMBAccel()
  454. {
  455. #if defined(EMBREE_GEOMETRY_SUBDIV)
  456. if (device->subdiv_accel_mb == "default")
  457. {
  458. if (isIncoherent(flags) && isStatic())
  459. accels.add(device->bvh4_factory->BVH4SubdivPatch1MBlur(this,false));
  460. else
  461. accels.add(device->bvh4_factory->BVH4SubdivPatch1MBlur(this,true));
  462. }
  463. else if (device->subdiv_accel_mb == "bvh4.subdivpatch1" ) accels.add(device->bvh4_factory->BVH4SubdivPatch1MBlur(this,false));
  464. else if (device->subdiv_accel_mb == "bvh4.subdivpatch1cached") accels.add(device->bvh4_factory->BVH4SubdivPatch1MBlur(this,true));
  465. else throw_RTCError(RTC_INVALID_ARGUMENT,"unknown subdiv mblur accel "+device->subdiv_accel_mb);
  466. #endif
  467. }
  468. void Scene::createUserGeometryAccel()
  469. {
  470. #if defined(EMBREE_GEOMETRY_USER)
  471. if (device->object_accel == "default")
  472. {
  473. if (isStatic()) {
  474. accels.add(device->bvh4_factory->BVH4UserGeometry(this,BVH4Factory::BuildVariant::STATIC));
  475. } else {
  476. accels.add(device->bvh4_factory->BVH4UserGeometry(this,BVH4Factory::BuildVariant::DYNAMIC));
  477. }
  478. }
  479. else if (device->object_accel == "bvh4.object") accels.add(device->bvh4_factory->BVH4UserGeometry(this));
  480. else throw_RTCError(RTC_INVALID_ARGUMENT,"unknown user geometry accel "+device->object_accel);
  481. #endif
  482. }
  483. void Scene::createUserGeometryMBAccel()
  484. {
  485. #if defined(EMBREE_GEOMETRY_USER)
  486. accels.add(device->bvh4_factory->BVH4UserGeometryMB(this));
  487. #endif
  488. }
  489. Scene::~Scene ()
  490. {
  491. for (size_t i=0; i<geometries.size(); i++)
  492. delete geometries[i];
  493. #if defined(TASKING_TBB) || defined(TASKING_PPL)
  494. delete group; group = nullptr;
  495. #endif
  496. }
  497. void Scene::clear() {
  498. }
  499. #if defined(EMBREE_GEOMETRY_USER)
  500. unsigned Scene::newUserGeometry (RTCGeometryFlags gflags, size_t items, size_t numTimeSteps)
  501. {
  502. if (isStatic() && (gflags != RTC_GEOMETRY_STATIC)) {
  503. throw_RTCError(RTC_INVALID_OPERATION,"static scenes can only contain static geometries");
  504. return -1;
  505. }
  506. if (numTimeSteps == 0 || numTimeSteps > RTC_MAX_TIME_STEPS) {
  507. throw_RTCError(RTC_INVALID_OPERATION,"maximal number of timesteps exceeded");
  508. return -1;
  509. }
  510. return add(new UserGeometry(this,gflags,items,numTimeSteps));
  511. }
  512. unsigned Scene::newInstance (Scene* scene, size_t numTimeSteps)
  513. {
  514. if (numTimeSteps == 0 || numTimeSteps > RTC_MAX_TIME_STEPS) {
  515. throw_RTCError(RTC_INVALID_OPERATION,"maximal number of timesteps exceeded");
  516. return -1;
  517. }
  518. return add(Instance::create(this,scene,numTimeSteps));
  519. }
  520. #endif
  521. unsigned Scene::newGeometryInstance (Geometry* geom_in)
  522. {
  523. Geometry* geom = new GeometryInstance(this,geom_in);
  524. unsigned id = add(geom);
  525. geom->id = id;
  526. return id;
  527. }
  528. #if defined(EMBREE_GEOMETRY_TRIANGLES)
  529. unsigned Scene::newTriangleMesh (RTCGeometryFlags gflags, size_t numTriangles, size_t numVertices, size_t numTimeSteps)
  530. {
  531. if (isStatic() && (gflags != RTC_GEOMETRY_STATIC)) {
  532. throw_RTCError(RTC_INVALID_OPERATION,"static scenes can only contain static geometries");
  533. return -1;
  534. }
  535. if (numTimeSteps == 0 || numTimeSteps > RTC_MAX_TIME_STEPS) {
  536. throw_RTCError(RTC_INVALID_OPERATION,"maximal number of timesteps exceeded");
  537. return -1;
  538. }
  539. return add(new TriangleMesh(this,gflags,numTriangles,numVertices,numTimeSteps));
  540. }
  541. #endif
  542. #if defined(EMBREE_GEOMETRY_QUADS)
  543. unsigned Scene::newQuadMesh (RTCGeometryFlags gflags, size_t numQuads, size_t numVertices, size_t numTimeSteps)
  544. {
  545. if (isStatic() && (gflags != RTC_GEOMETRY_STATIC)) {
  546. throw_RTCError(RTC_INVALID_OPERATION,"static scenes can only contain static geometries");
  547. return -1;
  548. }
  549. if (numTimeSteps == 0 || numTimeSteps > RTC_MAX_TIME_STEPS) {
  550. throw_RTCError(RTC_INVALID_OPERATION,"maximal number of timesteps exceeded");
  551. return -1;
  552. }
  553. return add(new QuadMesh(this,gflags,numQuads,numVertices,numTimeSteps));
  554. }
  555. #endif
  556. #if defined(EMBREE_GEOMETRY_SUBDIV)
  557. unsigned Scene::newSubdivisionMesh (RTCGeometryFlags gflags, size_t numFaces, size_t numEdges, size_t numVertices, size_t numEdgeCreases, size_t numVertexCreases, size_t numHoles, size_t numTimeSteps)
  558. {
  559. if (isStatic() && (gflags != RTC_GEOMETRY_STATIC)) {
  560. throw_RTCError(RTC_INVALID_OPERATION,"static scenes can only contain static geometries");
  561. return -1;
  562. }
  563. if (numTimeSteps == 0 || numTimeSteps > RTC_MAX_TIME_STEPS) {
  564. throw_RTCError(RTC_INVALID_OPERATION,"maximal number of timesteps exceeded");
  565. return -1;
  566. }
  567. #if defined(__TARGET_AVX__)
  568. if (device->hasISA(AVX))
  569. return add(new SubdivMeshAVX(this,gflags,numFaces,numEdges,numVertices,numEdgeCreases,numVertexCreases,numHoles,numTimeSteps));
  570. else
  571. #endif
  572. return add(new SubdivMesh(this,gflags,numFaces,numEdges,numVertices,numEdgeCreases,numVertexCreases,numHoles,numTimeSteps));
  573. }
  574. #endif
  575. #if defined(EMBREE_GEOMETRY_HAIR)
  576. unsigned Scene::newCurves (NativeCurves::SubType subtype, NativeCurves::Basis basis, RTCGeometryFlags gflags, size_t numCurves, size_t numVertices, size_t numTimeSteps)
  577. {
  578. if (isStatic() && (gflags != RTC_GEOMETRY_STATIC)) {
  579. throw_RTCError(RTC_INVALID_OPERATION,"static scenes can only contain static geometries");
  580. return -1;
  581. }
  582. if (numTimeSteps == 0 || numTimeSteps > RTC_MAX_TIME_STEPS) {
  583. throw_RTCError(RTC_INVALID_OPERATION,"maximal number of timesteps exceeded");
  584. return -1;
  585. }
  586. Geometry* geom = nullptr;
  587. #if defined(EMBREE_NATIVE_CURVE_BSPLINE)
  588. switch (basis) {
  589. case NativeCurves::BEZIER : geom = new CurvesBezier(this,subtype,basis,gflags,numCurves,numVertices,numTimeSteps); break;
  590. case NativeCurves::BSPLINE: geom = new NativeCurves(this,subtype,basis,gflags,numCurves,numVertices,numTimeSteps); break;
  591. }
  592. #else
  593. switch (basis) {
  594. case NativeCurves::BEZIER : geom = new NativeCurves (this,subtype,basis,gflags,numCurves,numVertices,numTimeSteps); break;
  595. case NativeCurves::BSPLINE: geom = new CurvesBSpline(this,subtype,basis,gflags,numCurves,numVertices,numTimeSteps); break;
  596. }
  597. #endif
  598. return add(geom);
  599. }
  600. #endif
  601. #if defined(EMBREE_GEOMETRY_LINES)
  602. unsigned Scene::newLineSegments (RTCGeometryFlags gflags, size_t numSegments, size_t numVertices, size_t numTimeSteps)
  603. {
  604. if (isStatic() && (gflags != RTC_GEOMETRY_STATIC)) {
  605. throw_RTCError(RTC_INVALID_OPERATION,"static scenes can only contain static geometries");
  606. return -1;
  607. }
  608. if (numTimeSteps == 0 || numTimeSteps > RTC_MAX_TIME_STEPS) {
  609. throw_RTCError(RTC_INVALID_OPERATION,"maximal number of timesteps exceeded");
  610. return -1;
  611. }
  612. return add(new LineSegments(this,gflags,numSegments,numVertices,numTimeSteps));
  613. }
  614. #endif
  615. unsigned Scene::add(Geometry* geometry)
  616. {
  617. Lock<SpinLock> lock(geometriesMutex);
  618. unsigned id = id_pool.allocate();
  619. if (id >= geometries.size())
  620. geometries.resize(id+1);
  621. geometries[id] = geometry;
  622. geometry->id = id;
  623. return id;
  624. }
  625. void Scene::deleteGeometry(size_t geomID)
  626. {
  627. Lock<SpinLock> lock(geometriesMutex);
  628. if (isStatic())
  629. throw_RTCError(RTC_INVALID_OPERATION,"rtcDeleteGeometry cannot get called in static scenes");
  630. if (geomID >= geometries.size())
  631. throw_RTCError(RTC_INVALID_OPERATION,"invalid geometry ID");
  632. Geometry* geometry = geometries[geomID];
  633. if (geometry == nullptr)
  634. throw_RTCError(RTC_INVALID_OPERATION,"invalid geometry");
  635. geometry->disable();
  636. accels.deleteGeometry(unsigned(geomID));
  637. id_pool.deallocate((unsigned)geomID);
  638. geometries[geomID] = nullptr;
  639. delete geometry;
  640. }
  641. void Scene::updateInterface()
  642. {
  643. /* update bounds */
  644. is_build = true;
  645. bounds = accels.bounds;
  646. intersectors = accels.intersectors;
  647. /* enable only algorithms choosen by application */
  648. if ((aflags & RTC_INTERSECT_STREAM) == 0)
  649. {
  650. intersectors.intersectorN = Accel::IntersectorN(&invalid_rtcIntersectN);
  651. if ((aflags & RTC_INTERSECT1) == 0) intersectors.intersector1 = Accel::Intersector1(&invalid_rtcIntersect1);
  652. if ((aflags & RTC_INTERSECT4) == 0) intersectors.intersector4 = Accel::Intersector4(&invalid_rtcIntersect4);
  653. if ((aflags & RTC_INTERSECT8) == 0) intersectors.intersector8 = Accel::Intersector8(&invalid_rtcIntersect8);
  654. if ((aflags & RTC_INTERSECT16) == 0) intersectors.intersector16 = Accel::Intersector16(&invalid_rtcIntersect16);
  655. }
  656. }
  657. void Scene::commit_task ()
  658. {
  659. progress_monitor_counter = 0;
  660. /* call preCommit function of each geometry */
  661. parallel_for(geometries.size(), [&] ( const size_t i ) {
  662. if (geometries[i]) geometries[i]->preCommit();
  663. });
  664. /* select fast code path if no intersection filter is present */
  665. accels.select(numIntersectionFiltersN+numIntersectionFilters4,
  666. numIntersectionFiltersN+numIntersectionFilters8,
  667. numIntersectionFiltersN+numIntersectionFilters16,
  668. numIntersectionFiltersN);
  669. /* build all hierarchies of this scene */
  670. accels.build();
  671. /* make static geometry immutable */
  672. if (isStatic()) accels.immutable();
  673. /* call postCommit function of each geometry */
  674. parallel_for(geometries.size(), [&] ( const size_t i ) {
  675. if (geometries[i]) geometries[i]->postCommit();
  676. });
  677. updateInterface();
  678. if (device->verbosity(2)) {
  679. std::cout << "created scene intersector" << std::endl;
  680. accels.print(2);
  681. std::cout << "selected scene intersector" << std::endl;
  682. intersectors.print(2);
  683. }
  684. setModified(false);
  685. }
  686. #if defined(TASKING_INTERNAL)
  687. void Scene::commit (size_t threadIndex, size_t threadCount, bool useThreadPool)
  688. {
  689. Lock<MutexSys> buildLock(buildMutex,false);
  690. /* allocates own taskscheduler for each build */
  691. Ref<TaskScheduler> scheduler = nullptr;
  692. {
  693. Lock<MutexSys> lock(schedulerMutex);
  694. scheduler = this->scheduler;
  695. if (scheduler == null) {
  696. buildLock.lock();
  697. this->scheduler = scheduler = new TaskScheduler;
  698. }
  699. }
  700. /* worker threads join build */
  701. if (!buildLock.isLocked()) {
  702. scheduler->join();
  703. return;
  704. }
  705. /* wait for all threads in rtcCommitThread mode */
  706. if (threadCount != 0)
  707. scheduler->wait_for_threads(threadCount);
  708. /* fast path for unchanged scenes */
  709. if (!isModified()) {
  710. scheduler->spawn_root([&]() { this->scheduler = nullptr; }, 1, useThreadPool);
  711. return;
  712. }
  713. /* report error if scene not ready */
  714. if (!ready()) {
  715. scheduler->spawn_root([&]() { this->scheduler = nullptr; }, 1, useThreadPool);
  716. throw_RTCError(RTC_INVALID_OPERATION,"not all buffers are unmapped");
  717. }
  718. /* initiate build */
  719. try {
  720. scheduler->spawn_root([&]() { commit_task(); this->scheduler = nullptr; }, 1, useThreadPool);
  721. }
  722. catch (...) {
  723. accels.clear();
  724. updateInterface();
  725. throw;
  726. }
  727. }
  728. #endif
  729. #if defined(TASKING_TBB) || defined(TASKING_PPL)
  730. void Scene::commit (size_t threadIndex, size_t threadCount, bool useThreadPool)
  731. {
  732. /* let threads wait for build to finish in rtcCommitThread mode */
  733. if (threadCount != 0) {
  734. #if defined(TASKING_TBB) && (TBB_INTERFACE_VERSION_MAJOR < 8)
  735. throw_RTCError(RTC_INVALID_OPERATION,"rtcCommitThread not supported");
  736. #endif
  737. if (threadIndex > 0) {
  738. group_barrier.wait(threadCount); // FIXME: use barrier that waits in condition
  739. group->wait();
  740. return;
  741. }
  742. }
  743. /* try to obtain build lock */
  744. Lock<MutexSys> lock(buildMutex,buildMutex.try_lock());
  745. /* join hierarchy build */
  746. if (!lock.isLocked()) {
  747. #if defined(TASKING_TBB) && (TBB_INTERFACE_VERSION_MAJOR < 8)
  748. throw_RTCError(RTC_INVALID_OPERATION,"join not supported");
  749. #endif
  750. #if USE_TASK_ARENA
  751. device->arena->execute([&]{ group->wait(); });
  752. #else
  753. group->wait();
  754. #endif
  755. while (!buildMutex.try_lock()) {
  756. __pause_cpu();
  757. yield();
  758. #if USE_TASK_ARENA
  759. device->arena->execute([&]{ group->wait(); });
  760. #else
  761. group->wait();
  762. #endif
  763. }
  764. buildMutex.unlock();
  765. return;
  766. }
  767. if (!isModified()) {
  768. if (threadCount) group_barrier.wait(threadCount);
  769. return;
  770. }
  771. if (!ready()) {
  772. if (threadCount) group_barrier.wait(threadCount);
  773. throw_RTCError(RTC_INVALID_OPERATION,"not all buffers are unmapped");
  774. return;
  775. }
  776. /* for best performance set FTZ and DAZ flags in the MXCSR control and status register */
  777. unsigned int mxcsr = _mm_getcsr();
  778. _mm_setcsr(mxcsr | /* FTZ */ (1<<15) | /* DAZ */ (1<<6));
  779. try {
  780. #if defined(TASKING_TBB)
  781. #if TBB_INTERFACE_VERSION_MAJOR < 8
  782. tbb::task_group_context ctx( tbb::task_group_context::isolated, tbb::task_group_context::default_traits);
  783. #else
  784. tbb::task_group_context ctx( tbb::task_group_context::isolated, tbb::task_group_context::default_traits | tbb::task_group_context::fp_settings );
  785. #endif
  786. //ctx.set_priority(tbb::priority_high);
  787. #if USE_TASK_ARENA
  788. device->arena->execute([&]{
  789. #endif
  790. group->run([&]{
  791. tbb::parallel_for (size_t(0), size_t(1), size_t(1), [&] (size_t) { commit_task(); }, ctx);
  792. });
  793. if (threadCount) group_barrier.wait(threadCount);
  794. group->wait();
  795. #if USE_TASK_ARENA
  796. });
  797. #endif
  798. /* reset MXCSR register again */
  799. _mm_setcsr(mxcsr);
  800. #else
  801. group->run([&]{
  802. concurrency::parallel_for(size_t(0), size_t(1), size_t(1), [&](size_t) { commit_task(); });
  803. });
  804. if (threadCount) group_barrier.wait(threadCount);
  805. group->wait();
  806. #endif
  807. }
  808. catch (...) {
  809. /* reset MXCSR register again */
  810. _mm_setcsr(mxcsr);
  811. accels.clear();
  812. updateInterface();
  813. throw;
  814. }
  815. }
  816. #endif
  817. void Scene::setProgressMonitorFunction(RTCProgressMonitorFunc func, void* ptr)
  818. {
  819. static MutexSys mutex;
  820. mutex.lock();
  821. progress_monitor_function = func;
  822. progress_monitor_ptr = ptr;
  823. mutex.unlock();
  824. }
  825. void Scene::progressMonitor(double dn)
  826. {
  827. if (progress_monitor_function) {
  828. size_t n = size_t(dn) + progress_monitor_counter.fetch_add(size_t(dn));
  829. if (!progress_monitor_function(progress_monitor_ptr, n / (double(numPrimitives())))) {
  830. throw_RTCError(RTC_CANCELLED,"progress monitor forced termination");
  831. }
  832. }
  833. }
  834. }