From 8ec834b98cf2f19b76709d272b5a8222916e697d Mon Sep 17 00:00:00 2001 From: Nicolas Silva Date: Fri, 12 Aug 2022 16:07:18 +0200 Subject: [PATCH] Shrink the default max binding index to 640 and expose it in Limits. Following the corresponding changes happening in WebGPU. --- wgpu-core/src/device/mod.rs | 7 ++----- wgpu-hal/src/dx11/adapter.rs | 1 + wgpu-hal/src/dx12/adapter.rs | 1 + wgpu-hal/src/gles/adapter.rs | 1 + wgpu-hal/src/metal/adapter.rs | 1 + wgpu-hal/src/vulkan/adapter.rs | 1 + wgpu-info/src/main.rs | 2 ++ wgpu-types/src/lib.rs | 4 ++++ wgpu/src/backend/web.rs | 1 + 9 files changed, 14 insertions(+), 5 deletions(-) diff --git a/wgpu-core/src/device/mod.rs b/wgpu-core/src/device/mod.rs index afe32801d77..7fd5e365e22 100644 --- a/wgpu-core/src/device/mod.rs +++ b/wgpu-core/src/device/mod.rs @@ -31,9 +31,6 @@ pub mod queue; #[cfg(any(feature = "trace", feature = "replay"))] pub mod trace; -// Per WebGPU specification. -pub const MAX_BINDING_INDEX: u32 = 65535; - pub const SHADER_STAGE_COUNT: usize = 3; // Should be large enough for the largest possible texture row. This value is enough for a 16k texture with float4 format. pub(crate) const ZERO_BUFFER_SIZE: BufferAddress = 512 << 10; @@ -4089,10 +4086,10 @@ impl Global { let mut entry_map = FastHashMap::default(); for entry in desc.entries.iter() { - if entry.binding > MAX_BINDING_INDEX { + if entry.binding > device.limits.max_bindings_per_bind_group { break 'outer binding_model::CreateBindGroupLayoutError::InvalidBindingIndex { binding: entry.binding, - maximum: MAX_BINDING_INDEX, + maximum: device.limits.max_bindings_per_bind_group, }; } if entry_map.insert(entry.binding, *entry).is_some() { diff --git a/wgpu-hal/src/dx11/adapter.rs b/wgpu-hal/src/dx11/adapter.rs index bfae7b2030e..035eab9d4cc 100644 --- a/wgpu-hal/src/dx11/adapter.rs +++ b/wgpu-hal/src/dx11/adapter.rs @@ -198,6 +198,7 @@ impl super::Adapter { max_texture_dimension_3d, max_texture_array_layers: max_texture_dimension_3d, max_bind_groups: u32::MAX, + max_bindings_per_bind_group: 65535, max_dynamic_uniform_buffers_per_pipeline_layout: max_constant_buffers, max_dynamic_storage_buffers_per_pipeline_layout: 0, max_sampled_textures_per_shader_stage: max_sampled_textures, diff --git a/wgpu-hal/src/dx12/adapter.rs b/wgpu-hal/src/dx12/adapter.rs index d17fd9b0b6c..afdd1cca26a 100644 --- a/wgpu-hal/src/dx12/adapter.rs +++ b/wgpu-hal/src/dx12/adapter.rs @@ -245,6 +245,7 @@ impl super::Adapter { max_texture_dimension_3d: d3d12::D3D12_REQ_TEXTURE3D_U_V_OR_W_DIMENSION, max_texture_array_layers: d3d12::D3D12_REQ_TEXTURE2D_ARRAY_AXIS_DIMENSION, max_bind_groups: crate::MAX_BIND_GROUPS as u32, + max_bindings_per_bind_group: 65535, // dynamic offsets take a root constant, so we expose the minimum here max_dynamic_uniform_buffers_per_pipeline_layout: base .max_dynamic_uniform_buffers_per_pipeline_layout, diff --git a/wgpu-hal/src/gles/adapter.rs b/wgpu-hal/src/gles/adapter.rs index a1b88c5b24a..d282680d2a7 100644 --- a/wgpu-hal/src/gles/adapter.rs +++ b/wgpu-hal/src/gles/adapter.rs @@ -424,6 +424,7 @@ impl super::Adapter { max_texture_dimension_3d: max_texture_3d_size, max_texture_array_layers: 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, 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, diff --git a/wgpu-hal/src/metal/adapter.rs b/wgpu-hal/src/metal/adapter.rs index 2b530695972..f602025ef80 100644 --- a/wgpu-hal/src/metal/adapter.rs +++ b/wgpu-hal/src/metal/adapter.rs @@ -829,6 +829,7 @@ impl super::PrivateCapabilities { max_texture_dimension_3d: self.max_texture_3d_size as u32, max_texture_array_layers: self.max_texture_layers as u32, max_bind_groups: 8, + max_bindings_per_bind_group: 65535, max_dynamic_uniform_buffers_per_pipeline_layout: base .max_dynamic_uniform_buffers_per_pipeline_layout, max_dynamic_storage_buffers_per_pipeline_layout: base diff --git a/wgpu-hal/src/vulkan/adapter.rs b/wgpu-hal/src/vulkan/adapter.rs index c45479bfc03..dad9058af7d 100644 --- a/wgpu-hal/src/vulkan/adapter.rs +++ b/wgpu-hal/src/vulkan/adapter.rs @@ -766,6 +766,7 @@ impl PhysicalDeviceCapabilities { max_bind_groups: limits .max_bound_descriptor_sets .min(crate::MAX_BIND_GROUPS as u32), + max_bindings_per_bind_group: 640, max_dynamic_uniform_buffers_per_pipeline_layout: limits .max_descriptor_set_uniform_buffers_dynamic, max_dynamic_storage_buffers_per_pipeline_layout: limits diff --git a/wgpu-info/src/main.rs b/wgpu-info/src/main.rs index 34260e10c25..b6517d2440c 100644 --- a/wgpu-info/src/main.rs +++ b/wgpu-info/src/main.rs @@ -156,6 +156,7 @@ mod inner { max_texture_dimension_3d, max_texture_array_layers, max_bind_groups, + 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, @@ -185,6 +186,7 @@ mod inner { println!("\t\t Max Texture Dimension 3d: {}", max_texture_dimension_3d); println!("\t\t Max Texture Array Layers: {}", max_texture_array_layers); println!("\t\t Max Bind Groups: {}", max_bind_groups); + println!("\t\t Max Bindings Per Bind Group: {}", max_bindings_per_bind_group); println!("\t\t Max Dynamic Uniform Buffers Per Pipeline Layout: {}", max_dynamic_uniform_buffers_per_pipeline_layout); println!("\t\t Max Dynamic Storage Buffers Per Pipeline Layout: {}", max_dynamic_storage_buffers_per_pipeline_layout); println!("\t\t Max Sampled Textures Per Shader Stage: {}", max_sampled_textures_per_shader_stage); diff --git a/wgpu-types/src/lib.rs b/wgpu-types/src/lib.rs index 0e9e6699f49..ce007f16ece 100644 --- a/wgpu-types/src/lib.rs +++ b/wgpu-types/src/lib.rs @@ -710,6 +710,8 @@ 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, + /// Maximum binding index allowed in `create_bind_group_layout`. Defaults to 640. + 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". pub max_dynamic_uniform_buffers_per_pipeline_layout: u32, /// Amount of storage buffer bindings that can be dynamic in a single pipeline. Defaults to 4. Higher is "better". @@ -792,6 +794,7 @@ impl Default for Limits { max_texture_dimension_3d: 2048, max_texture_array_layers: 256, max_bind_groups: 4, + max_bindings_per_bind_group: 640, max_dynamic_uniform_buffers_per_pipeline_layout: 8, max_dynamic_storage_buffers_per_pipeline_layout: 4, max_sampled_textures_per_shader_stage: 16, @@ -828,6 +831,7 @@ impl Limits { max_texture_dimension_3d: 256, max_texture_array_layers: 256, max_bind_groups: 4, + max_bindings_per_bind_group: 640, max_dynamic_uniform_buffers_per_pipeline_layout: 8, max_dynamic_storage_buffers_per_pipeline_layout: 4, max_sampled_textures_per_shader_stage: 16, diff --git a/wgpu/src/backend/web.rs b/wgpu/src/backend/web.rs index 15ed91356e7..579934fbbc9 100644 --- a/wgpu/src/backend/web.rs +++ b/wgpu/src/backend/web.rs @@ -1155,6 +1155,7 @@ impl crate::Context for Context { 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_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(), max_dynamic_storage_buffers_per_pipeline_layout: limits