#![allow(clippy::doc_markdown)]
use super::gpu_backend::shaders;
pub(super) const fn storage_entry(binding: u32, read_only: bool) -> wgpu::BindGroupLayoutEntry {
wgpu::BindGroupLayoutEntry {
binding,
visibility: wgpu::ShaderStages::COMPUTE,
ty: wgpu::BindingType::Buffer {
ty: wgpu::BufferBindingType::Storage { read_only },
has_dynamic_offset: false,
min_binding_size: None,
},
count: None,
}
}
pub(super) const fn uniform_entry(binding: u32) -> wgpu::BindGroupLayoutEntry {
wgpu::BindGroupLayoutEntry {
binding,
visibility: wgpu::ShaderStages::COMPUTE,
ty: wgpu::BindingType::Buffer {
ty: wgpu::BufferBindingType::Uniform,
has_dynamic_offset: false,
min_binding_size: None,
},
count: None,
}
}
pub(super) fn create_expand_bind_group_layout(device: &wgpu::Device) -> wgpu::BindGroupLayout {
device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
label: Some("Expand BGL"),
entries: &[
storage_entry(0, true), storage_entry(1, true), storage_entry(2, true), storage_entry(3, false), storage_entry(4, false), storage_entry(5, false), uniform_entry(6), ],
})
}
pub(super) fn create_select_bind_group_layout(device: &wgpu::Device) -> wgpu::BindGroupLayout {
device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
label: Some("Select BGL"),
entries: &[
storage_entry(0, true), storage_entry(1, true), storage_entry(2, false), storage_entry(3, false), storage_entry(4, false), uniform_entry(5), storage_entry(6, true), storage_entry(7, true), ],
})
}
pub(super) fn create_traversal_distance_bind_group_layout(
device: &wgpu::Device,
label: &str,
) -> wgpu::BindGroupLayout {
device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
label: Some(label),
entries: &[
storage_entry(0, true), storage_entry(1, true), storage_entry(2, true), storage_entry(3, false), uniform_entry(4), ],
})
}
pub(super) fn compile_expand_pipeline(device: &wgpu::Device) -> wgpu::ComputePipeline {
let shader = device.create_shader_module(wgpu::ShaderModuleDescriptor {
label: Some("Expand Frontier Shader"),
source: wgpu::ShaderSource::Wgsl(shaders::EXPAND_FRONTIER_SHADER.into()),
});
let layout = create_expand_bind_group_layout(device);
let pipeline_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
label: Some("Expand Pipeline Layout"),
bind_group_layouts: &[&layout],
push_constant_ranges: &[],
});
device.create_compute_pipeline(&wgpu::ComputePipelineDescriptor {
label: Some("Expand Frontier Pipeline"),
layout: Some(&pipeline_layout),
module: &shader,
entry_point: Some("expand_frontier"),
compilation_options: wgpu::PipelineCompilationOptions::default(),
cache: None,
})
}
pub(super) fn compile_traversal_distance_pipeline(
device: &wgpu::Device,
shader_source: &str,
entry_point: &str,
label: &str,
) -> wgpu::ComputePipeline {
let shader = device.create_shader_module(wgpu::ShaderModuleDescriptor {
label: Some(&format!("{label} Shader")),
source: wgpu::ShaderSource::Wgsl(shader_source.into()),
});
let layout = create_traversal_distance_bind_group_layout(device, &format!("{label} BGL"));
let pipeline_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
label: Some(&format!("{label} PL")),
bind_group_layouts: &[&layout],
push_constant_ranges: &[],
});
device.create_compute_pipeline(&wgpu::ComputePipelineDescriptor {
label: Some(&format!("{label} Pipeline")),
layout: Some(&pipeline_layout),
module: &shader,
entry_point: Some(entry_point),
compilation_options: wgpu::PipelineCompilationOptions::default(),
cache: None,
})
}
pub(super) fn compile_select_pipeline(device: &wgpu::Device) -> wgpu::ComputePipeline {
let shader = device.create_shader_module(wgpu::ShaderModuleDescriptor {
label: Some("Select TopK Shader"),
source: wgpu::ShaderSource::Wgsl(shaders::SELECT_TOPK_SHADER.into()),
});
let layout = create_select_bind_group_layout(device);
let pipeline_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
label: Some("Select Pipeline Layout"),
bind_group_layouts: &[&layout],
push_constant_ranges: &[],
});
device.create_compute_pipeline(&wgpu::ComputePipelineDescriptor {
label: Some("Select TopK Pipeline"),
layout: Some(&pipeline_layout),
module: &shader,
entry_point: Some(entry_point_name()),
compilation_options: wgpu::PipelineCompilationOptions::default(),
cache: None,
})
}
const fn entry_point_name() -> &'static str {
"select_topk"
}