Skip to content

Commit

Permalink
single_entry_point() always verifies it's the sole entry point, searc…
Browse files Browse the repository at this point in the history
…h optimizations
  • Loading branch information
Firestar99 committed Aug 23, 2023
1 parent 560cbaf commit 44f7af1
Showing 1 changed file with 21 additions and 17 deletions.
38 changes: 21 additions & 17 deletions vulkano/src/shader/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -401,16 +401,30 @@ impl ShaderModule {
})
}

/// check for *exactly* one item in the Iterator
#[inline]
fn single_entry_point_filter<P>(self: &Arc<Self>, mut filter: P) -> Option<EntryPoint>
where
P: FnMut(&EntryPointInfo) -> bool,
{
let mut iter = self
.entry_point_infos
.iter()
.enumerate()
.filter(|(_, infos)| filter(infos))
.map(|(x, _)| x);
let info_index = iter.next()?;
iter.next().is_none().then(|| EntryPoint {
module: self.clone(),
info_index,
})
}

/// Returns information about the entry point if self only contains a single entry point,
/// `None` otherwise.
#[inline]
pub fn single_entry_point(self: &Arc<Self>) -> Option<EntryPoint> {
self.entry_point_map.iter().next().and_then(|(_, infos)| {
infos.iter().next().map(|(_, &info_index)| EntryPoint {
module: self.clone(),
info_index,
})
})
self.single_entry_point_filter(|_| true)
}

/// Returns information about the entry point if self only contains a single entry point
Expand All @@ -421,17 +435,7 @@ impl ShaderModule {
self: &Arc<Self>,
execution: ExecutionModel,
) -> Option<EntryPoint> {
let mut iter = self
.entry_point_map
.iter()
.filter_map(|(_, infos)| infos.get(&execution));

// check for *exactly* one entry point being present
let info_index = *iter.next()?;
iter.next().is_none().then(|| EntryPoint {
module: self.clone(),
info_index,
})
self.single_entry_point_filter(|info| ExecutionModel::from(&info.execution) == execution)
}
}

Expand Down

0 comments on commit 44f7af1

Please sign in to comment.