Skip to content

Commit 73b200b

Browse files
committed
Initial implementation of slosh
1 parent dddf1e0 commit 73b200b

67 files changed

Lines changed: 7601 additions & 25 deletions

Some content is hidden

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

.gitignore

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/target
2+
*.lock
3+
.vscode
4+
.idea
5+
.DS_Store
6+
dist
7+
dist2d
8+
dist3d
9+
assets/**/*.bin
10+
src/autogen2d
11+
src/autogen3d

Cargo.toml

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
[workspace]
2+
members = [
3+
"crates/slosh-testbed2d",
4+
"crates/slosh-testbed3d",
5+
"crates/slosh2d",
6+
"crates/slosh3d",
7+
]
8+
resolver = "2"
9+
10+
[workspace.dependencies]
11+
nalgebra = { version = "0.34", features = ["convert-bytemuck"] }
12+
wgpu = { version = "26", features = ["naga-ir"] }
13+
encase = { version = "0.11", features = [ "nalgebra" ] }
14+
bytemuck = { version = "1", features = ["derive"] }
15+
async-channel = "2"
16+
17+
slang-hal = "0.1"
18+
stensor = "0.1"
19+
20+
[workspace.lints]
21+
rust.unexpected_cfgs = { level = "warn", check-cfg = [
22+
'cfg(feature, values("dim2", "dim3"))',
23+
] }
24+
25+
[patch.crates-io]
26+
#shader-slang = { path = "../slang-rs" }
27+
slang-hal-derive = { path = "../slang-hal/crates/slang-hal-derive" }
28+
slang-hal = { path = "../slang-hal/crates/slang-hal" }
29+
minislang = { path = "../slang-hal/crates/minislang" }
30+
stensor = { path = "../stensor" }
31+
nexus2d = { path = "../nexus/crates/nexus2d" }
32+
nexus3d = { path = "../nexus/crates/nexus3d" }
33+
encase = { path = "../encase" }
34+
kiss3d = { path = "../kiss3d" }
35+
36+
#wgcore = { git = "https://github.com/dimforge/wgmath.git", rev = "6d17942bd841efdfcc696d8455b22be3a8ddfe8d" }
37+
#wgcore-derive = { git = "https://github.com/dimforge/wgmath.git", rev = "6d17942bd841efdfcc696d8455b22be3a8ddfe8d" }
38+
#wgebra = { git = "https://github.com/dimforge/wgmath.git", rev = "6d17942bd841efdfcc696d8455b22be3a8ddfe8d" }
39+
#nexus3d = { git = "https://github.com/dimforge/wgmath.git", rev = "6d17942bd841efdfcc696d8455b22be3a8ddfe8d" }
40+
#nexus2d = { git = "https://github.com/dimforge/wgmath.git", rev = "6d17942bd841efdfcc696d8455b22be3a8ddfe8d" }
41+
#nexus3d = { git = "https://github.com/dimforge/wgmath.git", rev = "6d17942bd841efdfcc696d8455b22be3a8ddfe8d" }
42+
#nexus2d = { git = "https://github.com/dimforge/wgmath.git", rev = "6d17942bd841efdfcc696d8455b22be3a8ddfe8d" }
43+
44+
#wgcore = { path = "../wgmath/crates/wgcore" }
45+
#wgcore-derive = { path = "../wgmath/crates/wgcore-derive" }
46+
#wgebra = { path = "../wgmath/crates/wgebra" }
47+
#nexus3d = { path = "../wgmath/crates/nexus/crates/impulse3d" }
48+
#impulse2d = { path = "../wgmath/crates/impulse/crates/impulse2d" }
49+
#impulse3d = { path = "../wgmath/crates/impulse/crates/impulse3d" }
50+
#impulse2d = { path = "../wgmath/crates/impulse/crates/impulse2d" }
51+
#
52+
#parry2d = { git = "https://github.com/dimforge/parry.git", rev = "407fb449504dde7ba0a3d80a8de7e37ac991a77a" }
53+
#parry3d = { git = "https://github.com/dimforge/parry.git", rev = "407fb449504dde7ba0a3d80a8de7e37ac991a77a" }
54+
#encase = { git = "https://github.com/sebcrozet/encase.git", rev = "6755c1414c225cbeac9fde1ff9394b70d3b05404" }
55+
##wgcore = { git = "https://github.com/dimforge/wgmath.git", rev = "95538845080ef8680cf9906f1949623e30be3495" }
56+
##wgcore-derive = { git = "https://github.com/dimforge/wgmath.git", rev = "95538845080ef8680cf9906f1949623e30be3495" }
57+
##wgebra = { git = "https://github.com/dimforge/wgmath.git", rev = "95538845080ef8680cf9906f1949623e30be3495" }
58+
##impulse3d = { git = "https://github.com/dimforge/wgmath.git", rev = "95538845080ef8680cf9906f1949623e30be3495" }
59+
##impulse2d = { git = "https://github.com/dimforge/wgmath.git", rev = "95538845080ef8680cf9906f1949623e30be3495" }
60+
##impulse3d = { git = "https://github.com/dimforge/wgmath.git", rev = "95538845080ef8680cf9906f1949623e30be3495" }
61+
##impulse2d = { git = "https://github.com/dimforge/wgmath.git", rev = "95538845080ef8680cf9906f1949623e30be3495" }
62+
#rapier3d = { git = "https://github.com/vrixyz/rapier.git", branch = "uber_physics_context" }
63+
64+
[profile.release]
65+
opt-level = 'z'

