[gl] fix usage of glFlushMappedBufferRange

`offset` is relative to the start of the mapping not the start of the buffer.
This commit is contained in:
teoxoy
2024-08-08 17:29:50 +02:00
committed by Erich Gubler
parent a6bc2f6f53
commit b594497f4a
2 changed files with 7 additions and 1 deletions

View File

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

View File

@@ -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)]