From 718497356c43303653d177f062bffa8f165f8900 Mon Sep 17 00:00:00 2001 From: Andy Leiserson Date: Thu, 28 Aug 2025 16:58:32 -0700 Subject: [PATCH] Move `enum Command` from `device::trace` to `command::encoder_command`. --- player/src/lib.rs | 36 ++++++------ wgpu-core/src/command/clear.rs | 2 +- wgpu-core/src/command/compute.rs | 2 +- wgpu-core/src/command/encoder_command.rs | 70 ++++++++++++++++++++++++ wgpu-core/src/command/mod.rs | 7 ++- wgpu-core/src/command/query.rs | 2 +- wgpu-core/src/command/ray_tracing.rs | 2 +- wgpu-core/src/command/render.rs | 2 +- wgpu-core/src/command/transfer.rs | 2 +- wgpu-core/src/device/trace.rs | 67 +---------------------- 10 files changed, 98 insertions(+), 94 deletions(-) create mode 100644 wgpu-core/src/command/encoder_command.rs diff --git a/player/src/lib.rs b/player/src/lib.rs index 8ba7e13ce1..437f51b14b 100644 --- a/player/src/lib.rs +++ b/player/src/lib.rs @@ -6,7 +6,7 @@ extern crate wgpu_core as wgc; extern crate wgpu_types as wgt; -use wgc::{device::trace, identity::IdentityManager}; +use wgc::{command::Command, device::trace, identity::IdentityManager}; use std::{borrow::Cow, fs, path::Path}; @@ -14,7 +14,7 @@ pub trait GlobalPlay { fn encode_commands( &self, encoder: wgc::id::CommandEncoderId, - commands: Vec, + commands: Vec, command_buffer_id_manager: &mut IdentityManager, ) -> wgc::id::CommandBufferId; fn process( @@ -32,12 +32,12 @@ impl GlobalPlay for wgc::global::Global { fn encode_commands( &self, encoder: wgc::id::CommandEncoderId, - commands: Vec, + commands: Vec, command_buffer_id_manager: &mut IdentityManager, ) -> wgc::id::CommandBufferId { for command in commands { match command { - trace::Command::CopyBufferToBuffer { + Command::CopyBufferToBuffer { src, src_offset, dst, @@ -48,31 +48,31 @@ impl GlobalPlay for wgc::global::Global { encoder, src, src_offset, dst, dst_offset, size, ) .unwrap(), - trace::Command::CopyBufferToTexture { src, dst, size } => self + Command::CopyBufferToTexture { src, dst, size } => self .command_encoder_copy_buffer_to_texture(encoder, &src, &dst, &size) .unwrap(), - trace::Command::CopyTextureToBuffer { src, dst, size } => self + Command::CopyTextureToBuffer { src, dst, size } => self .command_encoder_copy_texture_to_buffer(encoder, &src, &dst, &size) .unwrap(), - trace::Command::CopyTextureToTexture { src, dst, size } => self + Command::CopyTextureToTexture { src, dst, size } => self .command_encoder_copy_texture_to_texture(encoder, &src, &dst, &size) .unwrap(), - trace::Command::ClearBuffer { dst, offset, size } => self + Command::ClearBuffer { dst, offset, size } => self .command_encoder_clear_buffer(encoder, dst, offset, size) .unwrap(), - trace::Command::ClearTexture { + Command::ClearTexture { dst, subresource_range, } => self .command_encoder_clear_texture(encoder, dst, &subresource_range) .unwrap(), - trace::Command::WriteTimestamp { + Command::WriteTimestamp { query_set_id, query_index, } => self .command_encoder_write_timestamp(encoder, query_set_id, query_index) .unwrap(), - trace::Command::ResolveQuerySet { + Command::ResolveQuerySet { query_set_id, start_query, query_count, @@ -88,16 +88,14 @@ impl GlobalPlay for wgc::global::Global { destination_offset, ) .unwrap(), - trace::Command::PushDebugGroup(marker) => self + Command::PushDebugGroup(marker) => self .command_encoder_push_debug_group(encoder, &marker) .unwrap(), - trace::Command::PopDebugGroup => { - self.command_encoder_pop_debug_group(encoder).unwrap() - } - trace::Command::InsertDebugMarker(marker) => self + Command::PopDebugGroup => self.command_encoder_pop_debug_group(encoder).unwrap(), + Command::InsertDebugMarker(marker) => self .command_encoder_insert_debug_marker(encoder, &marker) .unwrap(), - trace::Command::RunComputePass { + Command::RunComputePass { base, timestamp_writes, } => { @@ -107,7 +105,7 @@ impl GlobalPlay for wgc::global::Global { timestamp_writes.as_ref(), ); } - trace::Command::RunRenderPass { + Command::RunRenderPass { base, target_colors, target_depth_stencil, @@ -123,7 +121,7 @@ impl GlobalPlay for wgc::global::Global { occlusion_query_set_id, ); } - trace::Command::BuildAccelerationStructures { blas, tlas } => { + Command::BuildAccelerationStructures { blas, tlas } => { let blas_iter = blas.iter().map(|x| { let geometries = match &x.geometries { wgc::ray_tracing::TraceBlasGeometries::TriangleGeometries( diff --git a/wgpu-core/src/command/clear.rs b/wgpu-core/src/command/clear.rs index 840e906812..323bf5d489 100644 --- a/wgpu-core/src/command/clear.rs +++ b/wgpu-core/src/command/clear.rs @@ -2,7 +2,7 @@ use alloc::{sync::Arc, vec::Vec}; use core::ops::Range; #[cfg(feature = "trace")] -use crate::device::trace::Command as TraceCommand; +use crate::command::Command as TraceCommand; use crate::{ api_log, command::EncoderStateError, diff --git a/wgpu-core/src/command/compute.rs b/wgpu-core/src/command/compute.rs index 52f8e09cfc..f34c7779c1 100644 --- a/wgpu-core/src/command/compute.rs +++ b/wgpu-core/src/command/compute.rs @@ -438,7 +438,7 @@ impl Global { let cmd_buf_data = cmd_buf_data.get_inner(); if let Some(ref mut list) = cmd_buf_data.commands { - list.push(crate::device::trace::Command::RunComputePass { + list.push(crate::command::Command::RunComputePass { base: BasePass { label: base.label.clone(), error: None, diff --git a/wgpu-core/src/command/encoder_command.rs b/wgpu-core/src/command/encoder_command.rs new file mode 100644 index 0000000000..31d50504f7 --- /dev/null +++ b/wgpu-core/src/command/encoder_command.rs @@ -0,0 +1,70 @@ +use core::convert::Infallible; + +use alloc::{string::String, vec::Vec}; + +use crate::id; + +#[derive(Clone, Debug)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +pub enum Command { + CopyBufferToBuffer { + src: id::BufferId, + src_offset: wgt::BufferAddress, + dst: id::BufferId, + dst_offset: wgt::BufferAddress, + size: Option, + }, + CopyBufferToTexture { + src: crate::command::TexelCopyBufferInfo, + dst: crate::command::TexelCopyTextureInfo, + size: wgt::Extent3d, + }, + CopyTextureToBuffer { + src: crate::command::TexelCopyTextureInfo, + dst: crate::command::TexelCopyBufferInfo, + size: wgt::Extent3d, + }, + CopyTextureToTexture { + src: crate::command::TexelCopyTextureInfo, + dst: crate::command::TexelCopyTextureInfo, + size: wgt::Extent3d, + }, + ClearBuffer { + dst: id::BufferId, + offset: wgt::BufferAddress, + size: Option, + }, + ClearTexture { + dst: id::TextureId, + subresource_range: wgt::ImageSubresourceRange, + }, + WriteTimestamp { + query_set_id: id::QuerySetId, + query_index: u32, + }, + ResolveQuerySet { + query_set_id: id::QuerySetId, + start_query: u32, + query_count: u32, + destination: id::BufferId, + destination_offset: wgt::BufferAddress, + }, + PushDebugGroup(String), + PopDebugGroup, + InsertDebugMarker(String), + RunComputePass { + base: crate::command::BasePass, + timestamp_writes: Option, + }, + RunRenderPass { + base: crate::command::BasePass, + target_colors: Vec>, + target_depth_stencil: Option, + timestamp_writes: Option, + occlusion_query_set_id: Option, + }, + BuildAccelerationStructures { + blas: Vec, + tlas: Vec, + }, +} diff --git a/wgpu-core/src/command/mod.rs b/wgpu-core/src/command/mod.rs index cdf3435002..831b071d70 100644 --- a/wgpu-core/src/command/mod.rs +++ b/wgpu-core/src/command/mod.rs @@ -6,6 +6,7 @@ mod compute; mod compute_command; mod draw; mod encoder; +mod encoder_command; mod memory_init; mod pass; mod query; @@ -22,8 +23,8 @@ use core::ops; pub(crate) use self::clear::clear_texture; pub use self::{ - bundle::*, clear::ClearError, compute::*, compute_command::ComputeCommand, draw::*, query::*, - render::*, render_command::RenderCommand, transfer::*, + bundle::*, clear::ClearError, compute::*, compute_command::ComputeCommand, draw::*, + encoder_command::Command, query::*, render::*, render_command::RenderCommand, transfer::*, }; pub(crate) use allocator::CommandAllocator; @@ -55,7 +56,7 @@ use wgt::error::{ErrorType, WebGpuError}; use thiserror::Error; #[cfg(feature = "trace")] -use crate::device::trace::Command as TraceCommand; +type TraceCommand = Command; const PUSH_CONSTANT_CLEAR_ARRAY: &[u32] = &[0_u32; 64]; diff --git a/wgpu-core/src/command/query.rs b/wgpu-core/src/command/query.rs index c47374b028..afd7338457 100644 --- a/wgpu-core/src/command/query.rs +++ b/wgpu-core/src/command/query.rs @@ -2,7 +2,7 @@ use alloc::{sync::Arc, vec, vec::Vec}; use core::{iter, mem}; #[cfg(feature = "trace")] -use crate::device::trace::Command as TraceCommand; +use crate::command::Command as TraceCommand; use crate::{ command::{CommandEncoder, EncoderStateError}, device::{DeviceError, MissingFeatures}, diff --git a/wgpu-core/src/command/ray_tracing.rs b/wgpu-core/src/command/ray_tracing.rs index e4553ff222..1aac0014f3 100644 --- a/wgpu-core/src/command/ray_tracing.rs +++ b/wgpu-core/src/command/ray_tracing.rs @@ -201,7 +201,7 @@ impl Global { cmd_buf_data.record_with(|cmd_buf_data| { #[cfg(feature = "trace")] if let Some(ref mut list) = cmd_buf_data.commands { - list.push(crate::device::trace::Command::BuildAccelerationStructures { + list.push(crate::command::Command::BuildAccelerationStructures { blas: trace_blas.clone(), tlas: trace_tlas.clone(), }); diff --git a/wgpu-core/src/command/render.rs b/wgpu-core/src/command/render.rs index 7e38c468f9..30f45f1b00 100644 --- a/wgpu-core/src/command/render.rs +++ b/wgpu-core/src/command/render.rs @@ -1753,7 +1753,7 @@ impl Global { let cmd_buf_data = cmd_buf_data.get_inner(); if let Some(ref mut list) = cmd_buf_data.commands { - list.push(crate::device::trace::Command::RunRenderPass { + list.push(crate::command::Command::RunRenderPass { base: BasePass { label: base.label.clone(), error: None, diff --git a/wgpu-core/src/command/transfer.rs b/wgpu-core/src/command/transfer.rs index a9a125331d..e351de4c12 100644 --- a/wgpu-core/src/command/transfer.rs +++ b/wgpu-core/src/command/transfer.rs @@ -9,7 +9,7 @@ use wgt::{ }; #[cfg(feature = "trace")] -use crate::device::trace::Command as TraceCommand; +use crate::command::Command as TraceCommand; use crate::{ api_log, command::{clear_texture, CommandEncoderError, EncoderStateError}, diff --git a/wgpu-core/src/device/trace.rs b/wgpu-core/src/device/trace.rs index 80432d5e93..8b76c852db 100644 --- a/wgpu-core/src/device/trace.rs +++ b/wgpu-core/src/device/trace.rs @@ -4,7 +4,7 @@ use core::{convert::Infallible, ops::Range}; #[cfg(feature = "trace")] use {alloc::borrow::Cow, std::io::Write as _}; -use crate::id; +use crate::{command::Command, id}; //TODO: consider a readable Id that doesn't include the backend @@ -159,71 +159,6 @@ pub enum Action<'a> { DestroyTlas(id::TlasId), } -#[derive(Debug)] -#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] -pub enum Command { - CopyBufferToBuffer { - src: id::BufferId, - src_offset: wgt::BufferAddress, - dst: id::BufferId, - dst_offset: wgt::BufferAddress, - size: Option, - }, - CopyBufferToTexture { - src: crate::command::TexelCopyBufferInfo, - dst: crate::command::TexelCopyTextureInfo, - size: wgt::Extent3d, - }, - CopyTextureToBuffer { - src: crate::command::TexelCopyTextureInfo, - dst: crate::command::TexelCopyBufferInfo, - size: wgt::Extent3d, - }, - CopyTextureToTexture { - src: crate::command::TexelCopyTextureInfo, - dst: crate::command::TexelCopyTextureInfo, - size: wgt::Extent3d, - }, - ClearBuffer { - dst: id::BufferId, - offset: wgt::BufferAddress, - size: Option, - }, - ClearTexture { - dst: id::TextureId, - subresource_range: wgt::ImageSubresourceRange, - }, - WriteTimestamp { - query_set_id: id::QuerySetId, - query_index: u32, - }, - ResolveQuerySet { - query_set_id: id::QuerySetId, - start_query: u32, - query_count: u32, - destination: id::BufferId, - destination_offset: wgt::BufferAddress, - }, - PushDebugGroup(String), - PopDebugGroup, - InsertDebugMarker(String), - RunComputePass { - base: crate::command::BasePass, - timestamp_writes: Option, - }, - RunRenderPass { - base: crate::command::BasePass, - target_colors: Vec>, - target_depth_stencil: Option, - timestamp_writes: Option, - occlusion_query_set_id: Option, - }, - BuildAccelerationStructures { - blas: Vec, - tlas: Vec, - }, -} - #[cfg(feature = "trace")] #[derive(Debug)] pub struct Trace {