Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend WgpuSetup, egui_kittest now prefers software rasterizers for testing #5506

Merged
merged 12 commits into from
Jan 8, 2025
29 changes: 28 additions & 1 deletion Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1348,7 +1348,6 @@ dependencies = [
"egui_kittest",
"serde",
"unicode_names2",
"wgpu",
]

[[package]]
Expand Down Expand Up @@ -1926,6 +1925,18 @@ dependencies = [
"bitflags 2.6.0",
]

[[package]]
name = "gpu-allocator"
version = "0.27.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c151a2a5ef800297b4e79efa4f4bec035c5f51d5ae587287c9b952bdf734cacd"
dependencies = [
"log",
"presser",
"thiserror",
"windows",
]

[[package]]
name = "gpu-descriptor"
version = "0.3.0"
Expand Down Expand Up @@ -3109,6 +3120,12 @@ dependencies = [
"zerocopy",
]

[[package]]
name = "presser"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e8cf8e6a8aa66ce33f63993ffc4ea4271eb5b0530a9002db8455ea6050c77bfa"

[[package]]
name = "proc-macro-crate"
version = "3.2.0"
Expand Down Expand Up @@ -3262,6 +3279,12 @@ dependencies = [
"getrandom",
]

[[package]]
name = "range-alloc"
version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c8a99fddc9f0ba0a85884b8d14e3592853e787d581ca1816c91349b10e4eeab"

[[package]]
name = "raw-window-handle"
version = "0.5.2"
Expand Down Expand Up @@ -4512,6 +4535,7 @@ dependencies = [
"android_system_properties",
"arrayvec",
"ash",
"bit-set 0.8.0",
"bitflags 2.6.0",
"block",
"bytemuck",
Expand All @@ -4520,6 +4544,7 @@ dependencies = [
"glow 0.14.2",
"glutin_wgl_sys",
"gpu-alloc",
"gpu-allocator",
"gpu-descriptor",
"js-sys",
"khronos-egl",
Expand All @@ -4533,6 +4558,7 @@ dependencies = [
"once_cell",
"parking_lot",
"profiling",
"range-alloc",
"raw-window-handle 0.6.2",
"renderdoc-sys",
"rustc-hash",
Expand All @@ -4542,6 +4568,7 @@ dependencies = [
"web-sys",
"wgpu-types",
"windows",
"windows-core 0.58.0",
]

[[package]]
Expand Down
4 changes: 2 additions & 2 deletions crates/eframe/src/native/wgpu_integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ impl<'app> WgpuWinitApp<'app> {
) -> crate::Result<&mut WgpuWinitRunning<'app>> {
profiling::function_scope!();
#[allow(unsafe_code, unused_mut, unused_unsafe)]
let mut painter = egui_wgpu::winit::Painter::new(
let mut painter = pollster::block_on(egui_wgpu::winit::Painter::new(
egui_ctx.clone(),
self.native_options.wgpu_options.clone(),
self.native_options.multisampling.max(1) as _,
Expand All @@ -193,7 +193,7 @@ impl<'app> WgpuWinitApp<'app> {
),
self.native_options.viewport.transparent.unwrap_or(false),
self.native_options.dithering,
);
));

let window = Arc::new(window);

Expand Down
46 changes: 2 additions & 44 deletions crates/eframe/src/web/web_painter_wgpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use super::web_painter::WebPainter;
use crate::WebOptions;
use egui::{Event, UserData, ViewportId};
use egui_wgpu::capture::{capture_channel, CaptureReceiver, CaptureSender, CaptureState};
use egui_wgpu::{RenderState, SurfaceErrorAction, WgpuSetup};
use egui_wgpu::{RenderState, SurfaceErrorAction};
use wasm_bindgen::JsValue;
use web_sys::HtmlCanvasElement;

Expand Down Expand Up @@ -63,49 +63,7 @@ impl WebPainterWgpu {
) -> Result<Self, String> {
log::debug!("Creating wgpu painter");

let instance = match &options.wgpu_options.wgpu_setup {
WgpuSetup::CreateNew {
supported_backends: backends,
power_preference,
..
} => {
let mut backends = *backends;

// Don't try WebGPU if we're not in a secure context.
if backends.contains(wgpu::Backends::BROWSER_WEBGPU) {
let is_secure_context =
web_sys::window().map_or(false, |w| w.is_secure_context());
if !is_secure_context {
log::info!(
"WebGPU is only available in secure contexts, i.e. on HTTPS and on localhost."
);

// Don't try WebGPU since we established now that it will fail.
backends.remove(wgpu::Backends::BROWSER_WEBGPU);

if backends.is_empty() {
return Err("No available supported graphics backends.".to_owned());
}
}
}

log::debug!("Creating wgpu instance with backends {:?}", backends);

let instance =
wgpu::util::new_instance_with_webgpu_detection(wgpu::InstanceDescriptor {
backends,
..Default::default()
})
.await;

// On wasm, depending on feature flags, wgpu objects may or may not implement sync.
// It doesn't make sense to switch to Rc for that special usecase, so simply disable the lint.
#[allow(clippy::arc_with_non_send_sync)]
Arc::new(instance)
}
WgpuSetup::Existing { instance, .. } => instance.clone(),
};

let instance = options.wgpu_options.wgpu_setup.new_instance().await;
let surface = instance
.create_surface(wgpu::SurfaceTarget::Canvas(canvas.clone()))
.map_err(|err| format!("failed to create wgpu surface: {err}"))?;
Expand Down
Loading
Loading