Skip to content

Commit e16f0a0

Browse files
committed
Turn off timer queries if the debug UI is off.
Closes #360.
1 parent e21d79b commit e16f0a0

File tree

4 files changed

+97
-48
lines changed

4 files changed

+97
-48
lines changed

renderer/src/gpu/d3d11/renderer.rs

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
use crate::gpu::d3d11::shaders::{BOUND_WORKGROUP_SIZE, DICE_WORKGROUP_SIZE};
1212
use crate::gpu::d3d11::shaders::{PROPAGATE_WORKGROUP_SIZE, ProgramsD3D11, SORT_WORKGROUP_SIZE};
13-
use crate::gpu::perf::TimerFuture;
13+
use crate::gpu::perf::TimeCategory;
1414
use crate::gpu::renderer::{FramebufferFlags, RendererCore};
1515
use crate::gpu_data::{AlphaTileD3D11, BackdropInfoD3D11, DiceMetadataD3D11, DrawTileBatchD3D11};
1616
use crate::gpu_data::{Fill, FirstTileD3D11, MicrolineD3D11, PathSource, PropagateMetadataD3D11};
@@ -78,8 +78,8 @@ impl<D> RendererD3D11<D> where D: Device {
7878

7979
let tiles_buffer = core.allocator.get_buffer(tiles_d3d11_buffer_id);
8080

81-
let timer_query = core.timer_query_cache.alloc(&core.device);
82-
core.device.begin_timer_query(&timer_query);
81+
let timer_query = core.timer_query_cache.start_timing_draw_call(&core.device,
82+
&core.options);
8383

8484
let compute_dimensions = ComputeDimensions {
8585
x: (tile_count + BOUND_WORKGROUP_SIZE - 1) / BOUND_WORKGROUP_SIZE,
@@ -100,9 +100,9 @@ impl<D> RendererD3D11<D> where D: Device {
100100
],
101101
});
102102

103-
core.device.end_timer_query(&timer_query);
104-
core.current_timer.as_mut().unwrap().other_times.push(TimerFuture::new(timer_query));
105103
core.stats.drawcall_count += 1;
104+
core.finish_timing_draw_call(&timer_query);
105+
core.current_timer.as_mut().unwrap().push_query(TimeCategory::Other, timer_query);
106106

107107
core.allocator.free_buffer(path_info_buffer_id);
108108
}
@@ -174,8 +174,8 @@ impl<D> RendererD3D11<D> where D: Device {
174174
&indirect_draw_params,
175175
BufferTarget::Storage);
176176

177-
let timer_query = core.timer_query_cache.alloc(&core.device);
178-
core.device.begin_timer_query(&timer_query);
177+
let timer_query = core.timer_query_cache.start_timing_draw_call(&core.device,
178+
&core.options);
179179

180180
let compute_dimensions = ComputeDimensions {
181181
x: (microlines_storage.count + 63) / 64,
@@ -204,9 +204,9 @@ impl<D> RendererD3D11<D> where D: Device {
204204
],
205205
});
206206

207-
core.device.end_timer_query(&timer_query);
208-
core.current_timer.as_mut().unwrap().bin_times.push(TimerFuture::new(timer_query));
209207
core.stats.drawcall_count += 1;
208+
core.finish_timing_draw_call(&timer_query);
209+
core.current_timer.as_mut().unwrap().push_query(TimeCategory::Bin, timer_query);
210210

211211
let indirect_draw_params_receiver =
212212
core.device.read_buffer(fill_indirect_draw_params_buffer,
@@ -294,8 +294,8 @@ impl<D> RendererD3D11<D> where D: Device {
294294
dice_metadata,
295295
BufferTarget::Storage);
296296

297-
let timer_query = core.timer_query_cache.alloc(&core.device);
298-
core.device.begin_timer_query(&timer_query);
297+
let timer_query = core.timer_query_cache.start_timing_draw_call(&core.device,
298+
&core.options);
299299

300300
let workgroup_count = (batch_segment_count + DICE_WORKGROUP_SIZE - 1) /
301301
DICE_WORKGROUP_SIZE;
@@ -325,9 +325,9 @@ impl<D> RendererD3D11<D> where D: Device {
325325
],
326326
});
327327

