diff options
author | Jakub Mateusz Marcowski <01158831@pw.edu.pl> | 2024-02-24 12:40:55 +0100 |
---|---|---|
committer | Jakub Marcowski <chubercikbattle@gmail.com> | 2024-03-27 22:10:35 +0100 |
commit | c43eab55a417162624f47aed6bbbd0a4bd41c607 (patch) | |
tree | 3bd2fb83995573ef52edb5e8c8bfa686cff357aa /thirdparty/embree/kernels | |
parent | d2f9245ddc868b8ca04a6fb1b912ec4b59512c11 (diff) | |
download | redot-engine-c43eab55a417162624f47aed6bbbd0a4bd41c607.tar.gz |
embree: Update to 4.3.1
Diffstat (limited to 'thirdparty/embree/kernels')
139 files changed, 6279 insertions, 4343 deletions
diff --git a/thirdparty/embree/kernels/builders/bvh_builder_morton.h b/thirdparty/embree/kernels/builders/bvh_builder_morton.h index cba32ca73c..87d4786810 100644 --- a/thirdparty/embree/kernels/builders/bvh_builder_morton.h +++ b/thirdparty/embree/kernels/builders/bvh_builder_morton.h @@ -5,6 +5,7 @@ #include "../common/builder.h" #include "../../common/algorithms/parallel_reduce.h" +#include "../../common/algorithms/parallel_sort.h" namespace embree { @@ -101,7 +102,7 @@ namespace embree } }; -#if defined (__AVX2__) +#if defined (__AVX2__) || defined(__SYCL_DEVICE_ONLY__) /*! for AVX2 there is a fast scalar bitInterleave */ struct MortonCodeGenerator diff --git a/thirdparty/embree/kernels/builders/bvh_builder_msmblur.h b/thirdparty/embree/kernels/builders/bvh_builder_msmblur.h index 6e73c0d250..d4e3388db5 100644 --- a/thirdparty/embree/kernels/builders/bvh_builder_msmblur.h +++ b/thirdparty/embree/kernels/builders/bvh_builder_msmblur.h @@ -7,7 +7,7 @@ #define MBLUR_NUM_OBJECT_BINS 32 #include "../bvh/bvh.h" -#include "../common/primref_mb.h" +#include "../builders/primref_mb.h" #include "heuristic_binning_array_aligned.h" #include "heuristic_timesplit_array.h" @@ -141,16 +141,17 @@ namespace embree struct VirtualRecalculatePrimRef { Scene* scene; + const SubGridBuildData * const sgrids; - __forceinline VirtualRecalculatePrimRef (Scene* scene) - : scene(scene) {} + __forceinline VirtualRecalculatePrimRef (Scene* scene, const SubGridBuildData * const sgrids = nullptr) + : scene(scene), sgrids(sgrids) {} __forceinline PrimRefMB operator() (const PrimRefMB& prim, const BBox1f time_range) const { const unsigned geomID = prim.geomID(); const unsigned primID = prim.primID(); const Geometry* mesh = scene->get(geomID); - const LBBox3fa lbounds = mesh->vlinearBounds(primID, time_range); + const LBBox3fa lbounds = mesh->vlinearBounds(primID, time_range, sgrids); const range<int> tbounds = mesh->timeSegmentRange(time_range); return PrimRefMB (lbounds, tbounds.size(), mesh->time_range, mesh->numTimeSegments(), geomID, primID); } @@ -166,7 +167,7 @@ namespace embree } __forceinline LBBox3fa linearBounds(const PrimRefMB& prim, const BBox1f time_range) const { - return scene->get(prim.geomID())->vlinearBounds(prim.primID(), time_range); + return scene->get(prim.geomID())->vlinearBounds(prim.primID(), time_range, sgrids); } __forceinline LBBox3fa linearBounds(const PrimRefMB& prim, const BBox1f time_range, const LinearSpace3fa& space) const { diff --git a/thirdparty/embree/kernels/builders/bvh_builder_sah.h b/thirdparty/embree/kernels/builders/bvh_builder_sah.h index 24c5faf8be..7a0c0bdb8e 100644 --- a/thirdparty/embree/kernels/builders/bvh_builder_sah.h +++ b/thirdparty/embree/kernels/builders/bvh_builder_sah.h @@ -7,13 +7,8 @@ #include "heuristic_spatial_array.h" #include "heuristic_openmerge_array.h" -#if defined(__AVX512F__) && !defined(__AVX512VL__) // KNL -# define NUM_OBJECT_BINS 16 -# define NUM_SPATIAL_BINS 16 -#else -# define NUM_OBJECT_BINS 32 -# define NUM_SPATIAL_BINS 16 -#endif +#define NUM_OBJECT_BINS 32 +#define NUM_SPATIAL_BINS 16 namespace embree { diff --git a/thirdparty/embree/kernels/builders/heuristic_binning.h b/thirdparty/embree/kernels/builders/heuristic_binning.h index 41be6183b8..d66726d09b 100644 --- a/thirdparty/embree/kernels/builders/heuristic_binning.h +++ b/thirdparty/embree/kernels/builders/heuristic_binning.h @@ -4,6 +4,7 @@ #pragma once #include "priminfo.h" +#include "priminfo_mb.h" #include "../../common/algorithms/parallel_reduce.h" #include "../../common/algorithms/parallel_partition.h" @@ -390,6 +391,63 @@ namespace embree } return Split(bestSAH,bestDim,bestPos,mapping); } + + /*! finds the best split by scanning binning information */ + __forceinline Split best_block_size(const BinMapping<BINS>& mapping, const size_t blockSize) const + { + /* sweep from right to left and compute parallel prefix of merged bounds */ + vfloat4 rAreas[BINS]; + vuint4 rCounts[BINS]; + vuint4 count = 0; BBox bx = empty; BBox by = empty; BBox bz = empty; + for (size_t i=mapping.size()-1; i>0; i--) + { + count += counts(i); + rCounts[i] = count; + bx.extend(bounds(i,0)); rAreas[i][0] = expectedApproxHalfArea(bx); + by.extend(bounds(i,1)); rAreas[i][1] = expectedApproxHalfArea(by); + bz.extend(bounds(i,2)); rAreas[i][2] = expectedApproxHalfArea(bz); + rAreas[i][3] = 0.0f; + } + /* sweep from left to right and compute SAH */ + vuint4 blocks_add = blockSize-1; + vfloat4 blocks_factor = 1.0f/float(blockSize); + vuint4 ii = 1; vfloat4 vbestSAH = pos_inf; vuint4 vbestPos = 0; + count = 0; bx = empty; by = empty; bz = empty; + for (size_t i=1; i<mapping.size(); i++, ii+=1) + { + count += counts(i-1); + bx.extend(bounds(i-1,0)); float Ax = expectedApproxHalfArea(bx); + by.extend(bounds(i-1,1)); float Ay = expectedApproxHalfArea(by); + bz.extend(bounds(i-1,2)); float Az = expectedApproxHalfArea(bz); + const vfloat4 lArea = vfloat4(Ax,Ay,Az,Az); + const vfloat4 rArea = rAreas[i]; + const vfloat4 lCount = floor(vfloat4(count +blocks_add)*blocks_factor); + const vfloat4 rCount = floor(vfloat4(rCounts[i]+blocks_add)*blocks_factor); + const vfloat4 sah = madd(lArea,lCount,rArea*rCount); + + vbestPos = select(sah < vbestSAH,ii ,vbestPos); + vbestSAH = select(sah < vbestSAH,sah,vbestSAH); + } + + /* find best dimension */ + float bestSAH = inf; + int bestDim = -1; + int bestPos = 0; + for (int dim=0; dim<3; dim++) + { + /* ignore zero sized dimensions */ + if (unlikely(mapping.invalid(dim))) + continue; + + /* test if this is a better dimension */ + if (vbestSAH[dim] < bestSAH && vbestPos[dim] != 0) { + bestDim = dim; + bestPos = vbestPos[dim]; + bestSAH = vbestSAH[dim]; + } + } + return Split(bestSAH,bestDim,bestPos,mapping); + } /*! calculates extended split information */ __forceinline void getSplitInfo(const BinMapping<BINS>& mapping, const Split& split, SplitInfoT<BBox>& info) const diff --git a/thirdparty/embree/kernels/builders/heuristic_binning_array_aligned.h b/thirdparty/embree/kernels/builders/heuristic_binning_array_aligned.h index ab3b97efb9..51dda9b49d 100644 --- a/thirdparty/embree/kernels/builders/heuristic_binning_array_aligned.h +++ b/thirdparty/embree/kernels/builders/heuristic_binning_array_aligned.h @@ -22,6 +22,9 @@ namespace embree __forceinline PrimInfoRange (size_t begin, size_t end, const CentGeomBBox3fa& centGeomBounds) : CentGeomBBox3fa(centGeomBounds), range<size_t>(begin,end) {} + + __forceinline PrimInfoRange (range<size_t> r, const CentGeomBBox3fa& centGeomBounds) + : CentGeomBBox3fa(centGeomBounds), range<size_t>(r) {} __forceinline float leafSAH() const { return expectedApproxHalfArea(geomBounds)*float(size()); @@ -30,7 +33,45 @@ namespace embree __forceinline float leafSAH(size_t block_shift) const { return expectedApproxHalfArea(geomBounds)*float((size()+(size_t(1)<<block_shift)-1) >> block_shift); } + + __forceinline range<size_t> get_range() const { + return range<size_t>(begin(),end()); + } + + template<typename PrimRef> + __forceinline void add_primref(const PrimRef& prim) + { + CentGeomBBox3fa::extend_primref(prim); + _end++; + } }; + + inline void performFallbackSplit(PrimRef* const prims, const PrimInfoRange& pinfo, PrimInfoRange& linfo, PrimInfoRange& rinfo) + { + const size_t begin = pinfo.begin(); + const size_t end = pinfo.end(); + const size_t center = (begin + end)/2; + + CentGeomBBox3fa left(empty); + for (size_t i=begin; i<center; i++) + left.extend_center2(prims[i]); + new (&linfo) PrimInfoRange(begin,center,left); + + CentGeomBBox3fa right(empty); + for (size_t i=center; i<end; i++) + right.extend_center2(prims[i]); + new (&rinfo) PrimInfoRange(center,end,right); + } + + template<typename Type, typename getTypeFunc> + inline void performTypeSplit(const getTypeFunc& getType, Type type, PrimRef* const prims, range<size_t> range, PrimInfoRange& linfo, PrimInfoRange& rinfo) + { + CentGeomBBox3fa local_left(empty), local_right(empty); + auto isLeft = [&] (const PrimRef& ref) { return type == getType(ref.geomID()); }; + const size_t center = serial_partitioning(prims,range.begin(),range.end(),local_left,local_right,isLeft,CentGeomBBox3fa::extend_ref); + linfo = PrimInfoRange(make_range(range.begin(),center ),local_left); + rinfo = PrimInfoRange(make_range(center ,range.end()),local_right); + } /*! Performs standard object binning */ template<typename PrimRef, size_t BINS> @@ -69,6 +110,24 @@ namespace embree return binner.best(mapping,logBlockSize); } + /*! finds the best split */ + __noinline const Split find_block_size(const PrimInfoRange& pinfo, const size_t blockSize) + { + if (likely(pinfo.size() < PARALLEL_THRESHOLD)) + return find_block_size_template<false>(pinfo,blockSize); + else + return find_block_size_template<true>(pinfo,blockSize); + } + + template<bool parallel> + __forceinline const Split find_block_size_template(const PrimInfoRange& pinfo, const size_t blockSize) + { + Binner binner(empty); + const BinMapping<BINS> mapping(pinfo); + bin_serial_or_parallel<parallel>(binner,prims,pinfo.begin(),pinfo.end(),PARALLEL_FIND_BLOCK_SIZE,mapping); + return binner.best_block_size(mapping,blockSize); + } + /*! array partitioning */ __forceinline void split(const Split& split, const PrimInfoRange& pinfo, PrimInfoRange& linfo, PrimInfoRange& rinfo) { @@ -121,21 +180,8 @@ namespace embree std::sort(&prims[pinfo.begin()],&prims[pinfo.end()]); } - void splitFallback(const PrimInfoRange& pinfo, PrimInfoRange& linfo, PrimInfoRange& rinfo) - { - const size_t begin = pinfo.begin(); - const size_t end = pinfo.end(); - const size_t center = (begin + end)/2; - - CentGeomBBox3fa left(empty); - for (size_t i=begin; i<center; i++) - left.extend_center2(prims[i]); - new (&linfo) PrimInfoRange(begin,center,left); - - CentGeomBBox3fa right(empty); - for (size_t i=center; i<end; i++) - right.extend_center2(prims[i]); - new (&rinfo) PrimInfoRange(center,end,right); + void splitFallback(const PrimInfoRange& pinfo, PrimInfoRange& linfo, PrimInfoRange& rinfo) { + performFallbackSplit(prims,pinfo,linfo,rinfo); } void splitByGeometry(const range<size_t>& range, PrimInfoRange& linfo, PrimInfoRange& rinfo) @@ -156,6 +202,8 @@ namespace embree PrimRef* const prims; }; +#if !defined(RTHWIF_STANDALONE) + /*! Performs standard object binning */ template<typename PrimRefMB, size_t BINS> struct HeuristicArrayBinningMB @@ -196,5 +244,6 @@ namespace embree new (&rset) SetMB(right,set.prims,range<size_t>(center,end ),set.time_range); } }; +#endif } } diff --git a/thirdparty/embree/kernels/builders/heuristic_spatial.h b/thirdparty/embree/kernels/builders/heuristic_spatial.h index 8b3499ac8d..25abf025ae 100644 --- a/thirdparty/embree/kernels/builders/heuristic_spatial.h +++ b/thirdparty/embree/kernels/builders/heuristic_spatial.h @@ -3,7 +3,6 @@ #pragma once -#include "../common/scene.h" #include "priminfo.h" namespace embree diff --git a/thirdparty/embree/kernels/builders/heuristic_timesplit_array.h b/thirdparty/embree/kernels/builders/heuristic_timesplit_array.h index b968e01c90..fe97862eb6 100644 --- a/thirdparty/embree/kernels/builders/heuristic_timesplit_array.h +++ b/thirdparty/embree/kernels/builders/heuristic_timesplit_array.h @@ -3,7 +3,7 @@ #pragma once -#include "../common/primref_mb.h" +#include "../builders/primref_mb.h" #include "../../common/algorithms/parallel_filter.h" #define MBLUR_TIME_SPLIT_THRESHOLD 1.25f diff --git a/thirdparty/embree/kernels/builders/priminfo.h b/thirdparty/embree/kernels/builders/priminfo.h index fee515247a..52f035e869 100644 --- a/thirdparty/embree/kernels/builders/priminfo.h +++ b/thirdparty/embree/kernels/builders/priminfo.h @@ -3,9 +3,7 @@ #pragma once -#include "../common/default.h" -#include "../common/primref.h" -#include "../common/primref_mb.h" +#include "primref.h" namespace embree { @@ -41,6 +39,10 @@ namespace embree centBounds.extend(center); } + static void extend_ref (CentGeom& pinfo, const PrimRef& ref) { + pinfo.extend_primref(ref); + }; + template<typename PrimRef> __forceinline void extend_center2(const PrimRef& prim) { @@ -84,6 +86,9 @@ namespace embree __forceinline PrimInfoT (EmptyTy) : CentGeom<BBox>(empty), begin(0), end(0) {} + __forceinline PrimInfoT (size_t N) + : CentGeom<BBox>(empty), begin(0), end(N) {} + __forceinline PrimInfoT (size_t begin, size_t end, const CentGeomBBox3fa& centGeomBounds) : CentGeom<BBox>(centGeomBounds), begin(begin), end(end) {} @@ -158,205 +163,5 @@ namespace embree typedef PrimInfoT<BBox3fa> PrimInfo; //typedef PrimInfoT<LBBox3fa> PrimInfoMB; - - /*! stores bounding information for a set of primitives */ - template<typename BBox> - class PrimInfoMBT : public CentGeom<BBox> - { - public: - using CentGeom<BBox>::geomBounds; - using CentGeom<BBox>::centBounds; - - __forceinline PrimInfoMBT () { - } - - __forceinline PrimInfoMBT (EmptyTy) - : CentGeom<BBox>(empty), object_range(0,0), num_time_segments(0), max_num_time_segments(0), max_time_range(0.0f,1.0f), time_range(1.0f,0.0f) {} - - __forceinline PrimInfoMBT (size_t begin, size_t end) - : CentGeom<BBox>(empty), object_range(begin,end), num_time_segments(0), max_num_time_segments(0), max_time_range(0.0f,1.0f), time_range(1.0f,0.0f) {} - - template<typename PrimRef> - __forceinline void add_primref(const PrimRef& prim) - { - CentGeom<BBox>::extend_primref(prim); - time_range.extend(prim.time_range); - object_range._end++; - num_time_segments += prim.size(); - if (max_num_time_segments < prim.totalTimeSegments()) { - max_num_time_segments = prim.totalTimeSegments(); - max_time_range = prim.time_range; - } - } - - __forceinline void merge(const PrimInfoMBT& other) - { - CentGeom<BBox>::merge(other); - time_range.extend(other.time_range); - object_range._begin += other.object_range.begin(); - object_range._end += other.object_range.end(); - num_time_segments += other.num_time_segments; - if (max_num_time_segments < other.max_num_time_segments) { - max_num_time_segments = other.max_num_time_segments; - max_time_range = other.max_time_range; - } - } - - static __forceinline const PrimInfoMBT merge2(const PrimInfoMBT& a, const PrimInfoMBT& b) { - PrimInfoMBT r = a; r.merge(b); return r; - } - - __forceinline size_t begin() const { - return object_range.begin(); - } - - __forceinline size_t end() const { - return object_range.end(); - } - - /*! returns the number of primitives */ - __forceinline size_t size() const { - return object_range.size(); - } - - __forceinline float halfArea() const { - return time_range.size()*expectedApproxHalfArea(geomBounds); - } - - __forceinline float leafSAH() const { - return time_range.size()*expectedApproxHalfArea(geomBounds)*float(num_time_segments); - } - - __forceinline float leafSAH(size_t block_shift) const { - return time_range.size()*expectedApproxHalfArea(geomBounds)*float((num_time_segments+(size_t(1)<<block_shift)-1) >> block_shift); - } - - __forceinline float align_time(float ct) const - { - //return roundf(ct * float(numTimeSegments)) / float(numTimeSegments); - float t0 = (ct-max_time_range.lower)/max_time_range.size(); - float t1 = roundf(t0 * float(max_num_time_segments)) / float(max_num_time_segments); - return t1*max_time_range.size()+max_time_range.lower; - } - - /*! stream output */ - friend embree_ostream operator<<(embree_ostream cout, const PrimInfoMBT& pinfo) - { - return cout << "PrimInfo { " << - "object_range = " << pinfo.object_range << - ", time_range = " << pinfo.time_range << - ", time_segments = " << pinfo.num_time_segments << - ", geomBounds = " << pinfo.geomBounds << - ", centBounds = " << pinfo.centBounds << - "}"; - } - - public: - range<size_t> object_range; //!< primitive range - size_t num_time_segments; //!< total number of time segments of all added primrefs - size_t max_num_time_segments; //!< maximum number of time segments of a primitive - BBox1f max_time_range; //!< time range of primitive with max_num_time_segments - BBox1f time_range; //!< merged time range of primitives when merging prims, or additionally clipped with build time range when used in SetMB - }; - - typedef PrimInfoMBT<typename PrimRefMB::BBox> PrimInfoMB; - - struct SetMB : public PrimInfoMB - { - static const size_t PARALLEL_THRESHOLD = 3 * 1024; - static const size_t PARALLEL_FIND_BLOCK_SIZE = 1024; - static const size_t PARALLEL_PARTITION_BLOCK_SIZE = 128; - - typedef mvector<PrimRefMB>* PrimRefVector; - - __forceinline SetMB() {} - - __forceinline SetMB(const PrimInfoMB& pinfo_i, PrimRefVector prims) - : PrimInfoMB(pinfo_i), prims(prims) {} - - __forceinline SetMB(const PrimInfoMB& pinfo_i, PrimRefVector prims, range<size_t> object_range_in, BBox1f time_range_in) - : PrimInfoMB(pinfo_i), prims(prims) - { - object_range = object_range_in; - time_range = intersect(time_range,time_range_in); - } - - __forceinline SetMB(const PrimInfoMB& pinfo_i, PrimRefVector prims, BBox1f time_range_in) - : PrimInfoMB(pinfo_i), prims(prims) - { - time_range = intersect(time_range,time_range_in); - } - - void deterministic_order() const - { - /* required as parallel partition destroys original primitive order */ - PrimRefMB* prim = prims->data(); - std::sort(&prim[object_range.begin()],&prim[object_range.end()]); - } - - template<typename RecalculatePrimRef> - __forceinline LBBox3fa linearBounds(const RecalculatePrimRef& recalculatePrimRef) const - { - auto reduce = [&](const range<size_t>& r) -> LBBox3fa - { - LBBox3fa cbounds(empty); - for (size_t j = r.begin(); j < r.end(); j++) - { - PrimRefMB& ref = (*prims)[j]; - const LBBox3fa bn = recalculatePrimRef.linearBounds(ref, time_range); - cbounds.extend(bn); - }; - return cbounds; - }; - - return parallel_reduce(object_range.begin(), object_range.end(), PARALLEL_FIND_BLOCK_SIZE, PARALLEL_THRESHOLD, LBBox3fa(empty), - reduce, - [&](const LBBox3fa& b0, const LBBox3fa& b1) -> LBBox3fa { return embree::merge(b0, b1); }); - } - - template<typename RecalculatePrimRef> - __forceinline LBBox3fa linearBounds(const RecalculatePrimRef& recalculatePrimRef, const LinearSpace3fa& space) const - { - auto reduce = [&](const range<size_t>& r) -> LBBox3fa - { - LBBox3fa cbounds(empty); - for (size_t j = r.begin(); j < r.end(); j++) - { - PrimRefMB& ref = (*prims)[j]; - const LBBox3fa bn = recalculatePrimRef.linearBounds(ref, time_range, space); - cbounds.extend(bn); - }; - return cbounds; - }; - - return parallel_reduce(object_range.begin(), object_range.end(), PARALLEL_FIND_BLOCK_SIZE, PARALLEL_THRESHOLD, LBBox3fa(empty), - reduce, - [&](const LBBox3fa& b0, const LBBox3fa& b1) -> LBBox3fa { return embree::merge(b0, b1); }); - } - - template<typename RecalculatePrimRef> - const SetMB primInfo(const RecalculatePrimRef& recalculatePrimRef, const LinearSpace3fa& space) const - { - auto computePrimInfo = [&](const range<size_t>& r) -> PrimInfoMB - { - PrimInfoMB pinfo(empty); - for (size_t j=r.begin(); j<r.end(); j++) - { - PrimRefMB& ref = (*prims)[j]; - PrimRefMB ref1 = recalculatePrimRef(ref,time_range,space); - pinfo.add_primref(ref1); - }; - return pinfo; - }; - - const PrimInfoMB pinfo = parallel_reduce(object_range.begin(), object_range.end(), PARALLEL_FIND_BLOCK_SIZE, PARALLEL_THRESHOLD, - PrimInfoMB(empty), computePrimInfo, PrimInfoMB::merge2); - - return SetMB(pinfo,prims,object_range,time_range); - } - - public: - PrimRefVector prims; - }; //} } diff --git a/thirdparty/embree/kernels/builders/priminfo_mb.h b/thirdparty/embree/kernels/builders/priminfo_mb.h new file mode 100644 index 0000000000..4005f04da9 --- /dev/null +++ b/thirdparty/embree/kernels/builders/priminfo_mb.h @@ -0,0 +1,210 @@ +// Copyright 2009-2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include "primref_mb.h" + +namespace embree +{ + /*! stores bounding information for a set of primitives */ + template<typename BBox> + class PrimInfoMBT : public CentGeom<BBox> + { + public: + using CentGeom<BBox>::geomBounds; + using CentGeom<BBox>::centBounds; + + __forceinline PrimInfoMBT () { + } + + __forceinline PrimInfoMBT (EmptyTy) + : CentGeom<BBox>(empty), object_range(0,0), num_time_segments(0), max_num_time_segments(0), max_time_range(0.0f,1.0f), time_range(1.0f,0.0f) {} + + __forceinline PrimInfoMBT (size_t begin, size_t end) + : CentGeom<BBox>(empty), object_range(begin,end), num_time_segments(0), max_num_time_segments(0), max_time_range(0.0f,1.0f), time_range(1.0f,0.0f) {} + + template<typename PrimRef> + __forceinline void add_primref(const PrimRef& prim) + { + CentGeom<BBox>::extend_primref(prim); + time_range.extend(prim.time_range); + object_range._end++; + num_time_segments += prim.size(); + if (max_num_time_segments < prim.totalTimeSegments()) { + max_num_time_segments = prim.totalTimeSegments(); + max_time_range = prim.time_range; + } + } + + __forceinline void merge(const PrimInfoMBT& other) + { + CentGeom<BBox>::merge(other); + time_range.extend(other.time_range); + object_range._begin += other.object_range.begin(); + object_range._end += other.object_range.end(); + num_time_segments += other.num_time_segments; + if (max_num_time_segments < other.max_num_time_segments) { + max_num_time_segments = other.max_num_time_segments; + max_time_range = other.max_time_range; + } + } + + static __forceinline const PrimInfoMBT merge2(const PrimInfoMBT& a, const PrimInfoMBT& b) { + PrimInfoMBT r = a; r.merge(b); return r; + } + + __forceinline size_t begin() const { + return object_range.begin(); + } + + __forceinline size_t end() const { + return object_range.end(); + } + + /*! returns the number of primitives */ + __forceinline size_t size() const { + return object_range.size(); + } + + __forceinline float halfArea() const { + return time_range.size()*expectedApproxHalfArea(geomBounds); + } + + __forceinline float leafSAH() const { + return time_range.size()*expectedApproxHalfArea(geomBounds)*float(num_time_segments); + } + + __forceinline float leafSAH(size_t block_shift) const { + return time_range.size()*expectedApproxHalfArea(geomBounds)*float((num_time_segments+(size_t(1)<<block_shift)-1) >> block_shift); + } + + __forceinline float align_time(float ct) const + { + //return roundf(ct * float(numTimeSegments)) / float(numTimeSegments); + float t0 = (ct-max_time_range.lower)/max_time_range.size(); + float t1 = roundf(t0 * float(max_num_time_segments)) / float(max_num_time_segments); + return t1*max_time_range.size()+max_time_range.lower; + } + + /*! stream output */ + friend embree_ostream operator<<(embree_ostream cout, const PrimInfoMBT& pinfo) + { + return cout << "PrimInfo { " << + "object_range = " << pinfo.object_range << + ", time_range = " << pinfo.time_range << + ", time_segments = " << pinfo.num_time_segments << + ", geomBounds = " << pinfo.geomBounds << + ", centBounds = " << pinfo.centBounds << + "}"; + } + + public: + range<size_t> object_range; //!< primitive range + size_t num_time_segments; //!< total number of time segments of all added primrefs + size_t max_num_time_segments; //!< maximum number of time segments of a primitive + BBox1f max_time_range; //!< time range of primitive with max_num_time_segments + BBox1f time_range; //!< merged time range of primitives when merging prims, or additionally clipped with build time range when used in SetMB + }; + + typedef PrimInfoMBT<typename PrimRefMB::BBox> PrimInfoMB; + + struct SetMB : public PrimInfoMB + { + static const size_t PARALLEL_THRESHOLD = 3 * 1024; + static const size_t PARALLEL_FIND_BLOCK_SIZE = 1024; + static const size_t PARALLEL_PARTITION_BLOCK_SIZE = 128; + + typedef mvector<PrimRefMB>* PrimRefVector; + + __forceinline SetMB() {} + + __forceinline SetMB(const PrimInfoMB& pinfo_i, PrimRefVector prims) + : PrimInfoMB(pinfo_i), prims(prims) {} + + __forceinline SetMB(const PrimInfoMB& pinfo_i, PrimRefVector prims, range<size_t> object_range_in, BBox1f time_range_in) + : PrimInfoMB(pinfo_i), prims(prims) + { + object_range = object_range_in; + time_range = intersect(time_range,time_range_in); + } + + __forceinline SetMB(const PrimInfoMB& pinfo_i, PrimRefVector prims, BBox1f time_range_in) + : PrimInfoMB(pinfo_i), prims(prims) + { + time_range = intersect(time_range,time_range_in); + } + + void deterministic_order() const + { + /* required as parallel partition destroys original primitive order */ + PrimRefMB* prim = prims->data(); + std::sort(&prim[object_range.begin()],&prim[object_range.end()]); + } + + template<typename RecalculatePrimRef> + __forceinline LBBox3fa linearBounds(const RecalculatePrimRef& recalculatePrimRef) const + { + auto reduce = [&](const range<size_t>& r) -> LBBox3fa + { + LBBox3fa cbounds(empty); + for (size_t j = r.begin(); j < r.end(); j++) + { + PrimRefMB& ref = (*prims)[j]; + const LBBox3fa bn = recalculatePrimRef.linearBounds(ref, time_range); + cbounds.extend(bn); + }; + return cbounds; + }; + + return parallel_reduce(object_range.begin(), object_range.end(), PARALLEL_FIND_BLOCK_SIZE, PARALLEL_THRESHOLD, LBBox3fa(empty), + reduce, + [&](const LBBox3fa& b0, const LBBox3fa& b1) -> LBBox3fa { return embree::merge(b0, b1); }); + } + + template<typename RecalculatePrimRef> + __forceinline LBBox3fa linearBounds(const RecalculatePrimRef& recalculatePrimRef, const LinearSpace3fa& space) const + { + auto reduce = [&](const range<size_t>& r) -> LBBox3fa + { + LBBox3fa cbounds(empty); + for (size_t j = r.begin(); j < r.end(); j++) + { + PrimRefMB& ref = (*prims)[j]; + const LBBox3fa bn = recalculatePrimRef.linearBounds(ref, time_range, space); + cbounds.extend(bn); + }; + return cbounds; + }; + + return parallel_reduce(object_range.begin(), object_range.end(), PARALLEL_FIND_BLOCK_SIZE, PARALLEL_THRESHOLD, LBBox3fa(empty), + reduce, + [&](const LBBox3fa& b0, const LBBox3fa& b1) -> LBBox3fa { return embree::merge(b0, b1); }); + } + + template<typename RecalculatePrimRef> + const SetMB primInfo(const RecalculatePrimRef& recalculatePrimRef, const LinearSpace3fa& space) const + { + auto computePrimInfo = [&](const range<size_t>& r) -> PrimInfoMB + { + PrimInfoMB pinfo(empty); + for (size_t j=r.begin(); j<r.end(); j++) + { + PrimRefMB& ref = (*prims)[j]; + PrimRefMB ref1 = recalculatePrimRef(ref,time_range,space); + pinfo.add_primref(ref1); + }; + return pinfo; + }; + + const PrimInfoMB pinfo = parallel_reduce(object_range.begin(), object_range.end(), PARALLEL_FIND_BLOCK_SIZE, PARALLEL_THRESHOLD, + PrimInfoMB(empty), computePrimInfo, PrimInfoMB::merge2); + + return SetMB(pinfo,prims,object_range,time_range); + } + + public: + PrimRefVector prims; + }; +//} +} diff --git a/thirdparty/embree/kernels/common/primref.h b/thirdparty/embree/kernels/builders/primref.h index d61763487b..cf349c4a0c 100644 --- a/thirdparty/embree/kernels/common/primref.h +++ b/thirdparty/embree/kernels/builders/primref.h @@ -3,7 +3,7 @@ #pragma once -#include "default.h" +#include "../common/default.h" namespace embree { @@ -118,7 +118,8 @@ namespace embree std::swap(a,b); #endif } - + + /************************************************************************************/ /************************************************************************************/ /************************************************************************************/ diff --git a/thirdparty/embree/kernels/common/primref_mb.h b/thirdparty/embree/kernels/builders/primref_mb.h index fb08a05003..2c4bef8b8b 100644 --- a/thirdparty/embree/kernels/common/primref_mb.h +++ b/thirdparty/embree/kernels/builders/primref_mb.h @@ -3,7 +3,7 @@ #pragma once -#include "default.h" +#include "../common/default.h" #define MBLUR_BIN_LBBOX 1 diff --git a/thirdparty/embree/kernels/builders/primrefgen.cpp b/thirdparty/embree/kernels/builders/primrefgen.cpp index e2d7c27bd8..33f67697cb 100644 --- a/thirdparty/embree/kernels/builders/primrefgen.cpp +++ b/thirdparty/embree/kernels/builders/primrefgen.cpp @@ -55,6 +55,29 @@ namespace embree return pinfo; } + PrimInfo createPrimRefArray(Scene* scene, Geometry::GTypeMask types, bool mblur, const size_t numPrimRefs, mvector<PrimRef>& prims, mvector<SubGridBuildData>& sgrids, BuildProgressMonitor& progressMonitor) + { + ParallelForForPrefixSumState<PrimInfo> pstate; + Scene::Iterator2 iter(scene,types,mblur); + + /* first try */ + progressMonitor(0); + pstate.init(iter,size_t(1024)); + PrimInfo pinfo = parallel_for_for_prefix_sum0( pstate, iter, PrimInfo(empty), [&](Geometry* mesh, const range<size_t>& r, size_t k, size_t geomID) -> PrimInfo { + return mesh->createPrimRefArray(prims,sgrids,r,k,(unsigned)geomID); + }, [](const PrimInfo& a, const PrimInfo& b) -> PrimInfo { return PrimInfo::merge(a,b); }); + + /* if we need to filter out geometry, run again */ + if (pinfo.size() != numPrimRefs) + { + progressMonitor(0); + pinfo = parallel_for_for_prefix_sum1( pstate, iter, PrimInfo(empty), [&](Geometry* mesh, const range<size_t>& r, size_t k, size_t geomID, const PrimInfo& base) -> PrimInfo { + return mesh->createPrimRefArray(prims,sgrids,r,base.size(),(unsigned)geomID); + }, [](const PrimInfo& a, const PrimInfo& b) -> PrimInfo { return PrimInfo::merge(a,b); }); + } + return pinfo; + } + PrimInfo createPrimRefArrayMBlur(Scene* scene, Geometry::GTypeMask types, const size_t numPrimRefs, mvector<PrimRef>& prims, BuildProgressMonitor& progressMonitor, size_t itime) { ParallelForForPrefixSumState<PrimInfo> pstate; @@ -104,6 +127,32 @@ namespace embree return pinfo; } + PrimInfoMB createPrimRefArrayMSMBlur(Scene* scene, Geometry::GTypeMask types, const size_t numPrimRefs, mvector<PrimRefMB>& prims, mvector<SubGridBuildData>& sgrids, BuildProgressMonitor& progressMonitor, BBox1f t0t1) + { + ParallelForForPrefixSumState<PrimInfoMB> pstate; + Scene::Iterator2 iter(scene,types,true); + + /* first try */ + progressMonitor(0); + pstate.init(iter,size_t(1024)); + PrimInfoMB pinfo = parallel_for_for_prefix_sum0( pstate, iter, PrimInfoMB(empty), [&](Geometry* mesh, const range<size_t>& r, size_t k, size_t geomID) -> PrimInfoMB { + return mesh->createPrimRefMBArray(prims,sgrids,t0t1,r,k,(unsigned)geomID); + }, [](const PrimInfoMB& a, const PrimInfoMB& b) -> PrimInfoMB { return PrimInfoMB::merge2(a,b); }); + + /* if we need to filter out geometry, run again */ + if (pinfo.size() != numPrimRefs) + { + progressMonitor(0); + pinfo = parallel_for_for_prefix_sum1( pstate, iter, PrimInfoMB(empty), [&](Geometry* mesh, const range<size_t>& r, size_t k, size_t geomID, const PrimInfoMB& base) -> PrimInfoMB { + return mesh->createPrimRefMBArray(prims,sgrids,t0t1,r,base.size(),(unsigned)geomID); + }, [](const PrimInfoMB& a, const PrimInfoMB& b) -> PrimInfoMB { return PrimInfoMB::merge2(a,b); }); + } + + /* the BVH starts with that time range, even though primitives might have smaller/larger time range */ + pinfo.time_range = t0t1; + return pinfo; + } + template<typename Mesh> size_t createMortonCodeArray(Mesh* mesh, mvector<BVHBuilderMorton::BuildPrim>& morton, BuildProgressMonitor& progressMonitor) { @@ -218,26 +267,8 @@ namespace embree /* second run to fill primrefs and SubGridBuildData arrays */ pinfo = parallel_for_for_prefix_sum1( pstate, iter, PrimInfo(empty), [&](GridMesh* mesh, const range<size_t>& r, size_t k, size_t geomID, const PrimInfo& base) -> PrimInfo { - k = base.size(); - size_t p_index = k; - PrimInfo pinfo(empty); - for (size_t j=r.begin(); j<r.end(); j++) - { - if (!mesh->valid(j)) continue; - const GridMesh::Grid &g = mesh->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 (!mesh->buildBounds(g,x,y,bounds)) continue; // get bounds of subgrid - const PrimRef prim(bounds,(unsigned)geomID,(unsigned)p_index); - pinfo.add_center2(prim); - sgrids[p_index] = SubGridBuildData(x | g.get3x3FlagsX(x), y | g.get3x3FlagsY(y), unsigned(j)); - prims[p_index++] = prim; - } - } - return pinfo; - }, [](const PrimInfo& a, const PrimInfo& b) -> PrimInfo { return PrimInfo::merge(a,b); }); + return mesh->createPrimRefArray(prims,sgrids,r,base.size(),geomID); + }, [](const PrimInfo& a, const PrimInfo& b) -> PrimInfo { return PrimInfo::merge(a,b); }); assert(pinfo.size() == numPrimitives); return pinfo; } @@ -269,40 +300,60 @@ namespace embree prims.resize(numPrimitives); /* second run to fill primrefs and SubGridBuildData arrays */ - pinfo = parallel_prefix_sum( pstate, size_t(0), mesh->size(), size_t(1024), PrimInfo(empty), [&](const range<size_t>& r, const PrimInfo& base) -> PrimInfo - { - - size_t p_index = base.size(); - PrimInfo pinfo(empty); - for (size_t j=r.begin(); j<r.end(); j++) - { - if (!mesh->valid(j)) continue; - const GridMesh::Grid &g = mesh->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 (!mesh->buildBounds(g,x,y,bounds)) continue; // get bounds of subgrid - const PrimRef prim(bounds,geomID_,unsigned(p_index)); - pinfo.add_center2(prim); - sgrids[p_index] = SubGridBuildData(x | g.get3x3FlagsX(x), y | g.get3x3FlagsY(y), unsigned(j)); - prims[p_index++] = prim; - } - } - return pinfo; - }, [](const PrimInfo& a, const PrimInfo& b) -> PrimInfo { return PrimInfo::merge(a,b); }); + pinfo = parallel_prefix_sum( pstate, size_t(0), mesh->size(), size_t(1024), PrimInfo(empty), [&](const range<size_t>& r, const PrimInfo& base) -> PrimInfo { + return mesh->createPrimRefArray(prims,sgrids,r,base.size(),geomID_); + }, [](const PrimInfo& a, const PrimInfo& b) -> PrimInfo { return PrimInfo::merge(a,b); }); return pinfo; } + + PrimInfoMB createPrimRefArrayMSMBlurGrid(Scene* scene, mvector<PrimRefMB>& prims, mvector<SubGridBuildData>& sgrids, BuildProgressMonitor& progressMonitor, BBox1f t0t1) + { + /* first run to get #primitives */ + ParallelForForPrefixSumState<PrimInfoMB> pstate; + Scene::Iterator<GridMesh,true> iter(scene); + + pstate.init(iter,size_t(1024)); + /* iterate over all meshes in the scene */ + PrimInfoMB pinfoMB = parallel_for_for_prefix_sum0( pstate, iter, PrimInfoMB(empty), [&](GridMesh* mesh, const range<size_t>& r, size_t k, size_t /*geomID*/) -> PrimInfoMB { + + PrimInfoMB pinfoMB(empty); + for (size_t j=r.begin(); j<r.end(); j++) + { + if (!mesh->valid(j, mesh->timeSegmentRange(t0t1))) continue; + LBBox3fa bounds(empty); + PrimInfoMB gridMB(0,mesh->getNumSubGrids(j)); + pinfoMB.merge(gridMB); + } + return pinfoMB; + }, [](const PrimInfoMB& a, const PrimInfoMB& b) -> PrimInfoMB { return PrimInfoMB::merge2(a,b); }); + + size_t numPrimitives = pinfoMB.size(); + if (numPrimitives == 0) return pinfoMB; + + /* resize arrays */ + sgrids.resize(numPrimitives); + prims.resize(numPrimitives); + /* second run to fill primrefs and SubGridBuildData arrays */ + pinfoMB = parallel_for_for_prefix_sum1( pstate, iter, PrimInfoMB(empty), [&](GridMesh* mesh, const range<size_t>& r, size_t k, size_t geomID, const PrimInfoMB& base) -> PrimInfoMB { + return mesh->createPrimRefMBArray(prims,sgrids,t0t1,r,base.size(),(unsigned)geomID); + }, [](const PrimInfoMB& a, const PrimInfoMB& b) -> PrimInfoMB { return PrimInfoMB::merge2(a,b); }); + + assert(pinfoMB.size() == numPrimitives); + pinfoMB.time_range = t0t1; + return pinfoMB; + } + #endif // ==================================================================================================== // ==================================================================================================== // ==================================================================================================== - + IF_ENABLED_TRIS (template size_t createMortonCodeArray<TriangleMesh>(TriangleMesh* mesh COMMA mvector<BVHBuilderMorton::BuildPrim>& morton COMMA BuildProgressMonitor& progressMonitor)); IF_ENABLED_QUADS(template size_t createMortonCodeArray<QuadMesh>(QuadMesh* mesh COMMA mvector<BVHBuilderMorton::BuildPrim>& morton COMMA BuildProgressMonitor& progressMonitor)); IF_ENABLED_USER (template size_t createMortonCodeArray<UserGeometry>(UserGeometry* mesh COMMA mvector<BVHBuilderMorton::BuildPrim>& morton COMMA BuildProgressMonitor& progressMonitor)); IF_ENABLED_INSTANCE (template size_t createMortonCodeArray<Instance>(Instance* mesh COMMA mvector<BVHBuilderMorton::BuildPrim>& morton COMMA BuildProgressMonitor& progressMonitor)); + IF_ENABLED_INSTANCE_ARRAY (template size_t createMortonCodeArray<InstanceArray>(InstanceArray* mesh COMMA mvector<BVHBuilderMorton::BuildPrim>& morton COMMA BuildProgressMonitor& progressMonitor)); } } diff --git a/thirdparty/embree/kernels/builders/primrefgen.h b/thirdparty/embree/kernels/builders/primrefgen.h index c09a848ba3..0e2ab094fb 100644 --- a/thirdparty/embree/kernels/builders/primrefgen.h +++ b/thirdparty/embree/kernels/builders/primrefgen.h @@ -4,9 +4,8 @@ #pragma once #include "../common/scene.h" -#include "../common/primref.h" -#include "../common/primref_mb.h" #include "priminfo.h" +#include "priminfo_mb.h" #include "bvh_builder_morton.h" namespace embree @@ -16,19 +15,23 @@ namespace embree PrimInfo createPrimRefArray(Geometry* geometry, unsigned int geomID, size_t numPrimitives, mvector<PrimRef>& prims, BuildProgressMonitor& progressMonitor); PrimInfo createPrimRefArray(Scene* scene, Geometry::GTypeMask types, bool mblur, size_t numPrimitives, mvector<PrimRef>& prims, BuildProgressMonitor& progressMonitor); + + PrimInfo createPrimRefArray(Scene* scene, Geometry::GTypeMask types, bool mblur, size_t numPrimitives, mvector<PrimRef>& prims, mvector<SubGridBuildData>& sgrids, BuildProgressMonitor& progressMonitor); PrimInfo createPrimRefArrayMBlur(Scene* scene, Geometry::GTypeMask types, size_t numPrimitives, mvector<PrimRef>& prims, BuildProgressMonitor& progressMonitor, size_t itime = 0); PrimInfoMB createPrimRefArrayMSMBlur(Scene* scene, Geometry::GTypeMask types, size_t numPrimitives, mvector<PrimRefMB>& prims, BuildProgressMonitor& progressMonitor, BBox1f t0t1 = BBox1f(0.0f,1.0f)); + PrimInfoMB createPrimRefArrayMSMBlur(Scene* scene, Geometry::GTypeMask types, size_t numPrimitives, mvector<PrimRefMB>& prims, mvector<SubGridBuildData>& sgrids, BuildProgressMonitor& progressMonitor, BBox1f t0t1 = BBox1f(0.0f,1.0f)); + template<typename Mesh> size_t createMortonCodeArray(Mesh* mesh, mvector<BVHBuilderMorton::BuildPrim>& morton, BuildProgressMonitor& progressMonitor); /* special variants for grids */ - PrimInfo createPrimRefArrayGrids(Scene* scene, mvector<PrimRef>& prims, mvector<SubGridBuildData>& sgrids); + PrimInfo createPrimRefArrayGrids(Scene* scene, mvector<PrimRef>& prims, mvector<SubGridBuildData>& sgrids); // FIXME: remove PrimInfo createPrimRefArrayGrids(GridMesh* mesh, mvector<PrimRef>& prims, mvector<SubGridBuildData>& sgrids); - + + PrimInfoMB createPrimRefArrayMSMBlurGrid(Scene* scene, mvector<PrimRefMB>& prims, mvector<SubGridBuildData>& sgrids, BuildProgressMonitor& progressMonitor, BBox1f t0t1 = BBox1f(0.0f,1.0f)); } } - diff --git a/thirdparty/embree/kernels/builders/primrefgen_presplit.h b/thirdparty/embree/kernels/builders/primrefgen_presplit.h index aa2026a85e..db9010995d 100644 --- a/thirdparty/embree/kernels/builders/primrefgen_presplit.h +++ b/thirdparty/embree/kernels/builders/primrefgen_presplit.h @@ -3,10 +3,12 @@ #pragma once -#include "../builders/primrefgen.h" +#include "../../common/algorithms/parallel_reduce.h" +#include "../../common/algorithms/parallel_sort.h" #include "../builders/heuristic_spatial.h" #include "../builders/splitter.h" +#include "../../common/algorithms/parallel_partition.h" #include "../../common/algorithms/parallel_for_for.h" #include "../../common/algorithms/parallel_for_for_prefix_sum.h" @@ -14,15 +16,87 @@ #define CHECK_PRESPLIT(x) #define GRID_SIZE 1024 +//#define MAX_PRESPLITS_PER_PRIMITIVE_LOG 6 #define MAX_PRESPLITS_PER_PRIMITIVE_LOG 5 #define MAX_PRESPLITS_PER_PRIMITIVE (1<<MAX_PRESPLITS_PER_PRIMITIVE_LOG) -#define PRIORITY_CUTOFF_THRESHOLD 1.0f +//#define PRIORITY_CUTOFF_THRESHOLD 2.0f #define PRIORITY_SPLIT_POS_WEIGHT 1.5f namespace embree { namespace isa { + struct SplittingGrid + { + __forceinline SplittingGrid(const BBox3fa& bounds) + { + base = bounds.lower; + const Vec3fa diag = bounds.size(); + extend = max(diag.x,max(diag.y,diag.z)); + scale = extend == 0.0f ? 0.0f : GRID_SIZE / extend; + } + + __forceinline bool split_pos(const PrimRef& prim, unsigned int& dim_o, float& fsplit_o) const + { + /* compute morton code */ + const Vec3fa lower = prim.lower; + const Vec3fa upper = prim.upper; + const Vec3fa glower = (lower-base)*Vec3fa(scale)+Vec3fa(0.2f); + const Vec3fa gupper = (upper-base)*Vec3fa(scale)-Vec3fa(0.2f); + Vec3ia ilower(floor(glower)); + Vec3ia iupper(floor(gupper)); + + /* this ignores dimensions that are empty */ + iupper = (Vec3ia)select(vint4(glower) >= vint4(gupper),vint4(ilower),vint4(iupper)); + + /* compute a morton code for the lower and upper grid coordinates. */ + const unsigned int lower_code = bitInterleave(ilower.x,ilower.y,ilower.z); + const unsigned int upper_code = bitInterleave(iupper.x,iupper.y,iupper.z); + + /* if all bits are equal then we cannot split */ + if (unlikely(lower_code == upper_code)) + return false; + + /* compute octree level and dimension to perform the split in */ + const unsigned int diff = 31 - lzcnt(lower_code^upper_code); + const unsigned int level = diff / 3; + const unsigned int dim = diff % 3; + + /* now we compute the grid position of the split */ + const unsigned int isplit = iupper[dim] & ~((1<<level)-1); + + /* compute world space position of split */ + const float inv_grid_size = 1.0f / GRID_SIZE; + const float fsplit = base[dim] + isplit * inv_grid_size * extend; + assert(prim.lower[dim] <= fsplit && prim.upper[dim] >= fsplit); + + dim_o = dim; + fsplit_o = fsplit; + return true; + } + + __forceinline Vec2i computeMC(const PrimRef& ref) const + { + const Vec3fa lower = ref.lower; + const Vec3fa upper = ref.upper; + const Vec3fa glower = (lower-base)*Vec3fa(scale)+Vec3fa(0.2f); + const Vec3fa gupper = (upper-base)*Vec3fa(scale)-Vec3fa(0.2f); + Vec3ia ilower(floor(glower)); + Vec3ia iupper(floor(gupper)); + + /* this ignores dimensions that are empty */ + iupper = (Vec3ia)select(vint4(glower) >= vint4(gupper),vint4(ilower),vint4(iupper)); + + /* compute a morton code for the lower and upper grid coordinates. */ + const unsigned int lower_code = bitInterleave(ilower.x,ilower.y,ilower.z); + const unsigned int upper_code = bitInterleave(iupper.x,iupper.y,iupper.z); + return Vec2i(lower_code,upper_code); + } + + Vec3fa base; + float scale; + float extend; + }; struct PresplitItem { @@ -32,30 +106,30 @@ namespace embree }; unsigned int index; - __forceinline operator unsigned() const - { - return reinterpret_cast<const unsigned&>(priority); - } - __forceinline bool operator < (const PresplitItem& item) const - { - return (priority < item.priority); + __forceinline operator unsigned() const { + return data; } - template<typename Mesh> - __forceinline static float compute_priority(const PrimRef &ref, Scene *scene, const Vec2i &mc) + template<typename ProjectedPrimitiveAreaFunc> + __forceinline static float compute_priority(const ProjectedPrimitiveAreaFunc& primitiveArea, const PrimRef &ref, const Vec2i &mc) { - const unsigned int geomID = ref.geomID(); - const unsigned int primID = ref.primID(); const float area_aabb = area(ref.bounds()); - const float area_prim = ((Mesh*)scene->get(geomID))->projectedPrimitiveArea(primID); + const float area_prim = primitiveArea(ref); + if (area_prim == 0.0f) return 0.0f; const unsigned int diff = 31 - lzcnt(mc.x^mc.y); - assert(area_prim <= area_aabb); - //const float priority = powf((area_aabb - area_prim) * powf(PRIORITY_SPLIT_POS_WEIGHT,(float)diff),1.0f/4.0f); - const float priority = sqrtf(sqrtf( (area_aabb - area_prim) * powf(PRIORITY_SPLIT_POS_WEIGHT,(float)diff) )); + //assert(area_prim <= area_aabb); // may trigger due to numerical issues + const float area_diff = max(0.0f, area_aabb - area_prim); + //const float priority = powf(area_diff * powf(PRIORITY_SPLIT_POS_WEIGHT,(float)diff),1.0f/4.0f); + const float priority = sqrtf(sqrtf( area_diff * powf(PRIORITY_SPLIT_POS_WEIGHT,(float)diff) )); + //const float priority = sqrtf(sqrtf( area_diff ) ); + //const float priority = sqrtfarea_diff; + //const float priority = area_diff; // 104 fps !!!!!!!!!! + //const float priority = 0.2f*area_aabb + 0.8f*area_diff; // 104 fps + //const float priority = area_aabb * max(area_aabb/area_prim,32.0f); + //const float priority = area_prim; assert(priority >= 0.0f && priority < FLT_LARGE); return priority; } - }; @@ -63,77 +137,96 @@ namespace embree return cout << "index " << item.index << " priority " << item.priority; }; - template<typename SplitterFactory> - void splitPrimitive(SplitterFactory &Splitter, - const PrimRef &prim, - const unsigned int geomID, - const unsigned int primID, - const unsigned int split_level, - const Vec3fa &grid_base, - const float grid_scale, - const float grid_extend, +#if 1 + + template<typename Splitter> + void splitPrimitive(const Splitter& splitter, + const PrimRef& prim, + const unsigned int splitprims, + const SplittingGrid& grid, PrimRef subPrims[MAX_PRESPLITS_PER_PRIMITIVE], unsigned int& numSubPrims) { - assert(split_level <= MAX_PRESPLITS_PER_PRIMITIVE_LOG); - if (split_level == 0) + assert(splitprims > 0 && splitprims <= MAX_PRESPLITS_PER_PRIMITIVE); + + if (splitprims == 1) { assert(numSubPrims < MAX_PRESPLITS_PER_PRIMITIVE); subPrims[numSubPrims++] = prim; } else { - const Vec3fa lower = prim.lower; - const Vec3fa upper = prim.upper; - const Vec3fa glower = (lower-grid_base)*Vec3fa(grid_scale)+Vec3fa(0.2f); - const Vec3fa gupper = (upper-grid_base)*Vec3fa(grid_scale)-Vec3fa(0.2f); - Vec3ia ilower(floor(glower)); - Vec3ia iupper(floor(gupper)); - - /* this ignores dimensions that are empty */ - iupper = (Vec3ia)(select(vint4(glower) >= vint4(gupper),vint4(ilower),vint4(iupper))); - - /* compute a morton code for the lower and upper grid coordinates. */ - const unsigned int lower_code = bitInterleave(ilower.x,ilower.y,ilower.z); - const unsigned int upper_code = bitInterleave(iupper.x,iupper.y,iupper.z); - - /* if all bits are equal then we cannot split */ - if(unlikely(lower_code == upper_code)) + unsigned int dim; float fsplit; + if (!grid.split_pos(prim, dim, fsplit)) { assert(numSubPrims < MAX_PRESPLITS_PER_PRIMITIVE); subPrims[numSubPrims++] = prim; return; } - - /* compute octree level and dimension to perform the split in */ - const unsigned int diff = 31 - lzcnt(lower_code^upper_code); - const unsigned int level = diff / 3; - const unsigned int dim = diff % 3; + + /* split primitive */ + PrimRef left,right; + splitter(prim,dim,fsplit,left,right); + assert(!left.bounds().empty()); + assert(!right.bounds().empty()); + + const unsigned int splitprims_left = splitprims/2; + const unsigned int splitprims_right = splitprims - splitprims_left; + splitPrimitive(splitter,left,splitprims_left,grid,subPrims,numSubPrims); + splitPrimitive(splitter,right,splitprims_right,grid,subPrims,numSubPrims); + } + } + +#else + + template<typename Splitter> + void splitPrimitive(const Splitter& splitter, + const PrimRef& prim, + const unsigned int targetSubPrims, + const SplittingGrid& grid, + PrimRef subPrims[MAX_PRESPLITS_PER_PRIMITIVE], + unsigned int& numSubPrims) + { + assert(targetSubPrims > 0 && targetSubPrims <= MAX_PRESPLITS_PER_PRIMITIVE); - /* now we compute the grid position of the split */ - const unsigned int isplit = iupper[dim] & ~((1<<level)-1); - - /* compute world space position of split */ - const float inv_grid_size = 1.0f / GRID_SIZE; - const float fsplit = grid_base[dim] + isplit * inv_grid_size * grid_extend; + auto compare = [] ( const PrimRef& a, const PrimRef& b ) { + return area(a.bounds()) < area(b.bounds()); + }; + + subPrims[numSubPrims++] = prim; + + while (numSubPrims < targetSubPrims) + { + /* get top heap element */ + std::pop_heap(subPrims+0,subPrims+numSubPrims, compare); + PrimRef top = subPrims[--numSubPrims]; - assert(prim.lower[dim] <= fsplit && - prim.upper[dim] >= fsplit); - + unsigned int dim; float fsplit; + if (!grid.split_pos(top, dim, fsplit)) + { + assert(numSubPrims < MAX_PRESPLITS_PER_PRIMITIVE); + subPrims[numSubPrims++] = top; + return; + } + /* split primitive */ - const auto splitter = Splitter(prim); - BBox3fa left,right; - splitter(prim.bounds(),dim,fsplit,left,right); - assert(!left.empty()); - assert(!right.empty()); + PrimRef left,right; + splitter(top,dim,fsplit,left,right); + assert(!left.bounds().empty()); + assert(!right.bounds().empty()); - - splitPrimitive(Splitter,PrimRef(left ,geomID,primID),geomID,primID,split_level-1,grid_base,grid_scale,grid_extend,subPrims,numSubPrims); - splitPrimitive(Splitter,PrimRef(right,geomID,primID),geomID,primID,split_level-1,grid_base,grid_scale,grid_extend,subPrims,numSubPrims); + subPrims[numSubPrims++] = left; + std::push_heap(subPrims+0, subPrims+numSubPrims, compare); + + subPrims[numSubPrims++] = right; + std::push_heap(subPrims+0, subPrims+numSubPrims, compare); } } - +#endif + +#if !defined(RTHWIF_STANDALONE) + template<typename Mesh, typename SplitterFactory> PrimInfo createPrimRefArray_presplit(Geometry* geometry, unsigned int geomID, size_t numPrimRefs, mvector<PrimRef>& prims, BuildProgressMonitor& progressMonitor) { @@ -155,87 +248,40 @@ namespace embree } return pinfo; } +#endif - __forceinline Vec2i computeMC(const Vec3fa &grid_base, const float grid_scale, const PrimRef &ref) + template<typename SplitPrimitiveFunc, typename ProjectedPrimitiveAreaFunc, typename PrimVector> + PrimInfo createPrimRefArray_presplit(size_t numPrimRefs, + PrimVector& prims, + const PrimInfo& pinfo, + const SplitPrimitiveFunc& splitPrimitive, + const ProjectedPrimitiveAreaFunc& primitiveArea) { - const Vec3fa lower = ref.lower; - const Vec3fa upper = ref.upper; - const Vec3fa glower = (lower-grid_base)*Vec3fa(grid_scale)+Vec3fa(0.2f); - const Vec3fa gupper = (upper-grid_base)*Vec3fa(grid_scale)-Vec3fa(0.2f); - Vec3ia ilower(floor(glower)); - Vec3ia iupper(floor(gupper)); - - /* this ignores dimensions that are empty */ - iupper = (Vec3ia)select(vint4(glower) >= vint4(gupper),vint4(ilower),vint4(iupper)); - - /* compute a morton code for the lower and upper grid coordinates. */ - const unsigned int lower_code = bitInterleave(ilower.x,ilower.y,ilower.z); - const unsigned int upper_code = bitInterleave(iupper.x,iupper.y,iupper.z); - return Vec2i(lower_code,upper_code); - } - - template<typename Mesh, typename SplitterFactory> - PrimInfo createPrimRefArray_presplit(Scene* scene, Geometry::GTypeMask types, bool mblur, size_t numPrimRefs, mvector<PrimRef>& prims, BuildProgressMonitor& progressMonitor) - { static const size_t MIN_STEP_SIZE = 128; - ParallelForForPrefixSumState<PrimInfo> pstate; - Scene::Iterator2 iter(scene,types,mblur); - - /* first try */ - progressMonitor(0); - pstate.init(iter,size_t(1024)); - PrimInfo pinfo = parallel_for_for_prefix_sum0( pstate, iter, PrimInfo(empty), [&](Geometry* mesh, const range<size_t>& r, size_t k, size_t geomID) -> PrimInfo { - return mesh->createPrimRefArray(prims,r,k,(unsigned)geomID); - }, [](const PrimInfo& a, const PrimInfo& b) -> PrimInfo { return PrimInfo::merge(a,b); }); - - /* if we need to filter out geometry, run again */ - if (pinfo.size() != numPrimRefs) - { - progressMonitor(0); - pinfo = parallel_for_for_prefix_sum1( pstate, iter, PrimInfo(empty), [&](Geometry* mesh, const range<size_t>& r, size_t k, size_t geomID, const PrimInfo& base) -> PrimInfo { - return mesh->createPrimRefArray(prims,r,base.size(),(unsigned)geomID); - }, [](const PrimInfo& a, const PrimInfo& b) -> PrimInfo { return PrimInfo::merge(a,b); }); - } - /* use correct number of primitives */ size_t numPrimitives = pinfo.size(); - const size_t alloc_numPrimitives = prims.size(); - const size_t numSplitPrimitivesBudget = alloc_numPrimitives - numPrimitives; - - /* set up primitive splitter */ - SplitterFactory Splitter(scene); - - - DBG_PRESPLIT( - const size_t org_numPrimitives = pinfo.size(); - PRINT(numPrimitives); - PRINT(alloc_numPrimitives); - PRINT(numSplitPrimitivesBudget); - ); + const size_t numPrimitivesExt = prims.size(); + const size_t numSplitPrimitivesBudget = numPrimitivesExt - numPrimitives; /* allocate double buffer presplit items */ - const size_t presplit_allocation_size = sizeof(PresplitItem)*alloc_numPrimitives; - PresplitItem *presplitItem = (PresplitItem*)alignedMalloc(presplit_allocation_size,64); - PresplitItem *tmp_presplitItem = (PresplitItem*)alignedMalloc(presplit_allocation_size,64); + avector<PresplitItem> preSplitItem0(numPrimitivesExt); + avector<PresplitItem> preSplitItem1(numPrimitivesExt); /* compute grid */ - const Vec3fa grid_base = pinfo.geomBounds.lower; - const Vec3fa grid_diag = pinfo.geomBounds.size(); - const float grid_extend = max(grid_diag.x,max(grid_diag.y,grid_diag.z)); - const float grid_scale = grid_extend == 0.0f ? 0.0f : GRID_SIZE / grid_extend; - + SplittingGrid grid(pinfo.geomBounds); + /* init presplit items and get total sum */ const float psum = parallel_reduce( size_t(0), numPrimitives, size_t(MIN_STEP_SIZE), 0.0f, [&](const range<size_t>& r) -> float { float sum = 0.0f; for (size_t i=r.begin(); i<r.end(); i++) { - presplitItem[i].index = (unsigned int)i; - const Vec2i mc = computeMC(grid_base,grid_scale,prims[i]); + preSplitItem0[i].index = (unsigned int)i; + const Vec2i mc = grid.computeMC(prims[i]); /* if all bits are equal then we cannot split */ - presplitItem[i].priority = (mc.x != mc.y) ? PresplitItem::compute_priority<Mesh>(prims[i],scene,mc) : 0.0f; + preSplitItem0[i].priority = (mc.x != mc.y) ? PresplitItem::compute_priority(primitiveArea,prims[i],mc) : 0.0f; /* FIXME: sum undeterministic */ - sum += presplitItem[i].priority; + sum += preSplitItem0[i].priority; } return sum; },[](const float& a, const float& b) -> float { return a+b; }); @@ -245,132 +291,178 @@ namespace embree parallel_for( size_t(0), numPrimitives, size_t(MIN_STEP_SIZE), [&](const range<size_t>& r) -> void { for (size_t i=r.begin(); i<r.end(); i++) { - if (presplitItem[i].priority > 0.0f) - { - const float rel_p = (float)numSplitPrimitivesBudget * presplitItem[i].priority * inv_psum; - if (rel_p >= PRIORITY_CUTOFF_THRESHOLD) // need at least a split budget that generates two sub-prims - { - presplitItem[i].priority = max(min(ceilf(logf(rel_p)/logf(2.0f)),(float)MAX_PRESPLITS_PER_PRIMITIVE_LOG),1.0f); - //presplitItem[i].priority = min(floorf(logf(rel_p)/logf(2.0f)),(float)MAX_PRESPLITS_PER_PRIMITIVE_LOG); - assert(presplitItem[i].priority >= 0.0f && presplitItem[i].priority <= (float)MAX_PRESPLITS_PER_PRIMITIVE_LOG); - } - else - presplitItem[i].priority = 0.0f; + if (preSplitItem0[i].priority <= 0.0f) { + preSplitItem0[i].data = 1; + continue; } + + const float rel_p = (float)numSplitPrimitivesBudget * preSplitItem0[i].priority * inv_psum; + if (rel_p < 1) { + preSplitItem0[i].data = 1; + continue; + } + + //preSplitItem0[i].data = max(min(ceilf(rel_p),(float)MAX_PRESPLITS_PER_PRIMITIVE),1.0f); + preSplitItem0[i].data = max(min(ceilf(logf(rel_p)/logf(2.0f)),(float)MAX_PRESPLITS_PER_PRIMITIVE_LOG),1.0f); + preSplitItem0[i].data = 1 << preSplitItem0[i].data; + assert(preSplitItem0[i].data <= MAX_PRESPLITS_PER_PRIMITIVE); } }); - auto isLeft = [&] (const PresplitItem &ref) { return ref.priority < PRIORITY_CUTOFF_THRESHOLD; }; - size_t center = parallel_partitioning(presplitItem,0,numPrimitives,isLeft,1024); + auto isLeft = [&] (const PresplitItem &ref) { return ref.data <= 1; }; + size_t center = parallel_partitioning(preSplitItem0.data(),0,numPrimitives,isLeft,1024); + assert(center <= numPrimitives); /* anything to split ? */ - if (center < numPrimitives) + if (center >= numPrimitives) + return pinfo; + + size_t numPrimitivesToSplit = numPrimitives - center; + assert(preSplitItem0[center].data >= 1.0f); + + /* sort presplit items in ascending order */ + radix_sort_u32(preSplitItem0.data() + center,preSplitItem1.data() + center,numPrimitivesToSplit,1024); + + CHECK_PRESPLIT( + parallel_for( size_t(center+1), numPrimitives, size_t(MIN_STEP_SIZE), [&](const range<size_t>& r) -> void { + for (size_t i=r.begin(); i<r.end(); i++) + assert(preSplitItem0[i-1].data <= preSplitItem0[i].data); + }); + ); + + unsigned int* primOffset0 = (unsigned int*)preSplitItem1.data(); + unsigned int* primOffset1 = (unsigned int*)preSplitItem1.data() + numPrimitivesToSplit; + + /* compute actual number of sub-primitives generated within the [center;numPrimitives-1] range */ + const size_t totalNumSubPrims = parallel_reduce( size_t(center), numPrimitives, size_t(MIN_STEP_SIZE), size_t(0), [&](const range<size_t>& t) -> size_t { + size_t sum = 0; + for (size_t i=t.begin(); i<t.end(); i++) + { + const unsigned int primrefID = preSplitItem0[i].index; + const unsigned int splitprims = preSplitItem0[i].data; + assert(splitprims >= 1 && splitprims <= MAX_PRESPLITS_PER_PRIMITIVE); + + unsigned int numSubPrims = 0; + PrimRef subPrims[MAX_PRESPLITS_PER_PRIMITIVE]; + splitPrimitive(prims[primrefID],splitprims,grid,subPrims,numSubPrims); + assert(numSubPrims); + + numSubPrims--; // can reuse slot + sum+=numSubPrims; + preSplitItem0[i].data = (numSubPrims << 16) | splitprims; + + primOffset0[i-center] = numSubPrims; + } + return sum; + },[](const size_t& a, const size_t& b) -> size_t { return a+b; }); + + /* if we are over budget, need to shrink the range */ + if (totalNumSubPrims > numSplitPrimitivesBudget) { - size_t numPrimitivesToSplit = numPrimitives - center; - assert(presplitItem[center].priority >= 1.0f); - - /* sort presplit items in ascending order */ - radix_sort_u32(presplitItem + center,tmp_presplitItem + center,numPrimitivesToSplit,1024); - - CHECK_PRESPLIT( - parallel_for( size_t(center+1), numPrimitives, size_t(MIN_STEP_SIZE), [&](const range<size_t>& r) -> void { - for (size_t i=r.begin(); i<r.end(); i++) - assert(presplitItem[i-1].priority <= presplitItem[i].priority); - }); - ); - - unsigned int* primOffset0 = (unsigned int*)tmp_presplitItem; - unsigned int* primOffset1 = (unsigned int*)tmp_presplitItem + numPrimitivesToSplit; - - /* compute actual number of sub-primitives generated within the [center;numPrimitives-1] range */ - const size_t totalNumSubPrims = parallel_reduce( size_t(center), numPrimitives, size_t(MIN_STEP_SIZE), size_t(0), [&](const range<size_t>& t) -> size_t { - size_t sum = 0; - for (size_t i=t.begin(); i<t.end(); i++) - { - PrimRef subPrims[MAX_PRESPLITS_PER_PRIMITIVE]; - assert(presplitItem[i].priority >= 1.0f); - const unsigned int primrefID = presplitItem[i].index; - const float prio = presplitItem[i].priority; - const unsigned int geomID = prims[primrefID].geomID(); - const unsigned int primID = prims[primrefID].primID(); - const unsigned int split_levels = (unsigned int)prio; - unsigned int numSubPrims = 0; - splitPrimitive(Splitter,prims[primrefID],geomID,primID,split_levels,grid_base,grid_scale,grid_extend,subPrims,numSubPrims); - assert(numSubPrims); - numSubPrims--; // can reuse slot - sum+=numSubPrims; - presplitItem[i].data = (numSubPrims << MAX_PRESPLITS_PER_PRIMITIVE_LOG) | split_levels; - primOffset0[i-center] = numSubPrims; - } - return sum; - },[](const size_t& a, const size_t& b) -> size_t { return a+b; }); + size_t new_center = numPrimitives-1; + size_t sum = 0; + for (;new_center>=center;new_center--) + { + const unsigned int numSubPrims = preSplitItem0[new_center].data >> 16; + if (unlikely(sum + numSubPrims >= numSplitPrimitivesBudget)) break; + sum += numSubPrims; + } + new_center++; - /* if we are over budget, need to shrink the range */ - if (totalNumSubPrims > numSplitPrimitivesBudget) + primOffset0 += new_center - center; + numPrimitivesToSplit -= new_center - center; + center = new_center; + assert(numPrimitivesToSplit == (numPrimitives - center)); + } + + /* parallel prefix sum to compute offsets for storing sub-primitives */ + const unsigned int offset = parallel_prefix_sum(primOffset0,primOffset1,numPrimitivesToSplit,(unsigned int)0,std::plus<unsigned int>()); + assert(numPrimitives+offset <= numPrimitivesExt); + + /* iterate over range, and split primitives into sub primitives and append them to prims array */ + parallel_for( size_t(center), numPrimitives, size_t(MIN_STEP_SIZE), [&](const range<size_t>& rn) -> void { + for (size_t j=rn.begin(); j<rn.end(); j++) { - size_t new_center = numPrimitives-1; - size_t sum = 0; - for (;new_center>=center;new_center--) - { - const unsigned int numSubPrims = presplitItem[new_center].data >> MAX_PRESPLITS_PER_PRIMITIVE_LOG; - if (unlikely(sum + numSubPrims >= numSplitPrimitivesBudget)) break; - sum += numSubPrims; - } - new_center++; - - primOffset0 += new_center - center; - numPrimitivesToSplit -= new_center - center; - center = new_center; - assert(numPrimitivesToSplit == (numPrimitives - center)); + const unsigned int primrefID = preSplitItem0[j].index; + const unsigned int splitprims = preSplitItem0[j].data & 0xFFFF; + assert(splitprims >= 1 && splitprims <= MAX_PRESPLITS_PER_PRIMITIVE); + + unsigned int numSubPrims = 0; + PrimRef subPrims[MAX_PRESPLITS_PER_PRIMITIVE]; + splitPrimitive(prims[primrefID],splitprims,grid,subPrims,numSubPrims); + + const unsigned int numSubPrimsExpected MAYBE_UNUSED = preSplitItem0[j].data >> 16; + assert(numSubPrims-1 == numSubPrimsExpected); + + const size_t newID = numPrimitives + primOffset1[j-center]; + assert(newID+numSubPrims-1 <= numPrimitivesExt); + + prims[primrefID] = subPrims[0]; + for (size_t i=1;i<numSubPrims;i++) + prims[newID+i-1] = subPrims[i]; } + }); - /* parallel prefix sum to compute offsets for storing sub-primitives */ - const unsigned int offset = parallel_prefix_sum(primOffset0,primOffset1,numPrimitivesToSplit,(unsigned int)0,std::plus<unsigned int>()); - assert(numPrimitives+offset <= alloc_numPrimitives); - - /* iterate over range, and split primitives into sub primitives and append them to prims array */ - parallel_for( size_t(center), numPrimitives, size_t(MIN_STEP_SIZE), [&](const range<size_t>& rn) -> void { - for (size_t j=rn.begin(); j<rn.end(); j++) - { - PrimRef subPrims[MAX_PRESPLITS_PER_PRIMITIVE]; - const unsigned int primrefID = presplitItem[j].index; - const unsigned int geomID = prims[primrefID].geomID(); - const unsigned int primID = prims[primrefID].primID(); - const unsigned int split_levels = presplitItem[j].data & ((unsigned int)(1 << MAX_PRESPLITS_PER_PRIMITIVE_LOG)-1); - - assert(split_levels); - assert(split_levels <= MAX_PRESPLITS_PER_PRIMITIVE_LOG); - unsigned int numSubPrims = 0; - splitPrimitive(Splitter,prims[primrefID],geomID,primID,split_levels,grid_base,grid_scale,grid_extend,subPrims,numSubPrims); - const size_t newID = numPrimitives + primOffset1[j-center]; - assert(newID+numSubPrims-1 <= alloc_numPrimitives); - prims[primrefID] = subPrims[0]; - for (size_t i=1;i<numSubPrims;i++) - prims[newID+i-1] = subPrims[i]; - } - }); - - numPrimitives += offset; - DBG_PRESPLIT( - PRINT(pinfo.size()); - PRINT(numPrimitives); - PRINT((float)numPrimitives/org_numPrimitives)); - } + numPrimitives += offset; /* recompute centroid bounding boxes */ - pinfo = parallel_reduce(size_t(0),numPrimitives,size_t(MIN_STEP_SIZE),PrimInfo(empty),[&] (const range<size_t>& r) -> PrimInfo { + const PrimInfo pinfo1 = parallel_reduce(size_t(0),numPrimitives,size_t(MIN_STEP_SIZE),PrimInfo(empty),[&] (const range<size_t>& r) -> PrimInfo { PrimInfo p(empty); for (size_t j=r.begin(); j<r.end(); j++) p.add_center2(prims[j]); return p; }, [](const PrimInfo& a, const PrimInfo& b) -> PrimInfo { return PrimInfo::merge(a,b); }); - assert(pinfo.size() == numPrimitives); + assert(pinfo1.size() == numPrimitives); - /* free double buffer presplit items */ - alignedFree(tmp_presplitItem); - alignedFree(presplitItem); - return pinfo; + return pinfo1; + } + +#if !defined(RTHWIF_STANDALONE) + + template<typename Mesh, typename SplitterFactory> + PrimInfo createPrimRefArray_presplit(Scene* scene, Geometry::GTypeMask types, bool mblur, size_t numPrimRefs, mvector<PrimRef>& prims, BuildProgressMonitor& progressMonitor) + { + ParallelForForPrefixSumState<PrimInfo> pstate; + Scene::Iterator2 iter(scene,types,mblur); + + /* first try */ + progressMonitor(0); + pstate.init(iter,size_t(1024)); + PrimInfo pinfo = parallel_for_for_prefix_sum0( pstate, iter, PrimInfo(empty), [&](Geometry* mesh, const range<size_t>& r, size_t k, size_t geomID) -> PrimInfo { + return mesh->createPrimRefArray(prims,r,k,(unsigned)geomID); + }, [](const PrimInfo& a, const PrimInfo& b) -> PrimInfo { return PrimInfo::merge(a,b); }); + + /* if we need to filter out geometry, run again */ + if (pinfo.size() != numPrimRefs) + { + progressMonitor(0); + pinfo = parallel_for_for_prefix_sum1( pstate, iter, PrimInfo(empty), [&](Geometry* mesh, const range<size_t>& r, size_t k, size_t geomID, const PrimInfo& base) -> PrimInfo { + return mesh->createPrimRefArray(prims,r,base.size(),(unsigned)geomID); + }, [](const PrimInfo& a, const PrimInfo& b) -> PrimInfo { return PrimInfo::merge(a,b); }); + } + + + SplitterFactory Splitter(scene); + + auto split_primitive = [&] (const PrimRef &prim, + const unsigned int splitprims, + const SplittingGrid& grid, + PrimRef subPrims[MAX_PRESPLITS_PER_PRIMITIVE], + unsigned int& numSubPrims) + { + const auto splitter = Splitter(prim); + splitPrimitive(splitter,prim,splitprims,grid,subPrims,numSubPrims); + }; + + auto primitiveArea = [&] (const PrimRef &ref) { + const unsigned int geomID = ref.geomID(); + const unsigned int primID = ref.primID(); + return ((Mesh*)scene->get(geomID))->projectedPrimitiveArea(primID); + }; + + return createPrimRefArray_presplit(numPrimRefs,prims,pinfo,split_primitive,primitiveArea); } +#endif } } diff --git a/thirdparty/embree/kernels/builders/splitter.h b/thirdparty/embree/kernels/builders/splitter.h index da89d0b178..3daf55e801 100644 --- a/thirdparty/embree/kernels/builders/splitter.h +++ b/thirdparty/embree/kernels/builders/splitter.h @@ -3,8 +3,11 @@ #pragma once +#if !defined(RTHWIF_STANDALONE) #include "../common/scene.h" -#include "../common/primref.h" +#endif + +#include "../builders/primref.h" namespace embree { @@ -15,6 +18,41 @@ namespace embree const size_t dim, const float pos, const Vec3fa (&v)[N+1], + BBox3fa& left_o, + BBox3fa& right_o) + { + BBox3fa left = empty, right = empty; + /* clip triangle to left and right box by processing all edges */ + for (size_t i=0; i<N; i++) + { + const Vec3fa &v0 = v[i]; + const Vec3fa &v1 = v[i+1]; + const float v0d = v0[dim]; + const float v1d = v1[dim]; + + if (v0d <= pos) left. extend(v0); // this point is on left side + if (v0d >= pos) right.extend(v0); // this point is on right side + + if ((v0d < pos && pos < v1d) || (v1d < pos && pos < v0d)) // the edge crosses the splitting location + { + assert((v1d-v0d) != 0.0f); + const float inv_length = 1.0f/(v1d-v0d); + const Vec3fa c = madd(Vec3fa((pos-v0d)*inv_length),v1-v0,v0); + left.extend(c); + right.extend(c); + } + } + + /* clip against current bounds */ + left_o = intersect(left,bounds); + right_o = intersect(right,bounds); + } + + template<size_t N> + __forceinline void splitPolygon(const BBox3fa& bounds, + const size_t dim, + const float pos, + const Vec3fa (&v)[N+1], const Vec3fa (&inv_length)[N], BBox3fa& left_o, BBox3fa& right_o) @@ -78,7 +116,9 @@ namespace embree new (&left_o ) PrimRef(intersect(left ,prim.bounds()),prim.geomID(), prim.primID()); new (&right_o) PrimRef(intersect(right,prim.bounds()),prim.geomID(), prim.primID()); } - + +#if !defined(RTHWIF_STANDALONE) + struct TriangleSplitter { __forceinline TriangleSplitter(const Scene* scene, const PrimRef& prim) @@ -173,6 +213,13 @@ namespace embree __forceinline DummySplitter(const Scene* scene, const PrimRef& prim) { } + + __forceinline void operator() (const PrimRef& prim, const size_t dim, const float pos, PrimRef& left_o, PrimRef& right_o) const { + } + + __forceinline void operator() (const BBox3fa& prim, const size_t dim, const float pos, BBox3fa& left_o, BBox3fa& right_o) const { + } + }; struct DummySplitterFactory @@ -187,7 +234,7 @@ namespace embree private: const Scene* scene; }; - +#endif } } diff --git a/thirdparty/embree/kernels/bvh/bvh.h b/thirdparty/embree/kernels/bvh/bvh.h index 565eec5a58..e0ffb86af9 100644 --- a/thirdparty/embree/kernels/bvh/bvh.h +++ b/thirdparty/embree/kernels/bvh/bvh.h @@ -85,7 +85,7 @@ namespace embree typedef BVHNodeRecord<NodeRef> NodeRecord; typedef BVHNodeRecordMB<NodeRef> NodeRecordMB; typedef BVHNodeRecordMB4D<NodeRef> NodeRecordMB4D; - + public: /*! BVHN default constructor. */ diff --git a/thirdparty/embree/kernels/bvh/bvh4_factory.cpp b/thirdparty/embree/kernels/bvh/bvh4_factory.cpp index 890d5e7b7c..d03940deea 100644 --- a/thirdparty/embree/kernels/bvh/bvh4_factory.cpp +++ b/thirdparty/embree/kernels/bvh/bvh4_factory.cpp @@ -17,6 +17,7 @@ #include "../geometry/subdivpatch1.h" #include "../geometry/object.h" #include "../geometry/instance.h" +#include "../geometry/instance_array.h" #include "../geometry/subgrid.h" #include "../common/accelinstance.h" @@ -66,6 +67,9 @@ namespace embree DECLARE_SYMBOL2(Accel::Intersector1,BVH4InstanceIntersector1); DECLARE_SYMBOL2(Accel::Intersector1,BVH4InstanceMBIntersector1); + DECLARE_SYMBOL2(Accel::Intersector1,BVH4InstanceArrayIntersector1); + DECLARE_SYMBOL2(Accel::Intersector1,BVH4InstanceArrayMBIntersector1); + DECLARE_SYMBOL2(Accel::Intersector1,BVH4GridIntersector1Moeller); DECLARE_SYMBOL2(Accel::Intersector1,BVH4GridMBIntersector1Moeller); DECLARE_SYMBOL2(Accel::Intersector1,BVH4GridIntersector1Pluecker); @@ -104,6 +108,9 @@ namespace embree DECLARE_SYMBOL2(Accel::Intersector4,BVH4InstanceIntersector4Chunk); DECLARE_SYMBOL2(Accel::Intersector4,BVH4InstanceMBIntersector4Chunk); + DECLARE_SYMBOL2(Accel::Intersector4,BVH4InstanceArrayIntersector4Chunk); + DECLARE_SYMBOL2(Accel::Intersector4,BVH4InstanceArrayMBIntersector4Chunk); + DECLARE_SYMBOL2(Accel::Intersector4,BVH4GridIntersector4HybridMoeller); DECLARE_SYMBOL2(Accel::Intersector4,BVH4GridMBIntersector4HybridMoeller); DECLARE_SYMBOL2(Accel::Intersector4,BVH4GridIntersector4HybridPluecker); @@ -142,6 +149,9 @@ namespace embree DECLARE_SYMBOL2(Accel::Intersector8,BVH4InstanceIntersector8Chunk); DECLARE_SYMBOL2(Accel::Intersector8,BVH4InstanceMBIntersector8Chunk); + DECLARE_SYMBOL2(Accel::Intersector8,BVH4InstanceArrayIntersector8Chunk); + DECLARE_SYMBOL2(Accel::Intersector8,BVH4InstanceArrayMBIntersector8Chunk); + DECLARE_SYMBOL2(Accel::Intersector8,BVH4GridIntersector8HybridMoeller); DECLARE_SYMBOL2(Accel::Intersector8,BVH4GridMBIntersector8HybridMoeller); DECLARE_SYMBOL2(Accel::Intersector8,BVH4GridIntersector8HybridPluecker); @@ -180,33 +190,20 @@ namespace embree DECLARE_SYMBOL2(Accel::Intersector16,BVH4InstanceIntersector16Chunk); DECLARE_SYMBOL2(Accel::Intersector16,BVH4InstanceMBIntersector16Chunk); + DECLARE_SYMBOL2(Accel::Intersector16,BVH4InstanceArrayIntersector16Chunk); + DECLARE_SYMBOL2(Accel::Intersector16,BVH4InstanceArrayMBIntersector16Chunk); + DECLARE_SYMBOL2(Accel::Intersector16,BVH4GridIntersector16HybridMoeller); DECLARE_SYMBOL2(Accel::Intersector16,BVH4GridMBIntersector16HybridMoeller); DECLARE_SYMBOL2(Accel::Intersector16,BVH4GridIntersector16HybridPluecker); - DECLARE_SYMBOL2(Accel::IntersectorN,BVH4IntersectorStreamPacketFallback); - - DECLARE_SYMBOL2(Accel::IntersectorN,BVH4Triangle4IntersectorStreamMoeller); - DECLARE_SYMBOL2(Accel::IntersectorN,BVH4Triangle4IntersectorStreamMoellerNoFilter); - DECLARE_SYMBOL2(Accel::IntersectorN,BVH4Triangle4iIntersectorStreamMoeller); - DECLARE_SYMBOL2(Accel::IntersectorN,BVH4Triangle4vIntersectorStreamPluecker); - DECLARE_SYMBOL2(Accel::IntersectorN,BVH4Triangle4iIntersectorStreamPluecker); - - DECLARE_SYMBOL2(Accel::IntersectorN,BVH4Quad4vIntersectorStreamMoeller); - DECLARE_SYMBOL2(Accel::IntersectorN,BVH4Quad4vIntersectorStreamMoellerNoFilter); - DECLARE_SYMBOL2(Accel::IntersectorN,BVH4Quad4iIntersectorStreamMoeller); - DECLARE_SYMBOL2(Accel::IntersectorN,BVH4Quad4vIntersectorStreamPluecker); - DECLARE_SYMBOL2(Accel::IntersectorN,BVH4Quad4iIntersectorStreamPluecker); - - DECLARE_SYMBOL2(Accel::IntersectorN,BVH4VirtualIntersectorStream); - DECLARE_SYMBOL2(Accel::IntersectorN,BVH4InstanceIntersectorStream); - DECLARE_ISA_FUNCTION(Builder*,BVH4BuilderTwoLevelTriangle4MeshSAH,void* COMMA Scene* COMMA bool); DECLARE_ISA_FUNCTION(Builder*,BVH4BuilderTwoLevelTriangle4vMeshSAH,void* COMMA Scene* COMMA bool); DECLARE_ISA_FUNCTION(Builder*,BVH4BuilderTwoLevelTriangle4iMeshSAH,void* COMMA Scene* COMMA bool); DECLARE_ISA_FUNCTION(Builder*,BVH4BuilderTwoLevelQuadMeshSAH,void* COMMA Scene* COMMA bool); DECLARE_ISA_FUNCTION(Builder*,BVH4BuilderTwoLevelVirtualSAH,void* COMMA Scene* COMMA bool); DECLARE_ISA_FUNCTION(Builder*,BVH4BuilderTwoLevelInstanceSAH,void* COMMA Scene* COMMA Geometry::GTypeMask COMMA bool); + DECLARE_ISA_FUNCTION(Builder*,BVH4BuilderTwoLevelInstanceArraySAH,void* COMMA Scene* COMMA Geometry::GTypeMask COMMA bool); DECLARE_ISA_FUNCTION(Builder*,BVH4Curve4vBuilder_OBB_New,void* COMMA Scene* COMMA size_t); DECLARE_ISA_FUNCTION(Builder*,BVH4Curve4iBuilder_OBB_New,void* COMMA Scene* COMMA size_t); @@ -237,7 +234,10 @@ namespace embree DECLARE_ISA_FUNCTION(Builder*,BVH4InstanceSceneBuilderSAH,void* COMMA Scene* COMMA Geometry::GTypeMask); DECLARE_ISA_FUNCTION(Builder*,BVH4InstanceMBSceneBuilderSAH,void* COMMA Scene* COMMA Geometry::GTypeMask); - + + DECLARE_ISA_FUNCTION(Builder*,BVH4InstanceArraySceneBuilderSAH,void* COMMA Scene* COMMA Geometry::GTypeMask); + DECLARE_ISA_FUNCTION(Builder*,BVH4InstanceArrayMBSceneBuilderSAH,void* COMMA Scene* COMMA Geometry::GTypeMask); + DECLARE_ISA_FUNCTION(Builder*,BVH4GridSceneBuilderSAH,void* COMMA Scene* COMMA size_t); DECLARE_ISA_FUNCTION(Builder*,BVH4GridMBSceneBuilderSAH,void* COMMA Scene* COMMA size_t); @@ -266,6 +266,7 @@ namespace embree IF_ENABLED_QUADS (SELECT_SYMBOL_DEFAULT_AVX(features,BVH4BuilderTwoLevelQuadMeshSAH)); IF_ENABLED_USER (SELECT_SYMBOL_DEFAULT_AVX(features,BVH4BuilderTwoLevelVirtualSAH)); IF_ENABLED_INSTANCE (SELECT_SYMBOL_DEFAULT_AVX(features,BVH4BuilderTwoLevelInstanceSAH)); + IF_ENABLED_INSTANCE_ARRAY (SELECT_SYMBOL_DEFAULT_AVX(features,BVH4BuilderTwoLevelInstanceArraySAH)); IF_ENABLED_CURVES_OR_POINTS(SELECT_SYMBOL_DEFAULT_AVX(features,BVH4Curve4vBuilder_OBB_New)); IF_ENABLED_CURVES_OR_POINTS(SELECT_SYMBOL_DEFAULT_AVX(features,BVH4Curve4iBuilder_OBB_New)); @@ -296,7 +297,10 @@ namespace embree IF_ENABLED_INSTANCE(SELECT_SYMBOL_DEFAULT_AVX(features,BVH4InstanceSceneBuilderSAH)); IF_ENABLED_INSTANCE(SELECT_SYMBOL_DEFAULT_AVX(features,BVH4InstanceMBSceneBuilderSAH)); - + + IF_ENABLED_INSTANCE_ARRAY(SELECT_SYMBOL_DEFAULT_AVX(features,BVH4InstanceArraySceneBuilderSAH)); + IF_ENABLED_INSTANCE_ARRAY(SELECT_SYMBOL_DEFAULT_AVX(features,BVH4InstanceArrayMBSceneBuilderSAH)); + IF_ENABLED_GRIDS(SELECT_SYMBOL_DEFAULT_AVX(features,BVH4GridSceneBuilderSAH)); IF_ENABLED_GRIDS(SELECT_SYMBOL_DEFAULT_AVX(features,BVH4GridMBSceneBuilderSAH)); @@ -349,6 +353,9 @@ namespace embree IF_ENABLED_INSTANCE(SELECT_SYMBOL_DEFAULT_SSE42_AVX_AVX2_AVX512(features,BVH4InstanceIntersector1)); IF_ENABLED_INSTANCE(SELECT_SYMBOL_DEFAULT_SSE42_AVX_AVX2_AVX512(features,BVH4InstanceMBIntersector1)); + IF_ENABLED_INSTANCE_ARRAY(SELECT_SYMBOL_DEFAULT_SSE42_AVX_AVX2_AVX512(features,BVH4InstanceArrayIntersector1)); + IF_ENABLED_INSTANCE_ARRAY(SELECT_SYMBOL_DEFAULT_SSE42_AVX_AVX2_AVX512(features,BVH4InstanceArrayMBIntersector1)); + IF_ENABLED_GRIDS(SELECT_SYMBOL_DEFAULT_SSE42_AVX_AVX2_AVX512(features,BVH4GridIntersector1Moeller)); IF_ENABLED_GRIDS(SELECT_SYMBOL_DEFAULT_SSE42_AVX_AVX2_AVX512(features,BVH4GridMBIntersector1Moeller)) IF_ENABLED_GRIDS(SELECT_SYMBOL_DEFAULT_SSE42_AVX_AVX2_AVX512(features,BVH4GridIntersector1Pluecker)); @@ -389,7 +396,10 @@ namespace embree IF_ENABLED_INSTANCE(SELECT_SYMBOL_DEFAULT_SSE42_AVX_AVX2_AVX512(features,BVH4InstanceIntersector4Chunk)); IF_ENABLED_INSTANCE(SELECT_SYMBOL_DEFAULT_SSE42_AVX_AVX2_AVX512(features,BVH4InstanceMBIntersector4Chunk)); - + + IF_ENABLED_INSTANCE_ARRAY(SELECT_SYMBOL_DEFAULT_SSE42_AVX_AVX2_AVX512(features,BVH4InstanceArrayIntersector4Chunk)); + IF_ENABLED_INSTANCE_ARRAY(SELECT_SYMBOL_DEFAULT_SSE42_AVX_AVX2_AVX512(features,BVH4InstanceArrayMBIntersector4Chunk)); + IF_ENABLED_QUADS(SELECT_SYMBOL_DEFAULT_SSE42_AVX_AVX2_AVX512(features,BVH4Quad4vIntersector4HybridMoeller)); IF_ENABLED_GRIDS(SELECT_SYMBOL_DEFAULT_SSE42_AVX_AVX2_AVX512(features,BVH4GridIntersector4HybridMoeller)); @@ -424,13 +434,16 @@ namespace embree IF_ENABLED_SUBDIV(SELECT_SYMBOL_INIT_AVX_AVX2_AVX512(features,BVH4SubdivPatch1Intersector8)); IF_ENABLED_SUBDIV(SELECT_SYMBOL_INIT_AVX_AVX2_AVX512(features,BVH4SubdivPatch1MBIntersector8)); - + IF_ENABLED_USER(SELECT_SYMBOL_INIT_AVX_AVX2_AVX512(features,BVH4VirtualIntersector8Chunk)); IF_ENABLED_USER(SELECT_SYMBOL_INIT_AVX_AVX2_AVX512(features,BVH4VirtualMBIntersector8Chunk)); IF_ENABLED_INSTANCE(SELECT_SYMBOL_INIT_AVX_AVX2_AVX512(features,BVH4InstanceIntersector8Chunk)); IF_ENABLED_INSTANCE(SELECT_SYMBOL_INIT_AVX_AVX2_AVX512(features,BVH4InstanceMBIntersector8Chunk)); + IF_ENABLED_INSTANCE_ARRAY(SELECT_SYMBOL_INIT_AVX_AVX2_AVX512(features,BVH4InstanceArrayIntersector8Chunk)); + IF_ENABLED_INSTANCE_ARRAY(SELECT_SYMBOL_INIT_AVX_AVX2_AVX512(features,BVH4InstanceArrayMBIntersector8Chunk)); + IF_ENABLED_GRIDS(SELECT_SYMBOL_INIT_AVX_AVX2_AVX512(features,BVH4GridIntersector8HybridMoeller)); IF_ENABLED_GRIDS(SELECT_SYMBOL_INIT_AVX_AVX2_AVX512(features,BVH4GridMBIntersector8HybridMoeller)); IF_ENABLED_GRIDS(SELECT_SYMBOL_INIT_AVX_AVX2_AVX512(features,BVH4GridIntersector8HybridPluecker)); @@ -470,29 +483,13 @@ namespace embree IF_ENABLED_INSTANCE(SELECT_SYMBOL_INIT_AVX512(features,BVH4InstanceIntersector16Chunk)); IF_ENABLED_INSTANCE(SELECT_SYMBOL_INIT_AVX512(features,BVH4InstanceMBIntersector16Chunk)); + IF_ENABLED_INSTANCE_ARRAY(SELECT_SYMBOL_INIT_AVX512(features,BVH4InstanceArrayIntersector16Chunk)); + IF_ENABLED_INSTANCE_ARRAY(SELECT_SYMBOL_INIT_AVX512(features,BVH4InstanceArrayMBIntersector16Chunk)); + IF_ENABLED_GRIDS(SELECT_SYMBOL_INIT_AVX512(features,BVH4GridIntersector16HybridMoeller)); IF_ENABLED_GRIDS(SELECT_SYMBOL_INIT_AVX512(features,BVH4GridMBIntersector16HybridMoeller)); IF_ENABLED_GRIDS(SELECT_SYMBOL_INIT_AVX512(features,BVH4GridIntersector16HybridPluecker)); - /* select stream intersectors */ - SELECT_SYMBOL_DEFAULT_SSE42_AVX_AVX2_AVX512(features,BVH4IntersectorStreamPacketFallback); - - IF_ENABLED_TRIS(SELECT_SYMBOL_DEFAULT_SSE42_AVX_AVX2_AVX512(features,BVH4Triangle4IntersectorStreamMoeller)); - IF_ENABLED_TRIS(SELECT_SYMBOL_DEFAULT_SSE42_AVX_AVX2_AVX512(features,BVH4Triangle4IntersectorStreamMoellerNoFilter)); - IF_ENABLED_TRIS(SELECT_SYMBOL_DEFAULT_SSE42_AVX_AVX2_AVX512(features,BVH4Triangle4iIntersectorStreamMoeller)); - IF_ENABLED_TRIS(SELECT_SYMBOL_DEFAULT_SSE42_AVX_AVX2_AVX512(features,BVH4Triangle4vIntersectorStreamPluecker)); - IF_ENABLED_TRIS(SELECT_SYMBOL_DEFAULT_SSE42_AVX_AVX2_AVX512(features,BVH4Triangle4iIntersectorStreamPluecker)); - - IF_ENABLED_QUADS(SELECT_SYMBOL_DEFAULT_SSE42_AVX_AVX2_AVX512(features,BVH4Quad4vIntersectorStreamMoeller)); - IF_ENABLED_QUADS(SELECT_SYMBOL_DEFAULT_SSE42_AVX_AVX2_AVX512(features,BVH4Quad4vIntersectorStreamMoellerNoFilter)); - IF_ENABLED_QUADS(SELECT_SYMBOL_DEFAULT_SSE42_AVX_AVX2_AVX512(features,BVH4Quad4iIntersectorStreamMoeller)); - IF_ENABLED_QUADS(SELECT_SYMBOL_DEFAULT_SSE42_AVX_AVX2_AVX512(features,BVH4Quad4vIntersectorStreamPluecker)); - IF_ENABLED_QUADS(SELECT_SYMBOL_DEFAULT_SSE42_AVX_AVX2_AVX512(features,BVH4Quad4iIntersectorStreamPluecker)); - - IF_ENABLED_USER(SELECT_SYMBOL_DEFAULT_SSE42_AVX_AVX2_AVX512(features,BVH4VirtualIntersectorStream)); - - IF_ENABLED_INSTANCE(SELECT_SYMBOL_DEFAULT_SSE42_AVX_AVX2_AVX512(features,BVH4InstanceIntersectorStream)); - #endif } @@ -509,7 +506,6 @@ namespace embree intersectors.intersector4 = BVH4OBBVirtualCurveIntersector4Hybrid(); intersectors.intersector8 = BVH4OBBVirtualCurveIntersector8Hybrid(); intersectors.intersector16 = BVH4OBBVirtualCurveIntersector16Hybrid(); - intersectors.intersectorN = BVH4IntersectorStreamPacketFallback(); #endif return intersectors; } @@ -523,7 +519,6 @@ namespace embree intersectors.intersector4 = BVH4OBBVirtualCurveIntersectorRobust4Hybrid(); intersectors.intersector8 = BVH4OBBVirtualCurveIntersectorRobust8Hybrid(); intersectors.intersector16 = BVH4OBBVirtualCurveIntersectorRobust16Hybrid(); - intersectors.intersectorN = BVH4IntersectorStreamPacketFallback(); #endif return intersectors; } @@ -545,7 +540,6 @@ namespace embree intersectors.intersector4 = BVH4OBBVirtualCurveIntersector4HybridMB(); intersectors.intersector8 = BVH4OBBVirtualCurveIntersector8HybridMB(); intersectors.intersector16 = BVH4OBBVirtualCurveIntersector16HybridMB(); - intersectors.intersectorN = BVH4IntersectorStreamPacketFallback(); #endif return intersectors; } @@ -559,7 +553,6 @@ namespace embree intersectors.intersector4 = BVH4OBBVirtualCurveIntersectorRobust4HybridMB(); intersectors.intersector8 = BVH4OBBVirtualCurveIntersectorRobust8HybridMB(); intersectors.intersector16 = BVH4OBBVirtualCurveIntersectorRobust16HybridMB(); - intersectors.intersectorN = BVH4IntersectorStreamPacketFallback(); #endif return intersectors; } @@ -581,8 +574,6 @@ namespace embree intersectors.intersector8_nofilter = BVH4Triangle4Intersector8HybridMoellerNoFilter(); intersectors.intersector16_filter = BVH4Triangle4Intersector16HybridMoeller(); intersectors.intersector16_nofilter = BVH4Triangle4Intersector16HybridMoellerNoFilter(); - intersectors.intersectorN_filter = BVH4Triangle4IntersectorStreamMoeller(); - intersectors.intersectorN_nofilter = BVH4Triangle4IntersectorStreamMoellerNoFilter(); #endif return intersectors; } @@ -597,7 +588,6 @@ namespace embree intersectors.intersector4 = BVH4Triangle4vIntersector4HybridPluecker(); intersectors.intersector8 = BVH4Triangle4vIntersector8HybridPluecker(); intersectors.intersector16 = BVH4Triangle4vIntersector16HybridPluecker(); - intersectors.intersectorN = BVH4Triangle4vIntersectorStreamPluecker(); #endif return intersectors; } @@ -614,7 +604,6 @@ namespace embree intersectors.intersector4 = BVH4Triangle4iIntersector4HybridMoeller(); intersectors.intersector8 = BVH4Triangle4iIntersector8HybridMoeller(); intersectors.intersector16 = BVH4Triangle4iIntersector16HybridMoeller(); - intersectors.intersectorN = BVH4Triangle4iIntersectorStreamMoeller(); #endif return intersectors; } @@ -627,7 +616,6 @@ namespace embree intersectors.intersector4 = BVH4Triangle4iIntersector4HybridPluecker(); intersectors.intersector8 = BVH4Triangle4iIntersector8HybridPluecker(); intersectors.intersector16 = BVH4Triangle4iIntersector16HybridPluecker(); - intersectors.intersectorN = BVH4Triangle4iIntersectorStreamPluecker(); #endif return intersectors; } @@ -647,7 +635,6 @@ namespace embree intersectors.intersector4 = BVH4Triangle4vMBIntersector4HybridMoeller(); intersectors.intersector8 = BVH4Triangle4vMBIntersector8HybridMoeller(); intersectors.intersector16 = BVH4Triangle4vMBIntersector16HybridMoeller(); - intersectors.intersectorN = BVH4IntersectorStreamPacketFallback(); #endif return intersectors; } @@ -660,7 +647,6 @@ namespace embree intersectors.intersector4 = BVH4Triangle4vMBIntersector4HybridPluecker(); intersectors.intersector8 = BVH4Triangle4vMBIntersector8HybridPluecker(); intersectors.intersector16 = BVH4Triangle4vMBIntersector16HybridPluecker(); - intersectors.intersectorN = BVH4IntersectorStreamPacketFallback(); #endif return intersectors; } @@ -680,7 +666,6 @@ namespace embree intersectors.intersector4 = BVH4Triangle4iMBIntersector4HybridMoeller(); intersectors.intersector8 = BVH4Triangle4iMBIntersector8HybridMoeller(); intersectors.intersector16 = BVH4Triangle4iMBIntersector16HybridMoeller(); - intersectors.intersectorN = BVH4IntersectorStreamPacketFallback(); #endif return intersectors; } @@ -693,7 +678,6 @@ namespace embree intersectors.intersector4 = BVH4Triangle4iMBIntersector4HybridPluecker(); intersectors.intersector8 = BVH4Triangle4iMBIntersector8HybridPluecker(); intersectors.intersector16 = BVH4Triangle4iMBIntersector16HybridPluecker(); - intersectors.intersectorN = BVH4IntersectorStreamPacketFallback(); #endif return intersectors; } @@ -716,8 +700,6 @@ namespace embree intersectors.intersector8_nofilter = BVH4Quad4vIntersector8HybridMoellerNoFilter(); intersectors.intersector16_filter = BVH4Quad4vIntersector16HybridMoeller(); intersectors.intersector16_nofilter = BVH4Quad4vIntersector16HybridMoellerNoFilter(); - intersectors.intersectorN_filter = BVH4Quad4vIntersectorStreamMoeller(); - intersectors.intersectorN_nofilter = BVH4Quad4vIntersectorStreamMoellerNoFilter(); #endif return intersectors; } @@ -730,7 +712,6 @@ namespace embree intersectors.intersector4 = BVH4Quad4vIntersector4HybridPluecker(); intersectors.intersector8 = BVH4Quad4vIntersector8HybridPluecker(); intersectors.intersector16 = BVH4Quad4vIntersector16HybridPluecker(); - intersectors.intersectorN = BVH4Quad4vIntersectorStreamPluecker(); #endif return intersectors; } @@ -750,7 +731,6 @@ namespace embree intersectors.intersector4 = BVH4Quad4iIntersector4HybridMoeller(); intersectors.intersector8 = BVH4Quad4iIntersector8HybridMoeller(); intersectors.intersector16= BVH4Quad4iIntersector16HybridMoeller(); - intersectors.intersectorN = BVH4Quad4iIntersectorStreamMoeller(); #endif return intersectors; } @@ -763,7 +743,6 @@ namespace embree intersectors.intersector4 = BVH4Quad4iIntersector4HybridPluecker(); intersectors.intersector8 = BVH4Quad4iIntersector8HybridPluecker(); intersectors.intersector16= BVH4Quad4iIntersector16HybridPluecker(); - intersectors.intersectorN = BVH4Quad4iIntersectorStreamPluecker(); #endif return intersectors; } @@ -783,7 +762,6 @@ namespace embree intersectors.intersector4 = BVH4Quad4iMBIntersector4HybridMoeller(); intersectors.intersector8 = BVH4Quad4iMBIntersector8HybridMoeller(); intersectors.intersector16= BVH4Quad4iMBIntersector16HybridMoeller(); - intersectors.intersectorN = BVH4IntersectorStreamPacketFallback(); #endif return intersectors; } @@ -796,7 +774,6 @@ namespace embree intersectors.intersector4 = BVH4Quad4iMBIntersector4HybridPluecker(); intersectors.intersector8 = BVH4Quad4iMBIntersector8HybridPluecker(); intersectors.intersector16= BVH4Quad4iMBIntersector16HybridPluecker(); - intersectors.intersectorN = BVH4IntersectorStreamPacketFallback(); #endif return intersectors; } @@ -829,7 +806,6 @@ namespace embree intersectors.intersector4 = BVH4VirtualIntersector4Chunk(); intersectors.intersector8 = BVH4VirtualIntersector8Chunk(); intersectors.intersector16 = BVH4VirtualIntersector16Chunk(); - intersectors.intersectorN = BVH4VirtualIntersectorStream(); #endif intersectors.collider = BVH4ColliderUserGeom(); return intersectors; @@ -844,7 +820,6 @@ namespace embree intersectors.intersector4 = BVH4VirtualMBIntersector4Chunk(); intersectors.intersector8 = BVH4VirtualMBIntersector8Chunk(); intersectors.intersector16 = BVH4VirtualMBIntersector16Chunk(); - intersectors.intersectorN = BVH4IntersectorStreamPacketFallback(); #endif return intersectors; } @@ -858,7 +833,6 @@ namespace embree intersectors.intersector4 = BVH4InstanceIntersector4Chunk(); intersectors.intersector8 = BVH4InstanceIntersector8Chunk(); intersectors.intersector16 = BVH4InstanceIntersector16Chunk(); - intersectors.intersectorN = BVH4InstanceIntersectorStream(); #endif return intersectors; } @@ -872,7 +846,32 @@ namespace embree intersectors.intersector4 = BVH4InstanceMBIntersector4Chunk(); intersectors.intersector8 = BVH4InstanceMBIntersector8Chunk(); intersectors.intersector16 = BVH4InstanceMBIntersector16Chunk(); - intersectors.intersectorN = BVH4IntersectorStreamPacketFallback(); +#endif + return intersectors; + } + + Accel::Intersectors BVH4Factory::BVH4InstanceArrayIntersectors(BVH4* bvh) + { + Accel::Intersectors intersectors; + intersectors.ptr = bvh; + intersectors.intersector1 = BVH4InstanceArrayIntersector1(); +#if defined (EMBREE_RAY_PACKETS) + intersectors.intersector4 = BVH4InstanceArrayIntersector4Chunk(); + intersectors.intersector8 = BVH4InstanceArrayIntersector8Chunk(); + intersectors.intersector16 = BVH4InstanceArrayIntersector16Chunk(); +#endif + return intersectors; + } + + Accel::Intersectors BVH4Factory::BVH4InstanceArrayMBIntersectors(BVH4* bvh) + { + Accel::Intersectors intersectors; + intersectors.ptr = bvh; + intersectors.intersector1 = BVH4InstanceArrayMBIntersector1(); +#if defined (EMBREE_RAY_PACKETS) + intersectors.intersector4 = BVH4InstanceArrayMBIntersector4Chunk(); + intersectors.intersector8 = BVH4InstanceArrayMBIntersector8Chunk(); + intersectors.intersector16 = BVH4InstanceArrayMBIntersector16Chunk(); #endif return intersectors; } @@ -886,7 +885,6 @@ namespace embree intersectors.intersector4 = BVH4SubdivPatch1Intersector4(); intersectors.intersector8 = BVH4SubdivPatch1Intersector8(); intersectors.intersector16 = BVH4SubdivPatch1Intersector16(); - intersectors.intersectorN = BVH4IntersectorStreamPacketFallback(); #endif return intersectors; } @@ -900,7 +898,6 @@ namespace embree intersectors.intersector4 = BVH4SubdivPatch1MBIntersector4(); intersectors.intersector8 = BVH4SubdivPatch1MBIntersector8(); intersectors.intersector16 = BVH4SubdivPatch1MBIntersector16(); - intersectors.intersectorN = BVH4IntersectorStreamPacketFallback(); #endif return intersectors; } @@ -1255,6 +1252,35 @@ namespace embree return new AccelInstance(accel,builder,intersectors); } + Accel* BVH4Factory::BVH4InstanceArray(Scene* scene, BuildVariant bvariant) + { + BVH4* accel = new BVH4(InstanceArrayPrimitive::type,scene); + Accel::Intersectors intersectors = BVH4InstanceArrayIntersectors(accel); + auto gtype = Geometry::MTY_INSTANCE_ARRAY; + + Builder* builder = nullptr; + if (scene->device->object_builder == "default") { + switch (bvariant) { + case BuildVariant::STATIC : builder = BVH4InstanceArraySceneBuilderSAH(accel,scene,gtype); break; + case BuildVariant::DYNAMIC : builder = BVH4BuilderTwoLevelInstanceArraySAH(accel,scene,gtype,false); break; + case BuildVariant::HIGH_QUALITY: assert(false); break; + } + } + else if (scene->device->object_builder == "sah") { builder = BVH4InstanceArraySceneBuilderSAH(accel,scene,gtype); } + else if (scene->device->object_builder == "dynamic") { builder = BVH4BuilderTwoLevelInstanceArraySAH(accel,scene,gtype,false); } + else throw_RTCError(RTC_ERROR_INVALID_ARGUMENT,"unknown builder "+scene->device->object_builder+" for BVH4<Object>"); + + return new AccelInstance(accel,builder,intersectors); + } + + Accel* BVH4Factory::BVH4InstanceArrayMB(Scene* scene) + { + BVH4* accel = new BVH4(InstanceArrayPrimitive::type,scene); + Accel::Intersectors intersectors = BVH4InstanceArrayMBIntersectors(accel); + Builder* builder = BVH4InstanceArrayMBSceneBuilderSAH(accel,scene,Geometry::MTY_INSTANCE_ARRAY); + return new AccelInstance(accel,builder,intersectors); + } + Accel::Intersectors BVH4Factory::BVH4GridIntersectors(BVH4* bvh, IntersectVariant ivariant) { Accel::Intersectors intersectors; @@ -1266,7 +1292,6 @@ namespace embree intersectors.intersector4 = BVH4GridIntersector4HybridMoeller(); intersectors.intersector8 = BVH4GridIntersector8HybridMoeller(); intersectors.intersector16 = BVH4GridIntersector16HybridMoeller(); - intersectors.intersectorN = BVH4IntersectorStreamPacketFallback(); #endif } else /* if (ivariant == IntersectVariant::ROBUST) */ @@ -1276,7 +1301,6 @@ namespace embree intersectors.intersector4 = BVH4GridIntersector4HybridPluecker(); intersectors.intersector8 = BVH4GridIntersector8HybridPluecker(); intersectors.intersector16 = BVH4GridIntersector16HybridPluecker(); - intersectors.intersectorN = BVH4IntersectorStreamPacketFallback(); #endif } return intersectors; @@ -1291,7 +1315,6 @@ namespace embree intersectors.intersector4 = BVH4GridMBIntersector4HybridMoeller(); intersectors.intersector8 = BVH4GridMBIntersector8HybridMoeller(); intersectors.intersector16 = BVH4GridMBIntersector16HybridMoeller(); - intersectors.intersectorN = BVH4IntersectorStreamPacketFallback(); #endif return intersectors; } diff --git a/thirdparty/embree/kernels/bvh/bvh4_factory.h b/thirdparty/embree/kernels/bvh/bvh4_factory.h index 30973971a4..abf51dd108 100644 --- a/thirdparty/embree/kernels/bvh/bvh4_factory.h +++ b/thirdparty/embree/kernels/bvh/bvh4_factory.h @@ -48,6 +48,9 @@ namespace embree Accel* BVH4Instance(Scene* scene, bool isExpensive, BuildVariant bvariant = BuildVariant::STATIC); Accel* BVH4InstanceMB(Scene* scene, bool isExpensive); + Accel* BVH4InstanceArray(Scene* scene, BuildVariant bvariant = BuildVariant::STATIC); + Accel* BVH4InstanceArrayMB(Scene* scene); + Accel* BVH4Grid(Scene* scene, BuildVariant bvariant = BuildVariant::STATIC, IntersectVariant ivariant = IntersectVariant::FAST); Accel* BVH4GridMB(Scene* scene, BuildVariant bvariant = BuildVariant::STATIC, IntersectVariant ivariant = IntersectVariant::FAST); @@ -77,7 +80,10 @@ namespace embree Accel::Intersectors BVH4InstanceIntersectors(BVH4* bvh); Accel::Intersectors BVH4InstanceMBIntersectors(BVH4* bvh); - + + Accel::Intersectors BVH4InstanceArrayIntersectors(BVH4* bvh); + Accel::Intersectors BVH4InstanceArrayMBIntersectors(BVH4* bvh); + Accel::Intersectors BVH4SubdivPatch1Intersectors(BVH4* bvh); Accel::Intersectors BVH4SubdivPatch1MBIntersectors(BVH4* bvh); @@ -122,7 +128,10 @@ namespace embree DEFINE_SYMBOL2(Accel::Intersector1,BVH4InstanceIntersector1); DEFINE_SYMBOL2(Accel::Intersector1,BVH4InstanceMBIntersector1); - + + DEFINE_SYMBOL2(Accel::Intersector1,BVH4InstanceArrayIntersector1); + DEFINE_SYMBOL2(Accel::Intersector1,BVH4InstanceArrayMBIntersector1); + DEFINE_SYMBOL2(Accel::Intersector1,BVH4GridIntersector1Moeller); DEFINE_SYMBOL2(Accel::Intersector1,BVH4GridMBIntersector1Moeller); DEFINE_SYMBOL2(Accel::Intersector1,BVH4GridIntersector1Pluecker); @@ -161,6 +170,9 @@ namespace embree DEFINE_SYMBOL2(Accel::Intersector4,BVH4InstanceIntersector4Chunk); DEFINE_SYMBOL2(Accel::Intersector4,BVH4InstanceMBIntersector4Chunk); + DEFINE_SYMBOL2(Accel::Intersector4,BVH4InstanceArrayIntersector4Chunk); + DEFINE_SYMBOL2(Accel::Intersector4,BVH4InstanceArrayMBIntersector4Chunk); + DEFINE_SYMBOL2(Accel::Intersector4,BVH4GridIntersector4HybridMoeller); DEFINE_SYMBOL2(Accel::Intersector4,BVH4GridMBIntersector4HybridMoeller); DEFINE_SYMBOL2(Accel::Intersector4,BVH4GridIntersector4HybridPluecker); @@ -201,6 +213,9 @@ namespace embree DEFINE_SYMBOL2(Accel::Intersector8,BVH4InstanceIntersector8Chunk); DEFINE_SYMBOL2(Accel::Intersector8,BVH4InstanceMBIntersector8Chunk); + DEFINE_SYMBOL2(Accel::Intersector8,BVH4InstanceArrayIntersector8Chunk); + DEFINE_SYMBOL2(Accel::Intersector8,BVH4InstanceArrayMBIntersector8Chunk); + DEFINE_SYMBOL2(Accel::Intersector8,BVH4GridIntersector8HybridMoeller); DEFINE_SYMBOL2(Accel::Intersector8,BVH4GridMBIntersector8HybridMoeller); DEFINE_SYMBOL2(Accel::Intersector8,BVH4GridIntersector8HybridPluecker); @@ -241,30 +256,13 @@ namespace embree DEFINE_SYMBOL2(Accel::Intersector16,BVH4InstanceIntersector16Chunk); DEFINE_SYMBOL2(Accel::Intersector16,BVH4InstanceMBIntersector16Chunk); + DEFINE_SYMBOL2(Accel::Intersector16,BVH4InstanceArrayIntersector16Chunk); + DEFINE_SYMBOL2(Accel::Intersector16,BVH4InstanceArrayMBIntersector16Chunk); + DEFINE_SYMBOL2(Accel::Intersector16,BVH4GridIntersector16HybridMoeller); DEFINE_SYMBOL2(Accel::Intersector16,BVH4GridMBIntersector16HybridMoeller); DEFINE_SYMBOL2(Accel::Intersector16,BVH4GridIntersector16HybridPluecker); - // ============== - - DEFINE_SYMBOL2(Accel::IntersectorN, BVH4IntersectorStreamPacketFallback); - - DEFINE_SYMBOL2(Accel::IntersectorN, BVH4Triangle4IntersectorStreamMoeller); - DEFINE_SYMBOL2(Accel::IntersectorN, BVH4Triangle4IntersectorStreamMoellerNoFilter); - DEFINE_SYMBOL2(Accel::IntersectorN, BVH4Triangle4iIntersectorStreamMoeller); - DEFINE_SYMBOL2(Accel::IntersectorN, BVH4Triangle4vIntersectorStreamPluecker); - DEFINE_SYMBOL2(Accel::IntersectorN, BVH4Triangle4iIntersectorStreamPluecker); - - DEFINE_SYMBOL2(Accel::IntersectorN, BVH4Quad4vIntersectorStreamMoeller); - DEFINE_SYMBOL2(Accel::IntersectorN, BVH4Quad4vIntersectorStreamMoellerNoFilter); - DEFINE_SYMBOL2(Accel::IntersectorN, BVH4Quad4iIntersectorStreamMoeller); - DEFINE_SYMBOL2(Accel::IntersectorN, BVH4Quad4vIntersectorStreamPluecker); - DEFINE_SYMBOL2(Accel::IntersectorN, BVH4Quad4iIntersectorStreamPluecker); - - DEFINE_SYMBOL2(Accel::IntersectorN,BVH4VirtualIntersectorStream); - - DEFINE_SYMBOL2(Accel::IntersectorN,BVH4InstanceIntersectorStream); - // SAH scene builders private: DEFINE_ISA_FUNCTION(Builder*,BVH4Curve4vBuilder_OBB_New,void* COMMA Scene* COMMA size_t); @@ -294,6 +292,9 @@ namespace embree DEFINE_ISA_FUNCTION(Builder*,BVH4InstanceSceneBuilderSAH,void* COMMA Scene* COMMA Geometry::GTypeMask); DEFINE_ISA_FUNCTION(Builder*,BVH4InstanceMBSceneBuilderSAH,void* COMMA Scene* COMMA Geometry::GTypeMask); + DEFINE_ISA_FUNCTION(Builder*,BVH4InstanceArraySceneBuilderSAH,void* COMMA Scene* COMMA Geometry::GTypeMask); + DEFINE_ISA_FUNCTION(Builder*,BVH4InstanceArrayMBSceneBuilderSAH,void* COMMA Scene* COMMA Geometry::GTypeMask); + DEFINE_ISA_FUNCTION(Builder*,BVH4GridSceneBuilderSAH,void* COMMA Scene* COMMA size_t); DEFINE_ISA_FUNCTION(Builder*,BVH4GridMBSceneBuilderSAH,void* COMMA Scene* COMMA size_t); @@ -312,5 +313,6 @@ namespace embree DEFINE_ISA_FUNCTION(Builder*,BVH4BuilderTwoLevelQuadMeshSAH,void* COMMA Scene* COMMA bool); DEFINE_ISA_FUNCTION(Builder*,BVH4BuilderTwoLevelVirtualSAH,void* COMMA Scene* COMMA bool); DEFINE_ISA_FUNCTION(Builder*,BVH4BuilderTwoLevelInstanceSAH,void* COMMA Scene* COMMA Geometry::GTypeMask COMMA bool); + DEFINE_ISA_FUNCTION(Builder*,BVH4BuilderTwoLevelInstanceArraySAH,void* COMMA Scene* COMMA Geometry::GTypeMask COMMA bool); }; } diff --git a/thirdparty/embree/kernels/bvh/bvh8_factory.cpp b/thirdparty/embree/kernels/bvh/bvh8_factory.cpp index d4521af241..7c0f7565fa 100644 --- a/thirdparty/embree/kernels/bvh/bvh8_factory.cpp +++ b/thirdparty/embree/kernels/bvh/bvh8_factory.cpp @@ -21,6 +21,7 @@ #include "../geometry/subdivpatch1.h" #include "../geometry/object.h" #include "../geometry/instance.h" +#include "../geometry/instance_array.h" #include "../geometry/subgrid.h" #include "../common/accelinstance.h" @@ -66,6 +67,9 @@ namespace embree DECLARE_SYMBOL2(Accel::Intersector1,BVH8InstanceIntersector1); DECLARE_SYMBOL2(Accel::Intersector1,BVH8InstanceMBIntersector1); + DECLARE_SYMBOL2(Accel::Intersector1,BVH8InstanceArrayIntersector1); + DECLARE_SYMBOL2(Accel::Intersector1,BVH8InstanceArrayMBIntersector1); + DECLARE_SYMBOL2(Accel::Intersector1,BVH8GridIntersector1Moeller); DECLARE_SYMBOL2(Accel::Intersector1,BVH8GridMBIntersector1Moeller); DECLARE_SYMBOL2(Accel::Intersector1,BVH8GridIntersector1Pluecker); @@ -101,6 +105,9 @@ namespace embree DECLARE_SYMBOL2(Accel::Intersector4,BVH8InstanceIntersector4Chunk); DECLARE_SYMBOL2(Accel::Intersector4,BVH8InstanceMBIntersector4Chunk); + DECLARE_SYMBOL2(Accel::Intersector4,BVH8InstanceArrayIntersector4Chunk); + DECLARE_SYMBOL2(Accel::Intersector4,BVH8InstanceArrayMBIntersector4Chunk); + DECLARE_SYMBOL2(Accel::Intersector4,BVH8GridIntersector4HybridMoeller); DECLARE_SYMBOL2(Accel::Intersector4,BVH8GridIntersector4HybridPluecker); @@ -135,6 +142,9 @@ namespace embree DECLARE_SYMBOL2(Accel::Intersector8,BVH8InstanceIntersector8Chunk); DECLARE_SYMBOL2(Accel::Intersector8,BVH8InstanceMBIntersector8Chunk); + DECLARE_SYMBOL2(Accel::Intersector8,BVH8InstanceArrayIntersector8Chunk); + DECLARE_SYMBOL2(Accel::Intersector8,BVH8InstanceArrayMBIntersector8Chunk); + DECLARE_SYMBOL2(Accel::Intersector8,BVH8GridIntersector8HybridMoeller); DECLARE_SYMBOL2(Accel::Intersector8,BVH8GridIntersector8HybridPluecker); @@ -169,27 +179,12 @@ namespace embree DECLARE_SYMBOL2(Accel::Intersector16,BVH8InstanceIntersector16Chunk); DECLARE_SYMBOL2(Accel::Intersector16,BVH8InstanceMBIntersector16Chunk); + DECLARE_SYMBOL2(Accel::Intersector16,BVH8InstanceArrayIntersector16Chunk); + DECLARE_SYMBOL2(Accel::Intersector16,BVH8InstanceArrayMBIntersector16Chunk); + DECLARE_SYMBOL2(Accel::Intersector16,BVH8GridIntersector16HybridMoeller); DECLARE_SYMBOL2(Accel::Intersector16,BVH8GridIntersector16HybridPluecker); - DECLARE_SYMBOL2(Accel::IntersectorN,BVH8IntersectorStreamPacketFallback); - - DECLARE_SYMBOL2(Accel::IntersectorN,BVH8Triangle4IntersectorStreamMoeller); - DECLARE_SYMBOL2(Accel::IntersectorN,BVH8Triangle4IntersectorStreamMoellerNoFilter); - DECLARE_SYMBOL2(Accel::IntersectorN,BVH8Triangle4iIntersectorStreamMoeller); - DECLARE_SYMBOL2(Accel::IntersectorN,BVH8Triangle4vIntersectorStreamPluecker); - DECLARE_SYMBOL2(Accel::IntersectorN,BVH8Triangle4iIntersectorStreamPluecker); - - DECLARE_SYMBOL2(Accel::IntersectorN,BVH8Quad4vIntersectorStreamMoeller); - DECLARE_SYMBOL2(Accel::IntersectorN,BVH8Quad4vIntersectorStreamMoellerNoFilter); - DECLARE_SYMBOL2(Accel::IntersectorN,BVH8Quad4iIntersectorStreamMoeller); - DECLARE_SYMBOL2(Accel::IntersectorN,BVH8Quad4vIntersectorStreamPluecker); - DECLARE_SYMBOL2(Accel::IntersectorN,BVH8Quad4iIntersectorStreamPluecker); - - DECLARE_SYMBOL2(Accel::IntersectorN,BVH8VirtualIntersectorStream); - - DECLARE_SYMBOL2(Accel::IntersectorN,BVH8InstanceIntersectorStream); - DECLARE_ISA_FUNCTION(Builder*,BVH8Curve8vBuilder_OBB_New,void* COMMA Scene* COMMA size_t); DECLARE_ISA_FUNCTION(Builder*,BVH8OBBCurve8iMBBuilder_OBB,void* COMMA Scene* COMMA size_t); @@ -212,6 +207,9 @@ namespace embree DECLARE_ISA_FUNCTION(Builder*,BVH8InstanceSceneBuilderSAH,void* COMMA Scene* COMMA Geometry::GTypeMask); DECLARE_ISA_FUNCTION(Builder*,BVH8InstanceMBSceneBuilderSAH,void* COMMA Scene* COMMA Geometry::GTypeMask); + DECLARE_ISA_FUNCTION(Builder*,BVH8InstanceArraySceneBuilderSAH,void* COMMA Scene* COMMA Geometry::GTypeMask); + DECLARE_ISA_FUNCTION(Builder*,BVH8InstanceArrayMBSceneBuilderSAH,void* COMMA Scene* COMMA Geometry::GTypeMask); + DECLARE_ISA_FUNCTION(Builder*,BVH8Triangle4SceneBuilderFastSpatialSAH,void* COMMA Scene* COMMA size_t); DECLARE_ISA_FUNCTION(Builder*,BVH8Triangle4vSceneBuilderFastSpatialSAH,void* COMMA Scene* COMMA size_t); DECLARE_ISA_FUNCTION(Builder*,BVH8Quad4vSceneBuilderFastSpatialSAH,void* COMMA Scene* COMMA size_t); @@ -224,6 +222,7 @@ namespace embree DECLARE_ISA_FUNCTION(Builder*,BVH8BuilderTwoLevelQuadMeshSAH,void* COMMA Scene* COMMA bool); DECLARE_ISA_FUNCTION(Builder*,BVH8BuilderTwoLevelVirtualSAH,void* COMMA Scene* COMMA bool); DECLARE_ISA_FUNCTION(Builder*,BVH8BuilderTwoLevelInstanceSAH,void* COMMA Scene* COMMA Geometry::GTypeMask COMMA bool); + DECLARE_ISA_FUNCTION(Builder*,BVH8BuilderTwoLevelInstanceArraySAH,void* COMMA Scene* COMMA Geometry::GTypeMask COMMA bool); BVH8Factory::BVH8Factory(int bfeatures, int ifeatures) { @@ -256,6 +255,9 @@ namespace embree IF_ENABLED_INSTANCE(SELECT_SYMBOL_INIT_AVX(features,BVH8InstanceSceneBuilderSAH)); IF_ENABLED_INSTANCE(SELECT_SYMBOL_INIT_AVX(features,BVH8InstanceMBSceneBuilderSAH)); + + IF_ENABLED_INSTANCE_ARRAY(SELECT_SYMBOL_INIT_AVX(features,BVH8InstanceArraySceneBuilderSAH)); + IF_ENABLED_INSTANCE_ARRAY(SELECT_SYMBOL_INIT_AVX(features,BVH8InstanceArrayMBSceneBuilderSAH)); IF_ENABLED_GRIDS(SELECT_SYMBOL_INIT_AVX(features,BVH8GridSceneBuilderSAH)); IF_ENABLED_GRIDS(SELECT_SYMBOL_INIT_AVX(features,BVH8GridMBSceneBuilderSAH)); @@ -270,6 +272,7 @@ namespace embree IF_ENABLED_QUADS (SELECT_SYMBOL_INIT_AVX(features,BVH8BuilderTwoLevelQuadMeshSAH)); IF_ENABLED_USER (SELECT_SYMBOL_INIT_AVX(features,BVH8BuilderTwoLevelVirtualSAH)); IF_ENABLED_INSTANCE (SELECT_SYMBOL_INIT_AVX(features,BVH8BuilderTwoLevelInstanceSAH)); + IF_ENABLED_INSTANCE_ARRAY (SELECT_SYMBOL_INIT_AVX(features,BVH8BuilderTwoLevelInstanceArraySAH)); } void BVH8Factory::selectIntersectors(int features) @@ -313,6 +316,9 @@ namespace embree IF_ENABLED_INSTANCE(SELECT_SYMBOL_INIT_AVX_AVX2_AVX512(features,BVH8InstanceIntersector1)); IF_ENABLED_INSTANCE(SELECT_SYMBOL_INIT_AVX_AVX2_AVX512(features,BVH8InstanceMBIntersector1)); + IF_ENABLED_INSTANCE_ARRAY(SELECT_SYMBOL_INIT_AVX_AVX2_AVX512(features,BVH8InstanceArrayIntersector1)); + IF_ENABLED_INSTANCE_ARRAY(SELECT_SYMBOL_INIT_AVX_AVX2_AVX512(features,BVH8InstanceArrayMBIntersector1)); + IF_ENABLED_GRIDS(SELECT_SYMBOL_INIT_AVX_AVX2_AVX512(features,BVH8GridIntersector1Moeller)); IF_ENABLED_GRIDS(SELECT_SYMBOL_INIT_AVX_AVX2_AVX512(features,BVH8GridMBIntersector1Moeller)) IF_ENABLED_GRIDS(SELECT_SYMBOL_INIT_AVX_AVX2_AVX512(features,BVH8GridIntersector1Pluecker)); @@ -351,6 +357,9 @@ namespace embree IF_ENABLED_INSTANCE(SELECT_SYMBOL_INIT_AVX_AVX2_AVX512(features,BVH8InstanceIntersector4Chunk)); IF_ENABLED_INSTANCE(SELECT_SYMBOL_INIT_AVX_AVX2_AVX512(features,BVH8InstanceMBIntersector4Chunk)); + IF_ENABLED_INSTANCE_ARRAY(SELECT_SYMBOL_INIT_AVX_AVX2_AVX512(features,BVH8InstanceArrayIntersector4Chunk)); + IF_ENABLED_INSTANCE_ARRAY(SELECT_SYMBOL_INIT_AVX_AVX2_AVX512(features,BVH8InstanceArrayMBIntersector4Chunk)); + IF_ENABLED_GRIDS(SELECT_SYMBOL_INIT_AVX_AVX2_AVX512(features,BVH8GridIntersector4HybridMoeller)); IF_ENABLED_GRIDS(SELECT_SYMBOL_INIT_AVX_AVX2_AVX512(features,BVH8GridIntersector4HybridPluecker)); @@ -386,6 +395,9 @@ namespace embree IF_ENABLED_INSTANCE(SELECT_SYMBOL_INIT_AVX_AVX2_AVX512(features,BVH8InstanceIntersector8Chunk)); IF_ENABLED_INSTANCE(SELECT_SYMBOL_INIT_AVX_AVX2_AVX512(features,BVH8InstanceMBIntersector8Chunk)); + IF_ENABLED_INSTANCE_ARRAY(SELECT_SYMBOL_INIT_AVX_AVX2_AVX512(features,BVH8InstanceArrayIntersector8Chunk)); + IF_ENABLED_INSTANCE_ARRAY(SELECT_SYMBOL_INIT_AVX_AVX2_AVX512(features,BVH8InstanceArrayMBIntersector8Chunk)); + IF_ENABLED_GRIDS(SELECT_SYMBOL_INIT_AVX_AVX2_AVX512(features,BVH8GridIntersector8HybridMoeller)); IF_ENABLED_GRIDS(SELECT_SYMBOL_INIT_AVX_AVX2_AVX512(features,BVH8GridIntersector8HybridPluecker)); @@ -421,29 +433,12 @@ namespace embree IF_ENABLED_INSTANCE(SELECT_SYMBOL_INIT_AVX512(features,BVH8InstanceIntersector16Chunk)); IF_ENABLED_INSTANCE(SELECT_SYMBOL_INIT_AVX512(features,BVH8InstanceMBIntersector16Chunk)); + IF_ENABLED_INSTANCE_ARRAY(SELECT_SYMBOL_INIT_AVX512(features,BVH8InstanceArrayIntersector16Chunk)); + IF_ENABLED_INSTANCE_ARRAY(SELECT_SYMBOL_INIT_AVX512(features,BVH8InstanceArrayMBIntersector16Chunk)); + IF_ENABLED_GRIDS(SELECT_SYMBOL_INIT_AVX512(features,BVH8GridIntersector16HybridMoeller)); IF_ENABLED_GRIDS(SELECT_SYMBOL_INIT_AVX512(features,BVH8GridIntersector16HybridPluecker)); - /* select stream intersectors */ - - SELECT_SYMBOL_INIT_AVX_AVX2_AVX512(features,BVH8IntersectorStreamPacketFallback); - - IF_ENABLED_TRIS(SELECT_SYMBOL_INIT_AVX_AVX2_AVX512(features,BVH8Triangle4IntersectorStreamMoeller)); - IF_ENABLED_TRIS(SELECT_SYMBOL_INIT_AVX_AVX2_AVX512(features,BVH8Triangle4IntersectorStreamMoellerNoFilter)); - IF_ENABLED_TRIS(SELECT_SYMBOL_INIT_AVX_AVX2_AVX512(features,BVH8Triangle4iIntersectorStreamMoeller)); - IF_ENABLED_TRIS(SELECT_SYMBOL_INIT_AVX_AVX2_AVX512(features,BVH8Triangle4vIntersectorStreamPluecker)); - IF_ENABLED_TRIS(SELECT_SYMBOL_INIT_AVX_AVX2_AVX512(features,BVH8Triangle4iIntersectorStreamPluecker)); - - IF_ENABLED_QUADS(SELECT_SYMBOL_INIT_AVX_AVX2_AVX512(features,BVH8Quad4vIntersectorStreamMoeller)); - IF_ENABLED_QUADS(SELECT_SYMBOL_INIT_AVX_AVX2_AVX512(features,BVH8Quad4vIntersectorStreamMoellerNoFilter)); - IF_ENABLED_QUADS(SELECT_SYMBOL_INIT_AVX_AVX2_AVX512(features,BVH8Quad4iIntersectorStreamMoeller)); - IF_ENABLED_QUADS(SELECT_SYMBOL_INIT_AVX_AVX2_AVX512(features,BVH8Quad4vIntersectorStreamPluecker)); - IF_ENABLED_QUADS(SELECT_SYMBOL_INIT_AVX_AVX2_AVX512(features,BVH8Quad4iIntersectorStreamPluecker)); - - IF_ENABLED_USER(SELECT_SYMBOL_INIT_AVX_AVX2_AVX512(features,BVH8VirtualIntersectorStream)); - - IF_ENABLED_INSTANCE(SELECT_SYMBOL_INIT_AVX_AVX2_AVX512(features,BVH8InstanceIntersectorStream)); - #endif } @@ -460,7 +455,6 @@ namespace embree intersectors.intersector4 = BVH8OBBVirtualCurveIntersector4Hybrid(); intersectors.intersector8 = BVH8OBBVirtualCurveIntersector8Hybrid(); intersectors.intersector16 = BVH8OBBVirtualCurveIntersector16Hybrid(); - intersectors.intersectorN = BVH8IntersectorStreamPacketFallback(); #endif return intersectors; } @@ -474,7 +468,6 @@ namespace embree intersectors.intersector4 = BVH8OBBVirtualCurveIntersectorRobust4Hybrid(); intersectors.intersector8 = BVH8OBBVirtualCurveIntersectorRobust8Hybrid(); intersectors.intersector16 = BVH8OBBVirtualCurveIntersectorRobust16Hybrid(); - intersectors.intersectorN = BVH8IntersectorStreamPacketFallback(); #endif return intersectors; } @@ -496,7 +489,6 @@ namespace embree intersectors.intersector4 = BVH8OBBVirtualCurveIntersector4HybridMB(); intersectors.intersector8 = BVH8OBBVirtualCurveIntersector8HybridMB(); intersectors.intersector16 = BVH8OBBVirtualCurveIntersector16HybridMB(); - intersectors.intersectorN = BVH8IntersectorStreamPacketFallback(); #endif return intersectors; } @@ -510,7 +502,6 @@ namespace embree intersectors.intersector4 = BVH8OBBVirtualCurveIntersectorRobust4HybridMB(); intersectors.intersector8 = BVH8OBBVirtualCurveIntersectorRobust8HybridMB(); intersectors.intersector16 = BVH8OBBVirtualCurveIntersectorRobust16HybridMB(); - intersectors.intersectorN = BVH8IntersectorStreamPacketFallback(); #endif return intersectors; } @@ -532,8 +523,6 @@ namespace embree intersectors.intersector8_nofilter = BVH8Triangle4Intersector8HybridMoellerNoFilter(); intersectors.intersector16_filter = BVH8Triangle4Intersector16HybridMoeller(); intersectors.intersector16_nofilter = BVH8Triangle4Intersector16HybridMoellerNoFilter(); - intersectors.intersectorN_filter = BVH8Triangle4IntersectorStreamMoeller(); - intersectors.intersectorN_nofilter = BVH8Triangle4IntersectorStreamMoellerNoFilter(); #endif return intersectors; } @@ -554,7 +543,6 @@ namespace embree intersectors.intersector4 = BVH8Triangle4vIntersector4HybridPluecker(); intersectors.intersector8 = BVH8Triangle4vIntersector8HybridPluecker(); intersectors.intersector16 = BVH8Triangle4vIntersector16HybridPluecker(); - intersectors.intersectorN = BVH8Triangle4vIntersectorStreamPluecker(); #endif return intersectors; } @@ -571,7 +559,6 @@ namespace embree intersectors.intersector4 = BVH8Triangle4iIntersector4HybridMoeller(); intersectors.intersector8 = BVH8Triangle4iIntersector8HybridMoeller(); intersectors.intersector16 = BVH8Triangle4iIntersector16HybridMoeller(); - intersectors.intersectorN = BVH8Triangle4iIntersectorStreamMoeller(); #endif return intersectors; } @@ -584,7 +571,6 @@ namespace embree intersectors.intersector4 = BVH8Triangle4iIntersector4HybridPluecker(); intersectors.intersector8 = BVH8Triangle4iIntersector8HybridPluecker(); intersectors.intersector16 = BVH8Triangle4iIntersector16HybridPluecker(); - intersectors.intersectorN = BVH8Triangle4iIntersectorStreamPluecker(); #endif return intersectors; } @@ -604,7 +590,6 @@ namespace embree intersectors.intersector4 = BVH8Triangle4vMBIntersector4HybridMoeller(); intersectors.intersector8 = BVH8Triangle4vMBIntersector8HybridMoeller(); intersectors.intersector16 = BVH8Triangle4vMBIntersector16HybridMoeller(); - intersectors.intersectorN = BVH8IntersectorStreamPacketFallback(); #endif return intersectors; } @@ -617,7 +602,6 @@ namespace embree intersectors.intersector4 = BVH8Triangle4vMBIntersector4HybridPluecker(); intersectors.intersector8 = BVH8Triangle4vMBIntersector8HybridPluecker(); intersectors.intersector16 = BVH8Triangle4vMBIntersector16HybridPluecker(); - intersectors.intersectorN = BVH8IntersectorStreamPacketFallback(); #endif return intersectors; } @@ -637,7 +621,6 @@ namespace embree intersectors.intersector4 = BVH8Triangle4iMBIntersector4HybridMoeller(); intersectors.intersector8 = BVH8Triangle4iMBIntersector8HybridMoeller(); intersectors.intersector16 = BVH8Triangle4iMBIntersector16HybridMoeller(); - intersectors.intersectorN = BVH8IntersectorStreamPacketFallback(); #endif return intersectors; } @@ -650,7 +633,6 @@ namespace embree intersectors.intersector4 = BVH8Triangle4iMBIntersector4HybridPluecker(); intersectors.intersector8 = BVH8Triangle4iMBIntersector8HybridPluecker(); intersectors.intersector16 = BVH8Triangle4iMBIntersector16HybridPluecker(); - intersectors.intersectorN = BVH8IntersectorStreamPacketFallback(); #endif return intersectors; } @@ -673,8 +655,6 @@ namespace embree intersectors.intersector8_nofilter = BVH8Quad4vIntersector8HybridMoellerNoFilter(); intersectors.intersector16_filter = BVH8Quad4vIntersector16HybridMoeller(); intersectors.intersector16_nofilter = BVH8Quad4vIntersector16HybridMoellerNoFilter(); - intersectors.intersectorN_filter = BVH8Quad4vIntersectorStreamMoeller(); - intersectors.intersectorN_nofilter = BVH8Quad4vIntersectorStreamMoellerNoFilter(); #endif return intersectors; } @@ -687,7 +667,6 @@ namespace embree intersectors.intersector4 = BVH8Quad4vIntersector4HybridPluecker(); intersectors.intersector8 = BVH8Quad4vIntersector8HybridPluecker(); intersectors.intersector16 = BVH8Quad4vIntersector16HybridPluecker(); - intersectors.intersectorN = BVH8Quad4vIntersectorStreamPluecker(); #endif return intersectors; } @@ -707,7 +686,6 @@ namespace embree intersectors.intersector4 = BVH8Quad4iIntersector4HybridMoeller(); intersectors.intersector8 = BVH8Quad4iIntersector8HybridMoeller(); intersectors.intersector16 = BVH8Quad4iIntersector16HybridMoeller(); - intersectors.intersectorN = BVH8Quad4iIntersectorStreamMoeller(); #endif return intersectors; } @@ -720,7 +698,6 @@ namespace embree intersectors.intersector4 = BVH8Quad4iIntersector4HybridPluecker(); intersectors.intersector8 = BVH8Quad4iIntersector8HybridPluecker(); intersectors.intersector16 = BVH8Quad4iIntersector16HybridPluecker(); - intersectors.intersectorN = BVH8Quad4iIntersectorStreamPluecker(); #endif return intersectors; } @@ -740,7 +717,6 @@ namespace embree intersectors.intersector4 = BVH8Quad4iMBIntersector4HybridMoeller(); intersectors.intersector8 = BVH8Quad4iMBIntersector8HybridMoeller(); intersectors.intersector16 = BVH8Quad4iMBIntersector16HybridMoeller(); - intersectors.intersectorN = BVH8IntersectorStreamPacketFallback(); #endif return intersectors; } @@ -753,7 +729,6 @@ namespace embree intersectors.intersector4 = BVH8Quad4iMBIntersector4HybridPluecker(); intersectors.intersector8 = BVH8Quad4iMBIntersector8HybridPluecker(); intersectors.intersector16 = BVH8Quad4iMBIntersector16HybridPluecker(); - intersectors.intersectorN = BVH8IntersectorStreamPacketFallback(); #endif return intersectors; } @@ -794,7 +769,6 @@ namespace embree intersectors.intersector4 = BVH8VirtualIntersector4Chunk(); intersectors.intersector8 = BVH8VirtualIntersector8Chunk(); intersectors.intersector16 = BVH8VirtualIntersector16Chunk(); - intersectors.intersectorN = BVH8VirtualIntersectorStream(); #endif intersectors.collider = BVH8ColliderUserGeom(); return intersectors; @@ -809,7 +783,6 @@ namespace embree intersectors.intersector4 = BVH8VirtualMBIntersector4Chunk(); intersectors.intersector8 = BVH8VirtualMBIntersector8Chunk(); intersectors.intersector16 = BVH8VirtualMBIntersector16Chunk(); - intersectors.intersectorN = BVH8IntersectorStreamPacketFallback(); #endif return intersectors; } @@ -823,7 +796,19 @@ namespace embree intersectors.intersector4 = BVH8InstanceIntersector4Chunk(); intersectors.intersector8 = BVH8InstanceIntersector8Chunk(); intersectors.intersector16 = BVH8InstanceIntersector16Chunk(); - intersectors.intersectorN = BVH8InstanceIntersectorStream(); +#endif + return intersectors; + } + + Accel::Intersectors BVH8Factory::BVH8InstanceArrayIntersectors(BVH8* bvh) + { + Accel::Intersectors intersectors; + intersectors.ptr = bvh; + intersectors.intersector1 = BVH8InstanceArrayIntersector1(); +#if defined (EMBREE_RAY_PACKETS) + intersectors.intersector4 = BVH8InstanceArrayIntersector4Chunk(); + intersectors.intersector8 = BVH8InstanceArrayIntersector8Chunk(); + intersectors.intersector16 = BVH8InstanceArrayIntersector16Chunk(); #endif return intersectors; } @@ -837,7 +822,19 @@ namespace embree intersectors.intersector4 = BVH8InstanceMBIntersector4Chunk(); intersectors.intersector8 = BVH8InstanceMBIntersector8Chunk(); intersectors.intersector16 = BVH8InstanceMBIntersector16Chunk(); - intersectors.intersectorN = BVH8IntersectorStreamPacketFallback(); +#endif + return intersectors; + } + + Accel::Intersectors BVH8Factory::BVH8InstanceArrayMBIntersectors(BVH8* bvh) + { + Accel::Intersectors intersectors; + intersectors.ptr = bvh; + intersectors.intersector1 = BVH8InstanceArrayMBIntersector1(); +#if defined (EMBREE_RAY_PACKETS) + intersectors.intersector4 = BVH8InstanceArrayMBIntersector4Chunk(); + intersectors.intersector8 = BVH8InstanceArrayMBIntersector8Chunk(); + intersectors.intersector16 = BVH8InstanceArrayMBIntersector16Chunk(); #endif return intersectors; } @@ -1086,6 +1083,28 @@ namespace embree return new AccelInstance(accel,builder,intersectors); } + Accel* BVH8Factory::BVH8InstanceArray(Scene* scene, BuildVariant bvariant) + { + BVH8* accel = new BVH8(InstanceArrayPrimitive::type,scene); + Accel::Intersectors intersectors = BVH8InstanceArrayIntersectors(accel); + auto gtype = Geometry::MTY_INSTANCE_ARRAY; + // Builder* builder = BVH8InstanceSceneBuilderSAH(accel,scene,gtype); + + Builder* builder = nullptr; + if (scene->device->object_builder == "default") { + switch (bvariant) { + case BuildVariant::STATIC : builder = BVH8InstanceArraySceneBuilderSAH(accel,scene,gtype); break; + case BuildVariant::DYNAMIC : builder = BVH8BuilderTwoLevelInstanceArraySAH(accel,scene,gtype,false); break; + case BuildVariant::HIGH_QUALITY: assert(false); break; + } + } + else if (scene->device->object_builder == "sah") builder = BVH8InstanceArraySceneBuilderSAH(accel,scene,gtype); + else if (scene->device->object_builder == "dynamic") builder = BVH8BuilderTwoLevelInstanceArraySAH(accel,scene,gtype,false); + else throw_RTCError(RTC_ERROR_INVALID_ARGUMENT,"unknown builder "+scene->device->object_builder+" for BVH8<Object>"); + + return new AccelInstance(accel,builder,intersectors); + } + Accel* BVH8Factory::BVH8InstanceMB(Scene* scene, bool isExpensive) { BVH8* accel = new BVH8(InstancePrimitive::type,scene); @@ -1095,6 +1114,15 @@ namespace embree return new AccelInstance(accel,builder,intersectors); } + Accel* BVH8Factory::BVH8InstanceArrayMB(Scene* scene) + { + BVH8* accel = new BVH8(InstanceArrayPrimitive::type,scene); + Accel::Intersectors intersectors = BVH8InstanceArrayMBIntersectors(accel); + auto gtype = Geometry::MTY_INSTANCE_ARRAY; + Builder* builder = BVH8InstanceArrayMBSceneBuilderSAH(accel,scene,gtype); + return new AccelInstance(accel,builder,intersectors); + } + Accel::Intersectors BVH8Factory::BVH8GridIntersectors(BVH8* bvh, IntersectVariant ivariant) { Accel::Intersectors intersectors; @@ -1106,7 +1134,6 @@ namespace embree intersectors.intersector4 = BVH8GridIntersector4HybridMoeller(); intersectors.intersector8 = BVH8GridIntersector8HybridMoeller(); intersectors.intersector16 = BVH8GridIntersector16HybridMoeller(); - intersectors.intersectorN = BVH8IntersectorStreamPacketFallback(); #endif } else /* if (ivariant == IntersectVariant::ROBUST) */ @@ -1116,7 +1143,6 @@ namespace embree intersectors.intersector4 = BVH8GridIntersector4HybridPluecker(); intersectors.intersector8 = BVH8GridIntersector8HybridPluecker(); intersectors.intersector16 = BVH8GridIntersector16HybridPluecker(); - intersectors.intersectorN = BVH8IntersectorStreamPacketFallback(); #endif } return intersectors; @@ -1131,7 +1157,6 @@ namespace embree intersectors.intersector4 = nullptr; intersectors.intersector8 = nullptr; intersectors.intersector16 = nullptr; - intersectors.intersectorN = nullptr; #endif return intersectors; } diff --git a/thirdparty/embree/kernels/bvh/bvh8_factory.h b/thirdparty/embree/kernels/bvh/bvh8_factory.h index 198d6f1df0..e55310b703 100644 --- a/thirdparty/embree/kernels/bvh/bvh8_factory.h +++ b/thirdparty/embree/kernels/bvh/bvh8_factory.h @@ -39,6 +39,9 @@ namespace embree Accel* BVH8Instance(Scene* scene, bool isExpensive, BuildVariant bvariant = BuildVariant::STATIC); Accel* BVH8InstanceMB(Scene* scene, bool isExpensive); + Accel* BVH8InstanceArray(Scene* scene, BuildVariant bvariant = BuildVariant::STATIC); + Accel* BVH8InstanceArrayMB(Scene* scene); + Accel* BVH8Grid(Scene* scene, BuildVariant bvariant = BuildVariant::STATIC, IntersectVariant ivariant = IntersectVariant::FAST); Accel* BVH8GridMB(Scene* scene, BuildVariant bvariant = BuildVariant::STATIC, IntersectVariant ivariant = IntersectVariant::FAST); @@ -70,6 +73,9 @@ namespace embree Accel::Intersectors BVH8InstanceIntersectors(BVH8* bvh); Accel::Intersectors BVH8InstanceMBIntersectors(BVH8* bvh); + Accel::Intersectors BVH8InstanceArrayIntersectors(BVH8* bvh); + Accel::Intersectors BVH8InstanceArrayMBIntersectors(BVH8* bvh); + Accel::Intersectors BVH8GridIntersectors(BVH8* bvh, IntersectVariant ivariant); Accel::Intersectors BVH8GridMBIntersectors(BVH8* bvh, IntersectVariant ivariant); @@ -111,6 +117,9 @@ namespace embree DEFINE_SYMBOL2(Accel::Intersector1,BVH8InstanceIntersector1); DEFINE_SYMBOL2(Accel::Intersector1,BVH8InstanceMBIntersector1); + DEFINE_SYMBOL2(Accel::Intersector1,BVH8InstanceArrayIntersector1); + DEFINE_SYMBOL2(Accel::Intersector1,BVH8InstanceArrayMBIntersector1); + DEFINE_SYMBOL2(Accel::Intersector1,BVH8GridIntersector1Moeller); DEFINE_SYMBOL2(Accel::Intersector1,BVH8GridMBIntersector1Moeller); DEFINE_SYMBOL2(Accel::Intersector1,BVH8GridIntersector1Pluecker); @@ -145,7 +154,10 @@ namespace embree DEFINE_SYMBOL2(Accel::Intersector4,BVH8InstanceIntersector4Chunk); DEFINE_SYMBOL2(Accel::Intersector4,BVH8InstanceMBIntersector4Chunk); - + + DEFINE_SYMBOL2(Accel::Intersector4,BVH8InstanceArrayIntersector4Chunk); + DEFINE_SYMBOL2(Accel::Intersector4,BVH8InstanceArrayMBIntersector4Chunk); + DEFINE_SYMBOL2(Accel::Intersector4,BVH8GridIntersector4HybridMoeller); DEFINE_SYMBOL2(Accel::Intersector4,BVH8GridIntersector4HybridPluecker); @@ -180,9 +192,12 @@ namespace embree DEFINE_SYMBOL2(Accel::Intersector8,BVH8InstanceIntersector8Chunk); DEFINE_SYMBOL2(Accel::Intersector8,BVH8InstanceMBIntersector8Chunk); + DEFINE_SYMBOL2(Accel::Intersector8,BVH8InstanceArrayIntersector8Chunk); + DEFINE_SYMBOL2(Accel::Intersector8,BVH8InstanceArrayMBIntersector8Chunk); + DEFINE_SYMBOL2(Accel::Intersector8,BVH8GridIntersector8HybridMoeller); DEFINE_SYMBOL2(Accel::Intersector8,BVH8GridIntersector8HybridPluecker); - + DEFINE_SYMBOL2(Accel::Intersector16,BVH8OBBVirtualCurveIntersector16Hybrid); DEFINE_SYMBOL2(Accel::Intersector16,BVH8OBBVirtualCurveIntersector16HybridMB); DEFINE_SYMBOL2(Accel::Intersector16,BVH8OBBVirtualCurveIntersectorRobust16Hybrid); @@ -213,27 +228,12 @@ namespace embree DEFINE_SYMBOL2(Accel::Intersector16,BVH8InstanceIntersector16Chunk); DEFINE_SYMBOL2(Accel::Intersector16,BVH8InstanceMBIntersector16Chunk); - - DEFINE_SYMBOL2(Accel::Intersector16,BVH8GridIntersector16HybridMoeller); - DEFINE_SYMBOL2(Accel::Intersector16,BVH8GridIntersector16HybridPluecker); - - DEFINE_SYMBOL2(Accel::IntersectorN,BVH8IntersectorStreamPacketFallback); - - DEFINE_SYMBOL2(Accel::IntersectorN,BVH8Triangle4IntersectorStreamMoeller); - DEFINE_SYMBOL2(Accel::IntersectorN,BVH8Triangle4IntersectorStreamMoellerNoFilter); - DEFINE_SYMBOL2(Accel::IntersectorN,BVH8Triangle4iIntersectorStreamMoeller); - DEFINE_SYMBOL2(Accel::IntersectorN,BVH8Triangle4vIntersectorStreamPluecker); - DEFINE_SYMBOL2(Accel::IntersectorN,BVH8Triangle4iIntersectorStreamPluecker); - DEFINE_SYMBOL2(Accel::IntersectorN,BVH8Quad4vIntersectorStreamMoeller); - DEFINE_SYMBOL2(Accel::IntersectorN,BVH8Quad4vIntersectorStreamMoellerNoFilter); - DEFINE_SYMBOL2(Accel::IntersectorN,BVH8Quad4iIntersectorStreamMoeller); - DEFINE_SYMBOL2(Accel::IntersectorN,BVH8Quad4vIntersectorStreamPluecker); - DEFINE_SYMBOL2(Accel::IntersectorN,BVH8Quad4iIntersectorStreamPluecker); + DEFINE_SYMBOL2(Accel::Intersector16,BVH8InstanceArrayIntersector16Chunk); + DEFINE_SYMBOL2(Accel::Intersector16,BVH8InstanceArrayMBIntersector16Chunk); - DEFINE_SYMBOL2(Accel::IntersectorN,BVH8VirtualIntersectorStream); - - DEFINE_SYMBOL2(Accel::IntersectorN,BVH8InstanceIntersectorStream); + DEFINE_SYMBOL2(Accel::Intersector16,BVH8GridIntersector16HybridMoeller); + DEFINE_SYMBOL2(Accel::Intersector16,BVH8GridIntersector16HybridPluecker); // SAH scene builders private: @@ -258,6 +258,9 @@ namespace embree DEFINE_ISA_FUNCTION(Builder*,BVH8InstanceSceneBuilderSAH,void* COMMA Scene* COMMA Geometry::GTypeMask); DEFINE_ISA_FUNCTION(Builder*,BVH8InstanceMBSceneBuilderSAH,void* COMMA Scene* COMMA Geometry::GTypeMask); + + DEFINE_ISA_FUNCTION(Builder*,BVH8InstanceArraySceneBuilderSAH,void* COMMA Scene* COMMA Geometry::GTypeMask); + DEFINE_ISA_FUNCTION(Builder*,BVH8InstanceArrayMBSceneBuilderSAH,void* COMMA Scene* COMMA Geometry::GTypeMask); DEFINE_ISA_FUNCTION(Builder*,BVH8GridSceneBuilderSAH,void* COMMA Scene* COMMA size_t); DEFINE_ISA_FUNCTION(Builder*,BVH8GridMBSceneBuilderSAH,void* COMMA Scene* COMMA size_t); @@ -276,5 +279,6 @@ namespace embree DEFINE_ISA_FUNCTION(Builder*,BVH8BuilderTwoLevelQuadMeshSAH,void* COMMA Scene* COMMA bool); DEFINE_ISA_FUNCTION(Builder*,BVH8BuilderTwoLevelVirtualSAH,void* COMMA Scene* COMMA bool); DEFINE_ISA_FUNCTION(Builder*,BVH8BuilderTwoLevelInstanceSAH,void* COMMA Scene* COMMA Geometry::GTypeMask COMMA bool); + DEFINE_ISA_FUNCTION(Builder*,BVH8BuilderTwoLevelInstanceArraySAH,void* COMMA Scene* COMMA Geometry::GTypeMask COMMA bool); }; } diff --git a/thirdparty/embree/kernels/bvh/bvh_builder_morton.cpp b/thirdparty/embree/kernels/bvh/bvh_builder_morton.cpp index 4a4d8d71df..7d6548cb2a 100644 --- a/thirdparty/embree/kernels/bvh/bvh_builder_morton.cpp +++ b/thirdparty/embree/kernels/bvh/bvh_builder_morton.cpp @@ -17,6 +17,7 @@ #include "../geometry/quadi.h" #include "../geometry/object.h" #include "../geometry/instance.h" +#include "../geometry/instance_array.h" #if defined(__64BIT__) # define ROTATE_TREE 1 // specifies number of tree rotation rounds to perform @@ -399,6 +400,50 @@ namespace embree unsigned int geomID_ = std::numeric_limits<unsigned int>::max(); }; + template<int N> + struct CreateMortonLeaf<N,InstanceArrayPrimitive> + { + typedef BVHN<N> BVH; + typedef typename BVH::NodeRef NodeRef; + typedef typename BVH::NodeRecord NodeRecord; + + __forceinline CreateMortonLeaf (InstanceArray* mesh, unsigned int geomID, BVHBuilderMorton::BuildPrim* morton) + : mesh(mesh), morton(morton), geomID_(geomID) {} + + __noinline NodeRecord operator() (const range<unsigned>& current, const FastAllocator::CachedAllocator& alloc) + { + vfloat4 lower(pos_inf); + vfloat4 upper(neg_inf); + size_t items = current.size(); + size_t start = current.begin(); + assert(items <= 1); + + /* allocate leaf node */ + InstanceArrayPrimitive* accel = (InstanceArrayPrimitive*) alloc.malloc1(items*sizeof(InstanceArrayPrimitive),BVH::byteAlignment); + NodeRef ref = BVH::encodeLeaf((char*)accel,items); + const InstanceArray* instance = this->mesh; + + BBox3fa bounds = empty; + for (size_t i=0; i<items; i++) + { + const unsigned int primID = morton[start+i].index; + bounds.extend(instance->bounds(primID)); + new (&accel[i]) InstanceArrayPrimitive(geomID_, primID); + } + + BBox3fx box_o = (BBox3fx&)bounds; +#if ROTATE_TREE + if (N == 4) + box_o.lower.a = current.size(); +#endif + return NodeRecord(ref,box_o); + } + private: + InstanceArray* mesh; + BVHBuilderMorton::BuildPrim* morton; + unsigned int geomID_ = std::numeric_limits<unsigned int>::max(); + }; + template<typename Mesh> struct CalculateMeshBounds { @@ -523,7 +568,14 @@ namespace embree #if defined(EMBREE_GEOMETRY_INSTANCE) Builder* BVH4InstanceMeshBuilderMortonGeneral (void* bvh, Instance* mesh, Geometry::GTypeMask gtype, unsigned int geomID, size_t mode) { return new class BVHNMeshBuilderMorton<4,Instance,InstancePrimitive>((BVH4*)bvh,mesh,gtype,geomID,1,BVH4::maxLeafBlocks); } #if defined(__AVX__) - Builder* BVH8InstanceMeshBuilderMortonGeneral (void* bvh, Instance* mesh, Geometry::GTypeMask gtype, unsigned int geomID, size_t mode) { return new class BVHNMeshBuilderMorton<8,Instance,InstancePrimitive>((BVH8*)bvh,mesh,gtype,geomID,1,BVH4::maxLeafBlocks); } + Builder* BVH8InstanceMeshBuilderMortonGeneral (void* bvh, Instance* mesh, Geometry::GTypeMask gtype, unsigned int geomID, size_t mode) { return new class BVHNMeshBuilderMorton<8,Instance,InstancePrimitive>((BVH8*)bvh,mesh,gtype,geomID,1,BVH4::maxLeafBlocks); } +#endif +#endif + +#if defined(EMBREE_GEOMETRY_INSTANCE_ARRAY) + Builder* BVH4InstanceArrayMeshBuilderMortonGeneral (void* bvh, InstanceArray* mesh, Geometry::GTypeMask gtype, unsigned int geomID, size_t mode) { return new class BVHNMeshBuilderMorton<4,InstanceArray,InstanceArrayPrimitive>((BVH4*)bvh,mesh,gtype,geomID,1,BVH4::maxLeafBlocks); } +#if defined(__AVX__) + Builder* BVH8InstanceArrayMeshBuilderMortonGeneral (void* bvh, InstanceArray* mesh, Geometry::GTypeMask gtype, unsigned int geomID, size_t mode) { return new class BVHNMeshBuilderMorton<8,InstanceArray,InstanceArrayPrimitive>((BVH8*)bvh,mesh,gtype,geomID,1,BVH4::maxLeafBlocks); } #endif #endif diff --git a/thirdparty/embree/kernels/bvh/bvh_builder_sah.cpp b/thirdparty/embree/kernels/bvh/bvh_builder_sah.cpp index fad02fcc04..e20c088bba 100644 --- a/thirdparty/embree/kernels/bvh/bvh_builder_sah.cpp +++ b/thirdparty/embree/kernels/bvh/bvh_builder_sah.cpp @@ -15,6 +15,7 @@ #include "../geometry/quadi.h" #include "../geometry/object.h" #include "../geometry/instance.h" +#include "../geometry/instance_array.h" #include "../geometry/subgrid.h" #include "../common/state.h" @@ -150,7 +151,7 @@ namespace embree const size_t leaf_bytes = size_t(1.2*Primitive::blocks(numPrimitives)*sizeof(Primitive)); bvh->alloc.init_estimate(node_bytes+leaf_bytes); settings.singleThreadThreshold = bvh->alloc.fixSingleThreadThreshold(N,DEFAULT_SINGLE_THREAD_THRESHOLD,numPrimitives,node_bytes+leaf_bytes); - prims.resize(numPrimitives); + prims.resize(numPrimitives); PrimInfo pinfo = mesh ? createPrimRefArray(mesh,geomID_,numPrimitives,prims,bvh->scene->progressInterface) : @@ -518,14 +519,35 @@ namespace embree #endif #if defined(EMBREE_GEOMETRY_INSTANCE) - Builder* BVH4InstanceSceneBuilderSAH (void* bvh, Scene* scene, Geometry::GTypeMask gtype) { return new BVHNBuilderSAH<4,InstancePrimitive>((BVH4*)bvh,scene,4,1.0f,1,1,gtype); } + Builder* BVH4InstanceSceneBuilderSAH (void* bvh, Scene* scene, Geometry::GTypeMask gtype) { + return new BVHNBuilderSAH<4,InstancePrimitive>((BVH4*)bvh,scene,4,1.0f,1,1,gtype); + } Builder* BVH4InstanceMeshBuilderSAH (void* bvh, Instance* mesh, Geometry::GTypeMask gtype, unsigned int geomID, size_t mode) { return new BVHNBuilderSAH<4,InstancePrimitive>((BVH4*)bvh,mesh,geomID,4,1.0f,1,inf,gtype); } #if defined(__AVX__) - Builder* BVH8InstanceSceneBuilderSAH (void* bvh, Scene* scene, Geometry::GTypeMask gtype) { return new BVHNBuilderSAH<8,InstancePrimitive>((BVH8*)bvh,scene,8,1.0f,1,1,gtype); } + Builder* BVH8InstanceSceneBuilderSAH (void* bvh, Scene* scene, Geometry::GTypeMask gtype) { + return new BVHNBuilderSAH<8,InstancePrimitive>((BVH8*)bvh,scene,8,1.0f,1,1,gtype); + } Builder* BVH8InstanceMeshBuilderSAH (void* bvh, Instance* mesh, Geometry::GTypeMask gtype, unsigned int geomID, size_t mode) { - return new BVHNBuilderSAH<8,InstancePrimitive>((BVH8*)bvh,mesh,geomID,8,1.0f,1,inf,gtype); + return new BVHNBuilderSAH<8,InstancePrimitive>((BVH8*)bvh,mesh,geomID,8,1.0f,1,1,gtype); + } +#endif +#endif + +#if defined(EMBREE_GEOMETRY_INSTANCE_ARRAY) + Builder* BVH4InstanceArraySceneBuilderSAH (void* bvh, Scene* scene, Geometry::GTypeMask gtype) { + return new BVHNBuilderSAH<4,InstanceArrayPrimitive>((BVH4*)bvh,scene,4,1.0f,1,1,gtype); + } + Builder* BVH4InstanceArrayMeshBuilderSAH (void* bvh, InstanceArray* mesh, Geometry::GTypeMask gtype, unsigned int geomID, size_t mode) { + return new BVHNBuilderSAH<4,InstanceArrayPrimitive>((BVH4*)bvh,mesh,geomID,4,1.0f,1,1,gtype); + } +#if defined(__AVX__) + Builder* BVH8InstanceArraySceneBuilderSAH (void* bvh, Scene* scene, Geometry::GTypeMask gtype) { + return new BVHNBuilderSAH<8,InstanceArrayPrimitive>((BVH8*)bvh,scene,8,1.0f,1,1,gtype); + } + Builder* BVH8InstanceArrayMeshBuilderSAH (void* bvh, InstanceArray* mesh, Geometry::GTypeMask gtype, unsigned int geomID, size_t mode) { + return new BVHNBuilderSAH<8,InstanceArrayPrimitive>((BVH8*)bvh,mesh,geomID,8,1.0f,1,1,gtype); } #endif #endif diff --git a/thirdparty/embree/kernels/bvh/bvh_builder_sah_mb.cpp b/thirdparty/embree/kernels/bvh/bvh_builder_sah_mb.cpp index d163a80ab1..0dcf98a5be 100644 --- a/thirdparty/embree/kernels/bvh/bvh_builder_sah_mb.cpp +++ b/thirdparty/embree/kernels/bvh/bvh_builder_sah_mb.cpp @@ -17,6 +17,7 @@ #include "../geometry/quadi.h" #include "../geometry/object.h" #include "../geometry/instance.h" +#include "../geometry/instance_array.h" #include "../geometry/subgrid.h" #include "../common/state.h" @@ -695,6 +696,13 @@ namespace embree #endif #endif +#if defined(EMBREE_GEOMETRY_INSTANCE_ARRAY) + Builder* BVH4InstanceArrayMBSceneBuilderSAH (void* bvh, Scene* scene, Geometry::GTypeMask gtype) { return new BVHNBuilderMBlurSAH<4,InstanceArray,InstanceArrayPrimitive>((BVH4*)bvh,scene,4,1.0f,1,1,gtype); } +#if defined(__AVX__) + Builder* BVH8InstanceArrayMBSceneBuilderSAH (void* bvh, Scene* scene, Geometry::GTypeMask gtype) { return new BVHNBuilderMBlurSAH<8,InstanceArray,InstanceArrayPrimitive>((BVH8*)bvh,scene,8,1.0f,1,1,gtype); } +#endif +#endif + #if defined(EMBREE_GEOMETRY_GRID) Builder* BVH4GridMBSceneBuilderSAH (void* bvh, Scene* scene, size_t mode) { return new BVHNBuilderMBlurSAHGrid<4>((BVH4*)bvh,scene,4,1.0f,4,4); } #if defined(__AVX__) diff --git a/thirdparty/embree/kernels/bvh/bvh_builder_twolevel.cpp b/thirdparty/embree/kernels/bvh/bvh_builder_twolevel.cpp index 5d45ed3748..990b1d59ad 100644 --- a/thirdparty/embree/kernels/bvh/bvh_builder_twolevel.cpp +++ b/thirdparty/embree/kernels/bvh/bvh_builder_twolevel.cpp @@ -1,6 +1,10 @@ // Copyright 2009-2021 Intel Corporation // SPDX-License-Identifier: Apache-2.0 +#if !defined(_CRT_SECURE_NO_WARNINGS) +#define _CRT_SECURE_NO_WARNINGS +#endif + #include "bvh_builder_twolevel.h" #include "bvh_statistics.h" #include "../builders/bvh_builder_sah.h" @@ -333,6 +337,12 @@ namespace embree } #endif +#if defined(EMBREE_GEOMETRY_INSTANCE_ARRAY) + Builder* BVH4BuilderTwoLevelInstanceArraySAH (void* bvh, Scene* scene, Geometry::GTypeMask gtype, bool useMortonBuilder) { + return new BVHNBuilderTwoLevel<4,InstanceArray,InstanceArrayPrimitive>((BVH4*)bvh,scene,gtype,useMortonBuilder); + } +#endif + #if defined(__AVX__) #if defined(EMBREE_GEOMETRY_TRIANGLE) Builder* BVH8BuilderTwoLevelTriangle4MeshSAH (void* bvh, Scene* scene, bool useMortonBuilder) { @@ -364,6 +374,12 @@ namespace embree } #endif +#if defined(EMBREE_GEOMETRY_INSTANCE_ARRAY) + Builder* BVH8BuilderTwoLevelInstanceArraySAH (void* bvh, Scene* scene, Geometry::GTypeMask gtype, bool useMortonBuilder) { + return new BVHNBuilderTwoLevel<8,InstanceArray,InstanceArrayPrimitive>((BVH8*)bvh,scene,gtype,useMortonBuilder); + } +#endif + #endif } } diff --git a/thirdparty/embree/kernels/bvh/bvh_builder_twolevel.h b/thirdparty/embree/kernels/bvh/bvh_builder_twolevel.h index dc7ec7d278..97ae41a87d 100644 --- a/thirdparty/embree/kernels/bvh/bvh_builder_twolevel.h +++ b/thirdparty/embree/kernels/bvh/bvh_builder_twolevel.h @@ -7,7 +7,6 @@ #include "bvh_builder_twolevel_internal.h" #include "bvh.h" -#include "../common/primref.h" #include "../builders/priminfo.h" #include "../builders/primrefgen.h" diff --git a/thirdparty/embree/kernels/bvh/bvh_builder_twolevel_internal.h b/thirdparty/embree/kernels/bvh/bvh_builder_twolevel_internal.h index 023b52b780..b28afffae9 100644 --- a/thirdparty/embree/kernels/bvh/bvh_builder_twolevel_internal.h +++ b/thirdparty/embree/kernels/bvh/bvh_builder_twolevel_internal.h @@ -11,6 +11,7 @@ #include "../geometry/quadi.h" #include "../geometry/object.h" #include "../geometry/instance.h" +#include "../geometry/instance_array.h" namespace embree { @@ -32,6 +33,9 @@ namespace embree DECLARE_ISA_FUNCTION(Builder*,BVH4InstanceMeshBuilderMortonGeneral,void* COMMA Instance* COMMA Geometry::GTypeMask COMMA unsigned int COMMA size_t); DECLARE_ISA_FUNCTION(Builder*,BVH4InstanceMeshBuilderSAH,void* COMMA Instance* COMMA Geometry::GTypeMask COMMA unsigned int COMMA size_t); DECLARE_ISA_FUNCTION(Builder*,BVH4InstanceMeshRefitSAH,void* COMMA Instance* COMMA Geometry::GTypeMask COMMA unsigned int COMMA size_t) + DECLARE_ISA_FUNCTION(Builder*,BVH4InstanceArrayMeshBuilderMortonGeneral,void* COMMA InstanceArray* COMMA Geometry::GTypeMask COMMA unsigned int COMMA size_t); + DECLARE_ISA_FUNCTION(Builder*,BVH4InstanceArrayMeshBuilderSAH,void* COMMA InstanceArray* COMMA Geometry::GTypeMask COMMA unsigned int COMMA size_t); + DECLARE_ISA_FUNCTION(Builder*,BVH4InstanceArrayMeshRefitSAH,void* COMMA InstanceArray* COMMA Geometry::GTypeMask COMMA unsigned int COMMA size_t) DECLARE_ISA_FUNCTION(Builder*,BVH8Triangle4MeshBuilderMortonGeneral,void* COMMA TriangleMesh* COMMA unsigned int COMMA size_t); DECLARE_ISA_FUNCTION(Builder*,BVH8Triangle4MeshBuilderSAH,void* COMMA TriangleMesh* COMMA unsigned int COMMA size_t); DECLARE_ISA_FUNCTION(Builder*,BVH8Triangle4MeshRefitSAH,void* COMMA TriangleMesh* COMMA unsigned int COMMA size_t); @@ -50,6 +54,9 @@ namespace embree DECLARE_ISA_FUNCTION(Builder*,BVH8InstanceMeshBuilderMortonGeneral,void* COMMA Instance* COMMA Geometry::GTypeMask COMMA unsigned int COMMA size_t); DECLARE_ISA_FUNCTION(Builder*,BVH8InstanceMeshBuilderSAH,void* COMMA Instance* COMMA Geometry::GTypeMask COMMA unsigned int COMMA size_t); DECLARE_ISA_FUNCTION(Builder*,BVH8InstanceMeshRefitSAH,void* COMMA Instance* COMMA Geometry::GTypeMask COMMA unsigned int COMMA size_t) + DECLARE_ISA_FUNCTION(Builder*,BVH8InstanceArrayMeshBuilderMortonGeneral,void* COMMA InstanceArray* COMMA Geometry::GTypeMask COMMA unsigned int COMMA size_t); + DECLARE_ISA_FUNCTION(Builder*,BVH8InstanceArrayMeshBuilderSAH,void* COMMA InstanceArray* COMMA Geometry::GTypeMask COMMA unsigned int COMMA size_t); + DECLARE_ISA_FUNCTION(Builder*,BVH8InstanceArrayMeshRefitSAH,void* COMMA InstanceArray* COMMA Geometry::GTypeMask COMMA unsigned int COMMA size_t) namespace isa { @@ -89,6 +96,11 @@ namespace embree Builder* operator () (void* bvh, Instance* mesh, size_t geomID, Geometry::GTypeMask gtype) { return BVH4InstanceMeshBuilderMortonGeneral(bvh,mesh,gtype,geomID,0);} }; template<> + struct MortonBuilder<4,InstanceArray,InstanceArrayPrimitive> { + MortonBuilder () {} + Builder* operator () (void* bvh, InstanceArray* mesh, size_t geomID, Geometry::GTypeMask gtype) { return BVH4InstanceArrayMeshBuilderMortonGeneral(bvh,mesh,gtype,geomID,0);} + }; + template<> struct MortonBuilder<8,TriangleMesh,Triangle4> { MortonBuilder () {} Builder* operator () (void* bvh, TriangleMesh* mesh, size_t geomID, Geometry::GTypeMask /*gtype*/) { return BVH8Triangle4MeshBuilderMortonGeneral(bvh,mesh,geomID,0);} @@ -118,6 +130,11 @@ namespace embree MortonBuilder () {} Builder* operator () (void* bvh, Instance* mesh, size_t geomID, Geometry::GTypeMask gtype) { return BVH8InstanceMeshBuilderMortonGeneral(bvh,mesh,gtype,geomID,0);} }; + template<> + struct MortonBuilder<8,InstanceArray,InstanceArrayPrimitive> { + MortonBuilder () {} + Builder* operator () (void* bvh, InstanceArray* mesh, size_t geomID, Geometry::GTypeMask gtype) { return BVH8InstanceArrayMeshBuilderMortonGeneral(bvh,mesh,gtype,geomID,0);} + }; template<int N, typename Mesh, typename Primitive> struct SAHBuilder {}; @@ -152,6 +169,11 @@ namespace embree Builder* operator () (void* bvh, Instance* mesh, size_t geomID, Geometry::GTypeMask gtype) { return BVH4InstanceMeshBuilderSAH(bvh,mesh,gtype,geomID,0);} }; template<> + struct SAHBuilder<4,InstanceArray,InstanceArrayPrimitive> { + SAHBuilder () {} + Builder* operator () (void* bvh, InstanceArray* mesh, size_t geomID, Geometry::GTypeMask gtype) { return BVH4InstanceArrayMeshBuilderSAH(bvh,mesh,gtype,geomID,0);} + }; + template<> struct SAHBuilder<8,TriangleMesh,Triangle4> { SAHBuilder () {} Builder* operator () (void* bvh, TriangleMesh* mesh, size_t geomID, Geometry::GTypeMask /*gtype*/) { return BVH8Triangle4MeshBuilderSAH(bvh,mesh,geomID,0);} @@ -181,6 +203,11 @@ namespace embree SAHBuilder () {} Builder* operator () (void* bvh, Instance* mesh, size_t geomID, Geometry::GTypeMask gtype) { return BVH8InstanceMeshBuilderSAH(bvh,mesh,gtype,geomID,0);} }; + template<> + struct SAHBuilder<8,InstanceArray,InstanceArrayPrimitive> { + SAHBuilder () {} + Builder* operator () (void* bvh, InstanceArray* mesh, size_t geomID, Geometry::GTypeMask gtype) { return BVH8InstanceArrayMeshBuilderSAH(bvh,mesh,gtype,geomID,0);} + }; template<int N, typename Mesh, typename Primitive> struct RefitBuilder {}; @@ -215,6 +242,11 @@ namespace embree Builder* operator () (void* bvh, Instance* mesh, size_t geomID, Geometry::GTypeMask gtype) { return BVH4InstanceMeshRefitSAH(bvh,mesh,gtype,geomID,0);} }; template<> + struct RefitBuilder<4,InstanceArray,InstanceArrayPrimitive> { + RefitBuilder () {} + Builder* operator () (void* bvh, InstanceArray* mesh, size_t geomID, Geometry::GTypeMask gtype) { return BVH4InstanceArrayMeshRefitSAH(bvh,mesh,gtype,geomID,0);} + }; + template<> struct RefitBuilder<8,TriangleMesh,Triangle4> { RefitBuilder () {} Builder* operator () (void* bvh, TriangleMesh* mesh, size_t geomID, Geometry::GTypeMask /*gtype*/) { return BVH8Triangle4MeshRefitSAH(bvh,mesh,geomID,0);} @@ -244,7 +276,12 @@ namespace embree RefitBuilder () {} Builder* operator () (void* bvh, Instance* mesh, size_t geomID, Geometry::GTypeMask gtype) { return BVH8InstanceMeshRefitSAH(bvh,mesh,gtype,geomID,0);} }; - + template<> + struct RefitBuilder<8,InstanceArray,InstanceArrayPrimitive> { + RefitBuilder () {} + Builder* operator () (void* bvh, InstanceArray* mesh, size_t geomID, Geometry::GTypeMask gtype) { return BVH8InstanceArrayMeshRefitSAH(bvh,mesh,gtype,geomID,0);} + }; + template<int N, typename Mesh, typename Primitive> struct MeshBuilder { MeshBuilder () {} diff --git a/thirdparty/embree/kernels/bvh/bvh_collider.cpp b/thirdparty/embree/kernels/bvh/bvh_collider.cpp index 9428c0b88e..a22d701827 100644 --- a/thirdparty/embree/kernels/bvh/bvh_collider.cpp +++ b/thirdparty/embree/kernels/bvh/bvh_collider.cpp @@ -2,7 +2,9 @@ // SPDX-License-Identifier: Apache-2.0 #include "bvh_collider.h" + #include "../geometry/triangle_triangle_intersector.h" +#include "../../common/algorithms/parallel_for.h" namespace embree { diff --git a/thirdparty/embree/kernels/bvh/bvh_intersector1.cpp b/thirdparty/embree/kernels/bvh/bvh_intersector1.cpp index 9594f402c3..1d797df88f 100644 --- a/thirdparty/embree/kernels/bvh/bvh_intersector1.cpp +++ b/thirdparty/embree/kernels/bvh/bvh_intersector1.cpp @@ -19,6 +19,7 @@ #include "../geometry/subdivpatch1_intersector.h" #include "../geometry/object_intersector.h" #include "../geometry/instance_intersector.h" +#include "../geometry/instance_array_intersector.h" #include "../geometry/subgrid_intersector.h" #include "../geometry/subgrid_mb_intersector.h" #include "../geometry/curve_intersector_virtual.h" @@ -30,7 +31,7 @@ namespace embree template<int N, int types, bool robust, typename PrimitiveIntersector1> void BVHNIntersector1<N, types, robust, PrimitiveIntersector1>::intersect(const Accel::Intersectors* __restrict__ This, RayHit& __restrict__ ray, - IntersectContext* __restrict__ context) + RayQueryContext* __restrict__ context) { const BVH* __restrict__ bvh = (const BVH*)This->ptr; @@ -115,7 +116,7 @@ namespace embree template<int N, int types, bool robust, typename PrimitiveIntersector1> void BVHNIntersector1<N, types, robust, PrimitiveIntersector1>::occluded(const Accel::Intersectors* __restrict__ This, Ray& __restrict__ ray, - IntersectContext* __restrict__ context) + RayQueryContext* __restrict__ context) { const BVH* __restrict__ bvh = (const BVH*)This->ptr; diff --git a/thirdparty/embree/kernels/bvh/bvh_intersector1.h b/thirdparty/embree/kernels/bvh/bvh_intersector1.h index 2df3d6eddb..3cec4e113b 100644 --- a/thirdparty/embree/kernels/bvh/bvh_intersector1.h +++ b/thirdparty/embree/kernels/bvh/bvh_intersector1.h @@ -26,8 +26,8 @@ namespace embree static const size_t stackSize = 1+(N-1)*BVH::maxDepth+3; // +3 due to 16-wide store public: - static void intersect (const Accel::Intersectors* This, RayHit& ray, IntersectContext* context); - static void occluded (const Accel::Intersectors* This, Ray& ray, IntersectContext* context); + static void intersect (const Accel::Intersectors* This, RayHit& ray, RayQueryContext* context); + static void occluded (const Accel::Intersectors* This, Ray& ray, RayQueryContext* context); static bool pointQuery(const Accel::Intersectors* This, PointQuery* query, PointQueryContext* context); }; } diff --git a/thirdparty/embree/kernels/bvh/bvh_intersector1_bvh4.cpp b/thirdparty/embree/kernels/bvh/bvh_intersector1_bvh4.cpp index 831d613367..1baecc7bbc 100644 --- a/thirdparty/embree/kernels/bvh/bvh_intersector1_bvh4.cpp +++ b/thirdparty/embree/kernels/bvh/bvh_intersector1_bvh4.cpp @@ -48,6 +48,9 @@ namespace embree IF_ENABLED_INSTANCE(DEFINE_INTERSECTOR1(BVH4InstanceIntersector1,BVHNIntersector1<4 COMMA BVH_AN1 COMMA false COMMA ArrayIntersector1<InstanceIntersector1> >)); IF_ENABLED_INSTANCE(DEFINE_INTERSECTOR1(BVH4InstanceMBIntersector1,BVHNIntersector1<4 COMMA BVH_AN2_AN4D COMMA false COMMA ArrayIntersector1<InstanceIntersector1MB> >)); + IF_ENABLED_INSTANCE_ARRAY(DEFINE_INTERSECTOR1(BVH4InstanceArrayIntersector1,BVHNIntersector1<4 COMMA BVH_AN1 COMMA false COMMA ArrayIntersector1<InstanceArrayIntersector1> >)); + IF_ENABLED_INSTANCE_ARRAY(DEFINE_INTERSECTOR1(BVH4InstanceArrayMBIntersector1,BVHNIntersector1<4 COMMA BVH_AN2_AN4D COMMA false COMMA ArrayIntersector1<InstanceArrayIntersector1MB> >)); + IF_ENABLED_TRIS(DEFINE_INTERSECTOR1(QBVH4Triangle4iIntersector1Pluecker,BVHNIntersector1<4 COMMA BVH_QN1 COMMA false COMMA ArrayIntersector1<TriangleMiIntersector1Pluecker<4 COMMA true> > >)); IF_ENABLED_QUADS(DEFINE_INTERSECTOR1(QBVH4Quad4iIntersector1Pluecker,BVHNIntersector1<4 COMMA BVH_QN1 COMMA false COMMA ArrayIntersector1<QuadMiIntersector1Pluecker<4 COMMA true> > >)); diff --git a/thirdparty/embree/kernels/bvh/bvh_intersector_hybrid.cpp b/thirdparty/embree/kernels/bvh/bvh_intersector_hybrid.cpp index 1d393fd06b..e9e2262984 100644 --- a/thirdparty/embree/kernels/bvh/bvh_intersector_hybrid.cpp +++ b/thirdparty/embree/kernels/bvh/bvh_intersector_hybrid.cpp @@ -20,6 +20,7 @@ #include "../geometry/subdivpatch1_intersector.h" #include "../geometry/object_intersector.h" #include "../geometry/instance_intersector.h" +#include "../geometry/instance_array_intersector.h" #include "../geometry/subgrid_intersector.h" #include "../geometry/subgrid_mb_intersector.h" #include "../geometry/curve_intersector_virtual.h" @@ -41,7 +42,7 @@ namespace embree Precalculations& pre, RayHitK<K>& ray, const TravRayK<K, robust>& tray, - IntersectContext* context) + RayQueryContext* context) { /* stack state */ StackItemT<NodeRef> stack[stackSizeSingle]; // stack of nodes @@ -105,7 +106,7 @@ namespace embree void BVHNIntersectorKHybrid<N, K, types, robust, PrimitiveIntersectorK, single>::intersect(vint<K>* __restrict__ valid_i, Accel::Intersectors* __restrict__ This, RayHitK<K>& __restrict__ ray, - IntersectContext* __restrict__ context) + RayQueryContext* __restrict__ context) { BVH* __restrict__ bvh = (BVH*)This->ptr; @@ -373,7 +374,7 @@ namespace embree void BVHNIntersectorKHybrid<N, K, types, robust, PrimitiveIntersectorK, single>::intersectCoherent(vint<K>* __restrict__ valid_i, Accel::Intersectors* __restrict__ This, RayHitK<K>& __restrict__ ray, - IntersectContext* context) + RayQueryContext* context) { BVH* __restrict__ bvh = (BVH*)This->ptr; @@ -539,7 +540,7 @@ namespace embree Precalculations& pre, RayK<K>& ray, const TravRayK<K, robust>& tray, - IntersectContext* context) + RayQueryContext* context) { /* stack state */ NodeRef stack[stackSizeSingle]; // stack of nodes that still need to get traversed @@ -599,7 +600,7 @@ namespace embree void BVHNIntersectorKHybrid<N, K, types, robust, PrimitiveIntersectorK, single>::occluded(vint<K>* __restrict__ valid_i, Accel::Intersectors* __restrict__ This, RayK<K>& __restrict__ ray, - IntersectContext* context) + RayQueryContext* context) { BVH* __restrict__ bvh = (BVH*)This->ptr; @@ -784,7 +785,7 @@ namespace embree void BVHNIntersectorKHybrid<N, K, types, robust, PrimitiveIntersectorK, single>::occludedCoherent(vint<K>* __restrict__ valid_i, Accel::Intersectors* __restrict__ This, RayK<K>& __restrict__ ray, - IntersectContext* context) + RayQueryContext* context) { BVH* __restrict__ bvh = (BVH*)This->ptr; @@ -861,7 +862,7 @@ namespace embree #if defined(__AVX__) //STAT3(normal.trav_hit_boxes[popcnt(m_frustum_node)], 1, 1, 1); #endif - size_t num_child_hits = 0; + //size_t num_child_hits = 0; do { const size_t i = bscf(m_frustum_node); vfloat<K> lnearP; @@ -875,7 +876,7 @@ namespace embree assert(child != BVH::emptyNode); BVHN<N>::prefetch(child); if (likely(cur != BVH::emptyNode)) { - num_child_hits++; + //num_child_hits++; stackPtr->ptr = cur; stackPtr->mask = m_active; stackPtr++; diff --git a/thirdparty/embree/kernels/bvh/bvh_intersector_hybrid.h b/thirdparty/embree/kernels/bvh/bvh_intersector_hybrid.h index 50ebf375c4..1240bd5ab5 100644 --- a/thirdparty/embree/kernels/bvh/bvh_intersector_hybrid.h +++ b/thirdparty/embree/kernels/bvh/bvh_intersector_hybrid.h @@ -38,16 +38,16 @@ namespace embree private: static void intersect1(Accel::Intersectors* This, const BVH* bvh, NodeRef root, size_t k, Precalculations& pre, - RayHitK<K>& ray, const TravRayK<K, robust>& tray, IntersectContext* context); + RayHitK<K>& ray, const TravRayK<K, robust>& tray, RayQueryContext* context); static bool occluded1(Accel::Intersectors* This, const BVH* bvh, NodeRef root, size_t k, Precalculations& pre, - RayK<K>& ray, const TravRayK<K, robust>& tray, IntersectContext* context); + RayK<K>& ray, const TravRayK<K, robust>& tray, RayQueryContext* context); public: - static void intersect(vint<K>* valid, Accel::Intersectors* This, RayHitK<K>& ray, IntersectContext* context); - static void occluded (vint<K>* valid, Accel::Intersectors* This, RayK<K>& ray, IntersectContext* context); + static void intersect(vint<K>* valid, Accel::Intersectors* This, RayHitK<K>& ray, RayQueryContext* context); + static void occluded (vint<K>* valid, Accel::Intersectors* This, RayK<K>& ray, RayQueryContext* context); - static void intersectCoherent(vint<K>* valid, Accel::Intersectors* This, RayHitK<K>& ray, IntersectContext* context); - static void occludedCoherent (vint<K>* valid, Accel::Intersectors* This, RayK<K>& ray, IntersectContext* context); + static void intersectCoherent(vint<K>* valid, Accel::Intersectors* This, RayHitK<K>& ray, RayQueryContext* context); + static void occludedCoherent (vint<K>* valid, Accel::Intersectors* This, RayK<K>& ray, RayQueryContext* context); }; diff --git a/thirdparty/embree/kernels/bvh/bvh_intersector_hybrid4_bvh4.cpp b/thirdparty/embree/kernels/bvh/bvh_intersector_hybrid4_bvh4.cpp index 2137da6a25..72cefa9e8e 100644 --- a/thirdparty/embree/kernels/bvh/bvh_intersector_hybrid4_bvh4.cpp +++ b/thirdparty/embree/kernels/bvh/bvh_intersector_hybrid4_bvh4.cpp @@ -48,6 +48,9 @@ namespace embree IF_ENABLED_INSTANCE(DEFINE_INTERSECTOR4(BVH4InstanceIntersector4Chunk, BVHNIntersectorKChunk<4 COMMA 4 COMMA BVH_AN1 COMMA false COMMA ArrayIntersectorK_1<4 COMMA InstanceIntersectorK<4>> >)); IF_ENABLED_INSTANCE(DEFINE_INTERSECTOR4(BVH4InstanceMBIntersector4Chunk, BVHNIntersectorKChunk<4 COMMA 4 COMMA BVH_AN2_AN4D COMMA false COMMA ArrayIntersectorK_1<4 COMMA InstanceIntersectorKMB<4>> >)); + IF_ENABLED_INSTANCE_ARRAY(DEFINE_INTERSECTOR4(BVH4InstanceArrayIntersector4Chunk, BVHNIntersectorKChunk<4 COMMA 4 COMMA BVH_AN1 COMMA false COMMA ArrayIntersectorK_1<4 COMMA InstanceArrayIntersectorK<4>> >)); + IF_ENABLED_INSTANCE_ARRAY(DEFINE_INTERSECTOR4(BVH4InstanceArrayMBIntersector4Chunk, BVHNIntersectorKChunk<4 COMMA 4 COMMA BVH_AN2_AN4D COMMA false COMMA ArrayIntersectorK_1<4 COMMA InstanceArrayIntersectorKMB<4>> >)); + IF_ENABLED_GRIDS(DEFINE_INTERSECTOR4(BVH4GridIntersector4HybridMoeller, BVHNIntersectorKHybrid<4 COMMA 4 COMMA BVH_AN1 COMMA false COMMA SubGridIntersectorKMoeller <4 COMMA 4 COMMA true> >)); //IF_ENABLED_GRIDS(DEFINE_INTERSECTOR4(BVH4GridIntersector4HybridMoeller, BVHNIntersectorKChunk<4 COMMA 4 COMMA BVH_AN1 COMMA false COMMA SubGridIntersectorKMoeller <4 COMMA 4 COMMA true> >)); diff --git a/thirdparty/embree/kernels/bvh/bvh_intersector_stream.cpp b/thirdparty/embree/kernels/bvh/bvh_intersector_stream.cpp deleted file mode 100644 index 4a74d8468d..0000000000 --- a/thirdparty/embree/kernels/bvh/bvh_intersector_stream.cpp +++ /dev/null @@ -1,528 +0,0 @@ -// Copyright 2009-2021 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 - -#include "bvh_intersector_stream.h" - -#include "../geometry/intersector_iterators.h" -#include "../geometry/triangle_intersector.h" -#include "../geometry/trianglev_intersector.h" -#include "../geometry/trianglev_mb_intersector.h" -#include "../geometry/trianglei_intersector.h" -#include "../geometry/quadv_intersector.h" -#include "../geometry/quadi_intersector.h" -#include "../geometry/linei_intersector.h" -#include "../geometry/subdivpatch1_intersector.h" -#include "../geometry/object_intersector.h" -#include "../geometry/instance_intersector.h" - -#include "../common/scene.h" -#include <bitset> - -namespace embree -{ - namespace isa - { - __aligned(64) static const int shiftTable[32] = { - (int)1 << 0, (int)1 << 1, (int)1 << 2, (int)1 << 3, (int)1 << 4, (int)1 << 5, (int)1 << 6, (int)1 << 7, - (int)1 << 8, (int)1 << 9, (int)1 << 10, (int)1 << 11, (int)1 << 12, (int)1 << 13, (int)1 << 14, (int)1 << 15, - (int)1 << 16, (int)1 << 17, (int)1 << 18, (int)1 << 19, (int)1 << 20, (int)1 << 21, (int)1 << 22, (int)1 << 23, - (int)1 << 24, (int)1 << 25, (int)1 << 26, (int)1 << 27, (int)1 << 28, (int)1 << 29, (int)1 << 30, (int)1 << 31 - }; - - template<int N, int types, bool robust, typename PrimitiveIntersector> - __forceinline void BVHNIntersectorStream<N, types, robust, PrimitiveIntersector>::intersect(Accel::Intersectors* __restrict__ This, - RayHitN** inputPackets, - size_t numOctantRays, - IntersectContext* context) - { - /* we may traverse an empty BVH in case all geometry was invalid */ - BVH* __restrict__ bvh = (BVH*) This->ptr; - if (bvh->root == BVH::emptyNode) - return; - - // Only the coherent code path is implemented - assert(context->isCoherent()); - intersectCoherent(This, (RayHitK<VSIZEL>**)inputPackets, numOctantRays, context); - } - - template<int N, int types, bool robust, typename PrimitiveIntersector> - template<int K> - __forceinline void BVHNIntersectorStream<N, types, robust, PrimitiveIntersector>::intersectCoherent(Accel::Intersectors* __restrict__ This, - RayHitK<K>** inputPackets, - size_t numOctantRays, - IntersectContext* context) - { - assert(context->isCoherent()); - - BVH* __restrict__ bvh = (BVH*) This->ptr; - __aligned(64) StackItemMaskCoherent stack[stackSizeSingle]; // stack of nodes - assert(numOctantRays <= MAX_INTERNAL_STREAM_SIZE); - - __aligned(64) TravRayKStream<K, robust> packets[MAX_INTERNAL_STREAM_SIZE/K]; - __aligned(64) Frustum<robust> frustum; - - bool commonOctant = true; - const size_t m_active = initPacketsAndFrustum((RayK<K>**)inputPackets, numOctantRays, packets, frustum, commonOctant); - if (unlikely(m_active == 0)) return; - - /* case of non-common origin */ - if (unlikely(!commonOctant)) - { - const size_t numPackets = (numOctantRays+K-1)/K; - for (size_t i = 0; i < numPackets; i++) - This->intersect(inputPackets[i]->tnear() <= inputPackets[i]->tfar, *inputPackets[i], context); - return; - } - - stack[0].mask = m_active; - stack[0].parent = 0; - stack[0].child = bvh->root; - - /////////////////////////////////////////////////////////////////////////////////// - /////////////////////////////////////////////////////////////////////////////////// - /////////////////////////////////////////////////////////////////////////////////// - - StackItemMaskCoherent* stackPtr = stack + 1; - - while (1) pop: - { - if (unlikely(stackPtr == stack)) break; - - STAT3(normal.trav_stack_pop,1,1,1); - stackPtr--; - /*! pop next node */ - NodeRef cur = NodeRef(stackPtr->child); - size_t m_trav_active = stackPtr->mask; - assert(m_trav_active); - NodeRef parent = stackPtr->parent; - - while (1) - { - if (unlikely(cur.isLeaf())) break; - const AABBNode* __restrict__ const node = cur.getAABBNode(); - parent = cur; - - __aligned(64) size_t maskK[N]; - for (size_t i = 0; i < N; i++) - maskK[i] = m_trav_active; - vfloat<N> dist; - const size_t m_node_hit = traverseCoherentStream(m_trav_active, packets, node, frustum, maskK, dist); - if (unlikely(m_node_hit == 0)) goto pop; - - BVHNNodeTraverserStreamHitCoherent<N, types>::traverseClosestHit(cur, m_trav_active, vbool<N>((int)m_node_hit), dist, (size_t*)maskK, stackPtr); - assert(m_trav_active); - } - - /* non-root and leaf => full culling test for all rays */ - if (unlikely(parent != 0 && cur.isLeaf())) - { - const AABBNode* __restrict__ const node = parent.getAABBNode(); - size_t boxID = 0xff; - for (size_t i = 0; i < N; i++) - if (node->child(i) == cur) { boxID = i; break; } - assert(boxID < N); - assert(cur == node->child(boxID)); - m_trav_active = intersectAABBNodePacket(m_trav_active, packets, node, boxID, frustum.nf); - } - - /*! this is a leaf node */ - assert(cur != BVH::emptyNode); - STAT3(normal.trav_leaves, 1, 1, 1); - size_t num; PrimitiveK<K>* prim = (PrimitiveK<K>*)cur.leaf(num); - - size_t bits = m_trav_active; - - /*! intersect stream of rays with all primitives */ - size_t lazy_node = 0; -#if defined(__SSE4_2__) - STAT_USER(1,(popcnt(bits)+K-1)/K*4); -#endif - while(bits) - { - size_t i = bsf(bits) / K; - const size_t m_isec = ((((size_t)1 << K)-1) << (i*K)); - assert(m_isec & bits); - bits &= ~m_isec; - - TravRayKStream<K, robust>& p = packets[i]; - vbool<K> m_valid = p.tnear <= p.tfar; - PrimitiveIntersectorK<K>::intersectK(m_valid, This, *inputPackets[i], context, prim, num, lazy_node); - p.tfar = min(p.tfar, inputPackets[i]->tfar); - }; - - } // traversal + intersection - } - - template<int N, int types, bool robust, typename PrimitiveIntersector> - __forceinline void BVHNIntersectorStream<N, types, robust, PrimitiveIntersector>::occluded(Accel::Intersectors* __restrict__ This, - RayN** inputPackets, - size_t numOctantRays, - IntersectContext* context) - { - /* we may traverse an empty BVH in case all geometry was invalid */ - BVH* __restrict__ bvh = (BVH*) This->ptr; - if (bvh->root == BVH::emptyNode) - return; - - if (unlikely(context->isCoherent())) - occludedCoherent(This, (RayK<VSIZEL>**)inputPackets, numOctantRays, context); - else - occludedIncoherent(This, (RayK<VSIZEX>**)inputPackets, numOctantRays, context); - } - - template<int N, int types, bool robust, typename PrimitiveIntersector> - template<int K> - __noinline void BVHNIntersectorStream<N, types, robust, PrimitiveIntersector>::occludedCoherent(Accel::Intersectors* __restrict__ This, - RayK<K>** inputPackets, - size_t numOctantRays, - IntersectContext* context) - { - assert(context->isCoherent()); - - BVH* __restrict__ bvh = (BVH*)This->ptr; - __aligned(64) StackItemMaskCoherent stack[stackSizeSingle]; // stack of nodes - assert(numOctantRays <= MAX_INTERNAL_STREAM_SIZE); - - /* inactive rays should have been filtered out before */ - __aligned(64) TravRayKStream<K, robust> packets[MAX_INTERNAL_STREAM_SIZE/K]; - __aligned(64) Frustum<robust> frustum; - - bool commonOctant = true; - size_t m_active = initPacketsAndFrustum(inputPackets, numOctantRays, packets, frustum, commonOctant); - - /* valid rays */ - if (unlikely(m_active == 0)) return; - - /* case of non-common origin */ - if (unlikely(!commonOctant)) - { - const size_t numPackets = (numOctantRays+K-1)/K; - for (size_t i = 0; i < numPackets; i++) - This->occluded(inputPackets[i]->tnear() <= inputPackets[i]->tfar, *inputPackets[i], context); - return; - } - - stack[0].mask = m_active; - stack[0].parent = 0; - stack[0].child = bvh->root; - - /////////////////////////////////////////////////////////////////////////////////// - /////////////////////////////////////////////////////////////////////////////////// - /////////////////////////////////////////////////////////////////////////////////// - - StackItemMaskCoherent* stackPtr = stack + 1; - - while (1) pop: - { - if (unlikely(stackPtr == stack)) break; - - STAT3(normal.trav_stack_pop,1,1,1); - stackPtr--; - /*! pop next node */ - NodeRef cur = NodeRef(stackPtr->child); - size_t m_trav_active = stackPtr->mask & m_active; - if (unlikely(!m_trav_active)) continue; - assert(m_trav_active); - NodeRef parent = stackPtr->parent; - - while (1) - { - if (unlikely(cur.isLeaf())) break; - const AABBNode* __restrict__ const node = cur.getAABBNode(); - parent = cur; - - __aligned(64) size_t maskK[N]; - for (size_t i = 0; i < N; i++) - maskK[i] = m_trav_active; - - vfloat<N> dist; - const size_t m_node_hit = traverseCoherentStream(m_trav_active, packets, node, frustum, maskK, dist); - if (unlikely(m_node_hit == 0)) goto pop; - - BVHNNodeTraverserStreamHitCoherent<N, types>::traverseAnyHit(cur, m_trav_active, vbool<N>((int)m_node_hit), (size_t*)maskK, stackPtr); - assert(m_trav_active); - } - - /* non-root and leaf => full culling test for all rays */ - if (unlikely(parent != 0 && cur.isLeaf())) - { - const AABBNode* __restrict__ const node = parent.getAABBNode(); - size_t boxID = 0xff; - for (size_t i = 0; i < N; i++) - if (node->child(i) == cur) { boxID = i; break; } - assert(boxID < N); - assert(cur == node->child(boxID)); - m_trav_active = intersectAABBNodePacket(m_trav_active, packets, node, boxID, frustum.nf); - } - - /*! this is a leaf node */ - assert(cur != BVH::emptyNode); - STAT3(normal.trav_leaves, 1, 1, 1); - size_t num; PrimitiveK<K>* prim = (PrimitiveK<K>*)cur.leaf(num); - - size_t bits = m_trav_active & m_active; - /*! intersect stream of rays with all primitives */ - size_t lazy_node = 0; -#if defined(__SSE4_2__) - STAT_USER(1,(popcnt(bits)+K-1)/K*4); -#endif - while (bits) - { - size_t i = bsf(bits) / K; - const size_t m_isec = ((((size_t)1 << K)-1) << (i*K)); - assert(m_isec & bits); - bits &= ~m_isec; - TravRayKStream<K, robust>& p = packets[i]; - vbool<K> m_valid = p.tnear <= p.tfar; - vbool<K> m_hit = PrimitiveIntersectorK<K>::occludedK(m_valid, This, *inputPackets[i], context, prim, num, lazy_node); - inputPackets[i]->tfar = select(m_hit & m_valid, vfloat<K>(neg_inf), inputPackets[i]->tfar); - m_active &= ~((size_t)movemask(m_hit) << (i*K)); - } - - } // traversal + intersection - } - - - template<int N, int types, bool robust, typename PrimitiveIntersector> - template<int K> - __forceinline void BVHNIntersectorStream<N, types, robust, PrimitiveIntersector>::occludedIncoherent(Accel::Intersectors* __restrict__ This, - RayK<K>** inputPackets, - size_t numOctantRays, - IntersectContext* context) - { - assert(!context->isCoherent()); - assert(types & BVH_FLAG_ALIGNED_NODE); - - __aligned(64) TravRayKStream<K,robust> packet[MAX_INTERNAL_STREAM_SIZE/K]; - - assert(numOctantRays <= 32); - const size_t numPackets = (numOctantRays+K-1)/K; - size_t m_active = 0; - for (size_t i = 0; i < numPackets; i++) - { - const vfloat<K> tnear = inputPackets[i]->tnear(); - const vfloat<K> tfar = inputPackets[i]->tfar; - vbool<K> m_valid = (tnear <= tfar) & (tnear >= 0.0f); - m_active |= (size_t)movemask(m_valid) << (K*i); - const Vec3vf<K>& org = inputPackets[i]->org; - const Vec3vf<K>& dir = inputPackets[i]->dir; - vfloat<K> packet_min_dist = max(tnear, 0.0f); - vfloat<K> packet_max_dist = select(m_valid, tfar, neg_inf); - new (&packet[i]) TravRayKStream<K,robust>(org, dir, packet_min_dist, packet_max_dist); - } - - BVH* __restrict__ bvh = (BVH*)This->ptr; - - StackItemMaskT<NodeRef> stack[stackSizeSingle]; // stack of nodes - StackItemMaskT<NodeRef>* stackPtr = stack + 1; // current stack pointer - stack[0].ptr = bvh->root; - stack[0].mask = m_active; - - size_t terminated = ~m_active; - - /* near/far offsets based on first ray */ - const NearFarPrecalculations nf(Vec3fa(packet[0].rdir.x[0], packet[0].rdir.y[0], packet[0].rdir.z[0]), N); - - while (1) pop: - { - if (unlikely(stackPtr == stack)) break; - STAT3(shadow.trav_stack_pop,1,1,1); - stackPtr--; - NodeRef cur = NodeRef(stackPtr->ptr); - size_t cur_mask = stackPtr->mask & (~terminated); - if (unlikely(cur_mask == 0)) continue; - - while (true) - { - /*! stop if we found a leaf node */ - if (unlikely(cur.isLeaf())) break; - const AABBNode* __restrict__ const node = cur.getAABBNode(); - - const vint<N> vmask = traverseIncoherentStream(cur_mask, packet, node, nf, shiftTable); - - size_t mask = movemask(vmask != vint<N>(zero)); - if (unlikely(mask == 0)) goto pop; - - __aligned(64) unsigned int child_mask[N]; - vint<N>::storeu(child_mask, vmask); // this explicit store here causes much better code generation - - /*! one child is hit, continue with that child */ - size_t r = bscf(mask); - assert(r < N); - cur = node->child(r); - BVHN<N>::prefetch(cur,types); - cur_mask = child_mask[r]; - - /* simple in order sequence */ - assert(cur != BVH::emptyNode); - if (likely(mask == 0)) continue; - stackPtr->ptr = cur; - stackPtr->mask = cur_mask; - stackPtr++; - - for (; ;) - { - r = bscf(mask); - assert(r < N); - - cur = node->child(r); - BVHN<N>::prefetch(cur,types); - cur_mask = child_mask[r]; - assert(cur != BVH::emptyNode); - if (likely(mask == 0)) break; - stackPtr->ptr = cur; - stackPtr->mask = cur_mask; - stackPtr++; - } - } - - /*! this is a leaf node */ - assert(cur != BVH::emptyNode); - STAT3(shadow.trav_leaves,1,1,1); - size_t num; PrimitiveK<K>* prim = (PrimitiveK<K>*)cur.leaf(num); - - size_t bits = cur_mask; - size_t lazy_node = 0; - - for (; bits != 0;) - { - const size_t rayID = bscf(bits); - - RayK<K> &ray = *inputPackets[rayID / K]; - const size_t k = rayID % K; - if (PrimitiveIntersectorK<K>::occluded(This, ray, k, context, prim, num, lazy_node)) - { - ray.tfar[k] = neg_inf; - terminated |= (size_t)1 << rayID; - } - - /* lazy node */ - if (unlikely(lazy_node)) - { - stackPtr->ptr = lazy_node; - stackPtr->mask = cur_mask; - stackPtr++; - } - } - - if (unlikely(terminated == (size_t)-1)) break; - } - } - - //////////////////////////////////////////////////////////////////////////////// - /// ArrayIntersectorKStream Definitions - //////////////////////////////////////////////////////////////////////////////// - - template<bool filter> - struct Triangle4IntersectorStreamMoeller { - template<int K> using Type = ArrayIntersectorKStream<K,TriangleMIntersectorKMoeller<4 COMMA K COMMA true>>; - }; - - template<bool filter> - struct Triangle4vIntersectorStreamPluecker { - template<int K> using Type = ArrayIntersectorKStream<K,TriangleMvIntersectorKPluecker<4 COMMA K COMMA true>>; - }; - - template<bool filter> - struct Triangle4iIntersectorStreamMoeller { - template<int K> using Type = ArrayIntersectorKStream<K,TriangleMiIntersectorKMoeller<4 COMMA K COMMA true>>; - }; - - template<bool filter> - struct Triangle4iIntersectorStreamPluecker { - template<int K> using Type = ArrayIntersectorKStream<K,TriangleMiIntersectorKPluecker<4 COMMA K COMMA true>>; - }; - - template<bool filter> - struct Quad4vIntersectorStreamMoeller { - template<int K> using Type = ArrayIntersectorKStream<K,QuadMvIntersectorKMoeller<4 COMMA K COMMA true>>; - }; - - template<bool filter> - struct Quad4iIntersectorStreamMoeller { - template<int K> using Type = ArrayIntersectorKStream<K,QuadMiIntersectorKMoeller<4 COMMA K COMMA true>>; - }; - - template<bool filter> - struct Quad4vIntersectorStreamPluecker { - template<int K> using Type = ArrayIntersectorKStream<K,QuadMvIntersectorKPluecker<4 COMMA K COMMA true>>; - }; - - template<bool filter> - struct Quad4iIntersectorStreamPluecker { - template<int K> using Type = ArrayIntersectorKStream<K,QuadMiIntersectorKPluecker<4 COMMA K COMMA true>>; - }; - - struct ObjectIntersectorStream { - template<int K> using Type = ArrayIntersectorKStream<K,ObjectIntersectorK<K COMMA false>>; - }; - - struct InstanceIntersectorStream { - template<int K> using Type = ArrayIntersectorKStream<K,InstanceIntersectorK<K>>; - }; - - // ===================================================================================================== - // ===================================================================================================== - // ===================================================================================================== - - template<int N> - void BVHNIntersectorStreamPacketFallback<N>::intersect(Accel::Intersectors* __restrict__ This, - RayHitN** inputRays, - size_t numTotalRays, - IntersectContext* context) - { - if (unlikely(context->isCoherent())) - intersectK(This, (RayHitK<VSIZEL>**)inputRays, numTotalRays, context); - else - intersectK(This, (RayHitK<VSIZEX>**)inputRays, numTotalRays, context); - } - - template<int N> - void BVHNIntersectorStreamPacketFallback<N>::occluded(Accel::Intersectors* __restrict__ This, - RayN** inputRays, - size_t numTotalRays, - IntersectContext* context) - { - if (unlikely(context->isCoherent())) - occludedK(This, (RayK<VSIZEL>**)inputRays, numTotalRays, context); - else - occludedK(This, (RayK<VSIZEX>**)inputRays, numTotalRays, context); - } - - template<int N> - template<int K> - __noinline void BVHNIntersectorStreamPacketFallback<N>::intersectK(Accel::Intersectors* __restrict__ This, - RayHitK<K>** inputRays, - size_t numTotalRays, - IntersectContext* context) - { - /* fallback to packets */ - for (size_t i = 0; i < numTotalRays; i += K) - { - const vint<K> vi = vint<K>(int(i)) + vint<K>(step); - vbool<K> valid = vi < vint<K>(int(numTotalRays)); - RayHitK<K>& ray = *(inputRays[i / K]); - valid &= ray.tnear() <= ray.tfar; - This->intersect(valid, ray, context); - } - } - - template<int N> - template<int K> - __noinline void BVHNIntersectorStreamPacketFallback<N>::occludedK(Accel::Intersectors* __restrict__ This, - RayK<K>** inputRays, - size_t numTotalRays, - IntersectContext* context) - { - /* fallback to packets */ - for (size_t i = 0; i < numTotalRays; i += K) - { - const vint<K> vi = vint<K>(int(i)) + vint<K>(step); - vbool<K> valid = vi < vint<K>(int(numTotalRays)); - RayK<K>& ray = *(inputRays[i / K]); - valid &= ray.tnear() <= ray.tfar; - This->occluded(valid, ray, context); - } - } - } -} diff --git a/thirdparty/embree/kernels/bvh/bvh_intersector_stream.h b/thirdparty/embree/kernels/bvh/bvh_intersector_stream.h deleted file mode 100644 index c7e040fadb..0000000000 --- a/thirdparty/embree/kernels/bvh/bvh_intersector_stream.h +++ /dev/null @@ -1,281 +0,0 @@ -// Copyright 2009-2021 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 - -#pragma once - -#include "node_intersector_packet_stream.h" -#include "node_intersector_frustum.h" -#include "bvh_traverser_stream.h" - -namespace embree -{ - namespace isa - { - /*! BVH ray stream intersector. */ - template<int N, int types, bool robust, typename PrimitiveIntersector> - class BVHNIntersectorStream - { - /* shortcuts for frequently used types */ - template<int K> using PrimitiveIntersectorK = typename PrimitiveIntersector::template Type<K>; - template<int K> using PrimitiveK = typename PrimitiveIntersectorK<K>::PrimitiveK; - typedef BVHN<N> BVH; - typedef typename BVH::NodeRef NodeRef; - typedef typename BVH::BaseNode BaseNode; - typedef typename BVH::AABBNode AABBNode; - typedef typename BVH::AABBNodeMB AABBNodeMB; - - template<int K> - __forceinline static size_t initPacketsAndFrustum(RayK<K>** inputPackets, size_t numOctantRays, - TravRayKStream<K, robust>* packets, Frustum<robust>& frustum, bool& commonOctant) - { - const size_t numPackets = (numOctantRays+K-1)/K; - - Vec3vf<K> tmp_min_rdir(pos_inf); - Vec3vf<K> tmp_max_rdir(neg_inf); - Vec3vf<K> tmp_min_org(pos_inf); - Vec3vf<K> tmp_max_org(neg_inf); - vfloat<K> tmp_min_dist(pos_inf); - vfloat<K> tmp_max_dist(neg_inf); - - size_t m_active = 0; - for (size_t i = 0; i < numPackets; i++) - { - const vfloat<K> tnear = inputPackets[i]->tnear(); - const vfloat<K> tfar = inputPackets[i]->tfar; - vbool<K> m_valid = (tnear <= tfar) & (tnear >= 0.0f); - -#if defined(EMBREE_IGNORE_INVALID_RAYS) - m_valid &= inputPackets[i]->valid(); -#endif - - m_active |= (size_t)movemask(m_valid) << (i*K); - - vfloat<K> packet_min_dist = max(tnear, 0.0f); - vfloat<K> packet_max_dist = select(m_valid, tfar, neg_inf); - tmp_min_dist = min(tmp_min_dist, packet_min_dist); - tmp_max_dist = max(tmp_max_dist, packet_max_dist); - - const Vec3vf<K>& org = inputPackets[i]->org; - const Vec3vf<K>& dir = inputPackets[i]->dir; - - new (&packets[i]) TravRayKStream<K, robust>(org, dir, packet_min_dist, packet_max_dist); - - tmp_min_rdir = min(tmp_min_rdir, select(m_valid, packets[i].rdir, Vec3vf<K>(pos_inf))); - tmp_max_rdir = max(tmp_max_rdir, select(m_valid, packets[i].rdir, Vec3vf<K>(neg_inf))); - tmp_min_org = min(tmp_min_org , select(m_valid,org , Vec3vf<K>(pos_inf))); - tmp_max_org = max(tmp_max_org , select(m_valid,org , Vec3vf<K>(neg_inf))); - } - - m_active &= (numOctantRays == (8 * sizeof(size_t))) ? (size_t)-1 : (((size_t)1 << numOctantRays)-1); - - - const Vec3fa reduced_min_rdir(reduce_min(tmp_min_rdir.x), - reduce_min(tmp_min_rdir.y), - reduce_min(tmp_min_rdir.z)); - - const Vec3fa reduced_max_rdir(reduce_max(tmp_max_rdir.x), - reduce_max(tmp_max_rdir.y), - reduce_max(tmp_max_rdir.z)); - - const Vec3fa reduced_min_origin(reduce_min(tmp_min_org.x), - reduce_min(tmp_min_org.y), - reduce_min(tmp_min_org.z)); - - const Vec3fa reduced_max_origin(reduce_max(tmp_max_org.x), - reduce_max(tmp_max_org.y), - reduce_max(tmp_max_org.z)); - - commonOctant = - (reduced_max_rdir.x < 0.0f || reduced_min_rdir.x >= 0.0f) && - (reduced_max_rdir.y < 0.0f || reduced_min_rdir.y >= 0.0f) && - (reduced_max_rdir.z < 0.0f || reduced_min_rdir.z >= 0.0f); - - const float frustum_min_dist = reduce_min(tmp_min_dist); - const float frustum_max_dist = reduce_max(tmp_max_dist); - - frustum.init(reduced_min_origin, reduced_max_origin, - reduced_min_rdir, reduced_max_rdir, - frustum_min_dist, frustum_max_dist, - N); - - return m_active; - } - - template<int K> - __forceinline static size_t intersectAABBNodePacket(size_t m_active, - const TravRayKStream<K,robust>* packets, - const AABBNode* __restrict__ node, - size_t boxID, - const NearFarPrecalculations& nf) - { - assert(m_active); - const size_t startPacketID = bsf(m_active) / K; - const size_t endPacketID = bsr(m_active) / K; - size_t m_trav_active = 0; - for (size_t i = startPacketID; i <= endPacketID; i++) - { - const size_t m_hit = intersectNodeK<N>(node, boxID, packets[i], nf); - m_trav_active |= m_hit << (i*K); - } - return m_trav_active; - } - - template<int K> - __forceinline static size_t traverseCoherentStream(size_t m_active, - TravRayKStream<K, robust>* packets, - const AABBNode* __restrict__ node, - const Frustum<robust>& frustum, - size_t* maskK, - vfloat<N>& dist) - { - size_t m_node_hit = intersectNodeFrustum<N>(node, frustum, dist); - const size_t first_index = bsf(m_active); - const size_t first_packetID = first_index / K; - const size_t first_rayID = first_index % K; - size_t m_first_hit = intersectNode1<N>(node, packets[first_packetID], first_rayID, frustum.nf); - - /* this make traversal independent of the ordering of rays */ - size_t m_node = m_node_hit ^ m_first_hit; - while (unlikely(m_node)) - { - const size_t boxID = bscf(m_node); - const size_t m_current = m_active & intersectAABBNodePacket(m_active, packets, node, boxID, frustum.nf); - m_node_hit ^= m_current ? (size_t)0 : ((size_t)1 << boxID); - maskK[boxID] = m_current; - } - return m_node_hit; - } - - // TODO: explicit 16-wide path for KNL - template<int K> - __forceinline static vint<N> traverseIncoherentStream(size_t m_active, - TravRayKStreamFast<K>* __restrict__ packets, - const AABBNode* __restrict__ node, - const NearFarPrecalculations& nf, - const int shiftTable[32]) - { - const vfloat<N> bminX = vfloat<N>(*(const vfloat<N>*)((const char*)&node->lower_x + nf.nearX)); - const vfloat<N> bminY = vfloat<N>(*(const vfloat<N>*)((const char*)&node->lower_x + nf.nearY)); - const vfloat<N> bminZ = vfloat<N>(*(const vfloat<N>*)((const char*)&node->lower_x + nf.nearZ)); - const vfloat<N> bmaxX = vfloat<N>(*(const vfloat<N>*)((const char*)&node->lower_x + nf.farX)); - const vfloat<N> bmaxY = vfloat<N>(*(const vfloat<N>*)((const char*)&node->lower_x + nf.farY)); - const vfloat<N> bmaxZ = vfloat<N>(*(const vfloat<N>*)((const char*)&node->lower_x + nf.farZ)); - assert(m_active); - vint<N> vmask(zero); - do - { - STAT3(shadow.trav_nodes,1,1,1); - const size_t rayID = bscf(m_active); - assert(rayID < MAX_INTERNAL_STREAM_SIZE); - TravRayKStream<K,robust> &p = packets[rayID / K]; - const size_t i = rayID % K; - const vint<N> bitmask(shiftTable[rayID]); - -#if defined (__aarch64__) - const vfloat<N> tNearX = madd(bminX, p.rdir.x[i], p.neg_org_rdir.x[i]); - const vfloat<N> tNearY = madd(bminY, p.rdir.y[i], p.neg_org_rdir.y[i]); - const vfloat<N> tNearZ = madd(bminZ, p.rdir.z[i], p.neg_org_rdir.z[i]); - const vfloat<N> tFarX = madd(bmaxX, p.rdir.x[i], p.neg_org_rdir.x[i]); - const vfloat<N> tFarY = madd(bmaxY, p.rdir.y[i], p.neg_org_rdir.y[i]); - const vfloat<N> tFarZ = madd(bmaxZ, p.rdir.z[i], p.neg_org_rdir.z[i]); -#else - const vfloat<N> tNearX = msub(bminX, p.rdir.x[i], p.org_rdir.x[i]); - const vfloat<N> tNearY = msub(bminY, p.rdir.y[i], p.org_rdir.y[i]); - const vfloat<N> tNearZ = msub(bminZ, p.rdir.z[i], p.org_rdir.z[i]); - const vfloat<N> tFarX = msub(bmaxX, p.rdir.x[i], p.org_rdir.x[i]); - const vfloat<N> tFarY = msub(bmaxY, p.rdir.y[i], p.org_rdir.y[i]); - const vfloat<N> tFarZ = msub(bmaxZ, p.rdir.z[i], p.org_rdir.z[i]); -#endif - - const vfloat<N> tNear = maxi(tNearX, tNearY, tNearZ, vfloat<N>(p.tnear[i])); - const vfloat<N> tFar = mini(tFarX , tFarY , tFarZ, vfloat<N>(p.tfar[i])); - - const vbool<N> hit_mask = tNear <= tFar; -#if defined(__AVX2__) - vmask = vmask | (bitmask & vint<N>(hit_mask)); -#else - vmask = select(hit_mask, vmask | bitmask, vmask); -#endif - } while(m_active); - return vmask; - } - - template<int K> - __forceinline static vint<N> traverseIncoherentStream(size_t m_active, - TravRayKStreamRobust<K>* __restrict__ packets, - const AABBNode* __restrict__ node, - const NearFarPrecalculations& nf, - const int shiftTable[32]) - { - const vfloat<N> bminX = vfloat<N>(*(const vfloat<N>*)((const char*)&node->lower_x + nf.nearX)); - const vfloat<N> bminY = vfloat<N>(*(const vfloat<N>*)((const char*)&node->lower_x + nf.nearY)); - const vfloat<N> bminZ = vfloat<N>(*(const vfloat<N>*)((const char*)&node->lower_x + nf.nearZ)); - const vfloat<N> bmaxX = vfloat<N>(*(const vfloat<N>*)((const char*)&node->lower_x + nf.farX)); - const vfloat<N> bmaxY = vfloat<N>(*(const vfloat<N>*)((const char*)&node->lower_x + nf.farY)); - const vfloat<N> bmaxZ = vfloat<N>(*(const vfloat<N>*)((const char*)&node->lower_x + nf.farZ)); - assert(m_active); - vint<N> vmask(zero); - do - { - STAT3(shadow.trav_nodes,1,1,1); - const size_t rayID = bscf(m_active); - assert(rayID < MAX_INTERNAL_STREAM_SIZE); - TravRayKStream<K,robust> &p = packets[rayID / K]; - const size_t i = rayID % K; - const vint<N> bitmask(shiftTable[rayID]); - const vfloat<N> tNearX = (bminX - p.org.x[i]) * p.rdir.x[i]; - const vfloat<N> tNearY = (bminY - p.org.y[i]) * p.rdir.y[i]; - const vfloat<N> tNearZ = (bminZ - p.org.z[i]) * p.rdir.z[i]; - const vfloat<N> tFarX = (bmaxX - p.org.x[i]) * p.rdir.x[i]; - const vfloat<N> tFarY = (bmaxY - p.org.y[i]) * p.rdir.y[i]; - const vfloat<N> tFarZ = (bmaxZ - p.org.z[i]) * p.rdir.z[i]; - const vfloat<N> tNear = maxi(tNearX, tNearY, tNearZ, vfloat<N>(p.tnear[i])); - const vfloat<N> tFar = mini(tFarX , tFarY , tFarZ, vfloat<N>(p.tfar[i])); - const float round_down = 1.0f-2.0f*float(ulp); - const float round_up = 1.0f+2.0f*float(ulp); - const vbool<N> hit_mask = round_down*tNear <= round_up*tFar; -#if defined(__AVX2__) - vmask = vmask | (bitmask & vint<N>(hit_mask)); -#else - vmask = select(hit_mask, vmask | bitmask, vmask); -#endif - } while(m_active); - return vmask; - } - - - static const size_t stackSizeSingle = 1+(N-1)*BVH::maxDepth; - - public: - static void intersect(Accel::Intersectors* This, RayHitN** inputRays, size_t numRays, IntersectContext* context); - static void occluded (Accel::Intersectors* This, RayN** inputRays, size_t numRays, IntersectContext* context); - - private: - template<int K> - static void intersectCoherent(Accel::Intersectors* This, RayHitK<K>** inputRays, size_t numRays, IntersectContext* context); - - template<int K> - static void occludedCoherent(Accel::Intersectors* This, RayK<K>** inputRays, size_t numRays, IntersectContext* context); - - template<int K> - static void occludedIncoherent(Accel::Intersectors* This, RayK<K>** inputRays, size_t numRays, IntersectContext* context); - }; - - - /*! BVH ray stream intersector with direct fallback to packets. */ - template<int N> - class BVHNIntersectorStreamPacketFallback - { - public: - static void intersect(Accel::Intersectors* This, RayHitN** inputRays, size_t numRays, IntersectContext* context); - static void occluded (Accel::Intersectors* This, RayN** inputRays, size_t numRays, IntersectContext* context); - - private: - template<int K> - static void intersectK(Accel::Intersectors* This, RayHitK<K>** inputRays, size_t numRays, IntersectContext* context); - - template<int K> - static void occludedK(Accel::Intersectors* This, RayK<K>** inputRays, size_t numRays, IntersectContext* context); - }; - } -} diff --git a/thirdparty/embree/kernels/bvh/bvh_intersector_stream_bvh4.cpp b/thirdparty/embree/kernels/bvh/bvh_intersector_stream_bvh4.cpp deleted file mode 100644 index c3e5f137b8..0000000000 --- a/thirdparty/embree/kernels/bvh/bvh_intersector_stream_bvh4.cpp +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright 2009-2021 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 - -#include "bvh_intersector_stream.cpp" - -namespace embree -{ - namespace isa - { - - //////////////////////////////////////////////////////////////////////////////// - /// General BVHIntersectorStreamPacketFallback Intersector - //////////////////////////////////////////////////////////////////////////////// - - DEFINE_INTERSECTORN(BVH4IntersectorStreamPacketFallback,BVHNIntersectorStreamPacketFallback<4>); - - //////////////////////////////////////////////////////////////////////////////// - /// BVH4IntersectorStream Definitions - //////////////////////////////////////////////////////////////////////////////// - - IF_ENABLED_TRIS(DEFINE_INTERSECTORN(BVH4Triangle4iIntersectorStreamMoeller, BVHNIntersectorStream<4 COMMA BVH_AN1 COMMA false COMMA Triangle4iIntersectorStreamMoeller<true>>)); - IF_ENABLED_TRIS(DEFINE_INTERSECTORN(BVH4Triangle4vIntersectorStreamPluecker, BVHNIntersectorStream<4 COMMA BVH_AN1 COMMA true COMMA Triangle4vIntersectorStreamPluecker<true>>)); - IF_ENABLED_TRIS(DEFINE_INTERSECTORN(BVH4Triangle4iIntersectorStreamPluecker, BVHNIntersectorStream<4 COMMA BVH_AN1 COMMA true COMMA Triangle4iIntersectorStreamPluecker<true>>)); - IF_ENABLED_TRIS(DEFINE_INTERSECTORN(BVH4Triangle4IntersectorStreamMoeller, BVHNIntersectorStream<4 COMMA BVH_AN1 COMMA false COMMA Triangle4IntersectorStreamMoeller<true>>)); - IF_ENABLED_TRIS(DEFINE_INTERSECTORN(BVH4Triangle4IntersectorStreamMoellerNoFilter, BVHNIntersectorStream<4 COMMA BVH_AN1 COMMA false COMMA Triangle4IntersectorStreamMoeller<false>>)); - - IF_ENABLED_QUADS(DEFINE_INTERSECTORN(BVH4Quad4vIntersectorStreamMoeller, BVHNIntersectorStream<4 COMMA BVH_AN1 COMMA false COMMA Quad4vIntersectorStreamMoeller<true>>)); - IF_ENABLED_QUADS(DEFINE_INTERSECTORN(BVH4Quad4vIntersectorStreamMoellerNoFilter,BVHNIntersectorStream<4 COMMA BVH_AN1 COMMA false COMMA Quad4vIntersectorStreamMoeller<false>>)); - IF_ENABLED_QUADS(DEFINE_INTERSECTORN(BVH4Quad4iIntersectorStreamMoeller, BVHNIntersectorStream<4 COMMA BVH_AN1 COMMA false COMMA Quad4iIntersectorStreamMoeller<true>>)); - IF_ENABLED_QUADS(DEFINE_INTERSECTORN(BVH4Quad4vIntersectorStreamPluecker, BVHNIntersectorStream<4 COMMA BVH_AN1 COMMA true COMMA Quad4vIntersectorStreamPluecker<true>>)); - IF_ENABLED_QUADS(DEFINE_INTERSECTORN(BVH4Quad4iIntersectorStreamPluecker, BVHNIntersectorStream<4 COMMA BVH_AN1 COMMA true COMMA Quad4iIntersectorStreamPluecker<true>>)); - - IF_ENABLED_USER(DEFINE_INTERSECTORN(BVH4VirtualIntersectorStream,BVHNIntersectorStream<4 COMMA BVH_AN1 COMMA false COMMA ObjectIntersectorStream>)); - IF_ENABLED_INSTANCE(DEFINE_INTERSECTORN(BVH4InstanceIntersectorStream,BVHNIntersectorStream<4 COMMA BVH_AN1 COMMA false COMMA InstanceIntersectorStream>)); - } -} diff --git a/thirdparty/embree/kernels/bvh/bvh_intersector_stream_filters.cpp b/thirdparty/embree/kernels/bvh/bvh_intersector_stream_filters.cpp deleted file mode 100644 index b858eb163f..0000000000 --- a/thirdparty/embree/kernels/bvh/bvh_intersector_stream_filters.cpp +++ /dev/null @@ -1,657 +0,0 @@ -// Copyright 2009-2021 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 - -#include "bvh_intersector_stream_filters.h" -#include "bvh_intersector_stream.h" - -namespace embree -{ - namespace isa - { - template<int K, bool intersect> - __noinline void RayStreamFilter::filterAOS(Scene* scene, void* _rayN, size_t N, size_t stride, IntersectContext* context) - { - RayStreamAOS rayN(_rayN); - - /* use fast path for coherent ray mode */ - if (unlikely(context->isCoherent())) - { - __aligned(64) RayTypeK<K, intersect> rays[MAX_INTERNAL_STREAM_SIZE / K]; - __aligned(64) RayTypeK<K, intersect>* rayPtrs[MAX_INTERNAL_STREAM_SIZE / K]; - - for (size_t i = 0; i < N; i += MAX_INTERNAL_STREAM_SIZE) - { - const size_t size = min(N - i, MAX_INTERNAL_STREAM_SIZE); - - /* convert from AOS to SOA */ - for (size_t j = 0; j < size; j += K) - { - const vint<K> vij = vint<K>(int(i+j)) + vint<K>(step); - const vbool<K> valid = vij < vint<K>(int(N)); - const vint<K> offset = vij * int(stride); - const size_t packetIndex = j / K; - - RayTypeK<K, intersect> ray = rayN.getRayByOffset<K>(valid, offset); - ray.tnear() = select(valid, ray.tnear(), zero); - ray.tfar = select(valid, ray.tfar, neg_inf); - - rays[packetIndex] = ray; - rayPtrs[packetIndex] = &rays[packetIndex]; // rayPtrs might get reordered for occludedN - } - - /* trace stream */ - scene->intersectors.intersectN(rayPtrs, size, context); - - /* convert from SOA to AOS */ - for (size_t j = 0; j < size; j += K) - { - const vint<K> vij = vint<K>(int(i+j)) + vint<K>(step); - const vbool<K> valid = vij < vint<K>(int(N)); - const vint<K> offset = vij * int(stride); - const size_t packetIndex = j / K; - rayN.setHitByOffset(valid, offset, rays[packetIndex]); - } - } - } - else if (unlikely(!intersect)) - { - /* octant sorting for occlusion rays */ - __aligned(64) unsigned int octants[8][MAX_INTERNAL_STREAM_SIZE]; - __aligned(64) RayK<K> rays[MAX_INTERNAL_STREAM_SIZE / K]; - __aligned(64) RayK<K>* rayPtrs[MAX_INTERNAL_STREAM_SIZE / K]; - - unsigned int raysInOctant[8]; - for (unsigned int i = 0; i < 8; i++) - raysInOctant[i] = 0; - size_t inputRayID = 0; - - for (;;) - { - int curOctant = -1; - - /* sort rays into octants */ - for (; inputRayID < N;) - { - const Ray& ray = rayN.getRayByOffset(inputRayID * stride); - - /* skip invalid rays */ - if (unlikely(ray.tnear() > ray.tfar || ray.tfar < 0.0f)) { inputRayID++; continue; } // ignore invalid or already occluded rays -#if defined(EMBREE_IGNORE_INVALID_RAYS) - if (unlikely(!ray.valid())) { inputRayID++; continue; } -#endif - - const unsigned int octantID = movemask(vfloat4(Vec3fa(ray.dir)) < 0.0f) & 0x7; - - assert(octantID < 8); - octants[octantID][raysInOctant[octantID]++] = (unsigned int)inputRayID; - inputRayID++; - if (unlikely(raysInOctant[octantID] == MAX_INTERNAL_STREAM_SIZE)) - { - curOctant = octantID; - break; - } - } - - /* need to flush rays in octant? */ - if (unlikely(curOctant == -1)) - { - for (unsigned int i = 0; i < 8; i++) - if (raysInOctant[i]) { curOctant = i; break; } - } - - /* all rays traced? */ - if (unlikely(curOctant == -1)) - break; - - unsigned int* const rayIDs = &octants[curOctant][0]; - const unsigned int numOctantRays = raysInOctant[curOctant]; - assert(numOctantRays); - - for (unsigned int j = 0; j < numOctantRays; j += K) - { - const vint<K> vi = vint<K>(int(j)) + vint<K>(step); - const vbool<K> valid = vi < vint<K>(int(numOctantRays)); - const vint<K> offset = *(vint<K>*)&rayIDs[j] * int(stride); - RayK<K>& ray = rays[j/K]; - rayPtrs[j/K] = &ray; - ray = rayN.getRayByOffset<K>(valid, offset); - ray.tnear() = select(valid, ray.tnear(), zero); - ray.tfar = select(valid, ray.tfar, neg_inf); - } - - scene->intersectors.occludedN(rayPtrs, numOctantRays, context); - - for (unsigned int j = 0; j < numOctantRays; j += K) - { - const vint<K> vi = vint<K>(int(j)) + vint<K>(step); - const vbool<K> valid = vi < vint<K>(int(numOctantRays)); - const vint<K> offset = *(vint<K>*)&rayIDs[j] * int(stride); - rayN.setHitByOffset<K>(valid, offset, rays[j/K]); - } - - raysInOctant[curOctant] = 0; - } - } - else - { - /* fallback to packets */ - for (size_t i = 0; i < N; i += K) - { - const vint<K> vi = vint<K>(int(i)) + vint<K>(step); - vbool<K> valid = vi < vint<K>(int(N)); - const vint<K> offset = vi * int(stride); - - RayTypeK<K, intersect> ray = rayN.getRayByOffset<K>(valid, offset); - valid &= ray.tnear() <= ray.tfar; - - scene->intersectors.intersect(valid, ray, context); - - rayN.setHitByOffset<K>(valid, offset, ray); - } - } - } - - template<int K, bool intersect> - __noinline void RayStreamFilter::filterAOP(Scene* scene, void** _rayN, size_t N, IntersectContext* context) - { - RayStreamAOP rayN(_rayN); - - /* use fast path for coherent ray mode */ - if (unlikely(context->isCoherent())) - { - __aligned(64) RayTypeK<K, intersect> rays[MAX_INTERNAL_STREAM_SIZE / K]; - __aligned(64) RayTypeK<K, intersect>* rayPtrs[MAX_INTERNAL_STREAM_SIZE / K]; - - for (size_t i = 0; i < N; i += MAX_INTERNAL_STREAM_SIZE) - { - const size_t size = min(N - i, MAX_INTERNAL_STREAM_SIZE); - - /* convert from AOP to SOA */ - for (size_t j = 0; j < size; j += K) - { - const vint<K> vij = vint<K>(int(i+j)) + vint<K>(step); - const vbool<K> valid = vij < vint<K>(int(N)); - const size_t packetIndex = j / K; - - RayTypeK<K, intersect> ray = rayN.getRayByIndex<K>(valid, vij); - ray.tnear() = select(valid, ray.tnear(), zero); - ray.tfar = select(valid, ray.tfar, neg_inf); - - rays[packetIndex] = ray; - rayPtrs[packetIndex] = &rays[packetIndex]; // rayPtrs might get reordered for occludedN - } - - /* trace stream */ - scene->intersectors.intersectN(rayPtrs, size, context); - - /* convert from SOA to AOP */ - for (size_t j = 0; j < size; j += K) - { - const vint<K> vij = vint<K>(int(i+j)) + vint<K>(step); - const vbool<K> valid = vij < vint<K>(int(N)); - const size_t packetIndex = j / K; - - rayN.setHitByIndex<K>(valid, vij, rays[packetIndex]); - } - } - } - else if (unlikely(!intersect)) - { - /* octant sorting for occlusion rays */ - __aligned(64) unsigned int octants[8][MAX_INTERNAL_STREAM_SIZE]; - __aligned(64) RayK<K> rays[MAX_INTERNAL_STREAM_SIZE / K]; - __aligned(64) RayK<K>* rayPtrs[MAX_INTERNAL_STREAM_SIZE / K]; - - unsigned int raysInOctant[8]; - for (unsigned int i = 0; i < 8; i++) - raysInOctant[i] = 0; - size_t inputRayID = 0; - - for (;;) - { - int curOctant = -1; - - /* sort rays into octants */ - for (; inputRayID < N;) - { - const Ray& ray = rayN.getRayByIndex(inputRayID); - - /* skip invalid rays */ - if (unlikely(ray.tnear() > ray.tfar || ray.tfar < 0.0f)) { inputRayID++; continue; } // ignore invalid or already occluded rays -#if defined(EMBREE_IGNORE_INVALID_RAYS) - if (unlikely(!ray.valid())) { inputRayID++; continue; } -#endif - - const unsigned int octantID = movemask(lt_mask(ray.dir,Vec3fa(0.0f))); - - assert(octantID < 8); - octants[octantID][raysInOctant[octantID]++] = (unsigned int)inputRayID; - inputRayID++; - if (unlikely(raysInOctant[octantID] == MAX_INTERNAL_STREAM_SIZE)) - { - curOctant = octantID; - break; - } - } - - /* need to flush rays in octant? */ - if (unlikely(curOctant == -1)) - { - for (unsigned int i = 0; i < 8; i++) - if (raysInOctant[i]) { curOctant = i; break; } - } - - /* all rays traced? */ - if (unlikely(curOctant == -1)) - break; - - unsigned int* const rayIDs = &octants[curOctant][0]; - const unsigned int numOctantRays = raysInOctant[curOctant]; - assert(numOctantRays); - - for (unsigned int j = 0; j < numOctantRays; j += K) - { - const vint<K> vi = vint<K>(int(j)) + vint<K>(step); - const vbool<K> valid = vi < vint<K>(int(numOctantRays)); - const vint<K> index = *(vint<K>*)&rayIDs[j]; - RayK<K>& ray = rays[j/K]; - rayPtrs[j/K] = &ray; - ray = rayN.getRayByIndex<K>(valid, index); - ray.tnear() = select(valid, ray.tnear(), zero); - ray.tfar = select(valid, ray.tfar, neg_inf); - } - - scene->intersectors.occludedN(rayPtrs, numOctantRays, context); - - for (unsigned int j = 0; j < numOctantRays; j += K) - { - const vint<K> vi = vint<K>(int(j)) + vint<K>(step); - const vbool<K> valid = vi < vint<K>(int(numOctantRays)); - const vint<K> index = *(vint<K>*)&rayIDs[j]; - rayN.setHitByIndex<K>(valid, index, rays[j/K]); - } - - raysInOctant[curOctant] = 0; - } - } - else - { - /* fallback to packets */ - for (size_t i = 0; i < N; i += K) - { - const vint<K> vi = vint<K>(int(i)) + vint<K>(step); - vbool<K> valid = vi < vint<K>(int(N)); - - RayTypeK<K, intersect> ray = rayN.getRayByIndex<K>(valid, vi); - valid &= ray.tnear() <= ray.tfar; - - scene->intersectors.intersect(valid, ray, context); - - rayN.setHitByIndex<K>(valid, vi, ray); - } - } - } - - template<int K, bool intersect> - __noinline void RayStreamFilter::filterSOA(Scene* scene, char* rayData, size_t N, size_t numPackets, size_t stride, IntersectContext* context) - { - const size_t rayDataAlignment = (size_t)rayData % (K*sizeof(float)); - const size_t offsetAlignment = (size_t)stride % (K*sizeof(float)); - - /* fast path for packets with the correct width and data alignment */ - if (likely(N == K && - !rayDataAlignment && - !offsetAlignment)) - { - if (unlikely(context->isCoherent())) - { - __aligned(64) RayTypeK<K, intersect>* rayPtrs[MAX_INTERNAL_STREAM_SIZE / K]; - - size_t packetIndex = 0; - for (size_t i = 0; i < numPackets; i++) - { - const size_t offset = i * stride; - RayTypeK<K, intersect>& ray = *(RayTypeK<K, intersect>*)(rayData + offset); - rayPtrs[packetIndex++] = &ray; - - /* trace as stream */ - if (unlikely(packetIndex == MAX_INTERNAL_STREAM_SIZE / K)) - { - const size_t size = packetIndex*K; - scene->intersectors.intersectN(rayPtrs, size, context); - packetIndex = 0; - } - } - - /* flush remaining packets */ - if (unlikely(packetIndex > 0)) - { - const size_t size = packetIndex*K; - scene->intersectors.intersectN(rayPtrs, size, context); - } - } - else if (unlikely(!intersect)) - { - /* octant sorting for occlusion rays */ - RayStreamSOA rayN(rayData, K); - - __aligned(64) unsigned int octants[8][MAX_INTERNAL_STREAM_SIZE]; - __aligned(64) RayK<K> rays[MAX_INTERNAL_STREAM_SIZE / K]; - __aligned(64) RayK<K>* rayPtrs[MAX_INTERNAL_STREAM_SIZE / K]; - - unsigned int raysInOctant[8]; - for (unsigned int i = 0; i < 8; i++) - raysInOctant[i] = 0; - size_t inputRayID = 0; - - for (;;) - { - int curOctant = -1; - - /* sort rays into octants */ - for (; inputRayID < N*numPackets;) - { - const size_t offset = (inputRayID / K) * stride + (inputRayID % K) * sizeof(float); - - /* skip invalid rays */ - if (unlikely(!rayN.isValidByOffset(offset))) { inputRayID++; continue; } // ignore invalid or already occluded rays - #if defined(EMBREE_IGNORE_INVALID_RAYS) - __aligned(64) Ray ray = rayN.getRayByOffset(offset); - if (unlikely(!ray.valid())) { inputRayID++; continue; } - #endif - - const unsigned int octantID = (unsigned int)rayN.getOctantByOffset(offset); - - assert(octantID < 8); - octants[octantID][raysInOctant[octantID]++] = (unsigned int)offset; - inputRayID++; - if (unlikely(raysInOctant[octantID] == MAX_INTERNAL_STREAM_SIZE)) - { - curOctant = octantID; - break; - } - } - - /* need to flush rays in octant? */ - if (unlikely(curOctant == -1)) - { - for (unsigned int i = 0; i < 8; i++) - if (raysInOctant[i]) { curOctant = i; break; } - } - - /* all rays traced? */ - if (unlikely(curOctant == -1)) - break; - - unsigned int* const rayOffsets = &octants[curOctant][0]; - const unsigned int numOctantRays = raysInOctant[curOctant]; - assert(numOctantRays); - - for (unsigned int j = 0; j < numOctantRays; j += K) - { - const vint<K> vi = vint<K>(int(j)) + vint<K>(step); - const vbool<K> valid = vi < vint<K>(int(numOctantRays)); - const vint<K> offset = *(vint<K>*)&rayOffsets[j]; - RayK<K>& ray = rays[j/K]; - rayPtrs[j/K] = &ray; - ray = rayN.getRayByOffset<K>(valid, offset); - ray.tnear() = select(valid, ray.tnear(), zero); - ray.tfar = select(valid, ray.tfar, neg_inf); - } - - scene->intersectors.occludedN(rayPtrs, numOctantRays, context); - - for (unsigned int j = 0; j < numOctantRays; j += K) - { - const vint<K> vi = vint<K>(int(j)) + vint<K>(step); - const vbool<K> valid = vi < vint<K>(int(numOctantRays)); - const vint<K> offset = *(vint<K>*)&rayOffsets[j]; - rayN.setHitByOffset(valid, offset, rays[j/K]); - } - raysInOctant[curOctant] = 0; - } - } - else - { - /* fallback to packets */ - for (size_t i = 0; i < numPackets; i++) - { - const size_t offset = i * stride; - RayTypeK<K, intersect>& ray = *(RayTypeK<K, intersect>*)(rayData + offset); - const vbool<K> valid = ray.tnear() <= ray.tfar; - - scene->intersectors.intersect(valid, ray, context); - } - } - } - else - { - /* fallback to packets for arbitrary packet size and alignment */ - for (size_t i = 0; i < numPackets; i++) - { - const size_t offsetN = i * stride; - RayStreamSOA rayN(rayData + offsetN, N); - - for (size_t j = 0; j < N; j += K) - { - const size_t offset = j * sizeof(float); - vbool<K> valid = (vint<K>(int(j)) + vint<K>(step)) < vint<K>(int(N)); - RayTypeK<K, intersect> ray = rayN.getRayByOffset<K>(valid, offset); - valid &= ray.tnear() <= ray.tfar; - - scene->intersectors.intersect(valid, ray, context); - - rayN.setHitByOffset(valid, offset, ray); - } - } - } - } - - template<int K, bool intersect> - __noinline void RayStreamFilter::filterSOP(Scene* scene, const void* _rayN, size_t N, IntersectContext* context) - { - RayStreamSOP& rayN = *(RayStreamSOP*)_rayN; - - /* use fast path for coherent ray mode */ - if (unlikely(context->isCoherent())) - { - __aligned(64) RayTypeK<K, intersect> rays[MAX_INTERNAL_STREAM_SIZE / K]; - __aligned(64) RayTypeK<K, intersect>* rayPtrs[MAX_INTERNAL_STREAM_SIZE / K]; - - for (size_t i = 0; i < N; i += MAX_INTERNAL_STREAM_SIZE) - { - const size_t size = min(N - i, MAX_INTERNAL_STREAM_SIZE); - - /* convert from SOP to SOA */ - for (size_t j = 0; j < size; j += K) - { - const vint<K> vij = vint<K>(int(i+j)) + vint<K>(step); - const vbool<K> valid = vij < vint<K>(int(N)); - const size_t offset = (i+j) * sizeof(float); - const size_t packetIndex = j / K; - - RayTypeK<K, intersect> ray = rayN.getRayByOffset<K>(valid, offset); - ray.tnear() = select(valid, ray.tnear(), zero); - ray.tfar = select(valid, ray.tfar, neg_inf); - - rays[packetIndex] = ray; - rayPtrs[packetIndex] = &rays[packetIndex]; // rayPtrs might get reordered for occludedN - } - - /* trace stream */ - scene->intersectors.intersectN(rayPtrs, size, context); - - /* convert from SOA to SOP */ - for (size_t j = 0; j < size; j += K) - { - const vint<K> vij = vint<K>(int(i+j)) + vint<K>(step); - const vbool<K> valid = vij < vint<K>(int(N)); - const size_t offset = (i+j) * sizeof(float); - const size_t packetIndex = j / K; - - rayN.setHitByOffset(valid, offset, rays[packetIndex]); - } - } - } - else if (unlikely(!intersect)) - { - /* octant sorting for occlusion rays */ - __aligned(64) unsigned int octants[8][MAX_INTERNAL_STREAM_SIZE]; - __aligned(64) RayK<K> rays[MAX_INTERNAL_STREAM_SIZE / K]; - __aligned(64) RayK<K>* rayPtrs[MAX_INTERNAL_STREAM_SIZE / K]; - - unsigned int raysInOctant[8]; - for (unsigned int i = 0; i < 8; i++) - raysInOctant[i] = 0; - size_t inputRayID = 0; - - for (;;) - { - int curOctant = -1; - - /* sort rays into octants */ - for (; inputRayID < N;) - { - const size_t offset = inputRayID * sizeof(float); - /* skip invalid rays */ - if (unlikely(!rayN.isValidByOffset(offset))) { inputRayID++; continue; } // ignore invalid or already occluded rays -#if defined(EMBREE_IGNORE_INVALID_RAYS) - __aligned(64) Ray ray = rayN.getRayByOffset(offset); - if (unlikely(!ray.valid())) { inputRayID++; continue; } -#endif - - const unsigned int octantID = (unsigned int)rayN.getOctantByOffset(offset); - - assert(octantID < 8); - octants[octantID][raysInOctant[octantID]++] = (unsigned int)offset; - inputRayID++; - if (unlikely(raysInOctant[octantID] == MAX_INTERNAL_STREAM_SIZE)) - { - curOctant = octantID; - break; - } - } - - /* need to flush rays in octant? */ - if (unlikely(curOctant == -1)) - { - for (unsigned int i = 0; i < 8; i++) - if (raysInOctant[i]) { curOctant = i; break; } - } - - /* all rays traced? */ - if (unlikely(curOctant == -1)) - break; - - unsigned int* const rayOffsets = &octants[curOctant][0]; - const unsigned int numOctantRays = raysInOctant[curOctant]; - assert(numOctantRays); - - for (unsigned int j = 0; j < numOctantRays; j += K) - { - const vint<K> vi = vint<K>(int(j)) + vint<K>(step); - const vbool<K> valid = vi < vint<K>(int(numOctantRays)); - const vint<K> offset = *(vint<K>*)&rayOffsets[j]; - RayK<K>& ray = rays[j/K]; - rayPtrs[j/K] = &ray; - ray = rayN.getRayByOffset<K>(valid, offset); - ray.tnear() = select(valid, ray.tnear(), zero); - ray.tfar = select(valid, ray.tfar, neg_inf); - } - - scene->intersectors.occludedN(rayPtrs, numOctantRays, context); - - for (unsigned int j = 0; j < numOctantRays; j += K) - { - const vint<K> vi = vint<K>(int(j)) + vint<K>(step); - const vbool<K> valid = vi < vint<K>(int(numOctantRays)); - const vint<K> offset = *(vint<K>*)&rayOffsets[j]; - rayN.setHitByOffset(valid, offset, rays[j/K]); - } - - raysInOctant[curOctant] = 0; - } - } - else - { - /* fallback to packets */ - for (size_t i = 0; i < N; i += K) - { - const vint<K> vi = vint<K>(int(i)) + vint<K>(step); - vbool<K> valid = vi < vint<K>(int(N)); - const size_t offset = i * sizeof(float); - - RayTypeK<K, intersect> ray = rayN.getRayByOffset<K>(valid, offset); - valid &= ray.tnear() <= ray.tfar; - - scene->intersectors.intersect(valid, ray, context); - - rayN.setHitByOffset(valid, offset, ray); - } - } - } - - - void RayStreamFilter::intersectAOS(Scene* scene, RTCRayHit* _rayN, size_t N, size_t stride, IntersectContext* context) { - if (unlikely(context->isCoherent())) - filterAOS<VSIZEL, true>(scene, _rayN, N, stride, context); - else - filterAOS<VSIZEX, true>(scene, _rayN, N, stride, context); - } - - void RayStreamFilter::occludedAOS(Scene* scene, RTCRay* _rayN, size_t N, size_t stride, IntersectContext* context) { - if (unlikely(context->isCoherent())) - filterAOS<VSIZEL, false>(scene, _rayN, N, stride, context); - else - filterAOS<VSIZEX, false>(scene, _rayN, N, stride, context); - } - - void RayStreamFilter::intersectAOP(Scene* scene, RTCRayHit** _rayN, size_t N, IntersectContext* context) { - if (unlikely(context->isCoherent())) - filterAOP<VSIZEL, true>(scene, (void**)_rayN, N, context); - else - filterAOP<VSIZEX, true>(scene, (void**)_rayN, N, context); - } - - void RayStreamFilter::occludedAOP(Scene* scene, RTCRay** _rayN, size_t N, IntersectContext* context) { - if (unlikely(context->isCoherent())) - filterAOP<VSIZEL, false>(scene, (void**)_rayN, N, context); - else - filterAOP<VSIZEX, false>(scene, (void**)_rayN, N, context); - } - - void RayStreamFilter::intersectSOA(Scene* scene, char* rayData, size_t N, size_t numPackets, size_t stride, IntersectContext* context) { - if (unlikely(context->isCoherent())) - filterSOA<VSIZEL, true>(scene, rayData, N, numPackets, stride, context); - else - filterSOA<VSIZEX, true>(scene, rayData, N, numPackets, stride, context); - } - - void RayStreamFilter::occludedSOA(Scene* scene, char* rayData, size_t N, size_t numPackets, size_t stride, IntersectContext* context) { - if (unlikely(context->isCoherent())) - filterSOA<VSIZEL, false>(scene, rayData, N, numPackets, stride, context); - else - filterSOA<VSIZEX, false>(scene, rayData, N, numPackets, stride, context); - } - - void RayStreamFilter::intersectSOP(Scene* scene, const RTCRayHitNp* _rayN, size_t N, IntersectContext* context) { - if (unlikely(context->isCoherent())) - filterSOP<VSIZEL, true>(scene, _rayN, N, context); - else - filterSOP<VSIZEX, true>(scene, _rayN, N, context); - } - - void RayStreamFilter::occludedSOP(Scene* scene, const RTCRayNp* _rayN, size_t N, IntersectContext* context) { - if (unlikely(context->isCoherent())) - filterSOP<VSIZEL, false>(scene, _rayN, N, context); - else - filterSOP<VSIZEX, false>(scene, _rayN, N, context); - } - - - RayStreamFilterFuncs rayStreamFilterFuncs() { - return RayStreamFilterFuncs(RayStreamFilter::intersectAOS, RayStreamFilter::intersectAOP, RayStreamFilter::intersectSOA, RayStreamFilter::intersectSOP, - RayStreamFilter::occludedAOS, RayStreamFilter::occludedAOP, RayStreamFilter::occludedSOA, RayStreamFilter::occludedSOP); - } - }; -}; diff --git a/thirdparty/embree/kernels/bvh/bvh_intersector_stream_filters.h b/thirdparty/embree/kernels/bvh/bvh_intersector_stream_filters.h deleted file mode 100644 index e7df7c2ae2..0000000000 --- a/thirdparty/embree/kernels/bvh/bvh_intersector_stream_filters.h +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright 2009-2021 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 - -#pragma once - -#include "../common/default.h" -#include "../common/ray.h" -#include "../common/scene.h" - -namespace embree -{ - namespace isa - { - class RayStreamFilter - { - public: - static void intersectAOS(Scene* scene, RTCRayHit* rays, size_t N, size_t stride, IntersectContext* context); - static void intersectAOP(Scene* scene, RTCRayHit** rays, size_t N, IntersectContext* context); - static void intersectSOA(Scene* scene, char* rays, size_t N, size_t numPackets, size_t stride, IntersectContext* context); - static void intersectSOP(Scene* scene, const RTCRayHitNp* rays, size_t N, IntersectContext* context); - - static void occludedAOS(Scene* scene, RTCRay* rays, size_t N, size_t stride, IntersectContext* context); - static void occludedAOP(Scene* scene, RTCRay** rays, size_t N, IntersectContext* context); - static void occludedSOA(Scene* scene, char* rays, size_t N, size_t numPackets, size_t stride, IntersectContext* context); - static void occludedSOP(Scene* scene, const RTCRayNp* rays, size_t N, IntersectContext* context); - - private: - template<int K, bool intersect> - static void filterAOS(Scene* scene, void* rays, size_t N, size_t stride, IntersectContext* context); - - template<int K, bool intersect> - static void filterAOP(Scene* scene, void** rays, size_t N, IntersectContext* context); - - template<int K, bool intersect> - static void filterSOA(Scene* scene, char* rays, size_t N, size_t numPackets, size_t stride, IntersectContext* context); - - template<int K, bool intersect> - static void filterSOP(Scene* scene, const void* rays, size_t N, IntersectContext* context); - }; - } -}; diff --git a/thirdparty/embree/kernels/bvh/bvh_refit.cpp b/thirdparty/embree/kernels/bvh/bvh_refit.cpp index bf5c8538ba..9f8554112b 100644 --- a/thirdparty/embree/kernels/bvh/bvh_refit.cpp +++ b/thirdparty/embree/kernels/bvh/bvh_refit.cpp @@ -11,6 +11,9 @@ #include "../geometry/quadv.h" #include "../geometry/object.h" #include "../geometry/instance.h" +#include "../geometry/instance_array.h" + +#include "../../common/algorithms/parallel_for.h" namespace embree { @@ -82,7 +85,7 @@ namespace embree template<int N> BBox3fa BVHNRefitter<N>::refit_toplevel(NodeRef& ref, size_t &subtrees, - const BBox3fa *const subTreeBounds, + const BBox3fa *const subTreeBounds, const size_t depth) { if (depth >= MAX_SUB_TREE_EXTRACTION_DEPTH) @@ -236,12 +239,20 @@ namespace embree #if defined(EMBREE_GEOMETRY_INSTANCE) Builder* BVH4InstanceMeshBuilderSAH (void* bvh, Instance* mesh, Geometry::GTypeMask gtype, unsigned int geomID, size_t mode); Builder* BVH4InstanceMeshRefitSAH (void* accel, Instance* mesh, Geometry::GTypeMask gtype, unsigned int geomID, size_t mode) { return new BVHNRefitT<4,Instance,InstancePrimitive>((BVH4*)accel,BVH4InstanceMeshBuilderSAH(accel,mesh,gtype,geomID,mode),mesh,mode); } - #if defined(__AVX__) Builder* BVH8InstanceMeshBuilderSAH (void* bvh, Instance* mesh, Geometry::GTypeMask gtype, unsigned int geomID, size_t mode); Builder* BVH8InstanceMeshRefitSAH (void* accel, Instance* mesh, Geometry::GTypeMask gtype, unsigned int geomID, size_t mode) { return new BVHNRefitT<8,Instance,InstancePrimitive>((BVH8*)accel,BVH8InstanceMeshBuilderSAH(accel,mesh,gtype,geomID,mode),mesh,mode); } #endif #endif +#if defined(EMBREE_GEOMETRY_INSTANCE_ARRAY) + Builder* BVH4InstanceArrayMeshBuilderSAH (void* bvh, InstanceArray* mesh, Geometry::GTypeMask gtype, unsigned int geomID, size_t mode); + Builder* BVH4InstanceArrayMeshRefitSAH (void* accel, InstanceArray* mesh, Geometry::GTypeMask gtype, unsigned int geomID, size_t mode) { return new BVHNRefitT<4,InstanceArray,InstanceArrayPrimitive>((BVH4*)accel,BVH4InstanceArrayMeshBuilderSAH(accel,mesh,gtype,geomID,mode),mesh,mode); } + +#if defined(__AVX__) + Builder* BVH8InstanceArrayMeshBuilderSAH (void* bvh, InstanceArray* mesh, Geometry::GTypeMask gtype, unsigned int geomID, size_t mode); + Builder* BVH8InstanceArrayMeshRefitSAH (void* accel, InstanceArray* mesh, Geometry::GTypeMask gtype, unsigned int geomID, size_t mode) { return new BVHNRefitT<8,InstanceArray,InstanceArrayPrimitive>((BVH8*)accel,BVH8InstanceArrayMeshBuilderSAH(accel,mesh,gtype,geomID,mode),mesh,mode); } +#endif +#endif } } diff --git a/thirdparty/embree/kernels/bvh/bvh_traverser_stream.h b/thirdparty/embree/kernels/bvh/bvh_traverser_stream.h deleted file mode 100644 index 852981e69d..0000000000 --- a/thirdparty/embree/kernels/bvh/bvh_traverser_stream.h +++ /dev/null @@ -1,149 +0,0 @@ -// Copyright 2009-2021 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 - -#pragma once - -#include "bvh.h" -#include "../common/ray.h" -#include "../common/stack_item.h" - -namespace embree -{ - namespace isa - { - template<int N, int types> - class BVHNNodeTraverserStreamHitCoherent - { - typedef BVHN<N> BVH; - typedef typename BVH::NodeRef NodeRef; - typedef typename BVH::BaseNode BaseNode; - - public: - template<class T> - static __forceinline void traverseClosestHit(NodeRef& cur, - size_t& m_trav_active, - const vbool<N>& vmask, - const vfloat<N>& tNear, - const T* const tMask, - StackItemMaskCoherent*& stackPtr) - { - const NodeRef parent = cur; - size_t mask = movemask(vmask); - assert(mask != 0); - const BaseNode* node = cur.baseNode(); - - /*! one child is hit, continue with that child */ - const size_t r0 = bscf(mask); - assert(r0 < 8); - cur = node->child(r0); - BVHN<N>::prefetch(cur,types); - m_trav_active = tMask[r0]; - assert(cur != BVH::emptyNode); - if (unlikely(mask == 0)) return; - - const unsigned int* const tNear_i = (unsigned int*)&tNear; - - /*! two children are hit, push far child, and continue with closer child */ - NodeRef c0 = cur; - unsigned int d0 = tNear_i[r0]; - const size_t r1 = bscf(mask); - assert(r1 < 8); - NodeRef c1 = node->child(r1); - BVHN<N>::prefetch(c1,types); - unsigned int d1 = tNear_i[r1]; - - assert(c0 != BVH::emptyNode); - assert(c1 != BVH::emptyNode); - if (likely(mask == 0)) { - if (d0 < d1) { - assert(tNear[r1] >= 0.0f); - stackPtr->mask = tMask[r1]; - stackPtr->parent = parent; - stackPtr->child = c1; - stackPtr++; - cur = c0; - m_trav_active = tMask[r0]; - return; - } - else { - assert(tNear[r0] >= 0.0f); - stackPtr->mask = tMask[r0]; - stackPtr->parent = parent; - stackPtr->child = c0; - stackPtr++; - cur = c1; - m_trav_active = tMask[r1]; - return; - } - } - - /*! slow path for more than two hits */ - size_t hits = movemask(vmask); - const vint<N> dist_i = select(vmask, (asInt(tNear) & 0xfffffff8) | vint<N>(step), 0); - const vint<N> dist_i_sorted = usort_descending(dist_i); - const vint<N> sorted_index = dist_i_sorted & 7; - - size_t i = 0; - for (;;) - { - const unsigned int index = sorted_index[i]; - assert(index < 8); - cur = node->child(index); - m_trav_active = tMask[index]; - assert(m_trav_active); - BVHN<N>::prefetch(cur,types); - bscf(hits); - if (unlikely(hits==0)) break; - i++; - assert(cur != BVH::emptyNode); - assert(tNear[index] >= 0.0f); - stackPtr->mask = m_trav_active; - stackPtr->parent = parent; - stackPtr->child = cur; - stackPtr++; - } - } - - template<class T> - static __forceinline void traverseAnyHit(NodeRef& cur, - size_t& m_trav_active, - const vbool<N>& vmask, - const T* const tMask, - StackItemMaskCoherent*& stackPtr) - { - const NodeRef parent = cur; - size_t mask = movemask(vmask); - assert(mask != 0); - const BaseNode* node = cur.baseNode(); - - /*! one child is hit, continue with that child */ - size_t r = bscf(mask); - cur = node->child(r); - BVHN<N>::prefetch(cur,types); - m_trav_active = tMask[r]; - - /* simple in order sequence */ - assert(cur != BVH::emptyNode); - if (likely(mask == 0)) return; - stackPtr->mask = m_trav_active; - stackPtr->parent = parent; - stackPtr->child = cur; - stackPtr++; - - for (; ;) - { - r = bscf(mask); - cur = node->child(r); - BVHN<N>::prefetch(cur,types); - m_trav_active = tMask[r]; - assert(cur != BVH::emptyNode); - if (likely(mask == 0)) return; - stackPtr->mask = m_trav_active; - stackPtr->parent = parent; - stackPtr->child = cur; - stackPtr++; - } - } - }; - } -} diff --git a/thirdparty/embree/kernels/bvh/node_intersector_packet_stream.h b/thirdparty/embree/kernels/bvh/node_intersector_packet_stream.h deleted file mode 100644 index 943fd7043f..0000000000 --- a/thirdparty/embree/kernels/bvh/node_intersector_packet_stream.h +++ /dev/null @@ -1,215 +0,0 @@ -// Copyright 2009-2021 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 - -#pragma once - -#include "node_intersector.h" - -namespace embree -{ - namespace isa - { - ////////////////////////////////////////////////////////////////////////////////////// - // Ray packet structure used in stream traversal - ////////////////////////////////////////////////////////////////////////////////////// - - template<int K, bool robust> - struct TravRayKStream; - - /* Fast variant */ - template<int K> - struct TravRayKStream<K, false> - { - __forceinline TravRayKStream() {} - - __forceinline TravRayKStream(const Vec3vf<K>& ray_org, const Vec3vf<K>& ray_dir, const vfloat<K>& ray_tnear, const vfloat<K>& ray_tfar) - { - init(ray_org, ray_dir); - tnear = ray_tnear; - tfar = ray_tfar; - } - - __forceinline void init(const Vec3vf<K>& ray_org, const Vec3vf<K>& ray_dir) - { - rdir = rcp_safe(ray_dir); -#if defined(__aarch64__) - neg_org_rdir = -(ray_org * rdir); -#else - org_rdir = ray_org * rdir; -#endif - } - - Vec3vf<K> rdir; -#if defined(__aarch64__) - Vec3vf<K> neg_org_rdir; -#else - Vec3vf<K> org_rdir; -#endif - vfloat<K> tnear; - vfloat<K> tfar; - }; - - template<int K> - using TravRayKStreamFast = TravRayKStream<K, false>; - - /* Robust variant */ - template<int K> - struct TravRayKStream<K, true> - { - __forceinline TravRayKStream() {} - - __forceinline TravRayKStream(const Vec3vf<K>& ray_org, const Vec3vf<K>& ray_dir, const vfloat<K>& ray_tnear, const vfloat<K>& ray_tfar) - { - init(ray_org, ray_dir); - tnear = ray_tnear; - tfar = ray_tfar; - } - - __forceinline void init(const Vec3vf<K>& ray_org, const Vec3vf<K>& ray_dir) - { - rdir = vfloat<K>(1.0f)/(zero_fix(ray_dir)); - org = ray_org; - } - - Vec3vf<K> rdir; - Vec3vf<K> org; - vfloat<K> tnear; - vfloat<K> tfar; - }; - - template<int K> - using TravRayKStreamRobust = TravRayKStream<K, true>; - - ////////////////////////////////////////////////////////////////////////////////////// - // Fast AABBNode intersection - ////////////////////////////////////////////////////////////////////////////////////// - - template<int N, int K> - __forceinline size_t intersectNode1(const typename BVHN<N>::AABBNode* __restrict__ node, - const TravRayKStreamFast<K>& ray, size_t k, const NearFarPrecalculations& nf) - { - const vfloat<N> bminX = vfloat<N>(*(const vfloat<N>*)((const char*)&node->lower_x + nf.nearX)); - const vfloat<N> bminY = vfloat<N>(*(const vfloat<N>*)((const char*)&node->lower_x + nf.nearY)); - const vfloat<N> bminZ = vfloat<N>(*(const vfloat<N>*)((const char*)&node->lower_x + nf.nearZ)); - const vfloat<N> bmaxX = vfloat<N>(*(const vfloat<N>*)((const char*)&node->lower_x + nf.farX)); - const vfloat<N> bmaxY = vfloat<N>(*(const vfloat<N>*)((const char*)&node->lower_x + nf.farY)); - const vfloat<N> bmaxZ = vfloat<N>(*(const vfloat<N>*)((const char*)&node->lower_x + nf.farZ)); - -#if defined (__aarch64__) - const vfloat<N> rminX = madd(bminX, vfloat<N>(ray.rdir.x[k]), vfloat<N>(ray.neg_org_rdir.x[k])); - const vfloat<N> rminY = madd(bminY, vfloat<N>(ray.rdir.y[k]), vfloat<N>(ray.neg_org_rdir.y[k])); - const vfloat<N> rminZ = madd(bminZ, vfloat<N>(ray.rdir.z[k]), vfloat<N>(ray.neg_org_rdir.z[k])); - const vfloat<N> rmaxX = madd(bmaxX, vfloat<N>(ray.rdir.x[k]), vfloat<N>(ray.neg_org_rdir.x[k])); - const vfloat<N> rmaxY = madd(bmaxY, vfloat<N>(ray.rdir.y[k]), vfloat<N>(ray.neg_org_rdir.y[k])); - const vfloat<N> rmaxZ = madd(bmaxZ, vfloat<N>(ray.rdir.z[k]), vfloat<N>(ray.neg_org_rdir.z[k])); -#else - const vfloat<N> rminX = msub(bminX, vfloat<N>(ray.rdir.x[k]), vfloat<N>(ray.org_rdir.x[k])); - const vfloat<N> rminY = msub(bminY, vfloat<N>(ray.rdir.y[k]), vfloat<N>(ray.org_rdir.y[k])); - const vfloat<N> rminZ = msub(bminZ, vfloat<N>(ray.rdir.z[k]), vfloat<N>(ray.org_rdir.z[k])); - const vfloat<N> rmaxX = msub(bmaxX, vfloat<N>(ray.rdir.x[k]), vfloat<N>(ray.org_rdir.x[k])); - const vfloat<N> rmaxY = msub(bmaxY, vfloat<N>(ray.rdir.y[k]), vfloat<N>(ray.org_rdir.y[k])); - const vfloat<N> rmaxZ = msub(bmaxZ, vfloat<N>(ray.rdir.z[k]), vfloat<N>(ray.org_rdir.z[k])); -#endif - const vfloat<N> rmin = maxi(rminX, rminY, rminZ, vfloat<N>(ray.tnear[k])); - const vfloat<N> rmax = mini(rmaxX, rmaxY, rmaxZ, vfloat<N>(ray.tfar[k])); - - const vbool<N> vmask_first_hit = rmin <= rmax; - - return movemask(vmask_first_hit) & (((size_t)1 << N)-1); - } - - template<int N, int K> - __forceinline size_t intersectNodeK(const typename BVHN<N>::AABBNode* __restrict__ node, size_t i, - const TravRayKStreamFast<K>& ray, const NearFarPrecalculations& nf) - { - char* ptr = (char*)&node->lower_x + i*sizeof(float); - const vfloat<K> bminX = *(const float*)(ptr + nf.nearX); - const vfloat<K> bminY = *(const float*)(ptr + nf.nearY); - const vfloat<K> bminZ = *(const float*)(ptr + nf.nearZ); - const vfloat<K> bmaxX = *(const float*)(ptr + nf.farX); - const vfloat<K> bmaxY = *(const float*)(ptr + nf.farY); - const vfloat<K> bmaxZ = *(const float*)(ptr + nf.farZ); - -#if defined (__aarch64__) - const vfloat<K> rminX = madd(bminX, ray.rdir.x, ray.neg_org_rdir.x); - const vfloat<K> rminY = madd(bminY, ray.rdir.y, ray.neg_org_rdir.y); - const vfloat<K> rminZ = madd(bminZ, ray.rdir.z, ray.neg_org_rdir.z); - const vfloat<K> rmaxX = madd(bmaxX, ray.rdir.x, ray.neg_org_rdir.x); - const vfloat<K> rmaxY = madd(bmaxY, ray.rdir.y, ray.neg_org_rdir.y); - const vfloat<K> rmaxZ = madd(bmaxZ, ray.rdir.z, ray.neg_org_rdir.z); -#else - const vfloat<K> rminX = msub(bminX, ray.rdir.x, ray.org_rdir.x); - const vfloat<K> rminY = msub(bminY, ray.rdir.y, ray.org_rdir.y); - const vfloat<K> rminZ = msub(bminZ, ray.rdir.z, ray.org_rdir.z); - const vfloat<K> rmaxX = msub(bmaxX, ray.rdir.x, ray.org_rdir.x); - const vfloat<K> rmaxY = msub(bmaxY, ray.rdir.y, ray.org_rdir.y); - const vfloat<K> rmaxZ = msub(bmaxZ, ray.rdir.z, ray.org_rdir.z); -#endif - - const vfloat<K> rmin = maxi(rminX, rminY, rminZ, ray.tnear); - const vfloat<K> rmax = mini(rmaxX, rmaxY, rmaxZ, ray.tfar); - - const vbool<K> vmask_first_hit = rmin <= rmax; - - return movemask(vmask_first_hit); - } - - ////////////////////////////////////////////////////////////////////////////////////// - // Robust AABBNode intersection - ////////////////////////////////////////////////////////////////////////////////////// - - template<int N, int K> - __forceinline size_t intersectNode1(const typename BVHN<N>::AABBNode* __restrict__ node, - const TravRayKStreamRobust<K>& ray, size_t k, const NearFarPrecalculations& nf) - { - const vfloat<N> bminX = vfloat<N>(*(const vfloat<N>*)((const char*)&node->lower_x + nf.nearX)); - const vfloat<N> bminY = vfloat<N>(*(const vfloat<N>*)((const char*)&node->lower_x + nf.nearY)); - const vfloat<N> bminZ = vfloat<N>(*(const vfloat<N>*)((const char*)&node->lower_x + nf.nearZ)); - const vfloat<N> bmaxX = vfloat<N>(*(const vfloat<N>*)((const char*)&node->lower_x + nf.farX)); - const vfloat<N> bmaxY = vfloat<N>(*(const vfloat<N>*)((const char*)&node->lower_x + nf.farY)); - const vfloat<N> bmaxZ = vfloat<N>(*(const vfloat<N>*)((const char*)&node->lower_x + nf.farZ)); - - const vfloat<N> rminX = (bminX - vfloat<N>(ray.org.x[k])) * vfloat<N>(ray.rdir.x[k]); - const vfloat<N> rminY = (bminY - vfloat<N>(ray.org.y[k])) * vfloat<N>(ray.rdir.y[k]); - const vfloat<N> rminZ = (bminZ - vfloat<N>(ray.org.z[k])) * vfloat<N>(ray.rdir.z[k]); - const vfloat<N> rmaxX = (bmaxX - vfloat<N>(ray.org.x[k])) * vfloat<N>(ray.rdir.x[k]); - const vfloat<N> rmaxY = (bmaxY - vfloat<N>(ray.org.y[k])) * vfloat<N>(ray.rdir.y[k]); - const vfloat<N> rmaxZ = (bmaxZ - vfloat<N>(ray.org.z[k])) * vfloat<N>(ray.rdir.z[k]); - const float round_up = 1.0f+3.0f*float(ulp); // FIXME: use per instruction rounding for AVX512 - const vfloat<N> rmin = max(rminX, rminY, rminZ, vfloat<N>(ray.tnear[k])); - const vfloat<N> rmax = round_up *min(rmaxX, rmaxY, rmaxZ, vfloat<N>(ray.tfar[k])); - - const vbool<N> vmask_first_hit = rmin <= rmax; - - return movemask(vmask_first_hit) & (((size_t)1 << N)-1); - } - - template<int N, int K> - __forceinline size_t intersectNodeK(const typename BVHN<N>::AABBNode* __restrict__ node, size_t i, - const TravRayKStreamRobust<K>& ray, const NearFarPrecalculations& nf) - { - char *ptr = (char*)&node->lower_x + i*sizeof(float); - const vfloat<K> bminX = *(const float*)(ptr + nf.nearX); - const vfloat<K> bminY = *(const float*)(ptr + nf.nearY); - const vfloat<K> bminZ = *(const float*)(ptr + nf.nearZ); - const vfloat<K> bmaxX = *(const float*)(ptr + nf.farX); - const vfloat<K> bmaxY = *(const float*)(ptr + nf.farY); - const vfloat<K> bmaxZ = *(const float*)(ptr + nf.farZ); - - const vfloat<K> rminX = (bminX - ray.org.x) * ray.rdir.x; - const vfloat<K> rminY = (bminY - ray.org.y) * ray.rdir.y; - const vfloat<K> rminZ = (bminZ - ray.org.z) * ray.rdir.z; - const vfloat<K> rmaxX = (bmaxX - ray.org.x) * ray.rdir.x; - const vfloat<K> rmaxY = (bmaxY - ray.org.y) * ray.rdir.y; - const vfloat<K> rmaxZ = (bmaxZ - ray.org.z) * ray.rdir.z; - - const float round_up = 1.0f+3.0f*float(ulp); - const vfloat<K> rmin = max(rminX, rminY, rminZ, vfloat<K>(ray.tnear)); - const vfloat<K> rmax = round_up * min(rmaxX, rmaxY, rmaxZ, vfloat<K>(ray.tfar)); - - const vbool<K> vmask_first_hit = rmin <= rmax; - - return movemask(vmask_first_hit); - } - } -} 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/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; }; diff --git a/thirdparty/embree/kernels/config.h b/thirdparty/embree/kernels/config.h index 84ac27d103..5979b543c9 100644 --- a/thirdparty/embree/kernels/config.h +++ b/thirdparty/embree/kernels/config.h @@ -1,22 +1,26 @@ // Copyright 2009-2021 Intel Corporation // SPDX-License-Identifier: Apache-2.0 -/* #undef EMBREE_RAY_MASK */ -/* #undef EMBREE_STAT_COUNTERS */ -/* #undef EMBREE_BACKFACE_CULLING */ -/* #undef EMBREE_BACKFACE_CULLING_CURVES */ +#include "../include/embree4/rtcore_config.h" + +// #cmakedefine EMBREE_RAY_MASK +// #cmakedefine EMBREE_STAT_COUNTERS +// #cmakedefine EMBREE_BACKFACE_CULLING +// #cmakedefine EMBREE_BACKFACE_CULLING_CURVES +// #cmakedefine EMBREE_BACKFACE_CULLING_SPHERES #define EMBREE_FILTER_FUNCTION -/* #undef EMBREE_IGNORE_INVALID_RAYS */ +// #cmakedefine EMBREE_IGNORE_INVALID_RAYS #define EMBREE_GEOMETRY_TRIANGLE -/* #undef EMBREE_GEOMETRY_QUAD */ -/* #undef EMBREE_GEOMETRY_CURVE */ -/* #undef EMBREE_GEOMETRY_SUBDIVISION */ -/* #undef EMBREE_GEOMETRY_USER */ -/* #undef EMBREE_GEOMETRY_INSTANCE */ -/* #undef EMBREE_GEOMETRY_GRID */ -/* #undef EMBREE_GEOMETRY_POINT */ +// #cmakedefine EMBREE_GEOMETRY_QUAD +// #cmakedefine EMBREE_GEOMETRY_CURVE +// #cmakedefine EMBREE_GEOMETRY_SUBDIVISION +// #cmakedefine EMBREE_GEOMETRY_USER +// #cmakedefine EMBREE_GEOMETRY_INSTANCE +// EMBREE_GEOMETRY_INSTANCE_ARRAY is defined in rtcore_config.h +// #cmakedefine EMBREE_GEOMETRY_GRID +// #cmakedefine EMBREE_GEOMETRY_POINT #define EMBREE_RAY_PACKETS -/* #undef EMBREE_COMPACT_POLYS */ +// #cmakedefine EMBREE_COMPACT_POLYS #define EMBREE_CURVE_SELF_INTERSECTION_AVOIDANCE_FACTOR 2.0 #define EMBREE_DISC_POINT_SELF_INTERSECTION_AVOIDANCE @@ -69,8 +73,18 @@ #define IF_ENABLED_INSTANCE(x) #endif +#if defined(EMBREE_GEOMETRY_INSTANCE_ARRAY) + #define IF_ENABLED_INSTANCE_ARRAY(x) x +#else + #define IF_ENABLED_INSTANCE_ARRAY(x) +#endif + #if defined(EMBREE_GEOMETRY_GRID) #define IF_ENABLED_GRIDS(x) x #else #define IF_ENABLED_GRIDS(x) #endif + + + + diff --git a/thirdparty/embree/kernels/geometry/coneline_intersector.h b/thirdparty/embree/kernels/geometry/coneline_intersector.h index 90f3792eff..696ea41ebc 100644 --- a/thirdparty/embree/kernels/geometry/coneline_intersector.h +++ b/thirdparty/embree/kernels/geometry/coneline_intersector.h @@ -159,7 +159,7 @@ namespace embree template<typename Epilog> static __forceinline bool intersect(const vbool<M>& valid_i, Ray& ray, - IntersectContext* context, + RayQueryContext* context, const LineSegments* geom, const Precalculations& pre, const Vec4vf<M>& v0i, const Vec4vf<M>& v1i, @@ -190,7 +190,7 @@ namespace embree template<typename Epilog> static __forceinline bool intersect(const vbool<M>& valid_i, RayK<K>& ray, size_t k, - IntersectContext* context, + RayQueryContext* context, const LineSegments* geom, const Precalculations& pre, const Vec4vf<M>& v0i, const Vec4vf<M>& v1i, diff --git a/thirdparty/embree/kernels/geometry/conelinei_intersector.h b/thirdparty/embree/kernels/geometry/conelinei_intersector.h index 6a985ebcad..c919fe9f7b 100644 --- a/thirdparty/embree/kernels/geometry/conelinei_intersector.h +++ b/thirdparty/embree/kernels/geometry/conelinei_intersector.h @@ -16,7 +16,7 @@ namespace embree typedef LineMi<M> Primitive; typedef CurvePrecalculations1 Precalculations; - static __forceinline void intersect(const Precalculations& pre, RayHit& ray, IntersectContext* context, const Primitive& line) + static __forceinline void intersect(const Precalculations& pre, RayHit& ray, RayQueryContext* context, const Primitive& line) { STAT3(normal.trav_prims,1,1,1); const LineSegments* geom = context->scene->get<LineSegments>(line.geomID()); @@ -27,7 +27,7 @@ namespace embree ConeCurveIntersector1<M>::intersect(valid,ray,context,geom,pre,v0,v1,cL,cR,Intersect1EpilogM<M,filter>(ray,context,line.geomID(),line.primID())); } - static __forceinline bool occluded(const Precalculations& pre, Ray& ray, IntersectContext* context, const Primitive& line) + static __forceinline bool occluded(const Precalculations& pre, Ray& ray, RayQueryContext* context, const Primitive& line) { STAT3(shadow.trav_prims,1,1,1); const LineSegments* geom = context->scene->get<LineSegments>(line.geomID()); @@ -51,7 +51,7 @@ namespace embree typedef LineMi<M> Primitive; typedef CurvePrecalculations1 Precalculations; - static __forceinline void intersect(const Precalculations& pre, RayHit& ray, IntersectContext* context, const Primitive& line) + static __forceinline void intersect(const Precalculations& pre, RayHit& ray, RayQueryContext* context, const Primitive& line) { STAT3(normal.trav_prims,1,1,1); const LineSegments* geom = context->scene->get<LineSegments>(line.geomID()); @@ -62,7 +62,7 @@ namespace embree ConeCurveIntersector1<M>::intersect(valid,ray,context,geom,pre,v0,v1,cL,cR,Intersect1EpilogM<M,filter>(ray,context,line.geomID(),line.primID())); } - static __forceinline bool occluded(const Precalculations& pre, Ray& ray, IntersectContext* context, const Primitive& line) + static __forceinline bool occluded(const Precalculations& pre, Ray& ray, RayQueryContext* context, const Primitive& line) { STAT3(shadow.trav_prims,1,1,1); const LineSegments* geom = context->scene->get<LineSegments>(line.geomID()); @@ -86,7 +86,7 @@ namespace embree typedef LineMi<M> Primitive; typedef CurvePrecalculationsK<K> Precalculations; - static __forceinline void intersect(const Precalculations& pre, RayHitK<K>& ray, size_t k, IntersectContext* context, const Primitive& line) + static __forceinline void intersect(const Precalculations& pre, RayHitK<K>& ray, size_t k, RayQueryContext* context, const Primitive& line) { STAT3(normal.trav_prims,1,1,1); const LineSegments* geom = context->scene->get<LineSegments>(line.geomID()); @@ -97,7 +97,7 @@ namespace embree ConeCurveIntersectorK<M,K>::intersect(valid,ray,k,context,geom,pre,v0,v1,cL,cR,Intersect1KEpilogM<M,K,filter>(ray,k,context,line.geomID(),line.primID())); } - static __forceinline bool occluded(const Precalculations& pre, RayK<K>& ray, size_t k, IntersectContext* context, const Primitive& line) + static __forceinline bool occluded(const Precalculations& pre, RayK<K>& ray, size_t k, RayQueryContext* context, const Primitive& line) { STAT3(shadow.trav_prims,1,1,1); const LineSegments* geom = context->scene->get<LineSegments>(line.geomID()); @@ -115,7 +115,7 @@ namespace embree typedef LineMi<M> Primitive; typedef CurvePrecalculationsK<K> Precalculations; - static __forceinline void intersect(const Precalculations& pre, RayHitK<K>& ray, size_t k, IntersectContext* context, const Primitive& line) + static __forceinline void intersect(const Precalculations& pre, RayHitK<K>& ray, size_t k, RayQueryContext* context, const Primitive& line) { STAT3(normal.trav_prims,1,1,1); const LineSegments* geom = context->scene->get<LineSegments>(line.geomID()); @@ -126,7 +126,7 @@ namespace embree ConeCurveIntersectorK<M,K>::intersect(valid,ray,k,context,geom,pre,v0,v1,cL,cR,Intersect1KEpilogM<M,K,filter>(ray,k,context,line.geomID(),line.primID())); } - static __forceinline bool occluded(const Precalculations& pre, RayK<K>& ray, size_t k, IntersectContext* context, const Primitive& line) + static __forceinline bool occluded(const Precalculations& pre, RayK<K>& ray, size_t k, RayQueryContext* context, const Primitive& line) { STAT3(shadow.trav_prims,1,1,1); const LineSegments* geom = context->scene->get<LineSegments>(line.geomID()); diff --git a/thirdparty/embree/kernels/geometry/curveNi_intersector.h b/thirdparty/embree/kernels/geometry/curveNi_intersector.h index c0b66515c1..137ec06d0c 100644 --- a/thirdparty/embree/kernels/geometry/curveNi_intersector.h +++ b/thirdparty/embree/kernels/geometry/curveNi_intersector.h @@ -5,6 +5,12 @@ #include "curveNi.h" +#include "roundline_intersector.h" +#include "coneline_intersector.h" +#include "curve_intersector_ribbon.h" +#include "curve_intersector_oriented.h" +#include "curve_intersector_sweep.h" + namespace embree { namespace isa @@ -20,9 +26,14 @@ namespace embree static __forceinline vbool<M> intersect(Ray& ray, const Primitive& prim, vfloat<M>& tNear_o) { const size_t N = prim.N; +#if defined(EMBREE_SYCL_SUPPORT) && defined(__SYCL_DEVICE_ONLY__) + const Vec3fa offset = *prim.offset(N); + const float scale = *prim.scale(N); +#else const vfloat4 offset_scale = vfloat4::loadu(prim.offset(N)); const Vec3fa offset = Vec3fa(offset_scale); const Vec3fa scale = Vec3fa(shuffle<3,3,3,3>(offset_scale)); +#endif const Vec3fa org1 = (ray.org-offset)*scale; const Vec3fa dir1 = ray.dir*scale; @@ -50,7 +61,7 @@ namespace embree } template<typename Intersector, typename Epilog> - static __forceinline void intersect_t(const Precalculations& pre, RayHit& ray, IntersectContext* context, const Primitive& prim) + static __forceinline void intersect_t(const Precalculations& pre, RayHit& ray, RayQueryContext* context, const Primitive& prim) { vfloat<M> tNear; vbool<M> valid = intersect(ray,prim,tNear); @@ -84,7 +95,7 @@ namespace embree } template<typename Intersector, typename Epilog> - static __forceinline bool occluded_t(const Precalculations& pre, Ray& ray, IntersectContext* context, const Primitive& prim) + static __forceinline bool occluded_t(const Precalculations& pre, Ray& ray, RayQueryContext* context, const Primitive& prim) { vfloat<M> tNear; vbool<M> valid = intersect(ray,prim,tNear); @@ -121,7 +132,7 @@ namespace embree } template<typename Intersector, typename Epilog> - static __forceinline void intersect_n(const Precalculations& pre, RayHit& ray, IntersectContext* context, const Primitive& prim) + static __forceinline void intersect_n(const Precalculations& pre, RayHit& ray, RayQueryContext* context, const Primitive& prim) { vfloat<M> tNear; vbool<M> valid = intersect(ray,prim,tNear); @@ -157,7 +168,7 @@ namespace embree } template<typename Intersector, typename Epilog> - static __forceinline bool occluded_n(const Precalculations& pre, Ray& ray, IntersectContext* context, const Primitive& prim) + static __forceinline bool occluded_n(const Precalculations& pre, Ray& ray, RayQueryContext* context, const Primitive& prim) { vfloat<M> tNear; vbool<M> valid = intersect(ray,prim,tNear); @@ -196,7 +207,7 @@ namespace embree } template<typename Intersector, typename Epilog> - static __forceinline void intersect_h(const Precalculations& pre, RayHit& ray, IntersectContext* context, const Primitive& prim) + static __forceinline void intersect_h(const Precalculations& pre, RayHit& ray, RayQueryContext* context, const Primitive& prim) { vfloat<M> tNear; vbool<M> valid = intersect(ray,prim,tNear); @@ -217,7 +228,7 @@ namespace embree } template<typename Intersector, typename Epilog> - static __forceinline bool occluded_h(const Precalculations& pre, Ray& ray, IntersectContext* context, const Primitive& prim) + static __forceinline bool occluded_h(const Precalculations& pre, Ray& ray, RayQueryContext* context, const Primitive& prim) { vfloat<M> tNear; vbool<M> valid = intersect(ray,prim,tNear); @@ -241,7 +252,7 @@ namespace embree } template<typename Intersector, typename Epilog> - static __forceinline void intersect_hn(const Precalculations& pre, RayHit& ray, IntersectContext* context, const Primitive& prim) + static __forceinline void intersect_hn(const Precalculations& pre, RayHit& ray, RayQueryContext* context, const Primitive& prim) { vfloat<M> tNear; vbool<M> valid = intersect(ray,prim,tNear); @@ -262,7 +273,7 @@ namespace embree } template<typename Intersector, typename Epilog> - static __forceinline bool occluded_hn(const Precalculations& pre, Ray& ray, IntersectContext* context, const Primitive& prim) + static __forceinline bool occluded_hn(const Precalculations& pre, Ray& ray, RayQueryContext* context, const Primitive& prim) { vfloat<M> tNear; vbool<M> valid = intersect(ray,prim,tNear); @@ -297,10 +308,14 @@ namespace embree static __forceinline vbool<M> intersect(RayK<K>& ray, const size_t k, const Primitive& prim, vfloat<M>& tNear_o) { const size_t N = prim.N; +#if defined(EMBREE_SYCL_SUPPORT) && defined(__SYCL_DEVICE_ONLY__) + const Vec3fa offset = *prim.offset(N); + const float scale = *prim.scale(N); +#else const vfloat4 offset_scale = vfloat4::loadu(prim.offset(N)); const Vec3fa offset = Vec3fa(offset_scale); const Vec3fa scale = Vec3fa(shuffle<3,3,3,3>(offset_scale)); - +#endif const Vec3fa ray_org(ray.org.x[k],ray.org.y[k],ray.org.z[k]); const Vec3fa ray_dir(ray.dir.x[k],ray.dir.y[k],ray.dir.z[k]); const Vec3fa org1 = (ray_org-offset)*scale; @@ -330,7 +345,7 @@ namespace embree } template<typename Intersector, typename Epilog> - static __forceinline void intersect_t(Precalculations& pre, RayHitK<K>& ray, const size_t k, IntersectContext* context, const Primitive& prim) + static __forceinline void intersect_t(Precalculations& pre, RayHitK<K>& ray, const size_t k, RayQueryContext* context, const Primitive& prim) { vfloat<M> tNear; vbool<M> valid = intersect(ray,k,prim,tNear); @@ -364,7 +379,7 @@ namespace embree } template<typename Intersector, typename Epilog> - static __forceinline bool occluded_t(Precalculations& pre, RayK<K>& ray, const size_t k, IntersectContext* context, const Primitive& prim) + static __forceinline bool occluded_t(Precalculations& pre, RayK<K>& ray, const size_t k, RayQueryContext* context, const Primitive& prim) { vfloat<M> tNear; vbool<M> valid = intersect(ray,k,prim,tNear); @@ -401,7 +416,7 @@ namespace embree } template<typename Intersector, typename Epilog> - static __forceinline void intersect_n(Precalculations& pre, RayHitK<K>& ray, const size_t k, IntersectContext* context, const Primitive& prim) + static __forceinline void intersect_n(Precalculations& pre, RayHitK<K>& ray, const size_t k, RayQueryContext* context, const Primitive& prim) { vfloat<M> tNear; vbool<M> valid = intersect(ray,k,prim,tNear); @@ -437,7 +452,7 @@ namespace embree } template<typename Intersector, typename Epilog> - static __forceinline bool occluded_n(Precalculations& pre, RayK<K>& ray, const size_t k, IntersectContext* context, const Primitive& prim) + static __forceinline bool occluded_n(Precalculations& pre, RayK<K>& ray, const size_t k, RayQueryContext* context, const Primitive& prim) { vfloat<M> tNear; vbool<M> valid = intersect(ray,k,prim,tNear); @@ -476,7 +491,7 @@ namespace embree } template<typename Intersector, typename Epilog> - static __forceinline void intersect_h(Precalculations& pre, RayHitK<K>& ray, const size_t k, IntersectContext* context, const Primitive& prim) + static __forceinline void intersect_h(Precalculations& pre, RayHitK<K>& ray, const size_t k, RayQueryContext* context, const Primitive& prim) { vfloat<M> tNear; vbool<M> valid = intersect(ray,k,prim,tNear); @@ -497,7 +512,7 @@ namespace embree } template<typename Intersector, typename Epilog> - static __forceinline bool occluded_h(Precalculations& pre, RayK<K>& ray, const size_t k, IntersectContext* context, const Primitive& prim) + static __forceinline bool occluded_h(Precalculations& pre, RayK<K>& ray, const size_t k, RayQueryContext* context, const Primitive& prim) { vfloat<M> tNear; vbool<M> valid = intersect(ray,k,prim,tNear); @@ -521,7 +536,7 @@ namespace embree } template<typename Intersector, typename Epilog> - static __forceinline void intersect_hn(Precalculations& pre, RayHitK<K>& ray, const size_t k, IntersectContext* context, const Primitive& prim) + static __forceinline void intersect_hn(Precalculations& pre, RayHitK<K>& ray, const size_t k, RayQueryContext* context, const Primitive& prim) { vfloat<M> tNear; vbool<M> valid = intersect(ray,k,prim,tNear); @@ -542,7 +557,7 @@ namespace embree } template<typename Intersector, typename Epilog> - static __forceinline bool occluded_hn(Precalculations& pre, RayK<K>& ray, const size_t k, IntersectContext* context, const Primitive& prim) + static __forceinline bool occluded_hn(Precalculations& pre, RayK<K>& ray, const size_t k, RayQueryContext* context, const Primitive& prim) { vfloat<M> tNear; vbool<M> valid = intersect(ray,k,prim,tNear); @@ -565,5 +580,69 @@ namespace embree return false; } }; + + __forceinline void convert_to_bezier(const Geometry::GType gtype, + Vec3ff& v0, Vec3ff& v1, Vec3ff& v2, Vec3ff& v3, + Vec3fa& n0, Vec3fa& n1, Vec3fa& n2, Vec3fa& n3) + { + const Geometry::GType basis = (Geometry::GType)(gtype & Geometry::GTY_BASIS_MASK); + const Geometry::GType stype = (Geometry::GType)(gtype & Geometry::GTY_SUBTYPE_MASK); + + if (basis == Geometry::GTY_BASIS_BSPLINE) { + BezierCurveT<Vec3ff> bezier; + convert(BSplineCurveT<Vec3ff>(v0,v1,v2,v3),bezier); + v0 = bezier.v0; v1 = bezier.v1; v2 = bezier.v2; v3 = bezier.v3; + } + else if (basis == Geometry::GTY_BASIS_HERMITE) { + BezierCurveT<Vec3ff> bezier; + convert(HermiteCurveT<Vec3ff>(v0,v1,v2,v3),bezier); + v0 = bezier.v0; v1 = bezier.v1; v2 = bezier.v2; v3 = bezier.v3; + } + else if (basis == Geometry::GTY_BASIS_CATMULL_ROM) { + BezierCurveT<Vec3ff> bezier; + convert(CatmullRomCurveT<Vec3ff>(v0,v1,v2,v3),bezier); + v0 = bezier.v0; v1 = bezier.v1; v2 = bezier.v2; v3 = bezier.v3; + } + + if (stype == Geometry::GTY_SUBTYPE_ORIENTED_CURVE) + { + if (basis == Geometry::GTY_BASIS_BSPLINE) { + BezierCurveT<Vec3fa> bezier; + convert(BSplineCurveT<Vec3fa>(n0,n1,n2,n3),bezier); + n0 = bezier.v0; n1 = bezier.v1; n2 = bezier.v2; n3 = bezier.v3; + } + else if (basis == Geometry::GTY_BASIS_HERMITE) { + BezierCurveT<Vec3fa> bezier; + convert(HermiteCurveT<Vec3fa>(n0,n1,n2,n3),bezier); + n0 = bezier.v0; n1 = bezier.v1; n2 = bezier.v2; n3 = bezier.v3; + } + else if (basis == Geometry::GTY_BASIS_CATMULL_ROM) { + BezierCurveT<Vec3fa> bezier; + convert(CatmullRomCurveT<Vec3fa>(n0,n1,n2,n3),bezier); + n0 = bezier.v0; n1 = bezier.v1; n2 = bezier.v2; n3 = bezier.v3; + } + } + } + + __forceinline void convert_to_bezier(const Geometry::GType gtype, Vec3ff& v0, Vec3ff& v1, Vec3ff& v2, Vec3ff& v3) + { + const Geometry::GType basis = (Geometry::GType)(gtype & Geometry::GTY_BASIS_MASK); + + if (basis == Geometry::GTY_BASIS_BSPLINE) { + BezierCurveT<Vec3ff> bezier; + convert(BSplineCurveT<Vec3ff>(v0,v1,v2,v3),bezier); + v0 = bezier.v0; v1 = bezier.v1; v2 = bezier.v2; v3 = bezier.v3; + } + else if (basis == Geometry::GTY_BASIS_HERMITE) { + BezierCurveT<Vec3ff> bezier; + convert(HermiteCurveT<Vec3ff>(v0,v1,v2,v3),bezier); + v0 = bezier.v0; v1 = bezier.v1; v2 = bezier.v2; v3 = bezier.v3; + } + else if (basis == Geometry::GTY_BASIS_CATMULL_ROM) { + BezierCurveT<Vec3ff> bezier; + convert(CatmullRomCurveT<Vec3ff>(v0,v1,v2,v3),bezier); + v0 = bezier.v0; v1 = bezier.v1; v2 = bezier.v2; v3 = bezier.v3; + } + } } } diff --git a/thirdparty/embree/kernels/geometry/curveNi_mb_intersector.h b/thirdparty/embree/kernels/geometry/curveNi_mb_intersector.h index bab796b33b..4c14c2f004 100644 --- a/thirdparty/embree/kernels/geometry/curveNi_mb_intersector.h +++ b/thirdparty/embree/kernels/geometry/curveNi_mb_intersector.h @@ -6,6 +6,12 @@ #include "curveNi_mb.h" #include "../subdiv/linear_bezier_patch.h" +#include "roundline_intersector.h" +#include "coneline_intersector.h" +#include "curve_intersector_ribbon.h" +#include "curve_intersector_oriented.h" +#include "curve_intersector_sweep.h" + namespace embree { namespace isa @@ -21,9 +27,14 @@ namespace embree static __forceinline vbool<M> intersect(Ray& ray, const Primitive& prim, vfloat<M>& tNear_o) { const size_t N = prim.N; +#if __SYCL_DEVICE_ONLY__ + const Vec3f offset = *prim.offset(N); + const float scale = *prim.scale(N); +#else const vfloat4 offset_scale = vfloat4::loadu(prim.offset(N)); const Vec3fa offset = Vec3fa(offset_scale); const Vec3fa scale = Vec3fa(shuffle<3,3,3,3>(offset_scale)); +#endif const Vec3fa org1 = (ray.org-offset)*scale; const Vec3fa dir1 = ray.dir*scale; @@ -73,7 +84,7 @@ namespace embree } template<typename Intersector, typename Epilog> - static __forceinline void intersect_t(const Precalculations& pre, RayHit& ray, IntersectContext* context, const Primitive& prim) + static __forceinline void intersect_t(const Precalculations& pre, RayHit& ray, RayQueryContext* context, const Primitive& prim) { vfloat<M> tNear; vbool<M> valid = intersect(ray,prim,tNear); @@ -95,7 +106,7 @@ namespace embree } template<typename Intersector, typename Epilog> - static __forceinline bool occluded_t(const Precalculations& pre, Ray& ray, IntersectContext* context, const Primitive& prim) + static __forceinline bool occluded_t(const Precalculations& pre, Ray& ray, RayQueryContext* context, const Primitive& prim) { vfloat<M> tNear; vbool<M> valid = intersect(ray,prim,tNear); @@ -120,7 +131,7 @@ namespace embree } template<typename Intersector, typename Epilog> - static __forceinline void intersect_n(const Precalculations& pre, RayHit& ray, IntersectContext* context, const Primitive& prim) + static __forceinline void intersect_n(const Precalculations& pre, RayHit& ray, RayQueryContext* context, const Primitive& prim) { vfloat<M> tNear; vbool<M> valid = intersect(ray,prim,tNear); @@ -141,7 +152,7 @@ namespace embree } template<typename Intersector, typename Epilog> - static __forceinline bool occluded_n(const Precalculations& pre, Ray& ray, IntersectContext* context, const Primitive& prim) + static __forceinline bool occluded_n(const Precalculations& pre, Ray& ray, RayQueryContext* context, const Primitive& prim) { vfloat<M> tNear; vbool<M> valid = intersect(ray,prim,tNear); @@ -166,7 +177,7 @@ namespace embree } template<typename Intersector, typename Epilog> - static __forceinline void intersect_h(const Precalculations& pre, RayHit& ray, IntersectContext* context, const Primitive& prim) + static __forceinline void intersect_h(const Precalculations& pre, RayHit& ray, RayQueryContext* context, const Primitive& prim) { vfloat<M> tNear; vbool<M> valid = intersect(ray,prim,tNear); @@ -187,7 +198,7 @@ namespace embree } template<typename Intersector, typename Epilog> - static __forceinline bool occluded_h(const Precalculations& pre, Ray& ray, IntersectContext* context, const Primitive& prim) + static __forceinline bool occluded_h(const Precalculations& pre, Ray& ray, RayQueryContext* context, const Primitive& prim) { vfloat<M> tNear; vbool<M> valid = intersect(ray,prim,tNear); @@ -211,7 +222,7 @@ namespace embree } template<typename Intersector, typename Epilog> - static __forceinline void intersect_hn(const Precalculations& pre, RayHit& ray, IntersectContext* context, const Primitive& prim) + static __forceinline void intersect_hn(const Precalculations& pre, RayHit& ray, RayQueryContext* context, const Primitive& prim) { vfloat<M> tNear; vbool<M> valid = intersect(ray,prim,tNear); @@ -232,7 +243,7 @@ namespace embree } template<typename Intersector, typename Epilog> - static __forceinline bool occluded_hn(const Precalculations& pre, Ray& ray, IntersectContext* context, const Primitive& prim) + static __forceinline bool occluded_hn(const Precalculations& pre, Ray& ray, RayQueryContext* context, const Primitive& prim) { vfloat<M> tNear; vbool<M> valid = intersect(ray,prim,tNear); @@ -267,10 +278,14 @@ namespace embree static __forceinline vbool<M> intersect(RayK<K>& ray, const size_t k, const Primitive& prim, vfloat<M>& tNear_o) { const size_t N = prim.N; +#if __SYCL_DEVICE_ONLY__ + const Vec3f offset = *prim.offset(N); + const float scale = *prim.scale(N); +#else const vfloat4 offset_scale = vfloat4::loadu(prim.offset(N)); const Vec3fa offset = Vec3fa(offset_scale); const Vec3fa scale = Vec3fa(shuffle<3,3,3,3>(offset_scale)); - +#endif const Vec3fa ray_org(ray.org.x[k],ray.org.y[k],ray.org.z[k]); const Vec3fa ray_dir(ray.dir.x[k],ray.dir.y[k],ray.dir.z[k]); const Vec3fa org1 = (ray_org-offset)*scale; @@ -322,7 +337,7 @@ namespace embree } template<typename Intersector, typename Epilog> - static __forceinline void intersect_t(Precalculations& pre, RayHitK<K>& ray, const size_t k, IntersectContext* context, const Primitive& prim) + static __forceinline void intersect_t(Precalculations& pre, RayHitK<K>& ray, const size_t k, RayQueryContext* context, const Primitive& prim) { vfloat<M> tNear; @@ -345,7 +360,7 @@ namespace embree } template<typename Intersector, typename Epilog> - static __forceinline bool occluded_t(Precalculations& pre, RayK<K>& ray, const size_t k, IntersectContext* context, const Primitive& prim) + static __forceinline bool occluded_t(Precalculations& pre, RayK<K>& ray, const size_t k, RayQueryContext* context, const Primitive& prim) { vfloat<M> tNear; vbool<M> valid = intersect(ray,k,prim,tNear); @@ -370,7 +385,7 @@ namespace embree } template<typename Intersector, typename Epilog> - static __forceinline void intersect_n(Precalculations& pre, RayHitK<K>& ray, const size_t k, IntersectContext* context, const Primitive& prim) + static __forceinline void intersect_n(Precalculations& pre, RayHitK<K>& ray, const size_t k, RayQueryContext* context, const Primitive& prim) { vfloat<M> tNear; @@ -393,7 +408,7 @@ namespace embree } template<typename Intersector, typename Epilog> - static __forceinline bool occluded_n(Precalculations& pre, RayK<K>& ray, const size_t k, IntersectContext* context, const Primitive& prim) + static __forceinline bool occluded_n(Precalculations& pre, RayK<K>& ray, const size_t k, RayQueryContext* context, const Primitive& prim) { vfloat<M> tNear; vbool<M> valid = intersect(ray,k,prim,tNear); @@ -419,7 +434,7 @@ namespace embree } template<typename Intersector, typename Epilog> - static __forceinline void intersect_h(Precalculations& pre, RayHitK<K>& ray, const size_t k, IntersectContext* context, const Primitive& prim) + static __forceinline void intersect_h(Precalculations& pre, RayHitK<K>& ray, const size_t k, RayQueryContext* context, const Primitive& prim) { vfloat<M> tNear; @@ -441,7 +456,7 @@ namespace embree } template<typename Intersector, typename Epilog> - static __forceinline bool occluded_h(Precalculations& pre, RayK<K>& ray, const size_t k, IntersectContext* context, const Primitive& prim) + static __forceinline bool occluded_h(Precalculations& pre, RayK<K>& ray, const size_t k, RayQueryContext* context, const Primitive& prim) { vfloat<M> tNear; vbool<M> valid = intersect(ray,k,prim,tNear); @@ -465,7 +480,7 @@ namespace embree } template<typename Intersector, typename Epilog> - static __forceinline void intersect_hn(Precalculations& pre, RayHitK<K>& ray, const size_t k, IntersectContext* context, const Primitive& prim) + static __forceinline void intersect_hn(Precalculations& pre, RayHitK<K>& ray, const size_t k, RayQueryContext* context, const Primitive& prim) { vfloat<M> tNear; @@ -488,7 +503,7 @@ namespace embree } template<typename Intersector, typename Epilog> - static __forceinline bool occluded_hn(Precalculations& pre, RayK<K>& ray, const size_t k, IntersectContext* context, const Primitive& prim) + static __forceinline bool occluded_hn(Precalculations& pre, RayK<K>& ray, const size_t k, RayQueryContext* context, const Primitive& prim) { vfloat<M> tNear; vbool<M> valid = intersect(ray,k,prim,tNear); diff --git a/thirdparty/embree/kernels/geometry/curveNv_intersector.h b/thirdparty/embree/kernels/geometry/curveNv_intersector.h index 2742725aec..cfbd1a029c 100644 --- a/thirdparty/embree/kernels/geometry/curveNv_intersector.h +++ b/thirdparty/embree/kernels/geometry/curveNv_intersector.h @@ -17,7 +17,7 @@ namespace embree typedef CurvePrecalculations1 Precalculations; template<typename Intersector, typename Epilog> - static __forceinline void intersect_t(const Precalculations& pre, RayHit& ray, IntersectContext* context, const Primitive& prim) + static __forceinline void intersect_t(const Precalculations& pre, RayHit& ray, RayQueryContext* context, const Primitive& prim) { vfloat<M> tNear; vbool<M> valid = CurveNiIntersector1<M>::intersect(ray,prim,tNear); @@ -54,7 +54,7 @@ namespace embree } template<typename Intersector, typename Epilog> - static __forceinline bool occluded_t(const Precalculations& pre, Ray& ray, IntersectContext* context, const Primitive& prim) + static __forceinline bool occluded_t(const Precalculations& pre, Ray& ray, RayQueryContext* context, const Primitive& prim) { vfloat<M> tNear; vbool<M> valid = CurveNiIntersector1<M>::intersect(ray,prim,tNear); @@ -101,7 +101,7 @@ namespace embree typedef CurvePrecalculationsK<K> Precalculations; template<typename Intersector, typename Epilog> - static __forceinline void intersect_t(Precalculations& pre, RayHitK<K>& ray, const size_t k, IntersectContext* context, const Primitive& prim) + static __forceinline void intersect_t(Precalculations& pre, RayHitK<K>& ray, const size_t k, RayQueryContext* context, const Primitive& prim) { vfloat<M> tNear; vbool<M> valid = CurveNiIntersectorK<M,K>::intersect(ray,k,prim,tNear); @@ -138,7 +138,7 @@ namespace embree } template<typename Intersector, typename Epilog> - static __forceinline bool occluded_t(Precalculations& pre, RayK<K>& ray, const size_t k, IntersectContext* context, const Primitive& prim) + static __forceinline bool occluded_t(Precalculations& pre, RayK<K>& ray, const size_t k, RayQueryContext* context, const Primitive& prim) { vfloat<M> tNear; vbool<M> valid = CurveNiIntersectorK<M,K>::intersect(ray,k,prim,tNear); diff --git a/thirdparty/embree/kernels/geometry/curve_intersector.h b/thirdparty/embree/kernels/geometry/curve_intersector.h index 1e8ac26125..a258befb5e 100644 --- a/thirdparty/embree/kernels/geometry/curve_intersector.h +++ b/thirdparty/embree/kernels/geometry/curve_intersector.h @@ -24,7 +24,7 @@ namespace embree typedef CurvePrecalculations1 Precalculations; template<int N, bool robust> - static __forceinline void intersect(const Accel::Intersectors* This, Precalculations& pre, RayHit& ray, IntersectContext* context, const Primitive* prim, size_t num, const TravRay<N,robust> &tray, size_t& lazy_node) + static __forceinline void intersect(const Accel::Intersectors* This, Precalculations& pre, RayHit& ray, RayQueryContext* context, const Primitive* prim, size_t num, const TravRay<N,robust> &tray, size_t& lazy_node) { assert(num == 1); RTCGeometryType ty = (RTCGeometryType)(*prim); @@ -34,7 +34,7 @@ namespace embree } template<int N, bool robust> - static __forceinline bool occluded(const Accel::Intersectors* This, Precalculations& pre, Ray& ray, IntersectContext* context, const Primitive* prim, size_t num, const TravRay<N,robust> &tray, size_t& lazy_node) + static __forceinline bool occluded(const Accel::Intersectors* This, Precalculations& pre, Ray& ray, RayQueryContext* context, const Primitive* prim, size_t num, const TravRay<N,robust> &tray, size_t& lazy_node) { assert(num == 1); RTCGeometryType ty = (RTCGeometryType)(*prim); @@ -50,7 +50,7 @@ namespace embree typedef unsigned char Primitive; typedef CurvePrecalculationsK<K> Precalculations; - static __forceinline void intersect(const vbool<K>& valid_i, const Accel::Intersectors* This, Precalculations& pre, RayHitK<K>& ray, IntersectContext* context, const Primitive* prim, size_t num, size_t& lazy_node) + static __forceinline void intersect(const vbool<K>& valid_i, const Accel::Intersectors* This, Precalculations& pre, RayHitK<K>& ray, RayQueryContext* context, const Primitive* prim, size_t num, size_t& lazy_node) { assert(num == 1); RTCGeometryType ty = (RTCGeometryType)(*prim); @@ -60,7 +60,7 @@ namespace embree while (mask) leafIntersector.intersect<K>(&pre,&ray,bscf(mask),context,prim); } - static __forceinline vbool<K> occluded(const vbool<K>& valid_i, const Accel::Intersectors* This, Precalculations& pre, RayK<K>& ray, IntersectContext* context, const Primitive* prim, size_t num, size_t& lazy_node) + static __forceinline vbool<K> occluded(const vbool<K>& valid_i, const Accel::Intersectors* This, Precalculations& pre, RayK<K>& ray, RayQueryContext* context, const Primitive* prim, size_t num, size_t& lazy_node) { assert(num == 1); RTCGeometryType ty = (RTCGeometryType)(*prim); @@ -76,7 +76,7 @@ namespace embree return valid_o; } - static __forceinline void intersect(const Accel::Intersectors* This, Precalculations& pre, RayHitK<K>& ray, size_t k, IntersectContext* context, const Primitive* prim, size_t num, size_t& lazy_node) + static __forceinline void intersect(const Accel::Intersectors* This, Precalculations& pre, RayHitK<K>& ray, size_t k, RayQueryContext* context, const Primitive* prim, size_t num, size_t& lazy_node) { assert(num == 1); RTCGeometryType ty = (RTCGeometryType)(*prim); @@ -85,7 +85,7 @@ namespace embree leafIntersector.intersect<K>(&pre,&ray,k,context,prim); } - static __forceinline bool occluded(const Accel::Intersectors* This, Precalculations& pre, RayK<K>& ray, size_t k, IntersectContext* context, const Primitive* prim, size_t num, size_t& lazy_node) + static __forceinline bool occluded(const Accel::Intersectors* This, Precalculations& pre, RayK<K>& ray, size_t k, RayQueryContext* context, const Primitive* prim, size_t num, size_t& lazy_node) { assert(num == 1); RTCGeometryType ty = (RTCGeometryType)(*prim); diff --git a/thirdparty/embree/kernels/geometry/curve_intersector_distance.h b/thirdparty/embree/kernels/geometry/curve_intersector_distance.h index 748a9511a5..80e1760289 100644 --- a/thirdparty/embree/kernels/geometry/curve_intersector_distance.h +++ b/thirdparty/embree/kernels/geometry/curve_intersector_distance.h @@ -45,15 +45,56 @@ namespace embree vfloat<M> vv; vfloat<M> vt; }; - + template<typename NativeCurve3fa> + struct DistanceCurveHit<NativeCurve3fa,1> + { + enum { M = 1 }; + + __forceinline DistanceCurveHit() {} + + __forceinline DistanceCurveHit(const vbool<M>& valid, const vfloat<M>& U, const vfloat<M>& V, const vfloat<M>& T, const int i, const int N, + const NativeCurve3fa& curve3D) + : U(U), V(V), T(T), i(i), N(N), curve3D(curve3D), valid(valid) {} + + __forceinline void finalize() + { + vu = (vfloat<M>(step)+U+vfloat<M>(float(i)))*(1.0f/float(N)); + vv = V; + vt = T; + } + + __forceinline Vec2f uv () const { return Vec2f(vu,vv); } + __forceinline float t () const { return vt; } + __forceinline Vec3fa Ng() const { return curve3D.eval_du(vu); } + + public: + vfloat<M> U; + vfloat<M> V; + vfloat<M> T; + int i, N; + NativeCurve3fa curve3D; + + public: + vbool<M> valid; + vfloat<M> vu; + vfloat<M> vv; + vfloat<M> vt; + }; + + template<typename NativeCurve3fa, int W = VSIZEX> struct DistanceCurve1Intersector1 { + using vboolx = vbool<W>; + using vintx = vint<W>; + using vfloatx = vfloat<W>; + using Vec4vfx = Vec4vf<W>; + template<typename Epilog> - __forceinline bool intersect(const CurvePrecalculations1& pre,Ray& ray, - IntersectContext* context, + __forceinline bool intersect(const CurvePrecalculations1& pre, Ray& ray, + RayQueryContext* context, const CurveGeometry* geom, const unsigned int primID, - const Vec3fa& v0, const Vec3fa& v1, const Vec3fa& v2, const Vec3fa& v3, + const Vec3ff& v0, const Vec3ff& v1, const Vec3ff& v2, const Vec3ff& v3, const Epilog& epilog) { const int N = geom->tessellationRate; @@ -65,8 +106,8 @@ namespace embree /* evaluate the bezier curve */ vboolx valid = vfloatx(step) < vfloatx(float(N)); - const Vec4vfx p0 = curve2D.template eval0<VSIZEX>(0,N); - const Vec4vfx p1 = curve2D.template eval1<VSIZEX>(0,N); + const Vec4vfx p0 = curve2D.template eval0<W>(0,N); + const Vec4vfx p1 = curve2D.template eval1<W>(0,N); /* approximative intersection with cone */ const Vec4vfx v = p1-p0; @@ -86,19 +127,19 @@ namespace embree /* update hit information */ bool ishit = false; if (unlikely(any(valid))) { - DistanceCurveHit<NativeCurve3fa,VSIZEX> hit(valid,u,0.0f,t,0,N,curve3D); + DistanceCurveHit<NativeCurve3fa,W> hit(valid,u,0.0f,t,0,N,curve3D); ishit = ishit | epilog(valid,hit); } - if (unlikely(VSIZEX < N)) + if (unlikely(W < N)) { /* process SIMD-size many segments per iteration */ - for (int i=VSIZEX; i<N; i+=VSIZEX) + for (int i=W; i<N; i+=W) { /* evaluate the bezier curve */ vboolx valid = vintx(i)+vintx(step) < vintx(N); - const Vec4vfx p0 = curve2D.template eval0<VSIZEX>(i,N); - const Vec4vfx p1 = curve2D.template eval1<VSIZEX>(i,N); + const Vec4vfx p0 = curve2D.template eval0<W>(i,N); + const Vec4vfx p1 = curve2D.template eval1<W>(i,N); /* approximative intersection with cone */ const Vec4vfx v = p1-p0; @@ -117,7 +158,7 @@ namespace embree /* update hit information */ if (unlikely(any(valid))) { - DistanceCurveHit<NativeCurve3fa,VSIZEX> hit(valid,u,0.0f,t,i,N,curve3D); + DistanceCurveHit<NativeCurve3fa,W> hit(valid,u,0.0f,t,i,N,curve3D); ishit = ishit | epilog(valid,hit); } } diff --git a/thirdparty/embree/kernels/geometry/curve_intersector_oriented.h b/thirdparty/embree/kernels/geometry/curve_intersector_oriented.h index 75532f5ae0..cdab06ea5e 100644 --- a/thirdparty/embree/kernels/geometry/curve_intersector_oriented.h +++ b/thirdparty/embree/kernels/geometry/curve_intersector_oriented.h @@ -14,7 +14,7 @@ namespace embree { namespace isa { - template<typename Ray, typename Epilog> + template<typename Ray, typename Epilog, int N = VSIZEX-1, int V = VSIZEX> struct TensorLinearCubicBezierSurfaceIntersector { const LinearSpace3fa& ray_space; @@ -235,7 +235,7 @@ namespace embree if (!clip_v(cu,cv)) return; return solve_newton_raphson(cu,cv); } - + __forceinline void solve_newton_raphson_recursion(BBox1f cu, BBox1f cv) { unsigned int sptr = 0; @@ -259,8 +259,8 @@ namespace embree if (mask) sptr++; // there are still items on the stack /* process next element recurse into each hit curve segment */ - const float u0 = float(i+0)*(1.0f/(VSIZEX-1)); - const float u1 = float(i+1)*(1.0f/(VSIZEX-1)); + const float u0 = float(i+0)*(1.0f/(N)); + const float u1 = float(i+1)*(1.0f/(N)); const BBox1f cui(lerp(cu.lower,cu.upper,u0),lerp(cu.lower,cu.upper,u1)); cu = cui; } @@ -280,28 +280,37 @@ namespace embree #endif entry: - - /* split the curve into VSIZEX-1 segments in u-direction */ - vboolx valid = true; - TensorLinearCubicBezierSurface<Vec2vfx> subcurves = curve2d.clip_v(cv).vsplit_u(valid,cu); - - /* slabs test in u-direction */ - Vec2vfx ndv = cross(subcurves.axis_v()); - BBox<vfloatx> boundsv = subcurves.vxfm(ndv).bounds(); - valid &= boundsv.lower <= eps; - valid &= boundsv.upper >= -eps; - if (none(valid)) continue; - - /* slabs test in v-direction */ - Vec2vfx ndu = cross(subcurves.axis_u()); - BBox<vfloatx> boundsu = subcurves.vxfm(ndu).bounds(); - valid &= boundsu.lower <= eps; - valid &= boundsu.upper >= -eps; - if (none(valid)) continue; + + /* split the curve into N segments in u-direction */ + unsigned int mask = 0; + for (int i=0; i<N;) + { + int i0 = i; + vbool<V> valid = true; + TensorLinearCubicBezierSurface<Vec2vf<V>> subcurves = curve2d.clip_v(cv).template vsplit_u<V>(valid,cu,i,N); + + /* slabs test in u-direction */ + Vec2vf<V> ndv = cross(subcurves.axis_v()); + BBox<vfloat<V>> boundsv = subcurves.template vxfm<V>(ndv).bounds(); + valid &= boundsv.lower <= eps; + valid &= boundsv.upper >= -eps; + if (none(valid)) continue; + + /* slabs test in v-direction */ + Vec2vf<V> ndu = cross(subcurves.axis_u()); + BBox<vfloat<V>> boundsu = subcurves.template vxfm<V>(ndu).bounds(); + valid &= boundsu.lower <= eps; + valid &= boundsu.upper >= -eps; + if (none(valid)) continue; + + mask |= movemask(valid) << i0; + } + + if (!mask) continue; /* push valid segments to stack */ assert(sptr < stack_size); - mask_stack [sptr] = movemask(valid); + mask_stack [sptr] = mask; cu_stack [sptr] = cu; cv_stack [sptr] = cv; sptr++; @@ -318,7 +327,7 @@ namespace embree }; - template<template<typename Ty> class SourceCurve> + template<template<typename Ty> class SourceCurve, int N = VSIZEX-1, int V = VSIZEX> struct OrientedCurve1Intersector1 { //template<typename Ty> using Curve = SourceCurve<Ty>; @@ -329,33 +338,32 @@ namespace embree __forceinline OrientedCurve1Intersector1(const Ray& ray, const void* ptr) {} - template<typename Epilog> - __noinline bool intersect(const CurvePrecalculations1& pre, Ray& ray, - IntersectContext* context, + template<typename Ray, typename Epilog> + __forceinline bool intersect(const CurvePrecalculations1& pre, Ray& ray, + RayQueryContext* context, const CurveGeometry* geom, const unsigned int primID, const Vec3ff& v0i, const Vec3ff& v1i, const Vec3ff& v2i, const Vec3ff& v3i, const Vec3fa& n0i, const Vec3fa& n1i, const Vec3fa& n2i, const Vec3fa& n3i, const Epilog& epilog) const { STAT3(normal.trav_prims,1,1,1); - SourceCurve3ff ccurve(v0i,v1i,v2i,v3i); SourceCurve3fa ncurve(n0i,n1i,n2i,n3i); ccurve = enlargeRadiusToMinWidth(context,geom,ray.org,ccurve); TensorLinearCubicBezierSurface3fa curve = TensorLinearCubicBezierSurface3fa::fromCenterAndNormalCurve(ccurve,ncurve); //return TensorLinearCubicBezierSurfaceIntersector<Ray,Epilog>(pre.ray_space,ray,curve,epilog).solve_bezier_clipping(); - return TensorLinearCubicBezierSurfaceIntersector<Ray,Epilog>(pre.ray_space,ray,curve,epilog).solve_newton_raphson_main(); + return TensorLinearCubicBezierSurfaceIntersector<Ray,Epilog,N,V>(pre.ray_space,ray,curve,epilog).solve_newton_raphson_main(); } - template<typename Epilog> - __noinline bool intersect(const CurvePrecalculations1& pre, Ray& ray, - IntersectContext* context, + template<typename Ray, typename Epilog> + __forceinline bool intersect(const CurvePrecalculations1& pre, Ray& ray, + RayQueryContext* context, const CurveGeometry* geom, const unsigned int primID, const TensorLinearCubicBezierSurface3fa& curve, const Epilog& epilog) const { STAT3(normal.trav_prims,1,1,1); //return TensorLinearCubicBezierSurfaceIntersector<Ray,Epilog>(pre.ray_space,ray,curve,epilog).solve_bezier_clipping(); - return TensorLinearCubicBezierSurfaceIntersector<Ray,Epilog>(pre.ray_space,ray,curve,epilog).solve_newton_raphson_main(); + return TensorLinearCubicBezierSurfaceIntersector<Ray,Epilog,N,V>(pre.ray_space,ray,curve,epilog).solve_newton_raphson_main(); } }; @@ -384,7 +392,7 @@ namespace embree template<typename Epilog> __forceinline bool intersect(const CurvePrecalculationsK<K>& pre, RayK<K>& vray, size_t k, - IntersectContext* context, + RayQueryContext* context, const CurveGeometry* geom, const unsigned int primID, const Vec3ff& v0i, const Vec3ff& v1i, const Vec3ff& v2i, const Vec3ff& v3i, const Vec3fa& n0i, const Vec3fa& n1i, const Vec3fa& n2i, const Vec3fa& n3i, @@ -402,7 +410,7 @@ namespace embree template<typename Epilog> __forceinline bool intersect(const CurvePrecalculationsK<K>& pre, RayK<K>& vray, size_t k, - IntersectContext* context, + RayQueryContext* context, const CurveGeometry* geom, const unsigned int primID, const TensorLinearCubicBezierSurface3fa& curve, const Epilog& epilog) diff --git a/thirdparty/embree/kernels/geometry/curve_intersector_ribbon.h b/thirdparty/embree/kernels/geometry/curve_intersector_ribbon.h index c3272e99fd..423fd5b08d 100644 --- a/thirdparty/embree/kernels/geometry/curve_intersector_ribbon.h +++ b/thirdparty/embree/kernels/geometry/curve_intersector_ribbon.h @@ -53,21 +53,23 @@ namespace embree }; /* calculate squared distance of point p0 to line p1->p2 */ - __forceinline std::pair<vfloatx,vfloatx> sqr_point_line_distance(const Vec2vfx& p0, const Vec2vfx& p1, const Vec2vfx& p2) + template<int M> + __forceinline std::pair<vfloat<M>,vfloat<M>> sqr_point_line_distance(const Vec2vf<M>& p0, const Vec2vf<M>& p1, const Vec2vf<M>& p2) { - const vfloatx num = det(p2-p1,p1-p0); - const vfloatx den2 = dot(p2-p1,p2-p1); + const vfloat<M> num = det(p2-p1,p1-p0); + const vfloat<M> den2 = dot(p2-p1,p2-p1); return std::make_pair(num*num,den2); } /* performs culling against a cylinder */ - __forceinline vboolx cylinder_culling_test(const Vec2vfx& p0, const Vec2vfx& p1, const Vec2vfx& p2, const vfloatx& r) + template<int M> + __forceinline vbool<M> cylinder_culling_test(const Vec2vf<M>& p0, const Vec2vf<M>& p1, const Vec2vf<M>& p2, const vfloat<M>& r) { - const std::pair<vfloatx,vfloatx> d = sqr_point_line_distance(p0,p1,p2); + const std::pair<vfloat<M>,vfloat<M>> d = sqr_point_line_distance<M>(p0,p1,p2); return d.first <= r*r*d.second; } - template<typename NativeCurve3ff, typename Epilog> + template<int M = VSIZEX, typename NativeCurve3ff, typename Epilog> __forceinline bool intersect_ribbon(const Vec3fa& ray_org, const Vec3fa& ray_dir, const float ray_tnear, const float& ray_tfar, const LinearSpace3fa& ray_space, const float& depth_scale, const NativeCurve3ff& curve3D, const int N, @@ -76,89 +78,96 @@ namespace embree /* transform control points into ray space */ const NativeCurve3ff curve2D = curve3D.xfm_pr(ray_space,ray_org); float eps = 4.0f*float(ulp)*reduce_max(max(abs(curve2D.v0),abs(curve2D.v1),abs(curve2D.v2),abs(curve2D.v3))); - - /* evaluate the bezier curve */ + + int i=0; bool ishit = false; - vboolx valid = vfloatx(step) < vfloatx(float(N)); - const Vec4vfx p0 = curve2D.template eval0<VSIZEX>(0,N); - const Vec4vfx p1 = curve2D.template eval1<VSIZEX>(0,N); - valid &= cylinder_culling_test(zero,Vec2vfx(p0.x,p0.y),Vec2vfx(p1.x,p1.y),max(p0.w,p1.w)); - if (any(valid)) +#if !defined(__SYCL_DEVICE_ONLY__) { - Vec3vfx dp0dt = curve2D.template derivative0<VSIZEX>(0,N); - Vec3vfx dp1dt = curve2D.template derivative1<VSIZEX>(0,N); - dp0dt = select(reduce_max(abs(dp0dt)) < vfloatx(eps),Vec3vfx(p1-p0),dp0dt); - dp1dt = select(reduce_max(abs(dp1dt)) < vfloatx(eps),Vec3vfx(p1-p0),dp1dt); - const Vec3vfx n0(dp0dt.y,-dp0dt.x,0.0f); - const Vec3vfx n1(dp1dt.y,-dp1dt.x,0.0f); - const Vec3vfx nn0 = normalize(n0); - const Vec3vfx nn1 = normalize(n1); - const Vec3vfx lp0 = madd(p0.w,nn0,Vec3vfx(p0)); - const Vec3vfx lp1 = madd(p1.w,nn1,Vec3vfx(p1)); - const Vec3vfx up0 = nmadd(p0.w,nn0,Vec3vfx(p0)); - const Vec3vfx up1 = nmadd(p1.w,nn1,Vec3vfx(p1)); + /* evaluate the bezier curve */ + vbool<M> valid = vfloat<M>(step) < vfloat<M>(float(N)); + const Vec4vf<M> p0 = curve2D.template eval0<M>(0,N); + const Vec4vf<M> p1 = curve2D.template eval1<M>(0,N); + valid &= cylinder_culling_test<M>(zero,Vec2vf<M>(p0.x,p0.y),Vec2vf<M>(p1.x,p1.y),max(p0.w,p1.w)); - vfloatx vu,vv,vt; - vboolx valid0 = intersect_quad_backface_culling<VSIZEX>(valid,zero,Vec3fa(0,0,1),ray_tnear,ray_tfar,lp0,lp1,up1,up0,vu,vv,vt); - - if (any(valid0)) + if (any(valid)) { - /* ignore self intersections */ - if (EMBREE_CURVE_SELF_INTERSECTION_AVOIDANCE_FACTOR != 0.0f) { - vfloatx r = lerp(p0.w, p1.w, vu); - valid0 &= vt > float(EMBREE_CURVE_SELF_INTERSECTION_AVOIDANCE_FACTOR)*r*depth_scale; - } + Vec3vf<M> dp0dt = curve2D.template derivative0<M>(0,N); + Vec3vf<M> dp1dt = curve2D.template derivative1<M>(0,N); + dp0dt = select(reduce_max(abs(dp0dt)) < vfloat<M>(eps),Vec3vf<M>(p1-p0),dp0dt); + dp1dt = select(reduce_max(abs(dp1dt)) < vfloat<M>(eps),Vec3vf<M>(p1-p0),dp1dt); + const Vec3vf<M> n0(dp0dt.y,-dp0dt.x,0.0f); + const Vec3vf<M> n1(dp1dt.y,-dp1dt.x,0.0f); + const Vec3vf<M> nn0 = normalize(n0); + const Vec3vf<M> nn1 = normalize(n1); + const Vec3vf<M> lp0 = madd(p0.w,nn0,Vec3vf<M>(p0)); + const Vec3vf<M> lp1 = madd(p1.w,nn1,Vec3vf<M>(p1)); + const Vec3vf<M> up0 = nmadd(p0.w,nn0,Vec3vf<M>(p0)); + const Vec3vf<M> up1 = nmadd(p1.w,nn1,Vec3vf<M>(p1)); + + vfloat<M> vu,vv,vt; + vbool<M> valid0 = intersect_quad_backface_culling<M>(valid,zero,Vec3fa(0,0,1),ray_tnear,ray_tfar,lp0,lp1,up1,up0,vu,vv,vt); if (any(valid0)) { - vv = madd(2.0f,vv,vfloatx(-1.0f)); - RibbonHit<NativeCurve3ff,VSIZEX> bhit(valid0,vu,vv,vt,0,N,curve3D); - ishit |= epilog(bhit.valid,bhit); + /* ignore self intersections */ + if (EMBREE_CURVE_SELF_INTERSECTION_AVOIDANCE_FACTOR != 0.0f) { + vfloat<M> r = lerp(p0.w, p1.w, vu); + valid0 &= vt > float(EMBREE_CURVE_SELF_INTERSECTION_AVOIDANCE_FACTOR)*r*depth_scale; + } + + if (any(valid0)) + { + vv = madd(2.0f,vv,vfloat<M>(-1.0f)); + RibbonHit<NativeCurve3ff,M> bhit(valid0,vu,vv,vt,0,N,curve3D); + ishit |= epilog(bhit.valid,bhit); + } } } + i += M; } - if (unlikely(VSIZEX < N)) + if (unlikely(i < N)) +#endif { /* process SIMD-size many segments per iteration */ - for (int i=VSIZEX; i<N; i+=VSIZEX) + for (; i<N; i+=M) { /* evaluate the bezier curve */ - vboolx valid = vintx(i)+vintx(step) < vintx(N); - const Vec4vfx p0 = curve2D.template eval0<VSIZEX>(i,N); - const Vec4vfx p1 = curve2D.template eval1<VSIZEX>(i,N); - valid &= cylinder_culling_test(zero,Vec2vfx(p0.x,p0.y),Vec2vfx(p1.x,p1.y),max(p0.w,p1.w)); + vbool<M> valid = vint<M>(i)+vint<M>(step) < vint<M>(N); + const Vec4vf<M> p0 = curve2D.template eval0<M>(i,N); + const Vec4vf<M> p1 = curve2D.template eval1<M>(i,N); + valid &= cylinder_culling_test<M>(zero,Vec2vf<M>(p0.x,p0.y),Vec2vf<M>(p1.x,p1.y),max(p0.w,p1.w)); if (none(valid)) continue; - Vec3vfx dp0dt = curve2D.template derivative0<VSIZEX>(i,N); - Vec3vfx dp1dt = curve2D.template derivative1<VSIZEX>(i,N); - dp0dt = select(reduce_max(abs(dp0dt)) < vfloatx(eps),Vec3vfx(p1-p0),dp0dt); - dp1dt = select(reduce_max(abs(dp1dt)) < vfloatx(eps),Vec3vfx(p1-p0),dp1dt); - const Vec3vfx n0(dp0dt.y,-dp0dt.x,0.0f); - const Vec3vfx n1(dp1dt.y,-dp1dt.x,0.0f); - const Vec3vfx nn0 = normalize(n0); - const Vec3vfx nn1 = normalize(n1); - const Vec3vfx lp0 = madd(p0.w,nn0,Vec3vfx(p0)); - const Vec3vfx lp1 = madd(p1.w,nn1,Vec3vfx(p1)); - const Vec3vfx up0 = nmadd(p0.w,nn0,Vec3vfx(p0)); - const Vec3vfx up1 = nmadd(p1.w,nn1,Vec3vfx(p1)); + Vec3vf<M> dp0dt = curve2D.template derivative0<M>(i,N); + Vec3vf<M> dp1dt = curve2D.template derivative1<M>(i,N); + dp0dt = select(reduce_max(abs(dp0dt)) < vfloat<M>(eps),Vec3vf<M>(p1-p0),dp0dt); + dp1dt = select(reduce_max(abs(dp1dt)) < vfloat<M>(eps),Vec3vf<M>(p1-p0),dp1dt); + const Vec3vf<M> n0(dp0dt.y,-dp0dt.x,0.0f); + const Vec3vf<M> n1(dp1dt.y,-dp1dt.x,0.0f); + const Vec3vf<M> nn0 = normalize(n0); + const Vec3vf<M> nn1 = normalize(n1); + const Vec3vf<M> lp0 = madd(p0.w,nn0,Vec3vf<M>(p0)); + const Vec3vf<M> lp1 = madd(p1.w,nn1,Vec3vf<M>(p1)); + const Vec3vf<M> up0 = nmadd(p0.w,nn0,Vec3vf<M>(p0)); + const Vec3vf<M> up1 = nmadd(p1.w,nn1,Vec3vf<M>(p1)); - vfloatx vu,vv,vt; - vboolx valid0 = intersect_quad_backface_culling<VSIZEX>(valid,zero,Vec3fa(0,0,1),ray_tnear,ray_tfar,lp0,lp1,up1,up0,vu,vv,vt); + vfloat<M> vu,vv,vt; + vbool<M> valid0 = intersect_quad_backface_culling<M>(valid,zero,Vec3fa(0,0,1),ray_tnear,ray_tfar,lp0,lp1,up1,up0,vu,vv,vt); if (any(valid0)) { /* ignore self intersections */ if (EMBREE_CURVE_SELF_INTERSECTION_AVOIDANCE_FACTOR != 0.0f) { - vfloatx r = lerp(p0.w, p1.w, vu); + vfloat<M> r = lerp(p0.w, p1.w, vu); valid0 &= vt > float(EMBREE_CURVE_SELF_INTERSECTION_AVOIDANCE_FACTOR)*r*depth_scale; } if (any(valid0)) { - vv = madd(2.0f,vv,vfloatx(-1.0f)); - RibbonHit<NativeCurve3ff,VSIZEX> bhit(valid0,vu,vv,vt,i,N,curve3D); + vv = madd(2.0f,vv,vfloat<M>(-1.0f)); + RibbonHit<NativeCurve3ff,M> bhit(valid0,vu,vv,vt,i,N,curve3D); ishit |= epilog(bhit.valid,bhit); } } @@ -167,14 +176,14 @@ namespace embree return ishit; } - template<template<typename Ty> class NativeCurve> + template<template<typename Ty> class NativeCurve, int M = VSIZEX> struct RibbonCurve1Intersector1 { typedef NativeCurve<Vec3ff> NativeCurve3ff; - template<typename Epilog> + template<typename Ray, typename Epilog> __forceinline bool intersect(const CurvePrecalculations1& pre, Ray& ray, - IntersectContext* context, + RayQueryContext* context, const CurveGeometry* geom, const unsigned int primID, const Vec3ff& v0, const Vec3ff& v1, const Vec3ff& v2, const Vec3ff& v3, const Epilog& epilog) @@ -182,21 +191,21 @@ namespace embree const int N = geom->tessellationRate; NativeCurve3ff curve(v0,v1,v2,v3); curve = enlargeRadiusToMinWidth(context,geom,ray.org,curve); - return intersect_ribbon<NativeCurve3ff>(ray.org,ray.dir,ray.tnear(),ray.tfar, + return intersect_ribbon<M,NativeCurve3ff>(ray.org,ray.dir,ray.tnear(),ray.tfar, pre.ray_space,pre.depth_scale, curve,N, epilog); } }; - template<template<typename Ty> class NativeCurve, int K> + template<template<typename Ty> class NativeCurve, int K, int M = VSIZEX> struct RibbonCurve1IntersectorK { typedef NativeCurve<Vec3ff> NativeCurve3ff; template<typename Epilog> __forceinline bool intersect(const CurvePrecalculationsK<K>& pre, RayK<K>& ray, size_t k, - IntersectContext* context, + RayQueryContext* context, const CurveGeometry* geom, const unsigned int primID, const Vec3ff& v0, const Vec3ff& v1, const Vec3ff& v2, const Vec3ff& v3, const Epilog& epilog) @@ -206,7 +215,7 @@ namespace embree const Vec3fa ray_dir(ray.dir.x[k],ray.dir.y[k],ray.dir.z[k]); NativeCurve3ff curve(v0,v1,v2,v3); curve = enlargeRadiusToMinWidth(context,geom,ray_org,curve); - return intersect_ribbon<NativeCurve3ff>(ray_org,ray_dir,ray.tnear()[k],ray.tfar[k], + return intersect_ribbon<M,NativeCurve3ff>(ray_org,ray_dir,ray.tnear()[k],ray.tfar[k], pre.ray_space[k],pre.depth_scale[k], curve,N, epilog); diff --git a/thirdparty/embree/kernels/geometry/curve_intersector_sweep.h b/thirdparty/embree/kernels/geometry/curve_intersector_sweep.h index ed827d583f..5581822551 100644 --- a/thirdparty/embree/kernels/geometry/curve_intersector_sweep.h +++ b/thirdparty/embree/kernels/geometry/curve_intersector_sweep.h @@ -14,7 +14,9 @@ namespace embree namespace isa { static const size_t numJacobianIterations = 5; -#if defined(__AVX__) +#if defined(EMBREE_SYCL_SUPPORT) && defined(__SYCL_DEVICE_ONLY__) + static const size_t numBezierSubdivisions = 2; +#elif defined(__AVX__) static const size_t numBezierSubdivisions = 2; #else static const size_t numBezierSubdivisions = 3; @@ -132,10 +134,15 @@ namespace embree return false; } +#if !defined(__SYCL_DEVICE_ONLY__) + template<typename NativeCurve3ff, typename Ray, typename Epilog> - bool intersect_bezier_recursive_jacobian(const Ray& ray, const float dt, const NativeCurve3ff& curve, - float u0, float u1, unsigned int depth, const Epilog& epilog) + __forceinline bool intersect_bezier_recursive_jacobian(const Ray& ray, const float dt, const NativeCurve3ff& curve, const Epilog& epilog) { + float u0 = 0.0f; + float u1 = 1.0f; + unsigned int depth = 1; + #if defined(__AVX__) enum { VSIZEX_ = 8 }; typedef vbool8 vboolx; // maximally 8-wide to work around KNL issues @@ -147,8 +154,6 @@ namespace embree typedef vint4 vintx; typedef vfloat4 vfloatx; #endif - typedef Vec3<vfloatx> Vec3vfx; - typedef Vec4<vfloatx> Vec4vfx; unsigned int maxDepth = numBezierSubdivisions; bool found = false; @@ -295,14 +300,156 @@ namespace embree return found; } +#else + + template<typename NativeCurve3ff, typename Ray, typename Epilog> + __forceinline bool intersect_bezier_recursive_jacobian(const Ray& ray, const float dt, const NativeCurve3ff& curve, const Epilog& epilog) + { + const Vec3fa org = zero; + const Vec3fa dir = ray.dir; + const unsigned int max_depth = 7; + + bool found = false; + + struct ShortStack + { + /* pushes both children */ + __forceinline void push() { + depth++; + } + + /* pops next node */ + __forceinline void pop() { + short_stack += (1<<(31-depth)); + depth = 31-bsf(short_stack); + } + + unsigned int depth = 0; + unsigned int short_stack = 0; + }; + + ShortStack stack; + + do + { + const float u0 = (stack.short_stack+0*(1<<(31-stack.depth)))/float(0x80000000); + const float u1 = (stack.short_stack+1*(1<<(31-stack.depth)))/float(0x80000000); + + /* subdivide bezier curve */ + Vec3ff P0, dP0du; curve.eval(u0,P0,dP0du); dP0du = dP0du * (u1-u0); + Vec3ff P3, dP3du; curve.eval(u1,P3,dP3du); dP3du = dP3du * (u1-u0); + const Vec3ff P1 = P0 + dP0du*(1.0f/3.0f); + const Vec3ff P2 = P3 - dP3du*(1.0f/3.0f); + + /* check if curve is well behaved, by checking deviation of tangents from straight line */ + const Vec3ff W = Vec3ff(P3-P0,0.0f); + const Vec3ff dQ0 = abs(3.0f*(P1-P0) - W); + const Vec3ff dQ1 = abs(3.0f*(P2-P1) - W); + const Vec3ff dQ2 = abs(3.0f*(P3-P2) - W); + const Vec3ff max_dQ = max(dQ0,dQ1,dQ2); + const float m = max(max_dQ.x,max_dQ.y,max_dQ.z); //,max_dQ.w); + const float l = length(Vec3f(W)); + const bool well_behaved = m < 0.2f*l; + + if (!well_behaved && stack.depth < max_depth) { + stack.push(); + continue; + } + + /* calculate bounding cylinders */ + const float rr1 = sqr_point_to_line_distance(Vec3f(dP0du),Vec3f(P3-P0)); + const float rr2 = sqr_point_to_line_distance(Vec3f(dP3du),Vec3f(P3-P0)); + const float maxr12 = sqrt(max(rr1,rr2)); + const float one_plus_ulp = 1.0f+2.0f*float(ulp); + const float one_minus_ulp = 1.0f-2.0f*float(ulp); + float r_outer = max(P0.w,P1.w,P2.w,P3.w)+maxr12; + float r_inner = min(P0.w,P1.w,P2.w,P3.w)-maxr12; + r_outer = one_plus_ulp*r_outer; + r_inner = max(0.0f,one_minus_ulp*r_inner); + const Cylinder cylinder_outer(Vec3f(P0),Vec3f(P3),r_outer); + const Cylinder cylinder_inner(Vec3f(P0),Vec3f(P3),r_inner); + + /* intersect with outer cylinder */ + BBox<float> tc_outer; float u_outer0; Vec3fa Ng_outer0; float u_outer1; Vec3fa Ng_outer1; + if (!cylinder_outer.intersect(org,dir,tc_outer,u_outer0,Ng_outer0,u_outer1,Ng_outer1)) + { + stack.pop(); + continue; + } + + /* intersect with cap-planes */ + BBox<float> tp(ray.tnear()-dt,ray.tfar-dt); + tp = embree::intersect(tp,tc_outer); + BBox<float> h0 = HalfPlane(Vec3f(P0),+Vec3f(dP0du)).intersect(org,dir); + tp = embree::intersect(tp,h0); + BBox<float> h1 = HalfPlane(Vec3f(P3),-Vec3f(dP3du)).intersect(org,dir); + tp = embree::intersect(tp,h1); + if (tp.lower > tp.upper) + { + stack.pop(); + continue; + } + + bool valid = true; + + /* clamp and correct u parameter */ + u_outer0 = clamp(u_outer0,float(0.0f),float(1.0f)); + u_outer1 = clamp(u_outer1,float(0.0f),float(1.0f)); + u_outer0 = lerp(u0,u1,u_outer0); + u_outer1 = lerp(u0,u1,u_outer1); + + /* intersect with inner cylinder */ + BBox<float> tc_inner; + float u_inner0 = zero; Vec3fa Ng_inner0 = zero; float u_inner1 = zero; Vec3fa Ng_inner1 = zero; + const bool valid_inner = cylinder_inner.intersect(org,dir,tc_inner,u_inner0,Ng_inner0,u_inner1,Ng_inner1); + + /* subtract the inner interval from the current hit interval */ + BBox<float> tp0, tp1; + subtract(tp,tc_inner,tp0,tp1); + bool valid0 = valid & (tp0.lower <= tp0.upper); + bool valid1 = valid & (tp1.lower <= tp1.upper); + if (!(valid0 | valid1)) + { + stack.pop(); + continue; + } + + /* at the unstable area we subdivide deeper */ + const bool unstable0 = valid0 && ((!valid_inner) | (abs(dot(Vec3fa(ray.dir),Ng_inner0)) < 0.3f)); + const bool unstable1 = valid1 && ((!valid_inner) | (abs(dot(Vec3fa(ray.dir),Ng_inner1)) < 0.3f)); + + if ((unstable0 | unstable1) && (stack.depth < max_depth)) { + stack.push(); + continue; + } + + if (valid0) + found |= intersect_bezier_iterative_jacobian(ray,dt,curve,u_outer0,tp0.lower,epilog); + + /* the far hit cannot be closer, thus skip if we hit entry already */ + valid1 &= tp1.lower+dt <= ray.tfar; + + /* iterate over second hit */ + if (valid1) + found |= intersect_bezier_iterative_jacobian(ray,dt,curve,u_outer1,tp1.upper,epilog); + + stack.pop(); + + } while (stack.short_stack != 0x80000000); + + return found; + } + +#endif + template<template<typename Ty> class NativeCurve> struct SweepCurve1Intersector1 { typedef NativeCurve<Vec3ff> NativeCurve3ff; - template<typename Epilog> - __noinline bool intersect(const CurvePrecalculations1& pre, Ray& ray, - IntersectContext* context, + template<typename Ray, typename Epilog> + __forceinline bool intersect(const CurvePrecalculations1& pre, Ray& ray, + RayQueryContext* context, const CurveGeometry* geom, const unsigned int primID, const Vec3ff& v0, const Vec3ff& v1, const Vec3ff& v2, const Vec3ff& v3, const Epilog& epilog) @@ -315,7 +462,7 @@ namespace embree const float dt = dot(curve0.center()-ray.org,ray.dir)*rcp(dot(ray.dir,ray.dir)); const Vec3ff ref(madd(Vec3fa(dt),ray.dir,ray.org),0.0f); const NativeCurve3ff curve1 = curve0-ref; - return intersect_bezier_recursive_jacobian(ray,dt,curve1,0.0f,1.0f,1,epilog); + return intersect_bezier_recursive_jacobian(ray,dt,curve1,epilog); } }; @@ -343,7 +490,7 @@ namespace embree template<typename Epilog> __forceinline bool intersect(const CurvePrecalculationsK<K>& pre, RayK<K>& vray, size_t k, - IntersectContext* context, + RayQueryContext* context, const CurveGeometry* geom, const unsigned int primID, const Vec3ff& v0, const Vec3ff& v1, const Vec3ff& v2, const Vec3ff& v3, const Epilog& epilog) @@ -357,7 +504,7 @@ namespace embree const float dt = dot(curve0.center()-ray.org,ray.dir)*rcp(dot(ray.dir,ray.dir)); const Vec3ff ref(madd(Vec3fa(dt),ray.dir,ray.org),0.0f); const NativeCurve3ff curve1 = curve0-ref; - return intersect_bezier_recursive_jacobian(ray,dt,curve1,0.0f,1.0f,1,epilog); + return intersect_bezier_recursive_jacobian(ray,dt,curve1,epilog); } }; } diff --git a/thirdparty/embree/kernels/geometry/curve_intersector_virtual.h b/thirdparty/embree/kernels/geometry/curve_intersector_virtual.h index cffa8e46ad..cbdcadac0c 100644 --- a/thirdparty/embree/kernels/geometry/curve_intersector_virtual.h +++ b/thirdparty/embree/kernels/geometry/curve_intersector_virtual.h @@ -5,7 +5,7 @@ #include "primitive.h" #include "../subdiv/bezier_curve.h" -#include "../common/primref.h" +#include "../builders/primref.h" #include "curve_intersector_precalculations.h" #include "../bvh/node_intersector1.h" #include "../bvh/node_intersector_packet.h" @@ -37,28 +37,28 @@ namespace embree { struct VirtualCurveIntersector { - typedef void (*Intersect1Ty)(void* pre, void* ray, IntersectContext* context, const void* primitive); - typedef bool (*Occluded1Ty )(void* pre, void* ray, IntersectContext* context, const void* primitive); + typedef void (*Intersect1Ty)(void* pre, void* ray, RayQueryContext* context, const void* primitive); + typedef bool (*Occluded1Ty )(void* pre, void* ray, RayQueryContext* context, const void* primitive); - typedef void (*Intersect4Ty)(void* pre, void* ray, size_t k, IntersectContext* context, const void* primitive); - typedef bool (*Occluded4Ty) (void* pre, void* ray, size_t k, IntersectContext* context, const void* primitive); + typedef void (*Intersect4Ty)(void* pre, void* ray, size_t k, RayQueryContext* context, const void* primitive); + typedef bool (*Occluded4Ty) (void* pre, void* ray, size_t k, RayQueryContext* context, const void* primitive); - typedef void (*Intersect8Ty)(void* pre, void* ray, size_t k, IntersectContext* context, const void* primitive); - typedef bool (*Occluded8Ty) (void* pre, void* ray, size_t k, IntersectContext* context, const void* primitive); + typedef void (*Intersect8Ty)(void* pre, void* ray, size_t k, RayQueryContext* context, const void* primitive); + typedef bool (*Occluded8Ty) (void* pre, void* ray, size_t k, RayQueryContext* context, const void* primitive); - typedef void (*Intersect16Ty)(void* pre, void* ray, size_t k, IntersectContext* context, const void* primitive); - typedef bool (*Occluded16Ty) (void* pre, void* ray, size_t k, IntersectContext* context, const void* primitive); + typedef void (*Intersect16Ty)(void* pre, void* ray, size_t k, RayQueryContext* context, const void* primitive); + typedef bool (*Occluded16Ty) (void* pre, void* ray, size_t k, RayQueryContext* context, const void* primitive); public: struct Intersectors { Intersectors() {} // WARNING: Do not zero initialize this, as we otherwise get problems with thread unsafe local static variable initialization (e.g. on VS2013) in curve_intersector_virtual.cpp. - template<int K> void intersect(void* pre, void* ray, IntersectContext* context, const void* primitive); - template<int K> bool occluded (void* pre, void* ray, IntersectContext* context, const void* primitive); + template<int K> void intersect(void* pre, void* ray, RayQueryContext* context, const void* primitive); + template<int K> bool occluded (void* pre, void* ray, RayQueryContext* context, const void* primitive); - template<int K> void intersect(void* pre, void* ray, size_t k, IntersectContext* context, const void* primitive); - template<int K> bool occluded (void* pre, void* ray, size_t k, IntersectContext* context, const void* primitive); + template<int K> void intersect(void* pre, void* ray, size_t k, RayQueryContext* context, const void* primitive); + template<int K> bool occluded (void* pre, void* ray, size_t k, RayQueryContext* context, const void* primitive); public: Intersect1Ty intersect1; @@ -74,20 +74,20 @@ namespace embree Intersectors vtbl[Geometry::GTY_END]; }; - template<> __forceinline void VirtualCurveIntersector::Intersectors::intersect<1> (void* pre, void* ray, IntersectContext* context, const void* primitive) { assert(intersect1); intersect1(pre,ray,context,primitive); } - template<> __forceinline bool VirtualCurveIntersector::Intersectors::occluded<1> (void* pre, void* ray, IntersectContext* context, const void* primitive) { assert(occluded1); return occluded1(pre,ray,context,primitive); } + template<> __forceinline void VirtualCurveIntersector::Intersectors::intersect<1> (void* pre, void* ray, RayQueryContext* context, const void* primitive) { assert(intersect1); intersect1(pre,ray,context,primitive); } + template<> __forceinline bool VirtualCurveIntersector::Intersectors::occluded<1> (void* pre, void* ray, RayQueryContext* context, const void* primitive) { assert(occluded1); return occluded1(pre,ray,context,primitive); } - template<> __forceinline void VirtualCurveIntersector::Intersectors::intersect<4>(void* pre, void* ray, size_t k, IntersectContext* context, const void* primitive) { assert(intersect4); intersect4(pre,ray,k,context,primitive); } - template<> __forceinline bool VirtualCurveIntersector::Intersectors::occluded<4> (void* pre, void* ray, size_t k, IntersectContext* context, const void* primitive) { assert(occluded4); return occluded4(pre,ray,k,context,primitive); } + template<> __forceinline void VirtualCurveIntersector::Intersectors::intersect<4>(void* pre, void* ray, size_t k, RayQueryContext* context, const void* primitive) { assert(intersect4); intersect4(pre,ray,k,context,primitive); } + template<> __forceinline bool VirtualCurveIntersector::Intersectors::occluded<4> (void* pre, void* ray, size_t k, RayQueryContext* context, const void* primitive) { assert(occluded4); return occluded4(pre,ray,k,context,primitive); } #if defined(__AVX__) - template<> __forceinline void VirtualCurveIntersector::Intersectors::intersect<8>(void* pre, void* ray, size_t k, IntersectContext* context, const void* primitive) { assert(intersect8); intersect8(pre,ray,k,context,primitive); } - template<> __forceinline bool VirtualCurveIntersector::Intersectors::occluded<8> (void* pre, void* ray, size_t k, IntersectContext* context, const void* primitive) { assert(occluded8); return occluded8(pre,ray,k,context,primitive); } + template<> __forceinline void VirtualCurveIntersector::Intersectors::intersect<8>(void* pre, void* ray, size_t k, RayQueryContext* context, const void* primitive) { assert(intersect8); intersect8(pre,ray,k,context,primitive); } + template<> __forceinline bool VirtualCurveIntersector::Intersectors::occluded<8> (void* pre, void* ray, size_t k, RayQueryContext* context, const void* primitive) { assert(occluded8); return occluded8(pre,ray,k,context,primitive); } #endif #if defined(__AVX512F__) - template<> __forceinline void VirtualCurveIntersector::Intersectors::intersect<16>(void* pre, void* ray, size_t k, IntersectContext* context, const void* primitive) { assert(intersect16); intersect16(pre,ray,k,context,primitive); } - template<> __forceinline bool VirtualCurveIntersector::Intersectors::occluded<16> (void* pre, void* ray, size_t k, IntersectContext* context, const void* primitive) { assert(occluded16); return occluded16(pre,ray,k,context,primitive); } + template<> __forceinline void VirtualCurveIntersector::Intersectors::intersect<16>(void* pre, void* ray, size_t k, RayQueryContext* context, const void* primitive) { assert(intersect16); intersect16(pre,ray,k,context,primitive); } + template<> __forceinline bool VirtualCurveIntersector::Intersectors::occluded<16> (void* pre, void* ray, size_t k, RayQueryContext* context, const void* primitive) { assert(occluded16); return occluded16(pre,ray,k,context,primitive); } #endif namespace isa @@ -98,7 +98,7 @@ namespace embree typedef CurvePrecalculations1 Precalculations; template<int N, bool robust> - static __forceinline void intersect(const Accel::Intersectors* This, Precalculations& pre, RayHit& ray, IntersectContext* context, const Primitive* prim, size_t num, const TravRay<N,robust> &tray, size_t& lazy_node) + static __forceinline void intersect(const Accel::Intersectors* This, Precalculations& pre, RayHit& ray, RayQueryContext* context, const Primitive* prim, size_t num, const TravRay<N,robust> &tray, size_t& lazy_node) { assert(num == 1); RTCGeometryType ty = (RTCGeometryType)(*prim); @@ -108,7 +108,7 @@ namespace embree } template<int N, bool robust> - static __forceinline bool occluded(const Accel::Intersectors* This, Precalculations& pre, Ray& ray, IntersectContext* context, const Primitive* prim, size_t num, const TravRay<N,robust> &tray, size_t& lazy_node) + static __forceinline bool occluded(const Accel::Intersectors* This, Precalculations& pre, Ray& ray, RayQueryContext* context, const Primitive* prim, size_t num, const TravRay<N,robust> &tray, size_t& lazy_node) { assert(num == 1); RTCGeometryType ty = (RTCGeometryType)(*prim); @@ -125,7 +125,7 @@ namespace embree typedef CurvePrecalculationsK<K> Precalculations; template<bool robust> - static __forceinline void intersect(const vbool<K>& valid_i, const Accel::Intersectors* This, Precalculations& pre, RayHitK<K>& ray, IntersectContext* context, const Primitive* prim, size_t num, const TravRayK<K, robust> &tray, size_t& lazy_node) + static __forceinline void intersect(const vbool<K>& valid_i, const Accel::Intersectors* This, Precalculations& pre, RayHitK<K>& ray, RayQueryContext* context, const Primitive* prim, size_t num, const TravRayK<K, robust> &tray, size_t& lazy_node) { assert(num == 1); RTCGeometryType ty = (RTCGeometryType)(*prim); @@ -136,7 +136,7 @@ namespace embree } template<bool robust> - static __forceinline vbool<K> occluded(const vbool<K>& valid_i, const Accel::Intersectors* This, Precalculations& pre, RayK<K>& ray, IntersectContext* context, const Primitive* prim, size_t num, const TravRayK<K, robust> &tray, size_t& lazy_node) + static __forceinline vbool<K> occluded(const vbool<K>& valid_i, const Accel::Intersectors* This, Precalculations& pre, RayK<K>& ray, RayQueryContext* context, const Primitive* prim, size_t num, const TravRayK<K, robust> &tray, size_t& lazy_node) { assert(num == 1); RTCGeometryType ty = (RTCGeometryType)(*prim); @@ -153,7 +153,7 @@ namespace embree } template<int N, bool robust> - static __forceinline void intersect(const Accel::Intersectors* This, Precalculations& pre, RayHitK<K>& ray, size_t k, IntersectContext* context, const Primitive* prim, size_t num, const TravRay<N,robust> &tray, size_t& lazy_node) + static __forceinline void intersect(const Accel::Intersectors* This, Precalculations& pre, RayHitK<K>& ray, size_t k, RayQueryContext* context, const Primitive* prim, size_t num, const TravRay<N,robust> &tray, size_t& lazy_node) { assert(num == 1); RTCGeometryType ty = (RTCGeometryType)(*prim); @@ -163,7 +163,7 @@ namespace embree } template<int N, bool robust> - static __forceinline bool occluded(const Accel::Intersectors* This, Precalculations& pre, RayK<K>& ray, size_t k, IntersectContext* context, const Primitive* prim, size_t num, const TravRay<N,robust> &tray, size_t& lazy_node) + static __forceinline bool occluded(const Accel::Intersectors* This, Precalculations& pre, RayK<K>& ray, size_t k, RayQueryContext* context, const Primitive* prim, size_t num, const TravRay<N,robust> &tray, size_t& lazy_node) { assert(num == 1); RTCGeometryType ty = (RTCGeometryType)(*prim); diff --git a/thirdparty/embree/kernels/geometry/disc_intersector.h b/thirdparty/embree/kernels/geometry/disc_intersector.h index ec6fa9c4f3..2997d36202 100644 --- a/thirdparty/embree/kernels/geometry/disc_intersector.h +++ b/thirdparty/embree/kernels/geometry/disc_intersector.h @@ -23,18 +23,24 @@ namespace embree __forceinline void finalize() {} - __forceinline Vec2f uv(const size_t i) const - { + __forceinline Vec2f uv(const size_t i) const { return Vec2f(vu[i], vv[i]); } - __forceinline float t(const size_t i) const - { + __forceinline Vec2vf<M> uv() const { + return Vec2vf<M>(vu, vv); + } + __forceinline float t(const size_t i) const { return vt[i]; } - __forceinline Vec3fa Ng(const size_t i) const - { + __forceinline vfloat<M> t() const { + return vt; + } + __forceinline Vec3fa Ng(const size_t i) const { return Vec3fa(vNg.x[i], vNg.y[i], vNg.z[i]); } + __forceinline Vec3vf<M> Ng() const { + return vNg; + } public: vfloat<M> vu; @@ -43,16 +49,45 @@ namespace embree Vec3vf<M> vNg; }; + template<> + struct DiscIntersectorHitM<1> + { + __forceinline DiscIntersectorHitM() {} + + __forceinline DiscIntersectorHitM(const float& u, const float& v, const float& t, const Vec3fa& Ng) + : vu(u), vv(v), vt(t), vNg(Ng) {} + + __forceinline void finalize() {} + + __forceinline Vec2f uv() const { + return Vec2f(vu, vv); + } + + __forceinline float t() const { + return vt; + } + + __forceinline Vec3fa Ng() const { + return vNg; + } + + public: + float vu; + float vv; + float vt; + Vec3fa vNg; + }; + template<int M> struct DiscIntersector1 { typedef CurvePrecalculations1 Precalculations; - template<typename Epilog> + template<typename Ray, typename Epilog> static __forceinline bool intersect( const vbool<M>& valid_i, Ray& ray, - IntersectContext* context, + RayQueryContext* context, const Points* geom, const Precalculations& pre, const Vec4vf<M>& v0i, @@ -97,10 +132,10 @@ namespace embree return epilog(valid, hit); } - template<typename Epilog> + template<typename Ray, typename Epilog> static __forceinline bool intersect(const vbool<M>& valid_i, Ray& ray, - IntersectContext* context, + RayQueryContext* context, const Points* geom, const Precalculations& pre, const Vec4vf<M>& v0i, @@ -145,7 +180,7 @@ namespace embree static __forceinline bool intersect(const vbool<M>& valid_i, RayK<K>& ray, size_t k, - IntersectContext* context, + RayQueryContext* context, const Points* geom, const Precalculations& pre, const Vec4vf<M>& v0i, @@ -194,7 +229,7 @@ namespace embree static __forceinline bool intersect(const vbool<M>& valid_i, RayK<K>& ray, size_t k, - IntersectContext* context, + RayQueryContext* context, const Points* geom, const Precalculations& pre, const Vec4vf<M>& v0i, diff --git a/thirdparty/embree/kernels/geometry/disci_intersector.h b/thirdparty/embree/kernels/geometry/disci_intersector.h index bb9d396f6e..1ae4a66330 100644 --- a/thirdparty/embree/kernels/geometry/disci_intersector.h +++ b/thirdparty/embree/kernels/geometry/disci_intersector.h @@ -19,7 +19,7 @@ namespace embree static __forceinline void intersect(const Precalculations& pre, RayHit& ray, - IntersectContext* context, + RayQueryContext* context, const Primitive& Disc) { STAT3(normal.trav_prims, 1, 1, 1); @@ -32,7 +32,7 @@ namespace embree static __forceinline bool occluded(const Precalculations& pre, Ray& ray, - IntersectContext* context, + RayQueryContext* context, const Primitive& Disc) { STAT3(shadow.trav_prims, 1, 1, 1); @@ -52,7 +52,7 @@ namespace embree static __forceinline void intersect(const Precalculations& pre, RayHit& ray, - IntersectContext* context, + RayQueryContext* context, const Primitive& Disc) { STAT3(normal.trav_prims, 1, 1, 1); @@ -65,7 +65,7 @@ namespace embree static __forceinline bool occluded(const Precalculations& pre, Ray& ray, - IntersectContext* context, + RayQueryContext* context, const Primitive& Disc) { STAT3(shadow.trav_prims, 1, 1, 1); @@ -84,7 +84,7 @@ namespace embree typedef CurvePrecalculationsK<K> Precalculations; static __forceinline void intersect( - const Precalculations& pre, RayHitK<K>& ray, size_t k, IntersectContext* context, const Primitive& Disc) + const Precalculations& pre, RayHitK<K>& ray, size_t k, RayQueryContext* context, const Primitive& Disc) { STAT3(normal.trav_prims, 1, 1, 1); const Points* geom = context->scene->get<Points>(Disc.geomID()); @@ -96,7 +96,7 @@ namespace embree } static __forceinline bool occluded( - const Precalculations& pre, RayK<K>& ray, size_t k, IntersectContext* context, const Primitive& Disc) + const Precalculations& pre, RayK<K>& ray, size_t k, RayQueryContext* context, const Primitive& Disc) { STAT3(shadow.trav_prims, 1, 1, 1); const Points* geom = context->scene->get<Points>(Disc.geomID()); @@ -115,7 +115,7 @@ namespace embree typedef CurvePrecalculationsK<K> Precalculations; static __forceinline void intersect( - const Precalculations& pre, RayHitK<K>& ray, size_t k, IntersectContext* context, const Primitive& Disc) + const Precalculations& pre, RayHitK<K>& ray, size_t k, RayQueryContext* context, const Primitive& Disc) { STAT3(normal.trav_prims, 1, 1, 1); const Points* geom = context->scene->get<Points>(Disc.geomID()); @@ -127,7 +127,7 @@ namespace embree } static __forceinline bool occluded( - const Precalculations& pre, RayK<K>& ray, size_t k, IntersectContext* context, const Primitive& Disc) + const Precalculations& pre, RayK<K>& ray, size_t k, RayQueryContext* context, const Primitive& Disc) { STAT3(shadow.trav_prims, 1, 1, 1); const Points* geom = context->scene->get<Points>(Disc.geomID()); @@ -146,7 +146,7 @@ namespace embree static __forceinline void intersect(const Precalculations& pre, RayHit& ray, - IntersectContext* context, + RayQueryContext* context, const Primitive& Disc) { STAT3(normal.trav_prims, 1, 1, 1); @@ -160,7 +160,7 @@ namespace embree static __forceinline bool occluded(const Precalculations& pre, Ray& ray, - IntersectContext* context, + RayQueryContext* context, const Primitive& Disc) { STAT3(shadow.trav_prims, 1, 1, 1); @@ -181,7 +181,7 @@ namespace embree static __forceinline void intersect(const Precalculations& pre, RayHit& ray, - IntersectContext* context, + RayQueryContext* context, const Primitive& Disc) { STAT3(normal.trav_prims, 1, 1, 1); @@ -195,7 +195,7 @@ namespace embree static __forceinline bool occluded(const Precalculations& pre, Ray& ray, - IntersectContext* context, + RayQueryContext* context, const Primitive& Disc) { STAT3(shadow.trav_prims, 1, 1, 1); @@ -215,7 +215,7 @@ namespace embree typedef CurvePrecalculationsK<K> Precalculations; static __forceinline void intersect( - const Precalculations& pre, RayHitK<K>& ray, size_t k, IntersectContext* context, const Primitive& Disc) + const Precalculations& pre, RayHitK<K>& ray, size_t k, RayQueryContext* context, const Primitive& Disc) { STAT3(normal.trav_prims, 1, 1, 1); const Points* geom = context->scene->get<Points>(Disc.geomID()); @@ -228,7 +228,7 @@ namespace embree } static __forceinline bool occluded( - const Precalculations& pre, RayK<K>& ray, size_t k, IntersectContext* context, const Primitive& Disc) + const Precalculations& pre, RayK<K>& ray, size_t k, RayQueryContext* context, const Primitive& Disc) { STAT3(shadow.trav_prims, 1, 1, 1); const Points* geom = context->scene->get<Points>(Disc.geomID()); @@ -248,7 +248,7 @@ namespace embree typedef CurvePrecalculationsK<K> Precalculations; static __forceinline void intersect( - const Precalculations& pre, RayHitK<K>& ray, size_t k, IntersectContext* context, const Primitive& Disc) + const Precalculations& pre, RayHitK<K>& ray, size_t k, RayQueryContext* context, const Primitive& Disc) { STAT3(normal.trav_prims, 1, 1, 1); const Points* geom = context->scene->get<Points>(Disc.geomID()); @@ -261,7 +261,7 @@ namespace embree } static __forceinline bool occluded( - const Precalculations& pre, RayK<K>& ray, size_t k, IntersectContext* context, const Primitive& Disc) + const Precalculations& pre, RayK<K>& ray, size_t k, RayQueryContext* context, const Primitive& Disc) { STAT3(shadow.trav_prims, 1, 1, 1); const Points* geom = context->scene->get<Points>(Disc.geomID()); diff --git a/thirdparty/embree/kernels/geometry/filter.h b/thirdparty/embree/kernels/geometry/filter.h index d64320bf78..773c2bfeb8 100644 --- a/thirdparty/embree/kernels/geometry/filter.h +++ b/thirdparty/embree/kernels/geometry/filter.h @@ -12,20 +12,20 @@ namespace embree { namespace isa { - __forceinline bool runIntersectionFilter1Helper(RTCFilterFunctionNArguments* args, const Geometry* const geometry, IntersectContext* context) + __forceinline bool runIntersectionFilter1Helper(RTCFilterFunctionNArguments* args, const Geometry* const geometry, RayQueryContext* context) { if (geometry->intersectionFilterN) { - assert(context->scene->hasGeometryFilterFunction()); geometry->intersectionFilterN(args); if (args->valid[0] == 0) return false; } - - if (context->user->filter) { - assert(context->scene->hasContextFilterFunction()); - context->user->filter(args); + + if (context->getFilter()) + { + if (context->enforceArgumentFilterFunction() || geometry->hasArgumentFilterFunctions()) + context->getFilter()(args); if (args->valid[0] == 0) return false; @@ -35,7 +35,7 @@ namespace embree return true; } - __forceinline bool runIntersectionFilter1(const Geometry* const geometry, RayHit& ray, IntersectContext* context, Hit& hit) + __forceinline bool runIntersectionFilter1(const Geometry* const geometry, RayHit& ray, RayQueryContext* context, Hit& hit) { RTCFilterFunctionNArguments args; int mask = -1; @@ -48,39 +48,29 @@ namespace embree return runIntersectionFilter1Helper(&args,geometry,context); } - __forceinline void reportIntersection1(IntersectFunctionNArguments* args, const RTCFilterFunctionNArguments* filter_args) - { -#if defined(EMBREE_FILTER_FUNCTION) - if (args->geometry->intersectionFilterN) - args->geometry->intersectionFilterN(filter_args); - - if (args->context->filter) - args->context->filter(filter_args); -#endif - } - - __forceinline bool runOcclusionFilter1Helper(RTCFilterFunctionNArguments* args, const Geometry* const geometry, IntersectContext* context) + __forceinline bool runOcclusionFilter1Helper(RTCFilterFunctionNArguments* args, const Geometry* const geometry, RayQueryContext* context) { if (geometry->occlusionFilterN) { - assert(context->scene->hasGeometryFilterFunction()); geometry->occlusionFilterN(args); if (args->valid[0] == 0) return false; } - - if (context->user->filter) { - assert(context->scene->hasContextFilterFunction()); - context->user->filter(args); + + if (context->getFilter()) + { + if (context->enforceArgumentFilterFunction() || geometry->hasArgumentFilterFunctions()) + context->getFilter()(args); if (args->valid[0] == 0) return false; } + return true; } - __forceinline bool runOcclusionFilter1(const Geometry* const geometry, Ray& ray, IntersectContext* context, Hit& hit) + __forceinline bool runOcclusionFilter1(const Geometry* const geometry, Ray& ray, RayQueryContext* context, Hit& hit) { RTCFilterFunctionNArguments args; int mask = -1; @@ -93,33 +83,19 @@ namespace embree return runOcclusionFilter1Helper(&args,geometry,context); } - __forceinline void reportOcclusion1(OccludedFunctionNArguments* args, const RTCFilterFunctionNArguments* filter_args) - { -#if defined(EMBREE_FILTER_FUNCTION) - if (args->geometry->occlusionFilterN) - args->geometry->occlusionFilterN(filter_args); - - if (args->context->filter) - args->context->filter(filter_args); -#endif - } - template<int K> - __forceinline vbool<K> runIntersectionFilterHelper(RTCFilterFunctionNArguments* args, const Geometry* const geometry, IntersectContext* context) + __forceinline vbool<K> runIntersectionFilterHelper(RTCFilterFunctionNArguments* args, const Geometry* const geometry, RayQueryContext* context) { vint<K>* mask = (vint<K>*) args->valid; if (geometry->intersectionFilterN) - { - assert(context->scene->hasGeometryFilterFunction()); geometry->intersectionFilterN(args); - } - + vbool<K> valid_o = *mask != vint<K>(zero); if (none(valid_o)) return valid_o; - if (context->user->filter) { - assert(context->scene->hasContextFilterFunction()); - context->user->filter(args); + if (context->getFilter()) { + if (context->enforceArgumentFilterFunction() || geometry->hasArgumentFilterFunctions()) + context->getFilter()(args); } valid_o = *mask != vint<K>(zero); @@ -130,7 +106,7 @@ namespace embree } template<int K> - __forceinline vbool<K> runIntersectionFilter(const vbool<K>& valid, const Geometry* const geometry, RayHitK<K>& ray, IntersectContext* context, HitK<K>& hit) + __forceinline vbool<K> runIntersectionFilter(const vbool<K>& valid, const Geometry* const geometry, RayHitK<K>& ray, RayQueryContext* context, HitK<K>& hit) { RTCFilterFunctionNArguments args; vint<K> mask = valid.mask32(); @@ -144,24 +120,19 @@ namespace embree } template<int K> - __forceinline vbool<K> runOcclusionFilterHelper(RTCFilterFunctionNArguments* args, const Geometry* const geometry, IntersectContext* context) + __forceinline vbool<K> runOcclusionFilterHelper(RTCFilterFunctionNArguments* args, const Geometry* const geometry, RayQueryContext* context) { vint<K>* mask = (vint<K>*) args->valid; if (geometry->occlusionFilterN) - { - assert(context->scene->hasGeometryFilterFunction()); geometry->occlusionFilterN(args); - } - - vbool<K> valid_o = *mask != vint<K>(zero); + vbool<K> valid_o = *mask != vint<K>(zero); if (none(valid_o)) return valid_o; - if (context->user->filter) { - assert(context->scene->hasContextFilterFunction()); - context->user->filter(args); + if (context->getFilter()) { + if (context->enforceArgumentFilterFunction() || geometry->hasArgumentFilterFunctions()) + context->getFilter()(args); } - valid_o = *mask != vint<K>(zero); RayK<K>* ray = (RayK<K>*) args->ray; @@ -170,7 +141,7 @@ namespace embree } template<int K> - __forceinline vbool<K> runOcclusionFilter(const vbool<K>& valid, const Geometry* const geometry, RayK<K>& ray, IntersectContext* context, HitK<K>& hit) + __forceinline vbool<K> runOcclusionFilter(const vbool<K>& valid, const Geometry* const geometry, RayK<K>& ray, RayQueryContext* context, HitK<K>& hit) { RTCFilterFunctionNArguments args; vint<K> mask = valid.mask32(); diff --git a/thirdparty/embree/kernels/geometry/filter_sycl.h b/thirdparty/embree/kernels/geometry/filter_sycl.h new file mode 100644 index 0000000000..00f333134b --- /dev/null +++ b/thirdparty/embree/kernels/geometry/filter_sycl.h @@ -0,0 +1,109 @@ +// Copyright 2009-2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include "../common/geometry.h" +#include "../common/ray.h" +#include "../common/hit.h" +#include "../common/context.h" + +namespace embree +{ + __forceinline bool runIntersectionFilter1Helper(RTCFilterFunctionNArguments* args, int& mask, const Geometry* const geometry, RayQueryContext* context) + { + typedef void (*RTCFilterFunctionSYCL)(const void* args); + const RTCFeatureFlags feature_mask MAYBE_UNUSED = context->args->feature_mask; + +#if EMBREE_SYCL_GEOMETRY_CALLBACK + if (feature_mask & RTC_FEATURE_FLAG_FILTER_FUNCTION_IN_GEOMETRY) + { + RTCFilterFunctionSYCL gfilter = (RTCFilterFunctionSYCL) geometry->intersectionFilterN; + if (gfilter) + { + gfilter(args); + + if (mask == 0) + return false; + } + } +#endif + + if (feature_mask & RTC_FEATURE_FLAG_FILTER_FUNCTION_IN_ARGUMENTS) + { + RTCFilterFunctionSYCL cfilter = (RTCFilterFunctionSYCL) context->args->filter; + if (cfilter) + { + if (context->enforceArgumentFilterFunction() || geometry->hasArgumentFilterFunctions()) + cfilter(args); + + if (mask == 0) + return false; + } + } + + return true; + } + + __forceinline bool runOcclusionFilter1Helper(RTCFilterFunctionNArguments* args, int& mask, const Geometry* const geometry, RayQueryContext* context) + { + typedef void (*RTCFilterFunctionSYCL)(const void* args); + const RTCFeatureFlags feature_mask MAYBE_UNUSED = context->args->feature_mask; + +#if EMBREE_SYCL_GEOMETRY_CALLBACK + if (feature_mask & RTC_FEATURE_FLAG_FILTER_FUNCTION_IN_GEOMETRY) + { + RTCFilterFunctionSYCL gfilter = (RTCFilterFunctionSYCL) geometry->occlusionFilterN; + if (gfilter) + { + gfilter(args); + + if (mask == 0) + return false; + } + } +#endif + + if (feature_mask & RTC_FEATURE_FLAG_FILTER_FUNCTION_IN_ARGUMENTS) + { + RTCFilterFunctionSYCL cfilter = (RTCFilterFunctionSYCL) context->args->filter; + if (cfilter) + { + if (context->enforceArgumentFilterFunction() || geometry->hasArgumentFilterFunctions()) + cfilter(args); + + if (mask == 0) + return false; + } + } + + return true; + } + + __forceinline bool runIntersectionFilter1SYCL(Geometry* geometry, RayHit& ray, sycl::private_ptr<RayQueryContext> context, Hit& hit) + { + RTCFilterFunctionNArguments args; + int mask = -1; + args.valid = &mask; + args.geometryUserPtr = geometry->userPtr; + args.context = context->user; + args.ray = (RTCRayN*) &ray; + args.hit = (RTCHitN*) &hit; + args.N = 1; + return runIntersectionFilter1Helper(&args,mask,geometry,context); + } + + + __forceinline bool runIntersectionFilter1SYCL(Geometry* geometry, Ray& ray, sycl::private_ptr<RayQueryContext> context, Hit& hit) + { + RTCFilterFunctionNArguments args; + int mask = -1; + args.valid = &mask; + args.geometryUserPtr = geometry->userPtr; + args.context = context->user; + args.ray = (RTCRayN*) &ray; + args.hit = (RTCHitN*) &hit; + args.N = 1; + return runOcclusionFilter1Helper(&args,mask,geometry,context); + } +} diff --git a/thirdparty/embree/kernels/geometry/grid_intersector.h b/thirdparty/embree/kernels/geometry/grid_intersector.h index 9c59cef119..9837205445 100644 --- a/thirdparty/embree/kernels/geometry/grid_intersector.h +++ b/thirdparty/embree/kernels/geometry/grid_intersector.h @@ -35,20 +35,20 @@ namespace embree typedef Grid1Precalculations<GridSOAIntersector1::Precalculations> Precalculations; /*! Intersect a ray with the primitive. */ - static __forceinline void intersect(Precalculations& pre, RayHit& ray, IntersectContext* context, const Primitive* prim, size_t ty, size_t& lazy_node) + static __forceinline void intersect(Precalculations& pre, RayHit& ray, RayQueryContext* context, const Primitive* prim, size_t ty, size_t& lazy_node) { GridSOAIntersector1::intersect(pre,ray,context,prim,lazy_node); } - static __forceinline void intersect(Precalculations& pre, RayHit& ray, IntersectContext* context, size_t ty0, const Primitive* prim, size_t ty, size_t& lazy_node) { + static __forceinline void intersect(Precalculations& pre, RayHit& ray, RayQueryContext* context, size_t ty0, const Primitive* prim, size_t ty, size_t& lazy_node) { intersect(pre,ray,context,prim,ty,lazy_node); } /*! Test if the ray is occluded by the primitive */ - static __forceinline bool occluded(Precalculations& pre, Ray& ray, IntersectContext* context, const Primitive* prim, size_t ty, size_t& lazy_node) + static __forceinline bool occluded(Precalculations& pre, Ray& ray, RayQueryContext* context, const Primitive* prim, size_t ty, size_t& lazy_node) { GridSOAIntersector1::occluded(pre,ray,context,prim,lazy_node); } - static __forceinline bool occluded(Precalculations& pre, Ray& ray, IntersectContext* context, size_t ty0, const Primitive* prim, size_t ty, size_t& lazy_node) { + static __forceinline bool occluded(Precalculations& pre, Ray& ray, RayQueryContext* context, size_t ty0, const Primitive* prim, size_t ty, size_t& lazy_node) { return occluded(pre,ray,context,prim,ty,lazy_node); } @@ -70,22 +70,22 @@ namespace embree typedef SubdivPatch1PrecalculationsK<K,typename GridSOAIntersectorK<K>::Precalculations> Precalculations; - static __forceinline void intersect(const vbool<K>& valid, Precalculations& pre, RayHitK<K>& ray, IntersectContext* context, const Primitive* prim, size_t ty, size_t& lazy_node) + static __forceinline void intersect(const vbool<K>& valid, Precalculations& pre, RayHitK<K>& ray, RayQueryContext* context, const Primitive* prim, size_t ty, size_t& lazy_node) { GridSOAIntersectorK<K>::intersect(valid,pre,ray,context,prim,lazy_node); } - static __forceinline vbool<K> occluded(const vbool<K>& valid, Precalculations& pre, RayK<K>& ray, IntersectContext* context, const Primitive* prim, size_t ty, size_t& lazy_node) + static __forceinline vbool<K> occluded(const vbool<K>& valid, Precalculations& pre, RayK<K>& ray, RayQueryContext* context, const Primitive* prim, size_t ty, size_t& lazy_node) { GridSOAIntersectorK<K>::occluded(valid,pre,ray,context,prim,lazy_node); } - static __forceinline void intersect(Precalculations& pre, RayHitK<K>& ray, size_t k, IntersectContext* context, const Primitive* prim, size_t ty, size_t& lazy_node) + static __forceinline void intersect(Precalculations& pre, RayHitK<K>& ray, size_t k, RayQueryContext* context, const Primitive* prim, size_t ty, size_t& lazy_node) { GridSOAIntersectorK<K>::intersect(pre,ray,k,context,prim,lazy_node); } - static __forceinline bool occluded(Precalculations& pre, RayK<K>& ray, size_t k, IntersectContext* context, const Primitive* prim, size_t ty, size_t& lazy_node) + static __forceinline bool occluded(Precalculations& pre, RayK<K>& ray, size_t k, RayQueryContext* context, const Primitive* prim, size_t ty, size_t& lazy_node) { GridSOAIntersectorK<K>::occluded(pre,ray,k,context,prim,lazy_node); } diff --git a/thirdparty/embree/kernels/geometry/grid_soa_intersector1.h b/thirdparty/embree/kernels/geometry/grid_soa_intersector1.h index 8fbf0d4bdf..6d56bd0404 100644 --- a/thirdparty/embree/kernels/geometry/grid_soa_intersector1.h +++ b/thirdparty/embree/kernels/geometry/grid_soa_intersector1.h @@ -30,7 +30,7 @@ namespace embree template<typename Loader> static __forceinline void intersect(RayHit& ray, - IntersectContext* context, + RayQueryContext* context, const float* const grid_x, const size_t line_offset, const size_t lines, @@ -50,7 +50,7 @@ namespace embree template<typename Loader> static __forceinline bool occluded(Ray& ray, - IntersectContext* context, + RayQueryContext* context, const float* const grid_x, const size_t line_offset, const size_t lines, @@ -71,7 +71,7 @@ namespace embree } /*! Intersect a ray with the primitive. */ - static __forceinline void intersect(Precalculations& pre, RayHit& ray, IntersectContext* context, const Primitive* prim, size_t& lazy_node) + static __forceinline void intersect(Precalculations& pre, RayHit& ray, RayQueryContext* context, const Primitive* prim, size_t& lazy_node) { const size_t line_offset = pre.grid->width; const size_t lines = pre.grid->height; @@ -87,7 +87,7 @@ namespace embree } /*! Test if the ray is occluded by the primitive */ - static __forceinline bool occluded(Precalculations& pre, Ray& ray, IntersectContext* context, const Primitive* prim, size_t& lazy_node) + static __forceinline bool occluded(Precalculations& pre, Ray& ray, RayQueryContext* context, const Primitive* prim, size_t& lazy_node) { const size_t line_offset = pre.grid->width; const size_t lines = pre.grid->height; @@ -112,7 +112,7 @@ namespace embree template<typename Loader> static __forceinline void intersect(RayHit& ray, const float ftime, - IntersectContext* context, + RayQueryContext* context, const float* const grid_x, const size_t line_offset, const size_t lines, @@ -142,7 +142,7 @@ namespace embree template<typename Loader> static __forceinline bool occluded(Ray& ray, const float ftime, - IntersectContext* context, + RayQueryContext* context, const float* const grid_x, const size_t line_offset, const size_t lines, @@ -171,7 +171,7 @@ namespace embree } /*! Intersect a ray with the primitive. */ - static __forceinline void intersect(Precalculations& pre, RayHit& ray, IntersectContext* context, const Primitive* prim, size_t& lazy_node) + static __forceinline void intersect(Precalculations& pre, RayHit& ray, RayQueryContext* context, const Primitive* prim, size_t& lazy_node) { const size_t line_offset = pre.grid->width; const size_t lines = pre.grid->height; @@ -187,7 +187,7 @@ namespace embree } /*! Test if the ray is occluded by the primitive */ - static __forceinline bool occluded(Precalculations& pre, Ray& ray, IntersectContext* context, const Primitive* prim, size_t& lazy_node) + static __forceinline bool occluded(Precalculations& pre, Ray& ray, RayQueryContext* context, const Primitive* prim, size_t& lazy_node) { const size_t line_offset = pre.grid->width; const size_t lines = pre.grid->height; diff --git a/thirdparty/embree/kernels/geometry/grid_soa_intersector_packet.h b/thirdparty/embree/kernels/geometry/grid_soa_intersector_packet.h index 14cacab5fe..5e5a24b7dd 100644 --- a/thirdparty/embree/kernels/geometry/grid_soa_intersector_packet.h +++ b/thirdparty/embree/kernels/geometry/grid_soa_intersector_packet.h @@ -79,7 +79,7 @@ namespace embree }; /*! Intersect a ray with the primitive. */ - static __forceinline void intersect(const vbool<K>& valid_i, Precalculations& pre, RayHitK<K>& ray, IntersectContext* context, const Primitive* prim, size_t& lazy_node) + static __forceinline void intersect(const vbool<K>& valid_i, Precalculations& pre, RayHitK<K>& ray, RayQueryContext* context, const Primitive* prim, size_t& lazy_node) { const size_t dim_offset = pre.grid->dim_offset; const size_t line_offset = pre.grid->width; @@ -110,7 +110,7 @@ namespace embree } /*! Test if the ray is occluded by the primitive */ - static __forceinline vbool<K> occluded(const vbool<K>& valid_i, Precalculations& pre, RayK<K>& ray, IntersectContext* context, const Primitive* prim, size_t& lazy_node) + static __forceinline vbool<K> occluded(const vbool<K>& valid_i, Precalculations& pre, RayK<K>& ray, RayQueryContext* context, const Primitive* prim, size_t& lazy_node) { const size_t dim_offset = pre.grid->dim_offset; const size_t line_offset = pre.grid->width; @@ -146,7 +146,7 @@ namespace embree template<typename Loader> static __forceinline void intersect(RayHitK<K>& ray, size_t k, - IntersectContext* context, + RayQueryContext* context, const float* const grid_x, const size_t line_offset, const size_t lines, @@ -163,7 +163,7 @@ namespace embree template<typename Loader> static __forceinline bool occluded(RayK<K>& ray, size_t k, - IntersectContext* context, + RayQueryContext* context, const float* const grid_x, const size_t line_offset, const size_t lines, @@ -179,7 +179,7 @@ namespace embree } /*! Intersect a ray with the primitive. */ - static __forceinline void intersect(Precalculations& pre, RayHitK<K>& ray, size_t k, IntersectContext* context, const Primitive* prim, size_t& lazy_node) + static __forceinline void intersect(Precalculations& pre, RayHitK<K>& ray, size_t k, RayQueryContext* context, const Primitive* prim, size_t& lazy_node) { const size_t line_offset = pre.grid->width; const size_t lines = pre.grid->height; @@ -194,7 +194,7 @@ namespace embree } /*! Test if the ray is occluded by the primitive */ - static __forceinline bool occluded(Precalculations& pre, RayK<K>& ray, size_t k, IntersectContext* context, const Primitive* prim, size_t& lazy_node) + static __forceinline bool occluded(Precalculations& pre, RayK<K>& ray, size_t k, RayQueryContext* context, const Primitive* prim, size_t& lazy_node) { const size_t line_offset = pre.grid->width; const size_t lines = pre.grid->height; @@ -219,7 +219,7 @@ namespace embree typedef typename GridSOAIntersectorK<K>::Precalculations Precalculations; /*! Intersect a ray with the primitive. */ - static __forceinline void intersect(const vbool<K>& valid_i, Precalculations& pre, RayHitK<K>& ray, IntersectContext* context, const Primitive* prim, size_t& lazy_node) + static __forceinline void intersect(const vbool<K>& valid_i, Precalculations& pre, RayHitK<K>& ray, RayQueryContext* context, const Primitive* prim, size_t& lazy_node) { vfloat<K> vftime; vint<K> vitime = getTimeSegment<K>(ray.time(), vfloat<K>((float)(pre.grid->time_steps-1)), vftime); @@ -235,7 +235,7 @@ namespace embree } /*! Intersect a ray with the primitive. */ - static __forceinline void intersect(const vbool<K>& valid_i, Precalculations& pre, RayHitK<K>& ray, const vfloat<K>& ftime, int itime, IntersectContext* context, const Primitive* prim, size_t& lazy_node) + static __forceinline void intersect(const vbool<K>& valid_i, Precalculations& pre, RayHitK<K>& ray, const vfloat<K>& ftime, int itime, RayQueryContext* context, const Primitive* prim, size_t& lazy_node) { const size_t grid_offset = pre.grid->gridBytes >> 2; const size_t dim_offset = pre.grid->dim_offset; @@ -279,7 +279,7 @@ namespace embree } /*! Test if the ray is occluded by the primitive */ - static __forceinline vbool<K> occluded(const vbool<K>& valid_i, Precalculations& pre, RayK<K>& ray, IntersectContext* context, const Primitive* prim, size_t& lazy_node) + static __forceinline vbool<K> occluded(const vbool<K>& valid_i, Precalculations& pre, RayK<K>& ray, RayQueryContext* context, const Primitive* prim, size_t& lazy_node) { vfloat<K> vftime; vint<K> vitime = getTimeSegment<K>(ray.time(), vfloat<K>((float)(pre.grid->time_steps-1)), vftime); @@ -297,7 +297,7 @@ namespace embree } /*! Test if the ray is occluded by the primitive */ - static __forceinline vbool<K> occluded(const vbool<K>& valid_i, Precalculations& pre, RayK<K>& ray, const vfloat<K>& ftime, int itime, IntersectContext* context, const Primitive* prim, size_t& lazy_node) + static __forceinline vbool<K> occluded(const vbool<K>& valid_i, Precalculations& pre, RayK<K>& ray, const vfloat<K>& ftime, int itime, RayQueryContext* context, const Primitive* prim, size_t& lazy_node) { const size_t grid_offset = pre.grid->gridBytes >> 2; const size_t dim_offset = pre.grid->dim_offset; @@ -347,7 +347,7 @@ namespace embree template<typename Loader> static __forceinline void intersect(RayHitK<K>& ray, size_t k, const float ftime, - IntersectContext* context, + RayQueryContext* context, const float* const grid_x, const size_t line_offset, const size_t lines, @@ -376,7 +376,7 @@ namespace embree template<typename Loader> static __forceinline bool occluded(RayK<K>& ray, size_t k, const float ftime, - IntersectContext* context, + RayQueryContext* context, const float* const grid_x, const size_t line_offset, const size_t lines, @@ -403,7 +403,7 @@ namespace embree } /*! Intersect a ray with the primitive. */ - static __forceinline void intersect(Precalculations& pre, RayHitK<K>& ray, size_t k, IntersectContext* context, const Primitive* prim, size_t& lazy_node) + static __forceinline void intersect(Precalculations& pre, RayHitK<K>& ray, size_t k, RayQueryContext* context, const Primitive* prim, size_t& lazy_node) { float ftime; int itime = getTimeSegment(ray.time()[k], float(pre.grid->time_steps-1), ftime); @@ -422,7 +422,7 @@ namespace embree } /*! Test if the ray is occluded by the primitive */ - static __forceinline bool occluded(Precalculations& pre, RayK<K>& ray, size_t k, IntersectContext* context, const Primitive* prim, size_t& lazy_node) + static __forceinline bool occluded(Precalculations& pre, RayK<K>& ray, size_t k, RayQueryContext* context, const Primitive* prim, size_t& lazy_node) { float ftime; int itime = getTimeSegment(ray.time()[k], float(pre.grid->time_steps-1), ftime); diff --git a/thirdparty/embree/kernels/geometry/instance_array.h b/thirdparty/embree/kernels/geometry/instance_array.h new file mode 100644 index 0000000000..fdbe79b3a8 --- /dev/null +++ b/thirdparty/embree/kernels/geometry/instance_array.h @@ -0,0 +1,85 @@ +// Copyright 2009-2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include "primitive.h" +#include "../common/scene_instance_array.h" + +namespace embree +{ + //template<int M> + struct InstanceArrayPrimitive + { + struct Type : public PrimitiveType + { + const char* name() const; + size_t sizeActive(const char* This) const; + size_t sizeTotal(const char* This) const; + size_t getBytes(const char* This) const; + }; + static Type type; + + public: + + /* primitive supports multiple time segments */ + static const bool singleTimeSegment = false; + + /* Returns maximum number of stored primitives */ + static __forceinline size_t max_size() { return 1; } + + /* Returns required number of primitive blocks for N primitives */ + static __forceinline size_t blocks(size_t N) { return N; } + + public: + + InstanceArrayPrimitive (const uint32_t geomID, const uint32_t primID) + : primID_(primID) + , instID_(geomID) + {} + + __forceinline bool valid() const { + return primID_ != -1; + } + + void fill(const PrimRef* prims, size_t& i, size_t end, Scene* scene) + { + assert(end-i == 1); + const PrimRef& prim = prims[i]; i++; + const unsigned int geomID = prim.geomID(); + const unsigned int primID = prim.primID(); + new (this) InstanceArrayPrimitive(geomID, primID); + } + + __forceinline LBBox3fa fillMB(const PrimRef* prims, size_t& i, size_t end, Scene* scene, size_t itime) + { + assert(end-i == 1); + const PrimRef& prim = prims[i]; i++; + const unsigned int geomID = prim.geomID(); + const size_t primID = prim.primID(); + new (this) InstanceArrayPrimitive(geomID, primID); + const InstanceArray* instanceArray = scene->get<InstanceArray>(geomID); + return instanceArray->linearBounds(primID,itime); + } + + __forceinline LBBox3fa fillMB(const PrimRefMB* prims, size_t& i, size_t end, Scene* scene, const BBox1f time_range) + { + assert(end-i == 1); + const PrimRefMB& prim = prims[i]; i++; + const unsigned int geomID = prim.geomID(); + const size_t primID = prim.primID(); + new (this) InstanceArrayPrimitive(geomID, primID); + const InstanceArray* instanceArray = scene->get<InstanceArray>(geomID); + return instanceArray->linearBounds(primID,time_range); + } + + /* Updates the primitive */ + __forceinline BBox3fa update(InstanceArray* instanceArray) { + return instanceArray->bounds(0); + } + + public: + unsigned int primID_; + unsigned int instID_; + }; +} diff --git a/thirdparty/embree/kernels/geometry/instance_array_intersector.h b/thirdparty/embree/kernels/geometry/instance_array_intersector.h new file mode 100644 index 0000000000..c32c8b4cde --- /dev/null +++ b/thirdparty/embree/kernels/geometry/instance_array_intersector.h @@ -0,0 +1,85 @@ +// Copyright 2009-2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include "instance_array.h" +#include "../common/ray.h" +#include "../common/point_query.h" +#include "../common/scene.h" + +namespace embree +{ + namespace isa + { + struct InstanceArrayIntersector1 + { + typedef InstanceArrayPrimitive Primitive; + + struct Precalculations { + __forceinline Precalculations (const Ray& ray, const void *ptr) {} + }; + + static void intersect(const Precalculations& pre, RayHit& ray, RayQueryContext* context, const Primitive& prim); + static bool occluded(const Precalculations& pre, Ray& ray, RayQueryContext* context, const Primitive& prim); + static bool pointQuery(PointQuery* query, PointQueryContext* context, const Primitive& prim); + }; + + struct InstanceArrayIntersector1MB + { + typedef InstanceArrayPrimitive Primitive; + + struct Precalculations { + __forceinline Precalculations (const Ray& ray, const void *ptr) {} + }; + + static void intersect(const Precalculations& pre, RayHit& ray, RayQueryContext* context, const Primitive& prim); + static bool occluded(const Precalculations& pre, Ray& ray, RayQueryContext* context, const Primitive& prim); + static bool pointQuery(PointQuery* query, PointQueryContext* context, const Primitive& prim); + }; + + template<int K> + struct InstanceArrayIntersectorK + { + typedef InstanceArrayPrimitive Primitive; + + struct Precalculations { + __forceinline Precalculations (const vbool<K>& valid, const RayK<K>& ray) {} + }; + + static void intersect(const vbool<K>& valid_i, const Precalculations& pre, RayHitK<K>& ray, RayQueryContext* context, const Primitive& prim); + static vbool<K> occluded(const vbool<K>& valid_i, const Precalculations& pre, RayK<K>& ray, RayQueryContext* context, const Primitive& prim); + + static __forceinline void intersect(Precalculations& pre, RayHitK<K>& ray, size_t k, RayQueryContext* context, const Primitive& prim) { + intersect(vbool<K>(1<<int(k)),pre,ray,context,prim); + } + + static __forceinline bool occluded(Precalculations& pre, RayK<K>& ray, size_t k, RayQueryContext* context, const Primitive& prim) { + occluded(vbool<K>(1<<int(k)),pre,ray,context,prim); + return ray.tfar[k] < 0.0f; + } + }; + + template<int K> + struct InstanceArrayIntersectorKMB + { + typedef InstanceArrayPrimitive Primitive; + + struct Precalculations { + __forceinline Precalculations (const vbool<K>& valid, const RayK<K>& ray) {} + }; + + static void intersect(const vbool<K>& valid_i, const Precalculations& pre, RayHitK<K>& ray, RayQueryContext* context, const Primitive& prim); + static vbool<K> occluded(const vbool<K>& valid_i, const Precalculations& pre, RayK<K>& ray, RayQueryContext* context, const Primitive& prim); + + static __forceinline void intersect(Precalculations& pre, RayHitK<K>& ray, size_t k, RayQueryContext* context, const Primitive& prim) { + intersect(vbool<K>(1<<int(k)),pre,ray,context,prim); + } + + static __forceinline bool occluded(Precalculations& pre, RayK<K>& ray, size_t k, RayQueryContext* context, const Primitive& prim) { + occluded(vbool<K>(1<<int(k)),pre,ray,context,prim); + return ray.tfar[k] < 0.0f; + } + }; + } +} diff --git a/thirdparty/embree/kernels/geometry/instance_intersector.h b/thirdparty/embree/kernels/geometry/instance_intersector.h index 28a7b728e5..45c3d36c2d 100644 --- a/thirdparty/embree/kernels/geometry/instance_intersector.h +++ b/thirdparty/embree/kernels/geometry/instance_intersector.h @@ -19,8 +19,8 @@ namespace embree __forceinline Precalculations (const Ray& ray, const void *ptr) {} }; - static void intersect(const Precalculations& pre, RayHit& ray, IntersectContext* context, const Primitive& prim); - static bool occluded(const Precalculations& pre, Ray& ray, IntersectContext* context, const Primitive& prim); + static void intersect(const Precalculations& pre, RayHit& ray, RayQueryContext* context, const Primitive& prim); + static bool occluded(const Precalculations& pre, Ray& ray, RayQueryContext* context, const Primitive& prim); static bool pointQuery(PointQuery* query, PointQueryContext* context, const Primitive& prim); }; @@ -32,8 +32,8 @@ namespace embree __forceinline Precalculations (const Ray& ray, const void *ptr) {} }; - static void intersect(const Precalculations& pre, RayHit& ray, IntersectContext* context, const Primitive& prim); - static bool occluded(const Precalculations& pre, Ray& ray, IntersectContext* context, const Primitive& prim); + static void intersect(const Precalculations& pre, RayHit& ray, RayQueryContext* context, const Primitive& prim); + static bool occluded(const Precalculations& pre, Ray& ray, RayQueryContext* context, const Primitive& prim); static bool pointQuery(PointQuery* query, PointQueryContext* context, const Primitive& prim); }; @@ -46,14 +46,14 @@ namespace embree __forceinline Precalculations (const vbool<K>& valid, const RayK<K>& ray) {} }; - static void intersect(const vbool<K>& valid_i, const Precalculations& pre, RayHitK<K>& ray, IntersectContext* context, const Primitive& prim); - static vbool<K> occluded(const vbool<K>& valid_i, const Precalculations& pre, RayK<K>& ray, IntersectContext* context, const Primitive& prim); + static void intersect(const vbool<K>& valid_i, const Precalculations& pre, RayHitK<K>& ray, RayQueryContext* context, const Primitive& prim); + static vbool<K> occluded(const vbool<K>& valid_i, const Precalculations& pre, RayK<K>& ray, RayQueryContext* context, const Primitive& prim); - static __forceinline void intersect(Precalculations& pre, RayHitK<K>& ray, size_t k, IntersectContext* context, const Primitive& prim) { + static __forceinline void intersect(Precalculations& pre, RayHitK<K>& ray, size_t k, RayQueryContext* context, const Primitive& prim) { intersect(vbool<K>(1<<int(k)),pre,ray,context,prim); } - static __forceinline bool occluded(Precalculations& pre, RayK<K>& ray, size_t k, IntersectContext* context, const Primitive& prim) { + static __forceinline bool occluded(Precalculations& pre, RayK<K>& ray, size_t k, RayQueryContext* context, const Primitive& prim) { occluded(vbool<K>(1<<int(k)),pre,ray,context,prim); return ray.tfar[k] < 0.0f; } @@ -68,14 +68,14 @@ namespace embree __forceinline Precalculations (const vbool<K>& valid, const RayK<K>& ray) {} }; - static void intersect(const vbool<K>& valid_i, const Precalculations& pre, RayHitK<K>& ray, IntersectContext* context, const Primitive& prim); - static vbool<K> occluded(const vbool<K>& valid_i, const Precalculations& pre, RayK<K>& ray, IntersectContext* context, const Primitive& prim); + static void intersect(const vbool<K>& valid_i, const Precalculations& pre, RayHitK<K>& ray, RayQueryContext* context, const Primitive& prim); + static vbool<K> occluded(const vbool<K>& valid_i, const Precalculations& pre, RayK<K>& ray, RayQueryContext* context, const Primitive& prim); - static __forceinline void intersect(Precalculations& pre, RayHitK<K>& ray, size_t k, IntersectContext* context, const Primitive& prim) { + static __forceinline void intersect(Precalculations& pre, RayHitK<K>& ray, size_t k, RayQueryContext* context, const Primitive& prim) { intersect(vbool<K>(1<<int(k)),pre,ray,context,prim); } - static __forceinline bool occluded(Precalculations& pre, RayK<K>& ray, size_t k, IntersectContext* context, const Primitive& prim) { + static __forceinline bool occluded(Precalculations& pre, RayK<K>& ray, size_t k, RayQueryContext* context, const Primitive& prim) { occluded(vbool<K>(1<<int(k)),pre,ray,context,prim); return ray.tfar[k] < 0.0f; } diff --git a/thirdparty/embree/kernels/geometry/intersector_epilog.h b/thirdparty/embree/kernels/geometry/intersector_epilog.h index 7bf134cc54..af85b0e57d 100644 --- a/thirdparty/embree/kernels/geometry/intersector_epilog.h +++ b/thirdparty/embree/kernels/geometry/intersector_epilog.h @@ -21,12 +21,12 @@ namespace embree struct Intersect1Epilog1 { RayHit& ray; - IntersectContext* context; + RayQueryContext* context; const unsigned int geomID; const unsigned int primID; __forceinline Intersect1Epilog1(RayHit& ray, - IntersectContext* context, + RayQueryContext* context, const unsigned int geomID, const unsigned int primID) : ray(ray), context(context), geomID(geomID), primID(primID) {} @@ -64,6 +64,9 @@ namespace embree ray.primID = primID; ray.geomID = geomID; instance_id_stack::copy_UU(context->user->instID, ray.instID); +#if defined(RTC_GEOMETRY_INSTANCE_ARRAY) + instance_id_stack::copy_UU(context->user->instPrimID, ray.instPrimID); +#endif return true; } }; @@ -72,12 +75,12 @@ namespace embree struct Occluded1Epilog1 { Ray& ray; - IntersectContext* context; + RayQueryContext* context; const unsigned int geomID; const unsigned int primID; __forceinline Occluded1Epilog1(Ray& ray, - IntersectContext* context, + RayQueryContext* context, const unsigned int geomID, const unsigned int primID) : ray(ray), context(context), geomID(geomID), primID(primID) {} @@ -117,12 +120,12 @@ namespace embree { RayHitK<K>& ray; size_t k; - IntersectContext* context; + RayQueryContext* context; const unsigned int geomID; const unsigned int primID; __forceinline Intersect1KEpilog1(RayHitK<K>& ray, size_t k, - IntersectContext* context, + RayQueryContext* context, const unsigned int geomID, const unsigned int primID) : ray(ray), k(k), context(context), geomID(geomID), primID(primID) {} @@ -163,6 +166,9 @@ namespace embree ray.primID[k] = primID; ray.geomID[k] = geomID; instance_id_stack::copy_UV<K>(context->user->instID, ray.instID, k); +#if defined(RTC_GEOMETRY_INSTANCE_ARRAY) + instance_id_stack::copy_UV<K>(context->user->instPrimID, ray.instPrimID, k); +#endif return true; } }; @@ -172,12 +178,12 @@ namespace embree { RayK<K>& ray; size_t k; - IntersectContext* context; + RayQueryContext* context; const unsigned int geomID; const unsigned int primID; __forceinline Occluded1KEpilog1(RayK<K>& ray, size_t k, - IntersectContext* context, + RayQueryContext* context, const unsigned int geomID, const unsigned int primID) : ray(ray), k(k), context(context), geomID(geomID), primID(primID) {} @@ -215,12 +221,12 @@ namespace embree struct Intersect1EpilogM { RayHit& ray; - IntersectContext* context; + RayQueryContext* context; const vuint<M>& geomIDs; const vuint<M>& primIDs; __forceinline Intersect1EpilogM(RayHit& ray, - IntersectContext* context, + RayQueryContext* context, const vuint<M>& geomIDs, const vuint<M>& primIDs) : ray(ray), context(context), geomIDs(geomIDs), primIDs(primIDs) {} @@ -287,6 +293,9 @@ namespace embree ray.primID = primIDs[i]; ray.geomID = geomID; instance_id_stack::copy_UU(context->user->instID, ray.instID); +#if defined(RTC_GEOMETRY_INSTANCE_ARRAY) + instance_id_stack::copy_UU(context->user->instPrimID, ray.instPrimID); +#endif return true; } @@ -296,12 +305,12 @@ namespace embree struct Occluded1EpilogM { Ray& ray; - IntersectContext* context; + RayQueryContext* context; const vuint<M>& geomIDs; const vuint<M>& primIDs; __forceinline Occluded1EpilogM(Ray& ray, - IntersectContext* context, + RayQueryContext* context, const vuint<M>& geomIDs, const vuint<M>& primIDs) : ray(ray), context(context), geomIDs(geomIDs), primIDs(primIDs) {} @@ -363,12 +372,12 @@ namespace embree struct Intersect1EpilogMU { RayHit& ray; - IntersectContext* context; + RayQueryContext* context; const unsigned int geomID; const unsigned int primID; __forceinline Intersect1EpilogMU(RayHit& ray, - IntersectContext* context, + RayQueryContext* context, const unsigned int geomID, const unsigned int primID) : ray(ray), context(context), geomID(geomID), primID(primID) {} @@ -424,6 +433,9 @@ namespace embree ray.primID = primID; ray.geomID = geomID; instance_id_stack::copy_UU(context->user->instID, ray.instID); +#if defined(RTC_GEOMETRY_INSTANCE_ARRAY) + instance_id_stack::copy_UU(context->user->instPrimID, ray.instPrimID); +#endif return true; } }; @@ -432,12 +444,12 @@ namespace embree struct Occluded1EpilogMU { Ray& ray; - IntersectContext* context; + RayQueryContext* context; const unsigned int geomID; const unsigned int primID; __forceinline Occluded1EpilogMU(Ray& ray, - IntersectContext* context, + RayQueryContext* context, const unsigned int geomID, const unsigned int primID) : ray(ray), context(context), geomID(geomID), primID(primID) {} @@ -477,13 +489,13 @@ namespace embree struct IntersectKEpilogM { RayHitK<K>& ray; - IntersectContext* context; + RayQueryContext* context; const vuint<M>& geomIDs; const vuint<M>& primIDs; const size_t i; __forceinline IntersectKEpilogM(RayHitK<K>& ray, - IntersectContext* context, + RayQueryContext* context, const vuint<M>& geomIDs, const vuint<M>& primIDs, size_t i) @@ -534,6 +546,9 @@ namespace embree vuint<K>::store(valid,&ray.primID,primID); vuint<K>::store(valid,&ray.geomID,geomID); instance_id_stack::copy_UV<K>(context->user->instID, ray.instID, valid); +#if defined(RTC_GEOMETRY_INSTANCE_ARRAY) + instance_id_stack::copy_UV<K>(context->user->instPrimID, ray.instPrimID, valid); +#endif return valid; } }; @@ -543,14 +558,14 @@ namespace embree { vbool<K>& valid0; RayK<K>& ray; - IntersectContext* context; + RayQueryContext* context; const vuint<M>& geomIDs; const vuint<M>& primIDs; const size_t i; __forceinline OccludedKEpilogM(vbool<K>& valid0, RayK<K>& ray, - IntersectContext* context, + RayQueryContext* context, const vuint<M>& geomIDs, const vuint<M>& primIDs, size_t i) @@ -598,12 +613,12 @@ namespace embree struct IntersectKEpilogMU { RayHitK<K>& ray; - IntersectContext* context; + RayQueryContext* context; const unsigned int geomID; const unsigned int primID; __forceinline IntersectKEpilogMU(RayHitK<K>& ray, - IntersectContext* context, + RayQueryContext* context, const unsigned int geomID, const unsigned int primID) : ray(ray), context(context), geomID(geomID), primID(primID) {} @@ -649,6 +664,9 @@ namespace embree vuint<K>::store(valid,&ray.primID,primID); vuint<K>::store(valid,&ray.geomID,geomID); instance_id_stack::copy_UV<K>(context->user->instID, ray.instID, valid); +#if defined(RTC_GEOMETRY_INSTANCE_ARRAY) + instance_id_stack::copy_UV<K>(context->user->instPrimID, ray.instPrimID, valid); +#endif return valid; } }; @@ -658,13 +676,13 @@ namespace embree { vbool<K>& valid0; RayK<K>& ray; - IntersectContext* context; + RayQueryContext* context; const unsigned int geomID; const unsigned int primID; __forceinline OccludedKEpilogMU(vbool<K>& valid0, RayK<K>& ray, - IntersectContext* context, + RayQueryContext* context, const unsigned int geomID, const unsigned int primID) : valid0(valid0), ray(ray), context(context), geomID(geomID), primID(primID) {} @@ -709,12 +727,12 @@ namespace embree { RayHitK<K>& ray; size_t k; - IntersectContext* context; + RayQueryContext* context; const vuint<M>& geomIDs; const vuint<M>& primIDs; __forceinline Intersect1KEpilogM(RayHitK<K>& ray, size_t k, - IntersectContext* context, + RayQueryContext* context, const vuint<M>& geomIDs, const vuint<M>& primIDs) : ray(ray), k(k), context(context), geomIDs(geomIDs), primIDs(primIDs) {} @@ -783,6 +801,9 @@ namespace embree ray.primID[k] = primIDs[i]; ray.geomID[k] = geomID; instance_id_stack::copy_UV<K>(context->user->instID, ray.instID, k); +#if defined(RTC_GEOMETRY_INSTANCE_ARRAY) + instance_id_stack::copy_UV<K>(context->user->instPrimID, ray.instPrimID, k); +#endif return true; } }; @@ -792,12 +813,12 @@ namespace embree { RayK<K>& ray; size_t k; - IntersectContext* context; + RayQueryContext* context; const vuint<M>& geomIDs; const vuint<M>& primIDs; __forceinline Occluded1KEpilogM(RayK<K>& ray, size_t k, - IntersectContext* context, + RayQueryContext* context, const vuint<M>& geomIDs, const vuint<M>& primIDs) : ray(ray), k(k), context(context), geomIDs(geomIDs), primIDs(primIDs) {} @@ -860,12 +881,12 @@ namespace embree { RayHitK<K>& ray; size_t k; - IntersectContext* context; + RayQueryContext* context; const unsigned int geomID; const unsigned int primID; __forceinline Intersect1KEpilogMU(RayHitK<K>& ray, size_t k, - IntersectContext* context, + RayQueryContext* context, const unsigned int geomID, const unsigned int primID) : ray(ray), k(k), context(context), geomID(geomID), primID(primID) {} @@ -923,6 +944,9 @@ namespace embree ray.primID[k] = primID; ray.geomID[k] = geomID; instance_id_stack::copy_UV<K>(context->user->instID, ray.instID, k); +#if defined(RTC_GEOMETRY_INSTANCE_ARRAY) + instance_id_stack::copy_UV<K>(context->user->instPrimID, ray.instPrimID, k); +#endif return true; } }; @@ -932,12 +956,12 @@ namespace embree { RayK<K>& ray; size_t k; - IntersectContext* context; + RayQueryContext* context; const unsigned int geomID; const unsigned int primID; __forceinline Occluded1KEpilogMU(RayK<K>& ray, size_t k, - IntersectContext* context, + RayQueryContext* context, const unsigned int geomID, const unsigned int primID) : ray(ray), k(k), context(context), geomID(geomID), primID(primID) {} diff --git a/thirdparty/embree/kernels/geometry/intersector_epilog_sycl.h b/thirdparty/embree/kernels/geometry/intersector_epilog_sycl.h new file mode 100644 index 0000000000..9565006738 --- /dev/null +++ b/thirdparty/embree/kernels/geometry/intersector_epilog_sycl.h @@ -0,0 +1,207 @@ +// Copyright 2009-2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include "../common/ray.h" +#include "../common/context.h" +#include "filter_sycl.h" + +namespace embree +{ + template<typename Ray> + struct Intersect1Epilog1_HWIF; + + template<> + struct Intersect1Epilog1_HWIF<RayHit> + { + RayHit& ray; + sycl::private_ptr<RayQueryContext> context; + const unsigned int geomID; + const unsigned int primID; + const bool filter; + + __forceinline Intersect1Epilog1_HWIF(RayHit& ray, + sycl::private_ptr<RayQueryContext> context, + const unsigned int geomID, + const unsigned int primID, + const bool filter) + : ray(ray), context(context), geomID(geomID), primID(primID), filter(filter) {} + + template<typename Hit_i> + __forceinline bool operator() (Hit_i& hit_i) const + { + hit_i.finalize(); + + Scene* scene MAYBE_UNUSED = context->scene; + Geometry* geometry MAYBE_UNUSED = scene->get(geomID); + + /* ray mask test */ +#if defined(EMBREE_RAY_MASK) + if ((geometry->mask & ray.mask) == 0) + return false; +#endif + + /* call intersection filter function */ +#if defined(EMBREE_FILTER_FUNCTION) + if (filter && (unlikely(context->hasContextFilter() || geometry->hasIntersectionFilter()))) + { + Hit h(context->user,geomID,primID,Vec2f(hit_i.u,hit_i.v),hit_i.Ng); + float old_t = ray.tfar; + ray.tfar = hit_i.t; + bool found = runIntersectionFilter1SYCL(geometry,ray,context,h); + if (!found) { + ray.tfar = old_t; + return false; + } + } +#endif + + ray.tfar = hit_i.t; + ray.u = hit_i.u; + ray.v = hit_i.v; + ray.Ng.x = hit_i.Ng.x; + ray.Ng.y = hit_i.Ng.y; + ray.Ng.z = hit_i.Ng.z; + ray.geomID = geomID; + ray.primID = primID; + instance_id_stack::copy_UU(context->user, context->user->instID, ray.instID); +#if defined(EMBREE_GEOMETRY_INSTANCE_ARRAY) + instance_id_stack::copy_UU(context->user, context->user->instPrimID, ray.instPrimID); +#endif + return true; + } + + template<typename Hit_i> + __forceinline bool operator() (bool, Hit_i& hit_i) const + { + hit_i.finalize(); + + Scene* scene MAYBE_UNUSED = context->scene; + Geometry* geometry MAYBE_UNUSED = scene->get(geomID); + + /* ray mask test */ +#if defined(EMBREE_RAY_MASK) + if ((geometry->mask & ray.mask) == 0) + return false; +#endif + + const Vec3fa Ng = hit_i.Ng(); + const Vec2f uv = hit_i.uv(); + + /* call intersection filter function */ +#if defined(EMBREE_FILTER_FUNCTION) + if (filter && (unlikely(context->hasContextFilter() || geometry->hasIntersectionFilter()))) + { + Hit h(context->user,geomID,primID,uv,Ng); + float old_t = ray.tfar; + ray.tfar = hit_i.t(); + bool found = runIntersectionFilter1SYCL(geometry,ray,context,h); + if (!found) { + ray.tfar = old_t; + return false; + } + } +#endif + + ray.tfar = hit_i.t(); + ray.u = uv.x; + ray.v = uv.y; + ray.Ng.x = Ng.x; + ray.Ng.y = Ng.y; + ray.Ng.z = Ng.z; + ray.geomID = geomID; + ray.primID = primID; + instance_id_stack::copy_UU(context->user, context->user->instID, ray.instID); +#if defined(EMBREE_GEOMETRY_INSTANCE_ARRAY) + instance_id_stack::copy_UU(context->user, context->user->instPrimID, ray.instPrimID); +#endif + return true; + } + }; + + template<> + struct Intersect1Epilog1_HWIF<Ray> + { + Ray& ray; + sycl::private_ptr<RayQueryContext> context; + const unsigned int geomID; + const unsigned int primID; + const bool filter; + + __forceinline Intersect1Epilog1_HWIF(Ray& ray, + sycl::private_ptr<RayQueryContext> context, + const unsigned int geomID, + const unsigned int primID, + const bool filter) + : ray(ray), context(context), geomID(geomID), primID(primID), filter(filter) {} + + template<typename Hit_i> + __forceinline bool operator() (Hit_i& hit_i) const + { + hit_i.finalize(); + + Scene* scene MAYBE_UNUSED = context->scene; + Geometry* geometry MAYBE_UNUSED = scene->get(geomID); + + /* ray mask test */ +#if defined(EMBREE_RAY_MASK) + if ((geometry->mask & ray.mask) == 0) + return false; +#endif + + /* call intersection filter function */ +#if defined(EMBREE_FILTER_FUNCTION) + if (filter && (unlikely(context->hasContextFilter() || geometry->hasOcclusionFilter()))) + { + Hit h(context->user,geomID,primID,Vec2f(hit_i.u,hit_i.v),hit_i.Ng); + float old_t = ray.tfar; + ray.tfar = hit_i.t; + bool found = runIntersectionFilter1SYCL(geometry,ray,context,h); + if (!found) { + ray.tfar = old_t; + return false; + } + } +#endif + + ray.tfar = neg_inf; + return true; + } + + template<typename Hit_i> + __forceinline bool operator() (bool, Hit_i& hit_i) const + { + hit_i.finalize(); + + Scene* scene MAYBE_UNUSED = context->scene; + Geometry* geometry MAYBE_UNUSED = scene->get(geomID); + + /* ray mask test */ +#if defined(EMBREE_RAY_MASK) + if ((geometry->mask & ray.mask) == 0) + return false; +#endif + + /* call intersection filter function */ +#if defined(EMBREE_FILTER_FUNCTION) + if (filter && (unlikely(context->hasContextFilter() || geometry->hasOcclusionFilter()))) + { + const Vec3fa Ng = hit_i.Ng(); + const Vec2f uv = hit_i.uv(); + Hit h(context->user,geomID,primID,uv,Ng); + float old_t = ray.tfar; + ray.tfar = hit_i.t(); + bool found = runIntersectionFilter1SYCL(geometry,ray,context,h); + if (!found) { + ray.tfar = old_t; + return false; + } + } +#endif + + ray.tfar = neg_inf; + return true; + } + }; +} diff --git a/thirdparty/embree/kernels/geometry/intersector_iterators.h b/thirdparty/embree/kernels/geometry/intersector_iterators.h index 9cac1cd25c..5c6a6a7bb0 100644 --- a/thirdparty/embree/kernels/geometry/intersector_iterators.h +++ b/thirdparty/embree/kernels/geometry/intersector_iterators.h @@ -20,14 +20,15 @@ namespace embree typedef typename Intersector::Precalculations Precalculations; template<int N, bool robust> - static __forceinline void intersect(const Accel::Intersectors* This, Precalculations& pre, RayHit& ray, IntersectContext* context, const Primitive* prim, size_t num, const TravRay<N,robust> &tray, size_t& lazy_node) + static __forceinline void intersect(const Accel::Intersectors* This, Precalculations& pre, RayHit& ray, RayQueryContext* context, const Primitive* prim, size_t num, const TravRay<N,robust> &tray, size_t& lazy_node) { - for (size_t i=0; i<num; i++) + for (size_t i=0; i<num; i++) { Intersector::intersect(pre,ray,context,prim[i]); + } } template<int N, bool robust> - static __forceinline bool occluded(const Accel::Intersectors* This, Precalculations& pre, Ray& ray, IntersectContext* context, const Primitive* prim, size_t num, const TravRay<N,robust> &tray, size_t& lazy_node) + static __forceinline bool occluded(const Accel::Intersectors* This, Precalculations& pre, Ray& ray, RayQueryContext* context, const Primitive* prim, size_t num, const TravRay<N,robust> &tray, size_t& lazy_node) { for (size_t i=0; i<num; i++) { if (Intersector::occluded(pre,ray,context,prim[i])) @@ -35,7 +36,7 @@ namespace embree } return false; } - + template<int N> static __forceinline bool pointQuery(const Accel::Intersectors* This, PointQuery* query, PointQueryContext* context, const Primitive* prim, size_t num, const TravPointQuery<N> &tquery, size_t& lazy_node) { @@ -46,12 +47,12 @@ namespace embree } template<int K> - static __forceinline void intersectK(const vbool<K>& valid, /* PrecalculationsK& pre, */ RayHitK<K>& ray, IntersectContext* context, const Primitive* prim, size_t num, size_t& lazy_node) + static __forceinline void intersectK(const vbool<K>& valid, /* PrecalculationsK& pre, */ RayHitK<K>& ray, RayQueryContext* context, const Primitive* prim, size_t num, size_t& lazy_node) { } template<int K> - static __forceinline vbool<K> occludedK(const vbool<K>& valid, /* PrecalculationsK& pre, */ RayK<K>& ray, IntersectContext* context, const Primitive* prim, size_t num, size_t& lazy_node) + static __forceinline vbool<K> occludedK(const vbool<K>& valid, /* PrecalculationsK& pre, */ RayK<K>& ray, RayQueryContext* context, const Primitive* prim, size_t num, size_t& lazy_node) { return valid; } @@ -64,7 +65,7 @@ namespace embree typedef typename Intersector::Precalculations Precalculations; template<bool robust> - static __forceinline void intersect(const vbool<K>& valid, const Accel::Intersectors* This, Precalculations& pre, RayHitK<K>& ray, IntersectContext* context, const Primitive* prim, size_t num, const TravRayK<K, robust> &tray, size_t& lazy_node) + static __forceinline void intersect(const vbool<K>& valid, const Accel::Intersectors* This, Precalculations& pre, RayHitK<K>& ray, RayQueryContext* context, const Primitive* prim, size_t num, const TravRayK<K, robust> &tray, size_t& lazy_node) { for (size_t i=0; i<num; i++) { Intersector::intersect(valid,pre,ray,context,prim[i]); @@ -72,7 +73,7 @@ namespace embree } template<bool robust> - static __forceinline vbool<K> occluded(const vbool<K>& valid, const Accel::Intersectors* This, Precalculations& pre, RayK<K>& ray, IntersectContext* context, const Primitive* prim, size_t num, const TravRayK<K, robust> &tray, size_t& lazy_node) + static __forceinline vbool<K> occluded(const vbool<K>& valid, const Accel::Intersectors* This, Precalculations& pre, RayK<K>& ray, RayQueryContext* context, const Primitive* prim, size_t num, const TravRayK<K, robust> &tray, size_t& lazy_node) { vbool<K> valid0 = valid; for (size_t i=0; i<num; i++) { @@ -83,7 +84,7 @@ namespace embree } template<int N, bool robust> - static __forceinline void intersect(const Accel::Intersectors* This, Precalculations& pre, RayHitK<K>& ray, size_t k, IntersectContext* context, const Primitive* prim, size_t num, const TravRay<N,robust> &tray, size_t& lazy_node) + static __forceinline void intersect(const Accel::Intersectors* This, Precalculations& pre, RayHitK<K>& ray, size_t k, RayQueryContext* context, const Primitive* prim, size_t num, const TravRay<N,robust> &tray, size_t& lazy_node) { for (size_t i=0; i<num; i++) { Intersector::intersect(pre,ray,k,context,prim[i]); @@ -91,7 +92,7 @@ namespace embree } template<int N, bool robust> - static __forceinline bool occluded(const Accel::Intersectors* This, Precalculations& pre, RayK<K>& ray, size_t k, IntersectContext* context, const Primitive* prim, size_t num, const TravRay<N,robust> &tray, size_t& lazy_node) + static __forceinline bool occluded(const Accel::Intersectors* This, Precalculations& pre, RayK<K>& ray, size_t k, RayQueryContext* context, const Primitive* prim, size_t num, const TravRay<N,robust> &tray, size_t& lazy_node) { for (size_t i=0; i<num; i++) { if (Intersector::occluded(pre,ray,k,context,prim[i])) @@ -109,7 +110,7 @@ namespace embree typedef typename IntersectorK::Primitive PrimitiveK; typedef typename IntersectorK::Precalculations PrecalculationsK; - static __forceinline void intersectK(const vbool<K>& valid, const Accel::Intersectors* This, /* PrecalculationsK& pre, */ RayHitK<K>& ray, IntersectContext* context, const PrimitiveK* prim, size_t num, size_t& lazy_node) + static __forceinline void intersectK(const vbool<K>& valid, const Accel::Intersectors* This, /* PrecalculationsK& pre, */ RayHitK<K>& ray, RayQueryContext* context, const PrimitiveK* prim, size_t num, size_t& lazy_node) { PrecalculationsK pre(valid,ray); // FIXME: might cause trouble @@ -118,7 +119,7 @@ namespace embree } } - static __forceinline vbool<K> occludedK(const vbool<K>& valid, const Accel::Intersectors* This, /* PrecalculationsK& pre, */ RayK<K>& ray, IntersectContext* context, const PrimitiveK* prim, size_t num, size_t& lazy_node) + static __forceinline vbool<K> occludedK(const vbool<K>& valid, const Accel::Intersectors* This, /* PrecalculationsK& pre, */ RayK<K>& ray, RayQueryContext* context, const PrimitiveK* prim, size_t num, size_t& lazy_node) { PrecalculationsK pre(valid,ray); // FIXME: might cause trouble vbool<K> valid0 = valid; @@ -129,7 +130,7 @@ namespace embree return !valid0; } - static __forceinline void intersect(const Accel::Intersectors* This, RayHitK<K>& ray, size_t k, IntersectContext* context, const PrimitiveK* prim, size_t num, size_t& lazy_node) + static __forceinline void intersect(const Accel::Intersectors* This, RayHitK<K>& ray, size_t k, RayQueryContext* context, const PrimitiveK* prim, size_t num, size_t& lazy_node) { PrecalculationsK pre(ray.tnear() <= ray.tfar,ray); // FIXME: might cause trouble for (size_t i=0; i<num; i++) { @@ -137,7 +138,7 @@ namespace embree } } - static __forceinline bool occluded(const Accel::Intersectors* This, RayK<K>& ray, size_t k, IntersectContext* context, const PrimitiveK* prim, size_t num, size_t& lazy_node) + static __forceinline bool occluded(const Accel::Intersectors* This, RayK<K>& ray, size_t k, RayQueryContext* context, const PrimitiveK* prim, size_t num, size_t& lazy_node) { PrecalculationsK pre(ray.tnear() <= ray.tfar,ray); // FIXME: might cause trouble for (size_t i=0; i<num; i++) { @@ -147,7 +148,7 @@ namespace embree return false; } - static __forceinline size_t occluded(const Accel::Intersectors* This, size_t cur_mask, RayK<K>** __restrict__ inputPackets, IntersectContext* context, const PrimitiveK* prim, size_t num, size_t& lazy_node) + static __forceinline size_t occluded(const Accel::Intersectors* This, size_t cur_mask, RayK<K>** __restrict__ inputPackets, RayQueryContext* context, const PrimitiveK* prim, size_t num, size_t& lazy_node) { size_t m_occluded = 0; for (size_t i=0; i<num; i++) { diff --git a/thirdparty/embree/kernels/geometry/line_intersector.h b/thirdparty/embree/kernels/geometry/line_intersector.h index 41096d8794..e3bad0a3d5 100644 --- a/thirdparty/embree/kernels/geometry/line_intersector.h +++ b/thirdparty/embree/kernels/geometry/line_intersector.h @@ -43,7 +43,7 @@ namespace embree template<typename Ray, typename Epilog> static __forceinline bool intersect(const vbool<M>& valid_i, Ray& ray, - IntersectContext* context, + RayQueryContext* context, const LineSegments* geom, const Precalculations& pre, const Vec4vf<M>& v0i, const Vec4vf<M>& v1i, @@ -96,7 +96,7 @@ namespace embree template<typename Epilog> static __forceinline bool intersect(const vbool<M>& valid_i, RayK<K>& ray, size_t k, - IntersectContext* context, + RayQueryContext* context, const LineSegments* geom, const Precalculations& pre, const Vec4vf<M>& v0i, const Vec4vf<M>& v1i, diff --git a/thirdparty/embree/kernels/geometry/linei.h b/thirdparty/embree/kernels/geometry/linei.h index 3ee70ac012..3305025fc9 100644 --- a/thirdparty/embree/kernels/geometry/linei.h +++ b/thirdparty/embree/kernels/geometry/linei.h @@ -457,6 +457,9 @@ namespace embree p1 = lerp(a1,b1,vfloat4(ftime)); pL = lerp(aL,bL,vfloat4(ftime)); pR = lerp(aR,bR,vfloat4(ftime)); + + pL = select(vboolf4(leftExists), pL, Vec4vf4(inf)); + pR = select(vboolf4(rightExists), pR, Vec4vf4(inf)); } #if defined(__AVX__) @@ -647,6 +650,9 @@ namespace embree p1 = lerp(a1,b1,vfloat8(ftime)); pL = lerp(aL,bL,vfloat8(ftime)); pR = lerp(aR,bR,vfloat8(ftime)); + + pL = select(vboolf4(leftExists), pL, Vec4vf8(inf)); + pR = select(vboolf4(rightExists), pR, Vec4vf8(inf)); } template<> diff --git a/thirdparty/embree/kernels/geometry/linei_intersector.h b/thirdparty/embree/kernels/geometry/linei_intersector.h index 5992827f5b..d754cc1269 100644 --- a/thirdparty/embree/kernels/geometry/linei_intersector.h +++ b/thirdparty/embree/kernels/geometry/linei_intersector.h @@ -17,7 +17,7 @@ namespace embree typedef LineMi<M> Primitive; typedef CurvePrecalculations1 Precalculations; - static __forceinline void intersect(const Precalculations& pre, RayHit& ray, IntersectContext* context, const Primitive& line) + static __forceinline void intersect(const Precalculations& pre, RayHit& ray, RayQueryContext* context, const Primitive& line) { STAT3(normal.trav_prims,1,1,1); const LineSegments* geom = context->scene->get<LineSegments>(line.geomID()); @@ -26,7 +26,7 @@ namespace embree FlatLinearCurveIntersector1<M>::intersect(valid,ray,context,geom,pre,v0,v1,Intersect1EpilogM<M,filter>(ray,context,line.geomID(),line.primID())); } - static __forceinline bool occluded(const Precalculations& pre, Ray& ray, IntersectContext* context, const Primitive& line) + static __forceinline bool occluded(const Precalculations& pre, Ray& ray, RayQueryContext* context, const Primitive& line) { STAT3(shadow.trav_prims,1,1,1); const LineSegments* geom = context->scene->get<LineSegments>(line.geomID()); @@ -47,7 +47,7 @@ namespace embree typedef LineMi<M> Primitive; typedef CurvePrecalculations1 Precalculations; - static __forceinline void intersect(const Precalculations& pre, RayHit& ray, IntersectContext* context, const Primitive& line) + static __forceinline void intersect(const Precalculations& pre, RayHit& ray, RayQueryContext* context, const Primitive& line) { STAT3(normal.trav_prims,1,1,1); const LineSegments* geom = context->scene->get<LineSegments>(line.geomID()); @@ -56,7 +56,7 @@ namespace embree FlatLinearCurveIntersector1<M>::intersect(valid,ray,context,geom,pre,v0,v1,Intersect1EpilogM<M,filter>(ray,context,line.geomID(),line.primID())); } - static __forceinline bool occluded(const Precalculations& pre, Ray& ray, IntersectContext* context, const Primitive& line) + static __forceinline bool occluded(const Precalculations& pre, Ray& ray, RayQueryContext* context, const Primitive& line) { STAT3(shadow.trav_prims,1,1,1); const LineSegments* geom = context->scene->get<LineSegments>(line.geomID()); @@ -77,7 +77,7 @@ namespace embree typedef LineMi<M> Primitive; typedef CurvePrecalculationsK<K> Precalculations; - static __forceinline void intersect(const Precalculations& pre, RayHitK<K>& ray, size_t k, IntersectContext* context, const Primitive& line) + static __forceinline void intersect(const Precalculations& pre, RayHitK<K>& ray, size_t k, RayQueryContext* context, const Primitive& line) { STAT3(normal.trav_prims,1,1,1); const LineSegments* geom = context->scene->get<LineSegments>(line.geomID()); @@ -86,7 +86,7 @@ namespace embree FlatLinearCurveIntersectorK<M,K>::intersect(valid,ray,k,context,geom,pre,v0,v1,Intersect1KEpilogM<M,K,filter>(ray,k,context,line.geomID(),line.primID())); } - static __forceinline bool occluded(const Precalculations& pre, RayK<K>& ray, size_t k, IntersectContext* context, const Primitive& line) + static __forceinline bool occluded(const Precalculations& pre, RayK<K>& ray, size_t k, RayQueryContext* context, const Primitive& line) { STAT3(shadow.trav_prims,1,1,1); const LineSegments* geom = context->scene->get<LineSegments>(line.geomID()); @@ -102,7 +102,7 @@ namespace embree typedef LineMi<M> Primitive; typedef CurvePrecalculationsK<K> Precalculations; - static __forceinline void intersect(const Precalculations& pre, RayHitK<K>& ray, size_t k, IntersectContext* context, const Primitive& line) + static __forceinline void intersect(const Precalculations& pre, RayHitK<K>& ray, size_t k, RayQueryContext* context, const Primitive& line) { STAT3(normal.trav_prims,1,1,1); const LineSegments* geom = context->scene->get<LineSegments>(line.geomID()); @@ -111,7 +111,7 @@ namespace embree FlatLinearCurveIntersectorK<M,K>::intersect(valid,ray,k,context,geom,pre,v0,v1,Intersect1KEpilogM<M,K,filter>(ray,k,context,line.geomID(),line.primID())); } - static __forceinline bool occluded(const Precalculations& pre, RayK<K>& ray, size_t k, IntersectContext* context, const Primitive& line) + static __forceinline bool occluded(const Precalculations& pre, RayK<K>& ray, size_t k, RayQueryContext* context, const Primitive& line) { STAT3(shadow.trav_prims,1,1,1); const LineSegments* geom = context->scene->get<LineSegments>(line.geomID()); diff --git a/thirdparty/embree/kernels/geometry/object.h b/thirdparty/embree/kernels/geometry/object.h index 2a61829ffd..9525b97880 100644 --- a/thirdparty/embree/kernels/geometry/object.h +++ b/thirdparty/embree/kernels/geometry/object.h @@ -62,6 +62,17 @@ namespace embree } /*! fill triangle from triangle list */ + __forceinline LBBox3fa fillMB(const PrimRefMB* prims, size_t i, Scene* scene, const BBox1f time_range) + { + const PrimRefMB& prim = prims[i]; i++; + const unsigned geomID = prim.geomID(); + const unsigned primID = prim.primID(); + new (this) Object(geomID, primID); + AccelSet* accel = (AccelSet*) scene->get(geomID); + return accel->linearBounds(primID,time_range); + } + + /*! fill triangle from triangle list */ __forceinline LBBox3fa fillMB(const PrimRefMB* prims, size_t& i, size_t end, Scene* scene, const BBox1f time_range) { const PrimRefMB& prim = prims[i]; i++; diff --git a/thirdparty/embree/kernels/geometry/object_intersector.h b/thirdparty/embree/kernels/geometry/object_intersector.h index e4ad01852f..b89bc1837d 100644 --- a/thirdparty/embree/kernels/geometry/object_intersector.h +++ b/thirdparty/embree/kernels/geometry/object_intersector.h @@ -22,7 +22,7 @@ namespace embree __forceinline Precalculations (const Ray& ray, const void *ptr) {} }; - static __forceinline void intersect(const Precalculations& pre, RayHit& ray, IntersectContext* context, const Primitive& prim) + static __forceinline void intersect(const Precalculations& pre, RayHit& ray, RayQueryContext* context, const Primitive& prim) { AccelSet* accel = (AccelSet*) context->scene->get(prim.geomID()); @@ -35,7 +35,7 @@ namespace embree accel->intersect(ray,prim.geomID(),prim.primID(),context); } - static __forceinline bool occluded(const Precalculations& pre, Ray& ray, IntersectContext* context, const Primitive& prim) + static __forceinline bool occluded(const Precalculations& pre, Ray& ray, RayQueryContext* context, const Primitive& prim) { AccelSet* accel = (AccelSet*) context->scene->get(prim.geomID()); /* perform ray mask test */ @@ -47,6 +47,40 @@ namespace embree accel->occluded(ray,prim.geomID(),prim.primID(),context); return ray.tfar < 0.0f; } + + static __forceinline bool intersect(const Precalculations& pre, Ray& ray, RayQueryContext* context, const Primitive& prim) { + return occluded(pre,ray,context,prim); + } + + static __forceinline void intersect(unsigned int k, const Precalculations& pre, RayHit& ray, RayQueryContext* context, const Primitive& prim) + { + AccelSet* accel = (AccelSet*) context->scene->get(prim.geomID()); + + /* perform ray mask test */ +#if defined(EMBREE_RAY_MASK) + if ((ray.mask & accel->mask) == 0) + return; +#endif + + accel->intersect(k,ray,prim.geomID(),prim.primID(),context); + } + + static __forceinline bool occluded(unsigned int k, const Precalculations& pre, Ray& ray, RayQueryContext* context, const Primitive& prim) + { + AccelSet* accel = (AccelSet*) context->scene->get(prim.geomID()); + /* perform ray mask test */ +#if defined(EMBREE_RAY_MASK) + if ((ray.mask & accel->mask) == 0) + return false; +#endif + + accel->occluded(k, ray,prim.geomID(),prim.primID(),context); + return ray.tfar < 0.0f; + } + + static __forceinline bool intersect(unsigned int k, const Precalculations& pre, Ray& ray, RayQueryContext* context, const Primitive& prim) { + return occluded(k,pre,ray,context,prim); + } static __forceinline bool pointQuery(PointQuery* query, PointQueryContext* context, const Primitive& prim) { @@ -57,13 +91,13 @@ namespace embree } template<int K> - static __forceinline void intersectK(const vbool<K>& valid, /* PrecalculationsK& pre, */ RayHitK<K>& ray, IntersectContext* context, const Primitive* prim, size_t num, size_t& lazy_node) + static __forceinline void intersectK(const vbool<K>& valid, /* PrecalculationsK& pre, */ RayHitK<K>& ray, RayQueryContext* context, const Primitive* prim, size_t num, size_t& lazy_node) { assert(false); } template<int K> - static __forceinline vbool<K> occludedK(const vbool<K>& valid, /* PrecalculationsK& pre, */ RayK<K>& ray, IntersectContext* context, const Primitive* prim, size_t num, size_t& lazy_node) + static __forceinline vbool<K> occludedK(const vbool<K>& valid, /* PrecalculationsK& pre, */ RayK<K>& ray, RayQueryContext* context, const Primitive* prim, size_t num, size_t& lazy_node) { assert(false); return valid; @@ -79,7 +113,7 @@ namespace embree __forceinline Precalculations (const vbool<K>& valid, const RayK<K>& ray) {} }; - static __forceinline void intersect(const vbool<K>& valid_i, const Precalculations& pre, RayHitK<K>& ray, IntersectContext* context, const Primitive& prim) + static __forceinline void intersect(const vbool<K>& valid_i, const Precalculations& pre, RayHitK<K>& ray, RayQueryContext* context, const Primitive& prim) { vbool<K> valid = valid_i; AccelSet* accel = (AccelSet*) context->scene->get(prim.geomID()); @@ -92,7 +126,7 @@ namespace embree accel->intersect(valid,ray,prim.geomID(),prim.primID(),context); } - static __forceinline vbool<K> occluded(const vbool<K>& valid_i, const Precalculations& pre, RayK<K>& ray, IntersectContext* context, const Primitive& prim) + static __forceinline vbool<K> occluded(const vbool<K>& valid_i, const Precalculations& pre, RayK<K>& ray, RayQueryContext* context, const Primitive& prim) { vbool<K> valid = valid_i; AccelSet* accel = (AccelSet*) context->scene->get(prim.geomID()); @@ -106,11 +140,11 @@ namespace embree return ray.tfar < 0.0f; } - static __forceinline void intersect(Precalculations& pre, RayHitK<K>& ray, size_t k, IntersectContext* context, const Primitive& prim) { + static __forceinline void intersect(Precalculations& pre, RayHitK<K>& ray, size_t k, RayQueryContext* context, const Primitive& prim) { intersect(vbool<K>(1<<int(k)),pre,ray,context,prim); } - static __forceinline bool occluded(Precalculations& pre, RayK<K>& ray, size_t k, IntersectContext* context, const Primitive& prim) { + static __forceinline bool occluded(Precalculations& pre, RayK<K>& ray, size_t k, RayQueryContext* context, const Primitive& prim) { occluded(vbool<K>(1<<int(k)),pre,ray,context,prim); return ray.tfar[k] < 0.0f; } diff --git a/thirdparty/embree/kernels/geometry/pointi.h b/thirdparty/embree/kernels/geometry/pointi.h index bed04116b0..f81edb9035 100644 --- a/thirdparty/embree/kernels/geometry/pointi.h +++ b/thirdparty/embree/kernels/geometry/pointi.h @@ -267,10 +267,10 @@ namespace embree const vfloat4 a2 = vfloat4::loadu(geom->vertexPtr(primID(2), itime)); const vfloat4 a3 = vfloat4::loadu(geom->vertexPtr(primID(3), itime)); transpose(a0, a1, a2, a3, p0.x, p0.y, p0.z, p0.w); - const vfloat4 b0 = vfloat4(geom->normal(primID(0), itime)); - const vfloat4 b1 = vfloat4(geom->normal(primID(1), itime)); - const vfloat4 b2 = vfloat4(geom->normal(primID(2), itime)); - const vfloat4 b3 = vfloat4(geom->normal(primID(3), itime)); + const vfloat4 b0 = vfloat4(geom->normal((size_t)primID(0), (size_t)itime)); + const vfloat4 b1 = vfloat4(geom->normal((size_t)primID(1), (size_t)itime)); + const vfloat4 b2 = vfloat4(geom->normal((size_t)primID(2), (size_t)itime)); + const vfloat4 b3 = vfloat4(geom->normal((size_t)primID(3), (size_t)itime)); transpose(b0, b1, b2, b3, n0.x, n0.y, n0.z); } @@ -364,14 +364,14 @@ namespace embree const vfloat4 a6 = vfloat4::loadu(geom->vertexPtr(primID(6), itime)); const vfloat4 a7 = vfloat4::loadu(geom->vertexPtr(primID(7), itime)); transpose(a0, a1, a2, a3, a4, a5, a6, a7, p0.x, p0.y, p0.z, p0.w); - const vfloat4 b0 = vfloat4(geom->normal(primID(0), itime)); - const vfloat4 b1 = vfloat4(geom->normal(primID(1), itime)); - const vfloat4 b2 = vfloat4(geom->normal(primID(2), itime)); - const vfloat4 b3 = vfloat4(geom->normal(primID(3), itime)); - const vfloat4 b4 = vfloat4(geom->normal(primID(4), itime)); - const vfloat4 b5 = vfloat4(geom->normal(primID(5), itime)); - const vfloat4 b6 = vfloat4(geom->normal(primID(6), itime)); - const vfloat4 b7 = vfloat4(geom->normal(primID(7), itime)); + const vfloat4 b0 = vfloat4(geom->normal((size_t)primID(0), (size_t)itime)); + const vfloat4 b1 = vfloat4(geom->normal((size_t)primID(1), (size_t)itime)); + const vfloat4 b2 = vfloat4(geom->normal((size_t)primID(2), (size_t)itime)); + const vfloat4 b3 = vfloat4(geom->normal((size_t)primID(3), (size_t)itime)); + const vfloat4 b4 = vfloat4(geom->normal((size_t)primID(4), (size_t)itime)); + const vfloat4 b5 = vfloat4(geom->normal((size_t)primID(5), (size_t)itime)); + const vfloat4 b6 = vfloat4(geom->normal((size_t)primID(6), (size_t)itime)); + const vfloat4 b7 = vfloat4(geom->normal((size_t)primID(7), (size_t)itime)); transpose(b0, b1, b2, b3, b4, b5, b6, b7, n0.x, n0.y, n0.z); } diff --git a/thirdparty/embree/kernels/geometry/primitive.h b/thirdparty/embree/kernels/geometry/primitive.h index 608d981dd7..de25ab87ef 100644 --- a/thirdparty/embree/kernels/geometry/primitive.h +++ b/thirdparty/embree/kernels/geometry/primitive.h @@ -6,8 +6,8 @@ #include "../common/default.h" #include "../common/scene.h" #include "../../common/simd/simd.h" -#include "../common/primref.h" -#include "../common/primref_mb.h" +#include "../builders/primref.h" +#include "../builders/primref_mb.h" namespace embree { diff --git a/thirdparty/embree/kernels/geometry/primitive4.cpp b/thirdparty/embree/kernels/geometry/primitive4.cpp index 9c953c5d35..924e78bbf1 100644 --- a/thirdparty/embree/kernels/geometry/primitive4.cpp +++ b/thirdparty/embree/kernels/geometry/primitive4.cpp @@ -15,6 +15,7 @@ #include "subdivpatch1.h" #include "object.h" #include "instance.h" +#include "instance_array.h" #include "subgrid.h" namespace embree @@ -335,6 +336,26 @@ namespace embree InstancePrimitive::Type InstancePrimitive::type; + /********************** InstanceArray4 **************************/ + + const char* InstanceArrayPrimitive::Type::name () const { + return "instance_array"; + } + + size_t InstanceArrayPrimitive::Type::sizeActive(const char* This) const { + return 1; + } + + size_t InstanceArrayPrimitive::Type::sizeTotal(const char* This) const { + return 1; + } + + size_t InstanceArrayPrimitive::Type::getBytes(const char* This) const { + return sizeof(InstanceArrayPrimitive); + } + + InstanceArrayPrimitive::Type InstanceArrayPrimitive::type; + /********************** SubGrid **************************/ const char* SubGrid::Type::name () const { diff --git a/thirdparty/embree/kernels/geometry/quad_intersector_moeller.h b/thirdparty/embree/kernels/geometry/quad_intersector_moeller.h index 3abc9d6f70..2c574e4e47 100644 --- a/thirdparty/embree/kernels/geometry/quad_intersector_moeller.h +++ b/thirdparty/embree/kernels/geometry/quad_intersector_moeller.h @@ -122,7 +122,7 @@ namespace embree __forceinline QuadMIntersector1MoellerTrumbore(const Ray& ray, const void* ptr) {} - __forceinline void intersect(RayHit& ray, IntersectContext* context, + __forceinline void intersect(RayHit& ray, RayQueryContext* context, const Vec3vf<M>& v0, const Vec3vf<M>& v1, const Vec3vf<M>& v2, const Vec3vf<M>& v3, const vuint<M>& geomID, const vuint<M>& primID) const { @@ -144,7 +144,7 @@ namespace embree } } - __forceinline bool occluded(Ray& ray, IntersectContext* context, + __forceinline bool occluded(Ray& ray, RayQueryContext* context, const Vec3vf<M>& v0, const Vec3vf<M>& v1, const Vec3vf<M>& v2, const Vec3vf<M>& v3, const vuint<M>& geomID, const vuint<M>& primID) const { @@ -215,14 +215,14 @@ namespace embree return false; } - __forceinline bool intersect(RayHit& ray, IntersectContext* context, + __forceinline bool intersect(RayHit& ray, RayQueryContext* context, const Vec3vf4& v0, const Vec3vf4& v1, const Vec3vf4& v2, const Vec3vf4& v3, const vuint4& geomID, const vuint4& primID) const { return intersect(ray,v0,v1,v2,v3,Intersect1EpilogM<8,filter>(ray,context,vuint8(geomID),vuint8(primID))); } - __forceinline bool occluded(Ray& ray, IntersectContext* context, + __forceinline bool occluded(Ray& ray, RayQueryContext* context, const Vec3vf4& v0, const Vec3vf4& v1, const Vec3vf4& v2, const Vec3vf4& v3, const vuint4& geomID, const vuint4& primID) const { @@ -394,7 +394,7 @@ namespace embree __forceinline QuadMIntersectorKMoellerTrumbore(const vbool<K>& valid, const RayK<K>& ray) : QuadMIntersectorKMoellerTrumboreBase<M,K,filter>(valid,ray) {} - __forceinline void intersect1(RayHitK<K>& ray, size_t k, IntersectContext* context, + __forceinline void intersect1(RayHitK<K>& ray, size_t k, RayQueryContext* context, const Vec3vf<M>& v0, const Vec3vf<M>& v1, const Vec3vf<M>& v2, const Vec3vf<M>& v3, const vuint<M>& geomID, const vuint<M>& primID) const { @@ -403,7 +403,7 @@ namespace embree MoellerTrumboreIntersector1KTriangleM::intersect1<M,K>(ray,k,v2,v3,v1,vbool<M>(true ),epilog); } - __forceinline bool occluded1(RayK<K>& ray, size_t k, IntersectContext* context, + __forceinline bool occluded1(RayK<K>& ray, size_t k, RayQueryContext* context, const Vec3vf<M>& v0, const Vec3vf<M>& v1, const Vec3vf<M>& v2, const Vec3vf<M>& v3, const vuint<M>& geomID, const vuint<M>& primID) const { @@ -440,14 +440,14 @@ namespace embree return MoellerTrumboreIntersector1KTriangleM::intersect1<8,K>(ray,k,vtx0,vtx1,vtx2,flags,epilog); } - __forceinline bool intersect1(RayHitK<K>& ray, size_t k, IntersectContext* context, + __forceinline bool intersect1(RayHitK<K>& ray, size_t k, RayQueryContext* context, const Vec3vf4& v0, const Vec3vf4& v1, const Vec3vf4& v2, const Vec3vf4& v3, const vuint4& geomID, const vuint4& primID) const { return intersect1(ray,k,v0,v1,v2,v3,Intersect1KEpilogM<8,K,filter>(ray,k,context,vuint8(geomID),vuint8(primID))); } - __forceinline bool occluded1(RayK<K>& ray, size_t k, IntersectContext* context, + __forceinline bool occluded1(RayK<K>& ray, size_t k, RayQueryContext* context, const Vec3vf4& v0, const Vec3vf4& v1, const Vec3vf4& v2, const Vec3vf4& v3, const vuint4& geomID, const vuint4& primID) const { diff --git a/thirdparty/embree/kernels/geometry/quad_intersector_pluecker.h b/thirdparty/embree/kernels/geometry/quad_intersector_pluecker.h index 9873ff76ac..69d6881080 100644 --- a/thirdparty/embree/kernels/geometry/quad_intersector_pluecker.h +++ b/thirdparty/embree/kernels/geometry/quad_intersector_pluecker.h @@ -171,7 +171,7 @@ namespace embree __forceinline QuadMIntersector1Pluecker(const Ray& ray, const void* ptr) {} - __forceinline void intersect(RayHit& ray, IntersectContext* context, + __forceinline void intersect(RayHit& ray, RayQueryContext* context, const Vec3vf<M>& v0, const Vec3vf<M>& v1, const Vec3vf<M>& v2, const Vec3vf<M>& v3, const vuint<M>& geomID, const vuint<M>& primID) const { @@ -180,7 +180,7 @@ namespace embree PlueckerIntersectorTriangle1::intersect<M>(ray,v2,v3,v1,vbool<M>(true),epilog); } - __forceinline bool occluded(Ray& ray, IntersectContext* context, + __forceinline bool occluded(Ray& ray, RayQueryContext* context, const Vec3vf<M>& v0, const Vec3vf<M>& v1, const Vec3vf<M>& v2, const Vec3vf<M>& v3, const vuint<M>& geomID, const vuint<M>& primID) const { @@ -216,13 +216,13 @@ namespace embree return PlueckerIntersectorTriangle1::intersect<8>(ray,vtx0,vtx1,vtx2,flags,epilog); } - __forceinline bool intersect(RayHit& ray, IntersectContext* context, const Vec3vf4& v0, const Vec3vf4& v1, const Vec3vf4& v2, const Vec3vf4& v3, + __forceinline bool intersect(RayHit& ray, RayQueryContext* context, const Vec3vf4& v0, const Vec3vf4& v1, const Vec3vf4& v2, const Vec3vf4& v3, const vuint4& geomID, const vuint4& primID) const { return intersect(ray,v0,v1,v2,v3,Intersect1EpilogM<8,filter>(ray,context,vuint8(geomID),vuint8(primID))); } - __forceinline bool occluded(Ray& ray, IntersectContext* context, const Vec3vf4& v0, const Vec3vf4& v1, const Vec3vf4& v2, const Vec3vf4& v3, + __forceinline bool occluded(Ray& ray, RayQueryContext* context, const Vec3vf4& v0, const Vec3vf4& v1, const Vec3vf4& v2, const Vec3vf4& v3, const vuint4& geomID, const vuint4& primID) const { return intersect(ray,v0,v1,v2,v3,Occluded1EpilogM<8,filter>(ray,context,vuint8(geomID),vuint8(primID))); @@ -374,7 +374,7 @@ namespace embree __forceinline QuadMIntersectorKPluecker(const vbool<K>& valid, const RayK<K>& ray) : QuadMIntersectorKPlueckerBase<M,K,filter>(valid,ray) {} - __forceinline void intersect1(RayHitK<K>& ray, size_t k, IntersectContext* context, + __forceinline void intersect1(RayHitK<K>& ray, size_t k, RayQueryContext* context, const Vec3vf<M>& v0, const Vec3vf<M>& v1, const Vec3vf<M>& v2, const Vec3vf<M>& v3, const vuint<M>& geomID, const vuint<M>& primID) const { @@ -383,7 +383,7 @@ namespace embree PlueckerIntersector1KTriangleM::intersect1<M,K>(ray,k,v2,v3,v1,vbool<M>(true ),epilog); } - __forceinline bool occluded1(RayK<K>& ray, size_t k, IntersectContext* context, + __forceinline bool occluded1(RayK<K>& ray, size_t k, RayQueryContext* context, const Vec3vf<M>& v0, const Vec3vf<M>& v1, const Vec3vf<M>& v2, const Vec3vf<M>& v3, const vuint<M>& geomID, const vuint<M>& primID) const { @@ -418,14 +418,14 @@ namespace embree return PlueckerIntersector1KTriangleM::intersect1<8,K>(ray,k,vtx0,vtx1,vtx2,flags,epilog); } - __forceinline bool intersect1(RayHitK<K>& ray, size_t k, IntersectContext* context, + __forceinline bool intersect1(RayHitK<K>& ray, size_t k, RayQueryContext* context, const Vec3vf4& v0, const Vec3vf4& v1, const Vec3vf4& v2, const Vec3vf4& v3, const vuint4& geomID, const vuint4& primID) const { return intersect1(ray,k,v0,v1,v2,v3,Intersect1KEpilogM<8,K,filter>(ray,k,context,vuint8(geomID),vuint8(primID))); } - __forceinline bool occluded1(RayK<K>& ray, size_t k, IntersectContext* context, + __forceinline bool occluded1(RayK<K>& ray, size_t k, RayQueryContext* context, const Vec3vf4& v0, const Vec3vf4& v1, const Vec3vf4& v2, const Vec3vf4& v3, const vuint4& geomID, const vuint4& primID) const { diff --git a/thirdparty/embree/kernels/geometry/quadi_intersector.h b/thirdparty/embree/kernels/geometry/quadi_intersector.h index 20a98c3406..96fc77b42d 100644 --- a/thirdparty/embree/kernels/geometry/quadi_intersector.h +++ b/thirdparty/embree/kernels/geometry/quadi_intersector.h @@ -19,7 +19,7 @@ namespace embree typedef QuadMIntersector1MoellerTrumbore<M,filter> Precalculations; /*! Intersect a ray with the M quads and updates the hit. */ - static __forceinline void intersect(const Precalculations& pre, RayHit& ray, IntersectContext* context, const Primitive& quad) + static __forceinline void intersect(const Precalculations& pre, RayHit& ray, RayQueryContext* context, const Primitive& quad) { STAT3(normal.trav_prims,1,1,1); Vec3vf<M> v0,v1,v2,v3; quad.gather(v0,v1,v2,v3,context->scene); @@ -27,7 +27,7 @@ namespace embree } /*! Test if the ray is occluded by one of M quads. */ - static __forceinline bool occluded(const Precalculations& pre, Ray& ray, IntersectContext* context, const Primitive& quad) + static __forceinline bool occluded(const Precalculations& pre, Ray& ray, RayQueryContext* context, const Primitive& quad) { STAT3(shadow.trav_prims,1,1,1); Vec3vf<M> v0,v1,v2,v3; quad.gather(v0,v1,v2,v3,context->scene); @@ -48,7 +48,7 @@ namespace embree typedef QuadMIntersectorKMoellerTrumbore<M,K,filter> Precalculations; /*! Intersects K rays with M triangles. */ - static __forceinline void intersect(const vbool<K>& valid_i, Precalculations& pre, RayHitK<K>& ray, IntersectContext* context, const QuadMi<M>& quad) + static __forceinline void intersect(const vbool<K>& valid_i, Precalculations& pre, RayHitK<K>& ray, RayQueryContext* context, const QuadMi<M>& quad) { Scene* scene = context->scene; for (size_t i=0; i<QuadMi<M>::max_size(); i++) @@ -64,7 +64,7 @@ namespace embree } /*! Test for K rays if they are occluded by any of the M triangles. */ - static __forceinline vbool<K> occluded(const vbool<K>& valid_i, Precalculations& pre, RayK<K>& ray, IntersectContext* context, const QuadMi<M>& quad) + static __forceinline vbool<K> occluded(const vbool<K>& valid_i, Precalculations& pre, RayK<K>& ray, RayQueryContext* context, const QuadMi<M>& quad) { Scene* scene = context->scene; vbool<K> valid0 = valid_i; @@ -83,7 +83,7 @@ namespace embree } /*! Intersect a ray with M triangles and updates the hit. */ - static __forceinline void intersect(Precalculations& pre, RayHitK<K>& ray, size_t k, IntersectContext* context, const QuadMi<M>& quad) + static __forceinline void intersect(Precalculations& pre, RayHitK<K>& ray, size_t k, RayQueryContext* context, const QuadMi<M>& quad) { STAT3(normal.trav_prims,1,1,1); Vec3vf4 v0,v1,v2,v3; quad.gather(v0,v1,v2,v3,context->scene); @@ -91,7 +91,7 @@ namespace embree } /*! Test if the ray is occluded by one of the M triangles. */ - static __forceinline bool occluded(Precalculations& pre, RayK<K>& ray, size_t k, IntersectContext* context, const QuadMi<M>& quad) + static __forceinline bool occluded(Precalculations& pre, RayK<K>& ray, size_t k, RayQueryContext* context, const QuadMi<M>& quad) { STAT3(shadow.trav_prims,1,1,1); Vec3vf4 v0,v1,v2,v3; quad.gather(v0,v1,v2,v3,context->scene); @@ -107,7 +107,7 @@ namespace embree typedef QuadMIntersector1Pluecker<M,filter> Precalculations; /*! Intersect a ray with the M quads and updates the hit. */ - static __forceinline void intersect(const Precalculations& pre, RayHit& ray, IntersectContext* context, const Primitive& quad) + static __forceinline void intersect(const Precalculations& pre, RayHit& ray, RayQueryContext* context, const Primitive& quad) { STAT3(normal.trav_prims,1,1,1); Vec3vf<M> v0,v1,v2,v3; quad.gather(v0,v1,v2,v3,context->scene); @@ -115,7 +115,7 @@ namespace embree } /*! Test if the ray is occluded by one of M quads. */ - static __forceinline bool occluded(const Precalculations& pre, Ray& ray, IntersectContext* context, const Primitive& quad) + static __forceinline bool occluded(const Precalculations& pre, Ray& ray, RayQueryContext* context, const Primitive& quad) { STAT3(shadow.trav_prims,1,1,1); Vec3vf<M> v0,v1,v2,v3; quad.gather(v0,v1,v2,v3,context->scene); @@ -136,7 +136,7 @@ namespace embree typedef QuadMIntersectorKPluecker<M,K,filter> Precalculations; /*! Intersects K rays with M triangles. */ - static __forceinline void intersect(const vbool<K>& valid_i, Precalculations& pre, RayHitK<K>& ray, IntersectContext* context, const QuadMi<M>& quad) + static __forceinline void intersect(const vbool<K>& valid_i, Precalculations& pre, RayHitK<K>& ray, RayQueryContext* context, const QuadMi<M>& quad) { Scene* scene = context->scene; for (size_t i=0; i<QuadMi<M>::max_size(); i++) @@ -152,7 +152,7 @@ namespace embree } /*! Test for K rays if they are occluded by any of the M triangles. */ - static __forceinline vbool<K> occluded(const vbool<K>& valid_i, Precalculations& pre, RayK<K>& ray, IntersectContext* context, const QuadMi<M>& quad) + static __forceinline vbool<K> occluded(const vbool<K>& valid_i, Precalculations& pre, RayK<K>& ray, RayQueryContext* context, const QuadMi<M>& quad) { Scene* scene = context->scene; vbool<K> valid0 = valid_i; @@ -171,7 +171,7 @@ namespace embree } /*! Intersect a ray with M triangles and updates the hit. */ - static __forceinline void intersect(Precalculations& pre, RayHitK<K>& ray, size_t k, IntersectContext* context, const QuadMi<M>& quad) + static __forceinline void intersect(Precalculations& pre, RayHitK<K>& ray, size_t k, RayQueryContext* context, const QuadMi<M>& quad) { STAT3(normal.trav_prims,1,1,1); Vec3vf4 v0,v1,v2,v3; quad.gather(v0,v1,v2,v3,context->scene); @@ -179,7 +179,7 @@ namespace embree } /*! Test if the ray is occluded by one of the M triangles. */ - static __forceinline bool occluded(Precalculations& pre, RayK<K>& ray, size_t k, IntersectContext* context, const QuadMi<M>& quad) + static __forceinline bool occluded(Precalculations& pre, RayK<K>& ray, size_t k, RayQueryContext* context, const QuadMi<M>& quad) { STAT3(shadow.trav_prims,1,1,1); Vec3vf4 v0,v1,v2,v3; quad.gather(v0,v1,v2,v3,context->scene); @@ -195,7 +195,7 @@ namespace embree typedef QuadMIntersector1MoellerTrumbore<M,filter> Precalculations; /*! Intersect a ray with the M quads and updates the hit. */ - static __forceinline void intersect(const Precalculations& pre, RayHit& ray, IntersectContext* context, const Primitive& quad) + static __forceinline void intersect(const Precalculations& pre, RayHit& ray, RayQueryContext* context, const Primitive& quad) { STAT3(normal.trav_prims,1,1,1); Vec3vf<M> v0,v1,v2,v3; quad.gather(v0,v1,v2,v3,context->scene,ray.time()); @@ -203,7 +203,7 @@ namespace embree } /*! Test if the ray is occluded by one of M quads. */ - static __forceinline bool occluded(const Precalculations& pre, Ray& ray, IntersectContext* context, const Primitive& quad) + static __forceinline bool occluded(const Precalculations& pre, Ray& ray, RayQueryContext* context, const Primitive& quad) { STAT3(shadow.trav_prims,1,1,1); Vec3vf<M> v0,v1,v2,v3; quad.gather(v0,v1,v2,v3,context->scene,ray.time()); @@ -224,7 +224,7 @@ namespace embree typedef QuadMIntersectorKMoellerTrumbore<M,K,filter> Precalculations; /*! Intersects K rays with M quads. */ - static __forceinline void intersect(const vbool<K>& valid_i, Precalculations& pre, RayHitK<K>& ray, IntersectContext* context, const QuadMi<M>& quad) + static __forceinline void intersect(const vbool<K>& valid_i, Precalculations& pre, RayHitK<K>& ray, RayQueryContext* context, const QuadMi<M>& quad) { for (size_t i=0; i<QuadMi<M>::max_size(); i++) { @@ -236,7 +236,7 @@ namespace embree } /*! Test for K rays if they are occluded by any of the M quads. */ - static __forceinline vbool<K> occluded(const vbool<K>& valid_i, Precalculations& pre, RayK<K>& ray, IntersectContext* context, const QuadMi<M>& quad) + static __forceinline vbool<K> occluded(const vbool<K>& valid_i, Precalculations& pre, RayK<K>& ray, RayQueryContext* context, const QuadMi<M>& quad) { vbool<K> valid0 = valid_i; for (size_t i=0; i<QuadMi<M>::max_size(); i++) @@ -251,7 +251,7 @@ namespace embree } /*! Intersect a ray with M quads and updates the hit. */ - static __forceinline void intersect(Precalculations& pre, RayHitK<K>& ray, size_t k, IntersectContext* context, const QuadMi<M>& quad) + static __forceinline void intersect(Precalculations& pre, RayHitK<K>& ray, size_t k, RayQueryContext* context, const QuadMi<M>& quad) { STAT3(normal.trav_prims,1,1,1); Vec3vf<M> v0,v1,v2,v3; quad.gather(v0,v1,v2,v3,context->scene,ray.time()[k]); @@ -259,7 +259,7 @@ namespace embree } /*! Test if the ray is occluded by one of the M quads. */ - static __forceinline bool occluded(Precalculations& pre, RayK<K>& ray, size_t k, IntersectContext* context, const QuadMi<M>& quad) + static __forceinline bool occluded(Precalculations& pre, RayK<K>& ray, size_t k, RayQueryContext* context, const QuadMi<M>& quad) { STAT3(shadow.trav_prims,1,1,1); Vec3vf<M> v0,v1,v2,v3; quad.gather(v0,v1,v2,v3,context->scene,ray.time()[k]); @@ -275,7 +275,7 @@ namespace embree typedef QuadMIntersector1Pluecker<M,filter> Precalculations; /*! Intersect a ray with the M quads and updates the hit. */ - static __forceinline void intersect(const Precalculations& pre, RayHit& ray, IntersectContext* context, const Primitive& quad) + static __forceinline void intersect(const Precalculations& pre, RayHit& ray, RayQueryContext* context, const Primitive& quad) { STAT3(normal.trav_prims,1,1,1); Vec3vf<M> v0,v1,v2,v3; quad.gather(v0,v1,v2,v3,context->scene,ray.time()); @@ -283,7 +283,7 @@ namespace embree } /*! Test if the ray is occluded by one of M quads. */ - static __forceinline bool occluded(const Precalculations& pre, Ray& ray, IntersectContext* context, const Primitive& quad) + static __forceinline bool occluded(const Precalculations& pre, Ray& ray, RayQueryContext* context, const Primitive& quad) { STAT3(shadow.trav_prims,1,1,1); Vec3vf<M> v0,v1,v2,v3; quad.gather(v0,v1,v2,v3,context->scene,ray.time()); @@ -304,7 +304,7 @@ namespace embree typedef QuadMIntersectorKPluecker<M,K,filter> Precalculations; /*! Intersects K rays with M quads. */ - static __forceinline void intersect(const vbool<K>& valid_i, Precalculations& pre, RayHitK<K>& ray, IntersectContext* context, const QuadMi<M>& quad) + static __forceinline void intersect(const vbool<K>& valid_i, Precalculations& pre, RayHitK<K>& ray, RayQueryContext* context, const QuadMi<M>& quad) { for (size_t i=0; i<QuadMi<M>::max_size(); i++) { @@ -316,7 +316,7 @@ namespace embree } /*! Test for K rays if they are occluded by any of the M quads. */ - static __forceinline vbool<K> occluded(const vbool<K>& valid_i, Precalculations& pre, RayK<K>& ray, IntersectContext* context, const QuadMi<M>& quad) + static __forceinline vbool<K> occluded(const vbool<K>& valid_i, Precalculations& pre, RayK<K>& ray, RayQueryContext* context, const QuadMi<M>& quad) { vbool<K> valid0 = valid_i; for (size_t i=0; i<QuadMi<M>::max_size(); i++) @@ -331,7 +331,7 @@ namespace embree } /*! Intersect a ray with M quads and updates the hit. */ - static __forceinline void intersect(Precalculations& pre, RayHitK<K>& ray, size_t k, IntersectContext* context, const QuadMi<M>& quad) + static __forceinline void intersect(Precalculations& pre, RayHitK<K>& ray, size_t k, RayQueryContext* context, const QuadMi<M>& quad) { STAT3(normal.trav_prims,1,1,1); Vec3vf<M> v0,v1,v2,v3; quad.gather(v0,v1,v2,v3,context->scene,ray.time()[k]); @@ -339,7 +339,7 @@ namespace embree } /*! Test if the ray is occluded by one of the M quads. */ - static __forceinline bool occluded(Precalculations& pre, RayK<K>& ray, size_t k, IntersectContext* context, const QuadMi<M>& quad) + static __forceinline bool occluded(Precalculations& pre, RayK<K>& ray, size_t k, RayQueryContext* context, const QuadMi<M>& quad) { STAT3(shadow.trav_prims,1,1,1); Vec3vf<M> v0,v1,v2,v3; quad.gather(v0,v1,v2,v3,context->scene,ray.time()[k]); diff --git a/thirdparty/embree/kernels/geometry/quadv_intersector.h b/thirdparty/embree/kernels/geometry/quadv_intersector.h index 9b28e05614..9eea8275f7 100644 --- a/thirdparty/embree/kernels/geometry/quadv_intersector.h +++ b/thirdparty/embree/kernels/geometry/quadv_intersector.h @@ -19,14 +19,14 @@ namespace embree typedef QuadMIntersector1MoellerTrumbore<M,filter> Precalculations; /*! Intersect a ray with the M quads and updates the hit. */ - static __forceinline void intersect(const Precalculations& pre, RayHit& ray, IntersectContext* context, const Primitive& quad) + static __forceinline void intersect(const Precalculations& pre, RayHit& ray, RayQueryContext* context, const Primitive& quad) { STAT3(normal.trav_prims,1,1,1); pre.intersect(ray,context,quad.v0,quad.v1,quad.v2,quad.v3,quad.geomID(),quad.primID()); } /*! Test if the ray is occluded by one of M quads. */ - static __forceinline bool occluded(const Precalculations& pre, Ray& ray, IntersectContext* context, const Primitive& quad) + static __forceinline bool occluded(const Precalculations& pre, Ray& ray, RayQueryContext* context, const Primitive& quad) { STAT3(shadow.trav_prims,1,1,1); return pre.occluded(ray,context, quad.v0,quad.v1,quad.v2,quad.v3,quad.geomID(),quad.primID()); @@ -46,7 +46,7 @@ namespace embree typedef QuadMIntersectorKMoellerTrumbore<M,K,filter> Precalculations; /*! Intersects K rays with M triangles. */ - static __forceinline void intersect(const vbool<K>& valid_i, Precalculations& pre, RayHitK<K>& ray, IntersectContext* context, const QuadMv<M>& quad) + static __forceinline void intersect(const vbool<K>& valid_i, Precalculations& pre, RayHitK<K>& ray, RayQueryContext* context, const QuadMv<M>& quad) { for (size_t i=0; i<QuadMv<M>::max_size(); i++) { @@ -61,7 +61,7 @@ namespace embree } /*! Test for K rays if they are occluded by any of the M triangles. */ - static __forceinline vbool<K> occluded(const vbool<K>& valid_i, Precalculations& pre, RayK<K>& ray, IntersectContext* context, const QuadMv<M>& quad) + static __forceinline vbool<K> occluded(const vbool<K>& valid_i, Precalculations& pre, RayK<K>& ray, RayQueryContext* context, const QuadMv<M>& quad) { vbool<K> valid0 = valid_i; @@ -80,14 +80,14 @@ namespace embree } /*! Intersect a ray with M triangles and updates the hit. */ - static __forceinline void intersect(Precalculations& pre, RayHitK<K>& ray, size_t k, IntersectContext* context, const QuadMv<M>& quad) + static __forceinline void intersect(Precalculations& pre, RayHitK<K>& ray, size_t k, RayQueryContext* context, const QuadMv<M>& quad) { STAT3(normal.trav_prims,1,1,1); pre.intersect1(ray,k,context,quad.v0,quad.v1,quad.v2,quad.v3,quad.geomID(),quad.primID()); } /*! Test if the ray is occluded by one of the M triangles. */ - static __forceinline bool occluded(Precalculations& pre, RayK<K>& ray, size_t k, IntersectContext* context, const QuadMv<M>& quad) + static __forceinline bool occluded(Precalculations& pre, RayK<K>& ray, size_t k, RayQueryContext* context, const QuadMv<M>& quad) { STAT3(shadow.trav_prims,1,1,1); return pre.occluded1(ray,k,context,quad.v0,quad.v1,quad.v2,quad.v3,quad.geomID(),quad.primID()); @@ -102,14 +102,14 @@ namespace embree typedef QuadMIntersector1Pluecker<M,filter> Precalculations; /*! Intersect a ray with the M quads and updates the hit. */ - static __forceinline void intersect(const Precalculations& pre, RayHit& ray, IntersectContext* context, const Primitive& quad) + static __forceinline void intersect(const Precalculations& pre, RayHit& ray, RayQueryContext* context, const Primitive& quad) { STAT3(normal.trav_prims,1,1,1); pre.intersect(ray,context,quad.v0,quad.v1,quad.v2,quad.v3,quad.geomID(),quad.primID()); } /*! Test if the ray is occluded by one of M quads. */ - static __forceinline bool occluded(const Precalculations& pre, Ray& ray, IntersectContext* context, const Primitive& quad) + static __forceinline bool occluded(const Precalculations& pre, Ray& ray, RayQueryContext* context, const Primitive& quad) { STAT3(shadow.trav_prims,1,1,1); return pre.occluded(ray,context, quad.v0,quad.v1,quad.v2,quad.v3,quad.geomID(),quad.primID()); @@ -129,7 +129,7 @@ namespace embree typedef QuadMIntersectorKPluecker<M,K,filter> Precalculations; /*! Intersects K rays with M triangles. */ - static __forceinline void intersect(const vbool<K>& valid_i, Precalculations& pre, RayHitK<K>& ray, IntersectContext* context, const QuadMv<M>& quad) + static __forceinline void intersect(const vbool<K>& valid_i, Precalculations& pre, RayHitK<K>& ray, RayQueryContext* context, const QuadMv<M>& quad) { for (size_t i=0; i<QuadMv<M>::max_size(); i++) { @@ -144,7 +144,7 @@ namespace embree } /*! Test for K rays if they are occluded by any of the M triangles. */ - static __forceinline vbool<K> occluded(const vbool<K>& valid_i, Precalculations& pre, RayK<K>& ray, IntersectContext* context, const QuadMv<M>& quad) + static __forceinline vbool<K> occluded(const vbool<K>& valid_i, Precalculations& pre, RayK<K>& ray, RayQueryContext* context, const QuadMv<M>& quad) { vbool<K> valid0 = valid_i; @@ -163,14 +163,14 @@ namespace embree } /*! Intersect a ray with M triangles and updates the hit. */ - static __forceinline void intersect(Precalculations& pre, RayHitK<K>& ray, size_t k, IntersectContext* context, const QuadMv<M>& quad) + static __forceinline void intersect(Precalculations& pre, RayHitK<K>& ray, size_t k, RayQueryContext* context, const QuadMv<M>& quad) { STAT3(normal.trav_prims,1,1,1); pre.intersect1(ray,k,context,quad.v0,quad.v1,quad.v2,quad.v3,quad.geomID(),quad.primID()); } /*! Test if the ray is occluded by one of the M triangles. */ - static __forceinline bool occluded(Precalculations& pre, RayK<K>& ray, size_t k, IntersectContext* context, const QuadMv<M>& quad) + static __forceinline bool occluded(Precalculations& pre, RayK<K>& ray, size_t k, RayQueryContext* context, const QuadMv<M>& quad) { STAT3(shadow.trav_prims,1,1,1); return pre.occluded1(ray,k,context,quad.v0,quad.v1,quad.v2,quad.v3,quad.geomID(),quad.primID()); diff --git a/thirdparty/embree/kernels/geometry/roundline_intersector.h b/thirdparty/embree/kernels/geometry/roundline_intersector.h index 764ff93fec..a83dd72a7f 100644 --- a/thirdparty/embree/kernels/geometry/roundline_intersector.h +++ b/thirdparty/embree/kernels/geometry/roundline_intersector.h @@ -661,7 +661,7 @@ namespace embree template<typename Ray, typename Epilog> static __forceinline bool intersect(const vbool<M>& valid_i, Ray& ray, - IntersectContext* context, + RayQueryContext* context, const LineSegments* geom, const Precalculations& pre, const Vec4vf<M>& v0i, const Vec4vf<M>& v1i, @@ -694,7 +694,7 @@ namespace embree template<typename Epilog> static __forceinline bool intersect(const vbool<M>& valid_i, RayK<K>& ray, size_t k, - IntersectContext* context, + RayQueryContext* context, const LineSegments* geom, const Precalculations& pre, const Vec4vf<M>& v0i, const Vec4vf<M>& v1i, diff --git a/thirdparty/embree/kernels/geometry/roundlinei_intersector.h b/thirdparty/embree/kernels/geometry/roundlinei_intersector.h index 29061d6475..02a5d63a3d 100644 --- a/thirdparty/embree/kernels/geometry/roundlinei_intersector.h +++ b/thirdparty/embree/kernels/geometry/roundlinei_intersector.h @@ -16,7 +16,7 @@ namespace embree typedef LineMi<M> Primitive; typedef CurvePrecalculations1 Precalculations; - static __forceinline void intersect(const Precalculations& pre, RayHit& ray, IntersectContext* context, const Primitive& line) + static __forceinline void intersect(const Precalculations& pre, RayHit& ray, RayQueryContext* context, const Primitive& line) { STAT3(normal.trav_prims,1,1,1); const LineSegments* geom = context->scene->get<LineSegments>(line.geomID()); @@ -25,7 +25,7 @@ namespace embree RoundLinearCurveIntersector1<M>::intersect(valid,ray,context,geom,pre,v0,v1,vL,vR,Intersect1EpilogM<M,filter>(ray,context,line.geomID(),line.primID())); } - static __forceinline bool occluded(const Precalculations& pre, Ray& ray, IntersectContext* context, const Primitive& line) + static __forceinline bool occluded(const Precalculations& pre, Ray& ray, RayQueryContext* context, const Primitive& line) { STAT3(shadow.trav_prims,1,1,1); const LineSegments* geom = context->scene->get<LineSegments>(line.geomID()); @@ -46,7 +46,7 @@ namespace embree typedef LineMi<M> Primitive; typedef CurvePrecalculations1 Precalculations; - static __forceinline void intersect(const Precalculations& pre, RayHit& ray, IntersectContext* context, const Primitive& line) + static __forceinline void intersect(const Precalculations& pre, RayHit& ray, RayQueryContext* context, const Primitive& line) { STAT3(normal.trav_prims,1,1,1); const LineSegments* geom = context->scene->get<LineSegments>(line.geomID()); @@ -55,7 +55,7 @@ namespace embree RoundLinearCurveIntersector1<M>::intersect(valid,ray,context,geom,pre,v0,v1,vL,vR,Intersect1EpilogM<M,filter>(ray,context,line.geomID(),line.primID())); } - static __forceinline bool occluded(const Precalculations& pre, Ray& ray, IntersectContext* context, const Primitive& line) + static __forceinline bool occluded(const Precalculations& pre, Ray& ray, RayQueryContext* context, const Primitive& line) { STAT3(shadow.trav_prims,1,1,1); const LineSegments* geom = context->scene->get<LineSegments>(line.geomID()); @@ -76,7 +76,7 @@ namespace embree typedef LineMi<M> Primitive; typedef CurvePrecalculationsK<K> Precalculations; - static __forceinline void intersect(const Precalculations& pre, RayHitK<K>& ray, size_t k, IntersectContext* context, const Primitive& line) + static __forceinline void intersect(const Precalculations& pre, RayHitK<K>& ray, size_t k, RayQueryContext* context, const Primitive& line) { STAT3(normal.trav_prims,1,1,1); const LineSegments* geom = context->scene->get<LineSegments>(line.geomID()); @@ -85,7 +85,7 @@ namespace embree RoundLinearCurveIntersectorK<M,K>::intersect(valid,ray,k,context,geom,pre,v0,v1,vL,vR,Intersect1KEpilogM<M,K,filter>(ray,k,context,line.geomID(),line.primID())); } - static __forceinline bool occluded(const Precalculations& pre, RayK<K>& ray, size_t k, IntersectContext* context, const Primitive& line) + static __forceinline bool occluded(const Precalculations& pre, RayK<K>& ray, size_t k, RayQueryContext* context, const Primitive& line) { STAT3(shadow.trav_prims,1,1,1); const LineSegments* geom = context->scene->get<LineSegments>(line.geomID()); @@ -101,7 +101,7 @@ namespace embree typedef LineMi<M> Primitive; typedef CurvePrecalculationsK<K> Precalculations; - static __forceinline void intersect(const Precalculations& pre, RayHitK<K>& ray, size_t k, IntersectContext* context, const Primitive& line) + static __forceinline void intersect(const Precalculations& pre, RayHitK<K>& ray, size_t k, RayQueryContext* context, const Primitive& line) { STAT3(normal.trav_prims,1,1,1); const LineSegments* geom = context->scene->get<LineSegments>(line.geomID()); @@ -110,7 +110,7 @@ namespace embree RoundLinearCurveIntersectorK<M,K>::intersect(valid,ray,k,context,geom,pre,v0,v1,vL,vR,Intersect1KEpilogM<M,K,filter>(ray,k,context,line.geomID(),line.primID())); } - static __forceinline bool occluded(const Precalculations& pre, RayK<K>& ray, size_t k, IntersectContext* context, const Primitive& line) + static __forceinline bool occluded(const Precalculations& pre, RayK<K>& ray, size_t k, RayQueryContext* context, const Primitive& line) { STAT3(shadow.trav_prims,1,1,1); const LineSegments* geom = context->scene->get<LineSegments>(line.geomID()); diff --git a/thirdparty/embree/kernels/geometry/sphere_intersector.h b/thirdparty/embree/kernels/geometry/sphere_intersector.h index 2670f9762d..ba242a88b6 100644 --- a/thirdparty/embree/kernels/geometry/sphere_intersector.h +++ b/thirdparty/embree/kernels/geometry/sphere_intersector.h @@ -24,24 +24,60 @@ namespace embree __forceinline Vec2f uv(const size_t i) const { return Vec2f(0.0f, 0.0f); } + __forceinline Vec2vf<M> uv() const { + return Vec2vf<M>(0.0f, 0.0f); + } __forceinline float t(const size_t i) const { return vt[i]; } + __forceinline vfloat<M> t() const { + return vt; + } __forceinline Vec3fa Ng(const size_t i) const { return Vec3fa(vNg.x[i], vNg.y[i], vNg.z[i]); } + __forceinline Vec3vf<M> Ng() const { + return vNg; + } public: vfloat<M> vt; Vec3vf<M> vNg; }; + template<> + struct SphereIntersectorHitM<1> + { + __forceinline SphereIntersectorHitM() {} + + __forceinline SphereIntersectorHitM(const float& t, const Vec3f& Ng) + : vt(t), vNg(Ng) {} + + __forceinline void finalize() {} + + __forceinline Vec2f uv() const { + return Vec2f(0.0f, 0.0f); + } + + __forceinline float t() const { + return vt; + } + + __forceinline Vec3f Ng() const { + return vNg; + } + + public: + float vt; + Vec3f vNg; + }; + template<int M> struct SphereIntersector1 { typedef CurvePrecalculations1 Precalculations; - template<typename Epilog> + template<typename Ray, typename Epilog> static __forceinline bool intersect( const vbool<M>& valid_i, Ray& ray, const Precalculations& pre, const Vec4vf<M>& v0, const Epilog& epilog) @@ -68,10 +104,15 @@ namespace embree const vfloat<M> t_back = projC0 + td; const vbool<M> valid_front = valid & (ray.tnear() <= t_front) & (t_front <= ray.tfar); - const vbool<M> valid_back = valid & (ray.tnear() <= t_back ) & (t_back <= ray.tfar); /* check if there is a first hit */ +#if defined (EMBREE_BACKFACE_CULLING_SPHERES) + /* check if there is a first hit */ + const vbool<M> valid_first = valid_front; +#else + const vbool<M> valid_back = valid & (ray.tnear() <= t_back ) & (t_back <= ray.tfar); const vbool<M> valid_first = valid_front | valid_back; +#endif if (unlikely(none(valid_first))) return false; @@ -84,7 +125,10 @@ namespace embree /* invoke intersection filter for first hit */ const bool is_hit_first = epilog(valid_first, hit); - + +#if defined (EMBREE_BACKFACE_CULLING_SPHERES) + return is_hit_first; +#else /* check for possible second hits before potentially accepted hit */ const vfloat<M> t_second = t_back; const vbool<M> valid_second = valid_front & valid_back & (t_second <= ray.tfar); @@ -95,13 +139,13 @@ namespace embree const Vec3vf<M> Ng_second = td_back * ray_dir - perp; hit = SphereIntersectorHitM<M> (t_second, Ng_second); const bool is_hit_second = epilog(valid_second, hit); - return is_hit_first | is_hit_second; +#endif } template<typename Epilog> static __forceinline bool intersect( - const vbool<M>& valid_i, Ray& ray, IntersectContext* context, const Points* geom, + const vbool<M>& valid_i, Ray& ray, RayQueryContext* context, const Points* geom, const Precalculations& pre, const Vec4vf<M>& v0i, const Epilog& epilog) { const Vec3vf<M> ray_org(ray.org.x, ray.org.y, ray.org.z); @@ -118,7 +162,7 @@ namespace embree template<typename Epilog> static __forceinline bool intersect(const vbool<M>& valid_i, RayK<K>& ray, size_t k, - IntersectContext* context, + RayQueryContext* context, const Points* geom, const Precalculations& pre, const Vec4vf<M>& v0i, @@ -148,10 +192,14 @@ namespace embree const vfloat<M> t_back = projC0 + td; const vbool<M> valid_front = valid & (ray.tnear()[k] <= t_front) & (t_front <= ray.tfar[k]); - const vbool<M> valid_back = valid & (ray.tnear()[k] <= t_back ) & (t_back <= ray.tfar[k]); /* check if there is a first hit */ +#if defined (EMBREE_BACKFACE_CULLING_SPHERES) + const vbool<M> valid_first = valid_front; +#else + const vbool<M> valid_back = valid & (ray.tnear()[k] <= t_back ) & (t_back <= ray.tfar[k]); const vbool<M> valid_first = valid_front | valid_back; +#endif if (unlikely(none(valid_first))) return false; @@ -164,7 +212,10 @@ namespace embree /* invoke intersection filter for first hit */ const bool is_hit_first = epilog(valid_first, hit); - + +#if defined (EMBREE_BACKFACE_CULLING_SPHERES) + return is_hit_first; +#else /* check for possible second hits before potentially accepted hit */ const vfloat<M> t_second = t_back; const vbool<M> valid_second = valid_front & valid_back & (t_second <= ray.tfar[k]); @@ -177,6 +228,7 @@ namespace embree const bool is_hit_second = epilog(valid_second, hit); return is_hit_first | is_hit_second; +#endif } }; } // namespace isa diff --git a/thirdparty/embree/kernels/geometry/spherei_intersector.h b/thirdparty/embree/kernels/geometry/spherei_intersector.h index 7a0b428117..7072ea81e8 100644 --- a/thirdparty/embree/kernels/geometry/spherei_intersector.h +++ b/thirdparty/embree/kernels/geometry/spherei_intersector.h @@ -19,7 +19,7 @@ namespace embree static __forceinline void intersect(const Precalculations& pre, RayHit& ray, - IntersectContext* context, + RayQueryContext* context, const Primitive& sphere) { STAT3(normal.trav_prims, 1, 1, 1); @@ -32,7 +32,7 @@ namespace embree static __forceinline bool occluded(const Precalculations& pre, Ray& ray, - IntersectContext* context, + RayQueryContext* context, const Primitive& sphere) { STAT3(shadow.trav_prims, 1, 1, 1); @@ -59,7 +59,7 @@ namespace embree static __forceinline void intersect(const Precalculations& pre, RayHit& ray, - IntersectContext* context, + RayQueryContext* context, const Primitive& sphere) { STAT3(normal.trav_prims, 1, 1, 1); @@ -72,7 +72,7 @@ namespace embree static __forceinline bool occluded(const Precalculations& pre, Ray& ray, - IntersectContext* context, + RayQueryContext* context, const Primitive& sphere) { STAT3(shadow.trav_prims, 1, 1, 1); @@ -98,7 +98,7 @@ namespace embree typedef CurvePrecalculationsK<K> Precalculations; static __forceinline void intersect( - const Precalculations& pre, RayHitK<K>& ray, size_t k, IntersectContext* context, const Primitive& sphere) + const Precalculations& pre, RayHitK<K>& ray, size_t k, RayQueryContext* context, const Primitive& sphere) { STAT3(normal.trav_prims, 1, 1, 1); const Points* geom = context->scene->get<Points>(sphere.geomID()); @@ -110,7 +110,7 @@ namespace embree } static __forceinline bool occluded( - const Precalculations& pre, RayK<K>& ray, size_t k, IntersectContext* context, const Primitive& sphere) + const Precalculations& pre, RayK<K>& ray, size_t k, RayQueryContext* context, const Primitive& sphere) { STAT3(shadow.trav_prims, 1, 1, 1); const Points* geom = context->scene->get<Points>(sphere.geomID()); @@ -129,7 +129,7 @@ namespace embree typedef CurvePrecalculationsK<K> Precalculations; static __forceinline void intersect( - const Precalculations& pre, RayHitK<K>& ray, size_t k, IntersectContext* context, const Primitive& sphere) + const Precalculations& pre, RayHitK<K>& ray, size_t k, RayQueryContext* context, const Primitive& sphere) { STAT3(normal.trav_prims, 1, 1, 1); const Points* geom = context->scene->get<Points>(sphere.geomID()); @@ -141,7 +141,7 @@ namespace embree } static __forceinline bool occluded( - const Precalculations& pre, RayK<K>& ray, size_t k, IntersectContext* context, const Primitive& sphere) + const Precalculations& pre, RayK<K>& ray, size_t k, RayQueryContext* context, const Primitive& sphere) { STAT3(shadow.trav_prims, 1, 1, 1); const Points* geom = context->scene->get<Points>(sphere.geomID()); diff --git a/thirdparty/embree/kernels/geometry/subdivpatch1_intersector.h b/thirdparty/embree/kernels/geometry/subdivpatch1_intersector.h index b4b15a1210..cf17127169 100644 --- a/thirdparty/embree/kernels/geometry/subdivpatch1_intersector.h +++ b/thirdparty/embree/kernels/geometry/subdivpatch1_intersector.h @@ -35,7 +35,7 @@ namespace embree typedef GridSOA Primitive; typedef SubdivPatch1Precalculations<GridSOAIntersector1::Precalculations> Precalculations; - static __forceinline bool processLazyNode(Precalculations& pre, IntersectContext* context, const Primitive* prim, size_t& lazy_node) + static __forceinline bool processLazyNode(Precalculations& pre, RayQueryContext* context, const Primitive* prim, size_t& lazy_node) { lazy_node = prim->root(0); pre.grid = (Primitive*)prim; @@ -44,27 +44,27 @@ namespace embree /*! Intersect a ray with the primitive. */ template<int N, bool robust> - static __forceinline void intersect(const Accel::Intersectors* This, Precalculations& pre, RayHit& ray, IntersectContext* context, const Primitive* prim, size_t ty, const TravRay<N,robust> &tray, size_t& lazy_node) + static __forceinline void intersect(const Accel::Intersectors* This, Precalculations& pre, RayHit& ray, RayQueryContext* context, const Primitive* prim, size_t ty, const TravRay<N,robust> &tray, size_t& lazy_node) { if (likely(ty == 0)) GridSOAIntersector1::intersect(pre,ray,context,prim,lazy_node); else processLazyNode(pre,context,prim,lazy_node); } template<int N, bool robust> - static __forceinline void intersect(const Accel::Intersectors* This, Precalculations& pre, RayHit& ray, IntersectContext* context, size_t ty0, const Primitive* prim, size_t ty, const TravRay<N,robust> &tray, size_t& lazy_node) { + static __forceinline void intersect(const Accel::Intersectors* This, Precalculations& pre, RayHit& ray, RayQueryContext* context, size_t ty0, const Primitive* prim, size_t ty, const TravRay<N,robust> &tray, size_t& lazy_node) { intersect(This,pre,ray,context,prim,ty,tray,lazy_node); } /*! Test if the ray is occluded by the primitive */ template<int N, bool robust> - static __forceinline bool occluded(const Accel::Intersectors* This, Precalculations& pre, Ray& ray, IntersectContext* context, const Primitive* prim, size_t ty, const TravRay<N,robust> &tray, size_t& lazy_node) + static __forceinline bool occluded(const Accel::Intersectors* This, Precalculations& pre, Ray& ray, RayQueryContext* context, const Primitive* prim, size_t ty, const TravRay<N,robust> &tray, size_t& lazy_node) { if (likely(ty == 0)) return GridSOAIntersector1::occluded(pre,ray,context,prim,lazy_node); else return processLazyNode(pre,context,prim,lazy_node); } template<int N, bool robust> - static __forceinline bool occluded(const Accel::Intersectors* This, Precalculations& pre, Ray& ray, IntersectContext* context, size_t ty0, const Primitive* prim, size_t ty, const TravRay<N,robust> &tray, size_t& lazy_node) { + static __forceinline bool occluded(const Accel::Intersectors* This, Precalculations& pre, Ray& ray, RayQueryContext* context, size_t ty0, const Primitive* prim, size_t ty, const TravRay<N,robust> &tray, size_t& lazy_node) { return occluded(This,pre,ray,context,prim,ty,tray,lazy_node); } @@ -88,7 +88,7 @@ namespace embree typedef SubdivPatch1 Primitive; typedef GridSOAMBIntersector1::Precalculations Precalculations; - static __forceinline bool processLazyNode(Precalculations& pre, Ray& ray, IntersectContext* context, const Primitive* prim_i, size_t& lazy_node) + static __forceinline bool processLazyNode(Precalculations& pre, Ray& ray, RayQueryContext* context, const Primitive* prim_i, size_t& lazy_node) { Primitive* prim = (Primitive*) prim_i; GridSOA* grid = nullptr; @@ -101,27 +101,27 @@ namespace embree /*! Intersect a ray with the primitive. */ template<int N, bool robust> - static __forceinline void intersect(const Accel::Intersectors* This, Precalculations& pre, RayHit& ray, IntersectContext* context, const Primitive* prim, size_t ty, const TravRay<N,robust> &tray, size_t& lazy_node) + static __forceinline void intersect(const Accel::Intersectors* This, Precalculations& pre, RayHit& ray, RayQueryContext* context, const Primitive* prim, size_t ty, const TravRay<N,robust> &tray, size_t& lazy_node) { if (likely(ty == 0)) GridSOAMBIntersector1::intersect(pre,ray,context,prim,lazy_node); else processLazyNode(pre,ray,context,prim,lazy_node); } template<int N, bool robust> - static __forceinline void intersect(const Accel::Intersectors* This, Precalculations& pre, RayHit& ray, IntersectContext* context, size_t ty0, const Primitive* prim, size_t ty, const TravRay<N,robust> &tray, size_t& lazy_node) { + static __forceinline void intersect(const Accel::Intersectors* This, Precalculations& pre, RayHit& ray, RayQueryContext* context, size_t ty0, const Primitive* prim, size_t ty, const TravRay<N,robust> &tray, size_t& lazy_node) { intersect(This,pre,ray,context,prim,ty,tray,lazy_node); } /*! Test if the ray is occluded by the primitive */ template<int N, bool robust> - static __forceinline bool occluded(const Accel::Intersectors* This, Precalculations& pre, Ray& ray, IntersectContext* context, const Primitive* prim, size_t ty, const TravRay<N,robust> &tray, size_t& lazy_node) + static __forceinline bool occluded(const Accel::Intersectors* This, Precalculations& pre, Ray& ray, RayQueryContext* context, const Primitive* prim, size_t ty, const TravRay<N,robust> &tray, size_t& lazy_node) { if (likely(ty == 0)) return GridSOAMBIntersector1::occluded(pre,ray,context,prim,lazy_node); else return processLazyNode(pre,ray,context,prim,lazy_node); } template<int N, bool robust> - static __forceinline bool occluded(const Accel::Intersectors* This, Precalculations& pre, Ray& ray, IntersectContext* context, size_t ty0, const Primitive* prim, size_t ty, const TravRay<N,robust> &tray, size_t& lazy_node) { + static __forceinline bool occluded(const Accel::Intersectors* This, Precalculations& pre, Ray& ray, RayQueryContext* context, size_t ty0, const Primitive* prim, size_t ty, const TravRay<N,robust> &tray, size_t& lazy_node) { return occluded(This,pre,ray,context,prim,ty,tray,lazy_node); } @@ -145,7 +145,7 @@ namespace embree typedef GridSOA Primitive; typedef SubdivPatch1PrecalculationsK<K,typename GridSOAIntersectorK<K>::Precalculations> Precalculations; - static __forceinline bool processLazyNode(Precalculations& pre, IntersectContext* context, const Primitive* prim, size_t& lazy_node) + static __forceinline bool processLazyNode(Precalculations& pre, RayQueryContext* context, const Primitive* prim, size_t& lazy_node) { lazy_node = prim->root(0); pre.grid = (Primitive*)prim; @@ -153,28 +153,28 @@ namespace embree } template<bool robust> - static __forceinline void intersect(const vbool<K>& valid, const Accel::Intersectors* This, Precalculations& pre, RayHitK<K>& ray, IntersectContext* context, const Primitive* prim, size_t ty, const TravRayK<K, robust> &tray, size_t& lazy_node) + static __forceinline void intersect(const vbool<K>& valid, const Accel::Intersectors* This, Precalculations& pre, RayHitK<K>& ray, RayQueryContext* context, const Primitive* prim, size_t ty, const TravRayK<K, robust> &tray, size_t& lazy_node) { if (likely(ty == 0)) GridSOAIntersectorK<K>::intersect(valid,pre,ray,context,prim,lazy_node); else processLazyNode(pre,context,prim,lazy_node); } template<bool robust> - static __forceinline vbool<K> occluded(const vbool<K>& valid, const Accel::Intersectors* This, Precalculations& pre, RayK<K>& ray, IntersectContext* context, const Primitive* prim, size_t ty, const TravRayK<K, robust> &tray, size_t& lazy_node) + static __forceinline vbool<K> occluded(const vbool<K>& valid, const Accel::Intersectors* This, Precalculations& pre, RayK<K>& ray, RayQueryContext* context, const Primitive* prim, size_t ty, const TravRayK<K, robust> &tray, size_t& lazy_node) { if (likely(ty == 0)) return GridSOAIntersectorK<K>::occluded(valid,pre,ray,context,prim,lazy_node); else return processLazyNode(pre,context,prim,lazy_node); } template<int N, bool robust> - static __forceinline void intersect(const Accel::Intersectors* This, Precalculations& pre, RayHitK<K>& ray, size_t k, IntersectContext* context, const Primitive* prim, size_t ty, const TravRay<N,robust> &tray, size_t& lazy_node) + static __forceinline void intersect(const Accel::Intersectors* This, Precalculations& pre, RayHitK<K>& ray, size_t k, RayQueryContext* context, const Primitive* prim, size_t ty, const TravRay<N,robust> &tray, size_t& lazy_node) { if (likely(ty == 0)) GridSOAIntersectorK<K>::intersect(pre,ray,k,context,prim,lazy_node); else processLazyNode(pre,context,prim,lazy_node); } template<int N, bool robust> - static __forceinline bool occluded(const Accel::Intersectors* This, Precalculations& pre, RayK<K>& ray, size_t k, IntersectContext* context, const Primitive* prim, size_t ty, const TravRay<N,robust> &tray, size_t& lazy_node) + static __forceinline bool occluded(const Accel::Intersectors* This, Precalculations& pre, RayK<K>& ray, size_t k, RayQueryContext* context, const Primitive* prim, size_t ty, const TravRay<N,robust> &tray, size_t& lazy_node) { if (likely(ty == 0)) return GridSOAIntersectorK<K>::occluded(pre,ray,k,context,prim,lazy_node); else return processLazyNode(pre,context,prim,lazy_node); @@ -192,7 +192,7 @@ namespace embree //typedef GridSOAMBIntersectorK<K>::Precalculations Precalculations; typedef SubdivPatch1PrecalculationsK<K,typename GridSOAMBIntersectorK<K>::Precalculations> Precalculations; - static __forceinline bool processLazyNode(Precalculations& pre, IntersectContext* context, const Primitive* prim_i, size_t& lazy_node) + static __forceinline bool processLazyNode(Precalculations& pre, RayQueryContext* context, const Primitive* prim_i, size_t& lazy_node) { Primitive* prim = (Primitive*) prim_i; GridSOA* grid = (GridSOA*) prim->root_ref.get(); @@ -202,28 +202,28 @@ namespace embree } template<bool robust> - static __forceinline void intersect(const vbool<K>& valid, const Accel::Intersectors* This, Precalculations& pre, RayHitK<K>& ray, IntersectContext* context, const Primitive* prim, size_t ty, const TravRayK<K, robust> &tray, size_t& lazy_node) + static __forceinline void intersect(const vbool<K>& valid, const Accel::Intersectors* This, Precalculations& pre, RayHitK<K>& ray, RayQueryContext* context, const Primitive* prim, size_t ty, const TravRayK<K, robust> &tray, size_t& lazy_node) { if (likely(ty == 0)) GridSOAMBIntersectorK<K>::intersect(valid,pre,ray,context,prim,lazy_node); else processLazyNode(pre,context,prim,lazy_node); } template<bool robust> - static __forceinline vbool<K> occluded(const vbool<K>& valid, const Accel::Intersectors* This, Precalculations& pre, RayK<K>& ray, IntersectContext* context, const Primitive* prim, size_t ty, const TravRayK<K, robust> &tray, size_t& lazy_node) + static __forceinline vbool<K> occluded(const vbool<K>& valid, const Accel::Intersectors* This, Precalculations& pre, RayK<K>& ray, RayQueryContext* context, const Primitive* prim, size_t ty, const TravRayK<K, robust> &tray, size_t& lazy_node) { if (likely(ty == 0)) return GridSOAMBIntersectorK<K>::occluded(valid,pre,ray,context,prim,lazy_node); else return processLazyNode(pre,context,prim,lazy_node); } template<int N, bool robust> - static __forceinline void intersect(const Accel::Intersectors* This, Precalculations& pre, RayHitK<K>& ray, size_t k, IntersectContext* context, const Primitive* prim, size_t ty, const TravRay<N,robust> &tray, size_t& lazy_node) + static __forceinline void intersect(const Accel::Intersectors* This, Precalculations& pre, RayHitK<K>& ray, size_t k, RayQueryContext* context, const Primitive* prim, size_t ty, const TravRay<N,robust> &tray, size_t& lazy_node) { if (likely(ty == 0)) GridSOAMBIntersectorK<K>::intersect(pre,ray,k,context,prim,lazy_node); else processLazyNode(pre,context,prim,lazy_node); } template<int N, bool robust> - static __forceinline bool occluded(const Accel::Intersectors* This, Precalculations& pre, RayK<K>& ray, size_t k, IntersectContext* context, const Primitive* prim, size_t ty, const TravRay<N,robust> &tray, size_t& lazy_node) + static __forceinline bool occluded(const Accel::Intersectors* This, Precalculations& pre, RayK<K>& ray, size_t k, RayQueryContext* context, const Primitive* prim, size_t ty, const TravRay<N,robust> &tray, size_t& lazy_node) { if (likely(ty == 0)) return GridSOAMBIntersectorK<K>::occluded(pre,ray,k,context,prim,lazy_node); else return processLazyNode(pre,context,prim,lazy_node); diff --git a/thirdparty/embree/kernels/geometry/subgrid.h b/thirdparty/embree/kernels/geometry/subgrid.h index ce54421cab..f57e55db78 100644 --- a/thirdparty/embree/kernels/geometry/subgrid.h +++ b/thirdparty/embree/kernels/geometry/subgrid.h @@ -283,7 +283,7 @@ namespace embree friend embree_ostream operator<<(embree_ostream cout, const SubGrid& sg) { - return cout << "SubGrid " << " ( x " << sg.x() << ", y = " << sg.y() << ", geomID = " << sg.geomID() << ", primID = " << sg.primID() << " )"; + return cout << "SubGrid " << " ( x = " << sg.x() << ", y = " << sg.y() << ", geomID = " << sg.geomID() << ", primID = " << sg.primID() << ", invalid3x3X() " << (int)sg.invalid3x3X() << ", invalid3x3Y() " << (int)sg.invalid3x3Y(); } __forceinline unsigned int geomID() const { return _geomID; } @@ -305,9 +305,10 @@ namespace embree __forceinline SubGridID() {} __forceinline SubGridID(const unsigned int x, const unsigned int y, const unsigned int primID) : - x(x), y(y), primID(primID) {} + x(x), y(y), primID(primID) {} + }; - + /* QuantizedBaseNode as large subgrid leaf */ template<int N> struct SubGridQBVHN @@ -403,6 +404,9 @@ namespace embree typedef SubGridQBVHN<8> SubGridQBVH8; + + + /* QuantizedBaseNode as large subgrid leaf */ template<int N> struct SubGridMBQBVHN @@ -513,5 +517,4 @@ namespace embree } }; - } diff --git a/thirdparty/embree/kernels/geometry/subgrid_intersector.h b/thirdparty/embree/kernels/geometry/subgrid_intersector.h index e241073812..561d3d43f2 100644 --- a/thirdparty/embree/kernels/geometry/subgrid_intersector.h +++ b/thirdparty/embree/kernels/geometry/subgrid_intersector.h @@ -23,7 +23,7 @@ namespace embree typedef SubGridQBVHN<N> Primitive; typedef SubGridQuadMIntersector1MoellerTrumbore<4,filter> Precalculations; - static __forceinline void intersect(const Precalculations& pre, RayHit& ray, IntersectContext* context, const SubGrid& subgrid) + static __forceinline void intersect(const Precalculations& pre, RayHit& ray, RayQueryContext* context, const SubGrid& subgrid) { STAT3(normal.trav_prims,1,1,1); const GridMesh* mesh = context->scene->get<GridMesh>(subgrid.geomID()); @@ -33,7 +33,7 @@ namespace embree pre.intersect(ray,context,v0,v1,v2,v3,g,subgrid); } - static __forceinline bool occluded(const Precalculations& pre, Ray& ray, IntersectContext* context, const SubGrid& subgrid) + static __forceinline bool occluded(const Precalculations& pre, Ray& ray, RayQueryContext* context, const SubGrid& subgrid) { STAT3(shadow.trav_prims,1,1,1); const GridMesh* mesh = context->scene->get<GridMesh>(subgrid.geomID()); @@ -54,7 +54,7 @@ namespace embree } template<bool robust> - static __forceinline void intersect(const Accel::Intersectors* This, Precalculations& pre, RayHit& ray, IntersectContext* context, const Primitive* prim, size_t num, const TravRay<N,robust> &tray, size_t& lazy_node) + static __forceinline void intersect(const Accel::Intersectors* This, Precalculations& pre, RayHit& ray, RayQueryContext* context, const Primitive* prim, size_t num, const TravRay<N,robust> &tray, size_t& lazy_node) { BVHNQuantizedBaseNodeIntersector1<N,robust> isec1; @@ -76,7 +76,7 @@ namespace embree } } template<bool robust> - static __forceinline bool occluded(const Accel::Intersectors* This, Precalculations& pre, Ray& ray, IntersectContext* context, const Primitive* prim, size_t num, const TravRay<N,robust> &tray, size_t& lazy_node) + static __forceinline bool occluded(const Accel::Intersectors* This, Precalculations& pre, Ray& ray, RayQueryContext* context, const Primitive* prim, size_t num, const TravRay<N,robust> &tray, size_t& lazy_node) { BVHNQuantizedBaseNodeIntersector1<N,robust> isec1; @@ -126,7 +126,7 @@ namespace embree typedef SubGridQBVHN<N> Primitive; typedef SubGridQuadMIntersector1Pluecker<4,filter> Precalculations; - static __forceinline void intersect(const Precalculations& pre, RayHit& ray, IntersectContext* context, const SubGrid& subgrid) + static __forceinline void intersect(const Precalculations& pre, RayHit& ray, RayQueryContext* context, const SubGrid& subgrid) { STAT3(normal.trav_prims,1,1,1); const GridMesh* mesh = context->scene->get<GridMesh>(subgrid.geomID()); @@ -136,7 +136,7 @@ namespace embree pre.intersect(ray,context,v0,v1,v2,v3,g,subgrid); } - static __forceinline bool occluded(const Precalculations& pre, Ray& ray, IntersectContext* context, const SubGrid& subgrid) + static __forceinline bool occluded(const Precalculations& pre, Ray& ray, RayQueryContext* context, const SubGrid& subgrid) { STAT3(shadow.trav_prims,1,1,1); const GridMesh* mesh = context->scene->get<GridMesh>(subgrid.geomID()); @@ -156,7 +156,7 @@ namespace embree } template<bool robust> - static __forceinline void intersect(const Accel::Intersectors* This, Precalculations& pre, RayHit& ray, IntersectContext* context, const Primitive* prim, size_t num, const TravRay<N,robust> &tray, size_t& lazy_node) + static __forceinline void intersect(const Accel::Intersectors* This, Precalculations& pre, RayHit& ray, RayQueryContext* context, const Primitive* prim, size_t num, const TravRay<N,robust> &tray, size_t& lazy_node) { BVHNQuantizedBaseNodeIntersector1<N,robust> isec1; @@ -179,7 +179,7 @@ namespace embree } template<bool robust> - static __forceinline bool occluded(const Accel::Intersectors* This, Precalculations& pre, Ray& ray, IntersectContext* context, const Primitive* prim, size_t num, const TravRay<N,robust> &tray, size_t& lazy_node) + static __forceinline bool occluded(const Accel::Intersectors* This, Precalculations& pre, Ray& ray, RayQueryContext* context, const Primitive* prim, size_t num, const TravRay<N,robust> &tray, size_t& lazy_node) { BVHNQuantizedBaseNodeIntersector1<N,robust> isec1; @@ -231,7 +231,7 @@ namespace embree typedef SubGridQBVHN<N> Primitive; typedef SubGridQuadMIntersectorKMoellerTrumbore<4,K,filter> Precalculations; - static __forceinline void intersect(const vbool<K>& valid_i, Precalculations& pre, RayHitK<K>& ray, IntersectContext* context, const SubGrid& subgrid) + static __forceinline void intersect(const vbool<K>& valid_i, Precalculations& pre, RayHitK<K>& ray, RayQueryContext* context, const SubGrid& subgrid) { Vec3fa vtx[16]; const GridMesh* mesh = context->scene->get<GridMesh>(subgrid.geomID()); @@ -249,7 +249,7 @@ namespace embree } } - static __forceinline vbool<K> occluded(const vbool<K>& valid_i, Precalculations& pre, RayK<K>& ray, IntersectContext* context, const SubGrid& subgrid) + static __forceinline vbool<K> occluded(const vbool<K>& valid_i, Precalculations& pre, RayK<K>& ray, RayQueryContext* context, const SubGrid& subgrid) { vbool<K> valid0 = valid_i; Vec3fa vtx[16]; @@ -270,7 +270,7 @@ namespace embree return !valid0; } - static __forceinline void intersect(Precalculations& pre, RayHitK<K>& ray, size_t k, IntersectContext* context, const SubGrid& subgrid) + static __forceinline void intersect(Precalculations& pre, RayHitK<K>& ray, size_t k, RayQueryContext* context, const SubGrid& subgrid) { STAT3(normal.trav_prims,1,1,1); const GridMesh* mesh = context->scene->get<GridMesh>(subgrid.geomID()); @@ -280,7 +280,7 @@ namespace embree pre.intersect1(ray,k,context,v0,v1,v2,v3,g,subgrid); } - static __forceinline bool occluded(Precalculations& pre, RayK<K>& ray, size_t k, IntersectContext* context, const SubGrid& subgrid) + static __forceinline bool occluded(Precalculations& pre, RayK<K>& ray, size_t k, RayQueryContext* context, const SubGrid& subgrid) { STAT3(shadow.trav_prims,1,1,1); const GridMesh* mesh = context->scene->get<GridMesh>(subgrid.geomID()); @@ -290,7 +290,7 @@ namespace embree } template<bool robust> - static __forceinline void intersect(const vbool<K>& valid, const Accel::Intersectors* This, Precalculations& pre, RayHitK<K>& ray, IntersectContext* context, const Primitive* prim, size_t num, const TravRayK<K, robust> &tray, size_t& lazy_node) + static __forceinline void intersect(const vbool<K>& valid, const Accel::Intersectors* This, Precalculations& pre, RayHitK<K>& ray, RayQueryContext* context, const Primitive* prim, size_t num, const TravRayK<K, robust> &tray, size_t& lazy_node) { BVHNQuantizedBaseNodeIntersectorK<N,K,robust> isecK; for (size_t j=0;j<num;j++) @@ -307,7 +307,7 @@ namespace embree } template<bool robust> - static __forceinline vbool<K> occluded(const vbool<K>& valid, const Accel::Intersectors* This, Precalculations& pre, RayK<K>& ray, IntersectContext* context, const Primitive* prim, size_t num, const TravRayK<K, robust> &tray, size_t& lazy_node) + static __forceinline vbool<K> occluded(const vbool<K>& valid, const Accel::Intersectors* This, Precalculations& pre, RayK<K>& ray, RayQueryContext* context, const Primitive* prim, size_t num, const TravRayK<K, robust> &tray, size_t& lazy_node) { BVHNQuantizedBaseNodeIntersectorK<N,K,robust> isecK; vbool<K> valid0 = valid; @@ -327,7 +327,7 @@ namespace embree } template<bool robust> - static __forceinline void intersect(const Accel::Intersectors* This, Precalculations& pre, RayHitK<K>& ray, size_t k, IntersectContext* context, const Primitive* prim, size_t num, const TravRay<N,robust> &tray, size_t& lazy_node) + static __forceinline void intersect(const Accel::Intersectors* This, Precalculations& pre, RayHitK<K>& ray, size_t k, RayQueryContext* context, const Primitive* prim, size_t num, const TravRay<N,robust> &tray, size_t& lazy_node) { BVHNQuantizedBaseNodeIntersector1<N,robust> isec1; @@ -347,7 +347,7 @@ namespace embree } template<bool robust> - static __forceinline bool occluded(const Accel::Intersectors* This, Precalculations& pre, RayK<K>& ray, size_t k, IntersectContext* context, const Primitive* prim, size_t num, const TravRay<N,robust> &tray, size_t& lazy_node) + static __forceinline bool occluded(const Accel::Intersectors* This, Precalculations& pre, RayK<K>& ray, size_t k, RayQueryContext* context, const Primitive* prim, size_t num, const TravRay<N,robust> &tray, size_t& lazy_node) { BVHNQuantizedBaseNodeIntersector1<N,robust> isec1; @@ -375,7 +375,7 @@ namespace embree typedef SubGridQBVHN<N> Primitive; typedef SubGridQuadMIntersectorKPluecker<4,K,filter> Precalculations; - static __forceinline void intersect(const vbool<K>& valid_i, Precalculations& pre, RayHitK<K>& ray, IntersectContext* context, const SubGrid& subgrid) + static __forceinline void intersect(const vbool<K>& valid_i, Precalculations& pre, RayHitK<K>& ray, RayQueryContext* context, const SubGrid& subgrid) { Vec3fa vtx[16]; const GridMesh* mesh = context->scene->get<GridMesh>(subgrid.geomID()); @@ -393,7 +393,7 @@ namespace embree } } - static __forceinline vbool<K> occluded(const vbool<K>& valid_i, Precalculations& pre, RayK<K>& ray, IntersectContext* context, const SubGrid& subgrid) + static __forceinline vbool<K> occluded(const vbool<K>& valid_i, Precalculations& pre, RayK<K>& ray, RayQueryContext* context, const SubGrid& subgrid) { vbool<K> valid0 = valid_i; Vec3fa vtx[16]; @@ -414,7 +414,7 @@ namespace embree return !valid0; } - static __forceinline void intersect(Precalculations& pre, RayHitK<K>& ray, size_t k, IntersectContext* context, const SubGrid& subgrid) + static __forceinline void intersect(Precalculations& pre, RayHitK<K>& ray, size_t k, RayQueryContext* context, const SubGrid& subgrid) { STAT3(normal.trav_prims,1,1,1); const GridMesh* mesh = context->scene->get<GridMesh>(subgrid.geomID()); @@ -424,7 +424,7 @@ namespace embree pre.intersect1(ray,k,context,v0,v1,v2,v3,g,subgrid); } - static __forceinline bool occluded(Precalculations& pre, RayK<K>& ray, size_t k, IntersectContext* context, const SubGrid& subgrid) + static __forceinline bool occluded(Precalculations& pre, RayK<K>& ray, size_t k, RayQueryContext* context, const SubGrid& subgrid) { STAT3(shadow.trav_prims,1,1,1); const GridMesh* mesh = context->scene->get<GridMesh>(subgrid.geomID()); @@ -434,7 +434,7 @@ namespace embree } template<bool robust> - static __forceinline void intersect(const vbool<K>& valid, const Accel::Intersectors* This, Precalculations& pre, RayHitK<K>& ray, IntersectContext* context, const Primitive* prim, size_t num, const TravRayK<K, robust> &tray, size_t& lazy_node) + static __forceinline void intersect(const vbool<K>& valid, const Accel::Intersectors* This, Precalculations& pre, RayHitK<K>& ray, RayQueryContext* context, const Primitive* prim, size_t num, const TravRayK<K, robust> &tray, size_t& lazy_node) { BVHNQuantizedBaseNodeIntersectorK<N,K,robust> isecK; for (size_t j=0;j<num;j++) @@ -451,7 +451,7 @@ namespace embree } template<bool robust> - static __forceinline vbool<K> occluded(const vbool<K>& valid, const Accel::Intersectors* This, Precalculations& pre, RayK<K>& ray, IntersectContext* context, const Primitive* prim, size_t num, const TravRayK<K, robust> &tray, size_t& lazy_node) + static __forceinline vbool<K> occluded(const vbool<K>& valid, const Accel::Intersectors* This, Precalculations& pre, RayK<K>& ray, RayQueryContext* context, const Primitive* prim, size_t num, const TravRayK<K, robust> &tray, size_t& lazy_node) { BVHNQuantizedBaseNodeIntersectorK<N,K,robust> isecK; vbool<K> valid0 = valid; @@ -471,7 +471,7 @@ namespace embree } template<bool robust> - static __forceinline void intersect(const Accel::Intersectors* This, Precalculations& pre, RayHitK<K>& ray, size_t k, IntersectContext* context, const Primitive* prim, size_t num, const TravRay<N,robust> &tray, size_t& lazy_node) + static __forceinline void intersect(const Accel::Intersectors* This, Precalculations& pre, RayHitK<K>& ray, size_t k, RayQueryContext* context, const Primitive* prim, size_t num, const TravRay<N,robust> &tray, size_t& lazy_node) { BVHNQuantizedBaseNodeIntersector1<N,robust> isec1; @@ -491,7 +491,7 @@ namespace embree } template<bool robust> - static __forceinline bool occluded(const Accel::Intersectors* This, Precalculations& pre, RayK<K>& ray, size_t k, IntersectContext* context, const Primitive* prim, size_t num, const TravRay<N,robust> &tray, size_t& lazy_node) + static __forceinline bool occluded(const Accel::Intersectors* This, Precalculations& pre, RayK<K>& ray, size_t k, RayQueryContext* context, const Primitive* prim, size_t num, const TravRay<N,robust> &tray, size_t& lazy_node) { BVHNQuantizedBaseNodeIntersector1<N,robust> isec1; diff --git a/thirdparty/embree/kernels/geometry/subgrid_intersector_moeller.h b/thirdparty/embree/kernels/geometry/subgrid_intersector_moeller.h index 64937d34fe..2666847333 100644 --- a/thirdparty/embree/kernels/geometry/subgrid_intersector_moeller.h +++ b/thirdparty/embree/kernels/geometry/subgrid_intersector_moeller.h @@ -39,7 +39,7 @@ namespace embree __forceinline SubGridQuadMIntersector1MoellerTrumbore(const Ray& ray, const void* ptr) {} - __forceinline void intersect(RayHit& ray, IntersectContext* context, + __forceinline void intersect(RayHit& ray, RayQueryContext* context, const Vec3vf<M>& v0, const Vec3vf<M>& v1, const Vec3vf<M>& v2, const Vec3vf<M>& v3, const GridMesh::Grid &g, const SubGrid& subgrid) const { @@ -65,7 +65,7 @@ namespace embree } } - __forceinline bool occluded(Ray& ray, IntersectContext* context, + __forceinline bool occluded(Ray& ray, RayQueryContext* context, const Vec3vf<M>& v0, const Vec3vf<M>& v1, const Vec3vf<M>& v2, const Vec3vf<M>& v3, const GridMesh::Grid &g, const SubGrid& subgrid) const { @@ -135,14 +135,14 @@ namespace embree return false; } - __forceinline bool intersect(RayHit& ray, IntersectContext* context, + __forceinline bool intersect(RayHit& ray, RayQueryContext* context, const Vec3vf4& v0, const Vec3vf4& v1, const Vec3vf4& v2, const Vec3vf4& v3, const GridMesh::Grid &g, const SubGrid& subgrid) const { return intersect(ray,v0,v1,v2,v3,g,subgrid,Intersect1EpilogMU<8,filter>(ray,context,subgrid.geomID(),subgrid.primID())); } - __forceinline bool occluded(Ray& ray, IntersectContext* context, + __forceinline bool occluded(Ray& ray, RayQueryContext* context, const Vec3vf4& v0, const Vec3vf4& v1, const Vec3vf4& v2, const Vec3vf4& v3, const GridMesh::Grid &g, const SubGrid& subgrid) const { @@ -270,7 +270,7 @@ namespace embree __forceinline SubGridQuadMIntersectorKMoellerTrumbore(const vbool<K>& valid, const RayK<K>& ray) : SubGridQuadMIntersectorKMoellerTrumboreBase<M,K,filter>(valid,ray) {} - __forceinline void intersect1(RayHitK<K>& ray, size_t k, IntersectContext* context, + __forceinline void intersect1(RayHitK<K>& ray, size_t k, RayQueryContext* context, const Vec3vf<M>& v0, const Vec3vf<M>& v1, const Vec3vf<M>& v2, const Vec3vf<M>& v3, const GridMesh::Grid &g, const SubGrid &subgrid) const { UVIdentity<M> mapUV; @@ -294,7 +294,7 @@ namespace embree } } - __forceinline bool occluded1(RayK<K>& ray, size_t k, IntersectContext* context, + __forceinline bool occluded1(RayK<K>& ray, size_t k, RayQueryContext* context, const Vec3vf<M>& v0, const Vec3vf<M>& v1, const Vec3vf<M>& v2, const Vec3vf<M>& v3, const GridMesh::Grid &g, const SubGrid &subgrid) const { UVIdentity<M> mapUV; @@ -361,13 +361,13 @@ namespace embree return false; } - __forceinline bool intersect1(RayHitK<K>& ray, size_t k, IntersectContext* context, + __forceinline bool intersect1(RayHitK<K>& ray, size_t k, RayQueryContext* context, const Vec3vf4& v0, const Vec3vf4& v1, const Vec3vf4& v2, const Vec3vf4& v3, const GridMesh::Grid &g, const SubGrid &subgrid) const { return intersect1(ray,k,v0,v1,v2,v3,g,subgrid,Intersect1KEpilogMU<8,K,filter>(ray,k,context,subgrid.geomID(),subgrid.primID())); } - __forceinline bool occluded1(RayK<K>& ray, size_t k, IntersectContext* context, + __forceinline bool occluded1(RayK<K>& ray, size_t k, RayQueryContext* context, const Vec3vf4& v0, const Vec3vf4& v1, const Vec3vf4& v2, const Vec3vf4& v3, const GridMesh::Grid &g, const SubGrid &subgrid) const { return intersect1(ray,k,v0,v1,v2,v3,g,subgrid,Occluded1KEpilogMU<8,K,filter>(ray,k,context,subgrid.geomID(),subgrid.primID())); diff --git a/thirdparty/embree/kernels/geometry/subgrid_intersector_pluecker.h b/thirdparty/embree/kernels/geometry/subgrid_intersector_pluecker.h index 5ded56e1f7..4919f927ae 100644 --- a/thirdparty/embree/kernels/geometry/subgrid_intersector_pluecker.h +++ b/thirdparty/embree/kernels/geometry/subgrid_intersector_pluecker.h @@ -36,7 +36,7 @@ namespace embree __forceinline SubGridQuadMIntersector1Pluecker(const Ray& ray, const void* ptr) {} - __forceinline void intersect(RayHit& ray, IntersectContext* context, + __forceinline void intersect(RayHit& ray, RayQueryContext* context, const Vec3vf<M>& v0, const Vec3vf<M>& v1, const Vec3vf<M>& v2, const Vec3vf<M>& v3, const GridMesh::Grid &g, const SubGrid& subgrid) const { @@ -63,7 +63,7 @@ namespace embree } } - __forceinline bool occluded(Ray& ray, IntersectContext* context, + __forceinline bool occluded(Ray& ray, RayQueryContext* context, const Vec3vf<M>& v0, const Vec3vf<M>& v1, const Vec3vf<M>& v2, const Vec3vf<M>& v3, const GridMesh::Grid &g, const SubGrid& subgrid) const { @@ -134,14 +134,14 @@ namespace embree return false; } - __forceinline bool intersect(RayHit& ray, IntersectContext* context, + __forceinline bool intersect(RayHit& ray, RayQueryContext* context, const Vec3vf4& v0, const Vec3vf4& v1, const Vec3vf4& v2, const Vec3vf4& v3, const GridMesh::Grid &g, const SubGrid& subgrid) const { return intersect(ray,v0,v1,v2,v3,g,subgrid,Intersect1EpilogMU<8,filter>(ray,context,subgrid.geomID(),subgrid.primID())); } - __forceinline bool occluded(Ray& ray, IntersectContext* context, + __forceinline bool occluded(Ray& ray, RayQueryContext* context, const Vec3vf4& v0, const Vec3vf4& v1, const Vec3vf4& v2, const Vec3vf4& v3, const GridMesh::Grid &g, const SubGrid& subgrid) const { @@ -255,7 +255,7 @@ namespace embree __forceinline SubGridQuadMIntersectorKPluecker(const vbool<K>& valid, const RayK<K>& ray) : SubGridQuadMIntersectorKPlueckerBase<M,K,filter>(valid,ray) {} - __forceinline void intersect1(RayHitK<K>& ray, size_t k, IntersectContext* context, + __forceinline void intersect1(RayHitK<K>& ray, size_t k, RayQueryContext* context, const Vec3vf<M>& v0, const Vec3vf<M>& v1, const Vec3vf<M>& v2, const Vec3vf<M>& v3, const GridMesh::Grid &g, const SubGrid &subgrid) const { UVIdentity<M> mapUV; @@ -280,7 +280,7 @@ namespace embree } } - __forceinline bool occluded1(RayK<K>& ray, size_t k, IntersectContext* context, + __forceinline bool occluded1(RayK<K>& ray, size_t k, RayQueryContext* context, const Vec3vf<M>& v0, const Vec3vf<M>& v1, const Vec3vf<M>& v2, const Vec3vf<M>& v3, const GridMesh::Grid &g, const SubGrid &subgrid) const { UVIdentity<M> mapUV; @@ -348,13 +348,13 @@ namespace embree return false; } - __forceinline bool intersect1(RayHitK<K>& ray, size_t k, IntersectContext* context, + __forceinline bool intersect1(RayHitK<K>& ray, size_t k, RayQueryContext* context, const Vec3vf4& v0, const Vec3vf4& v1, const Vec3vf4& v2, const Vec3vf4& v3, const GridMesh::Grid &g, const SubGrid &subgrid) const { return intersect1(ray,k,v0,v1,v2,v3,g,subgrid,Intersect1KEpilogMU<8,K,filter>(ray,k,context,subgrid.geomID(),subgrid.primID())); } - __forceinline bool occluded1(RayK<K>& ray, size_t k, IntersectContext* context, + __forceinline bool occluded1(RayK<K>& ray, size_t k, RayQueryContext* context, const Vec3vf4& v0, const Vec3vf4& v1, const Vec3vf4& v2, const Vec3vf4& v3, const GridMesh::Grid &g, const SubGrid &subgrid) const { return intersect1(ray,k,v0,v1,v2,v3,g,subgrid,Occluded1KEpilogMU<8,K,filter>(ray,k,context,subgrid.geomID(),subgrid.primID())); diff --git a/thirdparty/embree/kernels/geometry/subgrid_mb_intersector.h b/thirdparty/embree/kernels/geometry/subgrid_mb_intersector.h index 473d656e24..0986eea134 100644 --- a/thirdparty/embree/kernels/geometry/subgrid_mb_intersector.h +++ b/thirdparty/embree/kernels/geometry/subgrid_mb_intersector.h @@ -15,7 +15,7 @@ namespace embree typedef SubGridMBQBVHN<N> Primitive; typedef SubGridQuadMIntersector1Pluecker<4,filter> Precalculations; - static __forceinline void intersect(const Precalculations& pre, RayHit& ray, IntersectContext* context, const SubGrid& subgrid) + static __forceinline void intersect(const Precalculations& pre, RayHit& ray, RayQueryContext* context, const SubGrid& subgrid) { STAT3(normal.trav_prims,1,1,1); const GridMesh* mesh = context->scene->get<GridMesh>(subgrid.geomID()); @@ -27,7 +27,7 @@ namespace embree pre.intersect(ray,context,v0,v1,v2,v3,g,subgrid); } - static __forceinline bool occluded(const Precalculations& pre, Ray& ray, IntersectContext* context, const SubGrid& subgrid) + static __forceinline bool occluded(const Precalculations& pre, Ray& ray, RayQueryContext* context, const SubGrid& subgrid) { STAT3(shadow.trav_prims,1,1,1); const GridMesh* mesh = context->scene->get<GridMesh>(subgrid.geomID()); @@ -46,7 +46,7 @@ namespace embree } template<bool robust> - static __forceinline void intersect(const Accel::Intersectors* This, Precalculations& pre, RayHit& ray, IntersectContext* context, const Primitive* prim, size_t num, const TravRay<N,robust> &tray, size_t& lazy_node) + static __forceinline void intersect(const Accel::Intersectors* This, Precalculations& pre, RayHit& ray, RayQueryContext* context, const Primitive* prim, size_t num, const TravRay<N,robust> &tray, size_t& lazy_node) { BVHNQuantizedBaseNodeIntersector1<N,robust> isec1; for (size_t i=0;i<num;i++) @@ -69,7 +69,7 @@ namespace embree } template<bool robust> - static __forceinline bool occluded(const Accel::Intersectors* This, Precalculations& pre, Ray& ray, IntersectContext* context, const Primitive* prim, size_t num, const TravRay<N,robust> &tray, size_t& lazy_node) + static __forceinline bool occluded(const Accel::Intersectors* This, Precalculations& pre, Ray& ray, RayQueryContext* context, const Primitive* prim, size_t num, const TravRay<N,robust> &tray, size_t& lazy_node) { BVHNQuantizedBaseNodeIntersector1<N,robust> isec1; for (size_t i=0;i<num;i++) @@ -102,7 +102,7 @@ namespace embree typedef SubGridMBQBVHN<N> Primitive; typedef SubGridQuadMIntersectorKPluecker<4,K,filter> Precalculations; - static __forceinline void intersect(const vbool<K>& valid_i, Precalculations& pre, RayHitK<K>& ray, IntersectContext* context, const SubGrid& subgrid) + static __forceinline void intersect(const vbool<K>& valid_i, Precalculations& pre, RayHitK<K>& ray, RayQueryContext* context, const SubGrid& subgrid) { size_t m_valid = movemask(valid_i); while(m_valid) @@ -112,7 +112,7 @@ namespace embree } } - static __forceinline vbool<K> occluded(const vbool<K>& valid_i, Precalculations& pre, RayK<K>& ray, IntersectContext* context, const SubGrid& subgrid) + static __forceinline vbool<K> occluded(const vbool<K>& valid_i, Precalculations& pre, RayK<K>& ray, RayQueryContext* context, const SubGrid& subgrid) { vbool<K> valid0 = valid_i; size_t m_valid = movemask(valid_i); @@ -125,7 +125,7 @@ namespace embree return !valid0; } - static __forceinline void intersect(Precalculations& pre, RayHitK<K>& ray, size_t k, IntersectContext* context, const SubGrid& subgrid) + static __forceinline void intersect(Precalculations& pre, RayHitK<K>& ray, size_t k, RayQueryContext* context, const SubGrid& subgrid) { STAT3(normal.trav_prims,1,1,1); const GridMesh* mesh = context->scene->get<GridMesh>(subgrid.geomID()); @@ -137,7 +137,7 @@ namespace embree pre.intersect1(ray,k,context,v0,v1,v2,v3,g,subgrid); } - static __forceinline bool occluded(Precalculations& pre, RayK<K>& ray, size_t k, IntersectContext* context, const SubGrid& subgrid) + static __forceinline bool occluded(Precalculations& pre, RayK<K>& ray, size_t k, RayQueryContext* context, const SubGrid& subgrid) { STAT3(shadow.trav_prims,1,1,1); const GridMesh* mesh = context->scene->get<GridMesh>(subgrid.geomID()); @@ -150,7 +150,7 @@ namespace embree } template<bool robust> - static __forceinline void intersect(const vbool<K>& valid, const Accel::Intersectors* This, Precalculations& pre, RayHitK<K>& ray, IntersectContext* context, const Primitive* prim, size_t num, const TravRayK<K, robust> &tray, size_t& lazy_node) + static __forceinline void intersect(const vbool<K>& valid, const Accel::Intersectors* This, Precalculations& pre, RayHitK<K>& ray, RayQueryContext* context, const Primitive* prim, size_t num, const TravRayK<K, robust> &tray, size_t& lazy_node) { BVHNQuantizedBaseNodeIntersectorK<N,K,robust> isecK; for (size_t j=0;j<num;j++) @@ -169,7 +169,7 @@ namespace embree } template<bool robust> - static __forceinline vbool<K> occluded(const vbool<K>& valid, const Accel::Intersectors* This, Precalculations& pre, RayK<K>& ray, IntersectContext* context, const Primitive* prim, size_t num, const TravRayK<K, robust> &tray, size_t& lazy_node) + static __forceinline vbool<K> occluded(const vbool<K>& valid, const Accel::Intersectors* This, Precalculations& pre, RayK<K>& ray, RayQueryContext* context, const Primitive* prim, size_t num, const TravRayK<K, robust> &tray, size_t& lazy_node) { BVHNQuantizedBaseNodeIntersectorK<N,K,robust> isecK; @@ -191,7 +191,7 @@ namespace embree } template<bool robust> - static __forceinline void intersect(const Accel::Intersectors* This, Precalculations& pre, RayHitK<K>& ray, size_t k, IntersectContext* context, const Primitive* prim, size_t num, const TravRay<N,robust> &tray, size_t& lazy_node) + static __forceinline void intersect(const Accel::Intersectors* This, Precalculations& pre, RayHitK<K>& ray, size_t k, RayQueryContext* context, const Primitive* prim, size_t num, const TravRay<N,robust> &tray, size_t& lazy_node) { BVHNQuantizedBaseNodeIntersector1<N,robust> isec1; for (size_t i=0;i<num;i++) @@ -211,7 +211,7 @@ namespace embree } template<bool robust> - static __forceinline bool occluded(const Accel::Intersectors* This, Precalculations& pre, RayK<K>& ray, size_t k, IntersectContext* context, const Primitive* prim, size_t num, const TravRay<N,robust> &tray, size_t& lazy_node) + static __forceinline bool occluded(const Accel::Intersectors* This, Precalculations& pre, RayK<K>& ray, size_t k, RayQueryContext* context, const Primitive* prim, size_t num, const TravRay<N,robust> &tray, size_t& lazy_node) { BVHNQuantizedBaseNodeIntersector1<N,robust> isec1; diff --git a/thirdparty/embree/kernels/geometry/triangle_intersector.h b/thirdparty/embree/kernels/geometry/triangle_intersector.h index 2cdff78ec8..9d9ddc7cad 100644 --- a/thirdparty/embree/kernels/geometry/triangle_intersector.h +++ b/thirdparty/embree/kernels/geometry/triangle_intersector.h @@ -18,14 +18,14 @@ namespace embree typedef MoellerTrumboreIntersector1<M> Precalculations; /*! Intersect a ray with the M triangles and updates the hit. */ - static __forceinline void intersect(const Precalculations& pre, RayHit& ray, IntersectContext* context, const TriangleM<M>& tri) + static __forceinline void intersect(const Precalculations& pre, RayHit& ray, RayQueryContext* context, const TriangleM<M>& tri) { STAT3(normal.trav_prims,1,1,1); pre.intersectEdge(ray,tri.v0,tri.e1,tri.e2,UVIdentity<M>(),Intersect1EpilogM<M,filter>(ray,context,tri.geomID(),tri.primID())); } /*! Test if the ray is occluded by one of M triangles. */ - static __forceinline bool occluded(const Precalculations& pre, Ray& ray, IntersectContext* context, const TriangleM<M>& tri) + static __forceinline bool occluded(const Precalculations& pre, Ray& ray, RayQueryContext* context, const TriangleM<M>& tri) { STAT3(shadow.trav_prims,1,1,1); return pre.intersectEdge(ray,tri.v0,tri.e1,tri.e2,UVIdentity<M>(),Occluded1EpilogM<M,filter>(ray,context,tri.geomID(),tri.primID())); @@ -46,7 +46,7 @@ namespace embree typedef MoellerTrumboreIntersectorK<M,K> Precalculations; /*! Intersects K rays with M triangles. */ - static __forceinline void intersect(const vbool<K>& valid_i, Precalculations& pre, RayHitK<K>& ray, IntersectContext* context, const TriangleM<M>& tri) + static __forceinline void intersect(const vbool<K>& valid_i, Precalculations& pre, RayHitK<K>& ray, RayQueryContext* context, const TriangleM<M>& tri) { STAT_USER(0,TriangleM<M>::max_size()); for (size_t i=0; i<TriangleM<M>::max_size(); i++) @@ -61,7 +61,7 @@ namespace embree } /*! Test for K rays if they are occluded by any of the M triangles. */ - static __forceinline vbool<K> occluded(const vbool<K>& valid_i, Precalculations& pre, RayK<K>& ray, IntersectContext* context, const TriangleM<M>& tri) + static __forceinline vbool<K> occluded(const vbool<K>& valid_i, Precalculations& pre, RayK<K>& ray, RayQueryContext* context, const TriangleM<M>& tri) { vbool<K> valid0 = valid_i; @@ -79,14 +79,14 @@ namespace embree } /*! Intersect a ray with M triangles and updates the hit. */ - static __forceinline void intersect(Precalculations& pre, RayHitK<K>& ray, size_t k, IntersectContext* context, const TriangleM<M>& tri) + static __forceinline void intersect(Precalculations& pre, RayHitK<K>& ray, size_t k, RayQueryContext* context, const TriangleM<M>& tri) { STAT3(normal.trav_prims,1,1,1); pre.intersectEdge(ray,k,tri.v0,tri.e1,tri.e2,UVIdentity<M>(),Intersect1KEpilogM<M,K,filter>(ray,k,context,tri.geomID(),tri.primID())); } /*! Test if the ray is occluded by one of the M triangles. */ - static __forceinline bool occluded(Precalculations& pre, RayK<K>& ray, size_t k, IntersectContext* context, const TriangleM<M>& tri) + static __forceinline bool occluded(Precalculations& pre, RayK<K>& ray, size_t k, RayQueryContext* context, const TriangleM<M>& tri) { STAT3(shadow.trav_prims,1,1,1); return pre.intersectEdge(ray,k,tri.v0,tri.e1,tri.e2,UVIdentity<M>(),Occluded1KEpilogM<M,K,filter>(ray,k,context,tri.geomID(),tri.primID())); diff --git a/thirdparty/embree/kernels/geometry/triangle_intersector_moeller.h b/thirdparty/embree/kernels/geometry/triangle_intersector_moeller.h index 0a42d8f08b..87bf0cd069 100644 --- a/thirdparty/embree/kernels/geometry/triangle_intersector_moeller.h +++ b/thirdparty/embree/kernels/geometry/triangle_intersector_moeller.h @@ -77,18 +77,18 @@ namespace embree { /* calculate denominator */ vbool<M> valid = valid0; + const Vec3vf<M> O = Vec3vf<M>((Vec3fa)ray.org); const Vec3vf<M> D = Vec3vf<M>((Vec3fa)ray.dir); const Vec3vf<M> C = Vec3vf<M>(tri_v0) - O; const Vec3vf<M> R = cross(C,D); const vfloat<M> den = dot(Vec3vf<M>(tri_Ng),D); - const vfloat<M> absDen = abs(den); const vfloat<M> sgnDen = signmsk(den); - + /* perform edge tests */ - const vfloat<M> U = dot(R,Vec3vf<M>(tri_e2)) ^ sgnDen; - const vfloat<M> V = dot(R,Vec3vf<M>(tri_e1)) ^ sgnDen; + const vfloat<M> U = asFloat(asInt(dot(R,Vec3vf<M>(tri_e2))) ^ asInt(sgnDen)); + const vfloat<M> V = asFloat(asInt(dot(R,Vec3vf<M>(tri_e1))) ^ asInt(sgnDen)); /* perform backface culling */ #if defined(EMBREE_BACKFACE_CULLING) @@ -99,14 +99,15 @@ namespace embree if (likely(early_out && none(valid))) return false; /* perform depth test */ - const vfloat<M> T = dot(Vec3vf<M>(tri_Ng),C) ^ sgnDen; + const vfloat<M> T = asFloat(asInt(dot(Vec3vf<M>(tri_Ng),C)) ^ asInt(sgnDen)); + valid &= (absDen*vfloat<M>(ray.tnear()) < T) & (T <= absDen*vfloat<M>(ray.tfar)); if (likely(early_out && none(valid))) return false; /* update hit information */ new (&hit) MoellerTrumboreHitM<M,UVMapper>(valid,U,V,T,absDen,tri_Ng,mapUV); - return true; + return early_out || any(valid); } template<typename UVMapper> @@ -320,8 +321,7 @@ namespace embree const Vec3vf<K> Ng = cross(e2,e1); return intersectK(valid0,ray.org,ray.dir,ray.tnear(),ray.tfar,tri_v0,e1,e2,Ng,mapUV,hit); } - - + /*! Intersects K rays with one of M triangles. */ template<typename UVMapper, typename Epilog> __forceinline vbool<K> intersectK(const vbool<K>& valid0, diff --git a/thirdparty/embree/kernels/geometry/triangle_intersector_pluecker.h b/thirdparty/embree/kernels/geometry/triangle_intersector_pluecker.h index 8fbefcea88..e21f1fa4c8 100644 --- a/thirdparty/embree/kernels/geometry/triangle_intersector_pluecker.h +++ b/thirdparty/embree/kernels/geometry/triangle_intersector_pluecker.h @@ -78,7 +78,7 @@ namespace embree /* calculate vertices relative to ray origin */ const Vec3vf<M> O = Vec3vf<M>((Vec3fa)ray.org); - const Vec3vf<M> D = Vec3vf<M>((Vec3fa)ray.dir); + const Vec3vf<M> D = Vec3vf<M>((Vec3fa)ray.dir); const Vec3vf<M> v0 = tri_v0-O; const Vec3vf<M> v1 = tri_v1-O; const Vec3vf<M> v2 = tri_v2-O; @@ -114,7 +114,7 @@ namespace embree /* update hit information */ new (&hit) PlueckerHitM<M,UVMapper>(valid,U,V,UVW,t,Ng,mapUV); - return true; + return early_out || any(valid); } template<typename UVMapper> diff --git a/thirdparty/embree/kernels/geometry/triangle_intersector_woop.h b/thirdparty/embree/kernels/geometry/triangle_intersector_woop.h index f05dcc4537..03d23adc3d 100644 --- a/thirdparty/embree/kernels/geometry/triangle_intersector_woop.h +++ b/thirdparty/embree/kernels/geometry/triangle_intersector_woop.h @@ -64,7 +64,7 @@ namespace embree kx = (kz+1) % 3; ky = (kx+1) % 3; const float inv_dir_kz = rcp(ray.dir[kz]); - if (ray.dir[kz]) std::swap(kx,ky); + if (ray.dir[kz] < 0.0f) std::swap(kx,ky); S.x = ray.dir[kx] * inv_dir_kz; S.y = ray.dir[ky] * inv_dir_kz; S.z = inv_dir_kz; diff --git a/thirdparty/embree/kernels/geometry/trianglei_intersector.h b/thirdparty/embree/kernels/geometry/trianglei_intersector.h index f7deb9e72d..fa7f3ae43d 100644 --- a/thirdparty/embree/kernels/geometry/trianglei_intersector.h +++ b/thirdparty/embree/kernels/geometry/trianglei_intersector.h @@ -18,14 +18,14 @@ namespace embree typedef TriangleMi<M> Primitive; typedef MoellerTrumboreIntersector1<M> Precalculations; - static __forceinline void intersect(const Precalculations& pre, RayHit& ray, IntersectContext* context, const Primitive& tri) + static __forceinline void intersect(const Precalculations& pre, RayHit& ray, RayQueryContext* context, const Primitive& tri) { STAT3(normal.trav_prims,1,1,1); Vec3vf<M> v0, v1, v2; tri.gather(v0,v1,v2,context->scene); pre.intersect(ray,v0,v1,v2,Intersect1EpilogM<M,filter>(ray,context,tri.geomID(),tri.primID())); } - static __forceinline bool occluded(const Precalculations& pre, Ray& ray, IntersectContext* context, const Primitive& tri) + static __forceinline bool occluded(const Precalculations& pre, Ray& ray, RayQueryContext* context, const Primitive& tri) { STAT3(shadow.trav_prims,1,1,1); Vec3vf<M> v0, v1, v2; tri.gather(v0,v1,v2,context->scene); @@ -45,7 +45,7 @@ namespace embree typedef TriangleMi<M> Primitive; typedef MoellerTrumboreIntersectorK<M,K> Precalculations; - static __forceinline void intersect(const vbool<K>& valid_i, Precalculations& pre, RayHitK<K>& ray, IntersectContext* context, const Primitive& tri) + static __forceinline void intersect(const vbool<K>& valid_i, Precalculations& pre, RayHitK<K>& ray, RayQueryContext* context, const Primitive& tri) { const Scene* scene = context->scene; for (size_t i=0; i<Primitive::max_size(); i++) @@ -59,7 +59,7 @@ namespace embree } } - static __forceinline vbool<K> occluded(const vbool<K>& valid_i, Precalculations& pre, RayK<K>& ray, IntersectContext* context, const Primitive& tri) + static __forceinline vbool<K> occluded(const vbool<K>& valid_i, Precalculations& pre, RayK<K>& ray, RayQueryContext* context, const Primitive& tri) { vbool<K> valid0 = valid_i; const Scene* scene = context->scene; @@ -77,14 +77,14 @@ namespace embree return !valid0; } - static __forceinline void intersect(Precalculations& pre, RayHitK<K>& ray, size_t k, IntersectContext* context, const Primitive& tri) + static __forceinline void intersect(Precalculations& pre, RayHitK<K>& ray, size_t k, RayQueryContext* context, const Primitive& tri) { STAT3(normal.trav_prims,1,1,1); Vec3vf<M> v0, v1, v2; tri.gather(v0,v1,v2,context->scene); pre.intersect(ray,k,v0,v1,v2,Intersect1KEpilogM<M,K,filter>(ray,k,context,tri.geomID(),tri.primID())); } - static __forceinline bool occluded(Precalculations& pre, RayK<K>& ray, size_t k, IntersectContext* context, const Primitive& tri) + static __forceinline bool occluded(Precalculations& pre, RayK<K>& ray, size_t k, RayQueryContext* context, const Primitive& tri) { STAT3(shadow.trav_prims,1,1,1); Vec3vf<M> v0, v1, v2; tri.gather(v0,v1,v2,context->scene); @@ -99,14 +99,14 @@ namespace embree typedef TriangleMi<M> Primitive; typedef PlueckerIntersector1<M> Precalculations; - static __forceinline void intersect(const Precalculations& pre, RayHit& ray, IntersectContext* context, const Primitive& tri) + static __forceinline void intersect(const Precalculations& pre, RayHit& ray, RayQueryContext* context, const Primitive& tri) { STAT3(normal.trav_prims,1,1,1); Vec3vf<M> v0, v1, v2; tri.gather(v0,v1,v2,context->scene); pre.intersect(ray,v0,v1,v2,Intersect1EpilogM<M,filter>(ray,context,tri.geomID(),tri.primID())); } - static __forceinline bool occluded(const Precalculations& pre, Ray& ray, IntersectContext* context, const Primitive& tri) + static __forceinline bool occluded(const Precalculations& pre, Ray& ray, RayQueryContext* context, const Primitive& tri) { STAT3(shadow.trav_prims,1,1,1); Vec3vf<M> v0, v1, v2; tri.gather(v0,v1,v2,context->scene); @@ -126,7 +126,7 @@ namespace embree typedef TriangleMi<M> Primitive; typedef PlueckerIntersectorK<M,K> Precalculations; - static __forceinline void intersect(const vbool<K>& valid_i, Precalculations& pre, RayHitK<K>& ray, IntersectContext* context, const Primitive& tri) + static __forceinline void intersect(const vbool<K>& valid_i, Precalculations& pre, RayHitK<K>& ray, RayQueryContext* context, const Primitive& tri) { const Scene* scene = context->scene; for (size_t i=0; i<Primitive::max_size(); i++) @@ -140,7 +140,7 @@ namespace embree } } - static __forceinline vbool<K> occluded(const vbool<K>& valid_i, Precalculations& pre, RayK<K>& ray, IntersectContext* context, const Primitive& tri) + static __forceinline vbool<K> occluded(const vbool<K>& valid_i, Precalculations& pre, RayK<K>& ray, RayQueryContext* context, const Primitive& tri) { vbool<K> valid0 = valid_i; const Scene* scene = context->scene; @@ -158,14 +158,14 @@ namespace embree return !valid0; } - static __forceinline void intersect(Precalculations& pre, RayHitK<K>& ray, size_t k, IntersectContext* context, const Primitive& tri) + static __forceinline void intersect(Precalculations& pre, RayHitK<K>& ray, size_t k, RayQueryContext* context, const Primitive& tri) { STAT3(normal.trav_prims,1,1,1); Vec3vf<M> v0, v1, v2; tri.gather(v0,v1,v2,context->scene); pre.intersect(ray,k,v0,v1,v2,Intersect1KEpilogM<M,K,filter>(ray,k,context,tri.geomID(),tri.primID())); } - static __forceinline bool occluded(Precalculations& pre, RayK<K>& ray, size_t k, IntersectContext* context, const Primitive& tri) + static __forceinline bool occluded(Precalculations& pre, RayK<K>& ray, size_t k, RayQueryContext* context, const Primitive& tri) { STAT3(shadow.trav_prims,1,1,1); Vec3vf<M> v0, v1, v2; tri.gather(v0,v1,v2,context->scene); @@ -181,7 +181,7 @@ namespace embree typedef MoellerTrumboreIntersector1<M> Precalculations; /*! Intersect a ray with the M triangles and updates the hit. */ - static __forceinline void intersect(const Precalculations& pre, RayHit& ray, IntersectContext* context, const Primitive& tri) + static __forceinline void intersect(const Precalculations& pre, RayHit& ray, RayQueryContext* context, const Primitive& tri) { STAT3(normal.trav_prims,1,1,1); Vec3vf<M> v0,v1,v2; tri.gather(v0,v1,v2,context->scene,ray.time()); @@ -189,7 +189,7 @@ namespace embree } /*! Test if the ray is occluded by one of M triangles. */ - static __forceinline bool occluded(const Precalculations& pre, Ray& ray, IntersectContext* context, const Primitive& tri) + static __forceinline bool occluded(const Precalculations& pre, Ray& ray, RayQueryContext* context, const Primitive& tri) { STAT3(shadow.trav_prims,1,1,1); Vec3vf<M> v0,v1,v2; tri.gather(v0,v1,v2,context->scene,ray.time()); @@ -210,7 +210,7 @@ namespace embree typedef MoellerTrumboreIntersectorK<M,K> Precalculations; /*! Intersects K rays with M triangles. */ - static __forceinline void intersect(const vbool<K>& valid_i, Precalculations& pre, RayHitK<K>& ray, IntersectContext* context, const TriangleMi<M>& tri) + static __forceinline void intersect(const vbool<K>& valid_i, Precalculations& pre, RayHitK<K>& ray, RayQueryContext* context, const TriangleMi<M>& tri) { for (size_t i=0; i<TriangleMi<M>::max_size(); i++) { @@ -222,7 +222,7 @@ namespace embree } /*! Test for K rays if they are occluded by any of the M triangles. */ - static __forceinline vbool<K> occluded(const vbool<K>& valid_i, Precalculations& pre, RayK<K>& ray, IntersectContext* context, const TriangleMi<M>& tri) + static __forceinline vbool<K> occluded(const vbool<K>& valid_i, Precalculations& pre, RayK<K>& ray, RayQueryContext* context, const TriangleMi<M>& tri) { vbool<K> valid0 = valid_i; for (size_t i=0; i<TriangleMi<M>::max_size(); i++) @@ -237,7 +237,7 @@ namespace embree } /*! Intersect a ray with M triangles and updates the hit. */ - static __forceinline void intersect(Precalculations& pre, RayHitK<K>& ray, size_t k, IntersectContext* context, const TriangleMi<M>& tri) + static __forceinline void intersect(Precalculations& pre, RayHitK<K>& ray, size_t k, RayQueryContext* context, const TriangleMi<M>& tri) { STAT3(normal.trav_prims,1,1,1); Vec3vf<M> v0,v1,v2; tri.gather(v0,v1,v2,context->scene,ray.time()[k]); @@ -245,7 +245,7 @@ namespace embree } /*! Test if the ray is occluded by one of the M triangles. */ - static __forceinline bool occluded(Precalculations& pre, RayK<K>& ray, size_t k, IntersectContext* context, const TriangleMi<M>& tri) + static __forceinline bool occluded(Precalculations& pre, RayK<K>& ray, size_t k, RayQueryContext* context, const TriangleMi<M>& tri) { STAT3(shadow.trav_prims,1,1,1); Vec3vf<M> v0,v1,v2; tri.gather(v0,v1,v2,context->scene,ray.time()[k]); @@ -261,7 +261,7 @@ namespace embree typedef PlueckerIntersector1<M> Precalculations; /*! Intersect a ray with the M triangles and updates the hit. */ - static __forceinline void intersect(const Precalculations& pre, RayHit& ray, IntersectContext* context, const Primitive& tri) + static __forceinline void intersect(const Precalculations& pre, RayHit& ray, RayQueryContext* context, const Primitive& tri) { STAT3(normal.trav_prims,1,1,1); Vec3vf<M> v0,v1,v2; tri.gather(v0,v1,v2,context->scene,ray.time()); @@ -269,7 +269,7 @@ namespace embree } /*! Test if the ray is occluded by one of M triangles. */ - static __forceinline bool occluded(const Precalculations& pre, Ray& ray, IntersectContext* context, const Primitive& tri) + static __forceinline bool occluded(const Precalculations& pre, Ray& ray, RayQueryContext* context, const Primitive& tri) { STAT3(shadow.trav_prims,1,1,1); Vec3vf<M> v0,v1,v2; tri.gather(v0,v1,v2,context->scene,ray.time()); @@ -290,7 +290,7 @@ namespace embree typedef PlueckerIntersectorK<M,K> Precalculations; /*! Intersects K rays with M triangles. */ - static __forceinline void intersect(const vbool<K>& valid_i, Precalculations& pre, RayHitK<K>& ray, IntersectContext* context, const TriangleMi<M>& tri) + static __forceinline void intersect(const vbool<K>& valid_i, Precalculations& pre, RayHitK<K>& ray, RayQueryContext* context, const TriangleMi<M>& tri) { for (size_t i=0; i<TriangleMi<M>::max_size(); i++) { @@ -302,7 +302,7 @@ namespace embree } /*! Test for K rays if they are occluded by any of the M triangles. */ - static __forceinline vbool<K> occluded(const vbool<K>& valid_i, Precalculations& pre, RayK<K>& ray, IntersectContext* context, const TriangleMi<M>& tri) + static __forceinline vbool<K> occluded(const vbool<K>& valid_i, Precalculations& pre, RayK<K>& ray, RayQueryContext* context, const TriangleMi<M>& tri) { vbool<K> valid0 = valid_i; for (size_t i=0; i<TriangleMi<M>::max_size(); i++) @@ -317,7 +317,7 @@ namespace embree } /*! Intersect a ray with M triangles and updates the hit. */ - static __forceinline void intersect(Precalculations& pre, RayHitK<K>& ray, size_t k, IntersectContext* context, const TriangleMi<M>& tri) + static __forceinline void intersect(Precalculations& pre, RayHitK<K>& ray, size_t k, RayQueryContext* context, const TriangleMi<M>& tri) { STAT3(normal.trav_prims,1,1,1); Vec3vf<M> v0,v1,v2; tri.gather(v0,v1,v2,context->scene,ray.time()[k]); @@ -325,7 +325,7 @@ namespace embree } /*! Test if the ray is occluded by one of the M triangles. */ - static __forceinline bool occluded(Precalculations& pre, RayK<K>& ray, size_t k, IntersectContext* context, const TriangleMi<M>& tri) + static __forceinline bool occluded(Precalculations& pre, RayK<K>& ray, size_t k, RayQueryContext* context, const TriangleMi<M>& tri) { STAT3(shadow.trav_prims,1,1,1); Vec3vf<M> v0,v1,v2; tri.gather(v0,v1,v2,context->scene,ray.time()[k]); diff --git a/thirdparty/embree/kernels/geometry/trianglev_intersector.h b/thirdparty/embree/kernels/geometry/trianglev_intersector.h index 3abb7f8e32..0575bad388 100644 --- a/thirdparty/embree/kernels/geometry/trianglev_intersector.h +++ b/thirdparty/embree/kernels/geometry/trianglev_intersector.h @@ -20,14 +20,14 @@ namespace embree typedef MoellerTrumboreIntersector1<M> Precalculations; /*! Intersect a ray with M triangles and updates the hit. */ - static __forceinline void intersect(Precalculations& pre, RayHit& ray, IntersectContext* context, const Primitive& tri) + static __forceinline void intersect(Precalculations& pre, RayHit& ray, RayQueryContext* context, const Primitive& tri) { STAT3(normal.trav_prims,1,1,1); pre.intersect(ray,tri.v0,tri.v1,tri.v2,/*UVIdentity<M>(),*/Intersect1EpilogM<M,filter>(ray,context,tri.geomID(),tri.primID())); } /*! Test if the ray is occluded by one of the M triangles. */ - static __forceinline bool occluded(const Precalculations& pre, Ray& ray, IntersectContext* context, const Primitive& tri) + static __forceinline bool occluded(const Precalculations& pre, Ray& ray, RayQueryContext* context, const Primitive& tri) { STAT3(shadow.trav_prims,1,1,1); return pre.intersect(ray,tri.v0,tri.v1,tri.v2,/*UVIdentity<M>(),*/Occluded1EpilogM<M,filter>(ray,context,tri.geomID(),tri.primID())); @@ -48,14 +48,14 @@ namespace embree typedef WoopPrecalculations1<M> Precalculations; /*! Intersect a ray with M triangles and updates the hit. */ - static __forceinline void intersect(const Precalculations& pre, RayHit& ray, IntersectContext* context, const Primitive& tri) + static __forceinline void intersect(const Precalculations& pre, RayHit& ray, RayQueryContext* context, const Primitive& tri) { STAT3(normal.trav_prims,1,1,1); intersec::intersect(ray,pre,tri.v0,tri.v1,tri.v2,Intersect1EpilogM<M,filter>(ray,context,tri.geomID(),tri.primID())); } /*! Test if the ray is occluded by one of the M triangles. */ - static __forceinline bool occluded(const Precalculations& pre, Ray& ray, IntersectContext* context, const Primitive& tri) + static __forceinline bool occluded(const Precalculations& pre, Ray& ray, RayQueryContext* context, const Primitive& tri) { STAT3(shadow.trav_prims,1,1,1); return intersec::intersect(ray,pre,tri.v0,tri.v1,tri.v2,Occluded1EpilogM<M,filter>(ray,context,tri.geomID(),tri.primID())); @@ -76,7 +76,7 @@ namespace embree typedef MoellerTrumboreIntersectorK<M,K> Precalculations; /*! Intersects K rays with M triangles. */ - static __forceinline void intersect(const vbool<K>& valid_i, Precalculations& pre, RayHitK<K>& ray, IntersectContext* context, const Primitive& tri) + static __forceinline void intersect(const vbool<K>& valid_i, Precalculations& pre, RayHitK<K>& ray, RayQueryContext* context, const Primitive& tri) { for (size_t i=0; i<M; i++) { @@ -90,7 +90,7 @@ namespace embree } /*! Test for K rays if they are occluded by any of the M triangles. */ - static __forceinline vbool<K> occluded(const vbool<K>& valid_i, Precalculations& pre, RayK<K>& ray, IntersectContext* context, const Primitive& tri) + static __forceinline vbool<K> occluded(const vbool<K>& valid_i, Precalculations& pre, RayK<K>& ray, RayQueryContext* context, const Primitive& tri) { vbool<K> valid0 = valid_i; @@ -108,14 +108,14 @@ namespace embree } /*! Intersect a ray with M triangles and updates the hit. */ - static __forceinline void intersect(Precalculations& pre, RayHitK<K>& ray, size_t k, IntersectContext* context, const Primitive& tri) + static __forceinline void intersect(Precalculations& pre, RayHitK<K>& ray, size_t k, RayQueryContext* context, const Primitive& tri) { STAT3(normal.trav_prims,1,1,1); pre.intersect(ray,k,tri.v0,tri.v1,tri.v2,/*UVIdentity<M>(),*/Intersect1KEpilogM<M,K,filter>(ray,k,context,tri.geomID(),tri.primID())); //FIXME: M } /*! Test if the ray is occluded by one of the M triangles. */ - static __forceinline bool occluded(Precalculations& pre, RayK<K>& ray, size_t k, IntersectContext* context, const Primitive& tri) + static __forceinline bool occluded(Precalculations& pre, RayK<K>& ray, size_t k, RayQueryContext* context, const Primitive& tri) { STAT3(shadow.trav_prims,1,1,1); return pre.intersect(ray,k,tri.v0,tri.v1,tri.v2,/*UVIdentity<M>(),*/Occluded1KEpilogM<M,K,filter>(ray,k,context,tri.geomID(),tri.primID())); //FIXME: M @@ -130,14 +130,14 @@ namespace embree typedef PlueckerIntersector1<M> Precalculations; /*! Intersect a ray with M triangles and updates the hit. */ - static __forceinline void intersect(Precalculations& pre, RayHit& ray, IntersectContext* context, const Primitive& tri) + static __forceinline void intersect(Precalculations& pre, RayHit& ray, RayQueryContext* context, const Primitive& tri) { STAT3(normal.trav_prims,1,1,1); pre.intersect(ray,tri.v0,tri.v1,tri.v2,UVIdentity<M>(),Intersect1EpilogM<M,filter>(ray,context,tri.geomID(),tri.primID())); } /*! Test if the ray is occluded by one of the M triangles. */ - static __forceinline bool occluded(const Precalculations& pre, Ray& ray, IntersectContext* context, const Primitive& tri) + static __forceinline bool occluded(const Precalculations& pre, Ray& ray, RayQueryContext* context, const Primitive& tri) { STAT3(shadow.trav_prims,1,1,1); return pre.intersect(ray,tri.v0,tri.v1,tri.v2,UVIdentity<M>(),Occluded1EpilogM<M,filter>(ray,context,tri.geomID(),tri.primID())); @@ -157,7 +157,7 @@ namespace embree typedef PlueckerIntersectorK<M,K> Precalculations; /*! Intersects K rays with M triangles. */ - static __forceinline void intersect(const vbool<K>& valid_i, Precalculations& pre, RayHitK<K>& ray, IntersectContext* context, const Primitive& tri) + static __forceinline void intersect(const vbool<K>& valid_i, Precalculations& pre, RayHitK<K>& ray, RayQueryContext* context, const Primitive& tri) { for (size_t i=0; i<M; i++) { @@ -171,7 +171,7 @@ namespace embree } /*! Test for K rays if they are occluded by any of the M triangles. */ - static __forceinline vbool<K> occluded(const vbool<K>& valid_i, Precalculations& pre, RayK<K>& ray, IntersectContext* context, const Primitive& tri) + static __forceinline vbool<K> occluded(const vbool<K>& valid_i, Precalculations& pre, RayK<K>& ray, RayQueryContext* context, const Primitive& tri) { vbool<K> valid0 = valid_i; @@ -189,14 +189,14 @@ namespace embree } /*! Intersect a ray with M triangles and updates the hit. */ - static __forceinline void intersect(Precalculations& pre, RayHitK<K>& ray, size_t k, IntersectContext* context, const Primitive& tri) + static __forceinline void intersect(Precalculations& pre, RayHitK<K>& ray, size_t k, RayQueryContext* context, const Primitive& tri) { STAT3(normal.trav_prims,1,1,1); pre.intersect(ray,k,tri.v0,tri.v1,tri.v2,UVIdentity<M>(),Intersect1KEpilogM<M,K,filter>(ray,k,context,tri.geomID(),tri.primID())); } /*! Test if the ray is occluded by one of the M triangles. */ - static __forceinline bool occluded(Precalculations& pre, RayK<K>& ray, size_t k, IntersectContext* context, const Primitive& tri) + static __forceinline bool occluded(Precalculations& pre, RayK<K>& ray, size_t k, RayQueryContext* context, const Primitive& tri) { STAT3(shadow.trav_prims,1,1,1); return pre.intersect(ray,k,tri.v0,tri.v1,tri.v2,UVIdentity<M>(),Occluded1KEpilogM<M,K,filter>(ray,k,context,tri.geomID(),tri.primID())); diff --git a/thirdparty/embree/kernels/geometry/trianglev_mb.h b/thirdparty/embree/kernels/geometry/trianglev_mb.h index b550a29fd5..c15313f209 100644 --- a/thirdparty/embree/kernels/geometry/trianglev_mb.h +++ b/thirdparty/embree/kernels/geometry/trianglev_mb.h @@ -113,7 +113,6 @@ namespace embree BBox3fa bounds0 = empty; BBox3fa bounds1 = empty; - for (size_t i=0; i<M && begin<end; i++, begin++) { const PrimRef& prim = prims[begin]; @@ -121,12 +120,12 @@ namespace embree const unsigned primID = prim.primID(); const TriangleMesh* __restrict__ const mesh = scene->get<TriangleMesh>(geomID); const TriangleMesh::Triangle& tri = mesh->triangle(primID); - const Vec3fa& a0 = mesh->vertex(tri.v[0],itime+0); bounds0.extend(a0); - const Vec3fa& a1 = mesh->vertex(tri.v[0],itime+1); bounds1.extend(a1); - const Vec3fa& b0 = mesh->vertex(tri.v[1],itime+0); bounds0.extend(b0); - const Vec3fa& b1 = mesh->vertex(tri.v[1],itime+1); bounds1.extend(b1); - const Vec3fa& c0 = mesh->vertex(tri.v[2],itime+0); bounds0.extend(c0); - const Vec3fa& c1 = mesh->vertex(tri.v[2],itime+1); bounds1.extend(c1); + const Vec3fa& a0 = mesh->vertex(tri.v[0],size_t(itime+0)); bounds0.extend(a0); + const Vec3fa& a1 = mesh->vertex(tri.v[0],size_t(itime+1)); bounds1.extend(a1); + const Vec3fa& b0 = mesh->vertex(tri.v[1],size_t(itime+0)); bounds0.extend(b0); + const Vec3fa& b1 = mesh->vertex(tri.v[1],size_t(itime+1)); bounds1.extend(b1); + const Vec3fa& c0 = mesh->vertex(tri.v[2],size_t(itime+0)); bounds0.extend(c0); + const Vec3fa& c1 = mesh->vertex(tri.v[2],size_t(itime+1)); bounds1.extend(c1); vgeomID [i] = geomID; vprimID [i] = primID; va0.x[i] = a0.x; va0.y[i] = a0.y; va0.z[i] = a0.z; @@ -159,12 +158,12 @@ namespace embree const int ilower = itime_range.begin(); const TriangleMesh::Triangle& tri = mesh->triangle(primID); allBounds.extend(mesh->linearBounds(primID, time_range)); - const Vec3fa& a0 = mesh->vertex(tri.v[0],ilower+0); - const Vec3fa& a1 = mesh->vertex(tri.v[0],ilower+1); - const Vec3fa& b0 = mesh->vertex(tri.v[1],ilower+0); - const Vec3fa& b1 = mesh->vertex(tri.v[1],ilower+1); - const Vec3fa& c0 = mesh->vertex(tri.v[2],ilower+0); - const Vec3fa& c1 = mesh->vertex(tri.v[2],ilower+1); + const Vec3fa& a0 = mesh->vertex(tri.v[0],size_t(ilower+0)); + const Vec3fa& a1 = mesh->vertex(tri.v[0],size_t(ilower+1)); + const Vec3fa& b0 = mesh->vertex(tri.v[1],size_t(ilower+0)); + const Vec3fa& b1 = mesh->vertex(tri.v[1],size_t(ilower+1)); + const Vec3fa& c0 = mesh->vertex(tri.v[2],size_t(ilower+0)); + const Vec3fa& c1 = mesh->vertex(tri.v[2],size_t(ilower+1)); const BBox1f time_range_v(mesh->timeStep(ilower+0),mesh->timeStep(ilower+1)); auto a01 = globalLinear(std::make_pair(a0,a1),time_range_v); auto b01 = globalLinear(std::make_pair(b0,b1),time_range_v); diff --git a/thirdparty/embree/kernels/geometry/trianglev_mb_intersector.h b/thirdparty/embree/kernels/geometry/trianglev_mb_intersector.h index 38cd52e85d..c9042ba323 100644 --- a/thirdparty/embree/kernels/geometry/trianglev_mb_intersector.h +++ b/thirdparty/embree/kernels/geometry/trianglev_mb_intersector.h @@ -18,7 +18,7 @@ namespace embree typedef MoellerTrumboreIntersector1<M> Precalculations; /*! Intersect a ray with the M triangles and updates the hit. */ - static __forceinline void intersect(const Precalculations& pre, RayHit& ray, IntersectContext* context, const TriangleMvMB<M>& tri) + static __forceinline void intersect(const Precalculations& pre, RayHit& ray, RayQueryContext* context, const TriangleMvMB<M>& tri) { STAT3(normal.trav_prims,1,1,1); const Vec3vf<M> time(ray.time()); @@ -29,7 +29,7 @@ namespace embree } /*! Test if the ray is occluded by one of M triangles. */ - static __forceinline bool occluded(const Precalculations& pre, Ray& ray, IntersectContext* context, const TriangleMvMB<M>& tri) + static __forceinline bool occluded(const Precalculations& pre, Ray& ray, RayQueryContext* context, const TriangleMvMB<M>& tri) { STAT3(shadow.trav_prims,1,1,1); const Vec3vf<M> time(ray.time()); @@ -53,7 +53,7 @@ namespace embree typedef MoellerTrumboreIntersectorK<M,K> Precalculations; /*! Intersects K rays with M triangles. */ - static __forceinline void intersect(const vbool<K>& valid_i, Precalculations& pre, RayHitK<K>& ray, IntersectContext* context, const TriangleMvMB<M>& tri) + static __forceinline void intersect(const vbool<K>& valid_i, Precalculations& pre, RayHitK<K>& ray, RayQueryContext* context, const TriangleMvMB<M>& tri) { for (size_t i=0; i<TriangleMvMB<M>::max_size(); i++) { @@ -68,7 +68,7 @@ namespace embree } /*! Test for K rays if they are occluded by any of the M triangles. */ - static __forceinline vbool<K> occluded(const vbool<K>& valid_i, Precalculations& pre, RayK<K>& ray, IntersectContext* context, const TriangleMvMB<M>& tri) + static __forceinline vbool<K> occluded(const vbool<K>& valid_i, Precalculations& pre, RayK<K>& ray, RayQueryContext* context, const TriangleMvMB<M>& tri) { vbool<K> valid0 = valid_i; @@ -87,7 +87,7 @@ namespace embree } /*! Intersect a ray with M triangles and updates the hit. */ - static __forceinline void intersect(Precalculations& pre, RayHitK<K>& ray, size_t k, IntersectContext* context, const TriangleMvMB<M>& tri) + static __forceinline void intersect(Precalculations& pre, RayHitK<K>& ray, size_t k, RayQueryContext* context, const TriangleMvMB<M>& tri) { STAT3(normal.trav_prims,1,1,1); const Vec3vf<M> time(ray.time()[k]); @@ -98,7 +98,7 @@ namespace embree } /*! Test if the ray is occluded by one of the M triangles. */ - static __forceinline bool occluded(Precalculations& pre, RayK<K>& ray, size_t k, IntersectContext* context, const TriangleMvMB<M>& tri) + static __forceinline bool occluded(Precalculations& pre, RayK<K>& ray, size_t k, RayQueryContext* context, const TriangleMvMB<M>& tri) { STAT3(shadow.trav_prims,1,1,1); const Vec3vf<M> time(ray.time()[k]); @@ -117,7 +117,7 @@ namespace embree typedef PlueckerIntersector1<M> Precalculations; /*! Intersect a ray with the M triangles and updates the hit. */ - static __forceinline void intersect(const Precalculations& pre, RayHit& ray, IntersectContext* context, const TriangleMvMB<M>& tri) + static __forceinline void intersect(const Precalculations& pre, RayHit& ray, RayQueryContext* context, const TriangleMvMB<M>& tri) { STAT3(normal.trav_prims,1,1,1); const Vec3vf<M> time(ray.time()); @@ -128,7 +128,7 @@ namespace embree } /*! Test if the ray is occluded by one of M triangles. */ - static __forceinline bool occluded(const Precalculations& pre, Ray& ray, IntersectContext* context, const TriangleMvMB<M>& tri) + static __forceinline bool occluded(const Precalculations& pre, Ray& ray, RayQueryContext* context, const TriangleMvMB<M>& tri) { STAT3(shadow.trav_prims,1,1,1); const Vec3vf<M> time(ray.time()); @@ -152,7 +152,7 @@ namespace embree typedef PlueckerIntersectorK<M,K> Precalculations; /*! Intersects K rays with M triangles. */ - static __forceinline void intersect(const vbool<K>& valid_i, Precalculations& pre, RayHitK<K>& ray, IntersectContext* context, const TriangleMvMB<M>& tri) + static __forceinline void intersect(const vbool<K>& valid_i, Precalculations& pre, RayHitK<K>& ray, RayQueryContext* context, const TriangleMvMB<M>& tri) { for (size_t i=0; i<TriangleMvMB<M>::max_size(); i++) { @@ -167,7 +167,7 @@ namespace embree } /*! Test for K rays if they are occluded by any of the M triangles. */ - static __forceinline vbool<K> occluded(const vbool<K>& valid_i, Precalculations& pre, RayK<K>& ray, IntersectContext* context, const TriangleMvMB<M>& tri) + static __forceinline vbool<K> occluded(const vbool<K>& valid_i, Precalculations& pre, RayK<K>& ray, RayQueryContext* context, const TriangleMvMB<M>& tri) { vbool<K> valid0 = valid_i; @@ -186,7 +186,7 @@ namespace embree } /*! Intersect a ray with M triangles and updates the hit. */ - static __forceinline void intersect(Precalculations& pre, RayHitK<K>& ray, size_t k, IntersectContext* context, const TriangleMvMB<M>& tri) + static __forceinline void intersect(Precalculations& pre, RayHitK<K>& ray, size_t k, RayQueryContext* context, const TriangleMvMB<M>& tri) { STAT3(normal.trav_prims,1,1,1); const Vec3vf<M> time(ray.time()[k]); @@ -197,7 +197,7 @@ namespace embree } /*! Test if the ray is occluded by one of the M triangles. */ - static __forceinline bool occluded(Precalculations& pre, RayK<K>& ray, size_t k, IntersectContext* context, const TriangleMvMB<M>& tri) + static __forceinline bool occluded(Precalculations& pre, RayK<K>& ray, size_t k, RayQueryContext* context, const TriangleMvMB<M>& tri) { STAT3(shadow.trav_prims,1,1,1); const Vec3vf<M> time(ray.time()[k]); diff --git a/thirdparty/embree/kernels/hash.h b/thirdparty/embree/kernels/hash.h index 39d50e2354..ec9759ee35 100644 --- a/thirdparty/embree/kernels/hash.h +++ b/thirdparty/embree/kernels/hash.h @@ -1,4 +1,4 @@ // Copyright 2009-2021 Intel Corporation // SPDX-License-Identifier: Apache-2.0 -#define RTC_HASH "698442324ccddd11725fb8875275dc1384f7fb40" +#define RTC_HASH "daa8de0e714e18ad5e5c9841b67c1950d9c91c51" diff --git a/thirdparty/embree/kernels/subdiv/bezier_curve.h b/thirdparty/embree/kernels/subdiv/bezier_curve.h index a5adad5cc9..257e0afd40 100644 --- a/thirdparty/embree/kernels/subdiv/bezier_curve.h +++ b/thirdparty/embree/kernels/subdiv/bezier_curve.h @@ -185,9 +185,10 @@ namespace embree __forceinline CubicBezierCurve<float> xfm(const Vertex& dx) const { return CubicBezierCurve<float>(dot(v0,dx),dot(v1,dx),dot(v2,dx),dot(v3,dx)); } - - __forceinline CubicBezierCurve<vfloatx> vxfm(const Vertex& dx) const { - return CubicBezierCurve<vfloatx>(dot(v0,dx),dot(v1,dx),dot(v2,dx),dot(v3,dx)); + + template<int W> + __forceinline CubicBezierCurve<vfloat<W>> vxfm(const Vertex& dx) const { + return CubicBezierCurve<vfloat<W>>(dot(v0,dx),dot(v1,dx),dot(v2,dx),dot(v3,dx)); } __forceinline CubicBezierCurve<float> xfm(const Vertex& dx, const Vertex& p) const { @@ -286,7 +287,7 @@ namespace embree { const float u0 = 0.0f, u1 = 1.0f; const float dscale = (u1-u0)*(1.0f/(3.0f*(VSIZEX-1))); - const vfloatx vu0 = lerp(u0,u1,vfloatx(step)*(1.0f/(VSIZEX-1))); + const vfloatx vu0 = lerp(u0,u1,vfloatx(StepTy())*(1.0f/(VSIZEX-1))); Vec2vfx P0, dP0du; evalN(vu0,P0,dP0du); dP0du = dP0du * Vec2vfx(dscale); const Vec2vfx P3 = shift_right_1(P0); const Vec2vfx dP3du = shift_right_1(dP0du); @@ -299,7 +300,7 @@ namespace embree { const float u0 = u.lower, u1 = u.upper; const float dscale = (u1-u0)*(1.0f/(3.0f*(VSIZEX-1))); - const vfloatx vu0 = lerp(u0,u1,vfloatx(step)*(1.0f/(VSIZEX-1))); + const vfloatx vu0 = lerp(u0,u1,vfloatx(StepTy())*(1.0f/(VSIZEX-1))); Vec2vfx P0, dP0du; evalN(vu0,P0,dP0du); dP0du = dP0du * Vec2vfx(dscale); const Vec2vfx P3 = shift_right_1(P0); const Vec2vfx dP3du = shift_right_1(dP0du); @@ -307,6 +308,33 @@ namespace embree const Vec2vfx P2 = P3 - dP3du; return CubicBezierCurve<Vec2vfx>(P0,P1,P2,P3); } + + template<int W> + __forceinline CubicBezierCurve<Vec2vf<W>> split(const BBox1f& u, int i, int N) const + { + const float u0 = u.lower, u1 = u.upper; + const float dscale = (u1-u0)*(1.0f/(3.0f*N)); + const vfloat<W> vu0 = lerp(u0,u1,(vfloat<W>(i)+vfloat<W>(StepTy()))*(1.0f/N)); + Vec2vf<W> P0, dP0du; evalN(vu0,P0,dP0du); dP0du = dP0du * Vec2vf<W>(dscale); + const Vec2vf<W> P3 = shift_right_1(P0); + const Vec2vf<W> dP3du = shift_right_1(dP0du); + const Vec2vf<W> P1 = P0 + dP0du; + const Vec2vf<W> P2 = P3 - dP3du; + return CubicBezierCurve<Vec2vf<W>>(P0,P1,P2,P3); + } + + __forceinline CubicBezierCurve<Vec2f> split1(const BBox1f& u, int i, int N) const + { + const float u0 = u.lower, u1 = u.upper; + const float dscale = (u1-u0)*(1.0f/(3.0f*N)); + const float vu0 = lerp(u0,u1,(float(i)+0)*(1.0f/N)); + const float vu1 = lerp(u0,u1,(float(i)+1)*(1.0f/N)); + Vec2fa P0, dP0du; eval(vu0,P0,dP0du); dP0du = dP0du * Vec2fa(dscale); + Vec2fa P3, dP3du; eval(vu1,P3,dP3du); dP3du = dP3du * Vec2fa(dscale); + const Vec2fa P1 = P0 + dP0du; + const Vec2fa P2 = P3 - dP3du; + return CubicBezierCurve<Vec2f>(P0,P1,P2,P3); + } __forceinline void eval(float t, Vertex& p, Vertex& dp) const { @@ -461,20 +489,20 @@ namespace embree return madd(b.x, Vec4vf<M>(v0), madd(b.y, Vec4vf<M>(v1), madd(b.z, Vec4vf<M>(v2), b.w * Vec4vf<M>(v3)))); } - template<int M> - __forceinline void veval(const vfloat<M>& t, Vec4vf<M>& p, Vec4vf<M>& dp) const + template<int M, typename Vec> + __forceinline void veval(const vfloat<M>& t, Vec& p, Vec& dp) const { - const Vec4vf<M> p00 = v0; - const Vec4vf<M> p01 = v1; - const Vec4vf<M> p02 = v2; - const Vec4vf<M> p03 = v3; + const Vec p00 = v0; + const Vec p01 = v1; + const Vec p02 = v2; + const Vec p03 = v3; - const Vec4vf<M> p10 = lerp(p00,p01,t); - const Vec4vf<M> p11 = lerp(p01,p02,t); - const Vec4vf<M> p12 = lerp(p02,p03,t); - const Vec4vf<M> p20 = lerp(p10,p11,t); - const Vec4vf<M> p21 = lerp(p11,p12,t); - const Vec4vf<M> p30 = lerp(p20,p21,t); + const Vec p10 = lerp(p00,p01,t); + const Vec p11 = lerp(p01,p02,t); + const Vec p12 = lerp(p02,p03,t); + const Vec p20 = lerp(p10,p11,t); + const Vec p21 = lerp(p11,p12,t); + const Vec p30 = lerp(p20,p21,t); p = p30; dp = vfloat<M>(3.0f)*(p21-p20); @@ -485,10 +513,17 @@ namespace embree { assert(size <= PrecomputedBezierBasis::N); assert(ofs <= size); +#if defined(EMBREE_SYCL_SUPPORT) && defined(__SYCL_DEVICE_ONLY__) + assert(size > 0); + const vfloat<M> t = (vfloat<M>(step) + vfloat<M>(ofs+0))*rcp(float(size)); + Vec p,dp; veval<M>(t,p,dp); + return p; +#else return madd(vfloat<M>::loadu(&bezier_basis0.c0[size][ofs]), Vec(v0), madd(vfloat<M>::loadu(&bezier_basis0.c1[size][ofs]), Vec(v1), madd(vfloat<M>::loadu(&bezier_basis0.c2[size][ofs]), Vec(v2), vfloat<M>::loadu(&bezier_basis0.c3[size][ofs]) * Vec(v3)))); +#endif } template<int M, typename Vec = Vec4vf<M>> @@ -496,10 +531,17 @@ namespace embree { assert(size <= PrecomputedBezierBasis::N); assert(ofs <= size); +#if defined(EMBREE_SYCL_SUPPORT) && defined(__SYCL_DEVICE_ONLY__) + assert(size > 0); + const vfloat<M> t = (vfloat<M>(step) + vfloat<M>(ofs+1))*rcp(float(size)); + Vec p,dp; veval<M>(t,p,dp); + return p; +#else return madd(vfloat<M>::loadu(&bezier_basis1.c0[size][ofs]), Vec(v0), madd(vfloat<M>::loadu(&bezier_basis1.c1[size][ofs]), Vec(v1), madd(vfloat<M>::loadu(&bezier_basis1.c2[size][ofs]), Vec(v2), vfloat<M>::loadu(&bezier_basis1.c3[size][ofs]) * Vec(v3)))); +#endif } template<int M, typename Vec = Vec4vf<M>> @@ -507,10 +549,17 @@ namespace embree { assert(size <= PrecomputedBezierBasis::N); assert(ofs <= size); +#if defined(EMBREE_SYCL_SUPPORT) && defined(__SYCL_DEVICE_ONLY__) + assert(size > 0); + const vfloat<M> t = (vfloat<M>(step) + vfloat<M>(ofs+0))*rcp(float(size)); + Vec p,dp; veval<M>(t,p,dp); + return dp; +#else return madd(vfloat<M>::loadu(&bezier_basis0.d0[size][ofs]), Vec(v0), madd(vfloat<M>::loadu(&bezier_basis0.d1[size][ofs]), Vec(v1), madd(vfloat<M>::loadu(&bezier_basis0.d2[size][ofs]), Vec(v2), vfloat<M>::loadu(&bezier_basis0.d3[size][ofs]) * Vec(v3)))); +#endif } template<int M, typename Vec = Vec4vf<M>> @@ -518,10 +567,17 @@ namespace embree { assert(size <= PrecomputedBezierBasis::N); assert(ofs <= size); +#if defined(EMBREE_SYCL_SUPPORT) && defined(__SYCL_DEVICE_ONLY__) + assert(size > 0); + const vfloat<M> t = (vfloat<M>(step) + vfloat<M>(ofs+1))*rcp(float(size)); + Vec p,dp; veval<M>(t,p,dp); + return dp; +#else return madd(vfloat<M>::loadu(&bezier_basis1.d0[size][ofs]), Vec(v0), madd(vfloat<M>::loadu(&bezier_basis1.d1[size][ofs]), Vec(v1), madd(vfloat<M>::loadu(&bezier_basis1.d2[size][ofs]), Vec(v2), vfloat<M>::loadu(&bezier_basis1.d3[size][ofs]) * Vec(v3)))); +#endif } /* calculates bounds of bezier curve geometry */ @@ -532,7 +588,7 @@ namespace embree Vec3vfx pl(pos_inf), pu(neg_inf); for (int i=0; i<=N; i+=VSIZEX) { - vintx vi = vintx(i)+vintx(step); + vintx vi = vintx(i)+vintx(StepTy()); vboolx valid = vi <= vintx(N); const Vec3vfx p = eval0<VSIZEX,Vec3vf<VSIZEX>>(i,N); const Vec3vfx dp = derivative0<VSIZEX,Vec3vf<VSIZEX>>(i,N); @@ -554,7 +610,7 @@ namespace embree Vec4vfx pl(pos_inf), pu(neg_inf); for (int i=0; i<=N; i+=VSIZEX) { - vintx vi = vintx(i)+vintx(step); + vintx vi = vintx(i)+vintx(StepTy()); vboolx valid = vi <= vintx(N); const Vec4vfx p = eval0<VSIZEX>(i,N); const Vec4vfx dp = derivative0<VSIZEX>(i,N); @@ -587,7 +643,7 @@ namespace embree Vec3vfx pl(pos_inf), pu(neg_inf); vfloatx ru(0.0f); for (int i=0; i<N; i+=VSIZEX) { - vboolx valid = vintx(i)+vintx(step) < vintx(N); + vboolx valid = vintx(i)+vintx(StepTy()) < vintx(N); const Vec4vfx pi = eval0<VSIZEX>(i,N); pl.x = select(valid,min(pl.x,pi.x),pl.x); // FIXME: use masked min @@ -645,6 +701,7 @@ namespace embree typedef CubicBezierCurve<Vec2fa> CubicBezierCurve2fa; typedef CubicBezierCurve<Vec3fa> CubicBezierCurve3fa; typedef CubicBezierCurve<Vec3fa> BezierCurve3fa; + typedef CubicBezierCurve<Vec3ff> BezierCurve3ff; template<> __forceinline int CubicBezierCurve<float>::maxRoots() const { @@ -660,8 +717,9 @@ namespace embree return numRoots(v0,v1) + numRoots(v1,v2) + numRoots(v2,v3); } + struct CurveGeometry; // FIXME: this code should move ! template<typename CurveGeometry> - __forceinline CubicBezierCurve<Vec3ff> enlargeRadiusToMinWidth(const IntersectContext* context, const CurveGeometry* geom, const Vec3fa& ray_org, const CubicBezierCurve<Vec3ff>& curve) + __forceinline CubicBezierCurve<Vec3ff> enlargeRadiusToMinWidth(const RayQueryContext* context, const CurveGeometry* geom, const Vec3fa& ray_org, const CubicBezierCurve<Vec3ff>& curve) { return CubicBezierCurve<Vec3ff>(enlargeRadiusToMinWidth(context,geom,ray_org,curve.v0), enlargeRadiusToMinWidth(context,geom,ray_org,curve.v1), diff --git a/thirdparty/embree/kernels/subdiv/bspline_curve.h b/thirdparty/embree/kernels/subdiv/bspline_curve.h index 51489ef37c..5d25ebb8e4 100644 --- a/thirdparty/embree/kernels/subdiv/bspline_curve.h +++ b/thirdparty/embree/kernels/subdiv/bspline_curve.h @@ -129,6 +129,12 @@ namespace embree const Vec4<float> b = BSplineBasis::derivative2(t); return madd(b.x,v0,madd(b.y,v1,madd(b.z,v2,b.w*v3))); } + + __forceinline void eval(const float t, Vertex& p, Vertex& dp) const + { + p = eval(t); + dp = eval_du(t); + } __forceinline void eval(const float t, Vertex& p, Vertex& dp, Vertex& ddp) const { @@ -307,7 +313,7 @@ namespace embree } template<typename CurveGeometry> - __forceinline BSplineCurveT<Vec3ff> enlargeRadiusToMinWidth(const IntersectContext* context, const CurveGeometry* geom, const Vec3fa& ray_org, const BSplineCurveT<Vec3ff>& curve) + __forceinline BSplineCurveT<Vec3ff> enlargeRadiusToMinWidth(const RayQueryContext* context, const CurveGeometry* geom, const Vec3fa& ray_org, const BSplineCurveT<Vec3ff>& curve) { return BSplineCurveT<Vec3ff>(enlargeRadiusToMinWidth(context,geom,ray_org,curve.v0), enlargeRadiusToMinWidth(context,geom,ray_org,curve.v1), diff --git a/thirdparty/embree/kernels/subdiv/catmullrom_curve.h b/thirdparty/embree/kernels/subdiv/catmullrom_curve.h index 9532287d98..c42435b9d7 100644 --- a/thirdparty/embree/kernels/subdiv/catmullrom_curve.h +++ b/thirdparty/embree/kernels/subdiv/catmullrom_curve.h @@ -4,12 +4,13 @@ #pragma once #include "../common/default.h" +#include "bezier_curve.h" #include "../common/scene_curves.h" /* - Implements Catmull-Rom curves with control points p0, p1, p2, p3. At - t=0 the curve goes through p1, with tangent (p2-p0)/3, and for t=1 + Implements Catmul Rom curves with control points p0, p1, p2, p3. At + t=0 the curve goes through p1, with tangent (p2-p0)/2, and for t=1 the curve goes through p2 with tangent (p3-p2)/2. */ @@ -99,7 +100,7 @@ namespace embree } __forceinline Vertex center() const { - return 0.25f*(v0+v1+v2+v3); + return 0.5f*(v0+v1); } __forceinline BBox<Vertex> bounds() const { @@ -136,6 +137,12 @@ namespace embree const Vec4<float> b = CatmullRomBasis::derivative2(t); return madd(b.x,v0,madd(b.y,v1,madd(b.z,v2,b.w*v3))); } + + __forceinline void eval(const float t, Vertex& p, Vertex& dp) const + { + p = eval(t); + dp = eval_du(t); + } __forceinline void eval(const float t, Vertex& p, Vertex& dp, Vertex& ddp) const { @@ -283,8 +290,18 @@ namespace embree } }; + template<typename Vertex> + __forceinline void convert(const CatmullRomCurveT<Vertex>& icurve, BezierCurveT<Vertex>& ocurve) + { + const Vertex v0 = icurve.v1; + const Vertex v1 = icurve.v1+(icurve.v2-icurve.v0)*(1.0f/6.0f); + const Vertex v2 = icurve.v2+(icurve.v1-icurve.v3)*(1.0f/6.0f); + const Vertex v3 = icurve.v2; + ocurve = BezierCurveT<Vertex>(v0,v1,v2,v3); + } + template<typename CurveGeometry> - __forceinline CatmullRomCurveT<Vec3ff> enlargeRadiusToMinWidth(const IntersectContext* context, const CurveGeometry* geom, const Vec3fa& ray_org, const CatmullRomCurveT<Vec3ff>& curve) + __forceinline CatmullRomCurveT<Vec3ff> enlargeRadiusToMinWidth(const RayQueryContext* context, const CurveGeometry* geom, const Vec3fa& ray_org, const CatmullRomCurveT<Vec3ff>& curve) { return CatmullRomCurveT<Vec3ff>(enlargeRadiusToMinWidth(context,geom,ray_org,curve.v0), enlargeRadiusToMinWidth(context,geom,ray_org,curve.v1), diff --git a/thirdparty/embree/kernels/subdiv/hermite_curve.h b/thirdparty/embree/kernels/subdiv/hermite_curve.h index ffef5a4315..09ad4cd8b4 100644 --- a/thirdparty/embree/kernels/subdiv/hermite_curve.h +++ b/thirdparty/embree/kernels/subdiv/hermite_curve.h @@ -29,8 +29,14 @@ namespace embree } }; + template<typename Vertex> + __forceinline void convert(const HermiteCurveT<Vertex>& icurve, BezierCurveT<Vertex>& ocurve) + { + ocurve = BezierCurveT<Vertex>(icurve.v0,icurve.v1,icurve.v2,icurve.v3); + } + template<typename CurveGeometry> - __forceinline HermiteCurveT<Vec3ff> enlargeRadiusToMinWidth(const IntersectContext* context, const CurveGeometry* geom, const Vec3fa& ray_org, const HermiteCurveT<Vec3ff>& curve) { + __forceinline HermiteCurveT<Vec3ff> enlargeRadiusToMinWidth(const RayQueryContext* context, const CurveGeometry* geom, const Vec3fa& ray_org, const HermiteCurveT<Vec3ff>& curve) { return HermiteCurveT<Vec3ff>(enlargeRadiusToMinWidth(context,geom,ray_org,BezierCurveT<Vec3ff>(curve))); } diff --git a/thirdparty/embree/kernels/subdiv/linear_bezier_patch.h b/thirdparty/embree/kernels/subdiv/linear_bezier_patch.h index dcdb101d7c..e93a86d7a3 100644 --- a/thirdparty/embree/kernels/subdiv/linear_bezier_patch.h +++ b/thirdparty/embree/kernels/subdiv/linear_bezier_patch.h @@ -31,7 +31,8 @@ namespace embree return merge(L.bounds(),R.bounds()); } }; - + +#if !defined(__SYCL_DEVICE_ONLY__) template<> struct TensorLinearQuadraticBezierSurface<Vec2fa> { @@ -57,6 +58,7 @@ namespace embree return merge(bl,br); } }; +#endif template<typename V> struct TensorLinearCubicBezierSurface @@ -148,9 +150,10 @@ namespace embree __forceinline TensorLinearCubicBezierSurface<float> xfm(const V& dx) const { return TensorLinearCubicBezierSurface<float>(L.xfm(dx),R.xfm(dx)); } - - __forceinline TensorLinearCubicBezierSurface<vfloatx> vxfm(const V& dx) const { - return TensorLinearCubicBezierSurface<vfloatx>(L.vxfm(dx),R.vxfm(dx)); + + template<int W> + __forceinline TensorLinearCubicBezierSurface<vfloat<W>> vxfm(const V& dx) const { + return TensorLinearCubicBezierSurface<vfloat<W>>(L.template vxfm<W>(dx),R.template vxfm<W>(dx)); } __forceinline TensorLinearCubicBezierSurface<float> xfm(const V& dx, const V& p) const { @@ -188,11 +191,20 @@ namespace embree new (&left ) TensorLinearCubicBezierSurface(L0,R0); new (&right) TensorLinearCubicBezierSurface(L1,R1); } - + __forceinline TensorLinearCubicBezierSurface<Vec2vfx> vsplit_u(vboolx& valid, const BBox1f& u) const { valid = true; clear(valid,VSIZEX-1); return TensorLinearCubicBezierSurface<Vec2vfx>(L.split(u),R.split(u)); } + + template<int W> + __forceinline TensorLinearCubicBezierSurface<Vec2vf<W>> vsplit_u(vbool<W>& valid, const BBox1f& u, int& i, int N) const + { + valid = true; clear(valid,W-1); + auto r = TensorLinearCubicBezierSurface<Vec2vf<W>>(L.template split<W>(u,i,N),R.template split<W>(u,i,N)); + i += W-1; + return r; + } __forceinline V eval(const float u, const float v) const { return clerp(L,R,V(v)).eval(u); @@ -244,6 +256,8 @@ namespace embree return TensorLinearCubicBezierSurface(clerp(a.L,b.L,V(t)), clerp(a.R,b.R,V(t))); } }; + +#if !defined(__SYCL_DEVICE_ONLY__) template<> struct TensorLinearCubicBezierSurface<Vec2fa> @@ -332,12 +346,20 @@ namespace embree new (&left ) TensorLinearCubicBezierSurface(LR0); new (&right) TensorLinearCubicBezierSurface(LR1); } - + __forceinline TensorLinearCubicBezierSurface<Vec2vfx> vsplit_u(vboolx& valid, const BBox1f& u) const { valid = true; clear(valid,VSIZEX-1); return TensorLinearCubicBezierSurface<Vec2vfx>(getL().split(u),getR().split(u)); } + template<int W> + __forceinline TensorLinearCubicBezierSurface<Vec2vf<W>> vsplit_u(vbool<W>& valid, const BBox1f& u, int& i, int N) const { + valid = true; clear(valid,W-1); + auto r = TensorLinearCubicBezierSurface<Vec2vf<W>>(getL().split<W>(u,i,N),getR().split<W>(u,i,N)); + i += W-1; + return r; + } + __forceinline Vec2fa eval(const float u, const float v) const { const vfloat4 p = LR.eval(u); @@ -396,6 +418,24 @@ namespace embree } }; + template<> + __forceinline TensorLinearCubicBezierSurface<Vec2f> TensorLinearCubicBezierSurface<Vec2fa>::vsplit_u<1>(bool& valid, const BBox1f& u, int& i, int N) const { + auto r = TensorLinearCubicBezierSurface<Vec2f>(getL().split1(u,i,N),getR().split1(u,i,N)); + valid = true; i += 1; + return r; + } + +#else + + template<> template<> + __forceinline TensorLinearCubicBezierSurface<Vec2f> TensorLinearCubicBezierSurface<Vec2fa>::vsplit_u<1>(bool& valid, const BBox1f& u, int& i, int N) const { + auto r = TensorLinearCubicBezierSurface<Vec2f>(L.split1(u,i,N),R.split1(u,i,N)); + valid = true; i += 1; + return r; + } + +#endif + typedef TensorLinearCubicBezierSurface<float> TensorLinearCubicBezierSurface1f; typedef TensorLinearCubicBezierSurface<Vec2fa> TensorLinearCubicBezierSurface2fa; typedef TensorLinearCubicBezierSurface<Vec3fa> TensorLinearCubicBezierSurface3fa; |