mirror of
https://github.com/emilk/egui.git
synced 2026-08-29 04:40:03 -04:00
Update to wgpu 25 (#6744)
Co-authored-by: Andreas Reich <r_andreas2@web.de>
This commit is contained in:
@@ -42,8 +42,11 @@ use epaint::mutex::RwLock;
|
||||
/// An error produced by egui-wgpu.
|
||||
#[derive(thiserror::Error, Debug)]
|
||||
pub enum WgpuError {
|
||||
#[error("Failed to create wgpu adapter, no suitable adapter found: {0}")]
|
||||
NoSuitableAdapterFound(String),
|
||||
#[error(transparent)]
|
||||
RequestAdapterError(#[from] wgpu::RequestAdapterError),
|
||||
|
||||
#[error("Adapter selection failed: {0}")]
|
||||
CustomNativeAdapterSelectionError(String),
|
||||
|
||||
#[error("There was no valid format for the surface at all.")]
|
||||
NoSurfaceFormatsAvailable,
|
||||
@@ -104,7 +107,7 @@ async fn request_adapter(
|
||||
force_fallback_adapter: false,
|
||||
})
|
||||
.await
|
||||
.ok_or_else(|| {
|
||||
.inspect_err(|_err| {
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
if _available_adapters.is_empty() {
|
||||
log::info!("No wgpu adapters found");
|
||||
@@ -120,8 +123,6 @@ async fn request_adapter(
|
||||
describe_adapters(_available_adapters)
|
||||
);
|
||||
}
|
||||
|
||||
WgpuError::NoSuitableAdapterFound("`request_adapters` returned `None`".to_owned())
|
||||
})?;
|
||||
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
@@ -184,7 +185,6 @@ impl RenderState {
|
||||
power_preference,
|
||||
native_adapter_selector: _native_adapter_selector,
|
||||
device_descriptor,
|
||||
trace_path,
|
||||
}) => {
|
||||
let adapter = {
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
@@ -194,7 +194,7 @@ impl RenderState {
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
if let Some(native_adapter_selector) = _native_adapter_selector {
|
||||
native_adapter_selector(&available_adapters, compatible_surface)
|
||||
.map_err(WgpuError::NoSuitableAdapterFound)
|
||||
.map_err(WgpuError::CustomNativeAdapterSelectionError)
|
||||
} else {
|
||||
request_adapter(
|
||||
instance,
|
||||
@@ -209,7 +209,7 @@ impl RenderState {
|
||||
let (device, queue) = {
|
||||
profiling::scope!("request_device");
|
||||
adapter
|
||||
.request_device(&(*device_descriptor)(&adapter), trace_path.as_deref())
|
||||
.request_device(&(*device_descriptor)(&adapter))
|
||||
.await?
|
||||
};
|
||||
|
||||
|
||||
@@ -126,13 +126,6 @@ pub struct WgpuSetupCreateNew {
|
||||
/// Configuration passed on device request, given an adapter
|
||||
pub device_descriptor:
|
||||
Arc<dyn Fn(&wgpu::Adapter) -> wgpu::DeviceDescriptor<'static> + Send + Sync>,
|
||||
|
||||
/// Option path to output a wgpu trace file.
|
||||
///
|
||||
/// This only works if this feature is enabled in `wgpu-core`.
|
||||
/// Does not work when running with WebGPU.
|
||||
/// Defaults to the path set in the `WGPU_TRACE` environment variable.
|
||||
pub trace_path: Option<std::path::PathBuf>,
|
||||
}
|
||||
|
||||
impl Clone for WgpuSetupCreateNew {
|
||||
@@ -142,7 +135,6 @@ impl Clone for WgpuSetupCreateNew {
|
||||
power_preference: self.power_preference,
|
||||
native_adapter_selector: self.native_adapter_selector.clone(),
|
||||
device_descriptor: self.device_descriptor.clone(),
|
||||
trace_path: self.trace_path.clone(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -156,7 +148,6 @@ impl std::fmt::Debug for WgpuSetupCreateNew {
|
||||
"native_adapter_selector",
|
||||
&self.native_adapter_selector.is_some(),
|
||||
)
|
||||
.field("trace_path", &self.trace_path)
|
||||
.finish()
|
||||
}
|
||||
}
|
||||
@@ -195,12 +186,9 @@ impl Default for WgpuSetupCreateNew {
|
||||
..base_limits
|
||||
},
|
||||
memory_hints: wgpu::MemoryHints::default(),
|
||||
trace: wgpu::Trace::Off,
|
||||
}
|
||||
}),
|
||||
|
||||
trace_path: std::env::var("WGPU_TRACE")
|
||||
.ok()
|
||||
.map(std::path::PathBuf::from),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,7 +52,12 @@ egui-wgpu = { workspace = true, optional = true }
|
||||
pollster = { workspace = true, optional = true }
|
||||
image = { workspace = true, optional = true }
|
||||
# Enable DX12 because it always comes with a software rasterizer.
|
||||
wgpu = { workspace = true, features = ["metal", "dx12"], optional = true }
|
||||
wgpu = { workspace = true, features = [
|
||||
"metal",
|
||||
"dx12",
|
||||
"vulkan",
|
||||
"gles",
|
||||
], optional = true }
|
||||
|
||||
# snapshot dependencies
|
||||
dify = { workspace = true, optional = true }
|
||||
|
||||
@@ -47,7 +47,9 @@ pub(crate) fn texture_to_image(device: &Device, queue: &Queue, texture: &Texture
|
||||
buffer_slice.map_async(wgpu::MapMode::Read, move |v| drop(sender.send(v)));
|
||||
|
||||
// Poll the device in a blocking manner so that our future resolves.
|
||||
device.poll(wgpu::Maintain::WaitForSubmissionIndex(submission_index));
|
||||
device
|
||||
.poll(wgpu::PollType::WaitForSubmissionIndex(submission_index))
|
||||
.expect("Failed to poll device");
|
||||
|
||||
receiver.recv().unwrap().unwrap();
|
||||
let buffer_slice = output_buffer.slice(..);
|
||||
|
||||
@@ -28,7 +28,7 @@ pub fn default_wgpu_setup() -> egui_wgpu::WgpuSetup {
|
||||
wgpu::Backend::Dx12 => 2,
|
||||
wgpu::Backend::Gl => 4,
|
||||
wgpu::Backend::BrowserWebGpu => 6,
|
||||
wgpu::Backend::Empty => 7,
|
||||
wgpu::Backend::Noop => 7,
|
||||
});
|
||||
|
||||
// Prefer CPU adapters, otherwise if we can't, prefer discrete GPU over integrated GPU.
|
||||
@@ -202,7 +202,10 @@ impl crate::TestRenderer for WgpuTestRenderer {
|
||||
.queue
|
||||
.submit(user_buffers.into_iter().chain(once(encoder.finish())));
|
||||
|
||||
self.render_state.device.poll(wgpu::Maintain::Wait);
|
||||
self.render_state
|
||||
.device
|
||||
.poll(wgpu::PollType::Wait)
|
||||
.map_err(|e| format!("{e}"))?;
|
||||
|
||||
Ok(texture_to_image(
|
||||
&self.render_state.device,
|
||||
|
||||
Reference in New Issue
Block a user