328-
core.device.end_timer_query(&timer_query);
329-
core.current_timer.as_mut().unwrap().dice_times.push(TimerFuture::new(timer_query));
330328
core.stats.drawcall_count += 1;
329+
core.finish_timing_draw_call(&timer_query);
330+
core.current_timer.as_mut().unwrap().push_query(TimeCategory::Dice, timer_query);
331331

332332
let indirect_compute_params_receiver =
333333
core.device.read_buffer(&dice_indirect_draw_params_buffer,
@@ -374,8 +374,8 @@ impl<D> RendererD3D11<D> where D: Device {
374374

375375
let area_lut_texture = core.allocator.get_texture(core.area_lut_texture_id);
376376

377-
let timer_query = core.timer_query_cache.alloc(&core.device);
378-
core.device.begin_timer_query(&timer_query);
377+
let timer_query = core.timer_query_cache.start_timing_draw_call(&core.device,
378+
&core.options);
379379

380380
// This setup is an annoying workaround for the 64K limit of compute invocation in OpenGL.
381381
let alpha_tile_count = alpha_tile_range.end - alpha_tile_range.start;
@@ -401,9 +401,9 @@ impl<D> RendererD3D11<D> where D: Device {
401401
],
402402
});
403403

404-
core.device.end_timer_query(&timer_query);
405-
core.current_timer.as_mut().unwrap().fill_times.push(TimerFuture::new(timer_query));
406404
core.stats.drawcall_count += 1;
405+
core.finish_timing_draw_call(&timer_query);
406+
core.current_timer.as_mut().unwrap().push_query(TimeCategory::Fill, timer_query);
407407

408408
core.framebuffer_flags.insert(FramebufferFlags::MASK_FRAMEBUFFER_IS_DIRTY);
409409
}
@@ -596,8 +596,8 @@ impl<D> RendererD3D11<D> where D: Device {
596596
storage_buffers.push((&propagate_program.clip_tiles_storage_buffer, clip_tile_buffer));
597597
}
598598

599-
let timer_query = core.timer_query_cache.alloc(&core.device);
600-
core.device.begin_timer_query(&timer_query);
599+
let timer_query = core.timer_query_cache.start_timing_draw_call(&core.device,
600+
&core.options);
601601

602602
let dimensions = ComputeDimensions {
603603
x: (column_count + PROPAGATE_WORKGROUP_SIZE - 1) / PROPAGATE_WORKGROUP_SIZE,
@@ -618,9 +618,9 @@ impl<D> RendererD3D11<D> where D: Device {
618618
storage_buffers: &storage_buffers,
619619
});
620620

621-
core.device.end_timer_query(&timer_query);
622-
core.current_timer.as_mut().unwrap().other_times.push(TimerFuture::new(timer_query));
623621
core.stats.drawcall_count += 1;
622+
core.finish_timing_draw_call(&timer_query);
623+
core.current_timer.as_mut().unwrap().push_query(TimeCategory::Other, timer_query);
624624

625625
let fill_indirect_draw_params_receiver =
626626
core.device.read_buffer(&fill_indirect_draw_params_buffer,
@@ -654,8 +654,8 @@ impl<D> RendererD3D11<D> where D: Device {
654654

655655
let tile_count = core.framebuffer_tile_size().area();
656656

657-
let timer_query = core.timer_query_cache.alloc(&core.device);
658-
core.device.begin_timer_query(&timer_query);
657+
let timer_query = core.timer_query_cache.start_timing_draw_call(&core.device,
658+
&core.options);
659659

660660
let dimensions = ComputeDimensions {
661661
x: (tile_count as u32 + SORT_WORKGROUP_SIZE - 1) / SORT_WORKGROUP_SIZE,
@@ -674,9 +674,9 @@ impl<D> RendererD3D11<D> where D: Device {
674674
],
675675
});
676676

677-
core.device.end_timer_query(&timer_query);
678-
core.current_timer.as_mut().unwrap().other_times.push(TimerFuture::new(timer_query));
679677
core.stats.drawcall_count += 1;
678+
core.finish_timing_draw_call(&timer_query);
679+
core.current_timer.as_mut().unwrap().push_query(TimeCategory::Other, timer_query);
680680
}
681681

