9#include <embree4/rtcore_geometry.h>
10#include <embree4/rtcore_ray.h>
11#include <embree4/rtcore_scene.h>
13#ifdef __KERNEL_ONEAPI__
32#ifdef __KERNEL_ONEAPI__
41#if RTC_VERSION < 40400
42# define RTCTraversable RTCScene
43# define rtcGetGeometryUserDataFromTraversable rtcGetGeometryUserDataFromScene
44# define rtcTraversableIntersect1 rtcIntersect1
45# define rtcTraversableOccluded1 rtcOccluded1
48#ifdef __KERNEL_ONEAPI__
49# define CYCLES_EMBREE_USED_FEATURES \
50 (kernel_handler.get_specialization_constant<oneapi_embree_features>())
52# define CYCLES_EMBREE_USED_FEATURES \
53 (RTCFeatureFlags)(RTC_FEATURE_FLAG_TRIANGLE | RTC_FEATURE_FLAG_INSTANCE | \
54 RTC_FEATURE_FLAG_FILTER_FUNCTION_IN_ARGUMENTS | RTC_FEATURE_FLAG_POINT | \
55 RTC_FEATURE_FLAG_MOTION_BLUR | RTC_FEATURE_FLAG_ROUND_CATMULL_ROM_CURVE | \
56 RTC_FEATURE_FLAG_FLAT_CATMULL_ROM_CURVE | \
57 RTC_FEATURE_FLAG_ROUND_LINEAR_CURVE | \
58 RTC_FEATURE_FLAG_USER_GEOMETRY_CALLBACK_IN_ARGUMENTS)
61#define EMBREE_IS_HAIR(x) (x & 1)
72#if defined(__KERNEL_ONEAPI__)
73 ONEAPIKernelContext *oneapi_kernel_context;
94#ifdef __VOLUME_RECORD_ALL__
105 const uint visibility)
107 rtc_ray.org_x = ray.
P.
x;
108 rtc_ray.org_y = ray.
P.
y;
109 rtc_ray.org_z = ray.
P.
z;
110 rtc_ray.dir_x = ray.
D.
x;
111 rtc_ray.dir_y = ray.
D.
y;
112 rtc_ray.dir_z = ray.
D.
z;
113 rtc_ray.tnear = ray.
tmin;
114 rtc_ray.tfar = ray.
tmax;
115 rtc_ray.time = ray.
time;
116 rtc_ray.mask = visibility;
121 const uint visibility)
124 rayhit.hit.geomID = RTC_INVALID_GEOMETRY_ID;
125 rayhit.hit.instID[0] = RTC_INVALID_GEOMETRY_ID;
130 return (hit->instID[0] != RTC_INVALID_GEOMETRY_ID ? hit->instID[0] : hit->geomID) / 2;
142 prim = hit->primID + prim_offset;
148 const bool is_hair = hit->geomID & 1;
164 isect->
t = ray->tfar;
165 isect->
prim = hit->primID + prim_offset;
168 const bool is_hair = hit->geomID & 1;
171 isect->
type = segment.type;
172 isect->
prim = segment.prim;
190 isect->
t = ray->tfar;
191 isect->
prim = hit->primID + prim_offset;
203 const RTCFilterFunctionNArguments *args)
208 RTCHit *hit = (RTCHit *)args->hit;
210#ifdef __KERNEL_ONEAPI__
215 const Ray *cray = ctx->
ray;
222#ifdef __SHADOW_LINKING__
231 unsigned int geom_id)
233 return ((ctx.instID[0] != RTC_INVALID_GEOMETRY_ID) ? ctx.instID[0] : geom_id) / 2;
237 const RTCIntersectFunctionNArguments *args)
240 static_assert(RTC_MAX_INSTANCE_LEVEL_COUNT == 1);
242#if defined(__GSPLATS__)
244 RTCRayHit *ray_hit = (RTCRayHit *)args->rayhit;
246# ifdef __KERNEL_ONEAPI__
252 if (!args->valid[0]) {
256 const float3 ray_P =
make_float3(ray_hit->ray.org_x, ray_hit->ray.org_y, ray_hit->ray.org_z);
257 const float3 ray_D =
make_float3(ray_hit->ray.dir_x, ray_hit->ray.dir_y, ray_hit->ray.dir_z);
261 const int prim = args->primID + prim_offset;
268 if (!gsplat_intersect_test(kg,
283 RTCHit potential_hit;
284 potential_hit.u = 0.0f;
285 potential_hit.v = 0.0f;
286 potential_hit.primID = args->primID;
287 potential_hit.geomID = args->geomID;
288 potential_hit.instID[0] = ctx->instID[0];
290 const float old_tfar = ray_hit->
ray.tfar;
291 ray_hit->ray.tfar = isect_t;
293 RTCFilterFunctionNArguments filter_args;
295 filter_args.valid = &valid;
296 filter_args.geometryUserPtr = args->geometryUserPtr;
297 filter_args.context = args->context;
298 filter_args.ray = (RTCRayN *)&ray_hit->ray;
299 filter_args.hit = (RTCHitN *)&potential_hit;
303 ray_hit->ray.tfar = old_tfar;
308 ray_hit->hit = potential_hit;
316 const RTCOccludedFunctionNArguments *args)
319 static_assert(RTC_MAX_INSTANCE_LEVEL_COUNT == 1);
321#if defined(__GSPLATS__)
322 if (!args->valid[0]) {
327 RTCRay *ray = (RTCRay *)args->ray;
328 BVHShadowAllPayload &payload = *ctx->
payload;
330# ifdef __KERNEL_ONEAPI__
341 const int prim = args->primID + prim_offset;
348 if (!gsplat_intersect(kg,
364 kg, payload.state, payload, payload.base.ray_self, 0, isect))
380 const RTCOccludedFunctionNArguments *args)
391 const RTCOccludedFunctionNArguments *args)
407 const RTCFilterFunctionNArguments *args)
412 const RTCRay *ray = (RTCRay *)args->ray;
413 const RTCHit *hit = (RTCHit *)args->hit;
416 BVHShadowAllPayload &payload = *ctx->
payload;
418#ifdef __KERNEL_ONEAPI__
428 kg, payload.state, payload, payload.base.ray_self, 0, isect))
437 const RTCFilterFunctionNArguments *args)
442 const RTCRay *ray = (RTCRay *)args->ray;
443 RTCHit *hit = (RTCHit *)args->hit;
445#ifdef __KERNEL_ONEAPI__
450 const Ray *cray = ctx->
ray;
488 if (local_isect->
hits[i].
t == ray->tfar) {
498 hit_idx = local_isect->
num_hits - 1;
514 if (local_isect->
num_hits && current_isect.
t > local_isect->
hits[0].
t) {
523 local_isect->
hits[hit_idx] = current_isect;
530 const RTCFilterFunctionNArguments *args)
535 const RTCRay *ray = (RTCRay *)args->ray;
536 RTCHit *hit = (RTCHit *)args->hit;
538#ifdef __KERNEL_ONEAPI__
543 const Ray *cray = ctx->
ray;
545#ifdef __VOLUME_RECORD_ALL__
547 if (ctx->
num_hits < ctx->max_hits) {
561 *isect = current_isect;
562#ifdef __VOLUME_RECORD_ALL__
569#ifdef __KERNEL_ONEAPI__
572kernel_embree_filter_intersection_func_static(
const RTCFilterFunctionNArguments *args)
574 RTCHit *hit = (RTCHit *)args->hit;
576 ONEAPIKernelContext *
context =
static_cast<ONEAPIKernelContext *
>(ctx->
kg);
577 context->kernel_embree_filter_intersection_func_impl(args);
581kernel_embree_filter_occluded_shadow_all_func_static(
const RTCFilterFunctionNArguments *args)
583 RTCHit *hit = (RTCHit *)args->hit;
585 ONEAPIKernelContext *
context = ctx->oneapi_kernel_context;
586 context->kernel_embree_filter_occluded_shadow_all_func_impl(args);
590kernel_embree_filter_occluded_local_func_static(
const RTCFilterFunctionNArguments *args)
592 RTCHit *hit = (RTCHit *)args->hit;
594 ONEAPIKernelContext *
context =
static_cast<ONEAPIKernelContext *
>(ctx->
kg);
595 context->kernel_embree_filter_occluded_local_func_impl(args);
599kernel_embree_filter_occluded_volume_all_func_static(
const RTCFilterFunctionNArguments *args)
601 RTCHit *hit = (RTCHit *)args->hit;
603 ONEAPIKernelContext *
context =
static_cast<ONEAPIKernelContext *
>(ctx->
kg);
604 context->kernel_embree_filter_occluded_volume_all_func_impl(args);
608kernel_embree_custom_intersection_func_static(
const RTCIntersectFunctionNArguments *args)
611 ONEAPIKernelContext *
context =
static_cast<ONEAPIKernelContext *
>(ctx->
kg);
612 context->kernel_embree_custom_intersection_func_impl(args);
616kernel_embree_custom_occluded_func_static(
const RTCOccludedFunctionNArguments *args)
619 ONEAPIKernelContext *
context = ctx->oneapi_kernel_context;
620 context->kernel_embree_custom_occluded_func_impl(args);
624kernel_embree_custom_occluded_local_func_static(
const RTCOccludedFunctionNArguments *args)
627 ONEAPIKernelContext *
context =
static_cast<ONEAPIKernelContext *
>(ctx->
kg);
628 context->kernel_embree_custom_occluded_local_func_impl(args);
632kernel_embree_custom_occluded_volume_func_static(
const RTCOccludedFunctionNArguments *args)
635 ONEAPIKernelContext *
context =
static_cast<ONEAPIKernelContext *
>(ctx->
kg);
636 context->kernel_embree_custom_occluded_volume_func_impl(args);
639# define kernel_embree_filter_intersection_func \
640 ONEAPIKernelContext::kernel_embree_filter_intersection_func_static
641# define kernel_embree_filter_occluded_shadow_all_func \
642 ONEAPIKernelContext::kernel_embree_filter_occluded_shadow_all_func_static
643# define kernel_embree_filter_occluded_local_func \
644 ONEAPIKernelContext::kernel_embree_filter_occluded_local_func_static
645# define kernel_embree_filter_occluded_volume_all_func \
646 ONEAPIKernelContext::kernel_embree_filter_occluded_volume_all_func_static
647# define kernel_embree_custom_intersection_func kernel_embree_custom_intersection_func_static
648# define kernel_embree_custom_occluded_func kernel_embree_custom_occluded_func_static
649# define kernel_embree_custom_occluded_local_func kernel_embree_custom_occluded_local_func_static
650# define kernel_embree_custom_occluded_volume_func \
651 kernel_embree_custom_occluded_volume_func_static
653# define kernel_embree_filter_intersection_func kernel_embree_filter_intersection_func_impl
654# define kernel_embree_filter_occluded_shadow_all_func \
655 kernel_embree_filter_occluded_shadow_all_func_impl
656# define kernel_embree_filter_occluded_local_func kernel_embree_filter_occluded_local_func_impl
657# define kernel_embree_filter_occluded_volume_all_func \
658 kernel_embree_filter_occluded_volume_all_func_impl
659# define kernel_embree_custom_intersection_func kernel_embree_custom_intersection_func_impl
660# define kernel_embree_custom_occluded_func kernel_embree_custom_occluded_func_impl
661# define kernel_embree_custom_occluded_local_func kernel_embree_custom_occluded_local_func_impl
662# define kernel_embree_custom_occluded_volume_func kernel_embree_custom_occluded_volume_func_impl
669 const uint visibility,
672 isect->t = ray->tmax;
674 rtcInitRayQueryContext(&ctx);
675#ifdef __KERNEL_ONEAPI__
689 RTCIntersectArguments args;
690 rtcInitIntersectArguments(&args);
696 if (ray_hit.hit.geomID == RTC_INVALID_GEOMETRY_ID ||
697 ray_hit.hit.primID == RTC_INVALID_GEOMETRY_ID)
710 const int local_object,
717 rtcInitRayQueryContext(&ctx);
718# ifdef __KERNEL_ONEAPI__
733 local_isect->num_hits = 0;
739 RTCOccludedArguments args;
740 rtcInitOccludedArguments(&args);
751# ifdef __OBJECT_MOTION__
752 bvh_instance_motion_push(kg, local_object, ray, &
P, &dir, &idir);
760 rtc_ray.dir_x = dir.
x;
761 rtc_ray.dir_y = dir.
y;
762 rtc_ray.dir_z = dir.
z;
763 rtc_ray.tnear = ray->tmin;
764 rtc_ray.tfar = ray->tmax;
777 return (local_isect && local_isect->num_hits > 0) || (rtc_ray.tfar < 0);
781#ifdef __TRANSPARENT_SHADOWS__
784 BVHShadowAllPayload &payload)
787 rtcInitRayQueryContext(&ctx);
788# if defined(__KERNEL_ONEAPI__)
789 ctx.oneapi_kernel_context =
this;
798 RTCOccludedArguments args;
799 rtcInitOccludedArguments(&args);
800 args.filter =
reinterpret_cast<RTCFilterFunctionN
>(
818 const uint visibility)
821 rtcInitRayQueryContext(&ctx);
822# ifdef __KERNEL_ONEAPI__
832# ifdef __VOLUME_RECORD_ALL__
839 RTCOccludedArguments args;
840 rtcInitOccludedArguments(&args);
841 args.occluded =
reinterpret_cast<RTCOccludedFunctionN
>(
843 args.filter =
reinterpret_cast<RTCFilterFunctionN
>(
ccl_device_inline bool intersection_skip_shadow_link(KernelGlobals kg, const ccl_ray_data RaySelfPrimitives &self, const int isect_object)
ccl_device_inline bool intersection_skip_self_shadow(const ccl_ray_data RaySelfPrimitives &self, const int object, const int prim)
ccl_device_inline bool intersection_skip_self_local(const ccl_ray_data RaySelfPrimitives &self, const int prim)
#define kernel_assert(cond)
#define ccl_device_forceinline
#define kernel_data_fetch(name, index)
#define ccl_always_inline
#define __VOLUME_RECORD_ALL__
#define ccl_device_inline
#define CCL_NAMESPACE_END
VecBase< float, D > normalize(VecOp< float, D >) RET
ccl_device_forceinline bool bvh_shadow_all_anyhit_filter(KernelGlobals kg, IntegratorShadowState state, ccl_ray_data BVHShadowAllPayload &ccl_restrict payload, const ccl_ray_data RaySelfPrimitives &ccl_restrict ray_self, const uint ray_visibility, const Intersection isect)
ccl_device_forceinline bool bvh_volume_anyhit_triangle_filter(KernelGlobals kg, const int object, const int prim, const ccl_ray_data RaySelfPrimitives &ccl_restrict ray_self, const uint ray_visibility)
#define ccl_device_intersect
#define rtcTraversableOccluded1
ccl_device_forceinline void kernel_embree_filter_occluded_local_func_impl(const RTCFilterFunctionNArguments *args)
#define CYCLES_EMBREE_USED_FEATURES
ccl_device_forceinline void kernel_embree_filter_occluded_volume_all_func_impl(const RTCFilterFunctionNArguments *args)
ccl_device_forceinline void kernel_embree_filter_occluded_shadow_all_func_impl(const RTCFilterFunctionNArguments *args)
ccl_device_forceinline void kernel_embree_custom_occluded_func_impl(const RTCOccludedFunctionNArguments *args)
ccl_device_intersect bool kernel_embree_intersect(KernelGlobals kg, const ccl_private Ray *ray, const uint visibility, ccl_private Intersection *isect)
ccl_device_inline void kernel_embree_setup_rayhit(const Ray &ray, RTCRayHit &rayhit, const uint visibility)
#define kernel_embree_filter_occluded_volume_all_func
ccl_device_inline bool kernel_embree_is_self_intersection(const KernelGlobals kg, const RTCHit *hit, const Ray *ray)
ccl_device_forceinline int custom_intersect_get_object(const RTCRayQueryContext &ctx, unsigned int geom_id)
ccl_device_forceinline void kernel_embree_custom_intersection_func_impl(const RTCIntersectFunctionNArguments *args)
#define kernel_embree_custom_occluded_func
#define kernel_embree_filter_intersection_func
#define rtcGetGeometryUserDataFromTraversable
ccl_device_forceinline void kernel_embree_custom_occluded_volume_func_impl(const RTCOccludedFunctionNArguments *args)
#define kernel_embree_custom_occluded_volume_func
#define kernel_embree_custom_intersection_func
ccl_device_inline int kernel_embree_get_hit_object(const RTCHit *hit)
#define EMBREE_IS_HAIR(x)
#define rtcTraversableIntersect1
#define kernel_embree_filter_occluded_local_func
ccl_device_forceinline void kernel_embree_custom_occluded_local_func_impl(const RTCOccludedFunctionNArguments *args)
ccl_device_inline void kernel_embree_convert_sss_hit(KernelGlobals kg, const RTCRay *ray, const RTCHit *hit, Intersection *isect, const int object)
#define kernel_embree_custom_occluded_local_func
ccl_device_forceinline void kernel_embree_filter_intersection_func_impl(const RTCFilterFunctionNArguments *args)
ccl_device_inline void kernel_embree_convert_hit(KernelGlobals kg, const RTCRay *ray, const RTCHit *hit, Intersection *isect)
#define kernel_embree_filter_occluded_shadow_all_func
ccl_device_inline void kernel_embree_setup_ray(const Ray &ray, RTCRay &rtc_ray, const uint visibility)
ccl_device_inline void bvh_instance_push(KernelGlobals kg, const int object, const ccl_private Ray *ray, ccl_private float3 *P, ccl_private float3 *dir, ccl_private float3 *idir)
@ PATH_RAY_VISIBILITY_OBJECT_ALL
@ SD_OBJECT_TRANSFORM_APPLIED
CCL_NAMESPACE_BEGIN ccl_device uint lcg_step_uint(T rng)
CCL_NAMESPACE_BEGIN ccl_device_inline float3 zero_float3()
int context(const bContext *C, const char *member, bContextDataResult *result)
LocalIntersection * local_isect
BVHShadowAllPayload * payload
Intersection hits[LOCAL_MAX_HITS]
float3 Ng[LOCAL_MAX_HITS]