[core] filter native-only features and limits if

`STRICT_WEBGPU_COMPLIANCE` is set
This commit is contained in:
teoxoy authored and Connor Fitzgerald committed 2026-07-01 14:43:44 -04:00
1 parent 2ea3a1d41b
commit aa2b7907c0
4 files changed
+130 -4

No files matched your search

+3 -1
View File
@@ -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()));
});
+38 -2
View File
@@ -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<Device>, Arc<Queue>), 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::*;
+1 -1
View File
@@ -244,7 +244,7 @@ pub fn apply_limit_buckets(mut raw: hal::DynExposedAdapter) -> Option<hal::DynEx
/// at that point neither excluding the tier1 formats from WebIDL entirely nor allowing
/// content to use them on a device that doesn't have the feature enabled will be
/// acceptable. See <https://github.com/gfx-rs/wgpu/issues/8122>.
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);
+88
View File
@@ -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,