// Copyright 2009-2021 Intel Corporation // SPDX-License-Identifier: Apache-2.0 #pragma once #include "primitive.h" namespace embree { /* Stores the vertices of M quads in struct of array layout */ template struct QuadMv { public: 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: /* Returns maximum number of stored quads */ static __forceinline size_t max_size() { return M; } /* Returns required number of primitive blocks for N primitives */ static __forceinline size_t blocks(size_t N) { return (N+max_size()-1)/max_size(); } public: /* Default constructor */ __forceinline QuadMv() {} /* Construction from vertices and IDs */ __forceinline QuadMv(const Vec3vf& v0, const Vec3vf& v1, const Vec3vf& v2, const Vec3vf& v3, const vuint& geomIDs, const vuint& primIDs) : v0(v0), v1(v1), v2(v2), v3(v3), geomIDs(geomIDs), primIDs(primIDs) {} /* Returns a mask that tells which quads are valid */ __forceinline vbool valid() const { return geomIDs != vuint(-1); } /* Returns true if the specified quad is valid */ __forceinline bool valid(const size_t i) const { assert(i& geomID() { return geomIDs; } __forceinline const vuint& geomID() const { return geomIDs; } __forceinline unsigned int geomID(const size_t i) const { assert(i primID() { return primIDs; } __forceinline const vuint primID() const { return primIDs; } __forceinline unsigned int primID(const size_t i) const { assert(i lower = min(v0,v1,v2,v3); Vec3vf upper = max(v0,v1,v2,v3); vbool mask = valid(); lower.x = select(mask,lower.x,vfloat(pos_inf)); lower.y = select(mask,lower.y,vfloat(pos_inf)); lower.z = select(mask,lower.z,vfloat(pos_inf)); upper.x = select(mask,upper.x,vfloat(neg_inf)); upper.y = select(mask,upper.y,vfloat(neg_inf)); upper.z = select(mask,upper.z,vfloat(neg_inf)); return BBox3fa(Vec3fa(reduce_min(lower.x),reduce_min(lower.y),reduce_min(lower.z)), Vec3fa(reduce_max(upper.x),reduce_max(upper.y),reduce_max(upper.z))); } /* Non temporal store */ __forceinline static void store_nt(QuadMv* dst, const QuadMv& src) { vfloat::store_nt(&dst->v0.x,src.v0.x); vfloat::store_nt(&dst->v0.y,src.v0.y); vfloat::store_nt(&dst->v0.z,src.v0.z); vfloat::store_nt(&dst->v1.x,src.v1.x); vfloat::store_nt(&dst->v1.y,src.v1.y); vfloat::store_nt(&dst->v1.z,src.v1.z); vfloat::store_nt(&dst->v2.x,src.v2.x); vfloat::store_nt(&dst->v2.y,src.v2.y); vfloat::store_nt(&dst->v2.z,src.v2.z); vfloat::store_nt(&dst->v3.x,src.v3.x); vfloat::store_nt(&dst->v3.y,src.v3.y); vfloat::store_nt(&dst->v3.z,src.v3.z); vuint::store_nt(&dst->geomIDs,src.geomIDs); vuint::store_nt(&dst->primIDs,src.primIDs); } /* Fill quad from quad list */ __forceinline void fill(const PrimRef* prims, size_t& begin, size_t end, Scene* scene) { vuint vgeomID = -1, vprimID = -1; Vec3vf v0 = zero, v1 = zero, v2 = zero, v3 = zero; for (size_t i=0; iget(geomID); const QuadMesh::Quad& quad = mesh->quad(primID); const Vec3fa& p0 = mesh->vertex(quad.v[0]); const Vec3fa& p1 = mesh->vertex(quad.v[1]); const Vec3fa& p2 = mesh->vertex(quad.v[2]); const Vec3fa& p3 = mesh->vertex(quad.v[3]); vgeomID [i] = geomID; vprimID [i] = primID; v0.x[i] = p0.x; v0.y[i] = p0.y; v0.z[i] = p0.z; v1.x[i] = p1.x; v1.y[i] = p1.y; v1.z[i] = p1.z; v2.x[i] = p2.x; v2.y[i] = p2.y; v2.z[i] = p2.z; v3.x[i] = p3.x; v3.y[i] = p3.y; v3.z[i] = p3.z; } QuadMv::store_nt(this,QuadMv(v0,v1,v2,v3,vgeomID,vprimID)); } /* Updates the primitive */ __forceinline BBox3fa update(QuadMesh* mesh) { BBox3fa bounds = empty; vuint vgeomID = -1, vprimID = -1; Vec3vf v0 = zero, v1 = zero, v2 = zero; for (size_t i=0; iquad(primId); const Vec3fa p0 = mesh->vertex(quad.v[0]); const Vec3fa p1 = mesh->vertex(quad.v[1]); const Vec3fa p2 = mesh->vertex(quad.v[2]); const Vec3fa p3 = mesh->vertex(quad.v[3]); bounds.extend(merge(BBox3fa(p0),BBox3fa(p1),BBox3fa(p2),BBox3fa(p3))); vgeomID [i] = geomId; vprimID [i] = primId; v0.x[i] = p0.x; v0.y[i] = p0.y; v0.z[i] = p0.z; v1.x[i] = p1.x; v1.y[i] = p1.y; v1.z[i] = p1.z; v2.x[i] = p2.x; v2.y[i] = p2.y; v2.z[i] = p2.z; v3.x[i] = p3.x; v3.y[i] = p3.y; v3.z[i] = p3.z; } new (this) QuadMv(v0,v1,v2,v3,vgeomID,vprimID); return bounds; } public: Vec3vf v0; // 1st vertex of the quads Vec3vf v1; // 2nd vertex of the quads Vec3vf v2; // 3rd vertex of the quads Vec3vf v3; // 4rd vertex of the quads private: vuint geomIDs; // geometry ID vuint primIDs; // primitive ID }; template typename QuadMv::Type QuadMv::type; typedef QuadMv<4> Quad4v; }