Skip to content

Commit

Permalink
Use BufferSlice in StagingBelt::allocate().
Browse files Browse the repository at this point in the history
  • Loading branch information
kpreid committed Feb 19, 2025
1 parent b5e32ce commit 1e05be8
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions wgpu/src/util/belt.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::{
util::align_to, Buffer, BufferAddress, BufferDescriptor, BufferSize, BufferUsages,
util::align_to, Buffer, BufferAddress, BufferDescriptor, BufferSize, BufferSlice, BufferUsages,
BufferViewMut, CommandEncoder, Device, MapMode,
};
use std::fmt;
Expand Down Expand Up @@ -77,14 +77,14 @@ impl StagingBelt {
size: BufferSize,
device: &Device,
) -> BufferViewMut<'_> {
let (mapped, belt_buffer, offset_in_belt_buffer) = self.allocate(
let (mapped, slice_of_belt) = self.allocate(
size,
const { BufferSize::new(crate::COPY_BUFFER_ALIGNMENT).unwrap() },
device,
);
encoder.copy_buffer_to_buffer(
belt_buffer,
offset_in_belt_buffer,
slice_of_belt.buffer(),
slice_of_belt.offset(),
target,
offset,
size.get(),
Expand Down Expand Up @@ -120,7 +120,7 @@ impl StagingBelt {
size: BufferSize,
alignment: BufferSize,
device: &Device,
) -> (BufferViewMut<'_>, &Buffer, BufferAddress) {
) -> (BufferViewMut<'_>, BufferSlice<'_>) {
assert!(
alignment.get().is_power_of_two(),
"alignment must be a power of two, not {alignment}"
Expand Down Expand Up @@ -161,14 +161,10 @@ impl StagingBelt {
self.active_chunks.push(chunk);
let chunk = self.active_chunks.last().unwrap();

(
chunk
.buffer
.slice(allocation_offset..allocation_offset + size.get())
.get_mapped_range_mut(),
&chunk.buffer,
allocation_offset,
)
let slice = chunk
.buffer
.slice(allocation_offset..allocation_offset + size.get());
(slice.get_mapped_range_mut(), slice)
}

/// Prepare currently mapped buffers for use in a submission.
Expand Down

0 comments on commit 1e05be8

Please sign in to comment.