pub struct DispatchConfig<'a> {
pub shader: &'a str,
pub entry_point: Option<&'a str>,
pub workgroups: Option<[u32; 3]>,
pub invocations: u32,
pub push_constants: Option<&'a [u8]>,
}
impl<'a> DispatchConfig<'a> {
pub const fn new(shader: &'a str, invocations: u32) -> Self {
Self {
shader,
entry_point: None,
workgroups: None,
invocations,
push_constants: None,
}
}
pub const fn entry_point(mut self, name: &'a str) -> Self {
self.entry_point = Some(name);
self
}
pub const fn workgroups(mut self, dims: [u32; 3]) -> Self {
self.workgroups = Some(dims);
self
}
pub const fn push_constants(mut self, data: &'a [u8]) -> Self {
self.push_constants = Some(data);
self
}
}
pub fn extract_workgroup_size(module: &naga::Module, entry: &str) -> [u32; 3] {
for ep in &module.entry_points {
if ep.name == entry {
let s = ep.workgroup_size;
return [s[0], s[1], s[2]];
}
}
[64, 1, 1]
}
pub fn calc_dispatch(invocations: u32, workgroup_size: [u32; 3]) -> [u32; 3] {
let ceil_div = |a: u32, b: u32| a.div_ceil(b);
[ceil_div(invocations, workgroup_size[0]).min(65535), 1, 1]
}