LICENSE renamed to LICENSE-APACHE

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -174,28 +174,3 @@
174174
of your accepting any such warranty or additional liability.
175175

176176
END OF TERMS AND CONDITIONS
177-
178-
APPENDIX: How to apply the Apache License to your work.
179-
180-
To apply the Apache License to your work, attach the following
181-
boilerplate notice, with the fields enclosed by brackets "[]"
182-
replaced with your own identifying information. (Don't include
183-
the brackets!) The text should be enclosed in the appropriate
184-
comment syntax for the file format. We also recommend that a
185-
file or class name and description of purpose be included on the
186-
same "printed page" as the copyright notice for easier
187-
identification within third-party archives.
188-
189-
Copyright [yyyy] [name of copyright owner]
190-
191-
Licensed under the Apache License, Version 2.0 (the "License");
192-
you may not use this file except in compliance with the License.
193-
You may obtain a copy of the License at
194-
195-
http://www.apache.org/licenses/LICENSE-2.0
196-
197-
Unless required by applicable law or agreed to in writing, software
198-
distributed under the License is distributed on an "AS IS" BASIS,
199-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200-
See the License for the specific language governing permissions and
201-
limitations under the License.

README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Slosh: cross-platform MPM GPU physics simulation
2+
3+
<p align="center">
4+
<img src="assets/slosh-logo.png" alt="crates.io" width="400px">
5+
</p>
6+
<p align="center">
7+
<a href="https://discord.gg/vt9DJSW">
8+
<img src="https://img.shields.io/discord/507548572338880513.svg?logo=discord&colorB=7289DA">
9+
</a>
10+
</p>
11+
12+
# Running the examples
13+
14+
1. Download the Slang compiler libraries for your platform: https://github.com/shader-slang/slang/releases/tag/v2025.16
15+
2. Unzip the downloaded directory, and use its path as value to the `SLANG_DIR` environment variable: `SLANG_DIR=/path/to/slang`.
16+
Note that the variable must point to the root of the slang installation (i.e. the directory that contains `bin` and `lib`).
17+
3. For the 2D examples, run `cargo run --release --example testbed2`
18+
4. For the 3D examples, run `cargo run --release --example testbed3`

assets/slosh-logo.png

1.46 MB
Loading

build_wasm.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/sh
2+
3+
cargo build --example testbed2 --release --target wasm32-unknown-unknown --features dim2
4+
cargo build --example testbed3 --release --target wasm32-unknown-unknown --features dim3
5+
wasm-bindgen --no-typescript --target web --out-dir dist2d --out-name testbed2 ./target/wasm32-unknown-unknown/release/examples/testbed2.wasm
6+
wasm-bindgen --no-typescript --target web --out-dir dist3d --out-name testbed3 ./target/wasm32-unknown-unknown/release/examples/testbed3.wasm
7+
wasm-opt -Oz -o ./dist2d/opt.wasm ./dist2d/testbed2_bg.wasm && mv ./dist2d/opt.wasm ./dist2d/testbed2_bg.wasm
8+
wasm-opt -Oz -o ./dist3d/opt.wasm ./dist3d/testbed3_bg.wasm && mv ./dist3d/opt.wasm ./dist3d/testbed3_bg.wasm
9+
10+
brotli ./dist2d/testbed2_bg.wasm && mv ./dist2d/testbed2_bg.wasm.br ./dist2d/testbed2_bg.wasm
11+
brotli ./dist3d/testbed3_bg.wasm && mv ./dist3d/testbed3_bg.wasm.br ./dist3d/testbed3_bg.wasm

