wgpu_primitives/sort/
sorter.rs1use crate::Error;
2use crate::context::Context;
3
4use super::core::RadixSorter;
5use super::pipeline::SortItemKind;
6
7pub struct Sorter {
9 core: RadixSorter,
10}
11
12impl Sorter {
13 pub fn new(device: &wgpu::Device, queue: &wgpu::Queue) -> Self {
15 Self {
16 core: RadixSorter::new(device, queue, SortItemKind::Key),
17 }
18 }
19
20 pub fn from_context(ctx: &Context) -> Self {
22 Self::new(&ctx.device, &ctx.queue)
23 }
24
25 pub async fn sort(&mut self, input: &[u32]) -> Result<Vec<u32>, Error> {
27 self.core.sort_slice(input).await
28 }
29
30 pub fn sort_gpu_to_gpu(
32 &mut self,
33 input: &wgpu::Buffer,
34 output: &wgpu::Buffer,
35 num_items: u32,
36 ) -> Result<(), Error> {
37 self.core.sort_gpu_to_gpu(input, output, num_items)
38 }
39
40 pub fn record_sort(
42 &mut self,
43 encoder: &mut wgpu::CommandEncoder,
44 input: &wgpu::Buffer,
45 output: &wgpu::Buffer,
46 num_items: u32,
47 ) -> Result<(), Error> {
48 self.core.record_sort(encoder, input, output, num_items)
49 }
50}