Skip to content

Commit

Permalink
gpu: Remove second lifetime parameter from BeltWritingParts.
Browse files Browse the repository at this point in the history
At the time I wrote this I must have still not fully understood how to
work with mutable references’ invariance. In fact, `&'a mut T` is
invariant in `T` only, not `'a`, so there is no reason for a structure
of references not to use the same lifetime for all references regardless
of whether mutable or immutable, as long as the lifetime does not appear
in any of the referents.

The one exception is if it were desirable to be able to copy out a
longer-lived `&'sh wgpu::Device`, but that does not occur in this
situation — if we needed that, we'd make an `Arc<Device>` or otherwise
do it separately from `BeltWritingParts`, which is about writing to the
stating belt and nothing else.
  • Loading branch information
kpreid committed Jan 11, 2025
1 parent a337a63 commit a5aba5d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
20 changes: 10 additions & 10 deletions all-is-cubes-gpu/src/in_wgpu/glue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,17 +98,17 @@ pub fn extent_to_size3d(size: wgpu::Extent3d) -> GridSize {
GridSize::new(size.width, size.height, size.depth_or_array_layers)
}

pub(crate) struct BeltWritingParts<'sh, 'mu> {
pub device: &'sh wgpu::Device,
pub belt: &'mu mut wgpu::util::StagingBelt,
pub encoder: &'mu mut wgpu::CommandEncoder,
/// The ingredients to make use of a [`wgpu::util::StagingBelt`].
pub(crate) struct BeltWritingParts<'a> {
pub device: &'a wgpu::Device,
pub belt: &'a mut wgpu::util::StagingBelt,
pub encoder: &'a mut wgpu::CommandEncoder,
}

impl<'sh, 'mu> BeltWritingParts<'sh, 'mu> {
pub fn reborrow<'r>(&'r mut self) -> BeltWritingParts<'sh, 'r>
where
'mu: 'r,
{
impl BeltWritingParts<'_> {
/// Borrow `self` to produce another `BeltWritingParts` that can be consumed (moved)
/// without losing this one.
pub fn reborrow(&mut self) -> BeltWritingParts<'_> {
BeltWritingParts {
device: self.device,
belt: self.belt,
Expand Down Expand Up @@ -145,7 +145,7 @@ impl ResizingBuffer {
/// if the existing buffer is used. TODO: Provide a means of lazy loading the label.
pub(crate) fn write_with_resizing(
&mut self,
mut bwp: BeltWritingParts<'_, '_>,
mut bwp: BeltWritingParts<'_>,
descriptor: &wgpu::util::BufferInitDescriptor<'_>,
) {
let new_size: u64 = descriptor.contents.len().try_into().unwrap();
Expand Down
4 changes: 2 additions & 2 deletions all-is-cubes-gpu/src/in_wgpu/space.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ impl<I: time::Instant> SpaceRenderer<I> {
queue: &wgpu::Queue,
pipelines: &Pipelines,
camera: &Camera,
mut bwp: BeltWritingParts<'_, '_>,
mut bwp: BeltWritingParts<'_>,
) -> Result<SpaceUpdateInfo, RenderError> {
let start_time = I::now();

Expand Down Expand Up @@ -957,7 +957,7 @@ fn set_buffers<'a>(render_pass: &mut wgpu::RenderPass<'a>, buffers: &'a ChunkBuf
reason = "https://github.com/rust-lang/rust-clippy/issues/12525"
)]
fn update_chunk_buffers<I: time::Instant>(
mut bwp: BeltWritingParts<'_, '_>,
mut bwp: BeltWritingParts<'_>,
update: RenderDataUpdate<'_, WgpuMt<I>>,
space_label: &str,
) {
Expand Down

0 comments on commit a5aba5d

Please sign in to comment.