diff --git a/wgpu/src/util/device.rs b/wgpu/src/util/device.rs index dff6423674..06775ee305 100644 --- a/wgpu/src/util/device.rs +++ b/wgpu/src/util/device.rs @@ -37,8 +37,12 @@ pub trait DeviceExt { impl DeviceExt for crate::Device { fn create_buffer_init(&self, descriptor: &BufferInitDescriptor<'_>) -> crate::Buffer { let unpadded_size = descriptor.contents.len() as crate::BufferAddress; - let padding = crate::COPY_BUFFER_ALIGNMENT - unpadded_size % crate::COPY_BUFFER_ALIGNMENT; - let padded_size = padding + unpadded_size; + // Valid vulkan usage is + // 1. buffer size must be a multiple of COPY_BUFFER_ALIGNMENT. + // 2. buffer size must be greater than 0. + // Therefore we round the value up to the nearest multiple, and ensure it's at least COPY_BUFFER_ALIGNMENT. + let align_mask = crate::COPY_BUFFER_ALIGNMENT - 1; + let padded_size = ((unpadded_size + align_mask) & !align_mask).max(crate::COPY_BUFFER_ALIGNMENT); let wgt_descriptor = crate::BufferDescriptor { label: descriptor.label,