From ee84090cc47ca341fe99fb00187225b3a64c534f Mon Sep 17 00:00:00 2001 From: Andy Leiserson Date: Mon, 27 Jul 2026 15:20:01 -0700 Subject: [PATCH] refactor(metal): Allow zeros in `vertex_buffer_size_map` (cherry picked from commit d2ad891087f431125ee15570334c806466a6e57b) --- wgpu-hal/src/metal/command.rs | 20 +++++++------------- wgpu-hal/src/metal/mod.rs | 5 ++++- 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/wgpu-hal/src/metal/command.rs b/wgpu-hal/src/metal/command.rs index b78a8e80a..76d546c1c 100644 --- a/wgpu-hal/src/metal/command.rs +++ b/wgpu-hal/src/metal/command.rs @@ -434,12 +434,13 @@ impl super::CommandState { .unwrap_or_default() })); - // Extend with the sizes of the mapped vertex buffers, in the order - // they were added to the map. + // Extend with the sizes of the mapped vertex buffers, in the order they were added + // to the map. Note that zeros in the sizes buffer can be for either an unused + // binding index (no entry in map) or a zero-size binding (map entry that is zero). result_sizes.extend(stage_info.vertex_buffer_mappings.iter().map(|vbm| { self.vertex_buffer_size_map .get(&vbm.id) - .map(|size| u32::try_from(size.get()).unwrap_or(u32::MAX)) + .map(|&size| u32::try_from(size).unwrap_or(u32::MAX)) .unwrap_or_default() })); @@ -1391,16 +1392,9 @@ impl crate::CommandEncoder for super::CommandEncoder { ) }; - // The size map uses `NonZeroU64` mostly because it did so in the past when - // `hal::BufferBinding` tried to disallow zero-length bindings. Zero-length bindings - // are valid for vertex buffers, so there isn't really a significance of a - // zero-length buffer being removed from the map (vs. the map storing `u64`). - if let Some(size) = NonZeroU64::new(binding.size) { - self.state.vertex_buffer_size_map.insert(buffer_index, size); - } else { - // `make_sizes_buffer_update` uses zero for buffers that are not in the map. - self.state.vertex_buffer_size_map.remove(&buffer_index); - } + self.state + .vertex_buffer_size_map + .insert(buffer_index, binding.size); if let Some((index, sizes)) = self .state diff --git a/wgpu-hal/src/metal/mod.rs b/wgpu-hal/src/metal/mod.rs index b845a929d..50698815e 100644 --- a/wgpu-hal/src/metal/mod.rs +++ b/wgpu-hal/src/metal/mod.rs @@ -1103,7 +1103,10 @@ struct CommandState { /// [`ResourceBinding`]: naga::ResourceBinding storage_buffer_length_map: FastHashMap, - vertex_buffer_size_map: FastHashMap, + /// Sizes of currently bound vertex buffers. + /// + /// Unlike storage buffer bindings, these may have size zero. + vertex_buffer_size_map: FastHashMap, immediates: Vec,