Update embree to 3.13.5

This commit is contained in:
DeeJayLSP 2022-11-24 11:45:59 -03:00 committed by Rémi Verschelde
parent f16c5b564b
commit 5e4158eb48
No known key found for this signature in database
GPG key ID: C3336907360768E1
110 changed files with 9963 additions and 6494 deletions

View file

@ -411,7 +411,7 @@ namespace embree
ReductionTy bounds[MAX_BRANCHING_FACTOR];
if (current.size() > singleThreadThreshold)
{
/*! parallel_for is faster than spawing sub-tasks */
/*! parallel_for is faster than spawning sub-tasks */
parallel_for(size_t(0), numChildren, [&] (const range<size_t>& r) {
for (size_t i=r.begin(); i<r.end(); i++) {
bounds[i] = recurse(depth+1,children[i],nullptr,true);

View file

@ -374,7 +374,7 @@ namespace embree
const size_t begin = set.begin();
const size_t end = set.end();
const size_t center = (begin + end)/2;
const size_t center = (begin + end + 1) / 2;
PrimInfoMB linfo = empty;
for (size_t i=begin; i<center; i++)
@ -594,7 +594,7 @@ namespace embree
/* spawn tasks */
if (unlikely(current.size() > cfg.singleThreadThreshold))
{
/*! parallel_for is faster than spawing sub-tasks */
/*! parallel_for is faster than spawning sub-tasks */
parallel_for(size_t(0), children.size(), [&] (const range<size_t>& r) {
for (size_t i=r.begin(); i<r.end(); i++) {
values[i] = recurse(children[i],nullptr,true);

View file

@ -298,7 +298,7 @@ namespace embree
/* spawn tasks */
if (current.size() > cfg.singleThreadThreshold)
{
/*! parallel_for is faster than spawing sub-tasks */
/*! parallel_for is faster than spawning sub-tasks */
parallel_for(size_t(0), numChildren, [&] (const range<size_t>& r) { // FIXME: no range here
for (size_t i=r.begin(); i<r.end(); i++) {
values[i] = recurse(children[i],nullptr,true);

View file

@ -57,14 +57,12 @@ namespace embree
__forceinline Vec3ia bin(const Vec3fa& p) const
{
const vint4 i = floori((vfloat4(p)-ofs)*scale);
#if 1
assert(i[0] >= 0 && (size_t)i[0] < num);
assert(i[1] >= 0 && (size_t)i[1] < num);
assert(i[2] >= 0 && (size_t)i[2] < num);
return Vec3ia(i);
#else
// we clamp to handle corner cases that could calculate out of bounds bin
return Vec3ia(clamp(i,vint4(0),vint4(num-1)));
#endif
}
/*! faster but unsafe binning */

View file

@ -275,7 +275,7 @@ namespace embree
openNodesBasedOnExtend(set);
#endif
/* disable opening when unsufficient space for opening a node available */
/* disable opening when insufficient space for opening a node available */
if (set.ext_range_size() < max_open_size-1)
set.set_ext_range(set.end()); /* disable opening */
}

View file

@ -159,72 +159,6 @@ namespace embree
assert(binID < BINS);
bounds [binID][dim].extend(b);
}
/*! bins an array of triangles */
template<typename SplitPrimitive>
__forceinline void bin(const SplitPrimitive& splitPrimitive, const PrimRef* prims, size_t N, const SpatialBinMapping<BINS>& mapping)
{
for (size_t i=0; i<N; i++)
{
const PrimRef prim = prims[i];
unsigned splits = prim.geomID() >> (32-RESERVED_NUM_SPATIAL_SPLITS_GEOMID_BITS);
if (unlikely(splits == 1))
{
const vint4 bin = mapping.bin(center(prim.bounds()));
for (size_t dim=0; dim<3; dim++)
{
assert(bin[dim] >= (int)0 && bin[dim] < (int)BINS);
numBegin[bin[dim]][dim]++;
numEnd [bin[dim]][dim]++;
bounds [bin[dim]][dim].extend(prim.bounds());
}
}
else
{
const vint4 bin0 = mapping.bin(prim.bounds().lower);
const vint4 bin1 = mapping.bin(prim.bounds().upper);
for (size_t dim=0; dim<3; dim++)
{
size_t bin;
PrimRef rest = prim;
size_t l = bin0[dim];
size_t r = bin1[dim];
// same bin optimization
if (likely(l == r))
{
numBegin[l][dim]++;
numEnd [l][dim]++;
bounds [l][dim].extend(prim.bounds());
continue;
}
for (bin=(size_t)bin0[dim]; bin<(size_t)bin1[dim]; bin++)
{
const float pos = mapping.pos(bin+1,dim);
PrimRef left,right;
splitPrimitive(rest,(int)dim,pos,left,right);
if (unlikely(left.bounds().empty())) l++;
bounds[bin][dim].extend(left.bounds());
rest = right;
}
if (unlikely(rest.bounds().empty())) r--;
numBegin[l][dim]++;
numEnd [r][dim]++;
bounds [bin][dim].extend(rest.bounds());
}
}
}
}
/*! bins a range of primitives inside an array */
template<typename SplitPrimitive>
void bin(const SplitPrimitive& splitPrimitive, const PrimRef* prims, size_t begin, size_t end, const SpatialBinMapping<BINS>& mapping) {
bin(splitPrimitive,prims+begin,end-begin,mapping);
}
/*! bins an array of primitives */
template<typename PrimitiveSplitterFactory>
@ -232,46 +166,65 @@ namespace embree
{
for (size_t i=begin; i<end; i++)
{
const PrimRef &prim = source[i];
const vint4 bin0 = mapping.bin(prim.bounds().lower);
const vint4 bin1 = mapping.bin(prim.bounds().upper);
const PrimRef& prim = source[i];
unsigned splits = prim.geomID() >> (32-RESERVED_NUM_SPATIAL_SPLITS_GEOMID_BITS);
for (size_t dim=0; dim<3; dim++)
if (unlikely(splits <= 1))
{
if (unlikely(mapping.invalid(dim)))
continue;
size_t bin;
size_t l = bin0[dim];
size_t r = bin1[dim];
// same bin optimization
if (likely(l == r))
const vint4 bin = mapping.bin(center(prim.bounds()));
for (size_t dim=0; dim<3; dim++)
{
add(dim,l,l,l,prim.bounds());
continue;
assert(bin[dim] >= (int)0 && bin[dim] < (int)BINS);
add(dim,bin[dim],bin[dim],bin[dim],prim.bounds());
}
const size_t bin_start = bin0[dim];
const size_t bin_end = bin1[dim];
BBox3fa rest = prim.bounds();
const auto splitter = splitterFactory(prim);
for (bin=bin_start; bin<bin_end; bin++)
{
const float pos = mapping.pos(bin+1,dim);
BBox3fa left,right;
splitter(rest,dim,pos,left,right);
if (unlikely(left.empty())) l++;
extend(dim,bin,left);
rest = right;
}
if (unlikely(rest.empty())) r--;
add(dim,l,r,bin,rest);
}
}
else
{
const vint4 bin0 = mapping.bin(prim.bounds().lower);
const vint4 bin1 = mapping.bin(prim.bounds().upper);
for (size_t dim=0; dim<3; dim++)
{
if (unlikely(mapping.invalid(dim)))
continue;
size_t bin;
size_t l = bin0[dim];
size_t r = bin1[dim];
// same bin optimization
if (likely(l == r))
{
add(dim,l,l,l,prim.bounds());
continue;
}
size_t bin_start = bin0[dim];
size_t bin_end = bin1[dim];
BBox3fa rest = prim.bounds();
/* assure that split position always overlaps the primitive bounds */
while (bin_start < bin_end && mapping.pos(bin_start+1,dim) <= rest.lower[dim]) bin_start++;
while (bin_start < bin_end && mapping.pos(bin_end ,dim) >= rest.upper[dim]) bin_end--;
const auto splitter = splitterFactory(prim);
for (bin=bin_start; bin<bin_end; bin++)
{
const float pos = mapping.pos(bin+1,dim);
BBox3fa left,right;
splitter(rest,dim,pos,left,right);
if (unlikely(left.empty())) l++;
extend(dim,bin,left);
rest = right;
}
if (unlikely(rest.empty())) r--;
add(dim,l,r,bin,rest);
}
}
}
}
/*! bins an array of primitives */
__forceinline void binSubTreeRefs(const PrimRef* source, size_t begin, size_t end, const SpatialBinMapping<BINS>& mapping)
{

View file

@ -241,7 +241,7 @@ namespace embree
SpatialBinner binner(empty);
const SpatialBinMapping<SPATIAL_BINS> mapping(set);
binner.bin2(splitterFactory,prims0,set.begin(),set.end(),mapping);
/* todo: best spatial split not exeeding the extended range does not provide any benefit ?*/
/* todo: best spatial split not exceeding the extended range does not provide any benefit ?*/
return binner.best(mapping,logBlockSize); //,set.ext_size());
}
@ -256,7 +256,7 @@ namespace embree
binner.bin2(splitterFactory,prims0,r.begin(),r.end(),_mapping);
return binner; },
[&] (const SpatialBinner& b0, const SpatialBinner& b1) -> SpatialBinner { return SpatialBinner::reduce(b0,b1); });
/* todo: best spatial split not exeeding the extended range does not provide any benefit ?*/
/* todo: best spatial split not exceeding the extended range does not provide any benefit ?*/
return binner.best(mapping,logBlockSize); //,set.ext_size());
}
@ -286,6 +286,7 @@ namespace embree
//int bin0 = split.mapping.bin(prims0[i].lower)[split.dim];
//int bin1 = split.mapping.bin(prims0[i].upper)[split.dim];
//if (unlikely(bin0 < split.pos && bin1 >= split.pos))
if (unlikely(prims0[i].lower[split.dim] < fpos && prims0[i].upper[split.dim] > fpos))
{
assert(splits > 1);
@ -384,8 +385,8 @@ namespace embree
new (&lset) PrimInfoExtRange(begin,center,center,local_left);
new (&rset) PrimInfoExtRange(center,end,end,local_right);
assert(area(lset.geomBounds) >= 0.0f);
assert(area(rset.geomBounds) >= 0.0f);
assert(!lset.geomBounds.empty() && area(lset.geomBounds) >= 0.0f);
assert(!rset.geomBounds.empty() && area(rset.geomBounds) >= 0.0f);
return std::pair<size_t,size_t>(left_weight,right_weight);
}
@ -410,7 +411,7 @@ namespace embree
begin,end,local_left,local_right,
[&] (const PrimRef& ref) {
const Vec3fa c = ref.bounds().center();
return any(((vint4)mapping.bin(c) < vSplitPos) & vSplitMask);
return any(((vint4)mapping.bin(c) < vSplitPos) & vSplitMask);
},
[] (PrimInfo& pinfo,const PrimRef& ref) { pinfo.add_center2(ref,ref.lower.u >> (32-RESERVED_NUM_SPATIAL_SPLITS_GEOMID_BITS)); });
@ -419,8 +420,8 @@ namespace embree
new (&lset) PrimInfoExtRange(begin,center,center,local_left);
new (&rset) PrimInfoExtRange(center,end,end,local_right);
assert(area(lset.geomBounds) >= 0.0f);
assert(area(rset.geomBounds) >= 0.0f);
assert(!lset.geomBounds.empty() && area(lset.geomBounds) >= 0.0f);
assert(!rset.geomBounds.empty() && area(rset.geomBounds) >= 0.0f);
return std::pair<size_t,size_t>(left_weight,right_weight);
}

View file

@ -184,9 +184,7 @@ namespace embree
// special variants for grid meshes
// -- GODOT start --
#if defined(EMBREE_GEOMETRY_GRID)
// -- GODOT end --
PrimInfo createPrimRefArrayGrids(Scene* scene, mvector<PrimRef>& prims, mvector<SubGridBuildData>& sgrids)
{
PrimInfo pinfo(empty);
@ -296,9 +294,7 @@ namespace embree
return pinfo;
}
// -- GODOT start --
#endif
// -- GODOT end --
// ====================================================================================================
// ====================================================================================================

View file

@ -266,7 +266,7 @@ namespace embree
/* anything to split ? */
if (center < numPrimitives)
{
const size_t numPrimitivesToSplit = numPrimitives - center;
size_t numPrimitivesToSplit = numPrimitives - center;
assert(presplitItem[center].priority >= 1.0f);
/* sort presplit items in ascending order */
@ -279,8 +279,8 @@ namespace embree
});
);
unsigned int *const primOffset0 = (unsigned int*)tmp_presplitItem;
unsigned int *const primOffset1 = (unsigned int*)tmp_presplitItem + numPrimitivesToSplit;
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 {
@ -317,11 +317,16 @@ namespace embree
sum += numSubPrims;
}
new_center++;
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 <= 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 {
@ -338,7 +343,7 @@ namespace embree
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 <= alloc_numPrimitives);
assert(newID+numSubPrims-1 <= alloc_numPrimitives);
prims[primrefID] = subPrims[0];
for (size_t i=1;i<numSubPrims;i++)
prims[newID+i-1] = subPrims[i];

View file

@ -128,28 +128,30 @@ namespace embree
const unsigned int mask = 0xFFFFFFFF >> RESERVED_NUM_SPATIAL_SPLITS_GEOMID_BITS;
const QuadMesh* mesh = (const QuadMesh*) scene->get(prim.geomID() & mask );
QuadMesh::Quad quad = mesh->quad(prim.primID());
v[0] = mesh->vertex(quad.v[0]);
v[1] = mesh->vertex(quad.v[1]);
v[2] = mesh->vertex(quad.v[2]);
v[3] = mesh->vertex(quad.v[3]);
v[4] = mesh->vertex(quad.v[0]);
inv_length[0] = Vec3fa(1.0f) / (v[1]-v[0]);
inv_length[1] = Vec3fa(1.0f) / (v[2]-v[1]);
inv_length[2] = Vec3fa(1.0f) / (v[3]-v[2]);
inv_length[3] = Vec3fa(1.0f) / (v[0]-v[3]);
v[0] = mesh->vertex(quad.v[1]);
v[1] = mesh->vertex(quad.v[2]);
v[2] = mesh->vertex(quad.v[3]);
v[3] = mesh->vertex(quad.v[0]);
v[4] = mesh->vertex(quad.v[1]);
v[5] = mesh->vertex(quad.v[3]);
inv_length[0] = Vec3fa(1.0f) / (v[1] - v[0]);
inv_length[1] = Vec3fa(1.0f) / (v[2] - v[1]);
inv_length[2] = Vec3fa(1.0f) / (v[3] - v[2]);
inv_length[3] = Vec3fa(1.0f) / (v[4] - v[3]);
inv_length[4] = Vec3fa(1.0f) / (v[5] - v[4]);
}
__forceinline void operator() (const PrimRef& prim, const size_t dim, const float pos, PrimRef& left_o, PrimRef& right_o) const {
splitPolygon<4>(prim,dim,pos,v,left_o,right_o);
splitPolygon<5>(prim,dim,pos,v,left_o,right_o);
}
__forceinline void operator() (const BBox3fa& prim, const size_t dim, const float pos, BBox3fa& left_o, BBox3fa& right_o) const {
splitPolygon<4>(prim,dim,pos,v,inv_length,left_o,right_o);
splitPolygon<5>(prim,dim,pos,v,inv_length,left_o,right_o);
}
private:
Vec3fa v[5];
Vec3fa inv_length[4];
Vec3fa v[6];
Vec3fa inv_length[5];
};
struct QuadSplitterFactory