Skip to content

Commit

Permalink
Partial update to bevy 0.15.rc.3 + add hot-reloading + fix macos nati…
Browse files Browse the repository at this point in the history
…ve (#2)

* feat: hot-reloading

* feat: start updating to bevy 0.15 + workaround for macos support

* feat: update to wgcore 0.2
  • Loading branch information
sebcrozet authored Nov 24, 2024
1 parent 0e2ddad commit 844605d
Show file tree
Hide file tree
Showing 19 changed files with 643 additions and 111 deletions.
39 changes: 3 additions & 36 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ resolver = "2"

[workspace.dependencies]
nalgebra = { version = "0.33", features = ["convert-bytemuck"] }
wgpu = { version = "22.1", features = ["naga-ir"] }
wgpu = { version = "23", features = ["naga-ir"] }
bytemuck = { version = "1", features = ["derive"] }
anyhow = "1"
async-channel = "2"
naga_oil = "0.15"
naga_oil = "0.16"
thiserror = "1"
encase = { version = "0.10.0", features = ["nalgebra"] }

Expand All @@ -19,40 +19,7 @@ rust.unexpected_cfgs = { level = "warn", check-cfg = [
] }

[patch.crates-io]
nalgebra = { git = "https://github.com/dimforge/nalgebra", branch = "more-bytemuck" }
bevy_wasm_window_resize = { git = "https://github.com/Vrixyz/bevy_wasm_window_resize", rev = "770a679316ae24772d278360635e086278c70fa2" }
bevy_editor_cam = { git = "https://github.com/Vrixyz/bevy_editor_cam", rev = "4dce484" }
bevy_egui = { git = "https://github.com/Vrixyz/bevy_egui", rev = "9edc10c" }
bevy_app = { git = "https://github.com/bevyengine/bevy.git", rev = "9386bd0114c44c9f00a2e9c41db1225aaa78d159" }
bevy_color = { git = "https://github.com/bevyengine/bevy.git", rev = "9386bd0114c44c9f00a2e9c41db1225aaa78d159" }
bevy_derive = { git = "https://github.com/bevyengine/bevy.git", rev = "9386bd0114c44c9f00a2e9c41db1225aaa78d159" }
bevy_ecs = { git = "https://github.com/bevyengine/bevy.git", rev = "9386bd0114c44c9f00a2e9c41db1225aaa78d159" }
bevy_input = { git = "https://github.com/bevyengine/bevy.git", rev = "9386bd0114c44c9f00a2e9c41db1225aaa78d159" }
bevy_log = { git = "https://github.com/bevyengine/bevy.git", rev = "9386bd0114c44c9f00a2e9c41db1225aaa78d159" }
bevy_math = { git = "https://github.com/bevyengine/bevy.git", rev = "9386bd0114c44c9f00a2e9c41db1225aaa78d159" }
bevy_reflect = { git = "https://github.com/bevyengine/bevy.git", rev = "9386bd0114c44c9f00a2e9c41db1225aaa78d159" }
bevy_render = { git = "https://github.com/bevyengine/bevy.git", rev = "9386bd0114c44c9f00a2e9c41db1225aaa78d159" }
bevy_time = { git = "https://github.com/bevyengine/bevy.git", rev = "9386bd0114c44c9f00a2e9c41db1225aaa78d159" }
bevy_text = { git = "https://github.com/bevyengine/bevy.git", rev = "9386bd0114c44c9f00a2e9c41db1225aaa78d159" }
bevy_pbr = { git = "https://github.com/bevyengine/bevy.git", rev = "9386bd0114c44c9f00a2e9c41db1225aaa78d159" }
bevy_sprite = { git = "https://github.com/bevyengine/bevy.git", rev = "9386bd0114c44c9f00a2e9c41db1225aaa78d159" }
bevy_ui = { git = "https://github.com/bevyengine/bevy.git", rev = "9386bd0114c44c9f00a2e9c41db1225aaa78d159" }
bevy_transform = { git = "https://github.com/bevyengine/bevy.git", rev = "9386bd0114c44c9f00a2e9c41db1225aaa78d159" }
bevy_utils = { git = "https://github.com/bevyengine/bevy.git", rev = "9386bd0114c44c9f00a2e9c41db1225aaa78d159" }
bevy_window = { git = "https://github.com/bevyengine/bevy.git", rev = "9386bd0114c44c9f00a2e9c41db1225aaa78d159" }
# Optional
bevy_asset = { git = "https://github.com/bevyengine/bevy.git", rev = "9386bd0114c44c9f00a2e9c41db1225aaa78d159" }
bevy_core_pipeline = { git = "https://github.com/bevyengine/bevy.git", rev = "9386bd0114c44c9f00a2e9c41db1225aaa78d159" }
bevy_gizmos = { git = "https://github.com/bevyengine/bevy.git", rev = "9386bd0114c44c9f00a2e9c41db1225aaa78d159" }
# Dev
bevy = { git = "https://github.com/bevyengine/bevy.git", rev = "9386bd0114c44c9f00a2e9c41db1225aaa78d159" }
# Upstream update needed
bevy_picking_core = { git = "https://github.com/vrixyz/bevy_mod_picking.git", branch = "bevy_main" }
bevy_mod_picking = { git = "https://github.com/vrixyz/bevy_mod_picking.git", branch = "bevy_main" }
# transitive dependencies
bevy_hierarchy = { git = "https://github.com/bevyengine/bevy.git", rev = "9386bd0114c44c9f00a2e9c41db1225aaa78d159" }
bevy_core = { git = "https://github.com/bevyengine/bevy.git", rev = "9386bd0114c44c9f00a2e9c41db1225aaa78d159" }
bevy_eventlistener = { git = "https://github.com/vrixyz/bevy_eventlistener.git", branch = "bevy_main" }
bevy_egui = { git = "https://github.com/Vrixyz/bevy_egui", branch = "bevy_main" }

[profile.release]
opt-level = 'z'
16 changes: 8 additions & 8 deletions crates/wgsparkl-testbed2d/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,17 @@ naga_oil = { workspace = true }
bytemuck = { workspace = true }
async-channel = { workspace = true }

wgcore = { path = "../../../wgmath/crates/wgcore" }
wgebra = { path = "../../../wgmath/crates/wgebra" }
wgparry2d = { path = "../../../wgmath/crates/wgparry/crates/wgparry2d" }
wgcore = { version = "0.2", path = "../../../wgmath/crates/wgcore" }
wgebra = { version = "0.2", path = "../../../wgmath/crates/wgebra" }
wgparry2d = { version = "0.2", path = "../../../wgmath/crates/wgparry/crates/wgparry2d" }

futures-test = "0.3"
serial_test = "3"
approx = "0.5"
async-std = { version = "1", features = ["attributes"] }
bevy = { version = "0.15.0-dev", features = ["shader_format_glsl", "shader_format_spirv", "webgpu"], git = "https://github.com/bevyengine/bevy", rev = "9386bd0114c44c9f00a2e9c41db1225aaa78d159" }
bevy_wasm_window_resize = "0.4"
bevy_editor_cam = "0.3"
bevy_mod_picking = { version = "0.20", default-features = false }
bevy_egui = { version = "0.29", default-features = false, features = ["default_fonts", "render"] }
bevy = { version = "0.15.0-rc.3", features = ["shader_format_glsl", "shader_format_spirv", "webgpu"] }
#bevy_wasm_window_resize = "0.4"
#bevy_editor_cam = "0.3"
#bevy_mod_picking = { version = "0.20", default-features = false }
bevy_egui = { version = "0.30", default-features = false, features = ["default_fonts", "render"] }
wgsparkl2d = { path = "../wgsparkl2d" }
16 changes: 8 additions & 8 deletions crates/wgsparkl-testbed3d/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,17 @@ naga_oil = { workspace = true }
bytemuck = { workspace = true }
async-channel = { workspace = true }

wgcore = { path = "../../../wgmath/crates/wgcore" }
wgebra = { path = "../../../wgmath/crates/wgebra" }
wgparry3d = { path = "../../../wgmath/crates/wgparry/crates/wgparry3d" }
wgcore = { version = "0.2", path = "../../../wgmath/crates/wgcore" }
wgebra = { version = "0.2", path = "../../../wgmath/crates/wgebra" }
wgparry3d = { version = "0.2", path = "../../../wgmath/crates/wgparry/crates/wgparry3d" }

futures-test = "0.3"
serial_test = "3"
approx = "0.5"
async-std = { version = "1", features = ["attributes"] }
bevy = { version = "0.15.0-dev", features = ["shader_format_glsl", "shader_format_spirv", "webgpu"], git = "https://github.com/bevyengine/bevy", rev = "9386bd0114c44c9f00a2e9c41db1225aaa78d159" }
bevy_editor_cam = "0.3"
bevy_mod_picking = { version = "0.20", default-features = false }
bevy_wasm_window_resize = "0.4"
bevy_egui = { version = "0.29", default-features = false, features = ["default_fonts", "render"] }
bevy = { version = "0.15.0-rc.3", features = ["shader_format_glsl", "shader_format_spirv", "webgpu"] }
#bevy_editor_cam = "0.3"
#bevy_mod_picking = { version = "0.20", default-features = false }
#bevy_wasm_window_resize = "0.4"
bevy_egui = { version = "0.30", default-features = false, features = ["default_fonts", "render"] }
wgsparkl3d = { path = "../wgsparkl3d" }
10 changes: 5 additions & 5 deletions crates/wgsparkl2d/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,16 @@ naga_oil = { workspace = true }
bytemuck = { workspace = true }
encase = { workspace = true }

wgcore = { version = "0.1", path = "../../../wgmath/crates/wgcore" }
wgebra = { version = "0.1", path = "../../../wgmath/crates/wgebra" }
wgparry2d = { version = "0.1", path = "../../../wgmath/crates/wgparry/crates/wgparry2d" }
wgrapier2d = { version = "0.1", path = "../../../wgmath/crates/wgrapier/crates/wgrapier2d" }
wgcore = { version = "0.2", path = "../../../wgmath/crates/wgcore", features = ["hot_reloading"] }
wgebra = { version = "0.2", path = "../../../wgmath/crates/wgebra" }
wgparry2d = { version = "0.2", path = "../../../wgmath/crates/wgparry/crates/wgparry2d" }
wgrapier2d = { version = "0.2", path = "../../../wgmath/crates/wgrapier/crates/wgrapier2d" }

[dev-dependencies]
nalgebra = { version = "0.33", features = ["rand"] }
futures-test = "0.3"
serial_test = "3"
approx = "0.5"
async-std = { version = "1", features = ["attributes"] }
bevy = { version = "0.15.0-dev", features = ["shader_format_glsl", "shader_format_spirv", "webgpu"], git = "https://github.com/bevyengine/bevy", rev = "9386bd0114c44c9f00a2e9c41db1225aaa78d159" }
bevy = { version = "0.15.0-dev", features = ["shader_format_glsl", "shader_format_spirv", "webgpu"] }
wgsparkl_testbed2d = { path = "../wgsparkl-testbed2d" }
10 changes: 5 additions & 5 deletions crates/wgsparkl3d/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,16 @@ naga_oil = { workspace = true }
bytemuck = { workspace = true }
encase = { workspace = true }

wgcore = { version = "0.1", path = "../../../wgmath/crates/wgcore" }
wgebra = { version = "0.1", path = "../../../wgmath/crates/wgebra" }
wgparry3d = { version = "0.1", path = "../../../wgmath/crates/wgparry/crates/wgparry3d" }
wgrapier3d = { version = "0.1", path = "../../../wgmath/crates/wgrapier/crates/wgrapier3d" }
wgcore = { version = "0.2", path = "../../../wgmath/crates/wgcore", features = ["hot_reloading"] }
wgebra = { version = "0.2", path = "../../../wgmath/crates/wgebra" }
wgparry3d = { version = "0.2", path = "../../../wgmath/crates/wgparry/crates/wgparry3d" }
wgrapier3d = { version = "0.2", path = "../../../wgmath/crates/wgrapier/crates/wgrapier3d" }

[dev-dependencies]
nalgebra = { version = "0.33", features = ["rand"] }
futures-test = "0.3"
serial_test = "3"
approx = "0.5"
async-std = { version = "1", features = ["attributes"] }
bevy = { version = "0.15.0-dev", features = ["shader_format_glsl", "shader_format_spirv", "webgpu"], git = "https://github.com/bevyengine/bevy", rev = "9386bd0114c44c9f00a2e9c41db1225aaa78d159" }
bevy = { version = "0.15.0-rc.3", features = ["shader_format_glsl", "shader_format_spirv", "webgpu"] }
wgsparkl_testbed3d = { path = "../wgsparkl-testbed3d" }
11 changes: 9 additions & 2 deletions src/grid/grid.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::dim_shader_defs;
use crate::grid::prefix_sum::{PrefixSumWorkspace, WgPrefixSum};
use crate::grid::sort::WgSort;
use crate::grid::sort::{TouchParticleBlocks, WgSort};
use crate::solver::{GpuParticles, WgParams};
use naga_oil::compose::NagaModuleDescriptor;
use std::sync::Arc;
Expand All @@ -26,6 +26,8 @@ impl WgGrid {
grid: &GpuGrid,
prefix_sum: &mut PrefixSumWorkspace,
sort_module: &'a WgSort,
#[cfg(target_os = "macos")]
touch_particle_blocks: &'a TouchParticleBlocks,
prefix_sum_module: &'a WgPrefixSum,
queue: &mut KernelInvocationQueue<'a>,
) {
Expand All @@ -45,7 +47,12 @@ impl WgGrid {
.bind0([grid.meta.buffer(), grid.hmap_entries.buffer()])
.queue(grid.cpu_meta.hmap_capacity.div_ceil(GRID_WORKGROUP_SIZE));

KernelInvocationBuilder::new(queue, &sort_module.touch_particle_blocks)
#[cfg(not(target_os = "macos"))]
let touch_particle_blocks = &sort_module.touch_particle_blocks;
#[cfg(target_os = "macos")]
let touch_particle_blocks = &touch_particle_blocks.touch_particle_blocks;

KernelInvocationBuilder::new(queue, touch_particle_blocks)
.bind_at(
0,
[
Expand Down
4 changes: 4 additions & 0 deletions src/grid/grid.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ struct GridHashMapEntry {
value: BlockHeaderId
}

#if MACOS == 0
// The hash map ipmelementation is inspired from https://nosferalatu.com/SimpleGPUHashTable.html
fn insertion_index(capacity: u32, key: BlockVirtualId) -> u32 {
let packed_key = pack_key(key);
Expand Down Expand Up @@ -157,6 +158,7 @@ fn insertion_index(capacity: u32, key: BlockVirtualId) -> u32 {

return NONE;
}
#endif

fn find_block_header_id(key: BlockVirtualId) -> BlockHeaderId {
let packed_key = pack_key(key);
Expand Down Expand Up @@ -284,6 +286,7 @@ fn blocks_associated_to_block(block: BlockVirtualId) -> array<BlockVirtualId, NU
#endif
}

#if MACOS == 0
fn mark_block_as_active(block: BlockVirtualId) {
let slot = insertion_index(grid.hmap_capacity, block);

Expand All @@ -296,6 +299,7 @@ fn mark_block_as_active(block: BlockVirtualId) {
hmap_entries[slot].value = BlockHeaderId(block_header_id);
}
}
#endif

fn block_header_id_to_physical_id(hid: BlockHeaderId) -> BlockPhysicalId {
return BlockPhysicalId(hid.id * NUM_CELL_PER_BLOCK);
Expand Down
25 changes: 25 additions & 0 deletions src/grid/sort.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,36 @@ use wgpu::ComputePipeline;
shader_defs = "dim_shader_defs"
)]
pub struct WgSort {
#[cfg(not(target_os = "macos"))]
pub(crate) touch_particle_blocks: ComputePipeline,
pub(crate) update_block_particle_count: ComputePipeline,
pub(crate) copy_particles_len_to_scan_value: ComputePipeline,
pub(crate) copy_scan_values_to_first_particles: ComputePipeline,
pub(crate) finalize_particles_sort: ComputePipeline,
}

#[cfg(target_os = "macos")]
pub struct TouchParticleBlocks {
pub(crate) touch_particle_blocks: ComputePipeline,
}

impl TouchParticleBlocks {
pub fn from_device(device: &wgpu::Device) -> Self {
#[cfg(feature = "dim2")]
let src = wgpu::include_wgsl!("touch_particle_blocks2d.wgsl");
#[cfg(feature = "dim3")]
let src = wgpu::include_wgsl!("touch_particle_blocks3d.wgsl");
let cs_module = device.create_shader_module(src);
let compute_pipeline = device.create_compute_pipeline(&wgpu::ComputePipelineDescriptor {
label: None,
layout: None,
module: &cs_module,
entry_point: Some("touch_particle_blocks"),
compilation_options: Default::default(),
cache: None,
});
Self { touch_particle_blocks: compute_pipeline }
}
}

wgcore::test_shader_compilation!(WgSort);
6 changes: 5 additions & 1 deletion src/grid/sort.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ var<storage, read_write> sorted_particle_ids: array<u32>;
@group(1) @binding(3)
var<storage, read_write> particle_node_linked_lists: array<u32>;


// Disable this kernel on macos because of the underlying compareExchangeMap which is
// not working well with naga-oil. This is why we currently have the flattened
// toouch_particle_block2/3d.wgsl shaders as a workaround currently.
#if MACOS == 0
@compute @workgroup_size(Grid::GRID_WORKGROUP_SIZE, 1, 1)
fn touch_particle_blocks(@builtin(global_invocation_id) invocation_id: vec3<u32>) {
let id = invocation_id.x;
Expand All @@ -25,6 +28,7 @@ fn touch_particle_blocks(@builtin(global_invocation_id) invocation_id: vec3<u32>
}
}
}
#endif

// TODO: can this kernel be combined with touch_particle_blocks?
@compute @workgroup_size(Grid::GRID_WORKGROUP_SIZE, 1, 1)
Expand Down
Loading

0 comments on commit 844605d

Please sign in to comment.