Flush staging init buffers

This commit is contained in:
Dzmitry Malyshau 2020-09-02 15:52:18 -04:00
parent 6df8421f22
commit 35d2ed39b5
2 changed files with 19 additions and 4 deletions

View File

@ -1032,13 +1032,13 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
},
gfx_memory::Kind::Linear,
)?;
let ptr = stage
let mapped = stage
.memory
.map(&device.raw, hal::memory::Segment::ALL)
.map_err(resource::BufferAccessError::from)?
.ptr();
.map_err(resource::BufferAccessError::from)?;
buffer.map_state = resource::BufferMapState::Init {
ptr,
ptr: mapped.ptr(),
needs_flush: !mapped.is_coherent(),
stage_buffer: stage.raw,
stage_memory: stage.memory,
};
@ -3681,6 +3681,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
ptr,
stage_buffer,
stage_memory,
needs_flush,
} => {
#[cfg(feature = "trace")]
match device.trace {
@ -3700,6 +3701,19 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
};
let _ = ptr;
if needs_flush {
let segment = hal::memory::Segment::default();
unsafe {
device
.raw
.flush_mapped_memory_ranges(iter::once((
stage_memory.memory(),
segment,
)))
.unwrap()
};
}
buffer.life_guard.use_at(device.active_submission_index + 1);
let region = hal::command::BufferCopy {
src: 0,

View File

@ -85,6 +85,7 @@ pub(crate) enum BufferMapState<B: hal::Backend> {
ptr: NonNull<u8>,
stage_buffer: B::Buffer,
stage_memory: MemoryBlock<B>,
needs_flush: bool,
},
/// Waiting for GPU to be done before mapping
Waiting(BufferPendingMapping),