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

GLTF rendering is no longer predictable after 0.13 #12066

Closed
Shatur opened this issue Feb 23, 2024 · 10 comments
Closed

GLTF rendering is no longer predictable after 0.13 #12066

Shatur opened this issue Feb 23, 2024 · 10 comments
Labels
A-Rendering Drawing game state to the screen C-Bug An unexpected or incorrect behavior P-Regression Functionality that used to work but no longer does. Add a test for this!

Comments

@Shatur
Copy link
Contributor

Shatur commented Feb 23, 2024

Bevy version

0.13

[Optional] Relevant system information

OS: ArchLinux
CPU: 32 × AMD Ryzen 9 5950X 16-Core Processor

What you did

I rendering to texture in order to have preview for models in my game.

In 0.12 I discovered a bug #10688 that has been fixed in #10745.

What went wrong

But after update to 0.13 it looks like it has been reintroduced. I have the same problem, sometimes it renders the asset, sometimes not.

Additional information

Here is the minimal example to reproduce: assets_render.zip.
If you disable multi-threaded feature, it will work as expected.

With the following changes the code compiles on 0.12 and works as expected with multi-threaded feature on:

diff --git a/Cargo.toml b/Cargo.toml
index 0d88782..6955489 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -4,7 +4,7 @@ version = "0.1.0"
 edition = "2021"
 
 [dependencies]
-bevy = { version = "0.13", default-features = false, features = [
+bevy = { version = "0.12", default-features = false, features = [
   "bevy_gltf",
   "bevy_ui",
   "bevy_sprite",
diff --git a/src/main.rs b/src/main.rs
index 190bc1c..7b5cd2f 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -12,7 +12,7 @@ fn main() {
     App::new()
         .insert_resource(AmbientLight {
             color: Color::WHITE,
-            brightness: 1000.0,
+            brightness: 1.0,
         })
         .add_plugins((
             DefaultPlugins.set(LogPlugin {
diff --git a/src/preview.rs b/src/preview.rs
index 7718258..3b55e72 100644
--- a/src/preview.rs
+++ b/src/preview.rs
@@ -14,7 +14,7 @@ pub(super) struct PreviewPlugin;
 
 impl Plugin for PreviewPlugin {
     fn build(&self, app: &mut App) {
-        app.init_state::<PreviewState>()
+        app.add_state::<PreviewState>()
             .add_systems(Startup, Self::spawn_camera_system)
             .add_systems(OnEnter(PreviewState::Inactive), Self::deactivation_system)
             .add_systems(
@@ -143,6 +143,7 @@ const PREVIEW_RENDER_LAYER: RenderLayers = RenderLayers::layer(1);
 #[derive(Bundle)]
 struct PreviewCameraBundle {
     name: Name,
+    ui_camera_config: UiCameraConfig,
     preview_camera: PreviewCamera,
     render_layer: RenderLayers,
     camera_bundle: Camera3dBundle,
@@ -153,6 +154,7 @@ impl Default for PreviewCameraBundle {
     fn default() -> Self {
         Self {
             name: "Preview camera".into(),
+            ui_camera_config: UiCameraConfig { show_ui: false },
             preview_camera: PreviewCamera,
             render_layer: PREVIEW_RENDER_LAYER,
             camera_bundle: Camera3dBundle {
@Shatur Shatur added C-Bug An unexpected or incorrect behavior S-Needs-Triage This issue needs to be labelled labels Feb 23, 2024
@Shatur Shatur changed the title GLTF rendering no longer predictable after 0.13 GLTF rendering is no longer predictable after 0.13 Feb 23, 2024
@BD103 BD103 added A-Rendering Drawing game state to the screen P-Regression Functionality that used to work but no longer does. Add a test for this! and removed S-Needs-Triage This issue needs to be labelled labels Feb 23, 2024
@BD103
Copy link
Member

BD103 commented Feb 23, 2024

I was unable to reproduce this on my machine, using the zipfile linked.

2024-02-23T19:33:07.795597Z  INFO log: Adapter Metal AdapterInfo { name: "Apple M1", vendor: 0, device: 0, device_type: IntegratedGpu, driver: "", driver_info: "", backend: Metal }    
2024-02-23T19:33:07.796343Z  INFO bevy_render::renderer: AdapterInfo { name: "Apple M1", vendor: 0, device: 0, device_type: IntegratedGpu, driver: "", driver_info: "", backend: Metal }
2024-02-23T19:33:08.136412Z  INFO bevy_winit::system: Creating new window "App" (0v1)
2024-02-23T19:33:08.165192Z  INFO bevy_diagnostic::system_information_diagnostics_plugin::internal: SystemInfo { os: "MacOS 14.2.1 ", kernel: "23.2.0", cpu: "Apple M1", core_count: "8", memory: "16.0 GiB" }

How many times did you have to run the program in order to see the incorrect behavior? All of the images rendered correctly for me.

@Shatur
Copy link
Contributor Author

Shatur commented Feb 23, 2024

Happens 100% of the time for me (I just downloaded the archive and compiled it from scratch):
image

Added system information to the issue. Looks like we have different OSes. I also have a lot of cores (32).

@BD103
Copy link
Member

BD103 commented Feb 23, 2024

Odd, there must be some architectural differences that makes the bug more common on your system. Let's wait for someone else to weigh in and test it...

@mockersf
Copy link
Member

This is due to asynchronous pipeline compilation, which is disabled on macOS or without feature multi-threaded

What's happening is:

  • gltf is loaded
  • you try to display it
  • displaying it trigger the pipeline compilation
  • if the pipeline is compiled fast enough, or was compiled for a previously loaded asset, the gltf will be displayed. otherwise, nothing happens

This is most of the times not a problem because Bevy keeps trying to render things every frame, but in your case you're only rendering it once

@rparrett
Copy link
Contributor

rparrett commented Feb 23, 2024

(async pipeline compilation can be disabled with this setting on RenderPlugin.)

Or you can try to make sure all pipelines are compiled before advancing from a loading state.

@Shatur
Copy link
Contributor Author

Shatur commented Feb 23, 2024

Thank you a lot, disabling async pipeline compilation fixed the issue.

@Shatur Shatur closed this as completed Feb 23, 2024
@Shatur
Copy link
Contributor Author

Shatur commented Feb 23, 2024

Or you can try to make sure all pipelines are compiled before advancing from a loading state.

How can I do so?

@rparrett
Copy link
Contributor

How can I do so?

It's a bit of a pain. You need to create a "loading scene" that has every permutation of material properties or whatever so that all pipelines are created.

And then in the render app, check that status of all pipelines in PipelineCache.

There are advantages though -- on the web, pipeline compilation hangs the app and causes audio weirdness.

This tiny plugin can help a bit: https://github.com/rparrett/bevy_pipelines_ready.

See also: #10871

@Shatur
Copy link
Contributor Author

Shatur commented Feb 23, 2024

Thanks!

@cart
Copy link
Member

cart commented Feb 23, 2024

I think an important missing feature is a reasonable way to detect when everything in a scene is "fully ready to render".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Rendering Drawing game state to the screen C-Bug An unexpected or incorrect behavior P-Regression Functionality that used to work but no longer does. Add a test for this!
Projects
None yet
Development

No branches or pull requests

5 participants