add max_bind_groups_plus_vertex_buffers limit

This commit is contained in:
teoxoy authored and Andy Leiserson committed 2026-04-14 17:20:15 -07:00
1 parent 2060683c29
commit 4bbed4074c
17 files changed
+113 -11

No files matched your search

+1 -2
View File
@@ -271,8 +271,7 @@ ObjectDefineProperty(GPUSupportedLimitsPrototype, privateCustomInspect, {
"maxTextureDimension3D",
"maxTextureArrayLayers",
"maxBindGroups",
// TODO(@crowlKats): support max_bind_groups_plus_vertex_buffers
// "maxBindGroupsPlusVertexBuffers",
"maxBindGroupsPlusVertexBuffers",
"maxBindingsPerBindGroup",
"maxDynamicUniformBuffersPerPipelineLayout",
"maxDynamicStorageBuffersPerPipelineLayout",
+4 -1
View File
@@ -297,7 +297,10 @@ impl GPUSupportedLimits {
self.0.max_bind_groups
}
// TODO(@crowlKats): support max_bind_groups_plus_vertex_buffers
#[getter]
fn maxBindGroupsPlusVertexBuffers(&self) -> u32 {
self.0.max_bind_groups_plus_vertex_buffers
}
#[getter]
fn maxBindingsPerBindGroup(&self) -> u32 {
+15
View File
@@ -48,6 +48,10 @@ mod compat {
}
}
fn is_assigned(&self) -> bool {
self.assigned.is_some()
}
fn is_active(&self) -> bool {
self.assigned.is_some() && self.expected.is_some()
}
@@ -250,6 +254,13 @@ mod compat {
self.entries[index].assigned = None;
}
pub fn list_assigned(&self) -> impl Iterator<Item = usize> + '_ {
self.entries
.iter()
.enumerate()
.filter_map(|(i, e)| if e.is_assigned() { Some(i) } else { None })
}
pub fn list_active(&self) -> impl Iterator<Item = usize> + '_ {
self.entries
.iter()
@@ -439,6 +450,10 @@ impl Binder {
})
}
pub(super) fn last_assigned_index(&self) -> Option<usize> {
self.manager.list_assigned().last()
}
pub(super) fn list_active(&self) -> impl Iterator<Item = &Arc<BindGroup>> + '_ {
let payloads = &self.payloads;
self.manager
+20
View File
@@ -1527,6 +1527,26 @@ impl State {
}
}
let bind_group_space_used = self.binder.last_assigned_index().map_or(0, |i| i + 1);
let vertex_buffer_space_used = self
.vertex
.iter()
.enumerate()
.filter_map(|(i, state)| state.as_ref().map(|_| i))
.next_back()
.map_or(0, |i| i + 1);
let bind_groups_plus_vertex_buffers =
u32::try_from(bind_group_space_used + vertex_buffer_space_used).unwrap();
if bind_groups_plus_vertex_buffers
> self.device.limits.max_bind_groups_plus_vertex_buffers
{
return Err(DrawError::TooManyBindGroupsPlusVertexBuffers {
given: bind_groups_plus_vertex_buffers,
limit: self.device.limits.max_bind_groups_plus_vertex_buffers,
});
}
if family == DrawCommandFamily::DrawIndexed {
let pipeline = &pipeline.pipeline;
let index_format = match &self.index {
+2
View File
@@ -74,6 +74,8 @@ pub enum DrawError {
MissingImmediateData {
missing: naga::valid::ImmediateSlots,
},
#[error("The number of bind groups + vertex buffers {given} exceeds the limit {limit}")]
TooManyBindGroupsPlusVertexBuffers { given: u32, limit: u32 },
}
impl WebGpuError for DrawError {
+21
View File
@@ -566,6 +566,27 @@ impl<'scope, 'snatch_guard, 'cmd_enc> State<'scope, 'snatch_guard, 'cmd_enc> {
}
}
let bind_group_space_used = self.pass.binder.last_assigned_index().map_or(0, |i| i + 1);
let vertex_buffer_space_used = self
.vertex
.buffer_sizes
.iter()
.enumerate()
.filter_map(|(i, size)| size.map(|_| i))
.next_back()
.map_or(0, |i| i + 1);
let bind_groups_plus_vertex_buffers =
u32::try_from(bind_group_space_used + vertex_buffer_space_used).unwrap();
if bind_groups_plus_vertex_buffers
> pipeline.device.limits.max_bind_groups_plus_vertex_buffers
{
return Err(DrawError::TooManyBindGroupsPlusVertexBuffers {
given: bind_groups_plus_vertex_buffers,
limit: pipeline.device.limits.max_bind_groups_plus_vertex_buffers,
});
}
if family == DrawCommandFamily::DrawIndexed {
// Pipeline expects an index buffer
// We have a buffer bound
+14
View File
@@ -4687,6 +4687,20 @@ impl Device {
}
};
if let pipeline::RenderPipelineVertexProcessor::Vertex(ref vertex) = desc.vertex {
let bind_groups_plus_vertex_buffers =
u32::try_from(pipeline_layout.bind_group_layouts.len() + vertex.buffers.len())
.unwrap();
if bind_groups_plus_vertex_buffers > self.limits.max_bind_groups_plus_vertex_buffers {
return Err(
pipeline::CreateRenderPipelineError::TooManyBindGroupsPlusVertexBuffers {
given: bind_groups_plus_vertex_buffers,
limit: self.limits.max_bind_groups_plus_vertex_buffers,
},
);
}
}
// Multiview is only supported if the feature is enabled
if let Some(mv_mask) = desc.multiview_mask {
self.require_features(wgt::Features::MULTIVIEW)?;
+1 -1
View File
@@ -291,7 +291,7 @@ const UPLEVEL: Bucket = Bucket {
name: "uplevel-defaults",
limits: Limits {
max_bind_groups: 8,
// wgpu does not implement max_bind_groups_plus_vertex_buffers
// use default max_bind_groups_plus_vertex_buffers
// use default max_bindings_per_bind_group
max_buffer_size: 1 << 30, // 1 GB
max_color_attachment_bytes_per_sample: 64,
+3
View File
@@ -698,6 +698,8 @@ pub enum CreateRenderPipelineError {
InvalidSampleCount(u32),
#[error("The number of vertex buffers {given} exceeds the limit {limit}")]
TooManyVertexBuffers { given: u32, limit: u32 },
#[error("The number of bind groups + vertex buffers {given} exceeds the limit {limit}")]
TooManyBindGroupsPlusVertexBuffers { given: u32, limit: u32 },
#[error("The total number of vertex attributes {given} exceeds the limit {limit}")]
TooManyVertexAttributes { given: u32, limit: u32 },
#[error("Vertex attribute location {given} must be less than limit {limit}")]
@@ -778,6 +780,7 @@ impl WebGpuError for CreateRenderPipelineError {
| Self::DepthStencilState(_)
| Self::InvalidSampleCount(_)
| Self::TooManyVertexBuffers { .. }
| Self::TooManyBindGroupsPlusVertexBuffers { .. }
| Self::TooManyVertexAttributes { .. }
| Self::VertexAttributeLocationTooLarge { .. }
| Self::VertexStrideTooLarge { .. }
+5
View File
@@ -128,6 +128,11 @@ pub(crate) fn adjust_raw_limits(mut limits: wgt::Limits) -> wgt::Limits {
limits.max_vertex_buffers = limits
.max_vertex_buffers
.min(crate::MAX_VERTEX_BUFFERS as u32);
// Once we allow the 2 limits above to be higher than 24 we should use
// `cap_limits_to_be_under_the_sum_limit` to cap them under
// `max_bind_groups_plus_vertex_buffers`.
const { assert!(crate::MAX_BIND_GROUPS + crate::MAX_VERTEX_BUFFERS == 24) };
limits.max_bind_groups_plus_vertex_buffers = limits.max_bind_groups_plus_vertex_buffers.min(24);
limits.max_color_attachments = limits
.max_color_attachments
.min(crate::MAX_COLOR_ATTACHMENTS as u32);
+3 -1
View File
@@ -894,7 +894,9 @@ impl super::Adapter {
max_texture_dimension_3d: Direct3D12::D3D12_REQ_TEXTURE3D_U_V_OR_W_DIMENSION,
// 2048
max_texture_array_layers: Direct3D12::D3D12_REQ_TEXTURE2D_ARRAY_AXIS_DIMENSION,
// No real limit.
// No limit.
max_bind_groups_plus_vertex_buffers: u32::MAX,
// No limit.
max_bindings_per_bind_group: u32::MAX,
max_sampled_textures_per_shader_stage,
max_samplers_per_shader_stage,
+4 -2
View File
@@ -714,8 +714,10 @@ impl super::Adapter {
max_texture_array_layers: unsafe {
gl.get_parameter_i32(glow::MAX_ARRAY_TEXTURE_LAYERS)
} as u32,
max_bind_groups: crate::MAX_BIND_GROUPS as u32,
// No real limit.
max_bind_groups: u32::MAX,
// No limit.
max_bind_groups_plus_vertex_buffers: u32::MAX,
// No 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,
+5 -3
View File
@@ -1316,9 +1316,11 @@ impl super::CapabilitiesQuery {
max_texture_dimension_2d: self.max_texture_size as u32,
max_texture_dimension_3d: self.max_texture_3d_size as u32,
max_texture_array_layers: self.max_texture_layers as u32,
// No real limit.
max_bind_groups: 8,
// No real limit.
// No limit.
max_bind_groups: u32::MAX,
// No limit. Once we start using argument buffers we should set this appropriately.
max_bind_groups_plus_vertex_buffers: u32::MAX,
// No limit.
max_bindings_per_bind_group: u32::MAX,
// No limit, use maxUniformBuffersPerShaderStage.
max_dynamic_uniform_buffers_per_pipeline_layout: MAX_UNIFORM_BUFFERS_PER_SHADER_STAGE,
+2
View File
@@ -1634,6 +1634,8 @@ 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 limit.
max_bind_groups_plus_vertex_buffers: u32::MAX,
max_bindings_per_bind_group,
max_dynamic_uniform_buffers_per_pipeline_layout: limits
.max_descriptor_set_uniform_buffers_dynamic,
+2
View File
@@ -151,6 +151,7 @@ fn print_adapter(output: &mut impl io::Write, report: &AdapterReport, idx: usize
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,
@@ -208,6 +209,7 @@ fn print_adapter(output: &mut impl io::Write, report: &AdapterReport, idx: usize
writeln!(output, "\t\t Max Texture Dimension 3d: {max_texture_dimension_3d}")?;
writeln!(output, "\t\t Max Texture Array Layers: {max_texture_array_layers}")?;
writeln!(output, "\t\t Max Bind Groups: {max_bind_groups}")?;
writeln!(output, "\t\t Max Bind Groups Plus Vertex Buffers: {max_bind_groups_plus_vertex_buffers}")?;
writeln!(output, "\t\t Max Bindings Per Bind Group: {max_bindings_per_bind_group}")?;
writeln!(output, "\t\t Max Dynamic Uniform Buffers Per Pipeline Layout: {max_dynamic_uniform_buffers_per_pipeline_layout}")?;
writeln!(output, "\t\t Max Dynamic Storage Buffers Per Pipeline Layout: {max_dynamic_storage_buffers_per_pipeline_layout}")?;
+9
View File
@@ -22,6 +22,7 @@ macro_rules! with_limits {
$macro_name!(max_texture_dimension_3d, Ordering::Less);
$macro_name!(max_texture_array_layers, Ordering::Less);
$macro_name!(max_bind_groups, Ordering::Less);
$macro_name!(max_bind_groups_plus_vertex_buffers, Ordering::Less);
$macro_name!(max_bindings_per_bind_group, Ordering::Less);
$macro_name!(
max_dynamic_uniform_buffers_per_pipeline_layout,
@@ -146,6 +147,9 @@ pub struct Limits {
pub max_texture_array_layers: u32,
/// Amount of bind groups that can be attached to a pipeline at the same time. Defaults to 4. Higher is "better".
pub max_bind_groups: u32,
/// The maximum number of bind group and vertex buffer slots used simultaneously, counting any empty slots below the highest index.
/// Defaults to 24. Higher is "better".
pub max_bind_groups_plus_vertex_buffers: u32,
/// Maximum binding index allowed in `create_bind_group_layout`. Defaults to 1000. Higher is "better".
pub max_bindings_per_bind_group: u32,
/// Amount of uniform buffer bindings that can be dynamic in a single pipeline. Defaults to 8. Higher is "better".
@@ -333,6 +337,7 @@ impl Limits {
/// max_texture_dimension_3d: 2048,
/// max_texture_array_layers: 256,
/// max_bind_groups: 4,
/// max_bind_groups_plus_vertex_buffers: 24,
/// max_bindings_per_bind_group: 1000,
/// max_dynamic_uniform_buffers_per_pipeline_layout: 8,
/// max_dynamic_storage_buffers_per_pipeline_layout: 4,
@@ -394,6 +399,7 @@ impl Limits {
max_texture_dimension_3d: 2048,
max_texture_array_layers: 256,
max_bind_groups: 4,
max_bind_groups_plus_vertex_buffers: 24,
max_bindings_per_bind_group: 1000,
max_dynamic_uniform_buffers_per_pipeline_layout: 8,
max_dynamic_storage_buffers_per_pipeline_layout: 4,
@@ -459,6 +465,7 @@ impl Limits {
/// max_texture_dimension_3d: 256, // *
/// max_texture_array_layers: 256,
/// max_bind_groups: 4,
/// max_bind_groups_plus_vertex_buffers: 24,
/// max_bindings_per_bind_group: 1000,
/// max_dynamic_uniform_buffers_per_pipeline_layout: 8,
/// max_dynamic_storage_buffers_per_pipeline_layout: 4,
@@ -540,6 +547,7 @@ impl Limits {
/// max_texture_dimension_3d: 256, // *
/// max_texture_array_layers: 256,
/// max_bind_groups: 4,
/// max_bind_groups_plus_vertex_buffers: 24,
/// max_bindings_per_bind_group: 1000,
/// max_dynamic_uniform_buffers_per_pipeline_layout: 8,
/// max_dynamic_storage_buffers_per_pipeline_layout: 0, // +
@@ -637,6 +645,7 @@ impl Limits {
max_texture_dimension_3d: ALLOC_MAX_U32,
max_texture_array_layers: ALLOC_MAX_U32,
max_bind_groups: ALLOC_MAX_U32,
max_bind_groups_plus_vertex_buffers: ALLOC_MAX_U32,
max_bindings_per_bind_group: ALLOC_MAX_U32,
max_dynamic_uniform_buffers_per_pipeline_layout: ALLOC_MAX_U32,
max_dynamic_storage_buffers_per_pipeline_layout: ALLOC_MAX_U32,
+2 -1
View File
@@ -818,6 +818,7 @@ fn map_wgt_limits(limits: webgpu_sys::GpuSupportedLimits) -> wgt::Limits {
max_texture_dimension_3d: limits.max_texture_dimension_3d(),
max_texture_array_layers: limits.max_texture_array_layers(),
max_bind_groups: limits.max_bind_groups(),
max_bind_groups_plus_vertex_buffers: limits.max_bind_groups_plus_vertex_buffers(),
max_bindings_per_bind_group: limits.max_bindings_per_bind_group(),
max_dynamic_uniform_buffers_per_pipeline_layout: limits
.max_dynamic_uniform_buffers_per_pipeline_layout(),
@@ -925,7 +926,7 @@ fn map_js_sys_limits(limits: &wgt::Limits) -> js_sys::Object<js_sys::Number> {
(maxTextureDimension3D, max_texture_dimension_3d),
(maxTextureArrayLayers, max_texture_array_layers),
(maxBindGroups, max_bind_groups),
// TODO: (maxBindGroupsPlusVertexBuffers, max_bind_groups_plus_vertex_buffers),
(maxBindGroupsPlusVertexBuffers, max_bind_groups_plus_vertex_buffers),
(maxBindingsPerBindGroup, max_bindings_per_bind_group),
(maxDynamicUniformBuffersPerPipelineLayout, max_dynamic_uniform_buffers_per_pipeline_layout),
(maxDynamicStorageBuffersPerPipelineLayout, max_dynamic_storage_buffers_per_pipeline_layout),