Skip to main content

wgpu_profiler/
errors.rs

1/// Errors that can occur during profiler creation.
2#[cfg_attr(not(feature = "tracy"), derive(PartialEq))]
3#[derive(thiserror::Error, Debug)]
4pub enum CreationError {
5    #[error(transparent)]
6    InvalidSettings(#[from] SettingsError),
7
8    #[cfg(feature = "tracy")]
9    #[error("Tracy client doesn't run yet.")]
10    TracyClientNotRunning,
11
12    #[cfg(feature = "tracy")]
13    #[error("Failed to create Tracy GPU context: {0}")]
14    TracyGpuContextCreationError(#[from] tracy_client::GpuContextCreationError),
15
16    #[cfg(feature = "tracy")]
17    #[error("Failed to read back initial GPU timestamp for Tracy: {0}")]
18    TracyGpuTimestampReadback(#[from] wgpu::MapRangeError),
19}
20
21#[cfg(feature = "tracy")]
22impl PartialEq for CreationError {
23    fn eq(&self, other: &Self) -> bool {
24        match self {
25            CreationError::InvalidSettings(left) => match other {
26                CreationError::InvalidSettings(right) => left == right,
27                _ => false,
28            },
29            CreationError::TracyClientNotRunning => {
30                matches!(other, CreationError::TracyClientNotRunning)
31            }
32            CreationError::TracyGpuContextCreationError(left) => match left {
33                tracy_client::GpuContextCreationError::TooManyContextsCreated => matches!(
34                    other,
35                    CreationError::TracyGpuContextCreationError(
36                        tracy_client::GpuContextCreationError::TooManyContextsCreated
37                    )
38                ),
39            },
40            CreationError::TracyGpuTimestampReadback(left) => match other {
41                CreationError::TracyGpuTimestampReadback(right) => {
42                    left.to_string() == right.to_string()
43                }
44                _ => false,
45            },
46        }
47    }
48}
49
50impl Eq for CreationError {}
51
52/// Errors that can occur during settings validation and change.
53#[derive(thiserror::Error, Debug, PartialEq, Eq)]
54pub enum SettingsError {
55    #[error("GpuProfilerSettings::max_num_pending_frames must be at least 1.")]
56    InvalidMaxNumPendingFrames,
57}
58
59/// Errors that can occur during [`crate::GpuProfiler::end_frame`].
60#[derive(thiserror::Error, Debug, PartialEq, Eq)]
61pub enum EndFrameError {
62    #[error("All profiling queries need to be closed before ending a frame. There were still {0} open queries.")]
63    UnclosedQueries(u32),
64
65    #[error(
66        "Not all queries were resolved before ending a frame.\n
67Call `GpuProfiler::resolve_queries` after all profiling queries have been closed and before ending the frame.\n
68There were still {0} queries unresolved."
69    )]
70    UnresolvedQueries(u32),
71}