bevyengine / bevy

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

compute_shader_game_of_life example: `prepare_bind_group` is called every frame #13806

Closed shiki-saiki closed 3 months ago

shiki-saiki commented 3 months ago

Bevy version

main branch (d659a1f)

AdapterInfo { name: "AMD Radeon RX 6600", vendor: 4098, device: 29695, device_type: DiscreteGpu, driver: "AMD proprietary driver", driver_info: "23.10.2 (AMD proprietary shader compiler)", backend: Vulkan }

What you did

In compute_shader_game_of_life example, I added println!("prepare_bind_group"); in prepare_bind_group function.

What went wrong

It was printed every frame.

I think we only need to create bind groups once before any frames begin.

Is it correct that systems in RenderSet::PrepareBindGroups are called every frame?

I'm relatively new to Bevy, so I apologize if there are any mistakes.

IceSentry commented 3 months ago

Prepare systems are expected to be called every frame. Creating bind groups is not particularly expensive and in bevy itself a lot of bind groups can change dynamically so it's easier to just always recreate them. Also, if a bind group is on an entity instead of a resource, since the render world recreates all entities every frame we need to recreate the bind groups every frame or store them somewhere else.

The code in examples is only the minimal code required to make something work. You could add code to control whether or not you want to create a bind group, that's completely up to you.

shiki-saiki commented 3 months ago

Thank you for the explanation!