diff --git a/Cargo.lock b/Cargo.lock index f3222ee74b..d7299452e9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -59,9 +59,9 @@ dependencies = [ [[package]] name = "arrayvec" -version = "0.5.2" +version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23b62fc65de8e4e7f52534fb52b0f3ed04746ae267519eef2a83941e8085068b" +checksum = "be4dc07131ffa69b8072d35f5007352af944213cde02545e2103680baed38fcd" dependencies = [ "serde", ] diff --git a/wgpu-core/Cargo.toml b/wgpu-core/Cargo.toml index 9cc6f2c705..59519a2194 100644 --- a/wgpu-core/Cargo.toml +++ b/wgpu-core/Cargo.toml @@ -21,7 +21,7 @@ replay = ["serde", "wgt/replay", "arrayvec/serde", "naga/deserialize"] serial-pass = ["serde", "wgt/serde", "arrayvec/serde"] [dependencies] -arrayvec = "0.5" +arrayvec = "0.7" bitflags = "1.0" copyless = "0.1" fxhash = "0.2" diff --git a/wgpu-core/src/binding_model.rs b/wgpu-core/src/binding_model.rs index a4d2a560a0..0e0cd78c13 100644 --- a/wgpu-core/src/binding_model.rs +++ b/wgpu-core/src/binding_model.rs @@ -496,8 +496,8 @@ pub struct PipelineLayout { pub(crate) raw: A::PipelineLayout, pub(crate) device_id: Stored, pub(crate) life_guard: LifeGuard, - pub(crate) bind_group_layout_ids: ArrayVec<[Valid; hal::MAX_BIND_GROUPS]>, - pub(crate) push_constant_ranges: ArrayVec<[wgt::PushConstantRange; SHADER_STAGE_COUNT]>, + pub(crate) bind_group_layout_ids: ArrayVec, { hal::MAX_BIND_GROUPS }>, + pub(crate) push_constant_ranges: ArrayVec, } impl PipelineLayout { diff --git a/wgpu-core/src/command/bind.rs b/wgpu-core/src/command/bind.rs index 4ba251aa9e..0a210e2b23 100644 --- a/wgpu-core/src/command/bind.rs +++ b/wgpu-core/src/command/bind.rs @@ -228,13 +228,13 @@ struct PushConstantChange { /// to every possible value. pub fn compute_nonoverlapping_ranges( ranges: &[wgt::PushConstantRange], -) -> ArrayVec<[wgt::PushConstantRange; SHADER_STAGE_COUNT * 2]> { +) -> ArrayVec { if ranges.is_empty() { return ArrayVec::new(); } debug_assert!(ranges.len() <= SHADER_STAGE_COUNT); - let mut breaks: ArrayVec<[PushConstantChange; SHADER_STAGE_COUNT * 2]> = ArrayVec::new(); + let mut breaks: ArrayVec = ArrayVec::new(); for range in ranges { breaks.push(PushConstantChange { stages: range.stages, diff --git a/wgpu-core/src/command/bundle.rs b/wgpu-core/src/command/bundle.rs index 110a9b2599..8a011e1890 100644 --- a/wgpu-core/src/command/bundle.rs +++ b/wgpu-core/src/command/bundle.rs @@ -906,7 +906,7 @@ impl BindState { #[derive(Debug)] struct PushConstantState { - ranges: ArrayVec<[wgt::PushConstantRange; SHADER_STAGE_COUNT]>, + ranges: ArrayVec, is_dirty: bool, } impl PushConstantState { @@ -944,8 +944,8 @@ struct VertexLimitState { struct State { trackers: TrackerSet, index: IndexState, - vertex: ArrayVec<[VertexState; hal::MAX_VERTEX_BUFFERS]>, - bind: ArrayVec<[BindState; hal::MAX_BIND_GROUPS]>, + vertex: ArrayVec, + bind: ArrayVec, push_constant_ranges: PushConstantState, raw_dynamic_offsets: Vec, flat_dynamic_offsets: Vec, diff --git a/wgpu-core/src/command/render.rs b/wgpu-core/src/command/render.rs index 0af4db7f2b..eb2053e192 100644 --- a/wgpu-core/src/command/render.rs +++ b/wgpu-core/src/command/render.rs @@ -154,7 +154,7 @@ pub struct RenderPassDescriptor<'a> { pub struct RenderPass { base: BasePass, parent_id: id::CommandEncoderId, - color_targets: ArrayVec<[RenderPassColorAttachment; hal::MAX_COLOR_TARGETS]>, + color_targets: ArrayVec, depth_stencil_target: Option, } @@ -277,7 +277,7 @@ impl VertexBufferState { #[derive(Debug, Default)] struct VertexState { - inputs: ArrayVec<[VertexBufferState; hal::MAX_VERTEX_BUFFERS]>, + inputs: ArrayVec, /// Length of the shortest vertex rate vertex buffer vertex_limit: u32, /// Buffer slot which the shortest vertex rate vertex buffer is bound to @@ -495,7 +495,7 @@ struct RenderAttachment<'a> { new_use: hal::TextureUses, } -type AttachmentDataVec = ArrayVec<[T; hal::MAX_COLOR_TARGETS + hal::MAX_COLOR_TARGETS + 1]>; +type AttachmentDataVec = ArrayVec; struct RenderPassInfo<'a, A: hal::Api> { context: RenderPassContext, @@ -552,7 +552,7 @@ impl<'a, A: HalApi> RenderPassInfo<'a, A> { Ok(()) }; - let mut colors = ArrayVec::<[hal::ColorAttachment; hal::MAX_COLOR_TARGETS]>::new(); + let mut colors = ArrayVec::, { hal::MAX_COLOR_TARGETS }>::new(); let mut depth_stencil = None; if let Some(at) = depth_stencil_attachment { diff --git a/wgpu-core/src/device/mod.rs b/wgpu-core/src/device/mod.rs index 47be0230e8..05b0d04498 100644 --- a/wgpu-core/src/device/mod.rs +++ b/wgpu-core/src/device/mod.rs @@ -45,8 +45,8 @@ pub enum HostMap { #[derive(Clone, Debug, Hash, PartialEq)] #[cfg_attr(feature = "serial-pass", derive(serde::Deserialize, serde::Serialize))] pub(crate) struct AttachmentData { - pub colors: ArrayVec<[T; hal::MAX_COLOR_TARGETS]>, - pub resolves: ArrayVec<[T; hal::MAX_COLOR_TARGETS]>, + pub colors: ArrayVec, + pub resolves: ArrayVec, pub depth_stencil: Option, } impl Eq for AttachmentData {} @@ -70,8 +70,8 @@ pub(crate) struct RenderPassContext { pub enum RenderPassCompatibilityError { #[error("Incompatible color attachment: {0:?} != {1:?}")] IncompatibleColorAttachment( - ArrayVec<[TextureFormat; hal::MAX_COLOR_TARGETS]>, - ArrayVec<[TextureFormat; hal::MAX_COLOR_TARGETS]>, + ArrayVec, + ArrayVec, ), #[error("Incompatible depth-stencil attachment: {0:?} != {1:?}")] IncompatibleDepthStencilAttachment(Option, Option), @@ -962,7 +962,7 @@ impl Device { fn get_introspection_bind_group_layouts<'a>( pipeline_layout: &binding_model::PipelineLayout, bgl_guard: &'a Storage, id::BindGroupLayoutId>, - ) -> ArrayVec<[&'a binding_model::BindEntryMap; hal::MAX_BIND_GROUPS]> { + ) -> ArrayVec<&'a binding_model::BindEntryMap, { hal::MAX_BIND_GROUPS }> { pipeline_layout .bind_group_layout_ids .iter() @@ -1690,7 +1690,7 @@ impl Device { &self, self_id: id::DeviceId, implicit_context: Option, - mut derived_group_layouts: ArrayVec<[binding_model::BindEntryMap; hal::MAX_BIND_GROUPS]>, + mut derived_group_layouts: ArrayVec, bgl_guard: &mut Storage, id::BindGroupLayoutId>, pipeline_layout_guard: &mut Storage, id::PipelineLayoutId>, ) -> Result { @@ -1757,7 +1757,7 @@ impl Device { self.require_downlevel_flags(wgt::DownlevelFlags::COMPUTE_SHADERS)?; let mut derived_group_layouts = - ArrayVec::<[binding_model::BindEntryMap; hal::MAX_BIND_GROUPS]>::new(); + ArrayVec::::new(); let io = validation::StageIo::default(); let (shader_module_guard, _) = hub.shader_modules.read(&mut token); @@ -1869,7 +1869,7 @@ impl Device { } let mut derived_group_layouts = - ArrayVec::<[binding_model::BindEntryMap; hal::MAX_BIND_GROUPS]>::new(); + ArrayVec::::new(); let color_targets = desc .fragment @@ -2446,7 +2446,7 @@ pub struct MissingDownlevelFlags(pub wgt::DownlevelFlags); #[cfg_attr(feature = "replay", derive(serde::Deserialize))] pub struct ImplicitPipelineContext { pub root_id: id::PipelineLayoutId, - pub group_ids: ArrayVec<[id::BindGroupLayoutId; hal::MAX_BIND_GROUPS]>, + pub group_ids: ArrayVec, } pub struct ImplicitPipelineIds<'a, G: GlobalIdentityHandlerFactory> { diff --git a/wgpu-core/src/lib.rs b/wgpu-core/src/lib.rs index deb45ba4c5..90e91f4462 100644 --- a/wgpu-core/src/lib.rs +++ b/wgpu-core/src/lib.rs @@ -14,6 +14,9 @@ clippy::needless_lifetimes, // No need for defaults in the internal types. clippy::new_without_default, + // For some reason `rustc` can warn about these in const generics even + // though they are required. + unused_braces, )] #![warn( trivial_casts, diff --git a/wgpu-core/src/track/texture.rs b/wgpu-core/src/track/texture.rs index 0d0088053a..84e3ae7499 100644 --- a/wgpu-core/src/track/texture.rs +++ b/wgpu-core/src/track/texture.rs @@ -18,7 +18,7 @@ pub struct TextureSelector { #[derive(Clone, Debug, Default, PartialEq)] pub(crate) struct TextureState { - mips: ArrayVec<[PlaneStates; hal::MAX_MIP_LEVELS as usize]>, + mips: ArrayVec, /// True if we have the information about all the subresources here full: bool, } diff --git a/wgpu-hal/Cargo.toml b/wgpu-hal/Cargo.toml index e33e59bffc..17108e824d 100644 --- a/wgpu-hal/Cargo.toml +++ b/wgpu-hal/Cargo.toml @@ -25,7 +25,7 @@ thiserror = "1" wgt = { package = "wgpu-types", path = "../wgpu-types" } # backends common -arrayvec = "0.5" +arrayvec = "0.7" fxhash = "0.2.1" log = "0.4" # backend: Metal diff --git a/wgpu-hal/src/gles/command.rs b/wgpu-hal/src/gles/command.rs index 50345b7ff2..5fb632f330 100644 --- a/wgpu-hal/src/gles/command.rs +++ b/wgpu-hal/src/gles/command.rs @@ -15,15 +15,15 @@ pub(super) struct State { index_format: wgt::IndexFormat, index_offset: wgt::BufferAddress, vertex_buffers: [(super::VertexBufferDesc, super::BufferBinding); crate::MAX_VERTEX_BUFFERS], - vertex_attributes: ArrayVec<[super::AttributeDesc; super::MAX_VERTEX_ATTRIBUTES]>, - color_targets: ArrayVec<[super::ColorTargetDesc; crate::MAX_COLOR_TARGETS]>, + vertex_attributes: ArrayVec, + color_targets: ArrayVec, stencil: super::StencilState, depth_bias: wgt::DepthBiasState, samplers: [Option; super::MAX_SAMPLERS], texture_slots: [TextureSlotDesc; super::MAX_TEXTURE_SLOTS], render_size: wgt::Extent3d, - resolve_attachments: ArrayVec<[(u32, super::TextureView); crate::MAX_COLOR_TARGETS]>, - invalidate_attachments: ArrayVec<[u32; crate::MAX_COLOR_TARGETS + 2]>, + resolve_attachments: ArrayVec<(u32, super::TextureView), { crate::MAX_COLOR_TARGETS }>, + invalidate_attachments: ArrayVec, has_pass_label: bool, instance_vbuf_mask: usize, dirty_vbuf_mask: usize, diff --git a/wgpu-hal/src/gles/device.rs b/wgpu-hal/src/gles/device.rs index fd0398a3b4..f04cb4fe28 100644 --- a/wgpu-hal/src/gles/device.rs +++ b/wgpu-hal/src/gles/device.rs @@ -176,7 +176,7 @@ impl super::Device { let mut name_binding_map = NameBindingMap::default(); let mut sampler_map = [None; super::MAX_TEXTURE_SLOTS]; let mut has_stages = wgt::ShaderStages::empty(); - let mut shaders_to_delete = arrayvec::ArrayVec::<[_; 3]>::new(); + let mut shaders_to_delete = arrayvec::ArrayVec::<_, 3>::new(); for (naga_stage, stage) in shaders { has_stages |= map_naga_stage(naga_stage); diff --git a/wgpu-hal/src/gles/mod.rs b/wgpu-hal/src/gles/mod.rs index 54663d8e11..cd324cc8a6 100644 --- a/wgpu-hal/src/gles/mod.rs +++ b/wgpu-hal/src/gles/mod.rs @@ -469,7 +469,7 @@ struct PrimitiveState { clamp_depth: bool, } -type InvalidatedAttachments = arrayvec::ArrayVec<[u32; crate::MAX_COLOR_TARGETS + 2]>; +type InvalidatedAttachments = arrayvec::ArrayVec; #[derive(Debug)] enum Command { diff --git a/wgpu-hal/src/gles/queue.rs b/wgpu-hal/src/gles/queue.rs index 0aee327f61..9e4cf285cd 100644 --- a/wgpu-hal/src/gles/queue.rs +++ b/wgpu-hal/src/gles/queue.rs @@ -576,7 +576,7 @@ impl super::Queue { C::SetDrawColorBuffers(count) => { let indices = (0..count as u32) .map(|i| glow::COLOR_ATTACHMENT0 + i) - .collect::>(); + .collect::>(); gl.draw_buffers(&indices); for draw_buffer in 0..count as u32 { gl.disable_draw_buffer(glow::BLEND, draw_buffer); diff --git a/wgpu-hal/src/metal/mod.rs b/wgpu-hal/src/metal/mod.rs index 2ec81ea5cf..54aa39eac4 100644 --- a/wgpu-hal/src/metal/mod.rs +++ b/wgpu-hal/src/metal/mod.rs @@ -504,7 +504,7 @@ struct PushConstantsInfo { #[derive(Debug)] pub struct PipelineLayout { naga_options: naga::back::msl::Options, - bind_group_infos: ArrayVec<[BindGroupLayoutInfo; crate::MAX_BIND_GROUPS]>, + bind_group_infos: ArrayVec, push_constants_infos: MultiStageData>, total_counters: MultiStageResourceCounters, } diff --git a/wgpu-hal/src/vulkan/command.rs b/wgpu-hal/src/vulkan/command.rs index a41a71e44e..9b2f7f4630 100644 --- a/wgpu-hal/src/vulkan/command.rs +++ b/wgpu-hal/src/vulkan/command.rs @@ -348,8 +348,9 @@ impl crate::CommandEncoder for super::CommandEncoder { // render unsafe fn begin_render_pass(&mut self, desc: &crate::RenderPassDescriptor) { - let mut vk_clear_values = ArrayVec::<[vk::ClearValue; super::MAX_TOTAL_ATTACHMENTS]>::new(); - let mut vk_image_views = ArrayVec::<[vk::ImageView; super::MAX_TOTAL_ATTACHMENTS]>::new(); + let mut vk_clear_values = + ArrayVec::::new(); + let mut vk_image_views = ArrayVec::::new(); let mut rp_key = super::RenderPassKey::default(); let mut fb_key = super::FramebufferKey { attachments: ArrayVec::default(), diff --git a/wgpu-hal/src/vulkan/device.rs b/wgpu-hal/src/vulkan/device.rs index 16c5c47bec..a1a34a2555 100644 --- a/wgpu-hal/src/vulkan/device.rs +++ b/wgpu-hal/src/vulkan/device.rs @@ -169,13 +169,13 @@ impl super::DeviceShared { .attachments .iter() .map(|at| at.raw) - .collect::>(); + .collect::>(); let vk_view_formats = e .key() .attachments .iter() .map(|at| self.private_caps.map_texture_format(at.view_format)) - .collect::>(); + .collect::>(); let vk_image_infos = e .key() .attachments @@ -191,7 +191,7 @@ impl super::DeviceShared { .view_formats(&vk_view_formats[i..i + 1]) .build() }) - .collect::>(); + .collect::>(); let mut vk_attachment_info = vk::FramebufferAttachmentsCreateInfo::builder() .attachment_image_infos(&vk_image_infos) @@ -377,7 +377,7 @@ impl ty, descriptor_count: count, }) - .collect::>(); + .collect::>(); let mut vk_flags = vk::DescriptorPoolCreateFlags::empty(); if flags.contains(gpu_descriptor::DescriptorPoolCreateFlags::FREE_DESCRIPTOR_SET) { @@ -1121,7 +1121,7 @@ impl crate::Device for super::Device { sample_count: desc.multisample.count, ..Default::default() }; - let mut stages = ArrayVec::<[_; 2]>::new(); + let mut stages = ArrayVec::<_, 2>::new(); let mut vertex_buffers = Vec::with_capacity(desc.vertex_buffers.len()); let mut vertex_attributes = Vec::new(); diff --git a/wgpu-hal/src/vulkan/mod.rs b/wgpu-hal/src/vulkan/mod.rs index 15da8f0ffc..4b5e17f97c 100644 --- a/wgpu-hal/src/vulkan/mod.rs +++ b/wgpu-hal/src/vulkan/mod.rs @@ -195,7 +195,7 @@ struct DepthStencilAttachmentKey { #[derive(Clone, Eq, Default, Hash, PartialEq)] struct RenderPassKey { - colors: ArrayVec<[ColorAttachmentKey; crate::MAX_COLOR_TARGETS]>, + colors: ArrayVec, depth_stencil: Option, sample_count: u32, } @@ -211,7 +211,7 @@ struct FramebufferAttachment { #[derive(Clone, Eq, Hash, PartialEq)] struct FramebufferKey { - attachments: ArrayVec<[FramebufferAttachment; MAX_TOTAL_ATTACHMENTS]>, + attachments: ArrayVec, extent: wgt::Extent3d, sample_count: u32, } diff --git a/wgpu/Cargo.toml b/wgpu/Cargo.toml index b37f42f0f6..f465f29a8d 100644 --- a/wgpu/Cargo.toml +++ b/wgpu/Cargo.toml @@ -47,7 +47,7 @@ package = "wgpu-hal" path = "../wgpu-hal" [dependencies] -arrayvec = "0.5" +arrayvec = "0.7" log = "0.4" parking_lot = "0.11" raw-window-handle = "0.3" diff --git a/wgpu/src/backend/direct.rs b/wgpu/src/backend/direct.rs index 5233bffc3d..c2c72fb9a3 100644 --- a/wgpu/src/backend/direct.rs +++ b/wgpu/src/backend/direct.rs @@ -1001,7 +1001,7 @@ impl crate::Context for Context { .bind_group_layouts .iter() .map(|bgl| bgl.id) - .collect::>(); + .collect::>(); let descriptor = wgc::binding_model::PipelineLayoutDescriptor { label: desc.label.map(Borrowed), bind_group_layouts: Borrowed(&temp_layouts), @@ -1033,7 +1033,7 @@ impl crate::Context for Context { ) -> Self::RenderPipelineId { use wgc::pipeline as pipe; - let vertex_buffers: ArrayVec<[_; hal::MAX_VERTEX_BUFFERS]> = desc + let vertex_buffers: ArrayVec<_, { hal::MAX_VERTEX_BUFFERS }> = desc .vertex .buffers .iter() @@ -1768,7 +1768,7 @@ impl crate::Context for Context { resolve_target: ca.resolve_target.map(|rt| rt.id), channel: map_pass_channel(Some(&ca.ops)), }) - .collect::>(); + .collect::>(); let depth_stencil = desc.depth_stencil_attachment.as_ref().map(|dsa| { wgc::command::RenderPassDepthStencilAttachment {