Skip to content

Commit eafbb2f

Browse files
committed
Upgrade to Bevy main.
1 parent 94d937b commit eafbb2f

35 files changed

Lines changed: 1852 additions & 1879 deletions

File tree

‎Cargo.lock‎

Lines changed: 866 additions & 1178 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Cargo.toml‎

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,11 @@ cuda = ["dep:processing_cuda", "processing_cuda/cuda"]
1818
[workspace]
1919
resolver = "3"
2020
members = ["crates/*", "tools/*"]
21+
# TEMP(bevy-020): bevy_seedling pins bevy 0.19
22+
exclude = ["crates/processing_audio"]
2123

2224
[workspace.package]
23-
rust-version = "1.95"
25+
rust-version = "1.100"
2426

2527
[workspace.lints.clippy]
2628
type_complexity = "allow"
@@ -52,17 +54,16 @@ bevy = { git = "https://github.com/processing/bevy", branch = "main", default-fe
5254
"wayland",
5355
"webgl2",
5456
"x11",
55-
"shader_format_wesl",
5657
"free_camera",
5758
"pan_camera",
5859

5960
# image formats Processing loads
6061
"jpeg",
6162
] }
62-
bevy_naga_reflect = { git = "https://github.com/tychedelia/bevy_naga_reflect" }
63+
bevy_naga_reflect = { git = "https://github.com/tychedelia/bevy_naga_reflect", branch = "bevy-020-fixes" }
6364
bevy_cuda = { git = "https://github.com/tychedelia/bevy_cuda" }
6465
naga = { version = "29", features = ["wgsl-in"] }
65-
wesl = { version = "0.3", default-features = false }
66+
wesl = { version = "0.6", features = ["naga-ext"] }
6667
pyo3 = { git = "https://github.com/PyO3/pyo3", branch = "main" }
6768
pyo3-introspection = { git = "https://github.com/PyO3/pyo3", branch = "main" }
6869
processing = { path = "." }
@@ -71,7 +72,8 @@ processing_cuda = { path = "crates/processing_cuda" }
7172
processing_pyo3 = { path = "crates/processing_pyo3" }
7273
processing_render = { path = "crates/processing_render" }
7374
processing_midi = { path = "crates/processing_midi" }
74-
processing_audio = { path = "crates/processing_audio" }
75+
# TEMP(bevy-020): bevy_seedling pins bevy 0.19
76+
# processing_audio = { path = "crates/processing_audio" }
7577
processing_input = { path = "crates/processing_input" }
7678
processing_glfw = { path = "crates/processing_glfw" }
7779
processing_webcam = { path = "crates/processing_webcam" }
@@ -83,7 +85,8 @@ bevy = { workspace = true }
8385
processing_core = { workspace = true }
8486
processing_render = { workspace = true }
8587
processing_midi = { workspace = true }
86-
processing_audio = { workspace = true }
88+
# TEMP(bevy-020): bevy_seedling pins bevy 0.19
89+
# processing_audio = { workspace = true }
8790
processing_input = { workspace = true }
8891
processing_webcam = { workspace = true, optional = true }
8992
processing_cuda = { workspace = true, optional = true }

‎assets/shaders/custom_vertex.wesl‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { processing::VertexOutput };
2-
import { processing::mesh::{Vertex, vertex_output} };
2+
import { processing::mesh::{Vertex, vertex_input, vertex_output} };
33

44
@group(3) @binding(0) var<uniform> bulge: f32;
55

