Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ShaderModule::single_entry_point() #2301

Merged
merged 4 commits into from
Aug 25, 2023
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions vulkano/src/shader/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,43 @@ 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,
Firestar99 marked this conversation as resolved.
Show resolved Hide resolved
/// `None` otherwise.
#[inline]
pub fn single_entry_point(self: &Arc<Self>) -> Option<EntryPoint> {
self.single_entry_point_filter(|_| true)
}

/// Returns information about the entry point if self only contains a single entry point
Firestar99 marked this conversation as resolved.
Show resolved Hide resolved
/// with the provided ExecutionModel. Returns `None` if no entry point was found or multiple
/// entry points have been found matching the provided ExecutionModel.
Firestar99 marked this conversation as resolved.
Show resolved Hide resolved
#[inline]
pub fn single_entry_point_of_execution(
self: &Arc<Self>,
execution: ExecutionModel,
) -> Option<EntryPoint> {
self.single_entry_point_filter(|info| ExecutionModel::from(&info.execution) == execution)
}
}

impl Drop for ShaderModule {
Expand Down