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}
29#[cfg(send_sync)]
30#[cfg(send_sync)]
31static_assertions::assert_impl_all!(QuerySet: Send, Sync);
32
33crate::cmp::impl_eq_ord_hash_proxy!(QuerySet => .inner);
34
35impl QuerySet {
36    #[cfg(custom)]
37    /// Returns custom implementation of QuerySet (if custom backend and is internally T)
38    pub fn as_custom<T: custom::QuerySetInterface>(&self) -> Option<&T> {
39        self.inner.as_custom()
40    }
41}
42
43/// Describes a [`QuerySet`].
44///
45/// For use with [`Device::create_query_set`].
46///
47/// Corresponds to [WebGPU `GPUQuerySetDescriptor`](
48/// https://gpuweb.github.io/gpuweb/#dictdef-gpuquerysetdescriptor).
49pub type QuerySetDescriptor<'a> = wgt::QuerySetDescriptor<Label<'a>>;
50static_assertions::assert_impl_all!(QuerySetDescriptor<'_>: Send, Sync);