-
-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
optimizations and other improvements #80
Conversation
…psule and aabb intersection tests. Expose C FFI
This reverts commit 1a152b4.
…bug with using the wrong surface_area
…cals and by computing centroid bounds during the bucket phase
bvh-lib/Cargo.toml
Outdated
lto = true | ||
codegen-units = 1 | ||
debug = true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want debug here?
bvh-lib/Cargo.toml
Outdated
lto = true | ||
codegen-units = 1 | ||
debug = true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want debug here?
Is there any chance you could cut down the PR into smaller chunks? I realize you did a lot of refactoring but are there perhaps any smaller chunks to make reviewing easier? |
The FFI stuff can very easily be separated so I'll do that. I'm not even sure what the best way to distribute that is I think I can also pull the new shapes out into a separate change, I'll see what I can come up with |
@@ -0,0 +1,59 @@ | |||
[package] | |||
name = "bvh-f64" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we really need a specialized crate for this? Can't we use traits for this to have Rust do the specialization?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So I tried a few approaches to this. It might be a possibility with nalgebra backing things to have the float be a generic on everything, but with glam there's no trait to abstract dvec3 from vec3 so we would have to wrap that ourselves. This trick using separate crates in the workspace is something I got from the author of nalgebra and how he builds rapier (2d 3d 32 and 64bit). When the workspace is all setup with this cargo test runs the test for all the versions and you'll get compiler errors from rust analyzer for both at the same time
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would very much like to see this move to nalgebra, it would make the usage much cleaner via Bvh<T>
. This would definitely be possible with the nalgebra vector types and number bounds.
Heck, because of the AABB's, assuming there are no dot products/cross products (which I don't think there are - haven't checked), it should work with integer types as well, and maybe even unsigned types (but there would have to be better bounds checking).
I could try and help get this working with nalgebra as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that would be pretty cool.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure how to approach this for now though, should I wait for these changes to get merged in? There are a lot of stacked up changes in this MR, so it might be easier to do after all the merge.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmmm it might be easier for me to port it now, and have this PR rebase on it. Otherwise we would be splitting code and then remerging.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Has nalgebra fixed the issues that made this crate switch from nalgebra to glam previously?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Elabajaba do you happen to know what those issues would be? I could look into it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
iirc the main issues with nalgebra used to be compile times, slower runtime performance for non-simd types, and the confusing docs. I haven't really used nalgebra for a few years at this point, so I'm not sure how it compares these days.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe that most of those issues have been addressed. It does still have a slower compilation time than glam
ok I think I've fixed all the lints now |
I've been a bit busy last couple of weeks haven't had time to look at breaking this apart. if that's still something you would prefer I can start working on trying to do so |
Well if we can somehow do this in small incremental PRs that would be ideal but I can understand if you don't want to go down that path but it would make reviewing faster for me for sure. You get to decide. :) |
I've pulled the ffi bindings out, I can add them back in if you want them in the repo otherwise I will just throw them up in a separate repo. In terms of reviewing this, the big change that affects the whole crate is refactoring all the types to use the vec/float types defined at the crate root. Otherwise the changes are pretty much file by file but because of that change to all of the types it's kind of a pain to break this down into little commits. |
fn intersects_aabb(&self, aabb: &AABB) -> bool { | ||
/* | ||
// Use Distance from closest point | ||
let mut point: Vector3 = self.start; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Commented out code. Delete it if it isn't used?
} | ||
|
||
// Only required for bounded intersection intervals. | ||
// if z_min > ray_min { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
More commented out code.
sign_z: (direction.z < 0.0) as usize, | ||
} | ||
/// This trait can be implemented on anything that can intersect with a `Ray` | ||
pub trait IntersectionRay { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you have your own IntersectionRay impls outside of this library? I'm wondering what the performance tradeoff of using a vtable here vs an enum would be.
Also, is there a reason why IntersectionRay is only implemented for sphere+triangle, but not aabb/capsule/obb?
default = ["f64"] | ||
bench = [] | ||
f64 = [] | ||
# Unfortunately can't use "serde" as the feature name until https://github.com/rust-lang/cargo/issues/5565 lands |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was stabilized in Rust 1.60.
[features] | ||
default = [] | ||
bench = [] | ||
# Unfortunately can't use "serde" as the feature name until https://github.com/rust-lang/cargo/issues/5565 lands |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was stabilized in Rust 1.60.
@@ -0,0 +1,5 @@ | |||
use crate::Vector3; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Empty file.
@@ -0,0 +1,2 @@ | |||
pub mod convex_hull; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also empty.
So I decided to try building a toy pathtracer against this branch, and I'm curious about how users are supposed to use the included shapes? Currently none of them can actually be used in the BVH since none of them have a BHShape impl, so you can't actually include them in the BVH. If you're supposed to shoot rays and intersect them against the included shapes, it'd be nice if they used a Structure of Arrays (SoA) layout (a simple SoA layout gets me ~2x the performance with 100 spheres, or ~3x with 1000 spheres in my pathtracer), however because intersects_ray (from the IntersectionRay impl) doesn't have a way to return an index, you can't currently use your own SOA layouts. I believe IntersectionAABB also doesn't have any way to return an index, so it also can't be used with SOA layouts. edit: Remove outdated info. |
@@ -166,7 +163,8 @@ pub fn traverse_some_bh<BH: BoundingHierarchy>() { | |||
} | |||
|
|||
/// A triangle struct. Instance of a more complex `Bounded` primitive. | |||
#[derive(Debug)] | |||
#[derive(Copy, Clone, Debug)] | |||
#[cfg_attr(feature = "serde_impls", derive(serde::Serialize, serde::Deserialize))] | |||
pub struct Triangle { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like this should be removed since this pr includes a triangle shape, and having 2 public triangle structs is confusing.
@Elabajaba the shapes missing impls are just because I haven't had time to write that code. This PR stems entirely from me writing other code and adding stuff to BVH as I needed it. In terms of the shapes not being able to be used in SOA, I chose not to attach an index to any of the shapes because it's very easy if you want to do that yourself. Just define an IndexedShape that stores the shape and it's index. I didn't think that it made sense to force an index onto every shape. |
Because of the discussion in the other thread: I wouldn't mind a co-maintainer on this. I don't use it much myself currently and I think someone with more stakes in this could really drive it forward a bit. |
I may be interested, I plan to use it quite a bit in the future. I am a bit new to the rust side of things, but I generally worked with c++ metaprogramming before my switch to game engine development in rust. |
How about you start off by making one or two PRs that I'll review and then I can make you contrib from there if we click well? |
@marstaik how do you wanna play this PR? Shall we close it? Shall we leave it open until you have implemented the bits that you are interested in? I don't think the original author is going to return to this any time soon and the rebase is very gnarly at this point. |
I'm going to close this, the original author has already started porting the changes incrementally starting with this: |
#71
Opening the PR, it's definitely not ready to be merged yet there's a couple more things I'm finishing up but I wanted to open earlier so if you wanted to read things over you'd be able to