use crate::Error;
use crate::context::Context;
use super::core::RadixSorter;
use super::pipeline::SortItemKind;
#[repr(C)]
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, bytemuck::Pod, bytemuck::Zeroable)]
pub struct KeyValue {
pub key: u32,
pub value: u32,
}
impl KeyValue {
pub const fn new(key: u32, value: u32) -> Self {
Self { key, value }
}
}
pub struct KeyValueSorter {
core: RadixSorter,
}
impl KeyValueSorter {
pub fn new(device: &wgpu::Device, queue: &wgpu::Queue) -> Self {
Self {
core: RadixSorter::new(device, queue, SortItemKind::KeyValue),
}
}
pub fn from_context(ctx: &Context) -> Self {
Self::new(&ctx.device, &ctx.queue)
}
pub async fn sort(&mut self, input: &[KeyValue]) -> Result<Vec<KeyValue>, Error> {
self.core.sort_slice(input).await
}
pub fn sort_gpu_to_gpu(
&mut self,
input: &wgpu::Buffer,
output: &wgpu::Buffer,
num_items: u32,
) -> Result<(), Error> {
self.core.sort_gpu_to_gpu(input, output, num_items)
}
pub fn record_sort(
&mut self,
encoder: &mut wgpu::CommandEncoder,
input: &wgpu::Buffer,
output: &wgpu::Buffer,
num_items: u32,
) -> Result<(), Error> {
self.core.record_sort(encoder, input, output, num_items)
}
}