From 975ccc0b9809d4e0780452fb11e6e654cf9a5179 Mon Sep 17 00:00:00 2001 From: Nicolas Silva Date: Tue, 21 Jun 2022 13:12:13 +0200 Subject: [PATCH] Prevent very large buffer with some drivers. Some drivers run into issues when buffer sizes and ranges are larger than what fits signed 32 bit integer. Adapt the maximum buffer size accordingly. --- wgpu-hal/src/vulkan/adapter.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/wgpu-hal/src/vulkan/adapter.rs b/wgpu-hal/src/vulkan/adapter.rs index ee1989f0639..5d21ac1e45b 100644 --- a/wgpu-hal/src/vulkan/adapter.rs +++ b/wgpu-hal/src/vulkan/adapter.rs @@ -768,6 +768,15 @@ impl PhysicalDeviceCapabilities { .min(limits.max_compute_work_group_count[1]) .min(limits.max_compute_work_group_count[2]); + // Prevent very large buffers on mesa and most android devices. + let is_nvidia = self.properties.vendor_id == crate::auxil::db::nvidia::VENDOR; + let max_buffer_size = + if (cfg!(target_os = "linux") || cfg!(target_os = "android")) && !is_nvidia { + std::i32::MAX as u64 + } else { + std::u64::MAX + }; + wgt::Limits { max_texture_dimension_1d: limits.max_image_dimension1_d, max_texture_dimension_2d: limits.max_image_dimension2_d, @@ -808,7 +817,7 @@ impl PhysicalDeviceCapabilities { max_compute_workgroup_size_y: max_compute_workgroup_sizes[1], max_compute_workgroup_size_z: max_compute_workgroup_sizes[2], max_compute_workgroups_per_dimension, - max_buffer_size: std::u64::MAX, + max_buffer_size, } }