Skip to content

Commit

Permalink
update bitflags to 2.3 (#8728)
Browse files Browse the repository at this point in the history
# Objective

- Update bitflags to 2.3
  • Loading branch information
mockersf authored Jun 1, 2023
1 parent bad754a commit bea7fd1
Show file tree
Hide file tree
Showing 14 changed files with 33 additions and 25 deletions.
2 changes: 1 addition & 1 deletion crates/bevy_core_pipeline/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
2 changes: 1 addition & 1 deletion crates/bevy_pbr/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
4 changes: 2 additions & 2 deletions crates/bevy_pbr/src/render/light.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
13 changes: 7 additions & 6 deletions crates/bevy_pbr/src/render/mesh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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 {
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_render/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_render/src/texture/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 4 additions & 2 deletions crates/bevy_render/src/view/visibility/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand All @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_sprite/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ fixedbitset = "0.4"
guillotiere = "0.6.0"
thiserror = "1.0"
rectangle-pack = "0.4"
bitflags = "1.2"
bitflags = "2.3"
13 changes: 7 additions & 6 deletions crates/bevy_sprite/src/mesh2d/mesh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
},
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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 {
Expand All @@ -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,
Expand Down
5 changes: 3 additions & 2 deletions crates/bevy_sprite/src/render/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion tools/build-templated-pages/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
2 changes: 2 additions & 0 deletions tools/build-templated-pages/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ mod examples;
mod features;

bitflags! {
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
struct Command: u32 {
const CHECK_MISSING = 0b00000001;
const UPDATE = 0b00000010;
}
}

bitflags! {
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
struct Target: u32 {
const EXAMPLES = 0b00000001;
const FEATURES = 0b00000010;
Expand Down
2 changes: 1 addition & 1 deletion tools/ci/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ license = "MIT OR Apache-2.0"

[dependencies]
xshell = "0.2"
bitflags = "1.3"
bitflags = "2.3"
1 change: 1 addition & 0 deletions tools/ci/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit bea7fd1

Please sign in to comment.