66
@vertex
77
fn vertex(vertex_in: Vertex) -> VertexOutput {
8-
var vertex = vertex_in;
8+
var vertex = vertex_input(vertex_in);
99
// `sphere()` draws a unit sphere scaled by its transform
1010
vertex.position += vertex.normal * bulge * sin(vertex.position.y * 12.0);
1111
return vertex_output(vertex);

‎crates/processing_midi/Cargo.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ rust-version.workspace = true
77
[dependencies]
88
bevy = { workspace = true }
99
processing_core = { workspace = true }
10-
nannou_midi = { git = "https://github.com/nannou-org/nannou", branch = "bevy-refactor" }
10+
nannou_midi = { git = "https://github.com/tychedelia/nannou", branch = "bevy-020" }
1111

1212
[target.'cfg(target_os = "macos")'.dependencies]
1313
midir = { version = "0.11", features = ["coremidi_send_timestamped"] }

‎crates/processing_pyo3/examples/Demos/Tests/first_frame.py‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@
77
from random import seed, uniform
88

99
points = None
10+
instances = None
11+
instance = None
1012
mat = None
1113

1214

1315
def setup():
14-
global points, mat
16+
global points, instances, instance, mat
1517
size(800, 600)
1618
mode_3d()
1719

@@ -25,6 +27,13 @@ def setup():
2527
positions.append([220 + uniform(-60, 60), 120 + uniform(-60, 60), uniform(-60, 60)])
2628
points.buffer("position").write(positions)
2729

30+
instances = create_particles(7, attributes=[Attribute.position()])
31+
positions = []
32+
for i in range(7):
33+
positions.append([-150 + i * 50, -30, 0])
34+
instances.buffer("position").write(positions)
35+
instance = Geometry.sphere(16, 12, 8)
36+
2837

2938
def draw():
3039
camera_position(0.0, 0.0, 500.0)
@@ -71,5 +80,8 @@ def draw():
7180
# particle points
7281
particles(points)
7382

83+
# instanced particles
84+
particles(instances, instance)
85+
7486

7587
run()

‎crates/processing_pyo3/src/color.rs‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,9 @@ fn components(color: &Color) -> [f32; 4] {
132132
Color::Lcha(c) => c.to_f32_array(),
133133
Color::Oklaba(c) => c.to_f32_array(),
134134
Color::Oklcha(c) => c.to_f32_array(),
135+
Color::Okhsla(c) => c.to_f32_array(),
136+
Color::Okhsva(c) => c.to_f32_array(),
137+
Color::Okhwba(c) => c.to_f32_array(),
135138
Color::Xyza(c) => c.to_f32_array(),
136139
}
137140
}
@@ -148,6 +151,9 @@ fn components_no_alpha(color: &Color) -> [f32; 3] {
148151
Color::Lcha(c) => c.to_f32_array_no_alpha(),
149152
Color::Oklaba(c) => c.to_f32_array_no_alpha(),
150153
Color::Oklcha(c) => c.to_f32_array_no_alpha(),
154+
Color::Okhsla(c) => c.to_f32_array_no_alpha(),
155+
Color::Okhsva(c) => c.to_f32_array_no_alpha(),
156+
Color::Okhwba(c) => c.to_f32_array_no_alpha(),
151157
Color::Xyza(c) => c.to_f32_array_no_alpha(),
152158
}
153159
}

‎crates/processing_render/Cargo.toml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ x11 = ["bevy/x11"]
1616
bevy = { workspace = true }
1717
bevy_naga_reflect = { workspace = true }
1818
# direct wgpu dep to reach `wgpu::util::TextureBlitter` (unifies to bevy's wgpu)
19-
wgpu = "29"
19+
wgpu = "30"
2020
naga = { workspace = true }
2121
wesl = { workspace = true }
2222
lyon = "1.0"
@@ -32,7 +32,7 @@ png = "0.18"
3232
processing_core = { workspace = true }
3333

3434
[build-dependencies]
35-
wesl = { workspace = true, features = ["package"] }
35+
serde_json = "1"
3636

3737
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
3838
bevy = { workspace = true, features = ["file_watcher"] }

‎crates/processing_render/build.rs‎

Lines changed: 149 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,158 @@
1+
use std::fmt::Write;
12
use std::path::Path;
23

