diff --git a/wgpu-core/src/command/allocator.rs b/wgpu-core/src/command/allocator.rs index 62a87e0dcf..df30faa6a8 100644 --- a/wgpu-core/src/command/allocator.rs +++ b/wgpu-core/src/command/allocator.rs @@ -115,7 +115,7 @@ impl CommandAllocator { recorded_thread_id: thread_id, device_id, trackers: TrackerSet::new(B::VARIANT), - used_swap_chain: None, + used_swap_chains: Default::default(), limits, private_features, has_labels: label.is_some(), diff --git a/wgpu-core/src/command/mod.rs b/wgpu-core/src/command/mod.rs index c53c1913a9..7c76aee159 100644 --- a/wgpu-core/src/command/mod.rs +++ b/wgpu-core/src/command/mod.rs @@ -29,6 +29,7 @@ use crate::{ }; use hal::command::CommandBuffer as _; +use smallvec::SmallVec; use thiserror::Error; use std::thread::ThreadId; @@ -42,7 +43,7 @@ pub struct CommandBuffer { recorded_thread_id: ThreadId, pub(crate) device_id: Stored, pub(crate) trackers: TrackerSet, - pub(crate) used_swap_chain: Option<(Stored, B::Framebuffer)>, + pub(crate) used_swap_chains: SmallVec<[(Stored, B::Framebuffer); 1]>, limits: wgt::Limits, private_features: PrivateFeatures, has_labels: bool, @@ -216,7 +217,7 @@ impl Global { Ok(cmd_buf) => { cmd_buf.is_recording = false; // stop tracking the swapchain image, if used - if let Some((ref sc_id, _)) = cmd_buf.used_swap_chain { + for (ref sc_id, _) in cmd_buf.used_swap_chains.iter() { let view_id = swap_chain_guard[sc_id.value] .acquired_view_id .as_ref() diff --git a/wgpu-core/src/command/render.rs b/wgpu-core/src/command/render.rs index 7c7503b149..3fbd0087b6 100644 --- a/wgpu-core/src/command/render.rs +++ b/wgpu-core/src/command/render.rs @@ -420,8 +420,6 @@ pub enum RenderPassErrorInner { InvalidStencilOps, #[error("all attachments must have the same sample count, found {actual} != {expected}")] SampleCountMismatch { actual: u8, expected: u8 }, - #[error("texture view's swap chain must match swap chain in use")] - SwapChainMismatch, #[error("setting `values_offset` to be `None` is only for internal use in render bundles")] InvalidValuesOffset, #[error("required device features not enabled: {0:?}")] @@ -696,14 +694,8 @@ impl<'a, B: GfxBackend> RenderPassInfo<'a, B> { old_layout..new_layout } TextureViewInner::SwapChain { ref source_id, .. } => { - if let Some((ref sc_id, _)) = cmd_buf.used_swap_chain { - if source_id.value != sc_id.value { - return Err(RenderPassErrorInner::SwapChainMismatch); - } - } else { - assert!(used_swap_chain.is_none()); - used_swap_chain = Some(source_id.clone()); - } + assert!(used_swap_chain.is_none()); + used_swap_chain = Some(source_id.clone()); let end = hal::image::Layout::Present; let start = match at.channel.load_op { @@ -786,14 +778,8 @@ impl<'a, B: GfxBackend> RenderPassInfo<'a, B> { old_layout..new_layout } TextureViewInner::SwapChain { ref source_id, .. } => { - if let Some((ref sc_id, _)) = cmd_buf.used_swap_chain { - if source_id.value != sc_id.value { - return Err(RenderPassErrorInner::SwapChainMismatch); - } - } else { - assert!(used_swap_chain.is_none()); - used_swap_chain = Some(source_id.clone()); - } + assert!(used_swap_chain.is_none()); + used_swap_chain = Some(source_id.clone()); hal::image::Layout::Undefined..hal::image::Layout::Present } }; @@ -919,7 +905,6 @@ impl<'a, B: GfxBackend> RenderPassInfo<'a, B> { let framebuffer = match used_swap_chain.take() { Some(sc_id) => { - assert!(cmd_buf.used_swap_chain.is_none()); // Always create a new framebuffer and delete it after presentation. let attachments = fb_key .all() @@ -1886,7 +1871,9 @@ impl Global { let cmd_buf = CommandBuffer::get_encoder_mut(&mut *cmb_guard, encoder_id).map_pass_err(scope)?; cmd_buf.has_labels |= base.label.is_some(); - cmd_buf.used_swap_chain = used_swapchain_with_framebuffer; + cmd_buf + .used_swap_chains + .extend(used_swapchain_with_framebuffer); #[cfg(feature = "trace")] if let Some(ref mut list) = cmd_buf.commands { diff --git a/wgpu-core/src/device/queue.rs b/wgpu-core/src/device/queue.rs index 071748da5c..208b4278a5 100644 --- a/wgpu-core/src/device/queue.rs +++ b/wgpu-core/src/device/queue.rs @@ -514,7 +514,7 @@ impl Global { )); } - if let Some((sc_id, fbo)) = cmdbuf.used_swap_chain.take() { + for (sc_id, fbo) in cmdbuf.used_swap_chains.drain(..) { let sc = &mut swap_chain_guard[sc_id.value]; sc.active_submission_index = submit_index; if sc.acquired_view_id.is_none() {