Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/bevy_render/src/render_resource/bind_group.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use crate::{
define_atomic_id,
render_asset::RenderAssets,
render_resource::{BindGroupLayout, Buffer, PipelineCache, Sampler, TextureView},
renderer::{RenderDevice, WgpuWrapper},
Expand All @@ -9,6 +8,7 @@ use bevy_derive::{Deref, DerefMut};
use bevy_ecs::system::{SystemParam, SystemParamItem};
use bevy_render::render_resource::BindGroupLayoutDescriptor;
pub use bevy_render_macros::AsBindGroup;
use bevy_utils::define_atomic_id;
use core::ops::Deref;
use encase::ShaderType;
use thiserror::Error;
Expand Down
3 changes: 2 additions & 1 deletion crates/bevy_render/src/render_resource/bind_group_layout.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::{define_atomic_id, renderer::WgpuWrapper};
use crate::renderer::WgpuWrapper;
use bevy_utils::define_atomic_id;
use core::ops::Deref;

define_atomic_id!(BindGroupLayoutId);
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_render/src/render_resource/buffer.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::define_atomic_id;
use crate::renderer::WgpuWrapper;
use bevy_utils::define_atomic_id;
use core::ops::{Deref, RangeBounds};

define_atomic_id!(BufferId);
Expand Down
1 change: 0 additions & 1 deletion crates/bevy_render/src/render_resource/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ mod gpu_array_buffer;
mod pipeline;
mod pipeline_cache;
mod pipeline_specializer;
pub mod resource_macros;
mod specializer;
mod storage_buffer;
mod texture;
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_render/src/render_resource/pipeline.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use crate::define_atomic_id;
use crate::renderer::WgpuWrapper;
use alloc::borrow::Cow;
use bevy_asset::Handle;
use bevy_mesh::VertexBufferLayout;
use bevy_shader::{Shader, ShaderDefVal};
use bevy_utils::define_atomic_id;
use core::iter;
use core::ops::Deref;
use thiserror::Error;
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_render/src/render_resource/texture.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::define_atomic_id;
use crate::renderer::WgpuWrapper;
use bevy_derive::{Deref, DerefMut};
use bevy_ecs::resource::Resource;
use bevy_utils::define_atomic_id;
use core::ops::Deref;

define_atomic_id!(TextureId);
Expand Down
1 change: 1 addition & 0 deletions crates/bevy_shader/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ keywords = ["bevy", "shader"]
bevy_asset = { path = "../bevy_asset", version = "0.18.0-dev" }
bevy_reflect = { path = "../bevy_reflect", version = "0.18.0-dev" }
bevy_platform = { path = "../bevy_platform", version = "0.18.0-dev" }
bevy_utils = { path = "../bevy_utils", version = "0.18.0-dev" }

# other
wgpu-types = { version = "27", default-features = false }
Expand Down
30 changes: 2 additions & 28 deletions crates/bevy_shader/src/shader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,10 @@ use super::ShaderDefVal;
use alloc::borrow::Cow;
use bevy_asset::{io::Reader, Asset, AssetLoader, AssetPath, Handle, LoadContext};
use bevy_reflect::TypePath;
use core::{marker::Copy, num::NonZero};
use bevy_utils::define_atomic_id;
use thiserror::Error;

#[derive(Copy, Clone, Hash, Eq, PartialEq, PartialOrd, Ord, Debug)]
pub struct ShaderId(NonZero<u32>);

impl ShaderId {
#[expect(
clippy::new_without_default,
reason = "Implementing the `Default` trait on atomic IDs would imply that two `<AtomicIdType>::default()` equal each other. By only implementing `new()`, we indicate that each atomic ID created will be unique."
)]
pub fn new() -> Self {
use core::sync::atomic::{AtomicU32, Ordering};
static COUNTER: AtomicU32 = AtomicU32::new(1);
let counter = COUNTER.fetch_add(1, Ordering::Relaxed);
Self(NonZero::<u32>::new(counter).unwrap_or_else(|| {
panic!("The system ran out of unique `{}`s.", stringify!(ShaderId));
}))
}
}
impl From<ShaderId> for NonZero<u32> {
fn from(value: ShaderId) -> Self {
value.0
}
}
impl From<NonZero<u32>> for ShaderId {
fn from(value: NonZero<u32>) -> Self {
Self(value)
}
}
define_atomic_id!(ShaderId);

#[derive(Error, Debug)]
pub enum ShaderReflectError {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/// Defines an id type which guarantees global uniqueness via atomics on a static global.
#[macro_export]
macro_rules! define_atomic_id {
($atomic_id_type:ident) => {
Expand Down
1 change: 1 addition & 0 deletions crates/bevy_utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ pub mod prelude {
pub use disqualified::ShortName;
}

mod atomic_id;
mod debug_info;
mod default;
mod once;
Expand Down
6 changes: 6 additions & 0 deletions release-content/migration-guides/define_atomic_id.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
title: "`define_atomic_id` now lives in `bevy_utils`"
pull_requests: [22417]
---

`define_atomic_id` was moved out of `bevy_render` and into `bevy_utils`. If you were using `bevy::render::define_atomic_id`, you can update to `bevy::utils::define_atomic_id`.