wgpu/api/
common_pipeline.rs

1use crate::*;
2
3#[derive(Clone, Debug)]
4/// Advanced options for use when a pipeline is compiled
5///
6/// This implements `Default`, and for most users can be set to `Default::default()`
7pub struct PipelineCompilationOptions<'a> {
8    /// Specifies the values of pipeline-overridable constants in the shader module.
9    ///
10    /// If an `@id` attribute was specified on the declaration,
11    /// the key must be the pipeline constant ID as a decimal ASCII number; if not,
12    /// the key must be the constant's identifier name.
13    ///
14    /// If the given constant is specified more than once, the last value specified is used.
15    ///
16    /// The value may represent any of WGSL's concrete scalar types.
17    ///
18    /// The default value is `&[]`.
19    pub constants: &'a [(&'a str, f64)],
20
21    /// Whether workgroup scoped memory will be initialized with zero values for this stage.
22    ///
23    /// This is required by the WebGPU spec, but may have overhead which can be avoided
24    /// for cross-platform applications
25    ///
26    /// The default value is `true`.
27    pub zero_initialize_workgroup_memory: bool,
28}
29
30impl PipelineCompilationOptions<'_> {
31    /// This function is identical to [`Default::default()`] except that it is a `const fn`.
32    pub const fn default() -> Self {
33        Self {
34            constants: &[],
35            zero_initialize_workgroup_memory: true,
36        }
37    }
38}
39
40impl Default for PipelineCompilationOptions<'_> {
41    fn default() -> Self {
42        Self::default() // call inherent function
43    }
44}
45
46/// Describes a pipeline cache, which allows reusing compilation work
47/// between program runs.
48///
49/// For use with [`Device::create_pipeline_cache`].
50///
51/// This type is unique to the Rust API of `wgpu`.
52#[derive(Clone, Debug)]
53pub struct PipelineCacheDescriptor<'a> {
54    /// Debug label of the pipeline cache. This might show up in some logs from `wgpu`
55    pub label: Label<'a>,
56    /// The data used to initialise the cache initialise
57    ///
58    /// # Safety
59    ///
60    /// This data must have been provided from a previous call to
61    /// [`PipelineCache::get_data`], if not `None`
62    pub data: Option<&'a [u8]>,
63    /// Whether to create a cache without data when the provided data
64    /// is invalid.
65    ///
66    /// Recommended to set to true
67    pub fallback: bool,
68}
69#[cfg(send_sync)]
70static_assertions::assert_impl_all!(PipelineCacheDescriptor<'_>: Send, Sync);