Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GPU markers support #604

Merged
merged 1 commit into from Nov 28, 2016
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

GPU markers support

  • Loading branch information
kvark committed Nov 28, 2016
commit 5a3196c172d539b1a85186e6e75a3a65507176bc

Some generated files are not rendered by default. Learn more.

@@ -20,7 +20,7 @@ bit-set = "0.4"
byteorder = "0.5"
euclid = "0.10"
fnv="1.0"
gleam = "0.2"
gleam = "0.2.25"
lazy_static = "0.2"
log = "0.3"
num-traits = "0.1.32"
@@ -3,7 +3,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

use debug_font_data;
use device::{Device, ProgramId, VAOId, TextureId, VertexFormat};
use device::{Device, GpuMarker, ProgramId, VAOId, TextureId, VertexFormat};
use device::{TextureFilter, VertexUsageHint, TextureTarget};
use euclid::{Matrix4D, Point2D, Size2D, Rect};
use internal_types::{ORTHO_NEAR_PLANE, ORTHO_FAR_PLANE, TextureSampler};
@@ -161,6 +161,7 @@ impl DebugRenderer {
pub fn render(&mut self,
device: &mut Device,
viewport_size: &DeviceUintSize) {
let _ = GpuMarker::new("debug");
device.disable_depth();
device.set_blend(true);
device.set_blend_mode_alpha();
@@ -484,6 +484,10 @@ pub struct UBOId(gl::GLuint);
const MAX_EVENTS_PER_FRAME: usize = 256;
const MAX_PROFILE_FRAMES: usize = 4;

pub trait NamedTag {
fn get_label(&self) -> &str;
}

#[derive(Debug, Clone)]
pub struct GpuSample<T> {
pub tag: T,
@@ -538,7 +542,10 @@ impl<T> GpuFrameProfile<T> {
}

#[cfg(not(target_os = "android"))]
fn add_marker(&mut self, tag: T) {
fn add_marker(&mut self, tag: T) -> GpuMarker
where T: NamedTag {
let marker = GpuMarker::new(tag.get_label());

if self.pending_query != 0 {
gl::end_query(gl::TIME_ELAPSED);
}
@@ -555,6 +562,7 @@ impl<T> GpuFrameProfile<T> {
}

self.next_query += 1;
marker
}

#[cfg(target_os = "android")]
@@ -633,9 +641,47 @@ impl<T> GpuProfiler<T> {
self.next_frame = (self.next_frame + 1) % MAX_PROFILE_FRAMES;
}

#[cfg(not(target_os = "android"))]
pub fn add_marker(&mut self, tag: T) -> GpuMarker
where T: NamedTag {
self.frames[self.next_frame].add_marker(tag)
}

#[cfg(target_os = "android")]
pub fn add_marker(&mut self, tag: T) {
let frame = &mut self.frames[self.next_frame];
frame.add_marker(tag);
self.frames[self.next_frame].add_marker(tag)
}
}

#[must_use]
pub struct GpuMarker(());

#[cfg(any(target_arch="arm", target_arch="aarch64"))]
impl GpuMarker {
pub fn new(_: &str) -> GpuMarker {
GpuMarker(())
}

pub fn fire(_: &str) {}
}


#[cfg(not(any(target_arch="arm", target_arch="aarch64")))]
impl GpuMarker {
pub fn new(message: &str) -> GpuMarker {
gl::push_group_marker_ext(message);
GpuMarker(())
}

pub fn fire(message: &str) {
gl::insert_event_marker_ext(message);
}
}

#[cfg(not(any(target_arch="arm", target_arch="aarch64")))]
impl Drop for GpuMarker {
fn drop(&mut self) {
gl::pop_group_marker_ext();
}
}

@@ -3,7 +3,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

use debug_render::DebugRenderer;
use device::GpuSample;
use device::{GpuMarker, GpuSample, NamedTag};
use euclid::{Point2D, Size2D, Rect};
use std::collections::vec_deque::VecDeque;
use std::f32;
@@ -25,6 +25,12 @@ pub struct GpuProfileTag {
pub color: ColorF,
}

impl NamedTag for GpuProfileTag {
fn get_label(&self) -> &str {
self.label
}
}

trait ProfileCounter {
fn description(&self) -> &'static str;
fn value(&self) -> String;
@@ -611,6 +617,8 @@ impl Profiler {
renderer_profile: &RendererProfileCounters,
renderer_timers: &mut RendererProfileTimers,
debug_renderer: &mut DebugRenderer) {

let _ = GpuMarker::new("profile");
self.x_left = 20.0;
self.y_left = 40.0;
self.x_right = 400.0;
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.