wgpu/api/
query_set.rs

1use crate::*;
2
3/// Handle to a query set.
4///
5/// A `QuerySet` is an opaque, mutable storage location for the results of queries:
6/// which are small pieces of information extracted from other operations such as render passes.
7/// See [`QueryType`] for what types of information can be collected.
8///
9/// Each query writes data into one or more result slots in the `QuerySet`, which must be created
10/// with a sufficient number of slots for that usage. Each result slot is a an unsigned 64-bit
11/// number.
12///
13/// Using queries consists of the following steps:
14///
15/// 1. Create a `QuerySet` of the appropriate type and number of query result slots
16///    using [`Device::create_query_set()`].
17/// 2. Pass the `QuerySet` to the commands which will write to it.
18///    See [`QueryType`] for the possible commands.
19/// 3. Execute the command [`CommandEncoder::resolve_query_set()`].
20///    This converts the opaque data stored in a `QuerySet` into [`u64`]s stored in a [`Buffer`].
21/// 4. Make use of that buffer, such as by copying its contents to the CPU
22///    or reading it from a compute shader.
23///
24/// Corresponds to [WebGPU `GPUQuerySet`](https://gpuweb.github.io/gpuweb/#queryset).
25#[derive(Debug, Clone)]
26pub struct QuerySet {
27    pub(crate) inner: dispatch::DispatchQuerySet,
28    pub(crate) ty: QueryType,
29    pub(crate) count: u32,
30}
31#[cfg(send_sync)]
32#[cfg(send_sync)]
33static_assertions::assert_impl_all!(QuerySet: Send, Sync);
34
35crate::cmp::impl_eq_ord_hash_proxy!(QuerySet => .inner);
36
37impl QuerySet {
38    #[cfg(custom)]
39    /// Returns custom implementation of QuerySet (if custom backend and is internally T)
40    pub fn as_custom<T: custom::QuerySetInterface>(&self) -> Option<&T> {
41        self.inner.as_custom()
42    }
43
44    /// Destroys the [`QuerySet`], releasing its resources.
45    pub fn destroy(&self) {
46        self.inner.destroy();
47    }
48
49    /// Returns the type of queries stored.
50    pub fn ty(&self) -> QueryType {
51        self.ty
52    }
53
54    /// Returns the number of query result slots.
55    pub fn count(&self) -> u32 {
56        self.count
57    }
58}
59
60/// Describes a [`QuerySet`].
61///
62/// For use with [`Device::create_query_set`].
63///
64/// Corresponds to [WebGPU `GPUQuerySetDescriptor`](
65/// https://gpuweb.github.io/gpuweb/#dictdef-gpuquerysetdescriptor).
66pub type QuerySetDescriptor<'a> = wgt::QuerySetDescriptor<Label<'a>>;
67static_assertions::assert_impl_all!(QuerySetDescriptor<'_>: Send, Sync);