Commit a26277d8 authored by Andrew Osmond's avatar Andrew Osmond
Browse files

Bug 1541059 - Add support for KHR_debug to WebRender for debug markers. r=kvark

Today we already support EXT_debug_marker for debug markers in
WebRender. This is useful to categorize GL API calls in tools such as
APITrace and RenderDoc. However not all drivers indicate support for
said extension, but instead support KHR_debug. This patch makes us
support both methods, preferring KHR_debug.

Differential Revision: https://phabricator.services.mozilla.com/D25787
parent f0bb7297
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -1284,7 +1284,7 @@ dependencies = [

[[package]]
name = "gleam"
version = "0.6.15"
version = "0.6.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
 "gl_generator 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -3315,7 +3315,7 @@ dependencies = [
 "dwrote 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
 "freetype 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
 "fxhash 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
 "gleam 0.6.15 (registry+https://github.com/rust-lang/crates.io-index)",
 "gleam 0.6.16 (registry+https://github.com/rust-lang/crates.io-index)",
 "lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
 "libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)",
 "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -3366,7 +3366,7 @@ dependencies = [
 "euclid 0.19.5 (registry+https://github.com/rust-lang/crates.io-index)",
 "foreign-types 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
 "fxhash 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
 "gleam 0.6.15 (registry+https://github.com/rust-lang/crates.io-index)",
 "gleam 0.6.16 (registry+https://github.com/rust-lang/crates.io-index)",
 "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
 "nsstring 0.1.0",
 "rayon 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -3624,7 +3624,7 @@ dependencies = [
"checksum generic-array 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3c0f28c2f5bfb5960175af447a2da7c18900693738343dc896ffbcabd9839592"
"checksum generic-array 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ef25c5683767570c2bbd7deba372926a55eaae9982d7726ee2a1050239d45b9d"
"checksum gl_generator 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "39a23d5e872a275135d66895d954269cf5e8661d234eb1c2480f4ce0d586acbd"
"checksum gleam 0.6.15 (registry+https://github.com/rust-lang/crates.io-index)" = "43edfa3a4321024d7dac1625cf154ef0c16996a6a384d066480e306ebd39fecc"
"checksum gleam 0.6.16 (registry+https://github.com/rust-lang/crates.io-index)" = "39bb69499005e11b7b7cc0af38404a1bc0f53d954bffa8adcdb6e8d5b14f75d5"
"checksum glob 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "8be18de09a56b60ed0edf84bc9df007e30040691af7acd1c41874faac5895bfb"
"checksum goblin 0.0.17 (registry+https://github.com/rust-lang/crates.io-index)" = "5911d7df7b8f65ab676c5327b50acea29d3c6a1a4ad05e444cf5dce321b26db2"
"checksum guid_win 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "87261686cc5e35b6584f4c2a430c2b153d8a92ab1ef820c16be34c1df8f5f58b"
+7 −7
Original line number Diff line number Diff line
@@ -143,7 +143,7 @@ name = "cgl"
version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
 "gleam 0.6.15 (registry+https://github.com/rust-lang/crates.io-index)",
 "gleam 0.6.16 (registry+https://github.com/rust-lang/crates.io-index)",
 "libc 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)",
]

