From d597e97db8720801dcae2829ddc00d13ce5e09bb Mon Sep 17 00:00:00 2001 From: Dzmitry Malyshau Date: Fri, 2 Nov 2018 21:44:17 -0400 Subject: [PATCH] Rewrite the consume() to use the last usage properly --- wgpu-native/src/track.rs | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/wgpu-native/src/track.rs b/wgpu-native/src/track.rs index aa7be070b..f5db2e290 100644 --- a/wgpu-native/src/track.rs +++ b/wgpu-native/src/track.rs @@ -3,6 +3,7 @@ use resource::{BufferUsageFlags, TextureUsageFlags}; use std::collections::hash_map::{Entry, HashMap}; use std::hash::Hash; +use std::mem; use std::ops::{BitOr, Range}; @@ -42,6 +43,7 @@ impl GenericUsage for TextureUsageFlags { } } +#[derive(Clone)] struct Track { ref_count: RefCount, init: U, @@ -126,12 +128,19 @@ impl< ) -> impl 'a + Iterator)> { other.map .iter() - .flat_map(move |(id, new)| match self.transit(id.0.clone(), &new.ref_count, new.last, TrackPermit::REPLACE) { - Ok(Tracktion::Init) | - Ok(Tracktion::Keep) => None, - Ok(Tracktion::Replace { old }) => Some((id.0.clone(), old .. new.last)), - Ok(Tracktion::Extend { .. }) | - Err(_) => panic!("Unable to consume a resource transition!"), + .flat_map(move |(id, new)| match self.map.entry(WeaklyStored(id.0.clone())) { + Entry::Vacant(e) => { + e.insert(new.clone()); + None + } + Entry::Occupied(mut e) => { + let old = mem::replace(&mut e.get_mut().last, new.last); + if old == new.init { + None + } else { + Some((id.0.clone(), old .. new.last)) + } + } }) } }