rtcore_common.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502
  1. // Copyright 2009-2021 Intel Corporation
  2. // SPDX-License-Identifier: Apache-2.0
  3. #pragma once
  4. #include <stddef.h>
  5. #include <sys/types.h>
  6. #include <stdbool.h>
  7. #include "rtcore_config.h"
  8. RTC_NAMESPACE_BEGIN
  9. #if defined(_WIN32)
  10. #if defined(_M_X64) || defined(_M_ARM64)
  11. typedef long long ssize_t;
  12. #else
  13. typedef int ssize_t;
  14. #endif
  15. #endif
  16. #if defined(_WIN32) && !defined(__MINGW32__)
  17. # define RTC_ALIGN(...) __declspec(align(__VA_ARGS__))
  18. #else
  19. # define RTC_ALIGN(...) __attribute__((aligned(__VA_ARGS__)))
  20. #endif
  21. #if !defined (RTC_DEPRECATED)
  22. #ifdef __GNUC__
  23. #define RTC_DEPRECATED __attribute__((deprecated))
  24. #elif defined(_MSC_VER)
  25. #define RTC_DEPRECATED __declspec(deprecated)
  26. #else
  27. #define RTC_DEPRECATED
  28. #endif
  29. #endif
  30. #if defined(_WIN32)
  31. # define RTC_FORCEINLINE __forceinline
  32. #else
  33. # define RTC_FORCEINLINE inline __attribute__((always_inline))
  34. #endif
  35. #if defined(__cplusplus)
  36. # define RTC_OPTIONAL_ARGUMENT = nullptr
  37. #else
  38. # define RTC_OPTIONAL_ARGUMENT
  39. #endif
  40. /* Invalid geometry ID */
  41. #define RTC_INVALID_GEOMETRY_ID ((unsigned int)-1)
  42. /* Maximum number of time steps */
  43. #define RTC_MAX_TIME_STEP_COUNT 129
  44. /* Formats of buffers and other data structures */
  45. enum RTCFormat
  46. {
  47. RTC_FORMAT_UNDEFINED = 0,
  48. /* 8-bit unsigned integer */
  49. RTC_FORMAT_UCHAR = 0x1001,
  50. RTC_FORMAT_UCHAR2,
  51. RTC_FORMAT_UCHAR3,
  52. RTC_FORMAT_UCHAR4,
  53. /* 8-bit signed integer */
  54. RTC_FORMAT_CHAR = 0x2001,
  55. RTC_FORMAT_CHAR2,
  56. RTC_FORMAT_CHAR3,
  57. RTC_FORMAT_CHAR4,
  58. /* 16-bit unsigned integer */
  59. RTC_FORMAT_USHORT = 0x3001,
  60. RTC_FORMAT_USHORT2,
  61. RTC_FORMAT_USHORT3,
  62. RTC_FORMAT_USHORT4,
  63. /* 16-bit signed integer */
  64. RTC_FORMAT_SHORT = 0x4001,
  65. RTC_FORMAT_SHORT2,
  66. RTC_FORMAT_SHORT3,
  67. RTC_FORMAT_SHORT4,
  68. /* 32-bit unsigned integer */
  69. RTC_FORMAT_UINT = 0x5001,
  70. RTC_FORMAT_UINT2,
  71. RTC_FORMAT_UINT3,
  72. RTC_FORMAT_UINT4,
  73. /* 32-bit signed integer */
  74. RTC_FORMAT_INT = 0x6001,
  75. RTC_FORMAT_INT2,
  76. RTC_FORMAT_INT3,
  77. RTC_FORMAT_INT4,
  78. /* 64-bit unsigned integer */
  79. RTC_FORMAT_ULLONG = 0x7001,
  80. RTC_FORMAT_ULLONG2,
  81. RTC_FORMAT_ULLONG3,
  82. RTC_FORMAT_ULLONG4,
  83. /* 64-bit signed integer */
  84. RTC_FORMAT_LLONG = 0x8001,
  85. RTC_FORMAT_LLONG2,
  86. RTC_FORMAT_LLONG3,
  87. RTC_FORMAT_LLONG4,
  88. /* 32-bit float */
  89. RTC_FORMAT_FLOAT = 0x9001,
  90. RTC_FORMAT_FLOAT2,
  91. RTC_FORMAT_FLOAT3,
  92. RTC_FORMAT_FLOAT4,
  93. RTC_FORMAT_FLOAT5,
  94. RTC_FORMAT_FLOAT6,
  95. RTC_FORMAT_FLOAT7,
  96. RTC_FORMAT_FLOAT8,
  97. RTC_FORMAT_FLOAT9,
  98. RTC_FORMAT_FLOAT10,
  99. RTC_FORMAT_FLOAT11,
  100. RTC_FORMAT_FLOAT12,
  101. RTC_FORMAT_FLOAT13,
  102. RTC_FORMAT_FLOAT14,
  103. RTC_FORMAT_FLOAT15,
  104. RTC_FORMAT_FLOAT16,
  105. /* 32-bit float matrix (row-major order) */
  106. RTC_FORMAT_FLOAT2X2_ROW_MAJOR = 0x9122,
  107. RTC_FORMAT_FLOAT2X3_ROW_MAJOR = 0x9123,
  108. RTC_FORMAT_FLOAT2X4_ROW_MAJOR = 0x9124,
  109. RTC_FORMAT_FLOAT3X2_ROW_MAJOR = 0x9132,
  110. RTC_FORMAT_FLOAT3X3_ROW_MAJOR = 0x9133,
  111. RTC_FORMAT_FLOAT3X4_ROW_MAJOR = 0x9134,
  112. RTC_FORMAT_FLOAT4X2_ROW_MAJOR = 0x9142,
  113. RTC_FORMAT_FLOAT4X3_ROW_MAJOR = 0x9143,
  114. RTC_FORMAT_FLOAT4X4_ROW_MAJOR = 0x9144,
  115. /* 32-bit float matrix (column-major order) */
  116. RTC_FORMAT_FLOAT2X2_COLUMN_MAJOR = 0x9222,
  117. RTC_FORMAT_FLOAT2X3_COLUMN_MAJOR = 0x9223,
  118. RTC_FORMAT_FLOAT2X4_COLUMN_MAJOR = 0x9224,
  119. RTC_FORMAT_FLOAT3X2_COLUMN_MAJOR = 0x9232,
  120. RTC_FORMAT_FLOAT3X3_COLUMN_MAJOR = 0x9233,
  121. RTC_FORMAT_FLOAT3X4_COLUMN_MAJOR = 0x9234,
  122. RTC_FORMAT_FLOAT4X2_COLUMN_MAJOR = 0x9242,
  123. RTC_FORMAT_FLOAT4X3_COLUMN_MAJOR = 0x9243,
  124. RTC_FORMAT_FLOAT4X4_COLUMN_MAJOR = 0x9244,
  125. /* special 12-byte format for grids */
  126. RTC_FORMAT_GRID = 0xA001,
  127. RTC_FORMAT_QUATERNION_DECOMPOSITION = 0xB001,
  128. };
  129. /* Build quality levels */
  130. enum RTCBuildQuality
  131. {
  132. RTC_BUILD_QUALITY_LOW = 0,
  133. RTC_BUILD_QUALITY_MEDIUM = 1,
  134. RTC_BUILD_QUALITY_HIGH = 2,
  135. RTC_BUILD_QUALITY_REFIT = 3,
  136. };
  137. /* Axis-aligned bounding box representation */
  138. struct RTC_ALIGN(16) RTCBounds
  139. {
  140. float lower_x, lower_y, lower_z, align0;
  141. float upper_x, upper_y, upper_z, align1;
  142. };
  143. /* Linear axis-aligned bounding box representation */
  144. struct RTC_ALIGN(16) RTCLinearBounds
  145. {
  146. struct RTCBounds bounds0;
  147. struct RTCBounds bounds1;
  148. };
  149. /* Feature flags for SYCL specialization constants */
  150. enum RTCFeatureFlags
  151. {
  152. RTC_FEATURE_FLAG_NONE = 0,
  153. RTC_FEATURE_FLAG_MOTION_BLUR = 1 << 0,
  154. RTC_FEATURE_FLAG_TRIANGLE = 1 << 1,
  155. RTC_FEATURE_FLAG_QUAD = 1 << 2,
  156. RTC_FEATURE_FLAG_GRID = 1 << 3,
  157. RTC_FEATURE_FLAG_SUBDIVISION = 1 << 4,
  158. RTC_FEATURE_FLAG_CONE_LINEAR_CURVE = 1 << 5,
  159. RTC_FEATURE_FLAG_ROUND_LINEAR_CURVE = 1 << 6,
  160. RTC_FEATURE_FLAG_FLAT_LINEAR_CURVE = 1 << 7,
  161. RTC_FEATURE_FLAG_ROUND_BEZIER_CURVE = 1 << 8,
  162. RTC_FEATURE_FLAG_FLAT_BEZIER_CURVE = 1 << 9,
  163. RTC_FEATURE_FLAG_NORMAL_ORIENTED_BEZIER_CURVE = 1 << 10,
  164. RTC_FEATURE_FLAG_ROUND_BSPLINE_CURVE = 1 << 11,
  165. RTC_FEATURE_FLAG_FLAT_BSPLINE_CURVE = 1 << 12,
  166. RTC_FEATURE_FLAG_NORMAL_ORIENTED_BSPLINE_CURVE = 1 << 13,
  167. RTC_FEATURE_FLAG_ROUND_HERMITE_CURVE = 1 << 14,
  168. RTC_FEATURE_FLAG_FLAT_HERMITE_CURVE = 1 << 15,
  169. RTC_FEATURE_FLAG_NORMAL_ORIENTED_HERMITE_CURVE = 1 << 16,
  170. RTC_FEATURE_FLAG_ROUND_CATMULL_ROM_CURVE = 1 << 17,
  171. RTC_FEATURE_FLAG_FLAT_CATMULL_ROM_CURVE = 1 << 18,
  172. RTC_FEATURE_FLAG_NORMAL_ORIENTED_CATMULL_ROM_CURVE = 1 << 19,
  173. RTC_FEATURE_FLAG_SPHERE_POINT = 1 << 20,
  174. RTC_FEATURE_FLAG_DISC_POINT = 1 << 21,
  175. RTC_FEATURE_FLAG_ORIENTED_DISC_POINT = 1 << 22,
  176. RTC_FEATURE_FLAG_POINT =
  177. RTC_FEATURE_FLAG_SPHERE_POINT |
  178. RTC_FEATURE_FLAG_DISC_POINT |
  179. RTC_FEATURE_FLAG_ORIENTED_DISC_POINT,
  180. RTC_FEATURE_FLAG_ROUND_CURVES =
  181. RTC_FEATURE_FLAG_ROUND_LINEAR_CURVE |
  182. RTC_FEATURE_FLAG_ROUND_BEZIER_CURVE |
  183. RTC_FEATURE_FLAG_ROUND_BSPLINE_CURVE |
  184. RTC_FEATURE_FLAG_ROUND_HERMITE_CURVE |
  185. RTC_FEATURE_FLAG_ROUND_CATMULL_ROM_CURVE,
  186. RTC_FEATURE_FLAG_FLAT_CURVES =
  187. RTC_FEATURE_FLAG_FLAT_LINEAR_CURVE |
  188. RTC_FEATURE_FLAG_FLAT_BEZIER_CURVE |
  189. RTC_FEATURE_FLAG_FLAT_BSPLINE_CURVE |
  190. RTC_FEATURE_FLAG_FLAT_HERMITE_CURVE |
  191. RTC_FEATURE_FLAG_FLAT_CATMULL_ROM_CURVE,
  192. RTC_FEATURE_FLAG_NORMAL_ORIENTED_CURVES =
  193. RTC_FEATURE_FLAG_NORMAL_ORIENTED_BEZIER_CURVE |
  194. RTC_FEATURE_FLAG_NORMAL_ORIENTED_BSPLINE_CURVE |
  195. RTC_FEATURE_FLAG_NORMAL_ORIENTED_HERMITE_CURVE |
  196. RTC_FEATURE_FLAG_NORMAL_ORIENTED_CATMULL_ROM_CURVE,
  197. RTC_FEATURE_FLAG_LINEAR_CURVES =
  198. RTC_FEATURE_FLAG_CONE_LINEAR_CURVE |
  199. RTC_FEATURE_FLAG_ROUND_LINEAR_CURVE |
  200. RTC_FEATURE_FLAG_FLAT_LINEAR_CURVE,
  201. RTC_FEATURE_FLAG_BEZIER_CURVES =
  202. RTC_FEATURE_FLAG_ROUND_BEZIER_CURVE |
  203. RTC_FEATURE_FLAG_FLAT_BEZIER_CURVE |
  204. RTC_FEATURE_FLAG_NORMAL_ORIENTED_BEZIER_CURVE,
  205. RTC_FEATURE_FLAG_BSPLINE_CURVES =
  206. RTC_FEATURE_FLAG_ROUND_BSPLINE_CURVE |
  207. RTC_FEATURE_FLAG_FLAT_BSPLINE_CURVE |
  208. RTC_FEATURE_FLAG_NORMAL_ORIENTED_BSPLINE_CURVE,
  209. RTC_FEATURE_FLAG_HERMITE_CURVES =
  210. RTC_FEATURE_FLAG_ROUND_HERMITE_CURVE |
  211. RTC_FEATURE_FLAG_FLAT_HERMITE_CURVE |
  212. RTC_FEATURE_FLAG_NORMAL_ORIENTED_HERMITE_CURVE,
  213. RTC_FEATURE_FLAG_CURVES =
  214. RTC_FEATURE_FLAG_CONE_LINEAR_CURVE |
  215. RTC_FEATURE_FLAG_ROUND_LINEAR_CURVE |
  216. RTC_FEATURE_FLAG_FLAT_LINEAR_CURVE |
  217. RTC_FEATURE_FLAG_ROUND_BEZIER_CURVE |
  218. RTC_FEATURE_FLAG_FLAT_BEZIER_CURVE |
  219. RTC_FEATURE_FLAG_NORMAL_ORIENTED_BEZIER_CURVE |
  220. RTC_FEATURE_FLAG_ROUND_BSPLINE_CURVE |
  221. RTC_FEATURE_FLAG_FLAT_BSPLINE_CURVE |
  222. RTC_FEATURE_FLAG_NORMAL_ORIENTED_BSPLINE_CURVE |
  223. RTC_FEATURE_FLAG_ROUND_HERMITE_CURVE |
  224. RTC_FEATURE_FLAG_FLAT_HERMITE_CURVE |
  225. RTC_FEATURE_FLAG_NORMAL_ORIENTED_HERMITE_CURVE |
  226. RTC_FEATURE_FLAG_ROUND_CATMULL_ROM_CURVE |
  227. RTC_FEATURE_FLAG_FLAT_CATMULL_ROM_CURVE |
  228. RTC_FEATURE_FLAG_NORMAL_ORIENTED_CATMULL_ROM_CURVE,
  229. RTC_FEATURE_FLAG_INSTANCE = 1 << 23,
  230. RTC_FEATURE_FLAG_FILTER_FUNCTION_IN_ARGUMENTS = 1 << 24,
  231. RTC_FEATURE_FLAG_FILTER_FUNCTION_IN_GEOMETRY = 1 << 25,
  232. RTC_FEATURE_FLAG_FILTER_FUNCTION =
  233. RTC_FEATURE_FLAG_FILTER_FUNCTION_IN_ARGUMENTS |
  234. RTC_FEATURE_FLAG_FILTER_FUNCTION_IN_GEOMETRY,
  235. RTC_FEATURE_FLAG_USER_GEOMETRY_CALLBACK_IN_ARGUMENTS = 1 << 26,
  236. RTC_FEATURE_FLAG_USER_GEOMETRY_CALLBACK_IN_GEOMETRY = 1 << 27,
  237. RTC_FEATURE_FLAG_USER_GEOMETRY =
  238. RTC_FEATURE_FLAG_USER_GEOMETRY_CALLBACK_IN_ARGUMENTS |
  239. RTC_FEATURE_FLAG_USER_GEOMETRY_CALLBACK_IN_GEOMETRY,
  240. RTC_FEATURE_FLAG_32_BIT_RAY_MASK = 1 << 28,
  241. RTC_FEATURE_FLAG_INSTANCE_ARRAY = 1 << 29,
  242. RTC_FEATURE_FLAG_ALL = 0xffffffff,
  243. };
  244. /* Ray query flags */
  245. enum RTCRayQueryFlags
  246. {
  247. /* matching intel_ray_flags_t layout */
  248. RTC_RAY_QUERY_FLAG_NONE = 0,
  249. RTC_RAY_QUERY_FLAG_INVOKE_ARGUMENT_FILTER = (1 << 1), // enable argument filter for each geometry
  250. /* embree specific flags */
  251. RTC_RAY_QUERY_FLAG_INCOHERENT = (0 << 16), // optimize for incoherent rays
  252. RTC_RAY_QUERY_FLAG_COHERENT = (1 << 16), // optimize for coherent rays
  253. };
  254. /* Arguments for RTCFilterFunctionN */
  255. struct RTCFilterFunctionNArguments
  256. {
  257. int* valid;
  258. void* geometryUserPtr;
  259. struct RTCRayQueryContext* context;
  260. struct RTCRayN* ray;
  261. struct RTCHitN* hit;
  262. unsigned int N;
  263. };
  264. /* Filter callback function */
  265. typedef void (*RTCFilterFunctionN)(const struct RTCFilterFunctionNArguments* args);
  266. /* Intersection callback function */
  267. struct RTCIntersectFunctionNArguments;
  268. typedef void (*RTCIntersectFunctionN)(const struct RTCIntersectFunctionNArguments* args);
  269. /* Occlusion callback function */
  270. struct RTCOccludedFunctionNArguments;
  271. typedef void (*RTCOccludedFunctionN)(const struct RTCOccludedFunctionNArguments* args);
  272. /* Ray query context passed to intersect/occluded calls */
  273. struct RTCRayQueryContext
  274. {
  275. #if RTC_MAX_INSTANCE_LEVEL_COUNT > 1
  276. unsigned int instStackSize; // Number of instances currently on the stack.
  277. #endif
  278. unsigned int instID[RTC_MAX_INSTANCE_LEVEL_COUNT]; // The current stack of instance ids.
  279. #if defined(RTC_GEOMETRY_INSTANCE_ARRAY)
  280. unsigned int instPrimID[RTC_MAX_INSTANCE_LEVEL_COUNT]; // The current stack of instance primitive ids.
  281. #endif
  282. };
  283. /* Initializes an ray query context. */
  284. RTC_FORCEINLINE void rtcInitRayQueryContext(struct RTCRayQueryContext* context)
  285. {
  286. unsigned l = 0;
  287. #if RTC_MAX_INSTANCE_LEVEL_COUNT > 1
  288. context->instStackSize = 0;
  289. #endif
  290. for (; l < RTC_MAX_INSTANCE_LEVEL_COUNT; ++l) {
  291. context->instID[l] = RTC_INVALID_GEOMETRY_ID;
  292. #if defined(RTC_GEOMETRY_INSTANCE_ARRAY)
  293. context->instPrimID[l] = RTC_INVALID_GEOMETRY_ID;
  294. #endif
  295. }
  296. }
  297. /* Point query structure for closest point query */
  298. struct RTC_ALIGN(16) RTCPointQuery
  299. {
  300. float x; // x coordinate of the query point
  301. float y; // y coordinate of the query point
  302. float z; // z coordinate of the query point
  303. float time; // time of the point query
  304. float radius; // radius of the point query
  305. };
  306. /* Structure of a packet of 4 query points */
  307. struct RTC_ALIGN(16) RTCPointQuery4
  308. {
  309. float x[4]; // x coordinate of the query point
  310. float y[4]; // y coordinate of the query point
  311. float z[4]; // z coordinate of the query point
  312. float time[4]; // time of the point query
  313. float radius[4]; // radius of the point query
  314. };
  315. /* Structure of a packet of 8 query points */
  316. struct RTC_ALIGN(32) RTCPointQuery8
  317. {
  318. float x[8]; // x coordinate of the query point
  319. float y[8]; // y coordinate of the query point
  320. float z[8]; // z coordinate of the query point
  321. float time[8]; // time of the point query
  322. float radius[8]; // radius ofr the point query
  323. };
  324. /* Structure of a packet of 16 query points */
  325. struct RTC_ALIGN(64) RTCPointQuery16
  326. {
  327. float x[16]; // x coordinate of the query point
  328. float y[16]; // y coordinate of the query point
  329. float z[16]; // z coordinate of the query point
  330. float time[16]; // time of the point quey
  331. float radius[16]; // radius of the point query
  332. };
  333. struct RTCPointQueryN;
  334. struct RTC_ALIGN(16) RTCPointQueryContext
  335. {
  336. // accumulated 4x4 column major matrices from world space to instance space.
  337. // undefined if size == 0.
  338. float world2inst[RTC_MAX_INSTANCE_LEVEL_COUNT][16];
  339. // accumulated 4x4 column major matrices from instance space to world space.
  340. // undefined if size == 0.
  341. float inst2world[RTC_MAX_INSTANCE_LEVEL_COUNT][16];
  342. // instance ids.
  343. unsigned int instID[RTC_MAX_INSTANCE_LEVEL_COUNT];
  344. #if defined(RTC_GEOMETRY_INSTANCE_ARRAY)
  345. // instance prim ids.
  346. unsigned int instPrimID[RTC_MAX_INSTANCE_LEVEL_COUNT];
  347. #endif
  348. // number of instances currently on the stack.
  349. unsigned int instStackSize;
  350. };
  351. /* Initializes an ray query context. */
  352. RTC_FORCEINLINE void rtcInitPointQueryContext(struct RTCPointQueryContext* context)
  353. {
  354. unsigned l = 0;
  355. context->instStackSize = 0;
  356. for (; l < RTC_MAX_INSTANCE_LEVEL_COUNT; ++l) {
  357. context->instID[l] = RTC_INVALID_GEOMETRY_ID;
  358. #if defined(RTC_GEOMETRY_INSTANCE_ARRAY)
  359. context->instPrimID[l] = RTC_INVALID_GEOMETRY_ID;
  360. #endif
  361. }
  362. }
  363. struct RTC_ALIGN(16) RTCPointQueryFunctionArguments
  364. {
  365. // The (world space) query object that was passed as an argument of rtcPointQuery. The
  366. // radius of the query can be decreased inside the callback to shrink the
  367. // search domain. Increasing the radius or modifying the time or position of
  368. // the query results in undefined behaviour.
  369. struct RTCPointQuery* query;
  370. // Used for user input/output data. Will not be read or modified internally.
  371. void* userPtr;
  372. // primitive and geometry ID of primitive
  373. unsigned int primID;
  374. unsigned int geomID;
  375. // the context with transformation and instance ID stack
  376. struct RTCPointQueryContext* context;
  377. // If the current instance transform M (= context->world2inst[context->instStackSize])
  378. // is a similarity matrix, i.e there is a constant factor similarityScale such that
  379. // for all x,y: dist(Mx, My) = similarityScale * dist(x, y),
  380. // The similarity scale is 0, if the current instance transform is not a
  381. // similarity transform and vice versa. The similarity scale allows to compute
  382. // distance information in instance space and scale the distances into world
  383. // space by dividing with the similarity scale, for example, to update the
  384. // query radius. If the current instance transform is not a similarity
  385. // transform (similarityScale = 0), the distance computation has to be
  386. // performed in world space to ensure correctness. if there is no instance
  387. // transform (context->instStackSize == 0), the similarity scale is 1.
  388. float similarityScale;
  389. };
  390. typedef bool (*RTCPointQueryFunction)(struct RTCPointQueryFunctionArguments* args);
  391. #if defined(EMBREE_SYCL_SUPPORT) && defined(SYCL_LANGUAGE_VERSION)
  392. /* returns function pointer to be usable in SYCL kernel */
  393. template<auto F>
  394. inline decltype(F) rtcGetSYCLDeviceFunctionPointer(sycl::queue& queue)
  395. {
  396. sycl::buffer<cl_ulong> fptr_buf(1);
  397. {
  398. auto fptr_acc = fptr_buf.get_host_access();
  399. fptr_acc[0] = 0;
  400. }
  401. queue.submit([&](sycl::handler& cgh) {
  402. auto fptr_acc = fptr_buf.get_access<sycl::access::mode::discard_write>(cgh);
  403. cgh.single_task([=]() {
  404. fptr_acc[0] = reinterpret_cast<cl_ulong>(F);
  405. });
  406. });
  407. queue.wait_and_throw();
  408. auto fptr_acc = fptr_buf.get_host_access();
  409. return (decltype(F)) fptr_acc[0];
  410. }
  411. #endif
  412. RTC_NAMESPACE_END