Use display-bound wgpu instance#119
Conversation
Create the GUI render instance from winit's display handle. This gives GLES presentation the Wayland display connection wgpu expects. Keep that instance in the render GPU context. Reuse it for secondary window surfaces. Use env-aware descriptors so WGPU_BACKEND is honored. Constraint: Scope to wgpu ownership and adapter selection Rejected: Replace renderer backend | too broad for this fix Confidence: medium Scope-risk: moderate Not-tested: Haswell HD 4600 under niri/Wayland
There was a problem hiding this comment.
Code Review
This pull request refactors the wgpu initialization and state management in the display runtime. It consolidates several wgpu-related fields (instance, adapter, device, and queue) into a unified RenderGpuContext struct, and updates the initialization paths to use display-bound descriptors from the environment (which is particularly important for GLES presentation on Wayland). The feedback highlights two opportunities to avoid unnecessary cloning of wgpu resources: first, by passing a reference to the device during window resize events, and second, by moving the device and queue directly into the RenderGpuContext during bootstrap.
| } else if let Some(device) = self.gpu.as_ref().map(|gpu| gpu.device.clone()) { | ||
| if let Some(ws) = self.multi_windows.get_mut(emacs_fid) { | ||
| ws.handle_resize(&device, size.width, size.height); |
There was a problem hiding this comment.
We can avoid cloning the Arc<wgpu::Device> here by matching on &self.gpu and passing a reference to gpu.device directly, since ws.handle_resize only requires a reference &wgpu::Device.
| } else if let Some(device) = self.gpu.as_ref().map(|gpu| gpu.device.clone()) { | |
| if let Some(ws) = self.multi_windows.get_mut(emacs_fid) { | |
| ws.handle_resize(&device, size.width, size.height); | |
| } else if let Some(gpu) = &self.gpu { | |
| if let Some(ws) = self.multi_windows.get_mut(emacs_fid) { | |
| ws.handle_resize(&gpu.device, size.width, size.height); |
| self.gpu = Some(RenderGpuContext { | ||
| instance, | ||
| adapter, | ||
| device: device.clone(), | ||
| queue: queue.clone(), | ||
| }); |
There was a problem hiding this comment.
Since device and queue are not used after this point in init_wgpu, we can move them directly into RenderGpuContext instead of cloning them.
| self.gpu = Some(RenderGpuContext { | |
| instance, | |
| adapter, | |
| device: device.clone(), | |
| queue: queue.clone(), | |
| }); | |
| self.gpu = Some(RenderGpuContext { | |
| instance, | |
| adapter, | |
| device, | |
| queue, | |
| }); |
|
thanks,it work. |
|
can neomacs -Q work? Can window show? Can cursor animate? @CarefreeLee |
yes,all it can work,but have some bug repo i put it in Failed to find suitable GPU adapter: NotFound { active_backends: Backends(VULKAN | GL), requested_backends: Backends(NOOP | VULKAN | GL | METAL | DX12 | BROWSER_WEBGPU), supported_backends: Backends(VULKAN | GL), no_fallback_backends: |
Summary
Why
CarefreeLee's logs in #109 show wgpu GLES initializing with no known windowing system and falling back to surfaceless EGL, then rejecting the GL adapter as incompatible with the Wayland surface. wgpu 29 documents that GLES presentation needs the display handle, especially on Wayland.
Verification
Not Verified
Fixes #109