Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade bevy to 0.15, purge bevy_mod_picking, github toolchain update. #86

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
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 .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:

- uses: dtolnay/rust-toolchain@master
with:
toolchain: 1.72.0
toolchain: 1.83.0

- name: install dependencies
run: sudo apt-get update; sudo apt-get install --no-install-recommends libasound2-dev libudev-dev
Expand Down
59 changes: 29 additions & 30 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,57 +3,57 @@ resolver = "2"
members = ["crates/*", "examples/*"]

[workspace.package]
version = "0.4.0"
rust-version = "1.78.0"
version = "0.5.0"
rust-version = "1.82.0"
edition = "2021"
license = "MIT OR Apache-2.0"
homepage = "https://github.com/urholaukkarinen/transform-gizmo"
repository = "https://github.com/urholaukkarinen/transform-gizmo"
authors = ["Urho Laukkarinen <[email protected]>"]

[workspace.dependencies]
transform-gizmo = { version = "0.4.0", path = "crates/transform-gizmo" }
transform-gizmo-egui = { version = "0.4.0", path = "crates/transform-gizmo-egui" }
transform-gizmo-bevy = { version = "0.4.0", path = "crates/transform-gizmo-bevy" }
transform-gizmo = { version = "0.5.0", path = "crates/transform-gizmo" }
transform-gizmo-egui = { version = "0.5.0", path = "crates/transform-gizmo-egui" }
transform-gizmo-bevy = { version = "0.5.0", path = "crates/transform-gizmo-bevy" }

egui = "0.29"
eframe = "0.29"
emath = "0.29"
epaint = "0.29"
ecolor = "0.29"
egui = "0.30"
eframe = "0.30"
emath = "0.30"
epaint = "0.30"
ecolor = "0.30"
glam = { version = "0.29.1", features = ["mint"] }
mint = "0.5"
enum_dispatch = "0.3.12"
ahash = "0.8.7"
enumset = "1.1.3"
bytemuck = "1.5"
uuid = "1.1"
bevy = "0.14"
bevy = "0.15"

bevy_app = { version = "0.14", default-features = false }
bevy_core = { version = "0.14", default-features = false }
bevy_core_pipeline = { version = "0.14", default-features = false }
bevy_reflect = { version = "0.14", default-features = false }
bevy_math = { version = "0.14", features = ["mint"], default-features = false }
bevy_render = { version = "0.14", default-features = false }
bevy_input = { version = "0.14", default-features = false }
bevy_asset = { version = "0.14", default-features = false }
bevy_utils = { version = "0.14", default-features = false }
bevy_pbr = { version = "0.14", default-features = false }
bevy_ecs = { version = "0.14", default-features = false }
bevy_log = { version = "0.14", default-features = false }
bevy_window = { version = "0.14", default-features = false }
bevy_transform = { version = "0.14", default-features = false }
bevy_app = { version = "0.15", default-features = false }
bevy_core = { version = "0.15", default-features = false }
bevy_core_pipeline = { version = "0.15", default-features = false }
bevy_reflect = { version = "0.15", default-features = false }
bevy_math = { version = "0.15", features = ["mint"], default-features = false }
bevy_render = { version = "0.15", default-features = false }
bevy_input = { version = "0.15", default-features = false }
bevy_asset = { version = "0.15", default-features = false }
bevy_utils = { version = "0.15", default-features = false }
bevy_pbr = { version = "0.15", default-features = false }
bevy_ecs = { version = "0.15", default-features = false }
bevy_log = { version = "0.15", default-features = false }
bevy_window = { version = "0.15", default-features = false }
bevy_transform = { version = "0.15", default-features = false }
bevy_derive = { version = "0.15", default-features = false }
bevy_image = { version = "0.15", default-features = false }
bevy_picking = {version = "0.15", default-features = false}

[profile.release]
opt-level = "s"
panic = "abort"

[workspace.lints.rust]
elided_lifetimes_in_paths = "allow"
future_incompatible = "deny"
nonstandard_style = "deny"
rust_2018_idioms = "warn"
rust_2021_prelude_collisions = "deny"
semicolon_in_expressions_from_macros = "deny"
trivial_numeric_casts = "deny"
Expand All @@ -64,7 +64,6 @@ unused_lifetimes = "deny"
unsafe_code = "deny"

