mirror of
https://github.com/storytold/wgpu.git
synced 2026-11-20 06:21:13 +01:00
[wgpu-hal] report accurate maxBindingsPerBindGroup limits
This commit is contained in:
1 parent
3d637fa78d
commit
990e12ebbc
5 files changed
+19
-32
No files matched your search
@@ -139,43 +139,25 @@ pub(crate) fn apply_hal_limits(mut limits: wgt::Limits) -> wgt::Limits {
|
||||
.max_color_attachments
|
||||
.min(crate::MAX_COLOR_ATTACHMENTS as u32);
|
||||
|
||||
// Vulkan and DX12 sometimes report large values for the "max resources per stage"
|
||||
// limits. WebGPU requires that consuming the maximum number of resources of every type
|
||||
// in every stage cannot exceed `max_bindings_per_bind_group`. To ensure this, we must
|
||||
// clamp per-stage limits.
|
||||
// WebGPU requires maxBindingsPerBindGroup to be at least the sum of all
|
||||
// per-stage limits multiplied with the maximum shader stages per pipeline.
|
||||
//
|
||||
// It is not expected that this clamping adjusts limits that are in a range where an
|
||||
// application might reach them. (The main dilemma here being how WebGPU will eventually
|
||||
// apply these or other limits to bindless. wgpu has separate `binding_array` limits for
|
||||
// its native-only extension; those are not touched here.)
|
||||
// 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;
|
||||
|
||||
if limits.max_sampled_textures_per_shader_stage
|
||||
+ limits.max_samplers_per_shader_stage
|
||||
+ limits.max_storage_buffers_per_shader_stage
|
||||
+ limits.max_storage_textures_per_shader_stage
|
||||
+ limits.max_uniform_buffers_per_shader_stage
|
||||
> max_per_stage_resources
|
||||
{
|
||||
// This is the "adjusted limits that are in a range where an application might reach
|
||||
// them" case. (In reality, even something quite a bit less than the default
|
||||
// `max_bindings_per_bind_group` of 1000 ought to be sufficient.)
|
||||
log::warn!(
|
||||
"Unexpected adjustment of per-stage resource limits to fit within max_bindings_per_bind_group."
|
||||
);
|
||||
}
|
||||
|
||||
cap_limits_to_be_under_the_sum_limit(
|
||||
[
|
||||
&mut limits.max_sampled_textures_per_shader_stage,
|
||||
&mut limits.max_samplers_per_shader_stage,
|
||||
&mut limits.max_storage_buffers_per_shader_stage,
|
||||
&mut limits.max_storage_textures_per_shader_stage,
|
||||
&mut limits.max_uniform_buffers_per_shader_stage,
|
||||
&mut limits.max_storage_textures_per_shader_stage,
|
||||
&mut limits.max_storage_buffers_per_shader_stage,
|
||||
&mut limits.max_samplers_per_shader_stage,
|
||||
&mut limits.max_acceleration_structures_per_shader_stage,
|
||||
],
|
||||
max_per_stage_resources,
|
||||
);
|
||||
|
||||
@@ -803,7 +803,7 @@ impl super::Adapter {
|
||||
// 2048
|
||||
max_texture_array_layers: Direct3D12::D3D12_REQ_TEXTURE2D_ARRAY_AXIS_DIMENSION,
|
||||
// No real limit.
|
||||
max_bindings_per_bind_group: 65535,
|
||||
max_bindings_per_bind_group: u32::MAX,
|
||||
max_sampled_textures_per_shader_stage,
|
||||
// 16 or 2048
|
||||
max_samplers_per_shader_stage: match options.ResourceBindingTier {
|
||||
|
||||
@@ -712,7 +712,8 @@ impl super::Adapter {
|
||||
gl.get_parameter_i32(glow::MAX_ARRAY_TEXTURE_LAYERS)
|
||||
} as u32,
|
||||
max_bind_groups: crate::MAX_BIND_GROUPS as u32,
|
||||
max_bindings_per_bind_group: 65535,
|
||||
// No real limit.
|
||||
max_bindings_per_bind_group: u32::MAX,
|
||||
max_dynamic_uniform_buffers_per_pipeline_layout: max_uniform_buffers_per_shader_stage,
|
||||
max_dynamic_storage_buffers_per_pipeline_layout: max_storage_buffers_per_shader_stage,
|
||||
max_sampled_textures_per_shader_stage: super::MAX_TEXTURE_SLOTS as u32,
|
||||
|
||||
@@ -1226,7 +1226,7 @@ impl super::PrivateCapabilities {
|
||||
// No real limit.
|
||||
max_bind_groups: 8,
|
||||
// No real limit.
|
||||
max_bindings_per_bind_group: 65535,
|
||||
max_bindings_per_bind_group: u32::MAX,
|
||||
// No limit, use maxUniformBuffersPerShaderStage.
|
||||
max_dynamic_uniform_buffers_per_pipeline_layout: MAX_UNIFORM_BUFFERS_PER_SHADER_STAGE,
|
||||
// No limit, use maxStorageBuffersPerShaderStage.
|
||||
|
||||
@@ -1562,6 +1562,12 @@ impl PhysicalDeviceProperties {
|
||||
max_per_set_descriptors / 2,
|
||||
);
|
||||
|
||||
// Use max(default, maxPerSetDescriptors) since the spec requires this
|
||||
// limit to be at least 1000. This is ok because we already lowered
|
||||
// all the other relevant per stage limits so their sum is lower
|
||||
// than maxPerSetDescriptors.
|
||||
let max_bindings_per_bind_group = 1000.max(max_per_set_descriptors);
|
||||
|
||||
// TODO: programmatically determine this, if possible. It's unclear whether we can
|
||||
// as of https://github.com/gpuweb/gpuweb/issues/2965#issuecomment-1361315447.
|
||||
//
|
||||
@@ -1589,9 +1595,7 @@ impl PhysicalDeviceProperties {
|
||||
max_texture_dimension_3d: limits.max_image_dimension3_d,
|
||||
max_texture_array_layers: limits.max_image_array_layers,
|
||||
max_bind_groups: limits.max_bound_descriptor_sets,
|
||||
// No real limit but use the default to avoid driver issues.
|
||||
// https://github.com/gpuweb/gpuweb/issues/3279
|
||||
max_bindings_per_bind_group: 1000,
|
||||
max_bindings_per_bind_group,
|
||||
max_dynamic_uniform_buffers_per_pipeline_layout: limits
|
||||
.max_descriptor_set_uniform_buffers_dynamic,
|
||||
max_dynamic_storage_buffers_per_pipeline_layout: limits
|
||||
|
||||
Reference in new issue
Block a user