Commit b45a409
Don't reallocate work item buffers every frame. (bevyengine#17684)
We were calling `clear()` on the work item buffer table, which caused us
to deallocate all the CPU side buffers. This patch changes the logic to
instead just clear the buffers individually, but leave their backing
stores. This has two consequences:
1. To effectively retain work item buffers from frame to frame, we need
to key them off `RetainedViewEntity` values and not the render world
`Entity`, which is transient. This PR changes those buffers accordingly.
2. We need to clean up work item buffers that belong to views that went
away. Amusingly enough, we actually have a system,
`delete_old_work_item_buffers`, that tries to do this already, but it
wasn't doing anything because the `clear_batched_gpu_instance_buffers`
system already handled that. This patch actually makes the
`delete_old_work_item_buffers` system useful, by removing the clearing
behavior from `clear_batched_gpu_instance_buffers` and instead making
`delete_old_work_item_buffers` delete buffers corresponding to
nonexistent views.
On Bistro, this PR improves the performance of
`batch_and_prepare_binned_render_phase` from 61.2 us to 47.8 us, a 28%
speedup.
1 parent ebdac8c commit b45a409
File tree
3 files changed
+69
-34
lines changed- crates
- bevy_pbr/src/render
- bevy_render/src/batching
- examples/shader
3 files changed
+69
-34
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
51 | | - | |
| 51 | + | |
52 | 52 | | |
53 | 53 | | |
54 | 54 | | |
| |||
100 | 100 | | |
101 | 101 | | |
102 | 102 | | |
103 | | - | |
| 103 | + | |
104 | 104 | | |
105 | 105 | | |
106 | 106 | | |
| |||
120 | 120 | | |
121 | 121 | | |
122 | 122 | | |
123 | | - | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
124 | 128 | | |
125 | 129 | | |
126 | 130 | | |
| |||
580 | 584 | | |
581 | 585 | | |
582 | 586 | | |
583 | | - | |
| 587 | + | |
| 588 | + | |
584 | 589 | | |
585 | 590 | | |
586 | 591 | | |
| |||
791 | 796 | | |
792 | 797 | | |
793 | 798 | | |
794 | | - | |
| 799 | + | |
| 800 | + | |
795 | 801 | | |
796 | 802 | | |
797 | 803 | | |
| |||
1619 | 1625 | | |
1620 | 1626 | | |
1621 | 1627 | | |
| 1628 | + | |
1622 | 1629 | | |
1623 | 1630 | | |
1624 | 1631 | | |
| |||
1651 | 1658 | | |
1652 | 1659 | | |
1653 | 1660 | | |
1654 | | - | |
| 1661 | + | |
| 1662 | + | |
| 1663 | + | |
| 1664 | + | |
| 1665 | + | |
| 1666 | + | |
1655 | 1667 | | |
1656 | 1668 | | |
1657 | 1669 | | |
1658 | 1670 | | |
1659 | 1671 | | |
1660 | 1672 | | |
1661 | | - | |
| 1673 | + | |
1662 | 1674 | | |
1663 | 1675 | | |
1664 | 1676 | | |
| |||
1719 | 1731 | | |
1720 | 1732 | | |
1721 | 1733 | | |
1722 | | - | |
| 1734 | + | |
1723 | 1735 | | |
1724 | 1736 | | |
1725 | 1737 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | | - | |
8 | 7 | | |
9 | 8 | | |
10 | 9 | | |
| |||
13 | 12 | | |
14 | 13 | | |
15 | 14 | | |
16 | | - | |
| 15 | + | |
17 | 16 | | |
18 | 17 | | |
19 | 18 | | |
| |||
30 | 29 | | |
31 | 30 | | |
32 | 31 | | |
33 | | - | |
| 32 | + | |
34 | 33 | | |
35 | 34 | | |
36 | 35 | | |
| |||
157 | 156 | | |
158 | 157 | | |
159 | 158 | | |
160 | | - | |
| 159 | + | |
161 | 160 | | |
162 | 161 | | |
163 | 162 | | |
| |||
409 | 408 | | |
410 | 409 | | |
411 | 410 | | |
412 | | - | |
413 | | - | |
| 411 | + | |
| 412 | + | |
414 | 413 | | |
415 | 414 | | |
416 | 415 | | |
| |||
493 | 492 | | |
494 | 493 | | |
495 | 494 | | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
496 | 517 | | |
497 | 518 | | |
498 | 519 | | |
| |||
942 | 963 | | |
943 | 964 | | |
944 | 965 | | |
945 | | - | |
| 966 | + | |
946 | 967 | | |
947 | 968 | | |
948 | 969 | | |
| |||
968 | 989 | | |
969 | 990 | | |
970 | 991 | | |
971 | | - | |
| 992 | + | |
| 993 | + | |
| 994 | + | |
| 995 | + | |
| 996 | + | |
| 997 | + | |
| 998 | + | |
| 999 | + | |
972 | 1000 | | |
973 | 1001 | | |
974 | 1002 | | |
| |||
1074 | 1102 | | |
1075 | 1103 | | |
1076 | 1104 | | |
1077 | | - | |
| 1105 | + | |
1078 | 1106 | | |
1079 | 1107 | | |
1080 | 1108 | | |
| 1109 | + | |
| 1110 | + | |
| 1111 | + | |
| 1112 | + | |
1081 | 1113 | | |
1082 | 1114 | | |
1083 | | - | |
| 1115 | + | |
1084 | 1116 | | |
1085 | 1117 | | |
1086 | 1118 | | |
| |||
1091 | 1123 | | |
1092 | 1124 | | |
1093 | 1125 | | |
1094 | | - | |
1095 | 1126 | | |
1096 | 1127 | | |
1097 | 1128 | | |
| |||
1110 | 1141 | | |
1111 | 1142 | | |
1112 | 1143 | | |
1113 | | - | |
| 1144 | + | |
1114 | 1145 | | |
1115 | 1146 | | |
1116 | 1147 | | |
1117 | 1148 | | |
1118 | 1149 | | |
1119 | 1150 | | |
1120 | 1151 | | |
1121 | | - | |
| 1152 | + | |
1122 | 1153 | | |
1123 | 1154 | | |
1124 | 1155 | | |
| |||
1248 | 1279 | | |
1249 | 1280 | | |
1250 | 1281 | | |
1251 | | - | |
1252 | 1282 | | |
1253 | 1283 | | |
1254 | 1284 | | |
| |||
1270 | 1300 | | |
1271 | 1301 | | |
1272 | 1302 | | |
1273 | | - | |
| 1303 | + | |
1274 | 1304 | | |
1275 | 1305 | | |
1276 | 1306 | | |
| |||
1279 | 1309 | | |
1280 | 1310 | | |
1281 | 1311 | | |
1282 | | - | |
| 1312 | + | |
1283 | 1313 | | |
1284 | 1314 | | |
1285 | 1315 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
280 | 280 | | |
281 | 281 | | |
282 | 282 | | |
283 | | - | |
284 | 283 | | |
285 | 284 | | |
286 | 285 | | |
| |||
318 | 317 | | |
319 | 318 | | |
320 | 319 | | |
321 | | - | |
322 | | - | |
323 | | - | |
324 | | - | |
325 | | - | |
326 | | - | |
327 | | - | |
328 | | - | |
| 320 | + | |
| 321 | + | |
329 | 322 | | |
330 | 323 | | |
331 | 324 | | |
| |||
336 | 329 | | |
337 | 330 | | |
338 | 331 | | |
339 | | - | |
| 332 | + | |
340 | 333 | | |
341 | 334 | | |
342 | 335 | | |
| |||
0 commit comments