From 82055a726bc101a6905db191345b1a17270ef55f Mon Sep 17 00:00:00 2001 From: Kartikaya Gupta Date: Mon, 6 May 2019 12:16:15 +0000 Subject: [PATCH] Bug 1547833 - Check for the KHR_debug extension before trying to use it. r=gw,kvark Differential Revision: https://phabricator.services.mozilla.com/D29824 --HG-- extra : moz-landing-system : lando --- gfx/wr/webrender/src/device/gl.rs | 35 +++++++++++++++++++++---------- gfx/wr/webrender/src/renderer.rs | 2 +- 2 files changed, 25 insertions(+), 12 deletions(-) diff --git a/gfx/wr/webrender/src/device/gl.rs b/gfx/wr/webrender/src/device/gl.rs index 91558cfc2975..49fedcbdb05f 100644 --- a/gfx/wr/webrender/src/device/gl.rs +++ b/gfx/wr/webrender/src/device/gl.rs @@ -903,6 +903,9 @@ pub struct Capabilities { /// is available on some mobile GPUs. This allows fast access to /// the per-pixel tile memory. pub supports_pixel_local_storage: bool, + /// Whether KHR_debug is supported for getting debug messages from + /// the driver. + pub supports_khr_debug: bool, } #[derive(Clone, Debug)] @@ -1134,16 +1137,6 @@ impl Device { cached_programs: Option>, allow_pixel_local_storage_support: bool, ) -> Device { - // On debug builds, assert that each GL call is error-free. We don't do - // this on release builds because the synchronous call can stall the - // pipeline. - if cfg!(debug_assertions) { - gl = gl::ErrorReactingGl::wrap(gl, |gl, name, code| { - Self::echo_driver_messages(gl); - panic!("Caught GL error {:x} at {}", code, name); - }); - } - let mut max_texture_size = [0]; let mut max_texture_layers = [0]; unsafe { @@ -1165,6 +1158,19 @@ impl Device { extensions.push(gl.get_string_i(gl::EXTENSIONS, i)); } + // On debug builds, assert that each GL call is error-free. We don't do + // this on release builds because the synchronous call can stall the + // pipeline. + let supports_khr_debug = supports_extension(&extensions, "GL_KHR_debug"); + if cfg!(debug_assertions) { + gl = gl::ErrorReactingGl::wrap(gl, move |gl, name, code| { + if supports_khr_debug { + Self::log_driver_messages(gl); + } + panic!("Caught GL error {:x} at {}", code, name); + }); + } + // Our common-case image data in Firefox is BGRA, so we make an effort // to use BGRA as the internal texture storage format to avoid the need // to swizzle during upload. Currently we only do this on GLES (and thus @@ -1285,6 +1291,7 @@ impl Device { supports_copy_image_sub_data, supports_blit_to_texture_array, supports_pixel_local_storage, + supports_khr_debug, }, bgra_format_internal, @@ -3093,7 +3100,13 @@ impl Device { } } - pub fn echo_driver_messages(gl: &gl::Gl) { + pub fn echo_driver_messages(&self) { + if self.capabilities.supports_khr_debug { + Device::log_driver_messages(self.gl()); + } + } + + fn log_driver_messages(gl: &gl::Gl) { for msg in gl.get_debug_messages() { let level = match msg.severity { gl::DEBUG_SEVERITY_HIGH => Level::Error, diff --git a/gfx/wr/webrender/src/renderer.rs b/gfx/wr/webrender/src/renderer.rs index 4d4d15025489..2424d023c4ee 100644 --- a/gfx/wr/webrender/src/renderer.rs +++ b/gfx/wr/webrender/src/renderer.rs @@ -3168,7 +3168,7 @@ impl Renderer { } if self.debug_flags.contains(DebugFlags::ECHO_DRIVER_MESSAGES) { - Device::echo_driver_messages(self.device.gl()); + self.device.echo_driver_messages(); } results.stats.texture_upload_kb = self.profile_counters.texture_data_uploaded.get();