diff --git a/crates/egui-wgpu/src/lib.rs b/crates/egui-wgpu/src/lib.rs index e827ea1839d..faa8d600c79 100644 --- a/crates/egui-wgpu/src/lib.rs +++ b/crates/egui-wgpu/src/lib.rs @@ -26,7 +26,7 @@ mod renderer; mod setup; pub use renderer::*; -pub use setup::{NativeAdapterSelectorMethod, WgpuSetup, WgpuSetupCreateNew}; +pub use setup::{NativeAdapterSelectorMethod, WgpuSetup, WgpuSetupCreateNew, WgpuSetupExisting}; /// Helpers for capturing screenshots of the UI. pub mod capture; @@ -227,12 +227,12 @@ impl RenderState { #[allow(clippy::arc_with_non_send_sync)] (adapter, Arc::new(device), Arc::new(queue)) } - WgpuSetup::Existing { + WgpuSetup::Existing(WgpuSetupExisting { instance: _, adapter, device, queue, - } => (adapter, device, queue), + }) => (adapter, device, queue), }; let surface_formats = { diff --git a/crates/egui-wgpu/src/setup.rs b/crates/egui-wgpu/src/setup.rs index 709cf624d83..567c0d75f6a 100644 --- a/crates/egui-wgpu/src/setup.rs +++ b/crates/egui-wgpu/src/setup.rs @@ -19,13 +19,7 @@ pub enum WgpuSetup { CreateNew(WgpuSetupCreateNew), /// Run on an existing wgpu setup. - Existing { - // TODO(gfx-rs/wgpu#6665): Remove layer of `Arc` here once we update to wgpu 24. - instance: Arc, - adapter: Arc, - device: Arc, - queue: Arc, - }, + Existing(WgpuSetupExisting), } impl Default for WgpuSetup { @@ -41,9 +35,7 @@ impl std::fmt::Debug for WgpuSetup { .debug_tuple("WgpuSetup::CreateNew") .field(create_new) .finish(), - Self::Existing { .. } => f - .debug_struct("WgpuSetup::Existing") - .finish_non_exhaustive(), + Self::Existing { .. } => f.debug_tuple("WgpuSetup::Existing").finish(), } } } @@ -88,11 +80,23 @@ impl WgpuSetup { .await, ) } - Self::Existing { instance, .. } => instance.clone(), + Self::Existing(existing) => existing.instance.clone(), } } } +impl From for WgpuSetup { + fn from(create_new: WgpuSetupCreateNew) -> Self { + Self::CreateNew(create_new) + } +} + +impl From for WgpuSetup { + fn from(existing: WgpuSetupExisting) -> Self { + Self::Existing(existing) + } +} + /// Method for selecting an adapter on native. /// /// This can be used for fully custom adapter selection. @@ -220,3 +224,14 @@ impl Default for WgpuSetupCreateNew { } } } + +/// Configuration for using an existing wgpu setup. +/// +/// Used for [`WgpuSetup::Existing`]. +#[derive(Clone)] +pub struct WgpuSetupExisting { + pub instance: Arc, + pub adapter: Arc, + pub device: Arc, + pub queue: Arc, +}