use crate::resource::*;
use crate::types::*;
pub struct GpuCommandEncoder {
inner: wgpu::CommandEncoder,
}
impl GpuCommandEncoder {
pub(crate) fn from_raw(inner: wgpu::CommandEncoder) -> Self {
Self { inner }
}
pub fn begin_render_pass<'a>(
&'a mut self,
desc: &wgpu::RenderPassDescriptor<'a>,
) -> GpuRenderPass<'a> {
let inner = self.inner.begin_render_pass(desc);
GpuRenderPass::from_raw(inner)
}
pub fn begin_compute_pass(
&mut self,
desc: &wgpu::ComputePassDescriptor<'_>,
) -> GpuComputePass<'_> {
let inner = self.inner.begin_compute_pass(desc);
GpuComputePass::from_raw(inner)
}
pub fn copy_buffer_to_buffer(
&mut self,
source: &GpuBuffer,
source_offset: BufferAddress,
destination: &GpuBuffer,
destination_offset: BufferAddress,
size: BufferAddress,
) {
self.inner.copy_buffer_to_buffer(
source.raw(),
source_offset,
destination.raw(),
destination_offset,
size,
);
}
pub fn copy_buffer_to_texture(
&mut self,
source: wgpu::TexelCopyBufferInfo<'_>,
destination: wgpu::TexelCopyTextureInfo<'_>,
copy_size: Extent3d,
) {
self.inner
.copy_buffer_to_texture(source, destination, copy_size);
}
pub fn copy_texture_to_buffer(
&mut self,
source: wgpu::TexelCopyTextureInfo<'_>,
destination: wgpu::TexelCopyBufferInfo<'_>,
copy_size: Extent3d,
) {
self.inner
.copy_texture_to_buffer(source, destination, copy_size);
}
pub fn copy_texture_to_texture(
&mut self,
source: wgpu::TexelCopyTextureInfo<'_>,
destination: wgpu::TexelCopyTextureInfo<'_>,
copy_size: Extent3d,
) {
self.inner
.copy_texture_to_texture(source, destination, copy_size);
}
pub fn finish(self) -> GpuCommandBuffer {
GpuCommandBuffer {
inner: self.inner.finish(),
}
}
pub fn raw(&self) -> &wgpu::CommandEncoder {
&self.inner
}
pub fn raw_mut(&mut self) -> &mut wgpu::CommandEncoder {
&mut self.inner
}
}
pub struct GpuCommandBuffer {
pub(crate) inner: wgpu::CommandBuffer,
}
impl GpuCommandBuffer {
pub fn into_inner(self) -> wgpu::CommandBuffer {
self.inner
}
pub fn raw(self) -> wgpu::CommandBuffer {
self.inner
}
}
pub struct GpuRenderPass<'a> {
inner: wgpu::RenderPass<'a>,
}
impl<'a> GpuRenderPass<'a> {
pub(crate) fn from_raw(inner: wgpu::RenderPass<'a>) -> Self {
Self { inner }
}
pub fn set_pipeline(&mut self, pipeline: &'a GpuRenderPipeline) {
self.inner.set_pipeline(pipeline.raw());
}
pub fn set_bind_group(&mut self, index: u32, bind_group: &'a GpuBindGroup, offsets: &[u32]) {
self.inner.set_bind_group(index, bind_group.raw(), offsets);
}
pub fn set_vertex_buffer(&mut self, slot: u32, buffer: &'a GpuBuffer) {
self.inner.set_vertex_buffer(slot, buffer.raw().slice(..));
}
pub fn set_vertex_buffer_range(&mut self, slot: u32, buffer_slice: wgpu::BufferSlice<'a>) {
self.inner.set_vertex_buffer(slot, buffer_slice);
}
pub fn set_index_buffer(&mut self, buffer: &'a GpuBuffer, format: IndexFormat) {
self.inner.set_index_buffer(buffer.raw().slice(..), format);
}
pub fn set_index_buffer_range(
&mut self,
buffer_slice: wgpu::BufferSlice<'a>,
format: IndexFormat,
) {
self.inner.set_index_buffer(buffer_slice, format);
}
pub fn draw(&mut self, vertices: std::ops::Range<u32>, instances: std::ops::Range<u32>) {
self.inner.draw(vertices, instances);
}
pub fn draw_indexed(
&mut self,
indices: std::ops::Range<u32>,
base_vertex: i32,
instances: std::ops::Range<u32>,
) {
self.inner.draw_indexed(indices, base_vertex, instances);
}
pub fn draw_indirect(&mut self, buffer: &'a GpuBuffer, offset: BufferAddress) {
self.inner.draw_indirect(buffer.raw(), offset);
}
pub fn draw_indexed_indirect(&mut self, buffer: &'a GpuBuffer, offset: BufferAddress) {
self.inner.draw_indexed_indirect(buffer.raw(), offset);
}
pub fn set_viewport(&mut self, x: f32, y: f32, w: f32, h: f32, min_depth: f32, max_depth: f32) {
self.inner.set_viewport(x, y, w, h, min_depth, max_depth);
}
pub fn set_scissor_rect(&mut self, x: u32, y: u32, w: u32, h: u32) {
self.inner.set_scissor_rect(x, y, w, h);
}
pub fn set_stencil_reference(&mut self, reference: u32) {
self.inner.set_stencil_reference(reference);
}
pub fn set_blend_constant(&mut self, color: Color) {
self.inner.set_blend_constant(color);
}
pub fn set_push_constants(&mut self, stages: ShaderStages, offset: u32, data: &[u8]) {
self.inner.set_push_constants(stages, offset, data);
}
pub fn raw(&self) -> &wgpu::RenderPass<'a> {
&self.inner
}
pub fn raw_mut(&mut self) -> &mut wgpu::RenderPass<'a> {
&mut self.inner
}
}
pub struct GpuComputePass<'a> {
inner: wgpu::ComputePass<'a>,
}
impl<'a> GpuComputePass<'a> {
pub(crate) fn from_raw(inner: wgpu::ComputePass<'a>) -> Self {
Self { inner }
}
pub fn set_pipeline(&mut self, pipeline: &'a GpuComputePipeline) {
self.inner.set_pipeline(pipeline.raw());
}
pub fn set_bind_group(&mut self, index: u32, bind_group: &'a GpuBindGroup, offsets: &[u32]) {
self.inner.set_bind_group(index, bind_group.raw(), offsets);
}
pub fn dispatch_workgroups(&mut self, x: u32, y: u32, z: u32) {
self.inner.dispatch_workgroups(x, y, z);
}
pub fn dispatch_workgroups_indirect(&mut self, buffer: &'a GpuBuffer, offset: BufferAddress) {
self.inner
.dispatch_workgroups_indirect(buffer.raw(), offset);
}
pub fn set_push_constants(&mut self, offset: u32, data: &[u8]) {
self.inner.set_push_constants(offset, data);
}
pub fn raw(&self) -> &wgpu::ComputePass<'a> {
&self.inner
}
pub fn raw_mut(&mut self) -> &mut wgpu::ComputePass<'a> {
&mut self.inner
}
}