Skip to content

Commit d1e4a48

Browse files
committed
Ci.
1 parent f2b5a21 commit d1e4a48

File tree

11 files changed

+323
-284
lines changed

11 files changed

+323
-284
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ too_many_arguments = "allow"
2222

2323
[workspace.dependencies]
2424
bevy = { git = "https://github.com/bevyengine/bevy", branch = "main", features = ["file_watcher", "shader_format_wesl"] }
25-
bevy_naga_reflect = { path = "../../tychedelia/bevy_naga_reflect" }
25+
bevy_naga_reflect = { git = "https://github.com/tychedelia/bevy_naga_reflect" }
2626
naga = { version = "28", features = ["wgsl-in"] }
2727
wesl = { version = "0.3", default-features = false }
2828
processing = { path = "." }

crates/processing_pyo3/src/gltf.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ impl Gltf {
4646
#[pyfunction]
4747
#[pyo3(pass_module)]
4848
pub fn load_gltf(module: &Bound<'_, PyModule>, path: &str) -> PyResult<Gltf> {
49-
let graphics = get_graphics(module)?
50-
.ok_or_else(|| PyRuntimeError::new_err("call size() first"))?;
49+
let graphics =
50+
get_graphics(module)?.ok_or_else(|| PyRuntimeError::new_err("call size() first"))?;
5151
let entity =
5252
gltf_load(graphics.entity, path).map_err(|e| PyRuntimeError::new_err(format!("{e}")))?;
5353
Ok(Gltf { entity })

crates/processing_pyo3/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,16 @@ pub(crate) mod shader;
1616

1717
use graphics::{Geometry, Graphics, Image, Light, Topology, get_graphics, get_graphics_mut};
1818
use material::Material;
19-
use shader::Shader;
2019
use pyo3::{
2120
exceptions::PyRuntimeError,
2221
prelude::*,
2322
types::{PyDict, PyTuple},
2423
};
24+
use shader::Shader;
2525
use std::ffi::{CStr, CString};
2626

27-
use gltf::Gltf;
2827
use bevy::log::warn;
28+
use gltf::Gltf;
2929
use std::env;
3030

3131
/// Get a shared ref to the Graphics context, or return Ok(()) if not yet initialized.

crates/processing_pyo3/src/material.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use bevy::prelude::Entity;
22
use processing::prelude::*;
3-
use pyo3::{exceptions::PyRuntimeError, prelude::*};
43
use pyo3::types::PyDict;
4+
use pyo3::{exceptions::PyRuntimeError, prelude::*};
55

66
use crate::shader::Shader;
77

@@ -44,11 +44,8 @@ impl Material {
4444
kwargs: Option<&Bound<'_, PyDict>>,
4545
) -> PyResult<Self> {
4646
let entity = if vertex.is_some() || fragment.is_some() {
47-
material_create_custom(
48-
vertex.map(|s| s.entity),
49-
fragment.map(|s| s.entity),
50-
)
51-
.map_err(|e| PyRuntimeError::new_err(format!("{e}")))?
47+
material_create_custom(vertex.map(|s| s.entity), fragment.map(|s| s.entity))
48+
.map_err(|e| PyRuntimeError::new_err(format!("{e}")))?
5249
} else {
5350
material_create_pbr().map_err(|e| PyRuntimeError::new_err(format!("{e}")))?
5451
};

crates/processing_pyo3/src/shader.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,13 @@ pub struct Shader {
1111
impl Shader {
1212
#[new]
1313
pub fn new(source: &str) -> PyResult<Self> {
14-
let entity =
15-
shader_create(source).map_err(|e| PyRuntimeError::new_err(format!("{e}")))?;
14+
let entity = shader_create(source).map_err(|e| PyRuntimeError::new_err(format!("{e}")))?;
1615
Ok(Self { entity })
1716
}
1817

1918
#[staticmethod]
2019
pub fn load(path: &str) -> PyResult<Self> {
21-
let entity =
22-
shader_load(path).map_err(|e| PyRuntimeError::new_err(format!("{e}")))?;
20+
let entity = shader_load(path).map_err(|e| PyRuntimeError::new_err(format!("{e}")))?;
2321
Ok(Self { entity })
2422
}
2523
}

crates/processing_render/build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// packages wesl libraries for processing and lygia
22
// note that bevy does not (as of yet) understand how to use these packages
3-
// they are, instead, used by us as part of shader pre-processing in the
3+
// they are, instead, used by us as part of shader pre-processing in the
44
// processing_render crate
55
fn main() {
66
wesl::PkgBuilder::new("processing")

crates/processing_render/src/lib.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,11 @@ fn create_app(config: Config) -> App {
287287
app.add_systems(First, (clear_transient_meshes, activate_cameras))
288288
.add_systems(
289289
Update,
290-
(flush_draw_commands, add_standard_materials, add_custom_materials)
290+
(
291+
flush_draw_commands,
292+
add_standard_materials,
293+
add_custom_materials,
294+
)
291295
.chain()
292296
.before(AssetEventSystems),
293297
);
@@ -1314,8 +1318,9 @@ pub fn shader_create(source: &str) -> error::Result<Entity> {
13141318

13151319
/// Load a shader from a file path.
13161320
pub fn shader_load(path: &str) -> error::Result<Entity> {
1317-
let source = std::fs::read_to_string(path)
1318-
.map_err(|e| error::ProcessingError::ShaderCompilationError(format!("Failed to read {path}: {e}")))?;
1321+
let source = std::fs::read_to_string(path).map_err(|e| {
1322+
error::ProcessingError::ShaderCompilationError(format!("Failed to read {path}: {e}"))
1323+
})?;
13191324
shader_create(&source)
13201325
}
13211326

crates/processing_render/src/material/custom.rs

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ use std::borrow::Cow;
33
use std::sync::Arc;
44

55
use bevy::platform::collections::hash_map::Entry;
6-
use wesl::syntax::{ModulePath, PathOrigin};
76
use wesl::PkgResolver;
7+
use wesl::syntax::{ModulePath, PathOrigin};
88

99
wesl::wesl_pkg!(processing);
1010
wesl::wesl_pkg!(lygia);
@@ -13,19 +13,20 @@ use bevy::{
1313
asset::{AsAssetId, AssetEventSystems},
1414
core_pipeline::core_3d::Opaque3d,
1515
ecs::system::{
16-
lifetimeless::{SRes, SResMut},
1716
SystemParamItem,
17+
lifetimeless::{SRes, SResMut},
1818
},
19-
material::{key::ErasedMeshPipelineKey, MaterialProperties},
19+
material::{MaterialProperties, key::ErasedMeshPipelineKey},
2020
pbr::{
21-
base_specialize, DrawMaterial, EntitiesNeedingSpecialization, MainPassOpaqueDrawFunction,
21+
DrawMaterial, EntitiesNeedingSpecialization, MainPassOpaqueDrawFunction,
2222
MaterialBindGroupAllocator, MaterialBindGroupAllocators, MaterialFragmentShader,
23-
MaterialVertexShader, MeshPipelineKey, PreparedMaterial, RenderMaterialBindings, RenderMaterialInstance,
24-
RenderMaterialInstances,
23+
MaterialVertexShader, MeshPipelineKey, PreparedMaterial, RenderMaterialBindings,
24+
RenderMaterialInstance, RenderMaterialInstances, base_specialize,
2525
},
2626
prelude::*,
27-
reflect::{structs::Struct, PartialReflect, ReflectMut, ReflectRef},
27+
reflect::{PartialReflect, ReflectMut, ReflectRef, structs::Struct},
2828
render::{
29+
Extract, RenderApp, RenderStartup,
2930
camera::{DirtySpecializationSystems, DirtySpecializations},
3031
erased_render_asset::{ErasedRenderAsset, ErasedRenderAssetPlugin, PrepareAssetError},
3132
render_asset::RenderAssets,
@@ -34,7 +35,6 @@ use bevy::{
3435
renderer::RenderDevice,
3536
sync_world::MainEntity,
3637
texture::GpuImage,
37-
Extract, RenderApp, RenderStartup,
3838
},
3939
};
4040

@@ -191,7 +191,11 @@ pub fn create_custom(
191191
Ok(commands.spawn(UntypedMaterial(handle.untyped())).id())
192192
}
193193

194-
pub fn set_property(material: &mut CustomMaterial, name: &str, value: &MaterialValue) -> Result<()> {
194+
pub fn set_property(
195+
material: &mut CustomMaterial,
196+
name: &str,
197+
value: &MaterialValue,
198+
) -> Result<()> {
195199
let reflect_value: Box<dyn PartialReflect> = material_value_to_reflect(value)?;
196200

197201
if let Some(field) = material.shader.field_mut(name) {
@@ -229,7 +233,7 @@ fn material_value_to_reflect(value: &MaterialValue) -> Result<Box<dyn PartialRef
229233
MaterialValue::Texture(_) => {
230234
return Err(ProcessingError::UnknownMaterialProperty(
231235
"Texture properties not yet supported for custom materials".to_string(),
232-
))
236+
));
233237
}
234238
})
235239
}
@@ -326,7 +330,8 @@ impl ErasedRenderAsset for CustomMaterial {
326330
let bind_group_layout =
327331
BindGroupLayoutDescriptor::new("custom_material_bind_group", &layout_entries);
328332

329-
let bindings = reflection.create_bindings(3, &source_asset.shader, render_device, gpu_images);
333+
let bindings =
334+
reflection.create_bindings(3, &source_asset.shader, render_device, gpu_images);
330335

331336
let unprepared = UnpreparedBindGroup {
332337
bindings: BindingResources(bindings),
@@ -348,9 +353,7 @@ impl ErasedRenderAsset for CustomMaterial {
348353
.insert(bind_group_allocator.allocate_unprepared(unprepared, &bind_group_layout)),
349354
};
350355

351-
let draw_function = opaque_draw_functions
352-
.read()
353-
.id::<DrawMaterial>();
356+
let draw_function = opaque_draw_functions.read().id::<DrawMaterial>();
354357

355358
let mut properties = MaterialProperties {
356359
mesh_pipeline_key_bits: ErasedMeshPipelineKey::new(MeshPipelineKey::empty()),
@@ -406,9 +409,7 @@ fn extract_custom_materials_needing_specialization(
406409
mut dirty: ResMut<DirtySpecializations>,
407410
) {
408411
for entity in entities.changed.iter() {
409-
dirty
410-
.changed_renderables
411-
.insert(MainEntity::from(*entity));
412+
dirty.changed_renderables.insert(MainEntity::from(*entity));
412413
}
413414
}
414415

@@ -417,9 +418,7 @@ fn extract_custom_materials_that_need_specializations_removed(
417418
mut dirty: ResMut<DirtySpecializations>,
418419
) {
419420
for entity in entities.removed.iter() {
420-
dirty
421-
.removed_renderables
422-
.insert(MainEntity::from(*entity));
421+
dirty.removed_renderables.insert(MainEntity::from(*entity));
423422
}
424423
}
425424

crates/processing_render/src/render/mod.rs

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -223,22 +223,32 @@ pub fn flush_draw_commands(
223223
};
224224
}
225225
DrawCommand::Rect { x, y, w, h, radii } => {
226-
add_fill(&mut res, &mut batch, &state, |mesh, color| {
227-
rect(mesh, x, y, w, h, radii, color, TessellationMode::Fill)
228-
}, &p_material_handles);
229-
230-
add_stroke(&mut res, &mut batch, &state, |mesh, color, weight| {
231-
rect(
232-
mesh,
233-
x,
234-
y,
235-
w,
236-
h,
237-
radii,
238-
color,
239-
TessellationMode::Stroke(weight),
240-
)
241-
}, &p_material_handles);
226+
add_fill(
227+
&mut res,
228+
&mut batch,
229+
&state,
230+
|mesh, color| rect(mesh, x, y, w, h, radii, color, TessellationMode::Fill),
231+
&p_material_handles,
232+
);
233+
234+
add_stroke(
235+
&mut res,
236+
&mut batch,
237+
&state,
238+
|mesh, color, weight| {
239+
rect(
240+
mesh,
241+
x,
242+
y,
243+
w,
244+
h,
245+
radii,
246+
color,
247+
TessellationMode::Stroke(weight),
248+
)
249+
},
250+
&p_material_handles,
251+
);
242252
}
243253
DrawCommand::BackgroundColor(color) => {
244254
flush_batch(&mut res, &mut batch, &p_material_handles);
@@ -347,7 +357,13 @@ pub fn flush_draw_commands(
347357
height,
348358
depth,
349359
} => {
350-
add_shape3d(&mut res, &mut batch, &state, box_mesh(width, height, depth), &p_material_handles);
360+
add_shape3d(
361+
&mut res,
362+
&mut batch,
363+
&state,
364+
box_mesh(width, height, depth),
365+
&p_material_handles,
366+
);
351367
}
352368
DrawCommand::Sphere {
353369
radius,

0 commit comments

Comments
 (0)