diff --git a/player/src/bin/play.rs b/player/src/bin/play.rs index 279681220..faff737a2 100644 --- a/player/src/bin/play.rs +++ b/player/src/bin/play.rs @@ -67,7 +67,7 @@ fn main() { Some(trace::Action::Init { desc, backend }) => { log::info!("Initializing the device for backend: {:?}", backend); let adapter = global - .pick_adapter( + .request_adapter( &wgc::instance::RequestAdapterOptions { power_preference: wgt::PowerPreference::Default, #[cfg(feature = "winit")] @@ -82,7 +82,7 @@ fn main() { ) .expect("Unable to find an adapter for selected backend"); - let info = gfx_select!(adapter => global.adapter_get_info(adapter)); + let info = gfx_select!(adapter => global.adapter_get_info(adapter)).unwrap(); log::info!("Picked '{}'", info.name); gfx_select!(adapter => global.adapter_request_device( adapter, diff --git a/player/src/lib.rs b/player/src/lib.rs index 921fb48ad..d149aab1e 100644 --- a/player/src/lib.rs +++ b/player/src/lib.rs @@ -155,21 +155,21 @@ impl GlobalPlay for wgc::hub::Global { } A::CreateBuffer(id, desc) => { let label = Label::new(&desc.label); - self.device_maintain_ids::(device); + self.device_maintain_ids::(device).unwrap(); self.device_create_buffer::(device, &desc.map_label(|_| label.as_ptr()), id) .unwrap(); } A::DestroyBuffer(id) => { - self.buffer_destroy::(id, true); + self.buffer_drop::(id, true); } A::CreateTexture(id, desc) => { let label = Label::new(&desc.label); - self.device_maintain_ids::(device); + self.device_maintain_ids::(device).unwrap(); self.device_create_texture::(device, &desc.map_label(|_| label.as_ptr()), id) .unwrap(); } A::DestroyTexture(id) => { - self.texture_destroy::(id); + self.texture_drop::(id); } A::CreateTextureView { id, @@ -177,7 +177,7 @@ impl GlobalPlay for wgc::hub::Global { desc, } => { let label = desc.as_ref().map_or(Label(None), |d| Label::new(&d.label)); - self.device_maintain_ids::(device); + self.device_maintain_ids::(device).unwrap(); self.texture_create_view::( parent_id, desc.map(|d| d.map_label(|_| label.as_ptr())).as_ref(), @@ -186,16 +186,16 @@ impl GlobalPlay for wgc::hub::Global { .unwrap(); } A::DestroyTextureView(id) => { - self.texture_view_destroy::(id).unwrap(); + self.texture_view_drop::(id).unwrap(); } A::CreateSampler(id, desc) => { let label = Label::new(&desc.label); - self.device_maintain_ids::(device); + self.device_maintain_ids::(device).unwrap(); self.device_create_sampler::(device, &desc.map_label(|_| label.as_ptr()), id) .unwrap(); } A::DestroySampler(id) => { - self.sampler_destroy::(id); + self.sampler_drop::(id); } A::GetSwapChainTexture { id, parent_id } => { if let Some(id) = id { @@ -210,23 +210,23 @@ impl GlobalPlay for wgc::hub::Global { .unwrap(); } A::DestroyBindGroupLayout(id) => { - self.bind_group_layout_destroy::(id); + self.bind_group_layout_drop::(id); } A::CreatePipelineLayout(id, desc) => { - self.device_maintain_ids::(device); + self.device_maintain_ids::(device).unwrap(); self.device_create_pipeline_layout::(device, &desc, id) .unwrap(); } A::DestroyPipelineLayout(id) => { - self.pipeline_layout_destroy::(id); + self.pipeline_layout_drop::(id); } A::CreateBindGroup(id, desc) => { - self.device_maintain_ids::(device); + self.device_maintain_ids::(device).unwrap(); self.device_create_bind_group::(device, &desc, id) .unwrap(); } A::DestroyBindGroup(id) => { - self.bind_group_destroy::(id); + self.bind_group_drop::(id); } A::CreateShaderModule { id, data } => { let source = if data.ends_with(".wgsl") { @@ -244,23 +244,23 @@ impl GlobalPlay for wgc::hub::Global { .unwrap(); } A::DestroyShaderModule(id) => { - self.shader_module_destroy::(id); + self.shader_module_drop::(id); } A::CreateComputePipeline(id, desc) => { - self.device_maintain_ids::(device); + self.device_maintain_ids::(device).unwrap(); self.device_create_compute_pipeline::(device, &desc, id) .unwrap(); } A::DestroyComputePipeline(id) => { - self.compute_pipeline_destroy::(id); + self.compute_pipeline_drop::(id); } A::CreateRenderPipeline(id, desc) => { - self.device_maintain_ids::(device); + self.device_maintain_ids::(device).unwrap(); self.device_create_render_pipeline::(device, &desc, id) .unwrap(); } A::DestroyRenderPipeline(id) => { - self.render_pipeline_destroy::(id); + self.render_pipeline_drop::(id); } A::CreateRenderBundle { id, desc, base } => { let label = Label::new(&desc.label.as_ref().unwrap()); @@ -276,7 +276,7 @@ impl GlobalPlay for wgc::hub::Global { .unwrap(); } A::DestroyRenderBundle(id) => { - self.render_bundle_destroy::(id); + self.render_bundle_drop::(id); } A::WriteBuffer { id, diff --git a/player/tests/test.rs b/player/tests/test.rs index 408dde336..f389e2b3d 100644 --- a/player/tests/test.rs +++ b/player/tests/test.rs @@ -141,7 +141,7 @@ impl Corpus { if !corpus.backends.contains(backend.into()) { continue; } - let adapter = match global.pick_adapter( + let adapter = match global.request_adapter( &wgc::instance::RequestAdapterOptions { power_preference: wgt::PowerPreference::Default, compatible_surface: None, @@ -151,12 +151,13 @@ impl Corpus { |id| id.backend(), ), ) { - Some(adapter) => adapter, - None => continue, + Ok(adapter) => adapter, + Err(_) => continue, }; println!("\tBackend {:?}", backend); - let supported_features = gfx_select!(adapter => global.adapter_features(adapter)); + let supported_features = + gfx_select!(adapter => global.adapter_features(adapter)).unwrap(); for test_path in &corpus.tests { println!("\t\tTest '{:?}'", test_path); let test = Test::load(dir.join(test_path), adapter.backend()); diff --git a/wgpu-core/src/binding_model.rs b/wgpu-core/src/binding_model.rs index cf68f6e05..214631688 100644 --- a/wgpu-core/src/binding_model.rs +++ b/wgpu-core/src/binding_model.rs @@ -3,8 +3,8 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ use crate::{ - device::SHADER_STAGE_COUNT, - id::{BindGroupLayoutId, BufferId, DeviceId, SamplerId, TextureViewId}, + device::{DeviceError, SHADER_STAGE_COUNT}, + id::{BindGroupLayoutId, BufferId, DeviceId, SamplerId, TextureViewId, Valid}, track::{TrackerSet, DUMMY_SELECTOR}, validation::{MissingBufferUsageError, MissingTextureUsageError}, FastHashMap, LifeGuard, MultiRefCount, RefCount, Stored, MAX_BIND_GROUPS, @@ -27,14 +27,14 @@ use thiserror::Error; #[derive(Clone, Debug, Error)] pub enum CreateBindGroupLayoutError { + #[error(transparent)] + Device(#[from] DeviceError), #[error("arrays of bindings unsupported for this type of binding")] ArrayUnsupported, #[error("conflicting binding at index {0}")] ConflictBinding(u32), #[error("required device feature is missing: {0:?}")] MissingFeature(wgt::Features), - #[error("not enough memory left")] - OutOfMemory, #[error(transparent)] TooManyBindings(BindingTypeMaxCountError), #[error("arrays of bindings can't be 0 elements long")] @@ -43,6 +43,16 @@ pub enum CreateBindGroupLayoutError { #[derive(Clone, Debug, Error)] pub enum CreateBindGroupError { + #[error(transparent)] + Device(#[from] DeviceError), + #[error("bind group layout is invalid")] + InvalidLayout, + #[error("buffer {0:?} is invalid")] + InvalidBuffer(BufferId), + #[error("texture view {0:?} is invalid")] + InvalidTextureView(TextureViewId), + #[error("sampler {0:?} is invalid")] + InvalidSampler(SamplerId), #[error("binding count declared with {expected} items, but {actual} items were provided")] BindingArrayLengthMismatch { actual: usize, expected: usize }, #[error("bound buffer range {range:?} does not fit in buffer of size {size}")] @@ -264,6 +274,10 @@ pub struct BindGroupLayout { #[derive(Clone, Debug, Error)] pub enum CreatePipelineLayoutError { + #[error(transparent)] + Device(#[from] DeviceError), + #[error("bind group layout {0:?} is invalid")] + InvalidBindGroupLayout(BindGroupLayoutId), #[error( "push constant at index {index} has range bound {bound} not aligned to {}", wgt::PUSH_CONSTANT_ALIGNMENT @@ -277,8 +291,6 @@ pub enum CreatePipelineLayoutError { provided: wgt::ShaderStage, intersected: wgt::ShaderStage, }, - #[error("not enough memory left")] - OutOfMemory, #[error("push constant at index {index} has range {}..{} which exceeds device push constant size limit 0..{max}", range.start, range.end)] PushConstantRangeTooLarge { index: usize, @@ -326,7 +338,7 @@ pub struct PipelineLayout { pub(crate) raw: B::PipelineLayout, pub(crate) device_id: Stored, pub(crate) life_guard: LifeGuard, - pub(crate) bind_group_layout_ids: ArrayVec<[BindGroupLayoutId; MAX_BIND_GROUPS]>, + pub(crate) bind_group_layout_ids: ArrayVec<[Valid; MAX_BIND_GROUPS]>, pub(crate) push_constant_ranges: ArrayVec<[wgt::PushConstantRange; SHADER_STAGE_COUNT]>, } @@ -459,7 +471,7 @@ pub struct BindGroupDynamicBindingData { pub struct BindGroup { pub(crate) raw: DescriptorSet, pub(crate) device_id: Stored, - pub(crate) layout_id: BindGroupLayoutId, + pub(crate) layout_id: Valid, pub(crate) life_guard: LifeGuard, pub(crate) used: TrackerSet, pub(crate) dynamic_binding_info: Vec, diff --git a/wgpu-core/src/command/allocator.rs b/wgpu-core/src/command/allocator.rs index 5c555d0d7..ea6ddbe09 100644 --- a/wgpu-core/src/command/allocator.rs +++ b/wgpu-core/src/command/allocator.rs @@ -4,8 +4,8 @@ use super::CommandBuffer; use crate::{ - hub::GfxBackend, id::DeviceId, track::TrackerSet, FastHashMap, PrivateFeatures, Stored, - SubmissionIndex, + device::DeviceError, hub::GfxBackend, id::DeviceId, track::TrackerSet, FastHashMap, + PrivateFeatures, Stored, SubmissionIndex, }; use hal::{command::CommandBuffer as _, device::Device as _, pool::CommandPool as _}; @@ -97,7 +97,7 @@ impl CommandAllocator { self.queue_family, hal::pool::CommandPoolCreateFlags::RESET_INDIVIDUAL, ) - .or(Err(CommandAllocatorError::OutOfMemory))? + .or(Err(DeviceError::OutOfMemory))? }; let pool = CommandPool { raw, @@ -147,7 +147,7 @@ impl CommandAllocator { queue_family, hal::pool::CommandPoolCreateFlags::RESET_INDIVIDUAL, ) - .or(Err(CommandAllocatorError::OutOfMemory))? + .or(Err(DeviceError::OutOfMemory))? }, total: 0, available: Vec::new(), @@ -256,6 +256,6 @@ impl CommandAllocator { #[derive(Clone, Debug, Error)] pub enum CommandAllocatorError { - #[error("not enough memory left")] - OutOfMemory, + #[error(transparent)] + Device(#[from] DeviceError), } diff --git a/wgpu-core/src/command/bind.rs b/wgpu-core/src/command/bind.rs index 272c644b0..ba1c3296b 100644 --- a/wgpu-core/src/command/bind.rs +++ b/wgpu-core/src/command/bind.rs @@ -6,7 +6,7 @@ use crate::{ binding_model::{BindGroup, PipelineLayout}, device::SHADER_STAGE_COUNT, hub::{GfxBackend, Storage}, - id::{BindGroupId, BindGroupLayoutId, PipelineLayoutId}, + id::{BindGroupId, BindGroupLayoutId, PipelineLayoutId, Valid}, Stored, MAX_BIND_GROUPS, }; @@ -17,15 +17,15 @@ use wgt::DynamicOffset; type BindGroupMask = u8; #[derive(Clone, Debug)] -pub struct BindGroupPair { - layout_id: BindGroupLayoutId, +pub(super) struct BindGroupPair { + layout_id: Valid, group_id: Stored, } #[derive(Debug)] -pub enum LayoutChange<'a> { +pub(super) enum LayoutChange<'a> { Unchanged, - Match(BindGroupId, &'a [DynamicOffset]), + Match(Valid, &'a [DynamicOffset]), Mismatch, } @@ -36,11 +36,11 @@ pub enum Provision { } #[derive(Clone)] -pub struct FollowUpIter<'a> { +pub(super) struct FollowUpIter<'a> { iter: slice::Iter<'a, BindGroupEntry>, } impl<'a> Iterator for FollowUpIter<'a> { - type Item = (BindGroupId, &'a [DynamicOffset]); + type Item = (Valid, &'a [DynamicOffset]); fn next(&mut self) -> Option { self.iter .next() @@ -49,8 +49,8 @@ impl<'a> Iterator for FollowUpIter<'a> { } #[derive(Clone, Default, Debug)] -pub struct BindGroupEntry { - expected_layout_id: Option, +pub(super) struct BindGroupEntry { + expected_layout_id: Option>, provided: Option, dynamic_offsets: Vec, } @@ -58,11 +58,11 @@ pub struct BindGroupEntry { impl BindGroupEntry { fn provide( &mut self, - bind_group_id: BindGroupId, + bind_group_id: Valid, bind_group: &BindGroup, offsets: &[DynamicOffset], ) -> Provision { - debug_assert_eq!(B::VARIANT, bind_group_id.backend()); + debug_assert_eq!(B::VARIANT, bind_group_id.0.backend()); let was_compatible = match self.provided { Some(BindGroupPair { @@ -91,7 +91,10 @@ impl BindGroupEntry { Provision::Changed { was_compatible } } - pub fn expect_layout(&mut self, bind_group_layout_id: BindGroupLayoutId) -> LayoutChange { + pub fn expect_layout( + &mut self, + bind_group_layout_id: Valid, + ) -> LayoutChange { let some = Some(bind_group_layout_id); if self.expected_layout_id != some { self.expected_layout_id = some; @@ -117,7 +120,7 @@ impl BindGroupEntry { } } - fn actual_value(&self) -> Option { + fn actual_value(&self) -> Option> { self.expected_layout_id.and_then(|layout_id| { self.provided.as_ref().and_then(|pair| { if pair.layout_id == layout_id { @@ -132,12 +135,12 @@ impl BindGroupEntry { #[derive(Debug)] pub struct Binder { - pub(crate) pipeline_layout_id: Option, //TODO: strongly `Stored` - pub(crate) entries: ArrayVec<[BindGroupEntry; MAX_BIND_GROUPS]>, + pub(super) pipeline_layout_id: Option>, //TODO: strongly `Stored` + pub(super) entries: ArrayVec<[BindGroupEntry; MAX_BIND_GROUPS]>, } impl Binder { - pub(crate) fn new(max_bind_groups: u32) -> Self { + pub(super) fn new(max_bind_groups: u32) -> Self { Self { pipeline_layout_id: None, entries: (0..max_bind_groups) @@ -146,15 +149,15 @@ impl Binder { } } - pub(crate) fn reset(&mut self) { + pub(super) fn reset(&mut self) { self.pipeline_layout_id = None; self.entries.clear(); } - pub(crate) fn change_pipeline_layout( + pub(super) fn change_pipeline_layout( &mut self, guard: &Storage, PipelineLayoutId>, - new_id: PipelineLayoutId, + new_id: Valid, ) { let old_id_opt = self.pipeline_layout_id.replace(new_id); let new = &guard[new_id]; @@ -180,15 +183,15 @@ impl Binder { /// (i.e. compatible with current expectations). Also returns an iterator /// of bind group IDs to be bound with it: those are compatible bind groups /// that were previously blocked because the current one was incompatible. - pub(crate) fn provide_entry<'a, B: GfxBackend>( + pub(super) fn provide_entry<'a, B: GfxBackend>( &'a mut self, index: usize, - bind_group_id: BindGroupId, + bind_group_id: Valid, bind_group: &BindGroup, offsets: &[DynamicOffset], - ) -> Option<(PipelineLayoutId, FollowUpIter<'a>)> { + ) -> Option<(Valid, FollowUpIter<'a>)> { tracing::trace!("\tBinding [{}] = group {:?}", index, bind_group_id); - debug_assert_eq!(B::VARIANT, bind_group_id.backend()); + debug_assert_eq!(B::VARIANT, bind_group_id.0.backend()); match self.entries[index].provide(bind_group_id, bind_group, offsets) { Provision::Unchanged => None, @@ -215,7 +218,7 @@ impl Binder { } } - pub(crate) fn invalid_mask(&self) -> BindGroupMask { + pub(super) fn invalid_mask(&self) -> BindGroupMask { self.entries.iter().enumerate().fold(0, |mask, (i, entry)| { if entry.is_valid() { mask diff --git a/wgpu-core/src/command/bundle.rs b/wgpu-core/src/command/bundle.rs index 9ceab782f..4279ffdba 100644 --- a/wgpu-core/src/command/bundle.rs +++ b/wgpu-core/src/command/bundle.rs @@ -38,16 +38,18 @@ #![allow(clippy::reversed_empty_ranges)] use crate::{ - binding_model::PushConstantUploadError, - command::{BasePass, RenderCommand}, + command::{BasePass, DrawError, RenderCommand, RenderCommandError}, conv, - device::{AttachmentData, Label, RenderPassContext, MAX_VERTEX_BUFFERS, SHADER_STAGE_COUNT}, + device::{ + AttachmentData, DeviceError, Label, RenderPassContext, MAX_VERTEX_BUFFERS, + SHADER_STAGE_COUNT, + }, hub::{GfxBackend, Global, GlobalIdentityHandlerFactory, Input, Storage, Token}, id, resource::BufferUse, span, track::TrackerSet, - validation::{check_buffer_usage, MissingBufferUsageError, MissingTextureUsageError}, + validation::check_buffer_usage, LifeGuard, RefCount, Stored, MAX_BIND_GROUPS, }; use arrayvec::ArrayVec; @@ -124,9 +126,12 @@ impl RenderBundle { /// This is partially duplicating the logic of `command_encoder_run_render_pass`. /// However the point of this function is to be lighter, since we already had /// a chance to go through the commands in `render_bundle_encoder_finish`. + /// + /// Note that the function isn't expected to fail. + /// All the validation has already been done by this point. pub(crate) unsafe fn execute( &self, - cmdbuf: &mut B::CommandBuffer, + cmd_buf: &mut B::CommandBuffer, pipeline_layout_guard: &Storage< crate::binding_model::PipelineLayout, id::PipelineLayoutId, @@ -134,12 +139,12 @@ impl RenderBundle { bind_group_guard: &Storage, id::BindGroupId>, pipeline_guard: &Storage, id::RenderPipelineId>, buffer_guard: &Storage, id::BufferId>, - ) -> Result<(), RenderCommandError> { + ) { use hal::command::CommandBuffer as _; let mut offsets = self.base.dynamic_offsets.as_slice(); let mut index_type = hal::IndexType::U16; - let mut pipeline_layout_id = None::; + let mut pipeline_layout_id = None::>; for command in self.base.commands.iter() { match *command { @@ -148,8 +153,8 @@ impl RenderBundle { num_dynamic_offsets, bind_group_id, } => { - let bind_group = &bind_group_guard[bind_group_id]; - cmdbuf.bind_graphics_descriptor_sets( + let bind_group = bind_group_guard.get(bind_group_id).unwrap(); + cmd_buf.bind_graphics_descriptor_sets( &pipeline_layout_guard[pipeline_layout_id.unwrap()].raw, index as usize, iter::once(bind_group.raw.raw()), @@ -158,8 +163,8 @@ impl RenderBundle { offsets = &offsets[num_dynamic_offsets as usize..]; } RenderCommand::SetPipeline(pipeline_id) => { - let pipeline = &pipeline_guard[pipeline_id]; - cmdbuf.bind_graphics_pipeline(&pipeline.raw); + let pipeline = pipeline_guard.get(pipeline_id).unwrap(); + cmd_buf.bind_graphics_pipeline(&pipeline.raw); index_type = conv::map_index_format(pipeline.index_format); pipeline_layout_id = Some(pipeline.layout_id.value); } @@ -168,7 +173,7 @@ impl RenderBundle { offset, size, } => { - let buffer = &buffer_guard[buffer_id]; + let buffer = buffer_guard.get(buffer_id).unwrap(); let view = hal::buffer::IndexBufferView { buffer: &buffer.raw, range: hal::buffer::SubRange { @@ -178,7 +183,7 @@ impl RenderBundle { index_type, }; - cmdbuf.bind_index_buffer(view); + cmd_buf.bind_index_buffer(view); } RenderCommand::SetVertexBuffer { slot, @@ -186,12 +191,12 @@ impl RenderBundle { offset, size, } => { - let buffer = &buffer_guard[buffer_id]; + let buffer = buffer_guard.get(buffer_id).unwrap(); let range = hal::buffer::SubRange { offset, size: size.map(|s| s.get()), }; - cmdbuf.bind_vertex_buffers(slot, iter::once((&buffer.raw, range))); + cmd_buf.bind_vertex_buffers(slot, iter::once((&buffer.raw, range))); } RenderCommand::SetPushConstant { stages, @@ -199,8 +204,7 @@ impl RenderBundle { size_bytes, values_offset, } => { - let pipeline_layout_id = - pipeline_layout_id.ok_or(RenderCommandError::UnboundPipeline)?; + let pipeline_layout_id = pipeline_layout_id.unwrap(); let pipeline_layout = &pipeline_layout_guard[pipeline_layout_id]; if let Some(values_offset) = values_offset { @@ -208,7 +212,7 @@ impl RenderBundle { let data_slice = &self.base.push_constant_data [(values_offset as usize)..values_end_offset]; - cmdbuf.push_graphics_constants( + cmd_buf.push_graphics_constants( &pipeline_layout.raw, conv::map_shader_stage_flags(stages), offset, @@ -219,7 +223,7 @@ impl RenderBundle { offset, size_bytes, |clear_offset, clear_data| { - cmdbuf.push_graphics_constants( + cmd_buf.push_graphics_constants( &pipeline_layout.raw, conv::map_shader_stage_flags(stages), clear_offset, @@ -235,7 +239,7 @@ impl RenderBundle { first_vertex, first_instance, } => { - cmdbuf.draw( + cmd_buf.draw( first_vertex..first_vertex + vertex_count, first_instance..first_instance + instance_count, ); @@ -247,7 +251,7 @@ impl RenderBundle { base_vertex, first_instance, } => { - cmdbuf.draw_indexed( + cmd_buf.draw_indexed( first_index..first_index + index_count, base_vertex, first_instance..first_instance + instance_count, @@ -259,8 +263,8 @@ impl RenderBundle { count: None, indexed: false, } => { - let buffer = &buffer_guard[buffer_id]; - cmdbuf.draw_indirect(&buffer.raw, offset, 1, 0); + let buffer = buffer_guard.get(buffer_id).unwrap(); + cmd_buf.draw_indirect(&buffer.raw, offset, 1, 0); } RenderCommand::MultiDrawIndirect { buffer_id, @@ -268,8 +272,8 @@ impl RenderBundle { count: None, indexed: true, } => { - let buffer = &buffer_guard[buffer_id]; - cmdbuf.draw_indexed_indirect(&buffer.raw, offset, 1, 0); + let buffer = buffer_guard.get(buffer_id).unwrap(); + cmd_buf.draw_indexed_indirect(&buffer.raw, offset, 1, 0); } RenderCommand::MultiDrawIndirect { .. } | RenderCommand::MultiDrawIndirectCount { .. } => unimplemented!(), @@ -283,7 +287,6 @@ impl RenderBundle { | RenderCommand::SetScissor(_) => unreachable!(), } } - Ok(()) } } @@ -488,12 +491,12 @@ impl State { &mut self, slot: u8, bind_group_id: id::BindGroupId, - layout_id: id::BindGroupLayoutId, + layout_id: id::Valid, offsets: &[wgt::DynamicOffset], ) { if self.bind[slot as usize].set_group( bind_group_id, - layout_id, + layout_id.0, self.raw_dynamic_offsets.len(), offsets.len(), ) { @@ -506,7 +509,7 @@ impl State { &mut self, index_format: wgt::IndexFormat, vertex_strides: &[(wgt::BufferAddress, wgt::InputStepMode)], - layout_ids: &[id::BindGroupLayoutId], + layout_ids: &[id::Valid], push_constant_layouts: &[wgt::PushConstantRange], ) { self.index.set_format(index_format); @@ -529,8 +532,8 @@ impl State { self.bind .iter() .zip(layout_ids) - .position(|(bs, &layout_id)| match bs.bind_group { - Some((_, bgl_id)) => bgl_id != layout_id, + .position(|(bs, layout_id)| match bs.bind_group { + Some((_, bgl_id)) => bgl_id != layout_id.0, None => false, }) }; @@ -595,36 +598,15 @@ impl State { } } -/// Error encountered when encoding a render command. +/// Error encountered when finishing recording a render bundle. #[derive(Clone, Debug, Error)] -pub enum RenderCommandError { - #[error("bind group index {index} is greater than the device's requested `max_bind_group` limit {max}")] - BindGroupIndexOutOfRange { index: u8, max: u32 }, - #[error("dynamic buffer offset {0} does not respect `BIND_BUFFER_ALIGNMENT`")] - UnalignedBufferOffset(u64), - #[error("number of buffer offsets ({actual}) does not match the number of dynamic bindings ({expected})")] - InvalidDynamicOffsetCount { actual: usize, expected: usize }, - #[error("render pipeline output formats and sample counts do not match render pass attachment formats")] - IncompatiblePipeline, - #[error("pipeline is not compatible with the depth-stencil read-only render pass")] - IncompatibleReadOnlyDepthStencil, +pub enum RenderBundleError { #[error(transparent)] - MissingBufferUsage(#[from] MissingBufferUsageError), + Device(#[from] DeviceError), #[error(transparent)] - MissingTextureUsage(#[from] MissingTextureUsageError), - #[error("a render pipeline must be bound")] - UnboundPipeline, + RenderCommand(#[from] RenderCommandError), #[error(transparent)] - PushConstants(#[from] PushConstantUploadError), - #[error("vertex {last_vertex} extends beyond limit {vertex_limit}")] - VertexBeyondLimit { last_vertex: u32, vertex_limit: u32 }, - #[error("instance {last_instance} extends beyond limit {instance_limit}")] - InstanceBeyondLimit { - last_instance: u32, - instance_limit: u32, - }, - #[error("index {last_index} extends beyond limit {index_limit}")] - IndexBeyondLimit { last_index: u32, index_limit: u32 }, + Draw(#[from] DrawError), } impl Global { @@ -633,13 +615,15 @@ impl Global { bundle_encoder: RenderBundleEncoder, desc: &wgt::RenderBundleDescriptor