diff --git a/CHANGELOG.md b/CHANGELOG.md index 9a0287f43f..8592bd1505 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -45,6 +45,7 @@ Bottom level categories: #### General - Fix crash on dropping `wgpu::CommandBuffer`. By @wumpf in [#3726](https://github.com/gfx-rs/wgpu/pull/3726). +- Use `u32`s internally for bind group indices, rather than `u8`. By @ErichDonGubler in [#3743](https://github.com/gfx-rs/wgpu/pull/3743). #### WebGPU diff --git a/wgpu-core/src/binding_model.rs b/wgpu-core/src/binding_model.rs index 5c63ac43ff..97f56095f4 100644 --- a/wgpu-core/src/binding_model.rs +++ b/wgpu-core/src/binding_model.rs @@ -697,7 +697,7 @@ pub enum BindError { s1 = if *.actual >= 2 { "s" } else { "" }, )] MismatchedDynamicOffsetCount { - group: u8, + group: u32, actual: usize, expected: usize, }, @@ -706,7 +706,7 @@ pub enum BindError { )] UnalignedDynamicBinding { idx: usize, - group: u8, + group: u32, binding: u32, offset: u32, alignment: u32, @@ -718,7 +718,7 @@ pub enum BindError { )] DynamicBindingOutOfBounds { idx: usize, - group: u8, + group: u32, binding: u32, offset: u32, buffer_size: wgt::BufferAddress, @@ -780,7 +780,7 @@ pub struct BindGroup { impl BindGroup { pub(crate) fn validate_dynamic_bindings( &self, - bind_group_index: u8, + bind_group_index: u32, offsets: &[wgt::DynamicOffset], limits: &wgt::Limits, ) -> Result<(), BindError> { diff --git a/wgpu-core/src/command/bundle.rs b/wgpu-core/src/command/bundle.rs index fa95ff87fe..34d7e84cf4 100644 --- a/wgpu-core/src/command/bundle.rs +++ b/wgpu-core/src/command/bundle.rs @@ -302,7 +302,7 @@ impl RenderBundleEncoder { .map_pass_err(scope)?; let max_bind_groups = device.limits.max_bind_groups; - if (index as u32) >= max_bind_groups { + if index >= max_bind_groups { return Err(RenderCommandError::BindGroupIndexOutOfRange { index, max: max_bind_groups, @@ -784,7 +784,7 @@ impl RenderBundle { unsafe { raw.set_bind_group( &pipeline_layout_guard[pipeline_layout_id.unwrap()].raw, - index as u32, + index, &bind_group.raw, &offsets[..num_dynamic_offsets as usize], ) @@ -1222,7 +1222,7 @@ impl State { fn set_bind_group( &mut self, - slot: u8, + slot: u32, bind_group_id: id::BindGroupId, layout_id: id::Valid, dynamic_offsets: Range, @@ -1365,7 +1365,7 @@ impl State { contents.is_dirty = false; let offsets = &contents.dynamic_offsets; return Some(RenderCommand::SetBindGroup { - index: i as u8, + index: i.try_into().unwrap(), bind_group_id: contents.bind_group_id, num_dynamic_offsets: (offsets.end - offsets.start) as u8, }); @@ -1469,7 +1469,7 @@ pub mod bundle_ffi { } bundle.base.commands.push(RenderCommand::SetBindGroup { - index: index.try_into().unwrap(), + index, num_dynamic_offsets: offset_length.try_into().unwrap(), bind_group_id, }); diff --git a/wgpu-core/src/command/compute.rs b/wgpu-core/src/command/compute.rs index ce40b8b79f..d5b514f194 100644 --- a/wgpu-core/src/command/compute.rs +++ b/wgpu-core/src/command/compute.rs @@ -38,7 +38,7 @@ use std::{fmt, mem, str}; )] pub enum ComputeCommand { SetBindGroup { - index: u8, + index: u32, num_dynamic_offsets: u8, bind_group_id: id::BindGroupId, }, @@ -163,7 +163,7 @@ pub enum ComputePassErrorInner { #[error("Bind group {0:?} is invalid")] InvalidBindGroup(id::BindGroupId), #[error("Bind group index {index} is greater than the device's requested `max_bind_group` limit {max}")] - BindGroupIndexOutOfRange { index: u8, max: u32 }, + BindGroupIndexOutOfRange { index: u32, max: u32 }, #[error("Compute pipeline {0:?} is invalid")] InvalidPipeline(id::ComputePipelineId), #[error("QuerySet {0:?} is invalid")] @@ -407,7 +407,7 @@ impl Global { let scope = PassErrorScope::SetBindGroup(bind_group_id); let max_bind_groups = cmd_buf.limits.max_bind_groups; - if (index as u32) >= max_bind_groups { + if index >= max_bind_groups { return Err(ComputePassErrorInner::BindGroupIndexOutOfRange { index, max: max_bind_groups, @@ -464,7 +464,7 @@ impl Global { unsafe { raw.set_bind_group( pipeline_layout, - index as u32 + i as u32, + index + i as u32, raw_bg, &e.dynamic_offsets, ); @@ -816,7 +816,7 @@ pub mod compute_ffi { } pass.base.commands.push(ComputeCommand::SetBindGroup { - index: index.try_into().unwrap(), + index, num_dynamic_offsets: offset_length.try_into().unwrap(), bind_group_id, }); diff --git a/wgpu-core/src/command/draw.rs b/wgpu-core/src/command/draw.rs index 26d2849e26..b629ffaba0 100644 --- a/wgpu-core/src/command/draw.rs +++ b/wgpu-core/src/command/draw.rs @@ -66,7 +66,7 @@ pub enum RenderCommandError { #[error("Render bundle {0:?} is invalid")] InvalidRenderBundle(id::RenderBundleId), #[error("Bind group index {index} is greater than the device's requested `max_bind_group` limit {max}")] - BindGroupIndexOutOfRange { index: u8, max: u32 }, + BindGroupIndexOutOfRange { index: u32, max: u32 }, #[error("Dynamic buffer offset {0} does not respect device's requested `{1}` limit {2}")] UnalignedBufferOffset(u64, &'static str, u32), #[error("Number of buffer offsets ({actual}) does not match the number of dynamic bindings ({expected})")] @@ -148,7 +148,7 @@ pub struct Rect { )] pub enum RenderCommand { SetBindGroup { - index: u8, + index: u32, num_dynamic_offsets: u8, bind_group_id: id::BindGroupId, }, diff --git a/wgpu-core/src/command/render.rs b/wgpu-core/src/command/render.rs index 0570ae8a0a..b38e79c4b4 100644 --- a/wgpu-core/src/command/render.rs +++ b/wgpu-core/src/command/render.rs @@ -1305,7 +1305,7 @@ impl Global { } => { let scope = PassErrorScope::SetBindGroup(bind_group_id); let max_bind_groups = device.limits.max_bind_groups; - if (index as u32) >= max_bind_groups { + if index >= max_bind_groups { return Err(RenderCommandError::BindGroupIndexOutOfRange { index, max: max_bind_groups, @@ -1372,7 +1372,7 @@ impl Global { unsafe { raw.set_bind_group( pipeline_layout, - index as u32 + i as u32, + index + i as u32, raw_bg, &e.dynamic_offsets, ); @@ -2225,7 +2225,7 @@ pub mod render_ffi { } pass.base.commands.push(RenderCommand::SetBindGroup { - index: index.try_into().unwrap(), + index, num_dynamic_offsets: offset_length.try_into().unwrap(), bind_group_id, });