1
0
mirror of https://github.com/emilk/egui.git synced 2026-08-30 13:20:05 -04:00

Add opt-out fragile-send-sync-non-atomic-wasm feature for wgpu (#5098)

Note this will break people depending on eframe or egui-wgpu with
--no-default-features.
I don't know what to do about that to be honest.

* Closes #4914 
* [x] I have followed the instructions in the PR template

---------

Co-authored-by: Andreas Reich <r_andreas2@web.de>
This commit is contained in:
9SMTM6
2024-09-13 13:00:18 +02:00
committed by GitHub
parent f658f8b02b
commit 08f5eb30a4
6 changed files with 53 additions and 6 deletions

View File

@@ -173,6 +173,9 @@ impl RenderState {
dithering,
);
// On wasm, depending on feature flags, wgpu objects may or may not implement sync.
// It doesn't make sense to switch to Rc for that special usecase, so simply disable the lint.
#[allow(clippy::arc_with_non_send_sync)]
Ok(Self {
adapter: Arc::new(adapter),
#[cfg(not(target_arch = "wasm32"))]

View File

@@ -7,8 +7,19 @@ use epaint::{emath::NumExt, PaintCallbackInfo, Primitive, Vertex};
use wgpu::util::DeviceExt as _;
// Only implements Send + Sync on wasm32 in order to allow storing wgpu resources on the type map.
#[cfg(not(all(
target_arch = "wasm32",
not(feature = "fragile-send-sync-non-atomic-wasm"),
)))]
/// You can use this for storage when implementing [`CallbackTrait`].
pub type CallbackResources = type_map::concurrent::TypeMap;
#[cfg(all(
target_arch = "wasm32",
not(feature = "fragile-send-sync-non-atomic-wasm"),
))]
/// You can use this for storage when implementing [`CallbackTrait`].
pub type CallbackResources = type_map::TypeMap;
/// You can use this to do custom [`wgpu`] rendering in an egui app.
///
@@ -1017,6 +1028,11 @@ impl ScissorRect {
}
}
// Look at the feature flag for an explanation.
#[cfg(not(all(
target_arch = "wasm32",
not(feature = "fragile-send-sync-non-atomic-wasm"),
)))]
#[test]
fn renderer_impl_send_sync() {
fn assert_send_sync<T: Send + Sync>() {}