[workspace.lints.clippy]
all = "deny"
as_ptr_cast_mut = "deny"
await_holding_lock = "deny"
bool_to_int_with_if = "deny"
Expand Down Expand Up @@ -133,7 +132,7 @@ match_same_arms = "deny"
match_wild_err_arm = "deny"
match_wildcard_for_single_variants = "deny"
mem_forget = "deny"
mismatched_target_os = "deny"
unexpected_cfgs = "deny"
mismatching_type_param_order = "deny"
missing_enforced_import_renames = "deny"
missing_safety_doc = "deny"
Expand Down
9 changes: 6 additions & 3 deletions crates/transform-gizmo-bevy/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "transform-gizmo-bevy"
description = "bevy integration for transform-gizmo"
version.workspace = true
rust-version = "1.79.0"
rust-version = "1.82.0"
edition.workspace = true
license.workspace = true
homepage.workspace = true
Expand All @@ -27,6 +27,7 @@ bevy_core.workspace = true
bevy_core_pipeline.workspace = true
bevy_reflect.workspace = true
bevy_math.workspace = true
bevy_picking.workspace = true
bevy_render.workspace = true
bevy_input.workspace = true
bevy_asset.workspace = true
Expand All @@ -36,11 +37,13 @@ bevy_ecs.workspace = true
bevy_log.workspace = true
bevy_window.workspace = true
bevy_transform.workspace = true
bevy_derive.workspace = true
bevy_image.workspace = true
bytemuck.workspace = true
uuid.workspace = true

[dev-dependencies]
bevy = "0.14"
bevy = "0.15"

[lints]
workspace = true
workspace = true
26 changes: 10 additions & 16 deletions crates/transform-gizmo-bevy/examples/bevy_minimal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,32 +19,26 @@ fn setup(
) {
// camera
commands.spawn((
Camera3dBundle {
transform: Transform::from_translation(Vec3::new(1.0, 3.0, -5.0))
.looking_at(Vec3::ZERO, Vec3::Y),
..default()
},
Camera3d::default(),
Transform::from_translation(Vec3::new(1.0, 3.0, -5.0)).looking_at(Vec3::ZERO, Vec3::Y),
Msaa::Sample2,
GizmoCamera,
));

// cube
commands.spawn((
PbrBundle {
mesh: meshes.add(Cuboid::new(1.0, 1.0, 1.0)),
material: materials.add(Color::from(LIME)),
transform: Transform::from_translation(Vec3::new(0.0, 0.0, 0.0)),
..default()
},
Mesh3d(meshes.add(Cuboid::new(1.0, 1.0, 1.0))),
MeshMaterial3d(materials.add(Color::from(LIME))),
Transform::from_translation(Vec3::new(0.0, 0.0, 0.0)),
GizmoTarget::default(),
));

// light
commands.spawn(PointLightBundle {
point_light: PointLight {
commands.spawn((
PointLight {
shadows_enabled: true,
..default()
},
transform: Transform::from_xyz(4.0, 8.0, 4.0),
..default()
});
Transform::from_xyz(4.0, 8.0, 4.0),
));
}
4 changes: 3 additions & 1 deletion crates/transform-gizmo-bevy/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,9 @@ fn draw_gizmos(
if is_new_asset {
let asset = draw_data_assets.add(bevy_draw_data);

draw_data_handles.handles.insert(*gizmo_uuid, asset.clone());
draw_data_handles
.handles
.insert(*gizmo_uuid, asset.clone().into());
}
}
}
Expand Down
73 changes: 57 additions & 16 deletions crates/transform-gizmo-bevy/src/render.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
use bevy_app::{App, Plugin};
use bevy_asset::{load_internal_asset, Asset, Handle};
use bevy_asset::{load_internal_asset, Asset, AssetId, Handle};
use bevy_core_pipeline::core_3d::{Transparent3d, CORE_3D_DEPTH_FORMAT};
use bevy_core_pipeline::prepass::{
DeferredPrepass, DepthPrepass, MotionVectorPrepass, NormalPrepass,
};
use bevy_derive::{Deref, DerefMut};
use bevy_ecs::prelude::*;
use bevy_ecs::query::ROQueryItem;
use bevy_ecs::system::lifetimeless::{Read, SRes};
use bevy_ecs::system::SystemParamItem;
use bevy_image::BevyDefault as _;
use bevy_pbr::{MeshPipeline, MeshPipelineKey, SetMeshViewBindGroup};
use bevy_reflect::TypePath;
use bevy_reflect::{Reflect, TypePath};
use bevy_render::extract_component::ExtractComponent;
use bevy_render::mesh::PrimitiveTopology;
use bevy_render::prelude::*;
use bevy_render::render_asset::{
Expand All @@ -28,13 +31,14 @@ use bevy_render::render_resource::{
VertexAttribute, VertexBufferLayout, VertexFormat, VertexState, VertexStepMode,
};
use bevy_render::renderer::RenderDevice;
use bevy_render::texture::BevyDefault;
use bevy_render::view::{ExtractedView, RenderLayers, ViewTarget};
use bevy_render::{Extract, Render, RenderApp, RenderSet};
use bevy_utils::{HashMap, HashSet};
use bytemuck::cast_slice;
use uuid::Uuid;

use crate::GizmoCamera;

const GIZMO_SHADER_HANDLE: Handle<Shader> = Handle::weak_from_u128(7414812681337026784);

pub(crate) struct TransformGizmoRenderPlugin;
Expand Down Expand Up @@ -74,7 +78,30 @@ impl Plugin for TransformGizmoRenderPlugin {

#[derive(Resource, Default)]
pub(crate) struct DrawDataHandles {
pub(crate) handles: HashMap<Uuid, Handle<GizmoDrawData>>,
pub(crate) handles: HashMap<Uuid, GizmoDrawDataHandle>,
}

#[derive(
Component, Default, Clone, Debug, Deref, DerefMut, Reflect, PartialEq, Eq, ExtractComponent,
)]
#[reflect(Component)]
pub(crate) struct GizmoDrawDataHandle(pub(crate) Handle<GizmoDrawData>);