682682
fn allocate_first_tile_map(&mut self, core: &mut RendererCore<D>) -> BufferID {
@@ -703,8 +703,8 @@ impl<D> RendererD3D11<D> where D: Device {
703703
tiles_d3d11_buffer_id: BufferID,
704704
first_tile_map_buffer_id: BufferID,
705705
color_texture_0: Option<TileBatchTexture>) {
706-
let timer_query = core.timer_query_cache.alloc(&core.device);
707-
core.device.begin_timer_query(&timer_query);
706+
let timer_query = core.timer_query_cache.start_timing_draw_call(&core.device,
707+
&core.options);
708708

709709
let tile_program = &self.programs.tile_program;
710710

@@ -763,9 +763,9 @@ impl<D> RendererD3D11<D> where D: Device {
763763
uniforms: &uniforms,
764764
});
765765

766-
core.device.end_timer_query(&timer_query);
767-
core.current_timer.as_mut().unwrap().composite_times.push(TimerFuture::new(timer_query));
768766
core.stats.drawcall_count += 1;
767+
core.finish_timing_draw_call(&timer_query);
768+
core.current_timer.as_mut().unwrap().push_query(TimeCategory::Composite, timer_query);
769769

770770
core.preserve_draw_framebuffer();
771771
}

renderer/src/gpu/d3d9/renderer.rs

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// except according to those terms.
1010

1111
use crate::gpu::blend::{BlendModeExt, ToBlendState};
12-
use crate::gpu::perf::TimerFuture;
12+
use crate::gpu::perf::TimeCategory;
1313
use crate::gpu::renderer::{FramebufferFlags, MASK_FRAMEBUFFER_HEIGHT, MASK_FRAMEBUFFER_WIDTH};
1414
use crate::gpu::renderer::{RendererCore, RendererFlags};
1515
use crate::gpu::d3d9::shaders::{ClipTileCombineVertexArrayD3D9, ClipTileCopyVertexArrayD3D9};
@@ -225,8 +225,8 @@ impl<D> RendererD3D9<D> where D: Device {
225225
clear_color = Some(ColorF::default());
226226
};
227227

228-
let timer_query = core.timer_query_cache.alloc(&core.device);
229-
core.device.begin_timer_query(&timer_query);
228+
let timer_query = core.timer_query_cache.start_timing_draw_call(&core.device,
229+
&core.options);
230230

231231
core.device.draw_elements_instanced(6, fill_count, &RenderState {
232232
target: &RenderTarget::Framebuffer(mask_framebuffer),
@@ -256,9 +256,9 @@ impl<D> RendererD3D9<D> where D: Device {
256256
},
257257
});
258258

259-
core.device.end_timer_query(&timer_query);
260-
core.current_timer.as_mut().unwrap().fill_times.push(TimerFuture::new(timer_query));
261259
core.stats.drawcall_count += 1;
260+
core.finish_timing_draw_call(&timer_query);
261+
core.current_timer.as_mut().unwrap().push_query(TimeCategory::Fill, timer_query);
262262

263263
core.framebuffer_flags.insert(FramebufferFlags::MASK_FRAMEBUFFER_IS_DIRTY);
264264
}
@@ -297,8 +297,8 @@ impl<D> RendererD3D9<D> where D: Device {
297297
quad_vertex_positions_buffer,
298298
quad_vertex_indices_buffer);
299299

300-
let timer_query = core.timer_query_cache.alloc(&core.device);
301-
core.device.begin_timer_query(&timer_query);
300+
let timer_query = core.timer_query_cache.start_timing_draw_call(&core.device,
301+
&core.options);
302302