3-
// packages wesl libraries for processing and lygia
4-
// note that bevy does not (as of yet) understand how to use these packages
5-
// they are, instead, used by us as part of shader pre-processing in the
6-
// processing_render crate
4+
// Embeds the `processing` and `lygia` WESL packages as tables of module sources; they are
5+
// registered with bevy at startup, so any shader can import them.
76
fn main() {
8-
wesl::PkgBuilder::new("processing")
9-
.scan_root("shaders/processing")
10-
.expect("failed to scan processing WESL files")
11-
.build_artifact()
12-
.expect("failed to build processing package artifact");
7+
let mut code = String::new();
8+
package(
9+
&mut code,
10+
"PROCESSING",
11+
"processing",
12+
Path::new("shaders/processing"),
13+
);
14+
package(&mut code, "LYGIA", "lygia", Path::new("../../lygia"));
15+
engine(&mut code);
16+
let out = Path::new(&std::env::var_os("OUT_DIR").unwrap()).join("shader_modules.rs");
17+
std::fs::write(out, code).unwrap();
18+
}
19+
20+
// Bevy's own shader modules that ours import, for editors to resolve those imports. A bevy
21+
// module is named after its crate and its path under `src`.
22+
fn engine(code: &mut String) {
23+
let query = |offline: &[&str]| {
24+
std::process::Command::new(std::env::var_os("CARGO").unwrap())
25+
.args(["metadata", "--format-version", "1", "--locked"])
26+
.args(offline)
27+
.output()
28+
.expect("cargo metadata")
29+
};
30+
let mut metadata = query(&["--offline"]);
31+
if !metadata.status.success() {
32+
// it reads every package in the lockfile, and a build only downloads its own platform's
33+
println!(
34+
"cargo::warning=downloading the other platforms' packages to locate bevy's shaders"
35+
);
36+
metadata = query(&[]);
37+
}
38+
assert!(
39+
metadata.status.success(),
40+
"cargo metadata failed: {}",
41+
String::from_utf8_lossy(&metadata.stderr)
42+
);
43+
let metadata: serde_json::Value = serde_json::from_slice(&metadata.stdout).unwrap();
44+
let crates: std::collections::BTreeMap<String, std::path::PathBuf> = metadata["packages"]
45+
.as_array()
46+
.unwrap()
47+
.iter()
48+
.filter_map(|package| {
49+
let name = package["name"].as_str()?;
50+
let manifest = Path::new(package["manifest_path"].as_str()?);
51+
name.starts_with("bevy_")
52+
.then(|| (name.to_string(), manifest.parent().unwrap().join("src")))
53+
})
54+
.collect();
1355

14-
let mut lygia = wesl::PkgBuilder::new("lygia")
15-
.scan_root("../../lygia")
16-
.expect("failed to scan Lygia WESL files");
17-
wesl_only(&mut lygia.root, Path::new("../../lygia"));
18-
lygia.root.submodules.retain(|sub| sub.name != "test");
19-
lygia
20-
.build_artifact()
21-
.expect("failed to build Lygia package artifact");
56+
// the crates our packages import, and the crates those import
57+
let mut wanted: Vec<String> = Vec::new();
58+
let mut sources: Vec<String> = ["shaders/processing.wesl", "shaders/processing"]
59+
.iter()
60+
.flat_map(|path| wesl_files(Path::new(path)))
61+
.map(|path| std::fs::read_to_string(path).unwrap())
62+
.collect();
63+
let mut modules = Vec::new();
64+
while let Some(source) = sources.pop() {
65+
for name in crates.keys() {
66+
if source.contains(&format!("{name}::")) && !wanted.contains(name) {
67+
wanted.push(name.clone());
68+
let mut found = Vec::new();
69+
walk(&crates[name], name, "", &mut found);
70+
for (_, _, path) in &found {
71+
sources.push(std::fs::read_to_string(path).unwrap());
72+
}
73+
modules.extend(found);
74+
}
75+
}
76+
}
77+
modules.sort();
78+
table(code, "ENGINE", modules);
2279
}
2380

