mirror of
https://github.com/gfx-rs/wgpu.git
synced 2024-11-22 14:55:05 +00:00
Refactor tracker initializers
This commit is contained in:
parent
d74c8cb5ae
commit
c0d6cf18e1
@ -56,7 +56,7 @@ impl<F: IdentityFilter<ComputePassId>> Global<F> {
|
||||
|
||||
// There are no transitions to be made: we've already been inserting barriers
|
||||
// into the parent command buffer while recording this compute pass.
|
||||
log::debug!("Compute pass {:?} tracker: {:#?}", pass_id, pass.trackers);
|
||||
log::debug!("Compute pass {:?} {:#?}", pass_id, pass.trackers);
|
||||
cmb.trackers = pass.trackers;
|
||||
cmb.raw.push(pass.raw);
|
||||
}
|
||||
|
@ -194,7 +194,7 @@ impl<F> Global<F> {
|
||||
if let Some((ref view_id, _)) = comb.used_swap_chain {
|
||||
comb.trackers.views.remove(view_id.value);
|
||||
}
|
||||
log::debug!("Command buffer {:?} tracker: {:#?}", encoder_id, comb.trackers);
|
||||
log::debug!("Command buffer {:?} {:#?}", encoder_id, comb.trackers);
|
||||
encoder_id
|
||||
}
|
||||
}
|
||||
@ -324,9 +324,8 @@ impl<F: IdentityFilter<RenderPassId>> Global<F> {
|
||||
let first_use = cmb.trackers.views.init(
|
||||
at.attachment,
|
||||
view.life_guard.ref_count.clone(),
|
||||
(),
|
||||
(),
|
||||
);
|
||||
&(),
|
||||
).is_some();
|
||||
|
||||
let layouts = match view.inner {
|
||||
TextureViewInner::Native { ref source_id, .. } => {
|
||||
@ -385,9 +384,8 @@ impl<F: IdentityFilter<RenderPassId>> Global<F> {
|
||||
let first_use = cmb.trackers.views.init(
|
||||
resolve_target,
|
||||
view.life_guard.ref_count.clone(),
|
||||
(),
|
||||
(),
|
||||
);
|
||||
&(),
|
||||
).is_some();
|
||||
|
||||
let layouts = match view.inner {
|
||||
TextureViewInner::Native { ref source_id, .. } => {
|
||||
@ -448,13 +446,15 @@ impl<F: IdentityFilter<RenderPassId>> Global<F> {
|
||||
let texture = &texture_guard[texture_id];
|
||||
assert!(texture.usage.contains(TextureUsage::OUTPUT_ATTACHMENT));
|
||||
|
||||
let ok = trackers.textures.init(
|
||||
let usage = consistent_usage.unwrap_or(TextureUsage::OUTPUT_ATTACHMENT);
|
||||
match trackers.textures.init(
|
||||
texture_id,
|
||||
texture.life_guard.ref_count.clone(),
|
||||
view_range.clone(),
|
||||
consistent_usage.unwrap_or(TextureUsage::OUTPUT_ATTACHMENT),
|
||||
);
|
||||
assert!(ok, "Your texture {:?} is in the another attachment!", texture_id);
|
||||
&texture.full_range,
|
||||
) {
|
||||
Some(mut init) => init.set(view_range.clone(), usage),
|
||||
None => panic!("Your texture {:?} is in the another attachment!", texture_id),
|
||||
};
|
||||
|
||||
if consistent_usage.is_some() {
|
||||
// If we expect the texture to be transited to a new state by the
|
||||
|
@ -186,7 +186,7 @@ impl<F: IdentityFilter<RenderPassId>> Global<F> {
|
||||
pass.raw.end_render_pass();
|
||||
}
|
||||
pass.trackers.optimize();
|
||||
log::debug!("Render pass {:?} tracker: {:#?}", pass_id, pass.trackers);
|
||||
log::debug!("Render pass {:?} {:#?}", pass_id, pass.trackers);
|
||||
|
||||
let cmb = &mut cmb_guard[pass.cmb_id.value];
|
||||
let (buffer_guard, mut token) = hub.buffers.read(&mut token);
|
||||
@ -209,6 +209,11 @@ impl<F: IdentityFilter<RenderPassId>> Global<F> {
|
||||
}
|
||||
}
|
||||
|
||||
if false {
|
||||
log::debug!("Command buffer {:?} after render pass {:#?}",
|
||||
pass.cmb_id.value, cmb.trackers);
|
||||
}
|
||||
|
||||
cmb.raw.push(pass.raw);
|
||||
}
|
||||
|
||||
|
@ -817,13 +817,12 @@ impl<F: IdentityFilter<BufferId>> Global<F> {
|
||||
let ref_count = buffer.life_guard.ref_count.clone();
|
||||
|
||||
let id = hub.buffers.register_identity(id_in, buffer, &mut token);
|
||||
let ok =
|
||||
device
|
||||
.trackers
|
||||
.lock()
|
||||
.buffers
|
||||
.init(id, ref_count, (), resource::BufferUsage::empty());
|
||||
assert!(ok);
|
||||
device
|
||||
.trackers
|
||||
.lock()
|
||||
.buffers
|
||||
.init(id, ref_count, &())
|
||||
.unwrap();
|
||||
id
|
||||
}
|
||||
|
||||
@ -857,13 +856,15 @@ impl<F: IdentityFilter<BufferId>> Global<F> {
|
||||
}
|
||||
|
||||
let id = hub.buffers.register_identity(id_in, buffer, &mut token);
|
||||
let ok = device.trackers.lock().buffers.init(
|
||||
id,
|
||||
ref_count,
|
||||
(),
|
||||
resource::BufferUsage::MAP_WRITE,
|
||||
);
|
||||
assert!(ok);
|
||||
device.trackers
|
||||
.lock()
|
||||
.buffers.init(
|
||||
id,
|
||||
ref_count,
|
||||
&(),
|
||||
)
|
||||
.unwrap()
|
||||
.set((), resource::BufferUsage::MAP_WRITE);
|
||||
id
|
||||
}
|
||||
|
||||
@ -967,13 +968,15 @@ impl<F: IdentityFilter<TextureId>> Global<F> {
|
||||
let ref_count = texture.life_guard.ref_count.clone();
|
||||
|
||||
let id = hub.textures.register_identity(id_in, texture, &mut token);
|
||||
let ok = device.trackers.lock().textures.init(
|
||||
id,
|
||||
ref_count,
|
||||
range,
|
||||
resource::TextureUsage::UNINITIALIZED,
|
||||
);
|
||||
assert!(ok);
|
||||
device.trackers
|
||||
.lock()
|
||||
.textures.init(
|
||||
id,
|
||||
ref_count,
|
||||
&range,
|
||||
)
|
||||
.unwrap()
|
||||
.set(range, resource::TextureUsage::UNINITIALIZED);
|
||||
id
|
||||
}
|
||||
|
||||
@ -1079,8 +1082,10 @@ impl<F: IdentityFilter<TextureViewId>> Global<F> {
|
||||
let ref_count = view.life_guard.ref_count.clone();
|
||||
|
||||
let id = hub.texture_views.register_identity(id_in, view, &mut token);
|
||||
let ok = device.trackers.lock().views.init(id, ref_count, (), ());
|
||||
assert!(ok);
|
||||
device.trackers
|
||||
.lock()
|
||||
.views.init(id, ref_count, &())
|
||||
.unwrap();
|
||||
id
|
||||
}
|
||||
|
||||
@ -1150,8 +1155,10 @@ impl<F: IdentityFilter<SamplerId>> Global<F> {
|
||||
let ref_count = sampler.life_guard.ref_count.clone();
|
||||
|
||||
let id = hub.samplers.register_identity(id_in, sampler, &mut token);
|
||||
let ok = device.trackers.lock().samplers.init(id, ref_count, (), ());
|
||||
assert!(ok);
|
||||
device.trackers
|
||||
.lock()
|
||||
.samplers.init(id, ref_count, &())
|
||||
.unwrap();
|
||||
id
|
||||
}
|
||||
|
||||
@ -1427,15 +1434,15 @@ impl<F: IdentityFilter<BindGroupId>> Global<F> {
|
||||
let id = hub
|
||||
.bind_groups
|
||||
.register_identity(id_in, bind_group, &mut token);
|
||||
log::debug!("Bind group {:?} tracker : {:#?}",
|
||||
log::debug!("Bind group {:?} {:#?}",
|
||||
id, hub.bind_groups.read(&mut token).0[id].used);
|
||||
|
||||
let ok = device
|
||||
device
|
||||
.trackers
|
||||
.lock()
|
||||
.bind_groups
|
||||
.init(id, ref_count, (), ());
|
||||
assert!(ok);
|
||||
.init(id, ref_count, &())
|
||||
.unwrap();
|
||||
id
|
||||
}
|
||||
|
||||
@ -1630,7 +1637,7 @@ impl<F: AllIdentityFilter + IdentityFilter<CommandBufferId>> Global<F> {
|
||||
}
|
||||
}
|
||||
|
||||
log::debug!("Device tracker after submission: {:#?}", trackers);
|
||||
log::debug!("Device after submission {}: {:#?}", submit_index, trackers);
|
||||
|
||||
// now prepare the GPU submission
|
||||
let fence = device.raw.create_fence(false).unwrap();
|
||||
|
@ -132,6 +132,21 @@ pub struct PendingTransition<S: ResourceState> {
|
||||
pub usage: Range<S::Usage>,
|
||||
}
|
||||
|
||||
/// Helper initialization structure that allows setting the usage on
|
||||
/// various sub-resources.
|
||||
#[derive(Debug)]
|
||||
pub struct Initializer<'a, S: ResourceState> {
|
||||
id: S::Id,
|
||||
state: &'a mut S,
|
||||
}
|
||||
|
||||
impl<S: ResourceState> Initializer<'_, S> {
|
||||
pub fn set(&mut self, selector: S::Selector, usage: S::Usage) -> bool {
|
||||
self.state.change(self.id, selector, usage, None)
|
||||
.is_ok()
|
||||
}
|
||||
}
|
||||
|
||||
/// A tracker for all resources of a given type.
|
||||
pub struct ResourceTracker<S: ResourceState> {
|
||||
/// An association of known resource indices with their tracked states.
|
||||
@ -204,27 +219,24 @@ impl<S: ResourceState> ResourceTracker<S> {
|
||||
&mut self,
|
||||
id: S::Id,
|
||||
ref_count: RefCount,
|
||||
selector: S::Selector,
|
||||
default: S::Usage,
|
||||
) -> bool {
|
||||
let mut state = S::new(&selector);
|
||||
match state.change(id, selector, default, None) {
|
||||
Ok(()) => (),
|
||||
Err(_) => unreachable!(),
|
||||
}
|
||||
|
||||
full_selector: &S::Selector,
|
||||
) -> Option<Initializer<S>> {
|
||||
let (index, epoch, backend) = id.unzip();
|
||||
debug_assert_eq!(backend, self.backend);
|
||||
self.map
|
||||
.insert(
|
||||
index,
|
||||
Resource {
|
||||
match self.map.entry(index) {
|
||||
Entry::Vacant(e) => {
|
||||
let res = e.insert(Resource {
|
||||
ref_count,
|
||||
state,
|
||||
state: S::new(full_selector),
|
||||
epoch,
|
||||
},
|
||||
)
|
||||
.is_none()
|
||||
});
|
||||
Some(Initializer {
|
||||
id,
|
||||
state: &mut res.state,
|
||||
})
|
||||
}
|
||||
Entry::Occupied(_) => None,
|
||||
}
|
||||
}
|
||||
|
||||
/// Query the usage of a resource selector.
|
||||
|
@ -171,9 +171,14 @@ impl ResourceState for TextureState {
|
||||
end: Some(end),
|
||||
} => {
|
||||
let to_usage = end.port();
|
||||
let final_usage = if start.last != to_usage
|
||||
|| !TextureUsage::ORDERED.contains(to_usage)
|
||||
if start.last == to_usage
|
||||
&& TextureUsage::ORDERED.contains(to_usage)
|
||||
{
|
||||
Unit {
|
||||
first: start.first,
|
||||
last: end.last,
|
||||
}
|
||||
} else {
|
||||
let pending = PendingTransition {
|
||||
id,
|
||||
selector: hal::image::SubresourceRange {
|
||||
@ -185,18 +190,20 @@ impl ResourceState for TextureState {
|
||||
};
|
||||
|
||||
match output {
|
||||
None => pending.collapse()?,
|
||||
None => {
|
||||
Unit {
|
||||
first: start.first,
|
||||
last: pending.collapse()?,
|
||||
}
|
||||
}
|
||||
Some(ref mut out) => {
|
||||
out.push(pending);
|
||||
end.last
|
||||
Unit {
|
||||
first: Some(start.last),
|
||||
last: end.last,
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
end.last
|
||||
};
|
||||
Unit {
|
||||
first: Some(start.port()),
|
||||
last: final_usage,
|
||||
}
|
||||
}
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user