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
This commit is contained in:
Andrew Osmond 2019-04-02 10:43:13 -04:00
Родитель f0bb72977e
Коммит a26277d8ff
10 изменённых файлов: 122 добавлений и 41 удалений

8
Cargo.lock сгенерированный
Просмотреть файл

@ -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"

14
gfx/wr/Cargo.lock сгенерированный
Просмотреть файл

@ -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"

Просмотреть файл

@ -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"

Просмотреть файл

@ -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 {
gl.push_group_marker_ext(message);
Some(Rc::clone(gl))
} else {
None
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), 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 => {}
};
}
}
}

Просмотреть файл

@ -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();

2
third_party/rust/gleam/.cargo-checksum.json поставляемый
Просмотреть файл

@ -1 +1 @@
{"files":{"COPYING":"ec82b96487e9e778ee610c7ab245162464782cfa1f555c2299333f8dbe5c036a","Cargo.toml":"5e823cb4a829b626b7b9b603dac4d3a98debf5e83b91897ab9f186eed8f49d61","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"62065228e42caebca7e7d7db1204cbb867033de5982ca4009928915e4095f3a3","README.md":"1acb12040be43a3582d5897f11870b3ffdcd7ce0f4f32de158175bb6b33ec0b7","build.rs":"6ee689b1edfcd469dea669b0dc11ca89e0172c3b58bb82ff7a58acc94e1f7e88","rustfmt.toml":"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855","src/gl.rs":"e659b099df9c2ae39fc311aa649bbb8b96dfc7df8eba8f98b2eab34d5a368442","src/gl_fns.rs":"99693ea60d5867fea7d6f092e9fae6f2ff3d0be3c6f533257618261ccdfc6341","src/gles_fns.rs":"e28eadc5907dd963765574b21f68eb308674c7ec799b26896b86de9fee8c8eac","src/lib.rs":"16610c19b45a3f26d56b379a3591aa2e4fc9477e7bd88f86b31c6ea32e834861"},"package":"43edfa3a4321024d7dac1625cf154ef0c16996a6a384d066480e306ebd39fecc"}
{"files":{"COPYING":"ec82b96487e9e778ee610c7ab245162464782cfa1f555c2299333f8dbe5c036a","Cargo.toml":"6bf850af90d5a3828cf26170a161f2ed06fa3cf3783dce79d28fe6444654408e","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"62065228e42caebca7e7d7db1204cbb867033de5982ca4009928915e4095f3a3","README.md":"1acb12040be43a3582d5897f11870b3ffdcd7ce0f4f32de158175bb6b33ec0b7","build.rs":"6ee689b1edfcd469dea669b0dc11ca89e0172c3b58bb82ff7a58acc94e1f7e88","rustfmt.toml":"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855","src/gl.rs":"2663b598573f7521d06f878229eee65434c831cf9fd4b543b4fcdd3bb1b281aa","src/gl_fns.rs":"239ace5607ee8dd4bcad35db0c4908469d7deb4841c162f736e404e1403980f7","src/gles_fns.rs":"51f25388f092242fb25bfe4861e70690006f4ac28e854d709ebb440cbef3df03","src/lib.rs":"16610c19b45a3f26d56b379a3591aa2e4fc9477e7bd88f86b31c6ea32e834861"},"package":"39bb69499005e11b7b7cc0af38404a1bc0f53d954bffa8adcdb6e8d5b14f75d5"}

4
third_party/rust/gleam/Cargo.toml поставляемый
Просмотреть файл

@ -3,7 +3,7 @@
# When uploading crates to the registry Cargo will automatically
# "normalize" Cargo.toml files for maximal compatibility
# with all versions of Cargo and also rewrite `path` dependencies
# to registry (e.g., crates.io) dependencies
# to registry (e.g. crates.io) dependencies
#
# If you believe there's an error in this file please file an
# issue against the rust-lang/cargo repository. If you're
@ -12,7 +12,7 @@
[package]
name = "gleam"
version = "0.6.15"
version = "0.6.16"
authors = ["The Servo Project Developers"]
build = "build.rs"
description = "Generated OpenGL bindings and wrapper for Servo."

3
third_party/rust/gleam/src/gl.rs поставляемый
Просмотреть файл

@ -553,6 +553,9 @@ declare_gl_apis! {
fn insert_event_marker_ext(&self, message: &str);
fn push_group_marker_ext(&self, message: &str);
fn pop_group_marker_ext(&self);
fn debug_message_insert_khr(&self, source: GLenum, type_: GLenum, id: GLuint, severity: GLenum, message: &str);
fn push_debug_group_khr(&self, source: GLenum, id: GLuint, message: &str);
fn pop_debug_group_khr(&self);
fn fence_sync(&self, condition: GLenum, flags: GLbitfield) -> GLsync;
fn client_wait_sync(&self, sync: GLsync, flags: GLbitfield, timeout: GLuint64);
fn wait_sync(&self, sync: GLsync, flags: GLbitfield, timeout: GLuint64);

26
third_party/rust/gleam/src/gl_fns.rs поставляемый
Просмотреть файл

@ -1946,6 +1946,32 @@ impl Gl for GlFns {
}
}
fn debug_message_insert_khr(&self, source: GLenum, type_: GLenum, id: GLuint, severity: GLenum, message: &str) {
if self.ffi_gl_.DebugMessageInsertKHR.is_loaded() {
unsafe {
self.ffi_gl_
.DebugMessageInsertKHR(source, type_, id, severity, message.len() as GLsizei, message.as_ptr() as *const _);
}
}
}
fn push_debug_group_khr(&self, source: GLenum, id: GLuint, message: &str) {
if self.ffi_gl_.PushDebugGroupKHR.is_loaded() {
unsafe {
self.ffi_gl_
.PushDebugGroupKHR(source, id, message.len() as GLsizei, message.as_ptr() as *const _);
}
}
}
fn pop_debug_group_khr(&self) {
if self.ffi_gl_.PopDebugGroupKHR.is_loaded() {
unsafe {
self.ffi_gl_.PopDebugGroupKHR();
}
}
}
fn fence_sync(&self, condition: GLenum, flags: GLbitfield) -> GLsync {
unsafe { self.ffi_gl_.FenceSync(condition, flags) as *const _ }
}

26
third_party/rust/gleam/src/gles_fns.rs поставляемый
Просмотреть файл

@ -1952,6 +1952,32 @@ impl Gl for GlesFns {
}
}
fn debug_message_insert_khr(&self, source: GLenum, type_: GLenum, id: GLuint, severity: GLenum, message: &str) {
if self.ffi_gl_.DebugMessageInsertKHR.is_loaded() {
unsafe {
self.ffi_gl_
.DebugMessageInsertKHR(source, type_, id, severity, message.len() as GLsizei, message.as_ptr() as *const _);
}
}
}
fn push_debug_group_khr(&self, source: GLenum, id: GLuint, message: &str) {
if self.ffi_gl_.PushDebugGroupKHR.is_loaded() {
unsafe {
self.ffi_gl_
.PushDebugGroupKHR(source, id, message.len() as GLsizei, message.as_ptr() as *const _);
}
}
}
fn pop_debug_group_khr(&self) {
if self.ffi_gl_.PopDebugGroupKHR.is_loaded() {
unsafe {
self.ffi_gl_.PopDebugGroupKHR();
}
}
}
fn fence_sync(&self, condition: GLenum, flags: GLbitfield) -> GLsync {
unsafe { self.ffi_gl_.FenceSync(condition, flags) as *const _ }
}