From e2dcac91d202ba9d88c3f235dacedfcd0737ad77 Mon Sep 17 00:00:00 2001 From: Dzmitry Malyshau Date: Tue, 23 Apr 2019 16:27:39 -0400 Subject: [PATCH] Round up mappable buffer size to non-coherent atom, if needed --- wgpu-native/src/device.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/wgpu-native/src/device.rs b/wgpu-native/src/device.rs index e7f7655901..fd78438470 100644 --- a/wgpu-native/src/device.rs +++ b/wgpu-native/src/device.rs @@ -502,10 +502,20 @@ pub fn device_create_buffer( .unwrap() .into(); // TODO: allocate with rendy + + // if the memory is mapped but not coherent, round up to the atom size + let mut mem_size = requirements.size; + if memory_properties.contains(hal::memory::Properties::CPU_VISIBLE) && + !memory_properties.contains(hal::memory::Properties::COHERENT) + { + let mask = device.limits.non_coherent_atom_size as u64 - 1; + mem_size = ((mem_size - 1 ) | mask) + 1; + } + let memory = unsafe { device .raw - .allocate_memory(device_type, requirements.size) + .allocate_memory(device_type, mem_size) .unwrap() }; unsafe {