From b825de07e31a460327c088ec2f3c3f44e83fece1 Mon Sep 17 00:00:00 2001 From: Dzmitry Malyshau Date: Thu, 6 Jan 2022 12:11:35 -0500 Subject: [PATCH] hal: limit binding sizes to i32 --- wgpu-hal/src/auxil/mod.rs | 6 ++++++ wgpu-hal/src/dx12/adapter.rs | 2 +- wgpu-hal/src/vulkan/adapter.rs | 8 ++++++-- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/wgpu-hal/src/auxil/mod.rs b/wgpu-hal/src/auxil/mod.rs index 56a2ba351..a157e8056 100644 --- a/wgpu-hal/src/auxil/mod.rs +++ b/wgpu-hal/src/auxil/mod.rs @@ -15,6 +15,12 @@ pub mod db { } } +/// Maximum binding size for the shaders that only support `i32` indexing. +/// Interestingly, the index itself can't reach that high, because the minimum +/// element size is 4 bytes, but the compiler toolchain still computes the +/// offset at some intermediate point, internally, as i32. +pub const MAX_I32_BINDING_SIZE: u32 = 1 << 31; + pub fn map_naga_stage(stage: naga::ShaderStage) -> wgt::ShaderStages { match stage { naga::ShaderStage::Vertex => wgt::ShaderStages::VERTEX, diff --git a/wgpu-hal/src/dx12/adapter.rs b/wgpu-hal/src/dx12/adapter.rs index 69f63b935..4f364a9fd 100644 --- a/wgpu-hal/src/dx12/adapter.rs +++ b/wgpu-hal/src/dx12/adapter.rs @@ -240,7 +240,7 @@ impl super::Adapter { max_uniform_buffers_per_shader_stage: full_heap_count, max_uniform_buffer_binding_size: d3d12::D3D12_REQ_CONSTANT_BUFFER_ELEMENT_COUNT * 16, - max_storage_buffer_binding_size: !0, + max_storage_buffer_binding_size: crate::auxil::MAX_I32_BINDING_SIZE, max_vertex_buffers: d3d12::D3D12_VS_INPUT_REGISTER_COUNT .min(crate::MAX_VERTEX_BUFFERS as u32), max_vertex_attributes: d3d12::D3D12_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT, diff --git a/wgpu-hal/src/vulkan/adapter.rs b/wgpu-hal/src/vulkan/adapter.rs index 8c98f62df..f8bfd53c3 100644 --- a/wgpu-hal/src/vulkan/adapter.rs +++ b/wgpu-hal/src/vulkan/adapter.rs @@ -708,8 +708,12 @@ impl PhysicalDeviceCapabilities { max_storage_buffers_per_shader_stage: max_storage_buffers, max_storage_textures_per_shader_stage: max_storage_textures, max_uniform_buffers_per_shader_stage: max_uniform_buffers, - max_uniform_buffer_binding_size: limits.max_uniform_buffer_range, - max_storage_buffer_binding_size: limits.max_storage_buffer_range, + max_uniform_buffer_binding_size: limits + .max_uniform_buffer_range + .min(crate::auxil::MAX_I32_BINDING_SIZE), + max_storage_buffer_binding_size: limits + .max_storage_buffer_range + .min(crate::auxil::MAX_I32_BINDING_SIZE), max_vertex_buffers: limits .max_vertex_input_bindings .min(crate::MAX_VERTEX_BUFFERS as u32),