fix: Change type of max_*_buffer_binding_size to follow spec

This commit is contained in:
Genna Wingert authored and Erich Gubler committed 2026-03-09 16:49:06 -06:00
1 parent 0afad95d9b
commit ce7dad3026
15 files changed
+39 -36

No files matched your search

+1
View File
@@ -167,6 +167,7 @@ depth_stencil: Some(wgpu::DepthStencilState::stencil(
- Removed the `NegativeRange` variant in favor of new `MapStartOffsetUnderrun` and `MapStartOffsetOverrun` variants.
- Split the `TransferError::BufferOverrun` variant into new `BufferStartOffsetOverrun` and `BufferEndOffsetOverrun` variants.
- The various "max resources per stage" limits are now capped at 100, so that their total remains below `max_bindings_per_bind_group`, as required by WebGPU. By @andyleiserson in [#9118](https://github.com/gfx-rs/wgpu/pull/9118).
- The `max_uniform_buffer_binding_size` and `max_storage_buffer_binding_size` limits are now `u64` instead of `u32`, to match WebGPU. By @wingertge in [#9146](https://github.com/gfx-rs/wgpu/pull/9146).
#### Metal
+4 -2
View File
@@ -375,12 +375,14 @@ impl GPUSupportedLimits {
}
#[getter]
fn maxUniformBufferBindingSize(&self) -> u32 {
#[number]
fn maxUniformBufferBindingSize(&self) -> u64 {
self.0.max_uniform_buffer_binding_size
}
#[getter]
fn maxStorageBufferBindingSize(&self) -> u32 {
#[number]
fn maxStorageBufferBindingSize(&self) -> u64 {
self.0.max_storage_buffer_binding_size
}
+1 -1
View File
@@ -419,7 +419,7 @@ static DEVICE_DESTROY_THEN_MORE: GpuTestConfiguration = GpuTestConfiguration::ne
ty: wgpu::BufferBindingType::Uniform,
has_dynamic_offset: false,
min_binding_size: std::num::NonZeroU64::new(
(ctx.device.limits().max_uniform_buffer_binding_size * 2) as u64,
ctx.device.limits().max_uniform_buffer_binding_size * 2,
),
},
count: None,
+2 -2
View File
@@ -181,8 +181,8 @@ pub enum CreateBindGroupError {
)]
BufferRangeTooLarge {
binding: u32,
given: u32,
limit: u32,
given: u64,
limit: u64,
},
#[error("Binding {binding} has a different type ({actual:?}) than the one in the layout ({expected:?})")]
WrongBindingType {
+2 -2
View File
@@ -2895,10 +2895,10 @@ impl Device {
let bind_end = bb.offset + bind_size;
if bind_size > range_limit as u64 {
if bind_size > range_limit {
return Err(Error::BufferRangeTooLarge {
binding,
given: bind_size as u32,
given: bind_size,
limit: range_limit,
});
}
+10 -12
View File
@@ -14,10 +14,7 @@ use crate::{
FastHashMap,
};
use alloc::{boxed::Box, string::ToString, sync::Arc, vec, vec::Vec};
use core::{
mem::{size_of, size_of_val},
num::NonZeroU64,
};
use core::{mem::size_of, num::NonZeroU64};
use wgt::Limits;
/// Note: This needs to be under:
@@ -653,7 +650,7 @@ fn create_bind_group_layout(
/// Returns the largest binding size that when combined with dynamic offsets can address the whole buffer.
fn calculate_src_buffer_binding_size(buffer_size: u64, limits: &Limits) -> u64 {
let max_storage_buffer_binding_size = limits.max_storage_buffer_binding_size as u64;
let max_storage_buffer_binding_size = limits.max_storage_buffer_binding_size;
let min_storage_buffer_offset_alignment = limits.min_storage_buffer_offset_alignment as u64;
if buffer_size <= max_storage_buffer_binding_size {
@@ -893,12 +890,13 @@ impl MetadataEntry {
vertex_or_index_limit: u64,
instance_limit: u64,
) -> Self {
debug_assert_eq!(
4,
size_of_val(&Limits::default().max_storage_buffer_binding_size)
);
const U32_MAX_AS_U64: u64 = u32::MAX as u64;
let src_offset = src_offset as u32; // max_storage_buffer_binding_size is a u32
// NOTE: buffer sizes should never exceed `u32::MAX`.
assert!(src_offset <= U32_MAX_AS_U64);
assert!(dst_offset <= U32_MAX_AS_U64);
let src_offset = src_offset as u32;
let src_offset = src_offset / 4; // translate byte offset to offset in u32's
// `src_offset` needs at most 30 bits,
@@ -906,7 +904,7 @@ impl MetadataEntry {
let src_offset = src_offset | ((indexed as u32) << 31);
// max value for limits since first_X and X_count indirect draw arguments are u32
let max_limit = u32::MAX as u64 + u32::MAX as u64; // 1 11111111 11111111 11111111 11111110
let max_limit = U32_MAX_AS_U64 + U32_MAX_AS_U64; // 1 11111111 11111111 11111111 11111110
let vertex_or_index_limit = vertex_or_index_limit.min(max_limit);
let vertex_or_index_limit_bit_32 = (vertex_or_index_limit >> 32) as u32; // extract bit 32
@@ -916,7 +914,7 @@ impl MetadataEntry {
let instance_limit_bit_32 = (instance_limit >> 32) as u32; // extract bit 32
let instance_limit = instance_limit as u32; // truncate the limit to a u32
let dst_offset = dst_offset as u32; // max_storage_buffer_binding_size is a u32
let dst_offset = dst_offset as u32;
let dst_offset = dst_offset / 4; // translate byte offset to offset in u32's
// `dst_offset` needs at most 30 bits,
+1 -1
View File
@@ -276,7 +276,7 @@ impl TimestampNormalizer {
// at once to normalize the timestamps, we can't use it. We force the buffer to fail
// to allocate. The lowest max binding size is 128MB, and query sets must be small
// (no more than 4096), so this should never be hit in practice by sane programs.
if buffer_size.get() > device.adapter.limits().max_storage_buffer_binding_size as u64 {
if buffer_size.get() > device.adapter.limits().max_storage_buffer_binding_size {
return Err(DeviceError::OutOfMemory);
}
+1 -1
View File
@@ -192,7 +192,7 @@ pub(crate) fn apply_hal_limits(mut limits: wgt::Limits) -> wgt::Limits {
// Round some limits down to the WebGPU alignment requirement, to avoid
// suggesting values that won't work. (In particular, the CTS queries limits
// and then tests the exact limit value.)
limits.max_storage_buffer_binding_size &= !(wgt::STORAGE_BINDING_SIZE_ALIGNMENT - 1);
limits.max_storage_buffer_binding_size &= !(wgt::STORAGE_BINDING_SIZE_ALIGNMENT - 1) as u64;
limits.max_vertex_buffer_array_stride &= !(wgt::VERTEX_ALIGNMENT as u32 - 1);
limits
+2 -2
View File
@@ -809,8 +809,8 @@ impl super::Adapter {
max_binding_array_elements_per_shader_stage: full_heap_count,
max_binding_array_sampler_elements_per_shader_stage: full_heap_count,
max_uniform_buffer_binding_size:
Direct3D12::D3D12_REQ_CONSTANT_BUFFER_ELEMENT_COUNT * 16,
max_storage_buffer_binding_size: auxil::MAX_I32_BINDING_SIZE,
Direct3D12::D3D12_REQ_CONSTANT_BUFFER_ELEMENT_COUNT as u64 * 16,
max_storage_buffer_binding_size: auxil::MAX_I32_BINDING_SIZE as u64,
max_vertex_buffers: Direct3D12::D3D12_VS_INPUT_REGISTER_COUNT,
max_vertex_attributes: Direct3D12::D3D12_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT,
max_vertex_buffer_array_stride: Direct3D12::D3D12_SO_BUFFER_MAX_STRIDE_IN_BYTES,
+2 -2
View File
@@ -717,12 +717,12 @@ impl super::Adapter {
max_binding_array_sampler_elements_per_shader_stage: 0,
max_uniform_buffer_binding_size: unsafe {
gl.get_parameter_i32(glow::MAX_UNIFORM_BLOCK_SIZE)
} as u32,
} as u64,
max_storage_buffer_binding_size: if supports_storage {
unsafe { gl.get_parameter_i32(glow::MAX_SHADER_STORAGE_BLOCK_SIZE) }
} else {
0
} as u32,
} as u64,
max_vertex_buffers: if private_caps
.contains(super::PrivateCapabilities::VERTEX_BUFFER_LAYOUT)
{
+3 -3
View File
@@ -1179,9 +1179,9 @@ impl super::PrivateCapabilities {
max_binding_array_sampler_elements_per_shader_stage: self
.max_sampler_binding_array_elements,
// Note: any adjustment here will not be reflected in the stored `PrivateCapabilities`.
max_uniform_buffer_binding_size: self.max_buffer_size.min(!0u32 as u64) as u32,
max_storage_buffer_binding_size: self.max_buffer_size.min(!0u32 as u64) as u32
& !(wgt::STORAGE_BINDING_SIZE_ALIGNMENT - 1),
max_uniform_buffer_binding_size: self.max_buffer_size.min(!0u32 as u64),
max_storage_buffer_binding_size: self.max_buffer_size.min(!0u32 as u64)
& !(wgt::STORAGE_BINDING_SIZE_ALIGNMENT as u64 - 1),
max_vertex_buffers: self.max_vertex_buffers,
max_vertex_attributes: 31,
max_vertex_buffer_array_stride: base.max_vertex_buffer_array_stride,
+2 -2
View File
@@ -176,8 +176,8 @@ pub const CAPABILITIES: crate::Capabilities = {
max_uniform_buffers_per_shader_stage: ALLOC_MAX_U32,
max_binding_array_elements_per_shader_stage: ALLOC_MAX_U32,
max_binding_array_sampler_elements_per_shader_stage: ALLOC_MAX_U32,
max_uniform_buffer_binding_size: ALLOC_MAX_U32,
max_storage_buffer_binding_size: ALLOC_MAX_U32,
max_uniform_buffer_binding_size: ALLOC_MAX_U32 as u64,
max_storage_buffer_binding_size: ALLOC_MAX_U32 as u64,
max_vertex_buffers: ALLOC_MAX_U32,
max_buffer_size: ALLOC_MAX_U32 as u64,
max_vertex_attributes: ALLOC_MAX_U32,
+4 -2
View File
@@ -1457,10 +1457,12 @@ impl PhysicalDeviceProperties {
max_binding_array_sampler_elements_per_shader_stage: max_sampler_binding_array_elements,
max_uniform_buffer_binding_size: limits
.max_uniform_buffer_range
.min(crate::auxil::MAX_I32_BINDING_SIZE),
.min(crate::auxil::MAX_I32_BINDING_SIZE)
as u64,
max_storage_buffer_binding_size: limits
.max_storage_buffer_range
.min(crate::auxil::MAX_I32_BINDING_SIZE),
.min(crate::auxil::MAX_I32_BINDING_SIZE)
as u64,
max_vertex_buffers: limits.max_vertex_input_bindings,
max_vertex_attributes: limits.max_vertex_input_attributes,
max_vertex_buffer_array_stride: limits.max_vertex_input_binding_stride,
+2 -2
View File
@@ -160,9 +160,9 @@ pub struct Limits {
/// This "defaults" to 0. However if binding arrays are supported, all devices can support 1,000. Higher is "better".
pub max_binding_array_sampler_elements_per_shader_stage: u32,
/// Maximum size in bytes of a binding to a uniform buffer. Defaults to 64 KiB. Higher is "better".
pub max_uniform_buffer_binding_size: u32,
pub max_uniform_buffer_binding_size: u64,
/// Maximum size in bytes of a binding to a storage buffer. Defaults to 128 MiB. Higher is "better".
pub max_storage_buffer_binding_size: u32,
pub max_storage_buffer_binding_size: u64,
/// Maximum length of `VertexState::buffers` when creating a `RenderPipeline`.
/// Defaults to 8. Higher is "better".
pub max_vertex_buffers: u32,
+2 -2
View File
@@ -804,8 +804,8 @@ fn map_wgt_limits(limits: webgpu_sys::GpuSupportedLimits) -> wgt::Limits {
max_uniform_buffers_per_shader_stage: limits.max_uniform_buffers_per_shader_stage(),
max_binding_array_elements_per_shader_stage: 0,
max_binding_array_sampler_elements_per_shader_stage: 0,
max_uniform_buffer_binding_size: limits.max_uniform_buffer_binding_size() as u32,
max_storage_buffer_binding_size: limits.max_storage_buffer_binding_size() as u32,
max_uniform_buffer_binding_size: limits.max_uniform_buffer_binding_size() as u64,
max_storage_buffer_binding_size: limits.max_storage_buffer_binding_size() as u64,
max_vertex_buffers: limits.max_vertex_buffers(),
max_buffer_size: limits.max_buffer_size() as u64,
max_vertex_attributes: limits.max_vertex_attributes(),