Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shrink the default max binding index to 640 and expose it in Limits. #2957

Merged
merged 3 commits into from
Oct 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ SurfaceConfiguration {
- Address Clippy 0.1.63 complaints. By @jimblandy in [#2977](https://github.com/gfx-rs/wgpu/pull/2977)
- Don't use `PhantomData` for `IdentityManager`'s `Input` type. By @jimblandy in [#2972](https://github.com/gfx-rs/wgpu/pull/2972)
- Changed Naga variant in ShaderSource to `Cow<'static, Module>`, to allow loading global variables by @daxpedda in [#2903](https://github.com/gfx-rs/wgpu/pull/2903)
- Updated the maximum binding index to match the WebGPU specification by @nical in [#2957](https://github.com/gfx-rs/wgpu/pull/2957)

#### Metal
- Extract the generic code into `get_metal_layer` by @jinleili in [#2826](https://github.com/gfx-rs/wgpu/pull/2826)
Expand Down
7 changes: 2 additions & 5 deletions wgpu-core/src/device/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -4128,10 +4125,10 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {

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() {
Expand Down
2 changes: 1 addition & 1 deletion wgpu-hal/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ core-graphics-types = "0.1"

[target.'cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))'.dependencies]
wasm-bindgen = { version = "0.2" }
web-sys = { version = "0.3", features = ["Window", "HtmlCanvasElement", "WebGl2RenderingContext", "OffscreenCanvas"] }
web-sys = { version = "=0.3.60", features = ["Window", "HtmlCanvasElement", "WebGl2RenderingContext", "OffscreenCanvas"] }
js-sys = { version = "0.3" }

[target.'cfg(target_os = "android")'.dependencies]
Expand Down
1 change: 1 addition & 0 deletions wgpu-hal/src/dx11/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions wgpu-hal/src/dx12/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,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,
Expand Down
1 change: 1 addition & 0 deletions wgpu-hal/src/gles/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,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,
Expand Down
1 change: 1 addition & 0 deletions wgpu-hal/src/metal/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -832,6 +832,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
Expand Down
1 change: 1 addition & 0 deletions wgpu-hal/src/vulkan/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -693,6 +693,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
Expand Down
2 changes: 2 additions & 0 deletions wgpu-info/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,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,
Expand Down Expand Up @@ -188,6 +189,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);
Expand Down
4 changes: 4 additions & 0 deletions wgpu-types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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".
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions wgpu/src/backend/web.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1166,6 +1166,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
Expand Down