Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions bevy_gpu_compute/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ exclude = [
[dependencies]
bevy_gpu_compute_macro = { path = "../bevy_gpu_compute_macro", version = "0.1"}
bevy_gpu_compute_core = { path = "../bevy_gpu_compute_core", version = "0.1"}
bevy = "0.15"
bevy = "0.18.1"
futures = "0.3.31"
pollster = "0.4.0"
wgpu = "23.0.1"
wgpu = "27"
sysinfo = "0.33.0"
bytemuck = {version = "1.21.0", features=["derive"]}

Expand Down
10 changes: 7 additions & 3 deletions bevy_gpu_compute/examples/collision_detection_barebones/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use bevy::{
DefaultPlugins,
app::{App, AppExit, Startup, Update},
log,
prelude::{EventWriter, IntoSystemConfigs, Local, Query, Res, ResMut, Resource},
prelude::{IntoScheduleConfigs, MessageWriter, Local, Query, Res, ResMut, Resource},
};
use bevy_gpu_compute::prelude::*;
mod visuals;
Expand Down Expand Up @@ -152,12 +152,16 @@ fn handle_task_results(mut gpu_task_reader: GpuTaskReader, mut state: ResMut<Sta
}

// when the local variable "count" goes above a certain number (representing frame count), exit the app
fn exit_and_show_results(mut count: Local<u32>, state: Res<State>, mut exit: EventWriter<AppExit>) {
fn exit_and_show_results(
mut count: Local<u32>,
state: Res<State>,
mut exit: MessageWriter<AppExit>,
) {
if *count > EXIT_AFTER_FRAMES {
let total_collisions = state.collisions_per_frame.iter().sum::<usize>();
log::trace!("total collisions count at exit: {}", total_collisions);
log::info!("Example completed successfully");
exit.send(AppExit::Success);
exit.write(AppExit::Success);
}
*count += 1;
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
use bevy::{
asset::Handle,
camera::Projection,
log,
prelude::{Color, Component, FromWorld, Resource, World},
sprite::ColorMaterial,
utils::hashbrown::HashMap,
platform::collections::HashMap,
prelude::{Color, ColorMaterial, Component, FromWorld, Resource, World},
};
use bevy::{
asset::{Assets, RenderAssetUsages},
math::{Vec2, Vec3, bounding::BoundingCircle},
prelude::{Camera2d, Commands, Mesh, Mesh2d, OrthographicProjection, Res, ResMut, Transform},
sprite::MeshMaterial2d,
prelude::{
Camera2d, Commands, Mesh, Mesh2d, MeshMaterial2d, OrthographicProjection, Res, ResMut,
Transform,
},
utils::default,
};

Expand Down Expand Up @@ -53,12 +55,12 @@ pub fn spawn_entities(
pub fn spawn_camera(mut commands: Commands) {
commands.spawn((
Camera2d,
OrthographicProjection {
Projection::Orthographic(OrthographicProjection {
near: -1000.0,
far: 1000.0,
scale: 0.1,
..OrthographicProjection::default_2d()
},
}),
Transform::from_xyz(
0., 0., 10.0, // 100.0,
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use bevy::{
DefaultPlugins,
app::{App, AppExit, PluginGroup, Startup, Update},
log::{self, LogPlugin},
prelude::{EventWriter, IntoSystemConfigs, Local, Query, Res, ResMut, Resource},
prelude::{IntoScheduleConfigs, MessageWriter, Local, Query, Res, ResMut, Resource},
};
use bevy_gpu_compute::prelude::*;
mod visuals;
Expand Down Expand Up @@ -230,7 +230,11 @@ fn handle_task_results(mut gpu_task_reader: GpuTaskReader, mut state: ResMut<Sta
}

// when the local variable "count" goes above a certain number (representing frame count), exit the app
fn exit_and_show_results(mut count: Local<u32>, state: Res<State>, mut exit: EventWriter<AppExit>) {
fn exit_and_show_results(
mut count: Local<u32>,
state: Res<State>,
mut exit: MessageWriter<AppExit>,
) {
if *count > EXIT_AFTER_FRAMES {
let total_collisions = state.collisions_per_frame.iter().sum::<usize>();
log::trace!("total collisions count at exit: {}", total_collisions);
Expand All @@ -251,7 +255,7 @@ fn exit_and_show_results(mut count: Local<u32>, state: Res<State>, mut exit: Eve
state.collisions_per_frame[2]
);
log::info!("Example completed successfully");
exit.send(AppExit::Success);
exit.write(AppExit::Success);
}
*count += 1;
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
use bevy::{
asset::Handle,
camera::Projection,
log,
prelude::{Color, Component, FromWorld, Resource, World},
sprite::ColorMaterial,
utils::hashbrown::HashMap,
platform::collections::HashMap,
prelude::{Color, ColorMaterial, Component, FromWorld, Resource, World},
};
use bevy::{
asset::{Assets, RenderAssetUsages},
math::{Vec2, Vec3, bounding::BoundingCircle},
prelude::{Camera2d, Commands, Mesh, Mesh2d, OrthographicProjection, Res, ResMut, Transform},
sprite::MeshMaterial2d,
prelude::{
Camera2d, Commands, Mesh, Mesh2d, MeshMaterial2d, OrthographicProjection, Res, ResMut,
Transform,
},
utils::default,
};

Expand Down Expand Up @@ -53,12 +55,12 @@ pub fn spawn_entities(
pub fn spawn_camera(mut commands: Commands) {
commands.spawn((
Camera2d,
OrthographicProjection {
Projection::Orthographic(OrthographicProjection {
near: -1000.0,
far: 1000.0,
scale: 0.1,
..OrthographicProjection::default_2d()
},
}),
Transform::from_xyz(
0., 0., 10.0, // 100.0,
),
Expand Down
2 changes: 1 addition & 1 deletion bevy_gpu_compute/src/plugin.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use bevy::{
app::{App, Plugin, Startup, Update},
prelude::{AppExtStates, IntoSystemConfigs, States, in_state},
prelude::{AppExtStates, IntoScheduleConfigs, States, in_state},
};

use crate::{
Expand Down
11 changes: 6 additions & 5 deletions bevy_gpu_compute/src/spawn_fallback_camera.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use bevy::{
camera::Projection,
log,
prelude::{
Camera, Camera2d, Commands, Component, DespawnRecursiveExt, Entity, OrthographicProjection,
Query, Res, Transform,
Camera, Camera2d, Commands, Component, Entity, OrthographicProjection, Query, Res,
Transform,
},
time::Time,
};
Expand All @@ -26,12 +27,12 @@ pub fn spawn_fallback_camera(
);
commands.spawn((
Camera2d,
OrthographicProjection {
Projection::Orthographic(OrthographicProjection {
near: -10.0,
far: 10.0,
scale: 1.,
..OrthographicProjection::default_2d()
},
}),
Transform::from_xyz(
0., 0., 10.0, // 100.0,
),
Expand All @@ -46,7 +47,7 @@ pub fn spawn_fallback_camera(
let fallback_cam_len = fallback_cameras.iter().len();
if fallback_cam_len > 0 {
fallback_cameras.iter().for_each(|(e, _)| {
commands.entity(e).despawn_recursive();
commands.entity(e).despawn();
});
}
}
Expand Down
4 changes: 2 additions & 2 deletions bevy_gpu_compute/src/system_params/task_deleter.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use bevy::{
ecs::system::SystemParam,
prelude::{Commands, DespawnRecursiveExt, Entity, Query},
prelude::{Commands, Entity, Query},
};

use crate::task::lib::BevyGpuComputeTask;
Expand All @@ -20,6 +20,6 @@ impl BevyGpuComputeTaskDeleter<'_, '_> {
.iter_mut()
.find(|(_, task)| task.name() == name)
.expect("Task not found");
self.commands.entity(entity).despawn_recursive();
self.commands.entity(entity).despawn();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,21 @@ pub fn update_compute_pipeline(task: &mut BevyGpuComputeTask, render_device: &Re
"pipeline layout {:?}",
task.runtime_state().pipeline_layout()
);

let pipeline_consts = task.get_pipeline_consts();
let constants_vec: Vec<(&str, f64)> = pipeline_consts
.iter()
.map(|(k, v)| (k.as_str(), *v))
.collect();

let compute_pipeline = render_device.create_compute_pipeline(&ComputePipelineDescriptor {
label: Some(task.name()),
layout: Some(task.runtime_state().pipeline_layout()),
module: task.configuration().shader().shader_module(),
entry_point: Some(task.configuration().shader().entry_point_function_name()),
// this is where we specify new values for pipeline constants...
compilation_options: PipelineCompilationOptions {
constants: &task.get_pipeline_consts(),
constants: &constants_vec,
zero_initialize_workgroup_memory: Default::default(),
},
cache: None,
Expand Down
15 changes: 9 additions & 6 deletions bevy_gpu_compute/src/task/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,15 @@ impl BevyGpuComputeTask {
render_device,
iteration_space,
max_output_vector_lengths,
WgslCode::from_string(
name,
render_device,
full_module.wgsl_code(iteration_space.num_dimmensions()),
"main".to_string(),
),
// SAFETY: wgsl_shader_module is compiled and validated
unsafe {
WgslCode::from_string(
name,
render_device,
full_module.wgsl_code(iteration_space.num_dimmensions()),
"main".to_string(),
)
},
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub fn get_gpu_output_as_bytes_vec(
slice.map_async(wgpu::MapMode::Read, move |result| {
sender.send(result).unwrap();
});
render_device.poll(wgpu::Maintain::Wait);
let _ = render_device.poll(wgpu::PollType::wait_indefinitely());

let result: Option<Vec<u8>> = if receiver.block_on().unwrap().is_ok() {
let data = slice.get_mapped_range();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub fn get_gpu_output_counter_value(
slice.map_async(wgpu::MapMode::Read, move |result| {
sender.send(result).unwrap();
});
render_device.poll(wgpu::Maintain::Wait);
let _ = render_device.poll(wgpu::PollType::wait_indefinitely());
let result = if receiver.block_on().unwrap().is_ok() {
let data = slice.get_mapped_range();
let transformed_data = &*data;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ impl Default for WgslCode {
}

impl WgslCode {
pub fn from_string(
pub unsafe fn from_string(
label: &str,
render_device: &RenderDevice,
wgsl_code: String,
Expand All @@ -27,20 +27,22 @@ impl WgslCode {
Self {
code: wgsl_code.clone(),
entry_point_function_name,
shader_module: Some(render_device.create_shader_module(ShaderModuleDescriptor {
label: Some(label),
source: ShaderSource::Wgsl(wgsl_code.into()),
})),
shader_module: Some(unsafe {
render_device.create_shader_module(ShaderModuleDescriptor {
label: Some(label),
source: ShaderSource::Wgsl(wgsl_code.into()),
})
}),
}
}
pub fn from_file(
pub unsafe fn from_file(
label: &str,
render_device: &RenderDevice,
file_path: &str,
entry_point_function_name: String,
) -> Self {
let code = std::fs::read_to_string(file_path).unwrap();
Self::from_string(label, render_device, code, entry_point_function_name)
unsafe { Self::from_string(label, render_device, code, entry_point_function_name) }
}
pub fn code(&self) -> &str {
&self.code
Expand Down
4 changes: 4 additions & 0 deletions rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[toolchain]
channel = "nightly"
components = ["rustfmt", "clippy"]
profile = "minimal"