From e07a35d4e3f571c0e6e8e29264825cd18d47c057 Mon Sep 17 00:00:00 2001 From: Coraline Sherratt Date: Fri, 27 Jul 2018 20:06:16 -0400 Subject: [PATCH] Check for EXT_debug_marker --- webrender/src/device/query_gl.rs | 43 +++++++++++++++++++++----------- webrender/src/renderer.rs | 3 ++- 2 files changed, 30 insertions(+), 16 deletions(-) diff --git a/webrender/src/device/query_gl.rs b/webrender/src/device/query_gl.rs index 97068146ed..4064363ad6 100644 --- a/webrender/src/device/query_gl.rs +++ b/webrender/src/device/query_gl.rs @@ -71,16 +71,18 @@ pub struct GpuFrameProfile { samplers: QuerySet>, frame_id: FrameId, inside_frame: bool, + ext_debug_marker: bool } impl GpuFrameProfile { - fn new(gl: Rc) -> Self { + fn new(gl: Rc, ext_debug_marker: bool) -> Self { GpuFrameProfile { gl, timers: QuerySet::new(), samplers: QuerySet::new(), frame_id: FrameId::new(0), inside_frame: false, + ext_debug_marker } } @@ -140,7 +142,7 @@ impl GpuFrameProfile { fn start_timer(&mut self, tag: T) -> GpuTimeQuery { self.finish_timer(); - let marker = GpuMarker::new(&self.gl, tag.get_label()); + let marker = GpuMarker::new(&self.gl, tag.get_label(), self.ext_debug_marker); if let Some(query) = self.timers.add(GpuTimer { tag, time_ns: 0 }) { self.gl.begin_query(gl::TIME_ELAPSED, query); @@ -187,19 +189,21 @@ pub struct GpuProfiler { gl: Rc, frames: Vec>, next_frame: usize, + ext_debug_marker: bool } impl GpuProfiler { - pub fn new(gl: Rc) -> Self { + pub fn new(gl: Rc, ext_debug_marker: bool) -> Self { const MAX_PROFILE_FRAMES: usize = 4; let frames = (0 .. MAX_PROFILE_FRAMES) - .map(|_| GpuFrameProfile::new(Rc::clone(&gl))) + .map(|_| GpuFrameProfile::new(Rc::clone(&gl), ext_debug_marker)) .collect(); GpuProfiler { gl, next_frame: 0, frames, + ext_debug_marker } } @@ -263,33 +267,42 @@ impl GpuProfiler { } pub fn start_marker(&mut self, label: &str) -> GpuMarker { - GpuMarker::new(&self.gl, label) + GpuMarker::new(&self.gl, label, self.ext_debug_marker) } pub fn place_marker(&mut self, label: &str) { - GpuMarker::fire(&self.gl, label) + GpuMarker::fire(&self.gl, label, self.ext_debug_marker) } } #[must_use] pub struct GpuMarker { - gl: Rc, + gl: Option> } impl GpuMarker { - fn new(gl: &Rc, message: &str) -> Self { - gl.push_group_marker_ext(message); - GpuMarker { gl: Rc::clone(gl) } - } - - fn fire(gl: &Rc, message: &str) { - gl.insert_event_marker_ext(message); + fn new(gl: &Rc, message: &str, ext_debug_marker: bool) -> Self { + let gl = if ext_debug_marker { + gl.push_group_marker_ext(message); + Some(Rc::clone(gl)) + } else { + None + }; + GpuMarker { gl } + } + + fn fire(gl: &Rc, message: &str, ext_debug_marker: bool) { + if ext_debug_marker { + gl.insert_event_marker_ext(message); + } } } impl Drop for GpuMarker { fn drop(&mut self) { - self.gl.pop_group_marker_ext(); + if let Some(ref gl) = self.gl { + gl.pop_group_marker_ext(); + } } } diff --git a/webrender/src/renderer.rs b/webrender/src/renderer.rs index f5969f6cf9..72e16648f4 100644 --- a/webrender/src/renderer.rs +++ b/webrender/src/renderer.rs @@ -1767,7 +1767,8 @@ impl Renderer { } })?; - let gpu_profile = GpuProfiler::new(Rc::clone(device.rc_gl())); + let ext_debug_marker = device.supports_extension("GL_EXT_debug_marker"); + let gpu_profile = GpuProfiler::new(Rc::clone(device.rc_gl()), ext_debug_marker); #[cfg(feature = "capture")] let read_fbo = device.create_fbo_for_external_texture(0);