From 01f079744b2f41a1bea029e0d43d975bd53cc01f 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 1f2363e21a..462a56d69a 100644 --- a/wgpu-core/src/device/mod.rs +++ b/wgpu-core/src/device/mod.rs @@ -32,9 +32,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; @@ -4128,10 +4125,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 bfae7b2030..035eab9d4c 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 55e3602c33..6ebc3cb76f 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 66709a424f..abc6cfe680 100644 --- a/wgpu-hal/src/gles/adapter.rs +++ b/wgpu-hal/src/gles/adapter.rs @@ -426,6 +426,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 7a219ed88a..0dd35547f0 100644 --- a/wgpu-hal/src/metal/adapter.rs +++ b/wgpu-hal/src/metal/adapter.rs @@ -823,6 +823,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 0a3afb690e..fd6b4eeb46 100644 --- a/wgpu-hal/src/vulkan/adapter.rs +++ b/wgpu-hal/src/vulkan/adapter.rs @@ -673,6 +673,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 34260e10c2..b6517d2440 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 1b698bd9d4..b065de9000 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 3a9c58fb65..cffcb6b4eb 100644 --- a/wgpu/src/backend/web.rs +++ b/wgpu/src/backend/web.rs @@ -1156,6 +1156,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