Ensure proper unmap of buffer

This commit is contained in:
Kunal Mohan 2020-06-27 12:03:59 +05:30
parent ef3b141406
commit b484836dbc
2 changed files with 24 additions and 27 deletions

View file

@ -198,10 +198,11 @@ pub enum WebGPURequest {
image_key: webrender_api::ImageKey,
},
UnmapBuffer {
device_id: id::DeviceId,
buffer_id: id::BufferId,
array_buffer: Vec<u8>,
mapped_at_creation: bool,
is_map_read: bool,
offset: u64,
size: u64,
},
}
@ -931,27 +932,23 @@ impl<'a> WGPU<'a> {
gfx_select!(buffer_id => global.buffer_unmap(buffer_id));
},
WebGPURequest::UnmapBuffer {
device_id,
buffer_id,
array_buffer,
mapped_at_creation,
is_map_read,
offset,
size,
} => {
let global = &self.global;
if mapped_at_creation {
gfx_select!(device_id => global.queue_write_buffer(
device_id,
if !is_map_read {
let map_ptr = gfx_select!(buffer_id => global.buffer_get_mapped_range(
buffer_id,
0,
array_buffer.as_slice()
));
} else {
gfx_select!(buffer_id => global.device_set_buffer_sub_data(
device_id,
buffer_id,
0,
array_buffer.as_slice()
offset,
wgt::BufferSize::new(size)
));
unsafe { slice::from_raw_parts_mut(map_ptr, size as usize) }
.copy_from_slice(&array_buffer);
}
gfx_select!(buffer_id => global.buffer_unmap(buffer_id));
},
}
}