summaryrefslogtreecommitdiffstats
path: root/thirdparty/embree/kernels/common
diff options
context:
space:
mode:
authorRémi Verschelde <rverschelde@gmail.com>2024-04-04 14:31:02 +0200
committerRémi Verschelde <rverschelde@gmail.com>2024-04-04 14:31:02 +0200
commitacfcdbd291174ea6a03ca77cf374dda9f2b300ff (patch)
treef001960b859c27dcecae15fccef5658ec528b715 /thirdparty/embree/kernels/common
parent2c65bf0d6986b420ec20393fa27f7c38f0814082 (diff)
parentc43eab55a417162624f47aed6bbbd0a4bd41c607 (diff)
downloadredot-engine-acfcdbd291174ea6a03ca77cf374dda9f2b300ff.tar.gz
Merge pull request #88783 from Chubercik/embree-4.3.1
embree: Update to 4.3.1
Diffstat (limited to 'thirdparty/embree/kernels/common')
-rw-r--r--thirdparty/embree/kernels/common/accel.h200
-rw-r--r--thirdparty/embree/kernels/common/acceln.cpp36
-rw-r--r--thirdparty/embree/kernels/common/acceln.h18
-rw-r--r--thirdparty/embree/kernels/common/accelset.h142
-rw-r--r--thirdparty/embree/kernels/common/alloc.cpp2
-rw-r--r--thirdparty/embree/kernels/common/alloc.h253
-rw-r--r--thirdparty/embree/kernels/common/buffer.h33
-rw-r--r--thirdparty/embree/kernels/common/builder.h2
-rw-r--r--thirdparty/embree/kernels/common/context.h74
-rw-r--r--thirdparty/embree/kernels/common/default.h10
-rw-r--r--thirdparty/embree/kernels/common/device.cpp228
-rw-r--r--thirdparty/embree/kernels/common/device.h121
-rw-r--r--thirdparty/embree/kernels/common/geometry.cpp14
-rw-r--r--thirdparty/embree/kernels/common/geometry.h107
-rw-r--r--thirdparty/embree/kernels/common/hit.h49
-rw-r--r--thirdparty/embree/kernels/common/instance_stack.h108
-rw-r--r--thirdparty/embree/kernels/common/point_query.h1
-rw-r--r--thirdparty/embree/kernels/common/primref.h138
-rw-r--r--thirdparty/embree/kernels/common/primref_mb.h262
-rw-r--r--thirdparty/embree/kernels/common/ray.h160
-rw-r--r--thirdparty/embree/kernels/common/rtcore.cpp1009
-rw-r--r--thirdparty/embree/kernels/common/rtcore.h61
-rw-r--r--thirdparty/embree/kernels/common/scene.cpp269
-rw-r--r--thirdparty/embree/kernels/common/scene.h98
-rw-r--r--thirdparty/embree/kernels/common/scene_curves.h90
-rw-r--r--thirdparty/embree/kernels/common/scene_grid_mesh.h186
-rw-r--r--thirdparty/embree/kernels/common/scene_instance.h46
-rw-r--r--thirdparty/embree/kernels/common/scene_instance_array.h385
-rw-r--r--thirdparty/embree/kernels/common/scene_line_segments.h301
-rw-r--r--thirdparty/embree/kernels/common/scene_points.h87
-rw-r--r--thirdparty/embree/kernels/common/scene_quad_mesh.h51
-rw-r--r--thirdparty/embree/kernels/common/scene_subdiv_mesh.h13
-rw-r--r--thirdparty/embree/kernels/common/scene_triangle_mesh.cpp2
-rw-r--r--thirdparty/embree/kernels/common/scene_triangle_mesh.h41
-rw-r--r--thirdparty/embree/kernels/common/scene_user_geometry.h23
-rw-r--r--thirdparty/embree/kernels/common/scene_verify.cpp24
-rw-r--r--thirdparty/embree/kernels/common/stat.cpp2
-rw-r--r--thirdparty/embree/kernels/common/state.cpp19
-rw-r--r--thirdparty/embree/kernels/common/state.h2
39 files changed, 3253 insertions, 1414 deletions
diff --git a/thirdparty/embree/kernels/common/accel.h b/thirdparty/embree/kernels/common/accel.h
index d24326ce92..7d959377ae 100644
--- a/thirdparty/embree/kernels/common/accel.h
+++ b/thirdparty/embree/kernels/common/accel.h
@@ -17,7 +17,7 @@ namespace embree
{
ALIGNED_CLASS_(16);
public:
- enum Type { TY_UNKNOWN = 0, TY_ACCELN = 1, TY_ACCEL_INSTANCE = 2, TY_BVH4 = 3, TY_BVH8 = 4 };
+ enum Type { TY_UNKNOWN = 0, TY_ACCELN = 1, TY_ACCEL_INSTANCE = 2, TY_BVH4 = 3, TY_BVH8 = 4, TY_GPU = 5 };
public:
AccelData (const Type type)
@@ -73,61 +73,49 @@ namespace embree
/*! Type of intersect function pointer for single rays. */
typedef void (*IntersectFunc)(Intersectors* This, /*!< this pointer to accel */
RTCRayHit& ray, /*!< ray to intersect */
- IntersectContext* context);
+ RayQueryContext* context);
/*! Type of intersect function pointer for ray packets of size 4. */
typedef void (*IntersectFunc4)(const void* valid, /*!< pointer to valid mask */
Intersectors* This, /*!< this pointer to accel */
RTCRayHit4& ray, /*!< ray packet to intersect */
- IntersectContext* context);
+ RayQueryContext* context);
/*! Type of intersect function pointer for ray packets of size 8. */
typedef void (*IntersectFunc8)(const void* valid, /*!< pointer to valid mask */
Intersectors* This, /*!< this pointer to accel */
RTCRayHit8& ray, /*!< ray packet to intersect */
- IntersectContext* context);
+ RayQueryContext* context);
/*! Type of intersect function pointer for ray packets of size 16. */
typedef void (*IntersectFunc16)(const void* valid, /*!< pointer to valid mask */
Intersectors* This, /*!< this pointer to accel */
RTCRayHit16& ray, /*!< ray packet to intersect */
- IntersectContext* context);
+ RayQueryContext* context);
- /*! Type of intersect function pointer for ray packets of size N. */
- typedef void (*IntersectFuncN)(Intersectors* This, /*!< this pointer to accel */
- RTCRayHitN** ray, /*!< ray stream to intersect */
- const size_t N, /*!< number of rays in stream */
- IntersectContext* context /*!< layout flags */);
-
-
/*! Type of occlusion function pointer for single rays. */
typedef void (*OccludedFunc) (Intersectors* This, /*!< this pointer to accel */
RTCRay& ray, /*!< ray to test occlusion */
- IntersectContext* context);
+ RayQueryContext* context);
/*! Type of occlusion function pointer for ray packets of size 4. */
typedef void (*OccludedFunc4) (const void* valid, /*!< pointer to valid mask */
Intersectors* This, /*!< this pointer to accel */
RTCRay4& ray, /*!< ray packet to test occlusion. */
- IntersectContext* context);
+ RayQueryContext* context);
/*! Type of occlusion function pointer for ray packets of size 8. */
typedef void (*OccludedFunc8) (const void* valid, /*!< pointer to valid mask */
Intersectors* This, /*!< this pointer to accel */
RTCRay8& ray, /*!< ray packet to test occlusion. */
- IntersectContext* context);
+ RayQueryContext* context);
/*! Type of occlusion function pointer for ray packets of size 16. */
typedef void (*OccludedFunc16) (const void* valid, /*!< pointer to valid mask */
Intersectors* This, /*!< this pointer to accel */
RTCRay16& ray, /*!< ray packet to test occlusion. */
- IntersectContext* context);
+ RayQueryContext* context);
- /*! Type of intersect function pointer for ray packets of size N. */
- typedef void (*OccludedFuncN)(Intersectors* This, /*!< this pointer to accel */
- RTCRayN** ray, /*!< ray stream to test occlusion */
- const size_t N, /*!< number of rays in stream */
- IntersectContext* context /*!< layout flags */);
typedef void (*ErrorFunc) ();
struct Collider
@@ -217,30 +205,13 @@ namespace embree
const char* name;
};
- struct IntersectorN
- {
- IntersectorN (ErrorFunc error = nullptr)
- : intersect((IntersectFuncN)error), occluded((OccludedFuncN)error), name(nullptr) {}
-
- IntersectorN (IntersectFuncN intersect, OccludedFuncN occluded, const char* name)
- : intersect(intersect), occluded(occluded), name(name) {}
-
- operator bool() const { return name; }
-
- public:
- static const char* type;
- IntersectFuncN intersect;
- OccludedFuncN occluded;
- const char* name;
- };
-
struct Intersectors
{
Intersectors()
- : ptr(nullptr), leafIntersector(nullptr), collider(nullptr), intersector1(nullptr), intersector4(nullptr), intersector8(nullptr), intersector16(nullptr), intersectorN(nullptr) {}
+ : ptr(nullptr), leafIntersector(nullptr), collider(nullptr), intersector1(nullptr), intersector4(nullptr), intersector8(nullptr), intersector16(nullptr) {}
Intersectors (ErrorFunc error)
- : ptr(nullptr), leafIntersector(nullptr), collider(error), intersector1(error), intersector4(error), intersector8(error), intersector16(error), intersectorN(error) {}
+ : ptr(nullptr), leafIntersector(nullptr), collider(error), intersector1(error), intersector4(error), intersector8(error), intersector16(error) {}
void print(size_t ident)
{
@@ -264,10 +235,6 @@ namespace embree
for (size_t i=0; i<ident; i++) std::cout << " ";
std::cout << "intersector16 = " << intersector16.name << std::endl;
}
- if (intersectorN.name) {
- for (size_t i=0; i<ident; i++) std::cout << " ";
- std::cout << "intersectorN = " << intersectorN.name << std::endl;
- }
}
void select(bool filter)
@@ -284,10 +251,6 @@ namespace embree
if (filter) intersector16 = intersector16_filter;
else intersector16 = intersector16_nofilter;
}
- if (intersectorN_filter) {
- if (filter) intersectorN = intersectorN_filter;
- else intersectorN = intersectorN_nofilter;
- }
}
__forceinline bool pointQuery (PointQuery* query, PointQueryContext* context) {
@@ -302,133 +265,138 @@ namespace embree
}
/*! Intersects a single ray with the scene. */
- __forceinline void intersect (RTCRayHit& ray, IntersectContext* context) {
+ __forceinline void intersect (RTCRayHit& ray, RayQueryContext* context) {
assert(intersector1.intersect);
intersector1.intersect(this,ray,context);
}
/*! Intersects a packet of 4 rays with the scene. */
- __forceinline void intersect4 (const void* valid, RTCRayHit4& ray, IntersectContext* context) {
+ __forceinline void intersect4 (const void* valid, RTCRayHit4& ray, RayQueryContext* context) {
assert(intersector4.intersect);
intersector4.intersect(valid,this,ray,context);
}
/*! Intersects a packet of 8 rays with the scene. */
- __forceinline void intersect8 (const void* valid, RTCRayHit8& ray, IntersectContext* context) {
+ __forceinline void intersect8 (const void* valid, RTCRayHit8& ray, RayQueryContext* context) {
assert(intersector8.intersect);
intersector8.intersect(valid,this,ray,context);
}
/*! Intersects a packet of 16 rays with the scene. */
- __forceinline void intersect16 (const void* valid, RTCRayHit16& ray, IntersectContext* context) {
+ __forceinline void intersect16 (const void* valid, RTCRayHit16& ray, RayQueryContext* context) {
assert(intersector16.intersect);
intersector16.intersect(valid,this,ray,context);
}
+
+ /*! Intersects a packet of 4 rays with the scene. */
+ __forceinline void intersect (const void* valid, RTCRayHit4& ray, RayQueryContext* context) {
+ assert(intersector4.intersect);
+ intersector4.intersect(valid,this,ray,context);
+ }
- /*! Intersects a stream of N rays in SOA layout with the scene. */
- __forceinline void intersectN (RTCRayHitN** rayN, const size_t N, IntersectContext* context)
- {
- assert(intersectorN.intersect);
- intersectorN.intersect(this,rayN,N,context);
+ /*! Intersects a packet of 8 rays with the scene. */
+ __forceinline void intersect (const void* valid, RTCRayHit8& ray, RayQueryContext* context) {
+ assert(intersector8.intersect);
+ intersector8.intersect(valid,this,ray,context);
+ }
+
+ /*! Intersects a packet of 16 rays with the scene. */
+ __forceinline void intersect (const void* valid, RTCRayHit16& ray, RayQueryContext* context) {
+ assert(intersector16.intersect);
+ intersector16.intersect(valid,this,ray,context);
}
#if defined(__SSE__) || defined(__ARM_NEON)
- __forceinline void intersect(const vbool4& valid, RayHitK<4>& ray, IntersectContext* context) {
+ __forceinline void intersect(const vbool4& valid, RayHitK<4>& ray, RayQueryContext* context) {
const vint<4> mask = valid.mask32();
intersect4(&mask,(RTCRayHit4&)ray,context);
}
#endif
#if defined(__AVX__)
- __forceinline void intersect(const vbool8& valid, RayHitK<8>& ray, IntersectContext* context) {
+ __forceinline void intersect(const vbool8& valid, RayHitK<8>& ray, RayQueryContext* context) {
const vint<8> mask = valid.mask32();
intersect8(&mask,(RTCRayHit8&)ray,context);
}
#endif
#if defined(__AVX512F__)
- __forceinline void intersect(const vbool16& valid, RayHitK<16>& ray, IntersectContext* context) {
+ __forceinline void intersect(const vbool16& valid, RayHitK<16>& ray, RayQueryContext* context) {
const vint<16> mask = valid.mask32();
intersect16(&mask,(RTCRayHit16&)ray,context);
}
#endif
- template<int K>
- __forceinline void intersectN (RayHitK<K>** rayN, const size_t N, IntersectContext* context)
- {
- intersectN((RTCRayHitN**)rayN,N,context);
- }
-
/*! Tests if single ray is occluded by the scene. */
- __forceinline void occluded (RTCRay& ray, IntersectContext* context) {
+ __forceinline void occluded (RTCRay& ray, RayQueryContext* context) {
assert(intersector1.occluded);
intersector1.occluded(this,ray,context);
}
/*! Tests if a packet of 4 rays is occluded by the scene. */
- __forceinline void occluded4 (const void* valid, RTCRay4& ray, IntersectContext* context) {
+ __forceinline void occluded4 (const void* valid, RTCRay4& ray, RayQueryContext* context) {
assert(intersector4.occluded);
intersector4.occluded(valid,this,ray,context);
}
/*! Tests if a packet of 8 rays is occluded by the scene. */
- __forceinline void occluded8 (const void* valid, RTCRay8& ray, IntersectContext* context) {
+ __forceinline void occluded8 (const void* valid, RTCRay8& ray, RayQueryContext* context) {
assert(intersector8.occluded);
intersector8.occluded(valid,this,ray,context);
}
/*! Tests if a packet of 16 rays is occluded by the scene. */
- __forceinline void occluded16 (const void* valid, RTCRay16& ray, IntersectContext* context) {
+ __forceinline void occluded16 (const void* valid, RTCRay16& ray, RayQueryContext* context) {
assert(intersector16.occluded);
intersector16.occluded(valid,this,ray,context);
}
+
+ /*! Tests if a packet of 4 rays is occluded by the scene. */
+ __forceinline void occluded (const void* valid, RTCRay4& ray, RayQueryContext* context) {
+ assert(intersector4.occluded);
+ intersector4.occluded(valid,this,ray,context);
+ }
- /*! Tests if a stream of N rays in SOA layout is occluded by the scene. */
- __forceinline void occludedN (RTCRayN** rayN, const size_t N, IntersectContext* context)
- {
- assert(intersectorN.occluded);
- intersectorN.occluded(this,rayN,N,context);
+ /*! Tests if a packet of 8 rays is occluded by the scene. */
+ __forceinline void occluded (const void* valid, RTCRay8& ray, RayQueryContext* context) {
+ assert(intersector8.occluded);
+ intersector8.occluded(valid,this,ray,context);
+ }
+
+ /*! Tests if a packet of 16 rays is occluded by the scene. */
+ __forceinline void occluded (const void* valid, RTCRay16& ray, RayQueryContext* context) {
+ assert(intersector16.occluded);
+ intersector16.occluded(valid,this,ray,context);
}
#if defined(__SSE__) || defined(__ARM_NEON)
- __forceinline void occluded(const vbool4& valid, RayK<4>& ray, IntersectContext* context) {
+ __forceinline void occluded(const vbool4& valid, RayK<4>& ray, RayQueryContext* context) {
const vint<4> mask = valid.mask32();
occluded4(&mask,(RTCRay4&)ray,context);
}
#endif
#if defined(__AVX__)
- __forceinline void occluded(const vbool8& valid, RayK<8>& ray, IntersectContext* context) {
+ __forceinline void occluded(const vbool8& valid, RayK<8>& ray, RayQueryContext* context) {
const vint<8> mask = valid.mask32();
occluded8(&mask,(RTCRay8&)ray,context);
}
#endif
#if defined(__AVX512F__)
- __forceinline void occluded(const vbool16& valid, RayK<16>& ray, IntersectContext* context) {
+ __forceinline void occluded(const vbool16& valid, RayK<16>& ray, RayQueryContext* context) {
const vint<16> mask = valid.mask32();
occluded16(&mask,(RTCRay16&)ray,context);
}
#endif
- template<int K>
- __forceinline void occludedN (RayK<K>** rayN, const size_t N, IntersectContext* context)
- {
- occludedN((RTCRayN**)rayN,N,context);
- }
-
/*! Tests if single ray is occluded by the scene. */
- __forceinline void intersect(RTCRay& ray, IntersectContext* context) {
+ __forceinline void intersect(RTCRay& ray, RayQueryContext* context) {
occluded(ray, context);
}
/*! Tests if a packet of K rays is occluded by the scene. */
template<int K>
- __forceinline void intersect(const vbool<K>& valid, RayK<K>& ray, IntersectContext* context) {
+ __forceinline void intersect(const vbool<K>& valid, RayK<K>& ray, RayQueryContext* context) {
occluded(valid, ray, context);
}
- /*! Tests if a packet of N rays in SOA layout is occluded by the scene. */
- template<int K>
- __forceinline void intersectN(RayK<K>** rayN, const size_t N, IntersectContext* context) {
- occludedN(rayN, N, context);
- }
public:
AccelData* ptr;
@@ -444,9 +412,6 @@ namespace embree
Intersector16 intersector16;
Intersector16 intersector16_filter;
Intersector16 intersector16_nofilter;
- IntersectorN intersectorN;
- IntersectorN intersectorN_filter;
- IntersectorN intersectorN_nofilter;
};
public:
@@ -506,51 +471,4 @@ namespace embree
(Accel::OccludedFunc16)intersector::occluded, \
TOSTRING(isa) "::" TOSTRING(symbol)); \
}
-
-#define DEFINE_INTERSECTORN(symbol,intersector) \
- Accel::IntersectorN symbol() { \
- return Accel::IntersectorN((Accel::IntersectFuncN)intersector::intersect, \
- (Accel::OccludedFuncN)intersector::occluded, \
- TOSTRING(isa) "::" TOSTRING(symbol)); \
- }
-
- /* ray stream filter interface */
- typedef void (*intersectStreamAOS_func)(Scene* scene, RTCRayHit* _rayN, const size_t N, const size_t stride, IntersectContext* context);
- typedef void (*intersectStreamAOP_func)(Scene* scene, RTCRayHit** _rayN, const size_t N, IntersectContext* context);
- typedef void (*intersectStreamSOA_func)(Scene* scene, char* rayN, const size_t N, const size_t streams, const size_t stream_offset, IntersectContext* context);
- typedef void (*intersectStreamSOP_func)(Scene* scene, const RTCRayHitNp* rayN, const size_t N, IntersectContext* context);
-
- typedef void (*occludedStreamAOS_func)(Scene* scene, RTCRay* _rayN, const size_t N, const size_t stride, IntersectContext* context);
- typedef void (*occludedStreamAOP_func)(Scene* scene, RTCRay** _rayN, const size_t N, IntersectContext* context);
- typedef void (*occludedStreamSOA_func)(Scene* scene, char* rayN, const size_t N, const size_t streams, const size_t stream_offset, IntersectContext* context);
- typedef void (*occludedStreamSOP_func)(Scene* scene, const RTCRayNp* rayN, const size_t N, IntersectContext* context);
-
- struct RayStreamFilterFuncs
- {
- RayStreamFilterFuncs()
- : intersectAOS(nullptr), intersectAOP(nullptr), intersectSOA(nullptr), intersectSOP(nullptr),
- occludedAOS(nullptr), occludedAOP(nullptr), occludedSOA(nullptr), occludedSOP(nullptr) {}
-
- RayStreamFilterFuncs(void (*ptr) ())
- : intersectAOS((intersectStreamAOS_func) ptr), intersectAOP((intersectStreamAOP_func) ptr), intersectSOA((intersectStreamSOA_func) ptr), intersectSOP((intersectStreamSOP_func) ptr),
- occludedAOS((occludedStreamAOS_func) ptr), occludedAOP((occludedStreamAOP_func) ptr), occludedSOA((occludedStreamSOA_func) ptr), occludedSOP((occludedStreamSOP_func) ptr) {}
-
- RayStreamFilterFuncs(intersectStreamAOS_func intersectAOS, intersectStreamAOP_func intersectAOP, intersectStreamSOA_func intersectSOA, intersectStreamSOP_func intersectSOP,
- occludedStreamAOS_func occludedAOS, occludedStreamAOP_func occludedAOP, occludedStreamSOA_func occludedSOA, occludedStreamSOP_func occludedSOP)
- : intersectAOS(intersectAOS), intersectAOP(intersectAOP), intersectSOA(intersectSOA), intersectSOP(intersectSOP),
- occludedAOS(occludedAOS), occludedAOP(occludedAOP), occludedSOA(occludedSOA), occludedSOP(occludedSOP) {}
-
- public:
- intersectStreamAOS_func intersectAOS;
- intersectStreamAOP_func intersectAOP;
- intersectStreamSOA_func intersectSOA;
- intersectStreamSOP_func intersectSOP;
-
- occludedStreamAOS_func occludedAOS;
- occludedStreamAOP_func occludedAOP;
- occludedStreamSOA_func occludedSOA;
- occludedStreamSOP_func occludedSOP;
- };
-
- typedef RayStreamFilterFuncs (*RayStreamFilterFuncsType)();
}
diff --git a/thirdparty/embree/kernels/common/acceln.cpp b/thirdparty/embree/kernels/common/acceln.cpp
index 111c62083d..9edb684db7 100644
--- a/thirdparty/embree/kernels/common/acceln.cpp
+++ b/thirdparty/embree/kernels/common/acceln.cpp
@@ -3,7 +3,7 @@
#include "acceln.h"
#include "ray.h"
-#include "../../include/embree3/rtcore_ray.h"
+#include "../../include/embree4/rtcore_ray.h"
#include "../../common/algorithms/parallel_for.h"
namespace embree
@@ -41,7 +41,7 @@ namespace embree
return changed;
}
- void AccelN::intersect (Accel::Intersectors* This_in, RTCRayHit& ray, IntersectContext* context)
+ void AccelN::intersect (Accel::Intersectors* This_in, RTCRayHit& ray, RayQueryContext* context)
{
AccelN* This = (AccelN*)This_in->ptr;
for (size_t i=0; i<This->accels.size(); i++)
@@ -49,7 +49,7 @@ namespace embree
This->accels[i]->intersectors.intersect(ray,context);
}
- void AccelN::intersect4 (const void* valid, Accel::Intersectors* This_in, RTCRayHit4& ray, IntersectContext* context)
+ void AccelN::intersect4 (const void* valid, Accel::Intersectors* This_in, RTCRayHit4& ray, RayQueryContext* context)
{
AccelN* This = (AccelN*)This_in->ptr;
for (size_t i=0; i<This->accels.size(); i++)
@@ -57,7 +57,7 @@ namespace embree
This->accels[i]->intersectors.intersect4(valid,ray,context);
}
- void AccelN::intersect8 (const void* valid, Accel::Intersectors* This_in, RTCRayHit8& ray, IntersectContext* context)
+ void AccelN::intersect8 (const void* valid, Accel::Intersectors* This_in, RTCRayHit8& ray, RayQueryContext* context)
{
AccelN* This = (AccelN*)This_in->ptr;
for (size_t i=0; i<This->accels.size(); i++)
@@ -65,7 +65,7 @@ namespace embree
This->accels[i]->intersectors.intersect8(valid,ray,context);
}
- void AccelN::intersect16 (const void* valid, Accel::Intersectors* This_in, RTCRayHit16& ray, IntersectContext* context)
+ void AccelN::intersect16 (const void* valid, Accel::Intersectors* This_in, RTCRayHit16& ray, RayQueryContext* context)
{
AccelN* This = (AccelN*)This_in->ptr;
for (size_t i=0; i<This->accels.size(); i++)
@@ -73,15 +73,7 @@ namespace embree
This->accels[i]->intersectors.intersect16(valid,ray,context);
}
- void AccelN::intersectN (Accel::Intersectors* This_in, RTCRayHitN** ray, const size_t N, IntersectContext* context)
- {
- AccelN* This = (AccelN*)This_in->ptr;
- for (size_t i=0; i<This->accels.size(); i++)
- if (!This->accels[i]->isEmpty())
- This->accels[i]->intersectors.intersectN(ray,N,context);
- }
-
- void AccelN::occluded (Accel::Intersectors* This_in, RTCRay& ray, IntersectContext* context)
+ void AccelN::occluded (Accel::Intersectors* This_in, RTCRay& ray, RayQueryContext* context)
{
AccelN* This = (AccelN*)This_in->ptr;
for (size_t i=0; i<This->accels.size(); i++) {
@@ -91,7 +83,7 @@ namespace embree
}
}
- void AccelN::occluded4 (const void* valid, Accel::Intersectors* This_in, RTCRay4& ray, IntersectContext* context)
+ void AccelN::occluded4 (const void* valid, Accel::Intersectors* This_in, RTCRay4& ray, RayQueryContext* context)
{
AccelN* This = (AccelN*)This_in->ptr;
for (size_t i=0; i<This->accels.size(); i++) {
@@ -105,7 +97,7 @@ namespace embree
}
}
- void AccelN::occluded8 (const void* valid, Accel::Intersectors* This_in, RTCRay8& ray, IntersectContext* context)
+ void AccelN::occluded8 (const void* valid, Accel::Intersectors* This_in, RTCRay8& ray, RayQueryContext* context)
{
AccelN* This = (AccelN*)This_in->ptr;
for (size_t i=0; i<This->accels.size(); i++) {
@@ -121,7 +113,7 @@ namespace embree
}
}
- void AccelN::occluded16 (const void* valid, Accel::Intersectors* This_in, RTCRay16& ray, IntersectContext* context)
+ void AccelN::occluded16 (const void* valid, Accel::Intersectors* This_in, RTCRay16& ray, RayQueryContext* context)
{
AccelN* This = (AccelN*)This_in->ptr;
for (size_t i=0; i<This->accels.size(); i++) {
@@ -141,15 +133,6 @@ namespace embree
}
}
- void AccelN::occludedN (Accel::Intersectors* This_in, RTCRayN** ray, const size_t N, IntersectContext* context)
- {
- AccelN* This = (AccelN*)This_in->ptr;
- size_t M = N;
- for (size_t i=0; i<This->accels.size(); i++)
- if (!This->accels[i]->isEmpty())
- This->accels[i]->intersectors.occludedN(ray,M,context);
- }
-
void AccelN::accels_print(size_t ident)
{
for (size_t i=0; i<accels.size(); i++)
@@ -201,7 +184,6 @@ namespace embree
intersectors.intersector4 = Intersector4(&intersect4,&occluded4,valid4 ? "AccelN::intersector4" : nullptr);
intersectors.intersector8 = Intersector8(&intersect8,&occluded8,valid8 ? "AccelN::intersector8" : nullptr);
intersectors.intersector16 = Intersector16(&intersect16,&occluded16,valid16 ? "AccelN::intersector16": nullptr);
- intersectors.intersectorN = IntersectorN(&intersectN,&occludedN,"AccelN::intersectorN");
/*! calculate bounds */
bounds = empty;
diff --git a/thirdparty/embree/kernels/common/acceln.h b/thirdparty/embree/kernels/common/acceln.h
index 0445b2e811..cc3406826c 100644
--- a/thirdparty/embree/kernels/common/acceln.h
+++ b/thirdparty/embree/kernels/common/acceln.h
@@ -22,18 +22,16 @@ namespace embree
static bool pointQuery (Accel::Intersectors* This, PointQuery* query, PointQueryContext* context);
public:
- static void intersect (Accel::Intersectors* This, RTCRayHit& ray, IntersectContext* context);
- static void intersect4 (const void* valid, Accel::Intersectors* This, RTCRayHit4& ray, IntersectContext* context);
- static void intersect8 (const void* valid, Accel::Intersectors* This, RTCRayHit8& ray, IntersectContext* context);
- static void intersect16 (const void* valid, Accel::Intersectors* This, RTCRayHit16& ray, IntersectContext* context);
- static void intersectN (Accel::Intersectors* This, RTCRayHitN** ray, const size_t N, IntersectContext* context);
+ static void intersect (Accel::Intersectors* This, RTCRayHit& ray, RayQueryContext* context);
+ static void intersect4 (const void* valid, Accel::Intersectors* This, RTCRayHit4& ray, RayQueryContext* context);
+ static void intersect8 (const void* valid, Accel::Intersectors* This, RTCRayHit8& ray, RayQueryContext* context);
+ static void intersect16 (const void* valid, Accel::Intersectors* This, RTCRayHit16& ray, RayQueryContext* context);
public:
- static void occluded (Accel::Intersectors* This, RTCRay& ray, IntersectContext* context);
- static void occluded4 (const void* valid, Accel::Intersectors* This, RTCRay4& ray, IntersectContext* context);
- static void occluded8 (const void* valid, Accel::Intersectors* This, RTCRay8& ray, IntersectContext* context);
- static void occluded16 (const void* valid, Accel::Intersectors* This, RTCRay16& ray, IntersectContext* context);
- static void occludedN (Accel::Intersectors* This, RTCRayN** ray, const size_t N, IntersectContext* context);
+ static void occluded (Accel::Intersectors* This, RTCRay& ray, RayQueryContext* context);
+ static void occluded4 (const void* valid, Accel::Intersectors* This, RTCRay4& ray, RayQueryContext* context);
+ static void occluded8 (const void* valid, Accel::Intersectors* This, RTCRay8& ray, RayQueryContext* context);
+ static void occluded16 (const void* valid, Accel::Intersectors* This, RTCRay16& ray, RayQueryContext* context);
public:
void accels_print(size_t ident);
diff --git a/thirdparty/embree/kernels/common/accelset.h b/thirdparty/embree/kernels/common/accelset.h
index 1b67120c97..f78830e397 100644
--- a/thirdparty/embree/kernels/common/accelset.h
+++ b/thirdparty/embree/kernels/common/accelset.h
@@ -17,11 +17,15 @@ namespace embree
struct IntersectFunctionNArguments : public RTCIntersectFunctionNArguments
{
Geometry* geometry;
+ RTCScene forward_scene;
+ RTCIntersectArguments* args;
};
struct OccludedFunctionNArguments : public RTCOccludedFunctionNArguments
{
Geometry* geometry;
+ RTCScene forward_scene;
+ RTCIntersectArguments* args;
};
/*! Base class for set of acceleration structures. */
@@ -138,10 +142,9 @@ namespace embree
public:
/*! Intersects a single ray with the scene. */
- __forceinline void intersect (RayHit& ray, unsigned int geomID, unsigned int primID, IntersectContext* context)
+ __forceinline bool intersect (RayHit& ray, unsigned int geomID, unsigned int primID, RayQueryContext* context)
{
assert(primID < size());
- assert(intersectorN.intersect);
int mask = -1;
IntersectFunctionNArguments args;
@@ -153,17 +156,94 @@ namespace embree
args.geomID = geomID;
args.primID = primID;
args.geometry = this;
+ args.forward_scene = nullptr;
+ args.args = context->args;
+
+ IntersectFuncN intersectFunc = nullptr;
+ intersectFunc = intersectorN.intersect;
- intersectorN.intersect(&args);
+ if (context->getIntersectFunction())
+ intersectFunc = context->getIntersectFunction();
+
+ assert(intersectFunc);
+ intersectFunc(&args);
+
+ return mask != 0;
}
/*! Tests if single ray is occluded by the scene. */
- __forceinline void occluded (Ray& ray, unsigned int geomID, unsigned int primID, IntersectContext* context)
+ __forceinline bool occluded (Ray& ray, unsigned int geomID, unsigned int primID, RayQueryContext* context)
{
assert(primID < size());
- assert(intersectorN.occluded);
+
+ int mask = -1;
+ OccludedFunctionNArguments args;
+ args.valid = &mask;
+ args.geometryUserPtr = userPtr;
+ args.context = context->user;
+ args.ray = (RTCRayN*)&ray;
+ args.N = 1;
+ args.geomID = geomID;
+ args.primID = primID;
+ args.geometry = this;
+ args.forward_scene = nullptr;
+ args.args = context->args;
+
+ OccludedFuncN occludedFunc = nullptr;
+ occludedFunc = intersectorN.occluded;
+
+ if (context->getOccludedFunction())
+ occludedFunc = context->getOccludedFunction();
+
+ assert(occludedFunc);
+ occludedFunc(&args);
+
+ return mask != 0;
+ }
+
+ /*! Intersects a single ray with the scene. */
+ __forceinline bool intersect (RayHit& ray, unsigned int geomID, unsigned int primID, RayQueryContext* context, RTCScene& forward_scene)
+ {
+ assert(primID < size());
int mask = -1;
+ IntersectFunctionNArguments args;
+ args.valid = &mask;
+ args.geometryUserPtr = userPtr;
+ args.context = context->user;
+ args.rayhit = (RTCRayHitN*)&ray;
+ args.N = 1;
+ args.geomID = geomID;
+ args.primID = primID;
+ args.geometry = this;
+ args.forward_scene = nullptr;
+ args.args = nullptr;
+
+ typedef void (*RTCIntersectFunctionSYCL)(const void* args);
+ RTCIntersectFunctionSYCL intersectFunc = nullptr;
+
+#if EMBREE_SYCL_GEOMETRY_CALLBACK
+ if (context->args->feature_mask & RTC_FEATURE_FLAG_USER_GEOMETRY_CALLBACK_IN_GEOMETRY)
+ intersectFunc = (RTCIntersectFunctionSYCL) intersectorN.intersect;
+#endif
+
+ if (context->args->feature_mask & RTC_FEATURE_FLAG_USER_GEOMETRY_CALLBACK_IN_ARGUMENTS)
+ if (context->getIntersectFunction())
+ intersectFunc = (RTCIntersectFunctionSYCL) context->getIntersectFunction();
+
+ if (intersectFunc)
+ intersectFunc(&args);
+
+ forward_scene = args.forward_scene;
+ return mask != 0;
+ }
+
+ /*! Tests if single ray is occluded by the scene. */
+ __forceinline bool occluded (Ray& ray, unsigned int geomID, unsigned int primID, RayQueryContext* context, RTCScene& forward_scene)
+ {
+ assert(primID < size());
+
+ int mask = -1;
OccludedFunctionNArguments args;
args.valid = &mask;
args.geometryUserPtr = userPtr;
@@ -173,16 +253,33 @@ namespace embree
args.geomID = geomID;
args.primID = primID;
args.geometry = this;
+ args.forward_scene = nullptr;
+ args.args = nullptr;
+
+ typedef void (*RTCOccludedFunctionSYCL)(const void* args);
+ RTCOccludedFunctionSYCL occludedFunc = nullptr;
+
+#if EMBREE_SYCL_GEOMETRY_CALLBACK
+ if (context->args->feature_mask & RTC_FEATURE_FLAG_USER_GEOMETRY_CALLBACK_IN_GEOMETRY)
+ occludedFunc = (RTCOccludedFunctionSYCL) intersectorN.occluded;
+#endif
+
+ if (context->args->feature_mask & RTC_FEATURE_FLAG_USER_GEOMETRY_CALLBACK_IN_ARGUMENTS)
+ if (context->getOccludedFunction())
+ occludedFunc = (RTCOccludedFunctionSYCL) context->getOccludedFunction();
+
+ if (occludedFunc)
+ occludedFunc(&args);
- intersectorN.occluded(&args);
+ forward_scene = args.forward_scene;
+ return mask != 0;
}
-
+
/*! Intersects a packet of K rays with the scene. */
template<int K>
- __forceinline void intersect (const vbool<K>& valid, RayHitK<K>& ray, unsigned int geomID, unsigned int primID, IntersectContext* context)
+ __forceinline void intersect (const vbool<K>& valid, RayHitK<K>& ray, unsigned int geomID, unsigned int primID, RayQueryContext* context)
{
assert(primID < size());
- assert(intersectorN.intersect);
vint<K> mask = valid.mask32();
IntersectFunctionNArguments args;
@@ -194,16 +291,24 @@ namespace embree
args.geomID = geomID;
args.primID = primID;
args.geometry = this;
-
- intersectorN.intersect(&args);
+ args.forward_scene = nullptr;
+ args.args = context->args;
+
+ IntersectFuncN intersectFunc = nullptr;
+ intersectFunc = intersectorN.intersect;
+
+ if (context->getIntersectFunction())
+ intersectFunc = context->getIntersectFunction();
+
+ assert(intersectFunc);
+ intersectFunc(&args);
}
/*! Tests if a packet of K rays is occluded by the scene. */
template<int K>
- __forceinline void occluded (const vbool<K>& valid, RayK<K>& ray, unsigned int geomID, unsigned int primID, IntersectContext* context)
+ __forceinline void occluded (const vbool<K>& valid, RayK<K>& ray, unsigned int geomID, unsigned int primID, RayQueryContext* context)
{
assert(primID < size());
- assert(intersectorN.occluded);
vint<K> mask = valid.mask32();
OccludedFunctionNArguments args;
@@ -215,8 +320,17 @@ namespace embree
args.geomID = geomID;
args.primID = primID;
args.geometry = this;
+ args.forward_scene = nullptr;
+ args.args = context->args;
+
+ OccludedFuncN occludedFunc = nullptr;
+ occludedFunc = intersectorN.occluded;
- intersectorN.occluded(&args);
+ if (context->getOccludedFunction())
+ occludedFunc = context->getOccludedFunction();
+
+ assert(occludedFunc);
+ occludedFunc(&args);
}
public:
diff --git a/thirdparty/embree/kernels/common/alloc.cpp b/thirdparty/embree/kernels/common/alloc.cpp
index 38a76225f4..cc2f9976f2 100644
--- a/thirdparty/embree/kernels/common/alloc.cpp
+++ b/thirdparty/embree/kernels/common/alloc.cpp
@@ -10,7 +10,7 @@
namespace embree
{
__thread FastAllocator::ThreadLocal2* FastAllocator::thread_local_allocator2 = nullptr;
- SpinLock FastAllocator::s_thread_local_allocators_lock;
+ MutexSys FastAllocator::s_thread_local_allocators_lock;
std::vector<std::unique_ptr<FastAllocator::ThreadLocal2>> FastAllocator::s_thread_local_allocators;
struct fast_allocator_regression_test : public RegressionTest
diff --git a/thirdparty/embree/kernels/common/alloc.h b/thirdparty/embree/kernels/common/alloc.h
index 12769df2c8..840d48c327 100644
--- a/thirdparty/embree/kernels/common/alloc.h
+++ b/thirdparty/embree/kernels/common/alloc.h
@@ -6,11 +6,9 @@
#include "default.h"
#include "device.h"
#include "scene.h"
-#include "primref.h"
+#include "../builders/primref.h"
-#if defined(APPLE) && defined(__aarch64__)
-#include <mutex>
-#endif
+#include "../../common/tasking/taskscheduler.h"
namespace embree
{
@@ -18,7 +16,7 @@ namespace embree
{
/*! maximum supported alignment */
static const size_t maxAlignment = 64;
-
+
/*! maximum allocation size */
/* default settings */
@@ -39,14 +37,14 @@ namespace embree
public:
/*! Constructor for usage with ThreadLocalData */
- __forceinline ThreadLocal (ThreadLocal2* parent)
- : parent(parent), ptr(nullptr), cur(0), end(0), allocBlockSize(0), bytesUsed(0), bytesWasted(0) {}
+ __forceinline ThreadLocal (ThreadLocal2* parent)
+ : parent(parent), ptr(nullptr), cur(0), end(0), allocBlockSize(0), bytesUsed(0), bytesWasted(0) {}
/*! initialize allocator */
- void init(FastAllocator* alloc)
+ void init(FastAllocator* alloc)
{
ptr = nullptr;
- cur = end = 0;
+ cur = end = 0;
bytesUsed = 0;
bytesWasted = 0;
allocBlockSize = 0;
@@ -54,64 +52,62 @@ namespace embree
}
/* Allocate aligned memory from the threads memory block. */
- __forceinline void* malloc(FastAllocator* alloc, size_t bytes, size_t align = 16)
+ __forceinline void* malloc(FastAllocator* alloc, size_t bytes, size_t align = 16)
{
/* bind the thread local allocator to the proper FastAllocator*/
parent->bind(alloc);
assert(align <= maxAlignment);
- bytesUsed += bytes;
+ bytesUsed += bytes;
/* try to allocate in local block */
- size_t ofs = (align - cur) & (align-1);
+ size_t ofs = (align - cur) & (align-1);
cur += bytes + ofs;
if (likely(cur <= end)) { bytesWasted += ofs; return &ptr[cur - bytes]; }
- cur -= bytes + ofs;
-
+ cur -= bytes + ofs;
+
/* if allocation is too large allocate with parent allocator */
if (4*bytes > allocBlockSize) {
return alloc->malloc(bytes,maxAlignment,false);
- }
+ }
/* get new partial block if allocation failed */
size_t blockSize = allocBlockSize;
ptr = (char*) alloc->malloc(blockSize,maxAlignment,true);
- bytesWasted += end-cur;
- cur = 0; end = blockSize;
+ bytesWasted += end-cur;
+ cur = 0; end = blockSize;
/* retry allocation */
- ofs = (align - cur) & (align-1);
+ ofs = (align - cur) & (align-1);
cur += bytes + ofs;
if (likely(cur <= end)) { bytesWasted += ofs; return &ptr[cur - bytes]; }
- cur -= bytes + ofs;
+ cur -= bytes + ofs;
/* get new full block if allocation failed */
blockSize = allocBlockSize;
ptr = (char*) alloc->malloc(blockSize,maxAlignment,false);
- bytesWasted += end-cur;
- cur = 0; end = blockSize;
+ bytesWasted += end-cur;
+ cur = 0; end = blockSize;
/* retry allocation */
- ofs = (align - cur) & (align-1);
+ ofs = (align - cur) & (align-1);
cur += bytes + ofs;
if (likely(cur <= end)) { bytesWasted += ofs; return &ptr[cur - bytes]; }
- cur -= bytes + ofs;
+ cur -= bytes + ofs;
/* should never happen as large allocations get handled specially above */
assert(false);
return nullptr;
}
-
- /*! returns amount of used bytes */
__forceinline size_t getUsedBytes() const { return bytesUsed; }
-
+
/*! returns amount of free bytes */
__forceinline size_t getFreeBytes() const { return end-cur; }
-
+
/*! returns amount of wasted bytes */
__forceinline size_t getWastedBytes() const { return bytesWasted; }
-
+
private:
ThreadLocal2* parent;
char* ptr; //!< pointer to memory block
@@ -136,11 +132,7 @@ namespace embree
{
assert(alloc_i);
if (alloc.load() == alloc_i) return;
-#if defined(APPLE) && defined(__aarch64__)
- std::scoped_lock lock(mutex);
-#else
- Lock<SpinLock> lock(mutex);
-#endif
+ Lock<MutexSys> lock(mutex);
//if (alloc.load() == alloc_i) return; // not required as only one thread calls bind
if (alloc.load()) {
alloc.load()->bytesUsed += alloc0.getUsedBytes() + alloc1.getUsedBytes();
@@ -158,11 +150,7 @@ namespace embree
{
assert(alloc_i);
if (alloc.load() != alloc_i) return;
-#if defined(APPLE) && defined(__aarch64__)
- std::scoped_lock lock(mutex);
-#else
- Lock<SpinLock> lock(mutex);
-#endif
+ Lock<MutexSys> lock(mutex);
if (alloc.load() != alloc_i) return; // required as a different thread calls unbind
alloc.load()->bytesUsed += alloc0.getUsedBytes() + alloc1.getUsedBytes();
alloc.load()->bytesFree += alloc0.getFreeBytes() + alloc1.getFreeBytes();
@@ -173,26 +161,47 @@ namespace embree
}
public:
-#if defined(APPLE) && defined(__aarch64__)
- std::mutex mutex;
-#else
- SpinLock mutex; //!< required as unbind is called from other threads
-#endif
+ MutexSys mutex;
std::atomic<FastAllocator*> alloc; //!< parent allocator
ThreadLocal alloc0;
ThreadLocal alloc1;
};
- FastAllocator (Device* device, bool osAllocation)
- : device(device), slotMask(0), usedBlocks(nullptr), freeBlocks(nullptr), use_single_mode(false), defaultBlockSize(PAGE_SIZE), estimatedSize(0),
- growSize(PAGE_SIZE), maxGrowSize(maxAllocationSize), log2_grow_size_scale(0), bytesUsed(0), bytesFree(0), bytesWasted(0), atype(osAllocation ? EMBREE_OS_MALLOC : ALIGNED_MALLOC),
- primrefarray(device,0)
+ FastAllocator (Device* device,
+ bool osAllocation,
+ bool useUSM = false,
+ bool blockAllocation = true)
+ : device(device)
+ , slotMask(0)
+ , defaultBlockSize(PAGE_SIZE)
+ , estimatedSize(0)
+ , growSize(PAGE_SIZE)
+ , maxGrowSize(maxAllocationSize)
+ , usedBlocks(nullptr)
+ , freeBlocks(nullptr)
+ , useUSM(useUSM)
+ , blockAllocation(blockAllocation)
+ , use_single_mode(false)
+ , log2_grow_size_scale(0)
+ , bytesUsed(0)
+ , bytesFree(0)
+ , bytesWasted(0)
+ , atype(osAllocation ? EMBREE_OS_MALLOC : ALIGNED_MALLOC)
+ , primrefarray(device,0)
{
+ // -- GODOT start --
+ // if (osAllocation && useUSM)
+ // throw std::runtime_error("USM allocation cannot be combined with OS allocation.");
+ if (osAllocation && useUSM) {
+ abort();
+ }
+ // -- GODOT end --
+
for (size_t i=0; i<MAX_THREAD_USED_BLOCK_SLOTS; i++)
{
threadUsedBlocks[i] = nullptr;
threadBlocks[i] = nullptr;
- assert(!slotMutex[i].isLocked());
+ //assert(!slotMutex[i].isLocked());
}
}
@@ -233,11 +242,7 @@ namespace embree
ThreadLocal2* alloc = thread_local_allocator2;
if (alloc == nullptr) {
thread_local_allocator2 = alloc = new ThreadLocal2;
-#if defined(APPLE) && defined(__aarch64__)
- std::scoped_lock lock(s_thread_local_allocators_lock);
-#else
- Lock<SpinLock> lock(s_thread_local_allocators_lock);
-#endif
+ Lock<MutexSys> lock(s_thread_local_allocators_lock);
s_thread_local_allocators.push_back(make_unique(alloc));
}
return alloc;
@@ -247,11 +252,7 @@ namespace embree
__forceinline void join(ThreadLocal2* alloc)
{
-#if defined(APPLE) && defined(__aarch64__)
- std::scoped_lock lock(s_thread_local_allocators_lock);
-#else
- Lock<SpinLock> lock(thread_local_allocators_lock);
-#endif
+ Lock<MutexSys> lock(s_thread_local_allocators_lock);
thread_local_allocators.push_back(alloc);
}
@@ -412,7 +413,7 @@ namespace embree
slotMask = MAX_THREAD_USED_BLOCK_SLOTS-1; // FIXME: remove
if (usedBlocks.load() || freeBlocks.load()) { reset(); return; }
if (bytesReserve == 0) bytesReserve = bytesAllocate;
- freeBlocks = Block::create(device,bytesAllocate,bytesReserve,nullptr,atype);
+ freeBlocks = Block::create(device,useUSM,bytesAllocate,bytesReserve,nullptr,atype);
estimatedSize = bytesEstimate;
initGrowSizeAndNumSlots(bytesEstimate,true);
}
@@ -478,8 +479,8 @@ namespace embree
bytesUsed.store(0);
bytesFree.store(0);
bytesWasted.store(0);
- if (usedBlocks.load() != nullptr) usedBlocks.load()->clear_list(device); usedBlocks = nullptr;
- if (freeBlocks.load() != nullptr) freeBlocks.load()->clear_list(device); freeBlocks = nullptr;
+ if (usedBlocks.load() != nullptr) usedBlocks.load()->clear_list(device,useUSM); usedBlocks = nullptr;
+ if (freeBlocks.load() != nullptr) freeBlocks.load()->clear_list(device,useUSM); freeBlocks = nullptr;
for (size_t i=0; i<MAX_THREAD_USED_BLOCK_SLOTS; i++) {
threadUsedBlocks[i] = nullptr;
threadBlocks[i] = nullptr;
@@ -503,9 +504,16 @@ namespace embree
/* allocate using current block */
size_t threadID = TaskScheduler::threadID();
size_t slot = threadID & slotMask;
- Block* myUsedBlocks = threadUsedBlocks[slot];
+ Block* myUsedBlocks = threadUsedBlocks[slot];
if (myUsedBlocks) {
void* ptr = myUsedBlocks->malloc(device,bytes,align,partial);
+ // -- GODOT start --
+ // if (ptr == nullptr && !blockAllocation)
+ // throw std::bad_alloc();
+ if (ptr == nullptr && !blockAllocation) {
+ abort();
+ }
+ // -- GODOT end --
if (ptr) return ptr;
}
@@ -516,16 +524,12 @@ namespace embree
/* parallel block creation in case of no freeBlocks, avoids single global mutex */
if (likely(freeBlocks.load() == nullptr))
{
-#if defined(APPLE) && defined(__aarch64__)
- std::scoped_lock lock(slotMutex[slot]);
-#else
- Lock<SpinLock> lock(slotMutex[slot]);
-#endif
+ Lock<MutexSys> lock(slotMutex[slot]);
if (myUsedBlocks == threadUsedBlocks[slot]) {
const size_t alignedBytes = (bytes+(align-1)) & ~(align-1);
const size_t allocSize = max(min(growSize,maxGrowSize),alignedBytes);
assert(allocSize >= bytes);
- threadBlocks[slot] = threadUsedBlocks[slot] = Block::create(device,allocSize,allocSize,threadBlocks[slot],atype); // FIXME: a large allocation might throw away a block here!
+ threadBlocks[slot] = threadUsedBlocks[slot] = Block::create(device,useUSM,allocSize,allocSize,threadBlocks[slot],atype); // FIXME: a large allocation might throw away a block here!
// FIXME: a direct allocation should allocate inside the block here, and not in the next loop! a different thread could do some allocation and make the large allocation fail.
}
continue;
@@ -533,24 +537,20 @@ namespace embree
/* if this fails allocate new block */
{
-#if defined(APPLE) && defined(__aarch64__)
- std::scoped_lock lock(mutex);
-#else
- Lock<SpinLock> lock(mutex);
-#endif
- if (myUsedBlocks == threadUsedBlocks[slot])
- {
+ Lock<MutexSys> lock(mutex);
+ if (myUsedBlocks == threadUsedBlocks[slot])
+ {
if (freeBlocks.load() != nullptr) {
- Block* nextFreeBlock = freeBlocks.load()->next;
- freeBlocks.load()->next = usedBlocks;
- __memory_barrier();
- usedBlocks = freeBlocks.load();
+ Block* nextFreeBlock = freeBlocks.load()->next;
+ freeBlocks.load()->next = usedBlocks;
+ __memory_barrier();
+ usedBlocks = freeBlocks.load();
threadUsedBlocks[slot] = freeBlocks.load();
- freeBlocks = nextFreeBlock;
- } else {
+ freeBlocks = nextFreeBlock;
+ } else {
const size_t allocSize = min(growSize*incGrowSizeScale(),maxGrowSize);
- usedBlocks = threadUsedBlocks[slot] = Block::create(device,allocSize,allocSize,usedBlocks,atype); // FIXME: a large allocation should get delivered directly, like above!
- }
+ usedBlocks = threadUsedBlocks[slot] = Block::create(device,useUSM,allocSize,allocSize,usedBlocks,atype); // FIXME: a large allocation should get delivered directly, like above!
+ }
}
}
}
@@ -559,11 +559,7 @@ namespace embree
/*! add new block */
void addBlock(void* ptr, ssize_t bytes)
{
-#if defined(APPLE) && defined(__aarch64__)
- std::scoped_lock lock(mutex);
-#else
- Lock<SpinLock> lock(mutex);
-#endif
+ Lock<MutexSys> lock(mutex);
const size_t sizeof_Header = offsetof(Block,data[0]);
void* aptr = (void*) ((((size_t)ptr)+maxAlignment-1) & ~(maxAlignment-1));
size_t ofs = (size_t) aptr - (size_t) ptr;
@@ -723,7 +719,12 @@ namespace embree
void print_blocks()
{
- std::cout << " estimatedSize = " << estimatedSize << ", slotMask = " << slotMask << ", use_single_mode = " << use_single_mode << ", maxGrowSize = " << maxGrowSize << ", defaultBlockSize = " << defaultBlockSize << std::endl;
+ std::cout << " estimatedSize = " << estimatedSize
+ << ", slotMask = " << slotMask
+ << ", use_single_mode = " << use_single_mode
+ << ", maxGrowSize = " << maxGrowSize
+ << ", defaultBlockSize = " << defaultBlockSize
+ << std::endl;
std::cout << " used blocks = ";
if (usedBlocks.load() != nullptr) usedBlocks.load()->print_list();
@@ -738,7 +739,19 @@ namespace embree
struct Block
{
- static Block* create(MemoryMonitorInterface* device, size_t bytesAllocate, size_t bytesReserve, Block* next, AllocationType atype)
+ __forceinline static void* blockAlignedMalloc(Device* device, bool useUSM, size_t bytesAllocate, size_t bytesAlignment)
+ {
+ if (useUSM) return device->malloc(bytesAllocate, bytesAlignment);
+ else return alignedMalloc (bytesAllocate, bytesAlignment);
+ }
+
+ __forceinline static void blockAlignedFree(Device* device, bool useUSM, void* ptr)
+ {
+ if (useUSM) return device->free(ptr);
+ else return alignedFree(ptr);
+ }
+
+ static Block* create(Device* device, bool useUSM, size_t bytesAllocate, size_t bytesReserve, Block* next, AllocationType atype)
{
/* We avoid using os_malloc for small blocks as this could
* cause a risk of fragmenting the virtual address space and
@@ -766,7 +779,7 @@ namespace embree
{
const size_t alignment = maxAlignment;
if (device) device->memoryMonitor(bytesAllocate+alignment,false);
- ptr = alignedMalloc(bytesAllocate,alignment);
+ ptr = blockAlignedMalloc(device,useUSM,bytesAllocate,alignment);
/* give hint to transparently convert these pages to 2MB pages */
const size_t ptr_aligned_begin = ((size_t)ptr) & ~size_t(PAGE_SIZE_2M-1);
@@ -780,7 +793,7 @@ namespace embree
{
const size_t alignment = maxAlignment;
if (device) device->memoryMonitor(bytesAllocate+alignment,false);
- ptr = alignedMalloc(bytesAllocate,alignment);
+ ptr = blockAlignedMalloc(device,useUSM,bytesAllocate,alignment);
return new (ptr) Block(ALIGNED_MALLOC,bytesAllocate-sizeof_Header,bytesAllocate-sizeof_Header,next,alignment);
}
}
@@ -812,23 +825,23 @@ namespace embree
return head;
}
- void clear_list(MemoryMonitorInterface* device)
+ void clear_list(Device* device, bool useUSM)
{
Block* block = this;
while (block) {
Block* next = block->next;
- block->clear_block(device);
+ block->clear_block(device, useUSM);
block = next;
}
}
- void clear_block (MemoryMonitorInterface* device)
+ void clear_block (Device* device, bool useUSM)
{
const size_t sizeof_Header = offsetof(Block,data[0]);
const ssize_t sizeof_Alloced = wasted+sizeof_Header+getBlockAllocatedBytes();
if (atype == ALIGNED_MALLOC) {
- alignedFree(this);
+ blockAlignedFree(device, useUSM, this);
if (device) device->memoryMonitor(-sizeof_Alloced,true);
}
@@ -847,16 +860,16 @@ namespace embree
size_t bytes = bytes_in;
assert(align <= maxAlignment);
bytes = (bytes+(align-1)) & ~(align-1);
- if (unlikely(cur+bytes > reserveEnd && !partial)) return nullptr;
- const size_t i = cur.fetch_add(bytes);
+ if (unlikely(cur+bytes > reserveEnd && !partial)) return nullptr;
+ const size_t i = cur.fetch_add(bytes);
if (unlikely(i+bytes > reserveEnd && !partial)) return nullptr;
if (unlikely(i > reserveEnd)) return nullptr;
bytes_in = bytes = min(bytes,reserveEnd-i);
-
- if (i+bytes > allocEnd) {
+
+ if (i+bytes > allocEnd) {
if (device) device->memoryMonitor(i+bytes-max(i,allocEnd),true);
}
- return &data[i];
+ return &data[i];
}
void* ptr() {
@@ -874,7 +887,7 @@ namespace embree
}
size_t getBlockFreeBytes() const {
- return getBlockAllocatedBytes() - getBlockUsedBytes();
+ return getBlockAllocatedBytes() - getBlockUsedBytes();
}
size_t getBlockAllocatedBytes() const {
@@ -963,40 +976,40 @@ namespace embree
char data[1]; //!< here starts memory to use for allocations
};
+ public:
+ static const size_t blockHeaderSize = offsetof(Block,data[0]);
+
private:
Device* device;
- SpinLock mutex;
size_t slotMask;
+ size_t defaultBlockSize;
+ size_t estimatedSize;
+ size_t growSize;
+ size_t maxGrowSize;
+
+ MutexSys mutex;
+ MutexSys slotMutex[MAX_THREAD_USED_BLOCK_SLOTS];
std::atomic<Block*> threadUsedBlocks[MAX_THREAD_USED_BLOCK_SLOTS];
+ std::atomic<Block*> threadBlocks[MAX_THREAD_USED_BLOCK_SLOTS];
std::atomic<Block*> usedBlocks;
std::atomic<Block*> freeBlocks;
- std::atomic<Block*> threadBlocks[MAX_THREAD_USED_BLOCK_SLOTS];
-#if defined(APPLE) && defined(__aarch64__)
- std::mutex slotMutex[MAX_THREAD_USED_BLOCK_SLOTS];
-#else
- PaddedSpinLock slotMutex[MAX_THREAD_USED_BLOCK_SLOTS];
-#endif
-
+ bool useUSM;
+ bool blockAllocation = true;
bool use_single_mode;
- size_t defaultBlockSize;
- size_t estimatedSize;
- size_t growSize;
- size_t maxGrowSize;
+
std::atomic<size_t> log2_grow_size_scale; //!< log2 of scaling factor for grow size // FIXME: remove
std::atomic<size_t> bytesUsed;
std::atomic<size_t> bytesFree;
std::atomic<size_t> bytesWasted;
+
static __thread ThreadLocal2* thread_local_allocator2;
- static SpinLock s_thread_local_allocators_lock;
+ static MutexSys s_thread_local_allocators_lock;
static std::vector<std::unique_ptr<ThreadLocal2>> s_thread_local_allocators;
-#if defined(APPLE) && defined(__aarch64__)
- std::mutex thread_local_allocators_lock;
-#else
- SpinLock thread_local_allocators_lock;
-#endif
+
std::vector<ThreadLocal2*> thread_local_allocators;
AllocationType atype;
+
mvector<PrimRef> primrefarray; //!< primrefarray used to allocate nodes
};
}
diff --git a/thirdparty/embree/kernels/common/buffer.h b/thirdparty/embree/kernels/common/buffer.h
index 793012c04d..831f5815e8 100644
--- a/thirdparty/embree/kernels/common/buffer.h
+++ b/thirdparty/embree/kernels/common/buffer.h
@@ -13,8 +13,8 @@ namespace embree
{
public:
/*! Buffer construction */
- Buffer()
- : device(nullptr), ptr(nullptr), numBytes(0), shared(false) {}
+ //Buffer()
+ //: device(nullptr), ptr(nullptr), numBytes(0), shared(false) {}
/*! Buffer construction */
Buffer(Device* device, size_t numBytes_in, void* ptr_in = nullptr)
@@ -77,19 +77,17 @@ namespace embree
/*! allocated buffer */
void alloc()
{
- if (device)
- device->memoryMonitor(this->bytes(), false);
+ device->memoryMonitor(this->bytes(), false);
size_t b = (this->bytes()+15) & ssize_t(-16);
- ptr = (char*)alignedMalloc(b,16);
+ ptr = (char*)device->malloc(b,16);
}
/*! frees the buffer */
void free()
{
if (shared) return;
- alignedFree(ptr);
- if (device)
- device->memoryMonitor(-ssize_t(this->bytes()), true);
+ device->free(ptr);
+ device->memoryMonitor(-ssize_t(this->bytes()), true);
ptr = nullptr;
}
@@ -246,6 +244,24 @@ namespace embree
public:
typedef Vec3fa value_type;
+#if defined(EMBREE_SYCL_SUPPORT) && defined(__SYCL_DEVICE_ONLY__)
+
+ /*! access to the ith element of the buffer */
+ __forceinline const Vec3fa operator [](size_t i) const
+ {
+ assert(i<num);
+ return Vec3fa::loadu(ptr_ofs + i*stride);
+ }
+
+ /*! writes the i'th element */
+ __forceinline void store(size_t i, const Vec3fa& v)
+ {
+ assert(i<num);
+ Vec3fa::storeu(ptr_ofs + i*stride, v);
+ }
+
+#else
+
/*! access to the ith element of the buffer */
__forceinline const Vec3fa operator [](size_t i) const
{
@@ -259,5 +275,6 @@ namespace embree
assert(i<num);
vfloat4::storeu((float*)(ptr_ofs + i*stride), (vfloat4)v);
}
+#endif
};
}
diff --git a/thirdparty/embree/kernels/common/builder.h b/thirdparty/embree/kernels/common/builder.h
index 07fe7b069b..4f6a226810 100644
--- a/thirdparty/embree/kernels/common/builder.h
+++ b/thirdparty/embree/kernels/common/builder.h
@@ -7,7 +7,7 @@
#include "accel.h"
namespace embree
-{
+{
#define MODE_HIGH_QUALITY (1<<8)
/*! virtual interface for all hierarchy builders */
diff --git a/thirdparty/embree/kernels/common/context.h b/thirdparty/embree/kernels/common/context.h
index ccd88bdeac..936d03e54d 100644
--- a/thirdparty/embree/kernels/common/context.h
+++ b/thirdparty/embree/kernels/common/context.h
@@ -11,35 +11,62 @@ namespace embree
{
class Scene;
- struct IntersectContext
+ struct RayQueryContext
{
public:
- __forceinline IntersectContext(Scene* scene, RTCIntersectContext* user_context)
- : scene(scene), user(user_context) {}
+
+ __forceinline RayQueryContext(Scene* scene, RTCRayQueryContext* user_context, RTCIntersectArguments* args)
+ : scene(scene), user(user_context), args(args) {}
+
+ __forceinline RayQueryContext(Scene* scene, RTCRayQueryContext* user_context, RTCOccludedArguments* args)
+ : scene(scene), user(user_context), args((RTCIntersectArguments*)args) {}
__forceinline bool hasContextFilter() const {
- return user->filter != nullptr;
+ return args->filter != nullptr;
+ }
+
+ RTCFilterFunctionN getFilter() const {
+ return args->filter;
+ }
+
+ RTCIntersectFunctionN getIntersectFunction() const {
+ return args->intersect;
+ }
+
+ RTCOccludedFunctionN getOccludedFunction() const {
+ return (RTCOccludedFunctionN) args->intersect;
}
__forceinline bool isCoherent() const {
- return embree::isCoherent(user->flags);
+ return embree::isCoherent(args->flags);
}
__forceinline bool isIncoherent() const {
- return embree::isIncoherent(user->flags);
+ return embree::isIncoherent(args->flags);
}
-
+
+ __forceinline bool enforceArgumentFilterFunction() const {
+ return args->flags & RTC_RAY_QUERY_FLAG_INVOKE_ARGUMENT_FILTER;
+ }
+
+#if RTC_MIN_WIDTH
+ __forceinline float getMinWidthDistanceFactor() const {
+ return args->minWidthDistanceFactor;
+ }
+#endif
+
public:
- Scene* scene;
- RTCIntersectContext* user;
+ Scene* scene = nullptr;
+ RTCRayQueryContext* user = nullptr;
+ RTCIntersectArguments* args = nullptr;
};
template<int M, typename Geometry>
- __forceinline Vec4vf<M> enlargeRadiusToMinWidth(const IntersectContext* context, const Geometry* geom, const Vec3vf<M>& ray_org, const Vec4vf<M>& v)
+ __forceinline Vec4vf<M> enlargeRadiusToMinWidth(const RayQueryContext* context, const Geometry* geom, const Vec3vf<M>& ray_org, const Vec4vf<M>& v)
{
#if RTC_MIN_WIDTH
const vfloat<M> d = length(Vec3vf<M>(v) - ray_org);
- const vfloat<M> r = clamp(context->user->minWidthDistanceFactor*d, v.w, geom->maxRadiusScale*v.w);
+ const vfloat<M> r = clamp(context->getMinWidthDistanceFactor()*d, v.w, geom->maxRadiusScale*v.w);
return Vec4vf<M>(v.x,v.y,v.z,r);
#else
return v;
@@ -47,16 +74,21 @@ namespace embree
}
template<typename Geometry>
- __forceinline Vec3ff enlargeRadiusToMinWidth(const IntersectContext* context, const Geometry* geom, const Vec3fa& ray_org, const Vec3ff& v)
+ __forceinline Vec3ff enlargeRadiusToMinWidth(const RayQueryContext* context, const Geometry* geom, const Vec3fa& ray_org, const Vec3ff& v)
{
#if RTC_MIN_WIDTH
const float d = length(Vec3fa(v) - ray_org);
- const float r = clamp(context->user->minWidthDistanceFactor*d, v.w, geom->maxRadiusScale*v.w);
+ const float r = clamp(context->getMinWidthDistanceFactor()*d, v.w, geom->maxRadiusScale*v.w);
return Vec3ff(v.x,v.y,v.z,r);
#else
return v;
#endif
}
+
+ template<typename Geometry>
+ __forceinline Vec3ff enlargeRadiusToMinWidth(const RayQueryContext* context, const Geometry* geom, const Vec3fa& ray_org, const Vec4f& v) {
+ return enlargeRadiusToMinWidth(context,geom,ray_org,Vec3ff(v.x,v.y,v.z,v.w));
+ }
enum PointQueryType
{
@@ -66,7 +98,7 @@ namespace embree
};
typedef bool (*PointQueryFunction)(struct RTCPointQueryFunctionArguments* args);
-
+
struct PointQueryContext
{
public:
@@ -78,6 +110,7 @@ namespace embree
float similarityScale,
void* userPtr)
: scene(scene)
+ , tstate(nullptr)
, query_ws(query_ws)
, query_type(query_type)
, func(func)
@@ -88,16 +121,24 @@ namespace embree
, geomID(RTC_INVALID_GEOMETRY_ID)
, query_radius(query_ws->radius)
{
+ update();
+ }
+
+ public:
+ __forceinline void update()
+ {
if (query_type == POINT_QUERY_TYPE_AABB) {
assert(similarityScale == 0.f);
updateAABB();
}
+ else{
+ query_radius = Vec3fa(query_ws->radius * similarityScale);
+ }
if (userContext->instStackSize == 0) {
assert(similarityScale == 1.f);
}
}
- public:
__forceinline void updateAABB()
{
if (likely(query_ws->radius == (float)inf || userContext->instStackSize == 0)) {
@@ -113,12 +154,13 @@ namespace embree
public:
Scene* scene;
+ void* tstate;
PointQuery* query_ws; // the original world space point query
PointQueryType query_type;
PointQueryFunction func;
RTCPointQueryContext* userContext;
- const float similarityScale;
+ float similarityScale;
void* userPtr;
diff --git a/thirdparty/embree/kernels/common/default.h b/thirdparty/embree/kernels/common/default.h
index f15d61b768..3b00ad3c88 100644
--- a/thirdparty/embree/kernels/common/default.h
+++ b/thirdparty/embree/kernels/common/default.h
@@ -13,11 +13,11 @@
#include "../../common/sys/mutex.h"
#include "../../common/sys/vector.h"
#include "../../common/sys/array.h"
-#include "../../common/sys/string.h"
+#include "../../common/sys/estring.h"
#include "../../common/sys/regression.h"
#include "../../common/sys/vector.h"
-#include "../../common/math/math.h"
+#include "../../common/math/emath.h"
#include "../../common/math/transcendental.h"
#include "../../common/simd/simd.h"
#include "../../common/math/vec2.h"
@@ -35,8 +35,6 @@
#include "../../common/math/range.h"
#include "../../common/lexers/tokenstream.h"
-#include "../../common/tasking/taskscheduler.h"
-
#define COMMA ,
#include "../config.h"
@@ -217,7 +215,7 @@ namespace embree
__forceinline int getTimeSegment(float time, float numTimeSegments, float& ftime)
{
const float timeScaled = time * numTimeSegments;
- const float itimef = clamp(floorf(timeScaled), 0.0f, numTimeSegments-1.0f);
+ const float itimef = clamp(floor(timeScaled), 0.0f, numTimeSegments-1.0f);
ftime = timeScaled - itimef;
return int(itimef);
}
@@ -225,7 +223,7 @@ namespace embree
__forceinline int getTimeSegment(float time, float start_time, float end_time, float numTimeSegments, float& ftime)
{
const float timeScaled = (time-start_time)/(end_time-start_time) * numTimeSegments;
- const float itimef = clamp(floorf(timeScaled), 0.0f, numTimeSegments-1.0f);
+ const float itimef = clamp(floor(timeScaled), 0.0f, numTimeSegments-1.0f);
ftime = timeScaled - itimef;
return int(itimef);
}
diff --git a/thirdparty/embree/kernels/common/device.cpp b/thirdparty/embree/kernels/common/device.cpp
index 833ec65139..07214532a1 100644
--- a/thirdparty/embree/kernels/common/device.cpp
+++ b/thirdparty/embree/kernels/common/device.cpp
@@ -2,6 +2,9 @@
// SPDX-License-Identifier: Apache-2.0
#include "device.h"
+
+#include "../../common/tasking/taskscheduler.h"
+
#include "../hash.h"
#include "scene_triangle_mesh.h"
#include "scene_user_geometry.h"
@@ -19,9 +22,12 @@
#include "../bvh/bvh4_factory.h"
#include "../bvh/bvh8_factory.h"
-#include "../../common/tasking/taskscheduler.h"
#include "../../common/sys/alloc.h"
+#if defined(EMBREE_SYCL_SUPPORT)
+# include "../level_zero/ze_wrapper.h"
+#endif
+
namespace embree
{
/*! some global variables that can be set via rtcSetParameter1i for debugging purposes */
@@ -30,13 +36,18 @@ namespace embree
ssize_t Device::debug_int2 = 0;
ssize_t Device::debug_int3 = 0;
- DECLARE_SYMBOL2(RayStreamFilterFuncs,rayStreamFilterFuncs);
-
static MutexSys g_mutex;
static std::map<Device*,size_t> g_cache_size_map;
static std::map<Device*,size_t> g_num_threads_map;
+
+ struct TaskArena
+ {
+#if USE_TASK_ARENA
+ std::unique_ptr<tbb::task_arena> arena;
+#endif
+ };
- Device::Device (const char* cfg)
+ Device::Device (const char* cfg) : arena(new TaskArena())
{
/* check that CPU supports lowest ISA */
if (!hasISA(ISA)) {
@@ -48,12 +59,12 @@ namespace embree
case CPU::UNKNOWN: frequency_level = FREQUENCY_SIMD256; break;
case CPU::XEON_ICE_LAKE: frequency_level = FREQUENCY_SIMD256; break;
case CPU::CORE_ICE_LAKE: frequency_level = FREQUENCY_SIMD256; break;
- case CPU::CORE_TIGER_LAKE: frequency_level = FREQUENCY_SIMD128; break;
- case CPU::CORE_COMET_LAKE: frequency_level = FREQUENCY_SIMD128; break;
- case CPU::CORE_CANNON_LAKE:frequency_level = FREQUENCY_SIMD128; break;
- case CPU::CORE_KABY_LAKE: frequency_level = FREQUENCY_SIMD128; break;
+ case CPU::CORE_TIGER_LAKE: frequency_level = FREQUENCY_SIMD256; break;
+ case CPU::CORE_COMET_LAKE: frequency_level = FREQUENCY_SIMD256; break;
+ case CPU::CORE_CANNON_LAKE:frequency_level = FREQUENCY_SIMD256; break;
+ case CPU::CORE_KABY_LAKE: frequency_level = FREQUENCY_SIMD256; break;
case CPU::XEON_SKY_LAKE: frequency_level = FREQUENCY_SIMD128; break;
- case CPU::CORE_SKY_LAKE: frequency_level = FREQUENCY_SIMD128; break;
+ case CPU::CORE_SKY_LAKE: frequency_level = FREQUENCY_SIMD256; break;
case CPU::XEON_BROADWELL: frequency_level = FREQUENCY_SIMD256; break;
case CPU::CORE_BROADWELL: frequency_level = FREQUENCY_SIMD256; break;
case CPU::XEON_HASWELL: frequency_level = FREQUENCY_SIMD256; break;
@@ -66,11 +77,7 @@ namespace embree
case CPU::CORE1: frequency_level = FREQUENCY_SIMD128; break;
case CPU::XEON_PHI_KNIGHTS_MILL : frequency_level = FREQUENCY_SIMD512; break;
case CPU::XEON_PHI_KNIGHTS_LANDING: frequency_level = FREQUENCY_SIMD512; break;
-#if defined(__APPLE__)
- case CPU::ARM: frequency_level = FREQUENCY_SIMD256; break; // Apple M1 supports high throughput for SIMD4
-#else
- case CPU::ARM: frequency_level = FREQUENCY_SIMD128; break;
-#endif
+ case CPU::ARM: frequency_level = FREQUENCY_SIMD256; break;
}
/* initialize global state */
@@ -126,13 +133,6 @@ namespace embree
/* setup tasking system */
initTaskingSystem(numThreads);
-
- /* ray stream SOA to AOS conversion */
-#if defined(EMBREE_RAY_PACKETS)
- RayStreamFilterFuncsType rayStreamFilterFuncs;
- SELECT_SYMBOL_DEFAULT_SSE42_AVX_AVX2_AVX512(enabled_cpu_features,rayStreamFilterFuncs);
- rayStreamFilters = rayStreamFilterFuncs();
-#endif
}
Device::~Device ()
@@ -174,6 +174,9 @@ namespace embree
#if defined (EMBREE_BACKFACE_CULLING_CURVES)
v += "backfacecullingcurves ";
#endif
+#if defined (EMBREE_BACKFACE_CULLING_SPHERES)
+ v += "backfacecullingspheres ";
+#endif
#if defined(EMBREE_FILTER_FUNCTION)
v += "intersection_filter ";
#endif
@@ -367,7 +370,7 @@ namespace embree
#if USE_TASK_ARENA
const size_t nThreads = min(maxNumThreads,TaskScheduler::threadCount());
const size_t uThreads = min(max(numUserThreads,(size_t)1),nThreads);
- arena = make_unique(new tbb::task_arena((int)nThreads,(unsigned int)uThreads));
+ arena->arena = make_unique(new tbb::task_arena((int)nThreads,(unsigned int)uThreads));
#endif
}
@@ -386,8 +389,21 @@ namespace embree
TaskScheduler::create(maxNumThreads,State::set_affinity,State::start_threads);
}
#if USE_TASK_ARENA
- arena.reset();
+ arena->arena.reset();
+#endif
+ }
+
+ void Device::execute(bool join, const std::function<void()>& func)
+ {
+#if USE_TASK_ARENA
+ if (join) {
+ arena->arena->execute(func);
+ }
+ else
#endif
+ {
+ func();
+ }
}
void Device::setProperty(const RTCDeviceProperty prop, ssize_t val)
@@ -450,12 +466,6 @@ namespace embree
case RTC_DEVICE_PROPERTY_NATIVE_RAY16_SUPPORTED: return 0;
#endif
-#if defined(EMBREE_RAY_PACKETS)
- case RTC_DEVICE_PROPERTY_RAY_STREAM_SUPPORTED: return 1;
-#else
- case RTC_DEVICE_PROPERTY_RAY_STREAM_SUPPORTED: return 0;
-#endif
-
#if defined(EMBREE_RAY_MASK)
case RTC_DEVICE_PROPERTY_RAY_MASK_SUPPORTED: return 1;
#else
@@ -474,6 +484,12 @@ namespace embree
case RTC_DEVICE_PROPERTY_BACKFACE_CULLING_CURVES_ENABLED: return 0;
#endif
+#if defined(EMBREE_BACKFACE_CULLING_SPHERES)
+ case RTC_DEVICE_PROPERTY_BACKFACE_CULLING_SPHERES_ENABLED: return 1;
+#else
+ case RTC_DEVICE_PROPERTY_BACKFACE_CULLING_SPHERES_ENABLED: return 0;
+#endif
+
#if defined(EMBREE_COMPACT_POLYS)
case RTC_DEVICE_PROPERTY_COMPACT_POLYS_ENABLED: return 1;
#else
@@ -557,4 +573,158 @@ namespace embree
default: throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "unknown readable property"); break;
};
}
+
+ void* Device::malloc(size_t size, size_t align) {
+ return alignedMalloc(size,align);
+ }
+
+ void Device::free(void* ptr) {
+ alignedFree(ptr);
+ }
+
+
+#if defined(EMBREE_SYCL_SUPPORT)
+
+ DeviceGPU::DeviceGPU(sycl::context sycl_context, const char* cfg)
+ : Device(cfg), gpu_context(sycl_context)
+ {
+ /* initialize ZeWrapper */
+ if (ZeWrapper::init() != ZE_RESULT_SUCCESS)
+ throw_RTCError(RTC_ERROR_UNKNOWN, "cannot initialize ZeWrapper");
+
+ /* take first device as default device */
+ auto devices = gpu_context.get_devices();
+ if (devices.size() == 0)
+ throw_RTCError(RTC_ERROR_UNKNOWN, "SYCL context contains no device");
+ gpu_device = devices[0];
+
+ /* check if RTAS build extension is available */
+ sycl::platform platform = gpu_device.get_platform();
+ ze_driver_handle_t hDriver = sycl::get_native<sycl::backend::ext_oneapi_level_zero>(platform);
+
+ uint32_t count = 0;
+ std::vector<ze_driver_extension_properties_t> extensions;
+ ze_result_t result = ZeWrapper::zeDriverGetExtensionProperties(hDriver,&count,extensions.data());
+ if (result != ZE_RESULT_SUCCESS)
+ throw_RTCError(RTC_ERROR_UNKNOWN, "zeDriverGetExtensionProperties failed");
+
+ extensions.resize(count);
+ result = ZeWrapper::zeDriverGetExtensionProperties(hDriver,&count,extensions.data());
+ if (result != ZE_RESULT_SUCCESS)
+ throw_RTCError(RTC_ERROR_UNKNOWN, "zeDriverGetExtensionProperties failed");
+
+#if defined(EMBREE_SYCL_L0_RTAS_BUILDER)
+ bool ze_rtas_builder = false;
+ for (uint32_t i=0; i<extensions.size(); i++)
+ {
+ if (strncmp("ZE_experimental_rtas_builder",extensions[i].name,sizeof(extensions[i].name)) == 0)
+ ze_rtas_builder = true;
+ }
+ if (!ze_rtas_builder)
+ throw_RTCError(RTC_ERROR_UNKNOWN, "ZE_experimental_rtas_builder extension not found");
+
+ result = ZeWrapper::initRTASBuilder(hDriver,ZeWrapper::LEVEL_ZERO);
+ if (result == ZE_RESULT_ERROR_DEPENDENCY_UNAVAILABLE)
+ throw_RTCError(RTC_ERROR_UNKNOWN, "cannot load ZE_experimental_rtas_builder extension");
+ if (result != ZE_RESULT_SUCCESS)
+ throw_RTCError(RTC_ERROR_UNKNOWN, "cannot initialize ZE_experimental_rtas_builder extension");
+#else
+ ZeWrapper::initRTASBuilder(hDriver,ZeWrapper::INTERNAL);
+#endif
+
+ if (State::verbosity(1))
+ {
+ if (ZeWrapper::rtas_builder == ZeWrapper::INTERNAL)
+ std::cout << " Internal RTAS Builder" << std::endl;
+ else
+ std::cout << " Level Zero RTAS Builder" << std::endl;
+ }
+
+ /* check if extension library can get loaded */
+ ze_rtas_parallel_operation_exp_handle_t hParallelOperation;
+ result = ZeWrapper::zeRTASParallelOperationCreateExp(hDriver, &hParallelOperation);
+ if (result == ZE_RESULT_ERROR_DEPENDENCY_UNAVAILABLE)
+ throw_RTCError(RTC_ERROR_UNKNOWN, "Level Zero RTAS Build Extension cannot get loaded");
+ if (result == ZE_RESULT_SUCCESS)
+ ZeWrapper::zeRTASParallelOperationDestroyExp(hParallelOperation);
+
+ gpu_maxWorkGroupSize = getGPUDevice().get_info<sycl::info::device::max_work_group_size>();
+ gpu_maxComputeUnits = getGPUDevice().get_info<sycl::info::device::max_compute_units>();
+
+ if (State::verbosity(1))
+ {
+ sycl::platform platform = gpu_context.get_platform();
+ std::cout << " Platform : " << platform.get_info<sycl::info::platform::name>() << std::endl;
+ std::cout << " Device : " << getGPUDevice().get_info<sycl::info::device::name>() << std::endl;
+ std::cout << " Max Work Group Size : " << gpu_maxWorkGroupSize << std::endl;
+ std::cout << " Max Compute Units : " << gpu_maxComputeUnits << std::endl;
+ std::cout << std::endl;
+ }
+
+ dispatchGlobalsPtr = zeRTASInitExp(gpu_device, gpu_context);
+ }
+
+ DeviceGPU::~DeviceGPU()
+ {
+ rthwifCleanup(this,dispatchGlobalsPtr,gpu_context);
+ }
+
+ void DeviceGPU::enter() {
+ enableUSMAllocEmbree(&gpu_context,&gpu_device);
+ }
+
+ void DeviceGPU::leave() {
+ disableUSMAllocEmbree();
+ }
+
+ void* DeviceGPU::malloc(size_t size, size_t align) {
+ return alignedSYCLMalloc(&gpu_context,&gpu_device,size,align,EMBREE_USM_SHARED_DEVICE_READ_ONLY);
+ }
+
+ void DeviceGPU::free(void* ptr) {
+ alignedSYCLFree(&gpu_context,ptr);
+ }
+
+ void DeviceGPU::setSYCLDevice(const sycl::device sycl_device_in) {
+ gpu_device = sycl_device_in;
+ }
+
+#endif
+
+ DeviceEnterLeave::DeviceEnterLeave (RTCDevice hdevice)
+ : device((Device*)hdevice)
+ {
+ assert(device);
+ device->refInc();
+ device->enter();
+ }
+
+ DeviceEnterLeave::DeviceEnterLeave (RTCScene hscene)
+ : device(((Scene*)hscene)->device)
+ {
+ assert(device);
+ device->refInc();
+ device->enter();
+ }
+
+ DeviceEnterLeave::DeviceEnterLeave (RTCGeometry hgeometry)
+ : device(((Geometry*)hgeometry)->device)
+ {
+ assert(device);
+ device->refInc();
+ device->enter();
+ }
+
+ DeviceEnterLeave::DeviceEnterLeave (RTCBuffer hbuffer)
+ : device(((Buffer*)hbuffer)->device)
+ {
+ assert(device);
+ device->refInc();
+ device->enter();
+ }
+
+ DeviceEnterLeave::~DeviceEnterLeave() {
+ device->leave();
+ device->refDec();
+ }
}
diff --git a/thirdparty/embree/kernels/common/device.h b/thirdparty/embree/kernels/common/device.h
index 21c42c654d..c9e8888a5a 100644
--- a/thirdparty/embree/kernels/common/device.h
+++ b/thirdparty/embree/kernels/common/device.h
@@ -11,10 +11,57 @@ namespace embree
{
class BVH4Factory;
class BVH8Factory;
+ struct TaskArena;
class Device : public State, public MemoryMonitorInterface
{
ALIGNED_CLASS_(16);
+
+ public:
+
+ /*! allocator that performs unified shared memory allocations */
+ template<typename T, size_t alignment>
+ struct allocator
+ {
+ typedef T value_type;
+ typedef T* pointer;
+ typedef const T* const_pointer;
+ typedef T& reference;
+ typedef const T& const_reference;
+ typedef std::size_t size_type;
+ typedef std::ptrdiff_t difference_type;
+
+ allocator() {}
+
+ allocator(Device* device)
+ : device(device) {}
+
+ __forceinline pointer allocate( size_type n ) {
+ assert(device);
+ return (pointer) device->malloc(n*sizeof(T),alignment);
+ }
+
+ __forceinline void deallocate( pointer p, size_type n ) {
+ if (device) device->free(p);
+ }
+
+ __forceinline void construct( pointer p, const_reference val ) {
+ new (p) T(val);
+ }
+
+ __forceinline void destroy( pointer p ) {
+ p->~T();
+ }
+
+ Device* device = nullptr;
+ };
+
+ /*! vector class that performs aligned allocations from Device object */
+ template<typename T>
+ using vector = vector_t<T,allocator<T,std::alignment_of<T>::value>>;
+
+ template<typename T, size_t alignment>
+ using avector = vector_t<T,allocator<T,alignment>>;
public:
@@ -54,6 +101,18 @@ namespace embree
/*! gets a property */
ssize_t getProperty(const RTCDeviceProperty prop);
+ /*! enter device by setting up some global state */
+ virtual void enter() {}
+
+ /*! leave device by setting up some global state */
+ virtual void leave() {}
+
+ /*! buffer allocation */
+ virtual void* malloc(size_t size, size_t align);
+
+ /*! buffer deallocation */
+ virtual void free(void* ptr);
+
private:
/*! initializes the tasking system */
@@ -62,6 +121,13 @@ namespace embree
/*! shuts down the tasking system */
void exitTaskingSystem();
+ std::unique_ptr<TaskArena> arena;
+
+ public:
+
+ // use tasking system arena to execute func
+ void execute(bool join, const std::function<void()>& func);
+
/*! some variables that can be set via rtcSetParameter1i for debugging purposes */
public:
static ssize_t debug_int0;
@@ -74,12 +140,55 @@ namespace embree
#if defined(EMBREE_TARGET_SIMD8)
std::unique_ptr<BVH8Factory> bvh8_factory;
#endif
-
-#if USE_TASK_ARENA
- std::unique_ptr<tbb::task_arena> arena;
+ };
+
+#if defined(EMBREE_SYCL_SUPPORT)
+
+ class DeviceGPU : public Device
+ {
+ public:
+
+ DeviceGPU(sycl::context sycl_context, const char* cfg);
+ ~DeviceGPU();
+
+ virtual void enter() override;
+ virtual void leave() override;
+ virtual void* malloc(size_t size, size_t align) override;
+ virtual void free(void* ptr) override;
+
+ /* set SYCL device */
+ void setSYCLDevice(const sycl::device sycl_device);
+
+ private:
+ sycl::context gpu_context;
+ sycl::device gpu_device;
+
+ unsigned int gpu_maxWorkGroupSize;
+ unsigned int gpu_maxComputeUnits;
+
+ public:
+ void* dispatchGlobalsPtr = nullptr;
+
+ public:
+ inline sycl::device &getGPUDevice() { return gpu_device; }
+ inline sycl::context &getGPUContext() { return gpu_context; }
+
+ inline unsigned int getGPUMaxWorkGroupSize() { return gpu_maxWorkGroupSize; }
+
+ void init_rthw_level_zero();
+ void init_rthw_opencl();
+ };
+
#endif
-
- /* ray streams filter */
- RayStreamFilterFuncs rayStreamFilters;
+
+ struct DeviceEnterLeave
+ {
+ DeviceEnterLeave (RTCDevice hdevice);
+ DeviceEnterLeave (RTCScene hscene);
+ DeviceEnterLeave (RTCGeometry hgeometry);
+ DeviceEnterLeave (RTCBuffer hbuffer);
+ ~DeviceEnterLeave();
+ private:
+ Device* device;
};
}
diff --git a/thirdparty/embree/kernels/common/geometry.cpp b/thirdparty/embree/kernels/common/geometry.cpp
index d8d3f65a5c..79a6eb00d7 100644
--- a/thirdparty/embree/kernels/common/geometry.cpp
+++ b/thirdparty/embree/kernels/common/geometry.cpp
@@ -45,12 +45,13 @@ namespace embree
Geometry::Geometry (Device* device, GType gtype, unsigned int numPrimitives, unsigned int numTimeSteps)
: device(device), userPtr(nullptr),
numPrimitives(numPrimitives), numTimeSteps(unsigned(numTimeSteps)), fnumTimeSegments(float(numTimeSteps-1)), time_range(0.0f,1.0f),
- mask(-1),
+ mask(1),
gtype(gtype),
gsubtype(GTY_SUBTYPE_DEFAULT),
quality(RTC_BUILD_QUALITY_MEDIUM),
state((unsigned)State::MODIFIED),
enabled(true),
+ argumentFilterEnabled(false),
intersectionFilterN(nullptr), occlusionFilterN(nullptr), pointQueryFunc(nullptr)
{
device->refInc();
@@ -88,6 +89,11 @@ namespace embree
Geometry::update();
}
+ BBox1f Geometry::getTimeRange () const
+ {
+ return time_range;
+ }
+
void Geometry::update()
{
++modCounter_; // FIXME: required?
@@ -227,11 +233,11 @@ namespace embree
}
}
}
-
+
bool Geometry::pointQuery(PointQuery* query, PointQueryContext* context)
{
assert(context->primID < size());
-
+
RTCPointQueryFunctionArguments args;
args.query = (RTCPointQuery*)context->query_ws;
args.userPtr = context->userPtr;
@@ -239,7 +245,7 @@ namespace embree
args.geomID = context->geomID;
args.context = context->userContext;
args.similarityScale = context->similarityScale;
-
+
bool update = false;
if(context->func) update |= context->func(&args);
if(pointQueryFunc) update |= pointQueryFunc(&args);
diff --git a/thirdparty/embree/kernels/common/geometry.h b/thirdparty/embree/kernels/common/geometry.h
index 593990f5b1..00e3c5ede3 100644
--- a/thirdparty/embree/kernels/common/geometry.h
+++ b/thirdparty/embree/kernels/common/geometry.h
@@ -8,6 +8,7 @@
#include "buffer.h"
#include "../common/point_query.h"
#include "../builders/priminfo.h"
+#include "../builders/priminfo_mb.h"
namespace embree
{
@@ -26,12 +27,14 @@ namespace embree
numUserGeometries(0), numMBUserGeometries(0),
numInstancesCheap(0), numMBInstancesCheap(0),
numInstancesExpensive(0), numMBInstancesExpensive(0),
- numGrids(0), numMBGrids(0),
+ numInstanceArrays(0), numMBInstanceArrays(0),
+ numGrids(0), numMBGrids(0),
+ numSubGrids(0), numMBSubGrids(0),
numPoints(0), numMBPoints(0) {}
__forceinline size_t size() const {
- return numTriangles + numQuads + numBezierCurves + numLineSegments + numSubdivPatches + numUserGeometries + numInstancesCheap + numInstancesExpensive + numGrids + numPoints
- + numMBTriangles + numMBQuads + numMBBezierCurves + numMBLineSegments + numMBSubdivPatches + numMBUserGeometries + numMBInstancesCheap + numMBInstancesExpensive + numMBGrids + numMBPoints;
+ return numTriangles + numQuads + numBezierCurves + numLineSegments + numSubdivPatches + numUserGeometries + numInstancesCheap + numInstancesExpensive + numInstanceArrays + numGrids + numPoints
+ + numMBTriangles + numMBQuads + numMBBezierCurves + numMBLineSegments + numMBSubdivPatches + numMBUserGeometries + numMBInstancesCheap + numMBInstancesExpensive + numMBInstanceArrays + numMBGrids + numMBPoints;
}
__forceinline unsigned int enabledGeometryTypesMask() const
@@ -44,8 +47,9 @@ namespace embree
if (numUserGeometries) mask |= 1 << 4;
if (numInstancesCheap) mask |= 1 << 5;
if (numInstancesExpensive) mask |= 1 << 6;
- if (numGrids) mask |= 1 << 7;
- if (numPoints) mask |= 1 << 8;
+ if (numInstanceArrays) mask |= 1 << 7;
+ if (numGrids) mask |= 1 << 8;
+ if (numPoints) mask |= 1 << 9;
unsigned int maskMB = 0;
if (numMBTriangles) maskMB |= 1 << 0;
@@ -55,8 +59,9 @@ namespace embree
if (numMBUserGeometries) maskMB |= 1 << 4;
if (numMBInstancesCheap) maskMB |= 1 << 5;
if (numMBInstancesExpensive) maskMB |= 1 << 6;
- if (numMBGrids) maskMB |= 1 << 7;
- if (numMBPoints) maskMB |= 1 << 8;
+ if (numMBInstanceArrays) maskMB |= 1 << 7;
+ if (numMBGrids) maskMB |= 1 << 8;
+ if (numMBPoints) maskMB |= 1 << 9;
return (mask<<8) + maskMB;
}
@@ -81,8 +86,12 @@ namespace embree
ret.numMBInstancesCheap = numMBInstancesCheap + rhs.numMBInstancesCheap;
ret.numInstancesExpensive = numInstancesExpensive + rhs.numInstancesExpensive;
ret.numMBInstancesExpensive = numMBInstancesExpensive + rhs.numMBInstancesExpensive;
+ ret.numInstanceArrays = numInstanceArrays + rhs.numInstanceArrays;
+ ret.numMBInstanceArrays = numMBInstanceArrays + rhs.numMBInstanceArrays;
ret.numGrids = numGrids + rhs.numGrids;
ret.numMBGrids = numMBGrids + rhs.numMBGrids;
+ ret.numSubGrids = numSubGrids + rhs.numSubGrids;
+ ret.numMBSubGrids = numMBSubGrids + rhs.numMBSubGrids;
ret.numPoints = numPoints + rhs.numPoints;
ret.numMBPoints = numMBPoints + rhs.numMBPoints;
@@ -106,8 +115,12 @@ namespace embree
size_t numMBInstancesCheap; //!< number of enabled motion blurred cheap instances
size_t numInstancesExpensive; //!< number of enabled expensive instances
size_t numMBInstancesExpensive; //!< number of enabled motion blurred expensive instances
+ size_t numInstanceArrays; //!< number of enabled instance arrays
+ size_t numMBInstanceArrays; //!< number of enabled motion blurred instance arrays
size_t numGrids; //!< number of enabled grid geometries
size_t numMBGrids; //!< number of enabled motion blurred grid geometries
+ size_t numSubGrids; //!< number of enabled grid geometries
+ size_t numMBSubGrids; //!< number of enabled motion blurred grid geometries
size_t numPoints; //!< number of enabled points
size_t numMBPoints; //!< number of enabled motion blurred points
};
@@ -115,6 +128,8 @@ namespace embree
/*! Base class all geometries are derived from */
class Geometry : public RefCount
{
+ ALIGNED_CLASS_USM_(16);
+
friend class Scene;
public:
@@ -154,6 +169,7 @@ namespace embree
GTY_USER_GEOMETRY = 29,
GTY_INSTANCE_CHEAP = 30,
GTY_INSTANCE_EXPENSIVE = 31,
+ GTY_INSTANCE_ARRAY = 24,
GTY_END = 32,
GTY_BASIS_LINEAR = 0,
@@ -222,7 +238,10 @@ namespace embree
MTY_INSTANCE_CHEAP = 1ul << GTY_INSTANCE_CHEAP,
MTY_INSTANCE_EXPENSIVE = 1ul << GTY_INSTANCE_EXPENSIVE,
- MTY_INSTANCE = MTY_INSTANCE_CHEAP | MTY_INSTANCE_EXPENSIVE
+ MTY_INSTANCE = MTY_INSTANCE_CHEAP | MTY_INSTANCE_EXPENSIVE,
+ MTY_INSTANCE_ARRAY = 1ul << GTY_INSTANCE_ARRAY,
+
+ MTY_ALL = -1
};
static const char* gtype_names[GTY_END];
@@ -248,8 +267,13 @@ namespace embree
/*! tests if geometry is disabled */
__forceinline bool isDisabled() const { return !isEnabled(); }
+ /* checks if argument version of filter functions are enabled */
+ __forceinline bool hasArgumentFilterFunctions() const {
+ return argumentFilterEnabled;
+ }
+
/*! tests if that geometry has some filter function set */
- __forceinline bool hasFilterFunctions () const {
+ __forceinline bool hasGeometryFilterFunctions () const {
return (intersectionFilterN != nullptr) || (occlusionFilterN != nullptr);
}
@@ -265,6 +289,11 @@ namespace embree
/*! returns geometry type mask */
__forceinline GTypeMask getTypeMask() const { return (GTypeMask)(1 << gtype); }
+ /*! returns true of geometry contains motion blur */
+ __forceinline bool hasMotionBlur () const {
+ return numTimeSteps > 1;
+ }
+
/*! returns number of primitives */
__forceinline size_t size() const { return numPrimitives; }
@@ -277,6 +306,9 @@ namespace embree
/*! sets motion blur time range */
void setTimeRange (const BBox1f range);
+ /*! gets motion blur time range */
+ BBox1f getTimeRange () const;
+
/*! sets number of vertex attributes */
virtual void setVertexAttributeCount (unsigned int N) {
throw_RTCError(RTC_ERROR_INVALID_OPERATION,"operation not supported for this geometry");
@@ -447,6 +479,11 @@ namespace embree
/*! Set occlusion filter function for ray packets of size N. */
virtual void setOcclusionFilterFunctionN (RTCFilterFunctionN filterN);
+ /* Enables argument version of intersection or occlusion filter function. */
+ virtual void enableFilterFunctionFromArguments (bool enable) {
+ argumentFilterEnabled = enable;
+ }
+
/*! for instances only */
public:
@@ -455,6 +492,11 @@ namespace embree
throw_RTCError(RTC_ERROR_INVALID_OPERATION,"operation not supported for this geometry");
}
+ /*! Sets the instanced scenes */
+ virtual void setInstancedScenes(const RTCScene* scenes, size_t numScenes) {
+ throw_RTCError(RTC_ERROR_INVALID_OPERATION,"operation not supported for this geometry");
+ }
+
/*! Sets transformation of the instance */
virtual void setTransform(const AffineSpace3fa& transform, unsigned int timeStep) {
throw_RTCError(RTC_ERROR_INVALID_OPERATION,"operation not supported for this geometry");
@@ -467,7 +509,12 @@ namespace embree
/*! Returns the transformation of the instance */
virtual AffineSpace3fa getTransform(float time) {
- throw_RTCError(RTC_ERROR_INVALID_OPERATION,"operation not supported for this geometry");
+ throw_RTCError(RTC_ERROR_INVALID_OPERATION,"operation not supported for this geometry");
+ }
+
+ /*! Returns the transformation of the instance */
+ virtual AffineSpace3fa getTransform(size_t instance, float time) {
+ throw_RTCError(RTC_ERROR_INVALID_OPERATION,"operation not supported for this geometry");
}
/*! for user geometries only */
@@ -498,18 +545,47 @@ namespace embree
public:
- virtual PrimInfo createPrimRefArray(mvector<PrimRef>& prims, const range<size_t>& r, size_t k, unsigned int geomID) const {
+ virtual PrimInfo createPrimRefArray(PrimRef* prims, const range<size_t>& r, size_t k, unsigned int geomID) const {
throw_RTCError(RTC_ERROR_INVALID_OPERATION,"createPrimRefArray not implemented for this geometry");
}
+ PrimInfo createPrimRefArray(mvector<PrimRef>& prims, const range<size_t>& r, size_t k, unsigned int geomID) const {
+ return createPrimRefArray(prims.data(),r,k,geomID);
+ }
+
+ PrimInfo createPrimRefArray(avector<PrimRef>& prims, const range<size_t>& r, size_t k, unsigned int geomID) const {
+ return createPrimRefArray(prims.data(),r,k,geomID);
+ }
+
+ virtual PrimInfo createPrimRefArray(mvector<PrimRef>& prims, mvector<SubGridBuildData>& sgrids, const range<size_t>& r, size_t k, unsigned int geomID) const {
+ return createPrimRefArray(prims,r,k,geomID);
+ }
+
virtual PrimInfo createPrimRefArrayMB(mvector<PrimRef>& prims, size_t itime, const range<size_t>& r, size_t k, unsigned int geomID) const {
throw_RTCError(RTC_ERROR_INVALID_OPERATION,"createPrimRefMBArray not implemented for this geometry");
}
+ /*! Calculates the PrimRef over the complete time interval */
+ virtual PrimInfo createPrimRefArrayMB(PrimRef* prims, const BBox1f& t0t1, const range<size_t>& r, size_t k, unsigned int geomID) const {
+ throw_RTCError(RTC_ERROR_INVALID_OPERATION,"createPrimRefMBArray not implemented for this geometry");
+ }
+
+ PrimInfo createPrimRefArrayMB(mvector<PrimRef>& prims, const BBox1f& t0t1, const range<size_t>& r, size_t k, unsigned int geomID) const {
+ return createPrimRefArrayMB(prims.data(),t0t1,r,k,geomID);
+ }
+
+ PrimInfo createPrimRefArrayMB(avector<PrimRef>& prims, const BBox1f& t0t1, const range<size_t>& r, size_t k, unsigned int geomID) const {
+ return createPrimRefArrayMB(prims.data(),t0t1,r,k,geomID);
+ }
+
virtual PrimInfoMB createPrimRefMBArray(mvector<PrimRefMB>& prims, const BBox1f& t0t1, const range<size_t>& r, size_t k, unsigned int geomID) const {
throw_RTCError(RTC_ERROR_INVALID_OPERATION,"createPrimRefMBArray not implemented for this geometry");
}
+ virtual PrimInfoMB createPrimRefMBArray(mvector<PrimRefMB>& prims, mvector<SubGridBuildData>& sgrids, const BBox1f& t0t1, const range<size_t>& r, size_t k, unsigned int geomID) const {
+ return createPrimRefMBArray(prims,t0t1,r,k,geomID);
+ }
+
virtual LinearSpace3fa computeAlignedSpace(const size_t primID) const {
throw_RTCError(RTC_ERROR_INVALID_OPERATION,"computeAlignedSpace not implemented for this geometry");
}
@@ -541,6 +617,10 @@ namespace embree
virtual LBBox3fa vlinearBounds(size_t primID, const BBox1f& time_range) const {
throw_RTCError(RTC_ERROR_INVALID_OPERATION,"vlinearBounds not implemented for this geometry");
}
+
+ virtual LBBox3fa vlinearBounds(size_t primID, const BBox1f& time_range, const SubGridBuildData * const sgrids) const {
+ return vlinearBounds(primID,time_range);
+ }
virtual LBBox3fa vlinearBounds(const LinearSpace3fa& space, size_t primID, const BBox1f& time_range) const {
throw_RTCError(RTC_ERROR_INVALID_OPERATION,"vlinearBounds not implemented for this geometry");
@@ -566,13 +646,14 @@ namespace embree
unsigned int mask; //!< for masking out geometry
unsigned int modCounter_ = 1; //!< counter for every modification - used to rebuild scenes when geo is modified
-
+
struct {
GType gtype : 8; //!< geometry type
GSubType gsubtype : 8; //!< geometry subtype
RTCBuildQuality quality : 3; //!< build quality for geometry
unsigned state : 2;
- bool enabled : 1; //!< true if geometry is enabled
+ bool enabled : 1; //!< true if geometry is enabled
+ bool argumentFilterEnabled : 1; //!< true if argument filter functions are enabled for this geometry
};
RTCFilterFunctionN intersectionFilterN;
diff --git a/thirdparty/embree/kernels/common/hit.h b/thirdparty/embree/kernels/common/hit.h
index fd1a9d6391..cbaeb9b73a 100644
--- a/thirdparty/embree/kernels/common/hit.h
+++ b/thirdparty/embree/kernels/common/hit.h
@@ -17,14 +17,26 @@ namespace embree
__forceinline HitK() {}
/* Constructs a hit */
- __forceinline HitK(const RTCIntersectContext* context, const vuint<K>& geomID, const vuint<K>& primID, const vfloat<K>& u, const vfloat<K>& v, const Vec3vf<K>& Ng)
+ __forceinline HitK(const RTCRayQueryContext* context, const vuint<K>& geomID, const vuint<K>& primID, const vfloat<K>& u, const vfloat<K>& v, const Vec3vf<K>& Ng)
: Ng(Ng), u(u), v(v), primID(primID), geomID(geomID)
{
- for (unsigned l = 0; l < RTC_MAX_INSTANCE_LEVEL_COUNT; ++l)
+ for (unsigned l = 0; l < RTC_MAX_INSTANCE_LEVEL_COUNT; ++l) {
instID[l] = RTC_INVALID_GEOMETRY_ID;
+#if defined(RTC_GEOMETRY_INSTANCE_ARRAY)
+ instPrimID[l] = RTC_INVALID_GEOMETRY_ID;
+#endif
+ }
+
instance_id_stack::copy_UV<K>(context->instID, instID);
+#if defined(RTC_GEOMETRY_INSTANCE_ARRAY)
+ instance_id_stack::copy_UV<K>(context->instPrimID, instPrimID);
+#endif
}
+ /* Constructs a hit */
+ __forceinline HitK(const RTCRayQueryContext* context, const vuint<K>& geomID, const vuint<K>& primID, const Vec2vf<K>& uv, const Vec3vf<K>& Ng)
+ : HitK(context,geomID,primID,uv.x,uv.y,Ng) {}
+
/* Returns the size of the hit */
static __forceinline size_t size() { return K; }
@@ -35,6 +47,9 @@ namespace embree
vuint<K> primID; // primitive ID
vuint<K> geomID; // geometry ID
vuint<K> instID[RTC_MAX_INSTANCE_LEVEL_COUNT]; // instance ID
+#if defined(RTC_GEOMETRY_INSTANCE_ARRAY)
+ vuint<K> instPrimID[RTC_MAX_INSTANCE_LEVEL_COUNT]; // instance primitive ID
+#endif
};
/* Specialization for a single hit */
@@ -45,12 +60,19 @@ namespace embree
__forceinline HitK() {}
/* Constructs a hit */
- __forceinline HitK(const RTCIntersectContext* context, unsigned int geomID, unsigned int primID, float u, float v, const Vec3fa& Ng)
+ __forceinline HitK(const RTCRayQueryContext* context, unsigned int geomID, unsigned int primID, float u, float v, const Vec3fa& Ng)
: Ng(Ng.x,Ng.y,Ng.z), u(u), v(v), primID(primID), geomID(geomID)
{
- instance_id_stack::copy_UU(context->instID, instID);
+ instance_id_stack::copy_UU(context, context->instID, instID);
+#if defined(RTC_GEOMETRY_INSTANCE_ARRAY)
+ instance_id_stack::copy_UU(context, context->instPrimID, instPrimID);
+#endif
}
+ /* Constructs a hit */
+ __forceinline HitK(const RTCRayQueryContext* context, unsigned int geomID, unsigned int primID, const Vec2f& uv, const Vec3fa& Ng)
+ : HitK<1>(context,geomID,primID,uv.x,uv.y,Ng) {}
+
/* Returns the size of the hit */
static __forceinline size_t size() { return 1; }
@@ -61,6 +83,9 @@ namespace embree
unsigned int primID; // primitive ID
unsigned int geomID; // geometry ID
unsigned int instID[RTC_MAX_INSTANCE_LEVEL_COUNT]; // instance ID
+#if defined(RTC_GEOMETRY_INSTANCE_ARRAY)
+ unsigned int instPrimID[RTC_MAX_INSTANCE_LEVEL_COUNT]; // instance primitive ID
+#endif
};
/* Shortcuts */
@@ -68,6 +93,7 @@ namespace embree
typedef HitK<4> Hit4;
typedef HitK<8> Hit8;
typedef HitK<16> Hit16;
+ typedef HitK<VSIZEX> Hitx;
/* Outputs hit to stream */
template<int K>
@@ -84,6 +110,13 @@ namespace embree
{
cout << " " << ray.instID[l];
}
+#if defined(RTC_GEOMETRY_INSTANCE_ARRAY)
+ cout << " instPrimID =";
+ for (unsigned l = 0; l < RTC_MAX_INSTANCE_LEVEL_COUNT; ++l)
+ {
+ cout << " " << ray.instPrimID[l];
+ }
+#endif
cout << embree_endl;
return cout << "}";
}
@@ -97,10 +130,13 @@ namespace embree
ray.primID = hit.primID;
ray.geomID = hit.geomID;
instance_id_stack::copy_UU(hit.instID, ray.instID);
+#if defined(RTC_GEOMETRY_INSTANCE_ARRAY)
+ instance_id_stack::copy_UU(hit.instPrimID, ray.instPrimID);
+#endif
}
template<int K>
- __forceinline void copyHitToRay(const vbool<K> &mask, RayHitK<K> &ray, const HitK<K> &hit)
+ __forceinline void copyHitToRay(const vbool<K>& mask, RayHitK<K>& ray, const HitK<K>& hit)
{
vfloat<K>::storeu(mask,&ray.Ng.x, hit.Ng.x);
vfloat<K>::storeu(mask,&ray.Ng.y, hit.Ng.y);
@@ -110,5 +146,8 @@ namespace embree
vuint<K>::storeu(mask,&ray.primID, hit.primID);
vuint<K>::storeu(mask,&ray.geomID, hit.geomID);
instance_id_stack::copy_VV<K>(hit.instID, ray.instID, mask);
+#if defined(RTC_GEOMETRY_INSTANCE_ARRAY)
+ instance_id_stack::copy_VV<K>(hit.instPrimID, ray.instPrimID, mask);
+#endif
}
}
diff --git a/thirdparty/embree/kernels/common/instance_stack.h b/thirdparty/embree/kernels/common/instance_stack.h
index d3c0a643f1..32b57b48a3 100644
--- a/thirdparty/embree/kernels/common/instance_stack.h
+++ b/thirdparty/embree/kernels/common/instance_stack.h
@@ -19,40 +19,108 @@ static_assert(RTC_MAX_INSTANCE_LEVEL_COUNT > 0,
/*
* Push an instance to the stack.
*/
-RTC_FORCEINLINE bool push(RTCIntersectContext* context,
- unsigned instanceId)
+template<typename Context>
+RTC_FORCEINLINE bool push(Context context,
+ unsigned instanceId,
+ unsigned instancePrimId)
{
#if RTC_MAX_INSTANCE_LEVEL_COUNT > 1
const bool spaceAvailable = context->instStackSize < RTC_MAX_INSTANCE_LEVEL_COUNT;
- /* We assert here because instances are silently dropped when the stack is full.
+ /* We assert here because instances are silently dropped when the stack is full.
This might be quite hard to find in production. */
- assert(spaceAvailable);
- if (likely(spaceAvailable))
- context->instID[context->instStackSize++] = instanceId;
+ assert(spaceAvailable);
+ if (likely(spaceAvailable)) {
+ context->instID[context->instStackSize] = instanceId;
+#if defined(RTC_GEOMETRY_INSTANCE_ARRAY)
+ context->instPrimID[context->instStackSize] = instancePrimId;
+#endif
+ context->instStackSize++;
+ }
return spaceAvailable;
#else
const bool spaceAvailable = (context->instID[0] == RTC_INVALID_GEOMETRY_ID);
- assert(spaceAvailable);
- if (likely(spaceAvailable))
+ assert(spaceAvailable);
+ if (likely(spaceAvailable)) {
context->instID[0] = instanceId;
+#if defined(RTC_GEOMETRY_INSTANCE_ARRAY)
+ context->instPrimID[0] = instancePrimId;
+#endif
+ }
return spaceAvailable;
#endif
}
-
/*
* Pop the last instance pushed to the stack.
* Do not call on an empty stack.
*/
-RTC_FORCEINLINE void pop(RTCIntersectContext* context)
+template<typename Context>
+RTC_FORCEINLINE void pop(Context context)
{
assert(context);
#if RTC_MAX_INSTANCE_LEVEL_COUNT > 1
assert(context->instStackSize > 0);
- context->instID[--context->instStackSize] = RTC_INVALID_GEOMETRY_ID;
+ --context->instStackSize;
+ context->instID[context->instStackSize] = RTC_INVALID_GEOMETRY_ID;
+#if defined(RTC_GEOMETRY_INSTANCE_ARRAY)
+ context->instPrimID[context->instStackSize] = RTC_INVALID_GEOMETRY_ID;
+#endif
#else
assert(context->instID[0] != RTC_INVALID_GEOMETRY_ID);
context->instID[0] = RTC_INVALID_GEOMETRY_ID;
+#if defined(RTC_GEOMETRY_INSTANCE_ARRAY)
+ context->instPrimID[0] = RTC_INVALID_GEOMETRY_ID;
+#endif
+#endif
+}
+
+
+/* Push an instance to the stack. Used for point queries*/
+RTC_FORCEINLINE bool push(RTCPointQueryContext* context,
+ unsigned int instanceId,
+ unsigned int instancePrimId,
+ AffineSpace3fa const& w2i,
+ AffineSpace3fa const& i2w)
+{
+ assert(context);
+ const size_t stackSize = context->instStackSize;
+ assert(stackSize < RTC_MAX_INSTANCE_LEVEL_COUNT);
+ context->instID[stackSize] = instanceId;
+#if defined(RTC_GEOMETRY_INSTANCE_ARRAY)
+ context->instPrimID[stackSize] = instancePrimId;
+#endif
+
+ AffineSpace3fa_store_unaligned(w2i,(AffineSpace3fa*)context->world2inst[stackSize]);
+ AffineSpace3fa_store_unaligned(i2w,(AffineSpace3fa*)context->inst2world[stackSize]);
+
+#if RTC_MAX_INSTANCE_LEVEL_COUNT > 1
+ if (unlikely(stackSize > 0))
+ {
+ const AffineSpace3fa world2inst = AffineSpace3fa_load_unaligned((AffineSpace3fa*)context->world2inst[stackSize ])
+ * AffineSpace3fa_load_unaligned((AffineSpace3fa*)context->world2inst[stackSize-1]);
+ const AffineSpace3fa inst2world = AffineSpace3fa_load_unaligned((AffineSpace3fa*)context->inst2world[stackSize-1])
+ * AffineSpace3fa_load_unaligned((AffineSpace3fa*)context->inst2world[stackSize ]);
+ AffineSpace3fa_store_unaligned(world2inst,(AffineSpace3fa*)context->world2inst[stackSize]);
+ AffineSpace3fa_store_unaligned(inst2world,(AffineSpace3fa*)context->inst2world[stackSize]);
+ }
+#endif
+ context->instStackSize++;
+ return true;
+}
+
+template<>
+RTC_FORCEINLINE void pop(RTCPointQueryContext* context)
+{
+ assert(context);
+#if RTC_MAX_INSTANCE_LEVEL_COUNT > 1
+ assert(context->instStackSize > 0);
+#else
+ assert(context->instID[0] != RTC_INVALID_GEOMETRY_ID);
+#endif
+ --context->instStackSize;
+ context->instID[context->instStackSize] = RTC_INVALID_GEOMETRY_ID;
+#if defined(RTC_GEOMETRY_INSTANCE_ARRAY)
+ context->instPrimID[context->instStackSize] = RTC_INVALID_GEOMETRY_ID;
#endif
}
@@ -77,6 +145,24 @@ RTC_FORCEINLINE void copy_UU(const unsigned* src, unsigned* tgt)
#endif
}
+RTC_FORCEINLINE void copy_UU(const RTCRayQueryContext* context, const unsigned* src, unsigned* tgt)
+{
+#if (RTC_MAX_INSTANCE_LEVEL_COUNT == 1)
+ tgt[0] = src[0];
+
+#else
+
+ unsigned int depth = context->instStackSize;
+
+ for (unsigned l = 0; l < depth; ++l)
+ tgt[l] = src[l];
+
+ for (unsigned l = depth; l < RTC_MAX_INSTANCE_LEVEL_COUNT; ++l)
+ tgt[l] = RTC_INVALID_GEOMETRY_ID;
+
+#endif
+}
+
template <int K>
RTC_FORCEINLINE void copy_UV(const unsigned* src, vuint<K>* tgt)
{
diff --git a/thirdparty/embree/kernels/common/point_query.h b/thirdparty/embree/kernels/common/point_query.h
index 7d55c91fff..e92e22ae36 100644
--- a/thirdparty/embree/kernels/common/point_query.h
+++ b/thirdparty/embree/kernels/common/point_query.h
@@ -120,6 +120,7 @@ namespace embree
typedef PointQueryK<4> PointQuery4;
typedef PointQueryK<8> PointQuery8;
typedef PointQueryK<16> PointQuery16;
+ typedef PointQueryK<VSIZEX> PointQueryx;
struct PointQueryN;
/* Outputs point query to stream */
diff --git a/thirdparty/embree/kernels/common/primref.h b/thirdparty/embree/kernels/common/primref.h
deleted file mode 100644
index d61763487b..0000000000
--- a/thirdparty/embree/kernels/common/primref.h
+++ /dev/null
@@ -1,138 +0,0 @@
-// Copyright 2009-2021 Intel Corporation
-// SPDX-License-Identifier: Apache-2.0
-
-#pragma once
-
-#include "default.h"
-
-namespace embree
-{
- /*! A primitive reference stores the bounds of the primitive and its ID. */
- struct __aligned(32) PrimRef
- {
- __forceinline PrimRef () {}
-
-#if defined(__AVX__)
- __forceinline PrimRef(const PrimRef& v) {
- vfloat8::store((float*)this,vfloat8::load((float*)&v));
- }
- __forceinline PrimRef& operator=(const PrimRef& v) {
- vfloat8::store((float*)this,vfloat8::load((float*)&v)); return *this;
- }
-#endif
-
- __forceinline PrimRef (const BBox3fa& bounds, unsigned int geomID, unsigned int primID)
- {
- lower = Vec3fx(bounds.lower, geomID);
- upper = Vec3fx(bounds.upper, primID);
- }
-
- __forceinline PrimRef (const BBox3fa& bounds, size_t id)
- {
-#if defined(__64BIT__)
- lower = Vec3fx(bounds.lower, (unsigned)(id & 0xFFFFFFFF));
- upper = Vec3fx(bounds.upper, (unsigned)((id >> 32) & 0xFFFFFFFF));
-#else
- lower = Vec3fx(bounds.lower, (unsigned)id);
- upper = Vec3fx(bounds.upper, (unsigned)0);
-#endif
- }
-
- /*! calculates twice the center of the primitive */
- __forceinline const Vec3fa center2() const {
- return lower+upper;
- }
-
- /*! return the bounding box of the primitive */
- __forceinline const BBox3fa bounds() const {
- return BBox3fa(lower,upper);
- }
-
- /*! size for bin heuristic is 1 */
- __forceinline unsigned size() const {
- return 1;
- }
-
- /*! returns bounds and centroid used for binning */
- __forceinline void binBoundsAndCenter(BBox3fa& bounds_o, Vec3fa& center_o) const
- {
- bounds_o = bounds();
- center_o = embree::center2(bounds_o);
- }
-
- __forceinline unsigned& geomIDref() { // FIXME: remove !!!!!!!
- return lower.u;
- }
- __forceinline unsigned& primIDref() { // FIXME: remove !!!!!!!
- return upper.u;
- }
-
- /*! returns the geometry ID */
- __forceinline unsigned geomID() const {
- return lower.a;
- }
-
- /*! returns the primitive ID */
- __forceinline unsigned primID() const {
- return upper.a;
- }
-
- /*! returns an size_t sized ID */
- __forceinline size_t ID() const {
-#if defined(__64BIT__)
- return size_t(lower.u) + (size_t(upper.u) << 32);
-#else
- return size_t(lower.u);
-#endif
- }
-
- /*! special function for operator< */
- __forceinline uint64_t ID64() const {
- return (((uint64_t)primID()) << 32) + (uint64_t)geomID();
- }
-
- /*! allows sorting the primrefs by ID */
- friend __forceinline bool operator<(const PrimRef& p0, const PrimRef& p1) {
- return p0.ID64() < p1.ID64();
- }
-
- /*! Outputs primitive reference to a stream. */
- friend __forceinline embree_ostream operator<<(embree_ostream cout, const PrimRef& ref) {
- return cout << "{ lower = " << ref.lower << ", upper = " << ref.upper << ", geomID = " << ref.geomID() << ", primID = " << ref.primID() << " }";
- }
-
- public:
- Vec3fx lower; //!< lower bounds and geomID
- Vec3fx upper; //!< upper bounds and primID
- };
-
- /*! fast exchange for PrimRefs */
- __forceinline void xchg(PrimRef& a, PrimRef& b)
- {
-#if defined(__AVX__)
- const vfloat8 aa = vfloat8::load((float*)&a);
- const vfloat8 bb = vfloat8::load((float*)&b);
- vfloat8::store((float*)&a,bb);
- vfloat8::store((float*)&b,aa);
-#else
- std::swap(a,b);
-#endif
- }
-
- /************************************************************************************/
- /************************************************************************************/
- /************************************************************************************/
- /************************************************************************************/
-
- struct SubGridBuildData {
- unsigned short sx,sy;
- unsigned int primID;
-
- __forceinline SubGridBuildData() {};
- __forceinline SubGridBuildData(const unsigned int sx, const unsigned int sy, const unsigned int primID) : sx(sx), sy(sy), primID(primID) {};
-
- __forceinline size_t x() const { return (size_t)sx & 0x7fff; }
- __forceinline size_t y() const { return (size_t)sy & 0x7fff; }
-
- };
-}
diff --git a/thirdparty/embree/kernels/common/primref_mb.h b/thirdparty/embree/kernels/common/primref_mb.h
deleted file mode 100644
index fb08a05003..0000000000
--- a/thirdparty/embree/kernels/common/primref_mb.h
+++ /dev/null
@@ -1,262 +0,0 @@
-// Copyright 2009-2021 Intel Corporation
-// SPDX-License-Identifier: Apache-2.0
-
-#pragma once
-
-#include "default.h"
-
-#define MBLUR_BIN_LBBOX 1
-
-namespace embree
-{
-#if MBLUR_BIN_LBBOX
-
- /*! A primitive reference stores the bounds of the primitive and its ID. */
- struct PrimRefMB
- {
- typedef LBBox3fa BBox;
-
- __forceinline PrimRefMB () {}
-
- __forceinline PrimRefMB (const LBBox3fa& lbounds_i, unsigned int activeTimeSegments, BBox1f time_range, unsigned int totalTimeSegments, unsigned int geomID, unsigned int primID)
- : lbounds((LBBox3fx)lbounds_i), time_range(time_range)
- {
- assert(activeTimeSegments > 0);
- lbounds.bounds0.lower.a = geomID;
- lbounds.bounds0.upper.a = primID;
- lbounds.bounds1.lower.a = activeTimeSegments;
- lbounds.bounds1.upper.a = totalTimeSegments;
- }
-
- __forceinline PrimRefMB (EmptyTy empty, const LBBox3fa& lbounds_i, unsigned int activeTimeSegments, BBox1f time_range, unsigned int totalTimeSegments, size_t id)
- : lbounds((LBBox3fx)lbounds_i), time_range(time_range)
- {
- assert(activeTimeSegments > 0);
-#if defined(__64BIT__)
- lbounds.bounds0.lower.a = id & 0xFFFFFFFF;
- lbounds.bounds0.upper.a = (id >> 32) & 0xFFFFFFFF;
-#else
- lbounds.bounds0.lower.a = id;
- lbounds.bounds0.upper.a = 0;
-#endif
- lbounds.bounds1.lower.a = activeTimeSegments;
- lbounds.bounds1.upper.a = totalTimeSegments;
- }
-
- __forceinline PrimRefMB (const LBBox3fa& lbounds_i, unsigned int activeTimeSegments, BBox1f time_range, unsigned int totalTimeSegments, size_t id)
- : lbounds((LBBox3fx)lbounds_i), time_range(time_range)
- {
- assert(activeTimeSegments > 0);
-#if defined(__64BIT__)
- lbounds.bounds0.lower.u = id & 0xFFFFFFFF;
- lbounds.bounds0.upper.u = (id >> 32) & 0xFFFFFFFF;
-#else
- lbounds.bounds0.lower.u = id;
- lbounds.bounds0.upper.u = 0;
-#endif
- lbounds.bounds1.lower.a = activeTimeSegments;
- lbounds.bounds1.upper.a = totalTimeSegments;
- }
-
- /*! returns bounds for binning */
- __forceinline LBBox3fa bounds() const {
- return lbounds;
- }
-
- /*! returns the number of time segments of this primref */
- __forceinline unsigned size() const {
- return lbounds.bounds1.lower.a;
- }
-
- __forceinline unsigned totalTimeSegments() const {
- return lbounds.bounds1.upper.a;
- }
-
- /* calculate overlapping time segment range */
- __forceinline range<int> timeSegmentRange(const BBox1f& range) const {
- return getTimeSegmentRange(range,time_range,float(totalTimeSegments()));
- }
-
- /* returns time that corresponds to time step */
- __forceinline float timeStep(const int i) const {
- assert(i>=0 && i<=(int)totalTimeSegments());
- return time_range.lower + time_range.size()*float(i)/float(totalTimeSegments());
- }
-
- /*! checks if time range overlaps */
- __forceinline bool time_range_overlap(const BBox1f& range) const
- {
- if (0.9999f*time_range.upper <= range.lower) return false;
- if (1.0001f*time_range.lower >= range.upper) return false;
- return true;
- }
-
- /*! returns center for binning */
- __forceinline Vec3fa binCenter() const {
- return center2(lbounds.interpolate(0.5f));
- }
-
- /*! returns bounds and centroid used for binning */
- __forceinline void binBoundsAndCenter(LBBox3fa& bounds_o, Vec3fa& center_o) const
- {
- bounds_o = bounds();
- center_o = binCenter();
- }
-
- /*! returns the geometry ID */
- __forceinline unsigned geomID() const {
- return lbounds.bounds0.lower.a;
- }
-
- /*! returns the primitive ID */
- __forceinline unsigned primID() const {
- return lbounds.bounds0.upper.a;
- }
-
- /*! returns an size_t sized ID */
- __forceinline size_t ID() const {
-#if defined(__64BIT__)
- return size_t(lbounds.bounds0.lower.u) + (size_t(lbounds.bounds0.upper.u) << 32);
-#else
- return size_t(lbounds.bounds0.lower.u);
-#endif
- }
-
- /*! special function for operator< */
- __forceinline uint64_t ID64() const {
- return (((uint64_t)primID()) << 32) + (uint64_t)geomID();
- }
-
- /*! allows sorting the primrefs by ID */
- friend __forceinline bool operator<(const PrimRefMB& p0, const PrimRefMB& p1) {
- return p0.ID64() < p1.ID64();
- }
-
- /*! Outputs primitive reference to a stream. */
- friend __forceinline embree_ostream operator<<(embree_ostream cout, const PrimRefMB& ref) {
- return cout << "{ time_range = " << ref.time_range << ", bounds = " << ref.bounds() << ", geomID = " << ref.geomID() << ", primID = " << ref.primID() << ", active_segments = " << ref.size() << ", total_segments = " << ref.totalTimeSegments() << " }";
- }
-
- public:
- LBBox3fx lbounds;
- BBox1f time_range; // entire geometry time range
- };
-
-#else
-
- /*! A primitive reference stores the bounds of the primitive and its ID. */
- struct __aligned(16) PrimRefMB
- {
- typedef BBox3fa BBox;
-
- __forceinline PrimRefMB () {}
-
- __forceinline PrimRefMB (const LBBox3fa& bounds, unsigned int activeTimeSegments, BBox1f time_range, unsigned int totalTimeSegments, unsigned int geomID, unsigned int primID)
- : bbox(bounds.interpolate(0.5f)), _activeTimeSegments(activeTimeSegments), _totalTimeSegments(totalTimeSegments), time_range(time_range)
- {
- assert(activeTimeSegments > 0);
- bbox.lower.a = geomID;
- bbox.upper.a = primID;
- }
-
- __forceinline PrimRefMB (EmptyTy empty, const LBBox3fa& bounds, unsigned int activeTimeSegments, BBox1f time_range, unsigned int totalTimeSegments, size_t id)
- : bbox(bounds.interpolate(0.5f)), _activeTimeSegments(activeTimeSegments), _totalTimeSegments(totalTimeSegments), time_range(time_range)
- {
- assert(activeTimeSegments > 0);
-#if defined(__64BIT__)
- bbox.lower.u = id & 0xFFFFFFFF;
- bbox.upper.u = (id >> 32) & 0xFFFFFFFF;
-#else
- bbox.lower.u = id;
- bbox.upper.u = 0;
-#endif
- }
-
- /*! returns bounds for binning */
- __forceinline BBox3fa bounds() const {
- return bbox;
- }
-
- /*! returns the number of time segments of this primref */
- __forceinline unsigned int size() const {
- return _activeTimeSegments;
- }
-
- __forceinline unsigned int totalTimeSegments() const {
- return _totalTimeSegments;
- }
-
- /* calculate overlapping time segment range */
- __forceinline range<int> timeSegmentRange(const BBox1f& range) const {
- return getTimeSegmentRange(range,time_range,float(_totalTimeSegments));
- }
-
- /* returns time that corresponds to time step */
- __forceinline float timeStep(const int i) const {
- assert(i>=0 && i<=(int)_totalTimeSegments);
- return time_range.lower + time_range.size()*float(i)/float(_totalTimeSegments);
- }
-
- /*! checks if time range overlaps */
- __forceinline bool time_range_overlap(const BBox1f& range) const
- {
- if (0.9999f*time_range.upper <= range.lower) return false;
- if (1.0001f*time_range.lower >= range.upper) return false;
- return true;
- }
-
- /*! returns center for binning */
- __forceinline Vec3fa binCenter() const {
- return center2(bounds());
- }
-
- /*! returns bounds and centroid used for binning */
- __forceinline void binBoundsAndCenter(BBox3fa& bounds_o, Vec3fa& center_o) const
- {
- bounds_o = bounds();
- center_o = center2(bounds());
- }
-
- /*! returns the geometry ID */
- __forceinline unsigned int geomID() const {
- return bbox.lower.a;
- }
-
- /*! returns the primitive ID */
- __forceinline unsigned int primID() const {
- return bbox.upper.a;
- }
-
- /*! returns an size_t sized ID */
- __forceinline size_t ID() const {
-#if defined(__64BIT__)
- return size_t(bbox.lower.u) + (size_t(bbox.upper.u) << 32);
-#else
- return size_t(bbox.lower.u);
-#endif
- }
-
- /*! special function for operator< */
- __forceinline uint64_t ID64() const {
- return (((uint64_t)primID()) << 32) + (uint64_t)geomID();
- }
-
- /*! allows sorting the primrefs by ID */
- friend __forceinline bool operator<(const PrimRefMB& p0, const PrimRefMB& p1) {
- return p0.ID64() < p1.ID64();
- }
-
- /*! Outputs primitive reference to a stream. */
- friend __forceinline embree_ostream operator<<(embree_ostream cout, const PrimRefMB& ref) {
- return cout << "{ bounds = " << ref.bounds() << ", geomID = " << ref.geomID() << ", primID = " << ref.primID() << ", active_segments = " << ref.size() << ", total_segments = " << ref.totalTimeSegments() << " }";
- }
-
- public:
- BBox3fa bbox; // bounds, geomID, primID
- unsigned int _activeTimeSegments;
- unsigned int _totalTimeSegments;
- BBox1f time_range; // entire geometry time range
- };
-
-#endif
-}
diff --git a/thirdparty/embree/kernels/common/ray.h b/thirdparty/embree/kernels/common/ray.h
index 3c8ee3989c..c886013354 100644
--- a/thirdparty/embree/kernels/common/ray.h
+++ b/thirdparty/embree/kernels/common/ray.h
@@ -10,8 +10,6 @@
namespace embree
{
- static const size_t MAX_INTERNAL_STREAM_SIZE = 32;
-
/* Ray structure for K rays */
template<int K>
struct RayK
@@ -97,16 +95,24 @@ namespace embree
: RayK<K>(org, dir, tnear, tfar, time, mask, id, flags),
geomID(RTC_INVALID_GEOMETRY_ID)
{
- for (unsigned l = 0; l < RTC_MAX_INSTANCE_LEVEL_COUNT; ++l)
+ for (unsigned l = 0; l < RTC_MAX_INSTANCE_LEVEL_COUNT; ++l) {
instID[l] = RTC_INVALID_GEOMETRY_ID;
+#if defined(RTC_GEOMETRY_INSTANCE_ARRAY)
+ instPrimID[l] = RTC_INVALID_GEOMETRY_ID;
+#endif
+ }
}
__forceinline RayHitK(const RayK<K>& ray)
: RayK<K>(ray),
geomID(RTC_INVALID_GEOMETRY_ID)
{
- for (unsigned l = 0; l < RTC_MAX_INSTANCE_LEVEL_COUNT; ++l)
+ for (unsigned l = 0; l < RTC_MAX_INSTANCE_LEVEL_COUNT; ++l) {
instID[l] = RTC_INVALID_GEOMETRY_ID;
+#if defined(RTC_GEOMETRY_INSTANCE_ARRAY)
+ instPrimID[l] = RTC_INVALID_GEOMETRY_ID;
+#endif
+ }
}
__forceinline RayHitK<K>& operator =(const RayK<K>& ray)
@@ -121,8 +127,12 @@ namespace embree
flags = ray.flags;
geomID = RTC_INVALID_GEOMETRY_ID;
- for (unsigned l = 0; l < RTC_MAX_INSTANCE_LEVEL_COUNT; ++l)
+ for (unsigned l = 0; l < RTC_MAX_INSTANCE_LEVEL_COUNT; ++l) {
instID[l] = RTC_INVALID_GEOMETRY_ID;
+#if defined(RTC_GEOMETRY_INSTANCE_ARRAY)
+ instPrimID[l] = RTC_INVALID_GEOMETRY_ID;
+#endif
+ }
return *this;
}
@@ -159,7 +169,10 @@ namespace embree
vuint<K> primID; // primitive ID
vuint<K> geomID; // geometry ID
vuint<K> instID[RTC_MAX_INSTANCE_LEVEL_COUNT]; // instance ID
- };
+#if defined(RTC_GEOMETRY_INSTANCE_ARRAY)
+ vuint<K> instPrimID[RTC_MAX_INSTANCE_LEVEL_COUNT]; // instance prim ID
+#endif
+};
/* Specialization for a single ray */
template<>
@@ -178,6 +191,11 @@ namespace embree
return all(le_mask(abs(Vec3fa(org)), Vec3fa(FLT_LARGE)) & le_mask(abs(Vec3fa(dir)), Vec3fa(FLT_LARGE))) && abs(tnear()) <= float(inf) && abs(tfar) <= float(inf);
}
+ /* checks if occlusion ray is done */
+ __forceinline bool occluded() const {
+ return tfar < 0.0f;
+ }
+
/* Ray data */
Vec3ff org; // 3 floats for ray origin, 1 float for tnear
//float tnear; // start of ray segment
@@ -251,6 +269,9 @@ namespace embree
unsigned int primID; // primitive ID
unsigned int geomID; // geometry ID
unsigned int instID[RTC_MAX_INSTANCE_LEVEL_COUNT]; // instance ID
+#if defined(RTC_GEOMETRY_INSTANCE_ARRAY)
+ unsigned int instPrimID[RTC_MAX_INSTANCE_LEVEL_COUNT]; // instance primitive ID
+#endif
};
/* Converts ray packet to single rays */
@@ -293,6 +314,9 @@ namespace embree
ray.primID = primID[i]; ray.geomID = geomID[i];
instance_id_stack::copy_VU<K>(instID, ray.instID, i);
+#if defined(RTC_GEOMETRY_INSTANCE_ARRAY)
+ instance_id_stack::copy_VU<K>(instPrimID, ray.instPrimID, i);
+#endif
}
/* Converts single rays to ray packet */
@@ -332,6 +356,9 @@ namespace embree
primID[i] = ray.primID; geomID[i] = ray.geomID;
instance_id_stack::copy_UV<K>(ray.instID, instID, i);
+#if defined(RTC_GEOMETRY_INSTANCE_ARRAY)
+ instance_id_stack::copy_UV<K>(ray.instPrimID, instPrimID, i);
+#endif
}
/* copies a ray packet element into another element*/
@@ -354,6 +381,9 @@ namespace embree
primID[dest] = primID[source]; geomID[dest] = geomID[source];
instance_id_stack::copy_VV<K>(instID, instID, source, dest);
+#if defined(RTC_GEOMETRY_INSTANCE_ARRAY)
+ instance_id_stack::copy_VV<K>(instPrimID, instPrimID, source, dest);
+#endif
}
/* Shortcuts */
@@ -361,12 +391,14 @@ namespace embree
typedef RayK<4> Ray4;
typedef RayK<8> Ray8;
typedef RayK<16> Ray16;
+ typedef RayK<VSIZEX> Rayx;
struct RayN;
typedef RayHitK<1> RayHit;
typedef RayHitK<4> RayHit4;
typedef RayHitK<8> RayHit8;
typedef RayHitK<16> RayHit16;
+ typedef RayHitK<VSIZEX> RayHitx;
struct RayHitN;
template<int K, bool intersect>
@@ -428,6 +460,13 @@ namespace embree
{
cout << " " << ray.instID[l];
}
+#if defined(RTC_GEOMETRY_INSTANCE_ARRAY)
+ cout << " instPrimID =";
+ for (unsigned l = 0; l < RTC_MAX_INSTANCE_LEVEL_COUNT; ++l)
+ {
+ cout << " " << ray.instPrimID[l];
+ }
+#endif
cout << embree_endl;
return cout << "}";
}
@@ -464,6 +503,9 @@ namespace embree
__forceinline unsigned int* primID(size_t offset = 0) { return (unsigned int*)&ptr[17*4*N+offset]; }; // primitive ID
__forceinline unsigned int* geomID(size_t offset = 0) { return (unsigned int*)&ptr[18*4*N+offset]; }; // geometry ID
__forceinline unsigned int* instID(size_t level, size_t offset = 0) { return (unsigned int*)&ptr[19*4*N+level*4*N+offset]; }; // instance ID
+#if defined(RTC_GEOMETRY_INSTANCE_ARRAY)
+ __forceinline unsigned int* instPrimID(size_t level, size_t offset = 0) { return (unsigned int*)&ptr[19*4*N+RTC_MAX_INSTANCE_LEVEL_COUNT*4*N+level*4*N+offset]; }; // instance primitive ID
+#endif
__forceinline Ray getRayByOffset(size_t offset)
{
@@ -578,9 +620,16 @@ namespace embree
geomID(offset)[k] = ray.geomID[k];
instID(0, offset)[k] = ray.instID[0][k];
+#if defined(RTC_GEOMETRY_INSTANCE_ARRAY)
+ instPrimID(0, offset)[k] = ray.instPrimID[0][k];
+#endif
#if (RTC_MAX_INSTANCE_LEVEL_COUNT > 1)
- for (unsigned l = 1; l < RTC_MAX_INSTANCE_LEVEL_COUNT && ray.instID[l-1][k] != RTC_INVALID_GEOMETRY_ID; ++l)
+ for (unsigned l = 1; l < RTC_MAX_INSTANCE_LEVEL_COUNT && ray.instID[l-1][k] != RTC_INVALID_GEOMETRY_ID; ++l) {
instID(l, offset)[k] = ray.instID[l][k];
+#if defined(RTC_GEOMETRY_INSTANCE_ARRAY)
+ instPrimID(l, offset)[k] = ray.instPrimID[l][k];
+#endif
+ }
#endif
}
}
@@ -592,9 +641,16 @@ namespace embree
vuint<K>::storeu(valid, geomID(offset), ray.geomID);
vuint<K>::storeu(valid, instID(0, offset), ray.instID[0]);
+#if defined(RTC_GEOMETRY_INSTANCE_ARRAY)
+ vuint<K>::storeu(valid, instPrimID(0, offset), ray.instPrimID[0]);
+#endif
#if (RTC_MAX_INSTANCE_LEVEL_COUNT > 1)
- for (unsigned l = 1; l < RTC_MAX_INSTANCE_LEVEL_COUNT && any(valid & (ray.instID[l-1] != RTC_INVALID_GEOMETRY_ID)); ++l)
+ for (unsigned l = 1; l < RTC_MAX_INSTANCE_LEVEL_COUNT && any(valid & (ray.instID[l-1] != RTC_INVALID_GEOMETRY_ID)); ++l) {
vuint<K>::storeu(valid, instID(l, offset), ray.instID[l]);
+#if defined(RTC_GEOMETRY_INSTANCE_ARRAY)
+ vuint<K>::storeu(valid, instPrimID(l, offset), ray.instPrimID[l]);
+#endif
+ }
#endif
}
}
@@ -698,9 +754,16 @@ namespace embree
vuint<K>::template scatter<1>(valid, geomID(), offset, ray.geomID);
vuint<K>::template scatter<1>(valid, instID(0), offset, ray.instID[0]);
+#if defined(RTC_GEOMETRY_INSTANCE_ARRAY)
+ vuint<K>::template scatter<1>(valid, instPrimID(0), offset, ray.instPrimID[0]);
+#endif
#if (RTC_MAX_INSTANCE_LEVEL_COUNT > 1)
- for (unsigned l = 1; l < RTC_MAX_INSTANCE_LEVEL_COUNT && any(valid & (ray.instID[l-1] != RTC_INVALID_GEOMETRY_ID)); ++l)
+ for (unsigned l = 1; l < RTC_MAX_INSTANCE_LEVEL_COUNT && any(valid & (ray.instID[l-1] != RTC_INVALID_GEOMETRY_ID)); ++l) {
vuint<K>::template scatter<1>(valid, instID(l), offset, ray.instID[l]);
+#if defined(RTC_GEOMETRY_INSTANCE_ARRAY)
+ vuint<K>::template scatter<1>(valid, instPrimID(l), offset, ray.instPrimID[l]);
+#endif
+ }
#endif
#else
size_t valid_bits = movemask(valid);
@@ -720,9 +783,16 @@ namespace embree
*geomID(ofs) = ray.geomID[k];
*instID(0, ofs) = ray.instID[0][k];
+#if defined(RTC_GEOMETRY_INSTANCE_ARRAY)
+ *instPrimID(0, ofs) = ray.instPrimID[0][k];
+#endif
#if (RTC_MAX_INSTANCE_LEVEL_COUNT > 1)
- for (unsigned l = 1; l < RTC_MAX_INSTANCE_LEVEL_COUNT && ray.instID[l-1][k] != RTC_INVALID_GEOMETRY_ID; ++l)
+ for (unsigned l = 1; l < RTC_MAX_INSTANCE_LEVEL_COUNT && ray.instID[l-1][k] != RTC_INVALID_GEOMETRY_ID; ++l) {
*instID(l, ofs) = ray.instID[l][k];
+#if defined(RTC_GEOMETRY_INSTANCE_ARRAY)
+ *instPrimID(l, ofs) = ray.instPrimID[l][k];
+#endif
+ }
#endif
}
#endif
@@ -792,8 +862,12 @@ namespace embree
primID = (unsigned int*)&t.primID;
geomID = (unsigned int*)&t.geomID;
- for (unsigned l = 0; l < RTC_MAX_INSTANCE_LEVEL_COUNT; ++l)
+ for (unsigned l = 0; l < RTC_MAX_INSTANCE_LEVEL_COUNT; ++l) {
instID[l] = (unsigned int*)&t.instID[l];
+#if defined(RTC_GEOMETRY_INSTANCE_ARRAY)
+ instPrimID[l] = (unsigned int*)&t.instPrimID[l];
+#endif
+ }
}
__forceinline Ray getRayByOffset(size_t offset)
@@ -859,9 +933,16 @@ namespace embree
if (likely(instID[0])) {
*(unsigned int* __restrict__)((char*)instID[0] + offset) = ray.instID[0];
+#if defined(RTC_GEOMETRY_INSTANCE_ARRAY)
+ *(unsigned int* __restrict__)((char*)instPrimID[0] + offset) = ray.instPrimID[0];
+#endif
#if (RTC_MAX_INSTANCE_LEVEL_COUNT > 1)
- for (unsigned l = 1; l < RTC_MAX_INSTANCE_LEVEL_COUNT && ray.instID[l-1] != RTC_INVALID_GEOMETRY_ID; ++l)
+ for (unsigned l = 1; l < RTC_MAX_INSTANCE_LEVEL_COUNT && ray.instID[l-1] != RTC_INVALID_GEOMETRY_ID; ++l) {
*(unsigned int* __restrict__)((char*)instID[l] + offset) = ray.instID[l];
+#if defined(RTC_GEOMETRY_INSTANCE_ARRAY)
+ *(unsigned int* __restrict__)((char*)instPrimID[l] + offset) = ray.instPrimID[l];
+#endif
+ }
#endif
}
}
@@ -892,9 +973,16 @@ namespace embree
if (likely(instID[0])) {
vuint<K>::storeu(valid, (unsigned int* __restrict__)((char*)instID[0] + offset), ray.instID[0]);
+#if defined(RTC_GEOMETRY_INSTANCE_ARRAY)
+ vuint<K>::storeu(valid, (unsigned int* __restrict__)((char*)instPrimID[0] + offset), ray.instPrimID[0]);
+#endif
#if (RTC_MAX_INSTANCE_LEVEL_COUNT > 1)
- for (unsigned l = 1; l < RTC_MAX_INSTANCE_LEVEL_COUNT && any(valid & (ray.instID[l-1] != RTC_INVALID_GEOMETRY_ID)); ++l)
+ for (unsigned l = 1; l < RTC_MAX_INSTANCE_LEVEL_COUNT && any(valid & (ray.instID[l-1] != RTC_INVALID_GEOMETRY_ID)); ++l) {
vuint<K>::storeu(valid, (unsigned int* __restrict__)((char*)instID[l] + offset), ray.instID[l]);
+#if defined(RTC_GEOMETRY_INSTANCE_ARRAY)
+ vuint<K>::storeu(valid, (unsigned int* __restrict__)((char*)instPrimID[l] + offset), ray.instPrimID[l]);
+#endif
+ }
#endif
}
}
@@ -1008,9 +1096,16 @@ namespace embree
if (likely(instID[0])) {
vuint<K>::template scatter<1>(valid, (unsigned int*)instID[0], offset, ray.instID[0]);
+#if defined(RTC_GEOMETRY_INSTANCE_ARRAY)
+ vuint<K>::template scatter<1>(valid, (unsigned int*)instPrimID[0], offset, ray.instPrimID[0]);
+#endif
#if (RTC_MAX_INSTANCE_LEVEL_COUNT > 1)
- for (unsigned l = 1; l < RTC_MAX_INSTANCE_LEVEL_COUNT && any(valid & (ray.instID[l-1] != RTC_INVALID_GEOMETRY_ID)); ++l)
+ for (unsigned l = 1; l < RTC_MAX_INSTANCE_LEVEL_COUNT && any(valid & (ray.instID[l-1] != RTC_INVALID_GEOMETRY_ID)); ++l) {
vuint<K>::template scatter<1>(valid, (unsigned int*)instID[l], offset, ray.instID[l]);
+#if defined(RTC_GEOMETRY_INSTANCE_ARRAY)
+ vuint<K>::template scatter<1>(valid, (unsigned int*)instPrimID[l], offset, ray.instPrimID[l]);
+#endif
+ }
#endif
}
#else
@@ -1032,9 +1127,16 @@ namespace embree
if (likely(instID[0])) {
*(unsigned int* __restrict__)((char*)instID[0] + ofs) = ray.instID[0][k];
+#if defined(RTC_GEOMETRY_INSTANCE_ARRAY)
+ *(unsigned int* __restrict__)((char*)instPrimID[0] + ofs) = ray.instPrimID[0][k];
+#endif
#if (RTC_MAX_INSTANCE_LEVEL_COUNT > 1)
- for (unsigned l = 1; l < RTC_MAX_INSTANCE_LEVEL_COUNT && ray.instID[l-1][k] != RTC_INVALID_GEOMETRY_ID; ++l)
+ for (unsigned l = 1; l < RTC_MAX_INSTANCE_LEVEL_COUNT && ray.instID[l-1][k] != RTC_INVALID_GEOMETRY_ID; ++l) {
*(unsigned int* __restrict__)((char*)instID[l] + ofs) = ray.instID[l][k];
+#if defined(RTC_GEOMETRY_INSTANCE_ARRAY)
+ *(unsigned int* __restrict__)((char*)instPrimID[l] + ofs) = ray.instPrimID[l][k];
+#endif
+ }
#endif
}
}
@@ -1091,7 +1193,10 @@ namespace embree
unsigned int* __restrict__ primID; // primitive ID
unsigned int* __restrict__ geomID; // geometry ID
- unsigned int* __restrict__ instID[RTC_MAX_INSTANCE_LEVEL_COUNT]; // instance ID (optional)
+ unsigned int* __restrict__ instID[RTC_MAX_INSTANCE_LEVEL_COUNT]; // instance ID
+#if defined(RTC_GEOMETRY_INSTANCE_ARRAY)
+ unsigned int* __restrict__ instPrimID[RTC_MAX_INSTANCE_LEVEL_COUNT]; // instance primitive ID (optional)
+#endif
};
@@ -1134,9 +1239,16 @@ namespace embree
vuint<K>::template scatter<1>(valid, (unsigned int*)&((RayHit*)ptr)->geomID, offset, ray.geomID);
vuint<K>::template scatter<1>(valid, (unsigned int*)&((RayHit*)ptr)->instID[0], offset, ray.instID[0]);
+#if defined(RTC_GEOMETRY_INSTANCE_ARRAY)
+ vuint<K>::template scatter<1>(valid, (unsigned int*)&((RayHit*)ptr)->instPrimID[0], offset, ray.instPrimID[0]);
+#endif
#if (RTC_MAX_INSTANCE_LEVEL_COUNT > 1)
- for (unsigned l = 1; l < RTC_MAX_INSTANCE_LEVEL_COUNT && any(valid & (ray.instID[l-1] != RTC_INVALID_GEOMETRY_ID)); ++l)
+ for (unsigned l = 1; l < RTC_MAX_INSTANCE_LEVEL_COUNT && any(valid & (ray.instID[l-1] != RTC_INVALID_GEOMETRY_ID)); ++l) {
vuint<K>::template scatter<1>(valid, (unsigned int*)&((RayHit*)ptr)->instID[l], offset, ray.instID[l]);
+#if defined(RTC_GEOMETRY_INSTANCE_ARRAY)
+ vuint<K>::template scatter<1>(valid, (unsigned int*)&((RayHit*)ptr)->instPrimID[l], offset, ray.instPrimID[l]);
+#endif
+ }
#endif
#else
size_t valid_bits = movemask(valid);
@@ -1154,6 +1266,9 @@ namespace embree
ray_k->geomID = ray.geomID[k];
instance_id_stack::copy_VU<K>(ray.instID, ray_k->instID, k);
+#if defined(RTC_GEOMETRY_INSTANCE_ARRAY)
+ instance_id_stack::copy_VU<K>(ray.instPrimID, ray_k->instPrimID, k);
+#endif
}
#endif
}
@@ -1183,7 +1298,7 @@ namespace embree
Ray* __restrict__ ptr;
};
-
+
template<>
__forceinline Ray4 RayStreamAOS::getRayByOffset<4>(const vint4& offset)
{
@@ -1219,7 +1334,7 @@ namespace embree
return ray;
}
-
+
#if defined(__AVX__)
template<>
__forceinline Ray8 RayStreamAOS::getRayByOffset<8>(const vint8& offset)
@@ -1358,6 +1473,9 @@ namespace embree
ray_k->primID = ray.primID[k];
ray_k->geomID = ray.geomID[k];
instance_id_stack::copy_VU<K>(ray.instID, ray_k->instID, k);
+#if defined(RTC_GEOMETRY_INSTANCE_ARRAY)
+ instance_id_stack::copy_VU<K>(ray.instPrimID, ray_k->instPrimID, k);
+#endif
}
}
}
@@ -1383,7 +1501,7 @@ namespace embree
Ray** __restrict__ ptr;
};
-
+
template<>
__forceinline Ray4 RayStreamAOP::getRayByIndex<4>(const vint4& index)
{
@@ -1419,7 +1537,7 @@ namespace embree
return ray;
}
-
+
#if defined(__AVX__)
template<>
__forceinline Ray8 RayStreamAOP::getRayByIndex<8>(const vint8& index)
diff --git a/thirdparty/embree/kernels/common/rtcore.cpp b/thirdparty/embree/kernels/common/rtcore.cpp
index a6ea55bfc4..eb8d2c0a58 100644
--- a/thirdparty/embree/kernels/common/rtcore.cpp
+++ b/thirdparty/embree/kernels/common/rtcore.cpp
@@ -8,11 +8,14 @@
#include "scene.h"
#include "context.h"
#include "../geometry/filter.h"
-#include "../../include/embree3/rtcore_ray.h"
+#include "../../include/embree4/rtcore_ray.h"
using namespace embree;
RTC_NAMESPACE_BEGIN;
+#define RTC_ENTER_DEVICE(arg) \
+ DeviceEnterLeave enterleave(arg);
+
/* mutex to make API thread safe */
static MutexSys g_mutex;
@@ -27,6 +30,57 @@ RTC_NAMESPACE_BEGIN;
return (RTCDevice) nullptr;
}
+#if defined(EMBREE_SYCL_SUPPORT)
+
+ RTC_API RTCDevice rtcNewSYCLDeviceInternal(sycl::context sycl_context, const char* config)
+ {
+ RTC_CATCH_BEGIN;
+ RTC_TRACE(rtcNewSYCLDevice);
+ Lock<MutexSys> lock(g_mutex);
+
+ DeviceGPU* device = new DeviceGPU(sycl_context,config);
+ return (RTCDevice) device->refInc();
+ RTC_CATCH_END(nullptr);
+ return (RTCDevice) nullptr;
+ }
+
+ RTC_API bool rtcIsSYCLDeviceSupported(const sycl::device device)
+ {
+ RTC_CATCH_BEGIN;
+ RTC_TRACE(rtcIsSYCLDeviceSupported);
+ return rthwifIsSYCLDeviceSupported(device) > 0;
+ RTC_CATCH_END(nullptr);
+ return false;
+ }
+
+ RTC_API int rtcSYCLDeviceSelector(const sycl::device device)
+ {
+ RTC_CATCH_BEGIN;
+ RTC_TRACE(rtcSYCLDeviceSelector);
+ return rthwifIsSYCLDeviceSupported(device);
+ RTC_CATCH_END(nullptr);
+ return -1;
+ }
+
+ RTC_API void rtcSetDeviceSYCLDevice(RTCDevice hdevice, const sycl::device sycl_device)
+ {
+ RTC_CATCH_BEGIN;
+ RTC_TRACE(rtcSetDeviceSYCLDevice);
+ RTC_VERIFY_HANDLE(hdevice);
+
+ Lock<MutexSys> lock(g_mutex);
+
+ DeviceGPU* device = dynamic_cast<DeviceGPU*>((Device*) hdevice);
+ if (device == nullptr)
+ throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "passed device must be an Embree SYCL device")
+
+ device->setSYCLDevice(sycl_device);
+
+ RTC_CATCH_END(nullptr);
+ }
+
+#endif
+
RTC_API void rtcRetainDevice(RTCDevice hdevice)
{
Device* device = (Device*) hdevice;
@@ -108,6 +162,7 @@ RTC_NAMESPACE_BEGIN;
RTC_CATCH_BEGIN;
RTC_TRACE(rtcNewBuffer);
RTC_VERIFY_HANDLE(hdevice);
+ RTC_ENTER_DEVICE(hdevice);
Buffer* buffer = new Buffer((Device*)hdevice, byteSize);
return (RTCBuffer)buffer->refInc();
RTC_CATCH_END((Device*)hdevice);
@@ -119,6 +174,7 @@ RTC_NAMESPACE_BEGIN;
RTC_CATCH_BEGIN;
RTC_TRACE(rtcNewSharedBuffer);
RTC_VERIFY_HANDLE(hdevice);
+ RTC_ENTER_DEVICE(hdevice);
Buffer* buffer = new Buffer((Device*)hdevice, byteSize, ptr);
return (RTCBuffer)buffer->refInc();
RTC_CATCH_END((Device*)hdevice);
@@ -131,6 +187,7 @@ RTC_NAMESPACE_BEGIN;
RTC_CATCH_BEGIN;
RTC_TRACE(rtcGetBufferData);
RTC_VERIFY_HANDLE(hbuffer);
+ RTC_ENTER_DEVICE(hbuffer);
return buffer->data();
RTC_CATCH_END2(buffer);
return nullptr;
@@ -142,6 +199,7 @@ RTC_NAMESPACE_BEGIN;
RTC_CATCH_BEGIN;
RTC_TRACE(rtcRetainBuffer);
RTC_VERIFY_HANDLE(hbuffer);
+ RTC_ENTER_DEVICE(hbuffer);
buffer->refInc();
RTC_CATCH_END2(buffer);
}
@@ -152,6 +210,7 @@ RTC_NAMESPACE_BEGIN;
RTC_CATCH_BEGIN;
RTC_TRACE(rtcReleaseBuffer);
RTC_VERIFY_HANDLE(hbuffer);
+ RTC_ENTER_DEVICE(hbuffer);
buffer->refDec();
RTC_CATCH_END2(buffer);
}
@@ -161,6 +220,7 @@ RTC_NAMESPACE_BEGIN;
RTC_CATCH_BEGIN;
RTC_TRACE(rtcNewScene);
RTC_VERIFY_HANDLE(hdevice);
+ RTC_ENTER_DEVICE(hdevice);
Scene* scene = new Scene((Device*)hdevice);
return (RTCScene) scene->refInc();
RTC_CATCH_END((Device*)hdevice);
@@ -184,6 +244,7 @@ RTC_NAMESPACE_BEGIN;
RTC_CATCH_BEGIN;
RTC_TRACE(rtcSetSceneProgressMonitorFunction);
RTC_VERIFY_HANDLE(hscene);
+ RTC_ENTER_DEVICE(hscene);
Lock<MutexSys> lock(g_mutex);
scene->setProgressMonitorFunction(progress,ptr);
RTC_CATCH_END2(scene);
@@ -195,13 +256,18 @@ RTC_NAMESPACE_BEGIN;
RTC_CATCH_BEGIN;
RTC_TRACE(rtcSetSceneBuildQuality);
RTC_VERIFY_HANDLE(hscene);
+ RTC_ENTER_DEVICE(hscene);
+ // -- GODOT start --
+ // if (quality != RTC_BUILD_QUALITY_LOW &&
+ // quality != RTC_BUILD_QUALITY_MEDIUM &&
+ // quality != RTC_BUILD_QUALITY_HIGH)
+ // throw std::runtime_error("invalid build quality");
if (quality != RTC_BUILD_QUALITY_LOW &&
quality != RTC_BUILD_QUALITY_MEDIUM &&
- quality != RTC_BUILD_QUALITY_HIGH)
- // -- GODOT start --
- // throw std::runtime_error("invalid build quality");
+ quality != RTC_BUILD_QUALITY_HIGH) {
abort();
- // -- GODOT end --
+ }
+ // -- GODOT end --
scene->setBuildQuality(quality);
RTC_CATCH_END2(scene);
}
@@ -212,6 +278,7 @@ RTC_NAMESPACE_BEGIN;
RTC_CATCH_BEGIN;
RTC_TRACE(rtcSetSceneFlags);
RTC_VERIFY_HANDLE(hscene);
+ RTC_ENTER_DEVICE(hscene);
scene->setSceneFlags(flags);
RTC_CATCH_END2(scene);
}
@@ -222,6 +289,7 @@ RTC_NAMESPACE_BEGIN;
RTC_CATCH_BEGIN;
RTC_TRACE(rtcGetSceneFlags);
RTC_VERIFY_HANDLE(hscene);
+ RTC_ENTER_DEVICE(hscene);
return scene->getSceneFlags();
RTC_CATCH_END2(scene);
return RTC_SCENE_FLAG_NONE;
@@ -233,6 +301,7 @@ RTC_NAMESPACE_BEGIN;
RTC_CATCH_BEGIN;
RTC_TRACE(rtcCommitScene);
RTC_VERIFY_HANDLE(hscene);
+ RTC_ENTER_DEVICE(hscene);
scene->commit(false);
RTC_CATCH_END2(scene);
}
@@ -243,6 +312,7 @@ RTC_NAMESPACE_BEGIN;
RTC_CATCH_BEGIN;
RTC_TRACE(rtcJoinCommitScene);
RTC_VERIFY_HANDLE(hscene);
+ RTC_ENTER_DEVICE(hscene);
scene->commit(true);
RTC_CATCH_END2(scene);
}
@@ -253,6 +323,7 @@ RTC_NAMESPACE_BEGIN;
RTC_CATCH_BEGIN;
RTC_TRACE(rtcGetSceneBounds);
RTC_VERIFY_HANDLE(hscene);
+ RTC_ENTER_DEVICE(hscene);
if (scene->isModified()) throw_RTCError(RTC_ERROR_INVALID_OPERATION,"scene not committed");
BBox3fa bounds = scene->bounds.bounds();
bounds_o->lower_x = bounds.lower.x;
@@ -272,6 +343,7 @@ RTC_NAMESPACE_BEGIN;
RTC_CATCH_BEGIN;
RTC_TRACE(rtcGetSceneBounds);
RTC_VERIFY_HANDLE(hscene);
+ RTC_ENTER_DEVICE(hscene);
if (bounds_o == nullptr)
throw_RTCError(RTC_ERROR_INVALID_OPERATION,"invalid destination pointer");
if (scene->isModified())
@@ -447,7 +519,7 @@ RTC_NAMESPACE_BEGIN;
RTC_CATCH_END2_FALSE(scene);
}
- RTC_API void rtcIntersect1 (RTCScene hscene, RTCIntersectContext* user_context, RTCRayHit* rayhit)
+ RTC_API void rtcIntersect1 (RTCScene hscene, RTCRayHit* rayhit, RTCIntersectArguments* args)
{
Scene* scene = (Scene*) hscene;
RTC_CATCH_BEGIN;
@@ -458,7 +530,21 @@ RTC_NAMESPACE_BEGIN;
if (((size_t)rayhit) & 0x0F) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "ray not aligned to 16 bytes");
#endif
STAT3(normal.travs,1,1,1);
- IntersectContext context(scene,user_context);
+
+ RTCIntersectArguments defaultArgs;
+ if (unlikely(args == nullptr)) {
+ rtcInitIntersectArguments(&defaultArgs);
+ args = &defaultArgs;
+ }
+ RTCRayQueryContext* user_context = args->context;
+
+ RTCRayQueryContext defaultContext;
+ if (unlikely(user_context == nullptr)) {
+ rtcInitRayQueryContext(&defaultContext);
+ user_context = &defaultContext;
+ }
+ RayQueryContext context(scene,user_context,args);
+
scene->intersectors.intersect(*rayhit,&context);
#if defined(DEBUG)
((RayHit*)rayhit)->verifyHit();
@@ -466,7 +552,45 @@ RTC_NAMESPACE_BEGIN;
RTC_CATCH_END2(scene);
}
- RTC_API void rtcIntersect4 (const int* valid, RTCScene hscene, RTCIntersectContext* user_context, RTCRayHit4* rayhit)
+ RTC_API void rtcForwardIntersect1 (const RTCIntersectFunctionNArguments* args, RTCScene hscene, RTCRay* iray_, unsigned int instID)
+ {
+ rtcForwardIntersect1Ex(args, hscene, iray_, instID, 0);
+ }
+
+ RTC_API void rtcForwardIntersect1Ex(const RTCIntersectFunctionNArguments* args, RTCScene hscene, RTCRay* iray_, unsigned int instID, unsigned int instPrimID)
+ {
+ Scene* scene = (Scene*) hscene;
+ RTC_CATCH_BEGIN;
+ RTC_TRACE(rtcForwardIntersect1Ex);
+#if defined(DEBUG)
+ RTC_VERIFY_HANDLE(hscene);
+ if (scene->isModified()) throw_RTCError(RTC_ERROR_INVALID_OPERATION,"scene not committed");
+ if (((size_t)iray_) & 0x0F) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "ray not aligned to 16 bytes");
+#endif
+
+ Ray* iray = (Ray*) iray_;
+ RayHit* oray = (RayHit*)args->rayhit;
+ RTCRayQueryContext* user_context = args->context;
+ const Vec3ff ray_org_tnear = oray->org;
+ const Vec3ff ray_dir_time = oray->dir;
+ oray->org = iray->org;
+ oray->dir = iray->dir;
+ STAT3(normal.travs,1,1,1);
+
+ RTCIntersectArguments* iargs = ((IntersectFunctionNArguments*) args)->args;
+ RayQueryContext context(scene,user_context,iargs);
+
+ instance_id_stack::push(user_context, instID, instPrimID);
+ scene->intersectors.intersect(*(RTCRayHit*)oray,&context);
+ instance_id_stack::pop(user_context);
+
+ oray->org = ray_org_tnear;
+ oray->dir = ray_dir_time;
+
+ RTC_CATCH_END2(scene);
+ }
+
+ RTC_API void rtcIntersect4 (const int* valid, RTCScene hscene, RTCRayHit4* rayhit, RTCIntersectArguments* args)
{
Scene* scene = (Scene*) hscene;
RTC_CATCH_BEGIN;
@@ -481,23 +605,119 @@ RTC_NAMESPACE_BEGIN;
STAT(size_t cnt=0; for (size_t i=0; i<4; i++) cnt += ((int*)valid)[i] == -1;);
STAT3(normal.travs,cnt,cnt,cnt);
- IntersectContext context(scene,user_context);
-#if !defined(EMBREE_RAY_PACKETS)
- RayHit4* ray4 = (RayHit4*) rayhit;
- for (size_t i=0; i<4; i++) {
- if (!valid[i]) continue;
- RayHit ray1; ray4->get(i,ray1);
- scene->intersectors.intersect((RTCRayHit&)ray1,&context);
- ray4->set(i,ray1);
+ RTCIntersectArguments defaultArgs;
+ if (unlikely(args == nullptr)) {
+ rtcInitIntersectArguments(&defaultArgs);
+ args = &defaultArgs;
+ }
+ RTCRayQueryContext* user_context = args->context;
+
+ RTCRayQueryContext defaultContext;
+ if (unlikely(user_context == nullptr)) {
+ rtcInitRayQueryContext(&defaultContext);
+ user_context = &defaultContext;
+ }
+ RayQueryContext context(scene,user_context,args);
+
+ if (likely(scene->intersectors.intersector4))
+ scene->intersectors.intersect4(valid,*rayhit,&context);
+
+ else {
+ RayHit4* ray4 = (RayHit4*) rayhit;
+ for (size_t i=0; i<4; i++) {
+ if (!valid[i]) continue;
+ RayHit ray1; ray4->get(i,ray1);
+ scene->intersectors.intersect((RTCRayHit&)ray1,&context);
+ ray4->set(i,ray1);
+ }
}
-#else
- scene->intersectors.intersect4(valid,*rayhit,&context);
-#endif
RTC_CATCH_END2(scene);
}
+
+ template<int N> void copy(float* dst, float* src);
+
+ template<>
+ __forceinline void copy<4>(float* dst, float* src) {
+ vfloat4::storeu(&dst[0],vfloat4::loadu(&src[0]));
+ }
+
+ template<>
+ __forceinline void copy<8>(float* dst, float* src) {
+ vfloat4::storeu(&dst[0],vfloat4::loadu(&src[0]));
+ vfloat4::storeu(&dst[4],vfloat4::loadu(&src[4]));
+ }
+
+ template<>
+ __forceinline void copy<16>(float* dst, float* src) {
+ vfloat4::storeu(&dst[0],vfloat4::loadu(&src[0]));
+ vfloat4::storeu(&dst[4],vfloat4::loadu(&src[4]));
+ vfloat4::storeu(&dst[8],vfloat4::loadu(&src[8]));
+ vfloat4::storeu(&dst[12],vfloat4::loadu(&src[12]));
+ }
+
+ template<typename RTCRay, typename RTCRayHit, int N>
+ __forceinline void rtcForwardIntersectN(const int* valid, const RTCIntersectFunctionNArguments* args, RTCScene hscene, RTCRay* iray, unsigned int instID, unsigned int instPrimID)
+ {
+ Scene* scene = (Scene*) hscene;
+ RTCRayHit* oray = (RTCRayHit*)args->rayhit;
+ RTCRayQueryContext* user_context = args->context;
+
+ __aligned(16) float ray_org_x[N];
+ __aligned(16) float ray_org_y[N];
+ __aligned(16) float ray_org_z[N];
+ __aligned(16) float ray_dir_x[N];
+ __aligned(16) float ray_dir_y[N];
+ __aligned(16) float ray_dir_z[N];
+
+ copy<N>(ray_org_x,oray->ray.org_x);
+ copy<N>(ray_org_y,oray->ray.org_y);
+ copy<N>(ray_org_z,oray->ray.org_z);
+ copy<N>(ray_dir_x,oray->ray.dir_x);
+ copy<N>(ray_dir_y,oray->ray.dir_y);
+ copy<N>(ray_dir_z,oray->ray.dir_z);
+
+ copy<N>(oray->ray.org_x,iray->org_x);
+ copy<N>(oray->ray.org_y,iray->org_y);
+ copy<N>(oray->ray.org_z,iray->org_z);
+ copy<N>(oray->ray.dir_x,iray->dir_x);
+ copy<N>(oray->ray.dir_y,iray->dir_y);
+ copy<N>(oray->ray.dir_z,iray->dir_z);
+
+ STAT(size_t cnt=0; for (size_t i=0; i<N; i++) cnt += ((int*)valid)[i] == -1;);
+ STAT3(normal.travs,cnt,cnt,cnt);
+
+ RTCIntersectArguments* iargs = ((IntersectFunctionNArguments*) args)->args;
+ RayQueryContext context(scene,user_context,iargs);
+
+ instance_id_stack::push(user_context, instID, instPrimID);
+ scene->intersectors.intersect(valid,*oray,&context);
+ instance_id_stack::pop(user_context);
+
+ copy<N>(oray->ray.org_x,ray_org_x);
+ copy<N>(oray->ray.org_y,ray_org_y);
+ copy<N>(oray->ray.org_z,ray_org_z);
+ copy<N>(oray->ray.dir_x,ray_dir_x);
+ copy<N>(oray->ray.dir_y,ray_dir_y);
+ copy<N>(oray->ray.dir_z,ray_dir_z);
+ }
+
+ RTC_API void rtcForwardIntersect4(const int* valid, const RTCIntersectFunctionNArguments* args, RTCScene hscene, RTCRay4* iray, unsigned int instID)
+ {
+ RTC_TRACE(rtcForwardIntersect4);
+ return rtcForwardIntersect4Ex(valid, args, hscene, iray, instID, 0);
+ }
+
+ RTC_API void rtcForwardIntersect4Ex(const int* valid, const RTCIntersectFunctionNArguments* args, RTCScene hscene, RTCRay4* iray, unsigned int instID, unsigned int instPrimID)
+ {
+ Scene* scene = (Scene*) hscene;
+ RTC_CATCH_BEGIN;
+ RTC_TRACE(rtcForwardIntersect4);
+ rtcForwardIntersectN<RTCRay4,RTCRayHit4,4>(valid,args,hscene,iray,instID,instPrimID);
+ RTC_CATCH_END2(scene);
+ }
- RTC_API void rtcIntersect8 (const int* valid, RTCScene hscene, RTCIntersectContext* user_context, RTCRayHit8* rayhit)
+ RTC_API void rtcIntersect8 (const int* valid, RTCScene hscene, RTCRayHit8* rayhit, RTCIntersectArguments* args)
{
Scene* scene = (Scene*) hscene;
RTC_CATCH_BEGIN;
@@ -512,25 +732,53 @@ RTC_NAMESPACE_BEGIN;
STAT(size_t cnt=0; for (size_t i=0; i<8; i++) cnt += ((int*)valid)[i] == -1;);
STAT3(normal.travs,cnt,cnt,cnt);
- IntersectContext context(scene,user_context);
-#if !defined(EMBREE_RAY_PACKETS)
- RayHit8* ray8 = (RayHit8*) rayhit;
- for (size_t i=0; i<8; i++) {
- if (!valid[i]) continue;
- RayHit ray1; ray8->get(i,ray1);
- scene->intersectors.intersect((RTCRayHit&)ray1,&context);
- ray8->set(i,ray1);
+ RTCIntersectArguments defaultArgs;
+ if (unlikely(args == nullptr)) {
+ rtcInitIntersectArguments(&defaultArgs);
+ args = &defaultArgs;
}
-#else
- if (likely(scene->intersectors.intersector8))
+ RTCRayQueryContext* user_context = args->context;
+
+ RTCRayQueryContext defaultContext;
+ if (unlikely(user_context == nullptr)) {
+ rtcInitRayQueryContext(&defaultContext);
+ user_context = &defaultContext;
+ }
+ RayQueryContext context(scene,user_context,args);
+
+ if (likely(scene->intersectors.intersector8))
scene->intersectors.intersect8(valid,*rayhit,&context);
+
else
- scene->device->rayStreamFilters.intersectSOA(scene,(char*)rayhit,8,1,sizeof(RTCRayHit8),&context);
-#endif
+ {
+ RayHit8* ray8 = (RayHit8*) rayhit;
+ for (size_t i=0; i<8; i++) {
+ if (!valid[i]) continue;
+ RayHit ray1; ray8->get(i,ray1);
+ scene->intersectors.intersect((RTCRayHit&)ray1,&context);
+ ray8->set(i,ray1);
+ }
+ }
+
RTC_CATCH_END2(scene);
}
-
- RTC_API void rtcIntersect16 (const int* valid, RTCScene hscene, RTCIntersectContext* user_context, RTCRayHit16* rayhit)
+
+ RTC_API void rtcForwardIntersect8(const int* valid, const RTCIntersectFunctionNArguments* args, RTCScene hscene, RTCRay8* iray, unsigned int instID)
+ {
+ RTC_TRACE(rtcForwardIntersect8);
+ return rtcForwardIntersect8Ex(valid, args, hscene, iray, instID, 0);
+ }
+
+ RTC_API void rtcForwardIntersect8Ex(const int* valid, const RTCIntersectFunctionNArguments* args, RTCScene hscene, RTCRay8* iray, unsigned int instID, unsigned int instPrimID)
+ {
+ Scene* scene = (Scene*) hscene;
+ RTC_CATCH_BEGIN;
+ RTC_TRACE(rtcForwardIntersect8Ex);
+ rtcForwardIntersectN<RTCRay8,RTCRayHit8,8>(valid,args,hscene,iray,instID,instPrimID);
+ RTC_CATCH_END2(scene);
+ }
+
+ RTC_API void rtcIntersect16 (const int* valid, RTCScene hscene, RTCRayHit16* rayhit, RTCIntersectArguments* args)
{
Scene* scene = (Scene*) hscene;
RTC_CATCH_BEGIN;
@@ -545,179 +793,121 @@ RTC_NAMESPACE_BEGIN;
STAT(size_t cnt=0; for (size_t i=0; i<16; i++) cnt += ((int*)valid)[i] == -1;);
STAT3(normal.travs,cnt,cnt,cnt);
- IntersectContext context(scene,user_context);
-#if !defined(EMBREE_RAY_PACKETS)
- RayHit16* ray16 = (RayHit16*) rayhit;
- for (size_t i=0; i<16; i++) {
- if (!valid[i]) continue;
- RayHit ray1; ray16->get(i,ray1);
- scene->intersectors.intersect((RTCRayHit&)ray1,&context);
- ray16->set(i,ray1);
+ RTCIntersectArguments defaultArgs;
+ if (unlikely(args == nullptr)) {
+ rtcInitIntersectArguments(&defaultArgs);
+ args = &defaultArgs;
}
-#else
+ RTCRayQueryContext* user_context = args->context;
+
+ RTCRayQueryContext defaultContext;
+ if (unlikely(user_context == nullptr)) {
+ rtcInitRayQueryContext(&defaultContext);
+ user_context = &defaultContext;
+ }
+ RayQueryContext context(scene,user_context,args);
+
if (likely(scene->intersectors.intersector16))
scene->intersectors.intersect16(valid,*rayhit,&context);
- else
- scene->device->rayStreamFilters.intersectSOA(scene,(char*)rayhit,16,1,sizeof(RTCRayHit16),&context);
-#endif
- RTC_CATCH_END2(scene);
- }
-
- RTC_API void rtcIntersect1M (RTCScene hscene, RTCIntersectContext* user_context, RTCRayHit* rayhit, unsigned int M, size_t byteStride)
- {
- Scene* scene = (Scene*) hscene;
- RTC_CATCH_BEGIN;
- RTC_TRACE(rtcIntersect1M);
-
-#if defined (EMBREE_RAY_PACKETS)
-#if defined(DEBUG)
- RTC_VERIFY_HANDLE(hscene);
- if (scene->isModified()) throw_RTCError(RTC_ERROR_INVALID_OPERATION,"scene not committed");
- if (((size_t)rayhit ) & 0x03) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "ray not aligned to 4 bytes");
-#endif
- STAT3(normal.travs,M,M,M);
- IntersectContext context(scene,user_context);
- /* fast codepath for single rays */
- if (likely(M == 1)) {
- if (likely(rayhit->ray.tnear <= rayhit->ray.tfar))
- scene->intersectors.intersect(*rayhit,&context);
- }
-
- /* codepath for streams */
else {
- scene->device->rayStreamFilters.intersectAOS(scene,rayhit,M,byteStride,&context);
+ RayHit16* ray16 = (RayHit16*) rayhit;
+ for (size_t i=0; i<16; i++) {
+ if (!valid[i]) continue;
+ RayHit ray1; ray16->get(i,ray1);
+ scene->intersectors.intersect((RTCRayHit&)ray1,&context);
+ ray16->set(i,ray1);
+ }
}
-#else
- throw_RTCError(RTC_ERROR_INVALID_OPERATION,"rtcIntersect1M not supported");
-#endif
+
RTC_CATCH_END2(scene);
}
- RTC_API void rtcIntersect1Mp (RTCScene hscene, RTCIntersectContext* user_context, RTCRayHit** rn, unsigned int M)
+ RTC_API void rtcForwardIntersect16(const int* valid, const RTCIntersectFunctionNArguments* args, RTCScene hscene, RTCRay16* iray, unsigned int instID)
+ {
+ RTC_TRACE(rtcForwardIntersect16);
+ return rtcForwardIntersect16Ex(valid, args, hscene, iray, instID, 0);
+ }
+
+ RTC_API void rtcForwardIntersect16Ex(const int* valid, const RTCIntersectFunctionNArguments* args, RTCScene hscene, RTCRay16* iray, unsigned int instID, unsigned int instPrimID)
{
Scene* scene = (Scene*) hscene;
RTC_CATCH_BEGIN;
- RTC_TRACE(rtcIntersect1Mp);
-
-#if defined (EMBREE_RAY_PACKETS)
-#if defined(DEBUG)
- RTC_VERIFY_HANDLE(hscene);
- if (scene->isModified()) throw_RTCError(RTC_ERROR_INVALID_OPERATION,"scene not committed");
- if (((size_t)rn) & 0x03) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "ray not aligned to 4 bytes");
-#endif
- STAT3(normal.travs,M,M,M);
- IntersectContext context(scene,user_context);
-
- /* fast codepath for single rays */
- if (likely(M == 1)) {
- if (likely(rn[0]->ray.tnear <= rn[0]->ray.tfar))
- scene->intersectors.intersect(*rn[0],&context);
- }
-
- /* codepath for streams */
- else {
- scene->device->rayStreamFilters.intersectAOP(scene,rn,M,&context);
- }
-#else
- throw_RTCError(RTC_ERROR_INVALID_OPERATION,"rtcIntersect1Mp not supported");
-#endif
+ RTC_TRACE(rtcForwardIntersect16Ex);
+ rtcForwardIntersectN<RTCRay16,RTCRayHit16,16>(valid,args,hscene,iray,instID,instPrimID);
RTC_CATCH_END2(scene);
}
- RTC_API void rtcIntersectNM (RTCScene hscene, RTCIntersectContext* user_context, struct RTCRayHitN* rayhit, unsigned int N, unsigned int M, size_t byteStride)
+ RTC_API void rtcOccluded1 (RTCScene hscene, RTCRay* ray, RTCOccludedArguments* args)
{
Scene* scene = (Scene*) hscene;
RTC_CATCH_BEGIN;
- RTC_TRACE(rtcIntersectNM);
-
-#if defined (EMBREE_RAY_PACKETS)
+ RTC_TRACE(rtcOccluded1);
+ STAT3(shadow.travs,1,1,1);
#if defined(DEBUG)
RTC_VERIFY_HANDLE(hscene);
if (scene->isModified()) throw_RTCError(RTC_ERROR_INVALID_OPERATION,"scene not committed");
- if (((size_t)rayhit) & 0x03) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "ray not aligned to 4 bytes");
+ if (((size_t)ray) & 0x0F) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "ray not aligned to 16 bytes");
#endif
- STAT3(normal.travs,N*M,N*M,N*M);
- IntersectContext context(scene,user_context);
- /* code path for single ray streams */
- if (likely(N == 1))
- {
- /* fast code path for streams of size 1 */
- if (likely(M == 1)) {
- if (likely(((RTCRayHit*)rayhit)->ray.tnear <= ((RTCRayHit*)rayhit)->ray.tfar))
- scene->intersectors.intersect(*(RTCRayHit*)rayhit,&context);
- }
- /* normal codepath for single ray streams */
- else {
- scene->device->rayStreamFilters.intersectAOS(scene,(RTCRayHit*)rayhit,M,byteStride,&context);
- }
+ RTCOccludedArguments defaultArgs;
+ if (unlikely(args == nullptr)) {
+ rtcInitOccludedArguments(&defaultArgs);
+ args = &defaultArgs;
}
- /* code path for ray packet streams */
- else {
- scene->device->rayStreamFilters.intersectSOA(scene,(char*)rayhit,N,M,byteStride,&context);
+ RTCRayQueryContext* user_context = args->context;
+
+ RTCRayQueryContext defaultContext;
+ if (unlikely(user_context == nullptr)) {
+ rtcInitRayQueryContext(&defaultContext);
+ user_context = &defaultContext;
}
-#else
- throw_RTCError(RTC_ERROR_INVALID_OPERATION,"rtcIntersectNM not supported");
-#endif
+ RayQueryContext context(scene,user_context,args);
+
+ scene->intersectors.occluded(*ray,&context);
RTC_CATCH_END2(scene);
}
- RTC_API void rtcIntersectNp (RTCScene hscene, RTCIntersectContext* user_context, const RTCRayHitNp* rayhit, unsigned int N)
+ RTC_API void rtcForwardOccluded1 (const RTCOccludedFunctionNArguments* args, RTCScene hscene, RTCRay* iray_, unsigned int instID)
{
- Scene* scene = (Scene*) hscene;
- RTC_CATCH_BEGIN;
- RTC_TRACE(rtcIntersectNp);
-
-#if defined (EMBREE_RAY_PACKETS)
-#if defined(DEBUG)
- RTC_VERIFY_HANDLE(hscene);
- if (scene->isModified()) throw_RTCError(RTC_ERROR_INVALID_OPERATION,"scene not committed");
- if (((size_t)rayhit->ray.org_x ) & 0x03 ) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "rayhit->ray.org_x not aligned to 4 bytes");
- if (((size_t)rayhit->ray.org_y ) & 0x03 ) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "rayhit->ray.org_y not aligned to 4 bytes");
- if (((size_t)rayhit->ray.org_z ) & 0x03 ) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "rayhit->ray.org_z not aligned to 4 bytes");
- if (((size_t)rayhit->ray.dir_x ) & 0x03 ) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "rayhit->ray.dir_x not aligned to 4 bytes");
- if (((size_t)rayhit->ray.dir_y ) & 0x03 ) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "rayhit->ray.dir_y not aligned to 4 bytes");
- if (((size_t)rayhit->ray.dir_z ) & 0x03 ) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "rayhit->ray.dir_z not aligned to 4 bytes");
- if (((size_t)rayhit->ray.tnear ) & 0x03 ) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "rayhit->ray.dir_x not aligned to 4 bytes");
- if (((size_t)rayhit->ray.tfar ) & 0x03 ) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "rayhit->ray.tnear not aligned to 4 bytes");
- if (((size_t)rayhit->ray.time ) & 0x03 ) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "rayhit->ray.time not aligned to 4 bytes");
- if (((size_t)rayhit->ray.mask ) & 0x03 ) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "rayhit->ray.mask not aligned to 4 bytes");
- if (((size_t)rayhit->hit.Ng_x ) & 0x03 ) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "rayhit->hit.Ng_x not aligned to 4 bytes");
- if (((size_t)rayhit->hit.Ng_y ) & 0x03 ) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "rayhit->hit.Ng_y not aligned to 4 bytes");
- if (((size_t)rayhit->hit.Ng_z ) & 0x03 ) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "rayhit->hit.Ng_z not aligned to 4 bytes");
- if (((size_t)rayhit->hit.u ) & 0x03 ) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "rayhit->hit.u not aligned to 4 bytes");
- if (((size_t)rayhit->hit.v ) & 0x03 ) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "rayhit->hit.v not aligned to 4 bytes");
- if (((size_t)rayhit->hit.geomID) & 0x03 ) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "rayhit->hit.geomID not aligned to 4 bytes");
- if (((size_t)rayhit->hit.primID) & 0x03 ) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "rayhit->hit.primID not aligned to 4 bytes");
- if (((size_t)rayhit->hit.instID) & 0x03 ) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "rayhit->hit.instID not aligned to 4 bytes");
-#endif
- STAT3(normal.travs,N,N,N);
- IntersectContext context(scene,user_context);
- scene->device->rayStreamFilters.intersectSOP(scene,rayhit,N,&context);
-#else
- throw_RTCError(RTC_ERROR_INVALID_OPERATION,"rtcIntersectNp not supported");
-#endif
- RTC_CATCH_END2(scene);
+ RTC_TRACE(rtcForwardOccluded1);
+ return rtcForwardOccluded1Ex(args, hscene, iray_, instID, 0);
}
-
- RTC_API void rtcOccluded1 (RTCScene hscene, RTCIntersectContext* user_context, RTCRay* ray)
+
+ RTC_API void rtcForwardOccluded1Ex(const RTCOccludedFunctionNArguments* args, RTCScene hscene, RTCRay* iray_, unsigned int instID, unsigned int instPrimID)
{
Scene* scene = (Scene*) hscene;
RTC_CATCH_BEGIN;
- RTC_TRACE(rtcOccluded1);
+ RTC_TRACE(rtcForwardOccluded1Ex);
STAT3(shadow.travs,1,1,1);
#if defined(DEBUG)
RTC_VERIFY_HANDLE(hscene);
if (scene->isModified()) throw_RTCError(RTC_ERROR_INVALID_OPERATION,"scene not committed");
- if (((size_t)ray) & 0x0F) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "ray not aligned to 16 bytes");
+ if (((size_t)iray_) & 0x0F) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "ray not aligned to 16 bytes");
#endif
- IntersectContext context(scene,user_context);
- scene->intersectors.occluded(*ray,&context);
+
+ Ray* iray = (Ray*)iray_;
+ Ray* oray = (Ray*)args->ray;
+ RTCRayQueryContext* user_context = args->context;
+ const Vec3ff ray_org_tnear = oray->org;
+ const Vec3ff ray_dir_time = oray->dir;
+ oray->org = iray->org;
+ oray->dir = iray->dir;
+
+ RTCIntersectArguments* iargs = ((OccludedFunctionNArguments*) args)->args;
+ RayQueryContext context(scene,user_context,iargs);
+
+ instance_id_stack::push(user_context, instID, instPrimID);
+ scene->intersectors.occluded(*(RTCRay*)oray,&context);
+ instance_id_stack::pop(user_context);
+
+ oray->org = ray_org_tnear;
+ oray->dir = ray_dir_time;
+
RTC_CATCH_END2(scene);
}
-
- RTC_API void rtcOccluded4 (const int* valid, RTCScene hscene, RTCIntersectContext* user_context, RTCRay4* ray)
+
+ RTC_API void rtcOccluded4 (const int* valid, RTCScene hscene, RTCRay4* ray, RTCOccludedArguments* args)
{
Scene* scene = (Scene*) hscene;
RTC_CATCH_BEGIN;
@@ -732,23 +922,98 @@ RTC_NAMESPACE_BEGIN;
STAT(size_t cnt=0; for (size_t i=0; i<4; i++) cnt += ((int*)valid)[i] == -1;);
STAT3(shadow.travs,cnt,cnt,cnt);
- IntersectContext context(scene,user_context);
-#if !defined(EMBREE_RAY_PACKETS)
- RayHit4* ray4 = (RayHit4*) ray;
- for (size_t i=0; i<4; i++) {
- if (!valid[i]) continue;
- RayHit ray1; ray4->get(i,ray1);
- scene->intersectors.occluded((RTCRay&)ray1,&context);
- ray4->geomID[i] = ray1.geomID;
+ RTCOccludedArguments defaultArgs;
+ if (unlikely(args == nullptr)) {
+ rtcInitOccludedArguments(&defaultArgs);
+ args = &defaultArgs;
+ }
+ RTCRayQueryContext* user_context = args->context;
+
+ RTCRayQueryContext defaultContext;
+ if (unlikely(user_context == nullptr)) {
+ rtcInitRayQueryContext(&defaultContext);
+ user_context = &defaultContext;
+ }
+ RayQueryContext context(scene,user_context,args);
+
+ if (likely(scene->intersectors.intersector4))
+ scene->intersectors.occluded4(valid,*ray,&context);
+
+ else {
+ RayHit4* ray4 = (RayHit4*) ray;
+ for (size_t i=0; i<4; i++) {
+ if (!valid[i]) continue;
+ RayHit ray1; ray4->get(i,ray1);
+ scene->intersectors.occluded((RTCRay&)ray1,&context);
+ ray4->geomID[i] = ray1.geomID;
+ }
}
-#else
- scene->intersectors.occluded4(valid,*ray,&context);
-#endif
RTC_CATCH_END2(scene);
}
+
+ template<typename RTCRay, int N>
+ __forceinline void rtcForwardOccludedN (const int* valid, const RTCOccludedFunctionNArguments* args, RTCScene hscene, RTCRay* iray, unsigned int instID, unsigned int instPrimID)
+ {
+ Scene* scene = (Scene*) hscene;
+ RTCRay* oray = (RTCRay*)args->ray;
+ RTCRayQueryContext* user_context = args->context;
+
+ __aligned(16) float ray_org_x[N];
+ __aligned(16) float ray_org_y[N];
+ __aligned(16) float ray_org_z[N];
+ __aligned(16) float ray_dir_x[N];
+ __aligned(16) float ray_dir_y[N];
+ __aligned(16) float ray_dir_z[N];
+
+ copy<N>(ray_org_x,oray->org_x);
+ copy<N>(ray_org_y,oray->org_y);
+ copy<N>(ray_org_z,oray->org_z);
+ copy<N>(ray_dir_x,oray->dir_x);
+ copy<N>(ray_dir_y,oray->dir_y);
+ copy<N>(ray_dir_z,oray->dir_z);
+
+ copy<N>(oray->org_x,iray->org_x);
+ copy<N>(oray->org_y,iray->org_y);
+ copy<N>(oray->org_z,iray->org_z);
+ copy<N>(oray->dir_x,iray->dir_x);
+ copy<N>(oray->dir_y,iray->dir_y);
+ copy<N>(oray->dir_z,iray->dir_z);
+
+ STAT(size_t cnt=0; for (size_t i=0; i<N; i++) cnt += ((int*)valid)[i] == -1;);
+ STAT3(normal.travs,cnt,cnt,cnt);
+
+ RTCIntersectArguments* iargs = ((IntersectFunctionNArguments*) args)->args;
+ RayQueryContext context(scene,user_context,iargs);
+
+ instance_id_stack::push(user_context, instID, instPrimID);
+ scene->intersectors.occluded(valid,*oray,&context);
+ instance_id_stack::pop(user_context);
+
+ copy<N>(oray->org_x,ray_org_x);
+ copy<N>(oray->org_y,ray_org_y);
+ copy<N>(oray->org_z,ray_org_z);
+ copy<N>(oray->dir_x,ray_dir_x);
+ copy<N>(oray->dir_y,ray_dir_y);
+ copy<N>(oray->dir_z,ray_dir_z);
+ }
+
+ RTC_API void rtcForwardOccluded4(const int* valid, const RTCOccludedFunctionNArguments* args, RTCScene hscene, RTCRay4* iray, unsigned int instID)
+ {
+ RTC_TRACE(rtcForwardOccluded4);
+ return rtcForwardOccluded4Ex(valid, args, hscene, iray, instID, 0);
+ }
+
+ RTC_API void rtcForwardOccluded4Ex(const int* valid, const RTCOccludedFunctionNArguments* args, RTCScene hscene, RTCRay4* iray, unsigned int instID, unsigned int instPrimID)
+ {
+ Scene* scene = (Scene*) hscene;
+ RTC_CATCH_BEGIN;
+ RTC_TRACE(rtcForwardOccluded4);
+ rtcForwardOccludedN<RTCRay4,4>(valid,args,hscene,iray,instID,instPrimID);
+ RTC_CATCH_END2(scene);
+ }
- RTC_API void rtcOccluded8 (const int* valid, RTCScene hscene, RTCIntersectContext* user_context, RTCRay8* ray)
+ RTC_API void rtcOccluded8 (const int* valid, RTCScene hscene, RTCRay8* ray, RTCOccludedArguments* args)
{
Scene* scene = (Scene*) hscene;
RTC_CATCH_BEGIN;
@@ -763,26 +1028,52 @@ RTC_NAMESPACE_BEGIN;
STAT(size_t cnt=0; for (size_t i=0; i<8; i++) cnt += ((int*)valid)[i] == -1;);
STAT3(shadow.travs,cnt,cnt,cnt);
- IntersectContext context(scene,user_context);
-#if !defined(EMBREE_RAY_PACKETS)
- RayHit8* ray8 = (RayHit8*) ray;
- for (size_t i=0; i<8; i++) {
- if (!valid[i]) continue;
- RayHit ray1; ray8->get(i,ray1);
- scene->intersectors.occluded((RTCRay&)ray1,&context);
- ray8->set(i,ray1);
+ RTCOccludedArguments defaultArgs;
+ if (unlikely(args == nullptr)) {
+ rtcInitOccludedArguments(&defaultArgs);
+ args = &defaultArgs;
}
-#else
+ RTCRayQueryContext* user_context = args->context;
+
+ RTCRayQueryContext defaultContext;
+ if (unlikely(user_context == nullptr)) {
+ rtcInitRayQueryContext(&defaultContext);
+ user_context = &defaultContext;
+ }
+ RayQueryContext context(scene,user_context,args);
+
if (likely(scene->intersectors.intersector8))
scene->intersectors.occluded8(valid,*ray,&context);
- else
- scene->device->rayStreamFilters.occludedSOA(scene,(char*)ray,8,1,sizeof(RTCRay8),&context);
-#endif
+
+ else {
+ RayHit8* ray8 = (RayHit8*) ray;
+ for (size_t i=0; i<8; i++) {
+ if (!valid[i]) continue;
+ RayHit ray1; ray8->get(i,ray1);
+ scene->intersectors.occluded((RTCRay&)ray1,&context);
+ ray8->set(i,ray1);
+ }
+ }
RTC_CATCH_END2(scene);
}
-
- RTC_API void rtcOccluded16 (const int* valid, RTCScene hscene, RTCIntersectContext* user_context, RTCRay16* ray)
+
+ RTC_API void rtcForwardOccluded8(const int* valid, const RTCOccludedFunctionNArguments* args, RTCScene hscene, RTCRay8* iray, unsigned int instID)
+ {
+ RTC_TRACE(rtcForwardOccluded8);
+ return rtcForwardOccluded8Ex(valid, args, hscene, iray, instID, 0);
+ }
+
+ RTC_API void rtcForwardOccluded8Ex(const int* valid, const RTCOccludedFunctionNArguments* args, RTCScene hscene, RTCRay8* iray, unsigned int instID, unsigned int instPrimID)
+ {
+ Scene* scene = (Scene*) hscene;
+ RTC_CATCH_BEGIN;
+ RTC_TRACE(rtcForwardOccluded8Ex);
+ rtcForwardOccludedN<RTCRay8,8>(valid, args, hscene, iray, instID, instPrimID);
+ RTC_CATCH_END2(scene);
+ }
+
+ RTC_API void rtcOccluded16 (const int* valid, RTCScene hscene, RTCRay16* ray, RTCOccludedArguments* args)
{
Scene* scene = (Scene*) hscene;
RTC_CATCH_BEGIN;
@@ -797,159 +1088,58 @@ RTC_NAMESPACE_BEGIN;
STAT(size_t cnt=0; for (size_t i=0; i<16; i++) cnt += ((int*)valid)[i] == -1;);
STAT3(shadow.travs,cnt,cnt,cnt);
- IntersectContext context(scene,user_context);
-#if !defined(EMBREE_RAY_PACKETS)
- RayHit16* ray16 = (RayHit16*) ray;
- for (size_t i=0; i<16; i++) {
- if (!valid[i]) continue;
- RayHit ray1; ray16->get(i,ray1);
- scene->intersectors.occluded((RTCRay&)ray1,&context);
- ray16->set(i,ray1);
+ RTCOccludedArguments defaultArgs;
+ if (unlikely(args == nullptr)) {
+ rtcInitOccludedArguments(&defaultArgs);
+ args = &defaultArgs;
}
-#else
+ RTCRayQueryContext* user_context = args->context;
+
+ RTCRayQueryContext defaultContext;
+ if (unlikely(user_context == nullptr)) {
+ rtcInitRayQueryContext(&defaultContext);
+ user_context = &defaultContext;
+ }
+ RayQueryContext context(scene,user_context,args);
+
if (likely(scene->intersectors.intersector16))
scene->intersectors.occluded16(valid,*ray,&context);
- else
- scene->device->rayStreamFilters.occludedSOA(scene,(char*)ray,16,1,sizeof(RTCRay16),&context);
-#endif
-
- RTC_CATCH_END2(scene);
- }
-
- RTC_API void rtcOccluded1M(RTCScene hscene, RTCIntersectContext* user_context, RTCRay* ray, unsigned int M, size_t byteStride)
- {
- Scene* scene = (Scene*) hscene;
- RTC_CATCH_BEGIN;
- RTC_TRACE(rtcOccluded1M);
-#if defined (EMBREE_RAY_PACKETS)
-#if defined(DEBUG)
- RTC_VERIFY_HANDLE(hscene);
- if (scene->isModified()) throw_RTCError(RTC_ERROR_INVALID_OPERATION,"scene not committed");
- if (((size_t)ray) & 0x03) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "ray not aligned to 4 bytes");
-#endif
- STAT3(shadow.travs,M,M,M);
- IntersectContext context(scene,user_context);
- /* fast codepath for streams of size 1 */
- if (likely(M == 1)) {
- if (likely(ray->tnear <= ray->tfar))
- scene->intersectors.occluded (*ray,&context);
- }
- /* codepath for normal streams */
else {
- scene->device->rayStreamFilters.occludedAOS(scene,ray,M,byteStride,&context);
+ RayHit16* ray16 = (RayHit16*) ray;
+ for (size_t i=0; i<16; i++) {
+ if (!valid[i]) continue;
+ RayHit ray1; ray16->get(i,ray1);
+ scene->intersectors.occluded((RTCRay&)ray1,&context);
+ ray16->set(i,ray1);
+ }
}
-#else
- throw_RTCError(RTC_ERROR_INVALID_OPERATION,"rtcOccluded1M not supported");
-#endif
- RTC_CATCH_END2(scene);
- }
- RTC_API void rtcOccluded1Mp(RTCScene hscene, RTCIntersectContext* user_context, RTCRay** ray, unsigned int M)
- {
- Scene* scene = (Scene*) hscene;
- RTC_CATCH_BEGIN;
- RTC_TRACE(rtcOccluded1Mp);
-
-#if defined (EMBREE_RAY_PACKETS)
-#if defined(DEBUG)
- RTC_VERIFY_HANDLE(hscene);
- if (scene->isModified()) throw_RTCError(RTC_ERROR_INVALID_OPERATION,"scene not committed");
- if (((size_t)ray) & 0x03) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "ray not aligned to 4 bytes");
-#endif
- STAT3(shadow.travs,M,M,M);
- IntersectContext context(scene,user_context);
-
- /* fast codepath for streams of size 1 */
- if (likely(M == 1)) {
- if (likely(ray[0]->tnear <= ray[0]->tfar))
- scene->intersectors.occluded (*ray[0],&context);
- }
- /* codepath for normal streams */
- else {
- scene->device->rayStreamFilters.occludedAOP(scene,ray,M,&context);
- }
-#else
- throw_RTCError(RTC_ERROR_INVALID_OPERATION,"rtcOccluded1Mp not supported");
-#endif
RTC_CATCH_END2(scene);
}
- RTC_API void rtcOccludedNM(RTCScene hscene, RTCIntersectContext* user_context, RTCRayN* ray, unsigned int N, unsigned int M, size_t byteStride)
+ RTC_API void rtcForwardOccluded16(const int* valid, const RTCOccludedFunctionNArguments* args, RTCScene hscene, RTCRay16* iray, unsigned int instID)
{
- Scene* scene = (Scene*) hscene;
- RTC_CATCH_BEGIN;
- RTC_TRACE(rtcOccludedNM);
-
-#if defined (EMBREE_RAY_PACKETS)
-#if defined(DEBUG)
- RTC_VERIFY_HANDLE(hscene);
- if (byteStride < sizeof(RTCRayHit)) throw_RTCError(RTC_ERROR_INVALID_OPERATION,"byteStride too small");
- if (scene->isModified()) throw_RTCError(RTC_ERROR_INVALID_OPERATION,"scene not committed");
- if (((size_t)ray) & 0x03) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "ray not aligned to 4 bytes");
-#endif
- STAT3(shadow.travs,N*M,N*N,N*N);
- IntersectContext context(scene,user_context);
-
- /* codepath for single rays */
- if (likely(N == 1))
- {
- /* fast path for streams of size 1 */
- if (likely(M == 1)) {
- if (likely(((RTCRay*)ray)->tnear <= ((RTCRay*)ray)->tfar))
- scene->intersectors.occluded (*(RTCRay*)ray,&context);
- }
- /* codepath for normal ray streams */
- else {
- scene->device->rayStreamFilters.occludedAOS(scene,(RTCRay*)ray,M,byteStride,&context);
- }
- }
- /* code path for ray packet streams */
- else {
- scene->device->rayStreamFilters.occludedSOA(scene,(char*)ray,N,M,byteStride,&context);
- }
-#else
- throw_RTCError(RTC_ERROR_INVALID_OPERATION,"rtcOccludedNM not supported");
-#endif
- RTC_CATCH_END2(scene);
+ RTC_TRACE(rtcForwardOccluded16);
+ return rtcForwardOccluded16Ex(valid, args, hscene, iray, instID, 0);
}
- RTC_API void rtcOccludedNp(RTCScene hscene, RTCIntersectContext* user_context, const RTCRayNp* ray, unsigned int N)
+ RTC_API void rtcForwardOccluded16Ex(const int* valid, const RTCOccludedFunctionNArguments* args, RTCScene hscene, RTCRay16* iray, unsigned int instID, unsigned int instPrimID)
{
Scene* scene = (Scene*) hscene;
RTC_CATCH_BEGIN;
- RTC_TRACE(rtcOccludedNp);
-
-#if defined (EMBREE_RAY_PACKETS)
-#if defined(DEBUG)
- RTC_VERIFY_HANDLE(hscene);
- if (scene->isModified()) throw_RTCError(RTC_ERROR_INVALID_OPERATION,"scene not committed");
- if (((size_t)ray->org_x ) & 0x03 ) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "org_x not aligned to 4 bytes");
- if (((size_t)ray->org_y ) & 0x03 ) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "org_y not aligned to 4 bytes");
- if (((size_t)ray->org_z ) & 0x03 ) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "org_z not aligned to 4 bytes");
- if (((size_t)ray->dir_x ) & 0x03 ) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "dir_x not aligned to 4 bytes");
- if (((size_t)ray->dir_y ) & 0x03 ) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "dir_y not aligned to 4 bytes");
- if (((size_t)ray->dir_z ) & 0x03 ) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "dir_z not aligned to 4 bytes");
- if (((size_t)ray->tnear ) & 0x03 ) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "dir_x not aligned to 4 bytes");
- if (((size_t)ray->tfar ) & 0x03 ) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "tnear not aligned to 4 bytes");
- if (((size_t)ray->time ) & 0x03 ) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "time not aligned to 4 bytes");
- if (((size_t)ray->mask ) & 0x03 ) throw_RTCError(RTC_ERROR_INVALID_ARGUMENT, "mask not aligned to 4 bytes");
-#endif
- STAT3(shadow.travs,N,N,N);
- IntersectContext context(scene,user_context);
- scene->device->rayStreamFilters.occludedSOP(scene,ray,N,&context);
-#else
- throw_RTCError(RTC_ERROR_INVALID_OPERATION,"rtcOccludedNp not supported");
-#endif
+ RTC_TRACE(rtcForwardOccluded16Ex);
+ rtcForwardOccludedN<RTCRay16,16>(valid, args, hscene, iray, instID, instPrimID);
RTC_CATCH_END2(scene);
}
-
+
RTC_API void rtcRetainScene (RTCScene hscene)
{
Scene* scene = (Scene*) hscene;
RTC_CATCH_BEGIN;
RTC_TRACE(rtcRetainScene);
RTC_VERIFY_HANDLE(hscene);
+ RTC_ENTER_DEVICE(hscene);
scene->refInc();
RTC_CATCH_END2(scene);
}
@@ -960,6 +1150,7 @@ RTC_NAMESPACE_BEGIN;
RTC_CATCH_BEGIN;
RTC_TRACE(rtcReleaseScene);
RTC_VERIFY_HANDLE(hscene);
+ RTC_ENTER_DEVICE(hscene);
scene->refDec();
RTC_CATCH_END2(scene);
}
@@ -972,10 +1163,23 @@ RTC_NAMESPACE_BEGIN;
RTC_TRACE(rtcSetGeometryInstancedScene);
RTC_VERIFY_HANDLE(hgeometry);
RTC_VERIFY_HANDLE(hscene);
+ RTC_ENTER_DEVICE(hgeometry);
geometry->setInstancedScene(scene);
RTC_CATCH_END2(geometry);
}
+ RTC_API void rtcSetGeometryInstancedScenes(RTCGeometry hgeometry, RTCScene* scenes, size_t numScenes)
+ {
+ Geometry* geometry = (Geometry*) hgeometry;
+ RTC_CATCH_BEGIN;
+ RTC_TRACE(rtcSetGeometryInstancedScene);
+ RTC_VERIFY_HANDLE(hgeometry);
+ RTC_VERIFY_HANDLE(scenes);
+ RTC_ENTER_DEVICE(hgeometry);
+ geometry->setInstancedScenes(scenes, numScenes);
+ RTC_CATCH_END2(geometry);
+ }
+
AffineSpace3fa loadTransform(RTCFormat format, const float* xfm)
{
AffineSpace3fa space = one;
@@ -1009,43 +1213,14 @@ RTC_NAMESPACE_BEGIN;
return space;
}
- void storeTransform(const AffineSpace3fa& space, RTCFormat format, float* xfm)
- {
- switch (format)
- {
- case RTC_FORMAT_FLOAT3X4_ROW_MAJOR:
- xfm[ 0] = space.l.vx.x; xfm[ 1] = space.l.vy.x; xfm[ 2] = space.l.vz.x; xfm[ 3] = space.p.x;
- xfm[ 4] = space.l.vx.y; xfm[ 5] = space.l.vy.y; xfm[ 6] = space.l.vz.y; xfm[ 7] = space.p.y;
- xfm[ 8] = space.l.vx.z; xfm[ 9] = space.l.vy.z; xfm[10] = space.l.vz.z; xfm[11] = space.p.z;
- break;
-
- case RTC_FORMAT_FLOAT3X4_COLUMN_MAJOR:
- xfm[ 0] = space.l.vx.x; xfm[ 1] = space.l.vx.y; xfm[ 2] = space.l.vx.z;
- xfm[ 3] = space.l.vy.x; xfm[ 4] = space.l.vy.y; xfm[ 5] = space.l.vy.z;
- xfm[ 6] = space.l.vz.x; xfm[ 7] = space.l.vz.y; xfm[ 8] = space.l.vz.z;
- xfm[ 9] = space.p.x; xfm[10] = space.p.y; xfm[11] = space.p.z;
- break;
-
- case RTC_FORMAT_FLOAT4X4_COLUMN_MAJOR:
- xfm[ 0] = space.l.vx.x; xfm[ 1] = space.l.vx.y; xfm[ 2] = space.l.vx.z; xfm[ 3] = 0.f;
- xfm[ 4] = space.l.vy.x; xfm[ 5] = space.l.vy.y; xfm[ 6] = space.l.vy.z; xfm[ 7] = 0.f;
- xfm[ 8] = space.l.vz.x; xfm[ 9] = space.l.vz.y; xfm[10] = space.l.vz.z; xfm[11] = 0.f;
- xfm[12] = space.p.x; xfm[13] = space.p.y; xfm[14] = space.p.z; xfm[15] = 1.f;
- break;
-
- default:
- throw_RTCError(RTC_ERROR_INVALID_OPERATION, "invalid matrix format");
- break;
- }
- }
-
- RTC_API void rtcSetGeometryTransform(RTCGeometry hgeometry, unsigned int timeStep, RTCFormat format, const void* xfm)
+RTC_API void rtcSetGeometryTransform(RTCGeometry hgeometry, unsigned int timeStep, RTCFormat format, const void* xfm)
{
Geometry* geometry = (Geometry*) hgeometry;
RTC_CATCH_BEGIN;
RTC_TRACE(rtcSetGeometryTransform);
RTC_VERIFY_HANDLE(hgeometry);
RTC_VERIFY_HANDLE(xfm);
+ RTC_ENTER_DEVICE(hgeometry);
const AffineSpace3fa transform = loadTransform(format, (const float*)xfm);
geometry->setTransform(transform, timeStep);
RTC_CATCH_END2(geometry);
@@ -1058,6 +1233,7 @@ RTC_NAMESPACE_BEGIN;
RTC_TRACE(rtcSetGeometryTransformQuaternion);
RTC_VERIFY_HANDLE(hgeometry);
RTC_VERIFY_HANDLE(qd);
+ RTC_ENTER_DEVICE(hgeometry);
AffineSpace3fx transform;
transform.l.vx.x = qd->scale_x;
@@ -1090,21 +1266,46 @@ RTC_NAMESPACE_BEGIN;
Geometry* geometry = (Geometry*) hgeometry;
RTC_CATCH_BEGIN;
RTC_TRACE(rtcGetGeometryTransform);
+ //RTC_ENTER_DEVICE(hgeometry); // no allocation required
const AffineSpace3fa transform = geometry->getTransform(time);
storeTransform(transform, format, (float*)xfm);
RTC_CATCH_END2(geometry);
}
- RTC_API void rtcFilterIntersection(const struct RTCIntersectFunctionNArguments* const args_i, const struct RTCFilterFunctionNArguments* filter_args)
+ RTC_API void rtcGetGeometryTransformEx(RTCGeometry hgeometry, unsigned int instPrimID, float time, RTCFormat format, void* xfm)
+ {
+ Geometry* geometry = (Geometry*) hgeometry;
+ RTC_CATCH_BEGIN;
+ RTC_TRACE(rtcGetGeometryTransformEx);
+ //RTC_ENTER_DEVICE(hgeometry); // no allocation required
+ const AffineSpace3fa transform = geometry->getTransform(instPrimID, time);
+ storeTransform(transform, format, (float*)xfm);
+ RTC_CATCH_END2(geometry);
+ }
+
+ RTC_API void rtcGetGeometryTransformFromScene(RTCScene hscene, unsigned int geomID, float time, RTCFormat format, void* xfm)
+ {
+ Scene* scene = (Scene*) hscene;
+ RTC_CATCH_BEGIN;
+ RTC_TRACE(rtcGetGeometryTransformFromScene);
+ //RTC_ENTER_DEVICE(hscene); // no allocation required
+ const AffineSpace3fa transform = scene->get(geomID)->getTransform(time);
+ storeTransform(transform, format, (float*)xfm);
+ RTC_CATCH_END2(scene);
+ }
+
+ RTC_API void rtcInvokeIntersectFilterFromGeometry(const struct RTCIntersectFunctionNArguments* const args_i, const struct RTCFilterFunctionNArguments* filter_args)
{
IntersectFunctionNArguments* args = (IntersectFunctionNArguments*) args_i;
- isa::reportIntersection1(args, filter_args);
+ if (args->geometry->intersectionFilterN)
+ args->geometry->intersectionFilterN(filter_args);
}
- RTC_API void rtcFilterOcclusion(const struct RTCOccludedFunctionNArguments* const args_i, const struct RTCFilterFunctionNArguments* filter_args)
+ RTC_API void rtcInvokeOccludedFilterFromGeometry(const struct RTCOccludedFunctionNArguments* const args_i, const struct RTCFilterFunctionNArguments* filter_args)
{
OccludedFunctionNArguments* args = (OccludedFunctionNArguments*) args_i;
- isa::reportOcclusion1(args,filter_args);
+ if (args->geometry->occlusionFilterN)
+ args->geometry->occlusionFilterN(filter_args);
}
RTC_API RTCGeometry rtcNewGeometry (RTCDevice hdevice, RTCGeometryType type)
@@ -1112,6 +1313,7 @@ RTC_NAMESPACE_BEGIN;
Device* device = (Device*) hdevice;
RTC_CATCH_BEGIN;
RTC_TRACE(rtcNewGeometry);
+ RTC_ENTER_DEVICE(hdevice);
RTC_VERIFY_HANDLE(hdevice);
switch (type)
@@ -1262,6 +1464,18 @@ RTC_NAMESPACE_BEGIN;
#endif
}
+ case RTC_GEOMETRY_TYPE_INSTANCE_ARRAY:
+ {
+#if defined(EMBREE_GEOMETRY_INSTANCE_ARRAY)
+ createInstanceArrayTy createInstanceArray = nullptr;
+ SELECT_SYMBOL_DEFAULT_AVX_AVX2_AVX512(device->enabled_cpu_features,createInstanceArray);
+ Geometry* geom = createInstanceArray(device);
+ return (RTCGeometry) geom->refInc();
+#else
+ throw_RTCError(RTC_ERROR_UNKNOWN,"RTC_GEOMETRY_TYPE_INSTANCE_ARRAY is not supported");
+#endif
+ }
+
case RTC_GEOMETRY_TYPE_GRID:
{
#if defined(EMBREE_GEOMETRY_GRID)
@@ -1288,6 +1502,7 @@ RTC_NAMESPACE_BEGIN;
RTC_CATCH_BEGIN;
RTC_TRACE(rtcSetGeometryUserPrimitiveCount);
RTC_VERIFY_HANDLE(hgeometry);
+ RTC_ENTER_DEVICE(hgeometry);
if (unlikely(geometry->getType() != Geometry::GTY_USER_GEOMETRY))
throw_RTCError(RTC_ERROR_INVALID_OPERATION,"operation only allowed for user geometries");
@@ -1302,6 +1517,7 @@ RTC_NAMESPACE_BEGIN;
RTC_CATCH_BEGIN;
RTC_TRACE(rtcSetGeometryTimeStepCount);
RTC_VERIFY_HANDLE(hgeometry);
+ RTC_ENTER_DEVICE(hgeometry);
if (timeStepCount > RTC_MAX_TIME_STEP_COUNT)
throw_RTCError(RTC_ERROR_INVALID_ARGUMENT,"number of time steps is out of range");
@@ -1316,6 +1532,7 @@ RTC_NAMESPACE_BEGIN;
RTC_CATCH_BEGIN;
RTC_TRACE(rtcSetGeometryTimeRange);
RTC_VERIFY_HANDLE(hgeometry);
+ RTC_ENTER_DEVICE(hgeometry);
if (startTime > endTime)
throw_RTCError(RTC_ERROR_INVALID_ARGUMENT,"startTime has to be smaller or equal to the endTime");
@@ -1330,6 +1547,7 @@ RTC_NAMESPACE_BEGIN;
RTC_CATCH_BEGIN;
RTC_TRACE(rtcSetGeometryVertexAttributeCount);
RTC_VERIFY_HANDLE(hgeometry);
+ RTC_ENTER_DEVICE(hgeometry);
geometry->setVertexAttributeCount(N);
RTC_CATCH_END2(geometry);
}
@@ -1340,6 +1558,7 @@ RTC_NAMESPACE_BEGIN;
RTC_CATCH_BEGIN;
RTC_TRACE(rtcSetGeometryTopologyCount);
RTC_VERIFY_HANDLE(hgeometry);
+ RTC_ENTER_DEVICE(hgeometry);
geometry->setTopologyCount(N);
RTC_CATCH_END2(geometry);
}
@@ -1350,14 +1569,20 @@ RTC_NAMESPACE_BEGIN;
RTC_CATCH_BEGIN;
RTC_TRACE(rtcSetGeometryBuildQuality);
RTC_VERIFY_HANDLE(hgeometry);
+ RTC_ENTER_DEVICE(hgeometry);
+ // -- GODOT start --
+ // if (quality != RTC_BUILD_QUALITY_LOW &&
+ // quality != RTC_BUILD_QUALITY_MEDIUM &&
+ // quality != RTC_BUILD_QUALITY_HIGH &&
+ // quality != RTC_BUILD_QUALITY_REFIT)
+ // throw std::runtime_error("invalid build quality");
if (quality != RTC_BUILD_QUALITY_LOW &&
quality != RTC_BUILD_QUALITY_MEDIUM &&
quality != RTC_BUILD_QUALITY_HIGH &&
- quality != RTC_BUILD_QUALITY_REFIT)
- // -- GODOT start --
- // throw std::runtime_error("invalid build quality");
+ quality != RTC_BUILD_QUALITY_REFIT) {
abort();
- // -- GODOT end --
+ }
+ // -- GODOT end --
geometry->setBuildQuality(quality);
RTC_CATCH_END2(geometry);
}
@@ -1383,6 +1608,7 @@ RTC_NAMESPACE_BEGIN;
RTC_CATCH_BEGIN;
RTC_TRACE(rtcSetGeometryMask);
RTC_VERIFY_HANDLE(hgeometry);
+ RTC_ENTER_DEVICE(hgeometry);
geometry->setMask(mask);
RTC_CATCH_END2(geometry);
}
@@ -1393,6 +1619,7 @@ RTC_NAMESPACE_BEGIN;
RTC_CATCH_BEGIN;
RTC_TRACE(rtcSetGeometrySubdivisionMode);
RTC_VERIFY_HANDLE(hgeometry);
+ RTC_ENTER_DEVICE(hgeometry);
geometry->setSubdivisionMode(topologyID,mode);
RTC_CATCH_END2(geometry);
}
@@ -1403,6 +1630,7 @@ RTC_NAMESPACE_BEGIN;
RTC_CATCH_BEGIN;
RTC_TRACE(rtcSetGeometryVertexAttributeTopology);
RTC_VERIFY_HANDLE(hgeometry);
+ RTC_ENTER_DEVICE(hgeometry);
geometry->setVertexAttributeTopology(vertexAttributeID, topologyID);
RTC_CATCH_END2(geometry);
}
@@ -1415,6 +1643,7 @@ RTC_NAMESPACE_BEGIN;
RTC_TRACE(rtcSetGeometryBuffer);
RTC_VERIFY_HANDLE(hgeometry);
RTC_VERIFY_HANDLE(hbuffer);
+ RTC_ENTER_DEVICE(hgeometry);
if (geometry->device != buffer->device)
throw_RTCError(RTC_ERROR_INVALID_ARGUMENT,"inputs are from different devices");
@@ -1432,10 +1661,11 @@ RTC_NAMESPACE_BEGIN;
RTC_CATCH_BEGIN;
RTC_TRACE(rtcSetSharedGeometryBuffer);
RTC_VERIFY_HANDLE(hgeometry);
+ RTC_ENTER_DEVICE(hgeometry);
if (itemCount > 0xFFFFFFFFu)
throw_RTCError(RTC_ERROR_INVALID_ARGUMENT,"buffer too large");
-
+
Ref<Buffer> buffer = new Buffer(geometry->device, itemCount*byteStride, (char*)ptr + byteOffset);
geometry->setBuffer(type, slot, format, buffer, 0, byteStride, (unsigned int)itemCount);
RTC_CATCH_END2(geometry);
@@ -1447,6 +1677,7 @@ RTC_NAMESPACE_BEGIN;
RTC_CATCH_BEGIN;
RTC_TRACE(rtcSetNewGeometryBuffer);
RTC_VERIFY_HANDLE(hgeometry);
+ RTC_ENTER_DEVICE(hgeometry);
if (itemCount > 0xFFFFFFFFu)
throw_RTCError(RTC_ERROR_INVALID_ARGUMENT,"buffer too large");
@@ -1469,6 +1700,7 @@ RTC_NAMESPACE_BEGIN;
RTC_CATCH_BEGIN;
RTC_TRACE(rtcGetGeometryBufferData);
RTC_VERIFY_HANDLE(hgeometry);
+ RTC_ENTER_DEVICE(hgeometry);
return geometry->getBuffer(type, slot);
RTC_CATCH_END2(geometry);
return nullptr;
@@ -1480,6 +1712,7 @@ RTC_NAMESPACE_BEGIN;
RTC_CATCH_BEGIN;
RTC_TRACE(rtcEnableGeometry);
RTC_VERIFY_HANDLE(hgeometry);
+ RTC_ENTER_DEVICE(hgeometry);
geometry->enable();
RTC_CATCH_END2(geometry);
}
@@ -1490,6 +1723,7 @@ RTC_NAMESPACE_BEGIN;
RTC_CATCH_BEGIN;
RTC_TRACE(rtcUpdateGeometryBuffer);
RTC_VERIFY_HANDLE(hgeometry);
+ RTC_ENTER_DEVICE(hgeometry);
geometry->updateBuffer(type, slot);
RTC_CATCH_END2(geometry);
}
@@ -1500,6 +1734,7 @@ RTC_NAMESPACE_BEGIN;
RTC_CATCH_BEGIN;
RTC_TRACE(rtcDisableGeometry);
RTC_VERIFY_HANDLE(hgeometry);
+ RTC_ENTER_DEVICE(hgeometry);
geometry->disable();
RTC_CATCH_END2(geometry);
}
@@ -1510,6 +1745,7 @@ RTC_NAMESPACE_BEGIN;
RTC_CATCH_BEGIN;
RTC_TRACE(rtcSetGeometryTessellationRate);
RTC_VERIFY_HANDLE(hgeometry);
+ RTC_ENTER_DEVICE(hgeometry);
geometry->setTessellationRate(tessellationRate);
RTC_CATCH_END2(geometry);
}
@@ -1520,6 +1756,7 @@ RTC_NAMESPACE_BEGIN;
RTC_CATCH_BEGIN;
RTC_TRACE(rtcSetGeometryUserData);
RTC_VERIFY_HANDLE(hgeometry);
+ RTC_ENTER_DEVICE(hgeometry);
geometry->setUserData(ptr);
RTC_CATCH_END2(geometry);
}
@@ -1530,17 +1767,34 @@ RTC_NAMESPACE_BEGIN;
RTC_CATCH_BEGIN;
RTC_TRACE(rtcGetGeometryUserData);
RTC_VERIFY_HANDLE(hgeometry);
+ //RTC_ENTER_DEVICE(hgeometry); // do not enable for performance reasons !
return geometry->getUserData();
RTC_CATCH_END2(geometry);
return nullptr;
}
+ RTC_API void* rtcGetGeometryUserDataFromScene (RTCScene hscene, unsigned int geomID)
+ {
+ Scene* scene = (Scene*) hscene;
+ RTC_CATCH_BEGIN;
+ RTC_TRACE(rtcGetGeometryUserDataFromScene);
+#if defined(DEBUG)
+ RTC_VERIFY_HANDLE(hscene);
+ RTC_VERIFY_GEOMID(geomID);
+#endif
+ //RTC_ENTER_DEVICE(hscene); // do not enable for performance reasons
+ return scene->get(geomID)->getUserData();
+ RTC_CATCH_END2(scene);
+ return nullptr;
+ }
+
RTC_API void rtcSetGeometryBoundsFunction (RTCGeometry hgeometry, RTCBoundsFunction bounds, void* userPtr)
{
Geometry* geometry = (Geometry*) hgeometry;
RTC_CATCH_BEGIN;
RTC_TRACE(rtcSetGeometryBoundsFunction);
RTC_VERIFY_HANDLE(hgeometry);
+ RTC_ENTER_DEVICE(hgeometry);
geometry->setBoundsFunction(bounds,userPtr);
RTC_CATCH_END2(geometry);
}
@@ -1551,6 +1805,7 @@ RTC_NAMESPACE_BEGIN;
RTC_CATCH_BEGIN;
RTC_TRACE(rtcSetGeometryDisplacementFunction);
RTC_VERIFY_HANDLE(hgeometry);
+ RTC_ENTER_DEVICE(hgeometry);
geometry->setDisplacementFunction(displacement);
RTC_CATCH_END2(geometry);
}
@@ -1561,6 +1816,7 @@ RTC_NAMESPACE_BEGIN;
RTC_CATCH_BEGIN;
RTC_TRACE(rtcSetGeometryIntersectFunction);
RTC_VERIFY_HANDLE(hgeometry);
+ RTC_ENTER_DEVICE(hgeometry);
geometry->setIntersectFunctionN(intersect);
RTC_CATCH_END2(geometry);
}
@@ -1571,6 +1827,7 @@ RTC_NAMESPACE_BEGIN;
RTC_CATCH_BEGIN;
RTC_TRACE(rtcSetGeometryPointQueryFunction);
RTC_VERIFY_HANDLE(hgeometry);
+ RTC_ENTER_DEVICE(hgeometry);
geometry->setPointQueryFunction(pointQuery);
RTC_CATCH_END2(geometry);
}
@@ -1580,6 +1837,7 @@ RTC_NAMESPACE_BEGIN;
Geometry* geometry = (Geometry*) hgeometry;
RTC_CATCH_BEGIN;
RTC_TRACE(rtcGetGeometryFirstHalfEdge);
+ //RTC_ENTER_DEVICE(hgeometry); // do not enable for performance reasons
return geometry->getFirstHalfEdge(faceID);
RTC_CATCH_END2(geometry);
return -1;
@@ -1590,6 +1848,7 @@ RTC_NAMESPACE_BEGIN;
Geometry* geometry = (Geometry*) hgeometry;
RTC_CATCH_BEGIN;
RTC_TRACE(rtcGetGeometryFace);
+ //RTC_ENTER_DEVICE(hgeometry); // do not enable for performance reasons
return geometry->getFace(edgeID);
RTC_CATCH_END2(geometry);
return -1;
@@ -1600,6 +1859,7 @@ RTC_NAMESPACE_BEGIN;
Geometry* geometry = (Geometry*) hgeometry;
RTC_CATCH_BEGIN;
RTC_TRACE(rtcGetGeometryNextHalfEdge);
+ //RTC_ENTER_DEVICE(hgeometry); // do not enable for performance reasons
return geometry->getNextHalfEdge(edgeID);
RTC_CATCH_END2(geometry);
return -1;
@@ -1610,6 +1870,7 @@ RTC_NAMESPACE_BEGIN;
Geometry* geometry = (Geometry*) hgeometry;
RTC_CATCH_BEGIN;
RTC_TRACE(rtcGetGeometryPreviousHalfEdge);
+ //RTC_ENTER_DEVICE(hgeometry); // do not enable for performance reasons
return geometry->getPreviousHalfEdge(edgeID);
RTC_CATCH_END2(geometry);
return -1;
@@ -1620,6 +1881,7 @@ RTC_NAMESPACE_BEGIN;
Geometry* geometry = (Geometry*) hgeometry;
RTC_CATCH_BEGIN;
RTC_TRACE(rtcGetGeometryOppositeHalfEdge);
+ //RTC_ENTER_DEVICE(hgeometry); // do not enable for performance reasons
return geometry->getOppositeHalfEdge(topologyID,edgeID);
RTC_CATCH_END2(geometry);
return -1;
@@ -1631,6 +1893,7 @@ RTC_NAMESPACE_BEGIN;
RTC_CATCH_BEGIN;
RTC_TRACE(rtcSetOccludedFunctionN);
RTC_VERIFY_HANDLE(hgeometry);
+ RTC_ENTER_DEVICE(hgeometry);
geometry->setOccludedFunctionN(occluded);
RTC_CATCH_END2(geometry);
}
@@ -1641,6 +1904,7 @@ RTC_NAMESPACE_BEGIN;
RTC_CATCH_BEGIN;
RTC_TRACE(rtcSetGeometryIntersectFilterFunction);
RTC_VERIFY_HANDLE(hgeometry);
+ RTC_ENTER_DEVICE(hgeometry);
geometry->setIntersectionFilterFunctionN(filter);
RTC_CATCH_END2(geometry);
}
@@ -1651,10 +1915,22 @@ RTC_NAMESPACE_BEGIN;
RTC_CATCH_BEGIN;
RTC_TRACE(rtcSetGeometryOccludedFilterFunction);
RTC_VERIFY_HANDLE(hgeometry);
+ RTC_ENTER_DEVICE(hgeometry);
geometry->setOcclusionFilterFunctionN(filter);
RTC_CATCH_END2(geometry);
}
+ RTC_API void rtcSetGeometryEnableFilterFunctionFromArguments (RTCGeometry hgeometry, bool enable)
+ {
+ Geometry* geometry = (Geometry*) hgeometry;
+ RTC_CATCH_BEGIN;
+ RTC_TRACE(rtcSetGeometryEnableFilterFunctionFromArguments);
+ RTC_VERIFY_HANDLE(hgeometry);
+ RTC_ENTER_DEVICE(hgeometry);
+ geometry->enableFilterFunctionFromArguments(enable);
+ RTC_CATCH_END2(geometry);
+ }
+
RTC_API void rtcInterpolate(const RTCInterpolateArguments* const args)
{
Geometry* geometry = (Geometry*) args->geometry;
@@ -1663,6 +1939,7 @@ RTC_NAMESPACE_BEGIN;
#if defined(DEBUG)
RTC_VERIFY_HANDLE(args->geometry);
#endif
+ //RTC_ENTER_DEVICE(hgeometry); // do not enable for performance reasons
geometry->interpolate(args);
RTC_CATCH_END2(geometry);
}
@@ -1675,6 +1952,7 @@ RTC_NAMESPACE_BEGIN;
#if defined(DEBUG)
RTC_VERIFY_HANDLE(args->geometry);
#endif
+ // RTC_ENTER_DEVICE(hgeometry); // do not enable for performance reasons
geometry->interpolateN(args);
RTC_CATCH_END2(geometry);
}
@@ -1685,6 +1963,7 @@ RTC_NAMESPACE_BEGIN;
RTC_CATCH_BEGIN;
RTC_TRACE(rtcCommitGeometry);
RTC_VERIFY_HANDLE(hgeometry);
+ RTC_ENTER_DEVICE(hgeometry);
return geometry->commit();
RTC_CATCH_END2(geometry);
}
@@ -1697,6 +1976,7 @@ RTC_NAMESPACE_BEGIN;
RTC_TRACE(rtcAttachGeometry);
RTC_VERIFY_HANDLE(hscene);
RTC_VERIFY_HANDLE(hgeometry);
+ RTC_ENTER_DEVICE(hgeometry);
if (scene->device != geometry->device)
throw_RTCError(RTC_ERROR_INVALID_ARGUMENT,"inputs are from different devices");
return scene->bind(RTC_INVALID_GEOMETRY_ID,geometry);
@@ -1713,6 +1993,7 @@ RTC_NAMESPACE_BEGIN;
RTC_VERIFY_HANDLE(hscene);
RTC_VERIFY_HANDLE(hgeometry);
RTC_VERIFY_GEOMID(geomID);
+ RTC_ENTER_DEVICE(hscene);
if (scene->device != geometry->device)
throw_RTCError(RTC_ERROR_INVALID_ARGUMENT,"inputs are from different devices");
scene->bind(geomID,geometry);
@@ -1726,6 +2007,7 @@ RTC_NAMESPACE_BEGIN;
RTC_TRACE(rtcDetachGeometry);
RTC_VERIFY_HANDLE(hscene);
RTC_VERIFY_GEOMID(geomID);
+ RTC_ENTER_DEVICE(hscene);
scene->detachGeometry(geomID);
RTC_CATCH_END2(scene);
}
@@ -1736,6 +2018,7 @@ RTC_NAMESPACE_BEGIN;
RTC_CATCH_BEGIN;
RTC_TRACE(rtcRetainGeometry);
RTC_VERIFY_HANDLE(hgeometry);
+ RTC_ENTER_DEVICE(hgeometry);
geometry->refInc();
RTC_CATCH_END2(geometry);
}
@@ -1746,6 +2029,7 @@ RTC_NAMESPACE_BEGIN;
RTC_CATCH_BEGIN;
RTC_TRACE(rtcReleaseGeometry);
RTC_VERIFY_HANDLE(hgeometry);
+ RTC_ENTER_DEVICE(hgeometry);
geometry->refDec();
RTC_CATCH_END2(geometry);
}
@@ -1759,6 +2043,7 @@ RTC_NAMESPACE_BEGIN;
RTC_VERIFY_HANDLE(hscene);
RTC_VERIFY_GEOMID(geomID);
#endif
+ //RTC_ENTER_DEVICE(hscene); // do not enable for performance reasons
return (RTCGeometry) scene->get(geomID);
RTC_CATCH_END2(scene);
return nullptr;
diff --git a/thirdparty/embree/kernels/common/rtcore.h b/thirdparty/embree/kernels/common/rtcore.h
index ac58a84d6f..47526482c1 100644
--- a/thirdparty/embree/kernels/common/rtcore.h
+++ b/thirdparty/embree/kernels/common/rtcore.h
@@ -3,26 +3,14 @@
#pragma once
-#include "../../include/embree3/rtcore.h"
+#include "../../include/embree4/rtcore.h"
RTC_NAMESPACE_USE
namespace embree
{
/*! decoding of intersection flags */
- __forceinline bool isCoherent (RTCIntersectContextFlags flags) { return (flags & RTC_INTERSECT_CONTEXT_FLAG_COHERENT) == RTC_INTERSECT_CONTEXT_FLAG_COHERENT; }
- __forceinline bool isIncoherent(RTCIntersectContextFlags flags) { return (flags & RTC_INTERSECT_CONTEXT_FLAG_COHERENT) == RTC_INTERSECT_CONTEXT_FLAG_INCOHERENT; }
-
-#if defined(TASKING_TBB) && (TBB_INTERFACE_VERSION_MAJOR >= 8)
-# define USE_TASK_ARENA 1
-#else
-# define USE_TASK_ARENA 0
-#endif
-
-#if defined(TASKING_TBB) && (TBB_INTERFACE_VERSION >= 11009) // TBB 2019 Update 9
-# define TASKING_TBB_USE_TASK_ISOLATION 1
-#else
-# define TASKING_TBB_USE_TASK_ISOLATION 0
-#endif
+ __forceinline bool isCoherent (RTCRayQueryFlags flags) { return (flags & RTC_RAY_QUERY_FLAG_COHERENT) == RTC_RAY_QUERY_FLAG_COHERENT; }
+ __forceinline bool isIncoherent(RTCRayQueryFlags flags) { return (flags & RTC_RAY_QUERY_FLAG_COHERENT) == RTC_RAY_QUERY_FLAG_INCOHERENT; }
/*! Macros used in the rtcore API implementation */
// -- GODOT start --
@@ -30,8 +18,8 @@ namespace embree
#define RTC_CATCH_END(device)
#define RTC_CATCH_END2(scene)
#define RTC_CATCH_END2_FALSE(scene) return false;
-
#if 0
+// -- GODOT end --
#define RTC_CATCH_BEGIN try {
#define RTC_CATCH_END(device) \
@@ -47,7 +35,7 @@ namespace embree
#define RTC_CATCH_END2(scene) \
} catch (std::bad_alloc&) { \
- Device* device = scene ? scene->device : nullptr; \
+ Device* device = scene ? scene->device : nullptr; \
Device::process_error(device,RTC_ERROR_OUT_OF_MEMORY,"out of memory"); \
} catch (rtcore_error& e) { \
Device* device = scene ? scene->device : nullptr; \
@@ -78,9 +66,9 @@ namespace embree
Device::process_error(device,RTC_ERROR_UNKNOWN,"unknown exception caught"); \
return false; \
}
-#endif
-// -- GODOT end --
+#endif
+
#define RTC_VERIFY_HANDLE(handle) \
if (handle == nullptr) { \
throw_RTCError(RTC_ERROR_INVALID_ARGUMENT,"invalid argument"); \
@@ -137,5 +125,38 @@ namespace embree
// -- GODOT end --
#define RTC_BUILD_ARGUMENTS_HAS(settings,member) \
- (settings.byteSize > (offsetof(RTCBuildArguments,member)+sizeof(settings.member)))
+ (settings.byteSize > (offsetof(RTCBuildArguments,member)+sizeof(settings.member)))
+
+
+ inline void storeTransform(const AffineSpace3fa& space, RTCFormat format, float* xfm)
+ {
+ switch (format)
+ {
+ case RTC_FORMAT_FLOAT3X4_ROW_MAJOR:
+ xfm[ 0] = space.l.vx.x; xfm[ 1] = space.l.vy.x; xfm[ 2] = space.l.vz.x; xfm[ 3] = space.p.x;
+ xfm[ 4] = space.l.vx.y; xfm[ 5] = space.l.vy.y; xfm[ 6] = space.l.vz.y; xfm[ 7] = space.p.y;
+ xfm[ 8] = space.l.vx.z; xfm[ 9] = space.l.vy.z; xfm[10] = space.l.vz.z; xfm[11] = space.p.z;
+ break;
+
+ case RTC_FORMAT_FLOAT3X4_COLUMN_MAJOR:
+ xfm[ 0] = space.l.vx.x; xfm[ 1] = space.l.vx.y; xfm[ 2] = space.l.vx.z;
+ xfm[ 3] = space.l.vy.x; xfm[ 4] = space.l.vy.y; xfm[ 5] = space.l.vy.z;
+ xfm[ 6] = space.l.vz.x; xfm[ 7] = space.l.vz.y; xfm[ 8] = space.l.vz.z;
+ xfm[ 9] = space.p.x; xfm[10] = space.p.y; xfm[11] = space.p.z;
+ break;
+
+ case RTC_FORMAT_FLOAT4X4_COLUMN_MAJOR:
+ xfm[ 0] = space.l.vx.x; xfm[ 1] = space.l.vx.y; xfm[ 2] = space.l.vx.z; xfm[ 3] = 0.f;
+ xfm[ 4] = space.l.vy.x; xfm[ 5] = space.l.vy.y; xfm[ 6] = space.l.vy.z; xfm[ 7] = 0.f;
+ xfm[ 8] = space.l.vz.x; xfm[ 9] = space.l.vz.y; xfm[10] = space.l.vz.z; xfm[11] = 0.f;
+ xfm[12] = space.p.x; xfm[13] = space.p.y; xfm[14] = space.p.z; xfm[15] = 1.f;
+ break;
+
+ default:
+#if !defined(__SYCL_DEVICE_ONLY__)
+ throw_RTCError(RTC_ERROR_INVALID_OPERATION, "invalid matrix format");
+#endif
+ break;
+ }
+ }
}
diff --git a/thirdparty/embree/kernels/common/scene.cpp b/thirdparty/embree/kernels/common/scene.cpp
index 65d31d0f81..10cb3c4bec 100644
--- a/thirdparty/embree/kernels/common/scene.cpp
+++ b/thirdparty/embree/kernels/common/scene.cpp
@@ -3,12 +3,35 @@
#include "scene.h"
+#include "../../common/tasking/taskscheduler.h"
+
#include "../bvh/bvh4_factory.h"
#include "../bvh/bvh8_factory.h"
+
#include "../../common/algorithms/parallel_reduce.h"
-
+
+#if defined(EMBREE_SYCL_SUPPORT)
+# include "../sycl/rthwif_embree_builder.h"
+#endif
+
+
namespace embree
{
+
+ struct TaskGroup {
+ /*! global lock step task scheduler */
+#if defined(TASKING_INTERNAL)
+ MutexSys schedulerMutex;
+ Ref<TaskScheduler> scheduler;
+#elif defined(TASKING_TBB) && TASKING_TBB_USE_TASK_ISOLATION
+ tbb::isolated_task_group group;
+#elif defined(TASKING_TBB)
+ tbb::task_group group;
+#elif defined(TASKING_PPL)
+ concurrency::task_group group;
+#endif
+ };
+
/* error raising rtcIntersect and rtcOccluded functions */
void missing_rtcCommit() { throw_RTCError(RTC_ERROR_INVALID_OPERATION,"scene not committed"); }
void invalid_rtcIntersect1() { throw_RTCError(RTC_ERROR_INVALID_OPERATION,"rtcIntersect and rtcOccluded not enabled"); }
@@ -22,13 +45,20 @@ namespace embree
flags_modified(true), enabled_geometry_types(0),
scene_flags(RTC_SCENE_FLAG_NONE),
quality_flags(RTC_BUILD_QUALITY_MEDIUM),
- is_build(false), modified(true),
+ modified(true),
+ taskGroup(new TaskGroup()),
progressInterface(this), progress_monitor_function(nullptr), progress_monitor_ptr(nullptr), progress_monitor_counter(0)
{
device->refInc();
intersectors = Accel::Intersectors(missing_rtcCommit);
+ /* use proper device and context for SYCL allocations */
+#if defined(EMBREE_SYCL_SUPPORT)
+ if (DeviceGPU* gpu_device = dynamic_cast<DeviceGPU*>(device))
+ hwaccel = AccelBuffer(AccelAllocator<char>(device,gpu_device->getGPUDevice(),gpu_device->getGPUContext()),0);
+#endif
+
/* one can overwrite flags through device for debugging */
if (device->quality_flags != -1)
quality_flags = (RTCBuildQuality) device->quality_flags;
@@ -90,10 +120,11 @@ namespace embree
void Scene::createTriangleAccel()
{
#if defined(EMBREE_GEOMETRY_TRIANGLE)
+
if (device->tri_accel == "default")
{
if (quality_flags != RTC_BUILD_QUALITY_LOW)
- {
+ {
int mode = 2*(int)isCompactAccel() + 1*(int)isRobustAccel();
switch (mode) {
case /*0b00*/ 0:
@@ -168,11 +199,13 @@ namespace embree
#endif
else throw_RTCError(RTC_ERROR_INVALID_ARGUMENT,"unknown triangle acceleration structure "+device->tri_accel);
#endif
+
}
void Scene::createTriangleMBAccel()
{
#if defined(EMBREE_GEOMETRY_TRIANGLE)
+
if (device->tri_accel_mb == "default")
{
int mode = 2*(int)isCompactAccel() + 1*(int)isRobustAccel();
@@ -211,6 +244,7 @@ namespace embree
void Scene::createQuadAccel()
{
#if defined(EMBREE_GEOMETRY_QUAD)
+
if (device->quad_accel == "default")
{
if (quality_flags != RTC_BUILD_QUALITY_LOW)
@@ -292,6 +326,7 @@ namespace embree
void Scene::createQuadMBAccel()
{
#if defined(EMBREE_GEOMETRY_QUAD)
+
if (device->quad_accel_mb == "default")
{
int mode = 2*(int)isCompactAccel() + 1*(int)isRobustAccel();
@@ -329,6 +364,7 @@ namespace embree
void Scene::createHairAccel()
{
#if defined(EMBREE_GEOMETRY_CURVE) || defined(EMBREE_GEOMETRY_POINT)
+
if (device->hair_accel == "default")
{
int mode = 2*(int)isCompactAccel() + 1*(int)isRobustAccel();
@@ -366,6 +402,7 @@ namespace embree
void Scene::createHairMBAccel()
{
#if defined(EMBREE_GEOMETRY_CURVE) || defined(EMBREE_GEOMETRY_POINT)
+
if (device->hair_accel_mb == "default")
{
#if defined (EMBREE_TARGET_SIMD8)
@@ -416,7 +453,8 @@ namespace embree
void Scene::createUserGeometryAccel()
{
#if defined(EMBREE_GEOMETRY_USER)
- if (device->object_accel == "default")
+
+ if (device->object_accel == "default")
{
#if defined (EMBREE_TARGET_SIMD8)
if (device->canUseAVX() && !isCompactAccel())
@@ -448,6 +486,7 @@ namespace embree
void Scene::createUserGeometryMBAccel()
{
#if defined(EMBREE_GEOMETRY_USER)
+
if (device->object_accel_mb == "default" ) {
#if defined (EMBREE_TARGET_SIMD8)
if (device->canUseAVX() && !isCompactAccel())
@@ -467,6 +506,7 @@ namespace embree
void Scene::createInstanceAccel()
{
#if defined(EMBREE_GEOMETRY_INSTANCE)
+
// if (device->object_accel == "default")
{
#if defined (EMBREE_TARGET_SIMD8)
@@ -494,6 +534,7 @@ namespace embree
void Scene::createInstanceMBAccel()
{
#if defined(EMBREE_GEOMETRY_INSTANCE)
+
//if (device->instance_accel_mb == "default")
{
#if defined (EMBREE_TARGET_SIMD8)
@@ -550,10 +591,58 @@ namespace embree
#endif
}
+ void Scene::createInstanceArrayAccel()
+ {
+#if defined(EMBREE_GEOMETRY_INSTANCE_ARRAY)
+
+ // if (device->object_accel == "default")
+ {
+#if defined (EMBREE_TARGET_SIMD8)
+ if (device->canUseAVX() && !isCompactAccel()) {
+ if (quality_flags != RTC_BUILD_QUALITY_LOW) {
+ accels_add(device->bvh8_factory->BVH8InstanceArray(this, BVHFactory::BuildVariant::STATIC));
+ } else {
+ accels_add(device->bvh8_factory->BVH8InstanceArray(this, BVHFactory::BuildVariant::DYNAMIC));
+ }
+ }
+ else
+#endif
+ {
+ if (quality_flags != RTC_BUILD_QUALITY_LOW) {
+ accels_add(device->bvh4_factory->BVH4InstanceArray(this, BVHFactory::BuildVariant::STATIC));
+ } else {
+ accels_add(device->bvh4_factory->BVH4InstanceArray(this, BVHFactory::BuildVariant::DYNAMIC));
+ }
+ }
+ }
+ // else throw_RTCError(RTC_ERROR_INVALID_ARGUMENT,"unknown instance accel "+device->instance_accel);
+#endif
+ }
+
+ void Scene::createInstanceArrayMBAccel()
+ {
+#if defined(EMBREE_GEOMETRY_INSTANCE_ARRAY)
+
+ //if (device->instance_accel_mb == "default")
+ {
+#if defined (EMBREE_TARGET_SIMD8)
+ if (device->canUseAVX() && !isCompactAccel())
+ accels_add(device->bvh8_factory->BVH8InstanceArrayMB(this));
+ else
+#endif
+ accels_add(device->bvh4_factory->BVH4InstanceArrayMB(this));
+ }
+ //else throw_RTCError(RTC_ERROR_INVALID_ARGUMENT,"unknown instance mblur accel "+device->instance_accel_mb);
+#endif
+ }
+
+
void Scene::createGridAccel()
{
- BVHFactory::IntersectVariant ivariant = isRobustAccel() ? BVHFactory::IntersectVariant::ROBUST : BVHFactory::IntersectVariant::FAST;
#if defined(EMBREE_GEOMETRY_GRID)
+
+ BVHFactory::IntersectVariant ivariant = isRobustAccel() ? BVHFactory::IntersectVariant::ROBUST : BVHFactory::IntersectVariant::FAST;
+
if (device->grid_accel == "default")
{
#if defined (EMBREE_TARGET_SIMD8)
@@ -579,6 +668,7 @@ namespace embree
void Scene::createGridMBAccel()
{
#if defined(EMBREE_GEOMETRY_GRID)
+
if (device->grid_accel_mb == "default")
{
accels_add(device->bvh4_factory->BVH4GridMB(this,BVHFactory::BuildVariant::STATIC));
@@ -588,13 +678,13 @@ namespace embree
#endif
}
-
+
void Scene::clear() {
}
unsigned Scene::bind(unsigned geomID, Ref<Geometry> geometry)
{
- Lock<SpinLock> lock(geometriesMutex);
+ Lock<MutexSys> lock(geometriesMutex);
if (geomID == RTC_INVALID_GEOMETRY_ID) {
geomID = id_pool.allocate();
if (geomID == RTC_INVALID_GEOMETRY_ID)
@@ -620,7 +710,7 @@ namespace embree
void Scene::detachGeometry(size_t geomID)
{
- Lock<SpinLock> lock(geometriesMutex);
+ Lock<MutexSys> lock(geometriesMutex);
if (geomID >= geometries.size())
throw_RTCError(RTC_ERROR_INVALID_OPERATION,"invalid geometry ID");
@@ -637,45 +727,11 @@ namespace embree
geometryModCounters_[geomID] = 0;
}
- void Scene::updateInterface()
- {
- is_build = true;
- }
-
- void Scene::commit_task ()
+ void Scene::build_cpu_accels()
{
- checkIfModifiedAndSet ();
- if (!isModified()) {
- return;
- }
-
- /* print scene statistics */
- if (device->verbosity(2))
- printStatistics();
-
- progress_monitor_counter = 0;
-
- /* gather scene stats and call preCommit function of each geometry */
- this->world = parallel_reduce (size_t(0), geometries.size(), GeometryCounts (),
- [this](const range<size_t>& r)->GeometryCounts
- {
- GeometryCounts c;
- for (auto i=r.begin(); i<r.end(); ++i)
- {
- if (geometries[i] && geometries[i]->isEnabled())
- {
- geometries[i]->preCommit();
- geometries[i]->addElementsToCount (c);
- c.numFilterFunctions += (int) geometries[i]->hasFilterFunctions();
- }
- }
- return c;
- },
- std::plus<GeometryCounts>()
- );
-
/* select acceleration structures to build */
unsigned int new_enabled_geometry_types = world.enabledGeometryTypesMask();
+
if (flags_modified || new_enabled_geometry_types != enabled_geometry_types)
{
accels_init();
@@ -685,7 +741,7 @@ namespace embree
parallel_for(geometryModCounters_.size(), [&] ( const size_t i ) {
geometryModCounters_[i] = 0;
});
-
+
if (getNumPrimitives(TriangleMesh::geom_type,false)) createTriangleAccel();
if (getNumPrimitives(TriangleMesh::geom_type,true)) createTriangleMBAccel();
if (getNumPrimitives(QuadMesh::geom_type,false)) createQuadAccel();
@@ -702,7 +758,9 @@ namespace embree
if (getNumPrimitives(Geometry::MTY_INSTANCE_CHEAP,true)) createInstanceMBAccel();
if (getNumPrimitives(Geometry::MTY_INSTANCE_EXPENSIVE,false)) createInstanceExpensiveAccel();
if (getNumPrimitives(Geometry::MTY_INSTANCE_EXPENSIVE,true)) createInstanceExpensiveMBAccel();
-
+ if (getNumPrimitives(Geometry::MTY_INSTANCE_ARRAY,false)) createInstanceArrayAccel();
+ if (getNumPrimitives(Geometry::MTY_INSTANCE_ARRAY,true)) createInstanceArrayMBAccel();
+
flags_modified = false;
enabled_geometry_types = new_enabled_geometry_types;
}
@@ -719,6 +777,61 @@ namespace embree
flags_modified = true; // in non-dynamic mode we have to re-create accels
}
+ if (device->verbosity(2)) {
+ std::cout << "created scene intersector" << std::endl;
+ accels_print(2);
+ std::cout << "selected scene intersector" << std::endl;
+ intersectors.print(2);
+ }
+ }
+
+ void Scene::build_gpu_accels()
+ {
+#if defined(EMBREE_SYCL_SUPPORT)
+ const BBox3f aabb = rthwifBuild(this,hwaccel);
+ bounds = LBBox<embree::Vec3fa>(aabb);
+ hwaccel_bounds = aabb;
+#endif
+ }
+
+ void Scene::commit_task ()
+ {
+ checkIfModifiedAndSet();
+ if (!isModified()) return;
+
+ /* print scene statistics */
+ if (device->verbosity(2))
+ printStatistics();
+
+ progress_monitor_counter = 0;
+
+ /* gather scene stats and call preCommit function of each geometry */
+ this->world = parallel_reduce (size_t(0), geometries.size(), GeometryCounts (),
+ [this](const range<size_t>& r)->GeometryCounts
+ {
+ GeometryCounts c;
+ for (auto i=r.begin(); i<r.end(); ++i)
+ {
+ if (geometries[i] && geometries[i]->isEnabled())
+ {
+ geometries[i]->preCommit();
+ geometries[i]->addElementsToCount (c);
+ c.numFilterFunctions += (int) geometries[i]->hasArgumentFilterFunctions();
+ c.numFilterFunctions += (int) geometries[i]->hasGeometryFilterFunctions();
+ }
+ }
+ return c;
+ },
+ std::plus<GeometryCounts>()
+ );
+
+#if defined(EMBREE_SYCL_SUPPORT)
+ if (DeviceGPU* gpu_device = dynamic_cast<DeviceGPU*>(device))
+ build_gpu_accels();
+ else
+#endif
+ build_cpu_accels();
+
/* call postCommit function of each geometry */
parallel_for(geometries.size(), [&] ( const size_t i ) {
if (geometries[i] && geometries[i]->isEnabled()) {
@@ -727,16 +840,7 @@ namespace embree
geometryModCounters_[i] = geometries[i]->getModCounter();
}
});
-
- updateInterface();
- if (device->verbosity(2)) {
- std::cout << "created scene intersector" << std::endl;
- accels_print(2);
- std::cout << "selected scene intersector" << std::endl;
- intersectors.print(2);
- }
-
setModified(false);
}
@@ -771,11 +875,11 @@ namespace embree
/* allocates own taskscheduler for each build */
Ref<TaskScheduler> scheduler = nullptr;
{
- Lock<MutexSys> lock(schedulerMutex);
- scheduler = this->scheduler;
+ Lock<MutexSys> lock(taskGroup->schedulerMutex);
+ scheduler = taskGroup->scheduler;
if (scheduler == null) {
buildLock.lock();
- this->scheduler = scheduler = new TaskScheduler;
+ taskGroup->scheduler = scheduler = new TaskScheduler;
}
}
@@ -792,13 +896,13 @@ namespace embree
/* initiate build */
// -- GODOT start --
// try {
- scheduler->spawn_root([&]() { commit_task(); Lock<MutexSys> lock(schedulerMutex); this->scheduler = nullptr; }, 1, !join);
+ TaskScheduler::TaskGroupContext context;
+ scheduler->spawn_root([&]() { commit_task(); Lock<MutexSys> lock(taskGroup->schedulerMutex); taskGroup->scheduler = nullptr; }, &context, 1, !join);
// }
// catch (...) {
// accels_clear();
- // updateInterface();
- // Lock<MutexSys> lock(schedulerMutex);
- // this->scheduler = nullptr;
+ // Lock<MutexSys> lock(taskGroup->schedulerMutex);
+ // taskGroup->scheduler = nullptr;
// throw;
// }
// -- GODOT end --
@@ -809,7 +913,7 @@ namespace embree
#if defined(TASKING_TBB)
void Scene::commit (bool join)
- {
+ {
#if defined(TASKING_TBB) && (TBB_INTERFACE_VERSION_MAJOR < 8)
if (join)
throw_RTCError(RTC_ERROR_INVALID_OPERATION,"rtcJoinCommitScene not supported with this TBB version");
@@ -827,16 +931,7 @@ namespace embree
#endif
do {
-
-#if USE_TASK_ARENA
- if (join) {
- device->arena->execute([&]{ group.wait(); });
- }
- else
-#endif
- {
- group.wait();
- }
+ device->execute(join, [&](){ taskGroup->group.wait(); });
pause_cpu();
yield();
@@ -857,26 +952,14 @@ namespace embree
tbb::task_group_context ctx( tbb::task_group_context::isolated, tbb::task_group_context::default_traits | tbb::task_group_context::fp_settings );
#endif
//ctx.set_priority(tbb::priority_high);
-
-#if USE_TASK_ARENA
- if (join)
- {
- device->arena->execute([&]{
- group.run([&]{
- tbb::parallel_for (size_t(0), size_t(1), size_t(1), [&] (size_t) { commit_task(); }, ctx);
- });
- group.wait();
- });
- }
- else
-#endif
+ device->execute(join, [&]()
{
- group.run([&]{
+ taskGroup->group.run([&]{
tbb::parallel_for (size_t(0), size_t(1), size_t(1), [&] (size_t) { commit_task(); }, ctx);
});
- group.wait();
- }
-
+ taskGroup->group.wait();
+ });
+
/* reset MXCSR register again */
_mm_setcsr(mxcsr);
}
@@ -886,7 +969,6 @@ namespace embree
_mm_setcsr(mxcsr);
accels_clear();
- updateInterface();
throw;
}
}
@@ -915,10 +997,10 @@ namespace embree
try {
- group.run([&]{
+ taskGroup->group.run([&]{
concurrency::parallel_for(size_t(0), size_t(1), size_t(1), [&](size_t) { commit_task(); });
});
- group.wait();
+ taskGroup->group.wait();
/* reset MXCSR register again */
_mm_setcsr(mxcsr);
@@ -929,7 +1011,6 @@ namespace embree
_mm_setcsr(mxcsr);
accels_clear();
- updateInterface();
throw;
}
}
diff --git a/thirdparty/embree/kernels/common/scene.h b/thirdparty/embree/kernels/common/scene.h
index 5ed80a63f6..d9acca1065 100644
--- a/thirdparty/embree/kernels/common/scene.h
+++ b/thirdparty/embree/kernels/common/scene.h
@@ -6,11 +6,11 @@
#include "default.h"
#include "device.h"
#include "builder.h"
-#include "../../common/algorithms/parallel_any_of.h"
#include "scene_triangle_mesh.h"
#include "scene_quad_mesh.h"
#include "scene_user_geometry.h"
#include "scene_instance.h"
+#include "scene_instance_array.h"
#include "scene_curves.h"
#include "scene_line_segments.h"
#include "scene_subdiv_mesh.h"
@@ -21,12 +21,18 @@
#include "acceln.h"
#include "geometry.h"
+#if defined(EMBREE_SYCL_SUPPORT)
+#include "../sycl/rthwif_embree_builder.h"
+#endif
+
namespace embree
{
+ struct TaskGroup;
+
/*! Base class all scenes are derived from */
class Scene : public AccelN
{
- ALIGNED_CLASS_(std::alignment_of<Scene>::value);
+ ALIGNED_CLASS_USM_(std::alignment_of<Scene>::value);
public:
template<typename Ty, bool mblur = false>
@@ -140,6 +146,7 @@ namespace embree
~Scene () noexcept;
private:
+
/*! class is non-copyable */
Scene (const Scene& other) DELETED; // do not implement
Scene& operator= (const Scene& other) DELETED; // do not implement
@@ -159,6 +166,8 @@ namespace embree
void createInstanceMBAccel();
void createInstanceExpensiveAccel();
void createInstanceExpensiveMBAccel();
+ void createInstanceArrayAccel();
+ void createInstanceArrayMBAccel();
void createGridAccel();
void createGridMBAccel();
@@ -176,13 +185,13 @@ namespace embree
void setSceneFlags(RTCSceneFlags scene_flags);
RTCSceneFlags getSceneFlags() const;
-
+
+ void build_cpu_accels();
+ void build_gpu_accels();
void commit (bool join);
void commit_task ();
void build () {}
- void updateInterface();
-
/* return number of geometries */
__forceinline size_t size() const { return geometries.size(); }
@@ -205,20 +214,9 @@ namespace embree
}
protected:
-
- __forceinline void checkIfModifiedAndSet ()
- {
- if (isModified ()) return;
-
- auto geometryIsModified = [this](size_t geomID)->bool {
- return isGeometryModified(geomID);
- };
- if (parallel_any_of (size_t(0), geometries.size (), geometryIsModified)) {
- setModified ();
- }
- }
-
+ void checkIfModifiedAndSet ();
+
public:
/* get mesh by ID */
@@ -247,7 +245,7 @@ namespace embree
}
__forceinline Ref<Geometry> get_locked(size_t i) {
- Lock<SpinLock> lock(geometriesMutex);
+ Lock<MutexSys> lock(geometriesMutex);
assert(i < geometries.size());
return geometries[i];
}
@@ -259,8 +257,8 @@ namespace embree
__forceinline bool isStaticAccel() const { return !(scene_flags & RTC_SCENE_FLAG_DYNAMIC); }
__forceinline bool isDynamicAccel() const { return scene_flags & RTC_SCENE_FLAG_DYNAMIC; }
- __forceinline bool hasContextFilterFunction() const {
- return scene_flags & RTC_SCENE_FLAG_CONTEXT_FILTER_FUNCTION;
+ __forceinline bool hasArgumentFilterFunction() const {
+ return scene_flags & RTC_SCENE_FLAG_FILTER_FUNCTION_IN_ARGUMENTS;
}
__forceinline bool hasGeometryFilterFunction() {
@@ -268,21 +266,21 @@ namespace embree
}
__forceinline bool hasFilterFunction() {
- return hasContextFilterFunction() || hasGeometryFilterFunction();
+ return hasArgumentFilterFunction() || hasGeometryFilterFunction();
}
- /* test if scene got already build */
- __forceinline bool isBuild() const { return is_build; }
+ void* createQBVH6Accel();
+
+ public:
+ Device* device;
public:
IDPool<unsigned,0xFFFFFFFE> id_pool;
- vector<Ref<Geometry>> geometries; //!< list of all user geometries
- vector<unsigned int> geometryModCounters_;
- vector<float*> vertices;
+ Device::vector<Ref<Geometry>> geometries = device; //!< list of all user geometries
+ avector<unsigned int> geometryModCounters_;
+ Device::vector<float*> vertices = device;
public:
- Device* device;
-
/* these are to detect if we need to recreate the acceleration structures */
bool flags_modified;
unsigned int enabled_geometry_types;
@@ -290,24 +288,20 @@ namespace embree
RTCSceneFlags scene_flags;
RTCBuildQuality quality_flags;
MutexSys buildMutex;
- SpinLock geometriesMutex;
- bool is_build;
+ MutexSys geometriesMutex;
+
+#if defined(EMBREE_SYCL_SUPPORT)
+ public:
+ BBox3f hwaccel_bounds = empty;
+ AccelBuffer hwaccel;
+#endif
+
private:
bool modified; //!< true if scene got modified
public:
-
- /*! global lock step task scheduler */
-#if defined(TASKING_INTERNAL)
- MutexSys schedulerMutex;
- Ref<TaskScheduler> scheduler;
-#elif defined(TASKING_TBB) && TASKING_TBB_USE_TASK_ISOLATION
- tbb::isolated_task_group group;
-#elif defined(TASKING_TBB)
- tbb::task_group group;
-#elif defined(TASKING_PPL)
- concurrency::task_group group;
-#endif
+
+ std::unique_ptr<TaskGroup> taskGroup;
public:
struct BuildProgressMonitorInterface : public BuildProgressMonitor {
@@ -363,12 +357,28 @@ namespace embree
if (mask & Geometry::MTY_INSTANCE_EXPENSIVE)
count += mblur ? world.numMBInstancesExpensive : world.numInstancesExpensive;
-
+
+ if (mask & Geometry::MTY_INSTANCE_ARRAY)
+ count += mblur ? world.numMBInstanceArrays : world.numInstanceArrays;
+
if (mask & Geometry::MTY_GRID_MESH)
count += mblur ? world.numMBGrids : world.numGrids;
return count;
}
+
+ __forceinline size_t getNumSubPrimitives(Geometry::GTypeMask mask, bool mblur) const
+ {
+ size_t count = 0;
+
+ if (mask & Geometry::MTY_GRID_MESH)
+ count += mblur ? world.numMBSubGrids : world.numSubGrids;
+
+ Geometry::GTypeMask new_mask = (Geometry::GTypeMask)(mask & ~Geometry::MTY_GRID_MESH);
+ count += getNumPrimitives(new_mask, mblur);
+
+ return count;
+ }
template<typename Mesh, bool mblur>
__forceinline unsigned getNumTimeSteps()
diff --git a/thirdparty/embree/kernels/common/scene_curves.h b/thirdparty/embree/kernels/common/scene_curves.h
index a1ea45d3c7..fd6ed81d7d 100644
--- a/thirdparty/embree/kernels/common/scene_curves.h
+++ b/thirdparty/embree/kernels/common/scene_curves.h
@@ -119,6 +119,15 @@ namespace embree
p3 = vertex(i+3,itime);
}
+ /*! gathers the curve normals starting with i'th vertex */
+ __forceinline void gather_normals(Vec3fa& n0, Vec3fa& n1, Vec3fa& n2, Vec3fa& n3, size_t i) const
+ {
+ n0 = normal(i+0);
+ n1 = normal(i+1);
+ n2 = normal(i+2);
+ n3 = normal(i+3);
+ }
+
/*! gathers the curve starting with i'th vertex */
__forceinline void gather(Vec3ff& p0, Vec3ff& p1, Vec3ff& p2, Vec3ff& p3, Vec3fa& n0, Vec3fa& n1, Vec3fa& n2, Vec3fa& n3, size_t i) const
{
@@ -178,6 +187,13 @@ namespace embree
}
/*! loads curve vertices for specified time */
+ __forceinline void gather_safe(Vec3ff& p0, Vec3ff& p1, Vec3ff& p2, Vec3ff& p3, size_t i, float time) const
+ {
+ if (hasMotionBlur()) gather(p0,p1,p2,p3,i,time);
+ else gather(p0,p1,p2,p3,i);
+ }
+
+ /*! loads curve vertices for specified time */
__forceinline void gather(Vec3ff& p0, Vec3ff& p1, Vec3ff& p2, Vec3ff& p3, Vec3fa& n0, Vec3fa& n1, Vec3fa& n2, Vec3fa& n3, size_t i, float time) const
{
float ftime;
@@ -199,8 +215,15 @@ namespace embree
n3 = madd(Vec3ff(t0),an3,t1*bn3);
}
+ /*! loads curve vertices for specified time for mblur and non-mblur case */
+ __forceinline void gather_safe(Vec3ff& p0, Vec3ff& p1, Vec3ff& p2, Vec3ff& p3, Vec3fa& n0, Vec3fa& n1, Vec3fa& n2, Vec3fa& n3, size_t i, float time) const
+ {
+ if (hasMotionBlur()) gather(p0,p1,p2,p3,n0,n1,n2,n3,i,time);
+ else gather(p0,p1,p2,p3,n0,n1,n2,n3,i);
+ }
+
template<typename SourceCurve3ff, typename SourceCurve3fa, typename TensorLinearCubicBezierSurface3fa>
- __forceinline TensorLinearCubicBezierSurface3fa getNormalOrientedCurve(IntersectContext* context, const Vec3fa& ray_org, const unsigned int primID, const size_t itime) const
+ __forceinline TensorLinearCubicBezierSurface3fa getNormalOrientedCurve(RayQueryContext* context, const Vec3fa& ray_org, const unsigned int primID, const size_t itime) const
{
Vec3ff v0,v1,v2,v3; Vec3fa n0,n1,n2,n3;
unsigned int vertexID = curve(primID);
@@ -212,7 +235,7 @@ namespace embree
}
template<typename SourceCurve3ff, typename SourceCurve3fa, typename TensorLinearCubicBezierSurface3fa>
- __forceinline TensorLinearCubicBezierSurface3fa getNormalOrientedCurve(IntersectContext* context, const Vec3fa& ray_org, const unsigned int primID, const float time) const
+ __forceinline TensorLinearCubicBezierSurface3fa getNormalOrientedCurve(RayQueryContext* context, const Vec3fa& ray_org, const unsigned int primID, const float time) const
{
float ftime;
const size_t itime = timeSegment(time, ftime);
@@ -221,6 +244,19 @@ namespace embree
return clerp(curve0,curve1,ftime);
}
+ template<typename SourceCurve3ff, typename SourceCurve3fa, typename TensorLinearCubicBezierSurface3fa>
+ __forceinline TensorLinearCubicBezierSurface3fa getNormalOrientedCurveSafe(RayQueryContext* context, const Vec3fa& ray_org, const unsigned int primID, const float time) const
+ {
+ float ftime = 0.0f;
+ const size_t itime = hasMotionBlur() ? timeSegment(time, ftime) : 0;
+ const TensorLinearCubicBezierSurface3fa curve0 = getNormalOrientedCurve<SourceCurve3ff, SourceCurve3fa, TensorLinearCubicBezierSurface3fa>(context,ray_org,primID,itime+0);
+ if (hasMotionBlur()) {
+ const TensorLinearCubicBezierSurface3fa curve1 = getNormalOrientedCurve<SourceCurve3ff, SourceCurve3fa, TensorLinearCubicBezierSurface3fa>(context,ray_org,primID,itime+1);
+ return clerp(curve0,curve1,ftime);
+ }
+ return curve0;
+ }
+
/*! gathers the hermite curve starting with i'th vertex */
__forceinline void gather_hermite(Vec3ff& p0, Vec3ff& t0, Vec3ff& p1, Vec3ff& t1, size_t i) const
{
@@ -255,6 +291,13 @@ namespace embree
t1 = madd(Vec3ff(f0),at1,f1*bt1);
}
+ /*! loads curve vertices for specified time for mblur and non-mblur geometry */
+ __forceinline void gather_hermite_safe(Vec3ff& p0, Vec3ff& t0, Vec3ff& p1, Vec3ff& t1, size_t i, float time) const
+ {
+ if (hasMotionBlur()) gather_hermite(p0,t0,p1,t1,i,time);
+ else gather_hermite(p0,t0,p1,t1,i);
+ }
+
/*! gathers the hermite curve starting with i'th vertex */
__forceinline void gather_hermite(Vec3ff& p0, Vec3ff& t0, Vec3fa& n0, Vec3fa& dn0, Vec3ff& p1, Vec3ff& t1, Vec3fa& n1, Vec3fa& dn1, size_t i) const
{
@@ -282,7 +325,7 @@ namespace embree
}
/*! loads curve vertices for specified time */
- __forceinline void gather_hermite(Vec3ff& p0, Vec3fa& t0, Vec3fa& n0, Vec3fa& dn0, Vec3ff& p1, Vec3fa& t1, Vec3fa& n1, Vec3fa& dn1, size_t i, float time) const
+ __forceinline void gather_hermite(Vec3ff& p0, Vec3ff& t0, Vec3fa& n0, Vec3fa& dn0, Vec3ff& p1, Vec3ff& t1, Vec3fa& n1, Vec3fa& dn1, size_t i, float time) const
{
float ftime;
const size_t itime = timeSegment(time, ftime);
@@ -301,8 +344,15 @@ namespace embree
dn1= madd(Vec3ff(f0),adn1,f1*bdn1);
}
+ /*! loads curve vertices for specified time */
+ __forceinline void gather_hermite_safe(Vec3ff& p0, Vec3ff& t0, Vec3fa& n0, Vec3fa& dn0, Vec3ff& p1, Vec3ff& t1, Vec3fa& n1, Vec3fa& dn1, size_t i, float time) const
+ {
+ if (hasMotionBlur()) gather_hermite(p0,t0,n0,dn0,p1,t1,n1,dn1,i,time);
+ else gather_hermite(p0,t0,n0,dn0,p1,t1,n1,dn1,i);
+ }
+
template<typename SourceCurve3ff, typename SourceCurve3fa, typename TensorLinearCubicBezierSurface3fa>
- __forceinline TensorLinearCubicBezierSurface3fa getNormalOrientedHermiteCurve(IntersectContext* context, const Vec3fa& ray_org, const unsigned int primID, const size_t itime) const
+ __forceinline TensorLinearCubicBezierSurface3fa getNormalOrientedHermiteCurve(RayQueryContext* context, const Vec3fa& ray_org, const unsigned int primID, const size_t itime) const
{
Vec3ff v0,t0,v1,t1; Vec3fa n0,dn0,n1,dn1;
unsigned int vertexID = curve(primID);
@@ -315,7 +365,7 @@ namespace embree
}
template<typename SourceCurve3ff, typename SourceCurve3fa, typename TensorLinearCubicBezierSurface3fa>
- __forceinline TensorLinearCubicBezierSurface3fa getNormalOrientedHermiteCurve(IntersectContext* context, const Vec3fa& ray_org, const unsigned int primID, const float time) const
+ __forceinline TensorLinearCubicBezierSurface3fa getNormalOrientedHermiteCurve(RayQueryContext* context, const Vec3fa& ray_org, const unsigned int primID, const float time) const
{
float ftime;
const size_t itime = timeSegment(time, ftime);
@@ -324,6 +374,24 @@ namespace embree
return clerp(curve0,curve1,ftime);
}
+ template<typename SourceCurve3ff, typename SourceCurve3fa, typename TensorLinearCubicBezierSurface3fa>
+ __forceinline TensorLinearCubicBezierSurface3fa getNormalOrientedHermiteCurveSafe(RayQueryContext* context, const Vec3fa& ray_org, const unsigned int primID, const float time) const
+ {
+ float ftime = 0.0f;
+ const size_t itime = hasMotionBlur() ? timeSegment(time, ftime) : 0;
+ const TensorLinearCubicBezierSurface3fa curve0 = getNormalOrientedHermiteCurve<SourceCurve3ff, SourceCurve3fa, TensorLinearCubicBezierSurface3fa>(context, ray_org, primID,itime+0);
+ if (hasMotionBlur()) {
+ const TensorLinearCubicBezierSurface3fa curve1 = getNormalOrientedHermiteCurve<SourceCurve3ff, SourceCurve3fa, TensorLinearCubicBezierSurface3fa>(context, ray_org, primID,itime+1);
+ return clerp(curve0,curve1,ftime);
+ }
+ return curve0;
+ }
+
+ /* returns the projected area */
+ __forceinline float projectedPrimitiveArea(const size_t i) const {
+ return 1.0f;
+ }
+
private:
void resizeBuffers(unsigned int numSteps);
@@ -333,12 +401,12 @@ namespace embree
BufferView<Vec3fa> normals0; //!< fast access to first normal buffer
BufferView<Vec3ff> tangents0; //!< fast access to first tangent buffer
BufferView<Vec3fa> dnormals0; //!< fast access to first normal derivative buffer
- vector<BufferView<Vec3ff>> vertices; //!< vertex array for each timestep
- vector<BufferView<Vec3fa>> normals; //!< normal array for each timestep
- vector<BufferView<Vec3ff>> tangents; //!< tangent array for each timestep
- vector<BufferView<Vec3fa>> dnormals; //!< normal derivative array for each timestep
+ Device::vector<BufferView<Vec3ff>> vertices = device; //!< vertex array for each timestep
+ Device::vector<BufferView<Vec3fa>> normals = device; //!< normal array for each timestep
+ Device::vector<BufferView<Vec3ff>> tangents = device; //!< tangent array for each timestep
+ Device::vector<BufferView<Vec3fa>> dnormals = device; //!< normal derivative array for each timestep
BufferView<char> flags; //!< start, end flag per segment
- vector<BufferView<char>> vertexAttribs; //!< user buffers
+ Device::vector<BufferView<char>> vertexAttribs = device; //!< user buffers
int tessellationRate; //!< tessellation rate for flat curve
float maxRadiusScale = 1.0; //!< maximal min-width scaling of curve radii
};
@@ -486,7 +554,7 @@ namespace embree
src = vertices[bufferSlot].getPtr();
stride = vertices[bufferSlot].getStride();
}
-
+
for (unsigned int i=0; i<valueCount; i+=N)
{
size_t ofs = i*sizeof(float);
diff --git a/thirdparty/embree/kernels/common/scene_grid_mesh.h b/thirdparty/embree/kernels/common/scene_grid_mesh.h
index fb6fed445b..eb2048b286 100644
--- a/thirdparty/embree/kernels/common/scene_grid_mesh.h
+++ b/thirdparty/embree/kernels/common/scene_grid_mesh.h
@@ -133,12 +133,26 @@ namespace embree
}
}
}
-
+
void addElementsToCount (GeometryCounts & counts) const;
- __forceinline unsigned int getNumSubGrids(const size_t gridID)
+ __forceinline unsigned int getNumTotalQuads() const
{
- const Grid &g = grid(gridID);
+ size_t quads = 0;
+ for (size_t primID=0; primID<numPrimitives; primID++)
+ quads += getNumQuads(primID);
+ return quads;
+ }
+
+ __forceinline unsigned int getNumQuads(const size_t gridID) const
+ {
+ const Grid& g = grid(gridID);
+ return (unsigned int) max((int)1,((int)g.resX-1) * ((int)g.resY-1));
+ }
+
+ __forceinline unsigned int getNumSubGrids(const size_t gridID) const
+ {
+ const Grid& g = grid(gridID);
return max((unsigned int)1,((unsigned int)g.resX >> 1) * ((unsigned int)g.resY >> 1));
}
@@ -174,6 +188,18 @@ namespace embree
return vertices[itime][i];
}
+ /*! returns i'th vertex of for specified time */
+ __forceinline const Vec3fa vertex(size_t i, float time) const
+ {
+ float ftime;
+ const size_t itime = timeSegment(time, ftime);
+ const float t0 = 1.0f - ftime;
+ const float t1 = ftime;
+ Vec3fa v0 = vertex(i, itime+0);
+ Vec3fa v1 = vertex(i, itime+1);
+ return madd(Vec3fa(t0),v0,t1*v1);
+ }
+
/*! returns i'th vertex of itime'th timestep */
__forceinline const char* vertexPtr(size_t i, size_t itime) const {
return vertices[itime].getPtr(i);
@@ -198,6 +224,56 @@ namespace embree
return vertex(index,itime);
}
+ /*! returns i'th vertex of the itime'th timestep */
+ __forceinline const Vec3fa grid_vertex(const Grid& g, size_t x, size_t y, float time) const {
+ const size_t index = grid_vertex_index(g,x,y);
+ return vertex(index,time);
+ }
+
+ /*! gathers quad vertices */
+ __forceinline void gather_quad_vertices(Vec3fa& v0, Vec3fa& v1, Vec3fa& v2, Vec3fa& v3, const Grid& g, size_t x, size_t y) const
+ {
+ v0 = grid_vertex(g,x+0,y+0);
+ v1 = grid_vertex(g,x+1,y+0);
+ v2 = grid_vertex(g,x+1,y+1);
+ v3 = grid_vertex(g,x+0,y+1);
+ }
+
+ /*! gathers quad vertices for specified time */
+ __forceinline void gather_quad_vertices(Vec3fa& v0, Vec3fa& v1, Vec3fa& v2, Vec3fa& v3, const Grid& g, size_t x, size_t y, float time) const
+ {
+ v0 = grid_vertex(g,x+0,y+0,time);
+ v1 = grid_vertex(g,x+1,y+0,time);
+ v2 = grid_vertex(g,x+1,y+1,time);
+ v3 = grid_vertex(g,x+0,y+1,time);
+ }
+
+ /*! gathers quad vertices for mblur and non-mblur meshes */
+ __forceinline void gather_quad_vertices_safe(Vec3fa& v0, Vec3fa& v1, Vec3fa& v2, Vec3fa& v3, const Grid& g, size_t x, size_t y, float time) const
+ {
+ if (hasMotionBlur()) gather_quad_vertices(v0,v1,v2,v3,g,x,y,time);
+ else gather_quad_vertices(v0,v1,v2,v3,g,x,y);
+ }
+
+ /*! calculates the build bounds of the i'th quad, if it's valid */
+ __forceinline bool buildBoundsQuad(const Grid& g, size_t sx, size_t sy, BBox3fa& bbox) const
+ {
+ BBox3fa b(empty);
+ for (size_t t=0; t<numTimeSteps; t++)
+ {
+ for (size_t y=sy;y<sy+2;y++)
+ for (size_t x=sx;x<sx+2;x++)
+ {
+ const Vec3fa v = grid_vertex(g,x,y,t);
+ if (unlikely(!isvalid(v))) return false;
+ b.extend(v);
+ }
+ }
+
+ bbox = b;
+ return true;
+ }
+
/*! calculates the build bounds of the i'th primitive, if it's valid */
__forceinline bool buildBounds(const Grid& g, size_t sx, size_t sy, BBox3fa& bbox) const
{
@@ -254,7 +330,6 @@ namespace embree
return true;
}
-
__forceinline BBox3fa bounds(const Grid& g, size_t sx, size_t sy, size_t itime) const
{
BBox3fa box(empty);
@@ -274,11 +349,22 @@ namespace embree
return LBBox3fa([&] (size_t itime) { return bounds(g,sx,sy,itime); }, dt, time_range, fnumTimeSegments);
}
+ __forceinline float projectedPrimitiveArea(const size_t i) const {
+ return pos_inf;
+ }
+
public:
BufferView<Grid> grids; //!< array of triangles
BufferView<Vec3fa> vertices0; //!< fast access to first vertex buffer
- vector<BufferView<Vec3fa>> vertices; //!< vertex array for each timestep
- vector<RawBufferView> vertexAttribs; //!< vertex attributes
+ Device::vector<BufferView<Vec3fa>> vertices = device; //!< vertex array for each timestep
+ Device::vector<RawBufferView> vertexAttribs = device; //!< vertex attributes
+
+#if defined(EMBREE_SYCL_SUPPORT)
+
+ public:
+ struct PrimID_XY { uint32_t primID; uint16_t x,y; };
+ Device::vector<PrimID_XY> quadID_to_primID_xy = device; //!< maps a quad to the primitive ID and grid coordinates
+#endif
};
namespace isa
@@ -287,6 +373,94 @@ namespace embree
{
GridMeshISA (Device* device)
: GridMesh(device) {}
+
+ LBBox3fa vlinearBounds(size_t buildID, const BBox1f& time_range, const SubGridBuildData * const sgrids) const override {
+ const SubGridBuildData &subgrid = sgrids[buildID];
+ const unsigned int primID = subgrid.primID;
+ const size_t x = subgrid.x();
+ const size_t y = subgrid.y();
+ return linearBounds(grid(primID),x,y,time_range);
+ }
+
+#if defined(EMBREE_SYCL_SUPPORT)
+ PrimInfo createPrimRefArray(PrimRef* prims, const range<size_t>& r, size_t k, unsigned int geomID) const override
+ {
+ PrimInfo pinfo(empty);
+ for (size_t j=r.begin(); j<r.end(); j++)
+ {
+ BBox3fa bounds = empty;
+ const PrimID_XY& quad = quadID_to_primID_xy[j];
+ if (!buildBoundsQuad(grids[quad.primID],quad.x,quad.y,bounds)) continue;
+ const PrimRef prim(bounds,geomID,unsigned(j));
+ pinfo.add_center2(prim);
+ prims[k++] = prim;
+ }
+ return pinfo;
+ }
+#endif
+
+ PrimInfo createPrimRefArray(mvector<PrimRef>& prims, mvector<SubGridBuildData>& sgrids, const range<size_t>& r, size_t k, unsigned int geomID) const override
+ {
+ PrimInfo pinfo(empty);
+ for (size_t j=r.begin(); j<r.end(); j++)
+ {
+ if (!valid(j)) continue;
+ const GridMesh::Grid &g = grid(j);
+
+ for (unsigned int y=0; y<g.resY-1u; y+=2)
+ {
+ for (unsigned int x=0; x<g.resX-1u; x+=2)
+ {
+ BBox3fa bounds = empty;
+ if (!buildBounds(g,x,y,bounds)) continue; // get bounds of subgrid
+ const PrimRef prim(bounds,(unsigned)geomID,(unsigned)k);
+ pinfo.add_center2(prim);
+ sgrids[k] = SubGridBuildData(x | g.get3x3FlagsX(x), y | g.get3x3FlagsY(y), unsigned(j));
+ prims[k++] = prim;
+ }
+ }
+ }
+ return pinfo;
+ }
+
+#if defined(EMBREE_SYCL_SUPPORT)
+ PrimInfo createPrimRefArrayMB(PrimRef* prims, const BBox1f& time_range, const range<size_t>& r, size_t k, unsigned int geomID) const override
+ {
+ const BBox1f t0t1 = BBox1f::intersect(getTimeRange(), time_range);
+ PrimInfo pinfo(empty);
+ for (size_t j=r.begin(); j<r.end(); j++)
+ {
+ const PrimID_XY& quad = quadID_to_primID_xy[j];
+ const LBBox3fa lbounds = linearBounds(grids[quad.primID],quad.x,quad.y,t0t1);
+ const PrimRef prim(lbounds.bounds(), unsigned(geomID), unsigned(j));
+ pinfo.add_center2(prim);
+ prims[k++] = prim;
+ }
+ return pinfo;
+ }
+#endif
+
+ PrimInfoMB createPrimRefMBArray(mvector<PrimRefMB>& prims, mvector<SubGridBuildData>& sgrids, const BBox1f& t0t1, const range<size_t>& r, size_t k, unsigned int geomID) const override
+ {
+ PrimInfoMB pinfoMB(empty);
+ for (size_t j=r.begin(); j<r.end(); j++)
+ {
+ if (!valid(j, timeSegmentRange(t0t1))) continue;
+ const GridMesh::Grid &g = grid(j);
+
+ for (unsigned int y=0; y<g.resY-1u; y+=2)
+ {
+ for (unsigned int x=0; x<g.resX-1u; x+=2)
+ {
+ const PrimRefMB prim(linearBounds(g,x,y,t0t1),numTimeSegments(),time_range,numTimeSegments(),unsigned(geomID),unsigned(k));
+ pinfoMB.add_primref(prim);
+ sgrids[k] = SubGridBuildData(x | g.get3x3FlagsX(x), y | g.get3x3FlagsY(y), unsigned(j));
+ prims[k++] = prim;
+ }
+ }
+ }
+ return pinfoMB;
+ }
};
}
diff --git a/thirdparty/embree/kernels/common/scene_instance.h b/thirdparty/embree/kernels/common/scene_instance.h
index 773f2b6fec..1176018777 100644
--- a/thirdparty/embree/kernels/common/scene_instance.h
+++ b/thirdparty/embree/kernels/common/scene_instance.h
@@ -13,7 +13,7 @@ namespace embree
/*! Instanced acceleration structure */
struct Instance : public Geometry
{
- ALIGNED_STRUCT_(16);
+ //ALIGNED_STRUCT_(16);
static const Geometry::GTypeMask geom_type = Geometry::MTY_INSTANCE;
public:
@@ -50,6 +50,7 @@ namespace embree
virtual void setTransform(const AffineSpace3fa& local2world, unsigned int timeStep) override;
virtual void setQuaternionDecomposition(const AffineSpace3ff& qd, unsigned int timeStep) override;
virtual AffineSpace3fa getTransform(float time) override;
+ virtual AffineSpace3fa getTransform(size_t, float time) override;
virtual void setMask (unsigned mask) override;
virtual void build() {}
virtual void addElementsToCount (GeometryCounts & counts) const override;
@@ -132,10 +133,13 @@ namespace embree
__forceinline AffineSpace3fa getLocal2World(float t) const
{
- float ftime; const unsigned int itime = timeSegment(t, ftime);
- if (unlikely(gsubtype == GTY_SUBTYPE_INSTANCE_QUATERNION))
- return slerp(local2world[itime+0],local2world[itime+1],ftime);
- return lerp(local2world[itime+0],local2world[itime+1],ftime);
+ if (numTimeSegments() > 0) {
+ float ftime; const unsigned int itime = timeSegment(t, ftime);
+ if (unlikely(gsubtype == GTY_SUBTYPE_INSTANCE_QUATERNION))
+ return slerp(local2world[itime+0],local2world[itime+1],ftime);
+ return lerp(local2world[itime+0],local2world[itime+1],ftime);
+ }
+ return getLocal2World();
}
__forceinline AffineSpace3fa getWorld2Local() const {
@@ -143,7 +147,9 @@ namespace embree
}
__forceinline AffineSpace3fa getWorld2Local(float t) const {
- return rcp(getLocal2World(t));
+ if (numTimeSegments() > 0)
+ return rcp(getLocal2World(t));
+ return getWorld2Local();
}
template<int K>
@@ -154,6 +160,10 @@ namespace embree
return getWorld2LocalLerp<K>(valid, t);
}
+ __forceinline float projectedPrimitiveArea(const size_t i) const {
+ return area(bounds(i));
+ }
+
private:
template<int K>
@@ -220,7 +230,11 @@ namespace embree
InstanceISA (Device* device)
: Instance(device) {}
- PrimInfo createPrimRefArray(mvector<PrimRef>& prims, const range<size_t>& r, size_t k, unsigned int geomID) const
+ LBBox3fa vlinearBounds(size_t primID, const BBox1f& time_range) const {
+ return linearBounds(primID,time_range);
+ }
+
+ PrimInfo createPrimRefArray(PrimRef* prims, const range<size_t>& r, size_t k, unsigned int geomID) const
{
assert(r.begin() == 0);
assert(r.end() == 1);
@@ -252,7 +266,23 @@ namespace embree
prims[k++] = prim;
return pinfo;
}
-
+
+ PrimInfo createPrimRefArrayMB(PrimRef* prims, const BBox1f& time_range, const range<size_t>& r, size_t k, unsigned int geomID) const
+ {
+ assert(r.begin() == 0);
+ assert(r.end() == 1);
+
+ PrimInfo pinfo(empty);
+ const BBox1f t0t1 = intersect(getTimeRange(), time_range);
+ if (t0t1.empty()) return pinfo;
+
+ const BBox3fa bounds = linearBounds(0, t0t1).bounds();
+ const PrimRef prim(bounds, geomID, unsigned(0));
+ pinfo.add_center2(prim);
+ prims[k++] = prim;
+ return pinfo;
+ }
+
PrimInfoMB createPrimRefMBArray(mvector<PrimRefMB>& prims, const BBox1f& t0t1, const range<size_t>& r, size_t k, unsigned int geomID) const
{
assert(r.begin() == 0);
diff --git a/thirdparty/embree/kernels/common/scene_instance_array.h b/thirdparty/embree/kernels/common/scene_instance_array.h
new file mode 100644
index 0000000000..3cf4d68feb
--- /dev/null
+++ b/thirdparty/embree/kernels/common/scene_instance_array.h
@@ -0,0 +1,385 @@
+// Copyright 2009-2021 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+
+#pragma once
+
+#include "geometry.h"
+#include "accel.h"
+
+namespace embree
+{
+ struct MotionDerivativeCoefficients;
+
+ /*! Instanced acceleration structure */
+ struct InstanceArray : public Geometry
+ {
+ //ALIGNED_STRUCT_(16);
+ static const Geometry::GTypeMask geom_type = Geometry::MTY_INSTANCE_ARRAY;
+
+ public:
+ InstanceArray (Device* device, unsigned int numTimeSteps = 1);
+ ~InstanceArray();
+
+ private:
+ InstanceArray (const InstanceArray& other) DELETED; // do not implement
+ InstanceArray& operator= (const InstanceArray& other) DELETED; // do not implement
+
+ private:
+ LBBox3fa nonlinearBounds(size_t i,
+ const BBox1f& time_range_in,
+ const BBox1f& geom_time_range,
+ float geom_time_segments) const;
+
+ BBox3fa boundSegment(size_t i, size_t itime,
+ BBox3fa const& obbox0, BBox3fa const& obbox1,
+ BBox3fa const& bbox0, BBox3fa const& bbox1,
+ float t_min, float t_max) const;
+
+ /* calculates the (correct) interpolated bounds */
+ __forceinline BBox3fa bounds(size_t i, size_t itime0, size_t itime1, float f) const
+ {
+ if (unlikely(gsubtype == GTY_SUBTYPE_INSTANCE_QUATERNION))
+ return xfmBounds(slerp(l2w(i, itime0), l2w(i, itime1), f),
+ lerp(getObjectBounds(i, itime0), getObjectBounds(i, itime1), f));
+ return xfmBounds(lerp(l2w(i, itime0), l2w(i, itime1), f),
+ lerp(getObjectBounds(i, itime0), getObjectBounds(i, itime1), f));
+ }
+
+ public:
+
+ virtual void setBuffer(RTCBufferType type, unsigned int slot, RTCFormat format, const Ref<Buffer>& buffer, size_t offset, size_t stride, unsigned int num) override;
+ virtual void* getBuffer(RTCBufferType type, unsigned int slot) override;
+ virtual void updateBuffer(RTCBufferType type, unsigned int slot) override;
+
+ virtual void setNumTimeSteps (unsigned int numTimeSteps) override;
+ virtual void setInstancedScene(const Ref<Scene>& scene) override;
+ virtual void setInstancedScenes(const RTCScene* scenes, size_t numScenes) override;
+ virtual AffineSpace3fa getTransform(size_t, float time) override;
+ virtual void setMask (unsigned mask) override;
+ virtual void build() {}
+ virtual void addElementsToCount (GeometryCounts & counts) const override;
+ virtual void commit() override;
+
+ public:
+
+ /*! calculates the bounds of instance */
+ __forceinline BBox3fa bounds(size_t i) const {
+ if (!valid(i))
+ return BBox3fa();
+
+ if (unlikely(gsubtype == GTY_SUBTYPE_INSTANCE_QUATERNION))
+ return xfmBounds(quaternionDecompositionToAffineSpace(l2w(i, 0)),getObject(i)->bounds.bounds());
+ return xfmBounds(l2w(i, 0),getObject(i)->bounds.bounds());
+ }
+
+ /*! gets the bounds of the instanced scene */
+ __forceinline BBox3fa getObjectBounds(size_t i, size_t itime) const {
+ if (!valid(i))
+ return BBox3fa();
+
+ return getObject(i)->getBounds(timeStep(itime));
+ }
+
+ /*! calculates the bounds of instance */
+ __forceinline BBox3fa bounds(size_t i, size_t itime) const {
+ if (!valid(i))
+ return BBox3fa();
+
+ if (unlikely(gsubtype == GTY_SUBTYPE_INSTANCE_QUATERNION))
+ return xfmBounds(quaternionDecompositionToAffineSpace(l2w(i, itime)),getObjectBounds(i, itime));
+ return xfmBounds(l2w(i, itime),getObjectBounds(i, itime));
+ }
+
+ /*! calculates the linear bounds of the i'th primitive for the specified time range */
+ __forceinline LBBox3fa linearBounds(size_t i, const BBox1f& dt) const {
+ if (!valid(i))
+ return LBBox3fa();
+
+ LBBox3fa lbbox = nonlinearBounds(i, dt, time_range, fnumTimeSegments);
+ return lbbox;
+ }
+
+ /*! calculates the build bounds of the i'th item, if it's valid */
+ __forceinline bool buildBounds(size_t i, BBox3fa* bbox = nullptr) const
+ {
+ if (!valid(i))
+ return false;
+
+ const BBox3fa b = bounds(i);
+ if (bbox) *bbox = b;
+ return isvalid(b);
+ }
+
+ /*! calculates the build bounds of the i'th item at the itime'th time segment, if it's valid */
+ __forceinline bool buildBounds(size_t i, size_t itime, BBox3fa& bbox) const
+ {
+ if (!valid(i))
+ return false;
+
+ const LBBox3fa bounds = linearBounds(i,itime);
+ bbox = bounds.bounds ();
+ return isvalid(bounds);
+ }
+
+ /* gets version info of topology */
+ unsigned int getTopologyVersion() const {
+ return numPrimitives;
+ }
+
+ /* returns true if topology changed */
+ bool topologyChanged(unsigned int otherVersion) const {
+ return numPrimitives != otherVersion;
+ }
+
+ /*! check if the i'th primitive is valid between the specified time range */
+ __forceinline bool valid(size_t i) const
+ {
+ if (object) return true;
+ return (object_ids[i] != (unsigned int)(-1));
+ }
+
+ /*! check if the i'th primitive is valid between the specified time range */
+ __forceinline bool valid(size_t i, const range<size_t>& itime_range) const
+ {
+ for (size_t itime = itime_range.begin(); itime <= itime_range.end(); itime++)
+ if (!isvalid(bounds(i,itime))) return false;
+
+ return true;
+ }
+
+ __forceinline AffineSpace3fa getLocal2World(size_t i) const
+ {
+ if (unlikely(gsubtype == GTY_SUBTYPE_INSTANCE_QUATERNION))
+ return quaternionDecompositionToAffineSpace(l2w(i,0));
+ return l2w(i, 0);
+ }
+
+ __forceinline AffineSpace3fa getLocal2World(size_t i, float t) const
+ {
+ if (numTimeSegments() > 0) {
+ float ftime; const unsigned int itime = timeSegment(t, ftime);
+ if (unlikely(gsubtype == GTY_SUBTYPE_INSTANCE_QUATERNION))
+ return slerp(l2w(i, itime+0),l2w(i, itime+1),ftime);
+ return lerp(l2w(i, itime+0),l2w(i, itime+1),ftime);
+ }
+ return getLocal2World(i);
+ }
+
+ __forceinline AffineSpace3fa getWorld2Local(size_t i) const {
+ return rcp(getLocal2World(i));
+ }
+
+ __forceinline AffineSpace3fa getWorld2Local(size_t i, float t) const {
+ return rcp(getLocal2World(i, t));
+ }
+
+ template<int K>
+ __forceinline AffineSpace3vf<K> getWorld2Local(size_t i, const vbool<K>& valid, const vfloat<K>& t) const
+ {
+ if (unlikely(gsubtype == GTY_SUBTYPE_INSTANCE_QUATERNION))
+ return getWorld2LocalSlerp<K>(i, valid, t);
+ return getWorld2LocalLerp<K>(i, valid, t);
+ }
+
+ __forceinline float projectedPrimitiveArea(const size_t i) const {
+ return area(bounds(i));
+ }
+
+ inline Accel* getObject(size_t i) const {
+ if (object) {
+ return object;
+ }
+
+ assert(objects);
+ assert(i < numPrimitives);
+ if (object_ids[i] == (unsigned int)(-1))
+ return nullptr;
+
+ assert(object_ids[i] < numObjects);
+ return objects[object_ids[i]];
+ }
+
+ private:
+
+ template<int K>
+ __forceinline AffineSpace3vf<K> getWorld2LocalSlerp(size_t i, const vbool<K>& valid, const vfloat<K>& t) const
+ {
+ vfloat<K> ftime;
+ const vint<K> itime_k = timeSegment<K>(t, ftime);
+ assert(any(valid));
+ const size_t index = bsf(movemask(valid));
+ const int itime = itime_k[index];
+ if (likely(all(valid, itime_k == vint<K>(itime)))) {
+ return rcp(slerp(AffineSpace3vff<K>(l2w(i, itime+0)),
+ AffineSpace3vff<K>(l2w(i, itime+1)),
+ ftime));
+ }
+ else {
+ AffineSpace3vff<K> space0,space1;
+ vbool<K> valid1 = valid;
+ while (any(valid1)) {
+ vbool<K> valid2;
+ const int itime = next_unique(valid1, itime_k, valid2);
+ space0 = select(valid2, AffineSpace3vff<K>(l2w(i, itime+0)), space0);
+ space1 = select(valid2, AffineSpace3vff<K>(l2w(i, itime+1)), space1);
+ }
+ return rcp(slerp(space0, space1, ftime));
+ }
+ }
+
+ template<int K>
+ __forceinline AffineSpace3vf<K> getWorld2LocalLerp(size_t i, const vbool<K>& valid, const vfloat<K>& t) const
+ {
+ vfloat<K> ftime;
+ const vint<K> itime_k = timeSegment<K>(t, ftime);
+ assert(any(valid));
+ const size_t index = bsf(movemask(valid));
+ const int itime = itime_k[index];
+ if (likely(all(valid, itime_k == vint<K>(itime)))) {
+ return rcp(lerp(AffineSpace3vf<K>((AffineSpace3fa)l2w(i, itime+0)),
+ AffineSpace3vf<K>((AffineSpace3fa)l2w(i, itime+1)),
+ ftime));
+ } else {
+ AffineSpace3vf<K> space0,space1;
+ vbool<K> valid1 = valid;
+ while (any(valid1)) {
+ vbool<K> valid2;
+ const int itime = next_unique(valid1, itime_k, valid2);
+ space0 = select(valid2, AffineSpace3vf<K>((AffineSpace3fa)l2w(i, itime+0)), space0);
+ space1 = select(valid2, AffineSpace3vf<K>((AffineSpace3fa)l2w(i, itime+1)), space1);
+ }
+ return rcp(lerp(space0, space1, ftime));
+ }
+ }
+
+ private:
+
+ __forceinline AffineSpace3ff l2w(size_t i, size_t itime) const {
+ if (l2w_buf[itime].getFormat() == RTC_FORMAT_FLOAT4X4_COLUMN_MAJOR) {
+ return *(AffineSpace3ff*)(l2w_buf[itime].getPtr(i));
+ }
+ else if(l2w_buf[itime].getFormat() == RTC_FORMAT_QUATERNION_DECOMPOSITION) {
+ AffineSpace3ff transform;
+ QuaternionDecomposition* qd = (QuaternionDecomposition*)l2w_buf[itime].getPtr(i);
+ transform.l.vx.x = qd->scale_x;
+ transform.l.vy.y = qd->scale_y;
+ transform.l.vz.z = qd->scale_z;
+ transform.l.vy.x = qd->skew_xy;
+ transform.l.vz.x = qd->skew_xz;
+ transform.l.vz.y = qd->skew_yz;
+ transform.l.vx.y = qd->translation_x;
+ transform.l.vx.z = qd->translation_y;
+ transform.l.vy.z = qd->translation_z;
+ transform.p.x = qd->shift_x;
+ transform.p.y = qd->shift_y;
+ transform.p.z = qd->shift_z;
+ // normalize quaternion
+ Quaternion3f q(qd->quaternion_r, qd->quaternion_i, qd->quaternion_j, qd->quaternion_k);
+ q = normalize(q);
+ transform.l.vx.w = q.i;
+ transform.l.vy.w = q.j;
+ transform.l.vz.w = q.k;
+ transform.p.w = q.r;
+ return transform;
+ }
+ else if (l2w_buf[itime].getFormat() == RTC_FORMAT_FLOAT3X4_COLUMN_MAJOR) {
+ AffineSpace3f* l2w = reinterpret_cast<AffineSpace3f*>(l2w_buf[itime].getPtr(i));
+ return AffineSpace3ff(*l2w);
+ }
+ else if (l2w_buf[itime].getFormat() == RTC_FORMAT_FLOAT3X4_ROW_MAJOR) {
+ float* data = reinterpret_cast<float*>(l2w_buf[itime].getPtr(i));
+ AffineSpace3f l2w;
+ l2w.l.vx.x = data[0]; l2w.l.vy.x = data[1]; l2w.l.vz.x = data[2]; l2w.p.x = data[3];
+ l2w.l.vx.y = data[4]; l2w.l.vy.y = data[5]; l2w.l.vz.y = data[6]; l2w.p.y = data[7];
+ l2w.l.vx.z = data[8]; l2w.l.vy.z = data[9]; l2w.l.vz.z = data[10]; l2w.p.z = data[11];
+ return l2w;
+ }
+ assert(false);
+ return AffineSpace3ff();
+ }
+
+ inline AffineSpace3ff l2w(size_t i) const {
+ return l2w(i, 0);
+ }
+
+ private:
+ Accel* object; //!< fast path if only one scene is instanced
+ Accel** objects;
+ uint32_t numObjects;
+ Device::vector<RawBufferView> l2w_buf = device; //!< transformation from local space to world space for each timestep (either normal matrix or quaternion decomposition)
+ BufferView<uint32_t> object_ids; //!< array of scene ids per instance array primitive
+ };
+
+ namespace isa
+ {
+ struct InstanceArrayISA : public InstanceArray
+ {
+ InstanceArrayISA (Device* device)
+ : InstanceArray(device) {}
+
+ LBBox3fa vlinearBounds(size_t primID, const BBox1f& time_range) const {
+ return linearBounds(primID,time_range);
+ }
+
+ PrimInfo createPrimRefArray(PrimRef* prims, const range<size_t>& r, size_t k, unsigned int geomID) const
+ {
+ PrimInfo pinfo(empty);
+ for (size_t j = r.begin(); j < r.end(); j++) {
+ BBox3fa bounds = empty;
+ if (!buildBounds(j, &bounds) || !valid(j))
+ continue;
+ const PrimRef prim(bounds, geomID, unsigned(j));
+ pinfo.add_center2(prim);
+ prims[k++] = prim;
+ }
+ return pinfo;
+ }
+
+ PrimInfo createPrimRefArrayMB(mvector<PrimRef>& prims, size_t itime, const range<size_t>& r, size_t k, unsigned int geomID) const
+ {
+ PrimInfo pinfo(empty);
+ for (size_t j = r.begin(); j < r.end(); j++) {
+ BBox3fa bounds = empty;
+ if (!buildBounds(j, itime, bounds))
+ continue;
+ const PrimRef prim(bounds, geomID, unsigned(j));
+ pinfo.add_center2(prim);
+ prims[k++] = prim;
+ }
+ return pinfo;
+ }
+
+ PrimInfo createPrimRefArrayMB(PrimRef* prims, const BBox1f& time_range, const range<size_t>& r, size_t k, unsigned int geomID) const
+ {
+ PrimInfo pinfo(empty);
+ const BBox1f t0t1 = BBox1f::intersect(getTimeRange(), time_range);
+ if (t0t1.empty()) return pinfo;
+
+ for (size_t j = r.begin(); j < r.end(); j++) {
+ LBBox3fa lbounds = linearBounds(j, t0t1);
+ if (!isvalid(lbounds.bounds()))
+ continue;
+ const PrimRef prim(lbounds.bounds(), geomID, unsigned(j));
+ pinfo.add_center2(prim);
+ prims[k++] = prim;
+ }
+ return pinfo;
+ }
+
+ PrimInfoMB createPrimRefMBArray(mvector<PrimRefMB>& prims, const BBox1f& t0t1, const range<size_t>& r, size_t k, unsigned int geomID) const
+ {
+ PrimInfoMB pinfo(empty);
+ for (size_t j = r.begin(); j < r.end(); j++) {
+ if (!valid(j, timeSegmentRange(t0t1)))
+ continue;
+ const PrimRefMB prim(linearBounds(j, t0t1), this->numTimeSegments(), this->time_range, this->numTimeSegments(), geomID, unsigned(j));
+ pinfo.add_primref(prim);
+ prims[k++] = prim;
+ }
+ return pinfo;
+ }
+ };
+ }
+
+ DECLARE_ISA_FUNCTION(InstanceArray*, createInstanceArray, Device*);
+}
diff --git a/thirdparty/embree/kernels/common/scene_line_segments.h b/thirdparty/embree/kernels/common/scene_line_segments.h
index 3c9fdb39db..e58fd1b7eb 100644
--- a/thirdparty/embree/kernels/common/scene_line_segments.h
+++ b/thirdparty/embree/kernels/common/scene_line_segments.h
@@ -84,6 +84,14 @@ namespace embree
return segments[i];
}
+#if defined(EMBREE_SYCL_SUPPORT) && defined(__SYCL_DEVICE_ONLY__)
+ /*! returns the i'th segment */
+ template<int M>
+ __forceinline const vuint<M> vsegment(const vuint<M>& i) const {
+ return segments[i.v];
+ }
+#endif
+
/*! returns the segment to the left of the i'th segment */
__forceinline bool segmentLeftExists(size_t i) const {
assert (flags);
@@ -136,6 +144,219 @@ namespace embree
return vertices[itime][i].w;
}
+ /*! gathers the curve starting with i'th vertex */
+ __forceinline void gather(Vec3ff& p0, Vec3ff& p1, unsigned int vid) const
+ {
+ p0 = vertex(vid+0);
+ p1 = vertex(vid+1);
+ }
+
+#if defined(EMBREE_SYCL_SUPPORT) && defined(__SYCL_DEVICE_ONLY__)
+ template<int M>
+ __forceinline void vgather(Vec4vf<M>& p0, Vec4vf<M>& p1, const vuint<M>& vid) const
+ {
+ p0 = vertex(vid.v+0);
+ p1 = vertex(vid.v+1);
+ }
+#endif
+
+ /*! gathers the curve starting with i'th vertex of itime'th timestep */
+ __forceinline void gather(Vec3ff& p0, Vec3ff& p1, unsigned int vid, size_t itime) const
+ {
+ p0 = vertex(vid+0,itime);
+ p1 = vertex(vid+1,itime);
+ }
+
+#if defined(EMBREE_SYCL_SUPPORT) && defined(__SYCL_DEVICE_ONLY__)
+ template<int M>
+ __forceinline void vgather(Vec4vf<M>& p0, Vec4vf<M>& p1, const vuint<M>& vid, const vint<M>& itime) const
+ {
+ p0 = vertex(vid.v+0,itime.v);
+ p1 = vertex(vid.v+1,itime.v);
+ }
+#endif
+
+ /*! loads curve vertices for specified time */
+ __forceinline void gather(Vec3ff& p0, Vec3ff& p1, unsigned int vid, float time) const
+ {
+ float ftime;
+ const size_t itime = timeSegment(time, ftime);
+
+ const float t0 = 1.0f - ftime;
+ const float t1 = ftime;
+ Vec3ff a0,a1; gather(a0,a1,vid,itime);
+ Vec3ff b0,b1; gather(b0,b1,vid,itime+1);
+ p0 = madd(Vec3ff(t0),a0,t1*b0);
+ p1 = madd(Vec3ff(t0),a1,t1*b1);
+ }
+
+ /*! loads curve vertices for specified time for mblur and non-mblur case */
+ __forceinline void gather_safe(Vec3ff& p0, Vec3ff& p1, unsigned int vid, float time) const
+ {
+ if (hasMotionBlur()) gather(p0,p1,vid,time);
+ else gather(p0,p1,vid);
+ }
+
+#if defined(EMBREE_SYCL_SUPPORT) && defined(__SYCL_DEVICE_ONLY__)
+ template<int M>
+ __forceinline void vgather(Vec4vf<M>& p0, Vec4vf<M>& p1, const vuint<M>& vid, const vfloat<M>& time) const
+ {
+ vfloat<M> ftime;
+ const vint<M> itime = timeSegment<M>(time, ftime);
+
+ const vfloat<M> t0 = 1.0f - ftime;
+ const vfloat<M> t1 = ftime;
+ Vec4vf<M> a0,a1; vgather<M>(a0,a1,vid,itime);
+ Vec4vf<M> b0,b1; vgather<M>(b0,b1,vid,itime+1);
+ p0 = madd(Vec4vf<M>(t0),a0,t1*b0);
+ p1 = madd(Vec4vf<M>(t0),a1,t1*b1);
+ }
+#endif
+
+ /*! gathers the cone curve starting with i'th vertex */
+ __forceinline void gather(Vec3ff& p0, Vec3ff& p1, bool& cL, bool& cR, unsigned int primID, unsigned int vid) const
+ {
+ gather(p0,p1,vid);
+ cL = !segmentLeftExists (primID);
+ cR = !segmentRightExists(primID);
+ }
+
+#if defined(EMBREE_SYCL_SUPPORT) && defined(__SYCL_DEVICE_ONLY__)
+ template<int M>
+ __forceinline void vgather(Vec4vf<M>& p0, Vec4vf<M>& p1, vbool<M>& cL, vbool<M>& cR, const vuint<M>& primID, const vuint<M>& vid) const
+ {
+ vgather<M>(p0,p1,vid);
+ cL = !segmentLeftExists (primID.v);
+ cR = !segmentRightExists(primID.v);
+ }
+#endif
+
+ /*! gathers the cone curve starting with i'th vertex of itime'th timestep */
+ __forceinline void gather(Vec3ff& p0, Vec3ff& p1, bool& cL, bool& cR, unsigned int primID, size_t vid, size_t itime) const
+ {
+ gather(p0,p1,vid,itime);
+ cL = !segmentLeftExists (primID);
+ cR = !segmentRightExists(primID);
+ }
+
+ /*! loads cone curve vertices for specified time */
+ __forceinline void gather(Vec3ff& p0, Vec3ff& p1, bool& cL, bool& cR, unsigned int primID, size_t vid, float time) const
+ {
+ gather(p0,p1,vid,time);
+ cL = !segmentLeftExists (primID);
+ cR = !segmentRightExists(primID);
+ }
+
+ /*! loads cone curve vertices for specified time for mblur and non-mblur geometry */
+ __forceinline void gather_safe(Vec3ff& p0, Vec3ff& p1, bool& cL, bool& cR, unsigned int primID, size_t vid, float time) const
+ {
+ if (hasMotionBlur()) gather(p0,p1,cL,cR,primID,vid,time);
+ else gather(p0,p1,cL,cR,primID,vid);
+ }
+
+#if defined(EMBREE_SYCL_SUPPORT) && defined(__SYCL_DEVICE_ONLY__)
+ template<int M>
+ __forceinline void vgather(Vec4vf<M>& p0, Vec4vf<M>& p1, vbool<M>& cL, vbool<M>& cR, const vuint<M>& primID, const vuint<M>& vid, const vfloat<M>& time) const
+ {
+ vgather<M>(p0,p1,vid,time);
+ cL = !segmentLeftExists (primID.v);
+ cR = !segmentRightExists(primID.v);
+ }
+#endif
+
+ /*! gathers the curve starting with i'th vertex */
+ __forceinline void gather(Vec3ff& p0, Vec3ff& p1, Vec3ff& p2, Vec3ff& p3, unsigned int primID, size_t vid) const
+ {
+ p0 = vertex(vid+0);
+ p1 = vertex(vid+1);
+ p2 = segmentLeftExists (primID) ? vertex(vid-1) : Vec3ff(inf);
+ p3 = segmentRightExists(primID) ? vertex(vid+2) : Vec3ff(inf);
+ }
+
+#if defined(EMBREE_SYCL_SUPPORT) && defined(__SYCL_DEVICE_ONLY__)
+ template<int M>
+ __forceinline void vgather(Vec4vf<M>& p0, Vec4vf<M>& p1, Vec4vf<M>& p2, Vec4vf<M>& p3, const vuint<M>& primID, const vuint<M>& vid) const
+ {
+ p0 = vertex(vid.v+0);
+ p1 = vertex(vid.v+1);
+ vbool<M> left = segmentLeftExists (primID.v);
+ vbool<M> right = segmentRightExists(primID.v);
+ vuint<M> i2 = select(left, vid-1,vid+0);
+ vuint<M> i3 = select(right,vid+2,vid+1);
+ p2 = vertex(i2.v);
+ p3 = vertex(i3.v);
+ p2 = select(left, p2,Vec4vf<M>(inf));
+ p3 = select(right,p3,Vec4vf<M>(inf));
+ }
+#endif
+
+ /*! gathers the curve starting with i'th vertex of itime'th timestep */
+ __forceinline void gather(Vec3ff& p0, Vec3ff& p1, Vec3ff& p2, Vec3ff& p3, unsigned int primID, size_t vid, size_t itime) const
+ {
+ p0 = vertex(vid+0,itime);
+ p1 = vertex(vid+1,itime);
+ p2 = segmentLeftExists (primID) ? vertex(vid-1,itime) : Vec3ff(inf);
+ p3 = segmentRightExists(primID) ? vertex(vid+2,itime) : Vec3ff(inf);
+ }
+
+#if defined(EMBREE_SYCL_SUPPORT) && defined(__SYCL_DEVICE_ONLY__)
+ template<int M>
+ __forceinline void vgather(Vec4vf<M>& p0, Vec4vf<M>& p1, Vec4vf<M>& p2, Vec4vf<M>& p3, const vuint<M>& primID, const vuint<M>& vid, const vint<M>& itime) const
+ {
+ p0 = vertex(vid.v+0, itime.v);
+ p1 = vertex(vid.v+1, itime.v);
+ vbool<M> left = segmentLeftExists (primID.v);
+ vbool<M> right = segmentRightExists(primID.v);
+ vuint<M> i2 = select(left, vid-1,vid+0);
+ vuint<M> i3 = select(right,vid+2,vid+1);
+ p2 = vertex(i2.v, itime.v);
+ p3 = vertex(i3.v, itime.v);
+ p2 = select(left, p2,Vec4vf<M>(inf));
+ p3 = select(right,p3,Vec4vf<M>(inf));
+ }
+#endif
+
+ /*! loads curve vertices for specified time */
+ __forceinline void gather(Vec3ff& p0, Vec3ff& p1, Vec3ff& p2, Vec3ff& p3, unsigned int primID, size_t vid, float time) const
+ {
+ float ftime;
+ const size_t itime = timeSegment(time, ftime);
+
+ const float t0 = 1.0f - ftime;
+ const float t1 = ftime;
+ Vec3ff a0,a1,a2,a3; gather(a0,a1,a2,a3,primID,vid,itime);
+ Vec3ff b0,b1,b2,b3; gather(b0,b1,b2,b3,primID,vid,itime+1);
+ p0 = madd(Vec3ff(t0),a0,t1*b0);
+ p1 = madd(Vec3ff(t0),a1,t1*b1);
+ p2 = madd(Vec3ff(t0),a2,t1*b2);
+ p3 = madd(Vec3ff(t0),a3,t1*b3);
+ }
+
+ /*! loads curve vertices for specified time for mblur and non-mblur geometry */
+ __forceinline void gather_safe(Vec3ff& p0, Vec3ff& p1, Vec3ff& p2, Vec3ff& p3, unsigned int primID, size_t vid, float time) const
+ {
+ if (hasMotionBlur()) gather(p0,p1,p2,p3,primID,vid,time);
+ else gather(p0,p1,p2,p3,primID,vid);
+ }
+
+#if defined(EMBREE_SYCL_SUPPORT) && defined(__SYCL_DEVICE_ONLY__)
+ template<int M>
+ __forceinline void vgather(Vec4vf<M>& p0, Vec4vf<M>& p1, Vec4vf<M>& p2, Vec4vf<M>& p3, const vuint<M>& primID, const vuint<M>& vid, const vfloat<M>& time) const
+ {
+ vfloat<M> ftime;
+ const vint<M> itime = timeSegment<M>(time, ftime);
+
+ const vfloat<M> t0 = 1.0f - ftime;
+ const vfloat<M> t1 = ftime;
+ Vec4vf<M> a0,a1,a2,a3; vgather<M>(a0,a1,a2,a3,primID,vid,itime);
+ Vec4vf<M> b0,b1,b2,b3; vgather<M>(b0,b1,b2,b3,primID,vid,itime+1);
+ p0 = madd(Vec4vf<M>(t0),a0,t1*b0);
+ p1 = madd(Vec4vf<M>(t0),a1,t1*b1);
+ p2 = madd(Vec4vf<M>(t0),a2,t1*b2);
+ p3 = madd(Vec4vf<M>(t0),a3,t1*b3);
+ }
+#endif
+
/*! calculates bounding box of i'th line segment */
__forceinline BBox3fa bounds(const Vec3ff& v0, const Vec3ff& v1) const
{
@@ -183,6 +404,18 @@ namespace embree
return bounds(w0,w1);
}
+ /*! calculates bounding box of i'th segment */
+ __forceinline BBox3fa bounds(const Vec3fa& ofs, const float scale, const float r_scale0, const LinearSpace3fa& space, size_t i, size_t itime = 0) const
+ {
+ const float r_scale = r_scale0*scale;
+ const unsigned int index = segment(i);
+ const Vec3ff v0 = vertex(index+0,itime);
+ const Vec3ff v1 = vertex(index+1,itime);
+ const Vec3ff w0(xfmVector(space,(v0-ofs)*Vec3fa(scale)),maxRadiusScale*v0.w*r_scale);
+ const Vec3ff w1(xfmVector(space,(v1-ofs)*Vec3fa(scale)),maxRadiusScale*v1.w*r_scale);
+ return bounds(w0,w1);
+ }
+
/*! check if the i'th primitive is valid at the itime'th timestep */
__forceinline bool valid(size_t i, size_t itime) const {
return valid(i, make_range(itime, itime));
@@ -193,13 +426,17 @@ namespace embree
{
const unsigned int index = segment(i);
if (index+1 >= numVertices()) return false;
-
+
+#if !defined(__SYCL_DEVICE_ONLY__)
+
for (size_t itime = itime_range.begin(); itime <= itime_range.end(); itime++)
{
const Vec3ff v0 = vertex(index+0,itime); if (unlikely(!isvalid4(v0))) return false;
const Vec3ff v1 = vertex(index+1,itime); if (unlikely(!isvalid4(v1))) return false;
if (min(v0.w,v1.w) < 0.0f) return false;
}
+#endif
+
return true;
}
@@ -235,6 +472,11 @@ namespace embree
}
/*! calculates the linear bounds of the i'th primitive for the specified time range */
+ __forceinline LBBox3fa linearBounds(const Vec3fa& ofs, const float scale, const float r_scale0, const LinearSpace3fa& space, size_t primID, const BBox1f& dt) const {
+ return LBBox3fa([&] (size_t itime) { return bounds(ofs, scale, r_scale0, space, primID, itime); }, dt, this->time_range, fnumTimeSegments);
+ }
+
+ /*! calculates the linear bounds of the i'th primitive for the specified time range */
__forceinline bool linearBounds(size_t i, const BBox1f& time_range, LBBox3fa& bbox) const
{
if (!valid(i, timeSegmentRange(time_range))) return false;
@@ -252,9 +494,9 @@ namespace embree
BufferView<Vec3ff> vertices0; //!< fast access to first vertex buffer
BufferView<Vec3fa> normals0; //!< fast access to first normal buffer
BufferView<char> flags; //!< start, end flag per segment
- vector<BufferView<Vec3ff>> vertices; //!< vertex array for each timestep
- vector<BufferView<Vec3fa>> normals; //!< normal array for each timestep
- vector<BufferView<char>> vertexAttribs; //!< user buffers
+ Device::vector<BufferView<Vec3ff>> vertices = device; //!< vertex array for each timestep
+ Device::vector<BufferView<Vec3fa>> normals = device; //!< normal array for each timestep
+ Device::vector<BufferView<char>> vertexAttribs = device; //!< user buffers
int tessellationRate; //!< tessellation rate for bezier curve
float maxRadiusScale = 1.0; //!< maximal min-width scaling of curve radii
};
@@ -266,6 +508,28 @@ namespace embree
LineSegmentsISA (Device* device, Geometry::GType gtype)
: LineSegments(device,gtype) {}
+ LinearSpace3fa computeAlignedSpace(const size_t primID) const
+ {
+ const Vec3fa dir = normalize(computeDirection(primID));
+ if (is_finite(dir)) return frame(dir);
+ else return LinearSpace3fa(one);
+ }
+
+ LinearSpace3fa computeAlignedSpaceMB(const size_t primID, const BBox1f time_range) const
+ {
+ Vec3fa axisz(0,0,1);
+ Vec3fa axisy(0,1,0);
+
+ const range<int> tbounds = this->timeSegmentRange(time_range);
+ if (tbounds.size() == 0) return frame(axisz);
+
+ const size_t itime = (tbounds.begin()+tbounds.end())/2;
+
+ const Vec3fa dir = normalize(computeDirection(primID,itime));
+ if (is_finite(dir)) return frame(dir);
+ else return LinearSpace3fa(one);
+ }
+
Vec3fa computeDirection(unsigned int primID) const
{
const unsigned vtxID = segment(primID);
@@ -282,7 +546,7 @@ namespace embree
return v1-v0;
}
- PrimInfo createPrimRefArray(mvector<PrimRef>& prims, const range<size_t>& r, size_t k, unsigned int geomID) const
+ PrimInfo createPrimRefArray(PrimRef* prims, const range<size_t>& r, size_t k, unsigned int geomID) const
{
PrimInfo pinfo(empty);
for (size_t j=r.begin(); j<r.end(); j++)
@@ -309,7 +573,24 @@ namespace embree
}
return pinfo;
}
-
+
+ PrimInfo createPrimRefArrayMB(PrimRef* prims, const BBox1f& time_range, const range<size_t>& r, size_t k, unsigned int geomID) const
+ {
+ PrimInfo pinfo(empty);
+ const BBox1f t0t1 = BBox1f::intersect(getTimeRange(), time_range);
+ if (t0t1.empty()) return pinfo;
+
+ for (size_t j = r.begin(); j < r.end(); j++) {
+ LBBox3fa lbounds = empty;
+ if (!linearBounds(j, t0t1, lbounds))
+ continue;
+ const PrimRef prim(lbounds.bounds(), geomID, unsigned(j));
+ pinfo.add_center2(prim);
+ prims[k++] = prim;
+ }
+ return pinfo;
+ }
+
PrimInfoMB createPrimRefMBArray(mvector<PrimRefMB>& prims, const BBox1f& t0t1, const range<size_t>& r, size_t k, unsigned int geomID) const
{
PrimInfoMB pinfo(empty);
@@ -331,6 +612,10 @@ namespace embree
return bounds(space,i);
}
+ BBox3fa vbounds(const Vec3fa& ofs, const float scale, const float r_scale0, const LinearSpace3fa& space, size_t i, size_t itime = 0) const {
+ return bounds(ofs,scale,r_scale0,space,i,itime);
+ }
+
LBBox3fa vlinearBounds(size_t primID, const BBox1f& time_range) const {
return linearBounds(primID,time_range);
}
@@ -338,6 +623,10 @@ namespace embree
LBBox3fa vlinearBounds(const LinearSpace3fa& space, size_t primID, const BBox1f& time_range) const {
return linearBounds(space,primID,time_range);
}
+
+ LBBox3fa vlinearBounds(const Vec3fa& ofs, const float scale, const float r_scale0, const LinearSpace3fa& space, size_t primID, const BBox1f& time_range) const {
+ return linearBounds(ofs,scale,r_scale0,space,primID,time_range);
+ }
};
}
diff --git a/thirdparty/embree/kernels/common/scene_points.h b/thirdparty/embree/kernels/common/scene_points.h
index 017e098a51..937a8f1806 100644
--- a/thirdparty/embree/kernels/common/scene_points.h
+++ b/thirdparty/embree/kernels/common/scene_points.h
@@ -68,6 +68,25 @@ namespace embree
return vertices[itime][i];
}
+ /*! returns i'th vertex of for specified time */
+ __forceinline Vec3ff vertex(size_t i, float time) const
+ {
+ float ftime;
+ const size_t itime = timeSegment(time, ftime);
+ const float t0 = 1.0f - ftime;
+ const float t1 = ftime;
+ Vec3ff v0 = vertex(i, itime+0);
+ Vec3ff v1 = vertex(i, itime+1);
+ return madd(Vec3ff(t0),v0,t1*v1);
+ }
+
+ /*! returns i'th vertex of for specified time */
+ __forceinline Vec3ff vertex_safe(size_t i, float time) const
+ {
+ if (hasMotionBlur()) return vertex(i,time);
+ else return vertex(i);
+ }
+
/*! returns i'th vertex of itime'th timestep */
__forceinline const char* vertexPtr(size_t i, size_t itime) const {
return vertices[itime].getPtr(i);
@@ -78,11 +97,49 @@ namespace embree
return normals[itime][i];
}
+ /*! returns i'th normal of for specified time */
+ __forceinline Vec3fa normal(size_t i, float time) const
+ {
+ float ftime;
+ const size_t itime = timeSegment(time, ftime);
+ const float t0 = 1.0f - ftime;
+ const float t1 = ftime;
+ Vec3fa n0 = normal(i, itime+0);
+ Vec3fa n1 = normal(i, itime+1);
+ return madd(Vec3fa(t0),n0,t1*n1);
+ }
+
+ /*! returns i'th normal of for specified time */
+ __forceinline Vec3fa normal_safe(size_t i, float time) const
+ {
+ if (hasMotionBlur()) return normal(i,time);
+ else return normal(i);
+ }
+
/*! returns i'th radius of itime'th timestep */
__forceinline float radius(size_t i, size_t itime) const {
return vertices[itime][i].w;
}
+ /*! returns i'th radius of for specified time */
+ __forceinline float radius(size_t i, float time) const
+ {
+ float ftime;
+ const size_t itime = timeSegment(time, ftime);
+ const float t0 = 1.0f - ftime;
+ const float t1 = ftime;
+ float r0 = radius(i, itime+0);
+ float r1 = radius(i, itime+1);
+ return madd(t0,r0,t1*r1);
+ }
+
+ /*! returns i'th radius of for specified time */
+ __forceinline float radius_safe(size_t i, float time) const
+ {
+ if (hasMotionBlur()) return radius(i,time);
+ else return radius(i);
+ }
+
/*! calculates bounding box of i'th line segment */
__forceinline BBox3fa bounds(const Vec3ff& v0) const {
return enlarge(BBox3fa(v0), maxRadiusScale*Vec3fa(v0.w));
@@ -185,13 +242,18 @@ namespace embree
__forceinline float * getCompactVertexArray () const {
return (float*) vertices0.getPtr();
}
+
+ __forceinline float projectedPrimitiveArea(const size_t i) const {
+ const float R = radius(i);
+ return 1 + 2*M_PI*R*R;
+ }
public:
BufferView<Vec3ff> vertices0; //!< fast access to first vertex buffer
BufferView<Vec3fa> normals0; //!< fast access to first normal buffer
- vector<BufferView<Vec3ff>> vertices; //!< vertex array for each timestep
- vector<BufferView<Vec3fa>> normals; //!< normal array for each timestep
- vector<BufferView<char>> vertexAttribs; //!< user buffers
+ Device::vector<BufferView<Vec3ff>> vertices = device; //!< vertex array for each timestep
+ Device::vector<BufferView<Vec3fa>> normals = device; //!< normal array for each timestep
+ Device::vector<BufferView<char>> vertexAttribs = device; //!< user buffers
float maxRadiusScale = 1.0; //!< maximal min-width scaling of curve radii
};
@@ -211,7 +273,7 @@ namespace embree
return Vec3fa(1, 0, 0);
}
- PrimInfo createPrimRefArray(mvector<PrimRef>& prims, const range<size_t>& r, size_t k, unsigned int geomID) const
+ PrimInfo createPrimRefArray(PrimRef* prims, const range<size_t>& r, size_t k, unsigned int geomID) const
{
PrimInfo pinfo(empty);
for (size_t j = r.begin(); j < r.end(); j++) {
@@ -239,6 +301,23 @@ namespace embree
return pinfo;
}
+ PrimInfo createPrimRefArrayMB(PrimRef* prims, const BBox1f& time_range, const range<size_t>& r, size_t k, unsigned int geomID) const
+ {
+ PrimInfo pinfo(empty);
+ const BBox1f t0t1 = BBox1f::intersect(getTimeRange(), time_range);
+ if (t0t1.empty()) return pinfo;
+
+ for (size_t j = r.begin(); j < r.end(); j++) {
+ LBBox3fa lbounds = empty;
+ if (!linearBounds(j, t0t1, lbounds))
+ continue;
+ const PrimRef prim(lbounds.bounds(), geomID, unsigned(j));
+ pinfo.add_center2(prim);
+ prims[k++] = prim;
+ }
+ return pinfo;
+ }
+
PrimInfoMB createPrimRefMBArray(mvector<PrimRefMB>& prims,
const BBox1f& t0t1,
const range<size_t>& r,
diff --git a/thirdparty/embree/kernels/common/scene_quad_mesh.h b/thirdparty/embree/kernels/common/scene_quad_mesh.h
index bd8eeaaeb7..09a8b8ddd9 100644
--- a/thirdparty/embree/kernels/common/scene_quad_mesh.h
+++ b/thirdparty/embree/kernels/common/scene_quad_mesh.h
@@ -17,12 +17,18 @@ namespace embree
/*! triangle indices */
struct Quad
{
- uint32_t v[4];
+ Quad() {}
+
+ Quad (uint32_t v0, uint32_t v1, uint32_t v2, uint32_t v3) {
+ v[0] = v0; v[1] = v1; v[2] = v2; v[3] = v3;
+ }
/*! outputs triangle indices */
__forceinline friend embree_ostream operator<<(embree_ostream cout, const Quad& q) {
return cout << "Quad {" << q.v[0] << ", " << q.v[1] << ", " << q.v[2] << ", " << q.v[3] << " }";
}
+
+ uint32_t v[4];
};
public:
@@ -135,6 +141,18 @@ namespace embree
return vertices[itime].getPtr(i);
}
+ /*! returns i'th vertex of for specified time */
+ __forceinline Vec3fa vertex(size_t i, float time) const
+ {
+ float ftime;
+ const size_t itime = timeSegment(time, ftime);
+ const float t0 = 1.0f - ftime;
+ const float t1 = ftime;
+ Vec3fa v0 = vertex(i, itime+0);
+ Vec3fa v1 = vertex(i, itime+1);
+ return madd(Vec3fa(t0),v0,t1*v1);
+ }
+
/*! calculates the bounds of the i'th quad */
__forceinline BBox3fa bounds(size_t i) const
{
@@ -196,7 +214,7 @@ namespace embree
if (q.v[2] >= numVertices()) return false;
if (q.v[3] >= numVertices()) return false;
- for (unsigned int t=0; t<numTimeSteps; t++)
+ for (size_t t=0; t<numTimeSteps; t++)
{
const Vec3fa v0 = vertex(q.v[0],t);
const Vec3fa v1 = vertex(q.v[1],t);
@@ -279,8 +297,8 @@ namespace embree
public:
BufferView<Quad> quads; //!< array of quads
BufferView<Vec3fa> vertices0; //!< fast access to first vertex buffer
- vector<BufferView<Vec3fa>> vertices; //!< vertex array for each timestep
- vector<BufferView<char>> vertexAttribs; //!< vertex attribute buffers
+ Device::vector<BufferView<Vec3fa>> vertices = device; //!< vertex array for each timestep
+ Device::vector<RawBufferView> vertexAttribs = device; //!< vertex attribute buffers
};
namespace isa
@@ -290,7 +308,11 @@ namespace embree
QuadMeshISA (Device* device)
: QuadMesh(device) {}
- PrimInfo createPrimRefArray(mvector<PrimRef>& prims, const range<size_t>& r, size_t k, unsigned int geomID) const
+ LBBox3fa vlinearBounds(size_t primID, const BBox1f& time_range) const {
+ return linearBounds(primID,time_range);
+ }
+
+ PrimInfo createPrimRefArray(PrimRef* prims, const range<size_t>& r, size_t k, unsigned int geomID) const
{
PrimInfo pinfo(empty);
for (size_t j=r.begin(); j<r.end(); j++)
@@ -317,7 +339,24 @@ namespace embree
}
return pinfo;
}
-
+
+ PrimInfo createPrimRefArrayMB(PrimRef* prims, const BBox1f& time_range, const range<size_t>& r, size_t k, unsigned int geomID) const
+ {
+ PrimInfo pinfo(empty);
+ const BBox1f t0t1 = BBox1f::intersect(getTimeRange(), time_range);
+ if (t0t1.empty()) return pinfo;
+
+ for (size_t j = r.begin(); j < r.end(); j++) {
+ LBBox3fa lbounds = empty;
+ if (!linearBounds(j, t0t1, lbounds))
+ continue;
+ const PrimRef prim(lbounds.bounds(), geomID, unsigned(j));
+ pinfo.add_center2(prim);
+ prims[k++] = prim;
+ }
+ return pinfo;
+ }
+
PrimInfoMB createPrimRefMBArray(mvector<PrimRefMB>& prims, const BBox1f& t0t1, const range<size_t>& r, size_t k, unsigned int geomID) const
{
PrimInfoMB pinfo(empty);
diff --git a/thirdparty/embree/kernels/common/scene_subdiv_mesh.h b/thirdparty/embree/kernels/common/scene_subdiv_mesh.h
index 1db170196d..b213a9b7ba 100644
--- a/thirdparty/embree/kernels/common/scene_subdiv_mesh.h
+++ b/thirdparty/embree/kernels/common/scene_subdiv_mesh.h
@@ -9,11 +9,13 @@
#include "../subdiv/tessellation_cache.h"
#include "../subdiv/catmullclark_coefficients.h"
#include "../subdiv/patch.h"
-#include "../../common/algorithms/parallel_map.h"
-#include "../../common/algorithms/parallel_set.h"
namespace embree
{
+ struct HoleSet;
+ struct VertexCreaseMap;
+ struct EdgeCreaseMap;
+
class SubdivMesh : public Geometry
{
ALIGNED_CLASS_(16);
@@ -49,6 +51,7 @@ namespace embree
/*! subdiv mesh construction */
SubdivMesh(Device* device);
+ ~SubdivMesh();
public:
void setMask (unsigned mask);
@@ -272,7 +275,7 @@ namespace embree
mvector<uint32_t> halfEdgeFace;
/*! set with all holes */
- parallel_set<uint32_t> holeSet;
+ std::unique_ptr<HoleSet> holeSet;
/*! fast lookup table to detect invalid faces */
mvector<char> invalid_face;
@@ -299,10 +302,10 @@ namespace embree
private:
/*! map with all vertex creases */
- parallel_map<uint32_t,float> vertexCreaseMap;
+ std::unique_ptr<VertexCreaseMap> vertexCreaseMap;
/*! map with all edge creases */
- parallel_map<uint64_t,float> edgeCreaseMap;
+ std::unique_ptr<EdgeCreaseMap> edgeCreaseMap;
protected:
diff --git a/thirdparty/embree/kernels/common/scene_triangle_mesh.cpp b/thirdparty/embree/kernels/common/scene_triangle_mesh.cpp
index 3bbd7e51ae..6cdd542a65 100644
--- a/thirdparty/embree/kernels/common/scene_triangle_mesh.cpp
+++ b/thirdparty/embree/kernels/common/scene_triangle_mesh.cpp
@@ -134,7 +134,7 @@ namespace embree
Geometry::update();
}
- void TriangleMesh::commit()
+ void TriangleMesh::commit()
{
/* verify that stride of all time steps are identical */
for (unsigned int t=0; t<numTimeSteps; t++)
diff --git a/thirdparty/embree/kernels/common/scene_triangle_mesh.h b/thirdparty/embree/kernels/common/scene_triangle_mesh.h
index ad3f602fde..0d28219b96 100644
--- a/thirdparty/embree/kernels/common/scene_triangle_mesh.h
+++ b/thirdparty/embree/kernels/common/scene_triangle_mesh.h
@@ -129,6 +129,18 @@ namespace embree
return vertices[itime].getPtr(i);
}
+ /*! returns i'th vertex of for specified time */
+ __forceinline Vec3fa vertex(size_t i, float time) const
+ {
+ float ftime;
+ const size_t itime = timeSegment(time, ftime);
+ const float t0 = 1.0f - ftime;
+ const float t1 = ftime;
+ Vec3fa v0 = vertex(i, itime+0);
+ Vec3fa v1 = vertex(i, itime+1);
+ return madd(Vec3fa(t0),v0,t1*v1);
+ }
+
/*! calculates the bounds of the i'th triangle */
__forceinline BBox3fa bounds(size_t i) const
{
@@ -260,8 +272,8 @@ namespace embree
public:
BufferView<Triangle> triangles; //!< array of triangles
BufferView<Vec3fa> vertices0; //!< fast access to first vertex buffer
- vector<BufferView<Vec3fa>> vertices; //!< vertex array for each timestep
- vector<RawBufferView> vertexAttribs; //!< vertex attributes
+ Device::vector<BufferView<Vec3fa>> vertices = device; //!< vertex array for each timestep
+ Device::vector<RawBufferView> vertexAttribs = device; //!< vertex attributes
};
namespace isa
@@ -271,7 +283,11 @@ namespace embree
TriangleMeshISA (Device* device)
: TriangleMesh(device) {}
- PrimInfo createPrimRefArray(mvector<PrimRef>& prims, const range<size_t>& r, size_t k, unsigned int geomID) const
+ LBBox3fa vlinearBounds(size_t primID, const BBox1f& time_range) const {
+ return linearBounds(primID,time_range);
+ }
+
+ PrimInfo createPrimRefArray(PrimRef* prims, const range<size_t>& r, size_t k, unsigned int geomID) const
{
PrimInfo pinfo(empty);
for (size_t j=r.begin(); j<r.end(); j++)
@@ -298,7 +314,24 @@ namespace embree
}
return pinfo;
}
-
+
+ PrimInfo createPrimRefArrayMB(PrimRef* prims, const BBox1f& time_range, const range<size_t>& r, size_t k, unsigned int geomID) const
+ {
+ PrimInfo pinfo(empty);
+ const BBox1f t0t1 = BBox1f::intersect(getTimeRange(), time_range);
+ if (t0t1.empty()) return pinfo;
+
+ for (size_t j = r.begin(); j < r.end(); j++) {
+ LBBox3fa lbounds = empty;
+ if (!linearBounds(j, t0t1, lbounds))
+ continue;
+ const PrimRef prim(lbounds.bounds(), geomID, unsigned(j));
+ pinfo.add_center2(prim);
+ prims[k++] = prim;
+ }
+ return pinfo;
+ }
+
PrimInfoMB createPrimRefMBArray(mvector<PrimRefMB>& prims, const BBox1f& t0t1, const range<size_t>& r, size_t k, unsigned int geomID) const
{
PrimInfoMB pinfo(empty);
diff --git a/thirdparty/embree/kernels/common/scene_user_geometry.h b/thirdparty/embree/kernels/common/scene_user_geometry.h
index 2867b18b79..033476f658 100644
--- a/thirdparty/embree/kernels/common/scene_user_geometry.h
+++ b/thirdparty/embree/kernels/common/scene_user_geometry.h
@@ -21,6 +21,8 @@ namespace embree
virtual void setOccludedFunctionN (RTCOccludedFunctionN occluded);
virtual void build() {}
virtual void addElementsToCount (GeometryCounts & counts) const;
+
+ __forceinline float projectedPrimitiveArea(const size_t i) const { return 0.0f; }
};
namespace isa
@@ -30,7 +32,7 @@ namespace embree
UserGeometryISA (Device* device)
: UserGeometry(device) {}
- PrimInfo createPrimRefArray(mvector<PrimRef>& prims, const range<size_t>& r, size_t k, unsigned int geomID) const
+ PrimInfo createPrimRefArray(PrimRef* prims, const range<size_t>& r, size_t k, unsigned int geomID) const
{
PrimInfo pinfo(empty);
for (size_t j=r.begin(); j<r.end(); j++)
@@ -57,7 +59,24 @@ namespace embree
}
return pinfo;
}
-
+
+ PrimInfo createPrimRefArrayMB(PrimRef* prims, const BBox1f& time_range, const range<size_t>& r, size_t k, unsigned int geomID) const
+ {
+ PrimInfo pinfo(empty);
+ const BBox1f t0t1 = BBox1f::intersect(getTimeRange(), time_range);
+ if (t0t1.empty()) return pinfo;
+
+ for (size_t j = r.begin(); j < r.end(); j++) {
+ LBBox3fa lbounds = empty;
+ if (!linearBounds(j, t0t1, lbounds))
+ continue;
+ const PrimRef prim(lbounds.bounds(), geomID, unsigned(j));
+ pinfo.add_center2(prim);
+ prims[k++] = prim;
+ }
+ return pinfo;
+ }
+
PrimInfoMB createPrimRefMBArray(mvector<PrimRefMB>& prims, const BBox1f& t0t1, const range<size_t>& r, size_t k, unsigned int geomID) const
{
PrimInfoMB pinfo(empty);
diff --git a/thirdparty/embree/kernels/common/scene_verify.cpp b/thirdparty/embree/kernels/common/scene_verify.cpp
new file mode 100644
index 0000000000..1db7844f4f
--- /dev/null
+++ b/thirdparty/embree/kernels/common/scene_verify.cpp
@@ -0,0 +1,24 @@
+// Copyright 2009-2021 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+
+#include "scene.h"
+
+#include "../../common/algorithms/parallel_any_of.h"
+
+namespace embree
+{
+
+void Scene::checkIfModifiedAndSet ()
+{
+ if (isModified ()) return;
+
+ auto geometryIsModified = [this](size_t geomID)->bool {
+ return isGeometryModified(geomID);
+ };
+
+ if (parallel_any_of (size_t(0), geometries.size (), geometryIsModified)) {
+ setModified ();
+ }
+}
+
+} \ No newline at end of file
diff --git a/thirdparty/embree/kernels/common/stat.cpp b/thirdparty/embree/kernels/common/stat.cpp
index ebb77cd534..9a8c8fac4e 100644
--- a/thirdparty/embree/kernels/common/stat.cpp
+++ b/thirdparty/embree/kernels/common/stat.cpp
@@ -17,7 +17,7 @@ namespace embree
#endif
}
- void Stat::print(std::ostream& cout)
+ void Stat::print(embree_ostream cout)
{
Counters& cntrs = instance.cntrs;
Counters::Data& data = instance.cntrs.code;
diff --git a/thirdparty/embree/kernels/common/state.cpp b/thirdparty/embree/kernels/common/state.cpp
index db6b803041..1d73ae9629 100644
--- a/thirdparty/embree/kernels/common/state.cpp
+++ b/thirdparty/embree/kernels/common/state.cpp
@@ -192,10 +192,17 @@ namespace embree
const char* symbols[3] = { "=", ",", "|" };
bool State::parseFile(const FileName& fileName)
- {
- FILE* f = fopen(fileName.c_str(),"r");
- if (!f) return false;
- Ref<Stream<int> > file = new FileStream(f,fileName);
+ {
+ Ref<Stream<int> > file;
+ // -- GODOT start --
+ // try {
+ file = new FileStream(fileName);
+ // }
+ // catch (std::runtime_error& e) {
+ // (void) e;
+ // return false;
+ // }
+ // -- GODOT end --
std::vector<std::string> syms;
for (size_t i=0; i<sizeof(symbols)/sizeof(void*); i++)
@@ -393,7 +400,7 @@ namespace embree
grid_accel = cin->get().Identifier();
else if (tok == Token::Id("grid_accel_mb") && cin->trySymbol("="))
grid_accel_mb = cin->get().Identifier();
-
+
else if (tok == Token::Id("verbose") && cin->trySymbol("="))
verbose = cin->get().Int();
else if (tok == Token::Id("benchmark") && cin->trySymbol("="))
@@ -419,7 +426,7 @@ namespace embree
} while (cin->trySymbol("|"));
}
}
-
+
else if (tok == Token::Id("max_spatial_split_replications") && cin->trySymbol("="))
max_spatial_split_replications = cin->get().Float();
diff --git a/thirdparty/embree/kernels/common/state.h b/thirdparty/embree/kernels/common/state.h
index 33bcc843b2..8c34614185 100644
--- a/thirdparty/embree/kernels/common/state.h
+++ b/thirdparty/embree/kernels/common/state.h
@@ -189,7 +189,7 @@ namespace embree
memory_monitor_function = fptr;
memory_monitor_userptr = uptr;
}
-
+
RTCMemoryMonitorFunction memory_monitor_function;
void* memory_monitor_userptr;
};