Skip to content

Commit

Permalink
We cannot list available adapters on web
Browse files Browse the repository at this point in the history
  • Loading branch information
emilk committed Jan 18, 2024
1 parent e996df6 commit 7e66aa5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
17 changes: 16 additions & 1 deletion crates/egui-wgpu/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ pub struct RenderState {
pub adapter: Arc<wgpu::Adapter>,

/// All the available adapters.
///
/// This is not availabler on web.
/// On web, we always select WebGPU is available, then fall back to WebGL if not.
#[cfg(not(target_arch = "wasm32"))]
pub available_adapters: Arc<[wgpu::Adapter]>,

/// Wgpu device used for rendering, created from the adapter.
Expand Down Expand Up @@ -86,7 +90,9 @@ impl RenderState {
) -> Result<Self, WgpuError> {
crate::profile_scope!("RenderState::create"); // async yield give bad names using `profile_function`

let available_adapters: Vec<_> = instance.enumerate_adapters(wgpu::Backends::all());
// This is always an empty list on web.
#[cfg(not(target_arch = "wasm32"))]
let available_adapters = instance.enumerate_adapters(wgpu::Backends::all());

let adapter = {
crate::profile_scope!("request_adapter");
Expand Down Expand Up @@ -118,6 +124,13 @@ impl RenderState {
})?
};

#[cfg(target_arch = "wasm32")]
log::debug!(
"Picked wgpu adapter: {}",
adapter_info_summary(&adapter.get_info())
);

#[cfg(not(target_arch = "wasm32"))]
if available_adapters.len() == 1 {
log::debug!(
"Picked the only available wgpu adapter: {}",
Expand Down Expand Up @@ -152,6 +165,7 @@ impl RenderState {

Ok(Self {
adapter: Arc::new(adapter),
#[cfg(not(target_arch = "wasm32"))]
available_adapters: available_adapters.into(),
device: Arc::new(device),
queue: Arc::new(queue),
Expand All @@ -161,6 +175,7 @@ impl RenderState {
}
}

#[cfg(not(target_arch = "wasm32"))]
fn describe_adapters(adapters: &[wgpu::Adapter]) -> String {
if adapters.is_empty() {
"(none)".to_owned()
Expand Down
1 change: 1 addition & 0 deletions crates/egui_demo_app/src/backend_panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ fn integration_ui(ui: &mut egui::Ui, _frame: &mut eframe::Frame) {
wgpu_adapter_ui(ui, &render_state.adapter);
ui.end_row();

#[cfg(not(target_arch = "wasm32"))]
if 1 < render_state.available_adapters.len() {
ui.label("Others:");
ui.vertical(|ui| {
Expand Down

0 comments on commit 7e66aa5

Please sign in to comment.