From eb52a489adfeb6457089beee83789a5dc6846090 Mon Sep 17 00:00:00 2001 From: James Liu Date: Sat, 2 Mar 2024 08:00:28 -0800 Subject: [PATCH] Batching: replace GpuArrayBufferIndex::index with a u32 (#12250) # Objective While mucking around with batch_and_prepare systems, it became apparent that `GpuArrayBufferIndex::index` doesn't need to be a NonMaxU32. ## Solution Replace it with a normal u32. This likely has some potential perf benefit by avoiding panics and the NOT operations, but I haven't been able to find any substantial gains, so this is primarily for code quality. --- ## Changelog Changed: `GpuArrayBufferIndex::index` is now a u32. ## Migration Guide `GpuArrayBuferIndex::index` is now a u32 instead of a `NonMaxU32`. Remove any calls to `NonMaxU32::get` on the member. --- crates/bevy_render/src/batching/mod.rs | 2 +- .../bevy_render/src/render_resource/batched_uniform_buffer.rs | 2 +- crates/bevy_render/src/render_resource/gpu_array_buffer.rs | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/crates/bevy_render/src/batching/mod.rs b/crates/bevy_render/src/batching/mod.rs index 859d56e98d..6f16617fe7 100644 --- a/crates/bevy_render/src/batching/mod.rs +++ b/crates/bevy_render/src/batching/mod.rs @@ -88,7 +88,7 @@ pub fn batch_and_prepare_render_phase BatchedUniformBuffer { pub fn push(&mut self, component: T) -> GpuArrayBufferIndex { let result = GpuArrayBufferIndex { - index: NonMaxU32::new(self.temp.0.len() as u32).unwrap(), + index: self.temp.0.len() as u32, dynamic_offset: NonMaxU32::new(self.current_offset), element_type: PhantomData, }; diff --git a/crates/bevy_render/src/render_resource/gpu_array_buffer.rs b/crates/bevy_render/src/render_resource/gpu_array_buffer.rs index dbfe6a5962..1d314f0a1d 100644 --- a/crates/bevy_render/src/render_resource/gpu_array_buffer.rs +++ b/crates/bevy_render/src/render_resource/gpu_array_buffer.rs @@ -57,7 +57,7 @@ impl GpuArrayBuffer { GpuArrayBuffer::Uniform(buffer) => buffer.push(value), GpuArrayBuffer::Storage(buffer) => { let buffer = buffer.get_mut(); - let index = NonMaxU32::new(buffer.len() as u32).unwrap(); + let index = buffer.len() as u32; buffer.push(value); GpuArrayBufferIndex { index, @@ -109,7 +109,7 @@ impl GpuArrayBuffer { #[derive(Component, Clone)] pub struct GpuArrayBufferIndex { /// The index to use in a shader into the array. - pub index: NonMaxU32, + pub index: u32, /// The dynamic offset to use when setting the bind group in a pass. /// Only used on platforms that don't support storage buffers. pub dynamic_offset: Option,