Skip to content

Commit

Permalink
Merge pull request #112 from Azkellas/parallelize-grid
Browse files Browse the repository at this point in the history
Parallelize generate_grid_sdf
  • Loading branch information
Azkellas authored Sep 16, 2024
2 parents 66c4461 + ee621e1 commit 1cb5566
Show file tree
Hide file tree
Showing 13 changed files with 1,004 additions and 551 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
target
mutants.out
mutants.out.old
.vscode/launch.json
6 changes: 4 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions mesh_to_sdf/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

## Unreleased

### Changed

- `generate_grid_sdf` is now fully parallelized. It's between 10x and 20x faster on a high end cpu, depending on the number of triangles and the grid resolution.


## [0.3.0]

### Added
Expand Down
5 changes: 4 additions & 1 deletion mesh_to_sdf/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,13 @@ bvh = "0.10.0"
glam = { version = "0.29.0", optional = true }
mint = { version = "0.5.9", optional = true }
cgmath = { version = "0.18.0", optional = true }
nalgebra = "0.33.0" # required for bvh.
# required for bvh.
nalgebra = "0.33.0"

serde = { version = "1.0.210", features = ["derive"], optional = true }
rmp-serde = { version = "1.3.0", optional = true }
parking_lot = "0.12.3"
web-time = "1.1.0"

[features]
cgmath = ["dep:cgmath"]
Expand Down
69 changes: 68 additions & 1 deletion mesh_to_sdf/benches/generate_grid_sdf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,72 @@ fn criterion_benchmark(c: &mut Criterion) {
});
}

fn criterion_benchmark_big(c: &mut Criterion) {
// env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("info")).init();

let path = "assets/knight.glb";
let gltf = easy_gltf::load(path).unwrap();

let model = &gltf.first().unwrap().models[0];
let vertices = model.vertices();
let indices = model.indices().unwrap();

let xbounds = vertices.iter().map(|v| v.position.x).minmax();
let ybounds = vertices.iter().map(|v| v.position.y).minmax();
let zbounds = vertices.iter().map(|v| v.position.z).minmax();

let MinMaxResult::MinMax(xmin, xmax) = xbounds else {
panic!("No vertices");
};
let MinMaxResult::MinMax(ymin, ymax) = ybounds else {
panic!("No vertices");
};
let MinMaxResult::MinMax(zmin, zmax) = zbounds else {
panic!("No vertices");
};

let vertices = vertices
.iter()
.map(|v| [v.position.x, v.position.y, v.position.z])
.collect_vec();

let cell_count = [100, 100, 100];
let grid =
mesh_to_sdf::Grid::from_bounding_box(&[xmin, ymin, zmin], &[xmax, ymax, zmax], cell_count);

println!("vertices: {:?}", vertices.len());
println!("triangles: {:?}", indices.len() / 3);
println!("grid size: {cell_count:?}");

c.bench_function("generate_grid_sdf_normal_big", |b| {
b.iter(|| {
mesh_to_sdf::generate_grid_sdf(
black_box(&vertices),
black_box(mesh_to_sdf::Topology::TriangleList(Some(indices))),
black_box(&grid),
black_box(mesh_to_sdf::SignMethod::Normal),
);
});
});

c.bench_function("generate_grid_sdf_raycast_big", |b| {
b.iter(|| {
mesh_to_sdf::generate_grid_sdf(
black_box(&vertices),
black_box(mesh_to_sdf::Topology::TriangleList(Some(indices))),
black_box(&grid),
black_box(mesh_to_sdf::SignMethod::Raycast),
);
});
});
}

criterion_group!(benches, criterion_benchmark);
criterion_main!(benches);

criterion_group! {
name = benches_big;
config = Criterion::default().sample_size(10);
targets = criterion_benchmark_big
}

criterion_main!(benches, benches_big);
Loading

0 comments on commit 1cb5566

Please sign in to comment.