From e66a61bc623224b7f0b621bd5c6576cb836eab21 Mon Sep 17 00:00:00 2001 From: james7132 Date: Fri, 9 Feb 2024 23:51:07 -0800 Subject: [PATCH] Doc comments and use-import cleanup --- crates/bevy_pbr/src/material.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/crates/bevy_pbr/src/material.rs b/crates/bevy_pbr/src/material.rs index c614b7ba4f561..289a8ebd23743 100644 --- a/crates/bevy_pbr/src/material.rs +++ b/crates/bevy_pbr/src/material.rs @@ -796,19 +796,29 @@ pub struct PreparedMaterial { #[derive(Component, Clone, Copy, Default, PartialEq, Eq, Deref, DerefMut)] pub struct MaterialBindGroupId(Option); +/// An atomic version of [`MaterialBindGroup`] that can be read from and written to +/// safely from multiple threads. #[derive(Default)] pub struct AtomicMaterialBindGroupId(AtomicU32); impl AtomicMaterialBindGroupId { + /// Stores a value atomically. Uses [`Ordering::Relaxed`] so there is zero guarentee of ordering + /// relative to other operations. + /// + /// See also: [`AtomicU32::store`]. pub fn set(&self, id: MaterialBindGroupId) { let id = if let Some(id) = id.0 { - core::num::NonZeroU32::from(id).get() + NonZeroU32::from(id).get() } else { 0 }; self.0.store(id, Ordering::Relaxed); } + /// Loads a value atomically. Uses [`Ordering::Relaxed`] so there is zero guarentee of ordering + /// relative to other operations. + /// + /// See also: [`AtomicU32::load`]. pub fn get(&self) -> MaterialBindGroupId { MaterialBindGroupId(NonZeroU32::new(self.0.load(Ordering::Relaxed)).map(BindGroupId::from)) }