Skip to content

Pass display handle to wgpu instance#108

Draft
eval-exec wants to merge 1 commit into
mainfrom
fix/wgpu-display-handle
Draft

Pass display handle to wgpu instance#108
eval-exec wants to merge 1 commit into
mainfrom
fix/wgpu-display-handle

Conversation

@eval-exec
Copy link
Copy Markdown
Owner

Summary

Pass winit's owned display handle into wgpu instance creation for GUI surfaces.

This changes both the primary render window and secondary GUI windows to create wgpu instances through a shared helper that uses InstanceDescriptor::new_with_display_handle_from_env(...). The helper keeps the default all-backends behavior while allowing WGPU_BACKEND to influence backend selection for diagnostics such as WGPU_BACKEND=gl.

Why

Issue #107 showed a Wayland/Haswell setup where Vulkan was rejected and GL was detected but reported as incompatible with the window surface. wgpu documents that GLES presentation, especially on Wayland, needs the platform display handle on the instance. The previous path used new_without_display_handle() everywhere.

Validation

  • cargo fmt --check
  • cargo check -p neomacs-display-runtime
  • pre-push hook: cargo fmt --all --check
  • pre-push hook: cargo check

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors the creation of wgpu::Instance by introducing a centralized create_wgpu_instance helper that leverages the ActiveEventLoop display handle. While this improves consistency across the codebase, a performance concern was identified in multi_window.rs where the instance is recreated for every window in a loop; it is recommended to create the instance once and reuse it to avoid the overhead of enumerating graphics backends.

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);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Creating a new wgpu::Instance inside the loop for every pending window creation is inefficient. wgpu::Instance::new is a relatively expensive operation as it enumerates system graphics backends. Since all windows in this event loop share the same display handle, it is better to create the instance once outside the loop and reuse it for all surface creations in the current batch.

@eval-exec eval-exec force-pushed the main branch 2 times, most recently from 50e93ec to 632bafb Compare May 16, 2026 21:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant