From b091159c2fe681a35b38d5761d514764cf45eaca Mon Sep 17 00:00:00 2001 From: Luo Zhiaho Date: Sun, 14 Jun 2026 16:01:20 +0800 Subject: [PATCH 1/2] Use send wrapped BindGroupEntry vec in `prepare_mesh_view_bind_groups` --- .../bevy_pbr/src/render/mesh_view_bindings.rs | 40 +++++++++++-------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/crates/bevy_pbr/src/render/mesh_view_bindings.rs b/crates/bevy_pbr/src/render/mesh_view_bindings.rs index c3e60b6188ffb..bdafdbe0793e3 100644 --- a/crates/bevy_pbr/src/render/mesh_view_bindings.rs +++ b/crates/bevy_pbr/src/render/mesh_view_bindings.rs @@ -23,6 +23,7 @@ use bevy_ecs::{ use bevy_light::{EnvironmentMapLight, IrradianceVolume}; use bevy_math::Vec4; use bevy_platform::sync::Arc; +use bevy_render::renderer::WgpuWrapper; use bevy_render::{ camera::ExtractedCamera, globals::{GlobalsBuffer, GlobalsUniform}, @@ -623,6 +624,16 @@ pub struct MeshViewBindGroup { pub empty: BindGroup, } +// Wrapped Vec to be used in `Local` system param in `prepare_mesh_view_bind_groups`, +// because `BindGroupEntry` is non-send on wasm with atomics. +pub struct WrappedBindGroupEntryVec(WgpuWrapper>>); + +impl Default for WrappedBindGroupEntryVec { + fn default() -> Self { + Self(WgpuWrapper::new(Vec::default())) + } +} + pub fn prepare_mesh_view_bind_groups( mut commands: Commands, (render_device, pipeline_cache, render_adapter): ( @@ -687,12 +698,8 @@ pub fn prepare_mesh_view_bind_groups( Res, Res, ), - // TODO: Figure out how to reuse the memory. `BindGroupEntry` is non-send on wasm with atomics. - #[cfg(not(all(target_arch = "wasm32", target_feature = "atomics")))] mut entries_cache: Local< - Vec, - >, - #[cfg(not(all(target_arch = "wasm32", target_feature = "atomics")))] - mut entries_binding_array_cache: Local>, + mut entries_cache: Local, + mut entries_binding_array_cache: Local, ) { if let ( Some(view_binding), @@ -738,18 +745,18 @@ pub fn prepare_mesh_view_bind_groups( { let mut entries = DynamicBindGroupEntries::new(); let mut entries_binding_array = DynamicBindGroupEntries::new(); - #[cfg(not(all(target_arch = "wasm32", target_feature = "atomics")))] { // Take cache that has static lifetime for `DynamicBindGroupEntries`. // See . - entries.entries = core::mem::take(&mut *entries_cache) - .into_iter() - .map(|_| -> BindGroupEntry { unreachable!() }) - .collect(); - entries_binding_array.entries = core::mem::take(&mut *entries_binding_array_cache) + entries.entries = core::mem::take(&mut *entries_cache.0) .into_iter() .map(|_| -> BindGroupEntry { unreachable!() }) .collect(); + entries_binding_array.entries = + core::mem::take(&mut *entries_binding_array_cache.0) + .into_iter() + .map(|_| -> BindGroupEntry { unreachable!() }) + .collect(); } let tonemap_in_shader = camera.is_none_or(|camera| !camera.hdr); @@ -1027,20 +1034,19 @@ pub fn prepare_mesh_view_bind_groups( ), },)); - #[cfg(not(all(target_arch = "wasm32", target_feature = "atomics")))] { entries.entries.clear(); entries_binding_array.entries.clear(); - *entries_cache = entries + *(entries_cache.0) = entries .entries .into_iter() .map(|_| -> BindGroupEntry<'static> { unreachable!() }) - .collect(); - *entries_binding_array_cache = entries_binding_array + .collect::>(); + *(entries_binding_array_cache.0) = entries_binding_array .entries .into_iter() .map(|_| -> BindGroupEntry<'static> { unreachable!() }) - .collect(); + .collect::>(); } } } From 831016487da6e7dff283b69aac9a01cab57e3b91 Mon Sep 17 00:00:00 2001 From: Luo Zhiaho Date: Sun, 14 Jun 2026 16:07:05 +0800 Subject: [PATCH 2/2] rm parentheses --- crates/bevy_pbr/src/render/mesh_view_bindings.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/bevy_pbr/src/render/mesh_view_bindings.rs b/crates/bevy_pbr/src/render/mesh_view_bindings.rs index bdafdbe0793e3..8a4d6b50033a3 100644 --- a/crates/bevy_pbr/src/render/mesh_view_bindings.rs +++ b/crates/bevy_pbr/src/render/mesh_view_bindings.rs @@ -1037,12 +1037,12 @@ pub fn prepare_mesh_view_bind_groups( { entries.entries.clear(); entries_binding_array.entries.clear(); - *(entries_cache.0) = entries + *entries_cache.0 = entries .entries .into_iter() .map(|_| -> BindGroupEntry<'static> { unreachable!() }) .collect::>(); - *(entries_binding_array_cache.0) = entries_binding_array + *entries_binding_array_cache.0 = entries_binding_array .entries .into_iter() .map(|_| -> BindGroupEntry<'static> { unreachable!() })