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

Current UiStack based extraction potentially leads to poor batching #7345

Open
james7132 opened this issue Jan 23, 2023 · 4 comments
Open

Current UiStack based extraction potentially leads to poor batching #7345

james7132 opened this issue Jan 23, 2023 · 4 comments
Labels
A-Rendering Drawing game state to the screen A-UI Graphical user interfaces, styles, layouts, and widgets C-Performance A change motivated by improving speed, memory usage or compile times S-Needs-Design This issue requires design work to think about how it would best be accomplished

Comments

@james7132
Copy link
Member

Bevy version

a3baf2a

What you did

cargo run --profile stress-test --features trace_tracy --example many_buttons

What went wrong

Issuing 24,000+ draw calls when it could be issuing 3.

The construction of UiStack forces siblings of a similar depth in the hierarchy to be non-adjacent if any of them have children. This also forces their descendants to not be adjacent, which is breaking large scale batching.

fn fill_stack_recursively(result: &mut Vec<Entity>, stack: &mut StackingContext) {
// sort entries by ascending z_index, while ensuring that siblings
// with the same local z_index will keep their ordering.
stack.entries.sort_by_key(|e| e.z_index);
for entry in &mut stack.entries {
result.push(entry.entity);
fill_stack_recursively(result, &mut entry.stack);
}
}

@james7132 james7132 added A-Rendering Drawing game state to the screen C-Performance A change motivated by improving speed, memory usage or compile times A-UI Graphical user interfaces, styles, layouts, and widgets S-Needs-Design This issue requires design work to think about how it would best be accomplished labels Jan 23, 2023
@james7132 james7132 changed the title Current UiStack based extractio potentially leads to poor batching Current UiStack based extraction potentially leads to poor batching Jan 23, 2023
@ickshonpe
Copy link
Contributor

ickshonpe commented Mar 7, 2023

I just had an epiphany about this.

The UiStack rendering order is correct. Most of the time it's only very inefficient in special cases like many_buttons where you have a huge number of UI elements arranged in a flat grid. But for these special cases there is an easy workaround, we can just give all the leaf nodes in the grid the same global ZIndex. That immediately doubles the FPS for me in many_buttons in release mode.

There might even be a way to do this automatically as leaf nodes are much more likely to be textured.

@nicoburns
Copy link
Contributor

Most of the time it's only very inefficient in special cases like many_buttons where you have a huge number of UI elements arranged in a flat grid. But for these special cases there is an easy workaround, we can just give all the leaf nodes in the grid the same global ZIndex.

What if you have a large number of items arranged in a flat grid with a modal rendering over the top? I think this needs a more general solution (and my understanding is that such a more general solution is possible).

@ickshonpe
Copy link
Contributor

Well, you just give the modal rendering an even higher Global ZIndex. But yeah, you are right, it's a hack not a solution to the overall problem.

@nicoburns
Copy link
Contributor

It may be possible to solve this using depth buffers. From the Iced discord:

Screenshot 2023-03-16 at 00 25 46

Screenshot 2023-03-16 at 00 25 58

Screenshot 2023-03-16 at 00 26 14

(https://discord.com/channels/628993209984614400/1027584473631555604/1075119353332248686)

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 A-UI Graphical user interfaces, styles, layouts, and widgets C-Performance A change motivated by improving speed, memory usage or compile times S-Needs-Design This issue requires design work to think about how it would best be accomplished
Projects
None yet
Development

No branches or pull requests

3 participants