Fix refcount use of the texture view source

This commit is contained in:
Dzmitry Malyshau
2019-12-31 18:57:09 -05:00
parent bf8c9fe27b
commit 040efa2820
3 changed files with 27 additions and 21 deletions

View File

@@ -252,7 +252,11 @@ impl<F: IdentityFilter<RenderPassId>> Global<F> {
);
const MAX_TOTAL_ATTACHMENTS: usize = 10;
type OutputAttachment<'a> = (TextureId, &'a hal::image::SubresourceRange, Option<TextureUsage>);
type OutputAttachment<'a> = (
&'a Stored<TextureId>,
&'a hal::image::SubresourceRange,
Option<TextureUsage>,
);
let mut output_attachments = ArrayVec::<[OutputAttachment; MAX_TOTAL_ATTACHMENTS]>::new();
log::trace!(
@@ -271,8 +275,8 @@ impl<F: IdentityFilter<RenderPassId>> Global<F> {
} else {
extent = Some(view.extent);
}
let texture_id = match view.inner {
TextureViewInner::Native { ref source_id, .. } => source_id.value,
let source_id = match view.inner {
TextureViewInner::Native { ref source_id, .. } => source_id,
TextureViewInner::SwapChain { .. } => {
panic!("Unexpected depth/stencil use of swapchain image!")
}
@@ -280,10 +284,10 @@ impl<F: IdentityFilter<RenderPassId>> Global<F> {
// Using render pass for transition.
let consistent_usage = cmb.trackers.textures.query(
texture_id,
source_id.value,
view.range.clone(),
);
output_attachments.push((texture_id, &view.range, consistent_usage));
output_attachments.push((source_id, &view.range, consistent_usage));
let old_layout = match consistent_usage {
Some(usage) => conv::map_texture_state(
@@ -333,7 +337,7 @@ impl<F: IdentityFilter<RenderPassId>> Global<F> {
source_id.value,
view.range.clone(),
);
output_attachments.push((source_id.value, &view.range, consistent_usage));
output_attachments.push((source_id, &view.range, consistent_usage));
let old_layout = match consistent_usage {
Some(usage) => conv::map_texture_state(usage, hal::format::Aspects::COLOR).1,
@@ -393,7 +397,7 @@ impl<F: IdentityFilter<RenderPassId>> Global<F> {
source_id.value,
view.range.clone(),
);
output_attachments.push((source_id.value, &view.range, consistent_usage));
output_attachments.push((source_id, &view.range, consistent_usage));
let old_layout = match consistent_usage {
Some(usage) => conv::map_texture_state(usage, hal::format::Aspects::COLOR).1,
@@ -442,27 +446,26 @@ impl<F: IdentityFilter<RenderPassId>> Global<F> {
};
let mut trackers = TrackerSet::new(B::VARIANT);
for (texture_id, view_range, consistent_usage) in output_attachments {
let texture = &texture_guard[texture_id];
for (source_id, view_range, consistent_usage) in output_attachments {
let texture = &texture_guard[source_id.value];
assert!(texture.usage.contains(TextureUsage::OUTPUT_ATTACHMENT));
let usage = consistent_usage.unwrap_or(TextureUsage::OUTPUT_ATTACHMENT);
let ref_count = texture.life_guard.ref_count.as_ref().unwrap();
match trackers.textures.init(
texture_id,
ref_count.clone(),
source_id.value,
source_id.ref_count.clone(),
&texture.full_range,
) {
Some(mut init) => init.set(view_range.clone(), usage),
None => panic!("Your texture {:?} is in the another attachment!", texture_id),
None => panic!("Your texture {:?} is in the another attachment!", source_id.value),
};
if consistent_usage.is_some() {
// If we expect the texture to be transited to a new state by the
// render pass configuration, make the tracker aware of that.
let _ = trackers.textures.change_replace(
texture_id,
ref_count,
source_id.value,
&source_id.ref_count,
view_range.clone(),
TextureUsage::OUTPUT_ATTACHMENT,
&texture.full_range,

View File

@@ -1069,13 +1069,16 @@ impl<F: IdentityFilter<id::BindGroupId>> Global<F> {
ref raw,
ref source_id,
} => {
let texture = used
.textures
.use_extend(
&*texture_guard,
// Careful here: the texture may no longer have its own ref count,
// if it was deleted by the user.
let texture = &texture_guard[source_id.value];
used.textures
.change_extend(
source_id.value,
&source_id.ref_count,
view.range.clone(),
usage,
&texture.full_range,
)
.unwrap();
assert!(texture.usage.contains(usage));

View File

@@ -167,7 +167,7 @@ impl<F: IdentityFilter<TextureViewId>> Global<F> {
image,
source_id: Stored {
value: swap_chain_id,
ref_count: sc.life_guard.ref_count.clone().unwrap(),
ref_count: sc.life_guard.add_ref(),
},
framebuffers: SmallVec::new(),
},
@@ -185,7 +185,7 @@ impl<F: IdentityFilter<TextureViewId>> Global<F> {
},
life_guard: LifeGuard::new(),
};
let ref_count = view.life_guard.ref_count.clone().unwrap();
let ref_count = view.life_guard.add_ref();
let view_id = hub
.texture_views
.register_identity(view_id_in, view, &mut token);