From aaf52e93d9929912a63b1a4febdd6bc692505977 Mon Sep 17 00:00:00 2001 From: Andy Leiserson Date: Wed, 10 Sep 2025 15:18:46 -0700 Subject: [PATCH] Move some `*Copy*Info` types out of `wgpu_core::command::transfer` In the future `transfer` will want to use the `Arc` versions of these types. I have exported them from `wgpu_core::command::ffi`, to document that these are used for FFI purposes, and from `wgpu_core::command`, for backwards compatibility, although I also change the in-tree uses to use them from `wgpu_types` instead of from `wgpu_core::command`. --- wgpu-core/src/command/encoder_command.rs | 12 ++++++------ wgpu-core/src/command/ffi.rs | 7 +++++++ wgpu-core/src/command/mod.rs | 5 +++++ wgpu-core/src/command/transfer.rs | 7 +++---- wgpu-core/src/device/queue.rs | 4 ++-- wgpu-core/src/device/trace.rs | 2 +- wgpu/src/backend/wgpu_core.rs | 10 ++++++---- 7 files changed, 30 insertions(+), 17 deletions(-) create mode 100644 wgpu-core/src/command/ffi.rs diff --git a/wgpu-core/src/command/encoder_command.rs b/wgpu-core/src/command/encoder_command.rs index 31d50504f7..058caed025 100644 --- a/wgpu-core/src/command/encoder_command.rs +++ b/wgpu-core/src/command/encoder_command.rs @@ -15,18 +15,18 @@ pub enum Command { size: Option, }, CopyBufferToTexture { - src: crate::command::TexelCopyBufferInfo, - dst: crate::command::TexelCopyTextureInfo, + src: wgt::TexelCopyBufferInfo, + dst: wgt::TexelCopyTextureInfo, size: wgt::Extent3d, }, CopyTextureToBuffer { - src: crate::command::TexelCopyTextureInfo, - dst: crate::command::TexelCopyBufferInfo, + src: wgt::TexelCopyTextureInfo, + dst: wgt::TexelCopyBufferInfo, size: wgt::Extent3d, }, CopyTextureToTexture { - src: crate::command::TexelCopyTextureInfo, - dst: crate::command::TexelCopyTextureInfo, + src: wgt::TexelCopyTextureInfo, + dst: wgt::TexelCopyTextureInfo, size: wgt::Extent3d, }, ClearBuffer { diff --git a/wgpu-core/src/command/ffi.rs b/wgpu-core/src/command/ffi.rs new file mode 100644 index 0000000000..9f53d7b563 --- /dev/null +++ b/wgpu-core/src/command/ffi.rs @@ -0,0 +1,7 @@ +//! Types that are useful for FFI bindings to `wgpu`. + +use crate::id; + +pub type TexelCopyBufferInfo = wgt::TexelCopyBufferInfo; +pub type TexelCopyTextureInfo = wgt::TexelCopyTextureInfo; +pub type CopyExternalImageDestInfo = wgt::CopyExternalImageDestInfo; diff --git a/wgpu-core/src/command/mod.rs b/wgpu-core/src/command/mod.rs index 0a84f10740..7ecc517a87 100644 --- a/wgpu-core/src/command/mod.rs +++ b/wgpu-core/src/command/mod.rs @@ -7,6 +7,7 @@ mod compute_command; mod draw; mod encoder; mod encoder_command; +pub mod ffi; mod memory_init; mod pass; mod query; @@ -58,6 +59,10 @@ use thiserror::Error; #[cfg(feature = "trace")] type TraceCommand = Command; +pub type TexelCopyBufferInfo = ffi::TexelCopyBufferInfo; +pub type TexelCopyTextureInfo = ffi::TexelCopyTextureInfo; +pub type CopyExternalImageDestInfo = ffi::CopyExternalImageDestInfo; + const PUSH_CONSTANT_CLEAR_ARRAY: &[u32] = &[0_u32; 64]; /// The current state of a command or pass encoder. diff --git a/wgpu-core/src/command/transfer.rs b/wgpu-core/src/command/transfer.rs index 52a0312b50..5ce0a2722f 100644 --- a/wgpu-core/src/command/transfer.rs +++ b/wgpu-core/src/command/transfer.rs @@ -15,7 +15,7 @@ use crate::{ command::{clear_texture, CommandEncoderError, EncoderStateError}, device::{Device, MissingDownlevelFlags}, global::Global, - id::{BufferId, CommandEncoderId, TextureId}, + id::{BufferId, CommandEncoderId}, init_tracker::{ has_copy_partial_init_tracker_coverage, MemoryInitKind, TextureInitRange, TextureInitTrackerAction, @@ -29,9 +29,8 @@ use crate::{ use super::{ClearError, CommandBufferMutable}; -pub type TexelCopyBufferInfo = wgt::TexelCopyBufferInfo; -pub type TexelCopyTextureInfo = wgt::TexelCopyTextureInfo; -pub type CopyExternalImageDestInfo = wgt::CopyExternalImageDestInfo; +use super::TexelCopyBufferInfo; +use super::TexelCopyTextureInfo; #[derive(Clone, Copy, Debug, Eq, PartialEq)] pub enum CopySide { diff --git a/wgpu-core/src/device/queue.rs b/wgpu-core/src/device/queue.rs index b900a437a9..eb936ce709 100644 --- a/wgpu-core/src/device/queue.rs +++ b/wgpu-core/src/device/queue.rs @@ -22,7 +22,7 @@ use crate::{ extract_texture_selector, validate_linear_texture_data, validate_texture_buffer_copy, validate_texture_copy_dst_format, validate_texture_copy_range, ClearError, CommandAllocator, CommandBuffer, CommandEncoder, CommandEncoderError, CopySide, - TexelCopyTextureInfo, TransferError, + TransferError, }, device::{DeviceError, WaitIdleError}, get_lowest_common_denom, @@ -1617,7 +1617,7 @@ impl Global { pub fn queue_write_texture( &self, queue_id: QueueId, - destination: &TexelCopyTextureInfo, + destination: &wgt::TexelCopyTextureInfo, data: &[u8], data_layout: &wgt::TexelCopyBufferLayout, size: &wgt::Extent3d, diff --git a/wgpu-core/src/device/trace.rs b/wgpu-core/src/device/trace.rs index 8b76c852db..fcb3f58915 100644 --- a/wgpu-core/src/device/trace.rs +++ b/wgpu-core/src/device/trace.rs @@ -140,7 +140,7 @@ pub enum Action<'a> { queued: bool, }, WriteTexture { - to: crate::command::TexelCopyTextureInfo, + to: wgt::TexelCopyTextureInfo, data: FileName, layout: wgt::TexelCopyBufferLayout, size: wgt::Extent3d, diff --git a/wgpu/src/backend/wgpu_core.rs b/wgpu/src/backend/wgpu_core.rs index 812cd5276a..b39e846efe 100644 --- a/wgpu/src/backend/wgpu_core.rs +++ b/wgpu/src/backend/wgpu_core.rs @@ -386,8 +386,10 @@ impl ContextWgpuCore { } } -fn map_buffer_copy_view(view: crate::TexelCopyBufferInfo<'_>) -> wgc::command::TexelCopyBufferInfo { - wgc::command::TexelCopyBufferInfo { +fn map_buffer_copy_view( + view: crate::TexelCopyBufferInfo<'_>, +) -> wgt::TexelCopyBufferInfo { + wgt::TexelCopyBufferInfo { buffer: view.buffer.inner.as_core().id, layout: view.layout, } @@ -407,8 +409,8 @@ fn map_texture_copy_view( #[cfg_attr(not(webgl), expect(unused))] fn map_texture_tagged_copy_view( view: crate::CopyExternalImageDestInfo<&api::Texture>, -) -> wgc::command::CopyExternalImageDestInfo { - wgc::command::CopyExternalImageDestInfo { +) -> wgt::CopyExternalImageDestInfo { + wgt::CopyExternalImageDestInfo { texture: view.texture.inner.as_core().id, mip_level: view.mip_level, origin: view.origin,