From 00ab6a70f57734666dc659dc8cbb9461189061d0 Mon Sep 17 00:00:00 2001 From: Zicklag Date: Wed, 14 Jul 2021 09:19:14 -0500 Subject: [PATCH] Make Intel Mesa Bug Workaround More Specific This helps make sure that we don't workaround the fastclear bug on cards that don't actually have the bug, by filtering on the renderer string. --- wgpu-hal/src/gles/egl.rs | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/wgpu-hal/src/gles/egl.rs b/wgpu-hal/src/gles/egl.rs index da04883345..942308ae5a 100644 --- a/wgpu-hal/src/gles/egl.rs +++ b/wgpu-hal/src/gles/egl.rs @@ -396,11 +396,6 @@ impl crate::Instance for Instance { None }; - // Workaround Mesa driver bug on Intel cards by disabling fastclear: - // https://gitlab.freedesktop.org/mesa/mesa/-/issues/2565 - // https://github.com/gfx-rs/wgpu/issues/1627#issuecomment-877854185 - std::env::set_var("INTEL_DEBUG", "nofc"); - let display = if let (Some(library), Some(egl)) = (wayland_library, egl.upcast::()) { @@ -601,6 +596,7 @@ impl crate::Instance for Instance { pbuffer: inner.pbuffer, wl_window, swapchain: None, + enable_intel_mesa_fastclear_workaround: None, }) } unsafe fn destroy_surface(&self, surface: Surface) { @@ -677,6 +673,9 @@ pub struct Surface { pub(super) presentable: bool, wl_window: Option<*mut raw::c_void>, swapchain: Option, + // If None, the check has not yet been done, if Some(bool) indicates whether or not we + // workaround this bug: https://gitlab.freedesktop.org/mesa/mesa/-/issues/2565 + enable_intel_mesa_fastclear_workaround: Option, } unsafe impl Send for Surface {} @@ -757,13 +756,30 @@ impl crate::Surface for Surface { ); } - let format_desc = device.shared.describe_texture_format(config.format); let gl = &device.shared.context; + + // Check renderer version to see if we need to workaround intel mesa bug + if self.enable_intel_mesa_fastclear_workaround.is_none() { + let renderer = gl.get_parameter_string(glow::RENDERER); + + // Check renderer string for buggy cards + self.enable_intel_mesa_fastclear_workaround = Some( + renderer.contains("Mesa") + && renderer.contains("Intel") + && renderer.contains("CML GT2"), + ); + } + + let format_desc = device.shared.describe_texture_format(config.format); let renderbuffer = gl.create_renderbuffer().unwrap(); gl.bind_renderbuffer(glow::RENDERBUFFER, Some(renderbuffer)); gl.renderbuffer_storage( glow::RENDERBUFFER, - format_desc.internal, + if self.enable_intel_mesa_fastclear_workaround.unwrap() { + glow::RGBA8 + } else { + format_desc.internal + }, config.extent.width as _, config.extent.height as _, );