@@ -9,7 +9,20 @@ use crate::{Texel, TexelBuffer};
99
1010/// A container of allocated bytes, parameterized over the layout.
1111///
12+ /// This is a synchronized, shared equivalent to [`Image`][`crate::image::Image`]. That is the
13+ /// buffer of bytes of this container is shared between clones of this value and potentially
14+ /// between threads. In particular the same buffer may be owned and viewed with different layouts
15+ /// and modified concurrently. The guarantee, however, is merely that concurrent modification is
16+ /// free of undefined data races. There is no locking, implied synchronization, or ordering
17+ /// guarantees between edits except when you can modify disjoint parts of the buffer.
18+ ///
1219/// ## Differences to owned Image
20+ ///
21+ /// Comparing values of this type is possible, but requires calling the method [`Self::compare`] to
22+ /// create a comparator. This is because comparing is inherently racing against modifications made
23+ /// on other threads. While the implementation prevents any unsound *data races* there is no
24+ /// specific meaning to any of its outcomes unless the caller ensure synchronization in some other
25+ /// manner.
1326#[ derive( Clone ) ]
1427pub struct AtomicImage < Layout = Bytes > {
1528 inner : RawImage < AtomicBuffer , Layout > ,
@@ -18,7 +31,8 @@ pub struct AtomicImage<Layout = Bytes> {
1831/// A partial view of an atomic image.
1932///
2033/// Note that this requires its underlying buffer to be highly aligned! For that reason it is not
21- /// possible to take a reference at an arbitrary number of bytes.
34+ /// possible to take a reference at an arbitrary number of bytes. Values of this type are created
35+ /// by calling [`AtomicImage::as_ref`] or [`AtomicImage::checked_to_ref`].
2236#[ derive( Clone , PartialEq , Eq ) ]
2337pub struct AtomicImageRef < ' buf , Layout = & ' buf Bytes > {
2438 inner : RawImage < & ' buf atomic_buf , Layout > ,
@@ -156,6 +170,26 @@ impl<L> AtomicImage<L> {
156170 self . inner . fits ( layout)
157171 }
158172
173+ /// Check if two images refer to the same buffer.
174+ pub fn ptr_eq ( & self , other : & Self ) -> bool {
175+ AtomicBuffer :: ptr_eq ( self . inner . get ( ) , other. inner . get ( ) )
176+ }
177+
178+ /// Create a comparator to another image.
179+ ///
180+ /// Note that comparing is inherently racing against modifications made on other threads. While
181+ /// the implementation prevents any unsound *data races* there is no specific meaning to any of
182+ /// its outcomes unless the caller ensure synchronization in some other manner.
183+ ///
184+ /// You can also compare the allocation with [`Self::ptr_eq`] or ignore the layout and compare
185+ /// buffer contents with [`Self::as_capacity_atomic_buf`].
186+ pub fn compare ( & self ) -> impl core:: cmp:: Eq + core:: cmp:: PartialEq + ' _
187+ where
188+ L : core:: cmp:: Eq ,
189+ {
190+ ( self . inner . layout ( ) , self . inner . get ( ) )
191+ }
192+
159193 /// Get a reference to the aligned unstructured bytes of the image.
160194 ///
161195 /// Note that this may return more bytes than required for the specific layout for various
0 commit comments