Commit fac186f
authored
UI stack partition (#20870)
# Objective
In the UI picking and rendering systems, we first query for all the
pickable or renderable UI nodes and then query per node for the details
of the camera and its render target. But the typical application using
Bevy UI will have hundreds of UI nodes and just one UI camera, so this
is extremely inefficient.
Instead, we can partition the UI stack into disjoint slices where all
the UI nodes in each slice have the same camera target. Then perform any
camera and render target lookups per slice, instead of per node.
## Solution
Partition the UI stack into disjoint layers of nodes sharing the same
camera target.
* Add a `partition: Vec<Range<usize>>` field to `UiStack`.
* Update the partitions in `ui_stack_system`.
* Query for cameras per slice in `ui_focus_system` and `ui_picking`.
Splitting the rendering changes off into their own PR.
---
## Testing
Some basic checks have been added to the existing `test_ui_stack_system`
and `test_with_equal_global_zindex_zindex_decides_order` tests.
Examples like `ui_target_camera`, `viewport_node` and `ui_drag_and_drop`
can be used to test the changes.
## Showcase
yellow this PR, red main:
```cargo run --example many_buttons --release --features bevy/trace_tracy```
`ui_picking`
<img width="500" alt="ui_picking" src="https://github.com/user-attachments/assets/a0e37205-dcb4-4228-8379-7d3fa4ea6adf" />
`ui_stack_system`
<img width="500" alt="ui_stack" src="https://github.com/user-attachments/assets/7e5487b8-9dc4-4db8-ac0e-04cc162cc420" />
---1 parent cf19650 commit fac186f
3 files changed
+123
-63
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
147 | 147 | | |
148 | 148 | | |
149 | 149 | | |
| 150 | + | |
150 | 151 | | |
151 | 152 | | |
152 | 153 | | |
| |||
215 | 216 | | |
216 | 217 | | |
217 | 218 | | |
218 | | - | |
219 | | - | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
220 | 224 | | |
221 | | - | |
222 | 225 | | |
223 | | - | |
224 | | - | |
225 | | - | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
226 | 247 | | |
227 | 248 | | |
228 | | - | |
229 | 249 | | |
230 | 250 | | |
231 | 251 | | |
232 | 252 | | |
233 | 253 | | |
234 | 254 | | |
235 | 255 | | |
236 | | - | |
| 256 | + | |
237 | 257 | | |
238 | | - | |
239 | | - | |
240 | | - | |
241 | 258 | | |
242 | 259 | | |
243 | 260 | | |
244 | | - | |
| 261 | + | |
245 | 262 | | |
246 | 263 | | |
247 | 264 | | |
| |||
270 | 287 | | |
271 | 288 | | |
272 | 289 | | |
273 | | - | |
| 290 | + | |
274 | 291 | | |
275 | 292 | | |
276 | 293 | | |
277 | 294 | | |
278 | 295 | | |
279 | 296 | | |
280 | 297 | | |
281 | | - | |
| 298 | + | |
282 | 299 | | |
283 | | - | |
284 | | - | |
285 | | - | |
| 300 | + | |
| 301 | + | |
286 | 302 | | |
287 | 303 | | |
288 | 304 | | |
289 | | - | |
| 305 | + | |
290 | 306 | | |
291 | 307 | | |
292 | 308 | | |
| |||
313 | 329 | | |
314 | 330 | | |
315 | 331 | | |
316 | | - | |
| 332 | + | |
317 | 333 | | |
318 | 334 | | |
319 | 335 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
157 | 157 | | |
158 | 158 | | |
159 | 159 | | |
160 | | - | |
161 | | - | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
162 | 163 | | |
163 | | - | |
164 | 164 | | |
| 165 | + | |
165 | 166 | | |
166 | | - | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
167 | 170 | | |
168 | 171 | | |
169 | 172 | | |
170 | | - | |
171 | | - | |
172 | | - | |
173 | | - | |
174 | | - | |
175 | | - | |
176 | | - | |
177 | | - | |
178 | | - | |
179 | | - | |
180 | | - | |
181 | | - | |
182 | | - | |
| 173 | + | |
183 | 174 | | |
184 | 175 | | |
185 | 176 | | |
186 | | - | |
187 | | - | |
188 | | - | |
189 | | - | |
190 | | - | |
191 | 177 | | |
192 | 178 | | |
193 | | - | |
194 | | - | |
195 | | - | |
196 | | - | |
197 | | - | |
198 | | - | |
199 | | - | |
200 | | - | |
201 | | - | |
202 | | - | |
203 | | - | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
204 | 207 | | |
205 | | - | |
206 | | - | |
207 | | - | |
208 | | - | |
209 | | - | |
210 | | - | |
211 | | - | |
212 | | - | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
213 | 225 | | |
214 | 226 | | |
215 | 227 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
4 | | - | |
5 | | - | |
6 | 3 | | |
7 | 4 | | |
8 | 5 | | |
9 | 6 | | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| 17 | + | |
| 18 | + | |
17 | 19 | | |
18 | 20 | | |
19 | 21 | | |
| |||
50 | 52 | | |
51 | 53 | | |
52 | 54 | | |
| 55 | + | |
53 | 56 | | |
54 | 57 | | |
55 | 58 | | |
| |||
81 | 84 | | |
82 | 85 | | |
83 | 86 | | |
| 87 | + | |
84 | 88 | | |
85 | 89 | | |
86 | 90 | | |
87 | 91 | | |
88 | 92 | | |
89 | 93 | | |
90 | 94 | | |
| 95 | + | |
| 96 | + | |
91 | 97 | | |
92 | 98 | | |
93 | 99 | | |
| |||
256 | 262 | | |
257 | 263 | | |
258 | 264 | | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
259 | 286 | | |
260 | 287 | | |
261 | 288 | | |
| |||
305 | 332 | | |
306 | 333 | | |
307 | 334 | | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
308 | 340 | | |
309 | 341 | | |
0 commit comments