From 924ac5c99b807dd1ca40e8adaa26c62275133439 Mon Sep 17 00:00:00 2001 From: Oleksiy Syvokon Date: Tue, 31 Mar 2026 20:08:20 +0300 Subject: [PATCH] gpui_wgpu: Guard against device feature mismatch (#52820) This should prevent the "wgpu-hal invariant was violated (usage error): Requested feature is not available on this device" panic, although I'm not 100% sure (there's a possibility that a device reports the feature but fails to use it). At the very least, we get more logging I've tested this fix by patching code to emulate a situation where device features change after the creation, but that may be not representative of the real world failure. Addresses ZED-5G1 Release Notes: - N/A --- crates/gpui_wgpu/src/wgpu_renderer.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/crates/gpui_wgpu/src/wgpu_renderer.rs b/crates/gpui_wgpu/src/wgpu_renderer.rs index 1ee595ca943db94ac003999b79116d2b7afc1eda..c25cba935447d76f0e112079b7c81a9463109806 100644 --- a/crates/gpui_wgpu/src/wgpu_renderer.rs +++ b/crates/gpui_wgpu/src/wgpu_renderer.rs @@ -615,6 +615,28 @@ impl WgpuRenderer { path_sample_count: u32, dual_source_blending: bool, ) -> WgpuPipelines { + // Diagnostic guard: verify the device actually has + // DUAL_SOURCE_BLENDING. We have a crash report (ZED-5G1) where a + // feature mismatch caused a wgpu-hal abort, but we haven't + // identified the code path that produces the mismatch. This + // guard prevents the crash and logs more evidence. + // Remove this check once: + // a) We find and fix the root cause, or + // b) There are no reports of this warning appearing for some time. + let device_has_feature = device + .features() + .contains(wgpu::Features::DUAL_SOURCE_BLENDING); + if dual_source_blending && !device_has_feature { + log::error!( + "BUG: dual_source_blending flag is true but device does not \ + have DUAL_SOURCE_BLENDING enabled (device features: {:?}). \ + Falling back to mono text rendering. Please report this at \ + https://github.com/zed-industries/zed/issues", + device.features(), + ); + } + let dual_source_blending = dual_source_blending && device_has_feature; + let base_shader_source = include_str!("shaders.wgsl"); let shader_module = device.create_shader_module(wgpu::ShaderModuleDescriptor { label: Some("gpui_shaders"),