Skip to content

Instantly share code, notes, and snippets.

@pcwalton
Created August 5, 2016 00:27
Show Gist options
  • Save pcwalton/f8d3ac19d486041e3ce88aae8fd79916 to your computer and use it in GitHub Desktop.
Save pcwalton/f8d3ac19d486041e3ce88aae8fd79916 to your computer and use it in GitHub Desktop.
diff --git a/src/device.rs b/src/device.rs
index eb93dd3..c90247e 100644
--- a/src/device.rs
+++ b/src/device.rs
@@ -670,6 +670,50 @@ impl UniformLocation {
}
}
+pub struct SamplesPassedQuery {
+ qid: gl::GLuint,
+}
+
+impl SamplesPassedQuery {
+ #[cfg(any(target_os = "linux", target_os = "windows", target_os = "macos"))]
+ pub fn new() -> SamplesPassedQuery {
+ SamplesPassedQuery {
+ qid: gl::gen_queries(1)[0],
+ }
+ }
+
+ #[cfg(target_os = "android")]
+ pub fn new() -> SamplesPassedQuery {
+ SamplesPassedQuery
+ }
+
+ #[cfg(any(target_os = "android", target_os = "gonk"))]
+ pub fn get(&mut self) -> u64 {
+ 0
+ }
+
+ #[cfg(any(target_os = "linux", target_os = "windows", target_os = "macos"))]
+ pub fn get(&mut self) -> u64 {
+ gl::get_query_object_uiv(self.qid, gl::QUERY_RESULT) as u64
+ }
+
+ #[cfg(any(target_os = "linux", target_os = "windows", target_os = "macos"))]
+ pub fn begin(&mut self) {
+ gl::begin_query(gl::SAMPLES_PASSED, self.qid);
+ }
+
+ #[cfg(target_os = "android")]
+ pub fn begin(&mut self) {}
+
+ #[cfg(any(target_os = "linux", target_os = "windows", target_os = "macos"))]
+ pub fn end(&mut self) {
+ gl::end_query(gl::SAMPLES_PASSED);
+ }
+
+ #[cfg(target_os = "android")]
+ pub fn end(&mut self) -> u64 { 0 }
+}
+
// TODO(gw): Fix up notify cargo deps and re-enable this!
/*
enum FileWatcherCmd {
diff --git a/src/renderer.rs b/src/renderer.rs
index 5ae8330..095a164 100644
--- a/src/renderer.rs
+++ b/src/renderer.rs
@@ -12,7 +12,7 @@
use batch::RasterBatch;
use debug_render::DebugRenderer;
use device::{Device, ProgramId, TextureId, UniformLocation, VertexFormat, GpuProfile};
-use device::{TextureFilter, VAOId, VertexUsageHint, FileWatcherHandler};
+use device::{SamplesPassedQuery, TextureFilter, VAOId, VertexUsageHint, FileWatcherHandler};
use euclid::{Matrix4D, Point2D, Rect, Size2D};
use gleam::gl;
use internal_types::{RendererFrame, ResultMsg, TextureUpdateOp};
@@ -229,6 +229,7 @@ pub struct Renderer {
gpu_profile_paint: GpuProfile,
gpu_profile_composite: GpuProfile,
+ samples_passed_query: SamplesPassedQuery,
quad_vao_id: VAOId,
}
@@ -544,6 +545,7 @@ impl Renderer {
max_raster_op_size: max_raster_op_size,
gpu_profile_paint: GpuProfile::new(),
gpu_profile_composite: GpuProfile::new(),
+ samples_passed_query: SamplesPassedQuery::new(),
quad_vao_id: quad_vao_id,
};
@@ -620,6 +622,7 @@ impl Renderer {
// In general this shouldn't block unless heavily GPU limited.
let paint_ns = self.gpu_profile_paint.get();
let composite_ns = self.gpu_profile_composite.get();
+ self.samples_passed_query.begin();
profile_timers.cpu_time.profile(|| {
self.device.begin_frame();
@@ -633,6 +636,9 @@ impl Renderer {
self.draw_frame(framebuffer_size);
});
+ self.samples_passed_query.end();
+ println!("samples passed: {}", self.samples_passed_query.get());
+
let current_time = precise_time_ns();
let ns = current_time - self.last_time;
self.profile_counters.frame_time.set(ns);
@@ -1249,7 +1255,7 @@ impl Renderer {
tile_y1,
c);
if label.len() > 0 {
- self.debug.add_text((tile_x0.0 as f32 + tile_x1.0 as f32) * 0.5,
+ self.debug.add_text(tile_x0.0 as f32 + (tile_x1.0 as f32 - tile_x0.0 as f32) * 0.25,
(tile_y0.0 as f32 + tile_y1.0 as f32) * 0.5,
label,
c);
diff --git a/src/tiling.rs b/src/tiling.rs
index c67f235..32c6068 100644
--- a/src/tiling.rs
+++ b/src/tiling.rs
@@ -2106,6 +2106,7 @@ impl ScreenTile {
}
self.prim_count = 0;
+
for (command_index, command) in mem::replace(&mut self.cmds, vec![]).into_iter()
.enumerate() {
match command {
@@ -2115,10 +2116,39 @@ impl ScreenTile {
}
self.prim_count += 1
}
+ TileCommand::PopLayer => {
+ if let Some(&TileCommand::PushLayer(_)) = self.cmds.last() {
+ self.cmds.pop();
+ continue
+ }
+ }
+ _ => {}
+ }
+ self.cmds.push(command);
+ }
+ }
+
+ #[allow(dead_code)]
+ fn dump_primitives(&self, prim_store: &[Primitive]) {
+ let mut string = String::new();
+ for command in &self.cmds {
+ match *command {
+ TileCommand::DrawPrimitive(index) => {
+ let primitive = &(*prim_store)[index.0];
+ match primitive.details {
+ PrimitiveDetails::Rectangle(_) => string.push('C'),
+ PrimitiveDetails::Text(_) => string.push('T'),
+ PrimitiveDetails::TextRun(_) => string.push('R'),
+ PrimitiveDetails::Image(_) => string.push('I'),
+ PrimitiveDetails::Border(_) => string.push('B'),
+ PrimitiveDetails::Gradient(_) => string.push('G'),
+ PrimitiveDetails::BoxShadow(_) => string.push('S'),
+ }
+ }
_ => {}
}
- self.cmds.push(command)
}
+ println!("Tile: {}", string);
}
fn compile(self, layer_store: &Vec<StackingContext>) -> Option<CompiledScreenTile> {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment