Skip to content

Commit

Permalink
Support drjit 1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
jeongseok-meta committed Jan 6, 2025
1 parent 5f9e742 commit eb97cb5
Show file tree
Hide file tree
Showing 5 changed files with 244 additions and 1,743 deletions.
6 changes: 3 additions & 3 deletions momentum/character_solver/simd_collision_error_function.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ closestPointOnTwoSegments(
// Note that the actual returned values are inherently unstable
// if the lines are near parallel, but the distance from
// (p0 + t0*d0) to (p1 + t1*d1) will be stable.
t0 = drjit::clamp(drjit::select(div > 0.0f, (pd0 * d11 - pd1 * d01) / div, t0), 0.0f, 1.0f);
t1 = drjit::clamp(drjit::select(d11 > 0.0f, (t0 * d01 - pd1) / d11, t1), 0.0f, 1.0f);
t0 = drjit::clamp(drjit::select(d00 > 0.0f, (t1 * d01 + pd0) / d00, t0), 0.0f, 1.0f);
t0 = drjit::clip(drjit::select(div > 0.0f, (pd0 * d11 - pd1 * d01) / div, t0), 0.0f, 1.0f);
t1 = drjit::clip(drjit::select(d11 > 0.0f, (t0 * d01 - pd1) / d11, t1), 0.0f, 1.0f);
t0 = drjit::clip(drjit::select(d00 > 0.0f, (t1 * d01 + pd0) / d00, t0), 0.0f, 1.0f);

return {t0, t1};
}
Expand Down
20 changes: 20 additions & 0 deletions momentum/simd/simd.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@
#include <Eigen/Core>
#include <Eigen/Geometry>

#define DRJIT_VERSION_GE(major, minor, patch) \
((DRJIT_VERSION_MAJOR > (major)) || \
(DRJIT_VERSION_MAJOR == (major) && DRJIT_VERSION_MINOR > (minor)) || \
(DRJIT_VERSION_MAJOR == (major) && DRJIT_VERSION_MINOR == (minor) && \
DRJIT_VERSION_PATCH >= (patch)))

// Utilities for writing cross-platform SIMD code.
// This currently uses the DrJit library for SIMD primitives.

Expand Down Expand Up @@ -194,3 +200,17 @@ Vector3P<S> cross(const Vector3P<S>& v1, const Eigen::MatrixBase<Derived>& v2) {
}

} // namespace momentum

#if DRJIT_VERSION_GE(1, 0, 0)

namespace drjit {

template <typename Stream, typename T>
std::stringstream& operator<<(std::stringstream& stream, const drjit::Packet<T>& packet) {
stream << drjit::string(packet).c_str();
return stream;
}

} // namespace drjit

#endif
3 changes: 2 additions & 1 deletion momentum/test/math/simd_generalized_loss_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ void testSimdGeneralizedLoss(T alpha, T c, T absTol, T relTol) {
<< "\n - val1 : " << val1
<< "\n - val2 : " << val2
<< "\n - refDeriv : " << refDeriv
<< "\n - testDeriv: " << testDeriv << std::endl;
<< "\n - testDeriv: " << testDeriv
<< std::endl;
// clang-format off
}

Expand Down
Loading

0 comments on commit eb97cb5

Please sign in to comment.