Move enum Command from device::trace to command::encoder_command.

This commit is contained in:
Andy Leiserson 2025-08-28 16:58:32 -07:00
parent c0c16078e9
commit 718497356c
10 changed files with 98 additions and 94 deletions

View File

@ -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<trace::Command>,
commands: Vec<Command>,
command_buffer_id_manager: &mut IdentityManager<wgc::id::markers::CommandBuffer>,
) -> 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<trace::Command>,
commands: Vec<Command>,
command_buffer_id_manager: &mut IdentityManager<wgc::id::markers::CommandBuffer>,
) -> 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(

View File

@ -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,

View File

@ -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,

View File

@ -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<wgt::BufferAddress>,
},
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<wgt::BufferAddress>,
},
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<crate::command::ComputeCommand, Infallible>,
timestamp_writes: Option<crate::command::PassTimestampWrites>,
},
RunRenderPass {
base: crate::command::BasePass<crate::command::RenderCommand, Infallible>,
target_colors: Vec<Option<crate::command::RenderPassColorAttachment>>,
target_depth_stencil: Option<crate::command::RenderPassDepthStencilAttachment>,
timestamp_writes: Option<crate::command::PassTimestampWrites>,
occlusion_query_set_id: Option<id::QuerySetId>,
},
BuildAccelerationStructures {
blas: Vec<crate::ray_tracing::TraceBlasBuildEntry>,
tlas: Vec<crate::ray_tracing::TraceTlasPackage>,
},
}

View File

@ -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];

View File

@ -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},

View File

@ -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(),
});

View File

@ -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,

View File

@ -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},

View File

@ -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<wgt::BufferAddress>,
},
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<wgt::BufferAddress>,
},
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<crate::command::ComputeCommand, Infallible>,
timestamp_writes: Option<crate::command::PassTimestampWrites>,
},
RunRenderPass {
base: crate::command::BasePass<crate::command::RenderCommand, Infallible>,
target_colors: Vec<Option<crate::command::RenderPassColorAttachment>>,
target_depth_stencil: Option<crate::command::RenderPassDepthStencilAttachment>,
timestamp_writes: Option<crate::command::PassTimestampWrites>,
occlusion_query_set_id: Option<id::QuerySetId>,
},
BuildAccelerationStructures {
blas: Vec<crate::ray_tracing::TraceBlasBuildEntry>,
tlas: Vec<crate::ray_tracing::TraceTlasPackage>,
},
}
#[cfg(feature = "trace")]
#[derive(Debug)]
pub struct Trace {