13#include <drjit/array.h>
14#include <drjit/array_router.h>
15#include <drjit/matrix.h>
16#include <drjit/packet.h>
17#include <drjit/util.h>
19#include <Eigen/Geometry>
26#define DRJIT_VERSION_GE(major, minor, patch) \
27 ((DRJIT_VERSION_MAJOR > (major)) || \
28 (DRJIT_VERSION_MAJOR == (major) && DRJIT_VERSION_MINOR > (minor)) || \
29 (DRJIT_VERSION_MAJOR == (major) && DRJIT_VERSION_MINOR == (minor) && \
30 DRJIT_VERSION_PATCH >= (patch)))
71using Packet = drjit::Packet<T, kSimdPacketSize>;
81template <
typename T,
int Dim>
82using VectorP = drjit::Array<Packet<T>, Dim>;
114template <
typename T,
int Dim>
136template <
size_t Alignment>
138 constexpr size_t sizeOfScalar =
sizeof(
typename Eigen::MatrixXf::Scalar);
139 const size_t addressOffset =
140 Alignment / sizeOfScalar - (((size_t)mat.data() % Alignment) / sizeOfScalar);
143 if (addressOffset == Alignment / sizeOfScalar) {
147 return addressOffset;
155template <
size_t Alignment>
158 (uintptr_t(mat.data() + offset)) % Alignment != 0,
159 "Matrix ({}x{}, ptr: {}) is not aligned ({}) correctly.",
162 uintptr_t(mat.data()),
190template <
typename Derived,
typename S>
192 return drjit::fmadd(v1.x(), v2.x(), drjit::fmadd(v1.y(), v2.y(), v1.z() * v2.z()));
202template <
typename Derived,
typename S>
204 return drjit::fmadd(v1.x(), v2.x(), drjit::fmadd(v1.y(), v2.y(), v1.z() * v2.z()));
214template <
typename S,
typename Derived>
216 return {v1.x() + v2.x(), v1.y() + v2.y(), v1.z() + v2.z()};
226template <
typename S,
typename Derived>
228 return {v1.x() + v2.x(), v1.y() + v2.y(), v1.z() + v2.z()};
238template <
typename S,
typename Derived>
240 return {v1.x() - v2.x(), v1.y() - v2.y(), v1.z() - v2.z()};
250template <
typename S,
typename Derived>
252 return {v1.x() - v2.x(), v1.y() - v2.y(), v1.z() - v2.z()};
275template <
typename S,
typename Derived>
308template <
typename S,
typename Derived>
311 drjit::fmsub(v1.y(), v2.z(), v1.z() * v2.y()),
312 drjit::fmsub(v1.z(), v2.x(), v1.x() * v2.z()),
313 drjit::fmsub(v1.x(), v2.y(), v1.y() * v2.x()),
324template <
typename S,
typename Derived>
327 drjit::fmsub(v1.y(), v2.z(), v1.z() * v2.y()),
328 drjit::fmsub(v1.z(), v2.x(), v1.x() * v2.z()),
329 drjit::fmsub(v1.x(), v2.y(), v1.y() * v2.x()),
#define MT_THROW_IF(Condition,...)
Conditionally throws a std::runtime_error with a formatted message if the condition is true.
Vector4P< double > Vector4dP
constexpr size_t kSimdPacketSize
Number of floats in the platform's default SIMD register, chosen at compile time by DrJit based on av...
drjit::Packet< T, kSimdPacketSize > Packet
A fixed-size SIMD packet of kSimdPacketSize elements of type T.
Vector3P< S > operator-(const Eigen::MatrixBase< Derived > &v1, const Vector3P< S > &v2)
Subtracts Vector3P from Eigen::Vector3f element-wise.
Matrix3P< double > Matrix3dP
constexpr size_t kSimdAlignment
Byte alignment required for the platform's default SIMD loads/stores.
Matrix4P< double > Matrix4dP
FloatP dot(const Eigen::MatrixBase< Derived > &v1, const Vector3P< S > &v2)
Computes dot product of Eigen::Vector3f and 3-vector of packets.
drjit::Array< ByteP, 3 > Vector3bP
void checkAlignment(const Eigen::Ref< Eigen::MatrixXf > &mat, size_t offset=0)
Checks if the data of the matrix is aligned correctly.
drjit::Array< IntP, 3 > Vector3iP
drjit::Array< Packet< T >, Dim > VectorP
A Dim-dimensional vector where each component is a SIMD packet.
Vector2P< double > Vector2dP
size_t computeOffset(const Eigen::Ref< Eigen::MatrixXf > &mat)
Computes the offset required for the matrix data to meet the alignment requirement.
Vector3P< double > Vector3dP
drjit::Array< IntP, 2 > Vector2iP
Integer and byte vector types.
drjit::Matrix< Packet< T >, Dim > MatrixP
Matrix types for SIMD packets.
VectorP< T, 4 > Vector4P
4D vector types.
Vector3P< S > operator+(const Eigen::MatrixBase< Derived > &v1, const Vector3P< S > &v2)
Adds Eigen::Vector3f and Vector3P element-wise.
Vector3P< S > cross(const Eigen::MatrixBase< Derived > &v1, const Vector3P< S > &v2)
Computes cross product of Eigen::Vector3f and Vector3P.
Vector3P< float > Vector3fP
Vector2P< float > Vector2fP
Vector3P< S > operator*(const Eigen::Quaternion< S > &q, const Vector3P< S > &vec)
Applies quaternion rotation to each 3x1 vector in packet.
Matrix3P< float > Matrix3fP
Matrix4P< float > Matrix4fP
Vector4P< float > Vector4fP