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