From be43b095f2d8aac6a177f5651a66252b65a6408c Mon Sep 17 00:00:00 2001 From: nuri Date: Thu, 17 Sep 2026 13:26:26 +0900 Subject: [PATCH] [metal] cap the storage binding size at `u32::MAX - 4` again (#10306) Co-authored-by: nuri-yoo Co-authored-by: Erich Gubler --- CHANGELOG.md | 1 + wgpu-hal/src/metal/adapter.rs | 6 ++++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6b10ecbff..3d55a3447 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -225,6 +225,7 @@ By @sagudev in [#10109](https://github.com/gfx-rs/wgpu/pull/10109). #### Metal +- Cap `max_storage_buffer_binding_size` to `u32::MAX - 4` again. By @nuri-yoo in [#10306](https://github.com/gfx-rs/wgpu/pull/10306). - Fix a crash/hang when configuring a surface with the `Bt2100Pq`, `Bt2100Hlg`, or `ExtendedDisplayP3` color space: the dynamically resolved CoreGraphics color-space constants were read with one level of indirection missing. By @stuartparmenter in [#10175](https://github.com/gfx-rs/wgpu/pull/10175). - Fix bind group resources for the task, mesh, fragment, and compute shader stages being bound from the wrong offsets whenever a bind group contained resources visible to the task or mesh stages, which could bind the wrong buffer, texture, or sampler to a shader slot. By @teoxoy in [#10043](https://github.com/gfx-rs/wgpu/issues/10043). - Report an error instead of panicking when Metal declines to create a texture view, which can occur for some views of textures with `TRANSIENT_ATTACHMENT` usage. By @matthargett in [#10145](https://github.com/gfx-rs/wgpu/pull/10145). diff --git a/wgpu-hal/src/metal/adapter.rs b/wgpu-hal/src/metal/adapter.rs index a30e73e99..cfdef666f 100644 --- a/wgpu-hal/src/metal/adapter.rs +++ b/wgpu-hal/src/metal/adapter.rs @@ -1490,8 +1490,10 @@ impl super::CapabilitiesQuery { max_buffer_size: self.max_buffer_size, // No limit, use maxBufferSize. max_uniform_buffer_binding_size: self.max_buffer_size, - // No limit, use maxBufferSize. - max_storage_buffer_binding_size: self.max_buffer_size, + // naga bounds-checks use `uint`. Limit to `u32::MAX` if enabled. + max_storage_buffer_binding_size: self + .max_buffer_size + .min(u64::from(u32::MAX) & !(wgt::STORAGE_BINDING_SIZE_ALIGNMENT as u64 - 1)), min_uniform_buffer_offset_alignment: self.constant_buffer_offset_alignment, // No documented limit. Use 32, which is the lowest allowed value. min_storage_buffer_offset_alignment: 32,