Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
241 changes: 160 additions & 81 deletions Cargo.lock

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ wasm-bindgen = "0.2"
wasm-bindgen-futures = "0.4"
web-sys = "0.3.73"
web-time = "1.1.0" # Timekeeping for native and web
wgpu = { version = "24.0.0", default-features = false }
wgpu = { version = "25.0.0", default-features = false }
wgpu-core = { version = "25.0.1", default-features = false }
windows-sys = "0.59"
winit = { version = "0.30.7", default-features = false }

Expand Down
4 changes: 4 additions & 0 deletions crates/egui-wgpu/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ wayland = ["winit?/wayland"]
## Enables x11 support for winit.
x11 = ["winit?/x11"]

## Enables tracing support for wgpu. Requires setting the `WGPU_TRACE` environment variable to a directory to work.
wgpu-trace = ["wgpu-core/trace"]

## Make the renderer `Sync` on wasm, exploiting that by default wasm isn't multithreaded.
## It may make code easier, expecially when targeting both native and web.
## On native most wgpu objects are send and sync, on the web they are not (by nature of the WebGPU specification).
Expand All @@ -62,6 +65,7 @@ thiserror.workspace = true
type-map.workspace = true
web-time.workspace = true
wgpu = { workspace = true, features = ["wgsl"] }
wgpu-core.workspace = true

# Optional dependencies:

Expand Down
7 changes: 3 additions & 4 deletions crates/egui-wgpu/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ async fn request_adapter(
force_fallback_adapter: false,
})
.await
.ok_or_else(|| {
.map_err(|e| {
#[cfg(not(target_arch = "wasm32"))]
if _available_adapters.is_empty() {
log::info!("No wgpu adapters found");
Expand All @@ -121,7 +121,7 @@ async fn request_adapter(
);
}

WgpuError::NoSuitableAdapterFound("`request_adapters` returned `None`".to_owned())
WgpuError::NoSuitableAdapterFound(format!("`request_adapters` returned `Err`: {e}"))
})?;

#[cfg(target_arch = "wasm32")]
Expand Down Expand Up @@ -184,7 +184,6 @@ impl RenderState {
power_preference,
native_adapter_selector: _native_adapter_selector,
device_descriptor,
trace_path,
}) => {
let adapter = {
#[cfg(target_arch = "wasm32")]
Expand All @@ -209,7 +208,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?
};

Expand Down
23 changes: 10 additions & 13 deletions crates/egui-wgpu/src/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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(),
}
}
}
Expand All @@ -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()
}
}
Expand Down Expand Up @@ -185,6 +176,15 @@ impl Default for WgpuSetupCreateNew {
wgpu::Limits::default()
};

let mut _trace = wgpu::Trace::Off;
#[cfg(feature = "wgpu-trace")]
if let Some(path) = std::env::var("WGPU_TRACE")
.ok()
.map(std::path::PathBuf::from)
{
_trace = wgpu::Trace::Directory(path);
}

wgpu::DeviceDescriptor {
label: Some("egui wgpu device"),
required_features: wgpu::Features::default(),
Expand All @@ -195,12 +195,9 @@ impl Default for WgpuSetupCreateNew {
..base_limits
},
memory_hints: wgpu::MemoryHints::default(),
trace: _trace,
}
}),

trace_path: std::env::var("WGPU_TRACE")
.ok()
.map(std::path::PathBuf::from),
}
}
}
Expand Down
7 changes: 6 additions & 1 deletion crates/egui_kittest/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
4 changes: 3 additions & 1 deletion crates/egui_kittest/src/texture_to_image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(..);
Expand Down
7 changes: 5 additions & 2 deletions crates/egui_kittest/src/wgpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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,
Expand Down
Loading