Add profiling for WebXR

This commit is contained in:
Manish Goregaokar 2020-02-19 17:23:39 -08:00
parent 52c9cce4c4
commit f3e1aba4e3
12 changed files with 93 additions and 9 deletions

View file

@ -15,6 +15,8 @@ canvas2d-azure = ["azure"]
canvas2d-raqote = ["raqote"]
webgl_backtrace = ["canvas_traits/webgl_backtrace"]
no-wgl = ["surfman/sm-no-wgl"]
xr-profile = ["webxr-api/profile", "time"]
[dependencies]
azure = {git = "https://github.com/servo/rust-azure", optional = true}
@ -32,6 +34,7 @@ ipc-channel = "0.14"
log = "0.4"
num-traits = "0.2"
raqote = {git = "https://github.com/jrmuizel/raqote", optional = true}
time = { version = "0.1.0", optional = true }
pixels = {path = "../pixels"}
servo_config = {path = "../config"}
sparkle = "0.1.16"

View file

@ -75,6 +75,11 @@ use surfman_chains_api::SwapChainsAPI;
use webrender_traits::{WebrenderExternalImageRegistry, WebrenderImageHandlerType};
use webxr_api::SwapChainId as WebXRSwapChainId;
#[cfg(feature = "xr-profile")]
fn to_ms(ns: u64) -> f64 {
ns as f64 / 1_000_000.
}
struct GLContextData {
ctx: Context,
gl: Rc<Gl>,
@ -329,8 +334,8 @@ impl WebGLThread {
WebGLMsg::CreateWebXRSwapChain(ctx_id, size, sender) => {
let _ = sender.send(self.create_webxr_swap_chain(ctx_id, size));
},
WebGLMsg::SwapBuffers(swap_ids, sender) => {
self.handle_swap_buffers(swap_ids, sender);
WebGLMsg::SwapBuffers(swap_ids, sender, sent_time) => {
self.handle_swap_buffers(swap_ids, sender, sent_time);
},
WebGLMsg::DOMToTextureCommand(command) => {
self.handle_dom_to_texture(command);
@ -667,8 +672,16 @@ impl WebGLThread {
fn handle_swap_buffers(
&mut self,
swap_ids: Vec<SwapChainId>,
completed_sender: WebGLSender<()>,
completed_sender: WebGLSender<u64>,
_sent_time: u64,
) {
#[cfg(feature = "xr-profile")]
let start_swap = time::precise_time_ns();
#[cfg(feature = "xr-profile")]
println!(
"WEBXR PROFILING [swap request]:\t{}ms",
to_ms(start_swap - _sent_time)
);
debug!("handle_swap_buffers()");
for swap_id in swap_ids {
let context_id = swap_id.context_id();
@ -733,7 +746,17 @@ impl WebGLThread {
);
}
completed_sender.send(()).unwrap();
#[allow(unused)]
let mut end_swap = 0;
#[cfg(feature = "xr-profile")]
{
end_swap = time::precise_time_ns();
println!(
"WEBXR PROFILING [swap buffer]:\t{}ms",
to_ms(end_swap - start_swap)
);
}
completed_sender.send(end_swap).unwrap();
}
/// Creates a new WebXR swap chain