303303
// Copy out tiles.
304304
//
@@ -322,6 +322,12 @@ impl<D> RendererD3D9<D> where D: Device {
322322
options: RenderOptions::default(),
323323
});
324324

325+
core.stats.drawcall_count += 1;
326+
core.finish_timing_draw_call(&timer_query);
327+
core.current_timer.as_mut().unwrap().push_query(TimeCategory::Other, timer_query);
328+
let timer_query = core.timer_query_cache.start_timing_draw_call(&core.device,
329+
&core.options);
330+
325331
// Combine clip tiles.
326332
core.device.draw_elements_instanced(6, clip_buffer_info.clip_count, &RenderState {
327333
target: &RenderTarget::Framebuffer(mask_framebuffer),
@@ -342,9 +348,9 @@ impl<D> RendererD3D9<D> where D: Device {
342348
options: RenderOptions::default(),
343349
});
344350

345-
core.device.end_timer_query(&timer_query);
346-
core.current_timer.as_mut().unwrap().other_times.push(TimerFuture::new(timer_query));
347-
core.stats.drawcall_count += 2;
351+
core.stats.drawcall_count += 1;
352+
core.finish_timing_draw_call(&timer_query);
353+
core.current_timer.as_mut().unwrap().push_query(TimeCategory::Other, timer_query);
348354

349355
core.allocator.free_framebuffer(mask_temp_framebuffer_id);
350356
}
@@ -397,8 +403,8 @@ impl<D> RendererD3D9<D> where D: Device {
397403
let clear_color = core.clear_color_for_draw_operation();
398404
let draw_viewport = core.draw_viewport();
399405

400-
let timer_query = core.timer_query_cache.alloc(&core.device);
401-
core.device.begin_timer_query(&timer_query);
406+
let timer_query = core.timer_query_cache.start_timing_draw_call(&core.device,
407+
&core.options);
402408

403409
let tile_raster_program = &self.programs.tile_program;
404410

@@ -454,9 +460,9 @@ impl<D> RendererD3D9<D> where D: Device {
454460
},
455461
});
456462

457-
core.device.end_timer_query(&timer_query);
458-
core.current_timer.as_mut().unwrap().composite_times.push(TimerFuture::new(timer_query));
459463
core.stats.drawcall_count += 1;
464+
core.finish_timing_draw_call(&timer_query);
465+
core.current_timer.as_mut().unwrap().push_query(TimeCategory::Composite, timer_query);
460466

461467
core.preserve_draw_framebuffer();
462468
}

renderer/src/gpu/perf.rs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
//! Performance monitoring infrastructure.
1212
13+
use crate::gpu::options::RendererOptions;
1314
use pathfinder_gpu::Device;
1415
use std::mem;
1516
use std::ops::{Add, Div};
@@ -76,6 +77,15 @@ pub(crate) enum TimerFuture<D> where D: Device {
7677
Resolved(Duration),
7778
}
7879

