Skip to main content

wgpu_types/
limits.rs

1//! [`Limits`] and downlevel-related types.
2
3use core::cmp::Ordering;
4
5#[cfg(any(feature = "serde", test))]
6use serde::{Deserialize, Serialize};
7
8#[cfg(doc)]
9use crate::{Features, TextureFormat};
10
11/// Invoke a macro for each of the limits.
12///
13/// The supplied macro should take two arguments. The first is a limit name, as
14/// an identifier, typically used to access a member of `struct Limits`. The
15/// second is `Ordering::Less` if valid values are less than the limit (the
16/// common case), or `Ordering::Greater` if valid values are more than the limit
17/// (for limits like alignments, which are minima instead of maxima).
18macro_rules! with_limits {
19    ($macro_name:ident) => {
20        $macro_name!(max_texture_dimension_1d, Ordering::Less);
21        $macro_name!(max_texture_dimension_1d, Ordering::Less);
22        $macro_name!(max_texture_dimension_2d, Ordering::Less);
23        $macro_name!(max_texture_dimension_3d, Ordering::Less);
24        $macro_name!(max_texture_array_layers, Ordering::Less);
25        $macro_name!(max_bind_groups, Ordering::Less);
26        $macro_name!(max_bindings_per_bind_group, Ordering::Less);
27        $macro_name!(
28            max_dynamic_uniform_buffers_per_pipeline_layout,
29            Ordering::Less
30        );
31        $macro_name!(
32            max_dynamic_storage_buffers_per_pipeline_layout,
33            Ordering::Less
34        );
35        $macro_name!(max_sampled_textures_per_shader_stage, Ordering::Less);
36        $macro_name!(max_samplers_per_shader_stage, Ordering::Less);
37        $macro_name!(max_storage_buffers_per_shader_stage, Ordering::Less);
38        $macro_name!(max_storage_textures_per_shader_stage, Ordering::Less);
39        $macro_name!(max_uniform_buffers_per_shader_stage, Ordering::Less);
40        $macro_name!(max_binding_array_elements_per_shader_stage, Ordering::Less);
41        $macro_name!(
42            max_binding_array_acceleration_structure_elements_per_shader_stage,
43            Ordering::Less
44        );
45        $macro_name!(max_uniform_buffer_binding_size, Ordering::Less);
46        $macro_name!(max_storage_buffer_binding_size, Ordering::Less);
47        $macro_name!(max_vertex_buffers, Ordering::Less);
48        $macro_name!(max_buffer_size, Ordering::Less);
49        $macro_name!(max_vertex_attributes, Ordering::Less);
50        $macro_name!(max_vertex_buffer_array_stride, Ordering::Less);
51        $macro_name!(max_inter_stage_shader_variables, Ordering::Less);
52        $macro_name!(min_uniform_buffer_offset_alignment, Ordering::Greater);
53        $macro_name!(min_storage_buffer_offset_alignment, Ordering::Greater);
54        $macro_name!(max_color_attachments, Ordering::Less);
55        $macro_name!(max_color_attachment_bytes_per_sample, Ordering::Less);
56        $macro_name!(max_compute_workgroup_storage_size, Ordering::Less);
57        $macro_name!(max_compute_invocations_per_workgroup, Ordering::Less);
58        $macro_name!(max_compute_workgroup_size_x, Ordering::Less);
59        $macro_name!(max_compute_workgroup_size_y, Ordering::Less);
60        $macro_name!(max_compute_workgroup_size_z, Ordering::Less);
61        $macro_name!(max_compute_workgroups_per_dimension, Ordering::Less);
62
63        $macro_name!(max_immediate_size, Ordering::Less);
64        $macro_name!(max_non_sampler_bindings, Ordering::Less);
65
66        $macro_name!(max_task_mesh_workgroup_total_count, Ordering::Less);
67        $macro_name!(max_task_mesh_workgroups_per_dimension, Ordering::Less);
68        $macro_name!(max_task_invocations_per_workgroup, Ordering::Less);
69        $macro_name!(max_task_invocations_per_dimension, Ordering::Less);
70        $macro_name!(max_mesh_invocations_per_workgroup, Ordering::Less);
71        $macro_name!(max_mesh_invocations_per_dimension, Ordering::Less);
72
73        $macro_name!(max_task_payload_size, Ordering::Less);
74        $macro_name!(max_mesh_output_vertices, Ordering::Less);
75        $macro_name!(max_mesh_output_primitives, Ordering::Less);
76        $macro_name!(max_mesh_output_layers, Ordering::Less);
77        $macro_name!(max_mesh_multiview_view_count, Ordering::Less);
78
79        $macro_name!(max_blas_primitive_count, Ordering::Less);
80        $macro_name!(max_blas_geometry_count, Ordering::Less);
81        $macro_name!(max_tlas_instance_count, Ordering::Less);
82
83        $macro_name!(max_multiview_view_count, Ordering::Less);
84    };
85}
86
87/// Represents the sets of limits an adapter/device supports.
88///
89/// We provide three different defaults.
90/// - [`Limits::downlevel_defaults()`]. This is a set of limits that is guaranteed to work on almost
91///   all backends, including "downlevel" backends such as OpenGL and D3D11, other than WebGL. For
92///   most applications we recommend using these limits, assuming they are high enough for your
93///   application, and you do not intend to support WebGL.
94/// - [`Limits::downlevel_webgl2_defaults()`] This is a set of limits that is lower even than the
95///   [`downlevel_defaults()`], configured to be low enough to support running in the browser using
96///   WebGL2.
97/// - [`Limits::default()`]. This is the set of limits that is guaranteed to work on all modern
98///   backends and is guaranteed to be supported by WebGPU. Applications needing more modern
99///   features can use this as a reasonable set of limits if they are targeting only desktop and
100///   modern mobile devices.
101///
102/// We recommend starting with the most restrictive limits you can and manually increasing the
103/// limits you need boosted. This will let you stay running on all hardware that supports the limits
104/// you need.
105///
106/// Limits "better" than the default must be supported by the adapter and requested when requesting
107/// a device. If limits "better" than the adapter supports are requested, requesting a device will
108/// panic. Once a device is requested, you may only use resources up to the limits requested _even_
109/// if the adapter supports "better" limits.
110///
111/// Requesting limits that are "better" than you need may cause performance to decrease because the
112/// implementation needs to support more than is needed. You should ideally only request exactly
113/// what you need.
114///
115/// Corresponds to [WebGPU `GPUSupportedLimits`](
116/// https://gpuweb.github.io/gpuweb/#gpusupportedlimits).
117///
118/// [`downlevel_defaults()`]: Limits::downlevel_defaults
119#[repr(C)]
120#[derive(Clone, Debug, PartialEq, Eq, Hash)]
121#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
122#[cfg_attr(feature = "serde", serde(rename_all = "camelCase", default))]
123pub struct Limits {
124    /// Maximum allowed value for the `size.width` of a texture created with `TextureDimension::D1`.
125    /// Defaults to 8192. Higher is "better".
126    #[cfg_attr(feature = "serde", serde(rename = "maxTextureDimension1D"))]
127    pub max_texture_dimension_1d: u32,
128    /// Maximum allowed value for the `size.width` and `size.height` of a texture created with `TextureDimension::D2`.
129    /// Defaults to 8192. Higher is "better".
130    #[cfg_attr(feature = "serde", serde(rename = "maxTextureDimension2D"))]
131    pub max_texture_dimension_2d: u32,
132    /// Maximum allowed value for the `size.width`, `size.height`, and `size.depth_or_array_layers`
133    /// of a texture created with `TextureDimension::D3`.
134    /// Defaults to 2048. Higher is "better".
135    #[cfg_attr(feature = "serde", serde(rename = "maxTextureDimension3D"))]
136    pub max_texture_dimension_3d: u32,
137    /// Maximum allowed value for the `size.depth_or_array_layers` of a texture created with `TextureDimension::D2`.
138    /// Defaults to 256. Higher is "better".
139    pub max_texture_array_layers: u32,
140    /// Amount of bind groups that can be attached to a pipeline at the same time. Defaults to 4. Higher is "better".
141    pub max_bind_groups: u32,
142    /// Maximum binding index allowed in `create_bind_group_layout`. Defaults to 1000. Higher is "better".
143    pub max_bindings_per_bind_group: u32,
144    /// Amount of uniform buffer bindings that can be dynamic in a single pipeline. Defaults to 8. Higher is "better".
145    pub max_dynamic_uniform_buffers_per_pipeline_layout: u32,
146    /// Amount of storage buffer bindings that can be dynamic in a single pipeline. Defaults to 4. Higher is "better".
147    pub max_dynamic_storage_buffers_per_pipeline_layout: u32,
148    /// Amount of sampled textures visible in a single shader stage. Defaults to 16. Higher is "better".
149    pub max_sampled_textures_per_shader_stage: u32,
150    /// Amount of samplers visible in a single shader stage. Defaults to 16. Higher is "better".
151    pub max_samplers_per_shader_stage: u32,
152    /// Amount of storage buffers visible in a single shader stage. Defaults to 8. Higher is "better".
153    pub max_storage_buffers_per_shader_stage: u32,
154    /// Amount of storage textures visible in a single shader stage. Defaults to 4. Higher is "better".
155    pub max_storage_textures_per_shader_stage: u32,
156    /// Amount of uniform buffers visible in a single shader stage. Defaults to 12. Higher is "better".
157    pub max_uniform_buffers_per_shader_stage: u32,
158    /// Amount of individual resources within binding arrays that can be accessed in a single shader stage. Applies
159    /// to all types of bindings except samplers.
160    ///
161    /// This "defaults" to 0. However if binding arrays are supported, all devices can support 500,000. Higher is "better".
162    pub max_binding_array_elements_per_shader_stage: u32,
163    /// Amount of individual acceleration structures within binding arrays that can be accessed in a single shader stage.
164    ///
165    /// This "defaults" to 0. Higher is "better".
166    pub max_binding_array_acceleration_structure_elements_per_shader_stage: u32,
167    /// Amount of individual samplers within binding arrays that can be accessed in a single shader stage.
168    ///
169    /// This "defaults" to 0. However if binding arrays are supported, all devices can support 1,000. Higher is "better".
170    pub max_binding_array_sampler_elements_per_shader_stage: u32,
171    /// Maximum size in bytes of a binding to a uniform buffer. Defaults to 64 KiB. Higher is "better".
172    pub max_uniform_buffer_binding_size: u64,
173    /// Maximum size in bytes of a binding to a storage buffer. Defaults to 128 MiB. Higher is "better".
174    pub max_storage_buffer_binding_size: u64,
175    /// Maximum length of `VertexState::buffers` when creating a `RenderPipeline`.
176    /// Defaults to 8. Higher is "better".
177    pub max_vertex_buffers: u32,
178    /// A limit above which buffer allocations are guaranteed to fail.
179    /// Defaults to 256 MiB. Higher is "better".
180    ///
181    /// Buffer allocations below the maximum buffer size may not succeed depending on available memory,
182    /// fragmentation and other factors.
183    pub max_buffer_size: u64,
184    /// Maximum length of `VertexBufferLayout::attributes`, summed over all `VertexState::buffers`,
185    /// when creating a `RenderPipeline`.
186    /// Defaults to 16. Higher is "better".
187    pub max_vertex_attributes: u32,
188    /// Maximum value for `VertexBufferLayout::array_stride` when creating a `RenderPipeline`.
189    /// Defaults to 2048. Higher is "better".
190    pub max_vertex_buffer_array_stride: u32,
191    /// Maximum value for the number of input or output variables for inter-stage communication
192    /// (like vertex outputs or fragment inputs) `@location(…)`s (in WGSL parlance)
193    /// when creating a `RenderPipeline`.
194    /// Defaults to 16. Higher is "better".
195    pub max_inter_stage_shader_variables: u32,
196    /// Required `BufferBindingType::Uniform` alignment for `BufferBinding::offset`
197    /// when creating a `BindGroup`, or for `set_bind_group` `dynamicOffsets`.
198    /// Defaults to 256. Lower is "better".
199    pub min_uniform_buffer_offset_alignment: u32,
200    /// Required `BufferBindingType::Storage` alignment for `BufferBinding::offset`
201    /// when creating a `BindGroup`, or for `set_bind_group` `dynamicOffsets`.
202    /// Defaults to 256. Lower is "better".
203    pub min_storage_buffer_offset_alignment: u32,
204    /// The maximum allowed number of color attachments.
205    pub max_color_attachments: u32,
206    /// The maximum number of bytes necessary to hold one sample (pixel or subpixel) of render
207    /// pipeline output data, across all color attachments as described by [`TextureFormat::target_pixel_byte_cost`]
208    /// and [`TextureFormat::target_component_alignment`]. Defaults to 32. Higher is "better".
209    ///
210    /// ⚠️ `Rgba8Unorm`/`Rgba8Snorm`/`Bgra8Unorm`/`Bgra8Snorm` are deceptively 8 bytes per sample. ⚠️
211    pub max_color_attachment_bytes_per_sample: u32,
212    /// Maximum number of bytes used for workgroup memory in a compute entry point. Defaults to
213    /// 16384. Higher is "better".
214    pub max_compute_workgroup_storage_size: u32,
215    /// Maximum value of the product of the `workgroup_size` dimensions for a compute entry-point.
216    /// Defaults to 256. Higher is "better".
217    pub max_compute_invocations_per_workgroup: u32,
218    /// The maximum value of the `workgroup_size` X dimension for a compute stage `ShaderModule` entry-point.
219    /// Defaults to 256. Higher is "better".
220    pub max_compute_workgroup_size_x: u32,
221    /// The maximum value of the `workgroup_size` Y dimension for a compute stage `ShaderModule` entry-point.
222    /// Defaults to 256. Higher is "better".
223    pub max_compute_workgroup_size_y: u32,
224    /// The maximum value of the `workgroup_size` Z dimension for a compute stage `ShaderModule` entry-point.
225    /// Defaults to 64. Higher is "better".
226    pub max_compute_workgroup_size_z: u32,
227    /// The maximum value for each dimension of a `ComputePass::dispatch(x, y, z)` operation.
228    /// Defaults to 65535. Higher is "better".
229    pub max_compute_workgroups_per_dimension: u32,
230
231    /// Amount of storage available for immediates in bytes. Defaults to 0. Higher is "better".
232    /// Requesting more than 0 during device creation requires [`Features::IMMEDIATES`] to be enabled.
233    ///
234    /// Expect the size to be:
235    /// - Vulkan: 128-256 bytes
236    /// - DX12: 128 bytes
237    /// - Metal: 4096 bytes
238    /// - OpenGL doesn't natively support immediates, and are emulated with uniforms,
239    ///   so this number is less useful but likely 256.
240    pub max_immediate_size: u32,
241    /// Maximum number of live non-sampler bindings.
242    ///
243    /// <div class="warning">
244    /// The default value is **1_000_000**, On systems with integrated GPUs (iGPUs)—particularly on Windows using the D3D12
245    /// backend—this can lead to significant system RAM consumption since iGPUs share system memory directly with the CPU.
246    /// </div>
247    ///
248    /// This limit only affects the d3d12 backend. Using a large number will allow the device
249    /// to create many bind groups at the cost of a large up-front allocation at device creation.
250    pub max_non_sampler_bindings: u32,
251
252    /// The maximum total value for a `RenderPass::draw_mesh_tasks(x, y, z)` operation or the
253    /// `@builtin(mesh_task_size)` returned from a task shader.  Higher is "better".
254    pub max_task_mesh_workgroup_total_count: u32,
255    /// The maximum value for each dimension of a `RenderPass::draw_mesh_tasks(x, y, z)` operation.
256    /// Also for task shader outputs. Higher is "better".
257    pub max_task_mesh_workgroups_per_dimension: u32,
258    // These are fundamentally different. It is very common for limits on mesh shaders to be much lower.
259    /// Maximum total number of invocations, or threads, per task shader workgroup. Higher is "better".
260    pub max_task_invocations_per_workgroup: u32,
261    /// The maximum value for each dimension of a task shader's workgroup size. Higher is "better".
262    pub max_task_invocations_per_dimension: u32,
263    /// Maximum total number of invocations, or threads, per mesh shader workgroup. Higher is "better".
264    pub max_mesh_invocations_per_workgroup: u32,
265    /// The maximum value for each dimension of a mesh shader's workgroup size. Higher is "better".
266    pub max_mesh_invocations_per_dimension: u32,
267
268    /// The maximum size of the payload passed from task to mesh shader. Higher is "better".
269    pub max_task_payload_size: u32,
270    /// The maximum number of vertices that a mesh shader may output. Higher is "better".
271    pub max_mesh_output_vertices: u32,
272    /// The maximum number of primitives that a mesh shader may output. Higher is "better".
273    pub max_mesh_output_primitives: u32,
274    /// The maximum number of layers that can be output from a mesh shader. Higher is "better".
275    /// See [#8509](https://github.com/gfx-rs/wgpu/issues/8509).
276    pub max_mesh_output_layers: u32,
277    /// The maximum number of views that can be used by a mesh shader in multiview rendering.
278    /// Higher is "better".
279    pub max_mesh_multiview_view_count: u32,
280
281    /// The maximum number of primitive (ex: triangles, aabbs) a BLAS is allowed to have. Requesting
282    /// more than 0 during device creation only makes sense if [`Features::EXPERIMENTAL_RAY_QUERY`]
283    /// is enabled.
284    pub max_blas_primitive_count: u32,
285    /// The maximum number of geometry descriptors a BLAS is allowed to have. Requesting
286    /// more than 0 during device creation only makes sense if [`Features::EXPERIMENTAL_RAY_QUERY`]
287    /// is enabled.
288    pub max_blas_geometry_count: u32,
289    /// The maximum number of instances a TLAS is allowed to have. Requesting more than 0 during
290    /// device creation only makes sense if [`Features::EXPERIMENTAL_RAY_QUERY`]
291    /// is enabled.
292    pub max_tlas_instance_count: u32,
293    /// The maximum number of acceleration structures allowed to be used in a shader stage.
294    /// Requesting more than 0 during device creation only makes sense if [`Features::EXPERIMENTAL_RAY_QUERY`]
295    /// is enabled.
296    pub max_acceleration_structures_per_shader_stage: u32,
297
298    /// The maximum number of views that can be used in multiview rendering
299    pub max_multiview_view_count: u32,
300}
301
302impl Default for Limits {
303    fn default() -> Self {
304        Self::defaults()
305    }
306}
307
308impl Limits {
309    /// These default limits are guaranteed to to work on all modern
310    /// backends and guaranteed to be supported by WebGPU
311    ///
312    /// Those limits are as follows:
313    /// ```rust
314    /// # use wgpu_types::Limits;
315    /// assert_eq!(Limits::defaults(), Limits {
316    ///     max_texture_dimension_1d: 8192,
317    ///     max_texture_dimension_2d: 8192,
318    ///     max_texture_dimension_3d: 2048,
319    ///     max_texture_array_layers: 256,
320    ///     max_bind_groups: 4,
321    ///     max_bindings_per_bind_group: 1000,
322    ///     max_dynamic_uniform_buffers_per_pipeline_layout: 8,
323    ///     max_dynamic_storage_buffers_per_pipeline_layout: 4,
324    ///     max_sampled_textures_per_shader_stage: 16,
325    ///     max_samplers_per_shader_stage: 16,
326    ///     max_storage_buffers_per_shader_stage: 8,
327    ///     max_storage_textures_per_shader_stage: 4,
328    ///     max_uniform_buffers_per_shader_stage: 12,
329    ///     max_binding_array_elements_per_shader_stage: 0,
330    ///     max_binding_array_acceleration_structure_elements_per_shader_stage: 0,
331    ///     max_binding_array_sampler_elements_per_shader_stage: 0,
332    ///     max_uniform_buffer_binding_size: 64 << 10, // (64 KiB)
333    ///     max_storage_buffer_binding_size: 128 << 20, // (128 MiB)
334    ///     max_vertex_buffers: 8,
335    ///     max_buffer_size: 256 << 20, // (256 MiB)
336    ///     max_vertex_attributes: 16,
337    ///     max_vertex_buffer_array_stride: 2048,
338    ///     max_inter_stage_shader_variables: 16,
339    ///     min_uniform_buffer_offset_alignment: 256,
340    ///     min_storage_buffer_offset_alignment: 256,
341    ///     max_color_attachments: 8,
342    ///     max_color_attachment_bytes_per_sample: 32,
343    ///     max_compute_workgroup_storage_size: 16384,
344    ///     max_compute_invocations_per_workgroup: 256,
345    ///     max_compute_workgroup_size_x: 256,
346    ///     max_compute_workgroup_size_y: 256,
347    ///     max_compute_workgroup_size_z: 64,
348    ///     max_compute_workgroups_per_dimension: 65535,
349    ///     max_immediate_size: 0,
350    ///     max_non_sampler_bindings: 1_000_000,
351    ///     max_task_mesh_workgroup_total_count: 0,
352    ///     max_task_mesh_workgroups_per_dimension: 0,
353    ///     max_task_invocations_per_workgroup: 0,
354    ///     max_task_invocations_per_dimension: 0,
355    ///     max_mesh_invocations_per_workgroup: 0,
356    ///     max_mesh_invocations_per_dimension: 0,
357    ///     max_task_payload_size: 0,
358    ///     max_mesh_output_vertices: 0,
359    ///     max_mesh_output_primitives: 0,
360    ///     max_mesh_output_layers: 0,
361    ///     max_mesh_multiview_view_count: 0,
362    ///     max_blas_primitive_count: 0,
363    ///     max_blas_geometry_count: 0,
364    ///     max_tlas_instance_count: 0,
365    ///     max_acceleration_structures_per_shader_stage: 0,
366    ///     max_multiview_view_count: 0,
367    /// });
368    /// ```
369    ///
370    /// Rust doesn't allow const in trait implementations, so we break this out
371    /// to allow reusing these defaults in const contexts
372    #[must_use]
373    pub const fn defaults() -> Self {
374        Self {
375            max_texture_dimension_1d: 8192,
376            max_texture_dimension_2d: 8192,
377            max_texture_dimension_3d: 2048,
378            max_texture_array_layers: 256,
379            max_bind_groups: 4,
380            max_bindings_per_bind_group: 1000,
381            max_dynamic_uniform_buffers_per_pipeline_layout: 8,
382            max_dynamic_storage_buffers_per_pipeline_layout: 4,
383            max_sampled_textures_per_shader_stage: 16,
384            max_samplers_per_shader_stage: 16,
385            max_storage_buffers_per_shader_stage: 8,
386            max_storage_textures_per_shader_stage: 4,
387            max_uniform_buffers_per_shader_stage: 12,
388            max_binding_array_elements_per_shader_stage: 0,
389            max_binding_array_acceleration_structure_elements_per_shader_stage: 0,
390            max_binding_array_sampler_elements_per_shader_stage: 0,
391            max_uniform_buffer_binding_size: 64 << 10, // (64 KiB)
392            max_storage_buffer_binding_size: 128 << 20, // (128 MiB)
393            max_vertex_buffers: 8,
394            max_buffer_size: 256 << 20, // (256 MiB)
395            max_vertex_attributes: 16,
396            max_vertex_buffer_array_stride: 2048,
397            max_inter_stage_shader_variables: 16,
398            min_uniform_buffer_offset_alignment: 256,
399            min_storage_buffer_offset_alignment: 256,
400            max_color_attachments: 8,
401            max_color_attachment_bytes_per_sample: 32,
402            max_compute_workgroup_storage_size: 16384,
403            max_compute_invocations_per_workgroup: 256,
404            max_compute_workgroup_size_x: 256,
405            max_compute_workgroup_size_y: 256,
406            max_compute_workgroup_size_z: 64,
407            max_compute_workgroups_per_dimension: 65535,
408            max_immediate_size: 0,
409            max_non_sampler_bindings: 1_000_000,
410
411            max_task_mesh_workgroup_total_count: 0,
412            max_task_mesh_workgroups_per_dimension: 0,
413            max_task_invocations_per_workgroup: 0,
414            max_task_invocations_per_dimension: 0,
415            max_mesh_invocations_per_workgroup: 0,
416            max_mesh_invocations_per_dimension: 0,
417            max_task_payload_size: 0,
418            max_mesh_output_vertices: 0,
419            max_mesh_output_primitives: 0,
420            max_mesh_output_layers: 0,
421            max_mesh_multiview_view_count: 0,
422
423            max_blas_primitive_count: 0,
424            max_blas_geometry_count: 0,
425            max_tlas_instance_count: 0,
426            max_acceleration_structures_per_shader_stage: 0,
427
428            max_multiview_view_count: 0,
429        }
430    }
431
432    /// These default limits are guaranteed to be compatible with GLES-3.1, and D3D11
433    ///
434    /// Those limits are as follows (different from default are marked with *):
435    /// ```rust
436    /// # use wgpu_types::Limits;
437    /// assert_eq!(Limits::downlevel_defaults(), Limits {
438    ///     max_texture_dimension_1d: 2048, // *
439    ///     max_texture_dimension_2d: 2048, // *
440    ///     max_texture_dimension_3d: 256, // *
441    ///     max_texture_array_layers: 256,
442    ///     max_bind_groups: 4,
443    ///     max_bindings_per_bind_group: 1000,
444    ///     max_dynamic_uniform_buffers_per_pipeline_layout: 8,
445    ///     max_dynamic_storage_buffers_per_pipeline_layout: 4,
446    ///     max_sampled_textures_per_shader_stage: 16,
447    ///     max_samplers_per_shader_stage: 16,
448    ///     max_storage_buffers_per_shader_stage: 4, // *
449    ///     max_storage_textures_per_shader_stage: 4,
450    ///     max_uniform_buffers_per_shader_stage: 12,
451    ///     max_binding_array_elements_per_shader_stage: 0,
452    ///     max_binding_array_acceleration_structure_elements_per_shader_stage: 0,
453    ///     max_binding_array_sampler_elements_per_shader_stage: 0,
454    ///     max_uniform_buffer_binding_size: 16 << 10, // * (16 KiB)
455    ///     max_storage_buffer_binding_size: 128 << 20, // (128 MiB)
456    ///     max_vertex_buffers: 8,
457    ///     max_vertex_attributes: 16,
458    ///     max_vertex_buffer_array_stride: 2048,
459    ///     max_immediate_size: 0,
460    ///     min_uniform_buffer_offset_alignment: 256,
461    ///     min_storage_buffer_offset_alignment: 256,
462    ///     max_inter_stage_shader_variables: 15,
463    ///     max_color_attachments: 4,
464    ///     max_color_attachment_bytes_per_sample: 32,
465    ///     max_compute_workgroup_storage_size: 16352, // *
466    ///     max_compute_invocations_per_workgroup: 256,
467    ///     max_compute_workgroup_size_x: 256,
468    ///     max_compute_workgroup_size_y: 256,
469    ///     max_compute_workgroup_size_z: 64,
470    ///     max_compute_workgroups_per_dimension: 65535,
471    ///     max_buffer_size: 256 << 20, // (256 MiB)
472    ///     max_non_sampler_bindings: 1_000_000,
473    ///
474    ///     max_task_mesh_workgroup_total_count: 0,
475    ///     max_task_mesh_workgroups_per_dimension: 0,
476    ///     max_task_invocations_per_workgroup: 0,
477    ///     max_task_invocations_per_dimension: 0,
478    ///     max_mesh_invocations_per_workgroup: 0,
479    ///     max_mesh_invocations_per_dimension: 0,
480    ///     max_task_payload_size: 0,
481    ///     max_mesh_output_vertices: 0,
482    ///     max_mesh_output_primitives: 0,
483    ///     max_mesh_output_layers: 0,
484    ///     max_mesh_multiview_view_count: 0,
485    ///
486    ///     max_blas_primitive_count: 0,
487    ///     max_blas_geometry_count: 0,
488    ///     max_tlas_instance_count: 0,
489    ///     max_acceleration_structures_per_shader_stage: 0,
490    ///
491    ///     max_multiview_view_count: 0,
492    /// });
493    /// ```
494    #[must_use]
495    pub const fn downlevel_defaults() -> Self {
496        Self {
497            max_texture_dimension_1d: 2048,
498            max_texture_dimension_2d: 2048,
499            max_texture_dimension_3d: 256,
500            max_storage_buffers_per_shader_stage: 4,
501            max_uniform_buffer_binding_size: 16 << 10, // (16 KiB)
502            max_inter_stage_shader_variables: 15,
503            max_color_attachments: 4,
504            // see: https://developer.apple.com/metal/Metal-Feature-Set-Tables.pdf#page=7
505            max_compute_workgroup_storage_size: 16352,
506            ..Self::defaults()
507        }
508    }
509
510    /// These default limits are guaranteed to be compatible with GLES-3.0, and D3D11, and WebGL2
511    ///
512    /// Those limits are as follows (different from `downlevel_defaults` are marked with +,
513    /// *'s from `downlevel_defaults` shown as well.):
514    /// ```rust
515    /// # use wgpu_types::Limits;
516    /// assert_eq!(Limits::downlevel_webgl2_defaults(), Limits {
517    ///     max_texture_dimension_1d: 2048, // *
518    ///     max_texture_dimension_2d: 2048, // *
519    ///     max_texture_dimension_3d: 256, // *
520    ///     max_texture_array_layers: 256,
521    ///     max_bind_groups: 4,
522    ///     max_bindings_per_bind_group: 1000,
523    ///     max_dynamic_uniform_buffers_per_pipeline_layout: 8,
524    ///     max_dynamic_storage_buffers_per_pipeline_layout: 0, // +
525    ///     max_sampled_textures_per_shader_stage: 16,
526    ///     max_samplers_per_shader_stage: 16,
527    ///     max_storage_buffers_per_shader_stage: 0, // * +
528    ///     max_storage_textures_per_shader_stage: 0, // +
529    ///     max_uniform_buffers_per_shader_stage: 11, // +
530    ///     max_binding_array_elements_per_shader_stage: 0,
531    ///     max_binding_array_acceleration_structure_elements_per_shader_stage: 0,
532    ///     max_binding_array_sampler_elements_per_shader_stage: 0,
533    ///     max_uniform_buffer_binding_size: 16 << 10, // * (16 KiB)
534    ///     max_storage_buffer_binding_size: 0, // * +
535    ///     max_vertex_buffers: 8,
536    ///     max_vertex_attributes: 16,
537    ///     max_vertex_buffer_array_stride: 255, // +
538    ///     max_immediate_size: 0,
539    ///     min_uniform_buffer_offset_alignment: 256,
540    ///     min_storage_buffer_offset_alignment: 256,
541    ///     max_inter_stage_shader_variables: 15,
542    ///     max_color_attachments: 4,
543    ///     max_color_attachment_bytes_per_sample: 32,
544    ///     max_compute_workgroup_storage_size: 0, // +
545    ///     max_compute_invocations_per_workgroup: 0, // +
546    ///     max_compute_workgroup_size_x: 0, // +
547    ///     max_compute_workgroup_size_y: 0, // +
548    ///     max_compute_workgroup_size_z: 0, // +
549    ///     max_compute_workgroups_per_dimension: 0, // +
550    ///     max_buffer_size: 256 << 20, // (256 MiB),
551    ///     max_non_sampler_bindings: 1_000_000,
552    ///
553    ///     max_task_mesh_workgroup_total_count: 0,
554    ///     max_task_mesh_workgroups_per_dimension: 0,
555    ///     max_task_invocations_per_workgroup: 0,
556    ///     max_task_invocations_per_dimension: 0,
557    ///     max_mesh_invocations_per_workgroup: 0,
558    ///     max_mesh_invocations_per_dimension: 0,
559    ///     max_task_payload_size: 0,
560    ///     max_mesh_output_vertices: 0,
561    ///     max_mesh_output_primitives: 0,
562    ///     max_mesh_output_layers: 0,
563    ///     max_mesh_multiview_view_count: 0,
564    ///
565    ///     max_blas_primitive_count: 0,
566    ///     max_blas_geometry_count: 0,
567    ///     max_tlas_instance_count: 0,
568    ///     max_acceleration_structures_per_shader_stage: 0,
569    ///
570    ///     max_multiview_view_count: 0,
571    /// });
572    /// ```
573    #[must_use]
574    pub const fn downlevel_webgl2_defaults() -> Self {
575        Self {
576            max_uniform_buffers_per_shader_stage: 11,
577            max_storage_buffers_per_shader_stage: 0,
578            max_storage_textures_per_shader_stage: 0,
579            max_dynamic_storage_buffers_per_pipeline_layout: 0,
580            max_storage_buffer_binding_size: 0,
581            max_vertex_buffer_array_stride: 255,
582            max_compute_workgroup_storage_size: 0,
583            max_compute_invocations_per_workgroup: 0,
584            max_compute_workgroup_size_x: 0,
585            max_compute_workgroup_size_y: 0,
586            max_compute_workgroup_size_z: 0,
587            max_compute_workgroups_per_dimension: 0,
588
589            // Value supported by Intel Celeron B830 on Windows (OpenGL 3.1)
590            max_inter_stage_shader_variables: 15,
591
592            // Most of the values should be the same as the downlevel defaults
593            ..Self::downlevel_defaults()
594        }
595    }
596
597    /// Modify the current limits to use the resolution limits of the other.
598    ///
599    /// This is useful because the swapchain might need to be larger than any other image in the application.
600    ///
601    /// If your application only needs 512x512, you might be running on a 4k display and need extremely high resolution limits.
602    #[must_use]
603    pub const fn using_resolution(self, other: Self) -> Self {
604        Self {
605            max_texture_dimension_1d: other.max_texture_dimension_1d,
606            max_texture_dimension_2d: other.max_texture_dimension_2d,
607            max_texture_dimension_3d: other.max_texture_dimension_3d,
608            ..self
609        }
610    }
611
612    /// Modify the current limits to use the buffer alignment limits of the adapter.
613    ///
614    /// This is useful for when you'd like to dynamically use the "best" supported buffer alignments.
615    #[must_use]
616    pub const fn using_alignment(self, other: Self) -> Self {
617        Self {
618            min_uniform_buffer_offset_alignment: other.min_uniform_buffer_offset_alignment,
619            min_storage_buffer_offset_alignment: other.min_storage_buffer_offset_alignment,
620            ..self
621        }
622    }
623
624    /// The minimum guaranteed limits for acceleration structures if you enable [`Features::EXPERIMENTAL_RAY_QUERY`]
625    #[must_use]
626    pub const fn using_minimum_supported_acceleration_structure_values(self) -> Self {
627        Self {
628            max_blas_geometry_count: (1 << 24) - 1, // 2^24 - 1: Vulkan's minimum
629            max_tlas_instance_count: (1 << 24) - 1, // 2^24 - 1: Vulkan's minimum
630            max_blas_primitive_count: 1 << 28,      // 2^28: Metal's minimum
631            max_acceleration_structures_per_shader_stage: 16, // Vulkan's minimum
632            ..self
633        }
634    }
635
636    /// Modify the current limits to use the acceleration structure limits of `other` (`other` could
637    /// be the limits of the adapter).
638    #[must_use]
639    pub const fn using_acceleration_structure_values(self, other: Self) -> Self {
640        Self {
641            max_blas_geometry_count: other.max_blas_geometry_count,
642            max_tlas_instance_count: other.max_tlas_instance_count,
643            max_blas_primitive_count: other.max_blas_primitive_count,
644            max_acceleration_structures_per_shader_stage: other
645                .max_acceleration_structures_per_shader_stage,
646            ..self
647        }
648    }
649
650    /// The recommended minimum limits for mesh shaders if you enable [`Features::EXPERIMENTAL_MESH_SHADER`]
651    ///
652    /// These are chosen somewhat arbitrarily. They are small enough that they should cover all physical devices,
653    /// but not necessarily all use cases.
654    #[must_use]
655    pub const fn using_recommended_minimum_mesh_shader_values(self) -> Self {
656        Self {
657            // This limitation comes from metal
658            max_task_mesh_workgroup_total_count: 1024,
659            // This is a DirectX limitation
660            max_task_mesh_workgroups_per_dimension: 256,
661            // Nvidia limit on vulkan
662            max_task_invocations_per_workgroup: 128,
663            max_task_invocations_per_dimension: 64,
664
665            // DX12 limitation, revisit for vulkan
666            max_mesh_invocations_per_workgroup: 128,
667            max_mesh_invocations_per_dimension: 128,
668
669            // Metal specifies this as its max
670            max_task_payload_size: 16384 - 32,
671            // DX12 limitation, revisit for vulkan
672            max_mesh_output_vertices: 256,
673            max_mesh_output_primitives: 256,
674            // llvmpipe once again requires this to be 8. An RTX 3060 supports well over 1024.
675            // Also DX12 vaguely suggests going over this is illegal in some cases.
676            max_mesh_output_layers: 8,
677            // llvmpipe reports 0 multiview count, which just means no multiview is allowed
678            max_mesh_multiview_view_count: 0,
679            ..self
680        }
681    }
682
683    /// Compares every limits within self is within the limits given in `allowed`.
684    ///
685    /// If you need detailed information on failures, look at [`Limits::check_limits_with_fail_fn`].
686    #[must_use]
687    pub fn check_limits(&self, allowed: &Self) -> bool {
688        let mut within = true;
689        self.check_limits_with_fail_fn(allowed, true, |_, _, _| within = false);
690        within
691    }
692
693    /// Compares every limits within self is within the limits given in `allowed`.
694    /// For an easy to use binary choice, use [`Limits::check_limits`].
695    ///
696    /// If a value is not within the allowed limit, this function calls the `fail_fn`
697    /// with the:
698    ///  - limit name
699    ///  - self's limit
700    ///  - allowed's limit.
701    ///
702    /// If fatal is true, a single failure bails out the comparison after a single failure.
703    pub fn check_limits_with_fail_fn(
704        &self,
705        allowed: &Self,
706        fatal: bool,
707        mut fail_fn: impl FnMut(&'static str, u64, u64),
708    ) {
709        macro_rules! check_with_fail_fn {
710            ($name:ident, $ordering:expr) => {
711                let invalid_ord = $ordering.reverse();
712                if self.$name.cmp(&allowed.$name) == invalid_ord {
713                    fail_fn(stringify!($name), self.$name as u64, allowed.$name as u64);
714                    if fatal {
715                        return;
716                    }
717                }
718            };
719        }
720
721        with_limits!(check_with_fail_fn);
722    }
723
724    /// For each limit in `other` that is better than the value in `self`,
725    /// replace the value in `self` with the value from `other`.
726    ///
727    /// A request for a limit value less than the WebGPU-specified default must
728    /// be ignored. This function is used to clamp such requests to the default
729    /// value.
730    ///
731    /// This function is not for clamping requests for values beyond the
732    /// supported limits. For that purpose the desired function would be
733    /// `or_worse_values_from`.
734    #[must_use]
735    pub fn or_better_values_from(mut self, other: &Self) -> Self {
736        macro_rules! or_better_value_from {
737            ($name:ident, $ordering:expr) => {
738                match $ordering {
739                    // Limits that are maximum values (most of them)
740                    Ordering::Less => self.$name = self.$name.max(other.$name),
741                    // Limits that are minimum values
742                    Ordering::Greater => self.$name = self.$name.min(other.$name),
743                    Ordering::Equal => unreachable!(),
744                }
745            };
746        }
747
748        with_limits!(or_better_value_from);
749
750        self
751    }
752
753    /// For each limit in `other` that is worse than the value in `self`,
754    /// replace the value in `self` with the value from `other`.
755    ///
756    /// This function is for clamping requests for values beyond the
757    /// supported limits.
758    #[must_use]
759    pub fn or_worse_values_from(mut self, other: &Self) -> Self {
760        macro_rules! or_worse_value_from {
761            ($name:ident, $ordering:expr) => {
762                match $ordering {
763                    // Limits that are maximum values (most of them)
764                    Ordering::Less => self.$name = self.$name.min(other.$name),
765                    // Limits that are minimum values
766                    Ordering::Greater => self.$name = self.$name.max(other.$name),
767                    Ordering::Equal => unreachable!(),
768                }
769            };
770        }
771
772        with_limits!(or_worse_value_from);
773
774        self
775    }
776}
777
778/// Represents the sets of additional limits on an adapter,
779/// which take place when running on downlevel backends.
780#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
781#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
782pub struct DownlevelLimits {}
783
784#[allow(clippy::derivable_impls)]
785impl Default for DownlevelLimits {
786    fn default() -> Self {
787        DownlevelLimits {}
788    }
789}
790
791/// Lists various ways the underlying platform does not conform to the WebGPU standard.
792#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
793#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
794pub struct DownlevelCapabilities {
795    /// Combined boolean flags.
796    pub flags: DownlevelFlags,
797    /// Additional limits
798    pub limits: DownlevelLimits,
799    /// Which collections of features shaders support. Defined in terms of D3D's shader models.
800    pub shader_model: ShaderModel,
801}
802
803impl Default for DownlevelCapabilities {
804    fn default() -> Self {
805        Self {
806            flags: DownlevelFlags::all(),
807            limits: DownlevelLimits::default(),
808            shader_model: ShaderModel::Sm5,
809        }
810    }
811}
812
813impl DownlevelCapabilities {
814    /// Returns true if the underlying platform offers complete support of the baseline WebGPU standard.
815    ///
816    /// If this returns false, some parts of the API will result in validation errors where they would not normally.
817    /// These parts can be determined by the values in this structure.
818    #[must_use]
819    pub fn is_webgpu_compliant(&self) -> bool {
820        self.flags.contains(DownlevelFlags::compliant())
821            && self.limits == DownlevelLimits::default()
822            && self.shader_model >= ShaderModel::Sm5
823    }
824}
825
826bitflags::bitflags! {
827    /// Binary flags listing features that may or may not be present on downlevel adapters.
828    ///
829    /// A downlevel adapter is a GPU adapter that wgpu supports, but with potentially limited
830    /// features, due to the lack of hardware feature support.
831    ///
832    /// Flags that are **not** present for a downlevel adapter or device usually indicates
833    /// non-compliance with the WebGPU specification, but not always.
834    ///
835    /// You can check whether a set of flags is compliant through the
836    /// [`DownlevelCapabilities::is_webgpu_compliant()`] function.
837    #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
838    #[cfg_attr(feature = "serde", serde(transparent))]
839    #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
840    pub struct DownlevelFlags: u32 {
841        /// The device supports compiling and using compute shaders.
842        ///
843        /// WebGL2, and GLES3.0 devices do not support compute.
844        const COMPUTE_SHADERS = 1 << 0;
845        /// Supports binding storage buffers and textures to fragment shaders.
846        const FRAGMENT_WRITABLE_STORAGE = 1 << 1;
847        /// Supports indirect drawing and dispatching.
848        ///
849        /// [`Self::COMPUTE_SHADERS`] must be present for this flag.
850        ///
851        /// WebGL2, GLES 3.0, and Metal on Apple1/Apple2 GPUs do not support indirect.
852        const INDIRECT_EXECUTION = 1 << 2;
853        /// Supports non-zero `base_vertex` parameter to direct indexed draw calls.
854        ///
855        /// Indirect calls, if supported, always support non-zero `base_vertex`.
856        ///
857        /// Supported by:
858        /// - Vulkan
859        /// - DX12
860        /// - Metal on Apple3+ or Mac1+
861        /// - OpenGL 3.2+
862        /// - OpenGL ES 3.2
863        const BASE_VERTEX = 1 << 3;
864        /// Supports reading from a depth/stencil texture while using it as a read-only
865        /// depth/stencil attachment.
866        ///
867        /// The WebGL2 and GLES backends do not support RODS.
868        const READ_ONLY_DEPTH_STENCIL = 1 << 4;
869        /// Supports textures with mipmaps which have a non power of two size.
870        const NON_POWER_OF_TWO_MIPMAPPED_TEXTURES = 1 << 5;
871        /// Supports textures that are cube arrays.
872        const CUBE_ARRAY_TEXTURES = 1 << 6;
873        /// Supports comparison samplers.
874        const COMPARISON_SAMPLERS = 1 << 7;
875        /// Supports different blend operations per color attachment.
876        const INDEPENDENT_BLEND = 1 << 8;
877        /// Supports storage buffers in vertex shaders.
878        const VERTEX_STORAGE = 1 << 9;
879
880        /// Supports samplers with anisotropic filtering. Note this isn't actually required by
881        /// WebGPU, the implementation is allowed to completely ignore aniso clamp. This flag is
882        /// here for native backends so they can communicate to the user of aniso is enabled.
883        ///
884        /// All backends and all devices support anisotropic filtering.
885        const ANISOTROPIC_FILTERING = 1 << 10;
886
887        /// Supports storage buffers in fragment shaders.
888        const FRAGMENT_STORAGE = 1 << 11;
889
890        /// Supports sample-rate shading.
891        const MULTISAMPLED_SHADING = 1 << 12;
892
893        /// Supports copies between depth textures and buffers.
894        ///
895        /// GLES/WebGL don't support this.
896        const DEPTH_TEXTURE_AND_BUFFER_COPIES = 1 << 13;
897
898        /// Supports all the texture usages described in WebGPU. If this isn't supported, you
899        /// should call `get_texture_format_features` to get how you can use textures of a given format
900        const WEBGPU_TEXTURE_FORMAT_SUPPORT = 1 << 14;
901
902        /// Supports buffer bindings with sizes that aren't a multiple of 16.
903        ///
904        /// WebGL doesn't support this.
905        const BUFFER_BINDINGS_NOT_16_BYTE_ALIGNED = 1 << 15;
906
907        /// Supports buffers to combine [`BufferUsages::INDEX`] with usages other than [`BufferUsages::COPY_DST`] and [`BufferUsages::COPY_SRC`].
908        /// Furthermore, in absence of this feature it is not allowed to copy index buffers from/to buffers with a set of usage flags containing
909        /// [`BufferUsages::VERTEX`]/[`BufferUsages::UNIFORM`]/[`BufferUsages::STORAGE`] or [`BufferUsages::INDIRECT`].
910        ///
911        /// WebGL doesn't support this.
912        const UNRESTRICTED_INDEX_BUFFER = 1 << 16;
913
914        /// Supports full 32-bit range indices (2^32-1 as opposed to 2^24-1 without this flag)
915        ///
916        /// Corresponds to Vulkan's `VkPhysicalDeviceFeatures.fullDrawIndexUint32`
917        const FULL_DRAW_INDEX_UINT32 = 1 << 17;
918
919        /// Supports depth bias clamping
920        ///
921        /// Corresponds to Vulkan's `VkPhysicalDeviceFeatures.depthBiasClamp`
922        const DEPTH_BIAS_CLAMP = 1 << 18;
923
924        /// Supports specifying which view format values are allowed when create_view() is called on a texture.
925        ///
926        /// The WebGL and GLES backends doesn't support this.
927        const VIEW_FORMATS = 1 << 19;
928
929        /// With this feature not present, there are the following restrictions on `Queue::copy_external_image_to_texture`:
930        /// - The source must not be [`web_sys::OffscreenCanvas`]
931        /// - [`CopyExternalImageSourceInfo::origin`] must be zero.
932        /// - [`CopyExternalImageDestInfo::color_space`] must be srgb.
933        /// - If the source is an [`web_sys::ImageBitmap`]:
934        ///   - [`CopyExternalImageSourceInfo::flip_y`] must be false.
935        ///   - [`CopyExternalImageDestInfo::premultiplied_alpha`] must be false.
936        ///
937        /// WebGL doesn't support this. WebGPU does.
938        const UNRESTRICTED_EXTERNAL_TEXTURE_COPIES = 1 << 20;
939
940        /// Supports specifying which view formats are allowed when calling create_view on the texture returned by
941        /// `Surface::get_current_texture`.
942        ///
943        /// The GLES/WebGL and Vulkan on Android doesn't support this.
944        const SURFACE_VIEW_FORMATS = 1 << 21;
945
946        /// If this is true, calls to `CommandEncoder::resolve_query_set` will be performed on the queue timeline.
947        ///
948        /// If this is false, calls to `CommandEncoder::resolve_query_set` will be performed on the device (i.e. cpu) timeline
949        /// and will block that timeline until the query has data. You may work around this limitation by waiting until the submit
950        /// whose queries you are resolving is fully finished (through use of `queue.on_submitted_work_done`) and only
951        /// then submitting the resolve_query_set command. The queries will be guaranteed finished, so will not block.
952        ///
953        /// Supported by:
954        /// - Vulkan,
955        /// - DX12
956        /// - Metal
957        /// - OpenGL 4.4+
958        ///
959        /// Not Supported by:
960        /// - GL ES / WebGL
961        const NONBLOCKING_QUERY_RESOLVE = 1 << 22;
962
963        /// Allows shaders to use `quantizeToF16`, `pack2x16float`, and `unpack2x16float`, which
964        /// operate on `f16`-precision values stored in `f32`s.
965        ///
966        /// Not supported by Vulkan on Mesa when [`Features::SHADER_F16`] is absent.
967        const SHADER_F16_IN_F32 = 1 << 23;
968    }
969}
970
971impl DownlevelFlags {
972    /// All flags that indicate if the backend is WebGPU compliant
973    #[must_use]
974    pub const fn compliant() -> Self {
975        // We use manual bit twiddling to make this a const fn as `Sub` and `.remove` aren't const
976
977        // WebGPU doesn't actually require aniso
978        Self::from_bits_truncate(Self::all().bits() & !Self::ANISOTROPIC_FILTERING.bits())
979    }
980}
981
982/// Collections of shader features a device supports if they support less than WebGPU normally allows.
983// TODO: Fill out the differences between shader models more completely
984#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
985#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
986pub enum ShaderModel {
987    /// Extremely limited shaders, including a total instruction limit.
988    Sm2,
989    /// Missing minor features and storage images.
990    Sm4,
991    /// WebGPU supports shader module 5.
992    Sm5,
993}