bevyengine / bevy

A refreshingly simple data-driven game engine built in Rust
https://bevyengine.org
Apache License 2.0
36.22k stars 3.57k forks source link

2D shapes demo flickers #10917

Open M1cha opened 11 months ago

M1cha commented 11 months ago

Bevy version

v0.12.1

Relevant system information

What you did

cargo run --features wayland --example 2d_shapes

What went wrong

https://github.com/bevyengine/bevy/assets/878458/0959d365-77a8-4a56-92eb-1ee9afa869b2

Additional information

There is a warning in the log:

2023-12-09T07:52:55.988086Z  WARN bevy_pbr::ssao: ScreenSpaceAmbientOcclusionPlugin not loaded. GPU lacks support: TextureFormat::R16Float does not support TextureUsages::STORAGE_BINDING.

I can't test x11 because cargo run --features x11 --example 2d_shapes fails at runtime with:

2023-12-09T07:51:08.177244Z  INFO bevy_winit::system: Creating new window "App" (0v0)
2023-12-09T07:51:08.178137Z  WARN log: XRandR reported that the display's 0mm in size, which is certifiably insane
2023-12-09T07:51:08.178381Z  INFO log: Guessed window scale factor: 1
2023-12-09T07:51:08.239390Z  INFO bevy_render::renderer: AdapterInfo { name: "AMD Radeon Graphics (rembrandt, LLVM 16.0.6, DRM 3.54, 6.6.3-zen1-1-zen)", vendor: 4098, device: 0, device_type: Other, driver: "", driver_info: "", backend: Gl }
2023-12-09T07:51:08.610113Z  WARN bevy_pbr::ssao: ScreenSpaceAmbientOcclusionPlugin not loaded. GPU lacks support: TextureFormat::R16Float does not support TextureUsages::STORAGE_BINDING.
2023-12-09T07:51:08.612960Z  INFO bevy_diagnostic::system_information_diagnostics_plugin::internal: SystemInfo { os: "Linux 20230625.0.160437 Arch Linux", kernel: "6.6.3-zen1-1-zen", cpu: "AMD Ryzen 9 6900HX with Radeon Graphics", core_count: "8", memory: "23.2 GiB" }
2023-12-09T07:51:08.660015Z ERROR log: surface configuration failed: incompatible window kind
thread 'main' panicked at /home/m1cha/.cargo/registry/src/index.crates.io-6f17d22bba15001f/wgpu-0.17.2/src/backend/direct.rs:771:18:
Error in Surface::configure: Validation Error

Caused by:
    Invalid surface

note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Encountered a panic in system `bevy_render::view::window::prepare_windows`!
thread 'main' panicked at crates/bevy_render/src/pipelined_rendering.rs:145:45:
called `Result::unwrap()` on an `Err` value: RecvError
kuras120 commented 10 months ago

Hey. I've faced the same bug while migrating from 0.11.3 to 0.12.1. For me, spawning single shape like this:

            commands.spawn(MaterialMesh2dBundle {
                mesh: meshes.add(shape::Quad::new(
                    Vec2::new(100., 100.)
                ).into()).into(),
                material: materials.add(ColorMaterial::from(resource.border_color)),
                transform: Transform::from_translation(Vec3::new(
                    calc_x,
                    calc_y,
                    0.
                )),
                ..default()
            });

works as expected. But if I add another spawn command, It starts its weird blinking. Moreover, when I had added mouse support for marking shapes It looked like shapes were switching places.

https://github.com/bevyengine/bevy/assets/27972409/7325dc93-2846-4beb-b693-b3699197acba

I'm currently using SpriteBundle as a temporary solution for testing purposes :)

Pranav-Badrinathan commented 9 months ago

Well, for me I don't see any output from running the 2D shapes example or my own extremely similar implementation on the latest branch (0.12.1 as of now). 0.12.0 works just fine, it's just 0.12.1 that does not. 0.12.1: image

0.12.0: image

Seems similar to #152? Though that was a loooooong while ago, so maybe a completely different reason?

OS: Windows 11 22H2 build 22621.3007 Rust ver: 1.75.0 bevy version: 0.12.1 CPU: Intel i5 8250U GPU: Intel UHD Graphics 620

Lommix commented 9 months ago

I have the same issue. Any custom or standard material2d causes flickering. Sprites work.

Running Wayland on Arch. cargo 1.75.0 bevy 0.12.1

2024-02-02T20:35:43.139661Z ERROR log: XDG Settings Portal did not return response in time: timeout: 100ms, key: color-scheme
2024-02-02T20:35:43.179693Z  INFO bevy_render::renderer: AdapterInfo { name: "AMD Radeon RX 6800 XT (radeonsi, navi21, LLVM 16.0.6, DRM 3.56, 6.7.2-arch1-1)", vendor: 4098, device: 0, device_type: Other, driver: "", driver_info: "", backend: Gl }
2024-02-02T20:35:43.224529Z  WARN bevy_pbr::ssao: ScreenSpaceAmbientOcclusionPlugin not loaded. GPU lacks support: TextureFormat::R16Float does not support TextureUsages::STORAGE_BINDING.

Example for Colormaterial:

20240202220234

I noticed, that the flickering only occures, when at least 2 meshes of the same kind are present on screen.

It feels like z-index fighting, but without sharing screen space.

20240202220114

I have no problems when exporting to wasm and running in the browser.

Lommix commented 9 months ago

So far I can confirm, that this bug only happens on the GL Backend. Switching to vulkan makes this disappear.

WGPU_BACKEND=vulkan cargo run --features wayland --example 2d_shapes
liquidhelium commented 9 months ago

I met the same issue as well, though in my case the overlapped three shapes are at the position of one of them, depending on which has the lowest z-value.