Skip to content

Commit 5e2df14

Browse files
committed
use StagingBuffer.flush() in Buffer.unmap_inner()
We should have always unmapped the staging buffer as we are using it on the GPU after this point.
1 parent 9a7f44b commit 5e2df14

File tree

2 files changed

+9
-11
lines changed

2 files changed

+9
-11
lines changed

wgpu-core/src/device/queue.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ impl<A: HalApi> PendingWrites<A> {
256256
self.temp_resources.push(resource);
257257
}
258258

259-
fn consume(&mut self, buffer: StagingBuffer<A>) {
259+
pub fn consume(&mut self, buffer: StagingBuffer<A>) {
260260
self.temp_resources
261261
.push(TempResource::StagingBuffer(buffer));
262262
}

wgpu-core/src/resource.rs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -669,12 +669,12 @@ impl<A: HalApi> Buffer<A> {
669669
}
670670
let _ = ptr;
671671

672-
if !staging_buffer.is_coherent {
673-
unsafe {
674-
device
675-
.raw()
676-
.flush_mapped_ranges(staging_buffer.raw(), iter::once(0..self.size));
677-
}
672+
let mut pending_writes = device.pending_writes.lock();
673+
let pending_writes = pending_writes.as_mut().unwrap();
674+
675+
if let Err(e) = unsafe { staging_buffer.flush() } {
676+
pending_writes.consume(staging_buffer);
677+
return Err(e.into());
678678
}
679679

680680
self.use_at(device.active_submission_index.load(Ordering::Relaxed) + 1);
@@ -691,8 +691,6 @@ impl<A: HalApi> Buffer<A> {
691691
buffer: raw_buf,
692692
usage: hal::BufferUses::empty()..hal::BufferUses::COPY_DST,
693693
};
694-
let mut pending_writes = device.pending_writes.lock();
695-
let pending_writes = pending_writes.as_mut().unwrap();
696694
let encoder = pending_writes.activate();
697695
unsafe {
698696
encoder.transition_buffers(
@@ -706,7 +704,7 @@ impl<A: HalApi> Buffer<A> {
706704
);
707705
}
708706
}
709-
pending_writes.consume_temp(queue::TempResource::StagingBuffer(staging_buffer));
707+
pending_writes.consume(staging_buffer);
710708
pending_writes.insert_buffer(self);
711709
}
712710
BufferMapState::Idle => {
@@ -866,7 +864,7 @@ pub struct StagingBuffer<A: HalApi> {
866864
raw: ManuallyDrop<A::Buffer>,
867865
device: Arc<Device<A>>,
868866
pub(crate) size: wgt::BufferSize,
869-
pub(crate) is_coherent: bool,
867+
is_coherent: bool,
870868
}
871869

872870
impl<A: HalApi> StagingBuffer<A> {

0 commit comments

Comments
 (0)