mirror of
https://github.com/storytold/wgpu.git
synced 2026-11-24 08:21:25 +01:00
Refactor the swap chain frame tracking
This commit is contained in:
1 parent
ec54038e7c
commit
8a5de68aab
6 files changed
+42
-55
No files matched your search
@@ -136,7 +136,7 @@ pub struct CommandBuffer<B: hal::Backend> {
|
||||
pub(crate) device_id: Stored<id::DeviceId>,
|
||||
pub(crate) life_guard: LifeGuard,
|
||||
pub(crate) trackers: TrackerSet,
|
||||
pub(crate) used_swap_chain: Option<(Stored<id::TextureViewId>, B::Framebuffer)>,
|
||||
pub(crate) used_swap_chain: Option<(Stored<id::SwapChainId>, B::Framebuffer)>,
|
||||
pub(crate) features: Features,
|
||||
}
|
||||
|
||||
@@ -263,13 +263,17 @@ impl<F> Global<F> {
|
||||
) -> id::CommandBufferId {
|
||||
let hub = B::hub(self);
|
||||
let mut token = Token::root();
|
||||
let (swap_chain_guard, mut token) = hub.swap_chains.read(&mut token);
|
||||
//TODO: actually close the last recorded command buffer
|
||||
let (mut comb_guard, _) = hub.command_buffers.write(&mut token);
|
||||
let comb = &mut comb_guard[encoder_id];
|
||||
assert!(comb.is_recording);
|
||||
comb.is_recording = false;
|
||||
// stop tracking the swapchain image, if used
|
||||
if let Some((ref view_id, _)) = comb.used_swap_chain {
|
||||
if let Some((ref sc_id, _)) = comb.used_swap_chain {
|
||||
let view_id = swap_chain_guard[sc_id.value].acquired_view_id
|
||||
.as_ref()
|
||||
.expect("Used swap chain frame has already presented");
|
||||
comb.trackers.views.remove(view_id.value);
|
||||
}
|
||||
log::debug!("Command buffer {:?} {:#?}", encoder_id, comb.trackers);
|
||||
|
||||
@@ -325,7 +325,7 @@ impl<F> Global<F> {
|
||||
let base_trackers = &cmb.trackers;
|
||||
|
||||
let mut extent = None;
|
||||
let mut used_swap_chain_image = None::<Stored<id::TextureViewId>>;
|
||||
let mut used_swap_chain = None::<Stored<id::SwapChainId>>;
|
||||
|
||||
let sample_count = color_attachments
|
||||
.get(0)
|
||||
@@ -430,15 +430,12 @@ impl<F> Global<F> {
|
||||
};
|
||||
old_layout .. hal::image::Layout::ColorAttachmentOptimal
|
||||
}
|
||||
TextureViewInner::SwapChain { .. } => {
|
||||
if let Some((ref view_id, _)) = cmb.used_swap_chain {
|
||||
assert_eq!(view_id.value, at.attachment);
|
||||
TextureViewInner::SwapChain { ref source_id, .. } => {
|
||||
if let Some((ref sc_id, _)) = cmb.used_swap_chain {
|
||||
assert_eq!(source_id.value, sc_id.value);
|
||||
} else {
|
||||
assert!(used_swap_chain_image.is_none());
|
||||
used_swap_chain_image = Some(Stored {
|
||||
value: at.attachment,
|
||||
ref_count: view.life_guard.add_ref(),
|
||||
});
|
||||
assert!(used_swap_chain.is_none());
|
||||
used_swap_chain = Some(source_id.clone());
|
||||
}
|
||||
|
||||
let end = hal::image::Layout::Present;
|
||||
@@ -490,15 +487,12 @@ impl<F> Global<F> {
|
||||
};
|
||||
old_layout .. hal::image::Layout::ColorAttachmentOptimal
|
||||
}
|
||||
TextureViewInner::SwapChain { .. } => {
|
||||
if let Some((ref view_id, _)) = cmb.used_swap_chain {
|
||||
assert_eq!(view_id.value, resolve_target);
|
||||
TextureViewInner::SwapChain { ref source_id, .. } => {
|
||||
if let Some((ref sc_id, _)) = cmb.used_swap_chain {
|
||||
assert_eq!(source_id.value, sc_id.value);
|
||||
} else {
|
||||
assert!(used_swap_chain_image.is_none());
|
||||
used_swap_chain_image = Some(Stored {
|
||||
value: resolve_target,
|
||||
ref_count: view.life_guard.add_ref(),
|
||||
});
|
||||
assert!(used_swap_chain.is_none());
|
||||
used_swap_chain = Some(source_id.clone());
|
||||
}
|
||||
|
||||
let end = hal::image::Layout::Present;
|
||||
@@ -624,8 +618,8 @@ impl<F> Global<F> {
|
||||
depth_stencil: depth_stencil_attachment.map(|at| at.attachment),
|
||||
};
|
||||
|
||||
let framebuffer = match used_swap_chain_image.take() {
|
||||
Some(view_id) => {
|
||||
let framebuffer = match used_swap_chain.take() {
|
||||
Some(sc_id) => {
|
||||
assert!(cmb.used_swap_chain.is_none());
|
||||
// Always create a new framebuffer and delete it after presentation.
|
||||
let attachments = fb_key.all().map(|&id| match view_guard[id].inner {
|
||||
@@ -638,7 +632,7 @@ impl<F> Global<F> {
|
||||
.create_framebuffer(&render_pass, attachments, extent.unwrap())
|
||||
.unwrap()
|
||||
};
|
||||
cmb.used_swap_chain = Some((view_id, framebuffer));
|
||||
cmb.used_swap_chain = Some((sc_id, framebuffer));
|
||||
&mut cmb.used_swap_chain.as_mut().unwrap().1
|
||||
}
|
||||
None => {
|
||||
|
||||
Reference in new issue
Block a user