rtcore.cpp 86 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415
  1. // Copyright 2009-2021 Intel Corporation
  2. // SPDX-License-Identifier: Apache-2.0
  3. #define RTC_EXPORT_API
  4. #include "default.h"
  5. #include "device.h"
  6. #include "scene.h"
  7. #include "context.h"
  8. #include "../geometry/filter.h"
  9. #include "../../include/embree4/rtcore_ray.h"
  10. using namespace embree;
  11. RTC_NAMESPACE_BEGIN;
  12. #define RTC_ENTER_DEVICE(arg) \
  13. DeviceEnterLeave enterleave(arg);
  14. /* mutex to make API thread safe */
  15. static MutexSys g_mutex;
  16. RTC_API RTCDevice rtcNewDevice(const char* config)
  17. {
  18. RTC_CATCH_BEGIN;
  19. RTC_TRACE(rtcNewDevice);
  20. Lock<MutexSys> lock(g_mutex);
  21. Device* device = new Device(config);
  22. return (RTCDevice) device->refInc();
  23. RTC_CATCH_END(nullptr);
  24. return (RTCDevice) nullptr;
  25. }
  26. #if defined(EMBREE_SYCL_SUPPORT)
  27. RTC_API RTCDevice rtcNewSYCLDeviceInternal(sycl::context sycl_context, const char* config)
  28. {
  29. RTC_CATCH_BEGIN;
  30. RTC_TRACE(rtcNewSYCLDevice);
  31. Lock<MutexSys> lock(g_mutex);
  32. DeviceGPU* device = new DeviceGPU(sycl_context,config);
  33. return (RTCDevice) device->refInc();
  34. RTC_CATCH_END(nullptr);
  35. return (RTCDevice) nullptr;
  36. }
  37. RTC_API bool rtcIsSYCLDeviceSupported(const sycl::device device)
  38. {
  39. try {
  40. RTC_TRACE(rtcIsSYCLDeviceSupported);
  41. return rthwifIsSYCLDeviceSupported(device) > 0;
  42. } catch (...) {
  43. return false;
  44. }
  45. return false;
  46. }
  47. RTC_API int rtcSYCLDeviceSelector(const sycl::device device)
  48. {
  49. try {
  50. RTC_TRACE(rtcSYCLDeviceSelector);
  51. return rthwifIsSYCLDeviceSupported(device);
  52. } catch (...) {
  53. return -1;
  54. }
  55. return -1;
  56. }
  57. RTC_API void rtcSetDeviceSYCLDevice(RTCDevice hdevice, const sycl::device sycl_device)
  58. {
  59. RTC_CATCH_BEGIN;
  60. RTC_TRACE(rtcSetDeviceSYCLDevice);
  61. RTC_VERIFY_HANDLE(hdevice);
  62. Lock<MutexSys> lock(g_mutex);
  63. DeviceGPU* device = dynamic_cast<DeviceGPU*>((Device*) hdevice);
  64. if (device == nullptr)
  65. throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "passed device must be an Embree SYCL device")
  66. device->setSYCLDevice(sycl_device);
  67. RTC_CATCH_END(nullptr);
  68. }
  69. RTC_API_CPP sycl::event rtcCommitSceneWithQueue (RTCScene hscene, sycl::queue queue)
  70. {
  71. Scene* scene = (Scene*) hscene;
  72. RTC_CATCH_BEGIN;
  73. RTC_TRACE(rtcCommitSceneWithQueue);
  74. RTC_VERIFY_HANDLE(hscene);
  75. RTC_ENTER_DEVICE(hscene);
  76. return scene->commit(false, queue);
  77. RTC_CATCH_END2(scene);
  78. return sycl::event();
  79. }
  80. RTC_API_CPP sycl::event rtcCommitBufferWithQueue(RTCBuffer hbuffer, sycl::queue queue) {
  81. Buffer* buffer = (Buffer*)hbuffer;
  82. RTC_CATCH_BEGIN;
  83. RTC_TRACE(rtcCommitBufferWithQueue);
  84. RTC_VERIFY_HANDLE(hbuffer);
  85. RTC_ENTER_DEVICE(hbuffer);
  86. return buffer->commit(queue);
  87. RTC_CATCH_END2(buffer);
  88. return sycl::event();
  89. }
  90. #endif
  91. RTC_API void rtcRetainDevice(RTCDevice hdevice)
  92. {
  93. Device* device = (Device*) hdevice;
  94. RTC_CATCH_BEGIN;
  95. RTC_TRACE(rtcRetainDevice);
  96. RTC_VERIFY_HANDLE(hdevice);
  97. Lock<MutexSys> lock(g_mutex);
  98. device->refInc();
  99. RTC_CATCH_END(nullptr);
  100. }
  101. RTC_API void rtcReleaseDevice(RTCDevice hdevice)
  102. {
  103. Device* device = (Device*) hdevice;
  104. RTC_CATCH_BEGIN;
  105. RTC_TRACE(rtcReleaseDevice);
  106. RTC_VERIFY_HANDLE(hdevice);
  107. Lock<MutexSys> lock(g_mutex);
  108. device->refDec();
  109. RTC_CATCH_END(nullptr);
  110. }
  111. RTC_API ssize_t rtcGetDeviceProperty(RTCDevice hdevice, RTCDeviceProperty prop)
  112. {
  113. Device* device = (Device*) hdevice;
  114. RTC_CATCH_BEGIN;
  115. RTC_TRACE(rtcGetDeviceProperty);
  116. RTC_VERIFY_HANDLE(hdevice);
  117. Lock<MutexSys> lock(g_mutex);
  118. return device->getProperty(prop);
  119. RTC_CATCH_END(device);
  120. return 0;
  121. }
  122. RTC_API void rtcSetDeviceProperty(RTCDevice hdevice, const RTCDeviceProperty prop, ssize_t val)
  123. {
  124. Device* device = (Device*) hdevice;
  125. RTC_CATCH_BEGIN;
  126. RTC_TRACE(rtcSetDeviceProperty);
  127. const bool internal_prop = (size_t)prop >= 1000000 && (size_t)prop < 1000004;
  128. if (!internal_prop) RTC_VERIFY_HANDLE(hdevice); // allow NULL device for special internal settings
  129. Lock<MutexSys> lock(g_mutex);
  130. device->setProperty(prop,val);
  131. RTC_CATCH_END(device);
  132. }
  133. RTC_API RTCError rtcGetDeviceError(RTCDevice hdevice)
  134. {
  135. Device* device = (Device*) hdevice;
  136. RTC_CATCH_BEGIN;
  137. RTC_TRACE(rtcGetDeviceError);
  138. if (device == nullptr) return Device::getThreadErrorCode();
  139. else return device->getDeviceErrorCode();
  140. RTC_CATCH_END(device);
  141. return RTC_ERROR_UNKNOWN;
  142. }
  143. RTC_API const char* rtcGetDeviceLastErrorMessage(RTCDevice hdevice)
  144. {
  145. Device* device = (Device*) hdevice;
  146. RTC_CATCH_BEGIN;
  147. RTC_TRACE(rtcGetDeviceLastErrorMessage);
  148. if (device == nullptr) return Device::getThreadLastErrorMessage();
  149. else return device->getDeviceLastErrorMessage();
  150. RTC_CATCH_END(device);
  151. return "";
  152. }
  153. RTC_API void rtcSetDeviceErrorFunction(RTCDevice hdevice, RTCErrorFunction error, void* userPtr)
  154. {
  155. Device* device = (Device*) hdevice;
  156. RTC_CATCH_BEGIN;
  157. RTC_TRACE(rtcSetDeviceErrorFunction);
  158. RTC_VERIFY_HANDLE(hdevice);
  159. device->setErrorFunction(error, userPtr);
  160. RTC_CATCH_END(device);
  161. }
  162. RTC_API void rtcSetDeviceMemoryMonitorFunction(RTCDevice hdevice, RTCMemoryMonitorFunction memoryMonitor, void* userPtr)
  163. {
  164. Device* device = (Device*) hdevice;
  165. RTC_CATCH_BEGIN;
  166. RTC_TRACE(rtcSetDeviceMemoryMonitorFunction);
  167. device->setMemoryMonitorFunction(memoryMonitor, userPtr);
  168. RTC_CATCH_END(device);
  169. }
  170. RTC_API RTCBuffer rtcNewBuffer(RTCDevice hdevice, size_t byteSize)
  171. {
  172. RTC_CATCH_BEGIN;
  173. RTC_TRACE(rtcNewBuffer);
  174. RTC_VERIFY_HANDLE(hdevice);
  175. RTC_ENTER_DEVICE(hdevice);
  176. Buffer* buffer = new Buffer((Device*)hdevice, byteSize, nullptr);
  177. return (RTCBuffer)buffer->refInc();
  178. RTC_CATCH_END((Device*)hdevice);
  179. return nullptr;
  180. }
  181. RTC_API RTCBuffer rtcNewBufferHostDevice(RTCDevice hdevice, size_t byteSize)
  182. {
  183. RTC_CATCH_BEGIN;
  184. RTC_TRACE(rtcNewBufferHostDevice);
  185. RTC_VERIFY_HANDLE(hdevice);
  186. RTC_ENTER_DEVICE(hdevice);
  187. Buffer* buffer = new Buffer((Device*)hdevice, byteSize, nullptr, nullptr);
  188. return (RTCBuffer)buffer->refInc();
  189. RTC_CATCH_END((Device*)hdevice);
  190. return nullptr;
  191. }
  192. RTC_API RTCBuffer rtcNewSharedBuffer(RTCDevice hdevice, void* ptr, size_t byteSize)
  193. {
  194. RTC_CATCH_BEGIN;
  195. RTC_TRACE(rtcNewSharedBuffer);
  196. RTC_VERIFY_HANDLE(hdevice);
  197. RTC_ENTER_DEVICE(hdevice);
  198. Buffer* buffer = new Buffer((Device*)hdevice, byteSize, ptr);
  199. return (RTCBuffer)buffer->refInc();
  200. RTC_CATCH_END((Device*)hdevice);
  201. return nullptr;
  202. }
  203. RTC_API RTCBuffer rtcNewSharedBufferHostDevice(RTCDevice hdevice, void* ptr, size_t byteSize)
  204. {
  205. RTC_CATCH_BEGIN;
  206. RTC_TRACE(rtcNewSharedBufferHostDevice);
  207. RTC_VERIFY_HANDLE(hdevice);
  208. RTC_ENTER_DEVICE(hdevice);
  209. Buffer* buffer = new Buffer((Device*)hdevice, byteSize, ptr, nullptr);
  210. return (RTCBuffer)buffer->refInc();
  211. RTC_CATCH_END((Device*)hdevice);
  212. return nullptr;
  213. }
  214. RTC_API void* rtcGetBufferDataDevice(RTCBuffer hbuffer)
  215. {
  216. Buffer* buffer = (Buffer*)hbuffer;
  217. RTC_CATCH_BEGIN;
  218. RTC_TRACE(rtcGetBufferDataDevice);
  219. RTC_VERIFY_HANDLE(hbuffer);
  220. RTC_ENTER_DEVICE(hbuffer);
  221. return buffer->dataDevice();
  222. RTC_CATCH_END2(buffer);
  223. return nullptr;
  224. }
  225. RTC_API void* rtcGetBufferData(RTCBuffer hbuffer)
  226. {
  227. Buffer* buffer = (Buffer*)hbuffer;
  228. RTC_CATCH_BEGIN;
  229. RTC_TRACE(rtcGetBufferData);
  230. RTC_VERIFY_HANDLE(hbuffer);
  231. RTC_ENTER_DEVICE(hbuffer);
  232. return buffer->data();
  233. RTC_CATCH_END2(buffer);
  234. return nullptr;
  235. }
  236. RTC_API void rtcRetainBuffer(RTCBuffer hbuffer)
  237. {
  238. Buffer* buffer = (Buffer*)hbuffer;
  239. RTC_CATCH_BEGIN;
  240. RTC_TRACE(rtcRetainBuffer);
  241. RTC_VERIFY_HANDLE(hbuffer);
  242. RTC_ENTER_DEVICE(hbuffer);
  243. buffer->refInc();
  244. RTC_CATCH_END2(buffer);
  245. }
  246. RTC_API void rtcReleaseBuffer(RTCBuffer hbuffer)
  247. {
  248. Buffer* buffer = (Buffer*)hbuffer;
  249. RTC_CATCH_BEGIN;
  250. RTC_TRACE(rtcReleaseBuffer);
  251. RTC_VERIFY_HANDLE(hbuffer);
  252. RTC_ENTER_DEVICE(hbuffer);
  253. buffer->refDec();
  254. RTC_CATCH_END2(buffer);
  255. }
  256. RTC_API void rtcCommitBuffer(RTCBuffer hbuffer) {
  257. Buffer* buffer = (Buffer*)hbuffer;
  258. RTC_CATCH_BEGIN;
  259. RTC_TRACE(rtcCommitBuffer);
  260. RTC_VERIFY_HANDLE(hbuffer);
  261. RTC_ENTER_DEVICE(hbuffer);
  262. buffer->commit();
  263. RTC_CATCH_END2(buffer);
  264. }
  265. RTC_API RTCScene rtcNewScene (RTCDevice hdevice)
  266. {
  267. RTC_CATCH_BEGIN;
  268. RTC_TRACE(rtcNewScene);
  269. RTC_VERIFY_HANDLE(hdevice);
  270. RTC_ENTER_DEVICE(hdevice);
  271. Scene* scene = new Scene((Device*)hdevice);
  272. return (RTCScene) scene->refInc();
  273. RTC_CATCH_END((Device*)hdevice);
  274. return nullptr;
  275. }
  276. RTC_API RTCDevice rtcGetSceneDevice(RTCScene hscene)
  277. {
  278. Scene* scene = (Scene*) hscene;
  279. RTC_CATCH_BEGIN;
  280. RTC_TRACE(rtcGetSceneDevice);
  281. RTC_VERIFY_HANDLE(hscene);
  282. return (RTCDevice)scene->device->refInc(); // user will own one additional device reference
  283. RTC_CATCH_END2(scene);
  284. return (RTCDevice)nullptr;
  285. }
  286. RTC_API RTCTraversable rtcGetSceneTraversable(RTCScene hscene)
  287. {
  288. Scene* scene = (Scene*) hscene;
  289. RTC_CATCH_BEGIN;
  290. RTC_TRACE(rtcGetSceneTraversable);
  291. RTC_VERIFY_HANDLE(hscene);
  292. RTCTraversable traversable = (RTCTraversable)scene->getTraversable();
  293. if (!traversable)
  294. throw_RTCError(RTC_ERROR_INVALID_OPERATION,"Traversable is NULL. The scene has to be committed first.");
  295. return traversable;
  296. RTC_CATCH_END2(scene);
  297. return (RTCTraversable)nullptr;
  298. }
  299. RTC_API void rtcSetSceneProgressMonitorFunction(RTCScene hscene, RTCProgressMonitorFunction progress, void* ptr)
  300. {
  301. Scene* scene = (Scene*) hscene;
  302. RTC_CATCH_BEGIN;
  303. RTC_TRACE(rtcSetSceneProgressMonitorFunction);
  304. RTC_VERIFY_HANDLE(hscene);
  305. RTC_ENTER_DEVICE(hscene);
  306. Lock<MutexSys> lock(g_mutex);
  307. scene->setProgressMonitorFunction(progress,ptr);
  308. RTC_CATCH_END2(scene);
  309. }
  310. RTC_API void rtcSetSceneBuildQuality (RTCScene hscene, RTCBuildQuality quality)
  311. {
  312. Scene* scene = (Scene*) hscene;
  313. RTC_CATCH_BEGIN;
  314. RTC_TRACE(rtcSetSceneBuildQuality);
  315. RTC_VERIFY_HANDLE(hscene);
  316. RTC_ENTER_DEVICE(hscene);
  317. if (quality != RTC_BUILD_QUALITY_LOW &&
  318. quality != RTC_BUILD_QUALITY_MEDIUM &&
  319. quality != RTC_BUILD_QUALITY_HIGH)
  320. abort(); //throw std::runtime_error("invalid build quality");
  321. scene->setBuildQuality(quality);
  322. RTC_CATCH_END2(scene);
  323. }
  324. RTC_API void rtcSetSceneFlags (RTCScene hscene, RTCSceneFlags flags)
  325. {
  326. Scene* scene = (Scene*) hscene;
  327. RTC_CATCH_BEGIN;
  328. RTC_TRACE(rtcSetSceneFlags);
  329. RTC_VERIFY_HANDLE(hscene);
  330. RTC_ENTER_DEVICE(hscene);
  331. scene->setSceneFlags(flags);
  332. RTC_CATCH_END2(scene);
  333. }
  334. RTC_API RTCSceneFlags rtcGetSceneFlags(RTCScene hscene)
  335. {
  336. Scene* scene = (Scene*) hscene;
  337. RTC_CATCH_BEGIN;
  338. RTC_TRACE(rtcGetSceneFlags);
  339. RTC_VERIFY_HANDLE(hscene);
  340. //RTC_ENTER_DEVICE(hscene);
  341. return scene->getSceneFlags();
  342. RTC_CATCH_END2(scene);
  343. return RTC_SCENE_FLAG_NONE;
  344. }
  345. RTC_API_EXTERN_C bool prefetchUSMSharedOnGPU(RTCScene scene);
  346. RTC_API void rtcCommitScene (RTCScene hscene)
  347. {
  348. Scene* scene = (Scene*) hscene;
  349. RTC_CATCH_BEGIN;
  350. RTC_TRACE(rtcCommitScene);
  351. RTC_VERIFY_HANDLE(hscene);
  352. RTC_ENTER_DEVICE(hscene);
  353. scene->commit(false);
  354. #if defined(EMBREE_SYCL_SUPPORT)
  355. //prefetchUSMSharedOnGPU(hscene);
  356. #endif
  357. RTC_CATCH_END2(scene);
  358. }
  359. RTC_API void rtcJoinCommitScene (RTCScene hscene)
  360. {
  361. Scene* scene = (Scene*) hscene;
  362. RTC_CATCH_BEGIN;
  363. RTC_TRACE(rtcJoinCommitScene);
  364. RTC_VERIFY_HANDLE(hscene);
  365. RTC_ENTER_DEVICE(hscene);
  366. scene->commit(true);
  367. RTC_CATCH_END2(scene);
  368. }
  369. RTC_API void rtcGetSceneBounds(RTCScene hscene, RTCBounds* bounds_o)
  370. {
  371. Scene* scene = (Scene*) hscene;
  372. RTC_CATCH_BEGIN;
  373. RTC_TRACE(rtcGetSceneBounds);
  374. RTC_VERIFY_HANDLE(hscene);
  375. RTC_ENTER_DEVICE(hscene);
  376. if (scene->isModified()) throw_RTCError(RTC_ERROR_INVALID_OPERATION,"scene not committed");
  377. BBox3fa bounds = scene->bounds.bounds();
  378. bounds_o->lower_x = bounds.lower.x;
  379. bounds_o->lower_y = bounds.lower.y;
  380. bounds_o->lower_z = bounds.lower.z;
  381. bounds_o->align0 = 0;
  382. bounds_o->upper_x = bounds.upper.x;
  383. bounds_o->upper_y = bounds.upper.y;
  384. bounds_o->upper_z = bounds.upper.z;
  385. bounds_o->align1 = 0;
  386. RTC_CATCH_END2(scene);
  387. }
  388. RTC_API void rtcGetSceneLinearBounds(RTCScene hscene, RTCLinearBounds* bounds_o)
  389. {
  390. Scene* scene = (Scene*) hscene;
  391. RTC_CATCH_BEGIN;
  392. RTC_TRACE(rtcGetSceneBounds);
  393. RTC_VERIFY_HANDLE(hscene);
  394. RTC_ENTER_DEVICE(hscene);
  395. if (bounds_o == nullptr)
  396. throw_RTCError(RTC_ERROR_INVALID_OPERATION,"invalid destination pointer");
  397. if (scene->isModified())
  398. throw_RTCError(RTC_ERROR_INVALID_OPERATION,"scene not committed");
  399. bounds_o->bounds0.lower_x = scene->bounds.bounds0.lower.x;
  400. bounds_o->bounds0.lower_y = scene->bounds.bounds0.lower.y;
  401. bounds_o->bounds0.lower_z = scene->bounds.bounds0.lower.z;
  402. bounds_o->bounds0.align0 = 0;
  403. bounds_o->bounds0.upper_x = scene->bounds.bounds0.upper.x;
  404. bounds_o->bounds0.upper_y = scene->bounds.bounds0.upper.y;
  405. bounds_o->bounds0.upper_z = scene->bounds.bounds0.upper.z;
  406. bounds_o->bounds0.align1 = 0;
  407. bounds_o->bounds1.lower_x = scene->bounds.bounds1.lower.x;
  408. bounds_o->bounds1.lower_y = scene->bounds.bounds1.lower.y;
  409. bounds_o->bounds1.lower_z = scene->bounds.bounds1.lower.z;
  410. bounds_o->bounds1.align0 = 0;
  411. bounds_o->bounds1.upper_x = scene->bounds.bounds1.upper.x;
  412. bounds_o->bounds1.upper_y = scene->bounds.bounds1.upper.y;
  413. bounds_o->bounds1.upper_z = scene->bounds.bounds1.upper.z;
  414. bounds_o->bounds1.align1 = 0;
  415. RTC_CATCH_END2(scene);
  416. }
  417. RTC_API void rtcCollide (RTCScene hscene0, RTCScene hscene1, RTCCollideFunc callback, void* userPtr)
  418. {
  419. Scene* scene0 = (Scene*) hscene0;
  420. Scene* scene1 = (Scene*) hscene1;
  421. RTC_CATCH_BEGIN;
  422. RTC_TRACE(rtcCollide);
  423. #if defined(DEBUG)
  424. RTC_VERIFY_HANDLE(hscene0);
  425. RTC_VERIFY_HANDLE(hscene1);
  426. if (scene0->isModified()) throw_RTCError(RTC_ERROR_INVALID_OPERATION,"scene got not committed");
  427. if (scene1->isModified()) throw_RTCError(RTC_ERROR_INVALID_OPERATION,"scene got not committed");
  428. if (scene0->device != scene1->device) throw_RTCError(RTC_ERROR_INVALID_OPERATION,"scenes are from different devices");
  429. auto nUserPrims0 = scene0->getNumPrimitives (Geometry::MTY_USER_GEOMETRY, false);
  430. auto nUserPrims1 = scene1->getNumPrimitives (Geometry::MTY_USER_GEOMETRY, false);
  431. if (scene0->numPrimitives() != nUserPrims0 && scene1->numPrimitives() != nUserPrims1) throw_RTCError(RTC_ERROR_INVALID_OPERATION,"scenes must only contain user geometries with a single timestep");
  432. #endif
  433. scene0->intersectors.collide(scene0,scene1,callback,userPtr);
  434. RTC_CATCH_END(scene0->device);
  435. }
  436. inline bool pointQuery(Scene* scene, RTCPointQuery* query, RTCPointQueryContext* userContext, RTCPointQueryFunction queryFunc, void* userPtr)
  437. {
  438. bool changed = false;
  439. if (userContext->instStackSize > 0)
  440. {
  441. const AffineSpace3fa transform = AffineSpace3fa_load_unaligned((AffineSpace3fa*)userContext->world2inst[userContext->instStackSize-1]);
  442. float similarityScale = 0.f;
  443. const bool similtude = similarityTransform(transform, &similarityScale);
  444. assert((similtude && similarityScale > 0) || (!similtude && similarityScale == 0.f));
  445. PointQuery query_inst;
  446. query_inst.p = xfmPoint(transform, Vec3fa(query->x, query->y, query->z));
  447. query_inst.radius = query->radius * similarityScale;
  448. query_inst.time = query->time;
  449. PointQueryContext context_inst(scene, (PointQuery*)query,
  450. similtude ? POINT_QUERY_TYPE_SPHERE : POINT_QUERY_TYPE_AABB,
  451. queryFunc, userContext, similarityScale, userPtr);
  452. changed = scene->intersectors.pointQuery((PointQuery*)&query_inst, &context_inst);
  453. }
  454. else
  455. {
  456. PointQueryContext context(scene, (PointQuery*)query,
  457. POINT_QUERY_TYPE_SPHERE, queryFunc, userContext, 1.f, userPtr);
  458. changed = scene->intersectors.pointQuery((PointQuery*)query, &context);
  459. }
  460. return changed;
  461. }
  462. RTC_API bool rtcPointQuery(RTCScene hscene, RTCPointQuery* query, RTCPointQueryContext* userContext, RTCPointQueryFunction queryFunc, void* userPtr)
  463. {
  464. Scene* scene = (Scene*) hscene;
  465. RTC_CATCH_BEGIN;
  466. RTC_TRACE(rtcPointQuery);
  467. #if defined(DEBUG)
  468. RTC_VERIFY_HANDLE(hscene);
  469. RTC_VERIFY_HANDLE(userContext);
  470. if (scene->isModified()) throw_RTCError(RTC_ERROR_INVALID_OPERATION,"scene got not committed");
  471. if (((size_t)query) & 0x0F) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "query not aligned to 16 bytes");
  472. if (((size_t)userContext) & 0x0F) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "context not aligned to 16 bytes");
  473. #endif
  474. return pointQuery(scene, query, userContext, queryFunc, userPtr);
  475. RTC_CATCH_END2_FALSE(scene);
  476. }
  477. RTC_API bool rtcPointQuery4 (const int* valid, RTCScene hscene, RTCPointQuery4* query, struct RTCPointQueryContext* userContext, RTCPointQueryFunction queryFunc, void** userPtrN)
  478. {
  479. Scene* scene = (Scene*) hscene;
  480. RTC_CATCH_BEGIN;
  481. RTC_TRACE(rtcPointQuery4);
  482. #if defined(DEBUG)
  483. RTC_VERIFY_HANDLE(hscene);
  484. if (scene->isModified()) throw_RTCError(RTC_ERROR_INVALID_OPERATION,"scene got not committed");
  485. if (((size_t)valid) & 0x0F) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "mask not aligned to 16 bytes");
  486. if (((size_t)query) & 0x0F) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "query not aligned to 16 bytes");
  487. #endif
  488. STAT(size_t cnt=0; for (size_t i=0; i<4; i++) cnt += ((int*)valid)[i] == -1;);
  489. STAT3(point_query.travs,cnt,cnt,cnt);
  490. bool changed = false;
  491. PointQuery4* query4 = (PointQuery4*)query;
  492. PointQuery query1;
  493. for (size_t i=0; i<4; i++) {
  494. if (!valid[i]) continue;
  495. query4->get(i,query1);
  496. changed |= pointQuery(scene, (RTCPointQuery*)&query1, userContext, queryFunc, userPtrN?userPtrN[i]:NULL);
  497. query4->set(i,query1);
  498. }
  499. return changed;
  500. RTC_CATCH_END2_FALSE(scene);
  501. }
  502. RTC_API bool rtcPointQuery8 (const int* valid, RTCScene hscene, RTCPointQuery8* query, struct RTCPointQueryContext* userContext, RTCPointQueryFunction queryFunc, void** userPtrN)
  503. {
  504. Scene* scene = (Scene*) hscene;
  505. RTC_CATCH_BEGIN;
  506. RTC_TRACE(rtcPointQuery8);
  507. #if defined(DEBUG)
  508. RTC_VERIFY_HANDLE(hscene);
  509. if (scene->isModified()) throw_RTCError(RTC_ERROR_INVALID_OPERATION,"scene got not committed");
  510. if (((size_t)valid) & 0x0F) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "mask not aligned to 16 bytes");
  511. if (((size_t)query) & 0x0F) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "query not aligned to 16 bytes");
  512. #endif
  513. STAT(size_t cnt=0; for (size_t i=0; i<4; i++) cnt += ((int*)valid)[i] == -1;);
  514. STAT3(point_query.travs,cnt,cnt,cnt);
  515. bool changed = false;
  516. PointQuery8* query8 = (PointQuery8*)query;
  517. PointQuery query1;
  518. for (size_t i=0; i<8; i++) {
  519. if (!valid[i]) continue;
  520. query8->get(i,query1);
  521. changed |= pointQuery(scene, (RTCPointQuery*)&query1, userContext, queryFunc, userPtrN?userPtrN[i]:NULL);
  522. query8->set(i,query1);
  523. }
  524. return changed;
  525. RTC_CATCH_END2_FALSE(scene);
  526. }
  527. RTC_API bool rtcPointQuery16 (const int* valid, RTCScene hscene, RTCPointQuery16* query, struct RTCPointQueryContext* userContext, RTCPointQueryFunction queryFunc, void** userPtrN)
  528. {
  529. Scene* scene = (Scene*) hscene;
  530. RTC_CATCH_BEGIN;
  531. RTC_TRACE(rtcPointQuery16);
  532. #if defined(DEBUG)
  533. RTC_VERIFY_HANDLE(hscene);
  534. if (scene->isModified()) throw_RTCError(RTC_ERROR_INVALID_OPERATION,"scene got not committed");
  535. if (((size_t)valid) & 0x0F) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "mask not aligned to 16 bytes");
  536. if (((size_t)query) & 0x0F) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "query not aligned to 16 bytes");
  537. #endif
  538. STAT(size_t cnt=0; for (size_t i=0; i<4; i++) cnt += ((int*)valid)[i] == -1;);
  539. STAT3(point_query.travs,cnt,cnt,cnt);
  540. bool changed = false;
  541. PointQuery16* query16 = (PointQuery16*)query;
  542. PointQuery query1;
  543. for (size_t i=0; i<16; i++) {
  544. if (!valid[i]) continue;
  545. PointQuery query1; query16->get(i,query1);
  546. changed |= pointQuery(scene, (RTCPointQuery*)&query1, userContext, queryFunc, userPtrN?userPtrN[i]:NULL);
  547. query16->set(i,query1);
  548. }
  549. return changed;
  550. RTC_CATCH_END2_FALSE(scene);
  551. }
  552. RTC_API void rtcIntersect1 (RTCScene hscene, RTCRayHit* rayhit, RTCIntersectArguments* args)
  553. {
  554. Scene* scene = (Scene*) hscene;
  555. RTC_CATCH_BEGIN;
  556. RTC_TRACE(rtcIntersect1);
  557. #if defined(DEBUG)
  558. RTC_VERIFY_HANDLE(hscene);
  559. if (scene->isModified()) throw_RTCError(RTC_ERROR_INVALID_OPERATION,"scene not committed");
  560. if (((size_t)rayhit) & 0x0F) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "ray not aligned to 16 bytes");
  561. #endif
  562. STAT3(normal.travs,1,1,1);
  563. RTCIntersectArguments defaultArgs;
  564. if (unlikely(args == nullptr)) {
  565. rtcInitIntersectArguments(&defaultArgs);
  566. args = &defaultArgs;
  567. }
  568. RTCRayQueryContext* user_context = args->context;
  569. RTCRayQueryContext defaultContext;
  570. if (unlikely(user_context == nullptr)) {
  571. rtcInitRayQueryContext(&defaultContext);
  572. user_context = &defaultContext;
  573. }
  574. RayQueryContext context(scene,user_context,args);
  575. scene->intersectors.intersect(*rayhit,&context);
  576. #if defined(DEBUG)
  577. ((RayHit*)rayhit)->verifyHit();
  578. #endif
  579. RTC_CATCH_END2(scene);
  580. }
  581. RTC_API void rtcForwardIntersect1 (const RTCIntersectFunctionNArguments* args, RTCScene hscene, RTCRay* iray_, unsigned int instID)
  582. {
  583. rtcForwardIntersect1Ex(args, hscene, iray_, instID, 0);
  584. }
  585. RTC_API void rtcForwardIntersect1Ex(const RTCIntersectFunctionNArguments* args, RTCScene hscene, RTCRay* iray_, unsigned int instID, unsigned int instPrimID)
  586. {
  587. Scene* scene = (Scene*) hscene;
  588. RTC_CATCH_BEGIN;
  589. RTC_TRACE(rtcForwardIntersect1Ex);
  590. #if defined(DEBUG)
  591. RTC_VERIFY_HANDLE(hscene);
  592. if (scene->isModified()) throw_RTCError(RTC_ERROR_INVALID_OPERATION,"scene not committed");
  593. if (((size_t)iray_) & 0x0F) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "ray not aligned to 16 bytes");
  594. #endif
  595. Ray* iray = (Ray*) iray_;
  596. RayHit* oray = (RayHit*)args->rayhit;
  597. RTCRayQueryContext* user_context = args->context;
  598. const Vec3ff ray_org_tnear = oray->org;
  599. const Vec3ff ray_dir_time = oray->dir;
  600. oray->org = iray->org;
  601. oray->dir = iray->dir;
  602. STAT3(normal.travs,1,1,1);
  603. RTCIntersectArguments* iargs = ((IntersectFunctionNArguments*) args)->args;
  604. RayQueryContext context(scene,user_context,iargs);
  605. instance_id_stack::push(user_context, instID, instPrimID);
  606. scene->intersectors.intersect(*(RTCRayHit*)oray,&context);
  607. instance_id_stack::pop(user_context);
  608. oray->org = ray_org_tnear;
  609. oray->dir = ray_dir_time;
  610. RTC_CATCH_END2(scene);
  611. }
  612. RTC_API void rtcIntersect4 (const int* valid, RTCScene hscene, RTCRayHit4* rayhit, RTCIntersectArguments* args)
  613. {
  614. Scene* scene = (Scene*) hscene;
  615. RTC_CATCH_BEGIN;
  616. RTC_TRACE(rtcIntersect4);
  617. #if defined(DEBUG)
  618. RTC_VERIFY_HANDLE(hscene);
  619. if (scene->isModified()) throw_RTCError(RTC_ERROR_INVALID_OPERATION,"scene not committed");
  620. if (((size_t)valid) & 0x0F) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "mask not aligned to 16 bytes");
  621. if (((size_t)rayhit) & 0x0F) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "rayhit not aligned to 16 bytes");
  622. #endif
  623. STAT(size_t cnt=0; for (size_t i=0; i<4; i++) cnt += ((int*)valid)[i] == -1;);
  624. STAT3(normal.travs,cnt,cnt,cnt);
  625. RTCIntersectArguments defaultArgs;
  626. if (unlikely(args == nullptr)) {
  627. rtcInitIntersectArguments(&defaultArgs);
  628. args = &defaultArgs;
  629. }
  630. RTCRayQueryContext* user_context = args->context;
  631. RTCRayQueryContext defaultContext;
  632. if (unlikely(user_context == nullptr)) {
  633. rtcInitRayQueryContext(&defaultContext);
  634. user_context = &defaultContext;
  635. }
  636. RayQueryContext context(scene,user_context,args);
  637. if (likely(scene->intersectors.intersector4))
  638. scene->intersectors.intersect4(valid,*rayhit,&context);
  639. else {
  640. RayHit4* ray4 = (RayHit4*) rayhit;
  641. for (size_t i=0; i<4; i++) {
  642. if (!valid[i]) continue;
  643. RayHit ray1; ray4->get(i,ray1);
  644. scene->intersectors.intersect((RTCRayHit&)ray1,&context);
  645. ray4->set(i,ray1);
  646. }
  647. }
  648. RTC_CATCH_END2(scene);
  649. }
  650. template<int N> void copy(float* dst, float* src);
  651. template<>
  652. __forceinline void copy<4>(float* dst, float* src) {
  653. vfloat4::storeu(&dst[0],vfloat4::loadu(&src[0]));
  654. }
  655. template<>
  656. __forceinline void copy<8>(float* dst, float* src) {
  657. vfloat4::storeu(&dst[0],vfloat4::loadu(&src[0]));
  658. vfloat4::storeu(&dst[4],vfloat4::loadu(&src[4]));
  659. }
  660. template<>
  661. __forceinline void copy<16>(float* dst, float* src) {
  662. vfloat4::storeu(&dst[0],vfloat4::loadu(&src[0]));
  663. vfloat4::storeu(&dst[4],vfloat4::loadu(&src[4]));
  664. vfloat4::storeu(&dst[8],vfloat4::loadu(&src[8]));
  665. vfloat4::storeu(&dst[12],vfloat4::loadu(&src[12]));
  666. }
  667. template<typename RTCRay, typename RTCRayHit, int N>
  668. __forceinline void rtcForwardIntersectN(const int* valid, const RTCIntersectFunctionNArguments* args, RTCScene hscene, RTCRay* iray, unsigned int instID, unsigned int instPrimID)
  669. {
  670. Scene* scene = (Scene*) hscene;
  671. RTCRayHit* oray = (RTCRayHit*)args->rayhit;
  672. RTCRayQueryContext* user_context = args->context;
  673. __aligned(16) float ray_org_x[N];
  674. __aligned(16) float ray_org_y[N];
  675. __aligned(16) float ray_org_z[N];
  676. __aligned(16) float ray_dir_x[N];
  677. __aligned(16) float ray_dir_y[N];
  678. __aligned(16) float ray_dir_z[N];
  679. copy<N>(ray_org_x,oray->ray.org_x);
  680. copy<N>(ray_org_y,oray->ray.org_y);
  681. copy<N>(ray_org_z,oray->ray.org_z);
  682. copy<N>(ray_dir_x,oray->ray.dir_x);
  683. copy<N>(ray_dir_y,oray->ray.dir_y);
  684. copy<N>(ray_dir_z,oray->ray.dir_z);
  685. copy<N>(oray->ray.org_x,iray->org_x);
  686. copy<N>(oray->ray.org_y,iray->org_y);
  687. copy<N>(oray->ray.org_z,iray->org_z);
  688. copy<N>(oray->ray.dir_x,iray->dir_x);
  689. copy<N>(oray->ray.dir_y,iray->dir_y);
  690. copy<N>(oray->ray.dir_z,iray->dir_z);
  691. STAT(size_t cnt=0; for (size_t i=0; i<N; i++) cnt += ((int*)valid)[i] == -1;);
  692. STAT3(normal.travs,cnt,cnt,cnt);
  693. RTCIntersectArguments* iargs = ((IntersectFunctionNArguments*) args)->args;
  694. RayQueryContext context(scene,user_context,iargs);
  695. instance_id_stack::push(user_context, instID, instPrimID);
  696. scene->intersectors.intersect(valid,*oray,&context);
  697. instance_id_stack::pop(user_context);
  698. copy<N>(oray->ray.org_x,ray_org_x);
  699. copy<N>(oray->ray.org_y,ray_org_y);
  700. copy<N>(oray->ray.org_z,ray_org_z);
  701. copy<N>(oray->ray.dir_x,ray_dir_x);
  702. copy<N>(oray->ray.dir_y,ray_dir_y);
  703. copy<N>(oray->ray.dir_z,ray_dir_z);
  704. }
  705. RTC_API void rtcForwardIntersect4(const int* valid, const RTCIntersectFunctionNArguments* args, RTCScene hscene, RTCRay4* iray, unsigned int instID)
  706. {
  707. RTC_TRACE(rtcForwardIntersect4);
  708. return rtcForwardIntersect4Ex(valid, args, hscene, iray, instID, 0);
  709. }
  710. RTC_API void rtcForwardIntersect4Ex(const int* valid, const RTCIntersectFunctionNArguments* args, RTCScene hscene, RTCRay4* iray, unsigned int instID, unsigned int instPrimID)
  711. {
  712. Scene* scene = (Scene*) hscene;
  713. RTC_CATCH_BEGIN;
  714. RTC_TRACE(rtcForwardIntersect4);
  715. rtcForwardIntersectN<RTCRay4,RTCRayHit4,4>(valid,args,hscene,iray,instID,instPrimID);
  716. RTC_CATCH_END2(scene);
  717. }
  718. RTC_API void rtcIntersect8 (const int* valid, RTCScene hscene, RTCRayHit8* rayhit, RTCIntersectArguments* args)
  719. {
  720. Scene* scene = (Scene*) hscene;
  721. RTC_CATCH_BEGIN;
  722. RTC_TRACE(rtcIntersect8);
  723. #if defined(DEBUG)
  724. RTC_VERIFY_HANDLE(hscene);
  725. if (scene->isModified()) throw_RTCError(RTC_ERROR_INVALID_OPERATION,"scene not committed");
  726. if (((size_t)valid) & 0x1F) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "mask not aligned to 32 bytes");
  727. if (((size_t)rayhit) & 0x1F) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "rayhit not aligned to 32 bytes");
  728. #endif
  729. STAT(size_t cnt=0; for (size_t i=0; i<8; i++) cnt += ((int*)valid)[i] == -1;);
  730. STAT3(normal.travs,cnt,cnt,cnt);
  731. RTCIntersectArguments defaultArgs;
  732. if (unlikely(args == nullptr)) {
  733. rtcInitIntersectArguments(&defaultArgs);
  734. args = &defaultArgs;
  735. }
  736. RTCRayQueryContext* user_context = args->context;
  737. RTCRayQueryContext defaultContext;
  738. if (unlikely(user_context == nullptr)) {
  739. rtcInitRayQueryContext(&defaultContext);
  740. user_context = &defaultContext;
  741. }
  742. RayQueryContext context(scene,user_context,args);
  743. if (likely(scene->intersectors.intersector8))
  744. scene->intersectors.intersect8(valid,*rayhit,&context);
  745. else
  746. {
  747. RayHit8* ray8 = (RayHit8*) rayhit;
  748. for (size_t i=0; i<8; i++) {
  749. if (!valid[i]) continue;
  750. RayHit ray1; ray8->get(i,ray1);
  751. scene->intersectors.intersect((RTCRayHit&)ray1,&context);
  752. ray8->set(i,ray1);
  753. }
  754. }
  755. RTC_CATCH_END2(scene);
  756. }
  757. RTC_API void rtcForwardIntersect8(const int* valid, const RTCIntersectFunctionNArguments* args, RTCScene hscene, RTCRay8* iray, unsigned int instID)
  758. {
  759. RTC_TRACE(rtcForwardIntersect8);
  760. return rtcForwardIntersect8Ex(valid, args, hscene, iray, instID, 0);
  761. }
  762. RTC_API void rtcForwardIntersect8Ex(const int* valid, const RTCIntersectFunctionNArguments* args, RTCScene hscene, RTCRay8* iray, unsigned int instID, unsigned int instPrimID)
  763. {
  764. Scene* scene = (Scene*) hscene;
  765. RTC_CATCH_BEGIN;
  766. RTC_TRACE(rtcForwardIntersect8Ex);
  767. rtcForwardIntersectN<RTCRay8,RTCRayHit8,8>(valid,args,hscene,iray,instID,instPrimID);
  768. RTC_CATCH_END2(scene);
  769. }
  770. RTC_API void rtcIntersect16 (const int* valid, RTCScene hscene, RTCRayHit16* rayhit, RTCIntersectArguments* args)
  771. {
  772. Scene* scene = (Scene*) hscene;
  773. RTC_CATCH_BEGIN;
  774. RTC_TRACE(rtcIntersect16);
  775. #if defined(DEBUG)
  776. RTC_VERIFY_HANDLE(hscene);
  777. if (scene->isModified()) throw_RTCError(RTC_ERROR_INVALID_OPERATION,"scene not committed");
  778. if (((size_t)valid) & 0x3F) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "mask not aligned to 64 bytes");
  779. if (((size_t)rayhit) & 0x3F) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "rayhit not aligned to 64 bytes");
  780. #endif
  781. STAT(size_t cnt=0; for (size_t i=0; i<16; i++) cnt += ((int*)valid)[i] == -1;);
  782. STAT3(normal.travs,cnt,cnt,cnt);
  783. RTCIntersectArguments defaultArgs;
  784. if (unlikely(args == nullptr)) {
  785. rtcInitIntersectArguments(&defaultArgs);
  786. args = &defaultArgs;
  787. }
  788. RTCRayQueryContext* user_context = args->context;
  789. RTCRayQueryContext defaultContext;
  790. if (unlikely(user_context == nullptr)) {
  791. rtcInitRayQueryContext(&defaultContext);
  792. user_context = &defaultContext;
  793. }
  794. RayQueryContext context(scene,user_context,args);
  795. if (likely(scene->intersectors.intersector16))
  796. scene->intersectors.intersect16(valid,*rayhit,&context);
  797. else {
  798. RayHit16* ray16 = (RayHit16*) rayhit;
  799. for (size_t i=0; i<16; i++) {
  800. if (!valid[i]) continue;
  801. RayHit ray1; ray16->get(i,ray1);
  802. scene->intersectors.intersect((RTCRayHit&)ray1,&context);
  803. ray16->set(i,ray1);
  804. }
  805. }
  806. RTC_CATCH_END2(scene);
  807. }
  808. RTC_API void rtcForwardIntersect16(const int* valid, const RTCIntersectFunctionNArguments* args, RTCScene hscene, RTCRay16* iray, unsigned int instID)
  809. {
  810. RTC_TRACE(rtcForwardIntersect16);
  811. return rtcForwardIntersect16Ex(valid, args, hscene, iray, instID, 0);
  812. }
  813. RTC_API void rtcForwardIntersect16Ex(const int* valid, const RTCIntersectFunctionNArguments* args, RTCScene hscene, RTCRay16* iray, unsigned int instID, unsigned int instPrimID)
  814. {
  815. Scene* scene = (Scene*) hscene;
  816. RTC_CATCH_BEGIN;
  817. RTC_TRACE(rtcForwardIntersect16Ex);
  818. rtcForwardIntersectN<RTCRay16,RTCRayHit16,16>(valid,args,hscene,iray,instID,instPrimID);
  819. RTC_CATCH_END2(scene);
  820. }
  821. RTC_API void rtcOccluded1 (RTCScene hscene, RTCRay* ray, RTCOccludedArguments* args)
  822. {
  823. Scene* scene = (Scene*) hscene;
  824. RTC_CATCH_BEGIN;
  825. RTC_TRACE(rtcOccluded1);
  826. STAT3(shadow.travs,1,1,1);
  827. #if defined(DEBUG)
  828. RTC_VERIFY_HANDLE(hscene);
  829. if (scene->isModified()) throw_RTCError(RTC_ERROR_INVALID_OPERATION,"scene not committed");
  830. if (((size_t)ray) & 0x0F) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "ray not aligned to 16 bytes");
  831. #endif
  832. RTCOccludedArguments defaultArgs;
  833. if (unlikely(args == nullptr)) {
  834. rtcInitOccludedArguments(&defaultArgs);
  835. args = &defaultArgs;
  836. }
  837. RTCRayQueryContext* user_context = args->context;
  838. RTCRayQueryContext defaultContext;
  839. if (unlikely(user_context == nullptr)) {
  840. rtcInitRayQueryContext(&defaultContext);
  841. user_context = &defaultContext;
  842. }
  843. RayQueryContext context(scene,user_context,args);
  844. scene->intersectors.occluded(*ray,&context);
  845. RTC_CATCH_END2(scene);
  846. }
  847. RTC_API void rtcForwardOccluded1 (const RTCOccludedFunctionNArguments* args, RTCScene hscene, RTCRay* iray_, unsigned int instID)
  848. {
  849. RTC_TRACE(rtcForwardOccluded1);
  850. return rtcForwardOccluded1Ex(args, hscene, iray_, instID, 0);
  851. }
  852. RTC_API void rtcForwardOccluded1Ex(const RTCOccludedFunctionNArguments* args, RTCScene hscene, RTCRay* iray_, unsigned int instID, unsigned int instPrimID)
  853. {
  854. Scene* scene = (Scene*) hscene;
  855. RTC_CATCH_BEGIN;
  856. RTC_TRACE(rtcForwardOccluded1Ex);
  857. STAT3(shadow.travs,1,1,1);
  858. #if defined(DEBUG)
  859. RTC_VERIFY_HANDLE(hscene);
  860. if (scene->isModified()) throw_RTCError(RTC_ERROR_INVALID_OPERATION,"scene not committed");
  861. if (((size_t)iray_) & 0x0F) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "ray not aligned to 16 bytes");
  862. #endif
  863. Ray* iray = (Ray*)iray_;
  864. Ray* oray = (Ray*)args->ray;
  865. RTCRayQueryContext* user_context = args->context;
  866. const Vec3ff ray_org_tnear = oray->org;
  867. const Vec3ff ray_dir_time = oray->dir;
  868. oray->org = iray->org;
  869. oray->dir = iray->dir;
  870. RTCIntersectArguments* iargs = ((OccludedFunctionNArguments*) args)->args;
  871. RayQueryContext context(scene,user_context,iargs);
  872. instance_id_stack::push(user_context, instID, instPrimID);
  873. scene->intersectors.occluded(*(RTCRay*)oray,&context);
  874. instance_id_stack::pop(user_context);
  875. oray->org = ray_org_tnear;
  876. oray->dir = ray_dir_time;
  877. RTC_CATCH_END2(scene);
  878. }
  879. RTC_API void rtcOccluded4 (const int* valid, RTCScene hscene, RTCRay4* ray, RTCOccludedArguments* args)
  880. {
  881. Scene* scene = (Scene*) hscene;
  882. RTC_CATCH_BEGIN;
  883. RTC_TRACE(rtcOccluded4);
  884. #if defined(DEBUG)
  885. RTC_VERIFY_HANDLE(hscene);
  886. if (scene->isModified()) throw_RTCError(RTC_ERROR_INVALID_OPERATION,"scene not committed");
  887. if (((size_t)valid) & 0x0F) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "mask not aligned to 16 bytes");
  888. if (((size_t)ray) & 0x0F) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "ray not aligned to 16 bytes");
  889. #endif
  890. STAT(size_t cnt=0; for (size_t i=0; i<4; i++) cnt += ((int*)valid)[i] == -1;);
  891. STAT3(shadow.travs,cnt,cnt,cnt);
  892. RTCOccludedArguments defaultArgs;
  893. if (unlikely(args == nullptr)) {
  894. rtcInitOccludedArguments(&defaultArgs);
  895. args = &defaultArgs;
  896. }
  897. RTCRayQueryContext* user_context = args->context;
  898. RTCRayQueryContext defaultContext;
  899. if (unlikely(user_context == nullptr)) {
  900. rtcInitRayQueryContext(&defaultContext);
  901. user_context = &defaultContext;
  902. }
  903. RayQueryContext context(scene,user_context,args);
  904. if (likely(scene->intersectors.intersector4))
  905. scene->intersectors.occluded4(valid,*ray,&context);
  906. else {
  907. RayHit4* ray4 = (RayHit4*) ray;
  908. for (size_t i=0; i<4; i++) {
  909. if (!valid[i]) continue;
  910. RayHit ray1; ray4->get(i,ray1);
  911. scene->intersectors.occluded((RTCRay&)ray1,&context);
  912. ray4->geomID[i] = ray1.geomID;
  913. }
  914. }
  915. RTC_CATCH_END2(scene);
  916. }
  917. template<typename RTCRay, int N>
  918. __forceinline void rtcForwardOccludedN (const int* valid, const RTCOccludedFunctionNArguments* args, RTCScene hscene, RTCRay* iray, unsigned int instID, unsigned int instPrimID)
  919. {
  920. Scene* scene = (Scene*) hscene;
  921. RTCRay* oray = (RTCRay*)args->ray;
  922. RTCRayQueryContext* user_context = args->context;
  923. __aligned(16) float ray_org_x[N];
  924. __aligned(16) float ray_org_y[N];
  925. __aligned(16) float ray_org_z[N];
  926. __aligned(16) float ray_dir_x[N];
  927. __aligned(16) float ray_dir_y[N];
  928. __aligned(16) float ray_dir_z[N];
  929. copy<N>(ray_org_x,oray->org_x);
  930. copy<N>(ray_org_y,oray->org_y);
  931. copy<N>(ray_org_z,oray->org_z);
  932. copy<N>(ray_dir_x,oray->dir_x);
  933. copy<N>(ray_dir_y,oray->dir_y);
  934. copy<N>(ray_dir_z,oray->dir_z);
  935. copy<N>(oray->org_x,iray->org_x);
  936. copy<N>(oray->org_y,iray->org_y);
  937. copy<N>(oray->org_z,iray->org_z);
  938. copy<N>(oray->dir_x,iray->dir_x);
  939. copy<N>(oray->dir_y,iray->dir_y);
  940. copy<N>(oray->dir_z,iray->dir_z);
  941. STAT(size_t cnt=0; for (size_t i=0; i<N; i++) cnt += ((int*)valid)[i] == -1;);
  942. STAT3(normal.travs,cnt,cnt,cnt);
  943. RTCIntersectArguments* iargs = ((IntersectFunctionNArguments*) args)->args;
  944. RayQueryContext context(scene,user_context,iargs);
  945. instance_id_stack::push(user_context, instID, instPrimID);
  946. scene->intersectors.occluded(valid,*oray,&context);
  947. instance_id_stack::pop(user_context);
  948. copy<N>(oray->org_x,ray_org_x);
  949. copy<N>(oray->org_y,ray_org_y);
  950. copy<N>(oray->org_z,ray_org_z);
  951. copy<N>(oray->dir_x,ray_dir_x);
  952. copy<N>(oray->dir_y,ray_dir_y);
  953. copy<N>(oray->dir_z,ray_dir_z);
  954. }
  955. RTC_API void rtcForwardOccluded4(const int* valid, const RTCOccludedFunctionNArguments* args, RTCScene hscene, RTCRay4* iray, unsigned int instID)
  956. {
  957. RTC_TRACE(rtcForwardOccluded4);
  958. return rtcForwardOccluded4Ex(valid, args, hscene, iray, instID, 0);
  959. }
  960. RTC_API void rtcForwardOccluded4Ex(const int* valid, const RTCOccludedFunctionNArguments* args, RTCScene hscene, RTCRay4* iray, unsigned int instID, unsigned int instPrimID)
  961. {
  962. Scene* scene = (Scene*) hscene;
  963. RTC_CATCH_BEGIN;
  964. RTC_TRACE(rtcForwardOccluded4);
  965. rtcForwardOccludedN<RTCRay4,4>(valid,args,hscene,iray,instID,instPrimID);
  966. RTC_CATCH_END2(scene);
  967. }
  968. RTC_API void rtcOccluded8 (const int* valid, RTCScene hscene, RTCRay8* ray, RTCOccludedArguments* args)
  969. {
  970. Scene* scene = (Scene*) hscene;
  971. RTC_CATCH_BEGIN;
  972. RTC_TRACE(rtcOccluded8);
  973. #if defined(DEBUG)
  974. RTC_VERIFY_HANDLE(hscene);
  975. if (scene->isModified()) throw_RTCError(RTC_ERROR_INVALID_OPERATION,"scene not committed");
  976. if (((size_t)valid) & 0x1F) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "mask not aligned to 32 bytes");
  977. if (((size_t)ray) & 0x1F) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "ray not aligned to 32 bytes");
  978. #endif
  979. STAT(size_t cnt=0; for (size_t i=0; i<8; i++) cnt += ((int*)valid)[i] == -1;);
  980. STAT3(shadow.travs,cnt,cnt,cnt);
  981. RTCOccludedArguments defaultArgs;
  982. if (unlikely(args == nullptr)) {
  983. rtcInitOccludedArguments(&defaultArgs);
  984. args = &defaultArgs;
  985. }
  986. RTCRayQueryContext* user_context = args->context;
  987. RTCRayQueryContext defaultContext;
  988. if (unlikely(user_context == nullptr)) {
  989. rtcInitRayQueryContext(&defaultContext);
  990. user_context = &defaultContext;
  991. }
  992. RayQueryContext context(scene,user_context,args);
  993. if (likely(scene->intersectors.intersector8))
  994. scene->intersectors.occluded8(valid,*ray,&context);
  995. else {
  996. RayHit8* ray8 = (RayHit8*) ray;
  997. for (size_t i=0; i<8; i++) {
  998. if (!valid[i]) continue;
  999. RayHit ray1; ray8->get(i,ray1);
  1000. scene->intersectors.occluded((RTCRay&)ray1,&context);
  1001. ray8->set(i,ray1);
  1002. }
  1003. }
  1004. RTC_CATCH_END2(scene);
  1005. }
  1006. RTC_API void rtcForwardOccluded8(const int* valid, const RTCOccludedFunctionNArguments* args, RTCScene hscene, RTCRay8* iray, unsigned int instID)
  1007. {
  1008. RTC_TRACE(rtcForwardOccluded8);
  1009. return rtcForwardOccluded8Ex(valid, args, hscene, iray, instID, 0);
  1010. }
  1011. RTC_API void rtcForwardOccluded8Ex(const int* valid, const RTCOccludedFunctionNArguments* args, RTCScene hscene, RTCRay8* iray, unsigned int instID, unsigned int instPrimID)
  1012. {
  1013. Scene* scene = (Scene*) hscene;
  1014. RTC_CATCH_BEGIN;
  1015. RTC_TRACE(rtcForwardOccluded8Ex);
  1016. rtcForwardOccludedN<RTCRay8,8>(valid, args, hscene, iray, instID, instPrimID);
  1017. RTC_CATCH_END2(scene);
  1018. }
  1019. RTC_API void rtcOccluded16 (const int* valid, RTCScene hscene, RTCRay16* ray, RTCOccludedArguments* args)
  1020. {
  1021. Scene* scene = (Scene*) hscene;
  1022. RTC_CATCH_BEGIN;
  1023. RTC_TRACE(rtcOccluded16);
  1024. #if defined(DEBUG)
  1025. RTC_VERIFY_HANDLE(hscene);
  1026. if (scene->isModified()) throw_RTCError(RTC_ERROR_INVALID_OPERATION,"scene not committed");
  1027. if (((size_t)valid) & 0x3F) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "mask not aligned to 64 bytes");
  1028. if (((size_t)ray) & 0x3F) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "ray not aligned to 64 bytes");
  1029. #endif
  1030. STAT(size_t cnt=0; for (size_t i=0; i<16; i++) cnt += ((int*)valid)[i] == -1;);
  1031. STAT3(shadow.travs,cnt,cnt,cnt);
  1032. RTCOccludedArguments defaultArgs;
  1033. if (unlikely(args == nullptr)) {
  1034. rtcInitOccludedArguments(&defaultArgs);
  1035. args = &defaultArgs;
  1036. }
  1037. RTCRayQueryContext* user_context = args->context;
  1038. RTCRayQueryContext defaultContext;
  1039. if (unlikely(user_context == nullptr)) {
  1040. rtcInitRayQueryContext(&defaultContext);
  1041. user_context = &defaultContext;
  1042. }
  1043. RayQueryContext context(scene,user_context,args);
  1044. if (likely(scene->intersectors.intersector16))
  1045. scene->intersectors.occluded16(valid,*ray,&context);
  1046. else {
  1047. RayHit16* ray16 = (RayHit16*) ray;
  1048. for (size_t i=0; i<16; i++) {
  1049. if (!valid[i]) continue;
  1050. RayHit ray1; ray16->get(i,ray1);
  1051. scene->intersectors.occluded((RTCRay&)ray1,&context);
  1052. ray16->set(i,ray1);
  1053. }
  1054. }
  1055. RTC_CATCH_END2(scene);
  1056. }
  1057. RTC_API void rtcForwardOccluded16(const int* valid, const RTCOccludedFunctionNArguments* args, RTCScene hscene, RTCRay16* iray, unsigned int instID)
  1058. {
  1059. RTC_TRACE(rtcForwardOccluded16);
  1060. return rtcForwardOccluded16Ex(valid, args, hscene, iray, instID, 0);
  1061. }
  1062. RTC_API void rtcForwardOccluded16Ex(const int* valid, const RTCOccludedFunctionNArguments* args, RTCScene hscene, RTCRay16* iray, unsigned int instID, unsigned int instPrimID)
  1063. {
  1064. Scene* scene = (Scene*) hscene;
  1065. RTC_CATCH_BEGIN;
  1066. RTC_TRACE(rtcForwardOccluded16Ex);
  1067. rtcForwardOccludedN<RTCRay16,16>(valid, args, hscene, iray, instID, instPrimID);
  1068. RTC_CATCH_END2(scene);
  1069. }
  1070. RTC_API bool rtcTraversablePointQuery(RTCTraversable htraversable, RTCPointQuery* query, RTCPointQueryContext* userContext, RTCPointQueryFunction queryFunc, void* userPtr)
  1071. {
  1072. return rtcPointQuery((RTCScene)htraversable, query, userContext, queryFunc, userPtr);
  1073. }
  1074. RTC_API bool rtcTraversablePointQuery4 (const int* valid, RTCTraversable htraversable, RTCPointQuery4* query, struct RTCPointQueryContext* userContext, RTCPointQueryFunction queryFunc, void** userPtrN)
  1075. {
  1076. return rtcPointQuery4(valid, (RTCScene)htraversable, query, userContext, queryFunc, userPtrN);
  1077. }
  1078. RTC_API bool rtcTraversablePointQuery8 (const int* valid, RTCTraversable htraversable, RTCPointQuery8* query, struct RTCPointQueryContext* userContext, RTCPointQueryFunction queryFunc, void** userPtrN)
  1079. {
  1080. return rtcPointQuery8(valid, (RTCScene)htraversable, query, userContext, queryFunc, userPtrN);
  1081. }
  1082. RTC_API bool rtcTraversablePointQuery16 (const int* valid, RTCTraversable htraversable, RTCPointQuery16* query, struct RTCPointQueryContext* userContext, RTCPointQueryFunction queryFunc, void** userPtrN)
  1083. {
  1084. return rtcPointQuery16(valid, (RTCScene)htraversable, query, userContext, queryFunc, userPtrN);
  1085. }
  1086. RTC_API void rtcTraversableIntersect1 (RTCTraversable htraversable, RTCRayHit* rayhit, RTCIntersectArguments* args)
  1087. {
  1088. rtcIntersect1((RTCScene)htraversable, rayhit, args);
  1089. }
  1090. RTC_API void rtcTraversableForwardIntersect1 (const RTCIntersectFunctionNArguments* args, RTCTraversable htraversable, RTCRay* iray_, unsigned int instID)
  1091. {
  1092. rtcForwardIntersect1(args, (RTCScene)htraversable, iray_, instID);
  1093. }
  1094. RTC_API void rtcTraversableForwardIntersect1Ex(const RTCIntersectFunctionNArguments* args, RTCTraversable htraversable, RTCRay* iray_, unsigned int instID, unsigned int instPrimID)
  1095. {
  1096. rtcForwardIntersect1Ex(args, (RTCScene)htraversable, iray_, instID, instPrimID);
  1097. }
  1098. RTC_API void rtcTraversableIntersect4 (const int* valid, RTCTraversable htraversable, RTCRayHit4* rayhit, RTCIntersectArguments* args)
  1099. {
  1100. rtcIntersect4(valid, (RTCScene)htraversable, rayhit, args);
  1101. }
  1102. template<typename RTCRay, typename RTCRayHit, int N>
  1103. __forceinline void rtcTraversableForwardIntersectN(const int* valid, const RTCIntersectFunctionNArguments* args, RTCTraversable htraversable, RTCRay* iray, unsigned int instID, unsigned int instPrimID)
  1104. {
  1105. rtcForwardIntersetN(valid, args, (RTCScene)htraversable, iray, instID, instPrimID);
  1106. }
  1107. RTC_API void rtcTraversableForwardIntersect4(const int* valid, const RTCIntersectFunctionNArguments* args, RTCTraversable htraversable, RTCRay4* iray, unsigned int instID)
  1108. {
  1109. rtcForwardIntersect4(valid, args, (RTCScene)htraversable, iray, instID);
  1110. }
  1111. RTC_API void rtcTraversableForwardIntersect4Ex(const int* valid, const RTCIntersectFunctionNArguments* args, RTCTraversable htraversable, RTCRay4* iray, unsigned int instID, unsigned int instPrimID)
  1112. {
  1113. rtcForwardIntersect4Ex(valid, args, (RTCScene)htraversable, iray, instID, instPrimID);
  1114. }
  1115. RTC_API void rtcTraversableIntersect8 (const int* valid, RTCTraversable htraversable, RTCRayHit8* rayhit, RTCIntersectArguments* args)
  1116. {
  1117. rtcIntersect8(valid, (RTCScene)htraversable, rayhit, args);
  1118. }
  1119. RTC_API void rtcTraversableForwardIntersect8(const int* valid, const RTCIntersectFunctionNArguments* args, RTCTraversable htraversable, RTCRay8* iray, unsigned int instID)
  1120. {
  1121. rtcForwardIntersect8(valid, args, (RTCScene)htraversable, iray, instID);
  1122. }
  1123. RTC_API void rtcTraversableForwardIntersect8Ex(const int* valid, const RTCIntersectFunctionNArguments* args, RTCTraversable htraversable, RTCRay8* iray, unsigned int instID, unsigned int instPrimID)
  1124. {
  1125. rtcForwardIntersect8Ex(valid, args, (RTCScene)htraversable, iray, instID, instPrimID);
  1126. }
  1127. RTC_API void rtcTraversableIntersect16 (const int* valid, RTCTraversable htraversable, RTCRayHit16* rayhit, RTCIntersectArguments* args)
  1128. {
  1129. rtcIntersect16(valid, (RTCScene)htraversable, rayhit, args);
  1130. }
  1131. RTC_API void rtcTraversableForwardIntersect16(const int* valid, const RTCIntersectFunctionNArguments* args, RTCTraversable htraversable, RTCRay16* iray, unsigned int instID)
  1132. {
  1133. rtcForwardIntersect16(valid, args, (RTCScene)htraversable, iray, instID);
  1134. }
  1135. RTC_API void rtcTraversableForwardIntersect16Ex(const int* valid, const RTCIntersectFunctionNArguments* args, RTCTraversable htraversable, RTCRay16* iray, unsigned int instID, unsigned int instPrimID)
  1136. {
  1137. rtcForwardIntersect16Ex(valid, args, (RTCScene)htraversable, iray, instID, instPrimID);
  1138. }
  1139. RTC_API void rtcTraversableOccluded1 (RTCTraversable htraversable, RTCRay* ray, RTCOccludedArguments* args)
  1140. {
  1141. rtcOccluded1((RTCScene)htraversable, ray, args);
  1142. }
  1143. RTC_API void rtcTraversableForwardOccluded1 (const RTCOccludedFunctionNArguments* args, RTCTraversable htraversable, RTCRay* iray_, unsigned int instID)
  1144. {
  1145. rtcForwardOccluded1(args, (RTCScene)htraversable, iray_, instID);
  1146. }
  1147. RTC_API void rtcTraversableForwardOccluded1Ex(const RTCOccludedFunctionNArguments* args, RTCTraversable htraversable, RTCRay* iray_, unsigned int instID, unsigned int instPrimID)
  1148. {
  1149. rtcForwardOccluded1Ex(args, (RTCScene)htraversable, iray_, instID, instPrimID);
  1150. }
  1151. RTC_API void rtcTraversableOccluded4 (const int* valid, RTCTraversable htraversable, RTCRay4* ray, RTCOccludedArguments* args)
  1152. {
  1153. rtcOccluded4(valid, (RTCScene)htraversable, ray, args);
  1154. }
  1155. template<typename RTCRay, int N>
  1156. __forceinline void rtcTraversableForwardOccludedN (const int* valid, const RTCOccludedFunctionNArguments* args, RTCTraversable htraversable, RTCRay* iray, unsigned int instID, unsigned int instPrimID)
  1157. {
  1158. rtcForwardOccludedN(valid, args, (RTCScene)htraversable, iray, instID, instPrimID);
  1159. }
  1160. RTC_API void rtcTraversableForwardOccluded4(const int* valid, const RTCOccludedFunctionNArguments* args, RTCTraversable htraversable, RTCRay4* iray, unsigned int instID)
  1161. {
  1162. rtcForwardOccluded4(valid, args, (RTCScene)htraversable, iray, instID);
  1163. }
  1164. RTC_API void rtcTraversableForwardOccluded4Ex(const int* valid, const RTCOccludedFunctionNArguments* args, RTCTraversable htraversable, RTCRay4* iray, unsigned int instID, unsigned int instPrimID)
  1165. {
  1166. rtcForwardOccluded4Ex(valid, args, (RTCScene)htraversable, iray, instID, instPrimID);
  1167. }
  1168. RTC_API void rtcTraversableOccluded8 (const int* valid, RTCTraversable htraversable, RTCRay8* ray, RTCOccludedArguments* args)
  1169. {
  1170. rtcOccluded8(valid, (RTCScene)htraversable, ray, args);
  1171. }
  1172. RTC_API void rtcTraversableForwardOccluded8(const int* valid, const RTCOccludedFunctionNArguments* args, RTCTraversable htraversable, RTCRay8* iray, unsigned int instID)
  1173. {
  1174. rtcForwardOccluded8(valid, args, (RTCScene)htraversable, iray, instID);
  1175. }
  1176. RTC_API void rtcTraversableForwardOccluded8Ex(const int* valid, const RTCOccludedFunctionNArguments* args, RTCTraversable htraversable, RTCRay8* iray, unsigned int instID, unsigned int instPrimID)
  1177. {
  1178. rtcForwardOccluded8Ex(valid, args, (RTCScene)htraversable, iray, instID, instPrimID);
  1179. }
  1180. RTC_API void rtcTraversableOccluded16 (const int* valid, RTCTraversable htraversable, RTCRay16* ray, RTCOccludedArguments* args)
  1181. {
  1182. rtcOccluded16(valid, (RTCScene)htraversable, ray, args);
  1183. }
  1184. RTC_API void rtcTraversableForwardOccluded16(const int* valid, const RTCOccludedFunctionNArguments* args, RTCTraversable htraversable, RTCRay16* iray, unsigned int instID)
  1185. {
  1186. rtcForwardOccluded16(valid, args, (RTCScene)htraversable, iray, instID);
  1187. }
  1188. RTC_API void rtcTraversableForwardOccluded16Ex(const int* valid, const RTCOccludedFunctionNArguments* args, RTCTraversable htraversable, RTCRay16* iray, unsigned int instID, unsigned int instPrimID)
  1189. {
  1190. rtcForwardOccluded16Ex(valid, args, (RTCScene)htraversable, iray, instID, instPrimID);
  1191. }
  1192. RTC_API void rtcRetainScene (RTCScene hscene)
  1193. {
  1194. Scene* scene = (Scene*) hscene;
  1195. RTC_CATCH_BEGIN;
  1196. RTC_TRACE(rtcRetainScene);
  1197. RTC_VERIFY_HANDLE(hscene);
  1198. RTC_ENTER_DEVICE(hscene);
  1199. scene->refInc();
  1200. RTC_CATCH_END2(scene);
  1201. }
  1202. RTC_API void rtcReleaseScene (RTCScene hscene)
  1203. {
  1204. Scene* scene = (Scene*) hscene;
  1205. RTC_CATCH_BEGIN;
  1206. RTC_TRACE(rtcReleaseScene);
  1207. RTC_VERIFY_HANDLE(hscene);
  1208. RTC_ENTER_DEVICE(hscene);
  1209. scene->refDec();
  1210. RTC_CATCH_END2(scene);
  1211. }
  1212. RTC_API void rtcSetGeometryInstancedScene(RTCGeometry hgeometry, RTCScene hscene)
  1213. {
  1214. Geometry* geometry = (Geometry*) hgeometry;
  1215. Ref<Scene> scene = (Scene*) hscene;
  1216. RTC_CATCH_BEGIN;
  1217. RTC_TRACE(rtcSetGeometryInstancedScene);
  1218. RTC_VERIFY_HANDLE(hgeometry);
  1219. RTC_VERIFY_HANDLE(hscene);
  1220. RTC_ENTER_DEVICE(hgeometry);
  1221. geometry->setInstancedScene(scene);
  1222. RTC_CATCH_END2(geometry);
  1223. }
  1224. RTC_API void rtcSetGeometryInstancedScenes(RTCGeometry hgeometry, RTCScene* scenes, size_t numScenes)
  1225. {
  1226. Geometry* geometry = (Geometry*) hgeometry;
  1227. RTC_CATCH_BEGIN;
  1228. RTC_TRACE(rtcSetGeometryInstancedScene);
  1229. RTC_VERIFY_HANDLE(hgeometry);
  1230. RTC_VERIFY_HANDLE(scenes);
  1231. RTC_ENTER_DEVICE(hgeometry);
  1232. geometry->setInstancedScenes(scenes, numScenes);
  1233. RTC_CATCH_END2(geometry);
  1234. }
  1235. AffineSpace3fa loadTransform(RTCFormat format, const float* xfm)
  1236. {
  1237. AffineSpace3fa space = one;
  1238. switch (format)
  1239. {
  1240. case RTC_FORMAT_FLOAT3X4_ROW_MAJOR:
  1241. space = AffineSpace3fa(Vec3fa(xfm[ 0], xfm[ 4], xfm[ 8]),
  1242. Vec3fa(xfm[ 1], xfm[ 5], xfm[ 9]),
  1243. Vec3fa(xfm[ 2], xfm[ 6], xfm[10]),
  1244. Vec3fa(xfm[ 3], xfm[ 7], xfm[11]));
  1245. break;
  1246. case RTC_FORMAT_FLOAT3X4_COLUMN_MAJOR:
  1247. space = AffineSpace3fa(Vec3fa(xfm[ 0], xfm[ 1], xfm[ 2]),
  1248. Vec3fa(xfm[ 3], xfm[ 4], xfm[ 5]),
  1249. Vec3fa(xfm[ 6], xfm[ 7], xfm[ 8]),
  1250. Vec3fa(xfm[ 9], xfm[10], xfm[11]));
  1251. break;
  1252. case RTC_FORMAT_FLOAT4X4_COLUMN_MAJOR:
  1253. space = AffineSpace3fa(Vec3fa(xfm[ 0], xfm[ 1], xfm[ 2]),
  1254. Vec3fa(xfm[ 4], xfm[ 5], xfm[ 6]),
  1255. Vec3fa(xfm[ 8], xfm[ 9], xfm[10]),
  1256. Vec3fa(xfm[12], xfm[13], xfm[14]));
  1257. break;
  1258. default:
  1259. throw_RTCError(RTC_ERROR_INVALID_OPERATION, "invalid matrix format");
  1260. break;
  1261. }
  1262. return space;
  1263. }
  1264. RTC_API void rtcSetGeometryTransform(RTCGeometry hgeometry, unsigned int timeStep, RTCFormat format, const void* xfm)
  1265. {
  1266. Geometry* geometry = (Geometry*) hgeometry;
  1267. RTC_CATCH_BEGIN;
  1268. RTC_TRACE(rtcSetGeometryTransform);
  1269. RTC_VERIFY_HANDLE(hgeometry);
  1270. RTC_VERIFY_HANDLE(xfm);
  1271. RTC_ENTER_DEVICE(hgeometry);
  1272. const AffineSpace3fa transform = loadTransform(format, (const float*)xfm);
  1273. geometry->setTransform(transform, timeStep);
  1274. RTC_CATCH_END2(geometry);
  1275. }
  1276. RTC_API void rtcSetGeometryTransformQuaternion(RTCGeometry hgeometry, unsigned int timeStep, const RTCQuaternionDecomposition* qd)
  1277. {
  1278. Geometry* geometry = (Geometry*) hgeometry;
  1279. RTC_CATCH_BEGIN;
  1280. RTC_TRACE(rtcSetGeometryTransformQuaternion);
  1281. RTC_VERIFY_HANDLE(hgeometry);
  1282. RTC_VERIFY_HANDLE(qd);
  1283. RTC_ENTER_DEVICE(hgeometry);
  1284. AffineSpace3fx transform;
  1285. transform.l.vx.x = qd->scale_x;
  1286. transform.l.vy.y = qd->scale_y;
  1287. transform.l.vz.z = qd->scale_z;
  1288. transform.l.vy.x = qd->skew_xy;
  1289. transform.l.vz.x = qd->skew_xz;
  1290. transform.l.vz.y = qd->skew_yz;
  1291. transform.l.vx.y = qd->translation_x;
  1292. transform.l.vx.z = qd->translation_y;
  1293. transform.l.vy.z = qd->translation_z;
  1294. transform.p.x = qd->shift_x;
  1295. transform.p.y = qd->shift_y;
  1296. transform.p.z = qd->shift_z;
  1297. // normalize quaternion
  1298. Quaternion3f q(qd->quaternion_r, qd->quaternion_i, qd->quaternion_j, qd->quaternion_k);
  1299. q = normalize(q);
  1300. transform.l.vx.w = q.i;
  1301. transform.l.vy.w = q.j;
  1302. transform.l.vz.w = q.k;
  1303. transform.p.w = q.r;
  1304. geometry->setQuaternionDecomposition(transform, timeStep);
  1305. RTC_CATCH_END2(geometry);
  1306. }
  1307. RTC_API void rtcGetGeometryTransform(RTCGeometry hgeometry, float time, RTCFormat format, void* xfm)
  1308. {
  1309. Geometry* geometry = (Geometry*) hgeometry;
  1310. RTC_CATCH_BEGIN;
  1311. RTC_TRACE(rtcGetGeometryTransform);
  1312. //RTC_ENTER_DEVICE(hgeometry); // no allocation required
  1313. const AffineSpace3fa transform = geometry->getTransform(time);
  1314. storeTransform(transform, format, (float*)xfm);
  1315. RTC_CATCH_END2(geometry);
  1316. }
  1317. RTC_API void rtcGetGeometryTransformEx(RTCGeometry hgeometry, unsigned int instPrimID, float time, RTCFormat format, void* xfm)
  1318. {
  1319. Geometry* geometry = (Geometry*) hgeometry;
  1320. RTC_CATCH_BEGIN;
  1321. RTC_TRACE(rtcGetGeometryTransformEx);
  1322. //RTC_ENTER_DEVICE(hgeometry); // no allocation required
  1323. const AffineSpace3fa transform = geometry->getTransform(instPrimID, time);
  1324. storeTransform(transform, format, (float*)xfm);
  1325. RTC_CATCH_END2(geometry);
  1326. }
  1327. RTC_API void rtcGetGeometryTransformFromScene(RTCScene hscene, unsigned int geomID, float time, RTCFormat format, void* xfm)
  1328. {
  1329. Scene* scene = (Scene*) hscene;
  1330. RTC_CATCH_BEGIN;
  1331. RTC_TRACE(rtcGetGeometryTransformFromScene);
  1332. //RTC_ENTER_DEVICE(hscene); // no allocation required
  1333. const AffineSpace3fa transform = scene->get(geomID)->getTransform(time);
  1334. storeTransform(transform, format, (float*)xfm);
  1335. RTC_CATCH_END2(scene);
  1336. }
  1337. RTC_API void rtcGetGeometryTransformFromTraversable(RTCTraversable htraversable, unsigned int geomID, float time, RTCFormat format, void* xfm)
  1338. {
  1339. rtcGetGeometryTransformFromScene((RTCScene)htraversable, geomID, time, format, xfm);
  1340. }
  1341. RTC_API void rtcInvokeIntersectFilterFromGeometry(const struct RTCIntersectFunctionNArguments* const args_i, const struct RTCFilterFunctionNArguments* filter_args)
  1342. {
  1343. IntersectFunctionNArguments* args = (IntersectFunctionNArguments*) args_i;
  1344. if (args->geometry->intersectionFilterN)
  1345. args->geometry->intersectionFilterN(filter_args);
  1346. }
  1347. RTC_API void rtcInvokeOccludedFilterFromGeometry(const struct RTCOccludedFunctionNArguments* const args_i, const struct RTCFilterFunctionNArguments* filter_args)
  1348. {
  1349. OccludedFunctionNArguments* args = (OccludedFunctionNArguments*) args_i;
  1350. if (args->geometry->occlusionFilterN)
  1351. args->geometry->occlusionFilterN(filter_args);
  1352. }
  1353. RTC_API RTCGeometry rtcNewGeometry (RTCDevice hdevice, RTCGeometryType type)
  1354. {
  1355. Device* device = (Device*) hdevice;
  1356. RTC_CATCH_BEGIN;
  1357. RTC_TRACE(rtcNewGeometry);
  1358. RTC_ENTER_DEVICE(hdevice);
  1359. RTC_VERIFY_HANDLE(hdevice);
  1360. switch (type)
  1361. {
  1362. case RTC_GEOMETRY_TYPE_TRIANGLE:
  1363. {
  1364. #if defined(EMBREE_GEOMETRY_TRIANGLE)
  1365. createTriangleMeshTy createTriangleMesh = nullptr;
  1366. SELECT_SYMBOL_DEFAULT_AVX_AVX2_AVX512(device->enabled_cpu_features,createTriangleMesh);
  1367. Geometry* geom = createTriangleMesh(device);
  1368. return (RTCGeometry) geom->refInc();
  1369. #else
  1370. throw_RTCError(RTC_ERROR_UNKNOWN,"RTC_GEOMETRY_TYPE_TRIANGLE is not supported");
  1371. #endif
  1372. }
  1373. case RTC_GEOMETRY_TYPE_QUAD:
  1374. {
  1375. #if defined(EMBREE_GEOMETRY_QUAD)
  1376. createQuadMeshTy createQuadMesh = nullptr;
  1377. SELECT_SYMBOL_DEFAULT_AVX_AVX2_AVX512(device->enabled_cpu_features,createQuadMesh);
  1378. Geometry* geom = createQuadMesh(device);
  1379. return (RTCGeometry) geom->refInc();
  1380. #else
  1381. throw_RTCError(RTC_ERROR_UNKNOWN,"RTC_GEOMETRY_TYPE_QUAD is not supported");
  1382. #endif
  1383. }
  1384. case RTC_GEOMETRY_TYPE_SPHERE_POINT:
  1385. case RTC_GEOMETRY_TYPE_DISC_POINT:
  1386. case RTC_GEOMETRY_TYPE_ORIENTED_DISC_POINT:
  1387. {
  1388. #if defined(EMBREE_GEOMETRY_POINT)
  1389. createPointsTy createPoints = nullptr;
  1390. SELECT_SYMBOL_DEFAULT_AVX_AVX2_AVX512(device->enabled_builder_cpu_features, createPoints);
  1391. Geometry *geom;
  1392. switch(type) {
  1393. case RTC_GEOMETRY_TYPE_SPHERE_POINT:
  1394. geom = createPoints(device, Geometry::GTY_SPHERE_POINT);
  1395. break;
  1396. case RTC_GEOMETRY_TYPE_DISC_POINT:
  1397. geom = createPoints(device, Geometry::GTY_DISC_POINT);
  1398. break;
  1399. case RTC_GEOMETRY_TYPE_ORIENTED_DISC_POINT:
  1400. geom = createPoints(device, Geometry::GTY_ORIENTED_DISC_POINT);
  1401. break;
  1402. default:
  1403. geom = nullptr;
  1404. break;
  1405. }
  1406. return (RTCGeometry) geom->refInc();
  1407. #else
  1408. throw_RTCError(RTC_ERROR_UNKNOWN,"RTC_GEOMETRY_TYPE_POINT is not supported");
  1409. #endif
  1410. }
  1411. case RTC_GEOMETRY_TYPE_CONE_LINEAR_CURVE:
  1412. case RTC_GEOMETRY_TYPE_ROUND_LINEAR_CURVE:
  1413. case RTC_GEOMETRY_TYPE_FLAT_LINEAR_CURVE:
  1414. case RTC_GEOMETRY_TYPE_ROUND_BEZIER_CURVE:
  1415. case RTC_GEOMETRY_TYPE_FLAT_BEZIER_CURVE:
  1416. case RTC_GEOMETRY_TYPE_NORMAL_ORIENTED_BEZIER_CURVE:
  1417. case RTC_GEOMETRY_TYPE_ROUND_BSPLINE_CURVE:
  1418. case RTC_GEOMETRY_TYPE_FLAT_BSPLINE_CURVE:
  1419. case RTC_GEOMETRY_TYPE_NORMAL_ORIENTED_BSPLINE_CURVE:
  1420. case RTC_GEOMETRY_TYPE_ROUND_HERMITE_CURVE:
  1421. case RTC_GEOMETRY_TYPE_FLAT_HERMITE_CURVE:
  1422. case RTC_GEOMETRY_TYPE_NORMAL_ORIENTED_HERMITE_CURVE:
  1423. case RTC_GEOMETRY_TYPE_ROUND_CATMULL_ROM_CURVE:
  1424. case RTC_GEOMETRY_TYPE_FLAT_CATMULL_ROM_CURVE:
  1425. case RTC_GEOMETRY_TYPE_NORMAL_ORIENTED_CATMULL_ROM_CURVE:
  1426. {
  1427. #if defined(EMBREE_GEOMETRY_CURVE)
  1428. createLineSegmentsTy createLineSegments = nullptr;
  1429. SELECT_SYMBOL_DEFAULT_AVX_AVX2_AVX512(device->enabled_cpu_features,createLineSegments);
  1430. createCurvesTy createCurves = nullptr;
  1431. SELECT_SYMBOL_DEFAULT_AVX_AVX2_AVX512(device->enabled_cpu_features,createCurves);
  1432. Geometry* geom;
  1433. switch (type) {
  1434. case RTC_GEOMETRY_TYPE_CONE_LINEAR_CURVE : geom = createLineSegments (device,Geometry::GTY_CONE_LINEAR_CURVE); break;
  1435. case RTC_GEOMETRY_TYPE_ROUND_LINEAR_CURVE : geom = createLineSegments (device,Geometry::GTY_ROUND_LINEAR_CURVE); break;
  1436. case RTC_GEOMETRY_TYPE_FLAT_LINEAR_CURVE : geom = createLineSegments (device,Geometry::GTY_FLAT_LINEAR_CURVE); break;
  1437. //case RTC_GEOMETRY_TYPE_NORMAL_ORIENTED_LINEAR_CURVE : geom = createLineSegments (device,Geometry::GTY_ORIENTED_LINEAR_CURVE); break;
  1438. case RTC_GEOMETRY_TYPE_ROUND_BEZIER_CURVE : geom = createCurves(device,Geometry::GTY_ROUND_BEZIER_CURVE); break;
  1439. case RTC_GEOMETRY_TYPE_FLAT_BEZIER_CURVE : geom = createCurves(device,Geometry::GTY_FLAT_BEZIER_CURVE); break;
  1440. case RTC_GEOMETRY_TYPE_NORMAL_ORIENTED_BEZIER_CURVE : geom = createCurves(device,Geometry::GTY_ORIENTED_BEZIER_CURVE); break;
  1441. case RTC_GEOMETRY_TYPE_ROUND_BSPLINE_CURVE : geom = createCurves(device,Geometry::GTY_ROUND_BSPLINE_CURVE); break;
  1442. case RTC_GEOMETRY_TYPE_FLAT_BSPLINE_CURVE : geom = createCurves(device,Geometry::GTY_FLAT_BSPLINE_CURVE); break;
  1443. case RTC_GEOMETRY_TYPE_NORMAL_ORIENTED_BSPLINE_CURVE : geom = createCurves(device,Geometry::GTY_ORIENTED_BSPLINE_CURVE); break;
  1444. case RTC_GEOMETRY_TYPE_ROUND_HERMITE_CURVE : geom = createCurves(device,Geometry::GTY_ROUND_HERMITE_CURVE); break;
  1445. case RTC_GEOMETRY_TYPE_FLAT_HERMITE_CURVE : geom = createCurves(device,Geometry::GTY_FLAT_HERMITE_CURVE); break;
  1446. case RTC_GEOMETRY_TYPE_NORMAL_ORIENTED_HERMITE_CURVE : geom = createCurves(device,Geometry::GTY_ORIENTED_HERMITE_CURVE); break;
  1447. case RTC_GEOMETRY_TYPE_ROUND_CATMULL_ROM_CURVE : geom = createCurves(device,Geometry::GTY_ROUND_CATMULL_ROM_CURVE); break;
  1448. case RTC_GEOMETRY_TYPE_FLAT_CATMULL_ROM_CURVE : geom = createCurves(device,Geometry::GTY_FLAT_CATMULL_ROM_CURVE); break;
  1449. case RTC_GEOMETRY_TYPE_NORMAL_ORIENTED_CATMULL_ROM_CURVE : geom = createCurves(device,Geometry::GTY_ORIENTED_CATMULL_ROM_CURVE); break;
  1450. default: geom = nullptr; break;
  1451. }
  1452. return (RTCGeometry) geom->refInc();
  1453. #else
  1454. throw_RTCError(RTC_ERROR_UNKNOWN,"RTC_GEOMETRY_TYPE_CURVE is not supported");
  1455. #endif
  1456. }
  1457. case RTC_GEOMETRY_TYPE_SUBDIVISION:
  1458. {
  1459. #if defined(EMBREE_GEOMETRY_SUBDIVISION)
  1460. createSubdivMeshTy createSubdivMesh = nullptr;
  1461. SELECT_SYMBOL_DEFAULT_AVX(device->enabled_cpu_features,createSubdivMesh);
  1462. //SELECT_SYMBOL_DEFAULT_AVX_AVX2_AVX512(device->enabled_cpu_features,createSubdivMesh); // FIXME: this does not work for some reason?
  1463. Geometry* geom = createSubdivMesh(device);
  1464. return (RTCGeometry) geom->refInc();
  1465. #else
  1466. throw_RTCError(RTC_ERROR_UNKNOWN,"RTC_GEOMETRY_TYPE_SUBDIVISION is not supported");
  1467. #endif
  1468. }
  1469. case RTC_GEOMETRY_TYPE_USER:
  1470. {
  1471. #if defined(EMBREE_GEOMETRY_USER)
  1472. createUserGeometryTy createUserGeometry = nullptr;
  1473. SELECT_SYMBOL_DEFAULT_AVX_AVX2_AVX512(device->enabled_cpu_features,createUserGeometry);
  1474. Geometry* geom = createUserGeometry(device);
  1475. return (RTCGeometry) geom->refInc();
  1476. #else
  1477. throw_RTCError(RTC_ERROR_UNKNOWN,"RTC_GEOMETRY_TYPE_USER is not supported");
  1478. #endif
  1479. }
  1480. case RTC_GEOMETRY_TYPE_INSTANCE:
  1481. {
  1482. #if defined(EMBREE_GEOMETRY_INSTANCE)
  1483. createInstanceTy createInstance = nullptr;
  1484. SELECT_SYMBOL_DEFAULT_AVX_AVX2_AVX512(device->enabled_cpu_features,createInstance);
  1485. Geometry* geom = createInstance(device);
  1486. return (RTCGeometry) geom->refInc();
  1487. #else
  1488. throw_RTCError(RTC_ERROR_UNKNOWN,"RTC_GEOMETRY_TYPE_INSTANCE is not supported");
  1489. #endif
  1490. }
  1491. case RTC_GEOMETRY_TYPE_INSTANCE_ARRAY:
  1492. {
  1493. #if defined(EMBREE_GEOMETRY_INSTANCE_ARRAY)
  1494. createInstanceArrayTy createInstanceArray = nullptr;
  1495. SELECT_SYMBOL_DEFAULT_AVX_AVX2_AVX512(device->enabled_cpu_features,createInstanceArray);
  1496. Geometry* geom = createInstanceArray(device);
  1497. return (RTCGeometry) geom->refInc();
  1498. #else
  1499. throw_RTCError(RTC_ERROR_UNKNOWN,"RTC_GEOMETRY_TYPE_INSTANCE_ARRAY is not supported");
  1500. #endif
  1501. }
  1502. case RTC_GEOMETRY_TYPE_GRID:
  1503. {
  1504. #if defined(EMBREE_GEOMETRY_GRID)
  1505. createGridMeshTy createGridMesh = nullptr;
  1506. SELECT_SYMBOL_DEFAULT_AVX_AVX2_AVX512(device->enabled_cpu_features,createGridMesh);
  1507. Geometry* geom = createGridMesh(device);
  1508. return (RTCGeometry) geom->refInc();
  1509. #else
  1510. throw_RTCError(RTC_ERROR_UNKNOWN,"RTC_GEOMETRY_TYPE_GRID is not supported");
  1511. #endif
  1512. }
  1513. default:
  1514. throw_RTCError(RTC_ERROR_UNKNOWN,"invalid geometry type");
  1515. }
  1516. RTC_CATCH_END(device);
  1517. return nullptr;
  1518. }
  1519. RTC_API void rtcSetGeometryUserPrimitiveCount(RTCGeometry hgeometry, unsigned int userPrimitiveCount)
  1520. {
  1521. Geometry* geometry = (Geometry*) hgeometry;
  1522. RTC_CATCH_BEGIN;
  1523. RTC_TRACE(rtcSetGeometryUserPrimitiveCount);
  1524. RTC_VERIFY_HANDLE(hgeometry);
  1525. RTC_ENTER_DEVICE(hgeometry);
  1526. if (unlikely(geometry->getType() != Geometry::GTY_USER_GEOMETRY))
  1527. throw_RTCError(RTC_ERROR_INVALID_OPERATION,"operation only allowed for user geometries");
  1528. geometry->setNumPrimitives(userPrimitiveCount);
  1529. RTC_CATCH_END2(geometry);
  1530. }
  1531. RTC_API void rtcSetGeometryTimeStepCount(RTCGeometry hgeometry, unsigned int timeStepCount)
  1532. {
  1533. Geometry* geometry = (Geometry*) hgeometry;
  1534. RTC_CATCH_BEGIN;
  1535. RTC_TRACE(rtcSetGeometryTimeStepCount);
  1536. RTC_VERIFY_HANDLE(hgeometry);
  1537. RTC_ENTER_DEVICE(hgeometry);
  1538. if (timeStepCount > RTC_MAX_TIME_STEP_COUNT)
  1539. throw_RTCError(RTC_ERROR_INVALID_ARGUMENT,"number of time steps is out of range");
  1540. geometry->setNumTimeSteps(timeStepCount);
  1541. RTC_CATCH_END2(geometry);
  1542. }
  1543. RTC_API void rtcSetGeometryTimeRange(RTCGeometry hgeometry, float startTime, float endTime)
  1544. {
  1545. Ref<Geometry> geometry = (Geometry*) hgeometry;
  1546. RTC_CATCH_BEGIN;
  1547. RTC_TRACE(rtcSetGeometryTimeRange);
  1548. RTC_VERIFY_HANDLE(hgeometry);
  1549. RTC_ENTER_DEVICE(hgeometry);
  1550. if (startTime > endTime)
  1551. throw_RTCError(RTC_ERROR_INVALID_ARGUMENT,"startTime has to be smaller or equal to the endTime");
  1552. geometry->setTimeRange(BBox1f(startTime,endTime));
  1553. RTC_CATCH_END2(geometry);
  1554. }
  1555. RTC_API void rtcSetGeometryVertexAttributeCount(RTCGeometry hgeometry, unsigned int N)
  1556. {
  1557. Geometry* geometry = (Geometry*) hgeometry;
  1558. RTC_CATCH_BEGIN;
  1559. RTC_TRACE(rtcSetGeometryVertexAttributeCount);
  1560. RTC_VERIFY_HANDLE(hgeometry);
  1561. RTC_ENTER_DEVICE(hgeometry);
  1562. geometry->setVertexAttributeCount(N);
  1563. RTC_CATCH_END2(geometry);
  1564. }
  1565. RTC_API void rtcSetGeometryTopologyCount(RTCGeometry hgeometry, unsigned int N)
  1566. {
  1567. Geometry* geometry = (Geometry*) hgeometry;
  1568. RTC_CATCH_BEGIN;
  1569. RTC_TRACE(rtcSetGeometryTopologyCount);
  1570. RTC_VERIFY_HANDLE(hgeometry);
  1571. RTC_ENTER_DEVICE(hgeometry);
  1572. geometry->setTopologyCount(N);
  1573. RTC_CATCH_END2(geometry);
  1574. }
  1575. RTC_API void rtcSetGeometryBuildQuality (RTCGeometry hgeometry, RTCBuildQuality quality)
  1576. {
  1577. Geometry* geometry = (Geometry*) hgeometry;
  1578. RTC_CATCH_BEGIN;
  1579. RTC_TRACE(rtcSetGeometryBuildQuality);
  1580. RTC_VERIFY_HANDLE(hgeometry);
  1581. RTC_ENTER_DEVICE(hgeometry);
  1582. if (quality != RTC_BUILD_QUALITY_LOW &&
  1583. quality != RTC_BUILD_QUALITY_MEDIUM &&
  1584. quality != RTC_BUILD_QUALITY_HIGH &&
  1585. quality != RTC_BUILD_QUALITY_REFIT)
  1586. abort(); //throw std::runtime_error("invalid build quality");
  1587. geometry->setBuildQuality(quality);
  1588. RTC_CATCH_END2(geometry);
  1589. }
  1590. RTC_API void rtcSetGeometryMaxRadiusScale(RTCGeometry hgeometry, float maxRadiusScale)
  1591. {
  1592. Geometry* geometry = (Geometry*) hgeometry;
  1593. RTC_CATCH_BEGIN;
  1594. RTC_TRACE(rtcSetGeometryMaxRadiusScale);
  1595. RTC_VERIFY_HANDLE(hgeometry);
  1596. #if RTC_MIN_WIDTH
  1597. if (maxRadiusScale < 1.0f) throw_RTCError(RTC_ERROR_INVALID_OPERATION,"maximal radius scale has to be larger or equal to 1");
  1598. geometry->setMaxRadiusScale(maxRadiusScale);
  1599. #else
  1600. throw_RTCError(RTC_ERROR_INVALID_OPERATION,"min-width feature is not enabled");
  1601. #endif
  1602. RTC_CATCH_END2(geometry);
  1603. }
  1604. RTC_API void rtcSetGeometryMask (RTCGeometry hgeometry, unsigned int mask)
  1605. {
  1606. Geometry* geometry = (Geometry*) hgeometry;
  1607. RTC_CATCH_BEGIN;
  1608. RTC_TRACE(rtcSetGeometryMask);
  1609. RTC_VERIFY_HANDLE(hgeometry);
  1610. RTC_ENTER_DEVICE(hgeometry);
  1611. geometry->setMask(mask);
  1612. RTC_CATCH_END2(geometry);
  1613. }
  1614. RTC_API void rtcSetGeometrySubdivisionMode (RTCGeometry hgeometry, unsigned topologyID, RTCSubdivisionMode mode)
  1615. {
  1616. Geometry* geometry = (Geometry*) hgeometry;
  1617. RTC_CATCH_BEGIN;
  1618. RTC_TRACE(rtcSetGeometrySubdivisionMode);
  1619. RTC_VERIFY_HANDLE(hgeometry);
  1620. RTC_ENTER_DEVICE(hgeometry);
  1621. geometry->setSubdivisionMode(topologyID,mode);
  1622. RTC_CATCH_END2(geometry);
  1623. }
  1624. RTC_API void rtcSetGeometryVertexAttributeTopology(RTCGeometry hgeometry, unsigned int vertexAttributeID, unsigned int topologyID)
  1625. {
  1626. Geometry* geometry = (Geometry*) hgeometry;
  1627. RTC_CATCH_BEGIN;
  1628. RTC_TRACE(rtcSetGeometryVertexAttributeTopology);
  1629. RTC_VERIFY_HANDLE(hgeometry);
  1630. RTC_ENTER_DEVICE(hgeometry);
  1631. geometry->setVertexAttributeTopology(vertexAttributeID, topologyID);
  1632. RTC_CATCH_END2(geometry);
  1633. }
  1634. RTC_API void rtcSetGeometryBuffer(RTCGeometry hgeometry, RTCBufferType type, unsigned int slot, RTCFormat format, RTCBuffer hbuffer, size_t byteOffset, size_t byteStride, size_t itemCount)
  1635. {
  1636. Geometry* geometry = (Geometry*) hgeometry;
  1637. Ref<Buffer> buffer = (Buffer*)hbuffer;
  1638. RTC_CATCH_BEGIN;
  1639. RTC_TRACE(rtcSetGeometryBuffer);
  1640. RTC_VERIFY_HANDLE(hgeometry);
  1641. RTC_VERIFY_HANDLE(hbuffer);
  1642. RTC_ENTER_DEVICE(hgeometry);
  1643. if (geometry->device != buffer->device)
  1644. throw_RTCError(RTC_ERROR_INVALID_ARGUMENT,"inputs are from different devices");
  1645. if (itemCount > 0xFFFFFFFFu)
  1646. throw_RTCError(RTC_ERROR_INVALID_ARGUMENT,"buffer too large");
  1647. geometry->setBuffer(type, slot, format, buffer, byteOffset, byteStride, (unsigned int)itemCount);
  1648. RTC_CATCH_END2(geometry);
  1649. }
  1650. RTC_API void rtcSetSharedGeometryBuffer(RTCGeometry hgeometry, RTCBufferType type, unsigned int slot, RTCFormat format, const void* ptr, size_t byteOffset, size_t byteStride, size_t itemCount)
  1651. {
  1652. Geometry* geometry = (Geometry*) hgeometry;
  1653. RTC_CATCH_BEGIN;
  1654. RTC_TRACE(rtcSetSharedGeometryBuffer);
  1655. RTC_VERIFY_HANDLE(hgeometry);
  1656. RTC_ENTER_DEVICE(hgeometry);
  1657. if (itemCount > 0xFFFFFFFFu)
  1658. throw_RTCError(RTC_ERROR_INVALID_ARGUMENT,"buffer too large");
  1659. Ref<Buffer> buffer = new Buffer(geometry->device, itemCount*byteStride, (char*)ptr + byteOffset);
  1660. geometry->setBuffer(type, slot, format, buffer, 0, byteStride, (unsigned int)itemCount);
  1661. RTC_CATCH_END2(geometry);
  1662. }
  1663. RTC_API void rtcSetSharedGeometryBufferHostDevice(RTCGeometry hgeometry, RTCBufferType type, unsigned int slot, RTCFormat format, const void* ptr, const void* dptr, size_t byteOffset, size_t byteStride, size_t itemCount)
  1664. {
  1665. Geometry* geometry = (Geometry*) hgeometry;
  1666. RTC_CATCH_BEGIN;
  1667. RTC_TRACE(rtcSetSharedGeometryBufferHostDevice);
  1668. RTC_VERIFY_HANDLE(hgeometry);
  1669. RTC_ENTER_DEVICE(hgeometry);
  1670. #if defined(EMBREE_SYCL_SUPPORT)
  1671. if (geometry->device->is_gpu())
  1672. {
  1673. if (itemCount > 0xFFFFFFFFu)
  1674. throw_RTCError(RTC_ERROR_INVALID_ARGUMENT,"buffer too large");
  1675. if ((ptr == nullptr) || (dptr == nullptr))
  1676. throw_RTCError(RTC_ERROR_INVALID_ARGUMENT,"host and device pointer may not be NULL pointers when using SYCL devices");
  1677. Ref<Buffer> buffer = new Buffer(geometry->device, itemCount*byteStride, (char*)ptr + byteOffset, (char*)dptr + byteOffset);
  1678. geometry->setBuffer(type, slot, format, buffer, 0, byteStride, (unsigned int)itemCount);
  1679. }
  1680. else
  1681. #endif
  1682. {
  1683. if (dptr != nullptr)
  1684. throw_RTCError(RTC_ERROR_INVALID_ARGUMENT,"Embree device is no SYCL device. Device pointer argument must not be valid, pass NULL instead");
  1685. rtcSetSharedGeometryBuffer(hgeometry, type, slot, format, ptr, byteOffset, byteStride, itemCount);
  1686. }
  1687. RTC_CATCH_END2(geometry);
  1688. }
  1689. RTC_API void* rtcSetNewGeometryBuffer(RTCGeometry hgeometry, RTCBufferType type, unsigned int slot, RTCFormat format, size_t byteStride, size_t itemCount)
  1690. {
  1691. Geometry* geometry = (Geometry*) hgeometry;
  1692. RTC_CATCH_BEGIN;
  1693. RTC_TRACE(rtcSetNewGeometryBuffer);
  1694. RTC_VERIFY_HANDLE(hgeometry);
  1695. RTC_ENTER_DEVICE(hgeometry);
  1696. if (itemCount > 0xFFFFFFFFu)
  1697. throw_RTCError(RTC_ERROR_INVALID_ARGUMENT,"buffer too large");
  1698. /* vertex buffers need to get overallocated slightly as elements are accessed using SSE loads */
  1699. size_t bytes = itemCount*byteStride;
  1700. if (type == RTC_BUFFER_TYPE_VERTEX || type == RTC_BUFFER_TYPE_VERTEX_ATTRIBUTE)
  1701. bytes += (16 - (byteStride%16))%16;
  1702. Ref<Buffer> buffer = new Buffer(geometry->device, bytes, nullptr);
  1703. geometry->setBuffer(type, slot, format, buffer, 0, byteStride, (unsigned int)itemCount);
  1704. return buffer->data();
  1705. RTC_CATCH_END2(geometry);
  1706. return nullptr;
  1707. }
  1708. RTC_API void rtcSetNewGeometryBufferHostDevice(RTCGeometry hgeometry, RTCBufferType bufferType, unsigned int slot, RTCFormat format, size_t byteStride, size_t itemCount, void** ptr, void** dptr)
  1709. {
  1710. Geometry* geometry = (Geometry*) hgeometry;
  1711. RTC_CATCH_BEGIN;
  1712. RTC_TRACE(rtcSetNewGeometryBufferHostDevice);
  1713. RTC_VERIFY_HANDLE(hgeometry);
  1714. RTC_ENTER_DEVICE(hgeometry);
  1715. #if defined(EMBREE_SYCL_SUPPORT)
  1716. if (geometry->device->is_gpu())
  1717. {
  1718. if (itemCount > 0xFFFFFFFFu)
  1719. throw_RTCError(RTC_ERROR_INVALID_ARGUMENT,"buffer too large");
  1720. /* vertex buffers need to get overallocated slightly as elements are accessed using SSE loads */
  1721. size_t bytes = itemCount*byteStride;
  1722. if (bufferType == RTC_BUFFER_TYPE_VERTEX || bufferType == RTC_BUFFER_TYPE_VERTEX_ATTRIBUTE)
  1723. bytes += (16 - (byteStride%16))%16;
  1724. Ref<Buffer> buffer = new Buffer(geometry->device, bytes, nullptr, nullptr);
  1725. geometry->setBuffer(bufferType, slot, format, buffer, 0, byteStride, (unsigned int)itemCount);
  1726. if(ptr)
  1727. *ptr = buffer->getHostPtr();
  1728. if (dptr)
  1729. *dptr = buffer->getDevicePtr();
  1730. }
  1731. else
  1732. #endif
  1733. {
  1734. void* tmp = rtcSetNewGeometryBuffer(hgeometry, bufferType, slot, format, byteStride, itemCount);
  1735. if(ptr)
  1736. *ptr = tmp;
  1737. if (dptr) {
  1738. *dptr = tmp;
  1739. }
  1740. }
  1741. RTC_CATCH_END2(geometry);
  1742. }
  1743. RTC_API void* rtcGetGeometryBufferData(RTCGeometry hgeometry, RTCBufferType type, unsigned int slot)
  1744. {
  1745. Geometry* geometry = (Geometry*) hgeometry;
  1746. RTC_CATCH_BEGIN;
  1747. RTC_TRACE(rtcGetGeometryBufferData);
  1748. RTC_VERIFY_HANDLE(hgeometry);
  1749. RTC_ENTER_DEVICE(hgeometry);
  1750. return geometry->getBufferData(type, slot, BufferDataPointerType::HOST);
  1751. RTC_CATCH_END2(geometry);
  1752. return nullptr;
  1753. }
  1754. RTC_API void* rtcGetGeometryBufferDataDevice(RTCGeometry hgeometry, RTCBufferType type, unsigned int slot)
  1755. {
  1756. Geometry* geometry = (Geometry*) hgeometry;
  1757. RTC_CATCH_BEGIN;
  1758. RTC_TRACE(rtcGetGeometryBufferDataDevice);
  1759. RTC_VERIFY_HANDLE(hgeometry);
  1760. RTC_ENTER_DEVICE(hgeometry);
  1761. return geometry->getBufferData(type, slot, BufferDataPointerType::DEVICE);
  1762. RTC_CATCH_END2(geometry);
  1763. return nullptr;
  1764. }
  1765. RTC_API void rtcEnableGeometry (RTCGeometry hgeometry)
  1766. {
  1767. Geometry* geometry = (Geometry*) hgeometry;
  1768. RTC_CATCH_BEGIN;
  1769. RTC_TRACE(rtcEnableGeometry);
  1770. RTC_VERIFY_HANDLE(hgeometry);
  1771. RTC_ENTER_DEVICE(hgeometry);
  1772. geometry->enable();
  1773. RTC_CATCH_END2(geometry);
  1774. }
  1775. RTC_API void rtcUpdateGeometryBuffer (RTCGeometry hgeometry, RTCBufferType type, unsigned int slot)
  1776. {
  1777. Geometry* geometry = (Geometry*) hgeometry;
  1778. RTC_CATCH_BEGIN;
  1779. RTC_TRACE(rtcUpdateGeometryBuffer);
  1780. RTC_VERIFY_HANDLE(hgeometry);
  1781. RTC_ENTER_DEVICE(hgeometry);
  1782. geometry->updateBuffer(type, slot);
  1783. RTC_CATCH_END2(geometry);
  1784. }
  1785. RTC_API void rtcDisableGeometry (RTCGeometry hgeometry)
  1786. {
  1787. Geometry* geometry = (Geometry*) hgeometry;
  1788. RTC_CATCH_BEGIN;
  1789. RTC_TRACE(rtcDisableGeometry);
  1790. RTC_VERIFY_HANDLE(hgeometry);
  1791. RTC_ENTER_DEVICE(hgeometry);
  1792. geometry->disable();
  1793. RTC_CATCH_END2(geometry);
  1794. }
  1795. RTC_API void rtcSetGeometryTessellationRate (RTCGeometry hgeometry, float tessellationRate)
  1796. {
  1797. Geometry* geometry = (Geometry*) hgeometry;
  1798. RTC_CATCH_BEGIN;
  1799. RTC_TRACE(rtcSetGeometryTessellationRate);
  1800. RTC_VERIFY_HANDLE(hgeometry);
  1801. RTC_ENTER_DEVICE(hgeometry);
  1802. geometry->setTessellationRate(tessellationRate);
  1803. RTC_CATCH_END2(geometry);
  1804. }
  1805. RTC_API void rtcSetGeometryUserData (RTCGeometry hgeometry, void* ptr)
  1806. {
  1807. Geometry* geometry = (Geometry*) hgeometry;
  1808. RTC_CATCH_BEGIN;
  1809. RTC_TRACE(rtcSetGeometryUserData);
  1810. RTC_VERIFY_HANDLE(hgeometry);
  1811. RTC_ENTER_DEVICE(hgeometry);
  1812. geometry->setUserData(ptr);
  1813. RTC_CATCH_END2(geometry);
  1814. }
  1815. RTC_API void* rtcGetGeometryUserData (RTCGeometry hgeometry)
  1816. {
  1817. Geometry* geometry = (Geometry*) hgeometry; // no ref counting here!
  1818. RTC_CATCH_BEGIN;
  1819. RTC_TRACE(rtcGetGeometryUserData);
  1820. RTC_VERIFY_HANDLE(hgeometry);
  1821. //RTC_ENTER_DEVICE(hgeometry); // do not enable for performance reasons !
  1822. return geometry->getUserData();
  1823. RTC_CATCH_END2(geometry);
  1824. return nullptr;
  1825. }
  1826. RTC_API void* rtcGetGeometryUserDataFromScene (RTCScene hscene, unsigned int geomID)
  1827. {
  1828. Scene* scene = (Scene*) hscene;
  1829. RTC_CATCH_BEGIN;
  1830. RTC_TRACE(rtcGetGeometryUserDataFromScene);
  1831. #if defined(DEBUG)
  1832. RTC_VERIFY_HANDLE(hscene);
  1833. RTC_VERIFY_GEOMID(geomID);
  1834. #endif
  1835. //RTC_ENTER_DEVICE(hscene); // do not enable for performance reasons
  1836. return scene->get(geomID)->getUserData();
  1837. RTC_CATCH_END2(scene);
  1838. return nullptr;
  1839. }
  1840. RTC_API void* rtcGetGeometryUserDataFromTraversable (RTCTraversable htraversable, unsigned int geomID)
  1841. {
  1842. return rtcGetGeometryUserDataFromScene((RTCScene)htraversable, geomID);
  1843. }
  1844. RTC_API void rtcSetGeometryBoundsFunction (RTCGeometry hgeometry, RTCBoundsFunction bounds, void* userPtr)
  1845. {
  1846. Geometry* geometry = (Geometry*) hgeometry;
  1847. RTC_CATCH_BEGIN;
  1848. RTC_TRACE(rtcSetGeometryBoundsFunction);
  1849. RTC_VERIFY_HANDLE(hgeometry);
  1850. RTC_ENTER_DEVICE(hgeometry);
  1851. geometry->setBoundsFunction(bounds,userPtr);
  1852. RTC_CATCH_END2(geometry);
  1853. }
  1854. RTC_API void rtcSetGeometryDisplacementFunction (RTCGeometry hgeometry, RTCDisplacementFunctionN displacement)
  1855. {
  1856. Geometry* geometry = (Geometry*) hgeometry;
  1857. RTC_CATCH_BEGIN;
  1858. RTC_TRACE(rtcSetGeometryDisplacementFunction);
  1859. RTC_VERIFY_HANDLE(hgeometry);
  1860. RTC_ENTER_DEVICE(hgeometry);
  1861. geometry->setDisplacementFunction(displacement);
  1862. RTC_CATCH_END2(geometry);
  1863. }
  1864. RTC_API void rtcSetGeometryIntersectFunction (RTCGeometry hgeometry, RTCIntersectFunctionN intersect)
  1865. {
  1866. Geometry* geometry = (Geometry*) hgeometry;
  1867. RTC_CATCH_BEGIN;
  1868. RTC_TRACE(rtcSetGeometryIntersectFunction);
  1869. RTC_VERIFY_HANDLE(hgeometry);
  1870. RTC_ENTER_DEVICE(hgeometry);
  1871. geometry->setIntersectFunctionN(intersect);
  1872. RTC_CATCH_END2(geometry);
  1873. }
  1874. RTC_API void rtcSetGeometryPointQueryFunction(RTCGeometry hgeometry, RTCPointQueryFunction pointQuery)
  1875. {
  1876. Geometry* geometry = (Geometry*) hgeometry;
  1877. RTC_CATCH_BEGIN;
  1878. RTC_TRACE(rtcSetGeometryPointQueryFunction);
  1879. RTC_VERIFY_HANDLE(hgeometry);
  1880. RTC_ENTER_DEVICE(hgeometry);
  1881. geometry->setPointQueryFunction(pointQuery);
  1882. RTC_CATCH_END2(geometry);
  1883. }
  1884. RTC_API unsigned int rtcGetGeometryFirstHalfEdge(RTCGeometry hgeometry, unsigned int faceID)
  1885. {
  1886. Geometry* geometry = (Geometry*) hgeometry;
  1887. RTC_CATCH_BEGIN;
  1888. RTC_TRACE(rtcGetGeometryFirstHalfEdge);
  1889. //RTC_ENTER_DEVICE(hgeometry); // do not enable for performance reasons
  1890. return geometry->getFirstHalfEdge(faceID);
  1891. RTC_CATCH_END2(geometry);
  1892. return -1;
  1893. }
  1894. RTC_API unsigned int rtcGetGeometryFace(RTCGeometry hgeometry, unsigned int edgeID)
  1895. {
  1896. Geometry* geometry = (Geometry*) hgeometry;
  1897. RTC_CATCH_BEGIN;
  1898. RTC_TRACE(rtcGetGeometryFace);
  1899. //RTC_ENTER_DEVICE(hgeometry); // do not enable for performance reasons
  1900. return geometry->getFace(edgeID);
  1901. RTC_CATCH_END2(geometry);
  1902. return -1;
  1903. }
  1904. RTC_API unsigned int rtcGetGeometryNextHalfEdge(RTCGeometry hgeometry, unsigned int edgeID)
  1905. {
  1906. Geometry* geometry = (Geometry*) hgeometry;
  1907. RTC_CATCH_BEGIN;
  1908. RTC_TRACE(rtcGetGeometryNextHalfEdge);
  1909. //RTC_ENTER_DEVICE(hgeometry); // do not enable for performance reasons
  1910. return geometry->getNextHalfEdge(edgeID);
  1911. RTC_CATCH_END2(geometry);
  1912. return -1;
  1913. }
  1914. RTC_API unsigned int rtcGetGeometryPreviousHalfEdge(RTCGeometry hgeometry, unsigned int edgeID)
  1915. {
  1916. Geometry* geometry = (Geometry*) hgeometry;
  1917. RTC_CATCH_BEGIN;
  1918. RTC_TRACE(rtcGetGeometryPreviousHalfEdge);
  1919. //RTC_ENTER_DEVICE(hgeometry); // do not enable for performance reasons
  1920. return geometry->getPreviousHalfEdge(edgeID);
  1921. RTC_CATCH_END2(geometry);
  1922. return -1;
  1923. }
  1924. RTC_API unsigned int rtcGetGeometryOppositeHalfEdge(RTCGeometry hgeometry, unsigned int topologyID, unsigned int edgeID)
  1925. {
  1926. Geometry* geometry = (Geometry*) hgeometry;
  1927. RTC_CATCH_BEGIN;
  1928. RTC_TRACE(rtcGetGeometryOppositeHalfEdge);
  1929. //RTC_ENTER_DEVICE(hgeometry); // do not enable for performance reasons
  1930. return geometry->getOppositeHalfEdge(topologyID,edgeID);
  1931. RTC_CATCH_END2(geometry);
  1932. return -1;
  1933. }
  1934. RTC_API void rtcSetGeometryOccludedFunction (RTCGeometry hgeometry, RTCOccludedFunctionN occluded)
  1935. {
  1936. Geometry* geometry = (Geometry*) hgeometry;
  1937. RTC_CATCH_BEGIN;
  1938. RTC_TRACE(rtcSetOccludedFunctionN);
  1939. RTC_VERIFY_HANDLE(hgeometry);
  1940. RTC_ENTER_DEVICE(hgeometry);
  1941. geometry->setOccludedFunctionN(occluded);
  1942. RTC_CATCH_END2(geometry);
  1943. }
  1944. RTC_API void rtcSetGeometryIntersectFilterFunction (RTCGeometry hgeometry, RTCFilterFunctionN filter)
  1945. {
  1946. Geometry* geometry = (Geometry*) hgeometry;
  1947. RTC_CATCH_BEGIN;
  1948. RTC_TRACE(rtcSetGeometryIntersectFilterFunction);
  1949. RTC_VERIFY_HANDLE(hgeometry);
  1950. RTC_ENTER_DEVICE(hgeometry);
  1951. geometry->setIntersectionFilterFunctionN(filter);
  1952. RTC_CATCH_END2(geometry);
  1953. }
  1954. RTC_API void rtcSetGeometryOccludedFilterFunction (RTCGeometry hgeometry, RTCFilterFunctionN filter)
  1955. {
  1956. Geometry* geometry = (Geometry*) hgeometry;
  1957. RTC_CATCH_BEGIN;
  1958. RTC_TRACE(rtcSetGeometryOccludedFilterFunction);
  1959. RTC_VERIFY_HANDLE(hgeometry);
  1960. RTC_ENTER_DEVICE(hgeometry);
  1961. geometry->setOcclusionFilterFunctionN(filter);
  1962. RTC_CATCH_END2(geometry);
  1963. }
  1964. RTC_API void rtcSetGeometryEnableFilterFunctionFromArguments (RTCGeometry hgeometry, bool enable)
  1965. {
  1966. Geometry* geometry = (Geometry*) hgeometry;
  1967. RTC_CATCH_BEGIN;
  1968. RTC_TRACE(rtcSetGeometryEnableFilterFunctionFromArguments);
  1969. RTC_VERIFY_HANDLE(hgeometry);
  1970. RTC_ENTER_DEVICE(hgeometry);
  1971. geometry->enableFilterFunctionFromArguments(enable);
  1972. RTC_CATCH_END2(geometry);
  1973. }
  1974. RTC_API void rtcInterpolate(const RTCInterpolateArguments* const args)
  1975. {
  1976. Geometry* geometry = (Geometry*) args->geometry;
  1977. RTC_CATCH_BEGIN;
  1978. RTC_TRACE(rtcInterpolate);
  1979. #if defined(DEBUG)
  1980. RTC_VERIFY_HANDLE(args->geometry);
  1981. #endif
  1982. //RTC_ENTER_DEVICE(hgeometry); // do not enable for performance reasons
  1983. geometry->interpolate(args);
  1984. RTC_CATCH_END2(geometry);
  1985. }
  1986. RTC_API void rtcInterpolateN(const RTCInterpolateNArguments* const args)
  1987. {
  1988. Geometry* geometry = (Geometry*) args->geometry;
  1989. RTC_CATCH_BEGIN;
  1990. RTC_TRACE(rtcInterpolateN);
  1991. #if defined(DEBUG)
  1992. RTC_VERIFY_HANDLE(args->geometry);
  1993. #endif
  1994. // RTC_ENTER_DEVICE(hgeometry); // do not enable for performance reasons
  1995. geometry->interpolateN(args);
  1996. RTC_CATCH_END2(geometry);
  1997. }
  1998. RTC_API void rtcCommitGeometry (RTCGeometry hgeometry)
  1999. {
  2000. Geometry* geometry = (Geometry*) hgeometry;
  2001. RTC_CATCH_BEGIN;
  2002. RTC_TRACE(rtcCommitGeometry);
  2003. RTC_VERIFY_HANDLE(hgeometry);
  2004. RTC_ENTER_DEVICE(hgeometry);
  2005. return geometry->commit();
  2006. RTC_CATCH_END2(geometry);
  2007. }
  2008. RTC_API unsigned int rtcAttachGeometry (RTCScene hscene, RTCGeometry hgeometry)
  2009. {
  2010. Scene* scene = (Scene*) hscene;
  2011. Geometry* geometry = (Geometry*) hgeometry;
  2012. RTC_CATCH_BEGIN;
  2013. RTC_TRACE(rtcAttachGeometry);
  2014. RTC_VERIFY_HANDLE(hscene);
  2015. RTC_VERIFY_HANDLE(hgeometry);
  2016. RTC_ENTER_DEVICE(hgeometry);
  2017. if (scene->device != geometry->device)
  2018. throw_RTCError(RTC_ERROR_INVALID_ARGUMENT,"inputs are from different devices");
  2019. return scene->bind(RTC_INVALID_GEOMETRY_ID,geometry);
  2020. RTC_CATCH_END2(scene);
  2021. return -1;
  2022. }
  2023. RTC_API void rtcAttachGeometryByID (RTCScene hscene, RTCGeometry hgeometry, unsigned int geomID)
  2024. {
  2025. Scene* scene = (Scene*) hscene;
  2026. Geometry* geometry = (Geometry*) hgeometry;
  2027. RTC_CATCH_BEGIN;
  2028. RTC_TRACE(rtcAttachGeometryByID);
  2029. RTC_VERIFY_HANDLE(hscene);
  2030. RTC_VERIFY_HANDLE(hgeometry);
  2031. RTC_VERIFY_GEOMID(geomID);
  2032. RTC_ENTER_DEVICE(hscene);
  2033. if (scene->device != geometry->device)
  2034. throw_RTCError(RTC_ERROR_INVALID_ARGUMENT,"inputs are from different devices");
  2035. scene->bind(geomID,geometry);
  2036. RTC_CATCH_END2(scene);
  2037. }
  2038. RTC_API void rtcDetachGeometry (RTCScene hscene, unsigned int geomID)
  2039. {
  2040. Scene* scene = (Scene*) hscene;
  2041. RTC_CATCH_BEGIN;
  2042. RTC_TRACE(rtcDetachGeometry);
  2043. RTC_VERIFY_HANDLE(hscene);
  2044. RTC_VERIFY_GEOMID(geomID);
  2045. RTC_ENTER_DEVICE(hscene);
  2046. scene->detachGeometry(geomID);
  2047. RTC_CATCH_END2(scene);
  2048. }
  2049. RTC_API void rtcRetainGeometry (RTCGeometry hgeometry)
  2050. {
  2051. Geometry* geometry = (Geometry*) hgeometry;
  2052. RTC_CATCH_BEGIN;
  2053. RTC_TRACE(rtcRetainGeometry);
  2054. RTC_VERIFY_HANDLE(hgeometry);
  2055. RTC_ENTER_DEVICE(hgeometry);
  2056. geometry->refInc();
  2057. RTC_CATCH_END2(geometry);
  2058. }
  2059. RTC_API void rtcReleaseGeometry (RTCGeometry hgeometry)
  2060. {
  2061. Geometry* geometry = (Geometry*) hgeometry;
  2062. RTC_CATCH_BEGIN;
  2063. RTC_TRACE(rtcReleaseGeometry);
  2064. RTC_VERIFY_HANDLE(hgeometry);
  2065. RTC_ENTER_DEVICE(hgeometry);
  2066. geometry->refDec();
  2067. RTC_CATCH_END2(geometry);
  2068. }
  2069. RTC_API RTCGeometry rtcGetGeometry (RTCScene hscene, unsigned int geomID)
  2070. {
  2071. Scene* scene = (Scene*) hscene;
  2072. RTC_CATCH_BEGIN;
  2073. RTC_TRACE(rtcGetGeometry);
  2074. #if defined(DEBUG)
  2075. RTC_VERIFY_HANDLE(hscene);
  2076. RTC_VERIFY_GEOMID(geomID);
  2077. #endif
  2078. //RTC_ENTER_DEVICE(hscene); // do not enable for performance reasons
  2079. return (RTCGeometry) scene->get(geomID);
  2080. RTC_CATCH_END2(scene);
  2081. return nullptr;
  2082. }
  2083. RTC_API RTCGeometry rtcGetGeometryThreadSafe (RTCScene hscene, unsigned int geomID)
  2084. {
  2085. Scene* scene = (Scene*) hscene;
  2086. RTC_CATCH_BEGIN;
  2087. RTC_TRACE(rtcGetGeometryThreadSafe);
  2088. #if defined(DEBUG)
  2089. RTC_VERIFY_HANDLE(hscene);
  2090. RTC_VERIFY_GEOMID(geomID);
  2091. #endif
  2092. Ref<Geometry> geom = scene->get_locked(geomID);
  2093. return (RTCGeometry) geom.ptr;
  2094. RTC_CATCH_END2(scene);
  2095. return nullptr;
  2096. }
  2097. RTC_API const char* rtcGetErrorString(RTCError error)
  2098. {
  2099. RTC_CATCH_BEGIN;
  2100. RTC_TRACE(rtcGetErrorString);
  2101. return Device::getErrorString(error);
  2102. RTC_CATCH_END(nullptr);
  2103. return nullptr;
  2104. }
  2105. RTC_NAMESPACE_END