24-
// lygia's manifest includes `**/*.wesl` only; the scan also picks up its legacy `.wgsl`
25-
fn wesl_only(module: &mut wesl::Module, path: &Path) {
26-
if !path.with_extension("wesl").is_file() {
27-
module.source.clear();
81+
fn wesl_files(path: &Path) -> Vec<std::path::PathBuf> {
82+
if path.is_file() {
83+
return vec![path.to_path_buf()];
2884
}
29-
for sub in &mut module.submodules {
30-
wesl_only(sub, &path.join(&sub.name));
85+
let mut files = Vec::new();
86+
for entry in std::fs::read_dir(path).into_iter().flatten().flatten() {
87+
let path = entry.path();
88+
if path.is_dir() || path.extension().is_some_and(|ext| ext == "wesl") {
89+
files.extend(wesl_files(&path));
90+
}
91+
}
92+
files
93+
}
94+
95+
// A package is a directory of modules; its root module is the `.wesl` file beside it.
96+
fn package(code: &mut String, table_name: &str, name: &str, dir: &Path) {
97+
println!("cargo::rerun-if-changed={}", dir.display());
98+
let mut modules = Vec::new();
99+
let root = dir.with_extension("wesl");
100+
if root.is_file() {
101+
println!("cargo::rerun-if-changed={}", root.display());
102+
modules.push((name.to_string(), "package.wesl".to_string(), root));
103+
}
104+
walk(dir, name, "", &mut modules);
105+
modules.sort();
106+
table(code, table_name, modules);
107+
}
108+
109+
fn table(code: &mut String, table: &str, modules: Vec<(String, String, std::path::PathBuf)>) {
110+
writeln!(code, "pub static {table}: &[ShaderModule] = &[").unwrap();
111+
for (path, file, source) in modules {
112+
let source = std::fs::canonicalize(source).unwrap();
113+
writeln!(
114+
code,
115+
" ShaderModule {{ path: {path:?}, file: {file:?}, source: include_str!({source:?}) }},"
116+
)
117+
.unwrap();
118+
}
119+
writeln!(code, "];").unwrap();
120+
}
121+
122+
fn walk(
123+
dir: &Path,
124+
module: &str,
125+
file: &str,
126+
modules: &mut Vec<(String, String, std::path::PathBuf)>,
127+
) {
128+
for entry in std::fs::read_dir(dir).unwrap().flatten() {
129+
let path = entry.path();
130+
let Some(stem) = path.file_stem().and_then(|stem| stem.to_str()) else {
131+
continue;
132+
};
133+
// a module name has to be an identifier
134+
let ident = stem.chars().all(|c| c.is_ascii_alphanumeric() || c == '_')
135+
&& !stem.starts_with(|c: char| c.is_ascii_digit());
136+
if !ident {
137+
continue;
138+
}
139+
if path.is_dir() {
140+
// lygia's own tests are not part of the package
141+
if module == "lygia" && stem == "test" {
142+
continue;
143+
}
144+
walk(
145+
&path,
146+
&format!("{module}::{stem}"),
147+
&format!("{file}{stem}/"),
148+
modules,
149+
);
150+
} else if path.extension().is_some_and(|ext| ext == "wesl") {
151+
modules.push((
152+
format!("{module}::{stem}"),
153+
format!("{file}{stem}.wesl"),
154+
path,
155+
));
156+
}
31157
}
32-
module
33-
.submodules
34-
.retain(|sub| !sub.source.is_empty() || !sub.submodules.is_empty());
35158
}

‎crates/processing_render/shaders/processing.wesl‎

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,7 @@ struct Globals {
44
frame_count: u32,
55
}
66

7-
@group(0) @binding(11) var<uniform> globals: Globals;
7+
@group(0) @binding(8) var<uniform> globals: Globals;
88

9-
struct VertexOutput {
10-
@builtin(position) position: vec4<f32>,
11-
@location(0) world_position: vec4<f32>,
12-
@location(1) world_normal: vec3<f32>,
13-
@location(2) uv: vec2<f32>,
14-
@location(5) color: vec4<f32>,
15-
}
9+
// what a custom fragment stage receives: `world_position`, `world_normal`, `uv`, `color`
10+
alias VertexOutput = bevy_pbr::render::forward_io::VertexOutput;

0 commit comments

Comments
 (0)