use crate::wgpu::{buffer::Buffer, buffers::BindGroup, compute::ComputePipeline};
pub struct ComputePass<'a> {
raw: wgpu::ComputePass<'a>,
}
impl<'a> ComputePass<'a> {
pub(crate) fn new(raw: wgpu::ComputePass<'a>) -> Self {
Self { raw }
}
pub fn set_pipeline(&mut self, pipeline: &ComputePipeline) {
self.raw.set_pipeline(pipeline.raw());
}
pub fn set_bind_group(&mut self, index: u32, bind_group: &BindGroup, offsets: &[u32]) {
self.raw.set_bind_group(index, Some(bind_group.raw()), offsets);
}
pub fn dispatch_workgroups(&mut self, x: u32, y: u32, z: u32) {
self.raw.dispatch_workgroups(x, y, z);
}
pub fn dispatch_workgroups_indirect(&mut self, indirect_buffer: &'a Buffer, indirect_offset: u64) {
self.raw.dispatch_workgroups_indirect(indirect_buffer.raw(), indirect_offset);
}
}
#[repr(C)]
#[derive(Copy, Clone, Debug, Default, bytemuck::Pod, bytemuck::Zeroable)]
pub struct DispatchIndirectArgs {
pub x: u32,
pub y: u32,
pub z: u32,
}
impl DispatchIndirectArgs {
pub fn as_bytes(&self) -> &[u8] {
bytemuck::bytes_of(self)
}
}
pub struct CommandEncoder {
raw: wgpu::CommandEncoder,
}
impl CommandEncoder {
pub(crate) fn new(raw: wgpu::CommandEncoder) -> Self {
Self { raw }
}
pub fn compute_pass(&mut self, label: Option<&str>) -> ComputePass<'_> {
let raw = self.raw.begin_compute_pass(&wgpu::ComputePassDescriptor {
label,
timestamp_writes: None,
});
ComputePass::new(raw)
}
pub(crate) fn into_raw(self) -> wgpu::CommandEncoder {
self.raw
}
}