use wgpu::{Buffer, Queue};
use super::super::linear_grid::dispatch_linear;
use super::super::pipeline::{LayoutKey, PipelineCache};
use crate::error::Result;
const VALIDATE_INDICES_SHADER: &str = include_str!("../validate_indices.wgsl");
pub fn launch_validate_indices(
cache: &PipelineCache,
queue: &Queue,
indices: &Buffer,
error_count: &Buffer,
params_buffer: &Buffer,
index_len: usize,
) -> Result<()> {
if index_len == 0 {
return Ok(());
}
let module = cache.get_or_create_module("validate_indices", VALIDATE_INDICES_SHADER);
let layout = cache.get_or_create_layout(LayoutKey {
num_storage_buffers: 2,
num_uniform_buffers: 1,
num_readonly_storage: 0,
});
let pipeline =
cache.get_or_create_pipeline("validate_indices", "validate_indices", &module, &layout);
let bind_group = cache.create_bind_group(&layout, &[indices, error_count, params_buffer])?;
let mut encoder = cache
.device()
.create_command_encoder(&wgpu::CommandEncoderDescriptor {
label: Some("validate_indices"),
});
{
let mut pass = encoder.begin_compute_pass(&wgpu::ComputePassDescriptor {
label: Some("validate_indices"),
timestamp_writes: None,
});
pass.set_pipeline(&pipeline);
pass.set_bind_group(0, Some(&bind_group), &[]);
dispatch_linear(&mut pass, index_len);
}
queue.submit(std::iter::once(encoder.finish()));
Ok(())
}