use crate::{Error, common::buffers::BufferRange, context::Context, profiling::GpuProfile};
use super::{core::CompactCore, pipeline::CompactItemKind};
pub struct Compactor {
core: CompactCore,
}
impl Compactor {
pub fn new(device: &wgpu::Device, queue: &wgpu::Queue) -> Self {
Self {
core: CompactCore::new(device, queue, CompactItemKind::Value),
}
}
pub fn from_context(context: &Context) -> Self {
Self {
core: CompactCore::from_context(context, CompactItemKind::Value),
}
}
pub async fn compact(&mut self, input: &[u32], mask: &[u32]) -> Result<Vec<u32>, Error> {
self.core.compact_slice(input, mask).await
}
pub fn compact_gpu_to_gpu(
&mut self,
input: &wgpu::Buffer,
mask: &wgpu::Buffer,
output: &wgpu::Buffer,
output_count: &wgpu::Buffer,
num_items: u32,
) -> Result<(), Error> {
self.core
.compact_gpu_to_gpu(input, mask, output, output_count, num_items)
}
pub fn record_compact(
&mut self,
encoder: &mut wgpu::CommandEncoder,
input: &wgpu::Buffer,
mask: &wgpu::Buffer,
output: &wgpu::Buffer,
output_count: &wgpu::Buffer,
num_items: u32,
) -> Result<(), Error> {
self.core
.record_compact(encoder, input, mask, output, output_count, num_items)
}
pub(crate) fn record_compact_ranges(
&mut self,
encoder: &mut wgpu::CommandEncoder,
input: BufferRange<'_>,
mask: BufferRange<'_>,
output: BufferRange<'_>,
output_count: BufferRange<'_>,
num_items: u32,
) -> Result<(), Error> {
self.core
.record_compact_ranges(encoder, input, mask, output, output_count, num_items)
}
pub(crate) fn reserve(&mut self, capacity: u32) -> Result<(), Error> {
self.core.reserve(capacity)
}
pub async fn profile_compact_gpu_to_gpu(
&mut self,
input: &wgpu::Buffer,
mask: &wgpu::Buffer,
output: &wgpu::Buffer,
output_count: &wgpu::Buffer,
num_items: u32,
) -> Result<GpuProfile, Error> {
self.core
.profile_compact_gpu_to_gpu(input, mask, output, output_count, num_items)
.await
}
}