gfx_hal/
query.rs

1//! Commands that can be used to record statistics or other useful values
2//! as the command buffer is running.
3//!
4//! They are often intended for profiling or other introspection,
5//! providing a mechanism for the command buffer to record data about its operation
6//! as it is running.
7
8use crate::{device::OutOfMemory, Backend};
9
10/// A query identifier.
11pub type Id = u32;
12
13/// Query creation error.
14#[derive(Clone, Debug, PartialEq, thiserror::Error)]
15pub enum CreationError {
16    /// Out of either host or device memory.
17    #[error(transparent)]
18    OutOfMemory(#[from] OutOfMemory),
19    /// Query type unsupported.
20    #[error("Unsupported type: {0:?}")]
21    Unsupported(Type),
22}
23
24/// A `Query` object has a particular identifier and saves its results to a given `QueryPool`.
25/// It is passed as a parameter to the command buffer's query methods.
26#[derive(Debug)]
27pub struct Query<'a, B: Backend> {
28    ///
29    pub pool: &'a B::QueryPool,
30    ///
31    pub id: Id,
32}
33
34bitflags!(
35    /// Query control flags.
36    #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
37    pub struct ControlFlags: u32 {
38        /// Occlusion queries **must** return the exact sampler number.
39        ///
40        /// Requires `precise_occlusion_query` device feature.
41        const PRECISE = 0x1;
42    }
43);
44
45bitflags!(
46    /// Query result flags.
47    #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
48    pub struct ResultFlags: u32 {
49        /// Results will be written as an array of 64-bit unsigned integer values.
50        const BITS_64 = 0x1;
51        /// Wait for each query’s status to become available before retrieving its results.
52        const WAIT = 0x2;
53        /// Availability status accompanies the results.
54        const WITH_AVAILABILITY = 0x4;
55        /// Returning partial results is acceptable.
56        const PARTIAL = 0x8;
57    }
58);
59
60/// Type of queries in a query pool.
61#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
62pub enum Type {
63    /// Occlusion query. Count the number of drawn samples between
64    /// the start and end of the query command.
65    Occlusion,
66    /// Pipeline statistic query. Counts the number of pipeline stage
67    /// invocations of the given types between the start and end of
68    /// the query command.
69    PipelineStatistics(PipelineStatistic),
70    /// Timestamp query. Timestamps can be recorded to the
71    /// query pool by calling `write_timestamp()`.
72    Timestamp,
73}
74
75bitflags!(
76    /// Pipeline statistic flags
77    #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
78    pub struct PipelineStatistic: u32 {
79        ///
80        const INPUT_ASSEMBLY_VERTICES = 0x1;
81        ///
82        const INPUT_ASSEMBLY_PRIMITIVES = 0x2;
83        ///
84        const VERTEX_SHADER_INVOCATIONS = 0x4;
85        ///
86        const GEOMETRY_SHADER_INVOCATIONS = 0x8;
87        ///
88        const GEOMETRY_SHADER_PRIMITIVES = 0x10;
89        ///
90        const CLIPPING_INVOCATIONS = 0x20;
91        ///
92        const CLIPPING_PRIMITIVES = 0x40;
93        ///
94        const FRAGMENT_SHADER_INVOCATIONS = 0x80;
95        ///
96        const HULL_SHADER_PATCHES = 0x100;
97        ///
98        const DOMAIN_SHADER_INVOCATIONS = 0x200;
99        ///
100        const COMPUTE_SHADER_INVOCATIONS = 0x400;
101    }
102);