Skip to content

Commit dad5a74

Browse files
cdtwiggfacebook-github-bot
authored andcommitted
Implement TriBvh in a more simd-efficient way. (#593)
Summary: Pull Request resolved: #593 The current TriBvh has a few specific limitations that bother me: 1. It's not _really_ simd code, because it does most operations without simd and then only tries to assemble simd triangles with a big gather() operation at the end. It would be much more efficient if data was actually stored packed in simd primitives. 2. It's annoying to construct a tri_bvh because it takes a very unusual data structures that aren't actually used anywhere in momentum (Eigen::MatrixX3 instead of the std::vector<<Eigen::Vector3f>> that momentum::Mesh uses, which means constructing a TriBvh for a momentum Character requires a bunch of boilerplate code). 3. It lacks an early exit for closest_point functionality based on distance, even though most closest point use cases only care if the query point is actually close (they don't need to distinguish between 1 meter and 10 meters). This is more important than you'd think because when you're doing a distance query and you use a point which is say 1 meter away from the mesh, it will end up looking at large chunks of the bbox hierarchy since all the bboxes are roughly the same distance away (by vector norm), but if you use a query point which is right next to the mesh it only needs to look at a relatively small number of triangles. This should be a solveable problem. I think the original issue here is that we are trying really hard to make TriBvh use the "regular" bvh class. However IMO in this case we should instead be optimizing for the triangle use case, because there are many more use cases for triangles specifically than for any other kind of thing you'd store in a bounding box hierarchy. So instead, let's specialize on triangles, and store the actual triangles in the leafs in SIMD-length blocks. This will let us quickly process the triangles 8 at a time, and gives us a nice ~2x speedup. Also, since we're repacking the triangles anyway, we no longer need to rely on taking the input arguments as std::move(), and allows us to support multiple possible input types. Reviewed By: jeongseok-meta, FallenShard Differential Revision: D82481416 fbshipit-source-id: 7ef210717f457de16c13c759ecaac289b7c33f12
1 parent 1f5277e commit dad5a74

File tree

12 files changed

+3589
-245
lines changed

12 files changed

+3589
-245
lines changed

axel/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ set(headers
3333
axel/math/BoundingBoxUtils.h
3434
axel/math/PointTriangleProjection.h
3535
axel/math/PointTriangleProjectionDefinitions.h
36+
axel/math/RayBoxIntersection.h
3637
axel/math/RayTriangleIntersection.h
3738
axel/BoundingBox.h
3839
axel/Bvh.h
@@ -45,6 +46,7 @@ set(headers
4546

4647
set(sources
4748
axel/math/PointTriangleProjection.cpp
49+
axel/math/RayBoxIntersection.cpp
4850
axel/math/RayTriangleIntersection.cpp
4951
axel/BoundingBox.cpp
5052
axel/Bvh.cpp

0 commit comments

Comments
 (0)