Merge pull request #25 from ztlpn/fix-mapping-size

Fix read mapping size in the Vulkan adapter
This commit is contained in:
Raph Levien 2020-07-02 11:45:50 -07:00 committed by GitHub
commit 2c0f1d3cdd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -744,18 +744,18 @@ impl crate::Device for VkDevice {
result: &mut Vec<T>, result: &mut Vec<T>,
) -> Result<(), Error> { ) -> Result<(), Error> {
let device = &self.device.device; let device = &self.device.device;
let size = buffer.size as usize / std::mem::size_of::<T>();
let buf = device.map_memory( let buf = device.map_memory(
buffer.buffer_memory, buffer.buffer_memory,
0, 0,
size as u64, buffer.size,
vk::MemoryMapFlags::empty(), vk::MemoryMapFlags::empty(),
)?; )?;
if size > result.len() { let len = buffer.size as usize / std::mem::size_of::<T>();
result.reserve(size - result.len()); if len > result.len() {
result.reserve(len - result.len());
} }
std::ptr::copy_nonoverlapping(buf as *const T, result.as_mut_ptr(), size); std::ptr::copy_nonoverlapping(buf as *const T, result.as_mut_ptr(), len);
result.set_len(size); result.set_len(len);
device.unmap_memory(buffer.buffer_memory); device.unmap_memory(buffer.buffer_memory);
Ok(()) Ok(())
} }