Skip to content

Commit

Permalink
single_entry_point() always verifies that there isn't another entry p…
Browse files Browse the repository at this point in the history
…oint present, also optimizations
  • Loading branch information
Firestar99 committed Aug 23, 2023
1 parent 2e6719d commit 1b186e1
Showing 1 changed file with 20 additions and 17 deletions.
37 changes: 20 additions & 17 deletions vulkano/src/shader/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -397,16 +397,25 @@ impl ShaderModule {
})
}

/// check for *exactly* one item in the Iterator
#[inline]
fn single_entry_point_verify<'a>(
self: &Arc<Self>,
iter: impl Iterator<Item = &'a EntryPointInfo>,
) -> Option<EntryPoint> {
let mut iter = iter.enumerate().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_verify(self.entry_point_infos.iter())
}

/// Returns information about the entry point if self only contains a single entry point
Expand All @@ -417,17 +426,11 @@ 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_verify(
self.entry_point_infos
.iter()
.filter(|info| ExecutionModel::from(&info.execution) == execution),
)
}
}

Expand Down

0 comments on commit 1b186e1

Please sign in to comment.