Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Ensure proper unmap of buffer
  • Loading branch information
kunalmohan committed Jun 27, 2020
1 parent ef3b141 commit b484836
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 27 deletions.
22 changes: 11 additions & 11 deletions components/script/dom/gpubuffer.rs
Expand Up @@ -146,17 +146,17 @@ impl GPUBufferMethods for GPUBuffer {
match ArrayBuffer::from(self.mapping.get()) {
Ok(array_buffer) => {
// Step 3.2
if Some(GPUMapModeConstants::READ) != self.map_mode.get() {
self.channel
.0
.send(WebGPURequest::UnmapBuffer {
device_id: self.device.0,
buffer_id: self.id().0,
array_buffer: array_buffer.to_vec(),
mapped_at_creation: self.map_mode.get() == None,
})
.unwrap();
}
self.channel
.0
.send(WebGPURequest::UnmapBuffer {
buffer_id: self.id().0,
array_buffer: array_buffer.to_vec(),
is_map_read: self.map_mode.get() == Some(GPUMapModeConstants::READ),
offset: self.mapping_range.borrow().start,
size: self.mapping_range.borrow().end -
self.mapping_range.borrow().start,
})
.unwrap();
// Step 3.3
unsafe {
DetachArrayBuffer(*cx, self.mapping.handle());
Expand Down
29 changes: 13 additions & 16 deletions components/webgpu/lib.rs
Expand Up @@ -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,
},
}

Expand Down Expand Up @@ -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));
},
}
}
Expand Down

0 comments on commit b484836

Please sign in to comment.