mirror of
https://github.com/bevyengine/bevy
synced 2024-11-26 06:30:19 +00:00
01a3b0e830
# Objective Fixes https://github.com/bevyengine/bevy/issues/14183 ## Solution Reimplement the UI texture atlas slicer using a shader. The problems with #14183 could be fixed more simply by hacking around with the coordinates and scaling but that way is very fragile and might get broken again the next time we make changes to the layout calculations. A shader based solution is more robust, it's impossible for gaps to appear between the image slices with these changes as we're only drawing a single quad. I've not tried any benchmarks yet but it should much more efficient as well, in the worst cases even hundreds or thousands of times faster. Maybe could have used the UiMaterialPipeline. I wrote the shader first and used fat vertices and then realised it wouldn't work that way with a UiMaterial. If it's rewritten it so it puts all the slice geometry in uniform buffer, then it might work? Adding the uniform buffer would probably make the shader more complicated though, so don't know if it's even worth it. Instancing is another alternative. ## Testing The examples are working and it seems to match the old API correctly but I've not used the texture atlas slicing API for anything before, I reviewed the PR but that was back in January. Needs a review by someone who knows the rendering pipeline and wgsl really well because I don't really have any idea what I'm doing.
82 lines
3 KiB
Rust
82 lines
3 KiB
Rust
//! A test to confirm that `bevy` doesn't regress its system ambiguities count when using [`DefaultPlugins`].
|
|
//! This is run in CI.
|
|
//!
|
|
//! Note that because this test requires rendering, it isn't actually an integration test!
|
|
//! Instead, it's secretly an example: you can run this test manually using `cargo run --example ambiguity_detection`.
|
|
|
|
use bevy::{
|
|
ecs::schedule::{InternedScheduleLabel, LogLevel, ScheduleBuildSettings},
|
|
prelude::*,
|
|
utils::HashMap,
|
|
};
|
|
use bevy_render::{pipelined_rendering::RenderExtractApp, RenderApp};
|
|
|
|
fn main() {
|
|
let mut app = App::new();
|
|
app.add_plugins(DefaultPlugins);
|
|
|
|
let sub_app = app.main_mut();
|
|
configure_ambiguity_detection(sub_app);
|
|
let sub_app = app.sub_app_mut(RenderApp);
|
|
configure_ambiguity_detection(sub_app);
|
|
let sub_app = app.sub_app_mut(RenderExtractApp);
|
|
configure_ambiguity_detection(sub_app);
|
|
|
|
app.finish();
|
|
app.cleanup();
|
|
app.update();
|
|
|
|
let main_app_ambiguities = count_ambiguities(app.main());
|
|
assert_eq!(
|
|
main_app_ambiguities.total(),
|
|
// This number *should* be zero.
|
|
// Over time, we are working to reduce the number: your PR should not increase it.
|
|
// If you decrease this by fixing an ambiguity, reduce the number to prevent regressions.
|
|
// See https://github.com/bevyengine/bevy/issues/7386 for progress.
|
|
44,
|
|
"Main app has unexpected ambiguities among the following schedules: \n{:#?}.",
|
|
main_app_ambiguities,
|
|
);
|
|
|
|
// RenderApp is not checked here, because it is not within the App at this point.
|
|
let render_extract_ambiguities = count_ambiguities(app.sub_app(RenderExtractApp));
|
|
assert_eq!(
|
|
render_extract_ambiguities.total(),
|
|
0,
|
|
"RenderExtract app has unexpected ambiguities among the following schedules: \n{:#?}",
|
|
render_extract_ambiguities,
|
|
);
|
|
}
|
|
|
|
/// Contains the number of conflicting systems per schedule.
|
|
#[derive(Debug, Deref, DerefMut)]
|
|
struct AmbiguitiesCount(pub HashMap<InternedScheduleLabel, usize>);
|
|
|
|
impl AmbiguitiesCount {
|
|
fn total(&self) -> usize {
|
|
self.values().sum()
|
|
}
|
|
}
|
|
|
|
fn configure_ambiguity_detection(sub_app: &mut SubApp) {
|
|
let mut schedules = sub_app.world_mut().resource_mut::<Schedules>();
|
|
for (_, schedule) in schedules.iter_mut() {
|
|
schedule.set_build_settings(ScheduleBuildSettings {
|
|
// NOTE: you can change this to `LogLevel::Ignore` to easily see the current number of ambiguities.
|
|
ambiguity_detection: LogLevel::Warn,
|
|
use_shortnames: false,
|
|
..default()
|
|
});
|
|
}
|
|
}
|
|
|
|
/// Returns the number of conflicting systems per schedule.
|
|
fn count_ambiguities(sub_app: &SubApp) -> AmbiguitiesCount {
|
|
let schedules = sub_app.world().resource::<Schedules>();
|
|
let mut ambiguities = HashMap::new();
|
|
for (_, schedule) in schedules.iter() {
|
|
let ambiguities_in_schedule = schedule.graph().conflicting_systems().len();
|
|
ambiguities.insert(schedule.label(), ambiguities_in_schedule);
|
|
}
|
|
AmbiguitiesCount(ambiguities)
|
|
}
|