Skip to content

Commit

Permalink
add WgpuSetupExisting type
Browse files Browse the repository at this point in the history
  • Loading branch information
Wumpf committed Jan 8, 2025
1 parent 80c9688 commit f5ae131
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 14 deletions.
6 changes: 3 additions & 3 deletions crates/egui-wgpu/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 = {
Expand Down
37 changes: 26 additions & 11 deletions crates/egui-wgpu/src/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<wgpu::Instance>,
adapter: Arc<wgpu::Adapter>,
device: Arc<wgpu::Device>,
queue: Arc<wgpu::Queue>,
},
Existing(WgpuSetupExisting),
}

impl Default for WgpuSetup {
Expand All @@ -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(),
}
}
}
Expand Down Expand Up @@ -88,11 +80,23 @@ impl WgpuSetup {
.await,
)
}
Self::Existing { instance, .. } => instance.clone(),
Self::Existing(existing) => existing.instance.clone(),
}
}
}

impl From<WgpuSetupCreateNew> for WgpuSetup {
fn from(create_new: WgpuSetupCreateNew) -> Self {
Self::CreateNew(create_new)
}
}

impl From<WgpuSetupExisting> 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.
Expand Down Expand Up @@ -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<wgpu::Instance>,
pub adapter: Arc<wgpu::Adapter>,
pub device: Arc<wgpu::Device>,
pub queue: Arc<wgpu::Queue>,
}

0 comments on commit f5ae131

Please sign in to comment.