Refactor the view tracker

This commit is contained in:
Dzmitry Malyshau 2019-02-26 23:05:36 -05:00
parent 0d59c16f16
commit cc5900b160
5 changed files with 31 additions and 69 deletions

View File

@ -74,7 +74,6 @@ pub extern "C" fn wgpu_compute_pass_set_bind_group(
&*HUB.buffers.read(),
&*HUB.textures.read(),
);
pass.trackers.views.consume(&bind_group.used.views);
if let Some(pipeline_layout_id) = pass.binder.provide_entry(index as usize, bind_group_id, bind_group) {
let pipeline_layout_guard = HUB.pipeline_layouts.read();

View File

@ -16,7 +16,7 @@ use crate::device::{
use crate::hub::{HUB, Storage};
use crate::resource::TexturePlacement;
use crate::swap_chain::{SwapChainLink, SwapImageEpoch};
use crate::track::TrackerSet;
use crate::track::{DummyUsage, TrackerSet};
use crate::conv;
use crate::{
BufferHandle, TextureHandle,
@ -123,7 +123,9 @@ impl CommandBufferHandle {
families: None,
}
});
base.views.consume(&head.views);
base.views
.consume_by_extend(&head.views)
.unwrap();
let stages = all_buffer_stages() | all_image_stages();
unsafe {
@ -194,7 +196,7 @@ pub fn command_encoder_begin_render_pass(
} else {
extent = Some(view.extent);
}
trackers.views.query(at.attachment, &view.life_guard.ref_count);
trackers.views.query(at.attachment, &view.life_guard.ref_count, DummyUsage);
let query = trackers.textures.query(
view.texture_id.value,
&view.texture_id.ref_count,
@ -237,7 +239,7 @@ pub fn command_encoder_begin_render_pass(
} else {
extent = Some(view.extent);
}
trackers.views.query(at.attachment, &view.life_guard.ref_count);
trackers.views.query(at.attachment, &view.life_guard.ref_count, DummyUsage);
let query = trackers.textures.query(
view.texture_id.value,
&view.texture_id.ref_count,

View File

@ -175,13 +175,7 @@ pub extern "C" fn wgpu_render_pass_set_bind_group(
let bind_group_guard = HUB.bind_groups.read();
let bind_group = &bind_group_guard[bind_group_id];
pass.trackers.buffers
.consume_by_extend(&bind_group.used.buffers)
.unwrap();
pass.trackers.textures
.consume_by_extend(&bind_group.used.textures)
.unwrap();
pass.trackers.views.consume(&bind_group.used.views);
pass.trackers.consume_by_extend(&bind_group.used);
if let Some(pipeline_layout_id) = pass.binder.provide_entry(index as usize, bind_group_id, bind_group) {
let pipeline_layout_guard = HUB.pipeline_layouts.read();

View File

@ -1,6 +1,6 @@
use crate::{binding_model, command, conv, pipeline, resource, swap_chain};
use crate::hub::HUB;
use crate::track::{TrackerSet, TrackPermit};
use crate::track::{DummyUsage, TrackerSet, TrackPermit};
use crate::{
LifeGuard, RefCount, Stored, SubmissionIndex,
BufferMapAsyncStatus, BufferMapOperation,
@ -640,13 +640,13 @@ pub fn device_track_view(
let device_id = HUB.textures
.read()
[texture_id].device_id.value;
let initialized = HUB.devices
let query = HUB.devices
.read()
[device_id].trackers
.lock()
.views
.query(view_id, &ref_count);
assert!(initialized);
.query(view_id, &ref_count, DummyUsage);
assert!(query.initialized);
}
#[cfg(feature = "local")]
@ -905,7 +905,7 @@ pub fn device_create_bind_group(
}
binding_model::BindingResource::TextureView(id) => {
let view = &texture_view_guard[id];
used.views.query(id, &view.life_guard.ref_count);
used.views.query(id, &view.life_guard.ref_count, DummyUsage);
used.textures
.transit(
view.texture_id.value,
@ -1599,6 +1599,7 @@ pub fn swap_chain_populate_textures(
trackers.views.query(
view_id.value,
&view_id.ref_count,
DummyUsage,
);
swap_chain.frames.push(swap_chain::Frame {

View File

@ -56,6 +56,15 @@ bitflags! {
pub trait GenericUsage {
fn is_exclusive(&self) -> bool;
}
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct DummyUsage;
impl BitOr for DummyUsage {
type Output = Self;
fn bitor(self, other: Self) -> Self {
other
}
}
impl GenericUsage for BufferUsageFlags {
fn is_exclusive(&self) -> bool {
BufferUsageFlags::WRITE_ALL.intersects(*self)
@ -66,6 +75,11 @@ impl GenericUsage for TextureUsageFlags {
TextureUsageFlags::WRITE_ALL.intersects(*self)
}
}
impl GenericUsage for DummyUsage {
fn is_exclusive(&self) -> bool {
false
}
}
#[derive(Clone)]
struct Track<U> {
@ -82,11 +96,7 @@ pub struct Tracker<I, U> {
}
pub type BufferTracker = Tracker<BufferId, BufferUsageFlags>;
pub type TextureTracker = Tracker<TextureId, TextureUsageFlags>;
pub struct DummyTracker<I> {
map: FastHashMap<Index, (RefCount, Epoch)>,
_phantom: PhantomData<I>,
}
pub type TextureViewTracker = DummyTracker<TextureViewId>;
pub type TextureViewTracker = Tracker<TextureViewId, DummyUsage>;
pub struct TrackerSet {
pub buffers: BufferTracker,
@ -111,53 +121,9 @@ impl TrackerSet {
self.textures
.consume_by_extend(&other.textures)
.unwrap();
self.views.consume(&other.views);
}
}
impl<I: NewId> DummyTracker<I> {
pub fn new() -> Self {
DummyTracker {
map: FastHashMap::default(),
_phantom: PhantomData,
}
}
/// Remove an id from the tracked map.
pub(crate) fn remove(&mut self, id: I) -> bool {
match self.map.remove(&id.index()) {
Some((_, epoch)) => {
assert_eq!(epoch, id.epoch());
true
}
None => false,
}
}
/// Get the last usage on a resource.
pub(crate) fn query(&mut self, id: I, ref_count: &RefCount) -> bool {
match self.map.entry(id.index()) {
Entry::Vacant(e) => {
e.insert((ref_count.clone(), id.epoch()));
true
}
Entry::Occupied(e) => {
assert_eq!(e.get().1, id.epoch());
false
}
}
}
/// Consume another tacker.
pub fn consume(&mut self, other: &Self) {
for (&index, &(ref ref_count, epoch)) in &other.map {
self.query(I::new(index, epoch), ref_count);
}
}
/// Return an iterator over used resources keys.
pub fn used<'a>(&'a self) -> impl 'a + Iterator<Item = I> {
self.map.iter().map(|(&index, &(_, epoch))| I::new(index, epoch))
self.views
.consume_by_extend(&other.views)
.unwrap();
}
}