Skip to content

Commit

Permalink
[gl] fix usage of glFlushMappedBufferRange
Browse files Browse the repository at this point in the history
`offset` is relative to the start of the mapping not the start of the buffer.
  • Loading branch information
teoxoy authored and ErichDonGubler committed Aug 12, 2024
1 parent a6bc2f6 commit b594497
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
7 changes: 6 additions & 1 deletion wgpu-hal/src/gles/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,7 @@ impl crate::Device for super::Device {
size: desc.size,
map_flags: 0,
data: Some(Arc::new(Mutex::new(vec![0; desc.size as usize]))),
offset_of_current_mapping: Arc::new(Mutex::new(0)),
});
}

Expand Down Expand Up @@ -635,6 +636,7 @@ impl crate::Device for super::Device {
size: desc.size,
map_flags,
data,
offset_of_current_mapping: Arc::new(Mutex::new(0)),
})
}

Expand Down Expand Up @@ -668,6 +670,7 @@ impl crate::Device for super::Device {
unsafe { self.shared.get_buffer_sub_data(gl, buffer.target, 0, slice) };
slice.as_mut_ptr()
} else {
*buffer.offset_of_current_mapping.lock().unwrap() = range.start;
unsafe {
gl.map_buffer_range(
buffer.target,
Expand All @@ -693,6 +696,7 @@ impl crate::Device for super::Device {
unsafe { gl.bind_buffer(buffer.target, Some(raw)) };
unsafe { gl.unmap_buffer(buffer.target) };
unsafe { gl.bind_buffer(buffer.target, None) };
*buffer.offset_of_current_mapping.lock().unwrap() = 0;
}
}
}
Expand All @@ -704,10 +708,11 @@ impl crate::Device for super::Device {
let gl = &self.shared.context.lock();
unsafe { gl.bind_buffer(buffer.target, Some(raw)) };
for range in ranges {
let offset_of_current_mapping = *buffer.offset_of_current_mapping.lock().unwrap();
unsafe {
gl.flush_mapped_buffer_range(
buffer.target,
range.start as i32,
(range.start - offset_of_current_mapping) as i32,
(range.end - range.start) as i32,
)
};
Expand Down
1 change: 1 addition & 0 deletions wgpu-hal/src/gles/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ pub struct Buffer {
size: wgt::BufferAddress,
map_flags: u32,
data: Option<Arc<std::sync::Mutex<Vec<u8>>>>,
offset_of_current_mapping: Arc<std::sync::Mutex<wgt::BufferAddress>>,
}

#[cfg(send_sync)]
Expand Down

0 comments on commit b594497

Please sign in to comment.