mirror of
https://github.com/gfx-rs/wgpu.git
synced 2026-01-15 07:08:00 -05:00
Merge #916
916: Flush staging init buffers r=cwfitzgerald a=kvark **Connections** Related to https://github.com/gfx-rs/gfx/pull/3362 With the new use of `write_buffer`/`write_texture`, the results on D3D11 regressed. **Description** It just happened to be the case that all the backends returned coherent staging buffers, used internally for `write_*` and `mapped_at_creation == true`. However, D3D11 backend currently doesn't have the coherent memory at all, and it helped me to see that we were missing a flush() on the staging buffer. **Testing** Untested, but should work (tm). Co-authored-by: Dzmitry Malyshau <dmalyshau@mozilla.com>
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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),
|
||||
|
||||
Reference in New Issue
Block a user