From aa2b7907c020c4f046ca697895f9be1a70b27a45 Mon Sep 17 00:00:00 2001 From: teoxoy <28601907+teoxoy@users.noreply.github.com> Date: Wed, 24 Jun 2026 17:06:42 +0200 Subject: [PATCH] [core] filter native-only features and limits if `STRICT_WEBGPU_COMPLIANCE` is set --- tests/tests/wgpu-gpu/adapter.rs | 4 +- wgpu-core/src/instance.rs | 40 ++++++++++++++- wgpu-core/src/limits.rs | 2 +- wgpu-types/src/limits.rs | 88 +++++++++++++++++++++++++++++++++ 4 files changed, 130 insertions(+), 4 deletions(-) diff --git a/tests/tests/wgpu-gpu/adapter.rs b/tests/tests/wgpu-gpu/adapter.rs index 6af483605..73f307e5e 100644 --- a/tests/tests/wgpu-gpu/adapter.rs +++ b/tests/tests/wgpu-gpu/adapter.rs @@ -16,5 +16,7 @@ static STRICT_WEBGPU_COMPLIANCE_ADAPTER: GpuTestConfiguration = GpuTestConfigura .adapter .get_downlevel_capabilities() .is_webgpu_compliant()); - assert!(wgpu::Limits::defaults().check_limits(&ctx.adapter.limits())); + let mut limits = wgpu::Limits::defaults(); + limits.zero_native_only(); + assert!(limits.check_limits(&ctx.adapter.limits())); }); diff --git a/wgpu-core/src/instance.rs b/wgpu-core/src/instance.rs index 1c38e2d07..26a3050a4 100644 --- a/wgpu-core/src/instance.rs +++ b/wgpu-core/src/instance.rs @@ -451,6 +451,14 @@ impl Instance { self.adjust_limits_for_indirect_validation(&mut raw.capabilities.limits); raw }) + .map(|mut raw| { + filter_features_and_limits( + self.flags, + &mut raw.features, + &mut raw.capabilities.limits, + ); + raw + }) .filter(|raw| self.adapter_allowed(raw)) .filter_map(|raw| { if apply_limit_buckets { @@ -543,6 +551,14 @@ impl Instance { self.adjust_limits_for_indirect_validation(&mut raw.capabilities.limits); raw }) + .map(|mut raw| { + filter_features_and_limits( + self.flags, + &mut raw.features, + &mut raw.capabilities.limits, + ); + raw + }) .filter(|raw| self.adapter_allowed(raw)); if desc.apply_limit_buckets { @@ -874,6 +890,13 @@ impl Adapter { desc: &DeviceDescriptor, instance_flags: InstanceFlags, ) -> Result<(Arc, Arc), RequestDeviceError> { + let mut desc = desc.clone(); + filter_features_and_limits( + instance_flags, + &mut desc.required_features, + &mut desc.required_limits, + ); + // Verify all features were exposed by the adapter if !self.raw.features.contains(desc.required_features) { return Err(RequestDeviceError::UnsupportedFeature( @@ -927,7 +950,7 @@ impl Adapter { } .map_err(DeviceError::from_hal)?; - self.create_device_and_queue_from_hal(open, desc, instance_flags) + self.create_device_and_queue_from_hal(open, &desc, instance_flags) } } @@ -1328,7 +1351,9 @@ fn adapter_allowed( } // Check "All supported limits must be either the default value or better." - let failed_limits = check_limits(&wgt::Limits::defaults(), limits); + let mut min_limits = wgt::Limits::defaults(); + min_limits.zero_native_only(); + let failed_limits = check_limits(&min_limits, limits); if !failed_limits.is_empty() { log::debug!( "Adapter {:?} is not WebGPU compliant due to limits: {:?}", @@ -1351,6 +1376,17 @@ fn adapter_allowed( true } +fn filter_features_and_limits( + flags: InstanceFlags, + features: &mut wgt::Features, + limits: &mut wgt::Limits, +) { + if flags.contains(InstanceFlags::STRICT_WEBGPU_COMPLIANCE) { + *features &= wgt::Features::all_webgpu_mask() | limits::EXEMPT_FEATURES; + limits.zero_native_only(); + } +} + #[cfg(test)] mod tests { use super::*; diff --git a/wgpu-core/src/limits.rs b/wgpu-core/src/limits.rs index a0a80fed9..cc8446819 100644 --- a/wgpu-core/src/limits.rs +++ b/wgpu-core/src/limits.rs @@ -244,7 +244,7 @@ pub fn apply_limit_buckets(mut raw: hal::DynExposedAdapter) -> Option. -const EXEMPT_FEATURES: Features = Features::EXTERNAL_TEXTURE +pub(crate) const EXEMPT_FEATURES: Features = Features::EXTERNAL_TEXTURE .union(Features::TEXTURE_FORMAT_NV12) .union(Features::TEXTURE_FORMAT_P010) .union(Features::TEXTURE_FORMAT_16BIT_NORM); diff --git a/wgpu-types/src/limits.rs b/wgpu-types/src/limits.rs index 8fb64f271..81175769b 100644 --- a/wgpu-types/src/limits.rs +++ b/wgpu-types/src/limits.rs @@ -945,6 +945,94 @@ impl Limits { self } + + /// Sets all native-only limits to zero, except for `max_non_sampler_bindings`. + pub fn zero_native_only(&mut self) { + let Self { + max_texture_dimension_1d: _, + max_texture_dimension_2d: _, + max_texture_dimension_3d: _, + max_texture_array_layers: _, + max_bind_groups: _, + max_bind_groups_plus_vertex_buffers: _, + max_bindings_per_bind_group: _, + max_dynamic_uniform_buffers_per_pipeline_layout: _, + max_dynamic_storage_buffers_per_pipeline_layout: _, + max_sampled_textures_per_shader_stage: _, + max_samplers_per_shader_stage: _, + max_storage_buffers_per_shader_stage: _, + max_storage_textures_per_shader_stage: _, + max_uniform_buffers_per_shader_stage: _, + max_uniform_buffer_binding_size: _, + max_storage_buffer_binding_size: _, + max_vertex_buffers: _, + max_buffer_size: _, + max_vertex_attributes: _, + max_vertex_buffer_array_stride: _, + max_inter_stage_shader_variables: _, + min_uniform_buffer_offset_alignment: _, + min_storage_buffer_offset_alignment: _, + max_color_attachments: _, + max_color_attachment_bytes_per_sample: _, + max_compute_workgroup_storage_size: _, + max_compute_invocations_per_workgroup: _, + max_compute_workgroup_size_x: _, + max_compute_workgroup_size_y: _, + max_compute_workgroup_size_z: _, + max_compute_workgroups_per_dimension: _, + max_immediate_size: _, + max_non_sampler_bindings: _, // This is more of an internal setting rather than a limit and it can't be 0. + + max_binding_array_elements_per_shader_stage, + max_binding_array_acceleration_structure_elements_per_shader_stage, + max_binding_array_sampler_elements_per_shader_stage, + max_task_workgroup_total_count, + max_task_workgroups_per_dimension, + max_mesh_workgroup_total_count, + max_mesh_workgroups_per_dimension, + max_task_invocations_per_workgroup, + max_task_invocations_per_dimension, + max_mesh_invocations_per_workgroup, + max_mesh_invocations_per_dimension, + max_task_payload_size, + max_mesh_output_vertices, + max_mesh_output_primitives, + max_mesh_output_layers, + max_mesh_multiview_view_count, + max_blas_primitive_count, + max_blas_geometry_count, + max_tlas_instance_count, + max_acceleration_structures_per_shader_stage, + max_buffers_and_acceleration_structures_per_shader_stage, + max_multiview_view_count, + max_ray_dispatch_count, + max_ray_recursion_depth, + } = self; + *max_binding_array_elements_per_shader_stage = 0; + *max_binding_array_acceleration_structure_elements_per_shader_stage = 0; + *max_binding_array_sampler_elements_per_shader_stage = 0; + *max_task_workgroup_total_count = 0; + *max_task_workgroups_per_dimension = 0; + *max_mesh_workgroup_total_count = 0; + *max_mesh_workgroups_per_dimension = 0; + *max_task_invocations_per_workgroup = 0; + *max_task_invocations_per_dimension = 0; + *max_mesh_invocations_per_workgroup = 0; + *max_mesh_invocations_per_dimension = 0; + *max_task_payload_size = 0; + *max_mesh_output_vertices = 0; + *max_mesh_output_primitives = 0; + *max_mesh_output_layers = 0; + *max_mesh_multiview_view_count = 0; + *max_blas_primitive_count = 0; + *max_blas_geometry_count = 0; + *max_tlas_instance_count = 0; + *max_acceleration_structures_per_shader_stage = 0; + *max_buffers_and_acceleration_structures_per_shader_stage = 0; + *max_multiview_view_count = 0; + *max_ray_dispatch_count = 0; + *max_ray_recursion_depth = 0; + } } /// Represents the sets of additional limits on an adapter,