Skip to content

Commit 868c4a8

Browse files
konsolassuperdump
authored andcommitted
BatchedUniformBuffer: Optimize rounding code
1 parent 499e3a2 commit 868c4a8

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

crates/bevy_render/src/render_resource/batched_uniform_buffer.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ impl<T: GpuArrayBufferable> BatchedUniformBuffer<T> {
9191
self.uniforms.push(self.temp.clone());
9292

9393
self.current_offset +=
94-
round_up(self.temp.size().get(), self.dynamic_offset_alignment as u64) as u32;
94+
align_to_next(self.temp.size().get(), self.dynamic_offset_alignment as u64) as u32;
9595

9696
self.temp.0.clear();
9797
}
@@ -115,8 +115,9 @@ impl<T: GpuArrayBufferable> BatchedUniformBuffer<T> {
115115
}
116116

117117
#[inline]
118-
fn round_up(v: u64, a: u64) -> u64 {
119-
((v + a - 1) / a) * a
118+
fn align_to_next(value: u64, alignment: u64) -> u64 {
119+
debug_assert!(alignment & (alignment - 1) == 0);
120+
((value - 1) | (alignment - 1)) + 1
120121
}
121122

122123
// ----------------------------------------------------------------------------

0 commit comments

Comments
 (0)