From 9bfeb2ed1d9b22dd590a9e296f623ff2fcac8bdc Mon Sep 17 00:00:00 2001 From: Ian Kettlewell Date: Thu, 29 Feb 2024 00:08:44 -0500 Subject: [PATCH 01/14] Get Bevy building when on Wasm when 'atomics' flag is enabled --- crates/bevy_render/Cargo.toml | 3 + crates/bevy_render/src/lib.rs | 3 +- .../src/render_resource/resource_macros.rs | 40 +++++- crates/bevy_render/src/renderer/mod.rs | 120 ++++++++++++++---- .../bevy_render/src/renderer/render_device.rs | 5 +- crates/bevy_render/src/view/window/mod.rs | 9 +- 6 files changed, 146 insertions(+), 34 deletions(-) diff --git a/crates/bevy_render/Cargo.toml b/crates/bevy_render/Cargo.toml index 7903dd8d08bea..e6b97534f2a60 100644 --- a/crates/bevy_render/Cargo.toml +++ b/crates/bevy_render/Cargo.toml @@ -120,5 +120,8 @@ web-sys = { version = "=0.3.67", features = [ ] } wasm-bindgen = "0.2" +[target.'cfg(all(target_arch = "wasm32", target_feature = "atomics"))'.dependencies] +send_wrapper = "0.6.0" + [lints] workspace = true diff --git a/crates/bevy_render/src/lib.rs b/crates/bevy_render/src/lib.rs index c9d99f661ce02..e9217625472e8 100644 --- a/crates/bevy_render/src/lib.rs +++ b/crates/bevy_render/src/lib.rs @@ -58,6 +58,7 @@ use globals::GlobalsPlugin; use renderer::{RenderAdapter, RenderAdapterInfo, RenderDevice, RenderQueue}; use crate::deterministic::DeterministicRenderingConfig; +use crate::renderer::WgpuWrapper; use crate::{ camera::CameraPlugin, mesh::{morph::MorphPlugin, Mesh, MeshPlugin}, @@ -301,7 +302,7 @@ impl Plugin for RenderPlugin { queue, adapter_info, render_adapter, - RenderInstance(Arc::new(instance)), + RenderInstance(Arc::new(WgpuWrapper::new(instance))), )); }; // In wasm, spawn a task and detach it for execution diff --git a/crates/bevy_render/src/render_resource/resource_macros.rs b/crates/bevy_render/src/render_resource/resource_macros.rs index de2ea0ec00e58..ea8d907a038c1 100644 --- a/crates/bevy_render/src/render_resource/resource_macros.rs +++ b/crates/bevy_render/src/render_resource/resource_macros.rs @@ -9,16 +9,25 @@ #[macro_export] macro_rules! render_resource_wrapper { ($wrapper_type:ident, $wgpu_type:ty) => { + #[cfg(not(all(target_arch = "wasm32", target_feature = "atomics")))] #[derive(Debug)] // SAFETY: while self is live, self.0 comes from `into_raw` of an Arc<$wgpu_type> with a strong ref. pub struct $wrapper_type(*const ()); + #[cfg(all(target_arch = "wasm32", target_feature = "atomics"))] + #[derive(Debug)] + pub struct $wrapper_type(send_wrapper::SendWrapper<*const ()>); + impl $wrapper_type { pub fn new(value: $wgpu_type) -> Self { let arc = std::sync::Arc::new(value); let value_ptr = std::sync::Arc::into_raw(arc); let unit_ptr = value_ptr.cast::<()>(); - Self(unit_ptr) + + #[cfg(not(all(target_arch = "wasm32", target_feature = "atomics")))] + return Self(unit_ptr); + #[cfg(all(target_arch = "wasm32", target_feature = "atomics"))] + return Self(send_wrapper::SendWrapper::new(unit_ptr)); } pub fn try_unwrap(self) -> Option<$wgpu_type> { @@ -57,9 +66,12 @@ macro_rules! render_resource_wrapper { // We ensure correctness by checking that $wgpu_type does implement Send and Sync. // If in future there is a case where a wrapper is required for a non-send/sync type // we can implement a macro variant that omits these manual Send + Sync impls + #[cfg(not(all(target_arch = "wasm32", target_feature = "atomics")))] unsafe impl Send for $wrapper_type {} // SAFETY: As explained above, we ensure correctness by checking that $wgpu_type implements Send and Sync. + #[cfg(not(all(target_arch = "wasm32", target_feature = "atomics")))] unsafe impl Sync for $wrapper_type {} + #[cfg(not(all(target_arch = "wasm32", target_feature = "atomics")))] const _: () = { trait AssertSendSyncBound: Send + Sync {} impl AssertSendSyncBound for $wgpu_type {} @@ -75,7 +87,14 @@ macro_rules! render_resource_wrapper { std::mem::forget(arc); let cloned_value_ptr = std::sync::Arc::into_raw(cloned); let cloned_unit_ptr = cloned_value_ptr.cast::<()>(); - Self(cloned_unit_ptr) + + #[cfg(not(all(target_arch = "wasm32", target_feature = "atomics")))] + return Self(cloned_unit_ptr); + + // Note: this implementation means that this Clone will panic + // when called off the wgpu thread. + #[cfg(all(target_arch = "wasm32", target_feature = "atomics"))] + return Self(send_wrapper::SendWrapper::new(cloned_unit_ptr)); } } }; @@ -85,16 +104,28 @@ macro_rules! render_resource_wrapper { #[macro_export] macro_rules! render_resource_wrapper { ($wrapper_type:ident, $wgpu_type:ty) => { + #[cfg(not(all(target_arch = "wasm32", target_feature = "atomics")))] #[derive(Clone, Debug)] pub struct $wrapper_type(std::sync::Arc<$wgpu_type>); + #[cfg(all(target_arch = "wasm32", target_feature = "atomics"))] + #[derive(Clone, Debug)] + pub struct $wrapper_type(std::sync::Arc>); impl $wrapper_type { pub fn new(value: $wgpu_type) -> Self { - Self(std::sync::Arc::new(value)) + #[cfg(not(all(target_arch = "wasm32", target_feature = "atomics")))] + return Self(std::sync::Arc::new(value)); + + #[cfg(all(target_arch = "wasm32", target_feature = "atomics"))] + return Self(std::sync::Arc::new(send_wrapper::SendWrapper::new(value))); } pub fn try_unwrap(self) -> Option<$wgpu_type> { - std::sync::Arc::try_unwrap(self.0).ok() + #[cfg(not(all(target_arch = "wasm32", target_feature = "atomics")))] + return std::sync::Arc::try_unwrap(self.0).ok(); + + #[cfg(all(target_arch = "wasm32", target_feature = "atomics"))] + return std::sync::Arc::try_unwrap(self.0).ok().map(|p| p.take()); } } @@ -106,6 +137,7 @@ macro_rules! render_resource_wrapper { } } + #[cfg(not(all(target_arch = "wasm32", target_feature = "atomics")))] const _: () = { trait AssertSendSyncBound: Send + Sync {} impl AssertSendSyncBound for $wgpu_type {} diff --git a/crates/bevy_render/src/renderer/mod.rs b/crates/bevy_render/src/renderer/mod.rs index fa4377a405c47..25f0b24bffcf8 100644 --- a/crates/bevy_render/src/renderer/mod.rs +++ b/crates/bevy_render/src/renderer/mod.rs @@ -104,23 +104,70 @@ pub fn render_system(world: &mut World, state: &mut SystemState(T); +#[cfg(all(target_arch = "wasm32", target_feature = "atomics"))] +#[derive(Debug, Clone)] +pub struct WgpuWrapper(send_wrapper::SendWrapper); + +// Safety: SendWrapper is always Send + Sync. +#[cfg(all(target_arch = "wasm32", target_feature = "atomics"))] +unsafe impl Send for WgpuWrapper {} +#[cfg(all(target_arch = "wasm32", target_feature = "atomics"))] +unsafe impl Sync for WgpuWrapper {} + +#[cfg(not(all(target_arch = "wasm32", target_feature = "atomics")))] +impl WgpuWrapper { + pub fn new(t: T) -> Self { + Self(t) + } +} + +#[cfg(all(target_arch = "wasm32", target_feature = "atomics"))] +impl WgpuWrapper { + pub fn new(t: T) -> Self { + Self(send_wrapper::SendWrapper::new(t)) + } +} + +impl std::ops::Deref for WgpuWrapper { + type Target = T; + + #[track_caller] + fn deref(&self) -> &T { + &self.0 + } +} + +impl std::ops::DerefMut for WgpuWrapper { + #[track_caller] + fn deref_mut(&mut self) -> &mut T { + &mut self.0 + } +} + /// This queue is used to enqueue tasks for the GPU to execute asynchronously. #[derive(Resource, Clone, Deref, DerefMut)] -pub struct RenderQueue(pub Arc); +pub struct RenderQueue(pub Arc>); /// The handle to the physical device being used for rendering. /// See [`Adapter`] for more info. #[derive(Resource, Clone, Debug, Deref, DerefMut)] -pub struct RenderAdapter(pub Arc); +pub struct RenderAdapter(pub Arc>); /// The GPU instance is used to initialize the [`RenderQueue`] and [`RenderDevice`], /// as well as to create [`WindowSurfaces`](crate::view::window::WindowSurfaces). #[derive(Resource, Clone, Deref, DerefMut)] -pub struct RenderInstance(pub Arc); +pub struct RenderInstance(pub Arc>); /// The [`AdapterInfo`] of the adapter in use by the renderer. #[derive(Resource, Clone, Deref, DerefMut)] -pub struct RenderAdapterInfo(pub AdapterInfo); +pub struct RenderAdapterInfo(pub WgpuWrapper); const GPU_NOT_FOUND_ERROR_MESSAGE: &str = if cfg!(target_os = "linux") { "Unable to find a GPU! Make sure you have installed required drivers! For extra information, see: https://github.com/bevyengine/bevy/blob/latest/docs/linux_dependencies.md" @@ -287,12 +334,12 @@ pub async fn initialize_renderer( ) .await .unwrap(); - let queue = Arc::new(queue); - let adapter = Arc::new(adapter); + let queue = Arc::new(WgpuWrapper::new(queue)); + let adapter = Arc::new(WgpuWrapper::new(adapter)); ( RenderDevice::from(device), RenderQueue(queue), - RenderAdapterInfo(adapter_info), + RenderAdapterInfo(WgpuWrapper::new(adapter_info)), RenderAdapter(adapter), ) } @@ -377,7 +424,10 @@ impl<'w> RenderContext<'w> { /// buffer. pub fn add_command_buffer_generation_task( &mut self, + #[cfg(not(all(target_arch = "wasm32", target_feature = "atomics")))] task: impl FnOnce(RenderDevice) -> CommandBuffer + 'w + Send, + #[cfg(all(target_arch = "wasm32", target_feature = "atomics"))] + task: impl FnOnce(RenderDevice) -> CommandBuffer + 'w, ) { self.flush_encoder(); @@ -393,27 +443,46 @@ impl<'w> RenderContext<'w> { self.flush_encoder(); let mut command_buffers = Vec::with_capacity(self.command_buffer_queue.len()); - let mut task_based_command_buffers = ComputeTaskPool::get().scope(|task_pool| { - for (i, queued_command_buffer) in self.command_buffer_queue.into_iter().enumerate() { - match queued_command_buffer { - QueuedCommandBuffer::Ready(command_buffer) => { - command_buffers.push((i, command_buffer)); - } - QueuedCommandBuffer::Task(command_buffer_generation_task) => { - let render_device = self.render_device.clone(); - if self.force_serial { - command_buffers - .push((i, command_buffer_generation_task(render_device))); - } else { - task_pool.spawn(async move { - (i, command_buffer_generation_task(render_device)) - }); + + #[cfg(not(all(target_arch = "wasm32", target_feature = "atomics")))] + { + let mut task_based_command_buffers = ComputeTaskPool::get().scope(|task_pool| { + for (i, queued_command_buffer) in self.command_buffer_queue.into_iter().enumerate() + { + match queued_command_buffer { + QueuedCommandBuffer::Ready(command_buffer) => { + command_buffers.push((i, command_buffer)); + } + QueuedCommandBuffer::Task(command_buffer_generation_task) => { + let render_device = self.render_device.clone(); + if self.force_serial { + command_buffers + .push((i, command_buffer_generation_task(render_device))); + } else { + task_pool.spawn(async move { + (i, command_buffer_generation_task(render_device)) + }); + } } } } + }); + command_buffers.append(&mut task_based_command_buffers); + } + + #[cfg(all(target_arch = "wasm32", target_feature = "atomics"))] + for (i, queued_command_buffer) in self.command_buffer_queue.into_iter().enumerate() { + match queued_command_buffer { + QueuedCommandBuffer::Ready(command_buffer) => { + command_buffers.push((i, command_buffer)); + } + QueuedCommandBuffer::Task(command_buffer_generation_task) => { + let render_device = self.render_device.clone(); + command_buffers.push((i, command_buffer_generation_task(render_device))); + } } - }); - command_buffers.append(&mut task_based_command_buffers); + } + command_buffers.sort_unstable_by_key(|(i, _)| *i); command_buffers.into_iter().map(|(_, cb)| cb).collect() } @@ -428,5 +497,8 @@ impl<'w> RenderContext<'w> { enum QueuedCommandBuffer<'w> { Ready(CommandBuffer), + #[cfg(not(all(target_arch = "wasm32", target_feature = "atomics")))] Task(Box CommandBuffer + 'w + Send>), + #[cfg(all(target_arch = "wasm32", target_feature = "atomics"))] + Task(Box CommandBuffer + 'w>), } diff --git a/crates/bevy_render/src/renderer/render_device.rs b/crates/bevy_render/src/renderer/render_device.rs index 45bccf0bbe667..1c0b26b912a42 100644 --- a/crates/bevy_render/src/renderer/render_device.rs +++ b/crates/bevy_render/src/renderer/render_device.rs @@ -11,19 +11,20 @@ use wgpu::{ use super::RenderQueue; use crate::render_resource::resource_macros::*; +use crate::WgpuWrapper; render_resource_wrapper!(ErasedRenderDevice, wgpu::Device); /// This GPU device is responsible for the creation of most rendering and compute resources. #[derive(Resource, Clone)] pub struct RenderDevice { - device: ErasedRenderDevice, + device: WgpuWrapper, } impl From for RenderDevice { fn from(device: wgpu::Device) -> Self { Self { - device: ErasedRenderDevice::new(device), + device: WgpuWrapper::new(ErasedRenderDevice::new(device)), } } } diff --git a/crates/bevy_render/src/view/window/mod.rs b/crates/bevy_render/src/view/window/mod.rs index 656d4ceaa881a..802c1a5a1f245 100644 --- a/crates/bevy_render/src/view/window/mod.rs +++ b/crates/bevy_render/src/view/window/mod.rs @@ -4,7 +4,7 @@ use crate::{ }, renderer::{RenderAdapter, RenderDevice, RenderInstance}, texture::TextureFormatPixelInfo, - Extract, ExtractSchedule, Render, RenderApp, RenderSet, + Extract, ExtractSchedule, Render, RenderApp, RenderSet, WgpuWrapper, }; use bevy_app::{App, Plugin}; use bevy_ecs::{entity::EntityHashMap, prelude::*}; @@ -197,7 +197,7 @@ fn extract_windows( struct SurfaceData { // TODO: what lifetime should this be? - surface: wgpu::Surface<'static>, + surface: WgpuWrapper>, format: TextureFormat, } @@ -477,7 +477,10 @@ pub fn create_surfaces( } } - SurfaceData { surface, format } + SurfaceData { + surface: WgpuWrapper::new(surface), + format, + } }); } } From eb846f70738126590aa7cb9fa4f6b73da1bdd191 Mon Sep 17 00:00:00 2001 From: Ian Kettlewell Date: Thu, 29 Feb 2024 15:25:02 -0500 Subject: [PATCH 02/14] Add CI checks to ensure building Wasm with atomics doesn't regress --- .github/workflows/ci.yml | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 58685510aced3..d59f708c0c4fe 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -146,6 +146,30 @@ jobs: run: cargo check --target wasm32-unknown-unknown env: RUSTFLAGS: --cfg=web_sys_unstable_apis + + build-wasm-atomics: + runs-on: ubuntu-latest + timeout-minutes: 30 + needs: build + steps: + - uses: actions/checkout@v4 + - uses: actions/cache@v4 + with: + path: | + ~/.cargo/bin/ + ~/.cargo/registry/index/ + ~/.cargo/registry/cache/ + ~/.cargo/git/db/ + target/ + key: ubuntu-assets-cargo-build-wasm-stable-${{ hashFiles('**/Cargo.toml') }} + - uses: dtolnay/rust-toolchain@stable + with: + target: wasm32-unknown-unknown + - name: Check wasm + run: cargo check --target wasm32-unknown-unknown -Z build-std=std,panic_abort + env: + RUSTFLAGS: "--cfg=web_sys_unstable_apis -C target-feature=+atomics,+bulk-memory,+mutable-globals" + markdownlint: runs-on: ubuntu-latest From 93a6042127711ef2122b6dfbc4868f3cf2904d93 Mon Sep 17 00:00:00 2001 From: Ian Kettlewell Date: Thu, 29 Feb 2024 15:43:15 -0500 Subject: [PATCH 03/14] Fix CI errors. * Move a comment * Run CI on nightly --- .github/workflows/ci.yml | 4 ++-- crates/bevy_render/src/render_resource/resource_macros.rs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d59f708c0c4fe..e3d9651faeb6b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -161,8 +161,8 @@ jobs: ~/.cargo/registry/cache/ ~/.cargo/git/db/ target/ - key: ubuntu-assets-cargo-build-wasm-stable-${{ hashFiles('**/Cargo.toml') }} - - uses: dtolnay/rust-toolchain@stable + key: ubuntu-assets-cargo-build-wasm-nightly-${{ hashFiles('**/Cargo.toml') }} + - uses: dtolnay/rust-toolchain@nightly with: target: wasm32-unknown-unknown - name: Check wasm diff --git a/crates/bevy_render/src/render_resource/resource_macros.rs b/crates/bevy_render/src/render_resource/resource_macros.rs index ea8d907a038c1..c027a92e2873f 100644 --- a/crates/bevy_render/src/render_resource/resource_macros.rs +++ b/crates/bevy_render/src/render_resource/resource_macros.rs @@ -62,14 +62,14 @@ macro_rules! render_resource_wrapper { } } + #[cfg(not(all(target_arch = "wasm32", target_feature = "atomics")))] // SAFETY: We manually implement Send and Sync, which is valid for Arc when T: Send + Sync. // We ensure correctness by checking that $wgpu_type does implement Send and Sync. // If in future there is a case where a wrapper is required for a non-send/sync type // we can implement a macro variant that omits these manual Send + Sync impls - #[cfg(not(all(target_arch = "wasm32", target_feature = "atomics")))] unsafe impl Send for $wrapper_type {} - // SAFETY: As explained above, we ensure correctness by checking that $wgpu_type implements Send and Sync. #[cfg(not(all(target_arch = "wasm32", target_feature = "atomics")))] + // SAFETY: As explained above, we ensure correctness by checking that $wgpu_type implements Send and Sync. unsafe impl Sync for $wrapper_type {} #[cfg(not(all(target_arch = "wasm32", target_feature = "atomics")))] const _: () = { From 59eddb574cc3e31d27f1ba84ccbf0b4a90c7af8e Mon Sep 17 00:00:00 2001 From: Ian Kettlewell Date: Thu, 29 Feb 2024 16:44:56 -0500 Subject: [PATCH 04/14] Use NIGHTLY_TOOLCHAIN env variable MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: François --- .github/workflows/ci.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e3d9651faeb6b..f313e7f127755 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -162,8 +162,9 @@ jobs: ~/.cargo/git/db/ target/ key: ubuntu-assets-cargo-build-wasm-nightly-${{ hashFiles('**/Cargo.toml') }} - - uses: dtolnay/rust-toolchain@nightly + - uses: dtolnay/rust-toolchain@master with: + toolchain: ${{ env.NIGHTLY_TOOLCHAIN }} target: wasm32-unknown-unknown - name: Check wasm run: cargo check --target wasm32-unknown-unknown -Z build-std=std,panic_abort From 106f8920917e919b9c4291909dc85eaf15a7ba58 Mon Sep 17 00:00:00 2001 From: Ian Kettlewell Date: Fri, 1 Mar 2024 17:24:21 -0500 Subject: [PATCH 05/14] Update crates/bevy_render/src/renderer/mod.rs Co-authored-by: Alice Cecile --- crates/bevy_render/src/renderer/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/bevy_render/src/renderer/mod.rs b/crates/bevy_render/src/renderer/mod.rs index 25f0b24bffcf8..236d5ab1d0723 100644 --- a/crates/bevy_render/src/renderer/mod.rs +++ b/crates/bevy_render/src/renderer/mod.rs @@ -115,7 +115,7 @@ pub struct WgpuWrapper(T); #[derive(Debug, Clone)] pub struct WgpuWrapper(send_wrapper::SendWrapper); -// Safety: SendWrapper is always Send + Sync. +// SAFETY: SendWrapper is always Send + Sync. #[cfg(all(target_arch = "wasm32", target_feature = "atomics"))] unsafe impl Send for WgpuWrapper {} #[cfg(all(target_arch = "wasm32", target_feature = "atomics"))] From 431aa3725a760f44710d884b27658b15496d5e7d Mon Sep 17 00:00:00 2001 From: Ian Kettlewell Date: Wed, 6 Mar 2024 22:24:25 -0500 Subject: [PATCH 06/14] Use derive instead of manual Deref / DerefMut impl --- crates/bevy_render/src/renderer/mod.rs | 20 ++------------------ 1 file changed, 2 insertions(+), 18 deletions(-) diff --git a/crates/bevy_render/src/renderer/mod.rs b/crates/bevy_render/src/renderer/mod.rs index 236d5ab1d0723..8d2c8d5e8be8a 100644 --- a/crates/bevy_render/src/renderer/mod.rs +++ b/crates/bevy_render/src/renderer/mod.rs @@ -109,10 +109,10 @@ pub fn render_system(world: &mut World, state: &mut SystemState(T); #[cfg(all(target_arch = "wasm32", target_feature = "atomics"))] -#[derive(Debug, Clone)] +#[derive(Debug, Clone, Deref, DerefMut)] pub struct WgpuWrapper(send_wrapper::SendWrapper); // SAFETY: SendWrapper is always Send + Sync. @@ -135,22 +135,6 @@ impl WgpuWrapper { } } -impl std::ops::Deref for WgpuWrapper { - type Target = T; - - #[track_caller] - fn deref(&self) -> &T { - &self.0 - } -} - -impl std::ops::DerefMut for WgpuWrapper { - #[track_caller] - fn deref_mut(&mut self) -> &mut T { - &mut self.0 - } -} - /// This queue is used to enqueue tasks for the GPU to execute asynchronously. #[derive(Resource, Clone, Deref, DerefMut)] pub struct RenderQueue(pub Arc>); From 97837267d3bf1096ba962e37363a29af6b033518 Mon Sep 17 00:00:00 2001 From: Ian Kettlewell Date: Thu, 7 Mar 2024 12:51:49 -0500 Subject: [PATCH 07/14] Remove unnecessary +mutable-globals target-feature Co-authored-by: daxpedda --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6c52a326a12d8..ecc7a5c5c4cd6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -167,7 +167,7 @@ jobs: - name: Check wasm run: cargo check --target wasm32-unknown-unknown -Z build-std=std,panic_abort env: - RUSTFLAGS: "-C target-feature=+atomics,+bulk-memory,+mutable-globals" + RUSTFLAGS: "-C target-feature=+atomics,+bulk-memory" markdownlint: runs-on: ubuntu-latest From e183932de8462f986c7af4d645afcafd609ef135 Mon Sep 17 00:00:00 2001 From: Ian Kettlewell Date: Sat, 9 Mar 2024 10:38:16 -0500 Subject: [PATCH 08/14] Add x86_64-unknown-linux-gnu target to fix failing CI MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: François --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ecc7a5c5c4cd6..fce405bfd7efb 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -163,7 +163,7 @@ jobs: - uses: dtolnay/rust-toolchain@master with: toolchain: ${{ env.NIGHTLY_TOOLCHAIN }} - target: wasm32-unknown-unknown + targets: wasm32-unknown-unknown,x86_64-unknown-linux-gnu - name: Check wasm run: cargo check --target wasm32-unknown-unknown -Z build-std=std,panic_abort env: From a14f55e6d5280ccb60873df799f806b5db414662 Mon Sep 17 00:00:00 2001 From: Ian Kettlewell Date: Sat, 9 Mar 2024 12:11:45 -0500 Subject: [PATCH 09/14] Attempting to fix build-wasm-atomics CI --- .github/workflows/ci.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index fce405bfd7efb..95419d3647f12 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -163,7 +163,8 @@ jobs: - uses: dtolnay/rust-toolchain@master with: toolchain: ${{ env.NIGHTLY_TOOLCHAIN }} - targets: wasm32-unknown-unknown,x86_64-unknown-linux-gnu + targets: wasm32-unknown-unknown + components: rust-std - name: Check wasm run: cargo check --target wasm32-unknown-unknown -Z build-std=std,panic_abort env: From 65cca195fedd83efdbe8bd7b1f7b6d355761f1dd Mon Sep 17 00:00:00 2001 From: Ian Kettlewell Date: Sat, 9 Mar 2024 12:28:38 -0500 Subject: [PATCH 10/14] Another attempt at CI fix: add back x86_64-unknown-linux-gnu target --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 95419d3647f12..0ac81128de134 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -163,7 +163,7 @@ jobs: - uses: dtolnay/rust-toolchain@master with: toolchain: ${{ env.NIGHTLY_TOOLCHAIN }} - targets: wasm32-unknown-unknown + targets: wasm32-unknown-unknown,x86_64-unknown-linux-gnu components: rust-std - name: Check wasm run: cargo check --target wasm32-unknown-unknown -Z build-std=std,panic_abort From 06365404a30579450c7989f880a0b5c288f1de49 Mon Sep 17 00:00:00 2001 From: Ian Kettlewell Date: Sat, 9 Mar 2024 12:44:20 -0500 Subject: [PATCH 11/14] CI fix to download rust-src --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0ac81128de134..f4e784c14a800 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -164,7 +164,7 @@ jobs: with: toolchain: ${{ env.NIGHTLY_TOOLCHAIN }} targets: wasm32-unknown-unknown,x86_64-unknown-linux-gnu - components: rust-std + components: rust-src - name: Check wasm run: cargo check --target wasm32-unknown-unknown -Z build-std=std,panic_abort env: From dd7240c76d9ed4ce228128d64d5dd3c2d08f5ec4 Mon Sep 17 00:00:00 2001 From: Ian Kettlewell Date: Sat, 16 Mar 2024 10:36:55 -0400 Subject: [PATCH 12/14] Try removing x86_64-unknown-linux-gnu from ci.yml Co-authored-by: daxpedda --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f4e784c14a800..fc4f2beeea01e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -163,7 +163,7 @@ jobs: - uses: dtolnay/rust-toolchain@master with: toolchain: ${{ env.NIGHTLY_TOOLCHAIN }} - targets: wasm32-unknown-unknown,x86_64-unknown-linux-gnu + targets: wasm32-unknown-unknown components: rust-src - name: Check wasm run: cargo check --target wasm32-unknown-unknown -Z build-std=std,panic_abort From e8fab229c07d0b5712efc0c053c1f90db0799eac Mon Sep 17 00:00:00 2001 From: Ian Kettlewell Date: Sat, 23 Mar 2024 16:07:01 -0400 Subject: [PATCH 13/14] Amend comments to add clarifications --- crates/bevy_render/Cargo.toml | 4 +++- crates/bevy_render/src/renderer/mod.rs | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/crates/bevy_render/Cargo.toml b/crates/bevy_render/Cargo.toml index 89424a8a8783e..e78cd2cbef02f 100644 --- a/crates/bevy_render/Cargo.toml +++ b/crates/bevy_render/Cargo.toml @@ -63,7 +63,9 @@ image = { version = "0.24", default-features = false } # misc codespan-reporting = "0.11.0" # `fragile-send-sync-non-atomic-wasm` feature means we can't use WASM threads for rendering -# It is enabled for now to avoid having to do a significant overhaul of the renderer just for wasm +# It is enabled for now to avoid having to do a significant overhaul of the renderer just for wasm. +# When the 'atomics' feature is enabled `fragile-send-sync-non-atomic` does nothing +# and Bevy instead wraps `wgpu` types to verify they are not used off their origin thread. wgpu = { version = "0.19.3", default-features = false, features = [ "wgsl", "dx12", diff --git a/crates/bevy_render/src/renderer/mod.rs b/crates/bevy_render/src/renderer/mod.rs index 8d2c8d5e8be8a..fe625b2c806c1 100644 --- a/crates/bevy_render/src/renderer/mod.rs +++ b/crates/bevy_render/src/renderer/mod.rs @@ -105,8 +105,8 @@ pub fn render_system(world: &mut World, state: &mut SystemState Date: Sat, 23 Mar 2024 16:19:54 -0400 Subject: [PATCH 14/14] Formatting tweak: remove trailing space in comment --- crates/bevy_render/src/renderer/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/bevy_render/src/renderer/mod.rs b/crates/bevy_render/src/renderer/mod.rs index 8ffa9deb7184a..3f1620ae876fe 100644 --- a/crates/bevy_render/src/renderer/mod.rs +++ b/crates/bevy_render/src/renderer/mod.rs @@ -118,7 +118,7 @@ pub fn render_system(world: &mut World, state: &mut SystemState