Only send mapping back on unmap when MapMode = WRITE (#34054)

Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
This commit is contained in:
Samson 2024-10-29 19:42:07 +01:00 committed by GitHub
parent d5554235fe
commit 43d1601016
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 20 additions and 23 deletions

View file

@ -995,25 +995,21 @@ impl WGPU {
};
self.maybe_dispatch_error(device_id, result.err());
},
WebGPURequest::UnmapBuffer {
buffer_id,
array_buffer,
write_back,
offset,
size,
} => {
WebGPURequest::UnmapBuffer { buffer_id, mapping } => {
let global = &self.global;
if write_back {
if let Ok((slice_pointer, range_size)) =
global.buffer_get_mapped_range(buffer_id, offset, Some(size))
{
if let Some(mapping) = mapping {
if let Ok((slice_pointer, range_size)) = global.buffer_get_mapped_range(
buffer_id,
mapping.range.start,
Some(mapping.range.end - mapping.range.start),
) {
unsafe {
slice::from_raw_parts_mut(
slice_pointer.as_ptr(),
range_size as usize,
)
}
.copy_from_slice(&array_buffer);
.copy_from_slice(&mapping.data);
}
}
// Ignore result because this operation always succeed from user perspective