impl From<Handle<GizmoDrawData>> for GizmoDrawDataHandle {
fn from(handle: Handle<GizmoDrawData>) -> Self {
Self(handle)
}
}

impl From<GizmoDrawDataHandle> for AssetId<GizmoDrawData> {
fn from(handle: GizmoDrawDataHandle) -> Self {
handle.0.id()
}
}
impl From<&GizmoDrawDataHandle> for AssetId<GizmoDrawData> {
fn from(handle: &GizmoDrawDataHandle) -> Self {
handle.0.id()
}
}

fn extract_gizmo_data(mut commands: Commands, handles: Extract<Res<DrawDataHandles>>) {
Expand All @@ -85,7 +112,7 @@ fn extract_gizmo_data(mut commands: Commands, handles: Extract<Res<DrawDataHandl
.collect::<HashSet<_>>();

for handle in handle_weak_refs {
commands.spawn((handle,));
commands.spawn(GizmoDrawDataHandle(handle));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bevy 0.15 switched to a retained rendering world, meaning these entities never get despawned. Leaving the app running with the gizmo visible in the window will cause render entities to build up in the render world, creating more and more draw calls per frame until the app slows to a halt.

Without re-architecting this portion of the library to utilize retained entities, a simple fix is to also insert the TemporaryRenderEntity component. This will cause the entity to be despawned at the end of each frame.

commands.spawn((GizmoDrawDataHandle(handle), TemporaryRenderEntity));

}
}

Expand Down Expand Up @@ -146,7 +173,7 @@ struct DrawTransformGizmo;

impl<P: PhaseItem> RenderCommand<P> for DrawTransformGizmo {
type ViewQuery = ();
type ItemQuery = Read<Handle<GizmoDrawData>>;
type ItemQuery = Read<GizmoDrawDataHandle>;
type Param = SRes<RenderAssets<GizmoBuffers>>;

#[inline]
Expand All @@ -158,13 +185,17 @@ impl<P: PhaseItem> RenderCommand<P> for DrawTransformGizmo {
pass: &mut TrackedRenderPass<'w>,
) -> RenderCommandResult {
let Some(handle) = handle else {
return RenderCommandResult::Failure;
return RenderCommandResult::Failure("No GizmoDrawDataHandle component found");
};

let Some(gizmo) = gizmos.into_inner().get(handle) else {
return RenderCommandResult::Failure;
return RenderCommandResult::Failure("No GizmoDrawDataHandle inner found");
};

if gizmo.index_buffer.size() == 0 {
return RenderCommandResult::Failure("gizmo.index_buffer is empty");
}

pass.set_index_buffer(gizmo.index_buffer.slice(..), 0, IndexFormat::Uint32);
pass.set_vertex_buffer(0, gizmo.position_buffer.slice(..));
pass.set_vertex_buffer(1, gizmo.color_buffer.slice(..));
Expand Down Expand Up @@ -199,8 +230,9 @@ impl SpecializedRenderPipeline for TransformGizmoPipeline {

fn specialize(&self, key: Self::Key) -> RenderPipelineDescriptor {
let mut shader_defs = vec![
#[cfg(feature = "webgl")]
"SIXTEEN_BYTE_ALIGNMENT".into(),
// TODO: When is this flag actually used?
// #[cfg(feature = "webgl")]
// "SIXTEEN_BYTE_ALIGNMENT".into(),
];

if key.perspective {
Expand All @@ -220,6 +252,7 @@ impl SpecializedRenderPipeline for TransformGizmoPipeline {

RenderPipelineDescriptor {
label: Some("TransformGizmo Pipeline".into()),
zero_initialize_workgroup_memory: true, // ?
vertex: VertexState {
shader: GIZMO_SHADER_HANDLE,
entry_point: "vertex".into(),
Expand Down Expand Up @@ -286,12 +319,13 @@ fn queue_transform_gizmos(
pipeline: Res<TransformGizmoPipeline>,
mut pipelines: ResMut<SpecializedRenderPipelines<TransformGizmoPipeline>>,
pipeline_cache: Res<PipelineCache>,
msaa: Res<Msaa>,
transform_gizmos: Query<(Entity, &Handle<GizmoDrawData>)>,
msaa_q: Query<Option<&Msaa>, With<GizmoCamera>>,
transform_gizmos: Query<(Entity, &GizmoDrawDataHandle)>,
transform_gizmo_assets: Res<RenderAssets<GizmoBuffers>>,
mut views: Query<(
Entity,
&ExtractedView,
Option<&Msaa>,
Option<&RenderLayers>,
(
Has<NormalPrepass>,
Expand All @@ -303,10 +337,11 @@ fn queue_transform_gizmos(
mut transparent_render_phases: ResMut<ViewSortedRenderPhases<Transparent3d>>,
) {
let draw_function = draw_functions.read().get_id::<DrawGizmo>().unwrap();

let camera_msaa = msaa_q.get_single().ok().flatten();
for (
view_entity,
view,
entity_msaa,
_render_layers,
(normal_prepass, depth_prepass, motion_vector_prepass, deferred_prepass),
) in &mut views
Expand All @@ -315,7 +350,13 @@ fn queue_transform_gizmos(
continue;
};

let mut view_key = MeshPipelineKey::from_msaa_samples(msaa.samples())
// entity_msaa > camera_msaa > default
let msaa_sample_count = entity_msaa.map_or(
camera_msaa.unwrap_or(&Msaa::default()).samples(),
Msaa::samples,
);

let mut view_key = MeshPipelineKey::from_msaa_samples(msaa_sample_count)
| MeshPipelineKey::from_hdr(view.hdr);

if normal_prepass {
Expand All @@ -335,7 +376,7 @@ fn queue_transform_gizmos(
}

for (entity, handle) in &transform_gizmos {
let Some(_) = transform_gizmo_assets.get(handle.id()) else {
let Some(_) = transform_gizmo_assets.get(handle.0.id()) else {
continue;
};

Expand All @@ -349,7 +390,7 @@ fn queue_transform_gizmos(
);

transparent_phase.add(Transparent3d {
entity,
entity: (entity, view_entity.into()), // TODO: ???
draw_function,
pipeline,
distance: 0.,
Expand Down
2 changes: 1 addition & 1 deletion crates/transform-gizmo/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ impl Default for GizmoVisuals {
z_color: Color32::from_rgb(0, 125, 255),
s_color: Color32::from_rgb(255, 255, 255),
inactive_alpha: 0.7,
highlight_alpha: 1.0,
highlight_alpha: 0.1,
highlight_color: None,
stroke_width: 4.0,
gizmo_size: 75.0,
Expand Down
Loading