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.
This commit is contained in:
James Liu 2024-03-02 08:00:28 -08:00 committed by GitHub
parent 45f7af6282
commit eb52a489ad
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 4 additions and 4 deletions

View file

@ -88,7 +88,7 @@ pub fn batch_and_prepare_render_phase<I: CachedRenderPipelinePhaseItem, F: GetBa
let (buffer_data, compare_data) = F::get_batch_data(&system_param_item, item.entity())?;
let buffer_index = gpu_array_buffer.push(buffer_data);
let index = buffer_index.index.get();
let index = buffer_index.index;
*item.batch_range_mut() = index..index + 1;
*item.dynamic_offset_mut() = buffer_index.dynamic_offset;

View file

@ -81,7 +81,7 @@ impl<T: GpuArrayBufferable> BatchedUniformBuffer<T> {
pub fn push(&mut self, component: T) -> GpuArrayBufferIndex<T> {
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,
};

View file

@ -57,7 +57,7 @@ impl<T: GpuArrayBufferable> GpuArrayBuffer<T> {
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<T: GpuArrayBufferable> GpuArrayBuffer<T> {
#[derive(Component, Clone)]
pub struct GpuArrayBufferIndex<T: GpuArrayBufferable> {
/// 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<NonMaxU32>,