From 252ef09792bb4c326049b3ccd005599c9d120ea2 Mon Sep 17 00:00:00 2001 From: Chris Biscardi Date: Mon, 16 Mar 2026 05:37:17 -0700 Subject: [PATCH] move WriteOnly to wgpu-types (#9236) * move WriteOnly to wgpu-types * un-pub mod, because pub use * is already in play * fixup doctests * link to wgpu items --- wgpu-types/src/lib.rs | 2 ++ {wgpu => wgpu-types}/src/write_only.rs | 15 +++++++++++++-- wgpu/src/lib.rs | 10 ++++------ 3 files changed, 19 insertions(+), 8 deletions(-) rename {wgpu => wgpu-types}/src/write_only.rs (98%) diff --git a/wgpu-types/src/lib.rs b/wgpu-types/src/lib.rs index bd98d2ded..7ea28ee1f 100644 --- a/wgpu-types/src/lib.rs +++ b/wgpu-types/src/lib.rs @@ -49,6 +49,7 @@ mod texture; mod tokens; mod transfers; mod vertex; +mod write_only; pub use adapter::*; pub use backend::*; @@ -70,6 +71,7 @@ pub use texture::*; pub use tokens::*; pub use transfers::*; pub use vertex::*; +pub use write_only::*; /// Create a Markdown link definition referring to the `wgpu` crate. /// diff --git a/wgpu/src/write_only.rs b/wgpu-types/src/write_only.rs similarity index 98% rename from wgpu/src/write_only.rs rename to wgpu-types/src/write_only.rs index 292c0d286..52febc5c2 100644 --- a/wgpu/src/write_only.rs +++ b/wgpu-types/src/write_only.rs @@ -20,10 +20,12 @@ use core::{ ptr::NonNull, }; +use crate::link_to_wgpu_item; + /// Like `&'a mut T`, but allows only write operations. /// -/// This pointer type is obtained from [`BufferViewMut`][crate::BufferViewMut] and -/// [`QueueWriteBufferView`][crate::QueueWriteBufferView]. +/// This pointer type is obtained from [`BufferViewMut`] and +/// [`QueueWriteBufferView`]. /// It is an unfortunate necessity due to the fact that mapped GPU memory may be [write combining], /// which means it cannot work normally with all of the things that Rust `&mut` access allows you to /// do. @@ -38,6 +40,8 @@ use core::{ // FIXME: Add an introduction to the necessity of explicit reborrowing. /// /// [write combining]: https://en.wikipedia.org/wiki/Write_combining +#[doc = link_to_wgpu_item!(struct BufferViewMut)] +#[doc = link_to_wgpu_item!(struct QueueWriteBufferView)] pub struct WriteOnly<'a, T: ?Sized> { /// The data which this write-only reference allows **writing** to. /// @@ -107,6 +111,7 @@ impl<'a, T: ?Sized> WriteOnly<'a, T> { /// # Example /// /// ``` + /// # use wgpu_types as wgpu; /// fn write_numbers(slice: wgpu::WriteOnly<[u32]>) { /// for (i, mut elem) in slice.into_iter().enumerate() { /// elem.write(i as u32); @@ -177,6 +182,7 @@ impl<'a, T> WriteOnly<'a, [T]> { /// # Example /// /// ``` + /// # use wgpu_types as wgpu; /// let example_slice: &mut [u8] = &mut [0; 10]; /// assert_eq!(wgpu::WriteOnly::from_mut(example_slice).len(), example_slice.len()); /// ``` @@ -203,6 +209,7 @@ impl<'a, T> WriteOnly<'a, [T]> { /// # Example /// /// ``` + /// # use wgpu_types as wgpu; /// // Ordinarily you would get a `WriteOnly` from `wgpu::Buffer` instead. /// let mut data: [u8; 9] = [0; 9]; /// let mut wo = wgpu::WriteOnly::from_mut(data.as_mut_slice()); @@ -259,6 +266,7 @@ impl<'a, T> WriteOnly<'a, [T]> { /// # Example /// /// ``` + /// # use wgpu_types as wgpu; /// // Ordinarily you would get a `WriteOnly` from `wgpu::Buffer` instead. /// let mut buf: [u8; 10] = [0; 10]; /// let wo = wgpu::WriteOnly::from_mut(buf.as_mut_slice()); @@ -305,6 +313,7 @@ impl<'a, T> WriteOnly<'a, [T]> { /// # Example /// /// ``` + /// # use wgpu_types as wgpu; /// // Ordinarily you would get a `WriteOnly` from `wgpu::Buffer` instead. /// let mut buf = vec![0; 10]; /// let mut wo = wgpu::WriteOnly::from_mut(buf.as_mut_slice()); @@ -357,6 +366,7 @@ impl<'a, T> WriteOnly<'a, [T]> { /// # Example /// /// ``` + /// # use wgpu_types as wgpu; /// // Ordinarily you would get a `WriteOnly` from `wgpu::Buffer` instead. /// let mut buf = vec![0; 5]; /// let mut wo = wgpu::WriteOnly::from_mut(buf.as_mut_slice()); @@ -415,6 +425,7 @@ impl<'a, T> WriteOnly<'a, [T]> { /// (If a transformation is not required, use [`WriteOnly::copy_from_slice()`].) /// /// ``` + /// # use wgpu_types as wgpu; /// fn write_text_as_chars(text: &str, output: wgpu::WriteOnly<[u8]>) { /// let (mut output, _remainder) = output.into_chunks::<{ size_of::() }>(); /// output.write_iter(text.chars().map(|ch| (ch as u32).to_ne_bytes())); diff --git a/wgpu/src/lib.rs b/wgpu/src/lib.rs index d3fdf79a8..5279e884e 100644 --- a/wgpu/src/lib.rs +++ b/wgpu/src/lib.rs @@ -116,7 +116,6 @@ mod cmp; mod dispatch; mod macros; pub mod util; -mod write_only; // // @@ -151,12 +150,11 @@ pub use wgt::{ SurfaceCapabilities, SurfaceStatus, TexelCopyBufferLayout, TextureAspect, TextureDimension, TextureFormat, TextureFormatFeatureFlags, TextureFormatFeatures, TextureSampleType, TextureTransition, TextureUsages, TextureUses, TextureViewDimension, Trace, VertexAttribute, - VertexFormat, VertexStepMode, WasmNotSend, WasmNotSendSync, WasmNotSync, COPY_BUFFER_ALIGNMENT, - COPY_BYTES_PER_ROW_ALIGNMENT, IMMEDIATE_DATA_ALIGNMENT, MAP_ALIGNMENT, - MAXIMUM_SUBGROUP_MAX_SIZE, MINIMUM_SUBGROUP_MIN_SIZE, QUERY_RESOLVE_BUFFER_ALIGNMENT, - QUERY_SET_MAX_QUERIES, QUERY_SIZE, VERTEX_ALIGNMENT, + VertexFormat, VertexStepMode, WasmNotSend, WasmNotSendSync, WasmNotSync, WriteOnly, + WriteOnlyIter, COPY_BUFFER_ALIGNMENT, COPY_BYTES_PER_ROW_ALIGNMENT, IMMEDIATE_DATA_ALIGNMENT, + MAP_ALIGNMENT, MAXIMUM_SUBGROUP_MAX_SIZE, MINIMUM_SUBGROUP_MIN_SIZE, + QUERY_RESOLVE_BUFFER_ALIGNMENT, QUERY_SET_MAX_QUERIES, QUERY_SIZE, VERTEX_ALIGNMENT, }; -pub use write_only::{WriteOnly, WriteOnlyIter}; #[expect(deprecated)] pub use wgt::VERTEX_STRIDE_ALIGNMENT;