@@ -370,7 +370,7 @@ name = "direct-composition"
version = "0.1.0"
dependencies = [
 "euclid 0.19.5 (registry+https://github.com/rust-lang/crates.io-index)",
 "gleam 0.6.15 (registry+https://github.com/rust-lang/crates.io-index)",
 "gleam 0.6.16 (registry+https://github.com/rust-lang/crates.io-index)",
 "mozangle 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
 "webrender 0.60.0",
 "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -569,7 +569,7 @@ dependencies = [

[[package]]
name = "gleam"
version = "0.6.15"
version = "0.6.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
 "gl_generator 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -1640,7 +1640,7 @@ dependencies = [
 "dwrote 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
 "freetype 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
 "fxhash 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
 "gleam 0.6.15 (registry+https://github.com/rust-lang/crates.io-index)",
 "gleam 0.6.16 (registry+https://github.com/rust-lang/crates.io-index)",
 "image 0.21.0 (registry+https://github.com/rust-lang/crates.io-index)",
 "lazy_static 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
 "libc 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -1676,7 +1676,7 @@ dependencies = [
 "app_units 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
 "env_logger 0.5.10 (registry+https://github.com/rust-lang/crates.io-index)",
 "euclid 0.19.5 (registry+https://github.com/rust-lang/crates.io-index)",
 "gleam 0.6.15 (registry+https://github.com/rust-lang/crates.io-index)",
 "gleam 0.6.16 (registry+https://github.com/rust-lang/crates.io-index)",
 "glutin 0.17.0 (registry+https://github.com/rust-lang/crates.io-index)",
 "rayon 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
 "webrender 0.60.0",
@@ -1793,7 +1793,7 @@ dependencies = [
 "env_logger 0.5.10 (registry+https://github.com/rust-lang/crates.io-index)",
 "euclid 0.19.5 (registry+https://github.com/rust-lang/crates.io-index)",
 "font-loader 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
 "gleam 0.6.15 (registry+https://github.com/rust-lang/crates.io-index)",
 "gleam 0.6.16 (registry+https://github.com/rust-lang/crates.io-index)",
 "glutin 0.17.0 (registry+https://github.com/rust-lang/crates.io-index)",
 "image 0.21.0 (registry+https://github.com/rust-lang/crates.io-index)",
 "lazy_static 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -1940,7 +1940,7 @@ dependencies = [
"checksum gif 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ff3414b424657317e708489d2857d9575f4403698428b040b609b9d1c1a84a2c"
"checksum gl_generator 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "39a23d5e872a275135d66895d954269cf5e8661d234eb1c2480f4ce0d586acbd"
"checksum gl_generator 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7a795170cbd85b5a7baa58d6d7525cae6a03e486859860c220f7ebbbdd379d0a"
"checksum gleam 0.6.15 (registry+https://github.com/rust-lang/crates.io-index)" = "43edfa3a4321024d7dac1625cf154ef0c16996a6a384d066480e306ebd39fecc"
"checksum gleam 0.6.16 (registry+https://github.com/rust-lang/crates.io-index)" = "39bb69499005e11b7b7cc0af38404a1bc0f53d954bffa8adcdb6e8d5b14f75d5"
"checksum glutin 0.17.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a70c5fe78efbd5a3b243a804ea1032053c584510f8822819f94cfb29b2100317"
"checksum half 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1d5c5f71a723d10dfc58927cbed37c3071a50afc7f073d86fd7d3e5727db890f"
"checksum httparse 1.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "c2f407128745b78abc95c0ffbe4e5d37427fdc0d45470710cfef8c44522a2e37"
+1 −1
Original line number Diff line number Diff line
@@ -29,7 +29,7 @@ byteorder = "1.0"
cfg-if = "0.1.2"
cstr = "0.1.2"
fxhash = "0.2.1"
gleam = "0.6.14"
gleam = "0.6.16"
image = { optional = true, version = "0.21" }
lazy_static = "1"
log = "0.4"
+40 −23
Original line number Diff line number Diff line
@@ -8,6 +8,12 @@ use std::rc::Rc;

use device::GpuFrameId;

#[derive(Copy, Clone, Debug)]
pub enum GpuDebugMethod {
    None,
    MarkerEXT,
    KHR,
}

pub trait NamedTag {
    fn get_label(&self) -> &str;
@@ -69,18 +75,18 @@ pub struct GpuFrameProfile<T> {
    samplers: QuerySet<GpuSampler<T>>,
    frame_id: GpuFrameId,
    inside_frame: bool,
    ext_debug_marker: bool
    debug_method: GpuDebugMethod,
}

impl<T> GpuFrameProfile<T> {
    fn new(gl: Rc<gl::Gl>, ext_debug_marker: bool) -> Self {
    fn new(gl: Rc<gl::Gl>, debug_method: GpuDebugMethod) -> Self {
        GpuFrameProfile {
            gl,
            timers: QuerySet::new(),
            samplers: QuerySet::new(),
            frame_id: GpuFrameId::new(0),
            inside_frame: false,
            ext_debug_marker
            debug_method
        }
    }

@@ -140,7 +146,7 @@ impl<T: NamedTag> GpuFrameProfile<T> {
    fn start_timer(&mut self, tag: T) -> GpuTimeQuery {
        self.finish_timer();

        let marker = GpuMarker::new(&self.gl, tag.get_label(), self.ext_debug_marker);
        let marker = GpuMarker::new(&self.gl, tag.get_label(), self.debug_method);

        if let Some(query) = self.timers.add(GpuTimer { tag, time_ns: 0 }) {
            self.gl.begin_query(gl::TIME_ELAPSED, query);
@@ -186,21 +192,21 @@ pub struct GpuProfiler<T> {
    gl: Rc<gl::Gl>,
    frames: Vec<GpuFrameProfile<T>>,
    next_frame: usize,
    ext_debug_marker: bool
    debug_method: GpuDebugMethod
}

impl<T> GpuProfiler<T> {
    pub fn new(gl: Rc<gl::Gl>, ext_debug_marker: bool) -> Self {
    pub fn new(gl: Rc<gl::Gl>, debug_method: GpuDebugMethod) -> Self {
        const MAX_PROFILE_FRAMES: usize = 4;
        let frames = (0 .. MAX_PROFILE_FRAMES)
            .map(|_| GpuFrameProfile::new(Rc::clone(&gl), ext_debug_marker))
            .map(|_| GpuFrameProfile::new(Rc::clone(&gl), debug_method))
            .collect();

        GpuProfiler {
            gl,
            next_frame: 0,
            frames,
            ext_debug_marker
            debug_method
        }
    }

@@ -263,41 +269,52 @@ impl<T: NamedTag> GpuProfiler<T> {
    }

    pub fn start_marker(&mut self, label: &str) -> GpuMarker {
        GpuMarker::new(&self.gl, label, self.ext_debug_marker)
        GpuMarker::new(&self.gl, label, self.debug_method)
    }

    pub fn place_marker(&mut self, label: &str) {
        GpuMarker::fire(&self.gl, label, self.ext_debug_marker)
        GpuMarker::fire(&self.gl, label, self.debug_method)
    }
}

#[must_use]
pub struct GpuMarker {
    gl: Option<Rc<gl::Gl>>
    gl: Option<(Rc<gl::Gl>, GpuDebugMethod)>,
}

impl GpuMarker {
    fn new(gl: &Rc<gl::Gl>, message: &str, ext_debug_marker: bool) -> Self {
        let gl = if ext_debug_marker {
    fn new(gl: &Rc<gl::Gl>, message: &str, debug_method: GpuDebugMethod) -> Self {
        let gl = match debug_method {
            GpuDebugMethod::KHR => {
              gl.push_debug_group_khr(gl::DEBUG_SOURCE_APPLICATION, 0, message);
              Some((Rc::clone(gl), debug_method))
            },
            GpuDebugMethod::MarkerEXT => {
              gl.push_group_marker_ext(message);
            Some(Rc::clone(gl))
        } else {
            None
              Some((Rc::clone(gl), debug_method))
            },
            GpuDebugMethod::None => None,
        };
        GpuMarker { gl }
    }

    fn fire(gl: &Rc<gl::Gl>, message: &str, ext_debug_marker: bool) {
        if ext_debug_marker {
            gl.insert_event_marker_ext(message);
        }
    fn fire(gl: &Rc<gl::Gl>, message: &str, debug_method: GpuDebugMethod) {
        match debug_method {
            GpuDebugMethod::KHR => gl.debug_message_insert_khr(gl::DEBUG_SOURCE_APPLICATION, gl::DEBUG_TYPE_MARKER, 0, gl::DEBUG_SEVERITY_NOTIFICATION, message),
            GpuDebugMethod::MarkerEXT => gl.insert_event_marker_ext(message),
            GpuDebugMethod::None => {}
        };
    }
}

impl Drop for GpuMarker {
    fn drop(&mut self) {
        if let Some(ref gl) = self.gl {
            gl.pop_group_marker_ext();
        if let Some((ref gl, debug_method)) = self.gl {
            match debug_method {
                GpuDebugMethod::KHR => gl.pop_debug_group_khr(),
                GpuDebugMethod::MarkerEXT => gl.pop_group_marker_ext(),
                GpuDebugMethod::None => {}
            };
        }
    }
}
+12 −3
Original line number Diff line number Diff line
@@ -75,7 +75,7 @@ use prim_store::DeferredResolve;
use profiler::{BackendProfileCounters, FrameProfileCounters, TimeProfileCounter,
               GpuProfileTag, RendererProfileCounters, RendererProfileTimers};
use profiler::{Profiler, ChangeIndicator};
use device::query::GpuProfiler;
use device::query::{GpuProfiler, GpuDebugMethod};
use rayon::{ThreadPool, ThreadPoolBuilder};
use record::ApiRecordingReceiver;
use render_backend::{FrameId, RenderBackend};
@@ -2339,8 +2339,17 @@ impl Renderer {
            }
        })?;

        let ext_debug_marker = device.supports_extension("GL_EXT_debug_marker");
        let gpu_profile = GpuProfiler::new(Rc::clone(device.rc_gl()), ext_debug_marker);
        let debug_support = if device.supports_extension("GL_KHR_debug") {
            GpuDebugMethod::KHR
        } else if device.supports_extension("GL_EXT_debug_marker") {
            GpuDebugMethod::MarkerEXT
        } else {
            GpuDebugMethod::None
        };

        info!("using {:?}", debug_support);

        let gpu_profile = GpuProfiler::new(Rc::clone(device.rc_gl()), debug_support);
        #[cfg(feature = "capture")]
        let read_fbo = device.create_fbo();

Loading