From f7fc94133b30a5adc5a562d8d309fcd312543f40 Mon Sep 17 00:00:00 2001 From: Eval Exec Date: Sat, 9 May 2026 16:54:13 -0400 Subject: [PATCH] Pass display handle to wgpu instance --- .../src/render_thread/bootstrap.rs | 17 +++++++++++------ .../src/render_thread/lifecycle.rs | 2 +- .../src/render_thread/multi_window.rs | 5 +---- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/neomacs-display-runtime/src/render_thread/bootstrap.rs b/neomacs-display-runtime/src/render_thread/bootstrap.rs index f4ded122f..856171d38 100644 --- a/neomacs-display-runtime/src/render_thread/bootstrap.rs +++ b/neomacs-display-runtime/src/render_thread/bootstrap.rs @@ -4,7 +4,7 @@ use super::{ use crate::thread_comm::{InputEvent, RenderComms}; use neomacs_renderer_wgpu::{WgpuGlyphAtlas, WgpuRenderer}; use std::sync::Arc; -use winit::event_loop::{ControlFlow, EventLoop}; +use winit::event_loop::{ActiveEventLoop, ControlFlow, EventLoop}; #[cfg(target_os = "linux")] use winit::platform::wayland::EventLoopBuilderExtWayland; #[cfg(target_os = "linux")] @@ -18,13 +18,10 @@ use crate::backend::wpe::sys::platform as plat; impl RenderApp { /// Initialize wgpu with the window - pub(super) fn init_wgpu(&mut self, window: Arc) { + pub(super) fn init_wgpu(&mut self, event_loop: &ActiveEventLoop, window: Arc) { tracing::info!("Initializing wgpu for render thread"); - // Create wgpu instance - let mut instance_descriptor = wgpu::InstanceDescriptor::new_without_display_handle(); - instance_descriptor.backends = wgpu::Backends::all(); - let instance = wgpu::Instance::new(instance_descriptor); + let instance = create_wgpu_instance(event_loop); // Create surface from window let surface = match instance.create_surface(window.clone()) { @@ -217,6 +214,14 @@ impl RenderApp { } } +pub(super) fn create_wgpu_instance(event_loop: &ActiveEventLoop) -> wgpu::Instance { + let display_handle = event_loop.owned_display_handle(); + let mut instance_descriptor = + wgpu::InstanceDescriptor::new_with_display_handle_from_env(Box::new(display_handle)); + instance_descriptor.backends = wgpu::Backends::all().with_env(); + wgpu::Instance::new(instance_descriptor) +} + fn build_render_event_loop_impl( allow_any_thread: bool, ) -> Result, String> { diff --git a/neomacs-display-runtime/src/render_thread/lifecycle.rs b/neomacs-display-runtime/src/render_thread/lifecycle.rs index d6f0705fb..35671250e 100644 --- a/neomacs-display-runtime/src/render_thread/lifecycle.rs +++ b/neomacs-display-runtime/src/render_thread/lifecycle.rs @@ -125,7 +125,7 @@ impl RenderApp { ); // Initialize wgpu with the window - self.init_wgpu(window.clone()); + self.init_wgpu(event_loop, window.clone()); // Enable IME input for CJK and compose support window.set_ime_allowed(true); diff --git a/neomacs-display-runtime/src/render_thread/multi_window.rs b/neomacs-display-runtime/src/render_thread/multi_window.rs index 883202828..55a5e7bf3 100644 --- a/neomacs-display-runtime/src/render_thread/multi_window.rs +++ b/neomacs-display-runtime/src/render_thread/multi_window.rs @@ -144,10 +144,7 @@ impl MultiWindowManager { let phys = window.inner_size(); // Create surface for this window - let mut instance_descriptor = - wgpu::InstanceDescriptor::new_without_display_handle(); - instance_descriptor.backends = wgpu::Backends::all(); - let instance = wgpu::Instance::new(instance_descriptor); + let instance = super::bootstrap::create_wgpu_instance(event_loop); let surface = match instance.create_surface(window.clone()) { Ok(s) => s, Err(e) => {