1145: Support trailing render passes after the swapchain rendering r=kvark a=kvark

**Connections**
Discussed on the matrix.

**Description**
Fixes a case where we have any other render pass in a command encoder that draws to the swapchain (after the pass that draws to the swapchain).

**Testing**
Tested on a modified hello-triangle example.

Co-authored-by: Dzmitry Malyshau <kvarkus@gmail.com>
This commit is contained in:
bors[bot]
2021-01-12 02:56:46 +00:00
committed by GitHub
4 changed files with 12 additions and 24 deletions

View File

@@ -115,7 +115,7 @@ impl<B: GfxBackend> CommandAllocator<B> {
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(),

View File

@@ -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<B: hal::Backend> {
recorded_thread_id: ThreadId,
pub(crate) device_id: Stored<id::DeviceId>,
pub(crate) trackers: TrackerSet,
pub(crate) used_swap_chain: Option<(Stored<id::SwapChainId>, B::Framebuffer)>,
pub(crate) used_swap_chains: SmallVec<[(Stored<id::SwapChainId>, B::Framebuffer); 1]>,
limits: wgt::Limits,
private_features: PrivateFeatures,
has_labels: bool,
@@ -216,7 +217,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
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()

View File

@@ -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<G: GlobalIdentityHandlerFactory> Global<G> {
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 {

View File

@@ -514,7 +514,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
));
}
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() {