80+
#[derive(Clone, Copy, PartialEq)]
81+
pub(crate) enum TimeCategory {
82+
Dice,
83+
Bin,
84+
Fill,
85+
Composite,
86+
Other,
87+
}
88+
7989
impl<D> TimerQueryCache<D> where D: Device {
8090
pub(crate) fn new() -> TimerQueryCache<D> {
8191
TimerQueryCache { free_queries: vec![] }
@@ -88,6 +98,17 @@ impl<D> TimerQueryCache<D> where D: Device {
8898
pub(crate) fn free(&mut self, old_query: D::TimerQuery) {
8999
self.free_queries.push(old_query);
90100
}
101+
102+
pub(crate) fn start_timing_draw_call(&mut self, device: &D, options: &RendererOptions<D>)
103+
-> Option<D::TimerQuery> {
104+
if !options.show_debug_ui {
105+
return None;
106+
}
107+
108+
let timer_query = self.alloc(device);
109+
device.begin_timer_query(&timer_query);
110+
Some(timer_query)
111+
}
91112
}
92113

93114
impl<D> PendingTimer<D> where D: Device {
@@ -131,6 +152,22 @@ impl<D> PendingTimer<D> where D: Device {
131152
_ => None,
132153
}
133154
}
155+
156+
pub(crate) fn push_query(&mut self,
157+
time_category: TimeCategory,
158+
timer_query: Option<D::TimerQuery>) {
159+
let timer_future = match timer_query {
160+
None => return,
161+
Some(timer_query) => TimerFuture::new(timer_query),
162+
};
163+
match time_category {
164+
TimeCategory::Dice => self.dice_times.push(timer_future),
165+
TimeCategory::Bin => self.bin_times.push(timer_future),
166+
TimeCategory::Fill => self.fill_times.push(timer_future),
167+
TimeCategory::Composite => self.composite_times.push(timer_future),
168+
TimeCategory::Other => self.other_times.push(timer_future),
169+
}
170+
}
134171
}
135172

136173
impl<D> TimerFuture<D> where D: Device {

renderer/src/gpu/renderer.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use crate::gpu::d3d9::renderer::RendererD3D9;
1313
use crate::gpu::d3d11::renderer::RendererD3D11;
1414
use crate::gpu::debug::DebugUIPresenter;
1515
use crate::gpu::options::{DestFramebuffer, RendererLevel, RendererMode, RendererOptions};
16-
use crate::gpu::perf::{PendingTimer, RenderStats, RenderTime, TimerFuture, TimerQueryCache};
16+
use crate::gpu::perf::{PendingTimer, RenderStats, RenderTime, TimeCategory, TimerQueryCache};
1717
use crate::gpu::shaders::{BlitProgram, BlitVertexArray, ClearProgram, ClearVertexArray};
1818
use crate::gpu::shaders::{ProgramsCore, ReprojectionProgram, ReprojectionVertexArray};
1919
use crate::gpu::shaders::{StencilProgram, StencilVertexArray, TileProgramCommon, VertexArraysCore};
@@ -934,8 +934,8 @@ impl<D> RendererCore<D> where D: Device {
934934
let old_mask_texture = self.device.framebuffer_texture(old_mask_framebuffer);
935935
let old_size = self.device.texture_size(old_mask_texture);
936936

937-
let timer_query = self.timer_query_cache.alloc(&self.device);
938-
self.device.begin_timer_query(&timer_query);
937+
let timer_query = self.timer_query_cache.start_timing_draw_call(&self.device,
938+
&self.options);
939939

940940
self.device.draw_elements(6, &RenderState {
941941
target: &RenderTarget::Framebuffer(mask_framebuffer),
@@ -961,9 +961,9 @@ impl<D> RendererCore<D> where D: Device {
961961
},
962962
});
963963

964-
self.device.end_timer_query(&timer_query);
965-
self.current_timer.as_mut().unwrap().other_times.push(TimerFuture::new(timer_query));
966964
self.stats.drawcall_count += 1;
965+
self.finish_timing_draw_call(&timer_query);
966+
self.current_timer.as_mut().unwrap().push_query(TimeCategory::Other, timer_query);
967967
}
968968

969969
pub(crate) fn set_uniforms_for_drawing_tiles<'a>(
@@ -1128,6 +1128,12 @@ impl<D> RendererCore<D> where D: Device {
11281128
fn render_target_location(&self, render_target_id: RenderTargetId) -> TextureLocation {
11291129
self.render_targets[render_target_id.render_target as usize].location
11301130
}
1131+
1132+
pub(crate) fn finish_timing_draw_call(&self, timer_query: &Option<D::TimerQuery>) {
1133+
if let Some(ref timer_query) = *timer_query {
1134+
self.device.end_timer_query(timer_query)
1135+
}
1136+
}
11311137
}
11321138

11331139
impl<D> Frame<D> where D: Device {

0 commit comments

Comments
 (0)