Path: blob/master/thirdparty/embree/kernels/builders/primref.h
9906 views
// Copyright 2009-2021 Intel Corporation1// SPDX-License-Identifier: Apache-2.023#pragma once45#include "../common/default.h"67namespace embree8{9/*! A primitive reference stores the bounds of the primitive and its ID. */10struct __aligned(32) PrimRef11{12__forceinline PrimRef () {}1314#if defined(__AVX__)15__forceinline PrimRef(const PrimRef& v) {16vfloat8::store((float*)this,vfloat8::load((float*)&v));17}18__forceinline PrimRef& operator=(const PrimRef& v) {19vfloat8::store((float*)this,vfloat8::load((float*)&v)); return *this;20}21#endif2223__forceinline PrimRef (const BBox3fa& bounds, unsigned int geomID, unsigned int primID)24{25lower = Vec3fx(bounds.lower, geomID);26upper = Vec3fx(bounds.upper, primID);27}2829__forceinline PrimRef (const BBox3fa& bounds, size_t id)30{31#if defined(__64BIT__)32lower = Vec3fx(bounds.lower, (unsigned)(id & 0xFFFFFFFF));33upper = Vec3fx(bounds.upper, (unsigned)((id >> 32) & 0xFFFFFFFF));34#else35lower = Vec3fx(bounds.lower, (unsigned)id);36upper = Vec3fx(bounds.upper, (unsigned)0);37#endif38}3940/*! calculates twice the center of the primitive */41__forceinline const Vec3fa center2() const {42return lower+upper;43}4445/*! return the bounding box of the primitive */46__forceinline const BBox3fa bounds() const {47return BBox3fa(lower,upper);48}4950/*! size for bin heuristic is 1 */51__forceinline unsigned size() const {52return 1;53}5455/*! returns bounds and centroid used for binning */56__forceinline void binBoundsAndCenter(BBox3fa& bounds_o, Vec3fa& center_o) const57{58bounds_o = bounds();59center_o = embree::center2(bounds_o);60}6162__forceinline unsigned& geomIDref() { // FIXME: remove !!!!!!!63return lower.u;64}65__forceinline unsigned& primIDref() { // FIXME: remove !!!!!!!66return upper.u;67}6869/*! returns the geometry ID */70__forceinline unsigned geomID() const {71return lower.a;72}7374/*! returns the primitive ID */75__forceinline unsigned primID() const {76return upper.a;77}7879/*! returns an size_t sized ID */80__forceinline size_t ID() const {81#if defined(__64BIT__)82return size_t(lower.u) + (size_t(upper.u) << 32);83#else84return size_t(lower.u);85#endif86}8788/*! special function for operator< */89__forceinline uint64_t ID64() const {90return (((uint64_t)primID()) << 32) + (uint64_t)geomID();91}9293/*! allows sorting the primrefs by ID */94friend __forceinline bool operator<(const PrimRef& p0, const PrimRef& p1) {95return p0.ID64() < p1.ID64();96}9798/*! Outputs primitive reference to a stream. */99friend __forceinline embree_ostream operator<<(embree_ostream cout, const PrimRef& ref) {100return cout << "{ lower = " << ref.lower << ", upper = " << ref.upper << ", geomID = " << ref.geomID() << ", primID = " << ref.primID() << " }";101}102103public:104Vec3fx lower; //!< lower bounds and geomID105Vec3fx upper; //!< upper bounds and primID106};107108/*! fast exchange for PrimRefs */109__forceinline void xchg(PrimRef& a, PrimRef& b)110{111#if defined(__AVX__)112const vfloat8 aa = vfloat8::load((float*)&a);113const vfloat8 bb = vfloat8::load((float*)&b);114vfloat8::store((float*)&a,bb);115vfloat8::store((float*)&b,aa);116#else117std::swap(a,b);118#endif119}120121122/************************************************************************************/123/************************************************************************************/124/************************************************************************************/125/************************************************************************************/126127struct SubGridBuildData {128unsigned short sx,sy;129unsigned int primID;130131__forceinline SubGridBuildData() {};132__forceinline SubGridBuildData(const unsigned int sx, const unsigned int sy, const unsigned int primID) : sx(sx), sy(sy), primID(primID) {};133134__forceinline size_t x() const { return (size_t)sx & 0x7fff; }135__forceinline size_t y() const { return (size_t)sy & 0x7fff; }136137};138}139140141