diff options
author | Martin Robinson <mrobinson@igalia.com> | 2025-04-04 10:06:07 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-04-04 08:06:07 +0000 |
commit | 0d693114ad4f27a07a3cd18c4c34da53be55d1bc (patch) | |
tree | 35d4382e088703434cb6b109b3a4bd9476c8ccf6 /components/shared/webgpu/render_commands.rs | |
parent | df9efde1c377f0ff701fdd72814b628e73397464 (diff) | |
download | servo-0d693114ad4f27a07a3cd18c4c34da53be55d1bc.tar.gz servo-0d693114ad4f27a07a3cd18c4c34da53be55d1bc.zip |
webgpu: Add a `webgpu_traits` crate (#36320)
This breaks the `script_traits` dependency on `webgpu`. In general, the
`traits` crates shouldn't depend on Servo non-`traits` crates. This is
necessary to move "script to constellation" messages to the
`constellation_traits` crate, making it the entire API for talking to
the
constellation. This will break a circular dependency when that happens.
Testing: Successfully building is enough of a test for this one as
it is mainly moving types around.
Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Diffstat (limited to 'components/shared/webgpu/render_commands.rs')
-rw-r--r-- | components/shared/webgpu/render_commands.rs | 155 |
1 files changed, 155 insertions, 0 deletions
diff --git a/components/shared/webgpu/render_commands.rs b/components/shared/webgpu/render_commands.rs new file mode 100644 index 00000000000..37ba70daaca --- /dev/null +++ b/components/shared/webgpu/render_commands.rs @@ -0,0 +1,155 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ + +//! Render pass commands + +use serde::{Deserialize, Serialize}; +use wgpu_core::command::{RenderPass, RenderPassError}; +use wgpu_core::global::Global; +use wgpu_core::id::{BindGroupId, BufferId, RenderBundleId, RenderPipelineId}; + +/// <https://github.com/gfx-rs/wgpu/blob/f25e07b984ab391628d9568296d5970981d79d8b/wgpu-core/src/command/render_command.rs#L17> +#[derive(Debug, Deserialize, Serialize)] +pub enum RenderCommand { + SetPipeline(RenderPipelineId), + SetBindGroup { + index: u32, + bind_group_id: BindGroupId, + offsets: Vec<u32>, + }, + 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(wgpu_types::Color), + SetStencilReference(u32), + SetIndexBuffer { + buffer_id: BufferId, + index_format: wgpu_types::IndexFormat, + offset: u64, + size: Option<wgpu_types::BufferSize>, + }, + SetVertexBuffer { + slot: u32, + buffer_id: BufferId, + offset: u64, + size: Option<wgpu_types::BufferSize>, + }, + Draw { + vertex_count: u32, + instance_count: u32, + first_vertex: u32, + first_instance: u32, + }, + DrawIndexed { + index_count: u32, + instance_count: u32, + first_index: u32, + base_vertex: i32, + first_instance: u32, + }, + DrawIndirect { + buffer_id: BufferId, + offset: u64, + }, + DrawIndexedIndirect { + buffer_id: BufferId, + offset: u64, + }, + ExecuteBundles(Vec<RenderBundleId>), +} + +pub fn apply_render_command( + global: &Global, + pass: &mut RenderPass, + command: RenderCommand, +) -> Result<(), RenderPassError> { + match command { + RenderCommand::SetPipeline(pipeline_id) => { + global.render_pass_set_pipeline(pass, pipeline_id) + }, + RenderCommand::SetBindGroup { + index, + bind_group_id, + offsets, + } => global.render_pass_set_bind_group(pass, index, Some(bind_group_id), &offsets), + RenderCommand::SetViewport { + x, + y, + width, + height, + min_depth, + max_depth, + } => global.render_pass_set_viewport(pass, x, y, width, height, min_depth, max_depth), + RenderCommand::SetScissorRect { + x, + y, + width, + height, + } => global.render_pass_set_scissor_rect(pass, x, y, width, height), + RenderCommand::SetBlendConstant(color) => { + global.render_pass_set_blend_constant(pass, color) + }, + RenderCommand::SetStencilReference(reference) => { + global.render_pass_set_stencil_reference(pass, reference) + }, + RenderCommand::SetIndexBuffer { + buffer_id, + index_format, + offset, + size, + } => global.render_pass_set_index_buffer(pass, buffer_id, index_format, offset, size), + RenderCommand::SetVertexBuffer { + slot, + buffer_id, + offset, + size, + } => global.render_pass_set_vertex_buffer(pass, slot, buffer_id, offset, size), + RenderCommand::Draw { + vertex_count, + instance_count, + first_vertex, + first_instance, + } => global.render_pass_draw( + pass, + vertex_count, + instance_count, + first_vertex, + first_instance, + ), + RenderCommand::DrawIndexed { + index_count, + instance_count, + first_index, + base_vertex, + first_instance, + } => global.render_pass_draw_indexed( + pass, + index_count, + instance_count, + first_index, + base_vertex, + first_instance, + ), + RenderCommand::DrawIndirect { buffer_id, offset } => { + global.render_pass_draw_indirect(pass, buffer_id, offset) + }, + RenderCommand::DrawIndexedIndirect { buffer_id, offset } => { + global.render_pass_draw_indexed_indirect(pass, buffer_id, offset) + }, + RenderCommand::ExecuteBundles(bundles) => { + global.render_pass_execute_bundles(pass, &bundles) + }, + } +} |