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

wgpu -> 0.20 #5814

Closed
wants to merge 1 commit into from
Closed
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
234 changes: 135 additions & 99 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion wezterm-gui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ wezterm-open-url = { path = "../wezterm-open-url" }
wezterm-ssh = { path = "../wezterm-ssh" }
wezterm-term = { path = "../term", features=["use_serde"] }
wezterm-toast-notification = { path = "../wezterm-toast-notification" }
wgpu = "0.18"
wgpu = "22.1"
window = { path = "../window" }
window-funcs = { path = "../lua-api-crates/window-funcs" }

Expand Down
1 change: 1 addition & 0 deletions wezterm-gui/src/scripting/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ pub fn register(lua: &Lua) -> anyhow::Result<()> {
});
let gpus: Vec<GpuInfo> = instance
.enumerate_adapters(backends)
.into_iter()
.map(|adapter| {
let info = adapter.get_info();
crate::termwindow::webgpu::adapter_info_to_gpu_info(info)
Expand Down
37 changes: 23 additions & 14 deletions wezterm-gui/src/termwindow/webgpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ use std::sync::Arc;
use wgpu::util::DeviceExt;
use window::bitmaps::Texture2d;
use window::raw_window_handle::{
HasRawDisplayHandle, HasRawWindowHandle, RawDisplayHandle, RawWindowHandle,
DisplayHandle, HandleError, HasDisplayHandle, HasWindowHandle, RawDisplayHandle,
RawWindowHandle, WindowHandle,
};
use window::{BitmapImage, Dimensions, Rect, Window};

Expand All @@ -23,7 +24,7 @@ pub struct ShaderUniform {
pub struct WebGpuState {
pub adapter_info: wgpu::AdapterInfo,
pub downlevel_caps: wgpu::DownlevelCapabilities,
pub surface: wgpu::Surface,
pub surface: wgpu::Surface<'static>,
pub device: wgpu::Device,
pub queue: Arc<wgpu::Queue>,
pub config: RefCell<wgpu::SurfaceConfiguration>,
Expand All @@ -44,21 +45,21 @@ pub struct RawHandlePair {
impl RawHandlePair {
fn new(window: &Window) -> Self {
Self {
window: window.raw_window_handle(),
display: window.raw_display_handle(),
window: window.window_handle().expect("window handle").as_raw(),
display: window.display_handle().expect("display handle").as_raw(),
}
}
}

unsafe impl HasRawWindowHandle for RawHandlePair {
fn raw_window_handle(&self) -> RawWindowHandle {
self.window
impl HasWindowHandle for RawHandlePair {
fn window_handle(&self) -> Result<WindowHandle, HandleError> {
unsafe { Ok(WindowHandle::borrow_raw(self.window)) }
}
}

unsafe impl HasRawDisplayHandle for RawHandlePair {
fn raw_display_handle(&self) -> RawDisplayHandle {
self.display
impl HasDisplayHandle for RawHandlePair {
fn display_handle(&self) -> Result<DisplayHandle, HandleError> {
unsafe { Ok(DisplayHandle::borrow_raw(self.display)) }
}
}

Expand Down Expand Up @@ -194,6 +195,7 @@ fn compute_compatibility_list(
) -> Vec<String> {
instance
.enumerate_adapters(backends)
.into_iter()
.map(|a| {
let info = adapter_info_to_gpu_info(a.get_info());
let compatible = a.is_surface_supported(&surface);
Expand Down Expand Up @@ -226,7 +228,9 @@ impl WebGpuState {
backends,
..Default::default()
});
let surface = unsafe { instance.create_surface(&handle)? };
let surface = unsafe {
instance.create_surface_unsafe(wgpu::SurfaceTargetUnsafe::from_window(&handle)?)?
};

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

Expand Down Expand Up @@ -316,16 +320,17 @@ impl WebGpuState {
let (device, queue) = adapter
.request_device(
&wgpu::DeviceDescriptor {
features: wgpu::Features::empty(),
required_features: wgpu::Features::empty(),
// WebGL doesn't support all of wgpu's features, so if
// we're building for the web we'll have to disable some.
limits: if cfg!(target_arch = "wasm32") {
required_limits: if cfg!(target_arch = "wasm32") {
wgpu::Limits::downlevel_webgl2_defaults()
} else {
wgpu::Limits::downlevel_defaults()
}
.using_resolution(adapter.limits()),
label: None,
memory_hints: Default::default(),
},
None, // Trace path
)
Expand Down Expand Up @@ -374,6 +379,7 @@ impl WebGpuState {
wgpu::CompositeAlphaMode::Auto
},
view_formats,
desired_maximum_frame_latency: 2,
};
surface.configure(&device, &config);

Expand Down Expand Up @@ -454,6 +460,7 @@ impl WebGpuState {
module: &shader,
entry_point: "vs_main",
buffers: &[Vertex::desc()],
compilation_options: wgpu::PipelineCompilationOptions::default(),
},
fragment: Some(wgpu::FragmentState {
module: &shader,
Expand All @@ -463,6 +470,7 @@ impl WebGpuState {
blend: Some(wgpu::BlendState::ALPHA_BLENDING),
write_mask: wgpu::ColorWrites::ALL,
})],
compilation_options: wgpu::PipelineCompilationOptions::default(),
}),

primitive: wgpu::PrimitiveState {
Expand All @@ -481,6 +489,7 @@ impl WebGpuState {
alpha_to_coverage_enabled: false,
},
multiview: None,
cache: None,
});

Ok(Self {
Expand Down Expand Up @@ -528,7 +537,7 @@ impl WebGpuState {
#[cfg(windows)]
RawWindowHandle::Win32(h) => {
let mut rect = unsafe { std::mem::zeroed() };
unsafe { winapi::um::winuser::GetClientRect(h.hwnd as _, &mut rect) };
unsafe { winapi::um::winuser::GetClientRect(h.hwnd.get() as _, &mut rect) };
dims.pixel_width = (rect.right - rect.left) as usize;
dims.pixel_height = (rect.bottom - rect.top) as usize;
}
Expand Down
3 changes: 2 additions & 1 deletion window/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ line_drawing = "0.8"
log = "0.4"
metrics = "0.23"
promise = { path = "../promise" }
raw-window-handle = "0.5"
raw-window-handle = "0.6"
resize = "0.5"
serde = {version="1.0", features = ["rc", "derive"]}
tiny-skia = "0.11"
Expand Down Expand Up @@ -82,6 +82,7 @@ zbus = "4.2"
zvariant = "4.0"

smithay-client-toolkit = {version = "0.19", default-features=false, optional=true}
wayland-backend = {version="0.3.5", features=["client_system", "rwh_06"]}
wayland-protocols = {version="0.32", optional=true}
wayland-client = {version="0.31", optional=true}
wayland-egl = {version="0.32", optional=true}
Expand Down
37 changes: 18 additions & 19 deletions window/src/os/macos/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,14 @@ use objc::runtime::{Class, Object, Protocol, Sel};
use objc::*;
use promise::Future;
use raw_window_handle::{
AppKitDisplayHandle, AppKitWindowHandle, HasRawDisplayHandle, HasRawWindowHandle,
RawDisplayHandle, RawWindowHandle,
AppKitDisplayHandle, AppKitWindowHandle, DisplayHandle, HandleError, HasDisplayHandle,
HasWindowHandle, RawDisplayHandle, RawWindowHandle, WindowHandle,
};
use std::any::Any;
use std::cell::RefCell;
use std::ffi::c_void;
use std::path::PathBuf;
use std::ptr::NonNull;
use std::rc::Rc;
use std::str::FromStr;
use std::time::Instant;
Expand Down Expand Up @@ -661,18 +662,21 @@ impl Window {
}
}

unsafe impl HasRawDisplayHandle for Window {
fn raw_display_handle(&self) -> RawDisplayHandle {
RawDisplayHandle::AppKit(AppKitDisplayHandle::empty())
impl HasDisplayHandle for Window {
fn display_handle(&self) -> Result<DisplayHandle, HandleError> {
unsafe {
Ok(DisplayHandle::borrow_raw(RawDisplayHandle::AppKit(
AppKitDisplayHandle::new(),
)))
}
}
}

unsafe impl HasRawWindowHandle for Window {
fn raw_window_handle(&self) -> RawWindowHandle {
let mut handle = AppKitWindowHandle::empty();
handle.ns_window = self.ns_window as *mut _;
handle.ns_view = self.ns_view as *mut _;
RawWindowHandle::AppKit(handle)
impl HasWindowHandle for Window {
fn window_handle(&self) -> Result<WindowHandle, HandleError> {
let mut handle =
AppKitWindowHandle::new(NonNull::new(self.ns_view as *mut _).expect("non-null"));
unsafe { Ok(WindowHandle::borrow_raw(RawWindowHandle::AppKit(handle))) }
}
}

Expand Down Expand Up @@ -865,18 +869,13 @@ impl WindowOps for Window {
_config: &ConfigHandle,
window_state: WindowState,
) -> anyhow::Result<Option<Parameters>> {
let raw = self.raw_window_handle();

// We implement this method primarily to provide Notch-avoidance for
// systems with a notch.
// We only need this for non-native full screen mode.

let native_full_screen = match raw {
RawWindowHandle::AppKit(raw) => {
let style_mask = unsafe { NSWindow::styleMask(raw.ns_window as *mut Object) };
style_mask.contains(NSWindowStyleMask::NSFullScreenWindowMask)
}
_ => false,
let native_full_screen = {
let style_mask = unsafe { NSWindow::styleMask(self.ns_window) };
style_mask.contains(NSWindowStyleMask::NSFullScreenWindowMask)
};

let border_dimensions =
Expand Down
43 changes: 27 additions & 16 deletions window/src/os/wayland/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use std::io::Read;
use std::num::NonZeroU32;
use std::os::fd::AsRawFd;
use std::path::PathBuf;
use std::ptr::NonNull;
use std::rc::Rc;
use std::sync::{Arc, Mutex};
use std::time::{Duration, Instant};
Expand All @@ -16,8 +17,8 @@ use async_trait::async_trait;
use config::ConfigHandle;
use promise::{Future, Promise};
use raw_window_handle::{
HasRawDisplayHandle, HasRawWindowHandle, RawDisplayHandle, RawWindowHandle,
WaylandDisplayHandle, WaylandWindowHandle,
DisplayHandle, HandleError, HasDisplayHandle, HasWindowHandle, RawWindowHandle,
WaylandWindowHandle, WindowHandle,
};
use smithay_client_toolkit::compositor::{CompositorHandler, SurfaceData, SurfaceDataExt};
use smithay_client_toolkit::data_device_manager::ReadPipe;
Expand Down Expand Up @@ -1377,33 +1378,43 @@ impl SurfaceDataExt for SurfaceUserData {
}
}

unsafe impl HasRawWindowHandle for WaylandWindowInner {
fn raw_window_handle(&self) -> RawWindowHandle {
let mut handle = WaylandWindowHandle::empty();
let surface = self.surface();
handle.surface = surface.id().as_ptr() as *mut _;
RawWindowHandle::Wayland(handle)
impl HasDisplayHandle for WaylandWindowInner {
fn display_handle(&self) -> Result<DisplayHandle, HandleError> {
let conn = WaylandConnection::get().unwrap().wayland();
let backend = conn.connection.backend();
let handle = backend.display_handle()?;
Ok(unsafe { DisplayHandle::borrow_raw(handle.as_raw()) })
}
}

impl HasWindowHandle for WaylandWindowInner {
fn window_handle(&self) -> Result<WindowHandle, HandleError> {
let handle = WaylandWindowHandle::new(
NonNull::new(self.surface().id().as_ptr() as _).expect("non-null"),
);
unsafe { Ok(WindowHandle::borrow_raw(RawWindowHandle::Wayland(handle))) }
}
}

unsafe impl HasRawDisplayHandle for WaylandWindow {
fn raw_display_handle(&self) -> RawDisplayHandle {
let mut handle = WaylandDisplayHandle::empty();
impl HasDisplayHandle for WaylandWindow {
fn display_handle(&self) -> Result<DisplayHandle, HandleError> {
let conn = WaylandConnection::get().unwrap().wayland();
handle.display = conn.connection.backend().display_ptr() as *mut _;
RawDisplayHandle::Wayland(handle)
let backend = conn.connection.backend();
let handle = backend.display_handle()?;
Ok(unsafe { DisplayHandle::borrow_raw(handle.as_raw()) })
}
}

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

let inner = handle.borrow();
inner.raw_window_handle()
let handle = inner.window_handle()?;
unsafe { Ok(WindowHandle::borrow_raw(handle.as_raw())) }
}
}
44 changes: 27 additions & 17 deletions window/src/os/windows/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ use config::{ConfigHandle, ImePreeditRendering, SystemBackdrop};
use lazy_static::lazy_static;
use promise::Future;
use raw_window_handle::{
HasRawDisplayHandle, HasRawWindowHandle, RawDisplayHandle, RawWindowHandle, Win32WindowHandle,
WindowsDisplayHandle,
DisplayHandle, HandleError, HasDisplayHandle, HasWindowHandle, RawDisplayHandle,
RawWindowHandle, Win32WindowHandle, WindowHandle, WindowsDisplayHandle,
};
use shared_library::shared_library;
use std::any::Any;
Expand All @@ -23,6 +23,7 @@ use std::collections::HashMap;
use std::convert::TryInto;
use std::ffi::OsString;
use std::io::{self, Error as IoError};
use std::num::NonZeroIsize;
use std::os::windows::ffi::OsStringExt;
use std::path::PathBuf;
use std::ptr::{null, null_mut};
Expand Down Expand Up @@ -200,18 +201,22 @@ fn callback_behavior() -> glium::debug::DebugCallbackBehavior {
}
}

unsafe impl HasRawDisplayHandle for WindowInner {
fn raw_display_handle(&self) -> RawDisplayHandle {
RawDisplayHandle::Windows(WindowsDisplayHandle::empty())
impl HasDisplayHandle for WindowInner {
fn display_handle(&self) -> Result<DisplayHandle, HandleError> {
unsafe {
Ok(DisplayHandle::borrow_raw(RawDisplayHandle::Windows(
WindowsDisplayHandle::new(),
)))
}
}
}

unsafe impl HasRawWindowHandle for WindowInner {
fn raw_window_handle(&self) -> RawWindowHandle {
let mut handle = Win32WindowHandle::empty();
handle.hwnd = self.hwnd.0 as *mut _;
handle.hinstance = unsafe { GetModuleHandleW(null()) } as _;
RawWindowHandle::Win32(handle)
impl HasWindowHandle for WindowInner {
fn window_handle(&self) -> Result<WindowHandle, HandleError> {
let mut handle =
Win32WindowHandle::new(NonZeroIsize::new(self.hwnd.0 as _).expect("non-zero"));
handle.hinstance = NonZeroIsize::new(unsafe { GetModuleHandleW(null()) } as _);
unsafe { Ok(WindowHandle::borrow_raw(RawWindowHandle::Win32(handle))) }
}
}

Expand Down Expand Up @@ -729,19 +734,24 @@ impl WindowInner {
}
}

unsafe impl HasRawDisplayHandle for Window {
fn raw_display_handle(&self) -> RawDisplayHandle {
RawDisplayHandle::Windows(WindowsDisplayHandle::empty())
impl HasDisplayHandle for Window {
fn display_handle(&self) -> Result<DisplayHandle, HandleError> {
unsafe {
Ok(DisplayHandle::borrow_raw(RawDisplayHandle::Windows(
WindowsDisplayHandle::new(),
)))
}
}
}

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

let inner = handle.borrow();
inner.raw_window_handle()
let handle = inner.window_handle()?;
unsafe { Ok(WindowHandle::borrow_raw(handle.as_raw())) }
}
}

Expand Down
Loading
Loading