diff --git a/crates/bevy_core_pipeline/Cargo.toml b/crates/bevy_core_pipeline/Cargo.toml index 59b6e2241955c..d2af8d00b1716 100644 --- a/crates/bevy_core_pipeline/Cargo.toml +++ b/crates/bevy_core_pipeline/Cargo.toml @@ -31,5 +31,5 @@ bevy_math = { path = "../bevy_math", version = "0.11.0-dev" } bevy_utils = { path = "../bevy_utils", version = "0.11.0-dev" } serde = { version = "1", features = ["derive"] } -bitflags = "1.2" +bitflags = "2.3" radsort = "0.1" diff --git a/crates/bevy_pbr/Cargo.toml b/crates/bevy_pbr/Cargo.toml index 9f6cadb767553..7230c59027816 100644 --- a/crates/bevy_pbr/Cargo.toml +++ b/crates/bevy_pbr/Cargo.toml @@ -26,7 +26,7 @@ bevy_window = { path = "../bevy_window", version = "0.11.0-dev" } bevy_derive = { path = "../bevy_derive", version = "0.11.0-dev" } # other -bitflags = "1.2" +bitflags = "2.3" # direct dependency required for derive macro bytemuck = { version = "1", features = ["derive"] } radsort = "0.1" diff --git a/crates/bevy_pbr/src/render/light.rs b/crates/bevy_pbr/src/render/light.rs index 85dacdad9be35..c9308982088d9 100644 --- a/crates/bevy_pbr/src/render/light.rs +++ b/crates/bevy_pbr/src/render/light.rs @@ -829,7 +829,7 @@ pub fn prepare_lights( .xyz() .extend(1.0 / (light.range * light.range)), position_radius: light.transform.translation().extend(light.radius), - flags: flags.bits, + flags: flags.bits(), shadow_depth_bias: light.shadow_depth_bias, shadow_normal_bias: light.shadow_normal_bias, spot_light_tan_angle, @@ -876,7 +876,7 @@ pub fn prepare_lights( color: Vec4::from_slice(&light.color.as_linear_rgba_f32()) * intensity, // direction is negated to be ready for N.L dir_to_light: light.transform.back(), - flags: flags.bits, + flags: flags.bits(), shadow_depth_bias: light.shadow_depth_bias, shadow_normal_bias: light.shadow_normal_bias, num_cascades: num_cascades as u32, diff --git a/crates/bevy_pbr/src/render/mesh.rs b/crates/bevy_pbr/src/render/mesh.rs index f94c75b370c3e..d4a80c55acd32 100644 --- a/crates/bevy_pbr/src/render/mesh.rs +++ b/crates/bevy_pbr/src/render/mesh.rs @@ -181,7 +181,7 @@ pub fn extract_meshes( flags |= MeshFlags::SIGN_DETERMINANT_MODEL_3X3; } let uniform = MeshUniform { - flags: flags.bits, + flags: flags.bits(), transform, previous_transform, inverse_transpose_model: transform.inverse().transpose(), @@ -571,6 +571,7 @@ impl MeshPipeline { } bitflags::bitflags! { + #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] #[repr(transparent)] // NOTE: Apparently quadro drivers support up to 64x MSAA. /// MSAA uses the highest 3 bits for the MSAA log2(sample count) to support up to 128x MSAA. @@ -622,7 +623,7 @@ impl MeshPipelineKey { pub fn from_msaa_samples(msaa_samples: u32) -> Self { let msaa_bits = (msaa_samples.trailing_zeros() & Self::MSAA_MASK_BITS) << Self::MSAA_SHIFT_BITS; - Self::from_bits(msaa_bits).unwrap() + Self::from_bits_retain(msaa_bits) } pub fn from_hdr(hdr: bool) -> Self { @@ -634,19 +635,19 @@ impl MeshPipelineKey { } pub fn msaa_samples(&self) -> u32 { - 1 << ((self.bits >> Self::MSAA_SHIFT_BITS) & Self::MSAA_MASK_BITS) + 1 << ((self.bits() >> Self::MSAA_SHIFT_BITS) & Self::MSAA_MASK_BITS) } pub fn from_primitive_topology(primitive_topology: PrimitiveTopology) -> Self { let primitive_topology_bits = ((primitive_topology as u32) & Self::PRIMITIVE_TOPOLOGY_MASK_BITS) << Self::PRIMITIVE_TOPOLOGY_SHIFT_BITS; - Self::from_bits(primitive_topology_bits).unwrap() + Self::from_bits_retain(primitive_topology_bits) } pub fn primitive_topology(&self) -> PrimitiveTopology { - let primitive_topology_bits = - (self.bits >> Self::PRIMITIVE_TOPOLOGY_SHIFT_BITS) & Self::PRIMITIVE_TOPOLOGY_MASK_BITS; + let primitive_topology_bits = (self.bits() >> Self::PRIMITIVE_TOPOLOGY_SHIFT_BITS) + & Self::PRIMITIVE_TOPOLOGY_MASK_BITS; match primitive_topology_bits { x if x == PrimitiveTopology::PointList as u32 => PrimitiveTopology::PointList, x if x == PrimitiveTopology::LineList as u32 => PrimitiveTopology::LineList, diff --git a/crates/bevy_render/Cargo.toml b/crates/bevy_render/Cargo.toml index a725524184c33..5f08c37252cf2 100644 --- a/crates/bevy_render/Cargo.toml +++ b/crates/bevy_render/Cargo.toml @@ -62,7 +62,7 @@ wgpu-hal = "0.16.0" codespan-reporting = "0.11.0" naga = { version = "0.12.0", features = ["wgsl-in"] } serde = { version = "1", features = ["derive"] } -bitflags = "1.2.1" +bitflags = "2.3" smallvec = { version = "1.6", features = ["union", "const_generics"] } once_cell = "1.4.1" # TODO: replace once_cell with std equivalent if/when this lands: https://github.com/rust-lang/rfcs/pull/2788 downcast-rs = "1.2.0" diff --git a/crates/bevy_render/src/texture/image.rs b/crates/bevy_render/src/texture/image.rs index bf3396e327270..03cc6d7402b9e 100644 --- a/crates/bevy_render/src/texture/image.rs +++ b/crates/bevy_render/src/texture/image.rs @@ -555,7 +555,7 @@ impl RenderAsset for Image { } bitflags::bitflags! { - #[derive(Default)] + #[derive(Default, Clone, Copy, Eq, PartialEq, Debug)] #[repr(transparent)] pub struct CompressedImageFormats: u32 { const NONE = 0; diff --git a/crates/bevy_render/src/view/visibility/mod.rs b/crates/bevy_render/src/view/visibility/mod.rs index 9521c1567e5d5..002e5db3b68e7 100644 --- a/crates/bevy_render/src/view/visibility/mod.rs +++ b/crates/bevy_render/src/view/visibility/mod.rs @@ -63,12 +63,14 @@ impl std::cmp::PartialEq<&Visibility> for Visibility { } bitflags::bitflags! { - #[derive(Reflect)] + #[derive(Clone, Debug, Eq, PartialEq)] pub(super) struct ComputedVisibilityFlags: u8 { const VISIBLE_IN_VIEW = 1 << 0; const VISIBLE_IN_HIERARCHY = 1 << 1; } } +bevy_reflect::impl_reflect_value!(ComputedVisibilityFlags); +bevy_reflect::impl_from_reflect_value!(ComputedVisibilityFlags); /// Algorithmically-computed indication of whether an entity is visible and should be extracted for rendering #[derive(Component, Clone, Reflect, Debug, Eq, PartialEq)] @@ -95,7 +97,7 @@ impl ComputedVisibility { /// Reading it during [`Update`](bevy_app::Update) will yield the value from the previous frame. #[inline] pub fn is_visible(&self) -> bool { - self.flags.bits == ComputedVisibilityFlags::all().bits + self.flags.bits() == ComputedVisibilityFlags::all().bits() } /// Whether this entity is visible in the entity hierarchy, which is determined by the [`Visibility`] component. diff --git a/crates/bevy_sprite/Cargo.toml b/crates/bevy_sprite/Cargo.toml index e2be37175d1da..c3c522b10b9d4 100644 --- a/crates/bevy_sprite/Cargo.toml +++ b/crates/bevy_sprite/Cargo.toml @@ -30,4 +30,4 @@ fixedbitset = "0.4" guillotiere = "0.6.0" thiserror = "1.0" rectangle-pack = "0.4" -bitflags = "1.2" +bitflags = "2.3" diff --git a/crates/bevy_sprite/src/mesh2d/mesh.rs b/crates/bevy_sprite/src/mesh2d/mesh.rs index 93c634f18a109..6e1ab779cc331 100644 --- a/crates/bevy_sprite/src/mesh2d/mesh.rs +++ b/crates/bevy_sprite/src/mesh2d/mesh.rs @@ -152,7 +152,7 @@ pub fn extract_mesh2d( ( Mesh2dHandle(handle.0.clone_weak()), Mesh2dUniform { - flags: MeshFlags::empty().bits, + flags: MeshFlags::empty().bits(), transform, inverse_transpose_model: transform.inverse().transpose(), }, @@ -283,6 +283,7 @@ impl Mesh2dPipeline { } bitflags::bitflags! { + #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] #[repr(transparent)] // NOTE: Apparently quadro drivers support up to 64x MSAA. // MSAA uses the highest 3 bits for the MSAA log2(sample count) to support up to 128x MSAA. @@ -318,7 +319,7 @@ impl Mesh2dPipelineKey { pub fn from_msaa_samples(msaa_samples: u32) -> Self { let msaa_bits = (msaa_samples.trailing_zeros() & Self::MSAA_MASK_BITS) << Self::MSAA_SHIFT_BITS; - Self::from_bits(msaa_bits).unwrap() + Self::from_bits_retain(msaa_bits) } pub fn from_hdr(hdr: bool) -> Self { @@ -330,19 +331,19 @@ impl Mesh2dPipelineKey { } pub fn msaa_samples(&self) -> u32 { - 1 << ((self.bits >> Self::MSAA_SHIFT_BITS) & Self::MSAA_MASK_BITS) + 1 << ((self.bits() >> Self::MSAA_SHIFT_BITS) & Self::MSAA_MASK_BITS) } pub fn from_primitive_topology(primitive_topology: PrimitiveTopology) -> Self { let primitive_topology_bits = ((primitive_topology as u32) & Self::PRIMITIVE_TOPOLOGY_MASK_BITS) << Self::PRIMITIVE_TOPOLOGY_SHIFT_BITS; - Self::from_bits(primitive_topology_bits).unwrap() + Self::from_bits_retain(primitive_topology_bits) } pub fn primitive_topology(&self) -> PrimitiveTopology { - let primitive_topology_bits = - (self.bits >> Self::PRIMITIVE_TOPOLOGY_SHIFT_BITS) & Self::PRIMITIVE_TOPOLOGY_MASK_BITS; + let primitive_topology_bits = (self.bits() >> Self::PRIMITIVE_TOPOLOGY_SHIFT_BITS) + & Self::PRIMITIVE_TOPOLOGY_MASK_BITS; match primitive_topology_bits { x if x == PrimitiveTopology::PointList as u32 => PrimitiveTopology::PointList, x if x == PrimitiveTopology::LineList as u32 => PrimitiveTopology::LineList, diff --git a/crates/bevy_sprite/src/render/mod.rs b/crates/bevy_sprite/src/render/mod.rs index 725aab3234df0..8bce8ac998ba4 100644 --- a/crates/bevy_sprite/src/render/mod.rs +++ b/crates/bevy_sprite/src/render/mod.rs @@ -137,6 +137,7 @@ impl FromWorld for SpritePipeline { } bitflags::bitflags! { + #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] #[repr(transparent)] // NOTE: Apparently quadro drivers support up to 64x MSAA. // MSAA uses the highest 3 bits for the MSAA log2(sample count) to support up to 128x MSAA. @@ -170,12 +171,12 @@ impl SpritePipelineKey { pub const fn from_msaa_samples(msaa_samples: u32) -> Self { let msaa_bits = (msaa_samples.trailing_zeros() & Self::MSAA_MASK_BITS) << Self::MSAA_SHIFT_BITS; - Self::from_bits_truncate(msaa_bits) + Self::from_bits_retain(msaa_bits) } #[inline] pub const fn msaa_samples(&self) -> u32 { - 1 << ((self.bits >> Self::MSAA_SHIFT_BITS) & Self::MSAA_MASK_BITS) + 1 << ((self.bits() >> Self::MSAA_SHIFT_BITS) & Self::MSAA_MASK_BITS) } #[inline] diff --git a/tools/build-templated-pages/Cargo.toml b/tools/build-templated-pages/Cargo.toml index e0406048acc44..5d0bee2a6aafa 100644 --- a/tools/build-templated-pages/Cargo.toml +++ b/tools/build-templated-pages/Cargo.toml @@ -10,4 +10,4 @@ license = "MIT OR Apache-2.0" toml_edit = "0.19" tera = "1.15" serde = { version = "1.0", features = [ "derive" ] } -bitflags = "1.3" +bitflags = "2.3" diff --git a/tools/build-templated-pages/src/main.rs b/tools/build-templated-pages/src/main.rs index 435cc3368703b..f0f9a95c21066 100644 --- a/tools/build-templated-pages/src/main.rs +++ b/tools/build-templated-pages/src/main.rs @@ -4,6 +4,7 @@ mod examples; mod features; bitflags! { + #[derive(Clone, Copy, Debug, PartialEq, Eq)] struct Command: u32 { const CHECK_MISSING = 0b00000001; const UPDATE = 0b00000010; @@ -11,6 +12,7 @@ bitflags! { } bitflags! { + #[derive(Clone, Copy, Debug, PartialEq, Eq)] struct Target: u32 { const EXAMPLES = 0b00000001; const FEATURES = 0b00000010; diff --git a/tools/ci/Cargo.toml b/tools/ci/Cargo.toml index 941bca58efc5d..e6ca164b1fb6f 100644 --- a/tools/ci/Cargo.toml +++ b/tools/ci/Cargo.toml @@ -8,4 +8,4 @@ license = "MIT OR Apache-2.0" [dependencies] xshell = "0.2" -bitflags = "1.3" +bitflags = "2.3" diff --git a/tools/ci/src/main.rs b/tools/ci/src/main.rs index c0105ed54312e..b4847d2bcc8fb 100644 --- a/tools/ci/src/main.rs +++ b/tools/ci/src/main.rs @@ -3,6 +3,7 @@ use xshell::{cmd, Shell}; use bitflags::bitflags; bitflags! { + #[derive(Clone, Copy, Debug, PartialEq, Eq)] struct Check: u32 { const FORMAT = 0b00000001; const CLIPPY = 0b00000010;