66 lines
1.7 KiB
Rust
66 lines
1.7 KiB
Rust
// Main common gpu parallel algorithms
|
|
pub mod buffer_compactor;
|
|
pub mod indirect_buffer;
|
|
pub mod radix_sort;
|
|
pub mod top_k;
|
|
|
|
// Utilities
|
|
pub fn create_multi_buffers_bind_group_layout(
|
|
device: &wgpu::Device,
|
|
count: u32,
|
|
label: Option<&str>,
|
|
) -> wgpu::BindGroupLayout
|
|
{
|
|
let entries = (0..count)
|
|
.map(|i| wgpu::BindGroupLayoutEntry {
|
|
binding: i,
|
|
visibility: wgpu::ShaderStages::COMPUTE,
|
|
ty: wgpu::BindingType::Buffer {
|
|
ty: wgpu::BufferBindingType::Storage { read_only: false },
|
|
has_dynamic_offset: false,
|
|
min_binding_size: None,
|
|
},
|
|
count: None,
|
|
})
|
|
.collect::<Vec<_>>();
|
|
|
|
device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
|
|
label,
|
|
entries: &entries,
|
|
})
|
|
}
|
|
|
|
pub fn create_multi_buffers_bind_group(
|
|
device: &wgpu::Device,
|
|
layout: &wgpu::BindGroupLayout,
|
|
buffers: &[&wgpu::Buffer],
|
|
label: Option<&str>,
|
|
) -> wgpu::BindGroup
|
|
{
|
|
let entries = buffers
|
|
.iter()
|
|
.enumerate()
|
|
.map(|(i, buffer)| wgpu::BindGroupEntry {
|
|
binding: i as u32,
|
|
resource: buffer.as_entire_binding(),
|
|
})
|
|
.collect::<Vec<_>>();
|
|
|
|
device.create_bind_group(&wgpu::BindGroupDescriptor {
|
|
label,
|
|
layout,
|
|
entries: &entries,
|
|
})
|
|
}
|
|
|
|
pub fn create_multi_buffers_bg_bg_layout(
|
|
device: &wgpu::Device,
|
|
buffers: &[&wgpu::Buffer],
|
|
label: Option<&str>,
|
|
) -> (wgpu::BindGroupLayout, wgpu::BindGroup)
|
|
{
|
|
let layout = create_multi_buffers_bind_group_layout(device, buffers.len() as u32, label);
|
|
let bg = create_multi_buffers_bind_group(device, &layout, buffers, label);
|
|
(layout, bg)
|
|
}
|