Path: blob/master/thirdparty/embree/include/embree4/rtcore_common.h
9905 views
// Copyright 2009-2021 Intel Corporation1// SPDX-License-Identifier: Apache-2.023#pragma once45#include <stddef.h>6#include <sys/types.h>7#include <stdbool.h>89#include "rtcore_config.h"1011RTC_NAMESPACE_BEGIN1213#if defined(_WIN32)14#if defined(_M_X64) || defined(_M_ARM64)15typedef long long ssize_t;16#else17typedef int ssize_t;18#endif19#endif2021#if defined(_WIN32) && !defined(__MINGW32__)22# define RTC_ALIGN(...) __declspec(align(__VA_ARGS__))23#else24# define RTC_ALIGN(...) __attribute__((aligned(__VA_ARGS__)))25#endif2627#if !defined (RTC_DEPRECATED)28#ifdef __GNUC__29#define RTC_DEPRECATED __attribute__((deprecated))30#elif defined(_MSC_VER)31#define RTC_DEPRECATED __declspec(deprecated)32#else33#define RTC_DEPRECATED34#endif35#endif3637#if defined(_WIN32)38# define RTC_FORCEINLINE __forceinline39#else40# define RTC_FORCEINLINE inline __attribute__((always_inline))41#endif4243#if defined(__cplusplus)44# define RTC_OPTIONAL_ARGUMENT = nullptr45#else46# define RTC_OPTIONAL_ARGUMENT47#endif4849/* Invalid geometry ID */50#define RTC_INVALID_GEOMETRY_ID ((unsigned int)-1)5152/* Maximum number of time steps */53#define RTC_MAX_TIME_STEP_COUNT 1295455/* Formats of buffers and other data structures */56enum RTCFormat57{58RTC_FORMAT_UNDEFINED = 0,5960/* 8-bit unsigned integer */61RTC_FORMAT_UCHAR = 0x1001,62RTC_FORMAT_UCHAR2,63RTC_FORMAT_UCHAR3,64RTC_FORMAT_UCHAR4,6566/* 8-bit signed integer */67RTC_FORMAT_CHAR = 0x2001,68RTC_FORMAT_CHAR2,69RTC_FORMAT_CHAR3,70RTC_FORMAT_CHAR4,7172/* 16-bit unsigned integer */73RTC_FORMAT_USHORT = 0x3001,74RTC_FORMAT_USHORT2,75RTC_FORMAT_USHORT3,76RTC_FORMAT_USHORT4,7778/* 16-bit signed integer */79RTC_FORMAT_SHORT = 0x4001,80RTC_FORMAT_SHORT2,81RTC_FORMAT_SHORT3,82RTC_FORMAT_SHORT4,8384/* 32-bit unsigned integer */85RTC_FORMAT_UINT = 0x5001,86RTC_FORMAT_UINT2,87RTC_FORMAT_UINT3,88RTC_FORMAT_UINT4,8990/* 32-bit signed integer */91RTC_FORMAT_INT = 0x6001,92RTC_FORMAT_INT2,93RTC_FORMAT_INT3,94RTC_FORMAT_INT4,9596/* 64-bit unsigned integer */97RTC_FORMAT_ULLONG = 0x7001,98RTC_FORMAT_ULLONG2,99RTC_FORMAT_ULLONG3,100RTC_FORMAT_ULLONG4,101102/* 64-bit signed integer */103RTC_FORMAT_LLONG = 0x8001,104RTC_FORMAT_LLONG2,105RTC_FORMAT_LLONG3,106RTC_FORMAT_LLONG4,107108/* 32-bit float */109RTC_FORMAT_FLOAT = 0x9001,110RTC_FORMAT_FLOAT2,111RTC_FORMAT_FLOAT3,112RTC_FORMAT_FLOAT4,113RTC_FORMAT_FLOAT5,114RTC_FORMAT_FLOAT6,115RTC_FORMAT_FLOAT7,116RTC_FORMAT_FLOAT8,117RTC_FORMAT_FLOAT9,118RTC_FORMAT_FLOAT10,119RTC_FORMAT_FLOAT11,120RTC_FORMAT_FLOAT12,121RTC_FORMAT_FLOAT13,122RTC_FORMAT_FLOAT14,123RTC_FORMAT_FLOAT15,124RTC_FORMAT_FLOAT16,125126/* 32-bit float matrix (row-major order) */127RTC_FORMAT_FLOAT2X2_ROW_MAJOR = 0x9122,128RTC_FORMAT_FLOAT2X3_ROW_MAJOR = 0x9123,129RTC_FORMAT_FLOAT2X4_ROW_MAJOR = 0x9124,130RTC_FORMAT_FLOAT3X2_ROW_MAJOR = 0x9132,131RTC_FORMAT_FLOAT3X3_ROW_MAJOR = 0x9133,132RTC_FORMAT_FLOAT3X4_ROW_MAJOR = 0x9134,133RTC_FORMAT_FLOAT4X2_ROW_MAJOR = 0x9142,134RTC_FORMAT_FLOAT4X3_ROW_MAJOR = 0x9143,135RTC_FORMAT_FLOAT4X4_ROW_MAJOR = 0x9144,136137/* 32-bit float matrix (column-major order) */138RTC_FORMAT_FLOAT2X2_COLUMN_MAJOR = 0x9222,139RTC_FORMAT_FLOAT2X3_COLUMN_MAJOR = 0x9223,140RTC_FORMAT_FLOAT2X4_COLUMN_MAJOR = 0x9224,141RTC_FORMAT_FLOAT3X2_COLUMN_MAJOR = 0x9232,142RTC_FORMAT_FLOAT3X3_COLUMN_MAJOR = 0x9233,143RTC_FORMAT_FLOAT3X4_COLUMN_MAJOR = 0x9234,144RTC_FORMAT_FLOAT4X2_COLUMN_MAJOR = 0x9242,145RTC_FORMAT_FLOAT4X3_COLUMN_MAJOR = 0x9243,146RTC_FORMAT_FLOAT4X4_COLUMN_MAJOR = 0x9244,147148/* special 12-byte format for grids */149RTC_FORMAT_GRID = 0xA001,150151RTC_FORMAT_QUATERNION_DECOMPOSITION = 0xB001,152};153154/* Build quality levels */155enum RTCBuildQuality156{157RTC_BUILD_QUALITY_LOW = 0,158RTC_BUILD_QUALITY_MEDIUM = 1,159RTC_BUILD_QUALITY_HIGH = 2,160RTC_BUILD_QUALITY_REFIT = 3,161};162163/* Axis-aligned bounding box representation */164struct RTC_ALIGN(16) RTCBounds165{166float lower_x, lower_y, lower_z, align0;167float upper_x, upper_y, upper_z, align1;168};169170/* Linear axis-aligned bounding box representation */171struct RTC_ALIGN(16) RTCLinearBounds172{173struct RTCBounds bounds0;174struct RTCBounds bounds1;175};176177/* Feature flags for SYCL specialization constants */178enum RTCFeatureFlags179{180RTC_FEATURE_FLAG_NONE = 0,181182RTC_FEATURE_FLAG_MOTION_BLUR = 1 << 0,183184RTC_FEATURE_FLAG_TRIANGLE = 1 << 1,185RTC_FEATURE_FLAG_QUAD = 1 << 2,186RTC_FEATURE_FLAG_GRID = 1 << 3,187188RTC_FEATURE_FLAG_SUBDIVISION = 1 << 4,189190RTC_FEATURE_FLAG_CONE_LINEAR_CURVE = 1 << 5,191RTC_FEATURE_FLAG_ROUND_LINEAR_CURVE = 1 << 6,192RTC_FEATURE_FLAG_FLAT_LINEAR_CURVE = 1 << 7,193194RTC_FEATURE_FLAG_ROUND_BEZIER_CURVE = 1 << 8,195RTC_FEATURE_FLAG_FLAT_BEZIER_CURVE = 1 << 9,196RTC_FEATURE_FLAG_NORMAL_ORIENTED_BEZIER_CURVE = 1 << 10,197198RTC_FEATURE_FLAG_ROUND_BSPLINE_CURVE = 1 << 11,199RTC_FEATURE_FLAG_FLAT_BSPLINE_CURVE = 1 << 12,200RTC_FEATURE_FLAG_NORMAL_ORIENTED_BSPLINE_CURVE = 1 << 13,201202RTC_FEATURE_FLAG_ROUND_HERMITE_CURVE = 1 << 14,203RTC_FEATURE_FLAG_FLAT_HERMITE_CURVE = 1 << 15,204RTC_FEATURE_FLAG_NORMAL_ORIENTED_HERMITE_CURVE = 1 << 16,205206RTC_FEATURE_FLAG_ROUND_CATMULL_ROM_CURVE = 1 << 17,207RTC_FEATURE_FLAG_FLAT_CATMULL_ROM_CURVE = 1 << 18,208RTC_FEATURE_FLAG_NORMAL_ORIENTED_CATMULL_ROM_CURVE = 1 << 19,209210RTC_FEATURE_FLAG_SPHERE_POINT = 1 << 20,211RTC_FEATURE_FLAG_DISC_POINT = 1 << 21,212RTC_FEATURE_FLAG_ORIENTED_DISC_POINT = 1 << 22,213214RTC_FEATURE_FLAG_POINT =215RTC_FEATURE_FLAG_SPHERE_POINT |216RTC_FEATURE_FLAG_DISC_POINT |217RTC_FEATURE_FLAG_ORIENTED_DISC_POINT,218219RTC_FEATURE_FLAG_ROUND_CURVES =220RTC_FEATURE_FLAG_ROUND_LINEAR_CURVE |221RTC_FEATURE_FLAG_ROUND_BEZIER_CURVE |222RTC_FEATURE_FLAG_ROUND_BSPLINE_CURVE |223RTC_FEATURE_FLAG_ROUND_HERMITE_CURVE |224RTC_FEATURE_FLAG_ROUND_CATMULL_ROM_CURVE,225226RTC_FEATURE_FLAG_FLAT_CURVES =227RTC_FEATURE_FLAG_FLAT_LINEAR_CURVE |228RTC_FEATURE_FLAG_FLAT_BEZIER_CURVE |229RTC_FEATURE_FLAG_FLAT_BSPLINE_CURVE |230RTC_FEATURE_FLAG_FLAT_HERMITE_CURVE |231RTC_FEATURE_FLAG_FLAT_CATMULL_ROM_CURVE,232233RTC_FEATURE_FLAG_NORMAL_ORIENTED_CURVES =234RTC_FEATURE_FLAG_NORMAL_ORIENTED_BEZIER_CURVE |235RTC_FEATURE_FLAG_NORMAL_ORIENTED_BSPLINE_CURVE |236RTC_FEATURE_FLAG_NORMAL_ORIENTED_HERMITE_CURVE |237RTC_FEATURE_FLAG_NORMAL_ORIENTED_CATMULL_ROM_CURVE,238239RTC_FEATURE_FLAG_LINEAR_CURVES =240RTC_FEATURE_FLAG_CONE_LINEAR_CURVE |241RTC_FEATURE_FLAG_ROUND_LINEAR_CURVE |242RTC_FEATURE_FLAG_FLAT_LINEAR_CURVE,243244RTC_FEATURE_FLAG_BEZIER_CURVES =245RTC_FEATURE_FLAG_ROUND_BEZIER_CURVE |246RTC_FEATURE_FLAG_FLAT_BEZIER_CURVE |247RTC_FEATURE_FLAG_NORMAL_ORIENTED_BEZIER_CURVE,248249RTC_FEATURE_FLAG_BSPLINE_CURVES =250RTC_FEATURE_FLAG_ROUND_BSPLINE_CURVE |251RTC_FEATURE_FLAG_FLAT_BSPLINE_CURVE |252RTC_FEATURE_FLAG_NORMAL_ORIENTED_BSPLINE_CURVE,253254RTC_FEATURE_FLAG_HERMITE_CURVES =255RTC_FEATURE_FLAG_ROUND_HERMITE_CURVE |256RTC_FEATURE_FLAG_FLAT_HERMITE_CURVE |257RTC_FEATURE_FLAG_NORMAL_ORIENTED_HERMITE_CURVE,258259RTC_FEATURE_FLAG_CURVES =260RTC_FEATURE_FLAG_CONE_LINEAR_CURVE |261RTC_FEATURE_FLAG_ROUND_LINEAR_CURVE |262RTC_FEATURE_FLAG_FLAT_LINEAR_CURVE |263RTC_FEATURE_FLAG_ROUND_BEZIER_CURVE |264RTC_FEATURE_FLAG_FLAT_BEZIER_CURVE |265RTC_FEATURE_FLAG_NORMAL_ORIENTED_BEZIER_CURVE |266RTC_FEATURE_FLAG_ROUND_BSPLINE_CURVE |267RTC_FEATURE_FLAG_FLAT_BSPLINE_CURVE |268RTC_FEATURE_FLAG_NORMAL_ORIENTED_BSPLINE_CURVE |269RTC_FEATURE_FLAG_ROUND_HERMITE_CURVE |270RTC_FEATURE_FLAG_FLAT_HERMITE_CURVE |271RTC_FEATURE_FLAG_NORMAL_ORIENTED_HERMITE_CURVE |272RTC_FEATURE_FLAG_ROUND_CATMULL_ROM_CURVE |273RTC_FEATURE_FLAG_FLAT_CATMULL_ROM_CURVE |274RTC_FEATURE_FLAG_NORMAL_ORIENTED_CATMULL_ROM_CURVE,275276RTC_FEATURE_FLAG_INSTANCE = 1 << 23,277278RTC_FEATURE_FLAG_FILTER_FUNCTION_IN_ARGUMENTS = 1 << 24,279RTC_FEATURE_FLAG_FILTER_FUNCTION_IN_GEOMETRY = 1 << 25,280281RTC_FEATURE_FLAG_FILTER_FUNCTION =282RTC_FEATURE_FLAG_FILTER_FUNCTION_IN_ARGUMENTS |283RTC_FEATURE_FLAG_FILTER_FUNCTION_IN_GEOMETRY,284285RTC_FEATURE_FLAG_USER_GEOMETRY_CALLBACK_IN_ARGUMENTS = 1 << 26,286RTC_FEATURE_FLAG_USER_GEOMETRY_CALLBACK_IN_GEOMETRY = 1 << 27,287288RTC_FEATURE_FLAG_USER_GEOMETRY =289RTC_FEATURE_FLAG_USER_GEOMETRY_CALLBACK_IN_ARGUMENTS |290RTC_FEATURE_FLAG_USER_GEOMETRY_CALLBACK_IN_GEOMETRY,291292RTC_FEATURE_FLAG_32_BIT_RAY_MASK = 1 << 28,293294RTC_FEATURE_FLAG_INSTANCE_ARRAY = 1 << 29,295296RTC_FEATURE_FLAG_ALL = 0xffffffff,297};298299/* Ray query flags */300enum RTCRayQueryFlags301{302/* matching intel_ray_flags_t layout */303RTC_RAY_QUERY_FLAG_NONE = 0,304RTC_RAY_QUERY_FLAG_INVOKE_ARGUMENT_FILTER = (1 << 1), // enable argument filter for each geometry305306/* embree specific flags */307RTC_RAY_QUERY_FLAG_INCOHERENT = (0 << 16), // optimize for incoherent rays308RTC_RAY_QUERY_FLAG_COHERENT = (1 << 16), // optimize for coherent rays309};310311/* Arguments for RTCFilterFunctionN */312struct RTCFilterFunctionNArguments313{314int* valid;315void* geometryUserPtr;316struct RTCRayQueryContext* context;317struct RTCRayN* ray;318struct RTCHitN* hit;319unsigned int N;320};321322/* Filter callback function */323typedef void (*RTCFilterFunctionN)(const struct RTCFilterFunctionNArguments* args);324325/* Intersection callback function */326struct RTCIntersectFunctionNArguments;327typedef void (*RTCIntersectFunctionN)(const struct RTCIntersectFunctionNArguments* args);328329/* Occlusion callback function */330struct RTCOccludedFunctionNArguments;331typedef void (*RTCOccludedFunctionN)(const struct RTCOccludedFunctionNArguments* args);332333/* Ray query context passed to intersect/occluded calls */334struct RTCRayQueryContext335{336#if RTC_MAX_INSTANCE_LEVEL_COUNT > 1337unsigned int instStackSize; // Number of instances currently on the stack.338#endif339unsigned int instID[RTC_MAX_INSTANCE_LEVEL_COUNT]; // The current stack of instance ids.340#if defined(RTC_GEOMETRY_INSTANCE_ARRAY)341unsigned int instPrimID[RTC_MAX_INSTANCE_LEVEL_COUNT]; // The current stack of instance primitive ids.342#endif343};344345/* Initializes an ray query context. */346RTC_FORCEINLINE void rtcInitRayQueryContext(struct RTCRayQueryContext* context)347{348unsigned l = 0;349350#if RTC_MAX_INSTANCE_LEVEL_COUNT > 1351context->instStackSize = 0;352#endif353354for (; l < RTC_MAX_INSTANCE_LEVEL_COUNT; ++l) {355context->instID[l] = RTC_INVALID_GEOMETRY_ID;356#if defined(RTC_GEOMETRY_INSTANCE_ARRAY)357context->instPrimID[l] = RTC_INVALID_GEOMETRY_ID;358#endif359}360}361362/* Point query structure for closest point query */363struct RTC_ALIGN(16) RTCPointQuery364{365float x; // x coordinate of the query point366float y; // y coordinate of the query point367float z; // z coordinate of the query point368float time; // time of the point query369float radius; // radius of the point query370};371372/* Structure of a packet of 4 query points */373struct RTC_ALIGN(16) RTCPointQuery4374{375float x[4]; // x coordinate of the query point376float y[4]; // y coordinate of the query point377float z[4]; // z coordinate of the query point378float time[4]; // time of the point query379float radius[4]; // radius of the point query380};381382/* Structure of a packet of 8 query points */383struct RTC_ALIGN(32) RTCPointQuery8384{385float x[8]; // x coordinate of the query point386float y[8]; // y coordinate of the query point387float z[8]; // z coordinate of the query point388float time[8]; // time of the point query389float radius[8]; // radius ofr the point query390};391392/* Structure of a packet of 16 query points */393struct RTC_ALIGN(64) RTCPointQuery16394{395float x[16]; // x coordinate of the query point396float y[16]; // y coordinate of the query point397float z[16]; // z coordinate of the query point398float time[16]; // time of the point quey399float radius[16]; // radius of the point query400};401402struct RTCPointQueryN;403404struct RTC_ALIGN(16) RTCPointQueryContext405{406// accumulated 4x4 column major matrices from world space to instance space.407// undefined if size == 0.408float world2inst[RTC_MAX_INSTANCE_LEVEL_COUNT][16];409410// accumulated 4x4 column major matrices from instance space to world space.411// undefined if size == 0.412float inst2world[RTC_MAX_INSTANCE_LEVEL_COUNT][16];413414// instance ids.415unsigned int instID[RTC_MAX_INSTANCE_LEVEL_COUNT];416417#if defined(RTC_GEOMETRY_INSTANCE_ARRAY)418// instance prim ids.419unsigned int instPrimID[RTC_MAX_INSTANCE_LEVEL_COUNT];420#endif421422// number of instances currently on the stack.423unsigned int instStackSize;424};425426/* Initializes an ray query context. */427RTC_FORCEINLINE void rtcInitPointQueryContext(struct RTCPointQueryContext* context)428{429unsigned l = 0;430431context->instStackSize = 0;432433for (; l < RTC_MAX_INSTANCE_LEVEL_COUNT; ++l) {434context->instID[l] = RTC_INVALID_GEOMETRY_ID;435#if defined(RTC_GEOMETRY_INSTANCE_ARRAY)436context->instPrimID[l] = RTC_INVALID_GEOMETRY_ID;437#endif438}439}440441struct RTC_ALIGN(16) RTCPointQueryFunctionArguments442{443// The (world space) query object that was passed as an argument of rtcPointQuery. The444// radius of the query can be decreased inside the callback to shrink the445// search domain. Increasing the radius or modifying the time or position of446// the query results in undefined behaviour.447struct RTCPointQuery* query;448449// Used for user input/output data. Will not be read or modified internally.450void* userPtr;451452// primitive and geometry ID of primitive453unsigned int primID;454unsigned int geomID;455456// the context with transformation and instance ID stack457struct RTCPointQueryContext* context;458459// If the current instance transform M (= context->world2inst[context->instStackSize])460// is a similarity matrix, i.e there is a constant factor similarityScale such that461// for all x,y: dist(Mx, My) = similarityScale * dist(x, y),462// The similarity scale is 0, if the current instance transform is not a463// similarity transform and vice versa. The similarity scale allows to compute464// distance information in instance space and scale the distances into world465// space by dividing with the similarity scale, for example, to update the466// query radius. If the current instance transform is not a similarity467// transform (similarityScale = 0), the distance computation has to be468// performed in world space to ensure correctness. if there is no instance469// transform (context->instStackSize == 0), the similarity scale is 1.470float similarityScale;471};472473typedef bool (*RTCPointQueryFunction)(struct RTCPointQueryFunctionArguments* args);474475#if defined(EMBREE_SYCL_SUPPORT) && defined(SYCL_LANGUAGE_VERSION)476477/* returns function pointer to be usable in SYCL kernel */478template<auto F>479inline decltype(F) rtcGetSYCLDeviceFunctionPointer(sycl::queue& queue)480{481sycl::buffer<cl_ulong> fptr_buf(1);482{483auto fptr_acc = fptr_buf.get_host_access();484fptr_acc[0] = 0;485}486487queue.submit([&](sycl::handler& cgh) {488auto fptr_acc = fptr_buf.get_access<sycl::access::mode::discard_write>(cgh);489cgh.single_task([=]() {490fptr_acc[0] = reinterpret_cast<cl_ulong>(F);491});492});493queue.wait_and_throw();494495auto fptr_acc = fptr_buf.get_host_access();496return (decltype(F)) fptr_acc[0];497}498499#endif500501RTC_NAMESPACE_END502503504