mirror of
https://github.com/storytold/wgpu.git
synced 2026-11-20 22:41:07 +01:00
[hal] add missing WebGPU adapter capability guarantees
This commit is contained in:
1 parent
c81c9783c5
commit
83c906f99f
6 files changed
+43
-15
No files matched your search
@@ -57,12 +57,22 @@ webgpu:api,operation,vertex_state,correctness:setVertexBuffer_offset_and_attribu
|
||||
webgpu:api,validation,buffer,create:*
|
||||
webgpu:api,validation,buffer,destroy:*
|
||||
webgpu:api,validation,capability_checks,limits,maxBindGroups:setBindGroup,*
|
||||
webgpu:api,validation,capability_checks,limits,maxBindingsPerBindGroup:validate,*
|
||||
webgpu:api,validation,capability_checks,limits,maxBufferSize:*
|
||||
webgpu:api,validation,capability_checks,limits,maxComputeWorkgroupSizeX:validate,*
|
||||
webgpu:api,validation,capability_checks,limits,maxComputeWorkgroupSizeY:validate,*
|
||||
webgpu:api,validation,capability_checks,limits,maxComputeWorkgroupSizeZ:validate,*
|
||||
webgpu:api,validation,capability_checks,limits,maxComputeWorkgroupsPerDimension:validate,*
|
||||
//FAIL: other `maxInterStageShaderVariables` cases w/ limitTest ∈ [underDefault, overMaximum]
|
||||
// https://github.com/gfx-rs/wgpu/issues/8945
|
||||
webgpu:api,validation,capability_checks,limits,maxInterStageShaderVariables:createRenderPipeline,at_over:limitTest="atDefault";*
|
||||
webgpu:api,validation,capability_checks,limits,maxInterStageShaderVariables:createRenderPipeline,at_over:limitTest="atMaximum";*
|
||||
webgpu:api,validation,capability_checks,limits,maxInterStageShaderVariables:createRenderPipeline,at_over:limitTest="betweenDefaultAndMaximum";*
|
||||
webgpu:api,validation,capability_checks,limits,maxStorageBufferBindingSize:validate,*
|
||||
webgpu:api,validation,capability_checks,limits,maxUniformBufferBindingSize:validate,*
|
||||
webgpu:api,validation,capability_checks,limits,maxVertexBufferArrayStride:validate,*
|
||||
webgpu:api,validation,capability_checks,limits,minStorageBufferOffsetAlignment:validate,*
|
||||
webgpu:api,validation,capability_checks,limits,minUniformBufferOffsetAlignment:validate,*
|
||||
webgpu:api,validation,compute_pipeline:basic:*
|
||||
webgpu:api,validation,compute_pipeline:limits,invocations_per_workgroup,each_component:*
|
||||
webgpu:api,validation,compute_pipeline:limits,invocations_per_workgroup:*
|
||||
|
||||
+29
-11
@@ -119,12 +119,11 @@ impl crate::TextureCopy {
|
||||
}
|
||||
}
|
||||
|
||||
/// Clamp the limits in `limits` to honor HAL-imposed maximums and WebGPU
|
||||
/// alignment requirements.
|
||||
///
|
||||
/// Other limits are left unchanged.
|
||||
/// Adjust `limits` to honor HAL-imposed maximums and comply with WebGPU's
|
||||
/// adapter capability guarantees.
|
||||
#[cfg_attr(not(any_backend), allow(dead_code))]
|
||||
pub(crate) fn apply_hal_limits(mut limits: wgt::Limits) -> wgt::Limits {
|
||||
pub(crate) fn adjust_raw_limits(mut limits: wgt::Limits) -> wgt::Limits {
|
||||
// Apply hal limits.
|
||||
limits.max_bind_groups = limits.max_bind_groups.min(crate::MAX_BIND_GROUPS as u32);
|
||||
limits.max_vertex_buffers = limits
|
||||
.max_vertex_buffers
|
||||
@@ -133,13 +132,14 @@ pub(crate) fn apply_hal_limits(mut limits: wgt::Limits) -> wgt::Limits {
|
||||
.max_color_attachments
|
||||
.min(crate::MAX_COLOR_ATTACHMENTS as u32);
|
||||
|
||||
// Adjust limits according to WebGPU adapter capability guarantees.
|
||||
// See <https://gpuweb.github.io/gpuweb/#adapter-capability-guarantees>.
|
||||
|
||||
// WebGPU requires maxBindingsPerBindGroup to be at least the sum of all
|
||||
// per-stage limits multiplied with the maximum shader stages per pipeline.
|
||||
//
|
||||
// Since backends already report their maximum maxBindingsPerBindGroup,
|
||||
// we need to lower all per-stage limits to satisfy this guarantee.
|
||||
//
|
||||
// See <https://gpuweb.github.io/gpuweb/#adapter-capability-guarantees>.
|
||||
const MAX_SHADER_STAGES_PER_PIPELINE: u32 = 2;
|
||||
let max_per_stage_resources =
|
||||
limits.max_bindings_per_bind_group / MAX_SHADER_STAGES_PER_PIPELINE;
|
||||
@@ -156,6 +156,8 @@ pub(crate) fn apply_hal_limits(mut limits: wgt::Limits) -> wgt::Limits {
|
||||
max_per_stage_resources,
|
||||
);
|
||||
|
||||
// Not required by the spec but dynamic buffers count
|
||||
// towards non-dynamic buffer limits as well.
|
||||
limits.max_dynamic_uniform_buffers_per_pipeline_layout = limits
|
||||
.max_dynamic_uniform_buffers_per_pipeline_layout
|
||||
.min(limits.max_uniform_buffers_per_shader_stage);
|
||||
@@ -163,12 +165,28 @@ pub(crate) fn apply_hal_limits(mut limits: wgt::Limits) -> wgt::Limits {
|
||||
.max_dynamic_storage_buffers_per_pipeline_layout
|
||||
.min(limits.max_storage_buffers_per_shader_stage);
|
||||
|
||||
// Round some limits down to the WebGPU alignment requirement, to avoid
|
||||
// suggesting values that won't work. (In particular, the CTS queries limits
|
||||
// and then tests the exact limit value.)
|
||||
limits.max_storage_buffer_binding_size &= u64::from(!(wgt::STORAGE_BINDING_SIZE_ALIGNMENT - 1));
|
||||
limits.min_uniform_buffer_offset_alignment = limits.min_uniform_buffer_offset_alignment.max(32);
|
||||
limits.min_storage_buffer_offset_alignment = limits.min_storage_buffer_offset_alignment.max(32);
|
||||
|
||||
limits.max_uniform_buffer_binding_size = limits
|
||||
.max_uniform_buffer_binding_size
|
||||
.min(limits.max_buffer_size);
|
||||
limits.max_storage_buffer_binding_size = limits
|
||||
.max_storage_buffer_binding_size
|
||||
.min(limits.max_buffer_size);
|
||||
|
||||
limits.max_storage_buffer_binding_size &= !(u64::from(wgt::STORAGE_BINDING_SIZE_ALIGNMENT) - 1);
|
||||
limits.max_vertex_buffer_array_stride &= !(wgt::VERTEX_ALIGNMENT as u32 - 1);
|
||||
|
||||
let x = limits.max_compute_workgroup_size_x;
|
||||
let y = limits.max_compute_workgroup_size_y;
|
||||
let z = limits.max_compute_workgroup_size_z;
|
||||
let m = limits.max_compute_invocations_per_workgroup;
|
||||
limits.max_compute_workgroup_size_x = x.min(m);
|
||||
limits.max_compute_workgroup_size_y = y.min(m);
|
||||
limits.max_compute_workgroup_size_z = z.min(m);
|
||||
limits.max_compute_invocations_per_workgroup = m.min(x.saturating_mul(y).saturating_mul(z));
|
||||
|
||||
limits
|
||||
}
|
||||
|
||||
|
||||
@@ -861,7 +861,7 @@ impl super::Adapter {
|
||||
info,
|
||||
features,
|
||||
capabilities: crate::Capabilities {
|
||||
limits: auxil::apply_hal_limits(wgt::Limits {
|
||||
limits: auxil::adjust_raw_limits(wgt::Limits {
|
||||
//
|
||||
// WebGPU LIMITS:
|
||||
// Based on https://gpuweb.github.io/gpuweb/correspondence/#limits
|
||||
|
||||
@@ -704,7 +704,7 @@ impl super::Adapter {
|
||||
let max_color_attachment_bytes_per_sample =
|
||||
max_color_attachments * wgt::TextureFormat::MAX_TARGET_PIXEL_BYTE_COST;
|
||||
|
||||
let limits = crate::auxil::apply_hal_limits(wgt::Limits {
|
||||
let limits = crate::auxil::adjust_raw_limits(wgt::Limits {
|
||||
max_texture_dimension_1d: max_texture_size,
|
||||
max_texture_dimension_2d: max_texture_size,
|
||||
max_texture_dimension_3d: max_texture_3d_size,
|
||||
|
||||
@@ -1202,7 +1202,7 @@ impl super::CapabilitiesQuery {
|
||||
.flags
|
||||
.set(wgt::DownlevelFlags::ANISOTROPIC_FILTERING, true);
|
||||
|
||||
let limits = crate::auxil::apply_hal_limits(wgt::Limits {
|
||||
let limits = crate::auxil::adjust_raw_limits(wgt::Limits {
|
||||
//
|
||||
// WebGPU LIMITS:
|
||||
// Based on https://gpuweb.github.io/gpuweb/correspondence/#limits
|
||||
|
||||
@@ -1594,7 +1594,7 @@ impl PhysicalDeviceProperties {
|
||||
.map(|a| a.max_multiview_view_count.min(32))
|
||||
.unwrap_or(0);
|
||||
|
||||
crate::auxil::apply_hal_limits(wgt::Limits {
|
||||
crate::auxil::adjust_raw_limits(wgt::Limits {
|
||||
//
|
||||
// WebGPU LIMITS:
|
||||
// Based on https://gpuweb.github.io/gpuweb/correspondence/#limits
|
||||
|
||||
Reference in new issue
Block a user