wgpu_types/tokens.rs
1use crate::link_to_wgpu_item;
2
3/// Token of the user agreeing to access experimental features.
4#[derive(Debug, Default, Copy, Clone)]
5pub struct ExperimentalFeatures {
6 enabled: bool,
7}
8
9impl ExperimentalFeatures {
10 /// Uses of [`Features`] prefixed with "EXPERIMENTAL" are disallowed.
11 ///
12 #[doc = link_to_wgpu_item!(struct Features)]
13 pub const fn disabled() -> Self {
14 Self { enabled: false }
15 }
16
17 /// Uses of [`Features`] prefixed with "EXPERIMENTAL" may result
18 /// in undefined behavior when used incorrectly. The exact bounds
19 /// of these issues varies by the feature. These instances are
20 /// inherently bugs in our implementation that we will eventually fix.
21 ///
22 /// By giving access to still work-in-progress APIs, users can get
23 /// access to newer technology sooner, and we can work with users
24 /// to fix bugs quicker.
25 ///
26 /// Look inside our repo at the [`api-specs`] for more information
27 /// on various experimental apis.
28 ///
29 /// # Safety
30 ///
31 /// - You acknowledge that there may be UB-containing bugs in these
32 /// apis and those may be hit by calling otherwise safe code.
33 /// - You agree to report any such bugs to us, if you find them.
34 ///
35 #[doc = link_to_wgpu_item!(struct Features)]
36 /// [`api-specs`]: https://github.com/gfx-rs/wgpu/tree/trunk/docs/api-specs
37 pub const unsafe fn enabled() -> Self {
38 Self { enabled: true }
39 }
40
41 /// Returns true if the user has agreed to access experimental features.
42 pub const fn is_enabled(&self) -> bool {
43 self.enabled
44 }
45}
46
47/// Token of the user agreeing to use [`LoadOp::DontCare`](crate::LoadOp::DontCare).
48#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)]
49pub struct LoadOpDontCare {
50 // Private to prevent construction outside of the unsafe
51 // enabled() function.
52 _private: (),
53}
54
55impl LoadOpDontCare {
56 /// Using [`LoadOp::DontCare`](crate::LoadOp::DontCare) will result
57 /// in the render target having undefined contents at the start of the render pass.
58 /// This may lead to undefined behavior if you read from the any of the
59 /// render target pixels without first writing to them.
60 ///
61 /// Blending also becomes undefined behavior if the source
62 /// pixels are undefined.
63 ///
64 /// All pixels in the render target must be written to before
65 /// any blending or a [`StoreOp::Store`](crate::StoreOp::Store) occurs.
66 ///
67 /// # Safety
68 ///
69 /// - You acknowledge that using `LoadOp::DontCare` may lead to undefined behavior
70 /// if the above conditions are not met.
71 pub const unsafe fn enabled() -> Self {
72 Self { _private: () }
73 }
74}