Skip to content

Commit 09ac8c5

Browse files
committed
wgpu -> 22.1
Tested on X11 and Wayland via weston and seems to work closes: wezterm#5814
1 parent 24702de commit 09ac8c5

File tree

10 files changed

+270
-202
lines changed

10 files changed

+270
-202
lines changed

Cargo.lock

Lines changed: 135 additions & 99 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

wezterm-gui/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ wezterm-open-url = { path = "../wezterm-open-url" }
105105
wezterm-ssh = { path = "../wezterm-ssh" }
106106
wezterm-term = { path = "../term", features=["use_serde"] }
107107
wezterm-toast-notification = { path = "../wezterm-toast-notification" }
108-
wgpu = "0.18"
108+
wgpu = "22.1"
109109
window = { path = "../window" }
110110
window-funcs = { path = "../lua-api-crates/window-funcs" }
111111

wezterm-gui/src/scripting/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ pub fn register(lua: &Lua) -> anyhow::Result<()> {
8888
});
8989
let gpus: Vec<GpuInfo> = instance
9090
.enumerate_adapters(backends)
91+
.into_iter()
9192
.map(|adapter| {
9293
let info = adapter.get_info();
9394
crate::termwindow::webgpu::adapter_info_to_gpu_info(info)

wezterm-gui/src/termwindow/webgpu.rs

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ use std::sync::Arc;
66
use wgpu::util::DeviceExt;
77
use window::bitmaps::Texture2d;
88
use window::raw_window_handle::{
9-
HasRawDisplayHandle, HasRawWindowHandle, RawDisplayHandle, RawWindowHandle,
9+
DisplayHandle, HandleError, HasDisplayHandle, HasWindowHandle, RawDisplayHandle,
10+
RawWindowHandle, WindowHandle,
1011
};
1112
use window::{BitmapImage, Dimensions, Rect, Window};
1213

@@ -23,7 +24,7 @@ pub struct ShaderUniform {
2324
pub struct WebGpuState {
2425
pub adapter_info: wgpu::AdapterInfo,
2526
pub downlevel_caps: wgpu::DownlevelCapabilities,
26-
pub surface: wgpu::Surface,
27+
pub surface: wgpu::Surface<'static>,
2728
pub device: wgpu::Device,
2829
pub queue: Arc<wgpu::Queue>,
2930
pub config: RefCell<wgpu::SurfaceConfiguration>,
@@ -44,21 +45,21 @@ pub struct RawHandlePair {
4445
impl RawHandlePair {
4546
fn new(window: &Window) -> Self {
4647
Self {
47-
window: window.raw_window_handle(),
48-
display: window.raw_display_handle(),
48+
window: window.window_handle().expect("window handle").as_raw(),
49+
display: window.display_handle().expect("display handle").as_raw(),
4950
}
5051
}
5152
}
5253

53-
unsafe impl HasRawWindowHandle for RawHandlePair {
54-
fn raw_window_handle(&self) -> RawWindowHandle {
55-
self.window
54+
impl HasWindowHandle for RawHandlePair {
55+
fn window_handle(&self) -> Result<WindowHandle, HandleError> {
56+
unsafe { Ok(WindowHandle::borrow_raw(self.window)) }
5657
}
5758
}
5859

59-
unsafe impl HasRawDisplayHandle for RawHandlePair {
60-
fn raw_display_handle(&self) -> RawDisplayHandle {
61-
self.display
60+
impl HasDisplayHandle for RawHandlePair {
61+
fn display_handle(&self) -> Result<DisplayHandle, HandleError> {
62+
unsafe { Ok(DisplayHandle::borrow_raw(self.display)) }
6263
}
6364
}
6465

@@ -194,6 +195,7 @@ fn compute_compatibility_list(
194195
) -> Vec<String> {
195196
instance
196197
.enumerate_adapters(backends)
198+
.into_iter()
197199
.map(|a| {
198200
let info = adapter_info_to_gpu_info(a.get_info());
199201
let compatible = a.is_surface_supported(&surface);
@@ -226,7 +228,9 @@ impl WebGpuState {
226228
backends,
227229
..Default::default()
228230
});
229-
let surface = unsafe { instance.create_surface(&handle)? };
231+
let surface = unsafe {
232+
instance.create_surface_unsafe(wgpu::SurfaceTargetUnsafe::from_window(&handle)?)?
233+
};
230234

231235
let mut adapter: Option<wgpu::Adapter> = None;
232236

@@ -316,16 +320,17 @@ impl WebGpuState {
316320
let (device, queue) = adapter
317321
.request_device(
318322
&wgpu::DeviceDescriptor {
319-
features: wgpu::Features::empty(),
323+
required_features: wgpu::Features::empty(),
320324
// WebGL doesn't support all of wgpu's features, so if
321325
// we're building for the web we'll have to disable some.
322-
limits: if cfg!(target_arch = "wasm32") {
326+
required_limits: if cfg!(target_arch = "wasm32") {
323327
wgpu::Limits::downlevel_webgl2_defaults()
324328
} else {
325329
wgpu::Limits::downlevel_defaults()
326330
}
327331
.using_resolution(adapter.limits()),
328332
label: None,
333+
memory_hints: Default::default(),
329334
},
330335
None, // Trace path
331336
)
@@ -374,6 +379,7 @@ impl WebGpuState {
374379
wgpu::CompositeAlphaMode::Auto
375380
},
376381
view_formats,
382+
desired_maximum_frame_latency: 2,
377383
};
378384
surface.configure(&device, &config);
379385

@@ -454,6 +460,7 @@ impl WebGpuState {
454460
module: &shader,
455461
entry_point: "vs_main",
456462
buffers: &[Vertex::desc()],
463+
compilation_options: wgpu::PipelineCompilationOptions::default(),
457464
},
458465
fragment: Some(wgpu::FragmentState {
459466
module: &shader,
@@ -463,6 +470,7 @@ impl WebGpuState {
463470
blend: Some(wgpu::BlendState::ALPHA_BLENDING),
464471
write_mask: wgpu::ColorWrites::ALL,
465472
})],
473+
compilation_options: wgpu::PipelineCompilationOptions::default(),
466474
}),
467475

468476
primitive: wgpu::PrimitiveState {
@@ -481,6 +489,7 @@ impl WebGpuState {
481489
alpha_to_coverage_enabled: false,
482490
},
483491
multiview: None,
492+
cache: None,
484493
});
485494

486495
Ok(Self {
@@ -528,7 +537,7 @@ impl WebGpuState {
528537
#[cfg(windows)]
529538
RawWindowHandle::Win32(h) => {
530539
let mut rect = unsafe { std::mem::zeroed() };
531-
unsafe { winapi::um::winuser::GetClientRect(h.hwnd as _, &mut rect) };
540+
unsafe { winapi::um::winuser::GetClientRect(h.hwnd.get() as _, &mut rect) };
532541
dims.pixel_width = (rect.right - rect.left) as usize;
533542
dims.pixel_height = (rect.bottom - rect.top) as usize;
534543
}

window/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ line_drawing = "0.8"
3636
log = "0.4"
3737
metrics = "0.23"
3838
promise = { path = "../promise" }
39-
raw-window-handle = "0.5"
39+
raw-window-handle = "0.6"
4040
resize = "0.5"
4141
serde = {version="1.0", features = ["rc", "derive"]}
4242
tiny-skia = "0.11"
@@ -82,6 +82,7 @@ zbus = "4.2"
8282
zvariant = "4.0"
8383

8484
smithay-client-toolkit = {version = "0.19", default-features=false, optional=true}
85+
wayland-backend = {version="0.3.5", features=["client_system", "rwh_06"]}
8586
wayland-protocols = {version="0.32", optional=true}
8687
wayland-client = {version="0.31", optional=true}
8788
wayland-egl = {version="0.32", optional=true}

window/src/os/macos/window.rs

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,14 @@ use objc::runtime::{Class, Object, Protocol, Sel};
3939
use objc::*;
4040
use promise::Future;
4141
use raw_window_handle::{
42-
AppKitDisplayHandle, AppKitWindowHandle, HasRawDisplayHandle, HasRawWindowHandle,
43-
RawDisplayHandle, RawWindowHandle,
42+
AppKitDisplayHandle, AppKitWindowHandle, DisplayHandle, HandleError, HasDisplayHandle,
43+
HasWindowHandle, RawDisplayHandle, RawWindowHandle, WindowHandle,
4444
};
4545
use std::any::Any;
4646
use std::cell::RefCell;
4747
use std::ffi::c_void;
4848
use std::path::PathBuf;
49+
use std::ptr::NonNull;
4950
use std::rc::Rc;
5051
use std::str::FromStr;
5152
use std::time::Instant;
@@ -665,18 +666,21 @@ impl Window {
665666
}
666667
}
667668

668-
unsafe impl HasRawDisplayHandle for Window {
669-
fn raw_display_handle(&self) -> RawDisplayHandle {
670-
RawDisplayHandle::AppKit(AppKitDisplayHandle::empty())
669+
impl HasDisplayHandle for Window {
670+
fn display_handle(&self) -> Result<DisplayHandle, HandleError> {
671+
unsafe {
672+
Ok(DisplayHandle::borrow_raw(RawDisplayHandle::AppKit(
673+
AppKitDisplayHandle::new(),
674+
)))
675+
}
671676
}
672677
}
673678

674-
unsafe impl HasRawWindowHandle for Window {
675-
fn raw_window_handle(&self) -> RawWindowHandle {
676-
let mut handle = AppKitWindowHandle::empty();
677-
handle.ns_window = self.ns_window as *mut _;
678-
handle.ns_view = self.ns_view as *mut _;
679-
RawWindowHandle::AppKit(handle)
679+
impl HasWindowHandle for Window {
680+
fn window_handle(&self) -> Result<WindowHandle, HandleError> {
681+
let mut handle =
682+
AppKitWindowHandle::new(NonNull::new(self.ns_view as *mut _).expect("non-null"));
683+
unsafe { Ok(WindowHandle::borrow_raw(RawWindowHandle::AppKit(handle))) }
680684
}
681685
}
682686

@@ -869,18 +873,13 @@ impl WindowOps for Window {
869873
_config: &ConfigHandle,
870874
window_state: WindowState,
871875
) -> anyhow::Result<Option<Parameters>> {
872-
let raw = self.raw_window_handle();
873-
874876
// We implement this method primarily to provide Notch-avoidance for
875877
// systems with a notch.
876878
// We only need this for non-native full screen mode.
877879

878-
let native_full_screen = match raw {
879-
RawWindowHandle::AppKit(raw) => {
880-
let style_mask = unsafe { NSWindow::styleMask(raw.ns_window as *mut Object) };
881-
style_mask.contains(NSWindowStyleMask::NSFullScreenWindowMask)
882-
}
883-
_ => false,
880+
let native_full_screen = {
881+
let style_mask = unsafe { NSWindow::styleMask(self.ns_window) };
882+
style_mask.contains(NSWindowStyleMask::NSFullScreenWindowMask)
884883
};
885884

886885
let border_dimensions =

window/src/os/wayland/window.rs

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use std::io::Read;
66
use std::num::NonZeroU32;
77
use std::os::fd::AsRawFd;
88
use std::path::PathBuf;
9+
use std::ptr::NonNull;
910
use std::rc::Rc;
1011
use std::sync::{Arc, Mutex};
1112
use std::time::{Duration, Instant};
@@ -16,8 +17,8 @@ use async_trait::async_trait;
1617
use config::ConfigHandle;
1718
use promise::{Future, Promise};
1819
use raw_window_handle::{
19-
HasRawDisplayHandle, HasRawWindowHandle, RawDisplayHandle, RawWindowHandle,
20-
WaylandDisplayHandle, WaylandWindowHandle,
20+
DisplayHandle, HandleError, HasDisplayHandle, HasWindowHandle, RawWindowHandle,
21+
WaylandWindowHandle, WindowHandle,
2122
};
2223
use smithay_client_toolkit::compositor::{CompositorHandler, SurfaceData, SurfaceDataExt};
2324
use smithay_client_toolkit::data_device_manager::ReadPipe;
@@ -1377,33 +1378,43 @@ impl SurfaceDataExt for SurfaceUserData {
13771378
}
13781379
}
13791380

1380-
unsafe impl HasRawWindowHandle for WaylandWindowInner {
1381-
fn raw_window_handle(&self) -> RawWindowHandle {
1382-
let mut handle = WaylandWindowHandle::empty();
1383-
let surface = self.surface();
1384-
handle.surface = surface.id().as_ptr() as *mut _;
1385-
RawWindowHandle::Wayland(handle)
1381+
impl HasDisplayHandle for WaylandWindowInner {
1382+
fn display_handle(&self) -> Result<DisplayHandle, HandleError> {
1383+
let conn = WaylandConnection::get().unwrap().wayland();
1384+
let backend = conn.connection.backend();
1385+
let handle = backend.display_handle()?;
1386+
Ok(unsafe { DisplayHandle::borrow_raw(handle.as_raw()) })
1387+
}
1388+
}
1389+
1390+
impl HasWindowHandle for WaylandWindowInner {
1391+
fn window_handle(&self) -> Result<WindowHandle, HandleError> {
1392+
let handle = WaylandWindowHandle::new(
1393+
NonNull::new(self.surface().id().as_ptr() as _).expect("non-null"),
1394+
);
1395+
unsafe { Ok(WindowHandle::borrow_raw(RawWindowHandle::Wayland(handle))) }
13861396
}
13871397
}
13881398

1389-
unsafe impl HasRawDisplayHandle for WaylandWindow {
1390-
fn raw_display_handle(&self) -> RawDisplayHandle {
1391-
let mut handle = WaylandDisplayHandle::empty();
1399+
impl HasDisplayHandle for WaylandWindow {
1400+
fn display_handle(&self) -> Result<DisplayHandle, HandleError> {
13921401
let conn = WaylandConnection::get().unwrap().wayland();
1393-
handle.display = conn.connection.backend().display_ptr() as *mut _;
1394-
RawDisplayHandle::Wayland(handle)
1402+
let backend = conn.connection.backend();
1403+
let handle = backend.display_handle()?;
1404+
Ok(unsafe { DisplayHandle::borrow_raw(handle.as_raw()) })
13951405
}
13961406
}
13971407

1398-
unsafe impl HasRawWindowHandle for WaylandWindow {
1399-
fn raw_window_handle(&self) -> RawWindowHandle {
1408+
impl HasWindowHandle for WaylandWindow {
1409+
fn window_handle(&self) -> Result<WindowHandle, HandleError> {
14001410
let conn = Connection::get().expect("raw_window_handle only callable on main thread");
14011411
let handle = conn
14021412
.wayland()
14031413
.window_by_id(self.0)
14041414
.expect("window handle invalid!?");
14051415

14061416
let inner = handle.borrow();
1407-
inner.raw_window_handle()
1417+
let handle = inner.window_handle()?;
1418+
unsafe { Ok(WindowHandle::borrow_raw(handle.as_raw())) }
14081419
}
14091420
}

window/src/os/windows/window.rs

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ use config::{ConfigHandle, ImePreeditRendering, SystemBackdrop};
1313
use lazy_static::lazy_static;
1414
use promise::Future;
1515
use raw_window_handle::{
16-
HasRawDisplayHandle, HasRawWindowHandle, RawDisplayHandle, RawWindowHandle, Win32WindowHandle,
17-
WindowsDisplayHandle,
16+
DisplayHandle, HandleError, HasDisplayHandle, HasWindowHandle, RawDisplayHandle,
17+
RawWindowHandle, Win32WindowHandle, WindowHandle, WindowsDisplayHandle,
1818
};
1919
use shared_library::shared_library;
2020
use std::any::Any;
@@ -23,6 +23,7 @@ use std::collections::HashMap;
2323
use std::convert::TryInto;
2424
use std::ffi::OsString;
2525
use std::io::{self, Error as IoError};
26+
use std::num::NonZeroIsize;
2627
use std::os::windows::ffi::OsStringExt;
2728
use std::path::PathBuf;
2829
use std::ptr::{null, null_mut};
@@ -200,18 +201,22 @@ fn callback_behavior() -> glium::debug::DebugCallbackBehavior {
200201
}
201202
}
202203

203-
unsafe impl HasRawDisplayHandle for WindowInner {
204-
fn raw_display_handle(&self) -> RawDisplayHandle {
205-
RawDisplayHandle::Windows(WindowsDisplayHandle::empty())
204+
impl HasDisplayHandle for WindowInner {
205+
fn display_handle(&self) -> Result<DisplayHandle, HandleError> {
206+
unsafe {
207+
Ok(DisplayHandle::borrow_raw(RawDisplayHandle::Windows(
208+
WindowsDisplayHandle::new(),
209+
)))
210+
}
206211
}
207212
}
208213

209-
unsafe impl HasRawWindowHandle for WindowInner {
210-
fn raw_window_handle(&self) -> RawWindowHandle {
211-
let mut handle = Win32WindowHandle::empty();
212-
handle.hwnd = self.hwnd.0 as *mut _;
213-
handle.hinstance = unsafe { GetModuleHandleW(null()) } as _;
214-
RawWindowHandle::Win32(handle)
214+
impl HasWindowHandle for WindowInner {
215+
fn window_handle(&self) -> Result<WindowHandle, HandleError> {
216+
let mut handle =
217+
Win32WindowHandle::new(NonZeroIsize::new(self.hwnd.0 as _).expect("non-zero"));
218+
handle.hinstance = NonZeroIsize::new(unsafe { GetModuleHandleW(null()) } as _);
219+
unsafe { Ok(WindowHandle::borrow_raw(RawWindowHandle::Win32(handle))) }
215220
}
216221
}
217222

@@ -729,19 +734,24 @@ impl WindowInner {
729734
}
730735
}
731736

732-
unsafe impl HasRawDisplayHandle for Window {
733-
fn raw_display_handle(&self) -> RawDisplayHandle {
734-
RawDisplayHandle::Windows(WindowsDisplayHandle::empty())
737+
impl HasDisplayHandle for Window {
738+
fn display_handle(&self) -> Result<DisplayHandle, HandleError> {
739+
unsafe {
740+
Ok(DisplayHandle::borrow_raw(RawDisplayHandle::Windows(
741+
WindowsDisplayHandle::new(),
742+
)))
743+
}
735744
}
736745
}
737746

738-
unsafe impl HasRawWindowHandle for Window {
739-
fn raw_window_handle(&self) -> RawWindowHandle {
747+
impl HasWindowHandle for Window {
748+
fn window_handle(&self) -> Result<WindowHandle, HandleError> {
740749
let conn = Connection::get().expect("raw_window_handle only callable on main thread");
741750
let handle = conn.get_window(self.0).expect("window handle invalid!?");
742751

743752
let inner = handle.borrow();
744-
inner.raw_window_handle()
753+
let handle = inner.window_handle()?;
754+
unsafe { Ok(WindowHandle::borrow_raw(handle.as_raw())) }
745755
}
746756
}
747757

0 commit comments

Comments
 (0)