crates/slosh-testbed2d/Cargo.toml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
[package]
2+
name = "slosh_testbed2d"
3+
version = "0.1.0"
4+
license = "Apache-2.0"
5+
edition = "2021"
6+
7+
[lints]
8+
workspace = true
9+
10+
[lib]
11+
name = "slosh_testbed2d"
12+
path = "../../src_testbed/lib.rs"
13+
required-features = ["dim2"]
14+
15+
[features]
16+
dim2 = []
17+
default = ["dim2"]
18+
19+
[dependencies]
20+
nalgebra = { workspace = true, features = ["rand"] }
21+
wgpu = { workspace = true }
22+
bytemuck = { workspace = true }
23+
async-channel = { workspace = true }
24+
encase = { workspace = true }
25+
26+
slang-hal = { workspace = true }
27+
stensor = { workspace = true }
28+
nexus2d = "0.1"
29+
30+
futures-test = "0.3"
31+
serial_test = "3"
32+
approx = "0.5"
33+
async-std = { version = "1", features = ["attributes"] }
34+
slosh2d = { path = "../slosh2d" }
35+
futures = "0.3"
36+
regex = "1"
37+
38+
kiss3d = { version = "0.35", features = [ "vertex_index_u32" ] }

crates/slosh-testbed3d/Cargo.toml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
[package]
2+
name = "slosh_testbed3d"
3+
version = "0.1.0"
4+
license = "Apache-2.0"
5+
edition = "2021"
6+
7+
[lints]
8+
workspace = true
9+
10+
[lib]
11+
name = "slosh_testbed3d"
12+
path = "../../src_testbed/lib.rs"
13+
required-features = ["dim3"]
14+
15+
[features]
16+
dim3 = []
17+
default = ["dim3"]
18+
19+
[dependencies]
20+
nalgebra = { workspace = true, features = ["rand"] }
21+
wgpu = { workspace = true }
22+
bytemuck = { workspace = true }
23+
async-channel = { workspace = true }
24+
encase = { workspace = true }
25+
26+
slang-hal = { workspace = true }
27+
stensor = { workspace = true }
28+
nexus3d = "0.1"
29+
30+
futures-test = "0.3"
31+
serial_test = "3"
32+
approx = "0.5"
33+
async-std = { version = "1", features = ["attributes"] }
34+
slosh3d = { path = "../slosh3d" }
35+
futures = "0.3"
36+
regex = "1"
37+
38+
kiss3d = { version = "0.35", features = [ "vertex_index_u32" ] }

crates/slosh2d/Cargo.toml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
[package]
2+
name = "slosh2d"
3+
version = "0.1.0"
4+
license = "Apache-2.0"
5+
edition = "2021"
6+
7+
[lints]
8+
workspace = true
9+
10+
[lib]
11+
name = "slosh2d"
12+
path = "../../src/lib.rs"
13+
required-features = ["dim2"]
14+
15+
[features]
16+
default = ["dim2"]
17+
dim2 = []
18+
19+
[dependencies]
20+
nalgebra = { workspace = true }
21+
wgpu = { workspace = true }
22+
encase = { workspace = true }
23+
slang-hal = { workspace = true }
24+
stensor = { workspace = true }
25+
bytemuck = { workspace = true }
26+
27+
#wgcore = "0.2"
28+
#wgebra = "0.2"
29+
nexus2d = "0.1"
30+
31+
# TODO: make rapier optional?
32+
rapier2d = "0.28"
33+
34+
# For wasm?
35+
getrandom = { version = "0.3.1", features = ["wasm_js"] }
36+
uuid = { version = "1", features = ["js"] }
37+
38+
[dev-dependencies]
39+
nalgebra = { version = "0.34", features = ["rand"] }
40+
futures-test = "0.3"
41+
serial_test = "3"
42+
approx = "0.5"
43+
async-std = { version = "1", features = ["attributes"] }
44+
slosh_testbed2d = { path = "../slosh-testbed2d", features = ["dim2"] }
45+
46+
[build-dependencies]
47+
minislang = "0.1"
48+
nexus2d = "0.1" # to access its shaders at compile-time

crates/slosh2d/build.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
use minislang::{shader_slang::CompileTarget, SlangCompiler};
2+
use std::path::PathBuf;
3+
use std::str::FromStr;
4+
5+
pub fn main() {
6+
println!("cargo:rerun-if-changed=../../shaders");
7+
8+
let mut slang = SlangCompiler::new(vec![PathBuf::from_str("../../shaders").unwrap()]);
9+
nexus2d::register_shaders(&mut slang);
10+
11+
let targets = [CompileTarget::Wgsl, CompileTarget::CudaSource];
12+
13+
for target in targets {
14+
slang.compile_all(
15+
target,
16+
"../../shaders",
17+
"../../src/autogen2d",
18+
&[("DIM".to_string(), "2".to_string())],
19+
);
20+
}
21+
}

0 commit comments

Comments
 (0)