Pass display handle to wgpu instance#108
Conversation
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.
50e93ec to
632bafb
Compare
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 allowingWGPU_BACKENDto influence backend selection for diagnostics such asWGPU_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 --checkcargo check -p neomacs-display-runtimecargo fmt --all --checkcargo check