wgpu_profiler/profiler_settings.rs
1use crate::SettingsError;
2
3/// Settings passed on initialization of [`GpuProfiler`](crate::GpuProfiler).
4#[derive(Debug, Clone)]
5pub struct GpuProfilerSettings {
6 /// Enables/disables gpu timer queries.
7 ///
8 /// If false, the profiler will not emit any timer queries, making most operations on [`GpuProfiler`](crate::GpuProfiler) no-ops.
9 ///
10 /// Since all resource creation is done lazily, this provides an effective way of disabling the profiler at runtime
11 /// without the need of special build configurations or code to handle enabled/disabled profiling.
12 pub enable_timer_queries: bool,
13
14 /// Enables/disables debug markers for all scopes on the respective encoder or pass.
15 ///
16 /// This is useful for debugging with tools like [RenderDoc](https://renderdoc.org/).
17 /// Debug markers will be emitted even if the device does not support timer queries or disables them via
18 /// [`GpuProfilerSettings::enable_timer_queries`].
19 pub enable_debug_groups: bool,
20
21 /// The profiler queues up to `max_num_pending_frames` "profiler-frames" at a time.
22 ///
23 /// A profiler-frame is regarded as in-flight until its queries have been successfully
24 /// resolved using [`GpuProfiler::process_finished_frame`](crate::GpuProfiler::process_finished_frame).
25 /// How long this takes to happen, depends on how fast buffer mappings return successfully
26 /// which in turn primarily depends on how fast the device is able to finish work queued to the [`wgpu::Queue`].
27 ///
28 /// If this threshold is exceeded, [`GpuProfiler::end_frame`](crate::GpuProfiler::end_frame) will silently drop frames.
29 /// *Newer* frames will be dropped first in order to get results back eventually.
30 /// (If the profiler were to drop the oldest frame, one may end up in a situation where there is never
31 /// frame that is fully processed and thus never any results to be retrieved).
32 ///
33 /// Good values for `max_num_pending_frames` are 2-4 but may depend on your application workload
34 /// and GPU-CPU syncing strategy.
35 /// Must be greater than 0.
36 pub max_num_pending_frames: usize,
37}
38
39impl Default for GpuProfilerSettings {
40 fn default() -> Self {
41 Self {
42 enable_timer_queries: true,
43 enable_debug_groups: true,
44 max_num_pending_frames: 3,
45 }
46 }
47}
48
49impl GpuProfilerSettings {
50 pub fn validate(&self) -> Result<(), SettingsError> {
51 if self.max_num_pending_frames == 0 {
52 Err(SettingsError::InvalidMaxNumPendingFrames)
53 } else {
54 Ok(())
55 }
56 }
57}