diff --git a/wgpu-core-remote-types/src/encoders.rs b/wgpu-core-remote-types/src/encoders.rs new file mode 100644 index 000000000..de5b19405 --- /dev/null +++ b/wgpu-core-remote-types/src/encoders.rs @@ -0,0 +1,108 @@ +use crate::id; + +#[derive(serde::Serialize, serde::Deserialize)] +/// Corresponds to [`GPURenderPassEncoder`](https://www.w3.org/TR/webgpu/#gpurenderpassencoder). +pub enum RenderPassEncoderCommand { + SetViewport { + x: f32, + y: f32, + width: f32, + height: f32, + min_depth: f32, + max_depth: f32, + }, + SetScissorRect { + x: u32, + y: u32, + width: u32, + height: u32, + }, + SetBlendConstant(wgt::Color), + SetStencilReference(u32), + BeginOcclusionQuery(u32), + EndOcclusionQuery, + ExecuteBundles(Vec), + BindingCommand(BindingCommand), + RenderCommand(RenderCommand), + DebugCommand(DebugCommand), + End, +} + +#[derive(serde::Serialize, serde::Deserialize)] +/// Corresponds to [`GPUComputePassEncoder`](https://www.w3.org/TR/webgpu/#gpucomputepassencoder). +pub enum ComputePassEncoderCommand { + BindingCommand(BindingCommand), + SetPipeline(id::ComputePipelineId), + DispatchWorkgroups { + workgroup_count_x: u32, + workgroup_count_y: u32, // optional, defaults to 1 + workgroup_count_z: u32, // optional, defaults to 1 + }, + DispatchWorkgroupsIndirect { + indirect_buffer: id::BufferId, + indirect_offset: u64, + }, + DebugCommand(DebugCommand), + End, +} + +#[derive(serde::Serialize, serde::Deserialize)] +/// Corresponds to [`GPUDebugCommandsMixin`](https://www.w3.org/TR/webgpu/#gpudebugcommandsmixin). +pub enum DebugCommand { + PushDebugGroup(String), + PopDebugGroup, + InsertDebugMarker(String), +} + +#[derive(serde::Serialize, serde::Deserialize)] +/// Corresponds to [`GPUBindingCommandsMixin`](https://www.w3.org/TR/webgpu/#gpubindingcommandsmixin). +pub enum BindingCommand { + SetBindGroup { + index: u32, + bind_group: Option, + dynamic_offsets: Vec, // optional, defaults to [] + }, + SetImmediates { + range_offset: u32, + data: Vec, + }, +} + +#[derive(serde::Serialize, serde::Deserialize)] +/// Corresponds to [`GPURenderCommandsMixin`](https://www.w3.org/TR/webgpu/#gpurendercommandsmixin). +pub enum RenderCommand { + SetPipeline(id::RenderPipelineId), + SetIndexBuffer { + buffer: id::BufferId, + index_format: wgt::IndexFormat, + offset: u64, // optional, defaults to 0 + size: Option, + }, + SetVertexBuffer { + slot: u32, + buffer: Option, + offset: u64, // optional, defaults to 0 + size: Option, + }, + Draw { + vertex_count: u32, + instance_count: u32, // optional, defaults to 1 + first_vertex: u32, // optional, defaults to 0 + first_instance: u32, // optional, defaults to 0 + }, + DrawIndexed { + index_count: u32, + instance_count: u32, // optional, defaults to 1 + first_index: u32, // optional, defaults to 0 + base_vertex: i32, // optional, defaults to 0 + first_instance: u32, // optional, defaults to 0 + }, + DrawIndirect { + indirect_buffer: id::BufferId, + indirect_offset: u64, + }, + DrawIndexedIndirect { + indirect_buffer: id::BufferId, + indirect_offset: u64, + }, +} diff --git a/wgpu-core-remote-types/src/lib.rs b/wgpu-core-remote-types/src/lib.rs index 1d594d427..28ace3113 100644 --- a/wgpu-core-remote-types/src/lib.rs +++ b/wgpu-core-remote-types/src/lib.rs @@ -10,5 +10,6 @@ pub mod id; pub mod identity; pub mod binding_model; +pub mod encoders; pub type Label<'a> = Option>; diff --git a/wgpu-core-remote/src/global/compute_pass.rs b/wgpu-core-remote/src/global/compute_pass.rs index 9ae94f5da..9da60b2e1 100644 --- a/wgpu-core-remote/src/global/compute_pass.rs +++ b/wgpu-core-remote/src/global/compute_pass.rs @@ -1,6 +1,7 @@ use alloc::borrow::Cow; use wgpu_core::command::{ComputePassDescriptor, PassTimestampWrites}; +use wgpu_core_remote_types::encoders::{BindingCommand, ComputePassEncoderCommand, DebugCommand}; use wgt::{BufferAddress, DynamicOffset}; use crate::global::Global; @@ -216,3 +217,55 @@ impl Global { pass.end_pipeline_statistics_query() } } + +impl Global { + pub fn handle_compute_pass_command( + &self, + pass_id: id::ComputePassEncoderId, + command: ComputePassEncoderCommand, + ) { + match command { + ComputePassEncoderCommand::BindingCommand(command) => match command { + BindingCommand::SetBindGroup { + index, + bind_group, + dynamic_offsets, + } => self.compute_pass_set_bind_group(pass_id, index, bind_group, &dynamic_offsets), + BindingCommand::SetImmediates { range_offset, data } => { + self.compute_pass_set_immediates(pass_id, range_offset, &data) + } + }, + ComputePassEncoderCommand::SetPipeline(pipeline_id) => { + self.compute_pass_set_pipeline(pass_id, pipeline_id) + } + ComputePassEncoderCommand::DispatchWorkgroups { + workgroup_count_x, + workgroup_count_y, + workgroup_count_z, + } => self.compute_pass_dispatch_workgroups( + pass_id, + workgroup_count_x, + workgroup_count_y, + workgroup_count_z, + ), + ComputePassEncoderCommand::DispatchWorkgroupsIndirect { + indirect_buffer, + indirect_offset, + } => self.compute_pass_dispatch_workgroups_indirect( + pass_id, + indirect_buffer, + indirect_offset, + ), + ComputePassEncoderCommand::DebugCommand(debug_command) => match debug_command { + DebugCommand::PushDebugGroup(label) => { + self.compute_pass_push_debug_group(pass_id, &label, 0) + } + DebugCommand::PopDebugGroup => self.compute_pass_pop_debug_group(pass_id), + DebugCommand::InsertDebugMarker(label) => { + self.compute_pass_insert_debug_marker(pass_id, &label, 0) + } + }, + ComputePassEncoderCommand::End => self.compute_pass_end(pass_id), + } + } +} diff --git a/wgpu-core-remote/src/global/render_pass.rs b/wgpu-core-remote/src/global/render_pass.rs index dc8045ec5..dcd91db57 100644 --- a/wgpu-core-remote/src/global/render_pass.rs +++ b/wgpu-core-remote/src/global/render_pass.rs @@ -1,5 +1,8 @@ use alloc::borrow::Cow; use core::num::NonZeroU32; +use wgpu_core_remote_types::encoders::{ + BindingCommand, DebugCommand, RenderCommand, RenderPassEncoderCommand, +}; use wgpu_core::command::{ PassTimestampWrites, RenderPassColorAttachment, RenderPassDepthStencilAttachment, @@ -411,3 +414,130 @@ impl Global { pass.execute_bundles(&render_bundles) } } + +impl Global { + pub fn handle_render_pass_command( + &self, + pass_id: id::RenderPassEncoderId, + command: RenderPassEncoderCommand, + ) { + match command { + RenderPassEncoderCommand::SetViewport { + x, + y, + width, + height, + min_depth, + max_depth, + } => self.render_pass_set_viewport(pass_id, x, y, width, height, min_depth, max_depth), + RenderPassEncoderCommand::SetScissorRect { + x, + y, + width, + height, + } => self.render_pass_set_scissor_rect(pass_id, x, y, width, height), + RenderPassEncoderCommand::SetBlendConstant(color) => { + self.render_pass_set_blend_constant(pass_id, color) + } + RenderPassEncoderCommand::SetStencilReference(value) => { + self.render_pass_set_stencil_reference(pass_id, value) + } + RenderPassEncoderCommand::BeginOcclusionQuery(query_index) => { + self.render_pass_begin_occlusion_query(pass_id, query_index) + } + RenderPassEncoderCommand::EndOcclusionQuery => { + self.render_pass_end_occlusion_query(pass_id) + } + RenderPassEncoderCommand::ExecuteBundles(ids) => { + self.render_pass_execute_bundles(pass_id, &ids) + } + RenderPassEncoderCommand::BindingCommand(binding_command) => match binding_command { + BindingCommand::SetBindGroup { + index, + bind_group, + dynamic_offsets, + } => self.render_pass_set_bind_group(pass_id, index, bind_group, &dynamic_offsets), + BindingCommand::SetImmediates { range_offset, data } => { + self.render_pass_set_immediates(pass_id, range_offset, &data) + } + }, + RenderPassEncoderCommand::RenderCommand(render_command) => match render_command { + RenderCommand::SetPipeline(pipeline_id) => { + self.render_pass_set_pipeline(pass_id, pipeline_id) + } + RenderCommand::SetIndexBuffer { + buffer, + index_format, + offset, + size, + } => self.render_pass_set_index_buffer( + pass_id, + buffer, + index_format, + offset, + size.and_then(core::num::NonZeroU64::new), // pass size directly once https://github.com/gfx-rs/wgpu/issues/3170 is resolved + ), + RenderCommand::SetVertexBuffer { + slot, + buffer, + offset, + size, + } => self.render_pass_set_vertex_buffer( + pass_id, + slot, + buffer, + offset, + size.and_then(core::num::NonZeroU64::new), // pass size directly once https://github.com/gfx-rs/wgpu/issues/3170 is resolved + ), + RenderCommand::Draw { + vertex_count, + instance_count, + first_vertex, + first_instance, + } => self.render_pass_draw( + pass_id, + vertex_count, + instance_count, + first_vertex, + first_instance, + ), + RenderCommand::DrawIndexed { + index_count, + instance_count, + first_index, + base_vertex, + first_instance, + } => self.render_pass_draw_indexed( + pass_id, + index_count, + instance_count, + first_index, + base_vertex, + first_instance, + ), + RenderCommand::DrawIndirect { + indirect_buffer, + indirect_offset, + } => self.render_pass_draw_indirect(pass_id, indirect_buffer, indirect_offset), + RenderCommand::DrawIndexedIndirect { + indirect_buffer, + indirect_offset, + } => self.render_pass_draw_indexed_indirect( + pass_id, + indirect_buffer, + indirect_offset, + ), + }, + RenderPassEncoderCommand::DebugCommand(debug_command) => match debug_command { + DebugCommand::PushDebugGroup(label) => { + self.render_pass_push_debug_group(pass_id, &label, 0) + } + DebugCommand::PopDebugGroup => self.render_pass_pop_debug_group(pass_id), + DebugCommand::InsertDebugMarker(label) => { + self.render_pass_insert_debug_marker(pass_id, &label, 0) + } + }, + RenderPassEncoderCommand::End => self.render_pass_end(pass_id), + } + } +}