Make DynamicUniformBuffer::push accept an &T instead of T (#11373)

# Objective

- `DynamicUniformBuffer::push` takes an owned `T` but only uses a shared
reference to it
- This in turn requires users of `DynamicUniformBuffer::push` to
potentially unecessarily clone data

## Solution

- Have `DynamicUniformBuffer::push` take a shared reference to `T`

---

## Changelog

- `DynamicUniformBuffer::push` now takes a `&T` instead of `T`

## Migration Guide

- Users of `DynamicUniformBuffer::push` now need to pass references to
`DynamicUniformBuffer::push` (e.g. existing `uniforms.push(value)` will
now become `uniforms.push(&value)`)
This commit is contained in:
Giacomo Stevanato 2024-01-16 21:51:56 +01:00 committed by GitHub
parent ea42d14344
commit 39cca41f3f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 3 additions and 3 deletions

View file

@ -89,7 +89,7 @@ impl<T: GpuArrayBufferable> BatchedUniformBuffer<T> {
}
pub fn flush(&mut self) {
self.uniforms.push(self.temp.clone());
self.uniforms.push(&self.temp);
self.current_offset +=
align_to_next(self.temp.size().get(), self.dynamic_offset_alignment as u64) as u32;

View file

@ -227,8 +227,8 @@ impl<T: ShaderType + WriteInto> DynamicUniformBuffer<T> {
/// Push data into the `DynamicUniformBuffer`'s internal vector (residing on system RAM).
#[inline]
pub fn push(&mut self, value: T) -> u32 {
self.scratch.write(&value).unwrap() as u32
pub fn push(&mut self, value: &T) -> u32 {
self.scratch.write(value).unwrap() as u32
}
pub fn set_label(&mut self, label: Option<&str>) {