Skip to content

Commit

Permalink
Prevent very large buffer with some drivers.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
nical committed Jun 22, 2022
1 parent cbc3e0d commit 975ccc0
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion wgpu-hal/src/vulkan/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
}
}

Expand Down

0 comments on commit 975ccc0

Please sign in to comment.