Skip to content

Commit f795871

Browse files
authored
Release v0.3.0 (#2)
* feat: implement timestep bound estimator * feat: update to the latest slang-hal version * feat: make the abstract gpu model interface more flexible * feat(testbed): add gravity and up-axis customization * feat: add hook state support + trimesh point projection * wip validation tests checkpoint feat: add validation test and comparison generation & visualization * feat: add proper per-collider boundary condition * feat: fix dam_break scenario * fix 2D examples compilation * feat: address CPIC limitation on non-stick boundary conditions * Release v0.3.0
1 parent 3769a2f commit f795871

79 files changed

Lines changed: 6041 additions & 390 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.cargo/config.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[target.wasm32-unknown-unknown]
2+
runner = "wasm-server-runner"
3+
# Needed for getrandom/uuid: https://github.com/uuid-rs/uuid/issues/792
4+
rustflags = ['--cfg', 'getrandom_backend="wasm_js"']

.github/workflows/ci.yaml

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ jobs:
8282
components: clippy
8383

8484
- name: Install dependencies
85-
run: sudo apt-get update; sudo apt-get install --no-install-recommends build-essential curl wget file libssl-dev
85+
run: sudo apt-get update; sudo apt-get install --no-install-recommends build-essential curl wget file libssl-dev libfontconfig1-dev pkg-config
8686

8787
- name: Retrieve Cache for Slang
8888
uses: actions/cache/restore@v4
@@ -96,7 +96,7 @@ jobs:
9696
sweep-cache: true
9797

9898
- name: Run clippy lints
99-
run: SLANG_DIR=$SLANG_DIR cargo clippy --locked --workspace --all-targets -- --deny warnings
99+
run: SLANG_DIR=$SLANG_DIR cargo clippy --locked --workspace --all-targets --features runtime -- --deny warnings
100100

101101
# Check documentation.
102102
doc:
@@ -114,7 +114,7 @@ jobs:
114114
uses: dtolnay/rust-toolchain@stable
115115

116116
- name: Install dependencies
117-
run: sudo apt-get update; sudo apt-get install --no-install-recommends build-essential curl wget file libssl-dev
117+
run: sudo apt-get update; sudo apt-get install --no-install-recommends build-essential curl wget file libssl-dev libfontconfig1-dev pkg-config
118118

119119
- name: Retrieve Cache for Slang
120120
uses: actions/cache/restore@v4
@@ -128,7 +128,7 @@ jobs:
128128
sweep-cache: true
129129

130130
- name: Check documentation
131-
run: SLANG_DIR=$SLANG_DIR cargo doc --locked --workspace --document-private-items --no-deps
131+
run: SLANG_DIR=$SLANG_DIR cargo doc --locked --workspace --document-private-items --no-deps --features runtime
132132
# Testing.
133133
test:
134134
needs: setup-slang # Depends on setup-slang
@@ -149,7 +149,8 @@ jobs:
149149
sudo apt-get update
150150
sudo apt-get install --no-install-recommends -y \
151151
build-essential curl wget file libssl-dev \
152-
libegl1-mesa-dev libgl1-mesa-dri libxcb-xfixes0-dev mesa-vulkan-drivers
152+
libegl1-mesa-dev libgl1-mesa-dri libxcb-xfixes0-dev mesa-vulkan-drivers \
153+
libfontconfig1-dev pkg-config
153154
154155
- name: Retrieve Cache for Slang
155156
uses: actions/cache/restore@v4
@@ -163,4 +164,4 @@ jobs:
163164
sweep-cache: true
164165
- name: Run Cargo Tests
165166
run: |
166-
SLANG_DIR=$SLANG_DIR LIBGL_ALWAYS_SOFTWARE=1 cargo test --verbose
167+
SLANG_DIR=$SLANG_DIR LIBGL_ALWAYS_SOFTWARE=1 cargo test --verbose --features runtime

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,6 @@ dist2d
88
dist3d
99
assets/**/*.bin
1010
src/autogen2d
11-
src/autogen3d
11+
src/autogen3d
12+
validation_results
13+
__pycache__

.run/testbed2d.run.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<component name="ProjectRunConfigurationManager">
22
<configuration default="false" name="testbed2d" type="CargoCommandRunConfiguration" factoryName="Cargo Command">
33
<option name="buildProfileId" value="release" />
4-
<option name="command" value="run --example testbed2" />
4+
<option name="command" value="run --example testbed2 --features runtime" />
55
<option name="workingDirectory" value="file://$PROJECT_DIR$" />
66
<envs />
77
<option name="emulateTerminal" value="true" />

.run/testbed3d.run.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<component name="ProjectRunConfigurationManager">
22
<configuration default="false" name="testbed3d" type="CargoCommandRunConfiguration" factoryName="Cargo Command">
33
<option name="buildProfileId" value="release" />
4-
<option name="command" value="run --example testbed3" />
4+
<option name="command" value="run --example testbed3 --features runtime,webgpu" />
55
<option name="workingDirectory" value="file://$PROJECT_DIR$" />
66
<envs />
77
<option name="emulateTerminal" value="true" />

Cargo.toml

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ members = [
44
"crates/slosh_testbed3d",
55
"crates/slosh2d",
66
"crates/slosh3d",
7+
"validation_tests",
78
]
89
resolver = "2"
910

@@ -15,8 +16,8 @@ bytemuck = { version = "1", features = ["derive"] }
1516
async-channel = "2"
1617
static_assertions = "1"
1718

18-
slang-hal = "0.2"
19-
stensor = "0.2"
19+
slang-hal = "0.3"
20+
stensor = "0.3"
2021

2122
[workspace.lints]
2223
rust.unexpected_cfgs = { level = "warn", check-cfg = [
@@ -25,10 +26,17 @@ rust.unexpected_cfgs = { level = "warn", check-cfg = [
2526

2627
[patch.crates-io]
2728
#slang-hal-derive = { path = "../slang-hal/crates/slang-hal-derive" }
29+
#slang-hal-build = { path = "../slang-hal/crates/slang-hal-build" }
2830
#slang-hal = { path = "../slang-hal/crates/slang-hal" }
2931
#minislang = { path = "../slang-hal/crates/minislang" }
3032
#stensor = { path = "../stensor" }
3133
#nexus2d = { path = "../nexus/crates/nexus2d" }
3234
#nexus3d = { path = "../nexus/crates/nexus3d" }
3335

34-
[profile.release]
36+
#slang-hal-derive = { git = "https://github.com/dimforge/slang-hal", branch = "comptime" }
37+
#slang-hal-build = { git = "https://github.com/dimforge/slang-hal", branch = "comptime" }
38+
#slang-hal = { git = "https://github.com/dimforge/slang-hal", branch = "comptime" }
39+
#minislang = { git = "https://github.com/dimforge/slang-hal", branch = "comptime" }
40+
#stensor = { git = "https://github.com/dimforge/stensor", branch = "comptime" }
41+
#nexus2d = { git = "https://github.com/dimforge/nexus", branch = "comptime" }
42+
#nexus3d = { git = "https://github.com/dimforge/nexus", branch = "comptime" }

crates/slosh2d/Cargo.toml

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name = "slosh2d"
33
authors = ["Sébastien Crozet <sebcrozet@dimforge.com>"]
44
description = "Cross-platform GPU 2D Material Point Method implementation."
55
repository = "https://github.com/dimforge/slosh"
6-
version = "0.2.0"
6+
version = "0.3.0"
77
edition = "2024"
88
license = "Apache-2.0"
99

@@ -19,6 +19,15 @@ required-features = ["dim2"]
1919
default = ["dim2"]
2020
dim2 = []
2121

22+
comptime = [ "nexus2d/comptime", "slosh_testbed2d/comptime" ]
23+
runtime = [ "nexus2d/runtime", "slosh_testbed2d/runtime" ]
24+
25+
webgpu = [ "nexus2d/webgpu", "slosh_testbed2d/webgpu" ]
26+
vulkan = [ "nexus2d/vulkan", "slosh_testbed2d/vulkan" ]
27+
metal = [ "nexus2d/metal", "slosh_testbed2d/metal" ]
28+
cpu = [ "nexus2d/cpu", "slosh_testbed2d/cpu" ]
29+
cuda = [ "nexus2d/cuda", "slosh_testbed2d/cuda" ]
30+
2231
[dependencies]
2332
nalgebra = { workspace = true }
2433
wgpu = { workspace = true }
@@ -30,10 +39,11 @@ static_assertions = { workspace = true }
3039

3140
#wgcore = "0.2"
3241
#wgebra = "0.2"
33-
nexus2d = "0.2.1"
42+
nexus2d = "0.3"
43+
bvh = "0.12.0"
3444

3545
# TODO: make rapier optional?
36-
rapier2d = "0.30"
46+
rapier2d = "0.31"
3747

3848
# For wasm?
3949
getrandom = { version = "0.3.1", features = ["wasm_js"] }
@@ -46,9 +56,11 @@ futures-test = "0.3"
4656
serial_test = "3"
4757
approx = "0.5"
4858
async-std = { version = "1", features = ["attributes"] }
49-
slosh_testbed2d = { path = "../slosh_testbed2d", features = ["dim2"] }
59+
slosh_testbed2d = { path = "../slosh_testbed2d", features = ["dim2"], default-features = false }
5060
kiss3d = { version = "0.37.0" }
5161

5262
[build-dependencies]
53-
minislang = "0.2"
54-
nexus2d = "0.2" # to access its shaders at compile-time
63+
minislang = "0.3"
64+
include_dir = "0.7"
65+
slang-hal-build = "0.3"
66+
nexus2d = "0.3" # to access its shaders at compile-time

crates/slosh2d/build.rs

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,26 @@
1-
use minislang::{SlangCompiler, shader_slang::CompileTarget};
2-
use std::path::PathBuf;
3-
use std::str::FromStr;
1+
#[cfg(not(feature = "comptime"))]
2+
pub fn main() {}
43

4+
#[cfg(feature = "comptime")]
55
pub fn main() {
6-
println!("cargo:rerun-if-changed=../../shaders");
6+
use slang_hal_build::ShaderCompiler;
7+
use std::env;
78

8-
let mut slang = SlangCompiler::new(vec![PathBuf::from_str("../../shaders").unwrap()]);
9-
nexus2d::register_shaders(&mut slang);
9+
const SLANG_SRC_DIR: include_dir::Dir<'_> =
10+
include_dir::include_dir!("$CARGO_MANIFEST_DIR/../../shaders");
1011

11-
let targets = [CompileTarget::Wgsl]; // , CompileTarget::CudaSource];
12+
let out_dir = env::var("OUT_DIR").expect("Couldn't determine output directory.");
13+
let mut compiler = ShaderCompiler::new(vec![], &out_dir);
14+
compiler.add_dir(nexus2d::re_exports::stensor::SLANG_SRC_DIR);
15+
compiler.add_dir(nexus2d::SLANG_SRC_DIR);
16+
compiler.add_dir(SLANG_SRC_DIR);
17+
compiler.set_global_macro("DIM", "2");
18+
compiler.set_global_macro("COMPTIME", "1");
1219

13-
for target in targets {
14-
slang.compile_all(
15-
target,
16-
"../../shaders",
17-
"../../src/autogen2d",
18-
&[
19-
("DIM".to_string(), "2".to_string()),
20-
("COMPILE_CHECK".to_string(), "1".to_string()),
21-
],
22-
);
23-
}
20+
// Compile all shaders from examples/shaders directory.
21+
// Note: slang-hal-build will automatically detect which backends to compile for
22+
// based on the cargo features enabled during the build.
23+
compiler
24+
.compile_shaders_dir("../../shaders", &[])
25+
.expect("Failed to compile shaders");
2426
}
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
use slosh_testbed2d::{RapierData, slosh};
2+
3+
use nalgebra::{point, vector};
4+
use rapier2d::prelude::{ColliderBuilder, RigidBodyBuilder};
5+
use slang_hal::backend::WebGpu;
6+
use slosh::{
7+
pipeline::MpmData,
8+
solver::{Particle, SimulationParams},
9+
};
10+
use slosh_testbed2d::{AppState, PhysicsContext};
11+
use slosh2d::solver::{GpuBoundaryCondition, ParticleModel};
12+
13+
#[allow(dead_code)]
14+
fn main() {
15+
panic!("Run the `testbed2` example instead.");
16+
}
17+
18+
pub fn beam_demo(backend: &WebGpu, app_state: &mut AppState) -> PhysicsContext {
19+
let mut rapier_data = RapierData::default();
20+
21+
let width = 10.0;
22+
let height = 2.0;
23+
let fixed_part = 1.0;
24+
let cell_width = 0.2;
25+
let particle_per_cell_dim = 2;
26+
let young_modulus = 1.0e8;
27+
let poisson_ratio = 0.3;
28+
29+
let diameter = cell_width / particle_per_cell_dim as f32;
30+
let ni = ((width + fixed_part) / diameter).ceil() as usize;
31+
let nj = (height / diameter).ceil() as usize;
32+
33+
let mut particles = vec![];
34+
for i in 0..ni {
35+
for j in 0..nj {
36+
let position = point![i as f32, j as f32] * diameter;
37+
let density = 1000.0;
38+
let radius = diameter / 2.0;
39+
let model = ParticleModel::elastic_neo_hookean(young_modulus, poisson_ratio);
40+
particles.push(Particle::new(position, radius, density, model));
41+
}
42+
}
43+
44+
if !app_state.restarting {
45+
app_state.min_num_substeps = 150;
46+
app_state.max_num_substeps = 150;
47+
app_state.gravity_factor = 1.0;
48+
};
49+
50+
let params = SimulationParams {
51+
gravity: vector![0.0, -9.81] * app_state.gravity_factor,
52+
dt: 1.0 / 60.0,
53+
padding: 0.0,
54+
};
55+
56+
let rb = RigidBodyBuilder::fixed()
57+
.translation(vector![0.0, height / 2.0])
58+
.build();
59+
let rb_handle = rapier_data.bodies.insert(rb);
60+
let co = ColliderBuilder::cuboid(fixed_part, height);
61+
let ground = rapier_data
62+
.colliders
63+
.insert_with_parent(co, rb_handle, &mut rapier_data.bodies);
64+
65+
let data = MpmData::new(
66+
backend,
67+
params,
68+
&particles,
69+
&rapier_data.bodies,
70+
&rapier_data.colliders,
71+
&[(ground, GpuBoundaryCondition::stick())],
72+
cell_width,
73+
30_000,
74+
)
75+
.unwrap();
76+
PhysicsContext {
77+
data,
78+
rapier_data,
79+
callbacks: vec![],
80+
hooks_state: None,
81+
}
82+
}

crates/slosh2d/examples/elastic_cut2.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use slosh2d::solver::ParticleModel;
1212

1313
#[allow(dead_code)]
1414
fn main() {
15-
panic!("Run the `testbed3` example instead.");
15+
panic!("Run the `testbed2` example instead.");
1616
}
1717

1818
pub fn elastic_cut_demo(backend: &WebGpu, app_state: &mut AppState) -> PhysicsContext {
@@ -26,6 +26,7 @@ pub fn elastic_cut_demo(backend: &WebGpu, app_state: &mut AppState) -> PhysicsCo
2626
for j in 0..700 {
2727
let position =
2828
point![i as f32 + 0.5, j as f32 + 0.5] * cell_width / 2.0 + Vector2::y() * offset_y;
29+
2930
let density = 1000.0;
3031
let radius = cell_width / 4.0;
3132
let model = ParticleModel::elastic(5.0e6, 0.2);
@@ -34,13 +35,13 @@ pub fn elastic_cut_demo(backend: &WebGpu, app_state: &mut AppState) -> PhysicsCo
3435
}
3536

3637
if !app_state.restarting {
37-
app_state.num_substeps = 15;
38+
app_state.max_num_substeps = 15;
3839
app_state.gravity_factor = 1.0;
3940
};
4041

4142
let params = SimulationParams {
4243
gravity: vector![0.0, -9.81] * app_state.gravity_factor,
43-
dt: (1.0 / 60.0) / (app_state.num_substeps as f32),
44+
dt: 1.0 / 60.0,
4445
padding: 0.0,
4546
};
4647

@@ -96,13 +97,15 @@ pub fn elastic_cut_demo(backend: &WebGpu, app_state: &mut AppState) -> PhysicsCo
9697
&particles,
9798
&rapier_data.bodies,
9899
&rapier_data.colliders,
100+
&[],
99101
cell_width,
100-
60_000,
102+
30_000,
101103
)
102104
.unwrap();
103105
PhysicsContext {
104106
data,
105107
rapier_data,
106108
callbacks: vec![],
109+
hooks_state: None,
107110
}
108111
}

0 commit comments

Comments
 (0)