11#ifndef EBGEOMETRY_TRIANGLESOA_HPP
12#define EBGEOMETRY_TRIANGLESOA_HPP
31namespace TriangleSoA {
51[[nodiscard]]
constexpr size_t
54 static_assert(std::is_floating_point_v<T>,
"EBGeometry::TriangleSoA::HostWidth requires a floating-point T");
55#if defined(__AVX512F__)
56 if constexpr (std::is_same_v<T, double>) {
63 if constexpr (std::is_same_v<T, double>) {
106[[nodiscard]]
constexpr size_t
109 static_assert(std::is_floating_point_v<T>,
"EBGeometry::TriangleSoA::DefaultWidth requires a floating-point T");
111#if defined(EBGEOMETRY_HOST_TUNED_DEFAULTS)
112 return HostWidth<T>();
140template <
class T,
size_t W>
143 static_assert(W > 0,
"W must be positive");
144 static_assert(std::is_floating_point_v<T>,
"TriangleSoAT requires a floating-point type T");
228 const Vec3T<T>& a_origin,
const Vec3T<T>& a_direction, T a_tMin, T a_tMax, uint32_t& a_lane)
const noexcept;
244 const Vec3T<T>& a_origin,
const Vec3T<T>& a_direction, T a_tMin, T a_tMax, T* a_crossings)
const noexcept;
275 getVertex(
size_t a_lane,
size_t a_vertex) const noexcept
320 fetch(
const T* a_lanes)
const noexcept
322 if constexpr (std::is_same_v<V, T>) {
417 const Vec3T<T>& a_origin,
const Vec3T<T>& a_direction, T a_tMin, T a_tMax, T* a_crossings)
const noexcept;
422 alignas(W *
sizeof(T)) T
m_vx[3][W];
437 alignas(W *
sizeof(T)) T
m_nx[W];
452 alignas(W *
sizeof(T)) T
m_vnx[3][W];
467 alignas(W *
sizeof(T)) T
m_enx[3][W];
488static_assert(std::is_trivially_copyable_v<TriangleSoAT<float, 4>>,
"TriangleSoAT<float> must be trivially copyable");
489static_assert(std::is_trivially_copyable_v<TriangleSoAT<double, 4>>,
"TriangleSoAT<double> must be trivially copyable");
493#include "EBGeometry_TriangleSoAImplem.hpp"
A fixed-size array that compiles for both host and device.
#define EBGEOMETRY_HOST_DEVICE
Mark a function as callable from both host and device code (no-op on host compilers).
Definition EBGeometry_GPU.hpp:80
#define EBGEOMETRY_HOST
Mark a function as callable from host code only (no-op on host compilers).
Definition EBGeometry_GPU.hpp:83
Thin wrappers over SSE4.1, AVX and AVX-512 registers, so that one kernel template serves every SIMD w...
The triangle distance kernels, written once for a scalar and for every SIMD::Pack.
Declaration of a triangle class with signed distance functionality.
Declaration of 2D and 3D point/vector classes with templated precision, and free functions on them.
Triangle class with signed distance functionality.
Definition EBGeometry_Triangle.hpp:52
Three-dimensional vector class with arithmetic operators.
Definition EBGeometry_Vec.hpp:258
constexpr size_t HostWidth() noexcept
The SoA width W (triangles per TriangleSoAT group) that fills one SIMD register for type T under the ...
Definition EBGeometry_TriangleSoA.hpp:52
constexpr size_t DefaultWidth() noexcept
The default SoA width W (triangles per TriangleSoAT group): 4, or HostWidth<T>() in a build that defi...
Definition EBGeometry_TriangleSoA.hpp:107
Namespace containing all of EBGeometry's functionality.
Definition EBGeometry_Affine.hpp:26
Fixed-size array with host- and device-callable members.
Definition EBGeometry_Array.hpp:33
A 3D vector of V, where V is a scalar or a SIMD::Pack: x, y and z each hold one lane per triangle.
Definition EBGeometry_TriangleDistance.hpp:39
The triangle accessor TriangleDistance::signedDistance() reads lanes [m_offset, m_offset + lanes of V...
Definition EBGeometry_TriangleSoA.hpp:302
TriangleDistance::Vec3V< V > vertexNormal(const size_t a_k) const noexcept
Vertex pseudonormal.
Definition EBGeometry_TriangleSoA.hpp:360
TriangleDistance::Vec3V< V > edgeNormal(const size_t a_k) const noexcept
Edge pseudonormal.
Definition EBGeometry_TriangleSoA.hpp:372
TriangleDistance::Vec3V< V > vertex(const size_t a_k) const noexcept
Vertex position.
Definition EBGeometry_TriangleSoA.hpp:337
TriangleDistance::Vec3V< V > normal() const noexcept
Face normal.
Definition EBGeometry_TriangleSoA.hpp:348
V fetch(const T *a_lanes) const noexcept
One value per lane, from the array starting at a_lanes.
Definition EBGeometry_TriangleSoA.hpp:320
const TriangleSoAT * m_group
The group.
Definition EBGeometry_TriangleSoA.hpp:306
size_t m_offset
First lane.
Definition EBGeometry_TriangleSoA.hpp:311
SoA (Structure of Arrays) layout for W triangles, enabling SIMD evaluation.
Definition EBGeometry_TriangleSoA.hpp:142
void pack(const Triangle< T > *tris, uint32_t count) noexcept
Pack count triangles from tris[0..count-1] into this SoA group.
T signedDistanceAt(uint32_t a_lane, const Vec3T< T > &a_point) const noexcept
One lane's signed distance: on the host, bit for bit the value signedDistances() gives that lane; on ...
T m_vz[3][W]
z-coordinates of vertex positions. m_vz[i][j] = z-coord of vertex i for triangle j.
Definition EBGeometry_TriangleSoA.hpp:432
void rayCrossings(const Vec3T< T > &a_origin, const Vec3T< T > &a_direction, T a_tMin, T a_tMax, T *a_crossings) const noexcept
Where a ray crosses each triangle in this group.
T m_enz[3][W]
z-components of edge normals. m_enz[i][j] = z of edge normal i for triangle j.
Definition EBGeometry_TriangleSoA.hpp:477
T m_nx[W]
x-components of face normals. m_nx[j] = x-component of the face normal for triangle j.
Definition EBGeometry_TriangleSoA.hpp:437
void signedDistancesSIMD(const Vec3T< T > &a_point, T *a_distances) const noexcept
Signed distances to the lanes below m_validCount, N at a time, with SIMD::Pack<T, N>.
uint32_t m_validCount
Number of valid (non-padded) triangles in this group (1..W).
Definition EBGeometry_TriangleSoA.hpp:485
T m_vnz[3][W]
z-components of vertex normals. m_vnz[i][j] = z of vertex normal i for triangle j.
Definition EBGeometry_TriangleSoA.hpp:462
T rayCrossing(const Vec3T< T > &a_origin, const Vec3T< T > &a_direction, T a_tMin, T a_tMax, uint32_t &a_lane) const noexcept
Where a ray first crosses a triangle in this group.
void unsignedDistances2SIMD(const Vec3T< T > &a_point, T *a_d2) const noexcept
Every lane's squared unsigned distance with SIMD packs of N lanes, as signedDistancesSIMD().
T signedDistanceLane(uint32_t a_lane, const Vec3T< T > &a_point) const noexcept
Signed distance from a_point to the single triangle stored in lane a_lane.
T m_ny[W]
y-components of face normals.
Definition EBGeometry_TriangleSoA.hpp:442
T m_enx[3][W]
x-components of edge normals. m_enx[i][j] = x of edge normal i for triangle j.
Definition EBGeometry_TriangleSoA.hpp:467
T m_vy[3][W]
y-coordinates of vertex positions. m_vy[i][j] = y-coord of vertex i for triangle j.
Definition EBGeometry_TriangleSoA.hpp:427
T m_nz[W]
z-components of face normals.
Definition EBGeometry_TriangleSoA.hpp:447
void rayCrossingsSIMD(const Vec3T< T > &a_origin, const Vec3T< T > &a_direction, T a_tMin, T a_tMax, T *a_crossings) const noexcept
Ray crossings of the lanes below m_validCount, N at a time, with SIMD::Pack<T, N>.
T m_vx[3][W]
x-coordinates of vertex positions. m_vx[i][j] = x-coord of vertex i for triangle j.
Definition EBGeometry_TriangleSoA.hpp:422
BV computeBoundingVolume() const noexcept
Compute the bounding volume enclosing all valid triangles in this group.
T m_eny[3][W]
y-components of edge normals. m_eny[i][j] = y of edge normal i for triangle j.
Definition EBGeometry_TriangleSoA.hpp:472
T m_vny[3][W]
y-components of vertex normals. m_vny[i][j] = y of vertex normal i for triangle j.
Definition EBGeometry_TriangleSoA.hpp:457
Vec3T< T > getVertex(size_t a_lane, size_t a_vertex) const noexcept
Vertex a_vertex of the triangle in lane a_lane.
Definition EBGeometry_TriangleSoA.hpp:275
Vec3T< T > getNormal(uint32_t a_lane) const noexcept
The unit normal of one lane's triangle.
T m_vnx[3][W]
x-components of vertex normals. m_vnx[i][j] = x of vertex normal i for triangle j.
Definition EBGeometry_TriangleSoA.hpp:452
Array< T, W > signedDistances(const Vec3T< T > &a_point) const noexcept
Signed distances from a_point to every one of the W lane triangles.
T signedDistance(const Vec3T< T > &a_point) const noexcept
Evaluate signed distance from a_point to the closest triangle in this group.
uint32_t nearestLane(const Vec3T< T > &a_point, T &a_d2) const noexcept
The lane nearest a point and its squared distance, without a sign.